mukan-sdk/x/auth/migrations/v3/store_test.go
Mukan Erkin Törük abb1ff956e
Some checks are pending
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
refactor: complete sovereign stack cleanup — all github.com upstream refs purged
2026-05-11 03:46:06 +03:00

111 lines
3.3 KiB
Go

package v3_test
import (
"math/rand"
"testing"
"time"
cmtproto "git.cw.tr/mukan-network/mukan-consensus/proto/tendermint/types"
"github.com/stretchr/testify/require"
"cosmossdk.io/collections"
"cosmossdk.io/depinject"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
"git.cw.tr/mukan-network/mukan-sdk/crypto/keys/secp256k1"
"git.cw.tr/mukan-network/mukan-sdk/runtime"
"git.cw.tr/mukan-network/mukan-sdk/testutil"
simtestutil "git.cw.tr/mukan-network/mukan-sdk/testutil/sims"
sdk "git.cw.tr/mukan-network/mukan-sdk/types"
moduletestutil "git.cw.tr/mukan-network/mukan-sdk/types/module/testutil"
"git.cw.tr/mukan-network/mukan-sdk/x/auth"
authexported "git.cw.tr/mukan-network/mukan-sdk/x/auth/exported"
"git.cw.tr/mukan-network/mukan-sdk/x/auth/keeper"
v1 "git.cw.tr/mukan-network/mukan-sdk/x/auth/migrations/v1"
v4 "git.cw.tr/mukan-network/mukan-sdk/x/auth/migrations/v4"
authtestutil "git.cw.tr/mukan-network/mukan-sdk/x/auth/testutil"
authtypes "git.cw.tr/mukan-network/mukan-sdk/x/auth/types"
)
type mockSubspace struct {
ps authtypes.Params
}
func newMockSubspace(ps authtypes.Params) mockSubspace {
return mockSubspace{ps: ps}
}
func (ms mockSubspace) GetParamSet(ctx sdk.Context, ps authexported.ParamSet) {
*ps.(*authtypes.Params) = ms.ps
}
// TestMigrateMapAccAddressToAccNumberKey test cases for state migration of map to accAddr to accNum
func TestMigrateMapAccAddressToAccNumberKey(t *testing.T) {
encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{})
cdc := encCfg.Codec
storeKey := storetypes.NewKVStoreKey(v1.ModuleName)
tKey := storetypes.NewTransientStoreKey("transient_test")
ctx := testutil.DefaultContext(storeKey, tKey)
storeService := runtime.NewKVStoreService(storeKey)
var accountKeeper keeper.AccountKeeper
app, err := simtestutil.Setup(
depinject.Configs(
authtestutil.AppConfig,
depinject.Supply(log.NewNopLogger()),
),
&accountKeeper,
)
require.NoError(t, err)
legacySubspace := newMockSubspace(authtypes.DefaultParams())
require.NoError(t, v4.Migrate(ctx, storeService, legacySubspace, cdc))
// new base account
senderPrivKey := secp256k1.GenPrivKey()
randAccNumber := uint64(rand.Intn(100000-10000) + 10000)
acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), randAccNumber, 0)
ctx = app.NewContextLegacy(false, cmtproto.Header{Time: time.Now()})
// migrator
m := keeper.NewMigrator(accountKeeper, app.GRPCQueryRouter(), legacySubspace)
// set the account to store with map acc addr to acc number
require.NoError(t, m.V45SetAccount(ctx, acc))
testCases := []struct {
name string
doMigration bool
accNum uint64
}{
{
name: "without state migration",
doMigration: false,
accNum: acc.AccountNumber,
},
{
name: "with state migration",
doMigration: true,
accNum: acc.AccountNumber,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
if tc.doMigration {
require.NoError(t, m.Migrate2to3(ctx))
}
// get the account address by acc id
accAddr, err := accountKeeper.Accounts.Indexes.Number.MatchExact(ctx, tc.accNum)
if tc.doMigration {
require.Equal(t, accAddr.String(), acc.Address)
} else {
require.ErrorIs(t, err, collections.ErrNotFound)
}
})
}
}