github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/wasm/ibctesting/chain.go (about)

     1  package ibctesting
     2  
     3  //import (
     4  //	"bytes"
     5  //	"fmt"
     6  //	"testing"
     7  //	"time"
     8  //
     9  //	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/baseapp"
    10  //	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client"
    11  //	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec"
    12  //	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/crypto/keys/secp256k1"
    13  //	cryptotypes "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/crypto/types"
    14  //	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
    15  //	sdkerrors "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/errors"
    16  //	authtypes "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/auth/types"
    17  //	banktypes "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/bank/types"
    18  //	capabilitykeeper "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/capability/keeper"
    19  //	capabilitytypes "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/capability/types"
    20  //	stakingkeeper "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/staking/keeper"
    21  //	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/staking/teststaking"
    22  //	stakingtypes "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/staking/types"
    23  //	clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
    24  //	channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
    25  //	commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types"
    26  //	host "github.com/cosmos/ibc-go/v3/modules/core/24-host"
    27  //	"github.com/cosmos/ibc-go/v3/modules/core/exported"
    28  //	ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
    29  //	"github.com/cosmos/ibc-go/v3/modules/core/types"
    30  //	ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types"
    31  //	ibctesting "github.com/cosmos/ibc-go/v3/testing"
    32  //	"github.com/cosmos/ibc-go/v3/testing/mock"
    33  //	"github.com/stretchr/testify/require"
    34  //	abci "github.com/tendermint/tendermint/abci/types"
    35  //	"github.com/tendermint/tendermint/crypto/tmhash"
    36  //	tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
    37  //	tmprotoversion "github.com/tendermint/tendermint/proto/tendermint/version"
    38  //	tmtypes "github.com/tendermint/tendermint/types"
    39  //	tmversion "github.com/tendermint/tendermint/version"
    40  //
    41  //	wasmd "github.com/fibonacci-chain/fbc/app"
    42  //	"github.com/fibonacci-chain/fbc/x/wasm"
    43  //)
    44  //
    45  //// TestChain is a testing struct that wraps a simapp with the last TM Header, the current ABCI
    46  //// header and the validators of the TestChain. It also contains a field called ChainID. This
    47  //// is the clientID that *other* chains use to refer to this TestChain. The SenderAccount
    48  //// is used for delivering transactions through the application state.
    49  //// NOTE: the actual application uses an empty chain-id for ease of testing.
    50  //type TestChain struct {
    51  //	t *testing.T
    52  //
    53  //	Coordinator   *Coordinator
    54  //	App           ibctesting.TestingApp
    55  //	ChainID       string
    56  //	LastHeader    *ibctmtypes.Header // header for last block height committed
    57  //	CurrentHeader tmproto.Header     // header for current block height
    58  //	QueryServer   types.QueryServer
    59  //	TxConfig      client.TxConfig
    60  //	Codec         codec.BinaryCodec
    61  //
    62  //	Vals    *tmtypes.ValidatorSet
    63  //	Signers []tmtypes.PrivValidator
    64  //
    65  //	senderPrivKey cryptotypes.PrivKey
    66  //	SenderAccount authtypes.AccountI
    67  //
    68  //	PendingSendPackets []channeltypes.Packet
    69  //	PendingAckPackets  []PacketAck
    70  //}
    71  //
    72  //type PacketAck struct {
    73  //	Packet channeltypes.Packet
    74  //	Ack    []byte
    75  //}
    76  //
    77  //// NewTestChain initializes a new TestChain instance with a single validator set using a
    78  //// generated private key. It also creates a sender account to be used for delivering transactions.
    79  ////
    80  //// The first block height is committed to state in order to allow for client creations on
    81  //// counterparty chains. The TestChain will return with a block height starting at 2.
    82  ////
    83  //// Time management is handled by the Coordinator in order to ensure synchrony between chains.
    84  //// Each update of any chain increments the block header time for all chains by 5 seconds.
    85  //func NewTestChain(t *testing.T, coord *Coordinator, chainID string, opts ...wasm.Option) *TestChain {
    86  //	// generate validator private/public key
    87  //	privVal := mock.NewPV()
    88  //	pubKey, err := privVal.GetPubKey()
    89  //	require.NoError(t, err)
    90  //
    91  //	// create validator set with single validator
    92  //	validator := tmtypes.NewValidator(pubKey, 1)
    93  //	valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})
    94  //	signers := []tmtypes.PrivValidator{privVal}
    95  //
    96  //	// generate genesis account
    97  //	senderPrivKey := secp256k1.GenPrivKey()
    98  //	acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0)
    99  //	amount, ok := sdk.NewIntFromString("10000000000000000000")
   100  //	require.True(t, ok)
   101  //
   102  //	balance := banktypes.Balance{
   103  //		Address: acc.GetAddress().String(),
   104  //		Coins:   sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, amount)),
   105  //	}
   106  //
   107  //	app := NewTestingAppDecorator(t, wasmd.SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, opts, balance))
   108  //
   109  //	// create current header and call begin block
   110  //	header := tmproto.Header{
   111  //		ChainID: chainID,
   112  //		Height:  1,
   113  //		Time:    coord.CurrentTime.UTC(),
   114  //	}
   115  //
   116  //	txConfig := app.GetTxConfig()
   117  //
   118  //	// create an account to send transactions from
   119  //	chain := &TestChain{
   120  //		t:             t,
   121  //		Coordinator:   coord,
   122  //		ChainID:       chainID,
   123  //		App:           app,
   124  //		CurrentHeader: header,
   125  //		QueryServer:   app.GetIBCKeeper(),
   126  //		TxConfig:      txConfig,
   127  //		Codec:         app.AppCodec(),
   128  //		Vals:          valSet,
   129  //		Signers:       signers,
   130  //		senderPrivKey: senderPrivKey,
   131  //		SenderAccount: acc,
   132  //	}
   133  //
   134  //	coord.CommitBlock(chain)
   135  //
   136  //	return chain
   137  //}
   138  //
   139  //// GetContext returns the current context for the application.
   140  //func (chain *TestChain) GetContext() sdk.Context {
   141  //	return chain.App.GetBaseApp().NewContext(false, chain.CurrentHeader)
   142  //}
   143  //
   144  //// QueryProof performs an abci query with the given key and returns the proto encoded merkle proof
   145  //// for the query and the height at which the proof will succeed on a tendermint verifier.
   146  //func (chain *TestChain) QueryProof(key []byte) ([]byte, clienttypes.Height) {
   147  //	return chain.QueryProofAtHeight(key, chain.App.LastBlockHeight())
   148  //}
   149  //
   150  //// QueryProof performs an abci query with the given key and returns the proto encoded merkle proof
   151  //// for the query and the height at which the proof will succeed on a tendermint verifier.
   152  //func (chain *TestChain) QueryProofAtHeight(key []byte, height int64) ([]byte, clienttypes.Height) {
   153  //	res := chain.App.Query(abci.RequestQuery{
   154  //		Path:   fmt.Sprintf("store/%s/key", host.StoreKey),
   155  //		Height: height - 1,
   156  //		Data:   key,
   157  //		Prove:  true,
   158  //	})
   159  //
   160  //	merkleProof, err := commitmenttypes.ConvertProofs(res.ProofOps)
   161  //	require.NoError(chain.t, err)
   162  //
   163  //	proof, err := chain.App.AppCodec().Marshal(&merkleProof)
   164  //	require.NoError(chain.t, err)
   165  //
   166  //	revision := clienttypes.ParseChainID(chain.ChainID)
   167  //
   168  //	// proof height + 1 is returned as the proof created corresponds to the height the proof
   169  //	// was created in the IAVL tree. Tendermint and subsequently the clients that rely on it
   170  //	// have heights 1 above the IAVL tree. Thus we return proof height + 1
   171  //	return proof, clienttypes.NewHeight(revision, uint64(res.Height)+1)
   172  //}
   173  //
   174  //// QueryUpgradeProof performs an abci query with the given key and returns the proto encoded merkle proof
   175  //// for the query and the height at which the proof will succeed on a tendermint verifier.
   176  //func (chain *TestChain) QueryUpgradeProof(key []byte, height uint64) ([]byte, clienttypes.Height) {
   177  //	res := chain.App.Query(abci.RequestQuery{
   178  //		Path:   "store/upgrade/key",
   179  //		Height: int64(height - 1),
   180  //		Data:   key,
   181  //		Prove:  true,
   182  //	})
   183  //
   184  //	merkleProof, err := commitmenttypes.ConvertProofs(res.ProofOps)
   185  //	require.NoError(chain.t, err)
   186  //
   187  //	proof, err := chain.App.AppCodec().Marshal(&merkleProof)
   188  //	require.NoError(chain.t, err)
   189  //
   190  //	revision := clienttypes.ParseChainID(chain.ChainID)
   191  //
   192  //	// proof height + 1 is returned as the proof created corresponds to the height the proof
   193  //	// was created in the IAVL tree. Tendermint and subsequently the clients that rely on it
   194  //	// have heights 1 above the IAVL tree. Thus we return proof height + 1
   195  //	return proof, clienttypes.NewHeight(revision, uint64(res.Height+1))
   196  //}
   197  //
   198  //// QueryConsensusStateProof performs an abci query for a consensus state
   199  //// stored on the given clientID. The proof and consensusHeight are returned.
   200  //func (chain *TestChain) QueryConsensusStateProof(clientID string) ([]byte, clienttypes.Height) {
   201  //	clientState := chain.GetClientState(clientID)
   202  //
   203  //	consensusHeight := clientState.GetLatestHeight().(clienttypes.Height)
   204  //	consensusKey := host.FullConsensusStateKey(clientID, consensusHeight)
   205  //	proofConsensus, _ := chain.QueryProof(consensusKey)
   206  //
   207  //	return proofConsensus, consensusHeight
   208  //}
   209  //
   210  //// NextBlock sets the last header to the current header and increments the current header to be
   211  //// at the next block height. It does not update the time as that is handled by the Coordinator.
   212  ////
   213  //// CONTRACT: this function must only be called after app.Commit() occurs
   214  //func (chain *TestChain) NextBlock() {
   215  //	// set the last header to the current header
   216  //	// use nil trusted fields
   217  //	chain.LastHeader = chain.CurrentTMClientHeader()
   218  //
   219  //	// increment the current header
   220  //	chain.CurrentHeader = tmproto.Header{
   221  //		ChainID: chain.ChainID,
   222  //		Height:  chain.App.LastBlockHeight() + 1,
   223  //		AppHash: chain.App.LastCommitID().Hash,
   224  //		// NOTE: the time is increased by the coordinator to maintain time synchrony amongst
   225  //		// chains.
   226  //		Time:               chain.CurrentHeader.Time,
   227  //		ValidatorsHash:     chain.Vals.Hash(),
   228  //		NextValidatorsHash: chain.Vals.Hash(),
   229  //	}
   230  //
   231  //	chain.App.BeginBlock(abci.RequestBeginBlock{Header: chain.CurrentHeader})
   232  //}
   233  //
   234  //// sendMsgs delivers a transaction through the application without returning the result.
   235  //func (chain *TestChain) sendMsgs(msgs ...sdk.Msg) error {
   236  //	_, err := chain.SendMsgs(msgs...)
   237  //	return err
   238  //}
   239  //
   240  //// SendMsgs delivers a transaction through the application. It updates the senders sequence
   241  //// number and updates the TestChain's headers. It returns the result and error if one
   242  //// occurred.
   243  //func (chain *TestChain) SendMsgs(msgs ...sdk.Msg) (*sdk.Result, error) {
   244  //	// ensure the chain has the latest time
   245  //	chain.Coordinator.UpdateTimeForChain(chain)
   246  //
   247  //	_, r, err := wasmd.SignAndDeliver(
   248  //		chain.t,
   249  //		chain.TxConfig,
   250  //		chain.App.GetBaseApp(),
   251  //		chain.GetContext().BlockHeader(),
   252  //		msgs,
   253  //		chain.ChainID,
   254  //		[]uint64{chain.SenderAccount.GetAccountNumber()},
   255  //		[]uint64{chain.SenderAccount.GetSequence()},
   256  //		true, true, chain.senderPrivKey,
   257  //	)
   258  //	if err != nil {
   259  //		return nil, err
   260  //	}
   261  //
   262  //	// SignAndDeliver calls app.Commit()
   263  //	chain.NextBlock()
   264  //
   265  //	// increment sequence for successful transaction execution
   266  //	err = chain.SenderAccount.SetSequence(chain.SenderAccount.GetSequence() + 1)
   267  //	if err != nil {
   268  //		return nil, err
   269  //	}
   270  //
   271  //	chain.Coordinator.IncrementTime()
   272  //
   273  //	chain.captureIBCEvents(r)
   274  //
   275  //	return r, nil
   276  //}
   277  //
   278  //func (chain *TestChain) captureIBCEvents(r *sdk.Result) {
   279  //	toSend := getSendPackets(r.Events)
   280  //	if len(toSend) > 0 {
   281  //		// Keep a queue on the chain that we can relay in tests
   282  //		chain.PendingSendPackets = append(chain.PendingSendPackets, toSend...)
   283  //	}
   284  //	toAck := getAckPackets(r.Events)
   285  //	if len(toAck) > 0 {
   286  //		// Keep a queue on the chain that we can relay in tests
   287  //		chain.PendingAckPackets = append(chain.PendingAckPackets, toAck...)
   288  //	}
   289  //}
   290  //
   291  //// GetClientState retrieves the client state for the provided clientID. The client is
   292  //// expected to exist otherwise testing will fail.
   293  //func (chain *TestChain) GetClientState(clientID string) exported.ClientState {
   294  //	clientState, found := chain.App.GetIBCKeeper().ClientKeeper.GetClientState(chain.GetContext(), clientID)
   295  //	require.True(chain.t, found)
   296  //
   297  //	return clientState
   298  //}
   299  //
   300  //// GetConsensusState retrieves the consensus state for the provided clientID and height.
   301  //// It will return a success boolean depending on if consensus state exists or not.
   302  //func (chain *TestChain) GetConsensusState(clientID string, height exported.Height) (exported.ConsensusState, bool) {
   303  //	return chain.App.GetIBCKeeper().ClientKeeper.GetClientConsensusState(chain.GetContext(), clientID, height)
   304  //}
   305  //
   306  //// GetValsAtHeight will return the validator set of the chain at a given height. It will return
   307  //// a success boolean depending on if the validator set exists or not at that height.
   308  //func (chain *TestChain) GetValsAtHeight(height int64) (*tmtypes.ValidatorSet, bool) {
   309  //	histInfo, ok := chain.App.GetStakingKeeper().GetHistoricalInfo(chain.GetContext(), height)
   310  //	if !ok {
   311  //		return nil, false
   312  //	}
   313  //
   314  //	valSet := stakingtypes.Validators(histInfo.Valset)
   315  //
   316  //	tmValidators, err := teststaking.ToTmValidators(valSet, sdk.DefaultPowerReduction)
   317  //	if err != nil {
   318  //		panic(err)
   319  //	}
   320  //	return tmtypes.NewValidatorSet(tmValidators), true
   321  //}
   322  //
   323  //// GetAcknowledgement retrieves an acknowledgement for the provided packet. If the
   324  //// acknowledgement does not exist then testing will fail.
   325  //func (chain *TestChain) GetAcknowledgement(packet exported.PacketI) []byte {
   326  //	ack, found := chain.App.GetIBCKeeper().ChannelKeeper.GetPacketAcknowledgement(chain.GetContext(), packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence())
   327  //	require.True(chain.t, found)
   328  //
   329  //	return ack
   330  //}
   331  //
   332  //// GetPrefix returns the prefix for used by a chain in connection creation
   333  //func (chain *TestChain) GetPrefix() commitmenttypes.MerklePrefix {
   334  //	return commitmenttypes.NewMerklePrefix(chain.App.GetIBCKeeper().ConnectionKeeper.GetCommitmentPrefix().Bytes())
   335  //}
   336  //
   337  //// ConstructUpdateTMClientHeader will construct a valid 07-tendermint Header to update the
   338  //// light client on the source chain.
   339  //func (chain *TestChain) ConstructUpdateTMClientHeader(counterparty *TestChain, clientID string) (*ibctmtypes.Header, error) {
   340  //	return chain.ConstructUpdateTMClientHeaderWithTrustedHeight(counterparty, clientID, clienttypes.ZeroHeight())
   341  //}
   342  //
   343  //// ConstructUpdateTMClientHeader will construct a valid 07-tendermint Header to update the
   344  //// light client on the source chain.
   345  //func (chain *TestChain) ConstructUpdateTMClientHeaderWithTrustedHeight(counterparty *TestChain, clientID string, trustedHeight clienttypes.Height) (*ibctmtypes.Header, error) {
   346  //	header := counterparty.LastHeader
   347  //	// Relayer must query for LatestHeight on client to get TrustedHeight if the trusted height is not set
   348  //	if trustedHeight.IsZero() {
   349  //		trustedHeight = chain.GetClientState(clientID).GetLatestHeight().(clienttypes.Height)
   350  //	}
   351  //	var (
   352  //		tmTrustedVals *tmtypes.ValidatorSet
   353  //		ok            bool
   354  //	)
   355  //	// Once we get TrustedHeight from client, we must query the validators from the counterparty chain
   356  //	// If the LatestHeight == LastHeader.Height, then TrustedValidators are current validators
   357  //	// If LatestHeight < LastHeader.Height, we can query the historical validator set from HistoricalInfo
   358  //	if trustedHeight == counterparty.LastHeader.GetHeight() {
   359  //		tmTrustedVals = counterparty.Vals
   360  //	} else {
   361  //		// NOTE: We need to get validators from counterparty at height: trustedHeight+1
   362  //		// since the last trusted validators for a header at height h
   363  //		// is the NextValidators at h+1 committed to in header h by
   364  //		// NextValidatorsHash
   365  //		tmTrustedVals, ok = counterparty.GetValsAtHeight(int64(trustedHeight.RevisionHeight + 1))
   366  //		if !ok {
   367  //			return nil, sdkerrors.Wrapf(ibctmtypes.ErrInvalidHeaderHeight, "could not retrieve trusted validators at trustedHeight: %d", trustedHeight)
   368  //		}
   369  //	}
   370  //	// inject trusted fields into last header
   371  //	// for now assume revision number is 0
   372  //	header.TrustedHeight = trustedHeight
   373  //
   374  //	trustedVals, err := tmTrustedVals.ToProto()
   375  //	if err != nil {
   376  //		return nil, err
   377  //	}
   378  //	header.TrustedValidators = trustedVals
   379  //
   380  //	return header, nil
   381  //}
   382  //
   383  //// ExpireClient fast forwards the chain's block time by the provided amount of time which will
   384  //// expire any clients with a trusting period less than or equal to this amount of time.
   385  //func (chain *TestChain) ExpireClient(amount time.Duration) {
   386  //	chain.Coordinator.IncrementTimeBy(amount)
   387  //}
   388  //
   389  //// CurrentTMClientHeader creates a TM header using the current header parameters
   390  //// on the chain. The trusted fields in the header are set to nil.
   391  //func (chain *TestChain) CurrentTMClientHeader() *ibctmtypes.Header {
   392  //	return chain.CreateTMClientHeader(chain.ChainID, chain.CurrentHeader.Height, clienttypes.Height{}, chain.CurrentHeader.Time, chain.Vals, nil, chain.Signers)
   393  //}
   394  //
   395  //// CreateTMClientHeader creates a TM header to update the TM client. Args are passed in to allow
   396  //// caller flexibility to use params that differ from the chain.
   397  //func (chain *TestChain) CreateTMClientHeader(chainID string, blockHeight int64, trustedHeight clienttypes.Height, timestamp time.Time, tmValSet, tmTrustedVals *tmtypes.ValidatorSet, signers []tmtypes.PrivValidator) *ibctmtypes.Header {
   398  //	var (
   399  //		valSet      *tmproto.ValidatorSet
   400  //		trustedVals *tmproto.ValidatorSet
   401  //	)
   402  //	require.NotNil(chain.t, tmValSet)
   403  //
   404  //	vsetHash := tmValSet.Hash()
   405  //
   406  //	tmHeader := tmtypes.Header{
   407  //		Version:            tmprotoversion.Consensus{Block: tmversion.BlockProtocol, App: 2},
   408  //		ChainID:            chainID,
   409  //		Height:             blockHeight,
   410  //		Time:               timestamp,
   411  //		LastBlockID:        MakeBlockID(make([]byte, tmhash.Size), 10_000, make([]byte, tmhash.Size)),
   412  //		LastCommitHash:     chain.App.LastCommitID().Hash,
   413  //		DataHash:           tmhash.Sum([]byte("data_hash")),
   414  //		ValidatorsHash:     vsetHash,
   415  //		NextValidatorsHash: vsetHash,
   416  //		ConsensusHash:      tmhash.Sum([]byte("consensus_hash")),
   417  //		AppHash:            chain.CurrentHeader.AppHash,
   418  //		LastResultsHash:    tmhash.Sum([]byte("last_results_hash")),
   419  //		EvidenceHash:       tmhash.Sum([]byte("evidence_hash")),
   420  //		ProposerAddress:    tmValSet.Proposer.Address, //nolint:staticcheck
   421  //	}
   422  //	hhash := tmHeader.Hash()
   423  //	blockID := MakeBlockID(hhash, 3, tmhash.Sum([]byte("part_set")))
   424  //	voteSet := tmtypes.NewVoteSet(chainID, blockHeight, 1, tmproto.PrecommitType, tmValSet)
   425  //
   426  //	commit, err := tmtypes.MakeCommit(blockID, blockHeight, 1, voteSet, signers, timestamp)
   427  //	require.NoError(chain.t, err)
   428  //
   429  //	signedHeader := &tmproto.SignedHeader{
   430  //		Header: tmHeader.ToProto(),
   431  //		Commit: commit.ToProto(),
   432  //	}
   433  //
   434  //	valSet, err = tmValSet.ToProto()
   435  //	if err != nil {
   436  //		panic(err)
   437  //	}
   438  //
   439  //	if tmTrustedVals != nil {
   440  //		trustedVals, err = tmTrustedVals.ToProto()
   441  //		if err != nil {
   442  //			panic(err)
   443  //		}
   444  //	}
   445  //
   446  //	// The trusted fields may be nil. They may be filled before relaying messages to a client.
   447  //	// The relayer is responsible for querying client and injecting appropriate trusted fields.
   448  //	return &ibctmtypes.Header{
   449  //		SignedHeader:      signedHeader,
   450  //		ValidatorSet:      valSet,
   451  //		TrustedHeight:     trustedHeight,
   452  //		TrustedValidators: trustedVals,
   453  //	}
   454  //}
   455  //
   456  //// MakeBlockID copied unimported test functions from tmtypes to use them here
   457  //func MakeBlockID(hash []byte, partSetSize uint32, partSetHash []byte) tmtypes.BlockID {
   458  //	return tmtypes.BlockID{
   459  //		Hash: hash,
   460  //		PartSetHeader: tmtypes.PartSetHeader{
   461  //			Total: partSetSize,
   462  //			Hash:  partSetHash,
   463  //		},
   464  //	}
   465  //}
   466  //
   467  //// CreateSortedSignerArray takes two PrivValidators, and the corresponding Validator structs
   468  //// (including voting power). It returns a signer array of PrivValidators that matches the
   469  //// sorting of ValidatorSet.
   470  //// The sorting is first by .VotingPower (descending), with secondary index of .Address (ascending).
   471  //func CreateSortedSignerArray(altPrivVal, suitePrivVal tmtypes.PrivValidator,
   472  //	altVal, suiteVal *tmtypes.Validator,
   473  //) []tmtypes.PrivValidator {
   474  //	switch {
   475  //	case altVal.VotingPower > suiteVal.VotingPower:
   476  //		return []tmtypes.PrivValidator{altPrivVal, suitePrivVal}
   477  //	case altVal.VotingPower < suiteVal.VotingPower:
   478  //		return []tmtypes.PrivValidator{suitePrivVal, altPrivVal}
   479  //	default:
   480  //		if bytes.Compare(altVal.Address, suiteVal.Address) == -1 {
   481  //			return []tmtypes.PrivValidator{altPrivVal, suitePrivVal}
   482  //		}
   483  //		return []tmtypes.PrivValidator{suitePrivVal, altPrivVal}
   484  //	}
   485  //}
   486  //
   487  //// CreatePortCapability binds and claims a capability for the given portID if it does not
   488  //// already exist. This function will fail testing on any resulting error.
   489  //// NOTE: only creation of a capbility for a transfer or mock port is supported
   490  //// Other applications must bind to the port in InitGenesis or modify this code.
   491  //func (chain *TestChain) CreatePortCapability(scopedKeeper capabilitykeeper.ScopedKeeper, portID string) {
   492  //	// check if the portId is already binded, if not bind it
   493  //	_, ok := chain.App.GetScopedIBCKeeper().GetCapability(chain.GetContext(), host.PortPath(portID))
   494  //	if !ok {
   495  //		// create capability using the IBC capability keeper
   496  //		cap, err := chain.App.GetScopedIBCKeeper().NewCapability(chain.GetContext(), host.PortPath(portID))
   497  //		require.NoError(chain.t, err)
   498  //
   499  //		// claim capability using the scopedKeeper
   500  //		err = scopedKeeper.ClaimCapability(chain.GetContext(), cap, host.PortPath(portID))
   501  //		require.NoError(chain.t, err)
   502  //	}
   503  //
   504  //	chain.App.Commit()
   505  //
   506  //	chain.NextBlock()
   507  //}
   508  //
   509  //// GetPortCapability returns the port capability for the given portID. The capability must
   510  //// exist, otherwise testing will fail.
   511  //func (chain *TestChain) GetPortCapability(portID string) *capabilitytypes.Capability {
   512  //	cap, ok := chain.App.GetScopedIBCKeeper().GetCapability(chain.GetContext(), host.PortPath(portID))
   513  //	require.True(chain.t, ok)
   514  //
   515  //	return cap
   516  //}
   517  //
   518  //// CreateChannelCapability binds and claims a capability for the given portID and channelID
   519  //// if it does not already exist. This function will fail testing on any resulting error. The
   520  //// scoped keeper passed in will claim the new capability.
   521  //func (chain *TestChain) CreateChannelCapability(scopedKeeper capabilitykeeper.ScopedKeeper, portID, channelID string) {
   522  //	capName := host.ChannelCapabilityPath(portID, channelID)
   523  //	// check if the portId is already binded, if not bind it
   524  //	_, ok := chain.App.GetScopedIBCKeeper().GetCapability(chain.GetContext(), capName)
   525  //	if !ok {
   526  //		cap, err := chain.App.GetScopedIBCKeeper().NewCapability(chain.GetContext(), capName)
   527  //		require.NoError(chain.t, err)
   528  //		err = scopedKeeper.ClaimCapability(chain.GetContext(), cap, capName)
   529  //		require.NoError(chain.t, err)
   530  //	}
   531  //
   532  //	chain.App.Commit()
   533  //
   534  //	chain.NextBlock()
   535  //}
   536  //
   537  //// GetChannelCapability returns the channel capability for the given portID and channelID.
   538  //// The capability must exist, otherwise testing will fail.
   539  //func (chain *TestChain) GetChannelCapability(portID, channelID string) *capabilitytypes.Capability {
   540  //	cap, ok := chain.App.GetScopedIBCKeeper().GetCapability(chain.GetContext(), host.ChannelCapabilityPath(portID, channelID))
   541  //	require.True(chain.t, ok)
   542  //
   543  //	return cap
   544  //}
   545  //
   546  //func (chain *TestChain) Balance(acc sdk.AccAddress, denom string) sdk.Coin {
   547  //	return chain.GetTestSupport().BankKeeper().GetBalance(chain.GetContext(), acc, denom)
   548  //}
   549  //
   550  //func (chain *TestChain) AllBalances(acc sdk.AccAddress) sdk.Coins {
   551  //	return chain.GetTestSupport().BankKeeper().GetAllBalances(chain.GetContext(), acc)
   552  //}
   553  //
   554  //func (chain TestChain) GetTestSupport() *wasmd.TestSupport {
   555  //	return chain.App.(*TestingAppDecorator).TestSupport()
   556  //}
   557  //
   558  //var _ ibctesting.TestingApp = TestingAppDecorator{}
   559  //
   560  //type TestingAppDecorator struct {
   561  //	*wasmd.WasmApp
   562  //	t *testing.T
   563  //}
   564  //
   565  //func NewTestingAppDecorator(t *testing.T, wasmApp *wasmd.WasmApp) *TestingAppDecorator {
   566  //	return &TestingAppDecorator{WasmApp: wasmApp, t: t}
   567  //}
   568  //
   569  //func (a TestingAppDecorator) GetBaseApp() *baseapp.BaseApp {
   570  //	return a.TestSupport().GetBaseApp()
   571  //}
   572  //
   573  //func (a TestingAppDecorator) GetStakingKeeper() stakingkeeper.Keeper {
   574  //	return a.TestSupport().StakingKeeper()
   575  //}
   576  //
   577  //func (a TestingAppDecorator) GetIBCKeeper() *ibckeeper.Keeper {
   578  //	return a.TestSupport().IBCKeeper()
   579  //}
   580  //
   581  //func (a TestingAppDecorator) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {
   582  //	return a.TestSupport().ScopeIBCKeeper()
   583  //}
   584  //
   585  //func (a TestingAppDecorator) GetTxConfig() client.TxConfig {
   586  //	return a.TestSupport().GetTxConfig()
   587  //}
   588  //
   589  //func (a TestingAppDecorator) TestSupport() *wasmd.TestSupport {
   590  //	return wasmd.NewTestSupport(a.t, a.WasmApp)
   591  //}