diff --git a/cosmos/precompile/bank/bank_test.go b/cosmos/precompile/bank/bank_test.go index afd570d95..08bbf414d 100644 --- a/cosmos/precompile/bank/bank_test.go +++ b/cosmos/precompile/bank/bank_test.go @@ -26,6 +26,7 @@ import ( "math/big" "testing" + "cosmossdk.io/log" sdkmath "cosmossdk.io/math" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -36,8 +37,8 @@ import ( "pkg.berachain.dev/polaris/cosmos/precompile" "pkg.berachain.dev/polaris/cosmos/precompile/bank" - testutils "pkg.berachain.dev/polaris/cosmos/testing/utils" - "pkg.berachain.dev/polaris/cosmos/x/evm/plugins/precompile/log" + testutils "pkg.berachain.dev/polaris/cosmos/testutil" + pclog "pkg.berachain.dev/polaris/cosmos/x/evm/plugins/precompile/log" evmtypes "pkg.berachain.dev/polaris/cosmos/x/evm/types" "pkg.berachain.dev/polaris/eth/common" ethprecompile "pkg.berachain.dev/polaris/eth/core/precompile" @@ -57,14 +58,14 @@ var _ = Describe("Bank Precompile Test", func() { var ( contract *bank.Contract addr sdk.AccAddress - factory *log.Factory + factory *pclog.Factory ak authkeeper.AccountKeeperI bk bankkeeper.BaseKeeper ctx context.Context ) BeforeEach(func() { - ctx, ak, bk, _ = testutils.SetupMinimalKeepers() + ctx, ak, bk, _ = testutils.SetupMinimalKeepers(log.NewTestLogger(GinkgoT())) contract = utils.MustGetAs[*bank.Contract](bank.NewPrecompileContract( ak, bankkeeper.NewMsgServerImpl(bk), bk), @@ -72,7 +73,7 @@ var _ = Describe("Bank Precompile Test", func() { addr = sdk.AccAddress([]byte("bank")) // Register the events. - factory = log.NewFactory([]ethprecompile.Registrable{contract}) + factory = pclog.NewFactory([]ethprecompile.Registrable{contract}) }) It("should register the send event", func() { diff --git a/cosmos/precompile/distribution/distribution_test.go b/cosmos/precompile/distribution/distribution_test.go index 558a2c042..b7c542c44 100644 --- a/cosmos/precompile/distribution/distribution_test.go +++ b/cosmos/precompile/distribution/distribution_test.go @@ -25,6 +25,7 @@ import ( "math/big" "testing" + "cosmossdk.io/log" sdkmath "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" @@ -44,8 +45,8 @@ import ( "github.com/ethereum/go-ethereum/common" - testutil "pkg.berachain.dev/polaris/cosmos/testing/utils" - "pkg.berachain.dev/polaris/cosmos/x/evm/plugins/precompile/log" + testutil "pkg.berachain.dev/polaris/cosmos/testutil" + pclog "pkg.berachain.dev/polaris/cosmos/x/evm/plugins/precompile/log" ethprecompile "pkg.berachain.dev/polaris/eth/core/precompile" "pkg.berachain.dev/polaris/eth/core/vm" "pkg.berachain.dev/polaris/lib/utils" @@ -77,7 +78,9 @@ func setup() ( *stakingkeeper.Keeper, *bankkeeper.BaseKeeper, ) { - ctx, ak, bk, sk := testutil.SetupMinimalKeepers() + distrKey := storetypes.NewKVStoreKey(distributiontypes.StoreKey) + ctx, ak, bk, sk := testutil.SetupMinimalKeepers(log.NewTestLogger(GinkgoT()), + []storetypes.StoreKey{distrKey}...) encCfg := cosmostestutil.MakeTestEncodingConfig( distribution.AppModuleBasic{}, @@ -85,7 +88,7 @@ func setup() ( dk := distrkeeper.NewKeeper( encCfg.Codec, - runtime.NewKVStoreService(storetypes.NewKVStoreKey(distributiontypes.StoreKey)), + runtime.NewKVStoreService(distrKey), ak, bk, sk, @@ -107,7 +110,7 @@ var _ = Describe("Distribution Precompile Test", func() { var ( contract *Contract valAddr sdk.ValAddress - f *log.Factory + f *pclog.Factory amt sdk.Coin ctx sdk.Context @@ -131,7 +134,7 @@ var _ = Describe("Distribution Precompile Test", func() { )) // Register the events. - f = log.NewFactory([]ethprecompile.Registrable{contract}) + f = pclog.NewFactory([]ethprecompile.Registrable{contract}) // Set up the stateful factory. sf = ethprecompile.NewStatefulFactory() diff --git a/cosmos/precompile/governance/governance_test.go b/cosmos/precompile/governance/governance_test.go index 614cf7f8b..9aa4ea283 100644 --- a/cosmos/precompile/governance/governance_test.go +++ b/cosmos/precompile/governance/governance_test.go @@ -43,7 +43,7 @@ import ( cbindings "pkg.berachain.dev/polaris/contracts/bindings/cosmos/lib" generated "pkg.berachain.dev/polaris/contracts/bindings/cosmos/precompile/governance" - testutils "pkg.berachain.dev/polaris/cosmos/testing/utils" + testutils "pkg.berachain.dev/polaris/cosmos/testutil" "pkg.berachain.dev/polaris/cosmos/types" "pkg.berachain.dev/polaris/eth/common" ethprecompile "pkg.berachain.dev/polaris/eth/core/precompile" diff --git a/cosmos/precompile/governance/testutil.go b/cosmos/precompile/governance/testutil.go index d0b8dca0b..d4dfa36d2 100644 --- a/cosmos/precompile/governance/testutil.go +++ b/cosmos/precompile/governance/testutil.go @@ -26,6 +26,7 @@ import ( "github.com/golang/mock/gomock" + "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/baseapp" @@ -43,7 +44,7 @@ import ( v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - testutils "pkg.berachain.dev/polaris/cosmos/testing/utils" + testutils "pkg.berachain.dev/polaris/cosmos/testutil" "pkg.berachain.dev/polaris/eth/common" //nolint:stylecheck,revive // Ginkgo is the testing framework. @@ -67,7 +68,10 @@ func setupGovTest(ctrl *gomock.Controller, caller sdk.AccAddress) ( sdk.Context, authkeeper.AccountKeeperI, bankkeeper.Keeper, *governancekeeper.Keeper, ) { // Setup the keepers and context. - ctx, ak, bk, sk := testutils.SetupMinimalKeepers() + govKey := storetypes.NewKVStoreKey(governancetypes.StoreKey) + ctx, ak, bk, sk := testutils.SetupMinimalKeepers( + log.NewTestLogger(GinkgoT()), []storetypes.StoreKey{govKey}..., + ) dk := govtestutil.NewMockDistributionKeeper(ctrl) // Create the codec. @@ -94,7 +98,7 @@ func setupGovTest(ctrl *gomock.Controller, caller sdk.AccAddress) ( } gk := governancekeeper.NewKeeper( encCfg.Codec, - runtime.NewKVStoreService(storetypes.NewKVStoreKey(governancetypes.StoreKey)), + runtime.NewKVStoreService(govKey), ak, bk, sk, diff --git a/cosmos/precompile/staking/staking_test.go b/cosmos/precompile/staking/staking_test.go index bb548c943..b0b345c90 100644 --- a/cosmos/precompile/staking/staking_test.go +++ b/cosmos/precompile/staking/staking_test.go @@ -25,6 +25,7 @@ import ( "math/big" "testing" + "cosmossdk.io/log" sdkmath "cosmossdk.io/math" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -38,7 +39,7 @@ import ( cbindings "pkg.berachain.dev/polaris/contracts/bindings/cosmos/lib" generated "pkg.berachain.dev/polaris/contracts/bindings/cosmos/precompile/staking" cosmlib "pkg.berachain.dev/polaris/cosmos/lib" - testutil "pkg.berachain.dev/polaris/cosmos/testing/utils" + testutil "pkg.berachain.dev/polaris/cosmos/testutil" "pkg.berachain.dev/polaris/eth/accounts/abi" "pkg.berachain.dev/polaris/eth/common" ethprecompile "pkg.berachain.dev/polaris/eth/core/precompile" @@ -88,7 +89,7 @@ var _ = Describe("Staking", func() { ) BeforeEach(func() { - sdkCtx, ak, bk, sk = testutil.SetupMinimalKeepers() + sdkCtx, ak, bk, sk = testutil.SetupMinimalKeepers(log.NewTestLogger(GinkgoT())) contract = libutils.MustGetAs[*Contract](NewPrecompileContract(ak, &sk)) sf = ethprecompile.NewStatefulFactory() }) diff --git a/cosmos/store/cachekv/readonly_store.go b/cosmos/store/cachekv/readonly_store.go index c709167fe..1100b6572 100644 --- a/cosmos/store/cachekv/readonly_store.go +++ b/cosmos/store/cachekv/readonly_store.go @@ -26,14 +26,14 @@ import ( "pkg.berachain.dev/polaris/eth/core/vm" ) -var _ storetypes.CacheKVStore = (*ReadOnlyStore)(nil) +var _ storetypes.KVStore = (*ReadOnlyStore)(nil) // ReadOnlyStore is a wrapper around cachekv.Store that panics on any write operation. type ReadOnlyStore struct { - storetypes.CacheKVStore + storetypes.KVStore } -func NewReadOnlyStoreFor(cacheKVStore storetypes.CacheKVStore) *ReadOnlyStore { +func NewReadOnlyStoreFor(cacheKVStore storetypes.KVStore) *ReadOnlyStore { return &ReadOnlyStore{cacheKVStore} } diff --git a/cosmos/store/cachekv/readonly_store_test.go b/cosmos/store/cachekv/readonly_store_test.go index 427a70f5c..0b26cfb51 100644 --- a/cosmos/store/cachekv/readonly_store_test.go +++ b/cosmos/store/cachekv/readonly_store_test.go @@ -23,11 +23,11 @@ package cachekv_test import ( "testing" - sdkcachekv "cosmossdk.io/store/cachekv" - storetypes "cosmossdk.io/store/types" + cdb "github.com/cosmos/cosmos-db" + + "cosmossdk.io/store/dbadapter" "pkg.berachain.dev/polaris/cosmos/store/cachekv" - "pkg.berachain.dev/polaris/cosmos/testing/types/mock" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -42,10 +42,9 @@ var _ = Describe("ReadOnly Store", func() { var readOnlyStore *cachekv.ReadOnlyStore BeforeEach(func() { - ms := mock.NewMultiStore() - kv := ms.GetKVStore(storetypes.NewKVStoreKey("test")) - kv.Set([]byte("key"), []byte("value")) - readOnlyStore = cachekv.NewReadOnlyStoreFor(sdkcachekv.NewStore(kv)) + kvStore := dbadapter.Store{DB: cdb.NewMemDB()} + kvStore.Set([]byte("key"), []byte("value")) + readOnlyStore = cachekv.NewReadOnlyStoreFor(kvStore) }) It("should panic only on writes", func() { diff --git a/cosmos/testing/types/mock/interfaces/mock/store.mock.go b/cosmos/testing/types/mock/interfaces/mock/store.mock.go deleted file mode 100644 index ac42b1516..000000000 --- a/cosmos/testing/types/mock/interfaces/mock/store.mock.go +++ /dev/null @@ -1,1431 +0,0 @@ -// Code generated by moq; DO NOT EDIT. -// github.com/matryer/moq - -package mock - -import ( - storetypes "cosmossdk.io/store/types" - "github.com/cosmos/cosmos-db" - "io" - "pkg.berachain.dev/polaris/cosmos/testing/types/mock/interfaces" - "sync" -) - -// Ensure, that MultiStoreMock does implement interfaces.MultiStore. -// If this is not the case, regenerate this file with moq. -var _ interfaces.MultiStore = &MultiStoreMock{} - -// MultiStoreMock is a mock implementation of interfaces.MultiStore. -// -// func TestSomethingThatUsesMultiStore(t *testing.T) { -// -// // make and configure a mocked interfaces.MultiStore -// mockedMultiStore := &MultiStoreMock{ -// CacheMultiStoreFunc: func() storetypes.CacheMultiStore { -// panic("mock out the CacheMultiStore method") -// }, -// CacheMultiStoreWithVersionFunc: func(version int64) (storetypes.CacheMultiStore, error) { -// panic("mock out the CacheMultiStoreWithVersion method") -// }, -// CacheWrapFunc: func() storetypes.CacheWrap { -// panic("mock out the CacheWrap method") -// }, -// CacheWrapWithTraceFunc: func(w io.Writer, tc storetypes.TraceContext) storetypes.CacheWrap { -// panic("mock out the CacheWrapWithTrace method") -// }, -// GetKVStoreFunc: func(storeKey storetypes.StoreKey) storetypes.KVStore { -// panic("mock out the GetKVStore method") -// }, -// GetStoreFunc: func(storeKey storetypes.StoreKey) storetypes.Store { -// panic("mock out the GetStore method") -// }, -// GetStoreTypeFunc: func() storetypes.StoreType { -// panic("mock out the GetStoreType method") -// }, -// LatestVersionFunc: func() int64 { -// panic("mock out the LatestVersion method") -// }, -// SetTracerFunc: func(w io.Writer) storetypes.MultiStore { -// panic("mock out the SetTracer method") -// }, -// SetTracingContextFunc: func(traceContext storetypes.TraceContext) storetypes.MultiStore { -// panic("mock out the SetTracingContext method") -// }, -// TracingEnabledFunc: func() bool { -// panic("mock out the TracingEnabled method") -// }, -// } -// -// // use mockedMultiStore in code that requires interfaces.MultiStore -// // and then make assertions. -// -// } -type MultiStoreMock struct { - // CacheMultiStoreFunc mocks the CacheMultiStore method. - CacheMultiStoreFunc func() storetypes.CacheMultiStore - - // CacheMultiStoreWithVersionFunc mocks the CacheMultiStoreWithVersion method. - CacheMultiStoreWithVersionFunc func(version int64) (storetypes.CacheMultiStore, error) - - // CacheWrapFunc mocks the CacheWrap method. - CacheWrapFunc func() storetypes.CacheWrap - - // CacheWrapWithTraceFunc mocks the CacheWrapWithTrace method. - CacheWrapWithTraceFunc func(w io.Writer, tc storetypes.TraceContext) storetypes.CacheWrap - - // GetKVStoreFunc mocks the GetKVStore method. - GetKVStoreFunc func(storeKey storetypes.StoreKey) storetypes.KVStore - - // GetStoreFunc mocks the GetStore method. - GetStoreFunc func(storeKey storetypes.StoreKey) storetypes.Store - - // GetStoreTypeFunc mocks the GetStoreType method. - GetStoreTypeFunc func() storetypes.StoreType - - // LatestVersionFunc mocks the LatestVersion method. - LatestVersionFunc func() int64 - - // SetTracerFunc mocks the SetTracer method. - SetTracerFunc func(w io.Writer) storetypes.MultiStore - - // SetTracingContextFunc mocks the SetTracingContext method. - SetTracingContextFunc func(traceContext storetypes.TraceContext) storetypes.MultiStore - - // TracingEnabledFunc mocks the TracingEnabled method. - TracingEnabledFunc func() bool - - // calls tracks calls to the methods. - calls struct { - // CacheMultiStore holds details about calls to the CacheMultiStore method. - CacheMultiStore []struct { - } - // CacheMultiStoreWithVersion holds details about calls to the CacheMultiStoreWithVersion method. - CacheMultiStoreWithVersion []struct { - // Version is the version argument value. - Version int64 - } - // CacheWrap holds details about calls to the CacheWrap method. - CacheWrap []struct { - } - // CacheWrapWithTrace holds details about calls to the CacheWrapWithTrace method. - CacheWrapWithTrace []struct { - // W is the w argument value. - W io.Writer - // Tc is the tc argument value. - Tc storetypes.TraceContext - } - // GetKVStore holds details about calls to the GetKVStore method. - GetKVStore []struct { - // StoreKey is the storeKey argument value. - StoreKey storetypes.StoreKey - } - // GetStore holds details about calls to the GetStore method. - GetStore []struct { - // StoreKey is the storeKey argument value. - StoreKey storetypes.StoreKey - } - // GetStoreType holds details about calls to the GetStoreType method. - GetStoreType []struct { - } - // LatestVersion holds details about calls to the LatestVersion method. - LatestVersion []struct { - } - // SetTracer holds details about calls to the SetTracer method. - SetTracer []struct { - // W is the w argument value. - W io.Writer - } - // SetTracingContext holds details about calls to the SetTracingContext method. - SetTracingContext []struct { - // TraceContext is the traceContext argument value. - TraceContext storetypes.TraceContext - } - // TracingEnabled holds details about calls to the TracingEnabled method. - TracingEnabled []struct { - } - } - lockCacheMultiStore sync.RWMutex - lockCacheMultiStoreWithVersion sync.RWMutex - lockCacheWrap sync.RWMutex - lockCacheWrapWithTrace sync.RWMutex - lockGetKVStore sync.RWMutex - lockGetStore sync.RWMutex - lockGetStoreType sync.RWMutex - lockLatestVersion sync.RWMutex - lockSetTracer sync.RWMutex - lockSetTracingContext sync.RWMutex - lockTracingEnabled sync.RWMutex -} - -// CacheMultiStore calls CacheMultiStoreFunc. -func (mock *MultiStoreMock) CacheMultiStore() storetypes.CacheMultiStore { - if mock.CacheMultiStoreFunc == nil { - panic("MultiStoreMock.CacheMultiStoreFunc: method is nil but MultiStore.CacheMultiStore was just called") - } - callInfo := struct { - }{} - mock.lockCacheMultiStore.Lock() - mock.calls.CacheMultiStore = append(mock.calls.CacheMultiStore, callInfo) - mock.lockCacheMultiStore.Unlock() - return mock.CacheMultiStoreFunc() -} - -// CacheMultiStoreCalls gets all the calls that were made to CacheMultiStore. -// Check the length with: -// -// len(mockedMultiStore.CacheMultiStoreCalls()) -func (mock *MultiStoreMock) CacheMultiStoreCalls() []struct { -} { - var calls []struct { - } - mock.lockCacheMultiStore.RLock() - calls = mock.calls.CacheMultiStore - mock.lockCacheMultiStore.RUnlock() - return calls -} - -// CacheMultiStoreWithVersion calls CacheMultiStoreWithVersionFunc. -func (mock *MultiStoreMock) CacheMultiStoreWithVersion(version int64) (storetypes.CacheMultiStore, error) { - if mock.CacheMultiStoreWithVersionFunc == nil { - panic("MultiStoreMock.CacheMultiStoreWithVersionFunc: method is nil but MultiStore.CacheMultiStoreWithVersion was just called") - } - callInfo := struct { - Version int64 - }{ - Version: version, - } - mock.lockCacheMultiStoreWithVersion.Lock() - mock.calls.CacheMultiStoreWithVersion = append(mock.calls.CacheMultiStoreWithVersion, callInfo) - mock.lockCacheMultiStoreWithVersion.Unlock() - return mock.CacheMultiStoreWithVersionFunc(version) -} - -// CacheMultiStoreWithVersionCalls gets all the calls that were made to CacheMultiStoreWithVersion. -// Check the length with: -// -// len(mockedMultiStore.CacheMultiStoreWithVersionCalls()) -func (mock *MultiStoreMock) CacheMultiStoreWithVersionCalls() []struct { - Version int64 -} { - var calls []struct { - Version int64 - } - mock.lockCacheMultiStoreWithVersion.RLock() - calls = mock.calls.CacheMultiStoreWithVersion - mock.lockCacheMultiStoreWithVersion.RUnlock() - return calls -} - -// CacheWrap calls CacheWrapFunc. -func (mock *MultiStoreMock) CacheWrap() storetypes.CacheWrap { - if mock.CacheWrapFunc == nil { - panic("MultiStoreMock.CacheWrapFunc: method is nil but MultiStore.CacheWrap was just called") - } - callInfo := struct { - }{} - mock.lockCacheWrap.Lock() - mock.calls.CacheWrap = append(mock.calls.CacheWrap, callInfo) - mock.lockCacheWrap.Unlock() - return mock.CacheWrapFunc() -} - -// CacheWrapCalls gets all the calls that were made to CacheWrap. -// Check the length with: -// -// len(mockedMultiStore.CacheWrapCalls()) -func (mock *MultiStoreMock) CacheWrapCalls() []struct { -} { - var calls []struct { - } - mock.lockCacheWrap.RLock() - calls = mock.calls.CacheWrap - mock.lockCacheWrap.RUnlock() - return calls -} - -// CacheWrapWithTrace calls CacheWrapWithTraceFunc. -func (mock *MultiStoreMock) CacheWrapWithTrace(w io.Writer, tc storetypes.TraceContext) storetypes.CacheWrap { - if mock.CacheWrapWithTraceFunc == nil { - panic("MultiStoreMock.CacheWrapWithTraceFunc: method is nil but MultiStore.CacheWrapWithTrace was just called") - } - callInfo := struct { - W io.Writer - Tc storetypes.TraceContext - }{ - W: w, - Tc: tc, - } - mock.lockCacheWrapWithTrace.Lock() - mock.calls.CacheWrapWithTrace = append(mock.calls.CacheWrapWithTrace, callInfo) - mock.lockCacheWrapWithTrace.Unlock() - return mock.CacheWrapWithTraceFunc(w, tc) -} - -// CacheWrapWithTraceCalls gets all the calls that were made to CacheWrapWithTrace. -// Check the length with: -// -// len(mockedMultiStore.CacheWrapWithTraceCalls()) -func (mock *MultiStoreMock) CacheWrapWithTraceCalls() []struct { - W io.Writer - Tc storetypes.TraceContext -} { - var calls []struct { - W io.Writer - Tc storetypes.TraceContext - } - mock.lockCacheWrapWithTrace.RLock() - calls = mock.calls.CacheWrapWithTrace - mock.lockCacheWrapWithTrace.RUnlock() - return calls -} - -// GetKVStore calls GetKVStoreFunc. -func (mock *MultiStoreMock) GetKVStore(storeKey storetypes.StoreKey) storetypes.KVStore { - if mock.GetKVStoreFunc == nil { - panic("MultiStoreMock.GetKVStoreFunc: method is nil but MultiStore.GetKVStore was just called") - } - callInfo := struct { - StoreKey storetypes.StoreKey - }{ - StoreKey: storeKey, - } - mock.lockGetKVStore.Lock() - mock.calls.GetKVStore = append(mock.calls.GetKVStore, callInfo) - mock.lockGetKVStore.Unlock() - return mock.GetKVStoreFunc(storeKey) -} - -// GetKVStoreCalls gets all the calls that were made to GetKVStore. -// Check the length with: -// -// len(mockedMultiStore.GetKVStoreCalls()) -func (mock *MultiStoreMock) GetKVStoreCalls() []struct { - StoreKey storetypes.StoreKey -} { - var calls []struct { - StoreKey storetypes.StoreKey - } - mock.lockGetKVStore.RLock() - calls = mock.calls.GetKVStore - mock.lockGetKVStore.RUnlock() - return calls -} - -// GetStore calls GetStoreFunc. -func (mock *MultiStoreMock) GetStore(storeKey storetypes.StoreKey) storetypes.Store { - if mock.GetStoreFunc == nil { - panic("MultiStoreMock.GetStoreFunc: method is nil but MultiStore.GetStore was just called") - } - callInfo := struct { - StoreKey storetypes.StoreKey - }{ - StoreKey: storeKey, - } - mock.lockGetStore.Lock() - mock.calls.GetStore = append(mock.calls.GetStore, callInfo) - mock.lockGetStore.Unlock() - return mock.GetStoreFunc(storeKey) -} - -// GetStoreCalls gets all the calls that were made to GetStore. -// Check the length with: -// -// len(mockedMultiStore.GetStoreCalls()) -func (mock *MultiStoreMock) GetStoreCalls() []struct { - StoreKey storetypes.StoreKey -} { - var calls []struct { - StoreKey storetypes.StoreKey - } - mock.lockGetStore.RLock() - calls = mock.calls.GetStore - mock.lockGetStore.RUnlock() - return calls -} - -// GetStoreType calls GetStoreTypeFunc. -func (mock *MultiStoreMock) GetStoreType() storetypes.StoreType { - if mock.GetStoreTypeFunc == nil { - panic("MultiStoreMock.GetStoreTypeFunc: method is nil but MultiStore.GetStoreType was just called") - } - callInfo := struct { - }{} - mock.lockGetStoreType.Lock() - mock.calls.GetStoreType = append(mock.calls.GetStoreType, callInfo) - mock.lockGetStoreType.Unlock() - return mock.GetStoreTypeFunc() -} - -// GetStoreTypeCalls gets all the calls that were made to GetStoreType. -// Check the length with: -// -// len(mockedMultiStore.GetStoreTypeCalls()) -func (mock *MultiStoreMock) GetStoreTypeCalls() []struct { -} { - var calls []struct { - } - mock.lockGetStoreType.RLock() - calls = mock.calls.GetStoreType - mock.lockGetStoreType.RUnlock() - return calls -} - -// LatestVersion calls LatestVersionFunc. -func (mock *MultiStoreMock) LatestVersion() int64 { - if mock.LatestVersionFunc == nil { - panic("MultiStoreMock.LatestVersionFunc: method is nil but MultiStore.LatestVersion was just called") - } - callInfo := struct { - }{} - mock.lockLatestVersion.Lock() - mock.calls.LatestVersion = append(mock.calls.LatestVersion, callInfo) - mock.lockLatestVersion.Unlock() - return mock.LatestVersionFunc() -} - -// LatestVersionCalls gets all the calls that were made to LatestVersion. -// Check the length with: -// -// len(mockedMultiStore.LatestVersionCalls()) -func (mock *MultiStoreMock) LatestVersionCalls() []struct { -} { - var calls []struct { - } - mock.lockLatestVersion.RLock() - calls = mock.calls.LatestVersion - mock.lockLatestVersion.RUnlock() - return calls -} - -// SetTracer calls SetTracerFunc. -func (mock *MultiStoreMock) SetTracer(w io.Writer) storetypes.MultiStore { - if mock.SetTracerFunc == nil { - panic("MultiStoreMock.SetTracerFunc: method is nil but MultiStore.SetTracer was just called") - } - callInfo := struct { - W io.Writer - }{ - W: w, - } - mock.lockSetTracer.Lock() - mock.calls.SetTracer = append(mock.calls.SetTracer, callInfo) - mock.lockSetTracer.Unlock() - return mock.SetTracerFunc(w) -} - -// SetTracerCalls gets all the calls that were made to SetTracer. -// Check the length with: -// -// len(mockedMultiStore.SetTracerCalls()) -func (mock *MultiStoreMock) SetTracerCalls() []struct { - W io.Writer -} { - var calls []struct { - W io.Writer - } - mock.lockSetTracer.RLock() - calls = mock.calls.SetTracer - mock.lockSetTracer.RUnlock() - return calls -} - -// SetTracingContext calls SetTracingContextFunc. -func (mock *MultiStoreMock) SetTracingContext(traceContext storetypes.TraceContext) storetypes.MultiStore { - if mock.SetTracingContextFunc == nil { - panic("MultiStoreMock.SetTracingContextFunc: method is nil but MultiStore.SetTracingContext was just called") - } - callInfo := struct { - TraceContext storetypes.TraceContext - }{ - TraceContext: traceContext, - } - mock.lockSetTracingContext.Lock() - mock.calls.SetTracingContext = append(mock.calls.SetTracingContext, callInfo) - mock.lockSetTracingContext.Unlock() - return mock.SetTracingContextFunc(traceContext) -} - -// SetTracingContextCalls gets all the calls that were made to SetTracingContext. -// Check the length with: -// -// len(mockedMultiStore.SetTracingContextCalls()) -func (mock *MultiStoreMock) SetTracingContextCalls() []struct { - TraceContext storetypes.TraceContext -} { - var calls []struct { - TraceContext storetypes.TraceContext - } - mock.lockSetTracingContext.RLock() - calls = mock.calls.SetTracingContext - mock.lockSetTracingContext.RUnlock() - return calls -} - -// TracingEnabled calls TracingEnabledFunc. -func (mock *MultiStoreMock) TracingEnabled() bool { - if mock.TracingEnabledFunc == nil { - panic("MultiStoreMock.TracingEnabledFunc: method is nil but MultiStore.TracingEnabled was just called") - } - callInfo := struct { - }{} - mock.lockTracingEnabled.Lock() - mock.calls.TracingEnabled = append(mock.calls.TracingEnabled, callInfo) - mock.lockTracingEnabled.Unlock() - return mock.TracingEnabledFunc() -} - -// TracingEnabledCalls gets all the calls that were made to TracingEnabled. -// Check the length with: -// -// len(mockedMultiStore.TracingEnabledCalls()) -func (mock *MultiStoreMock) TracingEnabledCalls() []struct { -} { - var calls []struct { - } - mock.lockTracingEnabled.RLock() - calls = mock.calls.TracingEnabled - mock.lockTracingEnabled.RUnlock() - return calls -} - -// Ensure, that CacheMultiStoreMock does implement interfaces.CacheMultiStore. -// If this is not the case, regenerate this file with moq. -var _ interfaces.CacheMultiStore = &CacheMultiStoreMock{} - -// CacheMultiStoreMock is a mock implementation of interfaces.CacheMultiStore. -// -// func TestSomethingThatUsesCacheMultiStore(t *testing.T) { -// -// // make and configure a mocked interfaces.CacheMultiStore -// mockedCacheMultiStore := &CacheMultiStoreMock{ -// CacheMultiStoreFunc: func() storetypes.CacheMultiStore { -// panic("mock out the CacheMultiStore method") -// }, -// CacheMultiStoreWithVersionFunc: func(version int64) (storetypes.CacheMultiStore, error) { -// panic("mock out the CacheMultiStoreWithVersion method") -// }, -// CacheWrapFunc: func() storetypes.CacheWrap { -// panic("mock out the CacheWrap method") -// }, -// CacheWrapWithTraceFunc: func(w io.Writer, tc storetypes.TraceContext) storetypes.CacheWrap { -// panic("mock out the CacheWrapWithTrace method") -// }, -// GetKVStoreFunc: func(storeKey storetypes.StoreKey) storetypes.KVStore { -// panic("mock out the GetKVStore method") -// }, -// GetStoreFunc: func(storeKey storetypes.StoreKey) storetypes.Store { -// panic("mock out the GetStore method") -// }, -// GetStoreTypeFunc: func() storetypes.StoreType { -// panic("mock out the GetStoreType method") -// }, -// LatestVersionFunc: func() int64 { -// panic("mock out the LatestVersion method") -// }, -// SetTracerFunc: func(w io.Writer) storetypes.MultiStore { -// panic("mock out the SetTracer method") -// }, -// SetTracingContextFunc: func(traceContext storetypes.TraceContext) storetypes.MultiStore { -// panic("mock out the SetTracingContext method") -// }, -// TracingEnabledFunc: func() bool { -// panic("mock out the TracingEnabled method") -// }, -// WriteFunc: func() { -// panic("mock out the Write method") -// }, -// } -// -// // use mockedCacheMultiStore in code that requires interfaces.CacheMultiStore -// // and then make assertions. -// -// } -type CacheMultiStoreMock struct { - // CacheMultiStoreFunc mocks the CacheMultiStore method. - CacheMultiStoreFunc func() storetypes.CacheMultiStore - - // CacheMultiStoreWithVersionFunc mocks the CacheMultiStoreWithVersion method. - CacheMultiStoreWithVersionFunc func(version int64) (storetypes.CacheMultiStore, error) - - // CacheWrapFunc mocks the CacheWrap method. - CacheWrapFunc func() storetypes.CacheWrap - - // CacheWrapWithTraceFunc mocks the CacheWrapWithTrace method. - CacheWrapWithTraceFunc func(w io.Writer, tc storetypes.TraceContext) storetypes.CacheWrap - - // GetKVStoreFunc mocks the GetKVStore method. - GetKVStoreFunc func(storeKey storetypes.StoreKey) storetypes.KVStore - - // GetStoreFunc mocks the GetStore method. - GetStoreFunc func(storeKey storetypes.StoreKey) storetypes.Store - - // GetStoreTypeFunc mocks the GetStoreType method. - GetStoreTypeFunc func() storetypes.StoreType - - // LatestVersionFunc mocks the LatestVersion method. - LatestVersionFunc func() int64 - - // SetTracerFunc mocks the SetTracer method. - SetTracerFunc func(w io.Writer) storetypes.MultiStore - - // SetTracingContextFunc mocks the SetTracingContext method. - SetTracingContextFunc func(traceContext storetypes.TraceContext) storetypes.MultiStore - - // TracingEnabledFunc mocks the TracingEnabled method. - TracingEnabledFunc func() bool - - // WriteFunc mocks the Write method. - WriteFunc func() - - // calls tracks calls to the methods. - calls struct { - // CacheMultiStore holds details about calls to the CacheMultiStore method. - CacheMultiStore []struct { - } - // CacheMultiStoreWithVersion holds details about calls to the CacheMultiStoreWithVersion method. - CacheMultiStoreWithVersion []struct { - // Version is the version argument value. - Version int64 - } - // CacheWrap holds details about calls to the CacheWrap method. - CacheWrap []struct { - } - // CacheWrapWithTrace holds details about calls to the CacheWrapWithTrace method. - CacheWrapWithTrace []struct { - // W is the w argument value. - W io.Writer - // Tc is the tc argument value. - Tc storetypes.TraceContext - } - // GetKVStore holds details about calls to the GetKVStore method. - GetKVStore []struct { - // StoreKey is the storeKey argument value. - StoreKey storetypes.StoreKey - } - // GetStore holds details about calls to the GetStore method. - GetStore []struct { - // StoreKey is the storeKey argument value. - StoreKey storetypes.StoreKey - } - // GetStoreType holds details about calls to the GetStoreType method. - GetStoreType []struct { - } - // LatestVersion holds details about calls to the LatestVersion method. - LatestVersion []struct { - } - // SetTracer holds details about calls to the SetTracer method. - SetTracer []struct { - // W is the w argument value. - W io.Writer - } - // SetTracingContext holds details about calls to the SetTracingContext method. - SetTracingContext []struct { - // TraceContext is the traceContext argument value. - TraceContext storetypes.TraceContext - } - // TracingEnabled holds details about calls to the TracingEnabled method. - TracingEnabled []struct { - } - // Write holds details about calls to the Write method. - Write []struct { - } - } - lockCacheMultiStore sync.RWMutex - lockCacheMultiStoreWithVersion sync.RWMutex - lockCacheWrap sync.RWMutex - lockCacheWrapWithTrace sync.RWMutex - lockGetKVStore sync.RWMutex - lockGetStore sync.RWMutex - lockGetStoreType sync.RWMutex - lockLatestVersion sync.RWMutex - lockSetTracer sync.RWMutex - lockSetTracingContext sync.RWMutex - lockTracingEnabled sync.RWMutex - lockWrite sync.RWMutex -} - -// CacheMultiStore calls CacheMultiStoreFunc. -func (mock *CacheMultiStoreMock) CacheMultiStore() storetypes.CacheMultiStore { - if mock.CacheMultiStoreFunc == nil { - panic("CacheMultiStoreMock.CacheMultiStoreFunc: method is nil but CacheMultiStore.CacheMultiStore was just called") - } - callInfo := struct { - }{} - mock.lockCacheMultiStore.Lock() - mock.calls.CacheMultiStore = append(mock.calls.CacheMultiStore, callInfo) - mock.lockCacheMultiStore.Unlock() - return mock.CacheMultiStoreFunc() -} - -// CacheMultiStoreCalls gets all the calls that were made to CacheMultiStore. -// Check the length with: -// -// len(mockedCacheMultiStore.CacheMultiStoreCalls()) -func (mock *CacheMultiStoreMock) CacheMultiStoreCalls() []struct { -} { - var calls []struct { - } - mock.lockCacheMultiStore.RLock() - calls = mock.calls.CacheMultiStore - mock.lockCacheMultiStore.RUnlock() - return calls -} - -// CacheMultiStoreWithVersion calls CacheMultiStoreWithVersionFunc. -func (mock *CacheMultiStoreMock) CacheMultiStoreWithVersion(version int64) (storetypes.CacheMultiStore, error) { - if mock.CacheMultiStoreWithVersionFunc == nil { - panic("CacheMultiStoreMock.CacheMultiStoreWithVersionFunc: method is nil but CacheMultiStore.CacheMultiStoreWithVersion was just called") - } - callInfo := struct { - Version int64 - }{ - Version: version, - } - mock.lockCacheMultiStoreWithVersion.Lock() - mock.calls.CacheMultiStoreWithVersion = append(mock.calls.CacheMultiStoreWithVersion, callInfo) - mock.lockCacheMultiStoreWithVersion.Unlock() - return mock.CacheMultiStoreWithVersionFunc(version) -} - -// CacheMultiStoreWithVersionCalls gets all the calls that were made to CacheMultiStoreWithVersion. -// Check the length with: -// -// len(mockedCacheMultiStore.CacheMultiStoreWithVersionCalls()) -func (mock *CacheMultiStoreMock) CacheMultiStoreWithVersionCalls() []struct { - Version int64 -} { - var calls []struct { - Version int64 - } - mock.lockCacheMultiStoreWithVersion.RLock() - calls = mock.calls.CacheMultiStoreWithVersion - mock.lockCacheMultiStoreWithVersion.RUnlock() - return calls -} - -// CacheWrap calls CacheWrapFunc. -func (mock *CacheMultiStoreMock) CacheWrap() storetypes.CacheWrap { - if mock.CacheWrapFunc == nil { - panic("CacheMultiStoreMock.CacheWrapFunc: method is nil but CacheMultiStore.CacheWrap was just called") - } - callInfo := struct { - }{} - mock.lockCacheWrap.Lock() - mock.calls.CacheWrap = append(mock.calls.CacheWrap, callInfo) - mock.lockCacheWrap.Unlock() - return mock.CacheWrapFunc() -} - -// CacheWrapCalls gets all the calls that were made to CacheWrap. -// Check the length with: -// -// len(mockedCacheMultiStore.CacheWrapCalls()) -func (mock *CacheMultiStoreMock) CacheWrapCalls() []struct { -} { - var calls []struct { - } - mock.lockCacheWrap.RLock() - calls = mock.calls.CacheWrap - mock.lockCacheWrap.RUnlock() - return calls -} - -// CacheWrapWithTrace calls CacheWrapWithTraceFunc. -func (mock *CacheMultiStoreMock) CacheWrapWithTrace(w io.Writer, tc storetypes.TraceContext) storetypes.CacheWrap { - if mock.CacheWrapWithTraceFunc == nil { - panic("CacheMultiStoreMock.CacheWrapWithTraceFunc: method is nil but CacheMultiStore.CacheWrapWithTrace was just called") - } - callInfo := struct { - W io.Writer - Tc storetypes.TraceContext - }{ - W: w, - Tc: tc, - } - mock.lockCacheWrapWithTrace.Lock() - mock.calls.CacheWrapWithTrace = append(mock.calls.CacheWrapWithTrace, callInfo) - mock.lockCacheWrapWithTrace.Unlock() - return mock.CacheWrapWithTraceFunc(w, tc) -} - -// CacheWrapWithTraceCalls gets all the calls that were made to CacheWrapWithTrace. -// Check the length with: -// -// len(mockedCacheMultiStore.CacheWrapWithTraceCalls()) -func (mock *CacheMultiStoreMock) CacheWrapWithTraceCalls() []struct { - W io.Writer - Tc storetypes.TraceContext -} { - var calls []struct { - W io.Writer - Tc storetypes.TraceContext - } - mock.lockCacheWrapWithTrace.RLock() - calls = mock.calls.CacheWrapWithTrace - mock.lockCacheWrapWithTrace.RUnlock() - return calls -} - -// GetKVStore calls GetKVStoreFunc. -func (mock *CacheMultiStoreMock) GetKVStore(storeKey storetypes.StoreKey) storetypes.KVStore { - if mock.GetKVStoreFunc == nil { - panic("CacheMultiStoreMock.GetKVStoreFunc: method is nil but CacheMultiStore.GetKVStore was just called") - } - callInfo := struct { - StoreKey storetypes.StoreKey - }{ - StoreKey: storeKey, - } - mock.lockGetKVStore.Lock() - mock.calls.GetKVStore = append(mock.calls.GetKVStore, callInfo) - mock.lockGetKVStore.Unlock() - return mock.GetKVStoreFunc(storeKey) -} - -// GetKVStoreCalls gets all the calls that were made to GetKVStore. -// Check the length with: -// -// len(mockedCacheMultiStore.GetKVStoreCalls()) -func (mock *CacheMultiStoreMock) GetKVStoreCalls() []struct { - StoreKey storetypes.StoreKey -} { - var calls []struct { - StoreKey storetypes.StoreKey - } - mock.lockGetKVStore.RLock() - calls = mock.calls.GetKVStore - mock.lockGetKVStore.RUnlock() - return calls -} - -// GetStore calls GetStoreFunc. -func (mock *CacheMultiStoreMock) GetStore(storeKey storetypes.StoreKey) storetypes.Store { - if mock.GetStoreFunc == nil { - panic("CacheMultiStoreMock.GetStoreFunc: method is nil but CacheMultiStore.GetStore was just called") - } - callInfo := struct { - StoreKey storetypes.StoreKey - }{ - StoreKey: storeKey, - } - mock.lockGetStore.Lock() - mock.calls.GetStore = append(mock.calls.GetStore, callInfo) - mock.lockGetStore.Unlock() - return mock.GetStoreFunc(storeKey) -} - -// GetStoreCalls gets all the calls that were made to GetStore. -// Check the length with: -// -// len(mockedCacheMultiStore.GetStoreCalls()) -func (mock *CacheMultiStoreMock) GetStoreCalls() []struct { - StoreKey storetypes.StoreKey -} { - var calls []struct { - StoreKey storetypes.StoreKey - } - mock.lockGetStore.RLock() - calls = mock.calls.GetStore - mock.lockGetStore.RUnlock() - return calls -} - -// GetStoreType calls GetStoreTypeFunc. -func (mock *CacheMultiStoreMock) GetStoreType() storetypes.StoreType { - if mock.GetStoreTypeFunc == nil { - panic("CacheMultiStoreMock.GetStoreTypeFunc: method is nil but CacheMultiStore.GetStoreType was just called") - } - callInfo := struct { - }{} - mock.lockGetStoreType.Lock() - mock.calls.GetStoreType = append(mock.calls.GetStoreType, callInfo) - mock.lockGetStoreType.Unlock() - return mock.GetStoreTypeFunc() -} - -// GetStoreTypeCalls gets all the calls that were made to GetStoreType. -// Check the length with: -// -// len(mockedCacheMultiStore.GetStoreTypeCalls()) -func (mock *CacheMultiStoreMock) GetStoreTypeCalls() []struct { -} { - var calls []struct { - } - mock.lockGetStoreType.RLock() - calls = mock.calls.GetStoreType - mock.lockGetStoreType.RUnlock() - return calls -} - -// LatestVersion calls LatestVersionFunc. -func (mock *CacheMultiStoreMock) LatestVersion() int64 { - if mock.LatestVersionFunc == nil { - panic("CacheMultiStoreMock.LatestVersionFunc: method is nil but CacheMultiStore.LatestVersion was just called") - } - callInfo := struct { - }{} - mock.lockLatestVersion.Lock() - mock.calls.LatestVersion = append(mock.calls.LatestVersion, callInfo) - mock.lockLatestVersion.Unlock() - return mock.LatestVersionFunc() -} - -// LatestVersionCalls gets all the calls that were made to LatestVersion. -// Check the length with: -// -// len(mockedCacheMultiStore.LatestVersionCalls()) -func (mock *CacheMultiStoreMock) LatestVersionCalls() []struct { -} { - var calls []struct { - } - mock.lockLatestVersion.RLock() - calls = mock.calls.LatestVersion - mock.lockLatestVersion.RUnlock() - return calls -} - -// SetTracer calls SetTracerFunc. -func (mock *CacheMultiStoreMock) SetTracer(w io.Writer) storetypes.MultiStore { - if mock.SetTracerFunc == nil { - panic("CacheMultiStoreMock.SetTracerFunc: method is nil but CacheMultiStore.SetTracer was just called") - } - callInfo := struct { - W io.Writer - }{ - W: w, - } - mock.lockSetTracer.Lock() - mock.calls.SetTracer = append(mock.calls.SetTracer, callInfo) - mock.lockSetTracer.Unlock() - return mock.SetTracerFunc(w) -} - -// SetTracerCalls gets all the calls that were made to SetTracer. -// Check the length with: -// -// len(mockedCacheMultiStore.SetTracerCalls()) -func (mock *CacheMultiStoreMock) SetTracerCalls() []struct { - W io.Writer -} { - var calls []struct { - W io.Writer - } - mock.lockSetTracer.RLock() - calls = mock.calls.SetTracer - mock.lockSetTracer.RUnlock() - return calls -} - -// SetTracingContext calls SetTracingContextFunc. -func (mock *CacheMultiStoreMock) SetTracingContext(traceContext storetypes.TraceContext) storetypes.MultiStore { - if mock.SetTracingContextFunc == nil { - panic("CacheMultiStoreMock.SetTracingContextFunc: method is nil but CacheMultiStore.SetTracingContext was just called") - } - callInfo := struct { - TraceContext storetypes.TraceContext - }{ - TraceContext: traceContext, - } - mock.lockSetTracingContext.Lock() - mock.calls.SetTracingContext = append(mock.calls.SetTracingContext, callInfo) - mock.lockSetTracingContext.Unlock() - return mock.SetTracingContextFunc(traceContext) -} - -// SetTracingContextCalls gets all the calls that were made to SetTracingContext. -// Check the length with: -// -// len(mockedCacheMultiStore.SetTracingContextCalls()) -func (mock *CacheMultiStoreMock) SetTracingContextCalls() []struct { - TraceContext storetypes.TraceContext -} { - var calls []struct { - TraceContext storetypes.TraceContext - } - mock.lockSetTracingContext.RLock() - calls = mock.calls.SetTracingContext - mock.lockSetTracingContext.RUnlock() - return calls -} - -// TracingEnabled calls TracingEnabledFunc. -func (mock *CacheMultiStoreMock) TracingEnabled() bool { - if mock.TracingEnabledFunc == nil { - panic("CacheMultiStoreMock.TracingEnabledFunc: method is nil but CacheMultiStore.TracingEnabled was just called") - } - callInfo := struct { - }{} - mock.lockTracingEnabled.Lock() - mock.calls.TracingEnabled = append(mock.calls.TracingEnabled, callInfo) - mock.lockTracingEnabled.Unlock() - return mock.TracingEnabledFunc() -} - -// TracingEnabledCalls gets all the calls that were made to TracingEnabled. -// Check the length with: -// -// len(mockedCacheMultiStore.TracingEnabledCalls()) -func (mock *CacheMultiStoreMock) TracingEnabledCalls() []struct { -} { - var calls []struct { - } - mock.lockTracingEnabled.RLock() - calls = mock.calls.TracingEnabled - mock.lockTracingEnabled.RUnlock() - return calls -} - -// Write calls WriteFunc. -func (mock *CacheMultiStoreMock) Write() { - if mock.WriteFunc == nil { - panic("CacheMultiStoreMock.WriteFunc: method is nil but CacheMultiStore.Write was just called") - } - callInfo := struct { - }{} - mock.lockWrite.Lock() - mock.calls.Write = append(mock.calls.Write, callInfo) - mock.lockWrite.Unlock() - mock.WriteFunc() -} - -// WriteCalls gets all the calls that were made to Write. -// Check the length with: -// -// len(mockedCacheMultiStore.WriteCalls()) -func (mock *CacheMultiStoreMock) WriteCalls() []struct { -} { - var calls []struct { - } - mock.lockWrite.RLock() - calls = mock.calls.Write - mock.lockWrite.RUnlock() - return calls -} - -// Ensure, that KVStoreMock does implement interfaces.KVStore. -// If this is not the case, regenerate this file with moq. -var _ interfaces.KVStore = &KVStoreMock{} - -// KVStoreMock is a mock implementation of interfaces.KVStore. -// -// func TestSomethingThatUsesKVStore(t *testing.T) { -// -// // make and configure a mocked interfaces.KVStore -// mockedKVStore := &KVStoreMock{ -// CacheWrapFunc: func() storetypes.CacheWrap { -// panic("mock out the CacheWrap method") -// }, -// CacheWrapWithTraceFunc: func(w io.Writer, tc storetypes.TraceContext) storetypes.CacheWrap { -// panic("mock out the CacheWrapWithTrace method") -// }, -// DeleteFunc: func(key []byte) { -// panic("mock out the Delete method") -// }, -// GetFunc: func(key []byte) []byte { -// panic("mock out the Get method") -// }, -// GetStoreTypeFunc: func() storetypes.StoreType { -// panic("mock out the GetStoreType method") -// }, -// HasFunc: func(key []byte) bool { -// panic("mock out the Has method") -// }, -// IteratorFunc: func(start []byte, end []byte) db.Iterator { -// panic("mock out the Iterator method") -// }, -// ReverseIteratorFunc: func(start []byte, end []byte) db.Iterator { -// panic("mock out the ReverseIterator method") -// }, -// SetFunc: func(key []byte, value []byte) { -// panic("mock out the Set method") -// }, -// } -// -// // use mockedKVStore in code that requires interfaces.KVStore -// // and then make assertions. -// -// } -type KVStoreMock struct { - // CacheWrapFunc mocks the CacheWrap method. - CacheWrapFunc func() storetypes.CacheWrap - - // CacheWrapWithTraceFunc mocks the CacheWrapWithTrace method. - CacheWrapWithTraceFunc func(w io.Writer, tc storetypes.TraceContext) storetypes.CacheWrap - - // DeleteFunc mocks the Delete method. - DeleteFunc func(key []byte) - - // GetFunc mocks the Get method. - GetFunc func(key []byte) []byte - - // GetStoreTypeFunc mocks the GetStoreType method. - GetStoreTypeFunc func() storetypes.StoreType - - // HasFunc mocks the Has method. - HasFunc func(key []byte) bool - - // IteratorFunc mocks the Iterator method. - IteratorFunc func(start []byte, end []byte) db.Iterator - - // ReverseIteratorFunc mocks the ReverseIterator method. - ReverseIteratorFunc func(start []byte, end []byte) db.Iterator - - // SetFunc mocks the Set method. - SetFunc func(key []byte, value []byte) - - // calls tracks calls to the methods. - calls struct { - // CacheWrap holds details about calls to the CacheWrap method. - CacheWrap []struct { - } - // CacheWrapWithTrace holds details about calls to the CacheWrapWithTrace method. - CacheWrapWithTrace []struct { - // W is the w argument value. - W io.Writer - // Tc is the tc argument value. - Tc storetypes.TraceContext - } - // Delete holds details about calls to the Delete method. - Delete []struct { - // Key is the key argument value. - Key []byte - } - // Get holds details about calls to the Get method. - Get []struct { - // Key is the key argument value. - Key []byte - } - // GetStoreType holds details about calls to the GetStoreType method. - GetStoreType []struct { - } - // Has holds details about calls to the Has method. - Has []struct { - // Key is the key argument value. - Key []byte - } - // Iterator holds details about calls to the Iterator method. - Iterator []struct { - // Start is the start argument value. - Start []byte - // End is the end argument value. - End []byte - } - // ReverseIterator holds details about calls to the ReverseIterator method. - ReverseIterator []struct { - // Start is the start argument value. - Start []byte - // End is the end argument value. - End []byte - } - // Set holds details about calls to the Set method. - Set []struct { - // Key is the key argument value. - Key []byte - // Value is the value argument value. - Value []byte - } - } - lockCacheWrap sync.RWMutex - lockCacheWrapWithTrace sync.RWMutex - lockDelete sync.RWMutex - lockGet sync.RWMutex - lockGetStoreType sync.RWMutex - lockHas sync.RWMutex - lockIterator sync.RWMutex - lockReverseIterator sync.RWMutex - lockSet sync.RWMutex -} - -// CacheWrap calls CacheWrapFunc. -func (mock *KVStoreMock) CacheWrap() storetypes.CacheWrap { - if mock.CacheWrapFunc == nil { - panic("KVStoreMock.CacheWrapFunc: method is nil but KVStore.CacheWrap was just called") - } - callInfo := struct { - }{} - mock.lockCacheWrap.Lock() - mock.calls.CacheWrap = append(mock.calls.CacheWrap, callInfo) - mock.lockCacheWrap.Unlock() - return mock.CacheWrapFunc() -} - -// CacheWrapCalls gets all the calls that were made to CacheWrap. -// Check the length with: -// -// len(mockedKVStore.CacheWrapCalls()) -func (mock *KVStoreMock) CacheWrapCalls() []struct { -} { - var calls []struct { - } - mock.lockCacheWrap.RLock() - calls = mock.calls.CacheWrap - mock.lockCacheWrap.RUnlock() - return calls -} - -// CacheWrapWithTrace calls CacheWrapWithTraceFunc. -func (mock *KVStoreMock) CacheWrapWithTrace(w io.Writer, tc storetypes.TraceContext) storetypes.CacheWrap { - if mock.CacheWrapWithTraceFunc == nil { - panic("KVStoreMock.CacheWrapWithTraceFunc: method is nil but KVStore.CacheWrapWithTrace was just called") - } - callInfo := struct { - W io.Writer - Tc storetypes.TraceContext - }{ - W: w, - Tc: tc, - } - mock.lockCacheWrapWithTrace.Lock() - mock.calls.CacheWrapWithTrace = append(mock.calls.CacheWrapWithTrace, callInfo) - mock.lockCacheWrapWithTrace.Unlock() - return mock.CacheWrapWithTraceFunc(w, tc) -} - -// CacheWrapWithTraceCalls gets all the calls that were made to CacheWrapWithTrace. -// Check the length with: -// -// len(mockedKVStore.CacheWrapWithTraceCalls()) -func (mock *KVStoreMock) CacheWrapWithTraceCalls() []struct { - W io.Writer - Tc storetypes.TraceContext -} { - var calls []struct { - W io.Writer - Tc storetypes.TraceContext - } - mock.lockCacheWrapWithTrace.RLock() - calls = mock.calls.CacheWrapWithTrace - mock.lockCacheWrapWithTrace.RUnlock() - return calls -} - -// Delete calls DeleteFunc. -func (mock *KVStoreMock) Delete(key []byte) { - if mock.DeleteFunc == nil { - panic("KVStoreMock.DeleteFunc: method is nil but KVStore.Delete was just called") - } - callInfo := struct { - Key []byte - }{ - Key: key, - } - mock.lockDelete.Lock() - mock.calls.Delete = append(mock.calls.Delete, callInfo) - mock.lockDelete.Unlock() - mock.DeleteFunc(key) -} - -// DeleteCalls gets all the calls that were made to Delete. -// Check the length with: -// -// len(mockedKVStore.DeleteCalls()) -func (mock *KVStoreMock) DeleteCalls() []struct { - Key []byte -} { - var calls []struct { - Key []byte - } - mock.lockDelete.RLock() - calls = mock.calls.Delete - mock.lockDelete.RUnlock() - return calls -} - -// Get calls GetFunc. -func (mock *KVStoreMock) Get(key []byte) []byte { - if mock.GetFunc == nil { - panic("KVStoreMock.GetFunc: method is nil but KVStore.Get was just called") - } - callInfo := struct { - Key []byte - }{ - Key: key, - } - mock.lockGet.Lock() - mock.calls.Get = append(mock.calls.Get, callInfo) - mock.lockGet.Unlock() - return mock.GetFunc(key) -} - -// GetCalls gets all the calls that were made to Get. -// Check the length with: -// -// len(mockedKVStore.GetCalls()) -func (mock *KVStoreMock) GetCalls() []struct { - Key []byte -} { - var calls []struct { - Key []byte - } - mock.lockGet.RLock() - calls = mock.calls.Get - mock.lockGet.RUnlock() - return calls -} - -// GetStoreType calls GetStoreTypeFunc. -func (mock *KVStoreMock) GetStoreType() storetypes.StoreType { - if mock.GetStoreTypeFunc == nil { - panic("KVStoreMock.GetStoreTypeFunc: method is nil but KVStore.GetStoreType was just called") - } - callInfo := struct { - }{} - mock.lockGetStoreType.Lock() - mock.calls.GetStoreType = append(mock.calls.GetStoreType, callInfo) - mock.lockGetStoreType.Unlock() - return mock.GetStoreTypeFunc() -} - -// GetStoreTypeCalls gets all the calls that were made to GetStoreType. -// Check the length with: -// -// len(mockedKVStore.GetStoreTypeCalls()) -func (mock *KVStoreMock) GetStoreTypeCalls() []struct { -} { - var calls []struct { - } - mock.lockGetStoreType.RLock() - calls = mock.calls.GetStoreType - mock.lockGetStoreType.RUnlock() - return calls -} - -// Has calls HasFunc. -func (mock *KVStoreMock) Has(key []byte) bool { - if mock.HasFunc == nil { - panic("KVStoreMock.HasFunc: method is nil but KVStore.Has was just called") - } - callInfo := struct { - Key []byte - }{ - Key: key, - } - mock.lockHas.Lock() - mock.calls.Has = append(mock.calls.Has, callInfo) - mock.lockHas.Unlock() - return mock.HasFunc(key) -} - -// HasCalls gets all the calls that were made to Has. -// Check the length with: -// -// len(mockedKVStore.HasCalls()) -func (mock *KVStoreMock) HasCalls() []struct { - Key []byte -} { - var calls []struct { - Key []byte - } - mock.lockHas.RLock() - calls = mock.calls.Has - mock.lockHas.RUnlock() - return calls -} - -// Iterator calls IteratorFunc. -func (mock *KVStoreMock) Iterator(start []byte, end []byte) db.Iterator { - if mock.IteratorFunc == nil { - panic("KVStoreMock.IteratorFunc: method is nil but KVStore.Iterator was just called") - } - callInfo := struct { - Start []byte - End []byte - }{ - Start: start, - End: end, - } - mock.lockIterator.Lock() - mock.calls.Iterator = append(mock.calls.Iterator, callInfo) - mock.lockIterator.Unlock() - return mock.IteratorFunc(start, end) -} - -// IteratorCalls gets all the calls that were made to Iterator. -// Check the length with: -// -// len(mockedKVStore.IteratorCalls()) -func (mock *KVStoreMock) IteratorCalls() []struct { - Start []byte - End []byte -} { - var calls []struct { - Start []byte - End []byte - } - mock.lockIterator.RLock() - calls = mock.calls.Iterator - mock.lockIterator.RUnlock() - return calls -} - -// ReverseIterator calls ReverseIteratorFunc. -func (mock *KVStoreMock) ReverseIterator(start []byte, end []byte) db.Iterator { - if mock.ReverseIteratorFunc == nil { - panic("KVStoreMock.ReverseIteratorFunc: method is nil but KVStore.ReverseIterator was just called") - } - callInfo := struct { - Start []byte - End []byte - }{ - Start: start, - End: end, - } - mock.lockReverseIterator.Lock() - mock.calls.ReverseIterator = append(mock.calls.ReverseIterator, callInfo) - mock.lockReverseIterator.Unlock() - return mock.ReverseIteratorFunc(start, end) -} - -// ReverseIteratorCalls gets all the calls that were made to ReverseIterator. -// Check the length with: -// -// len(mockedKVStore.ReverseIteratorCalls()) -func (mock *KVStoreMock) ReverseIteratorCalls() []struct { - Start []byte - End []byte -} { - var calls []struct { - Start []byte - End []byte - } - mock.lockReverseIterator.RLock() - calls = mock.calls.ReverseIterator - mock.lockReverseIterator.RUnlock() - return calls -} - -// Set calls SetFunc. -func (mock *KVStoreMock) Set(key []byte, value []byte) { - if mock.SetFunc == nil { - panic("KVStoreMock.SetFunc: method is nil but KVStore.Set was just called") - } - callInfo := struct { - Key []byte - Value []byte - }{ - Key: key, - Value: value, - } - mock.lockSet.Lock() - mock.calls.Set = append(mock.calls.Set, callInfo) - mock.lockSet.Unlock() - mock.SetFunc(key, value) -} - -// SetCalls gets all the calls that were made to Set. -// Check the length with: -// -// len(mockedKVStore.SetCalls()) -func (mock *KVStoreMock) SetCalls() []struct { - Key []byte - Value []byte -} { - var calls []struct { - Key []byte - Value []byte - } - mock.lockSet.RLock() - calls = mock.calls.Set - mock.lockSet.RUnlock() - return calls -} diff --git a/cosmos/testing/types/mock/interfaces/store.go b/cosmos/testing/types/mock/interfaces/store.go deleted file mode 100644 index 3e74a9f59..000000000 --- a/cosmos/testing/types/mock/interfaces/store.go +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-License-Identifier: BUSL-1.1 -// -// Copyright (C) 2023, Berachain Foundation. All rights reserved. -// Use of this software is govered by the Business Source License included -// in the LICENSE file of this repository and at www.mariadb.com/bsl11. -// -// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY -// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER -// VERSIONS OF THE LICENSED WORK. -// -// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF -// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF -// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). -// -// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON -// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, -// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND -// TITLE. - -package interfaces - -import storetypes "cosmossdk.io/store/types" - -// Interface wrappers for mocking -// -//go:generate moq -out ./mock/store.mock.go -pkg mock . MultiStore CacheMultiStore KVStore -type ( - // MultiStore wrapper for github.com/cosmos/cosmos-sdk/types.MultiStore. - MultiStore storetypes.MultiStore - // CacheMultiStore wrapper for github.com/cosmos/cosmos-sdk/types.CacheMultiStore. - CacheMultiStore storetypes.CacheMultiStore - // KVStore wrapper for github.com/cosmos/cosmos-sdk/types.KVStore. - KVStore storetypes.KVStore -) diff --git a/cosmos/testing/types/mock/store.go b/cosmos/testing/types/mock/store.go deleted file mode 100644 index 62b6f87d3..000000000 --- a/cosmos/testing/types/mock/store.go +++ /dev/null @@ -1,326 +0,0 @@ -// SPDX-License-Identifier: BUSL-1.1 -// -// Copyright (C) 2023, Berachain Foundation. All rights reserved. -// Use of this software is govered by the Business Source License included -// in the LICENSE file of this repository and at www.mariadb.com/bsl11. -// -// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY -// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER -// VERSIONS OF THE LICENSED WORK. -// -// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF -// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF -// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). -// -// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON -// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, -// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND -// TITLE. - -package mock - -import ( - "bytes" - "io" - "sort" - "sync" - - "cosmossdk.io/store/types" - - "pkg.berachain.dev/polaris/cosmos/testing/types/mock/interfaces" - "pkg.berachain.dev/polaris/cosmos/testing/types/mock/interfaces/mock" - "pkg.berachain.dev/polaris/lib/utils" -) - -// MultiStore is a simple multistore used for testing. -type MultiStore struct { - kvstore map[string]interfaces.KVStore - *mock.MultiStoreMock -} - -// MultiStore implements precompile.MultiStore. -func (m MultiStore) SetReadOnly(bool) {} - -// MultiStore implements precompile.MultiStore. -func (m MultiStore) IsReadOnly() bool { return false } - -// CachedMultiStore is a simple chached multistore for testing. -type CachedMultiStore struct { - kvstore map[string]interfaces.KVStore - *mock.CacheMultiStoreMock -} - -// NewMultiStore returns a new Multistore instance used for testing. -func NewMultiStore() types.MultiStore { - ms := MultiStore{ - kvstore: map[string]interfaces.KVStore{}, - MultiStoreMock: &mock.MultiStoreMock{}, - } - ms.GetKVStoreFunc = func(storeKey types.StoreKey) types.KVStore { - if store, ok := ms.kvstore[storeKey.String()]; ok { - return store - } - store := newTestKVStore() - ms.kvstore[storeKey.String()] = store - return store - } - - ms.CacheMultiStoreFunc = func() types.CacheMultiStore { - return NewCachedMultiStore(ms) - } - - return ms -} - -// NewCachedMultiStore returns a new CacheMultiStore instance for testing. -func NewCachedMultiStore(ms MultiStore) types.CacheMultiStore { - kvstore := map[string]interfaces.KVStore{} - - for key, store := range ms.kvstore { - kvstore[key] = utils.MustGetAs[interfaces.KVStore](store.CacheWrap()) - } - - cached := CachedMultiStore{ - kvstore: kvstore, - CacheMultiStoreMock: &mock.CacheMultiStoreMock{}, - } - cached.GetKVStoreFunc = func(storeKey types.StoreKey) types.KVStore { - if store, ok := cached.kvstore[storeKey.String()]; ok { - return store - } - store := newTestKVStore() - store.write = func() { - ms.kvstore[storeKey.String()] = store - } - cached.kvstore[storeKey.String()] = store - return store - } - - cached.WriteFunc = func() { - for _, store := range cached.kvstore { - utils.MustGetAs[*TestKVStore](store).Write() - } - } - return cached -} - -// TestKVStore is a kv store for testing. -type TestKVStore struct { - mutex *sync.RWMutex - store map[string][]byte - write func() -} - -func (t TestKVStore) Write() { - t.write() -} - -// newTestKVStore returns a new kv store instance for testing. -func newTestKVStore() *TestKVStore { - return &TestKVStore{ - mutex: &sync.RWMutex{}, - store: map[string][]byte{}, - write: func() {}, - } -} - -// GetStoreType is not implemented. -func (t TestKVStore) GetStoreType() types.StoreType { - panic("implement me") -} - -// CacheWrap is not implemented. -func (t *TestKVStore) CacheWrap() types.CacheWrap { - t.mutex.RLock() - defer t.mutex.RUnlock() - - cache := &TestKVStore{ - mutex: &sync.RWMutex{}, - store: map[string][]byte{}, - } - cache.write = func() { t.store = cache.store } - - for key, val := range t.store { - cache.store[key] = val - } - - return cache -} - -// CacheWrapWithTrace is not implemented. -func (t TestKVStore) CacheWrapWithTrace(_ io.Writer, _ types.TraceContext) types.CacheWrap { - panic("implement me") -} - -// Get returns the value of the given key, nil if it does not exist. -func (t TestKVStore) Get(key []byte) []byte { - t.mutex.RLock() - defer t.mutex.RUnlock() - val, ok := t.store[string(key)] - - if !ok { - return nil - } - return val -} - -// Has checks if an entry for the given key exists. -func (t TestKVStore) Has(key []byte) bool { - t.mutex.RLock() - defer t.mutex.RUnlock() - _, ok := t.store[string(key)] - return ok -} - -// Set stores the given key value pair. -func (t TestKVStore) Set(key, value []byte) { - t.mutex.Lock() - defer t.mutex.Unlock() - t.store[string(key)] = value -} - -// Delete deletes a key if it exists. -func (t TestKVStore) Delete(key []byte) { - t.mutex.Lock() - defer t.mutex.Unlock() - - delete(t.store, string(key)) -} - -// Iterator returns an interator over the given key domain. -func (t TestKVStore) Iterator(start, end []byte) types.Iterator { - t.mutex.Lock() - defer t.mutex.Unlock() - - return newMockIterator(start, end, t.store) -} - -// ReverseIterator returns an iterator -// that iterates over all keys in the given domain in reverse order. -func (t TestKVStore) ReverseIterator(start, end []byte) types.Iterator { - t.mutex.Lock() - defer t.mutex.Unlock() - - iter := newMockIterator(start, end, t.store) - - // reverse the order of the iterator, which is returned already - // sorted in ascending order - for i, j := 0, len(iter.keys)-1; i < j; i, j = i+1, j-1 { - iter.keys[i], iter.keys[j] = iter.keys[j], iter.keys[i] - iter.values[i], iter.values[j] = iter.values[j], iter.values[i] - } - - iter.start = end - iter.end = start - - return iter -} - -// fake iterator. -type mockIterator struct { - keys [][]byte - values [][]byte - index int - start, end []byte -} - -func newMockIterator(start, end []byte, content map[string][]byte) *mockIterator { - keys := make([][]byte, 0) - - // select the keys according to the specified domain - for k := range content { - b := []byte(k) - - if (start == nil && end == nil) || - (bytes.Compare(b, start) >= 0 && bytes.Compare(b, end) < 0) { - // make sure data is a copy so that there is no concurrent writing - temp := make([]byte, len(k)) - copy(temp, k) - keys = append(keys, temp) - } - } - - // Sort the keys in ascending order - sort.Slice(keys, func(i, j int) bool { - return bytes.Compare(keys[i], keys[j]) < 0 - }) - - // With the keys chosen and sorted, we can now populate the slice of values - values := make([][]byte, len(keys)) - - for i := 0; i < len(keys); i++ { - // make sure data is a copy so that there is no concurrent writing - value := content[string(keys[i])] - temp := make([]byte, len(value)) - copy(temp, value) - - values[i] = temp - } - - return &mockIterator{ - keys: keys, - values: values, - index: 0, - start: start, - end: end, - } -} - -// Domain returns the key domain of the iterator. -// The start & end (exclusive) limits to iterate over. -// If end < start, then the Iterator goes in reverse order. -// -// A domain of ([]byte{12, 13}, []byte{12, 14}) will iterate -// over anything with the prefix []byte{12, 13}. -// -// The smallest key is the empty byte array []byte{} - see BeginningKey(). -// The largest key is the nil byte array []byte(nil) - see EndingKey(). -// CONTRACT: start, end readonly []byte. -func (mi mockIterator) Domain() ([]byte, []byte) { - return mi.start, mi.end -} - -// Valid returns whether the current position is valid. -// Once invalid, an Iterator is forever invalid. -func (mi mockIterator) Valid() bool { - return mi.index < len(mi.keys) -} - -// Next moves the iterator to the next sequential key in the database, as -// defined by order of iteration. -// If Valid returns false, this method will panic. -func (mi *mockIterator) Next() { - mi.index++ -} - -// Key returns the key of the cursor. -// If Valid returns false, this method will panic. -// CONTRACT: key readonly []byte. -func (mi mockIterator) Key() []byte { - if !mi.Valid() { - panic("Iterator position out of bounds") - } - - return mi.keys[mi.index] -} - -// Value returns the value of the cursor. -// If Valid returns false, this method will panic. -// CONTRACT: value readonly []byte. -func (mi mockIterator) Value() []byte { - if !mi.Valid() { - panic("Iterator position out of bounds") - } - - return mi.values[mi.index] -} - -func (mi mockIterator) Error() error { - return nil -} - -// Close releases the Iterator. -func (mi mockIterator) Close() error { - return nil -} diff --git a/cosmos/testing/utils/bank.go b/cosmos/testutil/bank.go similarity index 98% rename from cosmos/testing/utils/bank.go rename to cosmos/testutil/bank.go index 07509382f..2bcf45331 100644 --- a/cosmos/testing/utils/bank.go +++ b/cosmos/testutil/bank.go @@ -18,7 +18,7 @@ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND // TITLE. -package utils +package testutil import ( "context" diff --git a/cosmos/testing/utils/interfaces.go b/cosmos/testutil/interfaces.go similarity index 98% rename from cosmos/testing/utils/interfaces.go rename to cosmos/testutil/interfaces.go index 56502eb9b..b1b944e56 100644 --- a/cosmos/testing/utils/interfaces.go +++ b/cosmos/testutil/interfaces.go @@ -18,7 +18,7 @@ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND // TITLE. -package utils +package testutil import ( "context" diff --git a/cosmos/testing/utils/setup.go b/cosmos/testutil/setup.go similarity index 84% rename from cosmos/testing/utils/setup.go rename to cosmos/testutil/setup.go index 8c84ee955..32a6a7000 100644 --- a/cosmos/testing/utils/setup.go +++ b/cosmos/testutil/setup.go @@ -18,12 +18,16 @@ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND // TITLE. -package utils +package testutil import ( "testing" + cdb "github.com/cosmos/cosmos-db" + "cosmossdk.io/log" + "cosmossdk.io/store/metrics" + "cosmossdk.io/store/rootmulti" storetypes "cosmossdk.io/store/types" cometproto "github.com/cometbft/cometbft/proto/tendermint/types" @@ -50,7 +54,6 @@ import ( stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "pkg.berachain.dev/polaris/cosmos/testing/types/mock" "pkg.berachain.dev/polaris/cosmos/types" evmtypes "pkg.berachain.dev/polaris/cosmos/x/evm/types" "pkg.berachain.dev/polaris/eth/common" @@ -66,13 +69,26 @@ var ( ) // NewContext creates a SDK context and mounts a mock multistore. -func NewContext() sdk.Context { - return sdk.NewContext( - mock.NewMultiStore(), cometproto.Header{}, false, log.NewTestLogger(&testing.T{})) +func NewContext(logger log.Logger, storekeys ...storetypes.StoreKey) sdk.Context { + cdb := cdb.NewMemDB() + rms := rootmulti.NewStore(cdb, logger, metrics.NewNoOpMetrics()) + + // Register defaults + rms.MountStoreWithDB(AccKey, storetypes.StoreTypeIAVL, cdb) + rms.MountStoreWithDB(BankKey, storetypes.StoreTypeIAVL, cdb) + rms.MountStoreWithDB(EvmKey, storetypes.StoreTypeIAVL, cdb) + rms.MountStoreWithDB(StakingKey, storetypes.StoreTypeIAVL, cdb) + + // Allow extending the + for _, storeKey := range storekeys { + rms.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, cdb) + } + _ = rms.LoadLatestVersion() + return NewContextWithMultiStore(rms, logger) } -func NewContextWithMultiStore(ms storetypes.MultiStore) sdk.Context { - return sdk.NewContext(ms, cometproto.Header{}, false, log.NewTestLogger(&testing.T{})) +func NewContextWithMultiStore(ms storetypes.MultiStore, logger log.Logger) sdk.Context { + return sdk.NewContext(ms, cometproto.Header{}, false, logger) } // TestEncodingConfig defines an encoding configuration that is used for testing @@ -112,14 +128,14 @@ func MakeTestEncodingConfig(modules ...module.AppModuleBasic) TestEncodingConfig } // SetupMinimalKeepers creates and returns keepers for the base SDK modules. -func SetupMinimalKeepers() ( +func SetupMinimalKeepers(logger log.Logger, keys ...storetypes.StoreKey) ( sdk.Context, authkeeper.AccountKeeper, bankkeeper.BaseKeeper, stakingkeeper.Keeper, ) { types.SetupCosmosConfig() - ctx := NewContext().WithBlockHeight(1) + ctx := NewContext(logger, keys...).WithBlockHeight(1) encodingConfig := testutil.MakeTestEncodingConfig( auth.AppModuleBasic{}, @@ -144,7 +160,6 @@ func SetupMinimalKeepers() ( govtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, distrtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, }, - // TODO: switch to eip-55 fuck bech32. addrCodec, "cosmos", authority, diff --git a/cosmos/x/evm/genesis_test.go b/cosmos/x/evm/genesis_test.go index 644e4d6cb..003b1cdd7 100644 --- a/cosmos/x/evm/genesis_test.go +++ b/cosmos/x/evm/genesis_test.go @@ -27,7 +27,6 @@ import ( "math/big" "cosmossdk.io/log" - storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -35,7 +34,7 @@ import ( "pkg.berachain.dev/polaris/cosmos/config" "pkg.berachain.dev/polaris/cosmos/precompile/staking" - testutil "pkg.berachain.dev/polaris/cosmos/testing/utils" + testutil "pkg.berachain.dev/polaris/cosmos/testutil" "pkg.berachain.dev/polaris/cosmos/x/evm" "pkg.berachain.dev/polaris/cosmos/x/evm/keeper" "pkg.berachain.dev/polaris/cosmos/x/evm/plugins/state" @@ -64,7 +63,7 @@ var _ = Describe("", func() { ) BeforeEach(func() { - ctx, ak, _, sk = testutil.SetupMinimalKeepers() + ctx, ak, _, sk = testutil.SetupMinimalKeepers(log.NewTestLogger(GinkgoT())) ctx = ctx.WithBlockHeight(0) sc = staking.NewPrecompileContract(ak, &sk) cfg := config.DefaultConfig() @@ -73,7 +72,7 @@ var _ = Describe("", func() { cfg.Node.KeyStoreDir = GinkgoT().TempDir() k = keeper.NewKeeper( ak, sk, - storetypes.NewKVStoreKey("evm"), + testutil.EvmKey, func() *ethprecompile.Injector { return ethprecompile.NewPrecompiles([]ethprecompile.Registrable{sc}...) }, diff --git a/cosmos/x/evm/keeper/processor_test.go b/cosmos/x/evm/keeper/processor_test.go index d5d169139..b882cc3c0 100644 --- a/cosmos/x/evm/keeper/processor_test.go +++ b/cosmos/x/evm/keeper/processor_test.go @@ -36,7 +36,7 @@ import ( bindings "pkg.berachain.dev/polaris/contracts/bindings/testing" "pkg.berachain.dev/polaris/cosmos/config" "pkg.berachain.dev/polaris/cosmos/precompile/staking" - testutil "pkg.berachain.dev/polaris/cosmos/testing/utils" + testutil "pkg.berachain.dev/polaris/cosmos/testutil" "pkg.berachain.dev/polaris/cosmos/x/evm/keeper" "pkg.berachain.dev/polaris/cosmos/x/evm/plugins/state" "pkg.berachain.dev/polaris/eth/accounts/abi" @@ -88,14 +88,14 @@ var _ = Describe("Processor", func() { } // before chain, init genesis state - ctx, ak, _, sk = testutil.SetupMinimalKeepers() + ctx, ak, _, sk = testutil.SetupMinimalKeepers(log.NewTestLogger(GinkgoT())) cfg := config.DefaultConfig() cfg.Node.DataDir = GinkgoT().TempDir() cfg.Node.KeyStoreDir = GinkgoT().TempDir() sc = staking.NewPrecompileContract(ak, &sk) k = keeper.NewKeeper( ak, sk, - storetypes.NewKVStoreKey("evm"), + testutil.EvmKey, func() *ethprecompile.Injector { return ethprecompile.NewPrecompiles([]ethprecompile.Registrable{sc}...) }, diff --git a/cosmos/x/evm/plugins/block/header_test.go b/cosmos/x/evm/plugins/block/header_test.go index 07a6abe29..87212a5fd 100644 --- a/cosmos/x/evm/plugins/block/header_test.go +++ b/cosmos/x/evm/plugins/block/header_test.go @@ -24,11 +24,12 @@ import ( "errors" "math/big" + "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - testutil "pkg.berachain.dev/polaris/cosmos/testing/utils" + testutil "pkg.berachain.dev/polaris/cosmos/testutil" evmtypes "pkg.berachain.dev/polaris/cosmos/x/evm/types" "pkg.berachain.dev/polaris/eth/common" "pkg.berachain.dev/polaris/eth/core" @@ -44,8 +45,10 @@ var _ = Describe("Header", func() { var p *plugin BeforeEach(func() { - _, _, _, sk := testutil.SetupMinimalKeepers() - ctx = testutil.NewContext().WithBlockGasMeter(storetypes.NewGasMeter(uint64(10000))) + _, _, _, sk := testutil.SetupMinimalKeepers(log.NewTestLogger(GinkgoT())) + ctx = testutil.NewContext( + log.NewTestLogger(GinkgoT())). + WithBlockGasMeter(storetypes.NewGasMeter(uint64(10000))) p = utils.MustGetAs[*plugin](NewPlugin(testutil.EvmKey, sk)) p.SetQueryContextFn( func() func(height int64, prove bool) (sdk.Context, error) { return mockQueryContext }) @@ -134,7 +137,7 @@ func mockQueryContext(height int64, _ bool) (sdk.Context, error) { if height <= 0 { return sdk.Context{}, errors.New("cannot query context at this height") } - ctx := testutil.NewContext().WithBlockHeight(height) + ctx := testutil.NewContext(log.NewTestLogger(GinkgoT())).WithBlockHeight(height) header := generateHeaderAtHeight(height) headerBz, err := types.MarshalHeader(header) if err != nil { diff --git a/cosmos/x/evm/plugins/gas/plugin_test.go b/cosmos/x/evm/plugins/gas/plugin_test.go index 4ac156486..d45b267a8 100644 --- a/cosmos/x/evm/plugins/gas/plugin_test.go +++ b/cosmos/x/evm/plugins/gas/plugin_test.go @@ -23,11 +23,12 @@ package gas import ( "math" + "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - testutil "pkg.berachain.dev/polaris/cosmos/testing/utils" + testutil "pkg.berachain.dev/polaris/cosmos/testutil" "pkg.berachain.dev/polaris/lib/utils" . "github.com/onsi/ginkgo/v2" @@ -43,14 +44,14 @@ var _ = Describe("plugin", func() { BeforeEach(func() { // new block blockGasMeter = storetypes.NewGasMeter(blockGasLimit) - ctx = testutil.NewContext().WithBlockGasMeter(blockGasMeter) + ctx = testutil.NewContext(log.NewTestLogger(GinkgoT())).WithBlockGasMeter(blockGasMeter) p = utils.MustGetAs[*plugin](NewPlugin()) p.Reset(ctx) p.Prepare(ctx) }) It("correctly consume, refund, and report cumulative in the same block", func() { - p.Reset(testutil.NewContext().WithBlockGasMeter(blockGasMeter)) + p.Reset(testutil.NewContext(log.NewTestLogger(GinkgoT())).WithBlockGasMeter(blockGasMeter)) // tx 1 p.gasMeter = storetypes.NewGasMeter(1000) @@ -65,7 +66,7 @@ var _ = Describe("plugin", func() { // as block gas is handled by the baseapp. blockGasMeter.ConsumeGas(250, "") // finalize tx 1 - p.Reset(testutil.NewContext().WithBlockGasMeter(blockGasMeter)) + p.Reset(testutil.NewContext(log.NewTestLogger(GinkgoT())).WithBlockGasMeter(blockGasMeter)) // tx 2 p.gasMeter = storetypes.NewGasMeter(1000) @@ -77,7 +78,7 @@ var _ = Describe("plugin", func() { Expect(p.BlockGasConsumed()).To(Equal(uint64(250))) // shouldn't use any xtra gas yet. blockGasMeter.ConsumeGas(1000, "") // finalize tx 2 Expect(p.BlockGasConsumed()).To(Equal(uint64(1250))) - p.Reset(testutil.NewContext().WithBlockGasMeter(blockGasMeter)) + p.Reset(testutil.NewContext(log.NewTestLogger(GinkgoT())).WithBlockGasMeter(blockGasMeter)) // tx 3 p.gasMeter = storetypes.NewGasMeter(1000) @@ -110,14 +111,14 @@ var _ = Describe("plugin", func() { It("should error on block gas overconsumption", func() { Expect(p.BlockGasLimit()).To(Equal(blockGasLimit)) - p.Reset(testutil.NewContext().WithBlockGasMeter(blockGasMeter)) + p.Reset(testutil.NewContext(log.NewTestLogger(GinkgoT())).WithBlockGasMeter(blockGasMeter)) // tx 1 err := p.ConsumeTxGas(1000) Expect(err).ToNot(HaveOccurred()) blockGasMeter.ConsumeGas(1000, "") // finalize tx 1 - p.Reset(testutil.NewContext().WithBlockGasMeter(blockGasMeter)) + p.Reset(testutil.NewContext(log.NewTestLogger(GinkgoT())).WithBlockGasMeter(blockGasMeter)) // tx 2 err = p.ConsumeTxGas(1000) diff --git a/cosmos/x/evm/plugins/historical/plugin_test.go b/cosmos/x/evm/plugins/historical/plugin_test.go index 7815df67f..e6f52e89f 100644 --- a/cosmos/x/evm/plugins/historical/plugin_test.go +++ b/cosmos/x/evm/plugins/historical/plugin_test.go @@ -23,11 +23,13 @@ package historical import ( "math/big" + "cosmossdk.io/log" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/trie" - testutil "pkg.berachain.dev/polaris/cosmos/testing/utils" + testutil "pkg.berachain.dev/polaris/cosmos/testutil" "pkg.berachain.dev/polaris/eth/common" "pkg.berachain.dev/polaris/eth/core" "pkg.berachain.dev/polaris/eth/core/mock" @@ -45,7 +47,7 @@ var _ = Describe("Historical Data", func() { ) BeforeEach(func() { - ctx = testutil.NewContext().WithBlockHeight(0) + ctx = testutil.NewContext(log.NewTestLogger(GinkgoT())).WithBlockHeight(0) cp := mock.NewConfigurationPluginMock() bp := mock.NewBlockPluginMock() diff --git a/cosmos/x/evm/plugins/precompile/log/factory_test.go b/cosmos/x/evm/plugins/precompile/log/factory_test.go index d5e7ffd8c..7b74eb6d1 100644 --- a/cosmos/x/evm/plugins/precompile/log/factory_test.go +++ b/cosmos/x/evm/plugins/precompile/log/factory_test.go @@ -24,13 +24,14 @@ import ( "errors" "strconv" + "cosmossdk.io/log" sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" cosmlib "pkg.berachain.dev/polaris/cosmos/lib" - testutil "pkg.berachain.dev/polaris/cosmos/testing/utils" + testutil "pkg.berachain.dev/polaris/cosmos/testutil" "pkg.berachain.dev/polaris/eth/accounts/abi" "pkg.berachain.dev/polaris/eth/common" "pkg.berachain.dev/polaris/eth/core/precompile" @@ -54,7 +55,7 @@ var _ = Describe("Factory", func() { ) BeforeEach(func() { - _, _, _, sk = testutil.SetupMinimalKeepers() + _, _, _, sk = testutil.SetupMinimalKeepers(log.NewTestLogger(GinkgoT())) valAddr = sdk.ValAddress([]byte("alice")) delAddr = sdk.AccAddress([]byte("bob")) creationHeight = int64(10) diff --git a/cosmos/x/evm/plugins/precompile/plugin_test.go b/cosmos/x/evm/plugins/precompile/plugin_test.go index 4ed23ffd4..135be6f22 100644 --- a/cosmos/x/evm/plugins/precompile/plugin_test.go +++ b/cosmos/x/evm/plugins/precompile/plugin_test.go @@ -25,12 +25,13 @@ import ( "errors" "math/big" + "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - tmock "pkg.berachain.dev/polaris/cosmos/testing/types/mock" - testutil "pkg.berachain.dev/polaris/cosmos/testing/utils" + "pkg.berachain.dev/polaris/cosmos/store/snapmulti" + testutil "pkg.berachain.dev/polaris/cosmos/testutil" "pkg.berachain.dev/polaris/cosmos/x/evm/plugins/state" "pkg.berachain.dev/polaris/cosmos/x/evm/plugins/state/events" "pkg.berachain.dev/polaris/cosmos/x/evm/plugins/state/events/mock" @@ -50,10 +51,11 @@ var _ = Describe("plugin", func() { var ctx sdk.Context BeforeEach(func() { - ctx = testutil.NewContext() + ctx = testutil.NewContext(log.NewTestLogger(GinkgoT())) ctx = ctx.WithEventManager( events.NewManagerFrom(ctx.EventManager(), mock.NewPrecompileLogFactory()), ) + ctx = ctx.WithMultiStore(snapmulti.NewStoreFrom(ctx.MultiStore())) p = utils.MustGetAs[*plugin](NewPlugin()) e = &mockEVM{nil, ctx, &mockSDB{nil, ctx, 0}} }) @@ -70,7 +72,7 @@ var _ = Describe("plugin", func() { }) It("should handle read-only static calls", func() { - ms := utils.MustGetAs[tmock.MultiStore](ctx.MultiStore()) + ms := utils.MustGetAs[MultiStore](ctx.MultiStore()) cem := utils.MustGetAs[state.ControllableEventManager](ctx.EventManager()) // verify its not read-only right now Expect(ms.IsReadOnly()).To(BeFalse()) diff --git a/cosmos/x/evm/plugins/state/events/manager_test.go b/cosmos/x/evm/plugins/state/events/manager_test.go index 9b454393a..f6f1e1921 100644 --- a/cosmos/x/evm/plugins/state/events/manager_test.go +++ b/cosmos/x/evm/plugins/state/events/manager_test.go @@ -18,9 +18,11 @@ package events_test import ( + "cosmossdk.io/log" + sdk "github.com/cosmos/cosmos-sdk/types" - testutil "pkg.berachain.dev/polaris/cosmos/testing/utils" + testutil "pkg.berachain.dev/polaris/cosmos/testutil" "pkg.berachain.dev/polaris/cosmos/x/evm/plugins/state" "pkg.berachain.dev/polaris/cosmos/x/evm/plugins/state/events" "pkg.berachain.dev/polaris/cosmos/x/evm/plugins/state/events/mock" @@ -37,7 +39,7 @@ var _ = Describe("Manager", func() { BeforeEach(func() { ldb = mock.NewEmptyLogsDB() - ctx = testutil.NewContext() + ctx = testutil.NewContext(log.NewTestLogger(GinkgoT())) ctx.EventManager().EmitEvent(sdk.NewEvent("1")) cem = events.NewManagerFrom(ctx.EventManager(), mock.NewPrecompileLogFactory()) diff --git a/cosmos/x/evm/plugins/state/genesis_test.go b/cosmos/x/evm/plugins/state/genesis_test.go index fe7228fb6..81818fbeb 100644 --- a/cosmos/x/evm/plugins/state/genesis_test.go +++ b/cosmos/x/evm/plugins/state/genesis_test.go @@ -23,9 +23,11 @@ package state_test import ( "math/big" + "cosmossdk.io/log" + sdk "github.com/cosmos/cosmos-sdk/types" - testutil "pkg.berachain.dev/polaris/cosmos/testing/utils" + testutil "pkg.berachain.dev/polaris/cosmos/testutil" "pkg.berachain.dev/polaris/cosmos/x/evm/plugins/state" "pkg.berachain.dev/polaris/eth/common" "pkg.berachain.dev/polaris/eth/core" @@ -44,7 +46,7 @@ var _ = Describe("Genesis", func() { BeforeEach(func() { var ak state.AccountKeeper - ctx, ak, _, _ = testutil.SetupMinimalKeepers() + ctx, ak, _, _ = testutil.SetupMinimalKeepers(log.NewTestLogger(GinkgoT())) sp = state.NewPlugin(ak, testutil.EvmKey, &mockPLF{}) // Create account for alice, bob diff --git a/cosmos/x/evm/plugins/state/plugin_benchmark_test.go b/cosmos/x/evm/plugins/state/plugin_benchmark_test.go index 7004c0720..1be40c1c2 100644 --- a/cosmos/x/evm/plugins/state/plugin_benchmark_test.go +++ b/cosmos/x/evm/plugins/state/plugin_benchmark_test.go @@ -24,7 +24,9 @@ import ( "math/big" "testing" - testutil "pkg.berachain.dev/polaris/cosmos/testing/utils" + "cosmossdk.io/log" + + testutil "pkg.berachain.dev/polaris/cosmos/testutil" "pkg.berachain.dev/polaris/cosmos/x/evm/plugins/state" "pkg.berachain.dev/polaris/eth/common" "pkg.berachain.dev/polaris/eth/core" @@ -37,7 +39,7 @@ var ( ) func GetNewStatePlugin() core.StatePlugin { - ctx, ak, _, _ := testutil.SetupMinimalKeepers() + ctx, ak, _, _ := testutil.SetupMinimalKeepers(log.NewTestLogger(&testing.B{})) sp := state.NewPlugin(ak, testutil.EvmKey, nil) sp.Reset(ctx) return sp diff --git a/cosmos/x/evm/plugins/state/plugin_test.go b/cosmos/x/evm/plugins/state/plugin_test.go index 979697065..a506dcd65 100644 --- a/cosmos/x/evm/plugins/state/plugin_test.go +++ b/cosmos/x/evm/plugins/state/plugin_test.go @@ -23,9 +23,11 @@ package state_test import ( "math/big" + "cosmossdk.io/log" + sdk "github.com/cosmos/cosmos-sdk/types" - testutil "pkg.berachain.dev/polaris/cosmos/testing/utils" + testutil "pkg.berachain.dev/polaris/cosmos/testutil" "pkg.berachain.dev/polaris/cosmos/x/evm/plugins/state" "pkg.berachain.dev/polaris/eth/common" coretypes "pkg.berachain.dev/polaris/eth/core/types" @@ -47,7 +49,7 @@ var _ = Describe("State Plugin", func() { var sp state.Plugin BeforeEach(func() { - ctx, ak, _, _ = testutil.SetupMinimalKeepers() + ctx, ak, _, _ = testutil.SetupMinimalKeepers(log.NewTestLogger(GinkgoT())) sp = state.NewPlugin(ak, testutil.EvmKey, &mockPLF{}) sp.Reset(ctx) }) @@ -63,7 +65,7 @@ var _ = Describe("State Plugin", func() { sp.SetCode(alice, []byte{1, 2, 3}) sp.SetState(alice, common.BytesToHash([]byte{1}), common.BytesToHash([]byte{2})) - sp.Reset(testutil.NewContext()) + sp.Reset(testutil.NewContext(log.NewTestLogger(GinkgoT()))) Expect(sp.Exist(alice)).To(BeFalse()) Expect(sp.GetBalance(alice)).To(Equal(new(big.Int)))