Skip to content

Commit

Permalink
unordered test
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Aug 22, 2024
1 parent 9de1a7f commit 959c7b3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
11 changes: 6 additions & 5 deletions wasmbinding/message_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"time"

types1 "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"

"github.com/cosmos/gogoproto/proto"

Expand Down Expand Up @@ -868,15 +868,16 @@ func (m *CustomMessenger) registerInterchainAccount(ctx sdk.Context, contractAdd

func (m *CustomMessenger) performRegisterInterchainAccount(ctx sdk.Context, contractAddr sdk.AccAddress, reg *bindings.RegisterInterchainAccount) (*ictxtypes.MsgRegisterInterchainAccountResponse, error) {
// parse incoming ordering. If nothing passed, use ORDERED by default
var orderValue types1.Order
var orderValue channeltypes.Order
if reg.Ordering == "" {
orderValue = types1.ORDERED
orderValue = channeltypes.ORDERED
} else {
orderValueInt, ok := types1.Order_value[reg.Ordering]
orderValueInt, ok := channeltypes.Order_value[reg.Ordering]

if !ok {
return nil, fmt.Errorf("failed to register interchain account: incorrect order value passed: %s", reg.Ordering)
}
orderValue = types1.Order(orderValueInt)
orderValue = channeltypes.Order(orderValueInt)
}

msg := ictxtypes.MsgRegisterInterchainAccount{
Expand Down
51 changes: 50 additions & 1 deletion wasmbinding/test/custom_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,23 @@ func (suite *CustomMessengerTestSuite) TestRegisterInterchainAccount() {
}

bankKeeper := suite.neutron.BankKeeper
channelKeeper := suite.neutron.IBCKeeper.ChannelKeeper
senderAddress := suite.ChainA.SenderAccounts[0].SenderAccount.GetAddress()
err = bankKeeper.SendCoins(suite.ctx, senderAddress, suite.contractAddress, sdk.NewCoins(sdk.NewCoin(params.DefaultDenom, math.NewInt(1_000_000))))
suite.NoError(err)

// Dispatch RegisterInterchainAccount message
_, err = suite.executeNeutronMsg(suite.contractAddress, msg)
data, err := suite.executeNeutronMsg(suite.contractAddress, msg)
suite.NoError(err)
suite.NotEmpty(data)

// default method should be ordered
var response ictxtypes.MsgRegisterInterchainAccountResponse
err = response.Unmarshal(data)
suite.NoError(err)
channel, found := channelKeeper.GetChannel(suite.ctx, response.PortId, response.ChannelId)
suite.True(found)
suite.Equal(channel.Ordering, ibcchanneltypes.ORDERED)
}

func (suite *CustomMessengerTestSuite) TestRegisterInterchainAccountLongID() {
Expand All @@ -130,6 +140,43 @@ func (suite *CustomMessengerTestSuite) TestRegisterInterchainAccountLongID() {
suite.ErrorIs(err, ictxtypes.ErrLongInterchainAccountID)
}

func (suite *CustomMessengerTestSuite) TestRegisterInterchainAccountUnordered() {
err := suite.neutron.FeeBurnerKeeper.SetParams(suite.ctx, feeburnertypes.Params{
NeutronDenom: "untrn",
TreasuryAddress: "neutron13jrwrtsyjjuynlug65r76r2zvfw5xjcq6532h2",
})
suite.Require().NoError(err)

// Craft RegisterInterchainAccount message
msg := bindings.NeutronMsg{
RegisterInterchainAccount: &bindings.RegisterInterchainAccount{
ConnectionId: suite.Path.EndpointA.ConnectionID,
InterchainAccountId: testutil.TestInterchainID,
RegisterFee: sdk.NewCoins(sdk.NewCoin(params.DefaultDenom, math.NewInt(1_000_000))),
Ordering: ibcchanneltypes.Order_name[int32(ibcchanneltypes.UNORDERED)],
},
}

bankKeeper := suite.neutron.BankKeeper
channelKeeper := suite.neutron.IBCKeeper.ChannelKeeper
senderAddress := suite.ChainA.SenderAccounts[0].SenderAccount.GetAddress()
err = bankKeeper.SendCoins(suite.ctx, senderAddress, suite.contractAddress, sdk.NewCoins(sdk.NewCoin(params.DefaultDenom, math.NewInt(1_000_000))))
suite.NoError(err)

// Dispatch RegisterInterchainAccount message
data, err := suite.executeNeutronMsg(suite.contractAddress, msg)
suite.NoError(err)
suite.NotEmpty(data)

// default method should be ordered
var response ictxtypes.MsgRegisterInterchainAccountResponse
err = response.Unmarshal(data)
suite.NoError(err)
channel, found := channelKeeper.GetChannel(suite.ctx, response.PortId, response.ChannelId)
suite.True(found)
suite.Equal(channel.Ordering, ibcchanneltypes.UNORDERED)
}

func (suite *CustomMessengerTestSuite) TestRegisterInterchainQuery() {
err := testutil.SetupICAPath(suite.Path, suite.contractAddress.String())
suite.Require().NoError(err)
Expand Down Expand Up @@ -777,6 +824,8 @@ func (suite *CustomMessengerTestSuite) executeNeutronMsg(contractAddress sdk.Acc
fullMsgBz, err := json.Marshal(fullMsg)
suite.NoError(err)

fmt.Printf("Marshalled msg: %s\n", string(fullMsgBz))

return suite.executeCustomMsg(contractAddress, fullMsgBz)
}

Expand Down
Binary file modified wasmbinding/testdata/reflect.wasm
Binary file not shown.

0 comments on commit 959c7b3

Please sign in to comment.