OSDN Git Service

Set chain Tx Gas 0 (#409) master
authoryahtoo <yahtoo.ma@gmail.com>
Tue, 15 Oct 2019 02:10:59 +0000 (10:10 +0800)
committerPaladz <yzhu101@uottawa.ca>
Tue, 15 Oct 2019 02:10:59 +0000 (10:10 +0800)
* Set chain Tx Gas 0

* Fix test file err

* Revert test file modify

account/builder.go
account/builder_test.go
test/builder_test.go

index ca533a0..af80a00 100644 (file)
@@ -20,7 +20,7 @@ var (
        //chainTxUtxoNum maximum utxo quantity in a tx
        chainTxUtxoNum = 20
        //chainTxMergeGas chain tx gas
-       chainTxMergeGas = uint64(10000000)
+       chainTxMergeGas = uint64(0)
 )
 
 //DecodeSpendAction unmarshal JSON-encoded data of spend action
index c5f2cbd..1ca6a62 100644 (file)
@@ -354,56 +354,10 @@ func TestMergeSpendAction(t *testing.T) {
        }
 }
 
-func TestCalcMergeGas(t *testing.T) {
-       chainTxUtxoNum = 10
-       cases := []struct {
-               utxoNum int
-               gas     uint64
-       }{
-               {
-                       utxoNum: 0,
-                       gas:     0,
-               },
-               {
-                       utxoNum: 1,
-                       gas:     0,
-               },
-               {
-                       utxoNum: 9,
-                       gas:     chainTxMergeGas,
-               },
-               {
-                       utxoNum: 10,
-                       gas:     chainTxMergeGas,
-               },
-               {
-                       utxoNum: 11,
-                       gas:     chainTxMergeGas * 2,
-               },
-               {
-                       utxoNum: 20,
-                       gas:     chainTxMergeGas * 3,
-               },
-               {
-                       utxoNum: 21,
-                       gas:     chainTxMergeGas * 3,
-               },
-               {
-                       utxoNum: 74,
-                       gas:     chainTxMergeGas * 9,
-               },
-       }
-
-       for i, c := range cases {
-               gas := calcMergeGas(c.utxoNum)
-               if gas != c.gas {
-                       t.Fatalf("case %d got %d want %d", i, gas, c.gas)
-               }
-       }
-}
-
 func TestReserveBtmUtxoChain(t *testing.T) {
        chainTxUtxoNum = 3
+       chainTxMergeGas = uint64(10000000)
+
        utxos := []*UTXO{}
        m := mockAccountManager(t)
        for i := uint64(1); i <= 20; i++ {
index 839a4a9..7eda649 100644 (file)
@@ -13,8 +13,6 @@ import (
 var (
        //chainTxUtxoNum maximum utxo quantity in a tx
        chainTxUtxoNum = 5
-       //chainTxMergeGas chain tx gas
-       chainTxMergeGas = uint64(10000000)
 )
 
 func TestBuildBtmTxChain(t *testing.T) {
@@ -30,7 +28,7 @@ func TestBuildBtmTxChain(t *testing.T) {
                        inputUtxo:  []uint64{5},
                        wantInput:  [][]uint64{},
                        wantOutput: [][]uint64{},
-                       wantUtxo:   5 * chainTxMergeGas,
+                       wantUtxo:   5,
                },
                {
                        inputUtxo: []uint64{5, 4},
@@ -38,9 +36,9 @@ func TestBuildBtmTxChain(t *testing.T) {
                                []uint64{5, 4},
                        },
                        wantOutput: [][]uint64{
-                               []uint64{8},
+                               []uint64{9},
                        },
-                       wantUtxo: 8 * chainTxMergeGas,
+                       wantUtxo: 9,
                },
                {
                        inputUtxo: []uint64{5, 4, 1, 1},
@@ -49,22 +47,22 @@ func TestBuildBtmTxChain(t *testing.T) {
                                []uint64{1, 9},
                        },
                        wantOutput: [][]uint64{
+                               []uint64{11},
                                []uint64{10},
-                               []uint64{9},
                        },
-                       wantUtxo: 10 * chainTxMergeGas,
+                       wantUtxo: 11,
                },
                {
                        inputUtxo: []uint64{22, 123, 53, 234, 23, 4, 2423, 24, 23, 43, 34, 234, 234, 24, 11, 16, 33, 59, 73, 89, 66},
                        wantInput: [][]uint64{
                                []uint64{22, 123, 53, 234, 23, 4, 2423, 24, 23, 43, 34, 234, 234, 24, 11, 16, 33, 59, 73, 89},
-                               []uint64{66, 3778},
+                               []uint64{66, 3779},
                        },
                        wantOutput: [][]uint64{
-                               []uint64{3778},
-                               []uint64{3843},
+                               []uint64{3779},
+                               []uint64{3845},
                        },
-                       wantUtxo: 3843 * chainTxMergeGas,
+                       wantUtxo: 3845,
                },
        }
 
@@ -82,7 +80,7 @@ func TestBuildBtmTxChain(t *testing.T) {
                utxos := []*acc.UTXO{}
                for _, amount := range c.inputUtxo {
                        utxos = append(utxos, &acc.UTXO{
-                               Amount:         amount * chainTxMergeGas,
+                               Amount:         amount,
                                AssetID:        *consensus.BTMAssetID,
                                Address:        acp.Address,
                                ControlProgram: acp.ControlProgram,
@@ -97,12 +95,12 @@ func TestBuildBtmTxChain(t *testing.T) {
                for i, tpl := range tpls {
                        gotInput := []uint64{}
                        for _, input := range tpl.Transaction.Inputs {
-                               gotInput = append(gotInput, input.Amount()/chainTxMergeGas)
+                               gotInput = append(gotInput, input.Amount())
                        }
 
                        gotOutput := []uint64{}
                        for _, output := range tpl.Transaction.Outputs {
-                               gotOutput = append(gotOutput, output.AssetAmount().Amount/chainTxMergeGas)
+                               gotOutput = append(gotOutput, output.AssetAmount().Amount)
                        }
 
                        if !testutil.DeepEqual(c.wantInput[i], gotInput) {