Skip to content

Commit

Permalink
chore: Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
kulikthebird committed Jan 17, 2025
1 parent f58e0f5 commit 22fb6bc
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 148 deletions.
12 changes: 6 additions & 6 deletions tests/e2e/gov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ 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/ibctesting"
ibctesting "github.com/cosmos/ibc-go/v9/testing"
)

func TestGovVoteByContract(t *testing.T) {
Expand All @@ -26,8 +26,8 @@ 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))
coord := wasmibctesting.NewCoordinator2(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
Expand All @@ -45,7 +45,7 @@ func TestGovVoteByContract(t *testing.T) {
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 @@ -128,7 +128,7 @@ func TestGovVoteByContract(t *testing.T) {
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
19 changes: 10 additions & 9 deletions tests/e2e/grants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ 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/ibctesting"
"github.com/CosmWasm/wasmd/x/wasm/types"
ibctesting "github.com/cosmos/ibc-go/v9/testing"
)

func TestGrants(t *testing.T) {
Expand All @@ -33,8 +34,8 @@ 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))
coord := wasmibctesting.NewCoordinator2(t, 1)
chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))
contractAddr := e2e.InstantiateReflectContract(t, chain)
require.NotEmpty(t, contractAddr)

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.NewCoordinator2(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.NewCoordinator2(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.NewCoordinator2(t, 1)
chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))

granterAddr := chain.SenderAccount.GetAddress()
granteePrivKey := secp256k1.GenPrivKey()
Expand Down
11 changes: 6 additions & 5 deletions tests/e2e/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ 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/ibctesting"
"github.com/CosmWasm/wasmd/x/wasm/types"
ibctesting "github.com/cosmos/ibc-go/v9/testing"
)

func TestGroupWithContract(t *testing.T) {
// Given a group with a contract as only member
// 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))
coord := wasmibctesting.NewCoordinator2(t, 1)
chain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))
contractAddr := e2e.InstantiateStargateReflectContract(t, chain)
chain.Fund(contractAddr, sdkmath.NewIntFromUint64(1_000_000_000))

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

Expand Down
29 changes: 14 additions & 15 deletions tests/e2e/ibc_callbacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ func TestIBCCallbacks(t *testing.T) {
// then the contract on B should receive a destination chain callback
// 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))
coord := wasmibctesting.NewCoordinator2(t, 2)
chainA := wasmibctesting.NewWasmTestChain(coord.GetChain(wasmibctesting.GetChainID(1)))
chainB := wasmibctesting.NewWasmTestChain(coord.GetChain(wasmibctesting.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 @@ -123,12 +123,12 @@ func TestIBCCallbacks(t *testing.T) {
Msg: contractMsgBz,
Funds: oneToken,
}
_, err = chainA.SendMsgs(&execMsg)
result, err := chainA.SendMsgs(&execMsg)
require.NoError(t, err)

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

// 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, path, result))

// then the contract on chain B should not receive anything
var response QueryResp
Expand Down Expand Up @@ -178,13 +178,13 @@ func TestIBCCallbacksWithoutEntrypoints(t *testing.T) {
// then the VM should try to call the callback on B and fail gracefully
// 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))
coord := wasmibctesting.NewCoordinator2(t, 2)
chainA := wasmibctesting.NewWasmTestChain(coord.GetChain(wasmibctesting.GetChainID(1)))
chainB := wasmibctesting.NewWasmTestChain(coord.GetChain(wasmibctesting.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 @@ -205,21 +205,20 @@ func TestIBCCallbacksWithoutEntrypoints(t *testing.T) {

// 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{
result := 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.ProposedHeader.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.RelayAndAckPacket(t, path, result)
}
16 changes: 8 additions & 8 deletions tests/e2e/ibc_fees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ func TestIBCFeesReflect(t *testing.T) {
// then the relayer's payee is receiving the fee(s) on success

marshaler := app.MakeEncodingConfig(t).Codec
coord := wasmibctesting.NewCoordinator(t, 2)
chainA := coord.GetChain(wasmibctesting.GetChainID(1))
chainB := coord.GetChain(ibctesting.GetChainID(2))
coord := wasmibctesting.NewCoordinator2(t, 2)
chainA := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))
chainB := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(2)))
actorChainA := sdk.AccAddress(chainA.SenderPrivKey.PubKey().Address())
actorChainB := sdk.AccAddress(chainB.SenderPrivKey.PubKey().Address())

Expand All @@ -262,7 +262,7 @@ func TestIBCFeesReflect(t *testing.T) {
payee := sdk.AccAddress(bytes.Repeat([]byte{2}, address.Len))
oneToken := []wasmvmtypes.Coin{wasmvmtypes.NewCoin(1, sdk.DefaultBondDenom)}

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 @@ -275,8 +275,8 @@ func TestIBCFeesReflect(t *testing.T) {
}
// with an ics-29 fee enabled channel setup between both chains
coord.Setup(path)
appA := chainA.App.(*app.WasmApp)
appB := chainB.App.(*app.WasmApp)
appA := chainA.GetWasmApp()
appB := chainB.GetWasmApp()
require.True(t, appA.IBCFeeKeeper.IsFeeEnabled(chainA.GetContext(), ibctransfertypes.PortID, path.EndpointA.ChannelID))
require.True(t, appB.IBCFeeKeeper.IsFeeEnabled(chainB.GetContext(), ibctransfertypes.PortID, path.EndpointB.ChannelID))
// and with a payee registered for A -> B
Expand All @@ -286,7 +286,7 @@ func TestIBCFeesReflect(t *testing.T) {
require.NoError(t, err)

// when reflect contract on A sends a PayPacketFee msg, followed by a transfer
_, err = ExecViaReflectContract(t, chainA, reflectContractAddr, []wasmvmtypes.CosmosMsg{
result, err := ExecViaReflectContract(t, chainA, reflectContractAddr, []wasmvmtypes.CosmosMsg{
{
IBC: &wasmvmtypes.IBCMsg{
PayPacketFee: &wasmvmtypes.PayPacketFeeMsg{
Expand Down Expand Up @@ -340,7 +340,7 @@ func TestIBCFeesReflect(t *testing.T) {
require.NoError(t, err)

// and packages relayed
require.NoError(t, coord.RelayAndAckPendingPackets(path))
wasmibctesting.RelayAndAckPacket(t, path, result)

// then
// on chain A
Expand Down
18 changes: 8 additions & 10 deletions tests/e2e/ica_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/cosmos/cosmos-sdk/types/address"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

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

Expand All @@ -33,15 +32,15 @@ func TestICA(t *testing.T) {
// and the channel is established to the host chain
// then the ICA owner can submit a message via IBC
// to control their account on the host chain
coord := wasmibctesting.NewCoordinator(t, 2)
hostChain := coord.GetChain(ibctesting.GetChainID(1))
coord := wasmibctesting.NewCoordinator2(t, 2)
hostChain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))
hostParams := hosttypes.NewParams(true, []string{sdk.MsgTypeURL(&banktypes.MsgSend{})})
hostApp := hostChain.App.(*app.WasmApp)
hostApp := hostChain.GetWasmApp()
hostApp.ICAHostKeeper.SetParams(hostChain.GetContext(), hostParams)

controllerChain := coord.GetChain(ibctesting.GetChainID(2))
controllerChain := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(2)))

path := wasmibctesting.NewPath(controllerChain, hostChain)
path := ibctesting.NewPath(controllerChain.TestChain, hostChain.TestChain)
coord.SetupConnections(path)

specs := map[string]struct {
Expand Down Expand Up @@ -90,7 +89,7 @@ func TestICA(t *testing.T) {
coord.CreateChannels(path)

// assert ICA exists on controller
contApp := controllerChain.App.(*app.WasmApp)
contApp := controllerChain.GetWasmApp()
icaRsp, err := contApp.ICAControllerKeeper.InterchainAccount(controllerChain.GetContext(), &icacontrollertypes.QueryInterchainAccountRequest{
Owner: icaControllerAddr.String(),
ConnectionId: path.EndpointA.ConnectionID,
Expand All @@ -112,11 +111,10 @@ func TestICA(t *testing.T) {
}
relativeTimeout := uint64(time.Minute.Nanoseconds()) // note this is in nanoseconds
msgSendTx := icacontrollertypes.NewMsgSendTx(icaControllerAddr.String(), path.EndpointA.ConnectionID, relativeTimeout, payloadPacket)
_, err = controllerChain.SendNonDefaultSenderMsgs(icaControllerKey, msgSendTx)
result, err := controllerChain.SendNonDefaultSenderMsgs(icaControllerKey, msgSendTx)
require.NoError(t, err)

assert.Equal(t, 1, len(controllerChain.PendingSendPackets))
require.NoError(t, coord.RelayAndAckPendingPackets(path))
wasmibctesting.RelayAndAckPacket(t, path, result)

gotBalance := hostChain.Balance(targetAddr, sdk.DefaultBondDenom)
assert.Equal(t, sendCoin.String(), gotBalance.String())
Expand Down
14 changes: 7 additions & 7 deletions tests/e2e/reflect_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@ import (

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

"github.com/CosmWasm/wasmd/tests/ibctesting"
wasmibctesting "github.com/CosmWasm/wasmd/tests/ibctesting"
"github.com/CosmWasm/wasmd/x/wasm/keeper/testdata"
"github.com/CosmWasm/wasmd/x/wasm/types"
)

// InstantiateStargateReflectContract stores and instantiates the reflect contract shipped with CosmWasm 1.5.3.
// This instance still expects the old CosmosMsg.Stargate variant instead of the new CosmosMsg.Any.
func InstantiateStargateReflectContract(t *testing.T, chain *ibctesting.TestChain) sdk.AccAddress {
func InstantiateStargateReflectContract(t *testing.T, chain wasmibctesting.WasmTestChain) sdk.AccAddress {
codeID := chain.StoreCodeFile("../../x/wasm/keeper/testdata/reflect_1_5.wasm").CodeID
contractAddr := chain.InstantiateContract(codeID, []byte(`{}`))
require.NotEmpty(t, contractAddr)
return contractAddr
}

// InstantiateReflectContract stores and instantiates a 2.0 reflect contract instance.
func InstantiateReflectContract(t *testing.T, chain *ibctesting.TestChain) sdk.AccAddress {
func InstantiateReflectContract(t *testing.T, chain wasmibctesting.WasmTestChain) sdk.AccAddress {
codeID := chain.StoreCodeFile("../../x/wasm/keeper/testdata/reflect_2_0.wasm").CodeID
contractAddr := chain.InstantiateContract(codeID, []byte(`{}`))
require.NotEmpty(t, contractAddr)
return contractAddr
}

// MustExecViaReflectContract submit execute message to send payload to reflect contract
func MustExecViaReflectContract(t *testing.T, chain *ibctesting.TestChain, contractAddr sdk.AccAddress, msgs ...wasmvmtypes.CosmosMsg) *abci.ExecTxResult {
func MustExecViaReflectContract(t *testing.T, chain wasmibctesting.WasmTestChain, contractAddr sdk.AccAddress, msgs ...wasmvmtypes.CosmosMsg) *abci.ExecTxResult {
rsp, err := ExecViaReflectContract(t, chain, contractAddr, msgs)
require.NoError(t, err)
return rsp
Expand All @@ -47,7 +47,7 @@ type sdkMessageType interface {
sdk.Msg
}

func MustExecViaStargateReflectContract[T sdkMessageType](t *testing.T, chain *ibctesting.TestChain, contractAddr sdk.AccAddress, msgs ...T) *abci.ExecTxResult {
func MustExecViaStargateReflectContract[T sdkMessageType](t *testing.T, chain wasmibctesting.WasmTestChain, contractAddr sdk.AccAddress, msgs ...T) *abci.ExecTxResult {
require.NotEmpty(t, msgs)
// convert messages to stargate variant
vmMsgs := make([]string, len(msgs))
Expand All @@ -70,7 +70,7 @@ func MustExecViaStargateReflectContract[T sdkMessageType](t *testing.T, chain *i
return rsp
}

func MustExecViaAnyReflectContract[T sdkMessageType](t *testing.T, chain *ibctesting.TestChain, contractAddr sdk.AccAddress, msgs ...T) *abci.ExecTxResult {
func MustExecViaAnyReflectContract[T sdkMessageType](t *testing.T, chain wasmibctesting.WasmTestChain, contractAddr sdk.AccAddress, msgs ...T) *abci.ExecTxResult {
vmMsgs := make([]wasmvmtypes.CosmosMsg, len(msgs))
for i, m := range msgs {
bz, err := chain.Codec.Marshal(m)
Expand All @@ -88,7 +88,7 @@ func MustExecViaAnyReflectContract[T sdkMessageType](t *testing.T, chain *ibctes
}

// ExecViaReflectContract submit execute message to send payload to reflect contract
func ExecViaReflectContract(t *testing.T, chain *ibctesting.TestChain, contractAddr sdk.AccAddress, msgs []wasmvmtypes.CosmosMsg) (*abci.ExecTxResult, error) {
func ExecViaReflectContract(t *testing.T, chain wasmibctesting.WasmTestChain, contractAddr sdk.AccAddress, msgs []wasmvmtypes.CosmosMsg) (*abci.ExecTxResult, error) {
require.NotEmpty(t, msgs)
reflectSend := testdata.ReflectHandleMsg{
Reflect: &testdata.ReflectPayload{Msgs: msgs},
Expand Down
Loading

0 comments on commit 22fb6bc

Please sign in to comment.