mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-25 15:55:18 +00:00
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
This commit is contained in:
parent
8aa176f05a
commit
f6c55b7015
@ -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)
|
||||
|
@ -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)
|
||||
|
10
migrate/v0_17/testdata/genesis-v17.json
vendored
10
migrate/v0_17/testdata/genesis-v17.json
vendored
@ -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": {
|
||||
|
Loading…
Reference in New Issue
Block a user