github.com/Finschia/finschia-sdk@v0.48.1/x/slashing/legacy/v043/store_test.go (about) 1 package v043_test 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 9 "github.com/Finschia/finschia-sdk/testutil" 10 "github.com/Finschia/finschia-sdk/testutil/testdata" 11 sdk "github.com/Finschia/finschia-sdk/types" 12 v040slashing "github.com/Finschia/finschia-sdk/x/slashing/legacy/v040" 13 v043slashing "github.com/Finschia/finschia-sdk/x/slashing/legacy/v043" 14 "github.com/Finschia/finschia-sdk/x/slashing/types" 15 ) 16 17 func TestStoreMigration(t *testing.T) { 18 slashingKey := sdk.NewKVStoreKey("slashing") 19 ctx := testutil.DefaultContext(slashingKey, sdk.NewTransientStoreKey("transient_test")) 20 store := ctx.KVStore(slashingKey) 21 22 _, _, addr1 := testdata.KeyTestPubAddr() 23 consAddr := sdk.ConsAddress(addr1) 24 // Use dummy value for all keys. 25 value := []byte("foo") 26 27 testCases := []struct { 28 name string 29 oldKey []byte 30 newKey []byte 31 }{ 32 { 33 "ValidatorSigningInfoKey", 34 v040slashing.ValidatorSigningInfoKey(consAddr), 35 types.ValidatorSigningInfoKey(consAddr), 36 }, 37 { 38 "ValidatorMissedBlockBitArrayKey", 39 v040slashing.ValidatorMissedBlockBitArrayKey(consAddr, 2), 40 types.ValidatorMissedBlockBitArrayKey(consAddr, 2), 41 }, 42 { 43 "AddrPubkeyRelationKey", 44 v040slashing.AddrPubkeyRelationKey(consAddr), 45 types.AddrPubkeyRelationKey(consAddr), 46 }, 47 } 48 49 // Set all the old keys to the store 50 for _, tc := range testCases { 51 store.Set(tc.oldKey, value) 52 } 53 54 // Run migrations. 55 err := v043slashing.MigrateStore(ctx, slashingKey) 56 require.NoError(t, err) 57 58 // Make sure the new keys are set and old keys are deleted. 59 for _, tc := range testCases { 60 tc := tc 61 t.Run(tc.name, func(t *testing.T) { 62 if !bytes.Equal(tc.oldKey, tc.newKey) { 63 require.Nil(t, store.Get(tc.oldKey)) 64 } 65 require.Equal(t, value, store.Get(tc.newKey)) 66 }) 67 } 68 }