Skip to content
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

chore: fixing e2e tests #454

Merged
merged 8 commits into from
Sep 14, 2023
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
2 changes: 1 addition & 1 deletion e2e/gastracking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (s *E2ETestSuite) TestGasTrackingAndRewardsDistribution() {
contractToBlockGasRatio := sdk.NewDec(int64(txGasTracked)).Quo(sdk.NewDec(blockGasLimit))
contractInflationRewardsExpected = sdk.Coin{
Denom: blockInflationRewardsExpected.Denom,
Amount: blockInflationRewardsExpected.Amount.ToDec().Mul(contractToBlockGasRatio).TruncateInt(),
Amount: sdk.NewDecFromInt(blockInflationRewardsExpected.Amount).Mul(contractToBlockGasRatio).TruncateInt(),
}

// Total
Expand Down
10 changes: 5 additions & 5 deletions e2e/testing/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func NewTestChain(t *testing.T, chainIdx int, opts ...interface{}) *TestChain {
app.EmptyBaseAppOptions{},
[]wasm.Option{},
)
genState := app.NewDefaultGenesisState()
genState := app.NewDefaultGenesisState(archApp.AppCodec())

// Generate validators
validators := make([]*tmTypes.Validator, 0, chainCfg.ValidatorsNum)
Expand Down Expand Up @@ -183,7 +183,7 @@ func NewTestChain(t *testing.T, chainIdx int, opts ...interface{}) *TestChain {
accGenCoins := genCoins
// Lower genesis balance for validator account
if i < chainCfg.ValidatorsNum {
accGenCoins = accGenCoins.Sub(bondCoins)
accGenCoins = accGenCoins.Sub(bondCoins...)
bondedPoolCoins = bondedPoolCoins.Add(bondCoins...)
}

Expand All @@ -207,7 +207,7 @@ func NewTestChain(t *testing.T, chainIdx int, opts ...interface{}) *TestChain {
Coins: bondedPoolCoins,
})

bankGenesis := bankTypes.NewGenesisState(bankTypes.DefaultGenesisState().Params, balances, totalSupply, []bankTypes.Metadata{})
bankGenesis := bankTypes.NewGenesisState(bankTypes.DefaultGenesisState().Params, balances, totalSupply, []bankTypes.Metadata{}, []bankTypes.SendEnabled{})
genState[bankTypes.ModuleName] = archApp.AppCodec().MustMarshalJSON(bankGenesis)

signInfo := make([]slashingTypes.SigningInfo, len(validatorSet.Validators))
Expand Down Expand Up @@ -381,7 +381,7 @@ func (chain *TestChain) BeginBlock() []abci.Event {
res := chain.app.BeginBlock(abci.RequestBeginBlock{
Hash: nil,
Header: chain.curHeader,
LastCommitInfo: abci.LastCommitInfo{
LastCommitInfo: abci.CommitInfo{
Round: 0,
Votes: voteInfo,
},
Expand Down Expand Up @@ -498,7 +498,7 @@ func (chain *TestChain) SendMsgsRaw(senderAcc Account, msgs []sdk.Msg, opts ...S
}

// Send the Tx
return chain.app.Deliver(chain.txConfig.TxEncoder(), tx)
return chain.app.SimDeliver(chain.txConfig.TxEncoder(), tx)
}

// ParseSDKResultData converts TX result data into a slice of Msgs.
Expand Down
9 changes: 5 additions & 4 deletions e2e/testing/chain_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package e2eTesting

import (
sdk "github.com/cosmos/cosmos-sdk/types"
govTypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govTypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/stretchr/testify/require"
)

Expand All @@ -14,8 +14,9 @@ func (chain *TestChain) ExecuteGovProposal(proposerAcc Account, expPass bool, pr

// Get params
k := chain.app.GovKeeper
depositCoin := k.GetDepositParams(chain.GetContext()).MinDeposit
votingDur := k.GetVotingParams(chain.GetContext()).VotingPeriod
govParams := k.GetParams(chain.GetContext())
depositCoin := govParams.MinDeposit
votingDur := govParams.VotingPeriod

// Submit proposal with min deposit to start the voting
msg, err := govTypes.NewMsgSubmitProposal(proposalContent, depositCoin, proposerAcc.Address)
Expand All @@ -39,7 +40,7 @@ func (chain *TestChain) ExecuteGovProposal(proposerAcc Account, expPass bool, pr
}

// Wait for voting to end
chain.NextBlock(votingDur)
chain.NextBlock(*votingDur)
chain.NextBlock(0) // for the Gov EndBlocker to work

// Check if proposal was passed
Expand Down
14 changes: 9 additions & 5 deletions e2e/testing/chain_ops_ibc.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package e2eTesting

import (
"fmt"
"time"

abci "github.com/cometbft/cometbft/abci/types"
Expand All @@ -11,7 +10,7 @@ import (
tmTypes "github.com/cometbft/cometbft/types"
tmVersion "github.com/cometbft/cometbft/version"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/staking/testutil"
stakingTestUtil "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"
channelTypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
Expand Down Expand Up @@ -56,7 +55,7 @@ func (chain *TestChain) GetValSetAtHeight(height int64) tmTypes.ValidatorSet {
require.True(t, ok)

validators := stakingTypes.Validators(histInfo.Valset)
tmValidators, err := teststaking.ToTmValidators(validators, sdk.DefaultPowerReduction)
tmValidators, err := stakingTestUtil.ToTmValidators(validators, sdk.DefaultPowerReduction)
require.NoError(t, err)

valSet := tmTypes.NewValidatorSet(tmValidators)
Expand All @@ -70,7 +69,7 @@ func (chain *TestChain) GetProofAtHeight(key []byte, height uint64) ([]byte, cli
t := chain.t

res := chain.app.Query(abci.RequestQuery{
Path: fmt.Sprintf("store/%s/key", host.StoreKey),
Path: "store/ibc/key",
Height: int64(height) - 1,
Data: key,
Prove: true,
Expand Down Expand Up @@ -101,7 +100,12 @@ func (chain *TestChain) SendIBCPacket(packet exported.PacketI) {
cap, ok := chain.app.ScopedIBCKeeper.GetCapability(chain.GetContext(), capPath)
require.True(t, ok)

require.NoError(t, chain.app.IBCKeeper.ChannelKeeper.SendPacket(chain.GetContext(), cap, packet))
timeout := clientTypes.Height{
RevisionNumber: packet.GetTimeoutHeight().GetRevisionNumber(),
RevisionHeight: packet.GetTimeoutHeight().GetRevisionHeight(),
}
_, err := chain.app.IBCKeeper.ChannelKeeper.SendPacket(chain.GetContext(), cap, packet.GetSourcePort(), packet.GetSourceChannel(), timeout, packet.GetTimeoutTimestamp(), packet.GetData())
require.NoError(t, err)

chain.NextBlock(0)
}
Expand Down
6 changes: 3 additions & 3 deletions e2e/testing/chain_options.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package e2eTesting

import (
abci "github.com/cometbft/cometbft/abci/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
mintTypes "github.com/cosmos/cosmos-sdk/x/mint/types"
Expand All @@ -28,7 +28,7 @@ type (

TestChainGenesisOption func(cdc codec.Codec, genesis app.GenesisState)

TestChainConsensusParamsOption func(params *abci.ConsensusParams)
TestChainConsensusParamsOption func(params *tmproto.ConsensusParams)
)

// defaultChainConfig builds chain default config.
Expand Down Expand Up @@ -92,7 +92,7 @@ func WithLogger() TestChainConfigOption {

// WithBlockGasLimit sets the block gas limit (not set by default).
func WithBlockGasLimit(gasLimit int64) TestChainConsensusParamsOption {
return func(params *abci.ConsensusParams) {
return func(params *tmproto.ConsensusParams) {
params.Block.MaxGas = gasLimit
}
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/testing/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func HumanizeCoins(decimals uint8, coins ...sdk.Coin) string {

strs := make([]string, 0, len(coins))
for _, coin := range coins {
amtDec := coin.Amount.ToDec().Mul(baseDec)
amtDec := sdk.NewDecFromInt(coin.Amount).Mul(baseDec)
amtFloat, _ := amtDec.Float64()

strs = append(strs, fmt.Sprintf("%.03f%s", amtFloat, coin.Denom))
Expand Down
2 changes: 0 additions & 2 deletions e2e/testing/ibc_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ func (e *IBCEndpoint) createIBCClient() {
dstChainLastTMHeader.GetHeight().(clientTypes.Height),
commitmentTypes.GetSDKSpecs(),
tmClientUpgradePath,
tmClientAllowUpdateAfterExpiry,
tmClientAllowUpdateAfterMisbehaviour,
)

srcChainSenderAcc := srcChain.GetAccount(0)
Expand Down
4 changes: 2 additions & 2 deletions e2e/txfees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ func (s *E2ETestSuite) TestTxFees() {
// Get rewards address balance diff (adjusting prev balance with fees paid)
var rewardsAddrBalanceDiff sdk.Coins
{
rewardsAccPrevBalance = rewardsAccPrevBalance.Sub(sdk.Coins{withdrawTxFees})
rewardsAccPrevBalance = rewardsAccPrevBalance.Sub(withdrawTxFees)

curBalance := chain.GetBalance(rewardsAcc.Address)
rewardsAddrBalanceDiff = curBalance.Sub(rewardsAccPrevBalance)
rewardsAddrBalanceDiff = curBalance.Sub(rewardsAccPrevBalance...)
rewardsAccPrevBalance = curBalance

s.Require().Equal(rewardsAddrBalanceDiff.String(), feeRebateRewards.Add(inflationRewards).String())
Expand Down
4 changes: 2 additions & 2 deletions e2e/voter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (s *E2ETestSuite) TestVoter_ExecuteQueryAndReply() {
// s.Assert().EqualValues(contractCoinsExp, releasedCoinsRcv)

acc1BalanceAfter := chain.GetBalance(acc1.Address)
acc1BalanceExpected := acc1BalanceBefore.Add(contractCoinsExp...).Sub(chain.GetDefaultTxFee())
acc1BalanceExpected := acc1BalanceBefore.Add(contractCoinsExp...).Sub(chain.GetDefaultTxFee()...)
s.Assert().EqualValues(acc1BalanceExpected.String(), acc1BalanceAfter.String())

releaseStats := s.VoterGetReleaseStats(chain, contractAddr)
Expand Down Expand Up @@ -1147,7 +1147,7 @@ func (s *E2ETestSuite) TestVoter_WASMBindingsWithdrawRewards() {
})

s.Run("Check rewardsAddr balance changed", func() {
rewardsAddrBalanceDiff := chain.GetBalance(contractAddr).Sub(rewardsAddrBalanceBefore)
rewardsAddrBalanceDiff := chain.GetBalance(contractAddr).Sub(rewardsAddrBalanceBefore...)
s.Assert().Equal(totalRewardsExpected.String(), rewardsAddrBalanceDiff.String())
})
}
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/cosmos-sdk v0.47.4
github.com/cosmos/gogoproto v1.4.11
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-go/v7 v7.2.0
github.com/dvsekhvalnov/jose2go v1.5.0
github.com/gogo/protobuf v1.3.2
Expand All @@ -24,7 +24,6 @@ require (
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
github.com/tendermint/tendermint v0.35.9
golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb
google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e
google.golang.org/grpc v1.57.0
Expand Down Expand Up @@ -55,7 +54,6 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/btcsuite/btcd v0.22.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
Expand Down Expand Up @@ -139,7 +137,6 @@ require (
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20210609091139-0a56a4bca00b // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect
Expand Down Expand Up @@ -188,3 +185,5 @@ replace github.com/CosmWasm/wasmd => github.com/archway-network/archway-wasmd v0
replace github.com/archway-network/voter => ./contracts/go/voter

replace github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.8.1

replace golang.org/x/exp => golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb
Loading