Add updates to ibctesting framework for MS (#1472)
* Add message fees * Init slashing module for tests * Capture endblock ibc events and other ibctesting updates
This commit is contained in:
@@ -38,6 +38,7 @@ import (
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@@ -168,14 +169,28 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
|
||||
)
|
||||
// commit genesis changes
|
||||
app.Commit()
|
||||
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{
|
||||
ChainID: chainID,
|
||||
Height: app.LastBlockHeight() + 1,
|
||||
AppHash: app.LastCommitID().Hash,
|
||||
Time: time.Now().UTC(),
|
||||
ValidatorsHash: valSet.Hash(),
|
||||
NextValidatorsHash: valSet.Hash(),
|
||||
}})
|
||||
|
||||
votes := make([]abci.VoteInfo, len(valSet.Validators))
|
||||
for i, v := range valSet.Validators {
|
||||
votes[i] = abci.VoteInfo{
|
||||
Validator: abci.Validator{Address: v.Address, Power: v.VotingPower},
|
||||
SignedLastBlock: true,
|
||||
}
|
||||
}
|
||||
|
||||
app.BeginBlock(abci.RequestBeginBlock{
|
||||
Header: tmproto.Header{
|
||||
ChainID: chainID,
|
||||
Height: app.LastBlockHeight() + 1,
|
||||
AppHash: app.LastCommitID().Hash,
|
||||
Time: time.Now().UTC(),
|
||||
ValidatorsHash: valSet.Hash(),
|
||||
NextValidatorsHash: valSet.Hash(),
|
||||
},
|
||||
LastCommitInfo: abci.CommitInfo{
|
||||
Votes: votes,
|
||||
},
|
||||
})
|
||||
|
||||
return app
|
||||
}
|
||||
@@ -289,14 +304,14 @@ func NewTestNetworkFixture() network.TestFixture {
|
||||
|
||||
// SignAndDeliverWithoutCommit signs and delivers a transaction. No commit
|
||||
func SignAndDeliverWithoutCommit(
|
||||
t *testing.T, txCfg client.TxConfig, app *bam.BaseApp, header tmproto.Header, msgs []sdk.Msg,
|
||||
t *testing.T, txCfg client.TxConfig, app *bam.BaseApp, msgs []sdk.Msg, fees sdk.Coins,
|
||||
chainID string, accNums, accSeqs []uint64, priv ...cryptotypes.PrivKey,
|
||||
) (sdk.GasInfo, *sdk.Result, error) {
|
||||
tx, err := simtestutil.GenSignedMockTx(
|
||||
rand.New(rand.NewSource(time.Now().UnixNano())),
|
||||
txCfg,
|
||||
msgs,
|
||||
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)},
|
||||
fees,
|
||||
simtestutil.DefaultGenTxGas,
|
||||
chainID,
|
||||
accNums,
|
||||
@@ -364,6 +379,16 @@ func GenesisStateWithValSet(
|
||||
stakingGenesis := stakingtypes.NewGenesisState(stakingtypes.DefaultParams(), validators, delegations)
|
||||
genesisState[stakingtypes.ModuleName] = codec.MustMarshalJSON(stakingGenesis)
|
||||
|
||||
signingInfos := make([]slashingtypes.SigningInfo, len(valSet.Validators))
|
||||
for i, val := range valSet.Validators {
|
||||
signingInfos[i] = slashingtypes.SigningInfo{
|
||||
Address: sdk.ConsAddress(val.Address).String(),
|
||||
ValidatorSigningInfo: slashingtypes.ValidatorSigningInfo{},
|
||||
}
|
||||
}
|
||||
slashingGenesis := slashingtypes.NewGenesisState(slashingtypes.DefaultParams(), signingInfos, nil)
|
||||
genesisState[slashingtypes.ModuleName] = codec.MustMarshalJSON(slashingGenesis)
|
||||
|
||||
// add bonded amount to bonded pool module account
|
||||
balances = append(balances, banktypes.Balance{
|
||||
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
|
||||
|
||||
@@ -5,35 +5,29 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
||||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
||||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"cosmossdk.io/math"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
|
||||
"github.com/CosmWasm/wasmd/app"
|
||||
"github.com/CosmWasm/wasmd/x/wasm"
|
||||
|
||||
// simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
"github.com/cometbft/cometbft/crypto/tmhash"
|
||||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
tmprotoversion "github.com/cometbft/cometbft/proto/tendermint/version"
|
||||
tmtypes "github.com/cometbft/cometbft/types"
|
||||
tmversion "github.com/cometbft/cometbft/version"
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
|
||||
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/testutil"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
|
||||
@@ -41,11 +35,15 @@ import (
|
||||
commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types"
|
||||
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
|
||||
"github.com/cosmos/ibc-go/v7/modules/core/exported"
|
||||
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
|
||||
"github.com/cosmos/ibc-go/v7/modules/core/types"
|
||||
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
|
||||
ibctesting "github.com/cosmos/ibc-go/v7/testing"
|
||||
"github.com/cosmos/ibc-go/v7/testing/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/CosmWasm/wasmd/app"
|
||||
"github.com/CosmWasm/wasmd/x/wasm"
|
||||
)
|
||||
|
||||
var MaxAccounts = 10
|
||||
@@ -106,6 +104,7 @@ type TestChain struct {
|
||||
SenderAccounts []SenderAccount
|
||||
|
||||
PendingSendPackets []channeltypes.Packet
|
||||
DefaultMsgFees sdk.Coins
|
||||
}
|
||||
|
||||
type PacketAck struct {
|
||||
@@ -224,6 +223,7 @@ func NewTestChainWithValSet(t *testing.T, coord *Coordinator, appFactory ChainAp
|
||||
SenderPrivKey: senderAccs[0].SenderPrivKey,
|
||||
SenderAccount: senderAccs[0].SenderAccount,
|
||||
SenderAccounts: senderAccs,
|
||||
DefaultMsgFees: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.ZeroInt())),
|
||||
}
|
||||
|
||||
coord.CommitBlock(chain)
|
||||
@@ -315,10 +315,10 @@ func (chain *TestChain) QueryConsensusStateProof(clientID string) ([]byte, clien
|
||||
// of the next block being created. This follows the Tendermint protocol of applying valset changes
|
||||
// returned on block `n` to the validators of block `n+2`.
|
||||
// It calls BeginBlock with the new block created before returning.
|
||||
func (chain *TestChain) NextBlock() {
|
||||
func (chain *TestChain) NextBlock() abci.ResponseEndBlock {
|
||||
res := chain.App.EndBlock(abci.RequestEndBlock{Height: chain.CurrentHeader.Height})
|
||||
|
||||
chain.App.Commit()
|
||||
chain.CaptureIBCEvents(res.Events)
|
||||
|
||||
// set the last header to the current header
|
||||
// use nil trusted fields
|
||||
@@ -342,7 +342,20 @@ func (chain *TestChain) NextBlock() {
|
||||
ProposerAddress: chain.CurrentHeader.ProposerAddress,
|
||||
}
|
||||
|
||||
chain.App.BeginBlock(abci.RequestBeginBlock{Header: chain.CurrentHeader})
|
||||
votes := make([]abci.VoteInfo, len(chain.Vals.Validators))
|
||||
for i, v := range chain.Vals.Validators {
|
||||
votes[i] = abci.VoteInfo{
|
||||
Validator: abci.Validator{Address: v.Address, Power: v.VotingPower},
|
||||
SignedLastBlock: true,
|
||||
}
|
||||
}
|
||||
chain.App.BeginBlock(abci.RequestBeginBlock{
|
||||
Header: chain.CurrentHeader,
|
||||
LastCommitInfo: abci.CommitInfo{
|
||||
Votes: votes,
|
||||
},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
// sendMsgs delivers a transaction through the application without returning the result.
|
||||
@@ -357,13 +370,12 @@ func (chain *TestChain) sendMsgs(msgs ...sdk.Msg) error {
|
||||
func (chain *TestChain) SendMsgs(msgs ...sdk.Msg) (*sdk.Result, error) {
|
||||
// ensure the chain has the latest time
|
||||
chain.Coordinator.UpdateTimeForChain(chain)
|
||||
|
||||
_, r, gotErr := app.SignAndDeliverWithoutCommit(
|
||||
chain.t,
|
||||
chain.TxConfig,
|
||||
chain.App.GetBaseApp(),
|
||||
chain.GetContext().BlockHeader(),
|
||||
msgs,
|
||||
chain.DefaultMsgFees,
|
||||
chain.ChainID,
|
||||
[]uint64{chain.SenderAccount.GetAccountNumber()},
|
||||
[]uint64{chain.SenderAccount.GetSequence()},
|
||||
@@ -381,13 +393,13 @@ func (chain *TestChain) SendMsgs(msgs ...sdk.Msg) (*sdk.Result, error) {
|
||||
return nil, gotErr
|
||||
}
|
||||
|
||||
chain.CaptureIBCEvents(r)
|
||||
chain.CaptureIBCEvents(r.Events)
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (chain *TestChain) CaptureIBCEvents(r *sdk.Result) {
|
||||
toSend := GetSendPackets(r.Events)
|
||||
func (chain *TestChain) CaptureIBCEvents(evts []abci.Event) {
|
||||
toSend := GetSendPackets(evts)
|
||||
if len(toSend) > 0 {
|
||||
// Keep a queue on the chain that we can relay in tests
|
||||
chain.PendingSendPackets = append(chain.PendingSendPackets, toSend...)
|
||||
|
||||
@@ -201,7 +201,6 @@ func (coord *Coordinator) CommitBlock(chains ...*TestChain) {
|
||||
// CommitNBlocks commits n blocks to state and updates the block height by 1 for each commit.
|
||||
func (coord *Coordinator) CommitNBlocks(chain *TestChain, n uint64) {
|
||||
for i := uint64(0); i < n; i++ {
|
||||
chain.App.BeginBlock(abci.RequestBeginBlock{Header: chain.CurrentHeader})
|
||||
chain.NextBlock()
|
||||
coord.IncrementTime()
|
||||
}
|
||||
@@ -254,6 +253,7 @@ func (coord *Coordinator) ChanOpenInitOnBothChains(path *Path) error {
|
||||
func (coord *Coordinator) RelayAndAckPendingPackets(path *Path) error {
|
||||
// get all the packet to relay src->dest
|
||||
src := path.EndpointA
|
||||
require.NoError(coord.t, src.UpdateClient())
|
||||
coord.t.Logf("Relay: %d Packets A->B, %d Packets B->A\n", len(src.Chain.PendingSendPackets), len(path.EndpointB.Chain.PendingSendPackets))
|
||||
for i, v := range src.Chain.PendingSendPackets {
|
||||
err := path.RelayPacket(v, nil)
|
||||
@@ -264,6 +264,7 @@ func (coord *Coordinator) RelayAndAckPendingPackets(path *Path) error {
|
||||
}
|
||||
|
||||
src = path.EndpointB
|
||||
require.NoError(coord.t, src.UpdateClient())
|
||||
for i, v := range src.Chain.PendingSendPackets {
|
||||
err := path.RelayPacket(v, nil)
|
||||
if err != nil {
|
||||
@@ -275,17 +276,15 @@ func (coord *Coordinator) RelayAndAckPendingPackets(path *Path) error {
|
||||
}
|
||||
|
||||
// TimeoutPendingPackets returns the package to source chain to let the IBC app revert any operation.
|
||||
// from A to A
|
||||
// from A to B
|
||||
func (coord *Coordinator) TimeoutPendingPackets(path *Path) error {
|
||||
src := path.EndpointA
|
||||
dest := path.EndpointB
|
||||
|
||||
toSend := src.Chain.PendingSendPackets
|
||||
coord.t.Logf("Timeout %d Packets A->A\n", len(toSend))
|
||||
coord.t.Logf("Timeout %d Packets A->B\n", len(toSend))
|
||||
require.NoError(coord.t, src.UpdateClient())
|
||||
|
||||
if err := src.UpdateClient(); err != nil {
|
||||
return err
|
||||
}
|
||||
// Increment time and commit block so that 5 second delay period passes between send and receive
|
||||
coord.IncrementTime()
|
||||
coord.CommitBlock(src.Chain, dest.Chain)
|
||||
|
||||
@@ -34,8 +34,8 @@ func (chain *TestChain) SendNonDefaultSenderMsgs(senderPrivKey cryptotypes.PrivK
|
||||
chain.t,
|
||||
chain.TxConfig,
|
||||
chain.App.GetBaseApp(),
|
||||
chain.GetContext().BlockHeader(),
|
||||
msgs,
|
||||
chain.DefaultMsgFees,
|
||||
chain.ChainID,
|
||||
[]uint64{account.GetAccountNumber()},
|
||||
[]uint64{account.GetSequence()},
|
||||
@@ -48,6 +48,6 @@ func (chain *TestChain) SendNonDefaultSenderMsgs(senderPrivKey cryptotypes.PrivK
|
||||
if err != nil {
|
||||
return r, err
|
||||
}
|
||||
chain.CaptureIBCEvents(r)
|
||||
chain.CaptureIBCEvents(r.Events)
|
||||
return r, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user