Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Cleanup in IBC tests #2089

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions tests/e2e/gov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types"
ibctesting "github.com/cosmos/ibc-go/v9/testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand All @@ -15,9 +16,8 @@ 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/wasmibctesting"
)

func TestGovVoteByContract(t *testing.T) {
Expand All @@ -26,9 +26,9 @@ 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))
contractAddr := e2e.InstantiateReflectContract(t, chain)
coord := wasmibctesting.NewCoordinator(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
delegateMsg := wasmvmtypes.CosmosMsg{
Expand All @@ -42,10 +42,10 @@ func TestGovVoteByContract(t *testing.T) {
},
},
}
e2e.MustExecViaReflectContract(t, chain, contractAddr, delegateMsg)
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())
Expand Down Expand Up @@ -122,13 +122,13 @@ func TestGovVoteByContract(t *testing.T) {
Vote: spec.vote,
},
}
e2e.MustExecViaReflectContract(t, chain, contractAddr, voteMsg)
e2e.MustExecViaReflectContract(t, &chain, contractAddr, voteMsg)

// then proposal executed after voting period
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)
Expand Down
21 changes: 11 additions & 10 deletions tests/e2e/grants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

wasmvm "github.com/CosmWasm/wasmvm/v2"
ibctesting "github.com/cosmos/ibc-go/v9/testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand All @@ -20,7 +21,7 @@ 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/wasmibctesting"
"github.com/CosmWasm/wasmd/x/wasm/types"
)

Expand All @@ -33,9 +34,9 @@ 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))
contractAddr := e2e.InstantiateReflectContract(t, chain)
coord := wasmibctesting.NewCoordinator(t, 1)
chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))
contractAddr := e2e.InstantiateReflectContract(t, &chain)
require.NotEmpty(t, contractAddr)

granterAddr := chain.SenderAccount.GetAddress()
Expand Down Expand Up @@ -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.NewCoordinator(t, 1)
chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))

granterAddr := chain.SenderAccount.GetAddress()
granteePrivKey := secp256k1.GenPrivKey()
Expand Down Expand Up @@ -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.NewCoordinator(t, 1)
chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))

granterAddr := chain.SenderAccount.GetAddress()
granteePrivKey := secp256k1.GenPrivKey()
Expand Down Expand Up @@ -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.NewCoordinator(t, 1)
chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))

granterAddr := chain.SenderAccount.GetAddress()
granteePrivKey := secp256k1.GenPrivKey()
Expand Down
19 changes: 10 additions & 9 deletions tests/e2e/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/cometbft/cometbft/libs/rand"
ibctesting "github.com/cosmos/ibc-go/v9/testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand All @@ -16,7 +17,7 @@ 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/wasmibctesting"
"github.com/CosmWasm/wasmd/x/wasm/types"
)

Expand All @@ -25,9 +26,9 @@ 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))
contractAddr := e2e.InstantiateStargateReflectContract(t, chain)
coord := wasmibctesting.NewCoordinator(t, 1)
chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))
contractAddr := e2e.InstantiateStargateReflectContract(t, &chain)
chain.Fund(contractAddr, sdkmath.NewIntFromUint64(1_000_000_000))

members := []group.MemberRequest{
Expand Down Expand Up @@ -61,7 +62,7 @@ func TestGroupWithContract(t *testing.T) {
propMsg, err := group.NewMsgSubmitProposal(policyAddr.String(), []string{contractAddr.String()}, payload, "my proposal", group.Exec_EXEC_TRY, "my title", "my description")
require.NoError(t, err)

rsp = e2e.MustExecViaStargateReflectContract(t, chain, contractAddr, propMsg)
rsp = e2e.MustExecViaStargateReflectContract(t, &chain, contractAddr, propMsg)
var execRsp types.MsgExecuteContractResponse
chain.UnwrapExecTXResult(rsp, &execRsp)

Expand All @@ -80,9 +81,9 @@ 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))
contractAddr := e2e.InstantiateReflectContract(t, chain)
coord := wasmibctesting.NewCoordinator(t, 1)
chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))
contractAddr := e2e.InstantiateReflectContract(t, &chain)
chain.Fund(contractAddr, sdkmath.NewIntFromUint64(1_000_000_000))

members := []group.MemberRequest{
Expand Down Expand Up @@ -116,7 +117,7 @@ func TestGroupWithNewReflectContract(t *testing.T) {
propMsg, err := group.NewMsgSubmitProposal(policyAddr.String(), []string{contractAddr.String()}, payload, "my proposal", group.Exec_EXEC_TRY, "my title", "my description")
require.NoError(t, err)

rsp = e2e.MustExecViaAnyReflectContract(t, chain, contractAddr, propMsg)
rsp = e2e.MustExecViaAnyReflectContract(t, &chain, contractAddr, propMsg)
var execRsp types.MsgExecuteContractResponse
chain.UnwrapExecTXResult(rsp, &execRsp)

Expand Down
30 changes: 15 additions & 15 deletions 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/tests/ibctesting"
wasmibctesting "github.com/CosmWasm/wasmd/tests/wasmibctesting"
"github.com/CosmWasm/wasmd/x/wasm/types"
)

Expand All @@ -34,13 +34,13 @@ func TestIBCCallbacks(t *testing.T) {
// 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))
chainA := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))
chainB := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.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})),
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestIBCCallbacks(t *testing.T) {

if spec.expAck {
// and the packet is relayed
require.NoError(t, coord.RelayAndAckPendingPackets(path))
wasmibctesting.RelayAndAckPendingPackets(&chainA, &chainB, path)

// then the contract on chain B should receive a receive callback
var response QueryResp
Expand All @@ -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, &chainA, path))

// then the contract on chain B should not receive anything
var response QueryResp
Expand Down Expand Up @@ -179,12 +179,12 @@ func TestIBCCallbacksWithoutEntrypoints(t *testing.T) {
// 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))
chainA := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))
chainB := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.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})),
Expand All @@ -199,27 +199,27 @@ func TestIBCCallbacksWithoutEntrypoints(t *testing.T) {
coord.Setup(path)

// with a reflect contract deployed on chain A and B
contractAddrA := e2e.InstantiateReflectContract(t, chainA)
contractAddrA := e2e.InstantiateReflectContract(t, &chainA)
chainA.Fund(contractAddrA, oneToken.Amount)
contractAddrB := e2e.InstantiateReflectContract(t, chainA)
contractAddrB := e2e.InstantiateReflectContract(t, &chainA)

// 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{
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.LatestCommittedHeader.GetTime().Add(time.Second * 100).UnixNano()),
},
Memo: memo,
},
},
})

// and the packet is relayed without problems
require.NoError(t, coord.RelayAndAckPendingPackets(path))
assert.Empty(t, chainA.PendingSendPackets)
wasmibctesting.RelayAndAckPendingPackets(&chainA, &chainB, path)
assert.Empty(t, *chainA.PendingSendPackets)
}
Loading
Loading