|
| 1 | +package deals_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/filecoin-project/go-state-types/exitcode" |
| 8 | + "github.com/filecoin-project/go-state-types/manifest" |
| 9 | + filApiTypes "github.com/filecoin-project/lotus/api/types" |
| 10 | + filTypes "github.com/filecoin-project/lotus/chain/types" |
| 11 | + "github.com/filecoin-project/lotus/node/modules/dtypes" |
| 12 | + cid "github.com/ipfs/go-cid" |
| 13 | + "github.com/stretchr/testify/mock" |
| 14 | + "github.com/stretchr/testify/require" |
| 15 | + filMetrics "github.com/zondax/fil-parser/metrics" |
| 16 | + "github.com/zondax/fil-parser/parser" |
| 17 | + "github.com/zondax/fil-parser/parser/helper" |
| 18 | + "github.com/zondax/fil-parser/tools" |
| 19 | + "github.com/zondax/fil-parser/tools/deals" |
| 20 | + "github.com/zondax/fil-parser/tools/mocks" |
| 21 | + "github.com/zondax/fil-parser/types" |
| 22 | + "github.com/zondax/golem/pkg/logger" |
| 23 | + metrics2 "github.com/zondax/golem/pkg/metrics" |
| 24 | + rosettaFilecoinLib "github.com/zondax/rosetta-filecoin-lib" |
| 25 | +) |
| 26 | + |
| 27 | +var ( |
| 28 | + tipsetCid = "bafy2bzaceaacubfrkq2wng5vcm53r7u5v5pjjs72s6kgqbm44dyfyik4y2azc" |
| 29 | + txCid = "bafy2bzaceadjahvfnskpsz33ansyymo7uoqm7iyapx5cjpja3327pffvml7je" |
| 30 | + actorCidStr = "bafkqae3gnfwc6mjpon2g64tbm5sw2ylsnnsxi" |
| 31 | + txFrom = "f2ncucfhaemzclocsau6o4u5b5bigjvpii2ql4rhi" |
| 32 | + txTo = "f05" |
| 33 | + actorCid cid.Cid |
| 34 | +) |
| 35 | + |
| 36 | +func init() { |
| 37 | + var err error |
| 38 | + actorCid, err = cid.Parse(actorCidStr) |
| 39 | + if err != nil { |
| 40 | + panic(err) |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +func setupTest(_ *testing.T, network string) deals.EventGenerator { |
| 45 | + logger := logger.NewDevelopmentLogger() |
| 46 | + metrics := filMetrics.NewMetricsClient(metrics2.NewNoopMetrics()) |
| 47 | + |
| 48 | + node := &mocks.FullNode{} |
| 49 | + node.On("StateNetworkName", mock.Anything).Return(dtypes.NetworkName(network), nil) |
| 50 | + node.On("StateNetworkVersion", mock.Anything, mock.Anything).Return(filApiTypes.NetworkVersion(16), nil) |
| 51 | + node.On("StateActorCodeCIDs", mock.Anything, mock.Anything).Return(map[string]cid.Cid{ |
| 52 | + manifest.MarketKey: actorCid, |
| 53 | + }, nil) |
| 54 | + |
| 55 | + cache := &mocks.IActorsCache{} |
| 56 | + cache.On("StoreAddressInfo", mock.Anything).Return(nil) |
| 57 | + cache.On("GetActorCode", mock.Anything, mock.Anything, mock.Anything).Return(actorCidStr, nil) |
| 58 | + cache.On("GetActorNameFromAddress", mock.Anything, mock.Anything, mock.Anything).Return(manifest.MinerKey, nil) |
| 59 | + |
| 60 | + lib := rosettaFilecoinLib.NewRosettaConstructionFilecoin(node) |
| 61 | + helper := helper.NewHelper(lib, cache, node, logger, metrics) |
| 62 | + |
| 63 | + return deals.NewEventGenerator(helper, logger, metrics, network, parser.Config{}) |
| 64 | +} |
| 65 | + |
| 66 | +func TestParseVerifyDealsForActivation(t *testing.T) { |
| 67 | + eg := setupTest(t, "mainnet") |
| 68 | + |
| 69 | + tests := []struct { |
| 70 | + name string |
| 71 | + txType string |
| 72 | + txFrom string |
| 73 | + txTo string |
| 74 | + metadata string |
| 75 | + height uint64 |
| 76 | + }{ |
| 77 | + |
| 78 | + { |
| 79 | + name: "NV3", |
| 80 | + txType: parser.MethodVerifyDealsForActivation, |
| 81 | + txFrom: txFrom, |
| 82 | + txTo: txTo, |
| 83 | + metadata: `{"MethodNum":"5","Params":{"DealIDs":null,"SectorExpiry":1644975,"SectorStart":94001},"Return":{"DealWeight":"0","VerifiedDealWeight":"0"}}`, |
| 84 | + height: 94000, |
| 85 | + }, |
| 86 | + { |
| 87 | + name: "NV10", |
| 88 | + txType: parser.MethodVerifyDealsForActivation, |
| 89 | + txFrom: txFrom, |
| 90 | + txTo: txTo, |
| 91 | + metadata: `{"MethodNum":"5","Params":{"Sectors":[{"SectorExpiry":2097712,"DealIDs":[1596539]}]},"Return":{"Sectors":[{"DealSpace":34359738368,"DealWeight":"0","VerifiedDealWeight":"52446704644915200"}]}}`, |
| 92 | + height: 550350, |
| 93 | + }, |
| 94 | + { |
| 95 | + name: "NV15", |
| 96 | + txType: parser.MethodVerifyDealsForActivation, |
| 97 | + txFrom: txFrom, |
| 98 | + txTo: txTo, |
| 99 | + metadata: `{"MethodNum":"5","Params":{"Sectors":[{"SectorExpiry":3149856,"DealIDs":[4137277]}]},"Return":{"Sectors":[{"DealSpace":34359738368,"DealWeight":"0","VerifiedDealWeight":"52941484877414400"}]}}`, |
| 100 | + height: 1594681, |
| 101 | + }, |
| 102 | + { |
| 103 | + name: "NV17", |
| 104 | + txType: parser.MethodVerifyDealsForActivation, |
| 105 | + txFrom: txFrom, |
| 106 | + txTo: txTo, |
| 107 | + metadata: `{"MethodNum":"5","Params":{"Sectors":[{"SectorType":8,"SectorExpiry":3938176,"DealIDs":[17514444]}]},"Return":{"Sectors":[{"CommD":{"/":"baga6ea4seaqcvxnumewlmsy3dgd6fzqzkmx6gwg2hrlea3mfsgsp342hmqausea"}}]}}`, |
| 108 | + height: 2383682, |
| 109 | + }, |
| 110 | + { |
| 111 | + name: "NV18", |
| 112 | + txType: parser.MethodVerifyDealsForActivation, |
| 113 | + txFrom: txFrom, |
| 114 | + txTo: txTo, |
| 115 | + metadata: `{"MethodNum":"5","Params":{"Sectors":[{"SectorType":9,"SectorExpiry":3752099,"DealIDs":[28436872,28436293]}]},"Return":{"Sectors":[{"CommD":{"/":"baga6ea4seaqezng67jc7t2mowage34tt4emcd4w7d5jnpusv5obmpexsq335ihy"}}]}}`, |
| 116 | + height: 2683349, |
| 117 | + }, |
| 118 | + { |
| 119 | + name: "NV19", |
| 120 | + txType: parser.MethodVerifyDealsForActivation, |
| 121 | + txFrom: txFrom, |
| 122 | + txTo: txTo, |
| 123 | + metadata: `{"MethodNum":"5","Params":{"Sectors":[{"SectorType":8,"SectorExpiry":4364609,"DealIDs":[34223220]}]},"Return":{"Sectors":[{"CommD":{"/":"baga6ea4seaqbro6cy6d6hp7ywf3ktxt3hygi376cannpbint5sqeih6nintqioq"}}]}}`, |
| 124 | + height: 2809801, |
| 125 | + }, |
| 126 | + } |
| 127 | + |
| 128 | + for _, test := range tests { |
| 129 | + t.Run(test.name, func(t *testing.T) { |
| 130 | + _, err := eg.GenerateDealsEvents(context.Background(), []*types.Transaction{ |
| 131 | + { |
| 132 | + TxBasicBlockData: types.TxBasicBlockData{ |
| 133 | + BasicBlockData: types.BasicBlockData{ |
| 134 | + Height: test.height, |
| 135 | + }, |
| 136 | + }, |
| 137 | + TxCid: txCid, |
| 138 | + TxType: test.txType, |
| 139 | + TxFrom: test.txFrom, |
| 140 | + TxTo: test.txTo, |
| 141 | + TxMetadata: test.metadata, |
| 142 | + Status: tools.GetExitCodeStatus(exitcode.Ok), |
| 143 | + SubcallStatus: tools.GetExitCodeStatus(exitcode.Ok), |
| 144 | + }, |
| 145 | + }, tipsetCid, filTypes.EmptyTSK) |
| 146 | + require.NoError(t, err) |
| 147 | + |
| 148 | + }) |
| 149 | + } |
| 150 | +} |
0 commit comments