OSDN Git Service

versoin1.1.9 (#594)
[bytom/vapor.git] / protocol / asset_filter_test.go
1 package protocol
2
3 import (
4         "testing"
5
6         "github.com/bytom/vapor/protocol/bc"
7         "github.com/bytom/vapor/protocol/bc/types"
8         "github.com/bytom/vapor/testutil"
9 )
10
11 func TestIsDust(t *testing.T) {
12         assetFilter := NewAssetFilter("184e1cc4ee4845023888810a79eed7a42c02c544cf2c61ceac05e176d575bd46")
13         cases := []struct {
14                 tx         *types.Tx
15                 wantIsDust bool
16         }{
17                 {
18                         tx: types.NewTx(types.TxData{
19                                 Inputs: []*types.TxInput{
20                                         types.NewCrossChainInput(nil, bc.Hash{}, testutil.MustDecodeAsset("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), 1e8, 1, 1, []byte("{\n  \"decimals\": 8,\n  \"description\": \"Bytom Official Issue\",\n  \"name\": \"BTM\",\n  \"symbol\": \"BTM\"\n}"), []byte("assetbtm"))},
21                                 Outputs: []*types.TxOutput{
22                                         types.NewIntraChainOutput(testutil.MustDecodeAsset("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), 1e8, []byte{0x51}),
23                                 },
24                         }),
25                         wantIsDust: false,
26                 },
27                 {
28                         tx: types.NewTx(types.TxData{
29                                 Inputs: []*types.TxInput{
30                                         types.NewCrossChainInput(nil, bc.Hash{}, testutil.MustDecodeAsset("184e1cc4ee4845023888810a79eed7a42c02c544cf2c61ceac05e176d575bd46"), 1e8, 1, 1, []byte("{\n  \"decimals\": 6,\n  \"description\": {\n    \"issue_asset_action\": \"open_federation_cross_chain\"\n  },\n  \"name\": \"USDT\",\n  \"quorum\": \"3\",\n  \"reissue\": \"true\",\n  \"symbol\": \"USDT\"\n}"), []byte("assetusdt"))},
31                                 Outputs: []*types.TxOutput{
32                                         types.NewIntraChainOutput(testutil.MustDecodeAsset("184e1cc4ee4845023888810a79eed7a42c02c544cf2c61ceac05e176d575bd46"), 1e8, []byte{0x51}),
33                                 },
34                         }),
35                         wantIsDust: false,
36                 },
37                 {
38                         tx: types.NewTx(types.TxData{
39                                 Inputs: []*types.TxInput{
40                                         types.NewCrossChainInput(nil, bc.Hash{}, testutil.MustDecodeAsset("47fcd4d7c22d1d38931a6cd7767156babbd5f05bbbb3f7d3900635b56eb1b67e"), 1e8, 1, 1, []byte("{\n  \"decimals\": 8,\n  \"description\": {},\n  \"name\": \"SUP\",\n  \"quorum\": 1,\n  \"reissue\": \"false\",\n  \"symbol\": \"SUP\"\n}"), []byte("assetsup"))},
41                                 Outputs: []*types.TxOutput{
42                                         types.NewIntraChainOutput(testutil.MustDecodeAsset("47fcd4d7c22d1d38931a6cd7767156babbd5f05bbbb3f7d3900635b56eb1b67e"), 1e8, []byte{0x51}),
43                                 },
44                         }),
45                         wantIsDust: false,
46                 },
47                 {
48                         tx: types.NewTx(types.TxData{
49                                 Inputs: []*types.TxInput{
50                                         types.NewCrossChainInput(nil, bc.Hash{}, testutil.MustDecodeAsset("c4644dd6643475d57ed624f63129ab815f282b61f4bb07646d73423a6e1a1563"), 1e8, 1, 1, []byte("{\n\"decimals\":6,\n\"description\":{\n\"issue_asset_action\":\"open_federation_cross_chain\"\n},\n\"name\":\"USDC\",\n\"quorum\":\"3\",\n\"reissue\":\"true\",\n\"symbol\":\"USDC\"\n}"), []byte("assetusdc"))},
51                                 Outputs: []*types.TxOutput{
52                                         types.NewIntraChainOutput(testutil.MustDecodeAsset("c4644dd6643475d57ed624f63129ab815f282b61f4bb07646d73423a6e1a1563"), 1e8, []byte{0x51}),
53                                 },
54                         }),
55                         wantIsDust: true,
56                 },
57         }
58
59         for i, c := range cases {
60                 if gotIsDust := assetFilter.IsDust(c.tx); gotIsDust != c.wantIsDust {
61                         t.Errorf("case %d: fail on AssetFilter TestIsDust", i)
62                 }
63         }
64 }