diff --git a/app/app.go b/app/app.go index 9d1a74c6..87daea69 100644 --- a/app/app.go +++ b/app/app.go @@ -381,8 +381,8 @@ func NewComposableApp( icqModule, ibcHooksModule, consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper), - wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)), wasm08.NewAppModule(app.Wasm08Keeper), + wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)), pfmModule, transfermiddlewareModule, txBoundaryModule, diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index a2b3c194..97fe25c6 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -566,7 +566,7 @@ func (appKeepers *AppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legac keyTable := ibcclienttypes.ParamKeyTable() keyTable.RegisterParamSet(&ibcconnectiontypes.Params{}) paramsKeeper.Subspace(ibcexported.ModuleName).WithKeyTable(keyTable) - paramsKeeper.Subspace(ibctransfertypes.ModuleName).WithKeyTable(ibctransfertypes.ParamKeyTable()) + paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(icacontrollertypes.SubModuleName).WithKeyTable(icacontrollertypes.ParamKeyTable()) paramsKeeper.Subspace(icahosttypes.SubModuleName).WithKeyTable(icahosttypes.ParamKeyTable()) @@ -583,7 +583,7 @@ func (appKeepers *AppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legac paramsKeeper.Subspace(icqtypes.ModuleName).WithKeyTable(icqtypes.ParamKeyTable()) paramsKeeper.Subspace(wasm08types.ModuleName) paramsKeeper.Subspace(wasmtypes.ModuleName) - paramsKeeper.Subspace(transfermiddlewaretypes.ModuleName).WithKeyTable(transfermiddlewaretypes.ParamKeyTable()) + paramsKeeper.Subspace(transfermiddlewaretypes.ModuleName) paramsKeeper.Subspace(stakingmiddlewaretypes.ModuleName) paramsKeeper.Subspace(ibctransfermiddlewaretypes.ModuleName) diff --git a/go.mod b/go.mod index 666e5781..611c369d 100644 --- a/go.mod +++ b/go.mod @@ -361,8 +361,9 @@ replace ( github.com/CosmWasm/wasmvm => github.com/CosmWasm/wasmvm v1.5.2 github.com/cosmos/cosmos-sdk => github.com/notional-labs/cosmos-sdk v0.50.5-patch-validators-trim-tag + // github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 => github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.0-20240504082418-e4d8c9cb7044 github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 => github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.0-20240503092956-16204721528b - // github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 => github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.0-20240501060940-654293260efb + github.com/cosmos/ibc-go/v8 => github.com/notional-labs/ibc-go/v8 v8.0.0-20240504081627-8ee51f5d7278 // use cosmos-compatible protobufs github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 diff --git a/go.sum b/go.sum index 1436ea9c..e7dfa16c 100644 --- a/go.sum +++ b/go.sum @@ -828,8 +828,6 @@ github.com/cosmos/ibc-go/modules/capability v1.0.0 h1:r/l++byFtn7jHYa09zlAdSeevo github.com/cosmos/ibc-go/modules/capability v1.0.0/go.mod h1:D81ZxzjZAe0ZO5ambnvn1qedsFQ8lOwtqicG6liLBco= github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092650-57fcdb9a9a9d h1:F4mhR61RZU4KJ38n5CeZrnNINU/KxMfP1sKfk5fTlHA= github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092650-57fcdb9a9a9d/go.mod h1:u2FXNcSxzzn5IwjWBA51HKMwiYMRK6/G35VmSJULhP0= -github.com/cosmos/ibc-go/v8 v8.2.1 h1:MTsnZZjxvGD4Fv5pYyx5UkELafSX0rlPt6IfsE2BpTQ= -github.com/cosmos/ibc-go/v8 v8.2.1/go.mod h1:wj3qx75iC/XNnsMqbPDCIGs0G6Y3E/lo3bdqCyoCy+8= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0= github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 h1:DdzS1m6o/pCqeZ8VOAit/gyATedRgjvkVI+UCrLpyuU= @@ -1389,6 +1387,8 @@ github.com/notional-labs/cosmos-sdk v0.50.5-patch-validators-trim-tag h1:lnMn2O2 github.com/notional-labs/cosmos-sdk v0.50.5-patch-validators-trim-tag/go.mod h1:oV/k6GJgXV9QPoM2fsYDPPsyPBgQbdotv532O6Mz1OQ= github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.0-20240503092956-16204721528b h1:4T8dAAY8Sou9ib7t+5NW8W+WfCz2PKTG5tubmun9Sko= github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.0-20240503092956-16204721528b/go.mod h1:dgFaRgM0YjzSBQ8zPLmBaQzMul8eNYPHu5EN84t5rYY= +github.com/notional-labs/ibc-go/v8 v8.0.0-20240504081627-8ee51f5d7278 h1:/NOkBq9mYJIGHWKEYbz2qOSQETw6hBPGzS4/64ZcUsk= +github.com/notional-labs/ibc-go/v8 v8.0.0-20240504081627-8ee51f5d7278/go.mod h1:wj3qx75iC/XNnsMqbPDCIGs0G6Y3E/lo3bdqCyoCy+8= github.com/nunnatsa/ginkgolinter v0.9.0 h1:Sm0zX5QfjJzkeCjEp+t6d3Ha0jwvoDjleP9XCsrEzOA= github.com/nunnatsa/ginkgolinter v0.9.0/go.mod h1:FHaMLURXP7qImeH6bvxWJUpyH+2tuqe5j4rW1gxJRmI= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= diff --git a/tests/interchaintest/contracts/ibchooks_counter.wasm b/tests/interchaintest/contracts/ibchooks_counter.wasm new file mode 100644 index 00000000..938171ef Binary files /dev/null and b/tests/interchaintest/contracts/ibchooks_counter.wasm differ diff --git a/tests/interchaintest/forward_timeout_test.go b/tests/interchaintest/forward_timeout_test.go index 40690451..4eb93bbc 100644 --- a/tests/interchaintest/forward_timeout_test.go +++ b/tests/interchaintest/forward_timeout_test.go @@ -3,6 +3,7 @@ package interchaintest import ( "context" "encoding/json" + sdk "github.com/cosmos/cosmos-sdk/types" "testing" "time" @@ -155,9 +156,9 @@ func TestTimeoutOnForward(t *testing.T) { secondHopIBCDenom := secondHopDenomTrace.IBCDenom() thirdHopIBCDenom := thirdHopDenomTrace.IBCDenom() - firstHopEscrowAccount := transfertypes.GetEscrowAddress(abChan.PortID, abChan.ChannelID).String() - secondHopEscrowAccount := transfertypes.GetEscrowAddress(bcChan.PortID, bcChan.ChannelID).String() - thirdHopEscrowAccount := transfertypes.GetEscrowAddress(cdChan.PortID, abChan.ChannelID).String() + firstHopEscrowAccount := sdk.MustBech32ifyAddressBytes(chainA.Config().Bech32Prefix, transfertypes.GetEscrowAddress(abChan.PortID, abChan.ChannelID)) + secondHopEscrowAccount := sdk.MustBech32ifyAddressBytes(chainB.Config().Bech32Prefix, transfertypes.GetEscrowAddress(bcChan.PortID, bcChan.ChannelID)) + thirdHopEscrowAccount := sdk.MustBech32ifyAddressBytes(chainC.Config().Bech32Prefix, transfertypes.GetEscrowAddress(cdChan.PortID, abChan.ChannelID)) zeroBal := math.ZeroInt() transferAmount := math.NewInt(100_000) diff --git a/tests/interchaintest/helpers/cosmwasm.go b/tests/interchaintest/helpers/cosmwasm.go new file mode 100644 index 00000000..bc722914 --- /dev/null +++ b/tests/interchaintest/helpers/cosmwasm.go @@ -0,0 +1,176 @@ +package helpers + +import ( + "context" + "encoding/json" + "testing" + + "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" + "github.com/strangelove-ventures/interchaintest/v8/ibc" + "github.com/strangelove-ventures/interchaintest/v8/testutil" + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/cosmos-sdk/crypto/keyring" +) + +func SmartQueryString(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, contractAddr, queryMsg string, res interface{}) error { + var jsonMap map[string]interface{} + if err := json.Unmarshal([]byte(queryMsg), &jsonMap); err != nil { + t.Fatal(err) + } + err := chain.QueryContract(ctx, contractAddr, jsonMap, &res) + return err +} + +func StoreContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, keyname string, fileLoc string) (codeId string) { + codeId, err := chain.StoreContract(ctx, keyname, fileLoc) + if err != nil { + t.Fatal(err) + } + return codeId +} + +func SetupContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, keyname string, fileLoc string, message string, extraFlags ...string) (codeId, contract string) { + codeId = StoreContract(t, ctx, chain, keyname, fileLoc) + + needsNoAdminFlag := true + // if extraFlags contains "--admin", switch to false + for _, flag := range extraFlags { + if flag == "--admin" { + needsNoAdminFlag = false + } + } + + contractAddr, err := chain.InstantiateContract(ctx, keyname, codeId, message, needsNoAdminFlag, extraFlags...) + if err != nil { + t.Fatal(err) + } + + return codeId, contractAddr +} + +func MigrateContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, keyname string, contractAddr string, fileLoc string, message string) (codeId, contract string) { + codeId, err := chain.StoreContract(ctx, keyname, fileLoc) + if err != nil { + t.Fatal(err) + } + + // Execute migrate tx + cmd := []string{ + "junod", "tx", "wasm", "migrate", contractAddr, codeId, message, + "--node", chain.GetRPCAddress(), + "--home", chain.HomeDir(), + "--chain-id", chain.Config().ChainID, + "--from", keyname, + "--gas", "500000", + "--keyring-dir", chain.HomeDir(), + "--keyring-backend", keyring.BackendTest, + "-y", + } + + stdout, _, err := chain.Exec(ctx, cmd, nil) + require.NoError(t, err) + + debugOutput(t, string(stdout)) + + if err := testutil.WaitForBlocks(ctx, 2, chain); err != nil { + t.Fatal(err) + } + + return codeId, contractAddr +} + +func ExecuteMsgWithAmount(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, contractAddr, amount, message string) { + // amount is #utoken + + // There has to be a way to do this in ictest? + cmd := []string{ + "junod", "tx", "wasm", "execute", contractAddr, message, + "--node", chain.GetRPCAddress(), + "--home", chain.HomeDir(), + "--chain-id", chain.Config().ChainID, + "--from", user.KeyName(), + "--gas", "500000", + "--amount", amount, + "--keyring-dir", chain.HomeDir(), + "--keyring-backend", keyring.BackendTest, + "-y", + } + stdout, _, err := chain.Exec(ctx, cmd, nil) + require.NoError(t, err) + + debugOutput(t, string(stdout)) + + if err := testutil.WaitForBlocks(ctx, 2, chain); err != nil { + t.Fatal(err) + } +} + +func ExecuteMsgWithFee(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, contractAddr, amount, feeCoin, message string) { + // amount is #utoken + + // There has to be a way to do this in ictest? + cmd := []string{ + "junod", "tx", "wasm", "execute", contractAddr, message, + "--node", chain.GetRPCAddress(), + "--home", chain.HomeDir(), + "--chain-id", chain.Config().ChainID, + "--from", user.KeyName(), + "--gas", "500000", + "--fees", feeCoin, + "--keyring-dir", chain.HomeDir(), + "--keyring-backend", keyring.BackendTest, + "-y", + } + + if amount != "" { + cmd = append(cmd, "--amount", amount) + } + + stdout, _, err := chain.Exec(ctx, cmd, nil) + require.NoError(t, err) + + debugOutput(t, string(stdout)) + + if err := testutil.WaitForBlocks(ctx, 2, chain); err != nil { + t.Fatal(err) + } +} + +func ExecuteMsgWithFeeReturn(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, contractAddr, amount, feeCoin, message string) (*sdk.TxResponse, error) { + // amount is #utoken + + // There has to be a way to do this in ictest? (there is, use node.ExecTx) + cmd := []string{ + "wasm", "execute", contractAddr, message, + "--output", "json", + "--node", chain.GetRPCAddress(), + "--home", chain.HomeDir(), + "--gas", "500000", + "--fees", feeCoin, + "--keyring-dir", chain.HomeDir(), + } + + if amount != "" { + cmd = append(cmd, "--amount", amount) + } + + node := chain.GetNode() + + txHash, err := node.ExecTx(ctx, user.KeyName(), cmd...) + if err != nil { + return nil, err + } + + // convert stdout into a TxResponse + txRes, err := chain.GetTransaction(txHash) + return txRes, err +} + +func debugOutput(t *testing.T, stdout string) { + if true { + t.Log(stdout) + } +} diff --git a/tests/interchaintest/helpers/ibchooks.go b/tests/interchaintest/helpers/ibchooks.go new file mode 100644 index 00000000..aecb3889 --- /dev/null +++ b/tests/interchaintest/helpers/ibchooks.go @@ -0,0 +1,41 @@ +package helpers + +import ( + "context" + "strings" + "testing" + + "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" + "github.com/stretchr/testify/require" +) + +func GetIBCHooksUserAddress(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, channel, uaddr string) string { + // picad q ibchooks wasm-sender channel-0 "contractAddr" --node http://localhost:26657 + cmd := []string{ + "picad", "query", "ibchooks", "wasm-sender", channel, uaddr, + "--node", chain.GetRPCAddress(), + "--chain-id", chain.Config().ChainID, + "--output", "json", + } + + // This query does not return a type, just prints the string. + stdout, _, err := chain.Exec(ctx, cmd, nil) + require.NoError(t, err) + + address := strings.Replace(string(stdout), "\n", "", -1) + return address +} + +func GetIBCHookTotalFunds(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, contract string, uaddr string) GetTotalFundsResponse { + var res GetTotalFundsResponse + err := chain.QueryContract(ctx, contract, QueryMsg{GetTotalFunds: &GetTotalFundsQuery{Addr: uaddr}}, &res) + require.NoError(t, err) + return res +} + +func GetIBCHookCount(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, contract string, uaddr string) GetCountResponse { + var res GetCountResponse + err := chain.QueryContract(ctx, contract, QueryMsg{GetCount: &GetCountQuery{Addr: uaddr}}, &res) + require.NoError(t, err) + return res +} diff --git a/tests/interchaintest/helpers/types.go b/tests/interchaintest/helpers/types.go new file mode 100644 index 00000000..489bff5c --- /dev/null +++ b/tests/interchaintest/helpers/types.go @@ -0,0 +1,95 @@ +package helpers + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// Go based data types for querying on the contract. +// Execute types are not needed here. We just use strings. Could add though in the future and to_string it + +// EntryPoint +type QueryMsg struct { + // Tokenfactory Core + GetConfig *struct{} `json:"get_config,omitempty"` + GetBalance *GetBalanceQuery `json:"get_balance,omitempty"` + GetAllBalances *GetAllBalancesQuery `json:"get_all_balances,omitempty"` + + // Unity Contract + GetWithdrawalReadyTime *struct{} `json:"get_withdrawal_ready_time,omitempty"` + + // IBCHooks + GetCount *GetCountQuery `json:"get_count,omitempty"` + GetTotalFunds *GetTotalFundsQuery `json:"get_total_funds,omitempty"` +} + +type GetAllBalancesQuery struct { + Address string `json:"address"` +} +type GetAllBalancesResponse struct { + // or is it wasm Coin type? + Data []sdk.Coin `json:"data"` +} + +type GetBalanceQuery struct { + // {"get_balance":{"address":"juno1...","denom":"factory/juno1.../RcqfWz"}} + Address string `json:"address"` + Denom string `json:"denom"` +} +type GetBalanceResponse struct { + // or is it wasm Coin type? + Data sdk.Coin `json:"data"` +} + +type WithdrawalTimestampResponse struct { + // {"data":{"withdrawal_ready_timestamp":"1686146048614053435"}} + Data *WithdrawalTimestampObj `json:"data"` +} +type WithdrawalTimestampObj struct { + WithdrawalReadyTimestamp string `json:"withdrawal_ready_timestamp"` +} + +type GetTotalFundsQuery struct { + // {"get_total_funds":{"addr":"juno1..."}} + Addr string `json:"addr"` +} +type GetTotalFundsResponse struct { + // {"data":{"total_funds":[{"denom":"ibc/04F5F501207C3626A2C14BFEF654D51C2E0B8F7CA578AB8ED272A66FE4E48097","amount":"1"}]}} + Data *GetTotalFundsObj `json:"data"` +} +type GetTotalFundsObj struct { + TotalFunds []WasmCoin `json:"total_funds"` +} + +type WasmCoin struct { + Denom string `json:"denom"` + Amount string `json:"amount"` +} + +type GetCountQuery struct { + // {"get_total_funds":{"addr":"juno1..."}} + Addr string `json:"addr"` +} +type GetCountResponse struct { + // {"data":{"count":0}} + Data *GetCountObj `json:"data"` +} +type GetCountObj struct { + Count int64 `json:"count"` +} + +type ClockContractResponse struct { + Data *ClockContractObj `json:"data"` +} +type ClockContractObj struct { + Val uint32 `json:"val"` +} + +type GetCwHooksDelegationResponse struct { + // {"data":{"validator_address":"%s","delegator_address":"%s","shares":"%s"}} + Data *GetDelegationObj `json:"data"` +} +type GetDelegationObj struct { + ValidatorAddress string `json:"validator_address"` + DelegatorAddress string `json:"delegator_address"` + Shares string `json:"shares"` +} diff --git a/tests/interchaintest/module_ibchooks_test.go b/tests/interchaintest/module_ibchooks_test.go new file mode 100644 index 00000000..8ec17669 --- /dev/null +++ b/tests/interchaintest/module_ibchooks_test.go @@ -0,0 +1,183 @@ +package interchaintest + +import ( + "context" + "fmt" + "github.com/notional-labs/composable-testnet/tests/interchaintest/helpers" + "github.com/strangelove-ventures/interchaintest/v8" + "github.com/strangelove-ventures/interchaintest/v8/relayer" + "strings" + "testing" + + "cosmossdk.io/math" + "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" + "github.com/strangelove-ventures/interchaintest/v8/ibc" + interchaintestrelayer "github.com/strangelove-ventures/interchaintest/v8/relayer" + "github.com/strangelove-ventures/interchaintest/v8/testreporter" + "github.com/strangelove-ventures/interchaintest/v8/testutil" + "github.com/stretchr/testify/require" + "go.uber.org/zap/zaptest" +) + +// TestComposableIBCHooks ensures the ibc-hooks middleware from osmosis works. +func TestComposableIBCHooks(t *testing.T) { + if testing.Short() { + t.Skip() + } + + t.Parallel() + + // Create chain factory with Centauri and Centauri2 + numVals := 1 + numFullNodes := 0 + + cfg2 := CentauriConfig.Clone() + cfg2.Name = "composable-counterparty" + cfg2.ChainID = "counterparty-2" + + cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{ + { + Name: "Centauri", + ChainConfig: CentauriConfig, + NumValidators: &numVals, + NumFullNodes: &numFullNodes, + }, + { + Name: "Centauri", + ChainConfig: cfg2, + NumValidators: &numVals, + NumFullNodes: &numFullNodes, + }, + }) + + const ( + path = "ibc-path" + ) + + // Get chains from the chain factory + chains, err := cf.Chains(t.Name()) + require.NoError(t, err) + + client, network := interchaintest.DockerSetup(t) + + composable, composable2 := chains[0].(*cosmos.CosmosChain), chains[1].(*cosmos.CosmosChain) + + relayerType, relayerName := ibc.CosmosRly, "relay" + + // Get a relayer instance + rf := interchaintest.NewBuiltinRelayerFactory( + relayerType, + zaptest.NewLogger(t), + relayer.DockerImage(&DefaultRelayer), + interchaintestrelayer.StartupFlags("--processor", "events", "--block-history", "100"), + ) + + r := rf.Build(t, client, network) + + ic := interchaintest.NewInterchain(). + AddChain(composable). + AddChain(composable2). + AddRelayer(r, relayerName). + AddLink(interchaintest.InterchainLink{ + Chain1: composable, + Chain2: composable2, + Relayer: r, + Path: path, + }) + + ctx := context.Background() + + rep := testreporter.NewNopReporter() + eRep := rep.RelayerExecReporter(t) + + require.NoError(t, ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{ + TestName: t.Name(), + Client: client, + NetworkID: network, + BlockDatabaseFile: interchaintest.DefaultBlockDatabaseFilepath(), + SkipPathCreation: false, + })) + t.Cleanup(func() { + _ = ic.Close() + }) + + // Create some user accounts on both chains + users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), genesisWalletAmount, composable, composable2) + + // Wait a few blocks for relayer to start and for user accounts to be created + err = testutil.WaitForBlocks(ctx, 5, composable, composable2) + require.NoError(t, err) + + // Get our Bech32 encoded user addresses + composableUser, composable2User := users[0], users[1] + + composableUserAddr := composableUser.FormattedAddress() + // composable2UserAddr := composable2User.FormattedAddress() + + channel, err := ibc.GetTransferChannel(ctx, r, eRep, composable.Config().ChainID, composable2.Config().ChainID) + require.NoError(t, err) + + err = r.StartRelayer(ctx, eRep, path) + require.NoError(t, err) + + t.Cleanup( + func() { + err := r.StopRelayer(ctx, eRep) + if err != nil { + t.Logf("an error occurred while stopping the relayer: %s", err) + } + }, + ) + + _, contractAddr := helpers.SetupContract(t, ctx, composable2, composable2User.KeyName(), "contracts/ibchooks_counter.wasm", `{"count":0}`) + + // do an ibc transfer through the memo to the other chain. + transfer := ibc.WalletAmount{ + Address: contractAddr, + Denom: composable.Config().Denom, + Amount: math.NewInt(1), + } + + memo := ibc.TransferOptions{ + Memo: fmt.Sprintf(`{"wasm":{"contract":"%s","msg":%s}}`, contractAddr, `{"increment":{}}`), + } + + // Initial transfer. Account is created by the wasm execute is not so we must do this twice to properly set up + transferTx, err := composable.SendIBCTransfer(ctx, channel.ChannelID, composableUser.KeyName(), transfer, memo) + require.NoError(t, err) + composableHeight, err := composable.Height(ctx) + require.NoError(t, err) + + _, err = testutil.PollForAck(ctx, composable, composableHeight-5, composableHeight+25, transferTx.Packet) + require.NoError(t, err) + + // Second time, this will make the counter == 1 since the account is now created. + transferTx, err = composable.SendIBCTransfer(ctx, channel.ChannelID, composableUser.KeyName(), transfer, memo) + require.NoError(t, err) + composableHeight, err = composable.Height(ctx) + require.NoError(t, err) + + _, err = testutil.PollForAck(ctx, composable, composableHeight-5, composableHeight+25, transferTx.Packet) + require.NoError(t, err) + + // Get the address on the other chain's side + addr := helpers.GetIBCHooksUserAddress(t, ctx, composable, channel.ChannelID, composableUserAddr) + require.NotEmpty(t, addr) + + // Get funds on the receiving chain + funds := helpers.GetIBCHookTotalFunds(t, ctx, composable2, contractAddr, addr) + require.Equal(t, int(1), len(funds.Data.TotalFunds)) + + var ibcDenom string + for _, coin := range funds.Data.TotalFunds { + if strings.HasPrefix(coin.Denom, "ibc/") { + ibcDenom = coin.Denom + break + } + } + require.NotEmpty(t, ibcDenom) + + // ensure the count also increased to 1 as expected. + count := helpers.GetIBCHookCount(t, ctx, composable2, contractAddr, addr) + require.Equal(t, int64(1), count.Data.Count) +} diff --git a/tests/interchaintest/packet_forward_test.go b/tests/interchaintest/packet_forward_test.go index d2f66945..aa9bb736 100644 --- a/tests/interchaintest/packet_forward_test.go +++ b/tests/interchaintest/packet_forward_test.go @@ -552,7 +552,8 @@ func TestPacketForwardMiddleware(t *testing.T) { chainABalance, err := chainA.GetBalance(ctx, userA.FormattedAddress(), baIBCDenom) require.NoError(t, err) - baEscrowBalance, err := chainB.GetBalance(ctx, transfertypes.GetEscrowAddress(baChan.PortID, baChan.ChannelID).String(), chainB.Config().Denom) + addr := sdk.MustBech32ifyAddressBytes(chainB.Config().Bech32Prefix, transfertypes.GetEscrowAddress(baChan.PortID, baChan.ChannelID)) + baEscrowBalance, err := chainB.GetBalance(ctx, addr, chainB.Config().Denom) require.NoError(t, err) require.True(t, chainABalance.Equal(transferAmount)) @@ -621,13 +622,16 @@ func TestPacketForwardMiddleware(t *testing.T) { require.True(t, chainDBalance.Equal(zeroBal)) // assert balances for IBC escrow accounts - cdEscrowBalance, err := chainC.GetBalance(ctx, transfertypes.GetEscrowAddress(cdChan.PortID, cdChan.ChannelID).String(), bcIBCDenom) + addr = sdk.MustBech32ifyAddressBytes(chainC.Config().Bech32Prefix, transfertypes.GetEscrowAddress(cdChan.PortID, cdChan.ChannelID)) + cdEscrowBalance, err := chainC.GetBalance(ctx, addr, bcIBCDenom) require.NoError(t, err) - bcEscrowBalance, err := chainB.GetBalance(ctx, transfertypes.GetEscrowAddress(bcChan.PortID, bcChan.ChannelID).String(), chainB.Config().Denom) + addr = sdk.MustBech32ifyAddressBytes(chainB.Config().Bech32Prefix, transfertypes.GetEscrowAddress(bcChan.PortID, bcChan.ChannelID)) + bcEscrowBalance, err := chainB.GetBalance(ctx, addr, chainB.Config().Denom) require.NoError(t, err) - baEscrowBalance, err = chainB.GetBalance(ctx, transfertypes.GetEscrowAddress(baChan.PortID, baChan.ChannelID).String(), chainB.Config().Denom) + addr = sdk.MustBech32ifyAddressBytes(chainB.Config().Bech32Prefix, transfertypes.GetEscrowAddress(baChan.PortID, baChan.ChannelID)) + baEscrowBalance, err = chainB.GetBalance(ctx, addr, chainB.Config().Denom) require.NoError(t, err) require.True(t, baEscrowBalance.Equal(transferAmount))