OSDN Git Service

delete the duplicate code
authorpaladz <453256728@qq.com>
Tue, 5 Nov 2019 08:35:48 +0000 (16:35 +0800)
committerpaladz <453256728@qq.com>
Tue, 5 Nov 2019 08:35:48 +0000 (16:35 +0800)
application/mov/database/mov_store_test.go

index a516867..d098044 100644 (file)
@@ -26,6 +26,174 @@ var (
        assetID6 = &bc.AssetID{V0: 6}
        assetID7 = &bc.AssetID{V0: 7}
        assetID8 = &bc.AssetID{V0: 8}
+
+       mockOrders = []*common.Order{
+               &common.Order{
+                       FromAssetID: assetID1,
+                       ToAssetID:   assetID2,
+                       Rate:        1.00090,
+                       Utxo: &common.MovUtxo{
+                               SourceID:       &bc.Hash{V0: 21},
+                               Amount:         1,
+                               SourcePos:      0,
+                               ControlProgram: []byte("aa"),
+                       },
+               },
+               &common.Order{
+                       FromAssetID: assetID1,
+                       ToAssetID:   assetID2,
+                       Rate:        0.00090,
+                       Utxo: &common.MovUtxo{
+                               SourceID:       &bc.Hash{V0: 22},
+                               Amount:         1,
+                               SourcePos:      0,
+                               ControlProgram: []byte("aa"),
+                       },
+               },
+               &common.Order{
+                       FromAssetID: assetID1,
+                       ToAssetID:   assetID2,
+                       Rate:        0.00097,
+                       Utxo: &common.MovUtxo{
+                               SourceID:       &bc.Hash{V0: 23},
+                               Amount:         1,
+                               SourcePos:      0,
+                               ControlProgram: []byte("aa"),
+                       },
+               },
+               &common.Order{
+                       FromAssetID: assetID1,
+                       ToAssetID:   assetID2,
+                       Rate:        0.00098,
+                       Utxo: &common.MovUtxo{
+                               SourceID:       &bc.Hash{V0: 13},
+                               Amount:         1,
+                               SourcePos:      0,
+                               ControlProgram: []byte("aa"),
+                       },
+               },
+               &common.Order{
+                       FromAssetID: assetID1,
+                       ToAssetID:   assetID2,
+                       Rate:        0.00098,
+                       Utxo: &common.MovUtxo{
+                               SourceID:       &bc.Hash{V0: 24},
+                               Amount:         10,
+                               SourcePos:      1,
+                               ControlProgram: []byte("aa"),
+                       },
+               },
+               &common.Order{
+                       FromAssetID: assetID1,
+                       ToAssetID:   assetID2,
+                       Rate:        0.00099,
+                       Utxo: &common.MovUtxo{
+                               SourceID:       &bc.Hash{V0: 24},
+                               Amount:         1,
+                               SourcePos:      0,
+                               ControlProgram: []byte("aa"),
+                       },
+               },
+               &common.Order{
+                       FromAssetID: assetID1,
+                       ToAssetID:   assetID2,
+                       Rate:        0.00096,
+                       Utxo: &common.MovUtxo{
+                               SourceID:       &bc.Hash{V0: 25},
+                               Amount:         1,
+                               SourcePos:      0,
+                               ControlProgram: []byte("aa"),
+                       },
+               },
+               &common.Order{
+                       FromAssetID: assetID1,
+                       ToAssetID:   assetID2,
+                       Rate:        0.00095,
+                       Utxo: &common.MovUtxo{
+                               SourceID:       &bc.Hash{V0: 26},
+                               Amount:         1,
+                               SourcePos:      0,
+                               ControlProgram: []byte("aa"),
+                       },
+               },
+               &common.Order{
+                       FromAssetID: assetID1,
+                       ToAssetID:   assetID2,
+                       Rate:        1.00090,
+                       Utxo: &common.MovUtxo{
+                               SourceID:       &bc.Hash{V0: 1},
+                               Amount:         1,
+                               SourcePos:      0,
+                               ControlProgram: []byte("aa"),
+                       },
+               },
+               &common.Order{
+                       FromAssetID: assetID1,
+                       ToAssetID:   assetID2,
+                       Rate:        0.00090,
+                       Utxo: &common.MovUtxo{
+                               SourceID:       &bc.Hash{V0: 2},
+                               Amount:         1,
+                               SourcePos:      0,
+                               ControlProgram: []byte("aa"),
+                       },
+               },
+               &common.Order{
+                       FromAssetID: assetID3,
+                       ToAssetID:   assetID2,
+                       Rate:        0.00096,
+                       Utxo: &common.MovUtxo{
+                               SourceID:       &bc.Hash{V0: 33},
+                               Amount:         1,
+                               SourcePos:      0,
+                               ControlProgram: []byte("aa"),
+                       },
+               },
+               &common.Order{
+                       FromAssetID: assetID4,
+                       ToAssetID:   assetID2,
+                       Rate:        0.00095,
+                       Utxo: &common.MovUtxo{
+                               SourceID:       &bc.Hash{V0: 34},
+                               Amount:         1,
+                               SourcePos:      0,
+                               ControlProgram: []byte("aa"),
+                       },
+               },
+               &common.Order{
+                       FromAssetID: assetID4,
+                       ToAssetID:   assetID2,
+                       Rate:        0.00096,
+                       Utxo: &common.MovUtxo{
+                               SourceID:       &bc.Hash{V0: 36},
+                               Amount:         1,
+                               SourcePos:      0,
+                               ControlProgram: []byte("aa"),
+                       },
+               },
+               &common.Order{
+                       FromAssetID: assetID5,
+                       ToAssetID:   assetID2,
+                       Rate:        0.00096,
+                       Utxo: &common.MovUtxo{
+                               SourceID:       &bc.Hash{V0: 37},
+                               Amount:         1,
+                               SourcePos:      0,
+                               ControlProgram: []byte("aa"),
+                       },
+               },
+               &common.Order{
+                       FromAssetID: assetID6,
+                       ToAssetID:   assetID2,
+                       Rate:        0.00098,
+                       Utxo: &common.MovUtxo{
+                               SourceID:       &bc.Hash{V0: 38},
+                               Amount:         1,
+                               SourcePos:      0,
+                               ControlProgram: []byte("aa"),
+                       },
+               },
+       }
 )
 
 func TestGetAssetIDFromTradePairKey(t *testing.T) {
@@ -62,12 +230,12 @@ func TestSortOrderKey(t *testing.T) {
        }
 
        cases := []struct {
-               orders []common.Order
+               orders []*common.Order
                want   []expectedData
        }{
                {
-                       orders: []common.Order{
-                               common.Order{
+                       orders: []*common.Order{
+                               &common.Order{
                                        FromAssetID: &bc.AssetID{V0: 1},
                                        ToAssetID:   &bc.AssetID{V0: 0},
                                        Rate:        1.00090,
@@ -78,7 +246,7 @@ func TestSortOrderKey(t *testing.T) {
                                                ControlProgram: []byte("aa"),
                                        },
                                },
-                               common.Order{
+                               &common.Order{
                                        FromAssetID: &bc.AssetID{V0: 1},
                                        ToAssetID:   &bc.AssetID{V0: 0},
                                        Rate:        0.00090,
@@ -89,7 +257,7 @@ func TestSortOrderKey(t *testing.T) {
                                                ControlProgram: []byte("aa"),
                                        },
                                },
-                               common.Order{
+                               &common.Order{
                                        FromAssetID: &bc.AssetID{V0: 1},
                                        ToAssetID:   &bc.AssetID{V0: 0},
                                        Rate:        0.00097,
@@ -100,7 +268,7 @@ func TestSortOrderKey(t *testing.T) {
                                                ControlProgram: []byte("aa"),
                                        },
                                },
-                               common.Order{
+                               &common.Order{
                                        FromAssetID: &bc.AssetID{V0: 1},
                                        ToAssetID:   &bc.AssetID{V0: 0},
                                        Rate:        0.00098,
@@ -111,7 +279,7 @@ func TestSortOrderKey(t *testing.T) {
                                                ControlProgram: []byte("aa"),
                                        },
                                },
-                               common.Order{
+                               &common.Order{
                                        FromAssetID: &bc.AssetID{V0: 1},
                                        ToAssetID:   &bc.AssetID{V0: 0},
                                        Rate:        0.00098,
@@ -122,7 +290,7 @@ func TestSortOrderKey(t *testing.T) {
                                                ControlProgram: []byte("aa"),
                                        },
                                },
-                               common.Order{
+                               &common.Order{
                                        FromAssetID: &bc.AssetID{V0: 1},
                                        ToAssetID:   &bc.AssetID{V0: 0},
                                        Rate:        0.00098,
@@ -133,7 +301,7 @@ func TestSortOrderKey(t *testing.T) {
                                                ControlProgram: []byte("aa"),
                                        },
                                },
-                               common.Order{
+                               &common.Order{
                                        FromAssetID: &bc.AssetID{V0: 1},
                                        ToAssetID:   &bc.AssetID{V0: 0},
                                        Rate:        0.00098,
@@ -144,7 +312,7 @@ func TestSortOrderKey(t *testing.T) {
                                                ControlProgram: []byte("aa"),
                                        },
                                },
-                               common.Order{
+                               &common.Order{
                                        FromAssetID: &bc.AssetID{V0: 1},
                                        ToAssetID:   &bc.AssetID{V0: 0},
                                        Rate:        0.00098,
@@ -155,7 +323,7 @@ func TestSortOrderKey(t *testing.T) {
                                                ControlProgram: []byte("aa"),
                                        },
                                },
-                               common.Order{
+                               &common.Order{
                                        FromAssetID: &bc.AssetID{V0: 1},
                                        ToAssetID:   &bc.AssetID{V0: 0},
                                        Rate:        0.00099,
@@ -166,7 +334,7 @@ func TestSortOrderKey(t *testing.T) {
                                                ControlProgram: []byte("aa"),
                                        },
                                },
-                               common.Order{
+                               &common.Order{
                                        FromAssetID: &bc.AssetID{V0: 1},
                                        ToAssetID:   &bc.AssetID{V0: 0},
                                        Rate:        0.00096,
@@ -177,7 +345,7 @@ func TestSortOrderKey(t *testing.T) {
                                                ControlProgram: []byte("aa"),
                                        },
                                },
-                               common.Order{
+                               &common.Order{
                                        FromAssetID: &bc.AssetID{V0: 1},
                                        ToAssetID:   &bc.AssetID{V0: 0},
                                        Rate:        0.00095,
@@ -188,7 +356,7 @@ func TestSortOrderKey(t *testing.T) {
                                                ControlProgram: []byte("aa"),
                                        },
                                },
-                               common.Order{
+                               &common.Order{
                                        FromAssetID: &bc.AssetID{V0: 1},
                                        ToAssetID:   &bc.AssetID{V0: 0},
                                        Rate:        0.00091,
@@ -199,7 +367,7 @@ func TestSortOrderKey(t *testing.T) {
                                                ControlProgram: []byte("aa"),
                                        },
                                },
-                               common.Order{
+                               &common.Order{
                                        FromAssetID: &bc.AssetID{V0: 1},
                                        ToAssetID:   &bc.AssetID{V0: 0},
                                        Rate:        0.00092,
@@ -210,7 +378,7 @@ func TestSortOrderKey(t *testing.T) {
                                                ControlProgram: []byte("aa"),
                                        },
                                },
-                               common.Order{
+                               &common.Order{
                                        FromAssetID: &bc.AssetID{V0: 1},
                                        ToAssetID:   &bc.AssetID{V0: 0},
                                        Rate:        0.00093,
@@ -221,7 +389,7 @@ func TestSortOrderKey(t *testing.T) {
                                                ControlProgram: []byte("aa"),
                                        },
                                },
-                               common.Order{
+                               &common.Order{
                                        FromAssetID: &bc.AssetID{V0: 1},
                                        ToAssetID:   &bc.AssetID{V0: 0},
                                        Rate:        0.00094,
@@ -232,7 +400,7 @@ func TestSortOrderKey(t *testing.T) {
                                                ControlProgram: []byte("aa"),
                                        },
                                },
-                               common.Order{
+                               &common.Order{
                                        FromAssetID: &bc.AssetID{V0: 1},
                                        ToAssetID:   &bc.AssetID{V0: 0},
                                        Rate:        0.00077,
@@ -243,7 +411,7 @@ func TestSortOrderKey(t *testing.T) {
                                                ControlProgram: []byte("aa"),
                                        },
                                },
-                               common.Order{
+                               &common.Order{
                                        FromAssetID: &bc.AssetID{V0: 1},
                                        ToAssetID:   &bc.AssetID{V0: 0},
                                        Rate:        0.00088,
@@ -254,7 +422,7 @@ func TestSortOrderKey(t *testing.T) {
                                                ControlProgram: []byte("aa"),
                                        },
                                },
-                               common.Order{
+                               &common.Order{
                                        FromAssetID: &bc.AssetID{V0: 1},
                                        ToAssetID:   &bc.AssetID{V0: 0},
                                        Rate:        999999.9521,
@@ -265,7 +433,7 @@ func TestSortOrderKey(t *testing.T) {
                                                ControlProgram: []byte("aa"),
                                        },
                                },
-                               common.Order{
+                               &common.Order{
                                        FromAssetID: &bc.AssetID{V0: 1},
                                        ToAssetID:   &bc.AssetID{V0: 0},
                                        Rate:        888888.7954,
@@ -407,1594 +575,209 @@ func TestMovStore(t *testing.T) {
                {
                        desc: "add order",
                        addOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 22},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00097,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 23},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 13},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         10,
-                                               SourcePos:      1,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
+                               mockOrders[0],
+                               mockOrders[1],
+                               mockOrders[2],
+                               mockOrders[3],
+                               mockOrders[4],
+                               mockOrders[5],
+                               mockOrders[6],
+                               mockOrders[7],
                        },
                        blockHeader: &types.BlockHeader{Height: 1, PreviousBlockHash: bc.Hash{V0: 524821139490765641, V1: 2484214155808702787, V2: 9108473449351508820, V3: 7972721253564512122}},
                        wantOrders: []*common.Order{
-                               &common.Order{
+                               mockOrders[1],
+                               mockOrders[7],
+                               mockOrders[6],
+                               mockOrders[2],
+                               mockOrders[3],
+                               mockOrders[4],
+                               mockOrders[5],
+                               mockOrders[0],
+                       },
+                       wantTradePairs: []*common.TradePair{
+                               &common.TradePair{FromAssetID: assetID1, ToAssetID: assetID2, Count: 8},
+                       },
+                       wantDBState: &common.MovDatabaseState{Height: 1, Hash: &bc.Hash{V0: 14213576368347360351, V1: 16287398171800437029, V2: 9513543230620030445, V3: 8534035697182508177}},
+               },
+               {
+                       desc: "del some order",
+                       beforeOrders: []*common.Order{
+                               mockOrders[0],
+                               mockOrders[1],
+                               mockOrders[2],
+                               mockOrders[3],
+                               mockOrders[4],
+                               mockOrders[5],
+                               mockOrders[6],
+                               mockOrders[7],
+                       },
+                       beforeTradePairs: []*common.TradePair{
+                               &common.TradePair{
                                        FromAssetID: assetID1,
                                        ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 22},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
+                                       Count:       8,
                                },
-                               &common.Order{
+                       },
+                       beforeDBStatus: &common.MovDatabaseState{Height: 1, Hash: &bc.Hash{V0: 14213576368347360351, V1: 16287398171800437029, V2: 9513543230620030445, V3: 8534035697182508177}},
+                       delOrders: []*common.Order{
+                               mockOrders[0],
+                               mockOrders[1],
+                               mockOrders[2],
+                       },
+                       blockHeader: &types.BlockHeader{Height: 2, PreviousBlockHash: bc.Hash{V0: 14213576368347360351, V1: 16287398171800437029, V2: 9513543230620030445, V3: 8534035697182508177}},
+                       wantOrders: []*common.Order{
+                               mockOrders[7],
+                               mockOrders[6],
+                               mockOrders[3],
+                               mockOrders[4],
+                               mockOrders[5],
+                       },
+                       wantTradePairs: []*common.TradePair{
+                               &common.TradePair{FromAssetID: assetID1, ToAssetID: assetID2, Count: 5},
+                       },
+                       wantDBState: &common.MovDatabaseState{Height: 2, Hash: &bc.Hash{V0: 3724755213446347384, V1: 158878632373345042, V2: 18283800951484248781, V3: 7520797730449067221}},
+               },
+               {
+                       desc: "del all order",
+                       beforeOrders: []*common.Order{
+                               mockOrders[0],
+                               mockOrders[1],
+                               mockOrders[2],
+                               mockOrders[3],
+                               mockOrders[4],
+                               mockOrders[5],
+                               mockOrders[6],
+                               mockOrders[7],
+                       },
+                       beforeTradePairs: []*common.TradePair{
+                               &common.TradePair{
                                        FromAssetID: assetID1,
                                        ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
+                                       Count:       8,
                                },
-                               &common.Order{
+                       },
+                       beforeDBStatus: &common.MovDatabaseState{Height: 1, Hash: &bc.Hash{V0: 14213576368347360351, V1: 16287398171800437029, V2: 9513543230620030445, V3: 8534035697182508177}},
+                       delOrders: []*common.Order{
+                               mockOrders[0],
+                               mockOrders[1],
+                               mockOrders[2],
+                               mockOrders[3],
+                               mockOrders[4],
+                               mockOrders[5],
+                               mockOrders[6],
+                               mockOrders[7],
+                       },
+                       blockHeader:    &types.BlockHeader{Height: 2, PreviousBlockHash: bc.Hash{V0: 14213576368347360351, V1: 16287398171800437029, V2: 9513543230620030445, V3: 8534035697182508177}},
+                       wantOrders:     []*common.Order{},
+                       wantTradePairs: []*common.TradePair{},
+                       wantDBState:    &common.MovDatabaseState{Height: 2, Hash: &bc.Hash{V0: 3724755213446347384, V1: 158878632373345042, V2: 18283800951484248781, V3: 7520797730449067221}},
+               },
+               {
+                       desc: "Add and delete the same trade pair", //Add and delete different transaction pairs
+                       beforeOrders: []*common.Order{
+                               mockOrders[0],
+                               mockOrders[1],
+                               mockOrders[2],
+                               mockOrders[3],
+                               mockOrders[4],
+                               mockOrders[5],
+                               mockOrders[6],
+                               mockOrders[7],
+                       },
+                       beforeTradePairs: []*common.TradePair{
+                               &common.TradePair{
                                        FromAssetID: assetID1,
                                        ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
+                                       Count:       8,
                                },
-                               &common.Order{
+                       },
+                       beforeDBStatus: &common.MovDatabaseState{Height: 1, Hash: &bc.Hash{V0: 14213576368347360351, V1: 16287398171800437029, V2: 9513543230620030445, V3: 8534035697182508177}},
+                       addOrders: []*common.Order{
+                               mockOrders[8],
+                               mockOrders[9],
+                       },
+                       delOrders: []*common.Order{
+                               mockOrders[0],
+                               mockOrders[1],
+                               mockOrders[2],
+                               mockOrders[3],
+                               mockOrders[4],
+                               mockOrders[5],
+                               mockOrders[6],
+                               mockOrders[7],
+                       },
+                       blockHeader: &types.BlockHeader{Height: 2, PreviousBlockHash: bc.Hash{V0: 14213576368347360351, V1: 16287398171800437029, V2: 9513543230620030445, V3: 8534035697182508177}},
+                       wantOrders: []*common.Order{
+                               mockOrders[9],
+                               mockOrders[8],
+                       },
+                       wantTradePairs: []*common.TradePair{
+                               &common.TradePair{FromAssetID: assetID1, ToAssetID: assetID2, Count: 2},
+                       },
+                       wantDBState: &common.MovDatabaseState{Height: 2, Hash: &bc.Hash{V0: 3724755213446347384, V1: 158878632373345042, V2: 18283800951484248781, V3: 7520797730449067221}},
+               },
+               {
+                       desc: "Add and delete different transaction pairs",
+                       beforeOrders: []*common.Order{
+                               mockOrders[0],
+                               mockOrders[1],
+                               mockOrders[2],
+                               mockOrders[3],
+                               mockOrders[4],
+                               mockOrders[5],
+                               mockOrders[6],
+                               mockOrders[7],
+                               mockOrders[10],
+                               mockOrders[11],
+                       },
+                       beforeTradePairs: []*common.TradePair{
+                               &common.TradePair{
                                        FromAssetID: assetID1,
                                        ToAssetID:   assetID2,
-                                       Rate:        0.00097,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 23},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
+                                       Count:       8,
                                },
-                               &common.Order{
-                                       FromAssetID: assetID1,
+                               &common.TradePair{
+                                       FromAssetID: assetID3,
                                        ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 13},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
+                                       Count:       1,
                                },
-                               &common.Order{
-                                       FromAssetID: assetID1,
+                               &common.TradePair{
+                                       FromAssetID: assetID4,
                                        ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         10,
-                                               SourcePos:      1,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                       },
-                       wantTradePairs: []*common.TradePair{
-                               &common.TradePair{FromAssetID: assetID1, ToAssetID: assetID2, Count: 8},
-                       },
-                       wantDBState: &common.MovDatabaseState{Height: 1, Hash: &bc.Hash{V0: 14213576368347360351, V1: 16287398171800437029, V2: 9513543230620030445, V3: 8534035697182508177}},
-               },
-               {
-                       desc: "del some order",
-                       beforeOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 22},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00097,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 23},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 13},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         10,
-                                               SourcePos:      1,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                       },
-                       beforeTradePairs: []*common.TradePair{
-                               &common.TradePair{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Count:       8,
-                               },
-                       },
-                       beforeDBStatus: &common.MovDatabaseState{Height: 1, Hash: &bc.Hash{V0: 14213576368347360351, V1: 16287398171800437029, V2: 9513543230620030445, V3: 8534035697182508177}},
-                       delOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 22},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00097,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 23},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                       },
-                       blockHeader: &types.BlockHeader{Height: 2, PreviousBlockHash: bc.Hash{V0: 14213576368347360351, V1: 16287398171800437029, V2: 9513543230620030445, V3: 8534035697182508177}},
-                       wantOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 13},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         10,
-                                               SourcePos:      1,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                       },
-                       wantTradePairs: []*common.TradePair{
-                               &common.TradePair{FromAssetID: assetID1, ToAssetID: assetID2, Count: 5},
-                       },
-                       wantDBState: &common.MovDatabaseState{Height: 2, Hash: &bc.Hash{V0: 3724755213446347384, V1: 158878632373345042, V2: 18283800951484248781, V3: 7520797730449067221}},
-               },
-               {
-                       desc: "del all order",
-                       beforeOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 22},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00097,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 23},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 13},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         10,
-                                               SourcePos:      1,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                       },
-                       beforeTradePairs: []*common.TradePair{
-                               &common.TradePair{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Count:       8,
-                               },
-                       },
-                       beforeDBStatus: &common.MovDatabaseState{Height: 1, Hash: &bc.Hash{V0: 14213576368347360351, V1: 16287398171800437029, V2: 9513543230620030445, V3: 8534035697182508177}},
-                       delOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 22},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00097,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 23},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 13},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         10,
-                                               SourcePos:      1,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                       },
-                       blockHeader:    &types.BlockHeader{Height: 2, PreviousBlockHash: bc.Hash{V0: 14213576368347360351, V1: 16287398171800437029, V2: 9513543230620030445, V3: 8534035697182508177}},
-                       wantOrders:     []*common.Order{},
-                       wantTradePairs: []*common.TradePair{},
-                       wantDBState:    &common.MovDatabaseState{Height: 2, Hash: &bc.Hash{V0: 3724755213446347384, V1: 158878632373345042, V2: 18283800951484248781, V3: 7520797730449067221}},
-               },
-               {
-                       desc: "Add and delete the same trade pair", //Add and delete different transaction pairs
-                       beforeOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 22},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00097,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 23},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 13},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         10,
-                                               SourcePos:      1,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                       },
-                       beforeTradePairs: []*common.TradePair{
-                               &common.TradePair{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Count:       8,
-                               },
-                       },
-                       beforeDBStatus: &common.MovDatabaseState{Height: 1, Hash: &bc.Hash{V0: 14213576368347360351, V1: 16287398171800437029, V2: 9513543230620030445, V3: 8534035697182508177}},
-                       addOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 1},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 2},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                       },
-                       delOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 22},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00097,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 23},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 13},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         10,
-                                               SourcePos:      1,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                       },
-                       blockHeader: &types.BlockHeader{Height: 2, PreviousBlockHash: bc.Hash{V0: 14213576368347360351, V1: 16287398171800437029, V2: 9513543230620030445, V3: 8534035697182508177}},
-                       wantOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 2},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 1},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                       },
-                       wantTradePairs: []*common.TradePair{
-                               &common.TradePair{FromAssetID: assetID1, ToAssetID: assetID2, Count: 2},
-                       },
-                       wantDBState: &common.MovDatabaseState{Height: 2, Hash: &bc.Hash{V0: 3724755213446347384, V1: 158878632373345042, V2: 18283800951484248781, V3: 7520797730449067221}},
-               },
-               {
-                       desc: "Add and delete different transaction pairs",
-                       beforeOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 22},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00097,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 23},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 13},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         10,
-                                               SourcePos:      1,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID3,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 33},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID4,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 34},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                       },
-                       beforeTradePairs: []*common.TradePair{
-                               &common.TradePair{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Count:       8,
-                               },
-                               &common.TradePair{
-                                       FromAssetID: assetID3,
-                                       ToAssetID:   assetID2,
-                                       Count:       1,
-                               },
-                               &common.TradePair{
-                                       FromAssetID: assetID4,
-                                       ToAssetID:   assetID2,
-                                       Count:       1,
-                               },
-                       },
-                       beforeDBStatus: &common.MovDatabaseState{Height: 1, Hash: &bc.Hash{V0: 14213576368347360351, V1: 16287398171800437029, V2: 9513543230620030445, V3: 8534035697182508177}},
-                       addOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID4,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 36},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID5,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 37},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID6,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 38},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                       },
-                       delOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 22},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00097,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 23},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 13},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         10,
-                                               SourcePos:      1,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID3,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 33},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                       },
-                       blockHeader: &types.BlockHeader{Height: 2, PreviousBlockHash: bc.Hash{V0: 14213576368347360351, V1: 16287398171800437029, V2: 9513543230620030445, V3: 8534035697182508177}},
-                       wantOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID4,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 34},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID4,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 36},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID5,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 37},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID6,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 38},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                       },
-                       wantTradePairs: []*common.TradePair{
-                               &common.TradePair{FromAssetID: assetID4, ToAssetID: assetID2, Count: 2},
-                               &common.TradePair{FromAssetID: assetID5, ToAssetID: assetID2, Count: 1},
-                               &common.TradePair{FromAssetID: assetID6, ToAssetID: assetID2, Count: 1},
-                       },
-                       wantDBState: &common.MovDatabaseState{Height: 2, Hash: &bc.Hash{V0: 3724755213446347384, V1: 158878632373345042, V2: 18283800951484248781, V3: 7520797730449067221}},
-               },
-       }
-
-       initBlockHeader := &types.BlockHeader{
-               Height:  0,
-               Version: 1,
-       }
-
-       height := initBlockHeader.Height
-       hash := initBlockHeader.Hash()
-
-       defer os.RemoveAll("temp")
-       for i, c := range cases {
-               testDB := dbm.NewDB("testdb", "leveldb", "temp")
-               movStore := NewLevelDBMovStore(testDB)
-               if err := movStore.InitDBState(height, &hash); err != nil {
-                       t.Fatalf("case %d: InitDBState error %v.", i, err)
-               }
-
-               batch := movStore.db.NewBatch()
-               tradePairsCnt := make(map[string]*common.TradePair)
-               movStore.addOrders(batch, c.beforeOrders, tradePairsCnt)
-               if len(c.beforeOrders) > 0 {
-                       tradePairsCnt = make(map[string]*common.TradePair)
-                       for _, tradePair := range c.beforeTradePairs {
-                               tradePairsCnt[tradePair.Key()] = tradePair
-                       }
-                       movStore.updateTradePairs(batch, tradePairsCnt)
-                       movStore.saveMovDatabaseState(batch, c.beforeDBStatus)
-               }
-               batch.Write()
-
-               if err := movStore.ProcessOrders(c.addOrders, c.delOrders, c.blockHeader); err != nil {
-                       t.Fatalf("case %d: ProcessOrders error %v.", i, err)
-               }
-
-               var gotOrders []*common.Order
-
-               tmp, err := movStore.ListOrders(&common.Order{FromAssetID: assetID1, ToAssetID: assetID2, Rate: 0})
-               if err != nil {
-                       t.Fatalf("case %d: ListOrders(assetID1 and assetID2) error %v.", i, err)
-               }
-
-               gotOrders = append(gotOrders, tmp...)
-
-               tmp, err = movStore.ListOrders(&common.Order{FromAssetID: assetID3, ToAssetID: assetID2, Rate: 0})
-               if err != nil {
-                       t.Fatalf("case %d: ListOrders(assetID3 and assetID2)  error %v.", i, err)
-               }
-
-               gotOrders = append(gotOrders, tmp...)
-
-               tmp, err = movStore.ListOrders(&common.Order{FromAssetID: assetID4, ToAssetID: assetID2, Rate: 0})
-               if err != nil {
-                       t.Fatalf("case %d: ListOrders(assetID4 and assetID2)  error %v.", i, err)
-               }
-
-               gotOrders = append(gotOrders, tmp...)
-
-               tmp, err = movStore.ListOrders(&common.Order{FromAssetID: assetID5, ToAssetID: assetID2, Rate: 0})
-               if err != nil {
-                       t.Fatalf("case %d: ListOrders(assetID5 and assetID2)  error %v.", i, err)
-               }
-
-               gotOrders = append(gotOrders, tmp...)
-
-               tmp, err = movStore.ListOrders(&common.Order{FromAssetID: assetID6, ToAssetID: assetID2, Rate: 0})
-               if err != nil {
-                       t.Fatalf("case %d: ListOrders(assetID6 and assetID2)  error %v.", i, err)
-               }
-
-               gotOrders = append(gotOrders, tmp...)
-
-               if !testutil.DeepEqual(gotOrders, c.wantOrders) {
-                       t.Fatalf("case %d: got orders , gotOrders: %v, wantOrders: %v.", i, gotOrders, c.wantOrders)
-               }
-
-               gotTradePairs, err := movStore.ListTradePairsWithStart(nil, nil)
-               if err != nil {
-                       t.Fatalf("case %d: ListTradePairsWithStart error %v.", i, err)
-               }
-
-               if !testutil.DeepEqual(gotTradePairs, c.wantTradePairs) {
-                       t.Fatalf("case %d: got tradePairs, gotTradePairs: %v, wantTradePairs: %v.", i, gotTradePairs, c.wantTradePairs)
-               }
-
-               gotDBState, err := movStore.GetMovDatabaseState()
-               if err != nil {
-                       t.Fatalf("case %d: GetMovDatabaseState error %v.", i, err)
-               }
-
-               if !testutil.DeepEqual(gotDBState, c.wantDBState) {
-                       t.Fatalf("case %d: got tradePairs, gotDBState: %v, wantDBStatus: %v.", i, gotDBState, c.wantDBState)
-               }
-
-               testDB.Close()
-               os.RemoveAll("temp")
-       }
-}
-
-func TestListOrders(t *testing.T) {
-       cases := []struct {
-               desc        string
-               storeOrders []*common.Order
-               query       *common.Order
-               wantOrders  []*common.Order
-       }{
-               {
-                       desc:       "empty",
-                       query:      &common.Order{FromAssetID: assetID1, ToAssetID: assetID2},
-                       wantOrders: []*common.Order{},
-               },
-               {
-                       desc: "query from first",
-                       storeOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 22},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00097,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 23},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 13},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         10,
-                                               SourcePos:      1,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID2,
-                                       ToAssetID:   assetID4,
-                                       Rate:        0.00075,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                       },
-                       query: &common.Order{FromAssetID: assetID1, ToAssetID: assetID2},
-                       wantOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 22},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00097,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 23},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 13},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         10,
-                                               SourcePos:      1,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
+                                       Count:       1,
                                },
                        },
-               },
-               {
-                       desc: "query from middle",
-                       storeOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 22},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00097,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 23},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 13},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         10,
-                                               SourcePos:      1,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
+                       beforeDBStatus: &common.MovDatabaseState{Height: 1, Hash: &bc.Hash{V0: 14213576368347360351, V1: 16287398171800437029, V2: 9513543230620030445, V3: 8534035697182508177}},
+                       addOrders: []*common.Order{
+                               mockOrders[12],
+                               mockOrders[13],
+                               mockOrders[14],
                        },
-                       query: &common.Order{
-                               FromAssetID: assetID1,
-                               ToAssetID:   assetID2,
-                               Rate:        0.00098,
-                               Utxo: &common.MovUtxo{
-                                       SourceID:       &bc.Hash{V0: 13},
-                                       Amount:         1,
-                                       SourcePos:      0,
-                                       ControlProgram: []byte("aa"),
-                               },
+                       delOrders: []*common.Order{
+                               mockOrders[0],
+                               mockOrders[1],
+                               mockOrders[2],
+                               mockOrders[3],
+                               mockOrders[4],
+                               mockOrders[5],
+                               mockOrders[6],
+                               mockOrders[7],
+                               mockOrders[10],
                        },
+                       blockHeader: &types.BlockHeader{Height: 2, PreviousBlockHash: bc.Hash{V0: 14213576368347360351, V1: 16287398171800437029, V2: 9513543230620030445, V3: 8534035697182508177}},
                        wantOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         10,
-                                               SourcePos:      1,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
+                               mockOrders[11],
+                               mockOrders[12],
+                               mockOrders[13],
+                               mockOrders[14],
+                       },
+                       wantTradePairs: []*common.TradePair{
+                               &common.TradePair{FromAssetID: assetID4, ToAssetID: assetID2, Count: 2},
+                               &common.TradePair{FromAssetID: assetID5, ToAssetID: assetID2, Count: 1},
+                               &common.TradePair{FromAssetID: assetID6, ToAssetID: assetID2, Count: 1},
                        },
+                       wantDBState: &common.MovDatabaseState{Height: 2, Hash: &bc.Hash{V0: 3724755213446347384, V1: 158878632373345042, V2: 18283800951484248781, V3: 7520797730449067221}},
                },
        }
 
@@ -2003,410 +786,245 @@ func TestListOrders(t *testing.T) {
                Version: 1,
        }
 
-       height := initBlockHeader.Height
-       hash := initBlockHeader.Hash()
+       height := initBlockHeader.Height
+       hash := initBlockHeader.Hash()
+
+       defer os.RemoveAll("temp")
+       for i, c := range cases {
+               testDB := dbm.NewDB("testdb", "leveldb", "temp")
+               movStore := NewLevelDBMovStore(testDB)
+               if err := movStore.InitDBState(height, &hash); err != nil {
+                       t.Fatalf("case %d: InitDBState error %v.", i, err)
+               }
+
+               batch := movStore.db.NewBatch()
+               tradePairsCnt := make(map[string]*common.TradePair)
+               movStore.addOrders(batch, c.beforeOrders, tradePairsCnt)
+               if len(c.beforeOrders) > 0 {
+                       tradePairsCnt = make(map[string]*common.TradePair)
+                       for _, tradePair := range c.beforeTradePairs {
+                               tradePairsCnt[tradePair.Key()] = tradePair
+                       }
+                       movStore.updateTradePairs(batch, tradePairsCnt)
+                       movStore.saveMovDatabaseState(batch, c.beforeDBStatus)
+               }
+               batch.Write()
+
+               if err := movStore.ProcessOrders(c.addOrders, c.delOrders, c.blockHeader); err != nil {
+                       t.Fatalf("case %d: ProcessOrders error %v.", i, err)
+               }
+
+               var gotOrders []*common.Order
+
+               tmp, err := movStore.ListOrders(&common.Order{FromAssetID: assetID1, ToAssetID: assetID2, Rate: 0})
+               if err != nil {
+                       t.Fatalf("case %d: ListOrders(assetID1 and assetID2) error %v.", i, err)
+               }
+
+               gotOrders = append(gotOrders, tmp...)
+
+               tmp, err = movStore.ListOrders(&common.Order{FromAssetID: assetID3, ToAssetID: assetID2, Rate: 0})
+               if err != nil {
+                       t.Fatalf("case %d: ListOrders(assetID3 and assetID2)  error %v.", i, err)
+               }
+
+               gotOrders = append(gotOrders, tmp...)
+
+               tmp, err = movStore.ListOrders(&common.Order{FromAssetID: assetID4, ToAssetID: assetID2, Rate: 0})
+               if err != nil {
+                       t.Fatalf("case %d: ListOrders(assetID4 and assetID2)  error %v.", i, err)
+               }
+
+               gotOrders = append(gotOrders, tmp...)
 
-       defer os.RemoveAll("temp")
-       for i, c := range cases {
-               testDB := dbm.NewDB("testdb", "leveldb", "temp")
-               movStore := NewLevelDBMovStore(testDB)
-               if err := movStore.InitDBState(height, &hash); err != nil {
-                       t.Fatalf("case %d: InitDBState error %v.", i, err)
+               tmp, err = movStore.ListOrders(&common.Order{FromAssetID: assetID5, ToAssetID: assetID2, Rate: 0})
+               if err != nil {
+                       t.Fatalf("case %d: ListOrders(assetID5 and assetID2)  error %v.", i, err)
                }
 
-               batch := movStore.db.NewBatch()
-               tradePairsCnt := make(map[string]*common.TradePair)
-               movStore.addOrders(batch, c.storeOrders, tradePairsCnt)
-               movStore.updateTradePairs(batch, tradePairsCnt)
-               batch.Write()
+               gotOrders = append(gotOrders, tmp...)
 
-               gotOrders, err := movStore.ListOrders(c.query)
+               tmp, err = movStore.ListOrders(&common.Order{FromAssetID: assetID6, ToAssetID: assetID2, Rate: 0})
                if err != nil {
-                       t.Fatalf("case %d: ListOrders error %v.", i, err)
+                       t.Fatalf("case %d: ListOrders(assetID6 and assetID2)  error %v.", i, err)
                }
 
+               gotOrders = append(gotOrders, tmp...)
+
                if !testutil.DeepEqual(gotOrders, c.wantOrders) {
                        t.Fatalf("case %d: got orders , gotOrders: %v, wantOrders: %v.", i, gotOrders, c.wantOrders)
                }
 
+               gotTradePairs, err := movStore.ListTradePairsWithStart(nil, nil)
+               if err != nil {
+                       t.Fatalf("case %d: ListTradePairsWithStart error %v.", i, err)
+               }
+
+               if !testutil.DeepEqual(gotTradePairs, c.wantTradePairs) {
+                       t.Fatalf("case %d: got tradePairs, gotTradePairs: %v, wantTradePairs: %v.", i, gotTradePairs, c.wantTradePairs)
+               }
+
+               gotDBState, err := movStore.GetMovDatabaseState()
+               if err != nil {
+                       t.Fatalf("case %d: GetMovDatabaseState error %v.", i, err)
+               }
+
+               if !testutil.DeepEqual(gotDBState, c.wantDBState) {
+                       t.Fatalf("case %d: got tradePairs, gotDBState: %v, wantDBStatus: %v.", i, gotDBState, c.wantDBState)
+               }
+
                testDB.Close()
                os.RemoveAll("temp")
        }
 }
 
-func TestAddOrders(t *testing.T) {
+func TestListOrders(t *testing.T) {
        cases := []struct {
-               desc         string
-               beforeOrders []*common.Order
-               addOrders    []*common.Order
-               wantOrders   []*common.Order
+               desc        string
+               storeOrders []*common.Order
+               query       *common.Order
+               wantOrders  []*common.Order
        }{
                {
-                       desc: "empty",
-                       addOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 22},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00097,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 23},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 13},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         10,
-                                               SourcePos:      1,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
+                       desc:       "empty",
+                       query:      &common.Order{FromAssetID: assetID1, ToAssetID: assetID2},
+                       wantOrders: []*common.Order{},
+               },
+               {
+                       desc: "query from first",
+                       storeOrders: []*common.Order{
+                               mockOrders[0],
+                               mockOrders[1],
+                               mockOrders[2],
+                               mockOrders[3],
+                               mockOrders[4],
+                               mockOrders[5],
+                               mockOrders[6],
+                               mockOrders[7],
+                               mockOrders[10],
                        },
+                       query: &common.Order{FromAssetID: assetID1, ToAssetID: assetID2},
                        wantOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 22},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00097,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 23},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 13},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         10,
-                                               SourcePos:      1,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
+                               mockOrders[1],
+                               mockOrders[7],
+                               mockOrders[6],
+                               mockOrders[2],
+                               mockOrders[3],
+                               mockOrders[4],
+                               mockOrders[5],
+                               mockOrders[0],
+                       },
+               },
+               {
+                       desc: "query from middle",
+                       storeOrders: []*common.Order{
+                               mockOrders[0],
+                               mockOrders[1],
+                               mockOrders[2],
+                               mockOrders[3],
+                               mockOrders[4],
+                               mockOrders[5],
+                               mockOrders[6],
+                               mockOrders[7],
+                       },
+                       query: mockOrders[3],
+                       wantOrders: []*common.Order{
+                               mockOrders[4],
+                               mockOrders[5],
+                               mockOrders[0],
+                       },
+               },
+       }
+
+       initBlockHeader := &types.BlockHeader{
+               Height:  0,
+               Version: 1,
+       }
+
+       height := initBlockHeader.Height
+       hash := initBlockHeader.Hash()
+
+       defer os.RemoveAll("temp")
+       for i, c := range cases {
+               testDB := dbm.NewDB("testdb", "leveldb", "temp")
+               movStore := NewLevelDBMovStore(testDB)
+               if err := movStore.InitDBState(height, &hash); err != nil {
+                       t.Fatalf("case %d: InitDBState error %v.", i, err)
+               }
+
+               batch := movStore.db.NewBatch()
+               tradePairsCnt := make(map[string]*common.TradePair)
+               movStore.addOrders(batch, c.storeOrders, tradePairsCnt)
+               movStore.updateTradePairs(batch, tradePairsCnt)
+               batch.Write()
+
+               gotOrders, err := movStore.ListOrders(c.query)
+               if err != nil {
+                       t.Fatalf("case %d: ListOrders error %v.", i, err)
+               }
+
+               if !testutil.DeepEqual(gotOrders, c.wantOrders) {
+                       t.Fatalf("case %d: got orders , gotOrders: %v, wantOrders: %v.", i, gotOrders, c.wantOrders)
+               }
+
+               testDB.Close()
+               os.RemoveAll("temp")
+       }
+}
+
+func TestAddOrders(t *testing.T) {
+       cases := []struct {
+               desc         string
+               beforeOrders []*common.Order
+               addOrders    []*common.Order
+               wantOrders   []*common.Order
+       }{
+               {
+                       desc: "empty",
+                       addOrders: []*common.Order{
+                               mockOrders[0],
+                               mockOrders[1],
+                               mockOrders[2],
+                               mockOrders[3],
+                               mockOrders[4],
+                               mockOrders[5],
+                               mockOrders[6],
+                               mockOrders[7],
+                       },
+                       wantOrders: []*common.Order{
+                               mockOrders[1],
+                               mockOrders[7],
+                               mockOrders[6],
+                               mockOrders[2],
+                               mockOrders[3],
+                               mockOrders[4],
+                               mockOrders[5],
+                               mockOrders[0],
                        },
                },
                {
                        desc: "Stored data already exists",
                        beforeOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 22},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00097,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 23},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 13},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
+                               mockOrders[0],
+                               mockOrders[1],
+                               mockOrders[2],
+                               mockOrders[3],
                        },
                        addOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         10,
-                                               SourcePos:      1,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
+                               mockOrders[4],
+                               mockOrders[5],
+                               mockOrders[6],
+                               mockOrders[7],
                        },
                        wantOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 22},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00097,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 23},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 13},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         10,
-                                               SourcePos:      1,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
+                               mockOrders[1],
+                               mockOrders[7],
+                               mockOrders[6],
+                               mockOrders[2],
+                               mockOrders[3],
+                               mockOrders[4],
+                               mockOrders[5],
+                               mockOrders[0],
                        },
                },
        }
@@ -2448,42 +1066,22 @@ func TestAddOrders(t *testing.T) {
 
                testDB.Close()
                os.RemoveAll("temp")
-       }
-}
-
-func TestDelOrders(t *testing.T) {
-       cases := []struct {
-               desc         string
-               beforeOrders []*common.Order
-               delOrders    []*common.Order
-               wantOrders   []*common.Order
-               err          error
-       }{
-               {
-                       desc: "empty",
-                       delOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 22},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
+       }
+}
+
+func TestDelOrders(t *testing.T) {
+       cases := []struct {
+               desc         string
+               beforeOrders []*common.Order
+               delOrders    []*common.Order
+               wantOrders   []*common.Order
+               err          error
+       }{
+               {
+                       desc: "empty",
+                       delOrders: []*common.Order{
+                               mockOrders[0],
+                               mockOrders[1],
                        },
                        wantOrders: []*common.Order{},
                        err:        errors.New("don't find trade pair"),
@@ -2491,260 +1089,40 @@ func TestDelOrders(t *testing.T) {
                {
                        desc: "Delete existing data",
                        beforeOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 22},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00097,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 23},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 13},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         10,
-                                               SourcePos:      1,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
+                               mockOrders[1],
+                               mockOrders[7],
+                               mockOrders[6],
+                               mockOrders[2],
+                               mockOrders[3],
+                               mockOrders[4],
+                               mockOrders[5],
+                               mockOrders[0],
                        },
                        delOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         10,
-                                               SourcePos:      1,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
+                               mockOrders[4],
+                               mockOrders[5],
+                               mockOrders[6],
+                               mockOrders[7],
                        },
                        wantOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 22},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00097,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 23},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00098,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 13},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        1.00090,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 21},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
+                               mockOrders[1],
+                               mockOrders[2],
+                               mockOrders[3],
+                               mockOrders[0],
                        },
                        err: nil,
                },
                {
                        desc: "Delete all data",
                        beforeOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
+                               mockOrders[7],
+                               mockOrders[6],
+                               mockOrders[5],
                        },
                        delOrders: []*common.Order{
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00099,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 24},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00096,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 25},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
-                               &common.Order{
-                                       FromAssetID: assetID1,
-                                       ToAssetID:   assetID2,
-                                       Rate:        0.00095,
-                                       Utxo: &common.MovUtxo{
-                                               SourceID:       &bc.Hash{V0: 26},
-                                               Amount:         1,
-                                               SourcePos:      0,
-                                               ControlProgram: []byte("aa"),
-                                       },
-                               },
+                               mockOrders[5],
+                               mockOrders[6],
+                               mockOrders[7],
                        },
                        wantOrders: []*common.Order{},
                        err:        nil,