Skip to content

Commit

Permalink
chore: Remove duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
kulikthebird committed Jan 17, 2025
1 parent bd3b37b commit 60b7c14
Show file tree
Hide file tree
Showing 12 changed files with 641 additions and 217 deletions.
2 changes: 1 addition & 1 deletion app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func NewTestNetworkFixture() network.TestFixture {
}

// SignAndDeliverWithoutCommit signs and delivers a transaction. No commit
func SignAndDeliverWithoutCommit(t *testing.T, txCfg client.TxConfig, app *bam.BaseApp, msgs []sdk.Msg, fees sdk.Coins, chainID string, accNums, accSeqs []uint64, blockTime time.Time, priv ...cryptotypes.PrivKey) (*abci.ResponseFinalizeBlock, error) {
func SignAndDeliverWithoutCommit(t testing.TB, txCfg client.TxConfig, app *bam.BaseApp, msgs []sdk.Msg, fees sdk.Coins, chainID string, accNums, accSeqs []uint64, blockTime time.Time, priv ...cryptotypes.PrivKey) (*abci.ResponseFinalizeBlock, error) {
tx, err := simtestutil.GenSignedMockTx(
rand.New(rand.NewSource(time.Now().UnixNano())),
txCfg,
Expand Down
18 changes: 9 additions & 9 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,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.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
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 @@ -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,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.NewCoordinator2(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.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
19 changes: 10 additions & 9 deletions tests/e2e/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ 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))
contractAddr := e2e.InstantiateStargateReflectContract(t, chain)
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))

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.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))

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
31 changes: 15 additions & 16 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 @@ -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 @@ -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 @@ -199,27 +199,26 @@ 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.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.RelayAndAckPendingPackets(&chainA, &chainB, path)
}
Loading

0 comments on commit 60b7c14

Please sign in to comment.