From d94cee3107f90f47c1251f6f114634559733b8d5 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 26 May 2022 10:02:04 -0500 Subject: [PATCH] Fix for fetching from separate keystore containers in test --- runtime/app.go | 13 +++++++++++++ simapp/app.go | 14 ++++++++++++-- simapp/sim_test.go | 22 +++++++++++----------- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/runtime/app.go b/runtime/app.go index 14f767b75897..b01395984ce5 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -6,6 +6,7 @@ import ( "github.com/gogo/protobuf/grpc" abci "github.com/tendermint/tendermint/abci/types" + "golang.org/x/exp/slices" runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" @@ -155,4 +156,16 @@ func (a *App) RegisterTendermintService(clientCtx client.Context) { ) } +// FindStoreKey fetches a registered StoreKey from the App in linear time. +// +// NOTE: This should only be used in testing. +func (a *App) FindStoreKey(storeKey string) storetypes.StoreKey { + i := slices.IndexFunc(a.storeKeys, func(s storetypes.StoreKey) bool { return s.Name() == storeKey }) + if i == -1 { + return nil + } + + return a.storeKeys[i] +} + var _ servertypes.Application = &App{} diff --git a/simapp/app.go b/simapp/app.go index 76734733df91..71ca2ba3e66b 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -325,7 +325,7 @@ func NewSimApp( app.GovKeeper = *govKeeper.SetHooks( govtypes.NewMultiGovHooks( - // register the governance hooks + // register the governance hooks ), ) // set the governance module account as the authority for conducting upgrades @@ -545,7 +545,17 @@ func (app *SimApp) InterfaceRegistry() codectypes.InterfaceRegistry { // // NOTE: This is solely to be used for testing purposes. func (app *SimApp) GetKey(storeKey string) *storetypes.KVStoreKey { - return app.keys[storeKey] + kvsk := app.keys[storeKey] + if kvsk != nil { + return kvsk + } + + sk := app.FindStoreKey(storeKey) + kvStoreKey, ok := sk.(*storetypes.KVStoreKey) + if !ok { + return nil + } + return kvStoreKey } // GetTKey returns the TransientStoreKey for the provided store key. diff --git a/simapp/sim_test.go b/simapp/sim_test.go index e09df9045950..cd965f76bdac 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -175,23 +175,23 @@ func TestAppImportExport(t *testing.T) { fmt.Printf("comparing stores...\n") storeKeysPrefixes := []StoreKeysPrefixes{ - {app.keys[authtypes.StoreKey], newApp.keys[authtypes.StoreKey], [][]byte{}}, + {app.GetKey(authtypes.StoreKey), newApp.GetKey(authtypes.StoreKey), [][]byte{}}, { - app.keys[stakingtypes.StoreKey], newApp.keys[stakingtypes.StoreKey], + app.GetKey(stakingtypes.StoreKey), newApp.GetKey(stakingtypes.StoreKey), [][]byte{ stakingtypes.UnbondingQueueKey, stakingtypes.RedelegationQueueKey, stakingtypes.ValidatorQueueKey, stakingtypes.HistoricalInfoKey, }, }, // ordering may change but it doesn't matter - {app.keys[slashingtypes.StoreKey], newApp.keys[slashingtypes.StoreKey], [][]byte{}}, - {app.keys[minttypes.StoreKey], newApp.keys[minttypes.StoreKey], [][]byte{}}, - {app.keys[distrtypes.StoreKey], newApp.keys[distrtypes.StoreKey], [][]byte{}}, - {app.keys[banktypes.StoreKey], newApp.keys[banktypes.StoreKey], [][]byte{banktypes.BalancesPrefix}}, - {app.keys[paramtypes.StoreKey], newApp.keys[paramtypes.StoreKey], [][]byte{}}, - {app.keys[govtypes.StoreKey], newApp.keys[govtypes.StoreKey], [][]byte{}}, - {app.keys[evidencetypes.StoreKey], newApp.keys[evidencetypes.StoreKey], [][]byte{}}, - {app.keys[capabilitytypes.StoreKey], newApp.keys[capabilitytypes.StoreKey], [][]byte{}}, - {app.keys[authzkeeper.StoreKey], newApp.keys[authzkeeper.StoreKey], [][]byte{authzkeeper.GrantKey, authzkeeper.GrantQueuePrefix}}, + {app.GetKey(slashingtypes.StoreKey), newApp.GetKey(slashingtypes.StoreKey), [][]byte{}}, + {app.GetKey(minttypes.StoreKey), newApp.GetKey(minttypes.StoreKey), [][]byte{}}, + {app.GetKey(distrtypes.StoreKey), newApp.GetKey(distrtypes.StoreKey), [][]byte{}}, + {app.GetKey(banktypes.StoreKey), newApp.GetKey(banktypes.StoreKey), [][]byte{banktypes.BalancesPrefix}}, + {app.GetKey(paramtypes.StoreKey), newApp.GetKey(paramtypes.StoreKey), [][]byte{}}, + {app.GetKey(govtypes.StoreKey), newApp.GetKey(govtypes.StoreKey), [][]byte{}}, + {app.GetKey(evidencetypes.StoreKey), newApp.GetKey(evidencetypes.StoreKey), [][]byte{}}, + {app.GetKey(capabilitytypes.StoreKey), newApp.GetKey(capabilitytypes.StoreKey), [][]byte{}}, + {app.GetKey(authzkeeper.StoreKey), newApp.GetKey(authzkeeper.StoreKey), [][]byte{authzkeeper.GrantKey, authzkeeper.GrantQueuePrefix}}, } for _, skp := range storeKeysPrefixes {