Skip to content

Commit

Permalink
Extract ibctesting from x/wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
pinosu committed Aug 29, 2024
1 parent b275e48 commit a77610c
Show file tree
Hide file tree
Showing 21 changed files with 118 additions and 132 deletions.
2 changes: 1 addition & 1 deletion tests/e2e/gov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

"github.com/CosmWasm/wasmd/app"
"github.com/CosmWasm/wasmd/tests/e2e"
"github.com/CosmWasm/wasmd/x/wasm/ibctesting"
"github.com/CosmWasm/wasmd/tests/ibctesting"
)

func TestGovVoteByContract(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/grants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/authz"

"github.com/CosmWasm/wasmd/tests/e2e"
"github.com/CosmWasm/wasmd/x/wasm/ibctesting"
"github.com/CosmWasm/wasmd/tests/ibctesting"
"github.com/CosmWasm/wasmd/x/wasm/types"
)

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/group"

"github.com/CosmWasm/wasmd/tests/e2e"
"github.com/CosmWasm/wasmd/x/wasm/ibctesting"
"github.com/CosmWasm/wasmd/tests/ibctesting"
"github.com/CosmWasm/wasmd/x/wasm/types"
)

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/ibc_callbacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"github.com/CosmWasm/wasmd/app"
"github.com/CosmWasm/wasmd/tests/e2e"
wasmibctesting "github.com/CosmWasm/wasmd/x/wasm/ibctesting"
wasmibctesting "github.com/CosmWasm/wasmd/tests/ibctesting"
"github.com/CosmWasm/wasmd/x/wasm/types"
)

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/ibc_fees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/address"

"github.com/CosmWasm/wasmd/app"
wasmibctesting "github.com/CosmWasm/wasmd/x/wasm/ibctesting"
wasmibctesting "github.com/CosmWasm/wasmd/tests/ibctesting"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
)

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/ica_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

"github.com/CosmWasm/wasmd/app"
wasmibctesting "github.com/CosmWasm/wasmd/x/wasm/ibctesting"
wasmibctesting "github.com/CosmWasm/wasmd/tests/ibctesting"
)

func TestICA(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/reflect_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/CosmWasm/wasmd/x/wasm/ibctesting"
"github.com/CosmWasm/wasmd/tests/ibctesting"
"github.com/CosmWasm/wasmd/x/wasm/keeper/testdata"
"github.com/CosmWasm/wasmd/x/wasm/types"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
110 changes: 109 additions & 1 deletion tests/integration/ibc_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,120 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/CosmWasm/wasmd/app"
wasmibctesting "github.com/CosmWasm/wasmd/x/wasm/ibctesting"
wasmibctesting "github.com/CosmWasm/wasmd/tests/ibctesting"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting"
"github.com/CosmWasm/wasmd/x/wasm/types"
)

func TestIBCReflectContract(t *testing.T) {
// scenario:
// chain A: ibc_reflect_send.wasm
// chain B: reflect_1_5.wasm + ibc_reflect.wasm
//
// Chain A "ibc_reflect_send" sends a IBC packet "on channel connect" event to chain B "ibc_reflect"
// "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.CommitBlock(chainA, chainB)

initMsg := []byte(`{}`)
codeID := chainA.StoreCodeFile("./testdata/ibc_reflect_send.wasm").CodeID
sendContractAddr := chainA.InstantiateContract(codeID, initMsg)

reflectID := chainB.StoreCodeFile("./testdata/reflect_1_5.wasm").CodeID
initMsg = wasmkeeper.IBCReflectInitMsg{
ReflectCodeID: reflectID,
}.GetBytes(t)
codeID = chainB.StoreCodeFile("./testdata/ibc_reflect.wasm").CodeID

reflectContractAddr := chainB.InstantiateContract(codeID, initMsg)
var (
sourcePortID = chainA.ContractInfo(sendContractAddr).IBCPortID
counterpartPortID = chainB.ContractInfo(reflectContractAddr).IBCPortID
)
coordinator.CommitBlock(chainA, chainB)
coordinator.UpdateTime()

require.Equal(t, chainA.CurrentHeader.Time, chainB.CurrentHeader.Time)
path := wasmibctesting.NewPath(chainA, chainB)
path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{
PortID: sourcePortID,
Version: "ibc-reflect-v1",
Order: channeltypes.ORDERED,
}
path.EndpointB.ChannelConfig = &ibctesting.ChannelConfig{
PortID: counterpartPortID,
Version: "ibc-reflect-v1",
Order: channeltypes.ORDERED,
}

coordinator.SetupConnections(path)
coordinator.CreateChannels(path)

// TODO: query both contracts directly to ensure they have registered the proper connection
// (and the chainB has created a reflect contract)

// there should be one packet to relay back and forth (whoami)
// TODO: how do I find the packet that was previously sent by the smart contract?
// Coordinator.RecvPacket requires channeltypes.Packet as input?
// Given the source (portID, channelID), we should be able to count how many packets are pending, query the data
// and submit them to the other side (same with acks). This is what the real relayer does. I guess the test framework doesn't?

// Update: I dug through the code, especially channel.Keeper.SendPacket, and it only writes a commitment
// only writes I see: https://github.com/cosmos/cosmos-sdk/blob/31fdee0228bd6f3e787489c8e4434aabc8facb7d/x/ibc/core/04-channel/keeper/packet.go#L115-L116
// commitment is hashed packet: https://github.com/cosmos/cosmos-sdk/blob/31fdee0228bd6f3e787489c8e4434aabc8facb7d/x/ibc/core/04-channel/types/packet.go#L14-L34
// how is the relayer supposed to get the original packet data??
// eg. ibctransfer doesn't store the packet either: https://github.com/cosmos/cosmos-sdk/blob/master/x/ibc/applications/transfer/keeper/relay.go#L145-L162
// ... or I guess the original packet data is only available in the event logs????
// https://github.com/cosmos/cosmos-sdk/blob/31fdee0228bd6f3e787489c8e4434aabc8facb7d/x/ibc/core/04-channel/keeper/packet.go#L121-L132

// ensure the expected packet was prepared, and relay it
require.Equal(t, 1, len(chainA.PendingSendPackets))
require.Equal(t, 0, len(chainB.PendingSendPackets))
err := coordinator.RelayAndAckPendingPackets(path)
require.NoError(t, err)
require.Equal(t, 0, len(chainA.PendingSendPackets))
require.Equal(t, 0, len(chainB.PendingSendPackets))

// let's query the source contract and make sure it registered an address
query := ReflectSendQueryMsg{Account: &AccountQuery{ChannelID: path.EndpointA.ChannelID}}
var account AccountResponse
err = chainA.SmartQuery(sendContractAddr.String(), query, &account)
require.NoError(t, err)
require.NotEmpty(t, account.RemoteAddr)
require.Empty(t, account.RemoteBalance)

// close channel
coordinator.CloseChannel(path)

// let's query the source contract and make sure it registered an address
account = AccountResponse{}
err = chainA.SmartQuery(sendContractAddr.String(), query, &account)
require.Error(t, err)
assert.Contains(t, err.Error(), "not found")
}

type ReflectSendQueryMsg struct {
Admin *struct{} `json:"admin,omitempty"`
ListAccounts *struct{} `json:"list_accounts,omitempty"`
Account *AccountQuery `json:"account,omitempty"`
}

type AccountQuery struct {
ChannelID string `json:"channel_id"`
}

type AccountResponse struct {
LastUpdateTime uint64 `json:"last_update_time,string"`
RemoteAddr string `json:"remote_addr"`
RemoteBalance wasmvmtypes.Array[wasmvmtypes.Coin] `json:"remote_balance"`
}

func TestOnChanOpenInitVersion(t *testing.T) {
const v1 = "v1"
specs := map[string]struct {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/relay_pingpong_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

app2 "github.com/CosmWasm/wasmd/app"
wasmibctesting "github.com/CosmWasm/wasmd/x/wasm/ibctesting"
wasmibctesting "github.com/CosmWasm/wasmd/tests/ibctesting"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/CosmWasm/wasmd/app"
wasmibctesting "github.com/CosmWasm/wasmd/x/wasm/ibctesting"
wasmibctesting "github.com/CosmWasm/wasmd/tests/ibctesting"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting"
"github.com/CosmWasm/wasmd/x/wasm/types"
Expand Down
122 changes: 0 additions & 122 deletions x/wasm/ibc_reflect_test.go

This file was deleted.

0 comments on commit a77610c

Please sign in to comment.