8000 ibctesting: use EthAccounts for IBC tests by fedekunze · Pull Request #280 · evmos/evmos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ibctesting: use EthAccounts for IBC tests #280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ibctesting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ This is because IBC will route to the top level IBC module of a middleware stack
sits at the top of middleware stack will need to be accessed via a public field in `SimApp`

This might look like:

```go
suite.chainA.GetSimApp().ICAAuthModule.IBCApp. sdk.Context, order channeltypes.Order, connectionHops []string,
portID, channelID string, chanCap *capabilitytypes.Capability,
Expand Down
3 changes: 2 additions & 1 deletion ibctesting/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/cosmos/ibc-go/v3/testing/simapp"

ibcgotesting "github.com/cosmos/ibc-go/v3/testing"
ethermint "github.com/tharsis/ethermint/types"
evmosapp "github.com/tharsis/evmos/app"
)

Expand All @@ -37,7 +38,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
validators := make([]stakingtypes.Validator, 0, len(valSet.Validators))
delegations := make([]stakingtypes.Delegation, 0, len(valSet.Validators))

bondAmt := sdk.DefaultPowerReduction
bondAmt := sdk.TokensFromConsensusPower(1, ethermint.PowerReduction)

for _, val := range valSet.Validators {
pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey)
Expand Down
33 changes: 17 additions & 16 deletions ibctesting/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/ethereum/go-ethereum/common"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
Expand All @@ -17,7 +21,7 @@ import (
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
"github.com/cosmos/cosmos-sdk/x/staking/teststaking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/require"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/tmhash"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
Expand All @@ -36,6 +40,8 @@ import (
"github.com/cosmos/ibc-go/v3/testing/simapp"

"github.com/tharsis/ethermint/crypto/ethsecp256k1"
ethermint "github.com/tharsis/ethermint/types"
evmtypes "github.com/tharsis/ethermint/x/evm/types"
)

// TestChain is a testing struct that wraps a simapp with the last TM Header, the current ABCI
Expand Down Expand Up @@ -87,9 +93,14 @@ func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain {
panic(err)
}

acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0)
amount, ok := sdk.NewIntFromString("10000000000000000000")
require.True(t, ok)
baseAcc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0)

acc := &ethermint.EthAccount{
BaseAccount: baseAcc,
CodeHash: common.BytesToHash(evmtypes.EmptyCodeHash).Hex(),
}

amount := sdk.TokensFromConsensusPower(1, ethermint.PowerReduction)

balance := banktypes.Balance{
Address: acc.GetAddress().String(),
Expand Down Expand Up @@ -133,16 +144,6 @@ func (chain *TestChain) GetContext() sdk.Context {
return chain.App.GetBaseApp().NewContext(false, chain.CurrentHeader)
}

// GetSimApp returns the SimApp to allow usage ofnon-interface fields.
// CONTRACT: This function should not be called by third parties implementing
// their own SimApp.
func (chain *TestChain) GetSimApp() *simapp.SimApp {
app, ok := chain.App.(*simapp.SimApp)
require.True(chain.t, ok)

return app
}

// QueryProof performs an abci query with the given key and returns the proto encoded merkle proof
// for the query and the height at which the proof will succeed on a tendermint verifier.
func (chain *TestChain) QueryProof(key []byte) ([]byte, clienttypes.Height) {
Expand Down Expand Up @@ -202,7 +203,7 @@ func (chain *TestChain) QueryUpgradeProof(key []byte, height uint64) ([]byte, cl
func (chain *TestChain) QueryConsensusStateProof(clientID string) ([]byte, clienttypes.Height) {
clientState := chain.GetClientState(clientID)

consensusHeight := clientState.GetLatestHeight().(clienttypes.Height)
consensusHeight, _ := clientState.GetLatestHeight().(clienttypes.Height)
consensusKey := host.FullConsensusStateKey(clientID, consensusHeight)
proofConsensus, _ := chain.QueryProof(consensusKey)

Expand Down Expand Up @@ -332,7 +333,7 @@ func (chain *TestChain) ConstructUpdateTMClientHeaderWithTrustedHeight(counterpa
header := counterparty.LastHeader
// Relayer must query for LatestHeight on client to get TrustedHeight if the trusted height is not set
if trustedHeight.IsZero() {
trustedHeight = chain.GetClientState(clientID).GetLatestHeight().(clienttypes.Height)
trustedHeight, _ = chain.GetClientState(clientID).GetLatestHeight().(clienttypes.Height)
}
var (
tmTrustedVals *tmtypes.ValidatorSet
Expand Down
0