Files
wasmd/x/wasm/relay_test.go
Alexander Peters 7e936c7fff Cosmos-SDK v0.47 integration brach (#1149)
* Start cosmos-sdk v0.47 integration (#1136)

* Upgrade to sdk v0.47 branch

* More integration work

* SDK version upgrade; fixes

* More fixes

* Fixes

* Deactivate failing tests

* SDK + ibc-go version upgrades

* limix gas fix

(cherry picked from commit f7f841768e5051d96d243b42ce4f231a33020326)

* with valset in bench

(cherry picked from commit 35b2a8fd2c23d6160fca540771fd348913f7f143)

* Revert staking query handler; fix tests

* Minor cleanup

* Rebased

* Address linter issues

* Set legacy router proper

* Deactivate failing test. Race condition needs to handled in SDK

* Address some code smells

* Bump sdk version

* Use gov v1 internally for votes

* Activate test after sdk fix

* Add group test

* Add config template for wasm fields

* Add Rust backtrace flag for more debug output on simulations

* Set unique node folder for tests

* Revert "Add Rust backtrace flag for more debug output on simulations"

This reverts commit 218c3c6ce137dc02f7bc38391408d3460fb27e6f.

* Simulations

* Run also im/export + deterministic sims

* Add package prefix to interfaces

* Add signer annotation (https://github.com/cosmos/cosmos-sdk/issues/10933), minor cleanup

* Bump sdk version

* Review comments

Co-authored-by: vuong <nguyenvuong1122000@gmail.com>

* Bump bufbuild/buf-setup-action from 1.11.0 to 1.12.0

Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.11.0 to 1.12.0.
- [Release notes](https://github.com/bufbuild/buf-setup-action/releases)
- [Commits](https://github.com/bufbuild/buf-setup-action/compare/v1.11.0...v1.12.0)

---
updated-dependencies:
- dependency-name: bufbuild/buf-setup-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
(cherry picked from commit f4905955b5)

* Remove intertx for vanilla ICA

* fix msg format in EVENTS.md

(cherry picked from commit 38d466adfd)

* Better to sdk coin convertion (#1164)

* Better to sdk coin convertion

* Review feedback

(cherry picked from commit a925a9ed61)

* Disallow only address permission (#1163)

* Remove AccessTypeOnlyAddress for store msg

* Remove AccessTypeOnlyAddress for update config msg

* Review feedback

Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com>

Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com>
(cherry picked from commit 8991633de2)

* Integrate wasmvm v1.2.0 (backport #1161) (#1175)

* Integrate wasmvm v1.2.0 (#1161)

* Bump wasmvm version

* Bump wasm test contracts

* Encode weighted votes

* Encode instantiate2

* Handle code info query; better wasmvm errors

* Fix readme

* Make linter happy

* add non cgo build

* Review comments

* Bump wasmvm to release version

Co-authored-by: jhernandezb <contact@jhernandez.me>
(cherry picked from commit 957b38e0a5)

# Conflicts:
#	x/wasm/keeper/handler_plugin_encoders.go
#	x/wasm/keeper/handler_plugin_encoders_test.go
#	x/wasm/keeper/keeper.go
#	x/wasm/keeper/keeper_test.go

* Adress merge conflicts

Co-authored-by: Alexander Peters <alpe@users.noreply.github.com>

* Bump bufbuild/buf-setup-action from 1.12.0 to 1.13.0

Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.12.0 to 1.13.0.
- [Release notes](https://github.com/bufbuild/buf-setup-action/releases)
- [Commits](https://github.com/bufbuild/buf-setup-action/compare/v1.12.0...v1.13.0)

---
updated-dependencies:
- dependency-name: bufbuild/buf-setup-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
(cherry picked from commit ffa0e5e5e1)

* Emit events for setContractAdmin + setAccessConfig (#1179)

(cherry picked from commit c9e7830ac1)

* Dependency upgrades (#1172)

* Bump sdk version to lastest

* Bump ibc-go  version to lastest

* Remove channel hack

* Update to ibc-go v7 + protoVer=0.11.5

* Bump bufbuild/buf-setup-action from 1.13.0 to 1.13.1

Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.13.0 to 1.13.1.
- [Release notes](https://github.com/bufbuild/buf-setup-action/releases)
- [Commits](https://github.com/bufbuild/buf-setup-action/compare/v1.13.0...v1.13.1)

---
updated-dependencies:
- dependency-name: bufbuild/buf-setup-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
(cherry picked from commit de27e7f82f)

* Fix typos (backport #1185) (#1194)

* Fix typos

(cherry picked from commit c88b8194cb)

# Conflicts:
#	proto/cosmwasm/wasm/v1/tx.proto

* Fix merge conflict

---------

Co-authored-by: Alex Peters <alpe@users.noreply.github.com>

* Bump bufbuild/buf-setup-action from 1.13.1 to 1.14.0 (#1200)

Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.13.1 to 1.14.0.
- [Release notes](https://github.com/bufbuild/buf-setup-action/releases)
- [Commits](https://github.com/bufbuild/buf-setup-action/compare/v1.13.1...v1.14.0)

---
updated-dependencies:
- dependency-name: bufbuild/buf-setup-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
(cherry picked from commit f3fc31c386)

* list-contract-by-code bugfix

(cherry picked from commit 2ccffed778)

* fix: stargate querier does not reset the state

(cherry picked from commit fd0323541d)

* test: add unit test

(cherry picked from commit 6d8018ac59)

* Add Windows client support (#1197)

* Add Windows client support

* Separate server and windows client

---------

Co-authored-by: Alex Peters <alpe@users.noreply.github.com>
(cherry picked from commit 8a20779518)

* Bump bufbuild/buf-setup-action from 1.14.0 to 1.15.0

Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.14.0 to 1.15.0.
- [Release notes](https://github.com/bufbuild/buf-setup-action/releases)
- [Commits](https://github.com/bufbuild/buf-setup-action/compare/v1.14.0...v1.15.0)

---
updated-dependencies:
- dependency-name: bufbuild/buf-setup-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
(cherry picked from commit e5fab3da5a)

* Rename windows client binary

(cherry picked from commit de09c7fe2b)

* Return IBC packet sequence number (backport #1225) (#1233)

* Return IBC packet sequence number (#1225)

* Return IBC packet sequence number

* Fix review feedbacks

* Remove names to return values in DispatchMsg method

* Fix comments

(cherry picked from commit 4f1c57fc12)

# Conflicts:
#	x/wasm/keeper/handler_plugin.go

* Fix merge conflict

---------

Co-authored-by: pinosu <95283998+pinosu@users.noreply.github.com>
Co-authored-by: Alex Peters <alpe@users.noreply.github.com>

* Test rust panic for regression

(cherry picked from commit a52e604966)

* Fix client checksum verification (#1234)

* Fix client checksum verification

* Review comments

(cherry picked from commit 1a8019b380)

# Conflicts:
#	x/wasm/client/cli/gov_tx.go

* Fix merge conflict

* Fix linters

* Configure sonarcloud analysis

(cherry picked from commit 85cf1614fb)

* Bump bufbuild/buf-setup-action from 1.15.0 to 1.15.1

Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.15.0 to 1.15.1.
- [Release notes](https://github.com/bufbuild/buf-setup-action/releases)
- [Commits](https://github.com/bufbuild/buf-setup-action/compare/v1.15.0...v1.15.1)

---
updated-dependencies:
- dependency-name: bufbuild/buf-setup-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
(cherry picked from commit 730ea5a1cf)

* Make `CaptureIbcEvents` in ibctesting public.

Before this change, it wasn't possible to implement the
`chain.SendMsgs` method without
[copying](https://github.com/public-awesome/ics721/blob/main/e2e/suite_helpers.go#L81-L98)
them over.

(cherry picked from commit b64fa078a3)

* Upgrade to wasmvm 1.2.1 (backport #1245) (#1254)

* Upgrade to wasmvm 1.2.1 (#1245)

* Use wasmvm store adapter

* Bump wasmvm to v1.2.1

(cherry picked from commit 850f901b2e)

# Conflicts:
#	go.mod
#	go.sum
#	x/wasm/keeper/keeper.go

* Resolve conflicts

---------

Co-authored-by: Alexander Peters <alpe@users.noreply.github.com>

* WIP All cometbft (#1244)

* Dep upgrade; use CometBft

* Remove duplicte message events

* Add changelog for v0.31.0 (#1188)

* Start changelog for v0.31.0

* Add ICA upgrade

* Add proto version link to buf.build

* Update changelog (#1239)

* Update changelog

* Update changelog with latest changes

* Set release date

---------

Co-authored-by: pinosu <95283998+pinosu@users.noreply.github.com>
(cherry picked from commit bc0e817912)

* Remove new message type event

* Support msg update params gov proposal (#1247)

* Add MsgUpdateParams support

* Implement UpdateParams msg

* Fix test UpdateParams

* Add migration test

* Fix

* Fix lint issues

* Revert changes according to review feedback

* Remove more x/params dependencies

* Remove x/params from genesis test

* Formatting

* Restore old changes

* fix lint

* Fix tests and restructure migrations

* Rename alias for convention

---------

Co-authored-by: Alex Peters <alpe@users.noreply.github.com>

* Fix test data generator (#1263)

* linting 47 pr (#1261)

* lint cosmwasm for sdk 47

* fix

* remove setGenesis

* remove additional unused functions

* pass tests

* use SDK's errors module

* unecessary conversions

* unnecessary conversions

* remove unneeded event manager

* complete linting of tests for 47

* add test for reimportation

* check errors

* Update x/wasm/keeper/proposal_integration_test.go

Co-authored-by: Alexander Peters <alpe@users.noreply.github.com>

* apply suggestion

* suggestions

* lints

* don't return error in when making new transactions

* no todo's in the code

* Fix test data generator

* Update x/wasm/types/genesis_test.go

Co-authored-by: Alexander Peters <alpe@users.noreply.github.com>

* use the full string invalid address (2 words) always

---------

Co-authored-by: Alexander Peters <alpe@users.noreply.github.com>

* Regenerate from proto; remove dead code; polish code

* Set SDK version to v0.47x.0 (#1262)

* Set SDK version to v0.47x.0

* Set chainID

* Minor updates

* Set chainID for simulations

* Buf mod update

* Use sdk tag instead of hash in buf

* Bump ibc-go to v7.0.0

* faddat/re merge main (#1274)

undefined

---------

Co-authored-by: vuong <nguyenvuong1122000@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: llllllluc <58892938+llllllluc@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Gjermund Garaba <gjermund@garaba.net>
Co-authored-by: Nikhil Suri <nikhilsuri@comcast.net>
Co-authored-by: Paul <p22626262@gmail.com>
Co-authored-by: pinosu <95283998+pinosu@users.noreply.github.com>
Co-authored-by: ekez <zekemedley@gmail.com>
Co-authored-by: Jacob Gadikian <jacobgadikian@gmail.com>
2023-03-20 10:32:22 +01:00

810 lines
32 KiB
Go

package wasm_test
import (
"encoding/json"
"errors"
"testing"
"time"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"
wasmvm "github.com/CosmWasm/wasmvm"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
wasmibctesting "github.com/CosmWasm/wasmd/x/wasm/ibctesting"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtesting "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting"
"github.com/CosmWasm/wasmd/x/wasm/types"
)
func TestFromIBCTransferToContract(t *testing.T) {
// scenario: given two chains,
// with a contract on chain B
// then the contract can handle the receiving side of an ics20 transfer
// that was started on chain A via ibc transfer module
transferAmount := sdk.NewInt(1)
specs := map[string]struct {
contract wasmtesting.IBCContractCallbacks
setupContract func(t *testing.T, contract wasmtesting.IBCContractCallbacks, chain *wasmibctesting.TestChain)
expChainABalanceDiff math.Int
expChainBBalanceDiff math.Int
}{
"ack": {
contract: &ackReceiverContract{},
setupContract: func(t *testing.T, contract wasmtesting.IBCContractCallbacks, chain *wasmibctesting.TestChain) {
c := contract.(*ackReceiverContract)
c.t = t
c.chain = chain
},
expChainABalanceDiff: transferAmount.Neg(),
expChainBBalanceDiff: transferAmount,
},
"nack": {
contract: &nackReceiverContract{},
setupContract: func(t *testing.T, contract wasmtesting.IBCContractCallbacks, chain *wasmibctesting.TestChain) {
c := contract.(*nackReceiverContract)
c.t = t
},
expChainABalanceDiff: sdk.ZeroInt(),
expChainBBalanceDiff: sdk.ZeroInt(),
},
"error": {
contract: &errorReceiverContract{},
setupContract: func(t *testing.T, contract wasmtesting.IBCContractCallbacks, chain *wasmibctesting.TestChain) {
c := contract.(*errorReceiverContract)
c.t = t
},
expChainABalanceDiff: sdk.ZeroInt(),
expChainBBalanceDiff: sdk.ZeroInt(),
},
}
for name, spec := range specs {
t.Run(name, func(t *testing.T) {
var (
chainAOpts = []wasmkeeper.Option{wasmkeeper.WithWasmEngine(
wasmtesting.NewIBCContractMockWasmer(spec.contract),
)}
coordinator = wasmibctesting.NewCoordinator(t, 2, []wasmkeeper.Option{}, chainAOpts)
chainA = coordinator.GetChain(wasmibctesting.GetChainID(1))
chainB = coordinator.GetChain(wasmibctesting.GetChainID(2))
)
coordinator.CommitBlock(chainA, chainB)
myContractAddr := chainB.SeedNewContractInstance()
contractBPortID := chainB.ContractInfo(myContractAddr).IBCPortID
spec.setupContract(t, spec.contract, chainB)
path := wasmibctesting.NewPath(chainA, chainB)
path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{
PortID: "transfer",
Version: ibctransfertypes.Version,
Order: channeltypes.UNORDERED,
}
path.EndpointB.ChannelConfig = &ibctesting.ChannelConfig{
PortID: contractBPortID,
Version: ibctransfertypes.Version,
Order: channeltypes.UNORDERED,
}
coordinator.SetupConnections(path)
coordinator.CreateChannels(path)
originalChainABalance := chainA.Balance(chainA.SenderAccount.GetAddress(), sdk.DefaultBondDenom)
// when transfer via sdk transfer from A (module) -> B (contract)
coinToSendToB := sdk.NewCoin(sdk.DefaultBondDenom, transferAmount)
timeoutHeight := clienttypes.NewHeight(1, 110)
msg := ibctransfertypes.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, coinToSendToB, chainA.SenderAccount.GetAddress().String(), chainB.SenderAccount.GetAddress().String(), timeoutHeight, 0, "")
_, err := chainA.SendMsgs(msg)
require.NoError(t, err)
require.NoError(t, path.EndpointB.UpdateClient())
// then
require.Equal(t, 1, len(chainA.PendingSendPackets))
require.Equal(t, 0, len(chainB.PendingSendPackets))
// and when relay to chain B and handle Ack on chain A
err = coordinator.RelayAndAckPendingPackets(path)
require.NoError(t, err)
// then
require.Equal(t, 0, len(chainA.PendingSendPackets))
require.Equal(t, 0, len(chainB.PendingSendPackets))
// and source chain balance was decreased
newChainABalance := chainA.Balance(chainA.SenderAccount.GetAddress(), sdk.DefaultBondDenom)
assert.Equal(t, originalChainABalance.Amount.Add(spec.expChainABalanceDiff), newChainABalance.Amount)
// and dest chain balance contains voucher
expBalance := ibctransfertypes.GetTransferCoin(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, coinToSendToB.Denom, spec.expChainBBalanceDiff)
gotBalance := chainB.Balance(chainB.SenderAccount.GetAddress(), expBalance.Denom)
assert.Equal(t, expBalance, gotBalance, "got total balance: %s", chainB.AllBalances(chainB.SenderAccount.GetAddress()))
})
}
}
func TestContractCanInitiateIBCTransferMsg(t *testing.T) {
// scenario: given two chains,
// with a contract on chain A
// then the contract can start an ibc transfer via ibctransfertypes.NewMsgTransfer
// that is handled on chain A by the ibc transfer module and
// received on chain B via ibc transfer module as well
myContract := &sendViaIBCTransferContract{t: t}
var (
chainAOpts = []wasmkeeper.Option{
wasmkeeper.WithWasmEngine(
wasmtesting.NewIBCContractMockWasmer(myContract)),
}
coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts)
chainA = coordinator.GetChain(wasmibctesting.GetChainID(1))
chainB = coordinator.GetChain(wasmibctesting.GetChainID(2))
)
myContractAddr := chainA.SeedNewContractInstance()
coordinator.CommitBlock(chainA, chainB)
path := wasmibctesting.NewPath(chainA, chainB)
path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{
PortID: ibctransfertypes.PortID,
Version: ibctransfertypes.Version,
Order: channeltypes.UNORDERED,
}
path.EndpointB.ChannelConfig = &ibctesting.ChannelConfig{
PortID: ibctransfertypes.PortID,
Version: ibctransfertypes.Version,
Order: channeltypes.UNORDERED,
}
coordinator.SetupConnections(path)
coordinator.CreateChannels(path)
// when contract is triggered to send IBCTransferMsg
receiverAddress := chainB.SenderAccount.GetAddress()
coinToSendToB := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))
// start transfer from chainA to chainB
startMsg := &types.MsgExecuteContract{
Sender: chainA.SenderAccount.GetAddress().String(),
Contract: myContractAddr.String(),
Msg: startTransfer{
ChannelID: path.EndpointA.ChannelID,
CoinsToSend: coinToSendToB,
ReceiverAddr: receiverAddress.String(),
}.GetBytes(),
}
// trigger contract to start the transfer
_, err := chainA.SendMsgs(startMsg)
require.NoError(t, err)
// then
require.Equal(t, 1, len(chainA.PendingSendPackets))
require.Equal(t, 0, len(chainB.PendingSendPackets))
// and when relay to chain B and handle Ack on chain A
err = coordinator.RelayAndAckPendingPackets(path)
require.NoError(t, err)
// then
require.Equal(t, 0, len(chainA.PendingSendPackets))
require.Equal(t, 0, len(chainB.PendingSendPackets))
// and dest chain balance contains voucher
bankKeeperB := chainB.App.BankKeeper
expBalance := ibctransfertypes.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()))
}
func TestContractCanEmulateIBCTransferMessage(t *testing.T) {
// scenario: given two chains,
// with a contract on chain A
// then the contract can emulate the ibc transfer module in the contract to send an ibc packet
// which is received on chain B via ibc transfer module
myContract := &sendEmulatedIBCTransferContract{t: t}
var (
chainAOpts = []wasmkeeper.Option{
wasmkeeper.WithWasmEngine(
wasmtesting.NewIBCContractMockWasmer(myContract)),
}
coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts)
chainA = coordinator.GetChain(wasmibctesting.GetChainID(1))
chainB = coordinator.GetChain(wasmibctesting.GetChainID(2))
)
myContractAddr := chainA.SeedNewContractInstance()
myContract.contractAddr = myContractAddr.String()
path := wasmibctesting.NewPath(chainA, chainB)
path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{
PortID: chainA.ContractInfo(myContractAddr).IBCPortID,
Version: ibctransfertypes.Version,
Order: channeltypes.UNORDERED,
}
path.EndpointB.ChannelConfig = &ibctesting.ChannelConfig{
PortID: ibctransfertypes.PortID,
Version: ibctransfertypes.Version,
Order: channeltypes.UNORDERED,
}
coordinator.SetupConnections(path)
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
receiverAddress := chainB.SenderAccount.GetAddress()
coinToSendToB := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))
// start transfer from chainA to chainB
startMsg := &types.MsgExecuteContract{
Sender: chainA.SenderAccount.GetAddress().String(),
Contract: myContractAddr.String(),
Msg: startTransfer{
ChannelID: path.EndpointA.ChannelID,
CoinsToSend: coinToSendToB,
ReceiverAddr: receiverAddress.String(),
ContractIBCPort: chainA.ContractInfo(myContractAddr).IBCPortID,
Timeout: timeout,
}.GetBytes(),
Funds: sdk.NewCoins(coinToSendToB),
}
_, err := chainA.SendMsgs(startMsg)
require.NoError(t, err)
// then
require.Equal(t, 1, len(chainA.PendingSendPackets))
require.Equal(t, 0, len(chainB.PendingSendPackets))
// and when relay to chain B and handle Ack on chain A
err = coordinator.RelayAndAckPendingPackets(path)
require.NoError(t, err)
// then
require.Equal(t, 0, len(chainA.PendingSendPackets))
require.Equal(t, 0, len(chainB.PendingSendPackets))
// and dest chain balance contains voucher
bankKeeperB := chainB.App.BankKeeper
expBalance := ibctransfertypes.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()))
}
func TestContractCanEmulateIBCTransferMessageWithTimeout(t *testing.T) {
// scenario: given two chains,
// with a contract on chain A
// then the contract can emulate the ibc transfer module in the contract to send an ibc packet
// which is not received on chain B and times out
myContract := &sendEmulatedIBCTransferContract{t: t}
var (
chainAOpts = []wasmkeeper.Option{
wasmkeeper.WithWasmEngine(
wasmtesting.NewIBCContractMockWasmer(myContract)),
}
coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts)
chainA = coordinator.GetChain(wasmibctesting.GetChainID(1))
chainB = coordinator.GetChain(wasmibctesting.GetChainID(2))
)
coordinator.CommitBlock(chainA, chainB)
myContractAddr := chainA.SeedNewContractInstance()
myContract.contractAddr = myContractAddr.String()
path := wasmibctesting.NewPath(chainA, chainB)
path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{
PortID: chainA.ContractInfo(myContractAddr).IBCPortID,
Version: ibctransfertypes.Version,
Order: channeltypes.UNORDERED,
}
path.EndpointB.ChannelConfig = &ibctesting.ChannelConfig{
PortID: ibctransfertypes.PortID,
Version: ibctransfertypes.Version,
Order: channeltypes.UNORDERED,
}
coordinator.SetupConnections(path)
coordinator.CreateChannels(path)
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
receiverAddress := chainB.SenderAccount.GetAddress()
coinToSendToB := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))
initialContractBalance := chainA.Balance(myContractAddr, sdk.DefaultBondDenom)
initialSenderBalance := chainA.Balance(chainA.SenderAccount.GetAddress(), sdk.DefaultBondDenom)
// custom payload data to be transferred into a proper ICS20 ibc packet
startMsg := &types.MsgExecuteContract{
Sender: chainA.SenderAccount.GetAddress().String(),
Contract: myContractAddr.String(),
Msg: startTransfer{
ChannelID: path.EndpointA.ChannelID,
CoinsToSend: coinToSendToB,
ReceiverAddr: receiverAddress.String(),
ContractIBCPort: chainA.ContractInfo(myContractAddr).IBCPortID,
Timeout: timeout,
}.GetBytes(),
Funds: sdk.NewCoins(coinToSendToB),
}
_, err := chainA.SendMsgs(startMsg)
require.NoError(t, err)
coordinator.CommitBlock(chainA, chainB)
// then
require.Equal(t, 1, len(chainA.PendingSendPackets))
require.Equal(t, 0, len(chainB.PendingSendPackets))
newContractBalance := chainA.Balance(myContractAddr, sdk.DefaultBondDenom)
assert.Equal(t, initialContractBalance.Add(coinToSendToB), newContractBalance) // hold in escrow
// when timeout packet send (by the relayer)
err = coordinator.TimeoutPendingPackets(path)
require.NoError(t, err)
coordinator.CommitBlock(chainA)
// then
require.Equal(t, 0, len(chainA.PendingSendPackets))
require.Equal(t, 0, len(chainB.PendingSendPackets))
// and then verify account balances restored
newContractBalance = chainA.Balance(myContractAddr, sdk.DefaultBondDenom)
assert.Equal(t, initialContractBalance.String(), newContractBalance.String())
newSenderBalance := chainA.Balance(chainA.SenderAccount.GetAddress(), sdk.DefaultBondDenom)
assert.Equal(t, initialSenderBalance.String(), newSenderBalance.String())
}
func TestContractEmulateIBCTransferMessageOnDiffContractIBCChannel(t *testing.T) {
// scenario: given two chains, A and B
// with 2 contract A1 and A2 on chain A
// then the contract A2 try to send an ibc packet via IBC Channel that create by A1 and B
myContractA1 := &sendEmulatedIBCTransferContract{}
myContractA2 := &sendEmulatedIBCTransferContract{}
var (
chainAOpts = []wasmkeeper.Option{
wasmkeeper.WithWasmEngine(
wasmtesting.NewIBCContractMockWasmer(myContractA1),
),
wasmkeeper.WithWasmEngine(
wasmtesting.NewIBCContractMockWasmer(myContractA2),
),
}
coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts)
chainA = coordinator.GetChain(wasmibctesting.GetChainID(1))
chainB = coordinator.GetChain(wasmibctesting.GetChainID(2))
)
coordinator.CommitBlock(chainA, chainB)
myContractAddr1 := chainA.SeedNewContractInstance()
myContractA1.contractAddr = myContractAddr1.String()
myContractAddr2 := chainA.SeedNewContractInstance()
myContractA2.contractAddr = myContractAddr2.String()
path := wasmibctesting.NewPath(chainA, chainB)
path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{
PortID: chainA.ContractInfo(myContractAddr1).IBCPortID,
Version: ibctransfertypes.Version,
Order: channeltypes.UNORDERED,
}
path.EndpointB.ChannelConfig = &ibctesting.ChannelConfig{
PortID: ibctransfertypes.PortID,
Version: ibctransfertypes.Version,
Order: channeltypes.UNORDERED,
}
coordinator.SetupConnections(path)
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
receiverAddress := chainB.SenderAccount.GetAddress()
coinToSendToB := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))
// start transfer from chainA - A2 to chainB via IBC channel
startMsg := &types.MsgExecuteContract{
Sender: chainA.SenderAccount.GetAddress().String(),
Contract: myContractAddr2.String(),
Msg: startTransfer{
ChannelID: path.EndpointA.ChannelID,
CoinsToSend: coinToSendToB,
ReceiverAddr: receiverAddress.String(),
Timeout: timeout,
}.GetBytes(),
Funds: sdk.NewCoins(coinToSendToB),
}
_, err := chainA.SendMsgs(startMsg)
require.Error(t, err)
}
func TestContractHandlesChannelClose(t *testing.T) {
// scenario: a contract is the sending side of an ics20 transfer but the packet was not received
// on the destination chain within the timeout boundaries
myContractA := &captureCloseContract{}
myContractB := &captureCloseContract{}
var (
chainAOpts = []wasmkeeper.Option{
wasmkeeper.WithWasmEngine(
wasmtesting.NewIBCContractMockWasmer(myContractA)),
}
chainBOpts = []wasmkeeper.Option{
wasmkeeper.WithWasmEngine(
wasmtesting.NewIBCContractMockWasmer(myContractB)),
}
coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts, chainBOpts)
chainA = coordinator.GetChain(wasmibctesting.GetChainID(1))
chainB = coordinator.GetChain(wasmibctesting.GetChainID(2))
)
coordinator.CommitBlock(chainA, chainB)
myContractAddrA := chainA.SeedNewContractInstance()
_ = chainB.SeedNewContractInstance() // skip one instance
myContractAddrB := chainB.SeedNewContractInstance()
path := wasmibctesting.NewPath(chainA, chainB)
path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{
PortID: chainA.ContractInfo(myContractAddrA).IBCPortID,
Version: ibctransfertypes.Version,
Order: channeltypes.UNORDERED,
}
path.EndpointB.ChannelConfig = &ibctesting.ChannelConfig{
PortID: chainB.ContractInfo(myContractAddrB).IBCPortID,
Version: ibctransfertypes.Version,
Order: channeltypes.UNORDERED,
}
coordinator.SetupConnections(path)
coordinator.CreateChannels(path)
coordinator.CloseChannel(path)
assert.True(t, myContractB.closeCalled)
}
func TestContractHandlesChannelCloseNotOwned(t *testing.T) {
// scenario: given two chains,
// with a contract A1, A2 on chain A, contract B on chain B
// contract A2 try to close ibc channel that create between A1 and B
myContractA1 := &closeChannelContract{}
myContractA2 := &closeChannelContract{}
myContractB := &closeChannelContract{}
var (
chainAOpts = []wasmkeeper.Option{
wasmkeeper.WithWasmEngine(
wasmtesting.NewIBCContractMockWasmer(myContractA1)),
wasmkeeper.WithWasmEngine(
wasmtesting.NewIBCContractMockWasmer(myContractA2)),
}
chainBOpts = []wasmkeeper.Option{
wasmkeeper.WithWasmEngine(
wasmtesting.NewIBCContractMockWasmer(myContractB)),
}
coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts, chainBOpts)
chainA = coordinator.GetChain(wasmibctesting.GetChainID(1))
chainB = coordinator.GetChain(wasmibctesting.GetChainID(2))
)
coordinator.CommitBlock(chainA, chainB)
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.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{
PortID: chainA.ContractInfo(myContractAddrA1).IBCPortID,
Version: ibctransfertypes.Version,
Order: channeltypes.UNORDERED,
}
path.EndpointB.ChannelConfig = &ibctesting.ChannelConfig{
PortID: chainB.ContractInfo(myContractAddrB).IBCPortID,
Version: ibctransfertypes.Version,
Order: channeltypes.UNORDERED,
}
coordinator.SetupConnections(path)
coordinator.CreateChannels(path)
closeIBCChannelMsg := &types.MsgExecuteContract{
Sender: chainA.SenderAccount.GetAddress().String(),
Contract: myContractAddrA2.String(),
Msg: closeIBCChannel{
ChannelID: path.EndpointA.ChannelID,
}.GetBytes(),
Funds: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))),
}
_, err := chainA.SendMsgs(closeIBCChannelMsg)
require.Error(t, err)
}
var _ wasmtesting.IBCContractCallbacks = &captureCloseContract{}
// contract that sets a flag on IBC channel close only.
type captureCloseContract struct {
contractStub
closeCalled bool
}
func (c *captureCloseContract) IBCChannelClose(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ wasmvmtypes.IBCChannelCloseMsg, _ wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) {
c.closeCalled = true
return &wasmvmtypes.IBCBasicResponse{}, 1, nil
}
var _ wasmtesting.IBCContractCallbacks = &sendViaIBCTransferContract{}
// contract that initiates an ics-20 transfer on execute via sdk message
type sendViaIBCTransferContract struct {
contractStub
t *testing.T
}
func (s *sendViaIBCTransferContract) Execute(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ wasmvmtypes.MessageInfo, executeMsg []byte, _ wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) {
var in startTransfer
if err := json.Unmarshal(executeMsg, &in); err != nil {
return nil, 0, err
}
ibcMsg := &wasmvmtypes.IBCMsg{
Transfer: &wasmvmtypes.TransferMsg{
ToAddress: in.ReceiverAddr,
Amount: wasmvmtypes.NewCoin(in.CoinsToSend.Amount.Uint64(), in.CoinsToSend.Denom),
ChannelID: in.ChannelID,
Timeout: wasmvmtypes.IBCTimeout{Block: &wasmvmtypes.IBCTimeoutBlock{
Revision: 1,
Height: 110,
}},
},
}
return &wasmvmtypes.Response{Messages: []wasmvmtypes.SubMsg{{ReplyOn: wasmvmtypes.ReplyNever, Msg: wasmvmtypes.CosmosMsg{IBC: ibcMsg}}}}, 0, nil
}
var _ wasmtesting.IBCContractCallbacks = &sendEmulatedIBCTransferContract{}
// contract that interacts as an ics20 sending side via IBC packets
// It can also handle the timeout.
type sendEmulatedIBCTransferContract struct {
contractStub
t *testing.T
contractAddr string
}
func (s *sendEmulatedIBCTransferContract) Execute(_ wasmvm.Checksum, _ wasmvmtypes.Env, info wasmvmtypes.MessageInfo, executeMsg []byte, _ wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) {
var in startTransfer
if err := json.Unmarshal(executeMsg, &in); err != nil {
return nil, 0, err
}
require.Len(s.t, info.Funds, 1)
require.Equal(s.t, in.CoinsToSend.Amount.String(), info.Funds[0].Amount)
require.Equal(s.t, in.CoinsToSend.Denom, info.Funds[0].Denom)
dataPacket := ibctransfertypes.NewFungibleTokenPacketData(
in.CoinsToSend.Denom, in.CoinsToSend.Amount.String(), info.Sender, in.ReceiverAddr, "memo",
)
if err := dataPacket.ValidateBasic(); err != nil {
return nil, 0, err
}
ibcMsg := &wasmvmtypes.IBCMsg{
SendPacket: &wasmvmtypes.SendPacketMsg{
ChannelID: in.ChannelID,
Data: dataPacket.GetBytes(),
Timeout: wasmvmtypes.IBCTimeout{Timestamp: in.Timeout},
},
}
return &wasmvmtypes.Response{Messages: []wasmvmtypes.SubMsg{{ReplyOn: wasmvmtypes.ReplyNever, Msg: wasmvmtypes.CosmosMsg{IBC: ibcMsg}}}}, 0, nil
}
func (s *sendEmulatedIBCTransferContract) IBCPacketTimeout(_ wasmvm.Checksum, _ wasmvmtypes.Env, msg wasmvmtypes.IBCPacketTimeoutMsg, _ wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) {
packet := msg.Packet
var data ibctransfertypes.FungibleTokenPacketData
if err := ibctransfertypes.ModuleCdc.UnmarshalJSON(packet.Data, &data); err != nil {
return nil, 0, err
}
if err := data.ValidateBasic(); err != nil {
return nil, 0, err
}
amount, _ := sdk.NewIntFromString(data.Amount)
returnTokens := &wasmvmtypes.BankMsg{
Send: &wasmvmtypes.SendMsg{
ToAddress: data.Sender,
Amount: wasmvmtypes.Coins{wasmvmtypes.NewCoin(amount.Uint64(), data.Denom)},
},
}
return &wasmvmtypes.IBCBasicResponse{Messages: []wasmvmtypes.SubMsg{{ReplyOn: wasmvmtypes.ReplyNever, Msg: wasmvmtypes.CosmosMsg{Bank: returnTokens}}}}, 0, nil
}
var _ wasmtesting.IBCContractCallbacks = &closeChannelContract{}
type closeChannelContract struct {
contractStub
}
func (c *closeChannelContract) IBCChannelClose(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ wasmvmtypes.IBCChannelCloseMsg, _ wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) {
return &wasmvmtypes.IBCBasicResponse{}, 1, nil
}
func (c *closeChannelContract) Execute(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ wasmvmtypes.MessageInfo, executeMsg []byte, _ wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) {
var in closeIBCChannel
if err := json.Unmarshal(executeMsg, &in); err != nil {
return nil, 0, err
}
ibcMsg := &wasmvmtypes.IBCMsg{
CloseChannel: &wasmvmtypes.CloseChannelMsg{
ChannelID: in.ChannelID,
},
}
return &wasmvmtypes.Response{Messages: []wasmvmtypes.SubMsg{{ReplyOn: wasmvmtypes.ReplyNever, Msg: wasmvmtypes.CosmosMsg{IBC: ibcMsg}}}}, 0, nil
}
type closeIBCChannel struct {
ChannelID string
}
func (g closeIBCChannel) GetBytes() types.RawContractMessage {
b, err := json.Marshal(g)
if err != nil {
panic(err)
}
return b
}
// custom contract execute payload
type startTransfer struct {
ChannelID string
CoinsToSend sdk.Coin
ReceiverAddr string
ContractIBCPort string
Timeout uint64
}
func (g startTransfer) GetBytes() types.RawContractMessage {
b, err := json.Marshal(g)
if err != nil {
panic(err)
}
return b
}
var _ wasmtesting.IBCContractCallbacks = &ackReceiverContract{}
// contract that acts as the receiving side for an ics-20 transfer.
type ackReceiverContract struct {
contractStub
t *testing.T
chain *wasmibctesting.TestChain
}
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) {
packet := msg.Packet
var src ibctransfertypes.FungibleTokenPacketData
if err := ibctransfertypes.ModuleCdc.UnmarshalJSON(packet.Data, &src); err != nil {
return nil, 0, err
}
require.NoError(c.t, src.ValidateBasic())
// 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.TransferKeeper.OnRecvPacket(ctx, ibcPacket, src)
if err != nil {
return nil, 0, errorsmod.Wrap(err, "within our smart contract")
}
var log []wasmvmtypes.EventAttribute // note: all events are under `wasm` event type
ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement()
return &wasmvmtypes.IBCReceiveResult{Ok: &wasmvmtypes.IBCReceiveResponse{Acknowledgement: ack, Attributes: log}}, 0, nil
}
func (c *ackReceiverContract) IBCPacketAck(_ wasmvm.Checksum, _ wasmvmtypes.Env, msg wasmvmtypes.IBCPacketAckMsg, _ wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) {
var data ibctransfertypes.FungibleTokenPacketData
if err := ibctransfertypes.ModuleCdc.UnmarshalJSON(msg.OriginalPacket.Data, &data); err != nil {
return nil, 0, err
}
// call original ibctransfer keeper to not copy all code into this
var ack channeltypes.Acknowledgement
if err := ibctransfertypes.ModuleCdc.UnmarshalJSON(msg.Acknowledgement.Data, &ack); err != nil {
return nil, 0, err
}
// 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.TransferKeeper.OnAcknowledgementPacket(ctx, ibcPacket, data, ack)
if err != nil {
return nil, 0, errorsmod.Wrap(err, "within our smart contract")
}
return &wasmvmtypes.IBCBasicResponse{}, 0, nil
}
// contract that acts as the receiving side for an ics-20 transfer and always returns a nack.
type nackReceiverContract struct {
contractStub
t *testing.T
}
func (c *nackReceiverContract) IBCPacketReceive(_ wasmvm.Checksum, _ wasmvmtypes.Env, msg wasmvmtypes.IBCPacketReceiveMsg, _ wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.IBCReceiveResult, uint64, error) {
packet := msg.Packet
var src ibctransfertypes.FungibleTokenPacketData
if err := ibctransfertypes.ModuleCdc.UnmarshalJSON(packet.Data, &src); err != nil {
return nil, 0, err
}
require.NoError(c.t, src.ValidateBasic())
return &wasmvmtypes.IBCReceiveResult{Err: "nack-testing"}, 0, nil
}
// contract that acts as the receiving side for an ics-20 transfer and always returns an error.
type errorReceiverContract struct {
contractStub
t *testing.T
}
func (c *errorReceiverContract) IBCPacketReceive(_ wasmvm.Checksum, _ wasmvmtypes.Env, msg wasmvmtypes.IBCPacketReceiveMsg, _ wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.IBCReceiveResult, uint64, error) {
packet := msg.Packet
var src ibctransfertypes.FungibleTokenPacketData
if err := ibctransfertypes.ModuleCdc.UnmarshalJSON(packet.Data, &src); err != nil {
return nil, 0, err
}
require.NoError(c.t, src.ValidateBasic())
return nil, 0, errors.New("error-testing")
}
// simple helper struct that implements connection setup methods.
type contractStub struct{}
func (s *contractStub) IBCChannelOpen(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ wasmvmtypes.IBCChannelOpenMsg, _ wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.IBC3ChannelOpenResponse, uint64, error) {
return &wasmvmtypes.IBC3ChannelOpenResponse{}, 0, nil
}
func (s *contractStub) IBCChannelConnect(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ wasmvmtypes.IBCChannelConnectMsg, _ wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) {
return &wasmvmtypes.IBCBasicResponse{}, 0, nil
}
func (s *contractStub) IBCChannelClose(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ wasmvmtypes.IBCChannelCloseMsg, _ wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) {
panic("implement me")
}
func (s *contractStub) IBCPacketReceive(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ wasmvmtypes.IBCPacketReceiveMsg, _ wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.IBCReceiveResult, uint64, error) {
panic("implement me")
}
func (s *contractStub) IBCPacketAck(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ wasmvmtypes.IBCPacketAckMsg, _ wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) {
return &wasmvmtypes.IBCBasicResponse{}, 0, nil
}
func (s *contractStub) IBCPacketTimeout(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ wasmvmtypes.IBCPacketTimeoutMsg, _ wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) {
panic("implement me")
}
func toIBCPacket(p wasmvmtypes.IBCPacket) channeltypes.Packet {
var height clienttypes.Height
if p.Timeout.Block != nil {
height = clienttypes.NewHeight(p.Timeout.Block.Revision, p.Timeout.Block.Height)
}
return channeltypes.Packet{
Sequence: p.Sequence,
SourcePort: p.Src.PortID,
SourceChannel: p.Src.ChannelID,
DestinationPort: p.Dest.PortID,
DestinationChannel: p.Dest.ChannelID,
Data: p.Data,
TimeoutHeight: height,
TimeoutTimestamp: p.Timeout.Timestamp,
}
}