From 4838021dbc642794dcde1fb15e122bbfa70cfa88 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Mon, 25 Mar 2024 10:42:48 +0900 Subject: [PATCH] chore: refactor to accept kvStoreService instead of key --- x/bankplus/deprecator.go | 13 +++++++------ x/bankplus/deprecator_test.go | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/x/bankplus/deprecator.go b/x/bankplus/deprecator.go index bd79235f9a..cc67ecbe12 100644 --- a/x/bankplus/deprecator.go +++ b/x/bankplus/deprecator.go @@ -3,6 +3,7 @@ package bankplus import ( "context" + "cosmossdk.io/core/store" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/runtime" @@ -36,22 +37,22 @@ func inactiveAddrKey(addr sdk.AccAddress) []byte { // func (app SimApp) deprecateBankPlusFromSimapp(ctx context.Context) { // for _, key := range app.kvStoreKeys() { // if key.Name() == banktypes.StoreKey { -// err := internal.DeprecateBankPlus(ctx, key) +// bankStoreService := runtime.NewKVStoreService(key) +// err := bankplus.DeprecateBankPlus(ctx, bankStoreService) // if err != nil { // panic(fmt.Errorf("failed to deprecate x/bankplus: %w", err)) // } // } // } // } -func DeprecateBankPlus(ctx context.Context, bankKey *storetypes.KVStoreKey) error { - kss := runtime.NewKVStoreService(bankKey) - ks := kss.OpenKVStore(ctx) - adapter := runtime.KVStoreAdapter(ks) +func DeprecateBankPlus(ctx context.Context, bankStoreService store.KVStoreService) error { + kvStore := bankStoreService.OpenKVStore(ctx) + adapter := runtime.KVStoreAdapter(kvStore) iter := storetypes.KVStorePrefixIterator(adapter, inactiveAddrsKeyPrefix) defer iter.Close() for ; iter.Valid(); iter.Next() { - err := ks.Delete(iter.Key()) + err := kvStore.Delete(iter.Key()) if err != nil { return err } diff --git a/x/bankplus/deprecator_test.go b/x/bankplus/deprecator_test.go index e207b12c68..086f37dd19 100644 --- a/x/bankplus/deprecator_test.go +++ b/x/bankplus/deprecator_test.go @@ -63,7 +63,7 @@ func (s *DeprecationTestSuite) TestDeprecateBankPlus() { s.Require().True(isStoredInactiveAddr(s.ctx, s.storeService, oldAcc.GetAddress())) s.Require().True(isStoredInactiveAddr(s.ctx, s.storeService, anotherOldAcc.GetAddress())) - err := DeprecateBankPlus(s.ctx, s.key) + err := DeprecateBankPlus(s.ctx, s.storeService) s.Require().NoError(err) s.Require().False(isStoredInactiveAddr(s.ctx, s.storeService, oldAcc.GetAddress()))