From aa2bea0bd1193be9257343b216471fddde0edd08 Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Sat, 22 Aug 2020 14:57:09 +0200 Subject: [PATCH] Add ping pong ibc example --- x/wasm/ibc_testing/chain.go | 17 +- x/wasm/ibc_testing/types.go | 3 + x/wasm/internal/keeper/cosmwasm/msg.go | 131 +++---------- x/wasm/internal/keeper/ibc.go | 2 + x/wasm/internal/keeper/keeper.go | 22 +++ x/wasm/relay_pingpong_test.go | 262 +++++++++++++++++++++++++ x/wasm/relay_test.go | 16 +- 7 files changed, 332 insertions(+), 121 deletions(-) create mode 100644 x/wasm/relay_pingpong_test.go diff --git a/x/wasm/ibc_testing/chain.go b/x/wasm/ibc_testing/chain.go index f29d635763..d466b315ea 100644 --- a/x/wasm/ibc_testing/chain.go +++ b/x/wasm/ibc_testing/chain.go @@ -44,13 +44,13 @@ const ( TrustingPeriod time.Duration = time.Hour * 24 * 7 * 2 UnbondingPeriod time.Duration = time.Hour * 24 * 7 * 3 MaxClockDrift time.Duration = time.Second * 10 - - ChannelVersion = ibctransfertypes.Version - InvalidID = "IDisInvalid" + InvalidID = "IDisInvalid" ConnectionIDPrefix = "connectionid" ) +//var ChannelVersion = ibctransfertypes.Version + // Default params variables used to create a TM client var ( DefaultTrustLevel ibctmtypes.Fraction = ibctmtypes.DefaultTrustLevel @@ -334,10 +334,11 @@ func (chain *TestChain) AddTestConnection(clientID, counterpartyClientID string) // format: // connectionid func (chain *TestChain) ConstructNextTestConnection(clientID, counterpartyClientID string) *TestConnection { - connectionID := ConnectionIDPrefix + strconv.Itoa(len(chain.Connections)) + connectionID := chain.ChainID + ConnectionIDPrefix + strconv.Itoa(len(chain.Connections)) return &TestConnection{ ID: connectionID, ClientID: clientID, + NextChannelVersion: ibctransfertypes.Version, CounterpartyClientID: counterpartyClientID, } } @@ -590,7 +591,7 @@ func (chain *TestChain) ChanOpenInit( ) error { msg := channeltypes.NewMsgChannelOpenInit( ch.PortID, ch.ID, - ChannelVersion, order, []string{connectionID}, + ch.Version, order, []string{connectionID}, counterparty.PortID, counterparty.ID, chain.SenderAccount.GetAddress(), ) @@ -608,9 +609,9 @@ func (chain *TestChain) ChanOpenTry( msg := channeltypes.NewMsgChannelOpenTry( ch.PortID, ch.ID, - ChannelVersion, order, []string{connectionID}, + ch.Version, order, []string{connectionID}, counterpartyCh.PortID, counterpartyCh.ID, - ChannelVersion, + counterpartyCh.Version, proof, height, chain.SenderAccount.GetAddress(), ) @@ -626,7 +627,7 @@ func (chain *TestChain) ChanOpenAck( msg := channeltypes.NewMsgChannelOpenAck( ch.PortID, ch.ID, - ChannelVersion, + counterpartyCh.Version, proof, height, chain.SenderAccount.GetAddress(), ) diff --git a/x/wasm/ibc_testing/types.go b/x/wasm/ibc_testing/types.go index 71898e01e2..d0c3e61780 100644 --- a/x/wasm/ibc_testing/types.go +++ b/x/wasm/ibc_testing/types.go @@ -10,6 +10,7 @@ type TestConnection struct { ID string ClientID string CounterpartyClientID string + NextChannelVersion string Channels []TestChannel } @@ -32,6 +33,7 @@ func (conn *TestConnection) AddTestChannel(portID string) TestChannel { func (conn *TestConnection) NextTestChannel(portID string) TestChannel { channelID := fmt.Sprintf("%s%d", conn.ID, len(conn.Channels)) return TestChannel{ + Version: conn.NextChannelVersion, PortID: portID, ID: channelID, ClientID: conn.ClientID, @@ -58,4 +60,5 @@ type TestChannel struct { ID string ClientID string CounterpartyClientID string + Version string } diff --git a/x/wasm/internal/keeper/cosmwasm/msg.go b/x/wasm/internal/keeper/cosmwasm/msg.go index 0c81e22109..ef806e2ab3 100644 --- a/x/wasm/internal/keeper/cosmwasm/msg.go +++ b/x/wasm/internal/keeper/cosmwasm/msg.go @@ -52,115 +52,28 @@ type HandleResponse struct { // base64-encoded bytes to return as ABCI.Data field Data []byte `json:"data"` // log message to return over abci interface - Log []LogAttribute `json:"log"` + Log []cosmwasmv1.LogAttribute `json:"log"` } -// InitResult is the raw response from the handle call -type InitResult struct { - Ok *InitResponse `json:"Ok,omitempty"` - Err *cosmwasmv1.StdError `json:"Err,omitempty"` -} - -// InitResponse defines the return value on a successful handle -type InitResponse struct { - // Messages comes directly from the contract and is it's request for action - Messages []CosmosMsg `json:"messages"` - // log message to return over abci interface - Log []LogAttribute `json:"log"` -} - -// MigrateResult is the raw response from the handle call -type MigrateResult struct { - Ok *MigrateResponse `json:"Ok,omitempty"` - Err *cosmwasmv1.StdError `json:"Err,omitempty"` -} - -// MigrateResponse defines the return value on a successful handle -type MigrateResponse struct { - // Messages comes directly from the contract and is it's request for action - Messages []CosmosMsg `json:"messages"` - // base64-encoded bytes to return as ABCI.Data field - Data []byte `json:"data"` - // log message to return over abci interface - Log []LogAttribute `json:"log"` -} - -// LogAttribute -type LogAttribute struct { - Key string `json:"key"` - Value string `json:"value"` -} - -type BankMsg struct { - Send *SendMsg `json:"send,omitempty"` -} - -// SendMsg contains instructions for a Cosmos-SDK/SendMsg -// It has a fixed interface here and should be converted into the proper SDK format before dispatching -type SendMsg struct { - FromAddress string `json:"from_address"` - ToAddress string `json:"to_address"` - Amount cosmwasmv1.Coins `json:"amount"` -} - -type StakingMsg struct { - Delegate *DelegateMsg `json:"delegate,omitempty"` - Undelegate *UndelegateMsg `json:"undelegate,omitempty"` - Redelegate *RedelegateMsg `json:"redelegate,omitempty"` - Withdraw *WithdrawMsg `json:"withdraw,omitempty"` -} - -type DelegateMsg struct { - Validator string `json:"validator"` - Amount cosmwasmv1.Coins `json:"amount"` -} - -type UndelegateMsg struct { - Validator string `json:"validator"` - Amount cosmwasmv1.Coins `json:"amount"` -} - -type RedelegateMsg struct { - SrcValidator string `json:"src_validator"` - DstValidator string `json:"dst_validator"` - Amount cosmwasmv1.Coins `json:"amount"` -} - -type WithdrawMsg struct { - Validator string `json:"validator"` - // this is optional - Recipient string `json:"recipient,omitempty"` -} - -type WasmMsg struct { - Execute *ExecuteMsg `json:"execute,omitempty"` - Instantiate *InstantiateMsg `json:"instantiate,omitempty"` -} - -// ExecuteMsg is used to call another defined contract on this chain. -// The calling contract requires the callee to be defined beforehand, -// and the address should have been defined in initialization. -// And we assume the developer tested the ABIs and coded them together. +//type WasmMsg struct { +// Execute *cosmwasmv1.ExecuteMsg `json:"execute,omitempty"` +// Instantiate *cosmwasmv1.InstantiateMsg `json:"instantiate,omitempty"` +//} // -// Since a contract is immutable once it is deployed, we don't need to transform this. -// If it was properly coded and worked once, it will continue to work throughout upgrades. -type ExecuteMsg struct { - // ContractAddr is the sdk.AccAddress of the contract, which uniquely defines - // the contract ID and instance ID. The sdk module should maintain a reverse lookup table. - ContractAddr string `json:"contract_addr"` - // Msg is assumed to be a json-encoded message, which will be passed directly - // as `userMsg` when calling `Handle` on the above-defined contract - Msg []byte `json:"msg"` - // Send is an optional amount of coins this contract sends to the called contract - Send cosmwasmv1.Coins `json:"send"` -} - -type InstantiateMsg struct { - // CodeID is the reference to the wasm byte code as used by the Cosmos-SDK - CodeID uint64 `json:"code_id"` - // Msg is assumed to be a json-encoded message, which will be passed directly - // as `userMsg` when calling `Handle` on the above-defined contract - Msg []byte `json:"msg"` - // Send is an optional amount of coins this contract sends to the called contract - Send cosmwasmv1.Coins `json:"send"` -} +//// ExecuteMsg is used to call another defined contract on this chain. +//// The calling contract requires the callee to be defined beforehand, +//// and the address should have been defined in initialization. +//// And we assume the developer tested the ABIs and coded them together. +//// +//// Since a contract is immutable once it is deployed, we don't need to transform this. +//// If it was properly coded and worked once, it will continue to work throughout upgrades. +//type ExecuteMsg struct { +// // ContractAddr is the sdk.AccAddress of the contract, which uniquely defines +// // the contract ID and instance ID. The sdk module should maintain a reverse lookup table. +// ContractAddr string `json:"contract_addr"` +// // Msg is assumed to be a json-encoded message, which will be passed directly +// // as `userMsg` when calling `Handle` on the above-defined contract +// Msg []byte `json:"msg"` +// // Send is an optional amount of coins this contract sends to the called contract +// Send cosmwasmv1.Coins `json:"send"` +//} diff --git a/x/wasm/internal/keeper/ibc.go b/x/wasm/internal/keeper/ibc.go index ea43f44167..5bc3cb4eb5 100644 --- a/x/wasm/internal/keeper/ibc.go +++ b/x/wasm/internal/keeper/ibc.go @@ -4,6 +4,7 @@ import ( "strings" wasm "github.com/CosmWasm/go-cosmwasm" + wasmTypes "github.com/CosmWasm/go-cosmwasm/types" "github.com/CosmWasm/wasmd/x/wasm/internal/keeper/cosmwasm" "github.com/CosmWasm/wasmd/x/wasm/internal/types" "github.com/cosmos/cosmos-sdk/store/prefix" @@ -81,6 +82,7 @@ type IBCContractCallbacks interface { OnIBCChannelConnect(hash []byte, params cosmwasm.Env, channel cosmwasm.IBCChannel, store prefix.Store, api wasm.GoAPI, querier QueryHandler, meter sdk.GasMeter, gas uint64) (*cosmwasm.IBCChannelConnectResponse, uint64, error) // OnIBCChannelConnect callback when a IBC channel is closed OnIBCChannelClose(ctx sdk.Context, hash []byte, params cosmwasm.Env, channel cosmwasm.IBCChannel, meter sdk.GasMeter, gas uint64) (*cosmwasm.IBCChannelCloseResponse, uint64, error) + Execute(hash []byte, params wasmTypes.Env, msg []byte, store prefix.Store, api wasm.GoAPI, querier QueryHandler, meter sdk.GasMeter, gas uint64) (*cosmwasm.HandleResponse, uint64, error) } var MockContracts = make(map[string]IBCContractCallbacks, 0) diff --git a/x/wasm/internal/keeper/keeper.go b/x/wasm/internal/keeper/keeper.go index 2f139d4a23..70045b4ef6 100644 --- a/x/wasm/internal/keeper/keeper.go +++ b/x/wasm/internal/keeper/keeper.go @@ -7,6 +7,7 @@ import ( wasm "github.com/CosmWasm/go-cosmwasm" wasmTypes "github.com/CosmWasm/go-cosmwasm/types" + cosmwasmv2 "github.com/CosmWasm/wasmd/x/wasm/internal/keeper/cosmwasm" "github.com/CosmWasm/wasmd/x/wasm/internal/types" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" @@ -309,6 +310,27 @@ func (k Keeper) Execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller } gas := gasForContract(ctx) + + mock, ok := MockContracts[contractAddress.String()] + if ok { + res, gasUsed, execErr := mock.Execute(codeInfo.CodeHash, params, msg, prefixStore, cosmwasmAPI, querier, ctx.GasMeter(), gas) + consumeGas(ctx, gasUsed) + if execErr != nil { + return nil, sdkerrors.Wrap(types.ErrExecuteFailed, execErr.Error()) + } + + // emit all events from this contract itself + events := types.ParseEvents(res.Log, contractAddress) + ctx.EventManager().EmitEvents(events) + + if err := k.messenger.DispatchV2(ctx, contractAddress, cosmwasmv2.IBCEndpoint{}, res.Messages...); err != nil { + return nil, err + } + return &sdk.Result{ + Data: res.Data, + }, nil + } + res, gasUsed, execErr := k.wasmer.Execute(codeInfo.CodeHash, params, msg, prefixStore, cosmwasmAPI, querier, gasMeter(ctx), gas) consumeGas(ctx, gasUsed) if execErr != nil { diff --git a/x/wasm/relay_pingpong_test.go b/x/wasm/relay_pingpong_test.go new file mode 100644 index 0000000000..af5f7370db --- /dev/null +++ b/x/wasm/relay_pingpong_test.go @@ -0,0 +1,262 @@ +package wasm_test + +import ( + "encoding/json" + "fmt" + "testing" + + "github.com/CosmWasm/go-cosmwasm" + wasmTypes "github.com/CosmWasm/go-cosmwasm/types" + "github.com/CosmWasm/wasmd/x/wasm" + "github.com/CosmWasm/wasmd/x/wasm/ibc_testing" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/internal/keeper" + cosmwasmv2 "github.com/CosmWasm/wasmd/x/wasm/internal/keeper/cosmwasm" + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" + channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" + "github.com/stretchr/testify/require" +) + +const ( + ping = "ping" + pong = "pong" +) +const doNotTimeout uint64 = 110000 + +func TestPinPong(t *testing.T) { + var ( + coordinator = ibc_testing.NewCoordinator(t, 2) + chainA = coordinator.GetChain(ibc_testing.GetChainID(0)) + chainB = coordinator.GetChain(ibc_testing.GetChainID(1)) + ) + _ = chainB.NewRandomContractInstance() // skip 1 id + var ( + pingContractAddr = chainA.NewRandomContractInstance() + pongContractAddr = chainB.NewRandomContractInstance() + ) + require.NotEqual(t, pingContractAddr, pongContractAddr) + + pingContract := &player{t: t, actor: ping, chain: chainA} + pongContract := &player{t: t, actor: pong, chain: chainB} + + wasmkeeper.MockContracts[pingContractAddr.String()] = pingContract + wasmkeeper.MockContracts[pongContractAddr.String()] = pongContract + + var ( + sourcePortID = wasmkeeper.PortIDForContract(pingContractAddr) + counterpartyPortID = wasmkeeper.PortIDForContract(pongContractAddr) + ) + clientA, clientB, connA, connB := coordinator.SetupClientConnections(chainA, chainB, clientexported.Tendermint) + connA.NextChannelVersion = ping + connB.NextChannelVersion = pong + + channelA, channelB := coordinator.CreateChannel(chainA, chainB, connA, connB, sourcePortID, counterpartyPortID, channeltypes.UNORDERED) + var err error + + //err = coordinator.UpdateClient(chainA, chainB, clientA, clientexported.Tendermint) + //require.NoError(t, err) + //err := coordinator.UpdateClient(chainB, chainA, clientB, clientexported.Tendermint) + //require.NoError(t, err) + s := startGame{ + Source: cosmwasmv2.IBCEndpoint{channelA.ID, channelA.PortID}, + CounterParty: cosmwasmv2.IBCEndpoint{channelB.ID, channelB.PortID}, + } + bz, err := json.Marshal(&s) + require.NoError(t, err) + startMsg := &wasm.MsgExecuteContract{ + Sender: chainA.SenderAccount.GetAddress(), + Contract: pingContractAddr, + Msg: bz, + } + // send from chainA to chainB + err = coordinator.SendMsgs(chainA, chainB, clientB, startMsg) + require.NoError(t, err) + + activePlayer := ping + // relay send + const rounds = 20 + for i := 1; i <= rounds; i++ { + t.Logf("++ round: %d\n", i) + + ball := hit{activePlayer: uint64(i)} + + seq := uint64(i) + pkg := channeltypes.NewPacket(ball.GetBytes(), seq, channelA.PortID, channelA.ID, channelB.PortID, channelB.ID, doNotTimeout, 0) + ack := ball.Ack() + + err = coordinator.RelayPacket(chainA, chainB, clientA, clientB, pkg, ack.GetBytes()) + require.NoError(t, err) + //coordinator.CommitBlock(chainA, chainB) + err = coordinator.UpdateClient(chainA, chainB, clientA, clientexported.Tendermint) + require.NoError(t, err) + + // switch side + activePlayer = counterParty(activePlayer) + ball = hit{activePlayer: uint64(i)} + pkg = channeltypes.NewPacket(ball.GetBytes(), seq, channelB.PortID, channelB.ID, channelA.PortID, channelA.ID, doNotTimeout, 0) + ack = ball.Ack() + + err = coordinator.RelayPacket(chainB, chainA, clientB, clientA, pkg, ack.GetBytes()) + require.NoError(t, err) + err = coordinator.UpdateClient(chainB, chainA, clientB, clientexported.Tendermint) + require.NoError(t, err) + + // switch side for next round + activePlayer = counterParty(activePlayer) + + } +} + +// hit is ibc packet payload +type hit map[string]uint64 + +func NewHit(player string, count uint64) hit { + return map[string]uint64{ + player: count, + } +} +func (h hit) GetBytes() []byte { + b, err := json.Marshal(h) + if err != nil { + panic(err) + } + return b +} + +func (h hit) Ack() hitAcknowledgement { + return hitAcknowledgement{Success: h} +} + +type hitAcknowledgement struct { + Error string `json:"error,omitempty"` + Success hit `json:"success,omitempty"` +} + +func (a hitAcknowledgement) GetBytes() []byte { + b, err := json.Marshal(a) + if err != nil { + panic(err) + } + return b +} + +type player struct { + chain *ibc_testing.TestChain + t *testing.T + actor string + execCalls int +} + +// startGame is an execute message payload +type startGame struct { + Source, CounterParty cosmwasmv2.IBCEndpoint +} + +func (p *player) Execute(hash []byte, params wasmTypes.Env, data []byte, store prefix.Store, api cosmwasm.GoAPI, querier wasmkeeper.QueryHandler, meter sdk.GasMeter, gas uint64) (*cosmwasmv2.HandleResponse, uint64, error) { + p.execCalls++ + if p.execCalls%2 == 1 { // skip checkTx step because of no rollback with `chain.GetContext()` + return &cosmwasmv2.HandleResponse{}, 0, nil + } + // start game + var start startGame + if err := json.Unmarshal(data, &start); err != nil { + return nil, 0, err + } + + ctx := p.chain.GetContext() + channelCap, ok := p.chain.App.WasmKeeper.ScopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(start.Source.Port, start.Source.Channel)) + if !ok { + return nil, 0, sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") + } + + count := p.IncrementCounter(sentBallsKey, store) + service := NewHit(p.actor, count) + var seq uint64 = 1 + packet := channeltypes.NewPacket(service.GetBytes(), seq, start.Source.Port, start.Source.Channel, start.CounterParty.Port, start.CounterParty.Channel, doNotTimeout, 0) + err := p.chain.App.WasmKeeper.ChannelKeeper.SendPacket(ctx, channelCap, packet) + if err != nil { + return nil, 0, err + } + return &cosmwasmv2.HandleResponse{}, 0, nil +} + +func (p player) OnIBCChannelOpen(hash []byte, params cosmwasmv2.Env, channel cosmwasmv2.IBCChannel, store prefix.Store, api cosmwasm.GoAPI, querier wasmkeeper.QueryHandler, meter sdk.GasMeter, gas uint64) (*cosmwasmv2.IBCChannelOpenResponse, uint64, error) { + if channel.Version != p.actor { + return &cosmwasmv2.IBCChannelOpenResponse{Success: false, Reason: fmt.Sprintf("expected %q but got %q", p.actor, channel.Version)}, 0, nil + } + return &cosmwasmv2.IBCChannelOpenResponse{Success: true}, 0, nil +} + +func (p player) OnIBCChannelConnect(hash []byte, params cosmwasmv2.Env, channel cosmwasmv2.IBCChannel, store prefix.Store, api cosmwasm.GoAPI, querier wasmkeeper.QueryHandler, meter sdk.GasMeter, gas uint64) (*cosmwasmv2.IBCChannelConnectResponse, uint64, error) { + return &cosmwasmv2.IBCChannelConnectResponse{}, 0, nil +} + +func (p player) OnIBCChannelClose(ctx sdk.Context, hash []byte, params cosmwasmv2.Env, channel cosmwasmv2.IBCChannel, meter sdk.GasMeter, gas uint64) (*cosmwasmv2.IBCChannelCloseResponse, uint64, error) { + panic("implement me") +} + +var ( + sentBallsKey = []byte("sentBalls") + receivedBallsKey = []byte("recvBalls") + lastBallReceivedKey = []byte("lastBallReceived") + confirmedBallsKey = []byte("confBalls") +) + +func (p player) IncrementCounter(key []byte, store prefix.Store) uint64 { + var count uint64 + bz := store.Get(key) + if bz != nil { + count = sdk.BigEndianToUint64(bz) + } + count++ + store.Set(key, sdk.Uint64ToBigEndian(count)) + return count +} + +func (p player) OnIBCPacketReceive(hash []byte, params cosmwasmv2.Env, packet cosmwasmv2.IBCPacket, store prefix.Store, api cosmwasm.GoAPI, querier wasmkeeper.QueryHandler, meter sdk.GasMeter, gas uint64) (*cosmwasmv2.IBCPacketReceiveResponse, uint64, error) { + // parse received data and store + var receivedBall hit + if err := json.Unmarshal(packet.Data, &receivedBall); err != nil { + return nil, 0, err // todo: can also be a app level error message: // r {"error": "message here"} or {"success": {"pong": 14}} + } + + otherCount := receivedBall[counterParty(p.actor)] + store.Set(lastBallReceivedKey, sdk.Uint64ToBigEndian(otherCount)) + + p.IncrementCounter(receivedBallsKey, store) + count := p.IncrementCounter(sentBallsKey, store) + newHit := hit{p.actor: count} + respHit := &cosmwasmv2.IBCMsg{SendPacket: &cosmwasmv2.IBCSendMsg{ + ChannelID: packet.Source.Channel, + Data: newHit.GetBytes(), + TimeoutHeight: doNotTimeout, + }} + ack := receivedBall.Ack() + return &cosmwasmv2.IBCPacketReceiveResponse{ + Acknowledgement: ack.GetBytes(), + Messages: []cosmwasmv2.CosmosMsg{{IBC: respHit}}, + }, 0, nil +} + +func (p player) OnIBCPacketAcknowledgement(hash []byte, params cosmwasmv2.Env, packetAck cosmwasmv2.IBCAcknowledgement, store prefix.Store, api cosmwasm.GoAPI, querier wasmkeeper.QueryHandler, meter sdk.GasMeter, gas uint64) (*cosmwasmv2.IBCPacketAcknowledgementResponse, uint64, error) { + p.IncrementCounter(confirmedBallsKey, store) + return &cosmwasmv2.IBCPacketAcknowledgementResponse{}, 0, nil +} + +func (p player) OnIBCPacketTimeout(hash []byte, params cosmwasmv2.Env, packet cosmwasmv2.IBCPacket, store prefix.Store, api cosmwasm.GoAPI, querier wasmkeeper.QueryHandler, meter sdk.GasMeter, gas uint64) (*cosmwasmv2.IBCPacketTimeoutResponse, uint64, error) { + panic("implement me") +} + +func counterParty(s string) string { + switch s { + case ping: + return pong + case pong: + return ping + default: + panic(fmt.Sprintf("unsupported: %q", s)) + } +} diff --git a/x/wasm/relay_test.go b/x/wasm/relay_test.go index 98dcfba352..0e2f07f2e9 100644 --- a/x/wasm/relay_test.go +++ b/x/wasm/relay_test.go @@ -3,7 +3,7 @@ package wasm_test import ( "testing" - cosmwasm "github.com/CosmWasm/go-cosmwasm" + "github.com/CosmWasm/go-cosmwasm" cosmwasmv1 "github.com/CosmWasm/go-cosmwasm/types" "github.com/CosmWasm/wasmd/x/wasm/ibc_testing" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/internal/keeper" @@ -56,7 +56,7 @@ func TestFromIBCTransferToContract(t *testing.T) { require.NoError(t, err) newBalance := chainA.App.BankKeeper.GetBalance(chainA.GetContext(), chainA.SenderAccount.GetAddress(), sdk.DefaultBondDenom) assert.Equal(t, originalBalance.Sub(coinToSendToB), newBalance) - const ibcVoucherTicker = "ibc/310F9D708E5AA2F54CA83BC04C2E56F1EA62DB6FBDA321B337867CF5BEECF531" + const ibcVoucherTicker = "ibc/1AAD10C9C252ACF464C7167E328C866BBDA0BDED3D89EFAB7B7C30BF01DE4657" chainBBalance := chainB.App.BankKeeper.GetBalance(chainB.GetContext(), chainB.SenderAccount.GetAddress(), ibcVoucherTicker) // note: the contract is called during check and deliverTX but the context used in the contract does not rollback // so that we got twice the amount @@ -81,7 +81,7 @@ func TestContractCanInitiateIBCTransfer(t *testing.T) { var ( sourcePortID = contractAPortID counterpartPortID = "transfer" - ibcVoucherTicker = "ibc/054D923266485D040762676605B33A3F4B560217E11FCACE3CE52D844CFBCEF6" + ibcVoucherTicker = "ibc/8D5B148875A26426899137B476C646A94652D73BAEEE3CD30B9C261EB7BC0E1B" ) clientA, clientB, connA, connB := coordinator.SetupClientConnections(chainA, chainB, clientexported.Tendermint) channelA, channelB := coordinator.CreateChannel(chainA, chainB, connA, connB, sourcePortID, counterpartPortID, channeltypes.UNORDERED) @@ -100,7 +100,7 @@ func TestContractCanInitiateIBCTransfer(t *testing.T) { require.NoError(t, err) newBalance := chainB.App.BankKeeper.GetBalance(chainB.GetContext(), chainB.SenderAccount.GetAddress(), ibcVoucherTicker) - assert.Equal(t, sdk.NewCoin(ibcVoucherTicker, coinToSendToB.Amount).String(), newBalance.String()) + assert.Equal(t, sdk.NewCoin(ibcVoucherTicker, coinToSendToB.Amount).String(), newBalance.String(), chainB.App.BankKeeper.GetAllBalances(chainB.GetContext(), chainB.SenderAccount.GetAddress())) } type senderContract struct { @@ -158,6 +158,10 @@ func (s *senderContract) OnIBCPacketTimeout(hash []byte, params cosmwasmv2.Env, panic("implement me") } +func (s *senderContract) Execute(hash []byte, params cosmwasmv1.Env, msg []byte, store prefix.Store, api cosmwasm.GoAPI, querier wasmkeeper.QueryHandler, meter sdk.GasMeter, gas uint64) (*cosmwasmv2.HandleResponse, uint64, error) { + panic("implement me") +} + type receiverContract struct { t *testing.T contractAddr sdk.AccAddress @@ -241,6 +245,10 @@ func (c *receiverContract) OnIBCPacketTimeout(hash []byte, params cosmwasmv2.Env return &cosmwasmv2.IBCPacketTimeoutResponse{}, 0, nil } +func (c *receiverContract) Execute(hash []byte, params cosmwasmv1.Env, msg []byte, store prefix.Store, api cosmwasm.GoAPI, querier wasmkeeper.QueryHandler, meter sdk.GasMeter, gas uint64) (*cosmwasmv2.HandleResponse, uint64, error) { + panic("implement me") +} + func toIBCPacket(p cosmwasmv2.IBCPacket) channeltypes.Packet { return channeltypes.Packet{ Sequence: p.Sequence,