OSDN Git Service

fix reorganize vote result (#151)
[bytom/vapor.git] / wallet / utxo_test.go
index fb8a224..e5fb1b8 100644 (file)
@@ -18,7 +18,10 @@ import (
 
 func TestGetAccountUtxos(t *testing.T) {
        testDB := dbm.NewDB("testdb", "leveldb", "temp")
-       defer os.RemoveAll("temp")
+       defer func() {
+               testDB.Close()
+               os.RemoveAll("temp")
+       }()
 
        cases := []struct {
                dbUtxos          map[string]*account.UTXO
@@ -207,7 +210,10 @@ func TestGetAccountUtxos(t *testing.T) {
 
 func TestFilterAccountUtxo(t *testing.T) {
        testDB := dbm.NewDB("testdb", "leveldb", "temp")
-       defer os.RemoveAll("temp")
+       defer func() {
+               testDB.Close()
+               os.RemoveAll("temp")
+       }()
 
        cases := []struct {
                dbPrograms map[string]*account.CtrlProgram
@@ -396,18 +402,6 @@ func TestTxInToUtxos(t *testing.T) {
                {
                        tx: types.NewTx(types.TxData{
                                Inputs: []*types.TxInput{
-                                       types.NewIssuanceInput([]byte{}, 4125, []byte{0x51}, [][]byte{}, []byte{}),
-                               },
-                               Outputs: []*types.TxOutput{
-                                       types.NewIntraChainOutput(*consensus.BTMAssetID, 4125, []byte{0x51}),
-                               },
-                       }),
-                       statusFail: false,
-                       wantUtxos:  []*account.UTXO{},
-               },
-               {
-                       tx: types.NewTx(types.TxData{
-                               Inputs: []*types.TxInput{
                                        types.NewSpendInput([][]byte{}, bc.Hash{V0: 1}, bc.AssetID{V0: 1}, 1, 1, []byte{0x51}),
                                        types.NewSpendInput([][]byte{}, bc.Hash{V0: 2}, bc.AssetID{V0: 1}, 3, 2, []byte{0x52}),
                                        types.NewSpendInput([][]byte{}, bc.Hash{V0: 3}, *consensus.BTMAssetID, 5, 3, []byte{0x53}),
@@ -487,6 +481,28 @@ func TestTxInToUtxos(t *testing.T) {
                                },
                        },
                },
+               {
+                       tx: types.NewTx(types.TxData{
+                               Inputs: []*types.TxInput{
+                                       types.NewUnvoteInput([][]byte{}, bc.Hash{V0: 1}, bc.AssetID{V0: 1}, 1, 1, []byte{0x51}, []byte("af594006a40837d9f028daabb6d589df0b9138daefad5683e5233c2646279217294a8d532e60863bcf196625a35fb8ceeffa3c09610eb92dcfb655a947f13269")),
+                               },
+                               Outputs: []*types.TxOutput{
+                                       types.NewIntraChainOutput(bc.AssetID{V0: 1}, 1, []byte{0x51}),
+                               },
+                       }),
+                       statusFail: false,
+                       wantUtxos: []*account.UTXO{
+                               &account.UTXO{
+                                       OutputID:       bc.NewHash([32]byte{0x95, 0x23, 0x06, 0xa5, 0x2f, 0xc4, 0xe2, 0x36, 0x03, 0x0f, 0xe3, 0xe6, 0xb8, 0x0b, 0xcc, 0x3c, 0x1e, 0x17, 0x3e, 0x25, 0x95, 0xd0, 0xbf, 0x08, 0x11, 0x73, 0x06, 0xd4, 0x64, 0x9c, 0xfb, 0x3b}),
+                                       AssetID:        bc.AssetID{V0: 1},
+                                       Amount:         1,
+                                       ControlProgram: []byte{0x51},
+                                       Vote:           []byte("af594006a40837d9f028daabb6d589df0b9138daefad5683e5233c2646279217294a8d532e60863bcf196625a35fb8ceeffa3c09610eb92dcfb655a947f13269"),
+                                       SourceID:       bc.Hash{V0: 1},
+                                       SourcePos:      1,
+                               },
+                       },
+               },
        }
 
        for i, c := range cases {
@@ -618,6 +634,89 @@ func TestTxOutToUtxos(t *testing.T) {
                                },
                        },
                },
+               {
+                       tx: types.NewTx(types.TxData{
+                               Inputs: []*types.TxInput{
+                                       types.NewSpendInput([][]byte{}, bc.Hash{V0: 1}, bc.AssetID{V0: 1}, 5, 1, []byte{0x51}),
+                                       types.NewSpendInput([][]byte{}, bc.Hash{V0: 2}, *consensus.BTMAssetID, 7, 1, []byte{0x51}),
+                               },
+                               Outputs: []*types.TxOutput{
+                                       types.NewIntraChainOutput(bc.AssetID{V0: 1}, 2, []byte{0x51}),
+                                       types.NewCrossChainOutput(bc.AssetID{V0: 1}, 3, []byte{0x52}),
+                                       types.NewIntraChainOutput(*consensus.BTMAssetID, 2, []byte{0x53}),
+                                       types.NewCrossChainOutput(*consensus.BTMAssetID, 5, []byte{0x54}),
+                               },
+                       }),
+                       statusFail:  false,
+                       vaildHeight: 0,
+                       wantUtxos: []*account.UTXO{
+                               &account.UTXO{
+                                       OutputID:       bc.Hash{V0: 8675398163687045889, V1: 7549510466747714094, V2: 13693077838209211470, V3: 6878568403630757599},
+                                       AssetID:        bc.AssetID{V0: 1},
+                                       Amount:         2,
+                                       ControlProgram: []byte{0x51},
+                                       SourceID:       bc.Hash{V0: 968805671293010031, V1: 9297014342000792994, V2: 16963674611624423333, V3: 2728293460397542670},
+                                       SourcePos:      0,
+                               },
+                               &account.UTXO{
+                                       OutputID:       bc.Hash{V0: 7067560744282869147, V1: 8991714784298240423, V2: 2595857933262917893, V3: 11490631006811252506},
+                                       AssetID:        *consensus.BTMAssetID,
+                                       Amount:         2,
+                                       ControlProgram: []byte{0x53},
+                                       SourceID:       bc.Hash{V0: 968805671293010031, V1: 9297014342000792994, V2: 16963674611624423333, V3: 2728293460397542670},
+                                       SourcePos:      2,
+                               },
+                       },
+               },
+               {
+                       tx: types.NewTx(types.TxData{
+                               Inputs: []*types.TxInput{
+                                       types.NewCrossChainInput([][]byte{}, bc.Hash{V0: 1}, bc.AssetID{V0: 1}, 5, 1, []byte{0x51}, []byte("asset1")),
+                                       types.NewCrossChainInput([][]byte{}, bc.Hash{V0: 2}, *consensus.BTMAssetID, 7, 1, []byte{0x51}, []byte("assetbtm"))},
+                               Outputs: []*types.TxOutput{
+                                       types.NewIntraChainOutput(bc.AssetID{V0: 1}, 2, []byte{0x51}),
+                                       types.NewIntraChainOutput(bc.AssetID{V0: 1}, 3, []byte{0x52}),
+                                       types.NewIntraChainOutput(*consensus.BTMAssetID, 2, []byte{0x53}),
+                                       types.NewIntraChainOutput(*consensus.BTMAssetID, 5, []byte{0x54}),
+                               },
+                       }),
+                       statusFail:  false,
+                       vaildHeight: 0,
+                       wantUtxos: []*account.UTXO{
+                               &account.UTXO{
+                                       OutputID:       bc.Hash{V0: 396952592194652166, V1: 9806684391645699244, V2: 484243382648745315, V3: 16988093808435014689},
+                                       AssetID:        bc.AssetID{V0: 1},
+                                       Amount:         2,
+                                       ControlProgram: []byte{0x51},
+                                       SourceID:       bc.Hash{V0: 15256474482236132139, V1: 14615963227748152009, V2: 1392768713126269609, V3: 3435801067785833027},
+                                       SourcePos:      0,
+                               },
+                               &account.UTXO{
+                                       OutputID:       bc.Hash{V0: 10880631720641638863, V1: 7783872056988487492, V2: 10925792818362846534, V3: 16483659407709834456},
+                                       AssetID:        bc.AssetID{V0: 1},
+                                       Amount:         3,
+                                       ControlProgram: []byte{0x52},
+                                       SourceID:       bc.Hash{V0: 15256474482236132139, V1: 14615963227748152009, V2: 1392768713126269609, V3: 3435801067785833027},
+                                       SourcePos:      1,
+                               },
+                               &account.UTXO{
+                                       OutputID:       bc.Hash{V0: 6688768820716928311, V1: 7640171490156205612, V2: 6082620342644961312, V3: 6194446985740174532},
+                                       AssetID:        *consensus.BTMAssetID,
+                                       Amount:         2,
+                                       ControlProgram: []byte{0x53},
+                                       SourceID:       bc.Hash{V0: 15256474482236132139, V1: 14615963227748152009, V2: 1392768713126269609, V3: 3435801067785833027},
+                                       SourcePos:      2,
+                               },
+                               &account.UTXO{
+                                       OutputID:       bc.Hash{V0: 13540722642395030514, V1: 15412939347183859286, V2: 9545016219428105666, V3: 11940603522975438116},
+                                       AssetID:        *consensus.BTMAssetID,
+                                       Amount:         5,
+                                       ControlProgram: []byte{0x54},
+                                       SourceID:       bc.Hash{V0: 15256474482236132139, V1: 14615963227748152009, V2: 1392768713126269609, V3: 3435801067785833027},
+                                       SourcePos:      3,
+                               },
+                       },
+               },
        }
 
        for i, c := range cases {