OSDN Git Service

Supplementary unit tests validate_matched_tx_sequence_test
authorshenao78 <shenao.78@163.com>
Thu, 13 Feb 2020 02:59:38 +0000 (10:59 +0800)
committershenao78 <shenao.78@163.com>
Thu, 13 Feb 2020 02:59:38 +0000 (10:59 +0800)
application/mov/mock/mock.go
application/mov/mov_core_test.go

index 6bd6e0d..8dbd921 100644 (file)
@@ -172,6 +172,12 @@ var (
                        Inputs:  []*types.TxInput{types.NewSpendInput([][]byte{{}, {}, vm.Int64Bytes(2)}, *Btc2EthOrders[0].Utxo.SourceID, *Btc2EthOrders[0].FromAssetID, Btc2EthOrders[0].Utxo.Amount, Btc2EthOrders[0].Utxo.SourcePos, Btc2EthOrders[0].Utxo.ControlProgram)},
                        Outputs: []*types.TxOutput{types.NewIntraChainOutput(*Btc2EthOrders[0].FromAssetID, Btc2EthOrders[0].Utxo.Amount, testutil.MustDecodeHexString("0014f928b723999312df4ed51cb275a2644336c19251"))},
                }),
+
+               // output 2 of MatchedTxs[2]
+               types.NewTx(types.TxData{
+                       Inputs:  []*types.TxInput{types.NewSpendInput([][]byte{{}, {}, vm.Int64Bytes(2)}, *MustNewOrderFromOutput(MatchedTxs[2], 2).Utxo.SourceID, *Eth2BtcOrders[2].FromAssetID, 270, 2, Eth2BtcOrders[2].Utxo.ControlProgram)},
+                       Outputs: []*types.TxOutput{types.NewIntraChainOutput(*Eth2BtcOrders[2].FromAssetID, Eth2BtcOrders[2].Utxo.Amount, testutil.MustDecodeHexString("0014f928b723999312df4ed51cb275a2644336c19255"))},
+               }),
        }
 
        Btc2EthMakerTxs = []*types.Tx{
@@ -379,6 +385,19 @@ var (
                                types.NewIntraChainOutput(*Etc2EosOrders[0].ToAssetID, 100, testutil.MustDecodeHexString("0014df7a97e53bbe278e4e44810b0a760fb472daa9a3")),
                        },
                }),
+
+               // full matched transaction from Btc2EthOrders[0], Eth2BtcMakerTxs[0]
+               types.NewTx(types.TxData{
+                       Inputs: []*types.TxInput{
+                               types.NewSpendInput([][]byte{vm.Int64Bytes(0), vm.Int64Bytes(1)}, *Btc2EthOrders[0].Utxo.SourceID, *Btc2EthOrders[0].FromAssetID, Btc2EthOrders[0].Utxo.Amount, Btc2EthOrders[0].Utxo.SourcePos, Btc2EthOrders[0].Utxo.ControlProgram),
+                               types.NewSpendInput([][]byte{vm.Int64Bytes(1), vm.Int64Bytes(1)}, *MustNewOrderFromOutput(Eth2BtcMakerTxs[0], 0).Utxo.SourceID, *Eth2BtcOrders[0].FromAssetID, Eth2BtcOrders[0].Utxo.Amount, 0, Eth2BtcOrders[0].Utxo.ControlProgram),
+                       },
+                       Outputs: []*types.TxOutput{
+                               types.NewIntraChainOutput(*Btc2EthOrders[0].ToAssetID, 500, testutil.MustDecodeHexString("0014f928b723999312df4ed51cb275a2644336c19251")),
+                               types.NewIntraChainOutput(*Eth2BtcOrders[0].ToAssetID, 10, testutil.MustDecodeHexString("0014f928b723999312df4ed51cb275a2644336c19253")),
+                               types.NewIntraChainOutput(*Btc2EthOrders[0].ToAssetID, 10, NodeProgram),
+                       },
+               }),
        }
 )
 
index f084d34..8c8e6a6 100644 (file)
@@ -628,6 +628,18 @@ func TestValidateMatchedTxSequence(t *testing.T) {
                        wantError:    nil,
                },
                {
+                       desc:         "package matched tx, one order from db, and the another order from transactions",
+                       initOrders:   []*common.Order{mock.Btc2EthOrders[0]},
+                       transactions: []*types.Tx{mock.Eth2BtcMakerTxs[0], mock.MatchedTxs[10]},
+                       wantError:    nil,
+               },
+               {
+                       desc:         "two matched txs use the same orders",
+                       initOrders:   []*common.Order{mock.Btc2EthOrders[0], mock.Eth2BtcOrders[0]},
+                       transactions: []*types.Tx{mock.MatchedTxs[1], mock.MatchedTxs[1]},
+                       wantError:    errNotMatchedOrder,
+               },
+               {
                        desc: "existing two matched orders in db, and only one corresponding matched tx in transactions",
                        initOrders: []*common.Order{
                                mock.Btc2EthOrders[3], mock.Eth2BtcOrders[2],
@@ -646,7 +658,7 @@ func TestValidateMatchedTxSequence(t *testing.T) {
                        wantError:    errSpendOutputIDIsIncorrect,
                },
                {
-                       desc:         "package full matched tx from maker tx",
+                       desc:         "matched tx and orders from packaged transactions",
                        initOrders:   []*common.Order{},
                        transactions: []*types.Tx{mock.Btc2EthMakerTxs[0], mock.Eth2BtcMakerTxs[1], mock.MatchedTxs[4]},
                        wantError:    nil,
@@ -688,11 +700,17 @@ func TestValidateMatchedTxSequence(t *testing.T) {
                        wantError:    nil,
                },
                {
-                       desc:         "package partial matched tx from db orders",
+                       desc:         "package partial match tx from db orders, and the re-pending order continue to match",
                        initOrders:   []*common.Order{mock.Btc2EthOrders[0], mock.Btc2EthOrders[1], mock.Eth2BtcOrders[2]},
                        transactions: []*types.Tx{mock.MatchedTxs[2], mock.MatchedTxs[3]},
                        wantError:    nil,
                },
+               {
+                       desc:         "cancel the re-pending order",
+                       initOrders:   []*common.Order{mock.Btc2EthOrders[0], mock.Btc2EthOrders[1], mock.Eth2BtcOrders[2]},
+                       transactions: []*types.Tx{mock.MatchedTxs[2], mock.Btc2EthCancelTxs[1], mock.MatchedTxs[3]},
+                       wantError:    errNotMatchedOrder,
+               },
        }
 
        for i, c := range cases {