From 0a25d1a4fca84844b8636c6e81afece7a85d8386 Mon Sep 17 00:00:00 2001 From: JimboJ <40345116+jimjbrettj@users.noreply.github.com> Date: Fri, 21 Jan 2022 16:49:40 -0700 Subject: [PATCH] testing (core): move existing tests to integration tests, rewrite `message.go` unit tests (#2224) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(pkg/scale): return error if `Result` already has an assigned value (#2143) * fix: return error if result already has an assigned value * chore: include unit test * chore: fix typo `ErrResultAlreadySet` * chore: remove unneeded `require.Error` * chore: fix undeclared name * chore: remove packaged scope var to avoid problems with result type * chore: fix result.Set error at offchain test * migrate core tests to integration tests * remove test.log * upgrade integration tests to match dev * testing (dot/core): rewrite message.go unit tests (#2197) * chore(pkg/scale): return error if `Result` already has an assigned value (#2143) * fix: return error if result already has an assigned value * chore: include unit test * chore: fix typo `ErrResultAlreadySet` * chore: remove unneeded `require.Error` * chore: fix undeclared name * chore: remove packaged scope var to avoid problems with result type * chore: fix result.Set error at offchain test * test txt count and generate mocks with mockgen * WIP/hanldeTxnMsgTest * WIP/core message tests * wip/finish core message tests * wip/message test * fix reporting issue * test core messages * remove comments and lint * remove unused file * wip/cr feedback * use dummy error for tests * wip/finish cr feedback * wip/move message validation to a separate function * move txn validity check to new func * lint * fix variable naming to make less confusing * remove pointer from validateTxn helper params * refactor tests to define mocks in subtest * CR feedback * finish feedback for core tests * define runtime mocks in subtest * remane validTxn var Co-authored-by: Eclésio Junior * CR feedback * finish feedback * CR feedback Co-authored-by: Eclésio Junior --- dot/core/interface.go | 8 +- dot/core/messages.go | 100 ++- dot/core/messages_integration_test.go | 172 ++++ dot/core/messages_test.go | 476 +++++++--- dot/core/mock_core_test.go | 827 ++++++++++++++++++ ...ce_test.go => service_integration_test.go} | 3 + 6 files changed, 1397 insertions(+), 189 deletions(-) create mode 100644 dot/core/messages_integration_test.go create mode 100644 dot/core/mock_core_test.go rename dot/core/{service_test.go => service_integration_test.go} (99%) diff --git a/dot/core/interface.go b/dot/core/interface.go index 35b66cc36b..bf880579a9 100644 --- a/dot/core/interface.go +++ b/dot/core/interface.go @@ -18,7 +18,7 @@ import ( "github.com/ChainSafe/gossamer/lib/transaction" ) -//go:generate mockery --name BlockState --structname BlockState --case underscore --keeptree +//go:generate mockgen -destination=mock_core_test.go -package $GOPACKAGE . BlockState,StorageState,TransactionState,Network,EpochState,CodeSubstitutedState,DigestHandler // BlockState interface for block state methods type BlockState interface { @@ -47,8 +47,6 @@ type BlockState interface { StoreRuntime(common.Hash, runtime.Instance) } -//go:generate mockery --name StorageState --structname StorageState --case underscore --keeptree - // StorageState interface for storage state methods type StorageState interface { LoadCode(root *common.Hash) ([]byte, error) @@ -70,8 +68,6 @@ type TransactionState interface { PendingInPool() []*transaction.ValidTransaction } -//go:generate mockery --name Network --structname Network --case underscore --keeptree - // Network is the interface for the network service type Network interface { GossipMessage(network.NotificationsMessage) @@ -92,8 +88,6 @@ type CodeSubstitutedState interface { StoreCodeSubstitutedBlockHash(hash common.Hash) error } -//go:generate mockery --name DigestHandler --structname DigestHandler --case underscore --keeptree - // DigestHandler is the interface for the consensus digest handler type DigestHandler interface { HandleDigests(header *types.Header) diff --git a/dot/core/messages.go b/dot/core/messages.go index 53e9834cea..839e4df996 100644 --- a/dot/core/messages.go +++ b/dot/core/messages.go @@ -5,16 +5,53 @@ package core import ( "errors" - - "github.com/libp2p/go-libp2p-core/peer" + "fmt" "github.com/ChainSafe/gossamer/dot/network" "github.com/ChainSafe/gossamer/dot/peerset" "github.com/ChainSafe/gossamer/dot/types" "github.com/ChainSafe/gossamer/lib/runtime" "github.com/ChainSafe/gossamer/lib/transaction" + + "github.com/libp2p/go-libp2p-core/peer" ) +func (s *Service) validateTransaction(peerID peer.ID, head *types.Header, rt runtime.Instance, + tx types.Extrinsic) (validity *transaction.Validity, valid bool, err error) { + s.storageState.Lock() + + ts, err := s.storageState.TrieState(&head.StateRoot) + s.storageState.Unlock() + if err != nil { + return nil, false, fmt.Errorf("cannot get trie state from storage for root %s: %w", head.StateRoot, err) + } + + rt.SetContextStorage(ts) + + // validate each transaction + externalExt := types.Extrinsic(append([]byte{byte(types.TxnExternal)}, tx...)) + validity, err = rt.ValidateTransaction(externalExt) + if err != nil { + if errors.Is(err, runtime.ErrInvalidTransaction) { + s.net.ReportPeer(peerset.ReputationChange{ + Value: peerset.BadTransactionValue, + Reason: peerset.BadTransactionReason, + }, peerID) + } + + logger.Debugf("failed to validate transaction: %s", err) + return nil, false, nil + } + + vtx := transaction.NewValidTransaction(tx, validity) + + // push to the transaction queue of BABE session + hash := s.transactionState.AddToPool(vtx) + logger.Tracef("added transaction with hash %s to pool", hash) + + return validity, true, nil +} + // HandleTransactionMessage validates each transaction in the message and // adds valid transactions to the transaction queue of the BABE session // returns boolean for transaction propagation, true - transactions should be propagated @@ -41,56 +78,27 @@ func (s *Service) HandleTransactionMessage(peerID peer.ID, msg *network.Transact return false, err } + allTxsAreValid := true for _, tx := range txs { - err = func() error { - s.storageState.Lock() - defer s.storageState.Unlock() - - ts, err := s.storageState.TrieState(&head.StateRoot) - if err != nil { - return err - } - - rt.SetContextStorage(ts) - - // validate each transaction - externalExt := types.Extrinsic(append([]byte{byte(types.TxnExternal)}, tx...)) - val, err := rt.ValidateTransaction(externalExt) - if err != nil { - if errors.Is(err, runtime.ErrInvalidTransaction) { - s.net.ReportPeer(peerset.ReputationChange{ - Value: peerset.BadTransactionValue, - Reason: peerset.BadTransactionReason, - }, peerID) - } - logger.Debugf("failed to validate transaction: %s", err) - return nil - } - - // create new valid transaction - vtx := transaction.NewValidTransaction(tx, val) - - // push to the transaction queue of BABE session - hash := s.transactionState.AddToPool(vtx) - logger.Tracef("added transaction with hash %s to pool", hash) + validity, isValidTxn, err := s.validateTransaction(peerID, head, rt, tx) + if err != nil { + return false, fmt.Errorf("failed validating transaction for peerID %s: %w", peerID, err) + } + if !isValidTxn { + allTxsAreValid = false + } else if validity.Propagate { // find tx(s) that should propagate - if val.Propagate { - toPropagate = append(toPropagate, tx) - } - - return nil - }() - - if err != nil { - return false, err + toPropagate = append(toPropagate, tx) } } - s.net.ReportPeer(peerset.ReputationChange{ - Value: peerset.GoodTransactionValue, - Reason: peerset.GoodTransactionReason, - }, peerID) + if allTxsAreValid { + s.net.ReportPeer(peerset.ReputationChange{ + Value: peerset.GoodTransactionValue, + Reason: peerset.GoodTransactionReason, + }, peerID) + } msg.Extrinsics = toPropagate return len(msg.Extrinsics) > 0, nil diff --git a/dot/core/messages_integration_test.go b/dot/core/messages_integration_test.go new file mode 100644 index 0000000000..5fca745e56 --- /dev/null +++ b/dot/core/messages_integration_test.go @@ -0,0 +1,172 @@ +// Copyright 2021 ChainSafe Systems (ON) +// SPDX-License-Identifier: LGPL-3.0-only + +//go:build integration +// +build integration + +package core + +import ( + "math/big" + "testing" + "time" + + "github.com/centrifuge/go-substrate-rpc-client/v3/signature" + ctypes "github.com/centrifuge/go-substrate-rpc-client/v3/types" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + + "github.com/ChainSafe/gossamer/dot/core/mocks" + "github.com/ChainSafe/gossamer/dot/network" + "github.com/ChainSafe/gossamer/dot/state" + "github.com/ChainSafe/gossamer/dot/sync" + "github.com/ChainSafe/gossamer/dot/types" + "github.com/ChainSafe/gossamer/lib/common" + "github.com/ChainSafe/gossamer/lib/crypto/sr25519" + "github.com/ChainSafe/gossamer/lib/keystore" + "github.com/ChainSafe/gossamer/lib/runtime" + "github.com/ChainSafe/gossamer/pkg/scale" +) + +func createExtrinsic(t *testing.T, rt runtime.Instance, genHash common.Hash, nonce uint64) types.Extrinsic { + t.Helper() + rawMeta, err := rt.Metadata() + require.NoError(t, err) + + var decoded []byte + err = scale.Unmarshal(rawMeta, &decoded) + require.NoError(t, err) + + meta := &ctypes.Metadata{} + err = ctypes.DecodeFromBytes(decoded, meta) + require.NoError(t, err) + + rv, err := rt.Version() + require.NoError(t, err) + + c, err := ctypes.NewCall(meta, "System.remark", []byte{0xab, 0xcd}) + require.NoError(t, err) + + ext := ctypes.NewExtrinsic(c) + options := ctypes.SignatureOptions{ + BlockHash: ctypes.Hash(genHash), + Era: ctypes.ExtrinsicEra{IsImmortalEra: false}, + GenesisHash: ctypes.Hash(genHash), + Nonce: ctypes.NewUCompactFromUInt(nonce), + SpecVersion: ctypes.U32(rv.SpecVersion()), + Tip: ctypes.NewUCompactFromUInt(0), + TransactionVersion: ctypes.U32(rv.TransactionVersion()), + } + + // Sign the transaction using Alice's key + err = ext.Sign(signature.TestKeyringPairAlice, options) + require.NoError(t, err) + + extEnc, err := ctypes.EncodeToHexString(ext) + require.NoError(t, err) + + extBytes := types.Extrinsic(common.MustHexToBytes(extEnc)) + return extBytes +} + +func TestService_HandleBlockProduced(t *testing.T) { + net := new(mocks.Network) + cfg := &Config{ + Network: net, + Keystore: keystore.NewGlobalKeystore(), + } + + s := NewTestService(t, cfg) + err := s.Start() + require.NoError(t, err) + + // simulate block sent from BABE session + digest := types.NewDigest() + prd, err := types.NewBabeSecondaryPlainPreDigest(0, 1).ToPreRuntimeDigest() + require.NoError(t, err) + err = digest.Add(*prd) + require.NoError(t, err) + + newBlock := types.Block{ + Header: types.Header{ + Number: big.NewInt(1), + ParentHash: s.blockState.BestBlockHash(), + Digest: digest, + }, + Body: *types.NewBody([]types.Extrinsic{}), + } + + expected := &network.BlockAnnounceMessage{ + ParentHash: newBlock.Header.ParentHash, + Number: newBlock.Header.Number, + StateRoot: newBlock.Header.StateRoot, + ExtrinsicsRoot: newBlock.Header.ExtrinsicsRoot, + Digest: digest, + BestBlock: true, + } + + net.On("GossipMessage", expected) + + state, err := s.storageState.TrieState(nil) + require.NoError(t, err) + + err = s.HandleBlockProduced(&newBlock, state) + require.NoError(t, err) + + time.Sleep(time.Second) + net.AssertCalled(t, "GossipMessage", expected) +} + +func TestService_HandleTransactionMessage(t *testing.T) { + t.Parallel() + + const peer1 = "testPeer1" + + kp, err := sr25519.GenerateKeypair() + require.NoError(t, err) + + ks := keystore.NewGlobalKeystore() + ks.Acco.Insert(kp) + + ctrl := gomock.NewController(t) + telemetryMock := NewMockClient(ctrl) + telemetryMock.EXPECT().SendMessage(gomock.Any()).AnyTimes() + + cfg := &Config{ + Keystore: ks, + TransactionState: state.NewTransactionState(telemetryMock), + } + + s := NewTestService(t, cfg) + genHash := s.blockState.GenesisHash() + genHeader, err := s.blockState.BestBlockHeader() + require.NoError(t, err) + + rt, err := s.blockState.GetRuntime(nil) + require.NoError(t, err) + + ts, err := s.storageState.TrieState(nil) + require.NoError(t, err) + rt.SetContextStorage(ts) + + block := sync.BuildBlock(t, rt, genHeader, nil) + + err = s.handleBlock(block, ts) + require.NoError(t, err) + + extBytes := createExtrinsic(t, rt, genHash, 0) + msg := &network.TransactionMessage{Extrinsics: []types.Extrinsic{extBytes}} + shouldPropagate, err := s.HandleTransactionMessage(peer1, msg) + require.NoError(t, err) + require.True(t, shouldPropagate) + + pending := s.transactionState.(*state.TransactionState).Pending() + require.NotEmpty(t, pending) + require.Equal(t, extBytes, pending[0].Extrinsic) + + extBytes = []byte(`bogus extrinsic`) + msg = &network.TransactionMessage{Extrinsics: []types.Extrinsic{extBytes}} + shouldPropagate, err = s.HandleTransactionMessage(peer1, msg) + require.NoError(t, err) + require.False(t, shouldPropagate) +} diff --git a/dot/core/messages_test.go b/dot/core/messages_test.go index cced5ad0fc..a918ffbf1c 100644 --- a/dot/core/messages_test.go +++ b/dot/core/messages_test.go @@ -4,166 +4,370 @@ package core import ( - "math/big" + "errors" "testing" - "time" - "github.com/centrifuge/go-substrate-rpc-client/v3/signature" - ctypes "github.com/centrifuge/go-substrate-rpc-client/v3/types" - "github.com/golang/mock/gomock" - "github.com/stretchr/testify/require" - - "github.com/ChainSafe/gossamer/dot/core/mocks" "github.com/ChainSafe/gossamer/dot/network" - "github.com/ChainSafe/gossamer/dot/state" - "github.com/ChainSafe/gossamer/dot/sync" + "github.com/ChainSafe/gossamer/dot/peerset" "github.com/ChainSafe/gossamer/dot/types" "github.com/ChainSafe/gossamer/lib/common" - "github.com/ChainSafe/gossamer/lib/crypto/sr25519" - "github.com/ChainSafe/gossamer/lib/keystore" "github.com/ChainSafe/gossamer/lib/runtime" - "github.com/ChainSafe/gossamer/pkg/scale" -) + mocksruntime "github.com/ChainSafe/gossamer/lib/runtime/mocks" + "github.com/ChainSafe/gossamer/lib/runtime/storage" + "github.com/ChainSafe/gossamer/lib/transaction" -func createExtrinsic(t *testing.T, rt runtime.Instance, genHash common.Hash, nonce uint64) types.Extrinsic { - t.Helper() - rawMeta, err := rt.Metadata() - require.NoError(t, err) - - var decoded []byte - err = scale.Unmarshal(rawMeta, &decoded) - require.NoError(t, err) - - meta := &ctypes.Metadata{} - err = ctypes.DecodeFromBytes(decoded, meta) - require.NoError(t, err) - - rv, err := rt.Version() - require.NoError(t, err) - - c, err := ctypes.NewCall(meta, "System.remark", []byte{0xab, 0xcd}) - require.NoError(t, err) - - ext := ctypes.NewExtrinsic(c) - o := ctypes.SignatureOptions{ - BlockHash: ctypes.Hash(genHash), - Era: ctypes.ExtrinsicEra{IsImmortalEra: false}, - GenesisHash: ctypes.Hash(genHash), - Nonce: ctypes.NewUCompactFromUInt(nonce), - SpecVersion: ctypes.U32(rv.SpecVersion()), - Tip: ctypes.NewUCompactFromUInt(0), - TransactionVersion: ctypes.U32(rv.TransactionVersion()), - } - - // Sign the transaction using Alice's key - err = ext.Sign(signature.TestKeyringPairAlice, o) - require.NoError(t, err) + "github.com/golang/mock/gomock" + "github.com/libp2p/go-libp2p-core/peer" + "github.com/stretchr/testify/assert" +) - extEnc, err := ctypes.EncodeToHexString(ext) - require.NoError(t, err) +var errDummyErr = errors.New("dummy error for testing") - extBytes := types.Extrinsic(common.MustHexToBytes(extEnc)) - return extBytes +type mockReportPeer struct { + change peerset.ReputationChange + id peer.ID } -func TestService_HandleBlockProduced(t *testing.T) { - net := new(mocks.Network) - cfg := &Config{ - Network: net, - Keystore: keystore.NewGlobalKeystore(), - } - - s := NewTestService(t, cfg) - err := s.Start() - require.Nil(t, err) - - // simulate block sent from BABE session - digest := types.NewDigest() - prd, err := types.NewBabeSecondaryPlainPreDigest(0, 1).ToPreRuntimeDigest() - require.NoError(t, err) - err = digest.Add(*prd) - require.NoError(t, err) - - newBlock := types.Block{ - Header: types.Header{ - Number: big.NewInt(1), - ParentHash: s.blockState.BestBlockHash(), - Digest: digest, - }, - Body: *types.NewBody([]types.Extrinsic{}), - } - - expected := &network.BlockAnnounceMessage{ - ParentHash: newBlock.Header.ParentHash, - Number: newBlock.Header.Number, - StateRoot: newBlock.Header.StateRoot, - ExtrinsicsRoot: newBlock.Header.ExtrinsicsRoot, - Digest: digest, - BestBlock: true, - } +type mockNetwork struct { + IsSynced bool + ReportPeer *mockReportPeer +} - net.On("GossipMessage", expected) +type mockBestHeader struct { + header *types.Header + err error +} - state, err := s.storageState.TrieState(nil) - require.NoError(t, err) +type mockGetRuntime struct { + runtime runtime.Instance + err error +} - err = s.HandleBlockProduced(&newBlock, state) - require.NoError(t, err) +type mockBlockState struct { + bestHeader *mockBestHeader + getRuntime *mockGetRuntime +} - time.Sleep(time.Second) - net.AssertCalled(t, "GossipMessage", expected) +type mockStorageState struct { + input *common.Hash + trieState *storage.TrieState + err error } -func TestService_HandleTransactionMessage(t *testing.T) { - t.Parallel() +type mockTxnState struct { + input *transaction.ValidTransaction + hash common.Hash +} - const peer1 = "testPeer1" +type mockSetContextStorage struct { + trieState *storage.TrieState +} - kp, err := sr25519.GenerateKeypair() - require.NoError(t, err) +type mockValidateTxn struct { + input types.Extrinsic + validity *transaction.Validity + err error +} - ks := keystore.NewGlobalKeystore() - ks.Acco.Insert(kp) +type mockRuntime struct { + runtime *mocksruntime.Instance + setContextStorage *mockSetContextStorage + validateTxn *mockValidateTxn +} +func TestService_TransactionsCount(t *testing.T) { ctrl := gomock.NewController(t) - telemetryMock := NewMockClient(ctrl) - telemetryMock.EXPECT().SendMessage(gomock.Any()).AnyTimes() - - cfg := &Config{ - Keystore: ks, - TransactionState: state.NewTransactionState(telemetryMock), + mockTxnStateEmpty := NewMockTransactionState(ctrl) + mockTxnState := NewMockTransactionState(ctrl) + + txs := []*transaction.ValidTransaction{nil, nil} + + mockTxnStateEmpty.EXPECT().PendingInPool().Return([]*transaction.ValidTransaction{}) + mockTxnState.EXPECT().PendingInPool().Return(txs) + + tests := []struct { + name string + service *Service + exp int + }{ + { + name: "empty", + service: &Service{transactionState: mockTxnStateEmpty}, + exp: 0, + }, + { + name: "not empty", + service: &Service{transactionState: mockTxnState}, + exp: 2, + }, } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + s := tt.service + res := s.TransactionsCount() + assert.Equal(t, tt.exp, res) + }) + } +} - s := NewTestService(t, cfg) - genHash := s.blockState.GenesisHash() - genHeader, err := s.blockState.BestBlockHeader() - require.NoError(t, err) - - rt, err := s.blockState.GetRuntime(nil) - require.NoError(t, err) - - ts, err := s.storageState.TrieState(nil) - require.NoError(t, err) - rt.SetContextStorage(ts) - - block := sync.BuildBlock(t, rt, genHeader, nil) - - err = s.handleBlock(block, ts) - require.NoError(t, err) - - extBytes := createExtrinsic(t, rt, genHash, 0) - msg := &network.TransactionMessage{Extrinsics: []types.Extrinsic{extBytes}} - b, err := s.HandleTransactionMessage(peer1, msg) - require.NoError(t, err) - require.True(t, b) +func TestServiceHandleTransactionMessage(t *testing.T) { + testEmptyHeader := types.NewEmptyHeader() + testExtrinsic := []types.Extrinsic{{1, 2, 3}} - pending := s.transactionState.(*state.TransactionState).Pending() - require.NotEqual(t, 0, len(pending)) - require.Equal(t, extBytes, pending[0].Extrinsic) + runtimeMock := new(mocksruntime.Instance) + runtimeMock2 := new(mocksruntime.Instance) + runtimeMock3 := new(mocksruntime.Instance) - extBytes = []byte(`bogus extrinsic`) - msg = &network.TransactionMessage{Extrinsics: []types.Extrinsic{extBytes}} - b, err = s.HandleTransactionMessage(peer1, msg) - require.NoError(t, err) - require.False(t, b) + type args struct { + peerID peer.ID + msg *network.TransactionMessage + } + tests := []struct { + name string + service *Service + args args + exp bool + expErr error + expErrMsg string + ctrl *gomock.Controller + mockNetwork *mockNetwork + mockBlockState *mockBlockState + mockStorageState *mockStorageState + mockTxnState *mockTxnState + mockRuntime *mockRuntime + }{ + { + name: "not synced", + mockNetwork: &mockNetwork{ + IsSynced: false, + }, + }, + { + name: "best block header error", + mockNetwork: &mockNetwork{ + IsSynced: true, + }, + mockBlockState: &mockBlockState{ + bestHeader: &mockBestHeader{ + err: errDummyErr, + }, + }, + args: args{ + msg: &network.TransactionMessage{Extrinsics: []types.Extrinsic{}}, + }, + expErr: errDummyErr, + expErrMsg: errDummyErr.Error(), + }, + { + name: "get runtime error", + mockNetwork: &mockNetwork{ + IsSynced: true, + }, + mockBlockState: &mockBlockState{ + bestHeader: &mockBestHeader{ + header: testEmptyHeader, + }, + getRuntime: &mockGetRuntime{ + err: errDummyErr, + }, + }, + args: args{ + msg: &network.TransactionMessage{Extrinsics: []types.Extrinsic{}}, + }, + expErr: errDummyErr, + expErrMsg: errDummyErr.Error(), + }, + { + name: "happy path no loop", + mockNetwork: &mockNetwork{ + IsSynced: true, + ReportPeer: &mockReportPeer{ + change: peerset.ReputationChange{ + Value: peerset.GoodTransactionValue, + Reason: peerset.GoodTransactionReason, + }, + }, + }, + mockBlockState: &mockBlockState{ + bestHeader: &mockBestHeader{ + header: testEmptyHeader, + }, + getRuntime: &mockGetRuntime{ + runtime: runtimeMock, + }, + }, + args: args{ + peerID: peer.ID("jimbo"), + msg: &network.TransactionMessage{Extrinsics: []types.Extrinsic{}}, + }, + }, + { + name: "trie state error", + mockNetwork: &mockNetwork{ + IsSynced: true, + }, + mockBlockState: &mockBlockState{ + bestHeader: &mockBestHeader{ + header: testEmptyHeader, + }, + getRuntime: &mockGetRuntime{ + runtime: runtimeMock, + }, + }, + mockStorageState: &mockStorageState{ + input: &common.Hash{}, + err: errDummyErr, + }, + args: args{ + peerID: peer.ID("jimbo"), + msg: &network.TransactionMessage{ + Extrinsics: []types.Extrinsic{{1, 2, 3}, {7, 8, 9, 0}, {0xa, 0xb}}, + }, + }, + expErr: errDummyErr, + expErrMsg: "failed validating transaction for peerID D1KeRhQ: cannot get trie state from storage" + + " for root 0x0000000000000000000000000000000000000000000000000000000000000000: dummy error for testing", + }, + { + name: "runtime.ErrInvalidTransaction", + mockNetwork: &mockNetwork{ + IsSynced: true, + ReportPeer: &mockReportPeer{ + change: peerset.ReputationChange{ + Value: peerset.BadTransactionValue, + Reason: peerset.BadTransactionReason, + }, + id: peer.ID("jimbo"), + }, + }, + mockBlockState: &mockBlockState{ + bestHeader: &mockBestHeader{ + header: testEmptyHeader, + }, + getRuntime: &mockGetRuntime{ + runtime: runtimeMock2, + }, + }, + mockStorageState: &mockStorageState{ + input: &common.Hash{}, + trieState: &storage.TrieState{}, + }, + mockRuntime: &mockRuntime{ + runtime: runtimeMock2, + setContextStorage: &mockSetContextStorage{trieState: &storage.TrieState{}}, + validateTxn: &mockValidateTxn{ + input: types.Extrinsic(append([]byte{byte(types.TxnExternal)}, testExtrinsic[0]...)), + err: runtime.ErrInvalidTransaction, + }, + }, + args: args{ + peerID: peer.ID("jimbo"), + msg: &network.TransactionMessage{ + Extrinsics: []types.Extrinsic{{1, 2, 3}}, + }, + }, + }, + { + name: "validTransaction", + mockNetwork: &mockNetwork{ + IsSynced: true, + ReportPeer: &mockReportPeer{ + change: peerset.ReputationChange{ + Value: peerset.GoodTransactionValue, + Reason: peerset.GoodTransactionReason, + }, + id: peer.ID("jimbo"), + }, + }, + mockBlockState: &mockBlockState{ + bestHeader: &mockBestHeader{ + header: testEmptyHeader, + }, + getRuntime: &mockGetRuntime{ + runtime: runtimeMock3, + }, + }, + mockStorageState: &mockStorageState{ + input: &common.Hash{}, + trieState: &storage.TrieState{}, + }, + mockTxnState: &mockTxnState{ + input: transaction.NewValidTransaction( + types.Extrinsic{1, 2, 3}, + &transaction.Validity{ + Propagate: true, + }), + hash: common.Hash{}, + }, + mockRuntime: &mockRuntime{ + runtime: runtimeMock3, + setContextStorage: &mockSetContextStorage{trieState: &storage.TrieState{}}, + validateTxn: &mockValidateTxn{ + input: types.Extrinsic(append([]byte{byte(types.TxnExternal)}, testExtrinsic[0]...)), + validity: &transaction.Validity{Propagate: true}, + }, + }, + args: args{ + peerID: peer.ID("jimbo"), + msg: &network.TransactionMessage{ + Extrinsics: []types.Extrinsic{{1, 2, 3}}, + }, + }, + exp: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + s := &Service{} + ctrl := gomock.NewController(t) + if tt.mockNetwork != nil { + mockNet := NewMockNetwork(ctrl) + mockNet.EXPECT().IsSynced().Return(tt.mockNetwork.IsSynced) + if tt.mockNetwork.ReportPeer != nil { + mockNet.EXPECT().ReportPeer(tt.mockNetwork.ReportPeer.change, tt.args.peerID) + } + s.net = mockNet + } + if tt.mockBlockState != nil { + blockState := NewMockBlockState(ctrl) + blockState.EXPECT().BestBlockHeader().Return( + tt.mockBlockState.bestHeader.header, + tt.mockBlockState.bestHeader.err) + + if tt.mockBlockState.getRuntime != nil { + blockState.EXPECT().GetRuntime(gomock.Any()).Return( + tt.mockBlockState.getRuntime.runtime, + tt.mockBlockState.getRuntime.err) + } + s.blockState = blockState + } + if tt.mockStorageState != nil { + storageState := NewMockStorageState(ctrl) + storageState.EXPECT().Lock() + storageState.EXPECT().Unlock() + storageState.EXPECT().TrieState(tt.mockStorageState.input).Return( + tt.mockStorageState.trieState, + tt.mockStorageState.err) + s.storageState = storageState + } + if tt.mockTxnState != nil { + txnState := NewMockTransactionState(ctrl) + txnState.EXPECT().AddToPool(tt.mockTxnState.input).Return(tt.mockTxnState.hash) + s.transactionState = txnState + } + if tt.mockRuntime != nil { + rt := tt.mockRuntime.runtime + rt.On("SetContextStorage", tt.mockRuntime.setContextStorage.trieState) + rt.On("ValidateTransaction", tt.mockRuntime.validateTxn.input). + Return(tt.mockRuntime.validateTxn.validity, tt.mockRuntime.validateTxn.err) + } + + res, err := s.HandleTransactionMessage(tt.args.peerID, tt.args.msg) + assert.ErrorIs(t, err, tt.expErr) + if tt.expErr != nil { + assert.EqualError(t, err, tt.expErrMsg) + } + assert.Equal(t, tt.exp, res) + }) + } } diff --git a/dot/core/mock_core_test.go b/dot/core/mock_core_test.go new file mode 100644 index 0000000000..8b6638c374 --- /dev/null +++ b/dot/core/mock_core_test.go @@ -0,0 +1,827 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/ChainSafe/gossamer/dot/core (interfaces: BlockState,StorageState,TransactionState,Network,EpochState,CodeSubstitutedState,DigestHandler) + +// Package core is a generated GoMock package. +package core + +import ( + big "math/big" + reflect "reflect" + + network "github.com/ChainSafe/gossamer/dot/network" + peerset "github.com/ChainSafe/gossamer/dot/peerset" + types "github.com/ChainSafe/gossamer/dot/types" + common "github.com/ChainSafe/gossamer/lib/common" + runtime "github.com/ChainSafe/gossamer/lib/runtime" + storage "github.com/ChainSafe/gossamer/lib/runtime/storage" + transaction "github.com/ChainSafe/gossamer/lib/transaction" + gomock "github.com/golang/mock/gomock" + peer "github.com/libp2p/go-libp2p-core/peer" +) + +// MockBlockState is a mock of BlockState interface. +type MockBlockState struct { + ctrl *gomock.Controller + recorder *MockBlockStateMockRecorder +} + +// MockBlockStateMockRecorder is the mock recorder for MockBlockState. +type MockBlockStateMockRecorder struct { + mock *MockBlockState +} + +// NewMockBlockState creates a new mock instance. +func NewMockBlockState(ctrl *gomock.Controller) *MockBlockState { + mock := &MockBlockState{ctrl: ctrl} + mock.recorder = &MockBlockStateMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockBlockState) EXPECT() *MockBlockStateMockRecorder { + return m.recorder +} + +// AddBlock mocks base method. +func (m *MockBlockState) AddBlock(arg0 *types.Block) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddBlock", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// AddBlock indicates an expected call of AddBlock. +func (mr *MockBlockStateMockRecorder) AddBlock(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddBlock", reflect.TypeOf((*MockBlockState)(nil).AddBlock), arg0) +} + +// BestBlock mocks base method. +func (m *MockBlockState) BestBlock() (*types.Block, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BestBlock") + ret0, _ := ret[0].(*types.Block) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// BestBlock indicates an expected call of BestBlock. +func (mr *MockBlockStateMockRecorder) BestBlock() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BestBlock", reflect.TypeOf((*MockBlockState)(nil).BestBlock)) +} + +// BestBlockHash mocks base method. +func (m *MockBlockState) BestBlockHash() common.Hash { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BestBlockHash") + ret0, _ := ret[0].(common.Hash) + return ret0 +} + +// BestBlockHash indicates an expected call of BestBlockHash. +func (mr *MockBlockStateMockRecorder) BestBlockHash() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BestBlockHash", reflect.TypeOf((*MockBlockState)(nil).BestBlockHash)) +} + +// BestBlockHeader mocks base method. +func (m *MockBlockState) BestBlockHeader() (*types.Header, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BestBlockHeader") + ret0, _ := ret[0].(*types.Header) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// BestBlockHeader indicates an expected call of BestBlockHeader. +func (mr *MockBlockStateMockRecorder) BestBlockHeader() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BestBlockHeader", reflect.TypeOf((*MockBlockState)(nil).BestBlockHeader)) +} + +// BestBlockNumber mocks base method. +func (m *MockBlockState) BestBlockNumber() (*big.Int, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BestBlockNumber") + ret0, _ := ret[0].(*big.Int) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// BestBlockNumber indicates an expected call of BestBlockNumber. +func (mr *MockBlockStateMockRecorder) BestBlockNumber() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BestBlockNumber", reflect.TypeOf((*MockBlockState)(nil).BestBlockNumber)) +} + +// BestBlockStateRoot mocks base method. +func (m *MockBlockState) BestBlockStateRoot() (common.Hash, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BestBlockStateRoot") + ret0, _ := ret[0].(common.Hash) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// BestBlockStateRoot indicates an expected call of BestBlockStateRoot. +func (mr *MockBlockStateMockRecorder) BestBlockStateRoot() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BestBlockStateRoot", reflect.TypeOf((*MockBlockState)(nil).BestBlockStateRoot)) +} + +// FreeFinalisedNotifierChannel mocks base method. +func (m *MockBlockState) FreeFinalisedNotifierChannel(arg0 chan *types.FinalisationInfo) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "FreeFinalisedNotifierChannel", arg0) +} + +// FreeFinalisedNotifierChannel indicates an expected call of FreeFinalisedNotifierChannel. +func (mr *MockBlockStateMockRecorder) FreeFinalisedNotifierChannel(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FreeFinalisedNotifierChannel", reflect.TypeOf((*MockBlockState)(nil).FreeFinalisedNotifierChannel), arg0) +} + +// FreeImportedBlockNotifierChannel mocks base method. +func (m *MockBlockState) FreeImportedBlockNotifierChannel(arg0 chan *types.Block) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "FreeImportedBlockNotifierChannel", arg0) +} + +// FreeImportedBlockNotifierChannel indicates an expected call of FreeImportedBlockNotifierChannel. +func (mr *MockBlockStateMockRecorder) FreeImportedBlockNotifierChannel(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FreeImportedBlockNotifierChannel", reflect.TypeOf((*MockBlockState)(nil).FreeImportedBlockNotifierChannel), arg0) +} + +// GenesisHash mocks base method. +func (m *MockBlockState) GenesisHash() common.Hash { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GenesisHash") + ret0, _ := ret[0].(common.Hash) + return ret0 +} + +// GenesisHash indicates an expected call of GenesisHash. +func (mr *MockBlockStateMockRecorder) GenesisHash() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GenesisHash", reflect.TypeOf((*MockBlockState)(nil).GenesisHash)) +} + +// GetAllBlocksAtDepth mocks base method. +func (m *MockBlockState) GetAllBlocksAtDepth(arg0 common.Hash) []common.Hash { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAllBlocksAtDepth", arg0) + ret0, _ := ret[0].([]common.Hash) + return ret0 +} + +// GetAllBlocksAtDepth indicates an expected call of GetAllBlocksAtDepth. +func (mr *MockBlockStateMockRecorder) GetAllBlocksAtDepth(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllBlocksAtDepth", reflect.TypeOf((*MockBlockState)(nil).GetAllBlocksAtDepth), arg0) +} + +// GetBlockBody mocks base method. +func (m *MockBlockState) GetBlockBody(arg0 common.Hash) (*types.Body, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBlockBody", arg0) + ret0, _ := ret[0].(*types.Body) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetBlockBody indicates an expected call of GetBlockBody. +func (mr *MockBlockStateMockRecorder) GetBlockBody(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBlockBody", reflect.TypeOf((*MockBlockState)(nil).GetBlockBody), arg0) +} + +// GetBlockByHash mocks base method. +func (m *MockBlockState) GetBlockByHash(arg0 common.Hash) (*types.Block, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBlockByHash", arg0) + ret0, _ := ret[0].(*types.Block) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetBlockByHash indicates an expected call of GetBlockByHash. +func (mr *MockBlockStateMockRecorder) GetBlockByHash(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBlockByHash", reflect.TypeOf((*MockBlockState)(nil).GetBlockByHash), arg0) +} + +// GetBlockStateRoot mocks base method. +func (m *MockBlockState) GetBlockStateRoot(arg0 common.Hash) (common.Hash, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBlockStateRoot", arg0) + ret0, _ := ret[0].(common.Hash) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetBlockStateRoot indicates an expected call of GetBlockStateRoot. +func (mr *MockBlockStateMockRecorder) GetBlockStateRoot(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBlockStateRoot", reflect.TypeOf((*MockBlockState)(nil).GetBlockStateRoot), arg0) +} + +// GetFinalisedHash mocks base method. +func (m *MockBlockState) GetFinalisedHash(arg0, arg1 uint64) (common.Hash, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetFinalisedHash", arg0, arg1) + ret0, _ := ret[0].(common.Hash) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetFinalisedHash indicates an expected call of GetFinalisedHash. +func (mr *MockBlockStateMockRecorder) GetFinalisedHash(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFinalisedHash", reflect.TypeOf((*MockBlockState)(nil).GetFinalisedHash), arg0, arg1) +} + +// GetFinalisedHeader mocks base method. +func (m *MockBlockState) GetFinalisedHeader(arg0, arg1 uint64) (*types.Header, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetFinalisedHeader", arg0, arg1) + ret0, _ := ret[0].(*types.Header) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetFinalisedHeader indicates an expected call of GetFinalisedHeader. +func (mr *MockBlockStateMockRecorder) GetFinalisedHeader(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFinalisedHeader", reflect.TypeOf((*MockBlockState)(nil).GetFinalisedHeader), arg0, arg1) +} + +// GetFinalisedNotifierChannel mocks base method. +func (m *MockBlockState) GetFinalisedNotifierChannel() chan *types.FinalisationInfo { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetFinalisedNotifierChannel") + ret0, _ := ret[0].(chan *types.FinalisationInfo) + return ret0 +} + +// GetFinalisedNotifierChannel indicates an expected call of GetFinalisedNotifierChannel. +func (mr *MockBlockStateMockRecorder) GetFinalisedNotifierChannel() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFinalisedNotifierChannel", reflect.TypeOf((*MockBlockState)(nil).GetFinalisedNotifierChannel)) +} + +// GetImportedBlockNotifierChannel mocks base method. +func (m *MockBlockState) GetImportedBlockNotifierChannel() chan *types.Block { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetImportedBlockNotifierChannel") + ret0, _ := ret[0].(chan *types.Block) + return ret0 +} + +// GetImportedBlockNotifierChannel indicates an expected call of GetImportedBlockNotifierChannel. +func (mr *MockBlockStateMockRecorder) GetImportedBlockNotifierChannel() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetImportedBlockNotifierChannel", reflect.TypeOf((*MockBlockState)(nil).GetImportedBlockNotifierChannel)) +} + +// GetRuntime mocks base method. +func (m *MockBlockState) GetRuntime(arg0 *common.Hash) (runtime.Instance, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetRuntime", arg0) + ret0, _ := ret[0].(runtime.Instance) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetRuntime indicates an expected call of GetRuntime. +func (mr *MockBlockStateMockRecorder) GetRuntime(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRuntime", reflect.TypeOf((*MockBlockState)(nil).GetRuntime), arg0) +} + +// GetSlotForBlock mocks base method. +func (m *MockBlockState) GetSlotForBlock(arg0 common.Hash) (uint64, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetSlotForBlock", arg0) + ret0, _ := ret[0].(uint64) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetSlotForBlock indicates an expected call of GetSlotForBlock. +func (mr *MockBlockStateMockRecorder) GetSlotForBlock(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSlotForBlock", reflect.TypeOf((*MockBlockState)(nil).GetSlotForBlock), arg0) +} + +// HandleRuntimeChanges mocks base method. +func (m *MockBlockState) HandleRuntimeChanges(arg0 *storage.TrieState, arg1 runtime.Instance, arg2 common.Hash) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HandleRuntimeChanges", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// HandleRuntimeChanges indicates an expected call of HandleRuntimeChanges. +func (mr *MockBlockStateMockRecorder) HandleRuntimeChanges(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HandleRuntimeChanges", reflect.TypeOf((*MockBlockState)(nil).HandleRuntimeChanges), arg0, arg1, arg2) +} + +// HighestCommonAncestor mocks base method. +func (m *MockBlockState) HighestCommonAncestor(arg0, arg1 common.Hash) (common.Hash, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HighestCommonAncestor", arg0, arg1) + ret0, _ := ret[0].(common.Hash) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// HighestCommonAncestor indicates an expected call of HighestCommonAncestor. +func (mr *MockBlockStateMockRecorder) HighestCommonAncestor(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HighestCommonAncestor", reflect.TypeOf((*MockBlockState)(nil).HighestCommonAncestor), arg0, arg1) +} + +// StoreRuntime mocks base method. +func (m *MockBlockState) StoreRuntime(arg0 common.Hash, arg1 runtime.Instance) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "StoreRuntime", arg0, arg1) +} + +// StoreRuntime indicates an expected call of StoreRuntime. +func (mr *MockBlockStateMockRecorder) StoreRuntime(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StoreRuntime", reflect.TypeOf((*MockBlockState)(nil).StoreRuntime), arg0, arg1) +} + +// SubChain mocks base method. +func (m *MockBlockState) SubChain(arg0, arg1 common.Hash) ([]common.Hash, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SubChain", arg0, arg1) + ret0, _ := ret[0].([]common.Hash) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SubChain indicates an expected call of SubChain. +func (mr *MockBlockStateMockRecorder) SubChain(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubChain", reflect.TypeOf((*MockBlockState)(nil).SubChain), arg0, arg1) +} + +// MockStorageState is a mock of StorageState interface. +type MockStorageState struct { + ctrl *gomock.Controller + recorder *MockStorageStateMockRecorder +} + +// MockStorageStateMockRecorder is the mock recorder for MockStorageState. +type MockStorageStateMockRecorder struct { + mock *MockStorageState +} + +// NewMockStorageState creates a new mock instance. +func NewMockStorageState(ctrl *gomock.Controller) *MockStorageState { + mock := &MockStorageState{ctrl: ctrl} + mock.recorder = &MockStorageStateMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockStorageState) EXPECT() *MockStorageStateMockRecorder { + return m.recorder +} + +// GenerateTrieProof mocks base method. +func (m *MockStorageState) GenerateTrieProof(arg0 common.Hash, arg1 [][]byte) ([][]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GenerateTrieProof", arg0, arg1) + ret0, _ := ret[0].([][]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GenerateTrieProof indicates an expected call of GenerateTrieProof. +func (mr *MockStorageStateMockRecorder) GenerateTrieProof(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GenerateTrieProof", reflect.TypeOf((*MockStorageState)(nil).GenerateTrieProof), arg0, arg1) +} + +// GetStateRootFromBlock mocks base method. +func (m *MockStorageState) GetStateRootFromBlock(arg0 *common.Hash) (*common.Hash, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetStateRootFromBlock", arg0) + ret0, _ := ret[0].(*common.Hash) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetStateRootFromBlock indicates an expected call of GetStateRootFromBlock. +func (mr *MockStorageStateMockRecorder) GetStateRootFromBlock(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStateRootFromBlock", reflect.TypeOf((*MockStorageState)(nil).GetStateRootFromBlock), arg0) +} + +// GetStorage mocks base method. +func (m *MockStorageState) GetStorage(arg0 *common.Hash, arg1 []byte) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetStorage", arg0, arg1) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetStorage indicates an expected call of GetStorage. +func (mr *MockStorageStateMockRecorder) GetStorage(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStorage", reflect.TypeOf((*MockStorageState)(nil).GetStorage), arg0, arg1) +} + +// LoadCode mocks base method. +func (m *MockStorageState) LoadCode(arg0 *common.Hash) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LoadCode", arg0) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// LoadCode indicates an expected call of LoadCode. +func (mr *MockStorageStateMockRecorder) LoadCode(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LoadCode", reflect.TypeOf((*MockStorageState)(nil).LoadCode), arg0) +} + +// LoadCodeHash mocks base method. +func (m *MockStorageState) LoadCodeHash(arg0 *common.Hash) (common.Hash, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LoadCodeHash", arg0) + ret0, _ := ret[0].(common.Hash) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// LoadCodeHash indicates an expected call of LoadCodeHash. +func (mr *MockStorageStateMockRecorder) LoadCodeHash(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LoadCodeHash", reflect.TypeOf((*MockStorageState)(nil).LoadCodeHash), arg0) +} + +// Lock mocks base method. +func (m *MockStorageState) Lock() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Lock") +} + +// Lock indicates an expected call of Lock. +func (mr *MockStorageStateMockRecorder) Lock() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Lock", reflect.TypeOf((*MockStorageState)(nil).Lock)) +} + +// StoreTrie mocks base method. +func (m *MockStorageState) StoreTrie(arg0 *storage.TrieState, arg1 *types.Header) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StoreTrie", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// StoreTrie indicates an expected call of StoreTrie. +func (mr *MockStorageStateMockRecorder) StoreTrie(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StoreTrie", reflect.TypeOf((*MockStorageState)(nil).StoreTrie), arg0, arg1) +} + +// TrieState mocks base method. +func (m *MockStorageState) TrieState(arg0 *common.Hash) (*storage.TrieState, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TrieState", arg0) + ret0, _ := ret[0].(*storage.TrieState) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// TrieState indicates an expected call of TrieState. +func (mr *MockStorageStateMockRecorder) TrieState(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TrieState", reflect.TypeOf((*MockStorageState)(nil).TrieState), arg0) +} + +// Unlock mocks base method. +func (m *MockStorageState) Unlock() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Unlock") +} + +// Unlock indicates an expected call of Unlock. +func (mr *MockStorageStateMockRecorder) Unlock() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Unlock", reflect.TypeOf((*MockStorageState)(nil).Unlock)) +} + +// MockTransactionState is a mock of TransactionState interface. +type MockTransactionState struct { + ctrl *gomock.Controller + recorder *MockTransactionStateMockRecorder +} + +// MockTransactionStateMockRecorder is the mock recorder for MockTransactionState. +type MockTransactionStateMockRecorder struct { + mock *MockTransactionState +} + +// NewMockTransactionState creates a new mock instance. +func NewMockTransactionState(ctrl *gomock.Controller) *MockTransactionState { + mock := &MockTransactionState{ctrl: ctrl} + mock.recorder = &MockTransactionStateMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockTransactionState) EXPECT() *MockTransactionStateMockRecorder { + return m.recorder +} + +// AddToPool mocks base method. +func (m *MockTransactionState) AddToPool(arg0 *transaction.ValidTransaction) common.Hash { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddToPool", arg0) + ret0, _ := ret[0].(common.Hash) + return ret0 +} + +// AddToPool indicates an expected call of AddToPool. +func (mr *MockTransactionStateMockRecorder) AddToPool(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddToPool", reflect.TypeOf((*MockTransactionState)(nil).AddToPool), arg0) +} + +// PendingInPool mocks base method. +func (m *MockTransactionState) PendingInPool() []*transaction.ValidTransaction { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PendingInPool") + ret0, _ := ret[0].([]*transaction.ValidTransaction) + return ret0 +} + +// PendingInPool indicates an expected call of PendingInPool. +func (mr *MockTransactionStateMockRecorder) PendingInPool() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PendingInPool", reflect.TypeOf((*MockTransactionState)(nil).PendingInPool)) +} + +// Push mocks base method. +func (m *MockTransactionState) Push(arg0 *transaction.ValidTransaction) (common.Hash, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Push", arg0) + ret0, _ := ret[0].(common.Hash) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Push indicates an expected call of Push. +func (mr *MockTransactionStateMockRecorder) Push(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Push", reflect.TypeOf((*MockTransactionState)(nil).Push), arg0) +} + +// RemoveExtrinsic mocks base method. +func (m *MockTransactionState) RemoveExtrinsic(arg0 types.Extrinsic) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RemoveExtrinsic", arg0) +} + +// RemoveExtrinsic indicates an expected call of RemoveExtrinsic. +func (mr *MockTransactionStateMockRecorder) RemoveExtrinsic(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveExtrinsic", reflect.TypeOf((*MockTransactionState)(nil).RemoveExtrinsic), arg0) +} + +// RemoveExtrinsicFromPool mocks base method. +func (m *MockTransactionState) RemoveExtrinsicFromPool(arg0 types.Extrinsic) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RemoveExtrinsicFromPool", arg0) +} + +// RemoveExtrinsicFromPool indicates an expected call of RemoveExtrinsicFromPool. +func (mr *MockTransactionStateMockRecorder) RemoveExtrinsicFromPool(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveExtrinsicFromPool", reflect.TypeOf((*MockTransactionState)(nil).RemoveExtrinsicFromPool), arg0) +} + +// MockNetwork is a mock of Network interface. +type MockNetwork struct { + ctrl *gomock.Controller + recorder *MockNetworkMockRecorder +} + +// MockNetworkMockRecorder is the mock recorder for MockNetwork. +type MockNetworkMockRecorder struct { + mock *MockNetwork +} + +// NewMockNetwork creates a new mock instance. +func NewMockNetwork(ctrl *gomock.Controller) *MockNetwork { + mock := &MockNetwork{ctrl: ctrl} + mock.recorder = &MockNetworkMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockNetwork) EXPECT() *MockNetworkMockRecorder { + return m.recorder +} + +// GossipMessage mocks base method. +func (m *MockNetwork) GossipMessage(arg0 network.NotificationsMessage) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "GossipMessage", arg0) +} + +// GossipMessage indicates an expected call of GossipMessage. +func (mr *MockNetworkMockRecorder) GossipMessage(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GossipMessage", reflect.TypeOf((*MockNetwork)(nil).GossipMessage), arg0) +} + +// IsSynced mocks base method. +func (m *MockNetwork) IsSynced() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsSynced") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsSynced indicates an expected call of IsSynced. +func (mr *MockNetworkMockRecorder) IsSynced() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsSynced", reflect.TypeOf((*MockNetwork)(nil).IsSynced)) +} + +// ReportPeer mocks base method. +func (m *MockNetwork) ReportPeer(arg0 peerset.ReputationChange, arg1 peer.ID) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "ReportPeer", arg0, arg1) +} + +// ReportPeer indicates an expected call of ReportPeer. +func (mr *MockNetworkMockRecorder) ReportPeer(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReportPeer", reflect.TypeOf((*MockNetwork)(nil).ReportPeer), arg0, arg1) +} + +// MockEpochState is a mock of EpochState interface. +type MockEpochState struct { + ctrl *gomock.Controller + recorder *MockEpochStateMockRecorder +} + +// MockEpochStateMockRecorder is the mock recorder for MockEpochState. +type MockEpochStateMockRecorder struct { + mock *MockEpochState +} + +// NewMockEpochState creates a new mock instance. +func NewMockEpochState(ctrl *gomock.Controller) *MockEpochState { + mock := &MockEpochState{ctrl: ctrl} + mock.recorder = &MockEpochStateMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEpochState) EXPECT() *MockEpochStateMockRecorder { + return m.recorder +} + +// GetCurrentEpoch mocks base method. +func (m *MockEpochState) GetCurrentEpoch() (uint64, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetCurrentEpoch") + ret0, _ := ret[0].(uint64) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetCurrentEpoch indicates an expected call of GetCurrentEpoch. +func (mr *MockEpochStateMockRecorder) GetCurrentEpoch() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCurrentEpoch", reflect.TypeOf((*MockEpochState)(nil).GetCurrentEpoch)) +} + +// GetEpochForBlock mocks base method. +func (m *MockEpochState) GetEpochForBlock(arg0 *types.Header) (uint64, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetEpochForBlock", arg0) + ret0, _ := ret[0].(uint64) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetEpochForBlock indicates an expected call of GetEpochForBlock. +func (mr *MockEpochStateMockRecorder) GetEpochForBlock(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEpochForBlock", reflect.TypeOf((*MockEpochState)(nil).GetEpochForBlock), arg0) +} + +// SetCurrentEpoch mocks base method. +func (m *MockEpochState) SetCurrentEpoch(arg0 uint64) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetCurrentEpoch", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// SetCurrentEpoch indicates an expected call of SetCurrentEpoch. +func (mr *MockEpochStateMockRecorder) SetCurrentEpoch(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetCurrentEpoch", reflect.TypeOf((*MockEpochState)(nil).SetCurrentEpoch), arg0) +} + +// MockCodeSubstitutedState is a mock of CodeSubstitutedState interface. +type MockCodeSubstitutedState struct { + ctrl *gomock.Controller + recorder *MockCodeSubstitutedStateMockRecorder +} + +// MockCodeSubstitutedStateMockRecorder is the mock recorder for MockCodeSubstitutedState. +type MockCodeSubstitutedStateMockRecorder struct { + mock *MockCodeSubstitutedState +} + +// NewMockCodeSubstitutedState creates a new mock instance. +func NewMockCodeSubstitutedState(ctrl *gomock.Controller) *MockCodeSubstitutedState { + mock := &MockCodeSubstitutedState{ctrl: ctrl} + mock.recorder = &MockCodeSubstitutedStateMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockCodeSubstitutedState) EXPECT() *MockCodeSubstitutedStateMockRecorder { + return m.recorder +} + +// LoadCodeSubstitutedBlockHash mocks base method. +func (m *MockCodeSubstitutedState) LoadCodeSubstitutedBlockHash() common.Hash { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LoadCodeSubstitutedBlockHash") + ret0, _ := ret[0].(common.Hash) + return ret0 +} + +// LoadCodeSubstitutedBlockHash indicates an expected call of LoadCodeSubstitutedBlockHash. +func (mr *MockCodeSubstitutedStateMockRecorder) LoadCodeSubstitutedBlockHash() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LoadCodeSubstitutedBlockHash", reflect.TypeOf((*MockCodeSubstitutedState)(nil).LoadCodeSubstitutedBlockHash)) +} + +// StoreCodeSubstitutedBlockHash mocks base method. +func (m *MockCodeSubstitutedState) StoreCodeSubstitutedBlockHash(arg0 common.Hash) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StoreCodeSubstitutedBlockHash", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// StoreCodeSubstitutedBlockHash indicates an expected call of StoreCodeSubstitutedBlockHash. +func (mr *MockCodeSubstitutedStateMockRecorder) StoreCodeSubstitutedBlockHash(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StoreCodeSubstitutedBlockHash", reflect.TypeOf((*MockCodeSubstitutedState)(nil).StoreCodeSubstitutedBlockHash), arg0) +} + +// MockDigestHandler is a mock of DigestHandler interface. +type MockDigestHandler struct { + ctrl *gomock.Controller + recorder *MockDigestHandlerMockRecorder +} + +// MockDigestHandlerMockRecorder is the mock recorder for MockDigestHandler. +type MockDigestHandlerMockRecorder struct { + mock *MockDigestHandler +} + +// NewMockDigestHandler creates a new mock instance. +func NewMockDigestHandler(ctrl *gomock.Controller) *MockDigestHandler { + mock := &MockDigestHandler{ctrl: ctrl} + mock.recorder = &MockDigestHandlerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockDigestHandler) EXPECT() *MockDigestHandlerMockRecorder { + return m.recorder +} + +// HandleDigests mocks base method. +func (m *MockDigestHandler) HandleDigests(arg0 *types.Header) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "HandleDigests", arg0) +} + +// HandleDigests indicates an expected call of HandleDigests. +func (mr *MockDigestHandlerMockRecorder) HandleDigests(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HandleDigests", reflect.TypeOf((*MockDigestHandler)(nil).HandleDigests), arg0) +} diff --git a/dot/core/service_test.go b/dot/core/service_integration_test.go similarity index 99% rename from dot/core/service_test.go rename to dot/core/service_integration_test.go index d1b78bd8d2..8ecc48697c 100644 --- a/dot/core/service_test.go +++ b/dot/core/service_integration_test.go @@ -1,6 +1,9 @@ // Copyright 2021 ChainSafe Systems (ON) // SPDX-License-Identifier: LGPL-3.0-only +//go:build integration +// +build integration + package core import (