Skip to content

Commit

Permalink
feat: add connection router address to nexus params
Browse files Browse the repository at this point in the history
  • Loading branch information
fish-sammy committed Sep 18, 2023
1 parent ce7e267 commit 98ae33a
Show file tree
Hide file tree
Showing 14 changed files with 230 additions and 70 deletions.
2 changes: 1 addition & 1 deletion client/docs/static/openapi/index.html

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions client/docs/static/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13787,6 +13787,9 @@ paths:
chain_maintainer_check_window:
type: integer
format: int32
connection_router:
type: string
format: byte
title: Params represent the genesis parameters for the module
default:
description: An unexpected error response
Expand Down Expand Up @@ -47026,6 +47029,9 @@ components:
chain_maintainer_check_window:
type: integer
format: int32
connection_router:
type: string
format: byte
title: Params represent the genesis parameters for the module
axelar.nexus.v1beta1.ParamsResponse:
type: object
Expand Down Expand Up @@ -47078,6 +47084,9 @@ components:
chain_maintainer_check_window:
type: integer
format: int32
connection_router:
type: string
format: byte
title: Params represent the genesis parameters for the module
axelar.nexus.v1beta1.RecipientAddressResponse:
type: object
Expand Down
9 changes: 9 additions & 0 deletions client/docs/static/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15166,6 +15166,9 @@ paths:
chain_maintainer_check_window:
type: integer
format: int32
connection_router:
type: string
format: byte
title: Params represent the genesis parameters for the module
default:
description: An unexpected error response
Expand Down Expand Up @@ -51031,6 +51034,9 @@ definitions:
chain_maintainer_check_window:
type: integer
format: int32
connection_router:
type: string
format: byte
title: Params represent the genesis parameters for the module
axelar.nexus.v1beta1.ParamsResponse:
type: object
Expand Down Expand Up @@ -51083,6 +51089,9 @@ definitions:
chain_maintainer_check_window:
type: integer
format: int32
connection_router:
type: string
format: byte
title: Params represent the genesis parameters for the module
axelar.nexus.v1beta1.RecipientAddressResponse:
type: object
Expand Down
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/proto/proto-docs.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions proto/axelar/nexus/v1beta1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ message Params {
utils.v1beta1.Threshold chain_maintainer_incorrect_vote_threshold = 3
[ (gogoproto.nullable) = false ];
int32 chain_maintainer_check_window = 4;
bytes connection_router = 5
[ (gogoproto.casttype) =
"github.com/cosmos/cosmos-sdk/types.AccAddress" ];
}
4 changes: 2 additions & 2 deletions x/axelarnet/keeper/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

func TestMigrate5to6(t *testing.T) {
encCfg := app.MakeEncodingConfig()
subspace := params.NewSubspace(encCfg.Codec, encCfg.Amino, sdk.NewKVStoreKey("nexusKey"), sdk.NewKVStoreKey("tNexusKey"), "nexus")
k := keeper.NewKeeper(encCfg.Codec, sdk.NewKVStoreKey("nexus"), subspace, &mock.ChannelKeeperMock{}, &mock.FeegrantKeeperMock{})
subspace := params.NewSubspace(encCfg.Codec, encCfg.Amino, sdk.NewKVStoreKey("axelarnetKey"), sdk.NewKVStoreKey("tAxelarnetKey"), "axelarnet")
k := keeper.NewKeeper(encCfg.Codec, sdk.NewKVStoreKey("axelarnet"), subspace, &mock.ChannelKeeperMock{}, &mock.FeegrantKeeperMock{})
ctx := sdk.NewContext(fake.NewMultiStore(), tmproto.Header{}, false, log.TestingLogger())

Given("subspace is setup with params before migration", func() {
Expand Down
57 changes: 28 additions & 29 deletions x/nexus/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ import (
evmkeeper "github.com/axelarnetwork/axelar-core/x/evm/keeper"
evmTypes "github.com/axelarnetwork/axelar-core/x/evm/types"
"github.com/axelarnetwork/axelar-core/x/nexus/exported"
nexusKeeper "github.com/axelarnetwork/axelar-core/x/nexus/keeper"
"github.com/axelarnetwork/axelar-core/x/nexus/keeper"
"github.com/axelarnetwork/axelar-core/x/nexus/types"
)

const maxAmount int64 = 100000000000

var keeper nexusKeeper.Keeper
var bankK *axelarnetmock.BankKeeperMock
var k keeper.Keeper

func addressValidator() types.Router {
axelarnetK := &axelarnetmock.BaseKeeperMock{
Expand Down Expand Up @@ -58,49 +57,49 @@ func addressValidator() types.Router {
func init() {
encCfg := app.MakeEncodingConfig()
subspace := params.NewSubspace(encCfg.Codec, encCfg.Amino, sdk.NewKVStoreKey("nexusKey"), sdk.NewKVStoreKey("tNexusKey"), "nexus")
keeper = nexusKeeper.NewKeeper(encCfg.Codec, sdk.NewKVStoreKey("nexus"), subspace)
keeper.SetRouter(addressValidator())
k = keeper.NewKeeper(encCfg.Codec, sdk.NewKVStoreKey("nexus"), subspace)
k.SetRouter(addressValidator())
}

func TestLinkAddress(t *testing.T) {
repeats := 20

var ctx sdk.Context
cfg := app.MakeEncodingConfig()
keeper, ctx = setup(cfg)
k, ctx = setup(cfg)

terra := exported.Chain{Name: exported.ChainName("terra"), Module: axelarnetTypes.ModuleName, SupportsForeignAssets: true}
evmAddr := exported.CrossChainAddress{Chain: evm.Ethereum, Address: "0x68B93045fe7D8794a7cAF327e7f855CD6Cd03BB8"}
axelarAddr := exported.CrossChainAddress{Chain: axelarnet.Axelarnet, Address: "axelar1t66w8cazua870wu7t2hsffndmy2qy2v556ymndnczs83qpz2h45sq6lq9w"}

t.Run("should pass address validation", testutils.Func(func(t *testing.T) {
err := keeper.LinkAddresses(ctx,
err := k.LinkAddresses(ctx,
evmAddr,
exported.CrossChainAddress{Chain: axelarnet.Axelarnet, Address: "axelar1t66w8cazua870wu7t2hsffndmy2qy2v556ymndnczs83qpz2h45sq6lq9w"},
)
assert.NoError(t, err)

err = keeper.LinkAddresses(ctx,
err = k.LinkAddresses(ctx,
evmAddr,
exported.CrossChainAddress{Chain: terra, Address: "terra18zhnqjv70v0d2f8v0s5lape0gr5ua94eqkk8ex"},
)
assert.NoError(t, err)

err = keeper.LinkAddresses(ctx,
err = k.LinkAddresses(ctx,
exported.CrossChainAddress{Chain: evm.Ethereum, Address: "68B93045fe7D8794a7cAF327e7f855CD6Cd03BB8"},
axelarAddr,
)
assert.NoError(t, err)
}))

t.Run("should return error when linking invalid addresses", testutils.Func(func(t *testing.T) {
err := keeper.LinkAddresses(ctx,
err := k.LinkAddresses(ctx,
exported.CrossChainAddress{Chain: evm.Ethereum, Address: "0xZ8B93045fe7D8794a7cAF327e7f855CD6Cd03BB8"},
axelarAddr,
)
assert.ErrorContains(t, err, "not an hex address")

err = keeper.LinkAddresses(ctx,
err = k.LinkAddresses(ctx,
evmAddr,
exported.CrossChainAddress{Chain: axelarnet.Axelarnet, Address: rand.StrBetween(10, 30)},
)
Expand All @@ -113,29 +112,29 @@ func TestLinkAddress(t *testing.T) {
SupportsForeignAssets: false,
Module: evmTypes.ModuleName,
}
keeper.SetChain(ctx, fromChain)
keeper.ActivateChain(ctx, fromChain)
k.SetChain(ctx, fromChain)
k.ActivateChain(ctx, fromChain)
sender, recipient := makeRandAddressesForChain(fromChain, evm.Ethereum)
err := keeper.LinkAddresses(ctx, sender, recipient)
err := k.LinkAddresses(ctx, sender, recipient)
assert.NoError(t, err)
_, err = keeper.EnqueueForTransfer(ctx, sender, makeRandAmount(makeRandomDenom()))
_, err = k.EnqueueForTransfer(ctx, sender, makeRandAmount(makeRandomDenom()))
assert.Error(t, err)
}).Repeat(repeats))

t.Run("successfully link", testutils.Func(func(t *testing.T) {
sender, recipient := makeRandAddressesForChain(axelarnet.Axelarnet, evm.Ethereum)
err := keeper.LinkAddresses(ctx, sender, recipient)
err := k.LinkAddresses(ctx, sender, recipient)
assert.NoError(t, err)
_, err = keeper.EnqueueForTransfer(ctx, sender, makeRandAmount(axelarnet.NativeAsset))
_, err = k.EnqueueForTransfer(ctx, sender, makeRandAmount(axelarnet.NativeAsset))
assert.NoError(t, err)
recp, ok := keeper.GetRecipient(ctx, sender)
recp, ok := k.GetRecipient(ctx, sender)
assert.True(t, ok)
assert.Equal(t, recipient, recp)

sender.Address = rand.Str(20)
_, err = keeper.EnqueueForTransfer(ctx, sender, makeRandAmount(axelarnet.NativeAsset))
_, err = k.EnqueueForTransfer(ctx, sender, makeRandAmount(axelarnet.NativeAsset))
assert.Error(t, err)
recp, ok = keeper.GetRecipient(ctx, sender)
recp, ok = k.GetRecipient(ctx, sender)
assert.False(t, ok)
assert.NotEqual(t, recipient, recp)
}).Repeat(repeats))
Expand All @@ -146,14 +145,14 @@ func TestSetChainGetChain_MixCaseChainName(t *testing.T) {
chain := makeRandomChain(chainName)

ctx := sdk.NewContext(fake.NewMultiStore(), tmproto.Header{}, false, log.TestingLogger())
keeper.SetChain(ctx, chain)
k.SetChain(ctx, chain)

actual, ok := keeper.GetChain(ctx, exported.ChainName(strings.ToUpper(chainName)))
actual, ok := k.GetChain(ctx, exported.ChainName(strings.ToUpper(chainName)))

assert.True(t, ok)
assert.Equal(t, chain, actual)

actual, ok = keeper.GetChain(ctx, exported.ChainName(strings.ToLower(chainName)))
actual, ok = k.GetChain(ctx, exported.ChainName(strings.ToLower(chainName)))

assert.True(t, ok)
assert.Equal(t, chain, actual)
Expand All @@ -164,14 +163,14 @@ func TestSetChainGetChain_UpperCaseChainName(t *testing.T) {
chain := makeRandomChain(chainName)

ctx := sdk.NewContext(fake.NewMultiStore(), tmproto.Header{}, false, log.TestingLogger())
keeper.SetChain(ctx, chain)
k.SetChain(ctx, chain)

actual, ok := keeper.GetChain(ctx, exported.ChainName(strings.ToUpper(chainName)))
actual, ok := k.GetChain(ctx, exported.ChainName(strings.ToUpper(chainName)))

assert.True(t, ok)
assert.Equal(t, chain, actual)

actual, ok = keeper.GetChain(ctx, exported.ChainName(strings.ToLower(chainName)))
actual, ok = k.GetChain(ctx, exported.ChainName(strings.ToLower(chainName)))

assert.True(t, ok)
assert.Equal(t, chain, actual)
Expand All @@ -182,14 +181,14 @@ func TestSetChainGetChain_LowerCaseChainName(t *testing.T) {
chain := makeRandomChain(chainName)

ctx := sdk.NewContext(fake.NewMultiStore(), tmproto.Header{}, false, log.TestingLogger())
keeper.SetChain(ctx, chain)
k.SetChain(ctx, chain)

actual, ok := keeper.GetChain(ctx, exported.ChainName(strings.ToUpper(chainName)))
actual, ok := k.GetChain(ctx, exported.ChainName(strings.ToUpper(chainName)))

assert.True(t, ok)
assert.Equal(t, chain, actual)

actual, ok = keeper.GetChain(ctx, exported.ChainName(strings.ToLower(chainName)))
actual, ok = k.GetChain(ctx, exported.ChainName(strings.ToLower(chainName)))

assert.True(t, ok)
assert.Equal(t, chain, actual)
Expand Down
11 changes: 9 additions & 2 deletions x/nexus/keeper/migrate.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package keeper

import (
"github.com/axelarnetwork/axelar-core/x/nexus/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// GetMigrationHandler returns the handler that performs in-place store migrations
func GetMigrationHandler(k Keeper) func(ctx sdk.Context) error {
// Migrate6to7 returns the handler that performs in-place store migrations
func Migrate6to7(k Keeper) func(ctx sdk.Context) error {
return func(ctx sdk.Context) error {
addModuleParamConnectionRouter(ctx, k)

return nil
}
}

func addModuleParamConnectionRouter(ctx sdk.Context, k Keeper) {
k.params.Set(ctx, types.KeyConnectionRouter, types.DefaultParams().ConnectionRouter)
}
56 changes: 56 additions & 0 deletions x/nexus/keeper/migrate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package keeper_test

import (
"testing"

"github.com/axelarnetwork/axelar-core/app"
"github.com/axelarnetwork/axelar-core/testutils/fake"
sdk "github.com/cosmos/cosmos-sdk/types"
params "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/stretchr/testify/assert"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/axelarnetwork/axelar-core/x/nexus/keeper"
"github.com/axelarnetwork/axelar-core/x/nexus/types"
. "github.com/axelarnetwork/utils/test"
)

func TestMigrate6to7(t *testing.T) {
encCfg := app.MakeEncodingConfig()
subspace := params.NewSubspace(encCfg.Codec, encCfg.Amino, sdk.NewKVStoreKey("nexusKey"), sdk.NewKVStoreKey("tNexusKey"), "nexus")
k := keeper.NewKeeper(encCfg.Codec, sdk.NewKVStoreKey("nexus"), subspace)
ctx := sdk.NewContext(fake.NewMultiStore(), tmproto.Header{}, false, log.TestingLogger())

Given("subspace is setup with params before migration", func() {
subspace.Set(ctx, types.KeyChainActivationThreshold, types.DefaultParams().ChainActivationThreshold)
subspace.Set(ctx, types.KeyChainMaintainerMissingVoteThreshold, types.DefaultParams().ChainMaintainerMissingVoteThreshold)
subspace.Set(ctx, types.KeyChainMaintainerIncorrectVoteThreshold, types.DefaultParams().ChainMaintainerIncorrectVoteThreshold)
subspace.Set(ctx, types.KeyChainMaintainerCheckWindow, types.DefaultParams().ChainMaintainerCheckWindow)
}).
When("", func() {}).
Then("the migration should add the new param with the default value", func(t *testing.T) {
actual := sdk.AccAddress{}

assert.PanicsWithError(t, "UnmarshalJSON cannot decode empty bytes", func() {
subspace.Get(ctx, types.KeyConnectionRouter, &actual)
})
assert.PanicsWithError(t, "UnmarshalJSON cannot decode empty bytes", func() {
k.GetParams(ctx)
})

keeper.Migrate6to7(k)(ctx)

assert.NotPanics(t, func() {
subspace.Get(ctx, types.KeyConnectionRouter, &actual)
})
assert.NotPanics(t, func() {
k.GetParams(ctx)
})

assert.Len(t, actual, 0)
assert.Len(t, k.GetParams(ctx).ConnectionRouter, 0)
}).
Run(t)

}
11 changes: 5 additions & 6 deletions x/nexus/keeper/rate_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/axelarnetwork/axelar-core/testutils/rand"
"github.com/axelarnetwork/axelar-core/utils"
"github.com/axelarnetwork/axelar-core/x/nexus/exported"
nexus "github.com/axelarnetwork/axelar-core/x/nexus/exported"
nexustestutils "github.com/axelarnetwork/axelar-core/x/nexus/exported/testutils"
nexusKeeper "github.com/axelarnetwork/axelar-core/x/nexus/keeper"
"github.com/axelarnetwork/utils/funcs"
Expand All @@ -28,7 +27,7 @@ func TestSetRateLimit(t *testing.T) {
var (
k nexusKeeper.Keeper
ctx sdk.Context
chain nexus.ChainName
chain exported.ChainName
asset string
limit sdk.Coin
window time.Duration
Expand All @@ -40,7 +39,7 @@ func TestSetRateLimit(t *testing.T) {

whenAssetIsRegistered := When("asset is registered", func() {
nexusChain := funcs.MustOk(k.GetChain(ctx, chain))
err := k.RegisterAsset(ctx, nexusChain, nexus.NewAsset(asset, false), utils.MaxUint, time.Hour)
err := k.RegisterAsset(ctx, nexusChain, exported.NewAsset(asset, false), utils.MaxUint, time.Hour)
assert.NoError(t, err)
})

Expand All @@ -53,7 +52,7 @@ func TestSetRateLimit(t *testing.T) {

givenKeeper.
When("using a non existent chain", func() {
chain = nexus.ChainName(rand.StrBetween(1, 20))
chain = exported.ChainName(rand.StrBetween(1, 20))
asset = rand.Denom(3, 20)
limit = sdk.NewInt64Coin(asset, mathrand.Int63())
window = rand.Duration()
Expand Down Expand Up @@ -127,7 +126,7 @@ func TestRateLimitTransfer(t *testing.T) {
var (
k nexusKeeper.Keeper
ctx sdk.Context
chain nexus.ChainName
chain exported.ChainName
denom string
asset sdk.Coin
direction exported.TransferDirection
Expand All @@ -143,7 +142,7 @@ func TestRateLimitTransfer(t *testing.T) {
chain = randChain(k, ctx).Name
denom = rand.Denom(3, 20)
nexusChain := funcs.MustOk(k.GetChain(ctx, chain))
err := k.RegisterAsset(ctx, nexusChain, nexus.NewAsset(denom, false), utils.MaxUint, time.Hour)
err := k.RegisterAsset(ctx, nexusChain, exported.NewAsset(denom, false), utils.MaxUint, time.Hour)
assert.NoError(t, err)
})

Expand Down
Loading

0 comments on commit 98ae33a

Please sign in to comment.