Skip to content

Commit

Permalink
pfm migrate validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Nov 3, 2023
1 parent f71f7f9 commit dbadb8a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

// NOTE: this can be removed in SDK v51

type (
ParamSet = paramtypes.ParamSet

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package v2

import (
"fmt"

"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/exported"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"

Expand All @@ -27,5 +29,24 @@ func Migrate(

bz := cdc.MustMarshal(&currParams)
store.Set(types.ParamsKey, bz)

return validate(store, cdc, currParams)
}

func validate(store sdk.KVStore, cdc codec.BinaryCodec, currParams types.Params) error {
var res types.Params
bz := store.Get(types.ParamsKey)
if bz == nil {
return fmt.Errorf("expected params at key %s but not found", types.ParamsKey)
}

if err := cdc.Unmarshal(bz, &res); err != nil {
return err
}

if !currParams.FeePercentage.Equal(res.FeePercentage) {
return fmt.Errorf("expected %s but got %s", currParams, res)
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
)

// 0.02
var migrateExpected = sdk.NewDecWithPrec(2, 2)

type mockSubspace struct {
ps types.Params
}
Expand All @@ -37,7 +40,7 @@ func TestMigrate(t *testing.T) {
store := ctx.KVStore(storeKey)

legacySubspace := newMockSubspace(types.Params{
FeePercentage: sdk.NewDec(1),
FeePercentage: migrateExpected,
})
require.NoError(t, v2.Migrate(ctx, store, legacySubspace, cdc))

Expand Down

0 comments on commit dbadb8a

Please sign in to comment.