Skip to content

Commit c5cec22

Browse files
authored
chore: Cleanup in IBC tests (#2097)
1 parent 219453c commit c5cec22

20 files changed

+808
-2534
lines changed

tests/e2e/gov_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"time"
66

77
wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types"
8+
ibctesting "github.com/cosmos/ibc-go/v9/testing"
89
"github.com/stretchr/testify/assert"
910
"github.com/stretchr/testify/require"
1011

@@ -15,9 +16,8 @@ import (
1516
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
1617
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
1718

18-
"github.com/CosmWasm/wasmd/app"
1919
"github.com/CosmWasm/wasmd/tests/e2e"
20-
"github.com/CosmWasm/wasmd/tests/ibctesting"
20+
wasmibctesting "github.com/CosmWasm/wasmd/tests/wasmibctesting"
2121
)
2222

2323
func TestGovVoteByContract(t *testing.T) {
@@ -26,8 +26,8 @@ func TestGovVoteByContract(t *testing.T) {
2626
// When the contract sends a vote for the proposal
2727
// Then the vote is taken into account
2828

29-
coord := ibctesting.NewCoordinator(t, 1)
30-
chain := coord.GetChain(ibctesting.GetChainID(1))
29+
coord := wasmibctesting.NewCoordinator(t, 1)
30+
chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))
3131
contractAddr := e2e.InstantiateReflectContract(t, chain)
3232
chain.Fund(contractAddr, sdkmath.NewIntFromUint64(1_000_000_000))
3333
// a contract with a high delegation amount
@@ -45,7 +45,7 @@ func TestGovVoteByContract(t *testing.T) {
4545
e2e.MustExecViaReflectContract(t, chain, contractAddr, delegateMsg)
4646

4747
signer := chain.SenderAccount.GetAddress().String()
48-
app := chain.App.(*app.WasmApp)
48+
app := chain.GetWasmApp()
4949
govKeeper, accountKeeper := app.GovKeeper, app.AccountKeeper
5050
communityPoolBalance := chain.Balance(accountKeeper.GetModuleAccount(chain.GetContext(), distributiontypes.ModuleName).GetAddress(), sdk.DefaultBondDenom)
5151
require.False(t, communityPoolBalance.IsZero())
@@ -128,7 +128,7 @@ func TestGovVoteByContract(t *testing.T) {
128128
proposal, err := govKeeper.Proposals.Get(chain.GetContext(), propID)
129129
require.NoError(t, err)
130130
coord.IncrementTimeBy(proposal.VotingEndTime.Sub(chain.GetContext().BlockTime()) + time.Minute)
131-
coord.CommitBlock(chain)
131+
coord.CommitBlock(chain.TestChain)
132132

133133
// and recipient balance updated
134134
recipientBalance := chain.Balance(recipientAddr, sdk.DefaultBondDenom)

tests/e2e/grants_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
wasmvm "github.com/CosmWasm/wasmvm/v2"
10+
ibctesting "github.com/cosmos/ibc-go/v9/testing"
1011
"github.com/stretchr/testify/assert"
1112
"github.com/stretchr/testify/require"
1213

@@ -20,7 +21,7 @@ import (
2021
"github.com/cosmos/cosmos-sdk/x/authz"
2122

2223
"github.com/CosmWasm/wasmd/tests/e2e"
23-
"github.com/CosmWasm/wasmd/tests/ibctesting"
24+
wasmibctesting "github.com/CosmWasm/wasmd/tests/wasmibctesting"
2425
"github.com/CosmWasm/wasmd/x/wasm/types"
2526
)
2627

@@ -33,8 +34,8 @@ func TestGrants(t *testing.T) {
3334
// - balance A reduced (on success)
3435
// - balance B not touched
3536

36-
coord := ibctesting.NewCoordinator(t, 1)
37-
chain := coord.GetChain(ibctesting.GetChainID(1))
37+
coord := wasmibctesting.NewCoordinator(t, 1)
38+
chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))
3839
contractAddr := e2e.InstantiateReflectContract(t, chain)
3940
require.NotEmpty(t, contractAddr)
4041

@@ -130,8 +131,8 @@ func TestStoreCodeGrant(t *testing.T) {
130131
reflectCodeChecksum, err := wasmvm.CreateChecksum(reflectWasmCode)
131132
require.NoError(t, err)
132133

133-
coord := ibctesting.NewCoordinator(t, 1)
134-
chain := coord.GetChain(ibctesting.GetChainID(1))
134+
coord := wasmibctesting.NewCoordinator(t, 1)
135+
chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))
135136

136137
granterAddr := chain.SenderAccount.GetAddress()
137138
granteePrivKey := secp256k1.GenPrivKey()
@@ -218,8 +219,8 @@ func TestGzipStoreCodeGrant(t *testing.T) {
218219
hackatomCodeChecksum, err := wasmvm.CreateChecksum(hackatomWasmCode)
219220
require.NoError(t, err)
220221

221-
coord := ibctesting.NewCoordinator(t, 1)
222-
chain := coord.GetChain(ibctesting.GetChainID(1))
222+
coord := wasmibctesting.NewCoordinator(t, 1)
223+
chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))
223224

224225
granterAddr := chain.SenderAccount.GetAddress()
225226
granteePrivKey := secp256k1.GenPrivKey()
@@ -300,8 +301,8 @@ func TestBrokenGzipStoreCodeGrant(t *testing.T) {
300301
brokenGzipWasmCode, err := os.ReadFile("../../x/wasm/keeper/testdata/broken_crc.gzip")
301302
require.NoError(t, err)
302303

303-
coord := ibctesting.NewCoordinator(t, 1)
304-
chain := coord.GetChain(ibctesting.GetChainID(1))
304+
coord := wasmibctesting.NewCoordinator(t, 1)
305+
chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))
305306

306307
granterAddr := chain.SenderAccount.GetAddress()
307308
granteePrivKey := secp256k1.GenPrivKey()

tests/e2e/group_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"time"
66

77
"github.com/cometbft/cometbft/libs/rand"
8+
ibctesting "github.com/cosmos/ibc-go/v9/testing"
89
"github.com/stretchr/testify/assert"
910
"github.com/stretchr/testify/require"
1011

@@ -16,7 +17,7 @@ import (
1617
"github.com/cosmos/cosmos-sdk/x/group"
1718

1819
"github.com/CosmWasm/wasmd/tests/e2e"
19-
"github.com/CosmWasm/wasmd/tests/ibctesting"
20+
wasmibctesting "github.com/CosmWasm/wasmd/tests/wasmibctesting"
2021
"github.com/CosmWasm/wasmd/x/wasm/types"
2122
)
2223

@@ -25,8 +26,8 @@ func TestGroupWithContract(t *testing.T) {
2526
// When contract submits a proposal with try_execute
2627
// Then the payload msg is executed
2728

28-
coord := ibctesting.NewCoordinator(t, 1)
29-
chain := coord.GetChain(ibctesting.GetChainID(1))
29+
coord := wasmibctesting.NewCoordinator(t, 1)
30+
chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))
3031
contractAddr := e2e.InstantiateStargateReflectContract(t, chain)
3132
chain.Fund(contractAddr, sdkmath.NewIntFromUint64(1_000_000_000))
3233

@@ -80,8 +81,8 @@ func TestGroupWithNewReflectContract(t *testing.T) {
8081
// When contract submits a proposal with try_execute
8182
// Then the payload msg is executed
8283

83-
coord := ibctesting.NewCoordinator(t, 1)
84-
chain := coord.GetChain(ibctesting.GetChainID(1))
84+
coord := wasmibctesting.NewCoordinator(t, 1)
85+
chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))
8586
contractAddr := e2e.InstantiateReflectContract(t, chain)
8687
chain.Fund(contractAddr, sdkmath.NewIntFromUint64(1_000_000_000))
8788

tests/e2e/ibc_callbacks_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020

2121
"github.com/CosmWasm/wasmd/app"
2222
"github.com/CosmWasm/wasmd/tests/e2e"
23-
wasmibctesting "github.com/CosmWasm/wasmd/tests/ibctesting"
23+
wasmibctesting "github.com/CosmWasm/wasmd/tests/wasmibctesting"
2424
"github.com/CosmWasm/wasmd/x/wasm/types"
2525
)
2626

@@ -34,13 +34,13 @@ func TestIBCCallbacks(t *testing.T) {
3434
// and the contract on A should receive a source chain callback with the result (ack or timeout)
3535
marshaler := app.MakeEncodingConfig(t).Codec
3636
coord := wasmibctesting.NewCoordinator(t, 2)
37-
chainA := coord.GetChain(wasmibctesting.GetChainID(1))
38-
chainB := coord.GetChain(wasmibctesting.GetChainID(2))
37+
chainA := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))
38+
chainB := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(2)))
3939

4040
actorChainA := sdk.AccAddress(chainA.SenderPrivKey.PubKey().Address())
4141
oneToken := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(1)))
4242

43-
path := wasmibctesting.NewPath(chainA, chainB)
43+
path := wasmibctesting.NewWasmPath(chainA, chainB)
4444
path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{
4545
PortID: ibctransfertypes.PortID,
4646
Version: string(marshaler.MustMarshalJSON(&ibcfee.Metadata{FeeVersion: ibcfee.Version, AppVersion: ibctransfertypes.V2})),
@@ -52,7 +52,7 @@ func TestIBCCallbacks(t *testing.T) {
5252
Order: channeltypes.UNORDERED,
5353
}
5454
// with an ics-20 transfer channel setup between both chains
55-
coord.Setup(path)
55+
coord.Setup(&path.Path)
5656

5757
// with an ibc-callbacks contract deployed on chain A
5858
codeIDonA := chainA.StoreCodeFile("./testdata/ibc_callbacks.wasm").CodeID
@@ -128,7 +128,7 @@ func TestIBCCallbacks(t *testing.T) {
128128

129129
if spec.expAck {
130130
// and the packet is relayed
131-
require.NoError(t, coord.RelayAndAckPendingPackets(path))
131+
wasmibctesting.RelayAndAckPendingPackets(path)
132132

133133
// then the contract on chain B should receive a receive callback
134134
var response QueryResp
@@ -150,7 +150,7 @@ func TestIBCCallbacks(t *testing.T) {
150150
assert.Equal(t, []byte(`{"result":"AQ=="}`), response.IBCAckCallbacks[0].Acknowledgement.Data)
151151
} else {
152152
// and the packet times out
153-
require.NoError(t, coord.TimeoutPendingPackets(path))
153+
require.NoError(t, wasmibctesting.TimeoutPendingPackets(coord, path))
154154

155155
// then the contract on chain B should not receive anything
156156
var response QueryResp
@@ -179,12 +179,12 @@ func TestIBCCallbacksWithoutEntrypoints(t *testing.T) {
179179
// and should try to call the callback on A and fail gracefully
180180
marshaler := app.MakeEncodingConfig(t).Codec
181181
coord := wasmibctesting.NewCoordinator(t, 2)
182-
chainA := coord.GetChain(wasmibctesting.GetChainID(1))
183-
chainB := coord.GetChain(wasmibctesting.GetChainID(2))
182+
chainA := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))
183+
chainB := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(2)))
184184

185185
oneToken := sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(1))
186186

187-
path := wasmibctesting.NewPath(chainA, chainB)
187+
path := wasmibctesting.NewWasmPath(chainA, chainB)
188188
path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{
189189
PortID: ibctransfertypes.PortID,
190190
Version: string(marshaler.MustMarshalJSON(&ibcfee.Metadata{FeeVersion: ibcfee.Version, AppVersion: ibctransfertypes.V2})),
@@ -196,7 +196,7 @@ func TestIBCCallbacksWithoutEntrypoints(t *testing.T) {
196196
Order: channeltypes.UNORDERED,
197197
}
198198
// with an ics-20 transfer channel setup between both chains
199-
coord.Setup(path)
199+
coord.Setup(&path.Path)
200200

201201
// with a reflect contract deployed on chain A and B
202202
contractAddrA := e2e.InstantiateReflectContract(t, chainA)
@@ -212,14 +212,14 @@ func TestIBCCallbacksWithoutEntrypoints(t *testing.T) {
212212
ChannelID: path.EndpointA.ChannelID,
213213
Amount: wasmvmtypes.NewCoin(oneToken.Amount.Uint64(), oneToken.Denom),
214214
Timeout: wasmvmtypes.IBCTimeout{
215-
Timestamp: uint64(chainA.LastHeader.GetTime().Add(time.Second * 100).UnixNano()),
215+
Timestamp: uint64(chainA.LatestCommittedHeader.GetTime().Add(time.Second * 100).UnixNano()),
216216
},
217217
Memo: memo,
218218
},
219219
},
220220
})
221221

222222
// and the packet is relayed without problems
223-
require.NoError(t, coord.RelayAndAckPendingPackets(path))
224-
assert.Empty(t, chainA.PendingSendPackets)
223+
wasmibctesting.RelayAndAckPendingPackets(path)
224+
assert.Empty(t, *chainA.PendingSendPackets)
225225
}

0 commit comments

Comments
 (0)