Skip to content

Commit

Permalink
refactor(nexus): rename param ConnectionRouter to Gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
fish-sammy committed Sep 29, 2023
1 parent 4fb24b0 commit 2d3262e
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 80 deletions.
2 changes: 1 addition & 1 deletion client/docs/static/openapi/index.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions client/docs/static/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13787,7 +13787,7 @@ paths:
chain_maintainer_check_window:
type: integer
format: int32
connection_router:
gateway:
type: string
format: byte
title: Params represent the genesis parameters for the module
Expand Down Expand Up @@ -47029,7 +47029,7 @@ components:
chain_maintainer_check_window:
type: integer
format: int32
connection_router:
gateway:
type: string
format: byte
title: Params represent the genesis parameters for the module
Expand Down Expand Up @@ -47084,7 +47084,7 @@ components:
chain_maintainer_check_window:
type: integer
format: int32
connection_router:
gateway:
type: string
format: byte
title: Params represent the genesis parameters for the module
Expand Down
6 changes: 3 additions & 3 deletions client/docs/static/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15166,7 +15166,7 @@ paths:
chain_maintainer_check_window:
type: integer
format: int32
connection_router:
gateway:
type: string
format: byte
title: Params represent the genesis parameters for the module
Expand Down Expand Up @@ -51034,7 +51034,7 @@ definitions:
chain_maintainer_check_window:
type: integer
format: int32
connection_router:
gateway:
type: string
format: byte
title: Params represent the genesis parameters for the module
Expand Down Expand Up @@ -51089,7 +51089,7 @@ definitions:
chain_maintainer_check_window:
type: integer
format: int32
connection_router:
gateway:
type: string
format: byte
title: Params represent the genesis parameters for the module
Expand Down
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/proto/proto-docs.md

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

5 changes: 2 additions & 3 deletions proto/axelar/nexus/v1beta1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ 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" ];
bytes gateway = 5 [ (gogoproto.casttype) =
"github.com/cosmos/cosmos-sdk/types.AccAddress" ];
}
6 changes: 3 additions & 3 deletions x/nexus/keeper/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
// 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)
addModuleParamGateway(ctx, k)

return nil
}
}

func addModuleParamConnectionRouter(ctx sdk.Context, k Keeper) {
k.params.Set(ctx, types.KeyConnectionRouter, types.DefaultParams().ConnectionRouter)
func addModuleParamGateway(ctx sdk.Context, k Keeper) {
k.params.Set(ctx, types.KeyGateway, types.DefaultParams().Gateway)
}
8 changes: 4 additions & 4 deletions x/nexus/keeper/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestMigrate6to7(t *testing.T) {
actual := sdk.AccAddress{}

assert.PanicsWithError(t, "UnmarshalJSON cannot decode empty bytes", func() {
subspace.Get(ctx, types.KeyConnectionRouter, &actual)
subspace.Get(ctx, types.KeyGateway, &actual)
})
assert.PanicsWithError(t, "UnmarshalJSON cannot decode empty bytes", func() {
k.GetParams(ctx)
Expand All @@ -42,14 +42,14 @@ func TestMigrate6to7(t *testing.T) {
keeper.Migrate6to7(k)(ctx)

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

assert.Equal(t, types.DefaultParams().ConnectionRouter, actual)
assert.Equal(t, types.DefaultParams().ConnectionRouter, k.GetParams(ctx).ConnectionRouter)
assert.Equal(t, types.DefaultParams().Gateway, actual)
assert.Equal(t, types.DefaultParams().Gateway, k.GetParams(ctx).Gateway)
}).
Run(t)

Expand Down
13 changes: 6 additions & 7 deletions x/nexus/keeper/msg_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,21 @@ func NewMessenger(nexus types.Nexus) Messenger {
return Messenger{nexus}
}

// DispatchMsg decodes the messages from the cosmowasm connection router and routes them to the nexus module if possible
// DispatchMsg decodes the messages from the cosmowasm gateway and routes them to the nexus module if possible
func (m Messenger) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddress, _ string, msg wasmvmtypes.CosmosMsg) (events []sdk.Event, data [][]byte, err error) {
req := request{}
if err := json.Unmarshal(msg.Custom, &req); err != nil {
return nil, nil, sdkerrors.Wrap(wasmtypes.ErrUnknownMsg, err.Error())
}

// TODO: rename to gateway
connectionRouter := m.GetParams(ctx).ConnectionRouter
gateway := m.GetParams(ctx).Gateway

if len(connectionRouter) == 0 {
return nil, nil, fmt.Errorf("connection router is not set")
if len(gateway) == 0 {
return nil, nil, fmt.Errorf("gateway is not set")
}

if !connectionRouter.Equals(contractAddr) {
return nil, nil, fmt.Errorf("contract address %s is not the connection router", contractAddr)
if !gateway.Equals(contractAddr) {
return nil, nil, fmt.Errorf("contract address %s is not the gateway", contractAddr)
}

if err := m.routeMsg(ctx, req); err != nil {
Expand Down
18 changes: 9 additions & 9 deletions x/nexus/keeper/msg_dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,44 +60,44 @@ func TestMessenger_DispatchMsg(t *testing.T) {
}
}).
Branch(
When("the connection router is not set", func() {
When("the gateway is not set", func() {
nexus.GetParamsFunc = func(_ sdk.Context) types.Params {
return types.DefaultParams()
}
}).
Then("should return error", func(t *testing.T) {
_, _, err := messenger.DispatchMsg(ctx, contractAddr, "", msg)

assert.ErrorContains(t, err, "connection router is not set")
assert.ErrorContains(t, err, "gateway is not set")
assert.False(t, errors.Is(err, wasmtypes.ErrUnknownMsg))
}),

When("the connection router is set but given contract address does not match", func() {
When("the gateway is set but given contract address does not match", func() {
nexus.GetParamsFunc = func(_ sdk.Context) types.Params {
params := types.DefaultParams()
params.ConnectionRouter = rand.AccAddr()
params.Gateway = rand.AccAddr()

return params
}
}).
Then("should return error", func(t *testing.T) {
_, _, err := messenger.DispatchMsg(ctx, contractAddr, "", msg)

assert.ErrorContains(t, err, "is not the connection router")
assert.ErrorContains(t, err, "is not the gateway")
assert.False(t, errors.Is(err, wasmtypes.ErrUnknownMsg))
}),
).
Run(t)

givenMessenger.
When("the msg is encoded correctly and the connection router is set correctly", func() {
When("the msg is encoded correctly and the gateway is set correctly", func() {
msg = wasmvmtypes.CosmosMsg{
Custom: []byte("{}"),
}

nexus.GetParamsFunc = func(_ sdk.Context) types.Params {
params := types.DefaultParams()
params.ConnectionRouter = contractAddr
params.Gateway = contractAddr

return params
}
Expand Down Expand Up @@ -137,10 +137,10 @@ func TestMessenger_DispatchMsg(t *testing.T) {
Run(t)

givenMessenger.
When("the connection router is set correctly", func() {
When("the gateway is set correctly", func() {
nexus.GetParamsFunc = func(_ sdk.Context) types.Params {
params := types.DefaultParams()
params.ConnectionRouter = contractAddr
params.Gateway = contractAddr

return params
}
Expand Down
16 changes: 8 additions & 8 deletions x/nexus/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ var (
KeyChainMaintainerIncorrectVoteThreshold = []byte("chainMaintainerIncorrectVoteThreshold")
// KeyChainMaintainerCheckWindow represents the key for chain maintainer check window
KeyChainMaintainerCheckWindow = []byte("chainMaintainerCheckWindow")
// KeyConnectionRouter represents the key for connection router's address
KeyConnectionRouter = []byte("connectionRouter")
// KeyGateway represents the key for the gateway's address
KeyGateway = []byte("gateway")
)

// KeyTable retrieves a subspace table for the module
Expand All @@ -36,7 +36,7 @@ func DefaultParams() Params {
ChainMaintainerMissingVoteThreshold: utils.NewThreshold(20, 100),
ChainMaintainerIncorrectVoteThreshold: utils.NewThreshold(15, 100),
ChainMaintainerCheckWindow: 500,
ConnectionRouter: sdk.AccAddress{},
Gateway: sdk.AccAddress{},
}
}

Expand All @@ -54,7 +54,7 @@ func (m *Params) ParamSetPairs() params.ParamSetPairs {
params.NewParamSetPair(KeyChainMaintainerMissingVoteThreshold, &m.ChainMaintainerMissingVoteThreshold, validateThresholdWith("ChainMaintainerMissingVoteThreshold")),
params.NewParamSetPair(KeyChainMaintainerIncorrectVoteThreshold, &m.ChainMaintainerIncorrectVoteThreshold, validateThresholdWith("ChainMaintainerIncorrectVoteThreshold")),
params.NewParamSetPair(KeyChainMaintainerCheckWindow, &m.ChainMaintainerCheckWindow, validateChainMaintainerCheckWindow),
params.NewParamSetPair(KeyConnectionRouter, &m.ConnectionRouter, validateConnectionRouter),
params.NewParamSetPair(KeyGateway, &m.Gateway, validateGateway),
}
}

Expand All @@ -76,7 +76,7 @@ func (m Params) Validate() error {
return err
}

if err := validateConnectionRouter(m.ConnectionRouter); err != nil {
if err := validateGateway(m.Gateway); err != nil {
return err
}

Expand Down Expand Up @@ -115,18 +115,18 @@ func validateChainMaintainerCheckWindow(i interface{}) error {
return nil
}

func validateConnectionRouter(i interface{}) error {
func validateGateway(i interface{}) error {
val, ok := i.(sdk.AccAddress)
if !ok {
return fmt.Errorf("invalid parameter type for ConnectionRouter: %T", i)
return fmt.Errorf("invalid parameter type for Gateway: %T", i)
}

if len(val) == 0 {
return nil
}

if err := sdk.VerifyAddressFormat(val); err != nil {
return sdkerrors.Wrap(err, "invalid ConnectionRouter")
return sdkerrors.Wrap(err, "invalid Gateway")
}

return nil
Expand Down
73 changes: 36 additions & 37 deletions x/nexus/types/params.pb.go

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

0 comments on commit 2d3262e

Please sign in to comment.