github.com/Finschia/finschia-sdk@v0.48.1/x/distribution/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 v040distribution "github.com/Finschia/finschia-sdk/x/distribution/legacy/v040" 13 v043distribution "github.com/Finschia/finschia-sdk/x/distribution/legacy/v043" 14 "github.com/Finschia/finschia-sdk/x/distribution/types" 15 ) 16 17 func TestStoreMigration(t *testing.T) { 18 distributionKey := sdk.NewKVStoreKey("distribution") 19 ctx := testutil.DefaultContext(distributionKey, sdk.NewTransientStoreKey("transient_test")) 20 store := ctx.KVStore(distributionKey) 21 22 _, _, addr1 := testdata.KeyTestPubAddr() 23 valAddr := sdk.ValAddress(addr1) 24 _, _, addr2 := testdata.KeyTestPubAddr() 25 // Use dummy value for all keys. 26 value := []byte("foo") 27 28 testCases := []struct { 29 name string 30 oldKey []byte 31 newKey []byte 32 }{ 33 { 34 "FeePoolKey", 35 v040distribution.FeePoolKey, 36 types.FeePoolKey, 37 }, 38 { 39 "ProposerKey", 40 v040distribution.ProposerKey, 41 types.ProposerKey, 42 }, 43 { 44 "ValidatorOutstandingRewards", 45 v040distribution.GetValidatorOutstandingRewardsKey(valAddr), 46 types.GetValidatorOutstandingRewardsKey(valAddr), 47 }, 48 { 49 "DelegatorWithdrawAddr", 50 v040distribution.GetDelegatorWithdrawAddrKey(addr2), 51 types.GetDelegatorWithdrawAddrKey(addr2), 52 }, 53 { 54 "DelegatorStartingInfo", 55 v040distribution.GetDelegatorStartingInfoKey(valAddr, addr2), 56 types.GetDelegatorStartingInfoKey(valAddr, addr2), 57 }, 58 { 59 "ValidatorHistoricalRewards", 60 v040distribution.GetValidatorHistoricalRewardsKey(valAddr, 6), 61 types.GetValidatorHistoricalRewardsKey(valAddr, 6), 62 }, 63 { 64 "ValidatorCurrentRewards", 65 v040distribution.GetValidatorCurrentRewardsKey(valAddr), 66 types.GetValidatorCurrentRewardsKey(valAddr), 67 }, 68 { 69 "ValidatorAccumulatedCommission", 70 v040distribution.GetValidatorAccumulatedCommissionKey(valAddr), 71 types.GetValidatorAccumulatedCommissionKey(valAddr), 72 }, 73 { 74 "ValidatorSlashEvent", 75 v040distribution.GetValidatorSlashEventKey(valAddr, 6, 8), 76 types.GetValidatorSlashEventKey(valAddr, 6, 8), 77 }, 78 } 79 80 // Set all the old keys to the store 81 for _, tc := range testCases { 82 store.Set(tc.oldKey, value) 83 } 84 85 // Run migrations. 86 err := v043distribution.MigrateStore(ctx, distributionKey) 87 require.NoError(t, err) 88 89 // Make sure the new keys are set and old keys are deleted. 90 for _, tc := range testCases { 91 tc := tc 92 t.Run(tc.name, func(t *testing.T) { 93 if !bytes.Equal(tc.oldKey, tc.newKey) { 94 require.Nil(t, store.Get(tc.oldKey)) 95 } 96 require.Equal(t, value, store.Get(tc.newKey)) 97 }) 98 } 99 }