From 749da7598d17ca22bb280c05ba17266545761527 Mon Sep 17 00:00:00 2001 From: elizabeth Date: Tue, 15 Jun 2021 16:40:37 -0400 Subject: [PATCH] add pause/resume test --- dot/network/mock_block_state.go | 146 ++++++++++++++++++++++++ dot/network/mock_syncer.go | 111 ++++++++++++++++++ dot/network/mock_transaction_handler.go | 24 ++++ lib/babe/babe_test.go | 30 +++++ lib/runtime/mock_transaction_state.go | 31 +++++ 5 files changed, 342 insertions(+) create mode 100644 dot/network/mock_block_state.go create mode 100644 dot/network/mock_syncer.go create mode 100644 dot/network/mock_transaction_handler.go create mode 100644 lib/runtime/mock_transaction_state.go diff --git a/dot/network/mock_block_state.go b/dot/network/mock_block_state.go new file mode 100644 index 0000000000..57b3f4d155 --- /dev/null +++ b/dot/network/mock_block_state.go @@ -0,0 +1,146 @@ +// Code generated by mockery v2.8.0. DO NOT EDIT. + +package network + +import ( + big "math/big" + + common "github.com/ChainSafe/gossamer/lib/common" + mock "github.com/stretchr/testify/mock" + + types "github.com/ChainSafe/gossamer/dot/types" +) + +// MockBlockState is an autogenerated mock type for the BlockState type +type MockBlockState struct { + mock.Mock +} + +// BestBlockHeader provides a mock function with given fields: +func (_m *MockBlockState) BestBlockHeader() (*types.Header, error) { + ret := _m.Called() + + var r0 *types.Header + if rf, ok := ret.Get(0).(func() *types.Header); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Header) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// BestBlockNumber provides a mock function with given fields: +func (_m *MockBlockState) BestBlockNumber() (*big.Int, error) { + ret := _m.Called() + + var r0 *big.Int + if rf, ok := ret.Get(0).(func() *big.Int); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*big.Int) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GenesisHash provides a mock function with given fields: +func (_m *MockBlockState) GenesisHash() common.Hash { + ret := _m.Called() + + var r0 common.Hash + if rf, ok := ret.Get(0).(func() common.Hash); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(common.Hash) + } + } + + return r0 +} + +// GetFinalizedHeader provides a mock function with given fields: round, setID +func (_m *MockBlockState) GetFinalizedHeader(round uint64, setID uint64) (*types.Header, error) { + ret := _m.Called(round, setID) + + var r0 *types.Header + if rf, ok := ret.Get(0).(func(uint64, uint64) *types.Header); ok { + r0 = rf(round, setID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Header) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(uint64, uint64) error); ok { + r1 = rf(round, setID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetHashByNumber provides a mock function with given fields: num +func (_m *MockBlockState) GetHashByNumber(num *big.Int) (common.Hash, error) { + ret := _m.Called(num) + + var r0 common.Hash + if rf, ok := ret.Get(0).(func(*big.Int) common.Hash); ok { + r0 = rf(num) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(common.Hash) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*big.Int) error); ok { + r1 = rf(num) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// HasBlockBody provides a mock function with given fields: _a0 +func (_m *MockBlockState) HasBlockBody(_a0 common.Hash) (bool, error) { + ret := _m.Called(_a0) + + var r0 bool + if rf, ok := ret.Get(0).(func(common.Hash) bool); ok { + r0 = rf(_a0) + } else { + r0 = ret.Get(0).(bool) + } + + var r1 error + if rf, ok := ret.Get(1).(func(common.Hash) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} diff --git a/dot/network/mock_syncer.go b/dot/network/mock_syncer.go new file mode 100644 index 0000000000..efa21957b4 --- /dev/null +++ b/dot/network/mock_syncer.go @@ -0,0 +1,111 @@ +// Code generated by mockery v2.8.0. DO NOT EDIT. + +package network + +import ( + types "github.com/ChainSafe/gossamer/dot/types" + mock "github.com/stretchr/testify/mock" +) + +// MockSyncer is an autogenerated mock type for the Syncer type +type MockSyncer struct { + mock.Mock +} + +// CreateBlockResponse provides a mock function with given fields: _a0 +func (_m *MockSyncer) CreateBlockResponse(_a0 *BlockRequestMessage) (*BlockResponseMessage, error) { + ret := _m.Called(_a0) + + var r0 *BlockResponseMessage + if rf, ok := ret.Get(0).(func(*BlockRequestMessage) *BlockResponseMessage); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*BlockResponseMessage) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*BlockRequestMessage) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// HandleBlockAnnounce provides a mock function with given fields: _a0 +func (_m *MockSyncer) HandleBlockAnnounce(_a0 *BlockAnnounceMessage) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(*BlockAnnounceMessage) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// IsSynced provides a mock function with given fields: +func (_m *MockSyncer) IsSynced() bool { + ret := _m.Called() + + var r0 bool + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// ProcessBlockData provides a mock function with given fields: data +func (_m *MockSyncer) ProcessBlockData(data []*types.BlockData) (int, error) { + ret := _m.Called(data) + + var r0 int + if rf, ok := ret.Get(0).(func([]*types.BlockData) int); ok { + r0 = rf(data) + } else { + r0 = ret.Get(0).(int) + } + + var r1 error + if rf, ok := ret.Get(1).(func([]*types.BlockData) error); ok { + r1 = rf(data) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ProcessJustification provides a mock function with given fields: data +func (_m *MockSyncer) ProcessJustification(data []*types.BlockData) (int, error) { + ret := _m.Called(data) + + var r0 int + if rf, ok := ret.Get(0).(func([]*types.BlockData) int); ok { + r0 = rf(data) + } else { + r0 = ret.Get(0).(int) + } + + var r1 error + if rf, ok := ret.Get(1).(func([]*types.BlockData) error); ok { + r1 = rf(data) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SetSyncing provides a mock function with given fields: _a0 +func (_m *MockSyncer) SetSyncing(_a0 bool) { + _m.Called(_a0) +} diff --git a/dot/network/mock_transaction_handler.go b/dot/network/mock_transaction_handler.go new file mode 100644 index 0000000000..45ad335bdc --- /dev/null +++ b/dot/network/mock_transaction_handler.go @@ -0,0 +1,24 @@ +// Code generated by mockery v2.8.0. DO NOT EDIT. + +package network + +import mock "github.com/stretchr/testify/mock" + +// MockTransactionHandler is an autogenerated mock type for the TransactionHandler type +type MockTransactionHandler struct { + mock.Mock +} + +// HandleTransactionMessage provides a mock function with given fields: _a0 +func (_m *MockTransactionHandler) HandleTransactionMessage(_a0 *TransactionMessage) error { + ret := _m.Called(_a0) + + var r0 error + if rf, ok := ret.Get(0).(func(*TransactionMessage) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} diff --git a/lib/babe/babe_test.go b/lib/babe/babe_test.go index 5727400066..bfd2b909ca 100644 --- a/lib/babe/babe_test.go +++ b/lib/babe/babe_test.go @@ -253,3 +253,33 @@ func TestStartAndStop(t *testing.T) { err = bs.Stop() require.NoError(t, err) } + +func TestService_PauseAndResume(t *testing.T) { + bs := createTestService(t, &ServiceConfig{ + LogLvl: log.LvlCrit, + }) + err := bs.Start() + require.NoError(t, err) + time.Sleep(time.Second) + + go func() { + _ = bs.Pause() + }() + + go func() { + _ = bs.Pause() + }() + + go func() { + err := bs.Resume() + require.NoError(t, err) + }() + + go func() { + err := bs.Resume() + require.NoError(t, err) + }() + + err = bs.Stop() + require.NoError(t, err) +} diff --git a/lib/runtime/mock_transaction_state.go b/lib/runtime/mock_transaction_state.go new file mode 100644 index 0000000000..e27caec9e4 --- /dev/null +++ b/lib/runtime/mock_transaction_state.go @@ -0,0 +1,31 @@ +// Code generated by mockery v2.8.0. DO NOT EDIT. + +package runtime + +import ( + common "github.com/ChainSafe/gossamer/lib/common" + mock "github.com/stretchr/testify/mock" + + transaction "github.com/ChainSafe/gossamer/lib/transaction" +) + +// MockTransactionState is an autogenerated mock type for the TransactionState type +type MockTransactionState struct { + mock.Mock +} + +// AddToPool provides a mock function with given fields: vt +func (_m *MockTransactionState) AddToPool(vt *transaction.ValidTransaction) common.Hash { + ret := _m.Called(vt) + + var r0 common.Hash + if rf, ok := ret.Get(0).(func(*transaction.ValidTransaction) common.Hash); ok { + r0 = rf(vt) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(common.Hash) + } + } + + return r0 +}