8000 feat(test): Add support for custom decimals to test suite. by 0xstepit · Pull Request #3006 · evmos/evmos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(test): Add support for custom decimals to test suite. #3006

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 40 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
9dc9eed
update names
0xstepit Nov 27, 2024
b527a1b
wip
ramacarlucho Nov 28, 2024
cf9554e
wip
ramacarlucho Nov 28, 2024
aced183
add base fee check
0xstepit Nov 28, 2024
39a6a3a
add testing chain id to config
0xstepit Nov 29, 2024
f690960
update testing suite
0xstepit Nov 29, 2024
91b4e2e
remove comment from tests
0xstepit Nov 29, 2024
edf9abd
Merge branch 'main' into stepit/new-config-approach
0xstepit Nov 29, 2024
af482ad
remove configurator from cmd
0xstepit Nov 29, 2024
5e4496e
add license
0xstepit Nov 29, 2024
c286969
linter
0xstepit Nov 29, 2024
7719d77
fix tagged files
0xstepit Nov 29, 2024
383323f
fix function signature
0xstepit Nov 29, 2024
702cc7e
fix(test): Verify account balance ante fix tests (#3007)
0xstepit Dec 2, 2024
4d49a02
remove test configurator
0xstepit Dec 2, 2024
fe843ae
remove constructor for network with config
0xstepit Dec 2, 2024
30f184d
Update app/ante/evm/suite_test.go
0xstepit Dec 4, 2024
94f78d9
run make format
0xstepit Dec 4, 2024
6a09119
Update testutil/integration/evmos/network/config.go
0xstepit Dec 4, 2024
7e191a7
remove unused deps in ante
0xstepit Dec 3, 2024
4681df3
fix initial base fee in test suite
0xstepit Dec 3, 2024
d861c3f
fix can transfer
0xstepit Dec 3, 2024
f59cc66
fix vesting
0xstepit Dec 3, 2024
7fe2012
fix gas consume
0xstepit Dec 3, 2024
5599b19
update gov genesis for custom dec
0xstepit Dec 4, 2024
aa78c85
fix gas wanted
0xstepit Dec 4, 2024
4cf9db0
fix increment sequence
0xstepit Dec 4, 2024
12539ef
remove unused configurator
0xstepit Dec 4, 2024
927f719
Merge branch 'main' into stepit/new-config-approach
0xstepit Dec 6, 2024
389eb3b
fix conflicts
0xstepit Dec 13, 2024
a50078f
fix unit tests
0xstepit Dec 13, 2024
2fb24d8
remove TODO associated with evmOS
0xstepit Dec 16, 2024
5be547b
apply suggestions from review
0xstepit Dec 16, 2024
addf51c
restore test
0xstepit Dec 16, 2024
8c2e9f9
Merge branch 'main' into stepit/new-config-approach
0xstepit Dec 16, 2024
30a8f39
add changelog entry
0xstepit Dec 16, 2024
b009b10
fix changelog
0xstepit Dec 16, 2024
692c882
fix linter
0xstepit Dec 16, 2024
ec31bc6
Merge branch 'main' into stepit/new-config-approach
0xstepit Dec 16, 2024
3371f04
Merge branch 'main' into stepit/new-config-approach
0xstepit Dec 17, 2024
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (precompiles) [#2943](https://github.com/evmos/evmos/pull/2943) Add WERC-20 precompile.
- (precompiles) [#2966](https://github.com/evmos/evmos/pull/2966) Add safety check that ERC-20 precompiles cannot receive funds.
- 8000 (app) [#3009](https://github.com/evmos/evmos/pull/3009) Move internal Evmos app initialization to input function.
- (tests) [#3006](https://github.com/evmos/evmos/pull/3006) Add support for custom decimals to test suite and fix ante tests.

### Bug Fixes

Expand Down
9 changes: 6 additions & 3 deletions app/ante/evm/06_account_verification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func (suite *EvmAnteTestSuite) TestVerifyAccountBalance() {
keyring := testkeyring.New(2)
unitNetwork := network.NewUnitTestNetwork(
network.WithPreFundedAccounts(keyring.GetAllAccAddrs()...),
network.WithChainID(suite.chainID),
)
grpcHandler := grpc.NewIntegrationHandler(unitNetwork)
txFactory := factory.New(unitNetwork, grpcHandler)
Expand Down Expand Up @@ -53,10 +54,12 @@ func (suite *EvmAnteTestSuite) TestVerifyAccountBalance() {
suite.Require().NoError(err)

// Make tx cost greater than balance
balanceResp, err := grpcHandler.GetBalanceFromBank(senderKey.AccAddr, unitNetwork.GetBaseDenom())
balanceResp, err := grpcHandler.GetBalanceFromEVM(senderKey.AccAddr)
suite.Require().NoError(err)

invalidAmount := balanceResp.Balance.Amount.Add(math.NewInt(100))
balance, ok := math.NewIntFromString(balanceResp.Balance)
suite.Require().True(ok)
invalidAmount := balance.Add(math.NewInt(100))
txArgs.Amount = invalidAmount.BigInt()
return statedbAccount, txArgs
},
Expand Down Expand Up @@ -98,7 +101,7 @@ func (suite *EvmAnteTestSuite) TestVerifyAccountBalance() {
}

for _, tc := range testCases {
suite.Run(fmt.Sprintf("%v_%v", evmtypes.GetTxTypeName(suite.ethTxType), tc.name), func() {
suite.Run(fmt.Sprintf("%v_%v_%v", evmtypes.GetTxTypeName(suite.ethTxType), suite.chainID, tc.name), func() {
// Perform test logic
statedbAccount, txArgs := tc.generateAccountAndArgs()
txData, err := txArgs.ToTxData()
Expand Down
10 changes: 7 additions & 3 deletions app/ante/evm/07_can_transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
func (suite *EvmAnteTestSuite) TestCanTransfer() {
keyring := testkeyring.New(1)
unitNetwork := network.NewUnitTestNetwork(
network.WithChainID(suite.chainID),
network.WithPreFundedAccounts(keyring.GetAllAccAddrs()...),
)
grpcHandler := grpc.NewIntegrationHandler(unitNetwork)
Expand All @@ -45,9 +46,12 @@ func (suite *EvmAnteTestSuite) TestCanTransfer() {
expectedError: errortypes.ErrInsufficientFunds,
isLondon: true,
malleate: func(txArgs *evmtypes.EvmTxArgs) {
balanceResp, err := grpcHandler.GetBalanceFromBank(senderKey.AccAddr, unitNetwork.GetBaseDenom())
balanceResp, err := grpcHandler.GetBalanceFromEVM(senderKey.AccAddr)
suite.Require().NoError(err)
invalidAmount := balanceResp.Balance.Amount.Add(math.NewInt(1)).BigInt()

balance, ok := math.NewIntFromString(balanceResp.Balance)
suite.Require().True(ok)
invalidAmount := balance.Add(math.NewInt(1)).BigInt()
txArgs.Amount = invalidAmount
},
},
Expand All @@ -61,7 +65,7 @@ func (suite *EvmAnteTestSuite) TestCanTransfer() {
}

for _, tc := range testCases {
suite.Run(fmt.Sprintf("%v_%v", evmtypes.GetTxTypeName(suite.ethTxType), tc.name), func() {
suite.Run(fmt.Sprintf("%v_%v_%v", evmtypes.GetTxTypeName(suite.ethTxType), suite.chainID, tc.name), func() {
baseFeeResp, err := grpcHandler.GetEvmBaseFee()
suite.Require().NoError(err)
ethCfg := unitNetwork.GetEVMChainConfig()
Expand Down
1 change: 1 addition & 0 deletions app/ante/evm/08_vesting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type AccountExpenses = map[string]*evm.EthVestingExpenseTracker
func (suite *EvmAnteTestSuite) TestCheckVesting() {
keyring := testkeyring.New(1)
unitNetwork := network.NewUnitTestNetwork(
network.WithChainID(suite.chainID),
network.WithPreFundedAccounts(keyring.GetAllAccAddrs()...),
)
grpcHandler := grpc.NewIntegrationHandler(unitNetwork)
Expand Down
6 changes: 1 addition & 5 deletions app/ante/evm/09_gas_consume.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
sdktypes "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
anteutils "github.com/evmos/evmos/v20/app/ante/utils"
"github.com/evmos/evmos/v20/types"
evmtypes "github.com/evmos/evmos/v20/x/evm/types"
)
Expand All @@ -35,10 +34,7 @@ func UpdateCumulativeGasWanted(
}

type ConsumeGasKeepers struct {
Bank anteutils.BankKeeper
Distribution anteutils.DistributionKeeper
Evm EVMKeeper
Staking anteutils.StakingKeeper
Evm EVMKeeper
}

// ConsumeFeesAndEmitEvent deduces fees from sender and emits the event
Expand Down
62 changes: 34 additions & 28 deletions app/ante/evm/09_gas_consume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
package evm_test

import (
"fmt"

"cosmossdk.io/math"
sdktypes "github.com/cosmos/cosmos-sdk/types"
evmante "github.com/evmos/evmos/v20/app/ante/evm"
"github.com/evmos/evmos/v20/testutil/integration/evmos/grpc"
testkeyring "github.com/evmos/evmos/v20/testutil/integration/evmos/keyring"
"github.com/evmos/evmos/v20/testutil/integration/evmos/network"
evmtypes "github.com/evmos/evmos/v20/x/evm/types"
)

func (suite *EvmAnteTestSuite) TestUpdateCumulativeGasWanted() {
keyring := testkeyring.New(1)
unitNetwork := network.NewUnitTestNetwork(
network.WithChainID(suite.chainID),
network.WithPreFundedAccounts(keyring.GetAllAccAddrs()...),
)

Expand Down Expand Up @@ -86,29 +90,28 @@ func (suite *EvmAnteTestSuite) TestUpdateCumulativeGasWanted() {
func (suite *EvmAnteTestSuite) TestConsumeGasAndEmitEvent() {
keyring := testkeyring.New(1)
unitNetwork := network.NewUnitTestNetwork(
network.WithChainID(suite.chainID),
network.WithPreFundedAccounts(keyring.GetAllAccAddrs()...),
)
grpcHandler := grpc.NewIntegrationHandler(unitNetwork)

testCases := []struct {
name string
expectedError string
fees sdktypes.Coins
feesAmt math.Int
getSender func() sdktypes.AccAddress
}{
{
name: "success: fees are zero and event emitted",
fees: sdktypes.Coins{},
name: "success: fees are zero and event emitted",
feesAmt: math.NewInt(0),
getSender: func() sdktypes.AccAddress {
// Return prefunded sender
return keyring.GetKey(0).AccAddr
},
},
{
name: "success: there are non zero fees, user has sufficient bank balances and event emitted",
fees: sdktypes.Coins{
sdktypes.NewCoin(unitNetwork.GetBaseDenom(), math.NewInt(1000)),
},
name: "success: there are non zero fees, user has sufficient bank balances and event emitted",
feesAmt: math.NewInt(1000),
getSender: func() sdktypes.AccAddress {
// Return prefunded sender
return keyring.GetKey(0).AccAddr
Expand All @@ -117,9 +120,7 @@ func (suite *EvmAnteTestSuite) TestConsumeGasAndEmitEvent() {
{
name: "fail: insufficient user balance, event is NOT emitted",
expectedError: "failed to deduct transaction costs from user balance",
fees: sdktypes.Coins{
sdktypes.NewCoin(unitNetwork.GetBaseDenom(), math.NewInt(1000)),
},
feesAmt: math.NewInt(1000),
getSender: func() sdktypes.AccAddress {
// Return unfunded account
index := keyring.AddKey()
Expand All @@ -129,24 +130,28 @@ func (suite *EvmAnteTestSuite) TestConsumeGasAndEmitEvent() {
}

for _, tc := range testCases {
suite.Run(tc.name, func() {
suite.Run(fmt.Sprintf("%v_%v_%v", evmtypes.GetTxTypeName(suite.ethTxType), suite.chainID, tc.name), func() {
keepers := &evmante.ConsumeGasKeepers{
Bank: unitNetwork.App.BankKeeper,
Distribution: unitNetwork.App.DistrKeeper,
Evm: unitNetwork.App.EvmKeeper,
Staking: unitNetwork.App.StakingKeeper,
Evm: unitNetwork.App.EvmKeeper,
}
sender := tc.getSender()
prevBalance, err := grpcHandler.GetAllBalances(
sender,
)

resp, err := grpcHandler.GetBalanceFromEVM(sender)
suite.Require().NoError(err)
prevBalance, ok := math.NewIntFromString(resp.Balance)
suite.Require().True(ok)

suite.Require().NoError(err)

evmDecimals := evmtypes.GetEVMCoinDecimals()
feesAmt := tc.feesAmt.Mul(evmDecimals.ConversionFactor())
fees := sdktypes.NewCoins(sdktypes.NewCoin(unitNetwork.GetBaseDenom(), feesAmt))

// Function under test
err = evmante.ConsumeFeesAndEmitEvent(
unitNetwork.GetContext(),
keepers,
tc.fees,
fees,
sender,
)

Expand All @@ -156,31 +161,32 @@ func (suite *EvmAnteTestSuite) TestConsumeGasAndEmitEvent() {

// Check events are not present
events := unitNetwork.GetContext().EventManager().Events()
suite.Require().Zero(len(events))
suite.Require().Zero(len(events), "required no events to be emitted")
} else {
suite.Require().NoError(err)

// Check fees are deducted
afterBalance, err := grpcHandler.GetAllBalances(
sender,
)
resp, err := grpcHandler.GetBalanceFromEVM(sender)
suite.Require().NoError(err)
expectedBalance := prevBalance.Balances.Sub(tc.fees...)
suite.Require().True(
expectedBalance.Equal(afterBalance.Balances),
)
afterBalance, ok := math.NewIntFromString(resp.Balance)
suite.Require().True(ok)

suite.Require().NoError(err)
expectedBalance := prevBalance.Sub(feesAmt)
suite.Require().True(expectedBalance.Equal(afterBalance), "expected different balance after fees deduction")

// Event to be emitted
expectedEvent := sdktypes.NewEvent(
sdktypes.EventTypeTx,
sdktypes.NewAttribute(sdktypes.AttributeKeyFee, tc.fees.String()),
sdktypes.NewAttribute(sdktypes.AttributeKeyFee, fees.String()),
)
// Check events are present
events := unitNetwork.GetContext().EventManager().Events()
suite.Require().NotZero(len(events))
suite.Require().Contains(
events,
expectedEvent,
"expected different events after fees deduction",
)
}

Expand Down
1 change: 1 addition & 0 deletions app/ante/evm/10_incremenet_sequence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
func (suite *EvmAnteTestSuite) TestIncrementSequence() {
keyring := testkeyring.New(1)
unitNetwork := network.NewUnitTestNetwork(
network.WithChainID(suite.chainID),
network.WithPreFundedAccounts(keyring.GetAllAccAddrs()...),
)
grpcHandler := grpc.NewIntegrationHandler(unitNetwork)
Expand Down
15 changes: 10 additions & 5 deletions app/ante/evm/11_gas_wanted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,30 @@
package evm_test

import (
"fmt"

storetypes "cosmossdk.io/store/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"

sdktypes "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/evmos/evmos/v20/app/ante/evm"
"github.com/evmos/evmos/v20/testutil/integration/evmos/factory"
"github.com/evmos/evmos/v20/testutil/integration/evmos/grpc"
testkeyring "github.com/evmos/evmos/v20/testutil/integration/evmos/keyring"
"github.com/evmos/evmos/v20/testutil/integration/evmos/network"
integrationutils "github.com/evmos/evmos/v20/testutil/integration/evmos/utils"
evmtypes "github.com/evmos/evmos/v20/x/evm/types"
)

func (suite *EvmAnteTestSuite) TestCheckGasWanted() {
keyring := testkeyring.New(1)
unitNetwork := network.NewUnitTestNetwork(
network.WithChainID(suite.chainID),
network.WithPreFundedAccounts(keyring.GetAllAccAddrs()...),
)
grpcHandler := grpc.NewIntegrationHandler(unitNetwork)
txFactory := factory.New(unitNetwork, grpcHandler)
commonGasLimit := uint64(100000)
commonGasLimit := uint64(100_000)

testCases := []struct {
name string
Expand Down Expand Up @@ -69,16 +73,17 @@ func (suite *EvmAnteTestSuite) TestCheckGasWanted() {
// Set basefee param to false
feeMarketParams, err := grpcHandler.GetFeeMarketParams()
suite.Require().NoError(err)

feeMarketParams.Params.NoBaseFee = true
err = integrationutils.UpdateFeeMarketParams(integrationutils.UpdateParamsInput{
Tf: txFactory,
Network: unitNetwork,
Pk: keyring.GetPrivKey(0),
Params: feeMarketParams.Params,
})
suite.Require().NoError(err)
suite.Require().NoError(err, "expected no error when updating fee market params")

blockMeter := storetypes.NewGasMeter(commonGasLimit + 10000)
blockMeter := storetypes.NewGasMeter(commonGasLimit + 10_000)
return unitNetwork.GetContext().WithBlockGasMeter(blockMeter)
},
isLondon: true,
Expand All @@ -87,7 +92,7 @@ func (suite *EvmAnteTestSuite) TestCheckGasWanted() {
}

for _, tc := range testCases {
suite.Run(tc.name, func() {
suite.Run(fmt.Sprintf("%v_%v_%v", evmtypes.GetTxTypeName(suite.ethTxType), suite.chainID, tc.name), func() {
sender := keyring.GetKey(0)
txArgs, err := txFactory.GenerateDefaultTxTypeArgs(
sender.Addr,
Expand Down
5 changes: 1 addition & 4 deletions app/ante/evm/eth_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ func BenchmarkEthGasConsumeDecorator(b *testing.B) {
cacheCtx = s.prepareAccount(cacheCtx, addr.Bytes(), tc.balance, tc.rewards)
s.Require().NoError(vmdb.Commit())
keepers := ethante.ConsumeGasKeepers{
Bank: s.GetNetwork().App.BankKeeper,
Distribution: s.GetNetwork().App.DistrKeeper,
Evm: s.GetNetwork().App.EvmKeeper,
Staking: s.GetNetwork().App.StakingKeeper,
Evm: s.GetNetwork().App.EvmKeeper,
}

baseFee := s.GetNetwork().App.FeeMarketKeeper.GetParams(ctx).BaseFee
Expand Down
5 changes: 1 addition & 4 deletions app/ante/evm/mono.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,7 @@ func (md MonoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne
err = ConsumeFeesAndEmitEvent(
ctx,
&ConsumeGasKeepers{
Bank: md.bankKeeper,
Distribution: md.distributionKeeper,
Evm: md.evmKeeper,
Staking: md.stakingKeeper,
Evm: md.evmKeeper,
},
msgFees,
from,
Expand Down
21 changes: 12 additions & 9 deletions app/ante/evm/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

gethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/evmos/evmos/v20/utils"
"github.com/stretchr/testify/suite"
)

Expand All @@ -15,16 +16,18 @@ type EvmAnteTestSuite struct {

// To make sure that every tests is run with all the tx types
ethTxType int
chainID string
}

func TestEvmAnteTestSuite(t *testing.T) {
suite.Run(t, &EvmAnteTestSuite{
ethTxType: gethtypes.DynamicFeeTxType,
})
suite.Run(t, &EvmAnteTestSuite{
ethTxType: gethtypes.LegacyTxType,
})
suite.Run(t, &EvmAnteTestSuite{
ethTxType: gethtypes.AccessListTxType,
})
txTypes := []int{gethtypes.DynamicFeeTxType, gethtypes.LegacyTxType, gethtypes.AccessListTxType}
chainIDs := []string{utils.MainnetChainID + "-1", utils.SixDecChainID + "-1"}
for _, txType := range txTypes {
for _, chainID := range chainIDs {
suite.Run(t, &EvmAnteTestSuite{
ethTxType: txType,
chainID: chainID,
})
}
}
}
Loading
Loading
0