From f6c55b701598f5e3afd5ecccaec6302ad918a1f0 Mon Sep 17 00:00:00 2001 From: Derrick Lee Date: Fri, 22 Apr 2022 09:22:20 -0700 Subject: [PATCH] Add bridge migration (#1214) * Add bridge migration * Use NewGenesisState method * Update migrations with new params * Use nil for relayer instead of empty address Both are still valid --- migrate/v0_17/kava.go | 16 ++++++++++++++++ migrate/v0_17/migrate_test.go | 18 ++++++++++++++++++ migrate/v0_17/testdata/genesis-v17.json | 10 ++++++++++ 3 files changed, 44 insertions(+) diff --git a/migrate/v0_17/kava.go b/migrate/v0_17/kava.go index 00b8b405..4b564f92 100644 --- a/migrate/v0_17/kava.go +++ b/migrate/v0_17/kava.go @@ -3,12 +3,15 @@ package v0_17 import ( "github.com/cosmos/cosmos-sdk/client" + sdk "github.com/cosmos/cosmos-sdk/types" authz "github.com/cosmos/cosmos-sdk/x/authz" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" evmtypes "github.com/tharsis/ethermint/x/evm/types" feemarkettypes "github.com/tharsis/ethermint/x/feemarket/types" evmutiltypes "github.com/kava-labs/kava/x/evmutil/types" + + bridgetypes "github.com/kava-labs/kava-bridge/x/bridge/types" ) func migrateAppState(appState genutiltypes.AppMap, clientCtx client.Context) { @@ -31,6 +34,19 @@ func migrateAppState(appState genutiltypes.AppMap, clientCtx client.Context) { } appState[evmtypes.ModuleName] = codec.MustMarshalJSON(evmGenState) + // x/bridge + bridgeGenState := bridgetypes.NewGenesisState( + bridgetypes.NewParams( + false, // Bridge disabled + bridgetypes.EnabledERC20Tokens{}, // No bridge ERC20 tokens + nil, // No relayer + bridgetypes.ConversionPairs{}, // No conversion pairs + ), + bridgetypes.ERC20BridgePairs{}, // Empty state as there has been no ERC20 contracts deployed + sdk.OneInt(), // NextWithdrawSequence starts at 1 + ) + appState[bridgetypes.ModuleName] = codec.MustMarshalJSON(&bridgeGenState) + // x/feemarket feemarketState := feemarkettypes.DefaultGenesisState() appState[feemarkettypes.ModuleName] = codec.MustMarshalJSON(feemarketState) diff --git a/migrate/v0_17/migrate_test.go b/migrate/v0_17/migrate_test.go index fdafdd65..77dc7462 100644 --- a/migrate/v0_17/migrate_test.go +++ b/migrate/v0_17/migrate_test.go @@ -5,10 +5,12 @@ import ( "path/filepath" "testing" + bridgetypes "github.com/kava-labs/kava-bridge/x/bridge/types" "github.com/kava-labs/kava/app" "github.com/stretchr/testify/assert" "github.com/cosmos/cosmos-sdk/client" + sdk "github.com/cosmos/cosmos-sdk/types" authz "github.com/cosmos/cosmos-sdk/x/authz" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" tmjson "github.com/tendermint/tendermint/libs/json" @@ -74,6 +76,22 @@ func TestMigrateAuthz(t *testing.T) { }) } +func TestMigrateBridge(t *testing.T) { + appMap, ctx := migrateToV17AndGetAppMap(t) + var genstate bridgetypes.GenesisState + err := ctx.Codec.UnmarshalJSON(appMap[bridgetypes.ModuleName], &genstate) + assert.NoError(t, err) + + assert.Len(t, genstate.ERC20BridgePairs, 0) + assert.Equal(t, genstate.NextWithdrawSequence, sdk.OneInt()) + assert.Equal(t, genstate.Params, bridgetypes.Params{ + BridgeEnabled: false, + EnabledERC20Tokens: bridgetypes.EnabledERC20Tokens{}, + Relayer: sdk.AccAddress{}, + EnabledConversionPairs: bridgetypes.ConversionPairs{}, + }) +} + func migrateToV17AndGetAppMap(t *testing.T) (genutiltypes.AppMap, client.Context) { genDoc, err := tmtypes.GenesisDocFromFile(filepath.Join("testdata", "genesis-v16.json")) assert.NoError(t, err) diff --git a/migrate/v0_17/testdata/genesis-v17.json b/migrate/v0_17/testdata/genesis-v17.json index 7c3fdb4c..e61e0479 100644 --- a/migrate/v0_17/testdata/genesis-v17.json +++ b/migrate/v0_17/testdata/genesis-v17.json @@ -559,6 +559,16 @@ ], "previous_block_time": "1970-01-01T00:00:00Z" }, + "bridge": { + "params": { + "bridge_enabled": false, + "enabled_erc20_tokens": [], + "relayer": "", + "enabled_conversion_pairs": [] + }, + "erc20_bridge_pairs": [], + "next_withdraw_sequence": "1" + }, "capability": { "index": "1", "owners": [] }, "cdp": { "params": {