Cosmos-SDK v0.47 integration brach (#1149)

* Start cosmos-sdk v0.47 integration (#1136)

* Upgrade to sdk v0.47 branch

* More integration work

* SDK version upgrade; fixes

* More fixes

* Fixes

* Deactivate failing tests

* SDK + ibc-go version upgrades

* limix gas fix

(cherry picked from commit f7f841768e5051d96d243b42ce4f231a33020326)

* with valset in bench

(cherry picked from commit 35b2a8fd2c23d6160fca540771fd348913f7f143)

* Revert staking query handler; fix tests

* Minor cleanup

* Rebased

* Address linter issues

* Set legacy router proper

* Deactivate failing test. Race condition needs to handled in SDK

* Address some code smells

* Bump sdk version

* Use gov v1 internally for votes

* Activate test after sdk fix

* Add group test

* Add config template for wasm fields

* Add Rust backtrace flag for more debug output on simulations

* Set unique node folder for tests

* Revert "Add Rust backtrace flag for more debug output on simulations"

This reverts commit 218c3c6ce137dc02f7bc38391408d3460fb27e6f.

* Simulations

* Run also im/export + deterministic sims

* Add package prefix to interfaces

* Add signer annotation (https://github.com/cosmos/cosmos-sdk/issues/10933), minor cleanup

* Bump sdk version

* Review comments

Co-authored-by: vuong <nguyenvuong1122000@gmail.com>

* Bump bufbuild/buf-setup-action from 1.11.0 to 1.12.0

Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.11.0 to 1.12.0.
- [Release notes](https://github.com/bufbuild/buf-setup-action/releases)
- [Commits](https://github.com/bufbuild/buf-setup-action/compare/v1.11.0...v1.12.0)

---
updated-dependencies:
- dependency-name: bufbuild/buf-setup-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
(cherry picked from commit f4905955b5)

* Remove intertx for vanilla ICA

* fix msg format in EVENTS.md

(cherry picked from commit 38d466adfd)

* Better to sdk coin convertion (#1164)

* Better to sdk coin convertion

* Review feedback

(cherry picked from commit a925a9ed61)

* Disallow only address permission (#1163)

* Remove AccessTypeOnlyAddress for store msg

* Remove AccessTypeOnlyAddress for update config msg

* Review feedback

Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com>

Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com>
(cherry picked from commit 8991633de2)

* Integrate wasmvm v1.2.0 (backport #1161) (#1175)

* Integrate wasmvm v1.2.0 (#1161)

* Bump wasmvm version

* Bump wasm test contracts

* Encode weighted votes

* Encode instantiate2

* Handle code info query; better wasmvm errors

* Fix readme

* Make linter happy

* add non cgo build

* Review comments

* Bump wasmvm to release version

Co-authored-by: jhernandezb <contact@jhernandez.me>
(cherry picked from commit 957b38e0a5)

# Conflicts:
#	x/wasm/keeper/handler_plugin_encoders.go
#	x/wasm/keeper/handler_plugin_encoders_test.go
#	x/wasm/keeper/keeper.go
#	x/wasm/keeper/keeper_test.go

* Adress merge conflicts

Co-authored-by: Alexander Peters <alpe@users.noreply.github.com>

* Bump bufbuild/buf-setup-action from 1.12.0 to 1.13.0

Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.12.0 to 1.13.0.
- [Release notes](https://github.com/bufbuild/buf-setup-action/releases)
- [Commits](https://github.com/bufbuild/buf-setup-action/compare/v1.12.0...v1.13.0)

---
updated-dependencies:
- dependency-name: bufbuild/buf-setup-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
(cherry picked from commit ffa0e5e5e1)

* Emit events for setContractAdmin + setAccessConfig (#1179)

(cherry picked from commit c9e7830ac1)

* Dependency upgrades (#1172)

* Bump sdk version to lastest

* Bump ibc-go  version to lastest

* Remove channel hack

* Update to ibc-go v7 + protoVer=0.11.5

* Bump bufbuild/buf-setup-action from 1.13.0 to 1.13.1

Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.13.0 to 1.13.1.
- [Release notes](https://github.com/bufbuild/buf-setup-action/releases)
- [Commits](https://github.com/bufbuild/buf-setup-action/compare/v1.13.0...v1.13.1)

---
updated-dependencies:
- dependency-name: bufbuild/buf-setup-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
(cherry picked from commit de27e7f82f)

* Fix typos (backport #1185) (#1194)

* Fix typos

(cherry picked from commit c88b8194cb)

# Conflicts:
#	proto/cosmwasm/wasm/v1/tx.proto

* Fix merge conflict

---------

Co-authored-by: Alex Peters <alpe@users.noreply.github.com>

* Bump bufbuild/buf-setup-action from 1.13.1 to 1.14.0 (#1200)

Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.13.1 to 1.14.0.
- [Release notes](https://github.com/bufbuild/buf-setup-action/releases)
- [Commits](https://github.com/bufbuild/buf-setup-action/compare/v1.13.1...v1.14.0)

---
updated-dependencies:
- dependency-name: bufbuild/buf-setup-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
(cherry picked from commit f3fc31c386)

* list-contract-by-code bugfix

(cherry picked from commit 2ccffed778)

* fix: stargate querier does not reset the state

(cherry picked from commit fd0323541d)

* test: add unit test

(cherry picked from commit 6d8018ac59)

* Add Windows client support (#1197)

* Add Windows client support

* Separate server and windows client

---------

Co-authored-by: Alex Peters <alpe@users.noreply.github.com>
(cherry picked from commit 8a20779518)

* Bump bufbuild/buf-setup-action from 1.14.0 to 1.15.0

Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.14.0 to 1.15.0.
- [Release notes](https://github.com/bufbuild/buf-setup-action/releases)
- [Commits](https://github.com/bufbuild/buf-setup-action/compare/v1.14.0...v1.15.0)

---
updated-dependencies:
- dependency-name: bufbuild/buf-setup-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
(cherry picked from commit e5fab3da5a)

* Rename windows client binary

(cherry picked from commit de09c7fe2b)

* Return IBC packet sequence number (backport #1225) (#1233)

* Return IBC packet sequence number (#1225)

* Return IBC packet sequence number

* Fix review feedbacks

* Remove names to return values in DispatchMsg method

* Fix comments

(cherry picked from commit 4f1c57fc12)

# Conflicts:
#	x/wasm/keeper/handler_plugin.go

* Fix merge conflict

---------

Co-authored-by: pinosu <95283998+pinosu@users.noreply.github.com>
Co-authored-by: Alex Peters <alpe@users.noreply.github.com>

* Test rust panic for regression

(cherry picked from commit a52e604966)

* Fix client checksum verification (#1234)

* Fix client checksum verification

* Review comments

(cherry picked from commit 1a8019b380)

# Conflicts:
#	x/wasm/client/cli/gov_tx.go

* Fix merge conflict

* Fix linters

* Configure sonarcloud analysis

(cherry picked from commit 85cf1614fb)

* Bump bufbuild/buf-setup-action from 1.15.0 to 1.15.1

Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.15.0 to 1.15.1.
- [Release notes](https://github.com/bufbuild/buf-setup-action/releases)
- [Commits](https://github.com/bufbuild/buf-setup-action/compare/v1.15.0...v1.15.1)

---
updated-dependencies:
- dependency-name: bufbuild/buf-setup-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
(cherry picked from commit 730ea5a1cf)

* Make `CaptureIbcEvents` in ibctesting public.

Before this change, it wasn't possible to implement the
`chain.SendMsgs` method without
[copying](https://github.com/public-awesome/ics721/blob/main/e2e/suite_helpers.go#L81-L98)
them over.

(cherry picked from commit b64fa078a3)

* Upgrade to wasmvm 1.2.1 (backport #1245) (#1254)

* Upgrade to wasmvm 1.2.1 (#1245)

* Use wasmvm store adapter

* Bump wasmvm to v1.2.1

(cherry picked from commit 850f901b2e)

# Conflicts:
#	go.mod
#	go.sum
#	x/wasm/keeper/keeper.go

* Resolve conflicts

---------

Co-authored-by: Alexander Peters <alpe@users.noreply.github.com>

* WIP All cometbft (#1244)

* Dep upgrade; use CometBft

* Remove duplicte message events

* Add changelog for v0.31.0 (#1188)

* Start changelog for v0.31.0

* Add ICA upgrade

* Add proto version link to buf.build

* Update changelog (#1239)

* Update changelog

* Update changelog with latest changes

* Set release date

---------

Co-authored-by: pinosu <95283998+pinosu@users.noreply.github.com>
(cherry picked from commit bc0e817912)

* Remove new message type event

* Support msg update params gov proposal (#1247)

* Add MsgUpdateParams support

* Implement UpdateParams msg

* Fix test UpdateParams

* Add migration test

* Fix

* Fix lint issues

* Revert changes according to review feedback

* Remove more x/params dependencies

* Remove x/params from genesis test

* Formatting

* Restore old changes

* fix lint

* Fix tests and restructure migrations

* Rename alias for convention

---------

Co-authored-by: Alex Peters <alpe@users.noreply.github.com>

* Fix test data generator (#1263)

* linting 47 pr (#1261)

* lint cosmwasm for sdk 47

* fix

* remove setGenesis

* remove additional unused functions

* pass tests

* use SDK's errors module

* unecessary conversions

* unnecessary conversions

* remove unneeded event manager

* complete linting of tests for 47

* add test for reimportation

* check errors

* Update x/wasm/keeper/proposal_integration_test.go

Co-authored-by: Alexander Peters <alpe@users.noreply.github.com>

* apply suggestion

* suggestions

* lints

* don't return error in when making new transactions

* no todo's in the code

* Fix test data generator

* Update x/wasm/types/genesis_test.go

Co-authored-by: Alexander Peters <alpe@users.noreply.github.com>

* use the full string invalid address (2 words) always

---------

Co-authored-by: Alexander Peters <alpe@users.noreply.github.com>

* Regenerate from proto; remove dead code; polish code

* Set SDK version to v0.47x.0 (#1262)

* Set SDK version to v0.47x.0

* Set chainID

* Minor updates

* Set chainID for simulations

* Buf mod update

* Use sdk tag instead of hash in buf

* Bump ibc-go to v7.0.0

* faddat/re merge main (#1274)

undefined

---------

Co-authored-by: vuong <nguyenvuong1122000@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: llllllluc <58892938+llllllluc@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Gjermund Garaba <gjermund@garaba.net>
Co-authored-by: Nikhil Suri <nikhilsuri@comcast.net>
Co-authored-by: Paul <p22626262@gmail.com>
Co-authored-by: pinosu <95283998+pinosu@users.noreply.github.com>
Co-authored-by: ekez <zekemedley@gmail.com>
Co-authored-by: Jacob Gadikian <jacobgadikian@gmail.com>
This commit is contained in:
Alexander Peters
2023-03-20 10:32:22 +01:00
committed by GitHub
parent bc0e817912
commit 7e936c7fff
153 changed files with 5721 additions and 6390 deletions

135
tests/e2e/gov_test.go Normal file
View File

@@ -0,0 +1,135 @@
package e2e_test
import (
"testing"
"time"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdk "github.com/cosmos/cosmos-sdk/types"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/CosmWasm/wasmd/tests/e2e"
"github.com/CosmWasm/wasmd/x/wasm/ibctesting"
)
func TestGovVoteByContract(t *testing.T) {
// Given a contract with delegation
// And a gov proposal
// 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)
chain.Fund(contractAddr, sdk.NewIntFromUint64(1_000_000_000))
// a contract with a high delegation amount
delegateMsg := wasmvmtypes.CosmosMsg{
Staking: &wasmvmtypes.StakingMsg{
Delegate: &wasmvmtypes.DelegateMsg{
Validator: sdk.ValAddress(chain.Vals.Validators[0].Address).String(),
Amount: wasmvmtypes.Coin{
Denom: sdk.DefaultBondDenom,
Amount: "1000000000",
},
},
},
}
e2e.MustExecViaReflectContract(t, chain, contractAddr, delegateMsg)
signer := chain.SenderAccount.GetAddress().String()
govKeeper, accountKeeper := chain.App.GovKeeper, chain.App.AccountKeeper
communityPoolBalance := chain.Balance(accountKeeper.GetModuleAccount(chain.GetContext(), distributiontypes.ModuleName).GetAddress(), sdk.DefaultBondDenom)
require.False(t, communityPoolBalance.IsZero())
initialDeposit := govKeeper.GetParams(chain.GetContext()).MinDeposit
govAcctAddr := govKeeper.GetGovernanceAccount(chain.GetContext()).GetAddress()
specs := map[string]struct {
vote *wasmvmtypes.VoteMsg
expPass bool
}{
"yes": {
vote: &wasmvmtypes.VoteMsg{
Vote: wasmvmtypes.Yes,
},
expPass: true,
},
"no": {
vote: &wasmvmtypes.VoteMsg{
Vote: wasmvmtypes.No,
},
expPass: false,
},
"abstain": {
vote: &wasmvmtypes.VoteMsg{
Vote: wasmvmtypes.Abstain,
},
expPass: true,
},
"no with veto": {
vote: &wasmvmtypes.VoteMsg{
Vote: wasmvmtypes.NoWithVeto,
},
expPass: false,
},
}
for name, spec := range specs {
t.Run(name, func(t *testing.T) {
// given a unique recipient
recipientAddr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address().Bytes())
// and a new proposal
payloadMsg := &distributiontypes.MsgCommunityPoolSpend{
Authority: govAcctAddr.String(),
Recipient: recipientAddr.String(),
Amount: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.OneInt())),
}
msg, err := v1.NewMsgSubmitProposal(
[]sdk.Msg{payloadMsg},
initialDeposit,
signer,
"",
"my proposal",
"testing",
)
require.NoError(t, err)
rsp, gotErr := chain.SendMsgs(msg)
require.NoError(t, gotErr)
require.Len(t, rsp.MsgResponses, 1)
got, ok := rsp.MsgResponses[0].GetCachedValue().(*v1.MsgSubmitProposalResponse)
require.True(t, ok)
propID := got.ProposalId
// with other delegators voted yes
_, err = chain.SendMsgs(v1.NewMsgVote(chain.SenderAccount.GetAddress(), propID, v1.VoteOption_VOTE_OPTION_YES, ""))
require.NoError(t, err)
// when contract votes
spec.vote.ProposalId = propID
voteMsg := wasmvmtypes.CosmosMsg{
Gov: &wasmvmtypes.GovMsg{
Vote: spec.vote,
},
}
e2e.MustExecViaReflectContract(t, chain, contractAddr, voteMsg)
// then proposal executed after voting period
proposal, ok := govKeeper.GetProposal(chain.GetContext(), propID)
require.True(t, ok)
coord.IncrementTimeBy(proposal.VotingEndTime.Sub(chain.GetContext().BlockTime()) + time.Minute)
coord.CommitBlock(chain)
// and recipient balance updated
recipientBalance := chain.Balance(recipientAddr, sdk.DefaultBondDenom)
if !spec.expPass {
assert.True(t, recipientBalance.IsZero())
return
}
expBalanceAmount := sdk.NewCoin(sdk.DefaultBondDenom, sdk.OneInt())
assert.Equal(t, expBalanceAmount.String(), recipientBalance.String())
})
}
}

View File

@@ -5,6 +5,7 @@ import (
"testing"
"time"
errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -13,6 +14,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/CosmWasm/wasmd/tests/e2e"
"github.com/CosmWasm/wasmd/x/wasm/ibctesting"
"github.com/CosmWasm/wasmd/x/wasm/types"
)
@@ -26,9 +28,9 @@ func TestGrants(t *testing.T) {
// - balance A reduced (on success)
// - balance B not touched
chain := ibctesting.NewCoordinator(t, 1).GetChain(ibctesting.GetChainID(0))
codeID := chain.StoreCodeFile("../../x/wasm/keeper/testdata/reflect_1_1.wasm").CodeID
contractAddr := chain.InstantiateContract(codeID, []byte(`{}`))
coord := ibctesting.NewCoordinator(t, 1)
chain := coord.GetChain(ibctesting.GetChainID(1))
contractAddr := e2e.InstantiateReflectContract(t, chain)
require.NotEmpty(t, contractAddr)
granterAddr := chain.SenderAccount.GetAddress()
@@ -48,7 +50,7 @@ func TestGrants(t *testing.T) {
filter types.ContractAuthzFilterX
transferAmount sdk.Coin
senderKey cryptotypes.PrivKey
expErr *sdkerrors.Error
expErr *errorsmod.Error
}{
"in limits and filter": {
limit: types.NewMaxFundsLimit(myAmount),
@@ -75,7 +77,7 @@ func TestGrants(t *testing.T) {
filter: types.NewAllowAllMessagesFilter(),
senderKey: otherPrivKey,
transferAmount: myAmount,
expErr: sdkerrors.ErrUnauthorized,
expErr: authz.ErrNoAuthorizationFound,
},
}
for name, spec := range specs {
@@ -84,7 +86,8 @@ func TestGrants(t *testing.T) {
grant, err := types.NewContractGrant(contractAddr, spec.limit, spec.filter)
require.NoError(t, err)
authorization := types.NewContractExecutionAuthorization(*grant)
grantMsg, err := authz.NewMsgGrant(granterAddr, granteeAddr, authorization, time.Now().Add(time.Hour))
expiry := time.Now().Add(time.Hour)
grantMsg, err := authz.NewMsgGrant(granterAddr, granteeAddr, authorization, &expiry)
require.NoError(t, err)
_, err = chain.SendMsgs(grantMsg)
require.NoError(t, err)
@@ -103,7 +106,7 @@ func TestGrants(t *testing.T) {
// then
if spec.expErr != nil {
require.ErrorIs(t, gotErr, spec.expErr)
require.True(t, spec.expErr.Is(gotErr))
assert.Equal(t, sdk.NewInt(1_000_000), chain.Balance(granteeAddr, sdk.DefaultBondDenom).Amount)
assert.Equal(t, granterStartBalance, chain.Balance(granterAddr, sdk.DefaultBondDenom).Amount)
return

71
tests/e2e/group_test.go Normal file
View File

@@ -0,0 +1,71 @@
package e2e_test
import (
"testing"
"time"
"github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cometbft/cometbft/libs/rand"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/group"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/CosmWasm/wasmd/tests/e2e"
"github.com/CosmWasm/wasmd/x/wasm/ibctesting"
)
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.InstantiateReflectContract(t, chain)
chain.Fund(contractAddr, sdk.NewIntFromUint64(1_000_000_000))
members := []group.MemberRequest{
{
Address: contractAddr.String(),
Weight: "1",
Metadata: "my contract",
},
}
msg, err := group.NewMsgCreateGroupWithPolicy(
chain.SenderAccount.GetAddress().String(),
members,
"my group",
"my metadata",
false,
group.NewPercentageDecisionPolicy("1", time.Second, 0),
)
require.NoError(t, err)
rsp, err := chain.SendMsgs(msg)
require.NoError(t, err)
createRsp := rsp.MsgResponses[0].GetCachedValue().(*group.MsgCreateGroupWithPolicyResponse)
groupID, policyAddr := createRsp.GroupId, sdk.MustAccAddressFromBech32(createRsp.GroupPolicyAddress)
require.NotEmpty(t, groupID)
chain.Fund(policyAddr, sdk.NewIntFromUint64(1_000_000_000))
// and a proposal submitted
recipientAddr := sdk.AccAddress(rand.Bytes(address.Len))
payload := []sdk.Msg{banktypes.NewMsgSend(policyAddr, recipientAddr, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.OneInt())))}
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)
bz := rsp.MsgResponses[0].GetCachedValue().(*types.MsgExecuteContractResponse).Data
var groupRsp group.MsgSubmitProposalResponse
require.NoError(t, chain.Codec.Unmarshal(bz, &groupRsp))
// require.NotEmpty(t, groupRsp.ProposalId)
// and coins received
recipientBalance := chain.Balance(recipientAddr, sdk.DefaultBondDenom)
expBalanceAmount := sdk.NewCoin(sdk.DefaultBondDenom, sdk.OneInt())
assert.Equal(t, expBalanceAmount.String(), recipientBalance.String())
}

View File

@@ -9,11 +9,11 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
ibcfee "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/types"
ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types"
ibctesting "github.com/cosmos/ibc-go/v4/testing"
ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -30,8 +30,8 @@ func TestIBCFeesTransfer(t *testing.T) {
// then the relayer's payee is receiving the fee(s) on success
marshaler := app.MakeEncodingConfig().Marshaler
coord := wasmibctesting.NewCoordinator(t, 2)
chainA := coord.GetChain(ibctesting.GetChainID(0))
chainB := coord.GetChain(ibctesting.GetChainID(1))
chainA := coord.GetChain(wasmibctesting.GetChainID(1))
chainB := coord.GetChain(wasmibctesting.GetChainID(2))
actorChainA := sdk.AccAddress(chainA.SenderPrivKey.PubKey().Address())
actorChainB := sdk.AccAddress(chainB.SenderPrivKey.PubKey().Address())
@@ -61,7 +61,7 @@ func TestIBCFeesTransfer(t *testing.T) {
// when a transfer package is sent
transferCoin := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1))
ibcPayloadMsg := ibctransfertypes.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, transferCoin, actorChainA.String(), receiver.String(), clienttypes.Height{}, uint64(time.Now().Add(time.Minute).UnixNano()))
ibcPayloadMsg := ibctransfertypes.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, transferCoin, actorChainA.String(), receiver.String(), clienttypes.Height{}, uint64(time.Now().Add(time.Minute).UnixNano()), "testing")
ibcPackageFee := ibcfee.NewFee(oneToken, oneToken, sdk.Coins{})
feeMsg := ibcfee.NewMsgPayPacketFee(ibcPackageFee, ibctransfertypes.PortID, path.EndpointA.ChannelID, actorChainA.String(), nil)
_, err = chainA.SendMsgs(feeMsg, ibcPayloadMsg)
@@ -86,7 +86,7 @@ func TestIBCFeesTransfer(t *testing.T) {
require.NoError(t, err)
// and transfer from B to A
ibcPayloadMsg = ibctransfertypes.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, transferCoin, actorChainB.String(), receiver.String(), clienttypes.Height{}, uint64(time.Now().Add(time.Minute).UnixNano()))
ibcPayloadMsg = ibctransfertypes.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, transferCoin, actorChainB.String(), receiver.String(), clienttypes.Height{}, uint64(time.Now().Add(time.Minute).UnixNano()), "more testing")
ibcPackageFee = ibcfee.NewFee(oneToken, oneToken, sdk.Coins{})
feeMsg = ibcfee.NewMsgPayPacketFee(ibcPackageFee, ibctransfertypes.PortID, path.EndpointB.ChannelID, actorChainB.String(), nil)
_, err = chainB.SendMsgs(feeMsg, ibcPayloadMsg)
@@ -113,8 +113,8 @@ func TestIBCFeesWasm(t *testing.T) {
// then the relayer's payee is receiving the fee(s) on success
marshaler := app.MakeEncodingConfig().Marshaler
coord := wasmibctesting.NewCoordinator(t, 2)
chainA := coord.GetChain(ibctesting.GetChainID(0))
chainB := coord.GetChain(ibctesting.GetChainID(1))
chainA := coord.GetChain(wasmibctesting.GetChainID(1))
chainB := coord.GetChain(ibctesting.GetChainID(2))
actorChainA := sdk.AccAddress(chainA.SenderPrivKey.PubKey().Address())
actorChainB := sdk.AccAddress(chainB.SenderPrivKey.PubKey().Address())
@@ -192,7 +192,7 @@ func TestIBCFeesWasm(t *testing.T) {
require.NoError(t, err)
// and when sent back from chain B to A
ibcPayloadMsg := ibctransfertypes.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, gotBalance, actorChainB.String(), actorChainA.String(), clienttypes.Height{}, uint64(time.Now().Add(time.Minute).UnixNano()))
ibcPayloadMsg := ibctransfertypes.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, gotBalance, actorChainB.String(), actorChainA.String(), clienttypes.Height{}, uint64(time.Now().Add(time.Minute).UnixNano()), "even more tests")
ibcPackageFee = ibcfee.NewFee(oneToken, oneToken, sdk.Coins{})
feeMsg = ibcfee.NewMsgPayPacketFee(ibcPackageFee, ibctransfertypes.PortID, path.EndpointB.ChannelID, actorChainB.String(), nil)
_, err = chainB.SendMsgs(feeMsg, ibcPayloadMsg)

View File

@@ -3,15 +3,17 @@ package e2e
import (
"bytes"
"testing"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
hosttypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types"
ibctesting "github.com/cosmos/ibc-go/v4/testing"
intertxtypes "github.com/cosmos/interchain-accounts/x/inter-tx/types"
"github.com/cosmos/gogoproto/proto"
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
hosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -26,18 +28,19 @@ func TestICA(t *testing.T) {
// 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(0))
hostChain := coord.GetChain(ibctesting.GetChainID(1))
hostParams := hosttypes.NewParams(true, []string{sdk.MsgTypeURL(&banktypes.MsgSend{})})
hostChain.App.ICAHostKeeper.SetParams(hostChain.GetContext(), hostParams)
controllerChain := coord.GetChain(ibctesting.GetChainID(1))
controllerChain := coord.GetChain(ibctesting.GetChainID(2))
path := wasmibctesting.NewPath(controllerChain, hostChain)
coord.SetupConnections(path)
ownerAddr := sdk.AccAddress(controllerChain.SenderPrivKey.PubKey().Address())
msg := intertxtypes.NewMsgRegisterAccount(ownerAddr.String(), path.EndpointA.ConnectionID, "")
msg := icacontrollertypes.NewMsgRegisterInterchainAccount(path.EndpointA.ConnectionID, ownerAddr.String(), "")
res, err := controllerChain.SendMsgs(msg)
require.NoError(t, err)
chanID, portID, version := parseIBCChannelEvents(t, res)
// next open channels on both sides
@@ -48,28 +51,35 @@ func TestICA(t *testing.T) {
Order: channeltypes.ORDERED,
}
path.EndpointB.ChannelConfig = &ibctesting.ChannelConfig{
PortID: icatypes.PortID,
PortID: icatypes.HostPortID,
Version: icatypes.Version,
Order: channeltypes.ORDERED,
}
coord.CreateChannels(path)
// assert ICA exists on controller
icaRsp, err := controllerChain.App.InterTxKeeper.InterchainAccount(sdk.WrapSDKContext(controllerChain.GetContext()), &intertxtypes.QueryInterchainAccountRequest{
icaRsp, err := controllerChain.App.ICAControllerKeeper.InterchainAccount(sdk.WrapSDKContext(controllerChain.GetContext()), &icacontrollertypes.QueryInterchainAccountRequest{
Owner: ownerAddr.String(),
ConnectionId: path.EndpointA.ConnectionID,
})
require.NoError(t, err)
icaAddr := sdk.MustAccAddressFromBech32(icaRsp.InterchainAccountAddress)
icaAddr := sdk.MustAccAddressFromBech32(icaRsp.GetAddress())
hostChain.Fund(icaAddr, sdk.NewInt(1_000))
// submit a tx
targetAddr := sdk.AccAddress(bytes.Repeat([]byte{1}, address.Len))
sendCoin := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))
payloadMsg := banktypes.NewMsgSend(icaAddr, targetAddr, sdk.NewCoins(sendCoin))
msg2, err := intertxtypes.NewMsgSubmitTx(payloadMsg, path.EndpointA.ConnectionID, ownerAddr.String())
rawPayloadData, err := icatypes.SerializeCosmosTx(controllerChain.Codec, []proto.Message{payloadMsg})
require.NoError(t, err)
res, err = controllerChain.SendMsgs(msg2)
payloadPacket := icatypes.InterchainAccountPacketData{
Type: icatypes.EXECUTE_TX,
Data: rawPayloadData,
Memo: "testing",
}
relativeTimeout := uint64(time.Minute.Nanoseconds()) // note this is in nanoseconds
msgSendTx := icacontrollertypes.NewMsgSendTx(ownerAddr.String(), path.EndpointA.ConnectionID, relativeTimeout, payloadPacket)
_, err = controllerChain.SendMsgs(msgSendTx)
require.NoError(t, err)
assert.Equal(t, 1, len(controllerChain.PendingSendPackets))

View File

@@ -0,0 +1,68 @@
package e2e
import (
"encoding/json"
"testing"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"github.com/CosmWasm/wasmd/x/wasm/ibctesting"
"github.com/CosmWasm/wasmd/x/wasm/keeper/testdata"
"github.com/CosmWasm/wasmd/x/wasm/types"
)
// InstantiateReflectContract store and instantiate a reflect contract instance
func InstantiateReflectContract(t *testing.T, chain *ibctesting.TestChain) sdk.AccAddress {
codeID := chain.StoreCodeFile("../../x/wasm/keeper/testdata/reflect_1_1.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) *sdk.Result {
rsp, err := ExecViaReflectContract(t, chain, contractAddr, msgs)
require.NoError(t, err)
return rsp
}
type sdkMessageType interface {
codec.ProtoMarshaler
sdk.Msg
}
func MustExecViaStargateReflectContract[T sdkMessageType](t *testing.T, chain *ibctesting.TestChain, contractAddr sdk.AccAddress, msgs ...T) *sdk.Result {
vmMsgs := make([]wasmvmtypes.CosmosMsg, len(msgs))
for i, m := range msgs {
bz, err := chain.Codec.Marshal(m)
require.NoError(t, err)
vmMsgs[i] = wasmvmtypes.CosmosMsg{
Stargate: &wasmvmtypes.StargateMsg{
TypeURL: sdk.MsgTypeURL(m),
Value: bz,
},
}
}
rsp, err := ExecViaReflectContract(t, chain, contractAddr, vmMsgs)
require.NoError(t, err)
return rsp
}
// ExecViaReflectContract submit execute message to send payload to reflect contract
func ExecViaReflectContract(t *testing.T, chain *ibctesting.TestChain, contractAddr sdk.AccAddress, msgs []wasmvmtypes.CosmosMsg) (*sdk.Result, error) {
require.NotEmpty(t, msgs)
reflectSend := testdata.ReflectHandleMsg{
Reflect: &testdata.ReflectPayload{Msgs: msgs},
}
reflectSendBz, err := json.Marshal(reflectSend)
require.NoError(t, err)
execMsg := &types.MsgExecuteContract{
Sender: chain.SenderAccount.GetAddress().String(),
Contract: contractAddr.String(),
Msg: reflectSendBz,
}
return chain.SendMsgs(execMsg)
}