From 22fb6bce9243cec968a064ec1a6a4fb8075087f7 Mon Sep 17 00:00:00 2001 From: Tomasz Kulik Date: Fri, 17 Jan 2025 10:20:10 +0100 Subject: [PATCH] chore: Progress --- tests/e2e/gov_test.go | 12 +-- tests/e2e/grants_test.go | 19 ++--- tests/e2e/group_test.go | 11 +-- tests/e2e/ibc_callbacks_test.go | 29 ++++--- tests/e2e/ibc_fees_test.go | 16 ++-- tests/e2e/ica_test.go | 18 ++--- tests/e2e/reflect_helper.go | 14 ++-- tests/ibctesting/chain2.go | 96 ++++++++++++++++++++++- tests/integration/ibc_integration_test.go | 59 +++++++------- tests/integration/relay_pingpong_test.go | 15 ++-- tests/integration/relay_test.go | 95 +++++++++++----------- 11 files changed, 236 insertions(+), 148 deletions(-) diff --git a/tests/e2e/gov_test.go b/tests/e2e/gov_test.go index ac57b5fbdf..79972796e4 100644 --- a/tests/e2e/gov_test.go +++ b/tests/e2e/gov_test.go @@ -15,9 +15,9 @@ import ( distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - "github.com/CosmWasm/wasmd/app" "github.com/CosmWasm/wasmd/tests/e2e" - "github.com/CosmWasm/wasmd/tests/ibctesting" + wasmibctesting "github.com/CosmWasm/wasmd/tests/ibctesting" + ibctesting "github.com/cosmos/ibc-go/v9/testing" ) func TestGovVoteByContract(t *testing.T) { @@ -26,8 +26,8 @@ func TestGovVoteByContract(t *testing.T) { // When the contract sends a vote for the proposal // Then the vote is taken into account - coord := ibctesting.NewCoordinator(t, 1) - chain := coord.GetChain(ibctesting.GetChainID(1)) + coord := wasmibctesting.NewCoordinator2(t, 1) + chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1))) contractAddr := e2e.InstantiateReflectContract(t, chain) chain.Fund(contractAddr, sdkmath.NewIntFromUint64(1_000_000_000)) // a contract with a high delegation amount @@ -45,7 +45,7 @@ func TestGovVoteByContract(t *testing.T) { e2e.MustExecViaReflectContract(t, chain, contractAddr, delegateMsg) signer := chain.SenderAccount.GetAddress().String() - app := chain.App.(*app.WasmApp) + app := chain.GetWasmApp() govKeeper, accountKeeper := app.GovKeeper, app.AccountKeeper communityPoolBalance := chain.Balance(accountKeeper.GetModuleAccount(chain.GetContext(), distributiontypes.ModuleName).GetAddress(), sdk.DefaultBondDenom) require.False(t, communityPoolBalance.IsZero()) @@ -128,7 +128,7 @@ func TestGovVoteByContract(t *testing.T) { proposal, err := govKeeper.Proposals.Get(chain.GetContext(), propID) require.NoError(t, err) coord.IncrementTimeBy(proposal.VotingEndTime.Sub(chain.GetContext().BlockTime()) + time.Minute) - coord.CommitBlock(chain) + coord.CommitBlock(chain.TestChain) // and recipient balance updated recipientBalance := chain.Balance(recipientAddr, sdk.DefaultBondDenom) diff --git a/tests/e2e/grants_test.go b/tests/e2e/grants_test.go index 12b7e9e165..385bceac26 100644 --- a/tests/e2e/grants_test.go +++ b/tests/e2e/grants_test.go @@ -20,8 +20,9 @@ import ( "github.com/cosmos/cosmos-sdk/x/authz" "github.com/CosmWasm/wasmd/tests/e2e" - "github.com/CosmWasm/wasmd/tests/ibctesting" + wasmibctesting "github.com/CosmWasm/wasmd/tests/ibctesting" "github.com/CosmWasm/wasmd/x/wasm/types" + ibctesting "github.com/cosmos/ibc-go/v9/testing" ) func TestGrants(t *testing.T) { @@ -33,8 +34,8 @@ func TestGrants(t *testing.T) { // - balance A reduced (on success) // - balance B not touched - coord := ibctesting.NewCoordinator(t, 1) - chain := coord.GetChain(ibctesting.GetChainID(1)) + coord := wasmibctesting.NewCoordinator2(t, 1) + chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1))) contractAddr := e2e.InstantiateReflectContract(t, chain) require.NotEmpty(t, contractAddr) @@ -130,8 +131,8 @@ func TestStoreCodeGrant(t *testing.T) { reflectCodeChecksum, err := wasmvm.CreateChecksum(reflectWasmCode) require.NoError(t, err) - coord := ibctesting.NewCoordinator(t, 1) - chain := coord.GetChain(ibctesting.GetChainID(1)) + coord := wasmibctesting.NewCoordinator2(t, 1) + chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1))) granterAddr := chain.SenderAccount.GetAddress() granteePrivKey := secp256k1.GenPrivKey() @@ -218,8 +219,8 @@ func TestGzipStoreCodeGrant(t *testing.T) { hackatomCodeChecksum, err := wasmvm.CreateChecksum(hackatomWasmCode) require.NoError(t, err) - coord := ibctesting.NewCoordinator(t, 1) - chain := coord.GetChain(ibctesting.GetChainID(1)) + coord := wasmibctesting.NewCoordinator2(t, 1) + chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1))) granterAddr := chain.SenderAccount.GetAddress() granteePrivKey := secp256k1.GenPrivKey() @@ -300,8 +301,8 @@ func TestBrokenGzipStoreCodeGrant(t *testing.T) { brokenGzipWasmCode, err := os.ReadFile("../../x/wasm/keeper/testdata/broken_crc.gzip") require.NoError(t, err) - coord := ibctesting.NewCoordinator(t, 1) - chain := coord.GetChain(ibctesting.GetChainID(1)) + coord := wasmibctesting.NewCoordinator2(t, 1) + chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1))) granterAddr := chain.SenderAccount.GetAddress() granteePrivKey := secp256k1.GenPrivKey() diff --git a/tests/e2e/group_test.go b/tests/e2e/group_test.go index 288a296be2..098d632409 100644 --- a/tests/e2e/group_test.go +++ b/tests/e2e/group_test.go @@ -16,8 +16,9 @@ import ( "github.com/cosmos/cosmos-sdk/x/group" "github.com/CosmWasm/wasmd/tests/e2e" - "github.com/CosmWasm/wasmd/tests/ibctesting" + wasmibctesting "github.com/CosmWasm/wasmd/tests/ibctesting" "github.com/CosmWasm/wasmd/x/wasm/types" + ibctesting "github.com/cosmos/ibc-go/v9/testing" ) func TestGroupWithContract(t *testing.T) { @@ -25,8 +26,8 @@ func TestGroupWithContract(t *testing.T) { // When contract submits a proposal with try_execute // Then the payload msg is executed - coord := ibctesting.NewCoordinator(t, 1) - chain := coord.GetChain(ibctesting.GetChainID(1)) + coord := wasmibctesting.NewCoordinator2(t, 1) + chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1))) contractAddr := e2e.InstantiateStargateReflectContract(t, chain) chain.Fund(contractAddr, sdkmath.NewIntFromUint64(1_000_000_000)) @@ -80,8 +81,8 @@ func TestGroupWithNewReflectContract(t *testing.T) { // When contract submits a proposal with try_execute // Then the payload msg is executed - coord := ibctesting.NewCoordinator(t, 1) - chain := coord.GetChain(ibctesting.GetChainID(1)) + coord := wasmibctesting.NewCoordinator2(t, 1) + chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1))) contractAddr := e2e.InstantiateReflectContract(t, chain) chain.Fund(contractAddr, sdkmath.NewIntFromUint64(1_000_000_000)) diff --git a/tests/e2e/ibc_callbacks_test.go b/tests/e2e/ibc_callbacks_test.go index bd85f6d3bc..32cb6a8787 100644 --- a/tests/e2e/ibc_callbacks_test.go +++ b/tests/e2e/ibc_callbacks_test.go @@ -33,14 +33,14 @@ func TestIBCCallbacks(t *testing.T) { // then the contract on B should receive a destination chain callback // and the contract on A should receive a source chain callback with the result (ack or timeout) marshaler := app.MakeEncodingConfig(t).Codec - coord := wasmibctesting.NewCoordinator(t, 2) - chainA := coord.GetChain(wasmibctesting.GetChainID(1)) - chainB := coord.GetChain(wasmibctesting.GetChainID(2)) + coord := wasmibctesting.NewCoordinator2(t, 2) + chainA := wasmibctesting.NewWasmTestChain(coord.GetChain(wasmibctesting.GetChainID(1))) + chainB := wasmibctesting.NewWasmTestChain(coord.GetChain(wasmibctesting.GetChainID(2))) actorChainA := sdk.AccAddress(chainA.SenderPrivKey.PubKey().Address()) oneToken := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(1))) - path := wasmibctesting.NewPath(chainA, chainB) + path := ibctesting.NewPath(chainA.TestChain, chainB.TestChain) path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{ PortID: ibctransfertypes.PortID, Version: string(marshaler.MustMarshalJSON(&ibcfee.Metadata{FeeVersion: ibcfee.Version, AppVersion: ibctransfertypes.V2})), @@ -123,12 +123,12 @@ func TestIBCCallbacks(t *testing.T) { Msg: contractMsgBz, Funds: oneToken, } - _, err = chainA.SendMsgs(&execMsg) + result, err := chainA.SendMsgs(&execMsg) require.NoError(t, err) if spec.expAck { // and the packet is relayed - require.NoError(t, coord.RelayAndAckPendingPackets(path)) + wasmibctesting.RelayAndAckPacket(t, path, result) // then the contract on chain B should receive a receive callback var response QueryResp @@ -150,7 +150,7 @@ func TestIBCCallbacks(t *testing.T) { assert.Equal(t, []byte(`{"result":"AQ=="}`), response.IBCAckCallbacks[0].Acknowledgement.Data) } else { // and the packet times out - require.NoError(t, coord.TimeoutPendingPackets(path)) + require.NoError(t, wasmibctesting.TimeoutPendingPackets(coord, path, result)) // then the contract on chain B should not receive anything var response QueryResp @@ -178,13 +178,13 @@ func TestIBCCallbacksWithoutEntrypoints(t *testing.T) { // then the VM should try to call the callback on B and fail gracefully // and should try to call the callback on A and fail gracefully marshaler := app.MakeEncodingConfig(t).Codec - coord := wasmibctesting.NewCoordinator(t, 2) - chainA := coord.GetChain(wasmibctesting.GetChainID(1)) - chainB := coord.GetChain(wasmibctesting.GetChainID(2)) + coord := wasmibctesting.NewCoordinator2(t, 2) + chainA := wasmibctesting.NewWasmTestChain(coord.GetChain(wasmibctesting.GetChainID(1))) + chainB := wasmibctesting.NewWasmTestChain(coord.GetChain(wasmibctesting.GetChainID(2))) oneToken := sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(1)) - path := wasmibctesting.NewPath(chainA, chainB) + path := ibctesting.NewPath(chainA.TestChain, chainB.TestChain) path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{ PortID: ibctransfertypes.PortID, Version: string(marshaler.MustMarshalJSON(&ibcfee.Metadata{FeeVersion: ibcfee.Version, AppVersion: ibctransfertypes.V2})), @@ -205,14 +205,14 @@ func TestIBCCallbacksWithoutEntrypoints(t *testing.T) { // when the contract on A sends an IBCMsg::Transfer to the contract on B memo := fmt.Sprintf(`{"src_callback":{"address":"%v"},"dest_callback":{"address":"%v"}}`, contractAddrA.String(), contractAddrB.String()) - e2e.MustExecViaReflectContract(t, chainA, contractAddrA, wasmvmtypes.CosmosMsg{ + result := e2e.MustExecViaReflectContract(t, chainA, contractAddrA, wasmvmtypes.CosmosMsg{ IBC: &wasmvmtypes.IBCMsg{ Transfer: &wasmvmtypes.TransferMsg{ ToAddress: contractAddrB.String(), ChannelID: path.EndpointA.ChannelID, Amount: wasmvmtypes.NewCoin(oneToken.Amount.Uint64(), oneToken.Denom), Timeout: wasmvmtypes.IBCTimeout{ - Timestamp: uint64(chainA.LastHeader.GetTime().Add(time.Second * 100).UnixNano()), + Timestamp: uint64(chainA.ProposedHeader.GetTime().Add(time.Second * 100).UnixNano()), }, Memo: memo, }, @@ -220,6 +220,5 @@ func TestIBCCallbacksWithoutEntrypoints(t *testing.T) { }) // and the packet is relayed without problems - require.NoError(t, coord.RelayAndAckPendingPackets(path)) - assert.Empty(t, chainA.PendingSendPackets) + wasmibctesting.RelayAndAckPacket(t, path, result) } diff --git a/tests/e2e/ibc_fees_test.go b/tests/e2e/ibc_fees_test.go index 51384de372..80c35361fe 100644 --- a/tests/e2e/ibc_fees_test.go +++ b/tests/e2e/ibc_fees_test.go @@ -247,9 +247,9 @@ func TestIBCFeesReflect(t *testing.T) { // then the relayer's payee is receiving the fee(s) on success marshaler := app.MakeEncodingConfig(t).Codec - coord := wasmibctesting.NewCoordinator(t, 2) - chainA := coord.GetChain(wasmibctesting.GetChainID(1)) - chainB := coord.GetChain(ibctesting.GetChainID(2)) + coord := wasmibctesting.NewCoordinator2(t, 2) + chainA := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1))) + chainB := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(2))) actorChainA := sdk.AccAddress(chainA.SenderPrivKey.PubKey().Address()) actorChainB := sdk.AccAddress(chainB.SenderPrivKey.PubKey().Address()) @@ -262,7 +262,7 @@ func TestIBCFeesReflect(t *testing.T) { payee := sdk.AccAddress(bytes.Repeat([]byte{2}, address.Len)) oneToken := []wasmvmtypes.Coin{wasmvmtypes.NewCoin(1, sdk.DefaultBondDenom)} - path := wasmibctesting.NewPath(chainA, chainB) + path := ibctesting.NewPath(chainA.TestChain, chainB.TestChain) path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{ PortID: ibctransfertypes.PortID, Version: string(marshaler.MustMarshalJSON(&ibcfee.Metadata{FeeVersion: ibcfee.Version, AppVersion: ibctransfertypes.V2})), @@ -275,8 +275,8 @@ func TestIBCFeesReflect(t *testing.T) { } // with an ics-29 fee enabled channel setup between both chains coord.Setup(path) - appA := chainA.App.(*app.WasmApp) - appB := chainB.App.(*app.WasmApp) + appA := chainA.GetWasmApp() + appB := chainB.GetWasmApp() require.True(t, appA.IBCFeeKeeper.IsFeeEnabled(chainA.GetContext(), ibctransfertypes.PortID, path.EndpointA.ChannelID)) require.True(t, appB.IBCFeeKeeper.IsFeeEnabled(chainB.GetContext(), ibctransfertypes.PortID, path.EndpointB.ChannelID)) // and with a payee registered for A -> B @@ -286,7 +286,7 @@ func TestIBCFeesReflect(t *testing.T) { require.NoError(t, err) // when reflect contract on A sends a PayPacketFee msg, followed by a transfer - _, err = ExecViaReflectContract(t, chainA, reflectContractAddr, []wasmvmtypes.CosmosMsg{ + result, err := ExecViaReflectContract(t, chainA, reflectContractAddr, []wasmvmtypes.CosmosMsg{ { IBC: &wasmvmtypes.IBCMsg{ PayPacketFee: &wasmvmtypes.PayPacketFeeMsg{ @@ -340,7 +340,7 @@ func TestIBCFeesReflect(t *testing.T) { require.NoError(t, err) // and packages relayed - require.NoError(t, coord.RelayAndAckPendingPackets(path)) + wasmibctesting.RelayAndAckPacket(t, path, result) // then // on chain A diff --git a/tests/e2e/ica_test.go b/tests/e2e/ica_test.go index f7ab56324f..c6c9c1ed7a 100644 --- a/tests/e2e/ica_test.go +++ b/tests/e2e/ica_test.go @@ -22,7 +22,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/address" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/CosmWasm/wasmd/app" wasmibctesting "github.com/CosmWasm/wasmd/tests/ibctesting" ) @@ -33,15 +32,15 @@ func TestICA(t *testing.T) { // and the channel is established to the host chain // then the ICA owner can submit a message via IBC // to control their account on the host chain - coord := wasmibctesting.NewCoordinator(t, 2) - hostChain := coord.GetChain(ibctesting.GetChainID(1)) + coord := wasmibctesting.NewCoordinator2(t, 2) + hostChain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1))) hostParams := hosttypes.NewParams(true, []string{sdk.MsgTypeURL(&banktypes.MsgSend{})}) - hostApp := hostChain.App.(*app.WasmApp) + hostApp := hostChain.GetWasmApp() hostApp.ICAHostKeeper.SetParams(hostChain.GetContext(), hostParams) - controllerChain := coord.GetChain(ibctesting.GetChainID(2)) + controllerChain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(2))) - path := wasmibctesting.NewPath(controllerChain, hostChain) + path := ibctesting.NewPath(controllerChain.TestChain, hostChain.TestChain) coord.SetupConnections(path) specs := map[string]struct { @@ -90,7 +89,7 @@ func TestICA(t *testing.T) { coord.CreateChannels(path) // assert ICA exists on controller - contApp := controllerChain.App.(*app.WasmApp) + contApp := controllerChain.GetWasmApp() icaRsp, err := contApp.ICAControllerKeeper.InterchainAccount(controllerChain.GetContext(), &icacontrollertypes.QueryInterchainAccountRequest{ Owner: icaControllerAddr.String(), ConnectionId: path.EndpointA.ConnectionID, @@ -112,11 +111,10 @@ func TestICA(t *testing.T) { } relativeTimeout := uint64(time.Minute.Nanoseconds()) // note this is in nanoseconds msgSendTx := icacontrollertypes.NewMsgSendTx(icaControllerAddr.String(), path.EndpointA.ConnectionID, relativeTimeout, payloadPacket) - _, err = controllerChain.SendNonDefaultSenderMsgs(icaControllerKey, msgSendTx) + result, err := controllerChain.SendNonDefaultSenderMsgs(icaControllerKey, msgSendTx) require.NoError(t, err) - assert.Equal(t, 1, len(controllerChain.PendingSendPackets)) - require.NoError(t, coord.RelayAndAckPendingPackets(path)) + wasmibctesting.RelayAndAckPacket(t, path, result) gotBalance := hostChain.Balance(targetAddr, sdk.DefaultBondDenom) assert.Equal(t, sendCoin.String(), gotBalance.String()) diff --git a/tests/e2e/reflect_helper.go b/tests/e2e/reflect_helper.go index 08a8fe2c06..eec95a9d62 100644 --- a/tests/e2e/reflect_helper.go +++ b/tests/e2e/reflect_helper.go @@ -13,14 +13,14 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/CosmWasm/wasmd/tests/ibctesting" + wasmibctesting "github.com/CosmWasm/wasmd/tests/ibctesting" "github.com/CosmWasm/wasmd/x/wasm/keeper/testdata" "github.com/CosmWasm/wasmd/x/wasm/types" ) // InstantiateStargateReflectContract stores and instantiates the reflect contract shipped with CosmWasm 1.5.3. // This instance still expects the old CosmosMsg.Stargate variant instead of the new CosmosMsg.Any. -func InstantiateStargateReflectContract(t *testing.T, chain *ibctesting.TestChain) sdk.AccAddress { +func InstantiateStargateReflectContract(t *testing.T, chain wasmibctesting.WasmTestChain) sdk.AccAddress { codeID := chain.StoreCodeFile("../../x/wasm/keeper/testdata/reflect_1_5.wasm").CodeID contractAddr := chain.InstantiateContract(codeID, []byte(`{}`)) require.NotEmpty(t, contractAddr) @@ -28,7 +28,7 @@ func InstantiateStargateReflectContract(t *testing.T, chain *ibctesting.TestChai } // InstantiateReflectContract stores and instantiates a 2.0 reflect contract instance. -func InstantiateReflectContract(t *testing.T, chain *ibctesting.TestChain) sdk.AccAddress { +func InstantiateReflectContract(t *testing.T, chain wasmibctesting.WasmTestChain) sdk.AccAddress { codeID := chain.StoreCodeFile("../../x/wasm/keeper/testdata/reflect_2_0.wasm").CodeID contractAddr := chain.InstantiateContract(codeID, []byte(`{}`)) require.NotEmpty(t, contractAddr) @@ -36,7 +36,7 @@ func InstantiateReflectContract(t *testing.T, chain *ibctesting.TestChain) sdk.A } // MustExecViaReflectContract submit execute message to send payload to reflect contract -func MustExecViaReflectContract(t *testing.T, chain *ibctesting.TestChain, contractAddr sdk.AccAddress, msgs ...wasmvmtypes.CosmosMsg) *abci.ExecTxResult { +func MustExecViaReflectContract(t *testing.T, chain wasmibctesting.WasmTestChain, contractAddr sdk.AccAddress, msgs ...wasmvmtypes.CosmosMsg) *abci.ExecTxResult { rsp, err := ExecViaReflectContract(t, chain, contractAddr, msgs) require.NoError(t, err) return rsp @@ -47,7 +47,7 @@ type sdkMessageType interface { sdk.Msg } -func MustExecViaStargateReflectContract[T sdkMessageType](t *testing.T, chain *ibctesting.TestChain, contractAddr sdk.AccAddress, msgs ...T) *abci.ExecTxResult { +func MustExecViaStargateReflectContract[T sdkMessageType](t *testing.T, chain wasmibctesting.WasmTestChain, contractAddr sdk.AccAddress, msgs ...T) *abci.ExecTxResult { require.NotEmpty(t, msgs) // convert messages to stargate variant vmMsgs := make([]string, len(msgs)) @@ -70,7 +70,7 @@ func MustExecViaStargateReflectContract[T sdkMessageType](t *testing.T, chain *i return rsp } -func MustExecViaAnyReflectContract[T sdkMessageType](t *testing.T, chain *ibctesting.TestChain, contractAddr sdk.AccAddress, msgs ...T) *abci.ExecTxResult { +func MustExecViaAnyReflectContract[T sdkMessageType](t *testing.T, chain wasmibctesting.WasmTestChain, contractAddr sdk.AccAddress, msgs ...T) *abci.ExecTxResult { vmMsgs := make([]wasmvmtypes.CosmosMsg, len(msgs)) for i, m := range msgs { bz, err := chain.Codec.Marshal(m) @@ -88,7 +88,7 @@ func MustExecViaAnyReflectContract[T sdkMessageType](t *testing.T, chain *ibctes } // ExecViaReflectContract submit execute message to send payload to reflect contract -func ExecViaReflectContract(t *testing.T, chain *ibctesting.TestChain, contractAddr sdk.AccAddress, msgs []wasmvmtypes.CosmosMsg) (*abci.ExecTxResult, error) { +func ExecViaReflectContract(t *testing.T, chain wasmibctesting.WasmTestChain, contractAddr sdk.AccAddress, msgs []wasmvmtypes.CosmosMsg) (*abci.ExecTxResult, error) { require.NotEmpty(t, msgs) reflectSend := testdata.ReflectHandleMsg{ Reflect: &testdata.ReflectPayload{Msgs: msgs}, diff --git a/tests/ibctesting/chain2.go b/tests/ibctesting/chain2.go index 31cae3a043..4d9c5887a6 100644 --- a/tests/ibctesting/chain2.go +++ b/tests/ibctesting/chain2.go @@ -3,6 +3,9 @@ package ibctesting import ( "bytes" "compress/gzip" + "context" + "encoding/json" + "fmt" "os" "strings" "testing" @@ -14,6 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -24,6 +28,8 @@ import ( "github.com/CosmWasm/wasmd/x/wasm/types" abci "github.com/cometbft/cometbft/abci/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ibctesting "github.com/cosmos/ibc-go/v9/testing" ibctestingtypes "github.com/cosmos/ibc-go/v9/testing/types" ) @@ -142,6 +148,64 @@ func (chain WasmTestChain) AllBalances(acc sdk.AccAddress) sdk.Coins { return chain.App.(WasmTestApp).GetBankKeeper().GetAllBalances(chain.GetContext(), acc) } +// SendNonDefaultSenderMsgs is the same as SendMsgs but with a custom signer/account +func (chain *WasmTestChain) SendNonDefaultSenderMsgs(senderPrivKey cryptotypes.PrivKey, msgs ...sdk.Msg) (*abci.ExecTxResult, error) { + require.NotEqual(chain.TB, chain.SenderPrivKey, senderPrivKey, "use SendMsgs method") + + addr := sdk.AccAddress(senderPrivKey.PubKey().Address().Bytes()) + account := chain.GetWasmApp().GetAccountKeeper().GetAccount(chain.GetContext(), addr) + prevAccount := chain.SenderAccount + prevSenderPrivKey := chain.SenderPrivKey + chain.SenderAccount = account + chain.SenderPrivKey = senderPrivKey + + require.NotNil(chain.TB, account) + result, err := chain.SendMsgs(msgs...) + + chain.SenderAccount = prevAccount + chain.SenderPrivKey = prevSenderPrivKey + + return result, err +} + +// SmartQuery This will serialize the query message and submit it to the contract. +// The response is parsed into the provided interface. +// Usage: SmartQuery(addr, QueryMsg{Foo: 1}, &response) +func (chain *WasmTestChain) SmartQuery(contractAddr string, queryMsg, response interface{}) error { + msg, err := json.Marshal(queryMsg) + if err != nil { + return err + } + + req := types.QuerySmartContractStateRequest{ + Address: contractAddr, + QueryData: msg, + } + reqBin, err := proto.Marshal(&req) + if err != nil { + return err + } + + res, err := chain.App.Query(context.TODO(), &abci.RequestQuery{ + Path: "/cosmwasm.wasm.v1.Query/SmartContractState", + Data: reqBin, + }) + require.NoError(chain.TB, err) + + if res.Code != 0 { + return fmt.Errorf("smart query failed: (%d) %s", res.Code, res.Log) + } + + // unpack protobuf + var resp types.QuerySmartContractStateResponse + err = proto.Unmarshal(res.Value, &resp) + if err != nil { + return err + } + // unpack json content + return json.Unmarshal(resp.Data, response) +} + func RelayAndAckPacket(t *testing.T, path *ibctesting.Path, result *abci.ExecTxResult) { packet, err := ibctesting.ParsePacketFromEvents(result.Events) require.NoError(t, err) @@ -149,6 +213,30 @@ func RelayAndAckPacket(t *testing.T, path *ibctesting.Path, result *abci.ExecTxR require.NoError(t, err) } +// TimeoutPendingPackets returns the package to source chain to let the IBC app revert any operation. +// from A to B +func TimeoutPendingPackets(coord *ibctesting.Coordinator, path *ibctesting.Path, result *abci.ExecTxResult) error { + src := path.EndpointA + dest := path.EndpointB + + packet, err := ibctesting.ParsePacketFromEvents(result.Events) + require.NoError(coord, err) + require.NoError(coord, src.UpdateClient()) + + // Increment time and commit block so that 5 second delay period passes between send and receive + coord.IncrementTime() + coord.CommitBlock(src.Chain, dest.Chain) + // get proof of packet unreceived on dest + packetKey := host.PacketReceiptKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) + proofUnreceived, proofHeight := dest.QueryProof(packetKey) + timeoutMsg := channeltypes.NewMsgTimeout(packet, packet.Sequence, proofUnreceived, proofHeight, src.Chain.SenderAccount.GetAddress().String()) + _, err = src.Chain.SendMsgs(timeoutMsg) + if err != nil { + return err + } + return nil +} + // ChainAppFactory abstract factory method that usually implemented by app.SetupWithGenesisValSet type ChainAppFactory2 func(t *testing.T, valSet *cmttypes.ValidatorSet, genAccs []authtypes.GenesisAccount, chainID string, opts []wasmkeeper.Option, balances ...banktypes.Balance) WasmTestApp @@ -267,7 +355,7 @@ func NewTestChainWithValSet2(t *testing.T, coord *ibctesting.Coordinator, appFac } // NewCoordinator initializes Coordinator with N TestChain's -func NewCoordinator2(t *testing.T, n int) *ibctesting.Coordinator { +func NewCoordinator2(t *testing.T, n int, opts ...[]wasmkeeper.Option) *ibctesting.Coordinator { t.Helper() chains := make(map[string]*ibctesting.TestChain) coord := &ibctesting.Coordinator{ @@ -277,7 +365,11 @@ func NewCoordinator2(t *testing.T, n int) *ibctesting.Coordinator { for i := 1; i <= n; i++ { chainID := ibctesting.GetChainID(i) - chains[chainID] = NewDefaultTestChain2(t, coord, chainID) + var x []wasmkeeper.Option + if len(opts) > (i - 1) { + x = opts[i-1] + } + chains[chainID] = NewDefaultTestChain2(t, coord, chainID, x...) } coord.Chains = chains diff --git a/tests/integration/ibc_integration_test.go b/tests/integration/ibc_integration_test.go index 944618922c..0b2b6745eb 100644 --- a/tests/integration/ibc_integration_test.go +++ b/tests/integration/ibc_integration_test.go @@ -16,7 +16,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/CosmWasm/wasmd/app" wasmibctesting "github.com/CosmWasm/wasmd/tests/ibctesting" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" @@ -32,11 +31,11 @@ func TestIBCReflectContract(t *testing.T) { // "ibc_reflect" sends a submessage to "reflect" which is returned as submessage. var ( - coordinator = wasmibctesting.NewCoordinator(t, 2) - chainA = coordinator.GetChain(wasmibctesting.GetChainID(1)) - chainB = coordinator.GetChain(wasmibctesting.GetChainID(2)) + coordinator = wasmibctesting.NewCoordinator2(t, 2) + chainA = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(1))) + chainB = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(2))) ) - coordinator.CommitBlock(chainA, chainB) + coordinator.CommitBlock(chainA.TestChain, chainB.TestChain) initMsg := []byte(`{}`) codeID := chainA.StoreCodeFile("./testdata/ibc_reflect_send.wasm").CodeID @@ -53,11 +52,11 @@ func TestIBCReflectContract(t *testing.T) { sourcePortID = chainA.ContractInfo(sendContractAddr).IBCPortID counterpartPortID = chainB.ContractInfo(reflectContractAddr).IBCPortID ) - coordinator.CommitBlock(chainA, chainB) + coordinator.CommitBlock(chainA.TestChain, chainB.TestChain) coordinator.UpdateTime() - require.Equal(t, chainA.CurrentHeader.Time, chainB.CurrentHeader.Time) - path := wasmibctesting.NewPath(chainA, chainB) + require.Equal(t, chainA.ProposedHeader.Time, chainB.ProposedHeader.Time) + path := ibctesting.NewPath(chainA.TestChain, chainB.TestChain) path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{ PortID: sourcePortID, Version: "ibc-reflect-v1", @@ -173,14 +172,14 @@ func TestOnChanOpenInitVersion(t *testing.T) { wasmkeeper.WithWasmEngine( wasmtesting.NewIBCContractMockWasmEngine(myContract)), } - coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts) - chainA = coordinator.GetChain(wasmibctesting.GetChainID(1)) - chainB = coordinator.GetChain(wasmibctesting.GetChainID(2)) + coordinator = wasmibctesting.NewCoordinator2(t, 2, chainAOpts) + chainA = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(1))) + chainB = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(2))) myContractAddr = chainA.SeedNewContractInstance() - appA = chainA.App.(*app.WasmApp) + appA = chainA.GetWasmApp() contractInfo = appA.WasmKeeper.GetContractInfo(chainA.GetContext(), myContractAddr) ) - path := wasmibctesting.NewPath(chainA, chainB) + path := ibctesting.NewPath(chainA.TestChain, chainB.TestChain) coordinator.SetupClients(path) coordinator.CreateConnections(path) path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{ @@ -233,14 +232,14 @@ func TestOnChanOpenTryVersion(t *testing.T) { wasmkeeper.WithWasmEngine( wasmtesting.NewIBCContractMockWasmEngine(myContract)), } - coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts) - chainA = coordinator.GetChain(wasmibctesting.GetChainID(1)) - chainB = coordinator.GetChain(wasmibctesting.GetChainID(2)) + coordinator = wasmibctesting.NewCoordinator2(t, 2, chainAOpts) + chainA = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(1))) + chainB = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(2))) myContractAddr = chainA.SeedNewContractInstance() contractInfo = chainA.ContractInfo(myContractAddr) ) - path := wasmibctesting.NewPath(chainA, chainB) + path := ibctesting.NewPath(chainA.TestChain, chainB.TestChain) coordinator.SetupConnections(path) path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{ @@ -300,9 +299,9 @@ func TestOnIBCPacketReceive(t *testing.T) { wasmkeeper.WithWasmEngine(mockContractEngine), } var ( - coord = wasmibctesting.NewCoordinator(t, 2, chainAOpts) - chainA = coord.GetChain(wasmibctesting.GetChainID(1)) - chainB = coord.GetChain(wasmibctesting.GetChainID(2)) + coord = wasmibctesting.NewCoordinator2(t, 2, chainAOpts) + chainA = wasmibctesting.NewWasmTestChain(coord.GetChain(wasmibctesting.GetChainID(1))) + chainB = wasmibctesting.NewWasmTestChain(coord.GetChain(wasmibctesting.GetChainID(2))) ) // setup chain A contract metadata for mock myMockContractAddr := chainA.SeedNewContractInstance() // setups env but uses mock contract @@ -318,7 +317,7 @@ func TestOnIBCPacketReceive(t *testing.T) { var ( sourcePortID = chainA.ContractInfo(myMockContractAddr).IBCPortID counterpartPortID = chainB.ContractInfo(ibcReflectContractAddr).IBCPortID - path = wasmibctesting.NewPath(chainA, chainB) + path = ibctesting.NewPath(chainA.TestChain, chainB.TestChain) ) path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{ PortID: sourcePortID, Version: "ibc-reflect-v1", Order: channeltypes.ORDERED, @@ -329,13 +328,13 @@ func TestOnIBCPacketReceive(t *testing.T) { coord.SetupConnections(path) coord.CreateChannels(path) - coord.CommitBlock(chainA, chainB) + coord.CommitBlock(chainA.TestChain, chainB.TestChain) require.Equal(t, 0, len(chainA.PendingSendPackets)) require.Equal(t, 0, len(chainB.PendingSendPackets)) // when an ibc packet is sent from chain A to chain B capturedAck := mockContractEngine.SubmitIBCPacket(t, path, chainA, myMockContractAddr, spec.packetData) - coord.CommitBlock(chainA, chainB) + coord.CommitBlock(chainA.TestChain, chainB.TestChain) require.Equal(t, 1, len(chainA.PendingSendPackets)) require.Equal(t, 0, len(chainB.PendingSendPackets)) @@ -375,9 +374,9 @@ func TestIBCAsyncAck(t *testing.T) { wasmkeeper.WithWasmEngine(mockContractEngine), } var ( - coord = wasmibctesting.NewCoordinator(t, 2, chainAOpts) - chainA = coord.GetChain(wasmibctesting.GetChainID(1)) - chainB = coord.GetChain(wasmibctesting.GetChainID(2)) + coord = wasmibctesting.NewCoordinator2(t, 2, chainAOpts) + chainA = wasmibctesting.NewWasmTestChain(coord.GetChain(wasmibctesting.GetChainID(1))) + chainB = wasmibctesting.NewWasmTestChain(coord.GetChain(wasmibctesting.GetChainID(2))) ) // setup chain A contract metadata for mock myMockContractAddr := chainA.SeedNewContractInstance() // setups env but uses mock contract @@ -393,7 +392,7 @@ func TestIBCAsyncAck(t *testing.T) { var ( sourcePortID = chainA.ContractInfo(myMockContractAddr).IBCPortID counterpartPortID = chainB.ContractInfo(ibcReflectContractAddr).IBCPortID - path = wasmibctesting.NewPath(chainA, chainB) + path = ibctesting.NewPath(chainA.TestChain, chainB.TestChain) ) path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{ PortID: sourcePortID, Version: "ibc-reflect-v1", Order: channeltypes.UNORDERED, @@ -404,13 +403,13 @@ func TestIBCAsyncAck(t *testing.T) { coord.SetupConnections(path) coord.CreateChannels(path) - coord.CommitBlock(chainA, chainB) + coord.CommitBlock(chainA.TestChain, chainB.TestChain) require.Equal(t, 0, len(chainA.PendingSendPackets)) require.Equal(t, 0, len(chainB.PendingSendPackets)) // when the "no_ack" ibc packet is sent from chain A to chain B capturedAck := mockContractEngine.SubmitIBCPacket(t, path, chainA, myMockContractAddr, []byte(`{"no_ack":{}}`)) - coord.CommitBlock(chainA, chainB) + coord.CommitBlock(chainA.TestChain, chainB.TestChain) require.Equal(t, 1, len(chainA.PendingSendPackets)) require.Equal(t, 0, len(chainB.PendingSendPackets)) @@ -466,7 +465,7 @@ func NewCaptureAckTestContractEngine() *captureAckTestContractEngine { } // SubmitIBCPacket starts an IBC packet transfer on given chain and captures the ack returned -func (x *captureAckTestContractEngine) SubmitIBCPacket(t *testing.T, path *wasmibctesting.Path, chainA *wasmibctesting.TestChain, senderContractAddr sdk.AccAddress, packetData []byte) *[]byte { +func (x *captureAckTestContractEngine) SubmitIBCPacket(t *testing.T, path *ibctesting.Path, chainA wasmibctesting.WasmTestChain, senderContractAddr sdk.AccAddress, packetData []byte) *[]byte { t.Helper() // prepare a bridge to send an ibc packet by an ordinary wasm execute message x.MockWasmEngine.ExecuteFn = func(codeID wasmvm.Checksum, env wasmvmtypes.Env, info wasmvmtypes.MessageInfo, executeMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.ContractResult, uint64, error) { diff --git a/tests/integration/relay_pingpong_test.go b/tests/integration/relay_pingpong_test.go index fdff6c31aa..a10c85305b 100644 --- a/tests/integration/relay_pingpong_test.go +++ b/tests/integration/relay_pingpong_test.go @@ -16,7 +16,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - app2 "github.com/CosmWasm/wasmd/app" wasmibctesting "github.com/CosmWasm/wasmd/tests/ibctesting" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" @@ -48,9 +47,9 @@ func TestPinPong(t *testing.T) { chainBOpts = []wasmkeeper.Option{wasmkeeper.WithWasmEngine( wasmtesting.NewIBCContractMockWasmEngine(pongContract), )} - coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts, chainBOpts) - chainA = coordinator.GetChain(wasmibctesting.GetChainID(1)) - chainB = coordinator.GetChain(wasmibctesting.GetChainID(2)) + coordinator = wasmibctesting.NewCoordinator2(t, 2, chainAOpts, chainBOpts) + chainA = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(1))) + chainB = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(2))) ) _ = chainB.SeedNewContractInstance() // skip 1 instance so that addresses are not the same var ( @@ -58,7 +57,7 @@ func TestPinPong(t *testing.T) { pongContractAddr = chainB.SeedNewContractInstance() ) require.NotEqual(t, pingContractAddr, pongContractAddr) - coordinator.CommitBlock(chainA, chainB) + coordinator.CommitBlock(chainA.TestChain, chainB.TestChain) pingContract.chain = chainA pingContract.contractAddr = pingContractAddr @@ -71,7 +70,7 @@ func TestPinPong(t *testing.T) { counterpartyPortID = wasmkeeper.PortIDForContract(pongContractAddr) ) - path := wasmibctesting.NewPath(chainA, chainB) + path := ibctesting.NewPath(chainA.TestChain, chainB.TestChain) path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{ PortID: sourcePortID, Version: ibctransfertypes.V2, @@ -129,7 +128,7 @@ var _ wasmtesting.IBCContractCallbacks = &player{} // player is a (mock) contract that sends and receives ibc packages type player struct { t *testing.T - chain *wasmibctesting.TestChain + chain wasmibctesting.WasmTestChain contractAddr sdk.AccAddress actor string // either ping or pong execCalls int // number of calls to Execute method (checkTx + deliverTx) @@ -312,7 +311,7 @@ func (p player) incrementCounter(key []byte, store wasmvm.KVStore) uint64 { } func (p player) QueryState(key []byte) uint64 { - app := p.chain.App.(*app2.WasmApp) + app := p.chain.GetWasmApp() raw := app.WasmKeeper.QueryRaw(p.chain.GetContext(), p.contractAddr, key) return sdk.BigEndianToUint64(raw) } diff --git a/tests/integration/relay_test.go b/tests/integration/relay_test.go index 0150be3818..a969ea2924 100644 --- a/tests/integration/relay_test.go +++ b/tests/integration/relay_test.go @@ -24,7 +24,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/CosmWasm/wasmd/app" wasmibctesting "github.com/CosmWasm/wasmd/tests/ibctesting" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" @@ -53,7 +52,7 @@ func TestFromIBCTransferToContract(t *testing.T) { transferAmount := sdkmath.NewInt(1) specs := map[string]struct { contract wasmtesting.IBCContractCallbacks - setupContract func(t *testing.T, contract wasmtesting.IBCContractCallbacks, chain *wasmibctesting.TestChain) + setupContract func(t *testing.T, contract wasmtesting.IBCContractCallbacks, chain wasmibctesting.WasmTestChain) expChainAPendingSendPackets int expChainBPendingSendPackets int expChainABalanceDiff sdkmath.Int @@ -62,7 +61,7 @@ func TestFromIBCTransferToContract(t *testing.T) { }{ "ack": { contract: &ackReceiverContract{}, - setupContract: func(t *testing.T, contract wasmtesting.IBCContractCallbacks, chain *wasmibctesting.TestChain) { + setupContract: func(t *testing.T, contract wasmtesting.IBCContractCallbacks, chain wasmibctesting.WasmTestChain) { c := contract.(*ackReceiverContract) c.t = t c.chain = chain @@ -74,7 +73,7 @@ func TestFromIBCTransferToContract(t *testing.T) { }, "nack": { contract: &nackReceiverContract{}, - setupContract: func(t *testing.T, contract wasmtesting.IBCContractCallbacks, chain *wasmibctesting.TestChain) { + setupContract: func(t *testing.T, contract wasmtesting.IBCContractCallbacks, chain wasmibctesting.WasmTestChain) { c := contract.(*nackReceiverContract) c.t = t }, @@ -85,7 +84,7 @@ func TestFromIBCTransferToContract(t *testing.T) { }, "error": { contract: &errorReceiverContract{}, - setupContract: func(t *testing.T, contract wasmtesting.IBCContractCallbacks, chain *wasmibctesting.TestChain) { + setupContract: func(t *testing.T, contract wasmtesting.IBCContractCallbacks, chain wasmibctesting.WasmTestChain) { c := contract.(*errorReceiverContract) c.t = t }, @@ -102,17 +101,17 @@ func TestFromIBCTransferToContract(t *testing.T) { chainAOpts = []wasmkeeper.Option{wasmkeeper.WithWasmEngine( wasmtesting.NewIBCContractMockWasmEngine(spec.contract), )} - coordinator = wasmibctesting.NewCoordinator(t, 2, []wasmkeeper.Option{}, chainAOpts) - chainA = coordinator.GetChain(wasmibctesting.GetChainID(1)) - chainB = coordinator.GetChain(wasmibctesting.GetChainID(2)) + coordinator = wasmibctesting.NewCoordinator2(t, 2, []wasmkeeper.Option{}, chainAOpts) + chainA = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(1))) + chainB = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(2))) ) - coordinator.CommitBlock(chainA, chainB) + coordinator.CommitBlock(chainA.TestChain, chainB.TestChain) myContractAddr := chainB.SeedNewContractInstance() contractBPortID := chainB.ContractInfo(myContractAddr).IBCPortID spec.setupContract(t, spec.contract, chainB) - path := wasmibctesting.NewPath(chainA, chainB) + path := ibctesting.NewPath(chainA.TestChain, chainB.TestChain) path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{ PortID: "transfer", Version: ibctransfertypes.V1, @@ -178,14 +177,14 @@ func TestContractCanInitiateIBCTransferMsg(t *testing.T) { wasmkeeper.WithWasmEngine( wasmtesting.NewIBCContractMockWasmEngine(myContract)), } - coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts) - chainA = coordinator.GetChain(wasmibctesting.GetChainID(1)) - chainB = coordinator.GetChain(wasmibctesting.GetChainID(2)) + coordinator = wasmibctesting.NewCoordinator2(t, 2, chainAOpts) + chainA = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(1))) + chainB = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(2))) ) myContractAddr := chainA.SeedNewContractInstance() - coordinator.CommitBlock(chainA, chainB) + coordinator.CommitBlock(chainA.TestChain, chainB.TestChain) - path := wasmibctesting.NewPath(chainA, chainB) + path := ibctesting.NewPath(chainA.TestChain, chainB.TestChain) path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{ PortID: ibctransfertypes.PortID, Version: ibctransfertypes.V1, @@ -230,7 +229,7 @@ func TestContractCanInitiateIBCTransferMsg(t *testing.T) { require.Equal(t, 0, len(chainB.PendingSendPackets)) // and dest chain balance contains voucher - bankKeeperB := chainB.App.(*app.WasmApp).BankKeeper + bankKeeperB := chainB.GetWasmApp().BankKeeper expBalance := GetTransferCoin(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, coinToSendToB.Denom, coinToSendToB.Amount) gotBalance := chainB.Balance(chainB.SenderAccount.GetAddress(), expBalance.Denom) assert.Equal(t, expBalance, gotBalance, "got total balance: %s", bankKeeperB.GetAllBalances(chainB.GetContext(), chainB.SenderAccount.GetAddress())) @@ -249,15 +248,15 @@ func TestContractCanEmulateIBCTransferMessage(t *testing.T) { wasmkeeper.WithWasmEngine( wasmtesting.NewIBCContractMockWasmEngine(myContract)), } - coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts) + coordinator = wasmibctesting.NewCoordinator2(t, 2, chainAOpts) - chainA = coordinator.GetChain(wasmibctesting.GetChainID(1)) - chainB = coordinator.GetChain(wasmibctesting.GetChainID(2)) + chainA = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(1))) + chainB = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(2))) ) myContractAddr := chainA.SeedNewContractInstance() myContract.contractAddr = myContractAddr.String() - path := wasmibctesting.NewPath(chainA, chainB) + path := ibctesting.NewPath(chainA.TestChain, chainB.TestChain) path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{ PortID: chainA.ContractInfo(myContractAddr).IBCPortID, Version: ibctransfertypes.V1, @@ -272,7 +271,7 @@ func TestContractCanEmulateIBCTransferMessage(t *testing.T) { coordinator.CreateChannels(path) // when contract is triggered to send the ibc package to chain B - timeout := uint64(chainB.LastHeader.Header.Time.Add(time.Hour).UnixNano()) // enough time to not timeout + timeout := uint64(chainB.ProposedHeader.Time.Add(time.Hour).UnixNano()) // enough time to not timeout receiverAddress := chainB.SenderAccount.GetAddress() coinToSendToB := sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100)) @@ -323,16 +322,16 @@ func TestContractCanEmulateIBCTransferMessageWithTimeout(t *testing.T) { wasmkeeper.WithWasmEngine( wasmtesting.NewIBCContractMockWasmEngine(myContract)), } - coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts) + coordinator = wasmibctesting.NewCoordinator2(t, 2, chainAOpts) - chainA = coordinator.GetChain(wasmibctesting.GetChainID(1)) - chainB = coordinator.GetChain(wasmibctesting.GetChainID(2)) + chainA = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(1))) + chainB = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(2))) ) - coordinator.CommitBlock(chainA, chainB) + coordinator.CommitBlock(chainA.TestChain, chainB.TestChain) myContractAddr := chainA.SeedNewContractInstance() myContract.contractAddr = myContractAddr.String() - path := wasmibctesting.NewPath(chainA, chainB) + path := ibctesting.NewPath(chainA.TestChain, chainB.TestChain) path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{ PortID: chainA.ContractInfo(myContractAddr).IBCPortID, Version: ibctransfertypes.V2, @@ -348,7 +347,7 @@ func TestContractCanEmulateIBCTransferMessageWithTimeout(t *testing.T) { coordinator.UpdateTime() // when contract is triggered to send the ibc package to chain B - timeout := uint64(chainB.LastHeader.Header.Time.Add(time.Nanosecond).UnixNano()) // will timeout + timeout := uint64(chainB.ProposedHeader.Time.Add(time.Nanosecond).UnixNano()) // will timeout receiverAddress := chainB.SenderAccount.GetAddress() coinToSendToB := sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100)) initialContractBalance := chainA.Balance(myContractAddr, sdk.DefaultBondDenom) @@ -369,7 +368,7 @@ func TestContractCanEmulateIBCTransferMessageWithTimeout(t *testing.T) { } _, err := chainA.SendMsgs(startMsg) require.NoError(t, err) - coordinator.CommitBlock(chainA, chainB) + coordinator.CommitBlock(chainA.TestChain, chainB.TestChain) // then require.Equal(t, 1, len(chainA.PendingSendPackets)) require.Equal(t, 0, len(chainB.PendingSendPackets)) @@ -379,7 +378,7 @@ func TestContractCanEmulateIBCTransferMessageWithTimeout(t *testing.T) { // when timeout packet send (by the relayer) err = coordinator.TimeoutPendingPackets(path) require.NoError(t, err) - coordinator.CommitBlock(chainA) + coordinator.CommitBlock(chainA.TestChain) // then require.Equal(t, 0, len(chainA.PendingSendPackets)) @@ -409,19 +408,19 @@ func TestContractEmulateIBCTransferMessageOnDiffContractIBCChannel(t *testing.T) ), } - coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts) + coordinator = wasmibctesting.NewCoordinator2(t, 2, chainAOpts) - chainA = coordinator.GetChain(wasmibctesting.GetChainID(1)) - chainB = coordinator.GetChain(wasmibctesting.GetChainID(2)) + chainA = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(1))) + chainB = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(2))) ) - coordinator.CommitBlock(chainA, chainB) + coordinator.CommitBlock(chainA.TestChain, chainB.TestChain) myContractAddr1 := chainA.SeedNewContractInstance() myContractA1.contractAddr = myContractAddr1.String() myContractAddr2 := chainA.SeedNewContractInstance() myContractA2.contractAddr = myContractAddr2.String() - path := wasmibctesting.NewPath(chainA, chainB) + path := ibctesting.NewPath(chainA.TestChain, chainB.TestChain) path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{ PortID: chainA.ContractInfo(myContractAddr1).IBCPortID, Version: ibctransfertypes.V2, @@ -436,7 +435,7 @@ func TestContractEmulateIBCTransferMessageOnDiffContractIBCChannel(t *testing.T) coordinator.CreateChannels(path) // when contract is triggered to send the ibc package to chain B - timeout := uint64(chainB.LastHeader.Header.Time.Add(time.Hour).UnixNano()) // enough time to not timeout + timeout := uint64(chainB.ProposedHeader.Time.Add(time.Hour).UnixNano()) // enough time to not timeout receiverAddress := chainB.SenderAccount.GetAddress() coinToSendToB := sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100)) @@ -471,18 +470,18 @@ func TestContractHandlesChannelClose(t *testing.T) { wasmkeeper.WithWasmEngine( wasmtesting.NewIBCContractMockWasmEngine(myContractB)), } - coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts, chainBOpts) + coordinator = wasmibctesting.NewCoordinator2(t, 2, chainAOpts, chainBOpts) - chainA = coordinator.GetChain(wasmibctesting.GetChainID(1)) - chainB = coordinator.GetChain(wasmibctesting.GetChainID(2)) + chainA = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(1))) + chainB = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(2))) ) - coordinator.CommitBlock(chainA, chainB) + coordinator.CommitBlock(chainA.TestChain, chainB.TestChain) myContractAddrA := chainA.SeedNewContractInstance() _ = chainB.SeedNewContractInstance() // skip one instance myContractAddrB := chainB.SeedNewContractInstance() - path := wasmibctesting.NewPath(chainA, chainB) + path := ibctesting.NewPath(chainA.TestChain, chainB.TestChain) path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{ PortID: chainA.ContractInfo(myContractAddrA).IBCPortID, Version: ibctransfertypes.V2, @@ -519,20 +518,20 @@ func TestContractHandlesChannelCloseNotOwned(t *testing.T) { wasmkeeper.WithWasmEngine( wasmtesting.NewIBCContractMockWasmEngine(myContractB)), } - coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts, chainBOpts) + coordinator = wasmibctesting.NewCoordinator2(t, 2, chainAOpts, chainBOpts) - chainA = coordinator.GetChain(wasmibctesting.GetChainID(1)) - chainB = coordinator.GetChain(wasmibctesting.GetChainID(2)) + chainA = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(1))) + chainB = wasmibctesting.NewWasmTestChain(coordinator.GetChain(wasmibctesting.GetChainID(2))) ) - coordinator.CommitBlock(chainA, chainB) + coordinator.CommitBlock(chainA.TestChain, chainB.TestChain) myContractAddrA1 := chainA.SeedNewContractInstance() myContractAddrA2 := chainA.SeedNewContractInstance() _ = chainB.SeedNewContractInstance() // skip one instance _ = chainB.SeedNewContractInstance() // skip one instance myContractAddrB := chainB.SeedNewContractInstance() - path := wasmibctesting.NewPath(chainA, chainB) + path := ibctesting.NewPath(chainA.TestChain, chainB.TestChain) path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{ PortID: chainA.ContractInfo(myContractAddrA1).IBCPortID, Version: ibctransfertypes.V2, @@ -716,7 +715,7 @@ var _ wasmtesting.IBCContractCallbacks = &ackReceiverContract{} type ackReceiverContract struct { contractStub t *testing.T - chain *wasmibctesting.TestChain + chain wasmibctesting.WasmTestChain } func (c *ackReceiverContract) IBCPacketReceive(_ wasmvm.Checksum, _ wasmvmtypes.Env, msg wasmvmtypes.IBCPacketReceiveMsg, _ wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.IBCReceiveResult, uint64, error) { @@ -733,7 +732,7 @@ func (c *ackReceiverContract) IBCPacketReceive(_ wasmvm.Checksum, _ wasmvmtypes. // call original ibctransfer keeper to not copy all code into this ibcPacket := toIBCPacket(packet) ctx := c.chain.GetContext() // HACK: please note that this is not reverted after checkTX - err := c.chain.App.(*app.WasmApp).TransferKeeper.OnRecvPacket(ctx, ibcPacket, srcV2) + err := c.chain.GetWasmApp().TransferKeeper.OnRecvPacket(ctx, ibcPacket, srcV2) if err != nil { return nil, 0, errorsmod.Wrap(err, "within our smart contract") } @@ -759,7 +758,7 @@ func (c *ackReceiverContract) IBCPacketAck(_ wasmvm.Checksum, _ wasmvmtypes.Env, // call original ibctransfer keeper to not copy all code into this ctx := c.chain.GetContext() // HACK: please note that this is not reverted after checkTX ibcPacket := toIBCPacket(msg.OriginalPacket) - err := c.chain.App.(*app.WasmApp).TransferKeeper.OnAcknowledgementPacket(ctx, ibcPacket, dataV2, ack) + err := c.chain.GetWasmApp().TransferKeeper.OnAcknowledgementPacket(ctx, ibcPacket, dataV2, ack) if err != nil { return nil, 0, errorsmod.Wrap(err, "within our smart contract") }