Skip to content

Commit

Permalink
address coderabbit comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MalteHerrmann committed Sep 24, 2024
1 parent c4ea4b5 commit 0d60901
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 36 deletions.
1 change: 1 addition & 0 deletions ante/evm/fee_market_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func (suite *AnteTestSuite) TestGasWantedDecorator() {
expectedGasWanted += tc.expectedGasWanted
suite.Require().Equal(expectedGasWanted, gasWanted)
} else {
// TODO: check for specific error message
suite.Require().Error(err)
}
})
Expand Down
2 changes: 1 addition & 1 deletion ante/evm/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (suite *AnteTestSuite) CreateTestEIP712MsgCreateValidator2(from sdk.AccAddr
privEd.PubKey(),
sdk.NewCoin(suite.GetNetwork().GetDenom(), sdkmath.NewInt(20)),
// Ensure optional fields can be left blank
stakingtypes.NewDescription("moniker", "indentity", "", "", ""),
stakingtypes.NewDescription("moniker", "identity", "", "", ""),
stakingtypes.NewCommissionRates(sdkmath.LegacyOneDec(), sdkmath.LegacyOneDec(), sdkmath.LegacyOneDec()),
sdkmath.OneInt(),
)
Expand Down
13 changes: 6 additions & 7 deletions example_chain/ante/evm_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math/big"
"testing"

"cosmossdk.io/errors"
"cosmossdk.io/math"
sdktypes "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand Down Expand Up @@ -58,11 +59,12 @@ var table = []struct {
}

func BenchmarkAnteHandler(b *testing.B) {
keyring := testkeyring.New(2)

for _, v := range table {
// Reset chain on every tx type to have a clean state
// and a fair benchmark
b.StopTimer()
keyring := testkeyring.New(2)
unitNetwork := network.NewUnitTestNetwork(
network.WithPreFundedAccounts(keyring.GetAllAccAddrs()...),
)
Expand All @@ -85,24 +87,21 @@ func BenchmarkAnteHandler(b *testing.B) {
b.StopTimer()
// Start with a clean block
if err := unitNetwork.NextBlock(); err != nil {
fmt.Println(err)
break
b.Fatal(errors.Wrap(err, "failed to create block"))
}
ctx := unitNetwork.GetContext()

// Generate fresh tx type
tx, err := suite.generateTxType(v.txType)
if err != nil {
fmt.Println(err)
break
b.Fatal(errors.Wrap(err, "failed to generate tx type"))
}
b.StartTimer()

// Run benchmark
_, err = ante(ctx, tx, v.simulate)
if err != nil {
fmt.Println(err)
break
b.Fatal(errors.Wrap(err, "failed to run ante handler"))
}
}
})
Expand Down
4 changes: 4 additions & 0 deletions example_chain/ante/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/evmos/os/testutil/integration/os/network"
integrationutils "github.com/evmos/os/testutil/integration/os/utils"
testutiltx "github.com/evmos/os/testutil/tx"

//nolint:revive // dot imports are fine for Ginkgo
. "github.com/onsi/ginkgo/v2"
//nolint:revive // dot imports are fine for Ginkgo
Expand Down Expand Up @@ -86,6 +87,7 @@ var _ = Describe("when sending a Cosmos transaction", Label("AnteHandler"), Orde

baseFeeRes, err := s.grpcHandler.GetBaseFee()
Expect(err).To(BeNil())
Expect(baseFeeRes).ToNot(BeNil(), "baseFeeRes is nil")

res, err := s.factory.ExecuteCosmosTx(
priv,
Expand All @@ -102,6 +104,8 @@ var _ = Describe("when sending a Cosmos transaction", Label("AnteHandler"), Orde
Expect(err).To(BeNil())

// fees should be deducted from balance
Expect(baseFeeRes.BaseFee).ToNot(BeNil(), "baseFeeRes.BaseFee is nil")

feesAmt := sdkmath.NewInt(res.GasWanted).Mul(*baseFeeRes.BaseFee)
balanceRes, err := s.grpcHandler.GetBalance(addr, s.network.GetDenom())
Expect(err).To(BeNil())
Expand Down
6 changes: 3 additions & 3 deletions precompiles/bank/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/evmos/os/precompiles/bank"
"github.com/evmos/os/precompiles/bank/testdata"
"github.com/evmos/os/precompiles/testutil"
evmostestutil "github.com/evmos/os/testutil/constants"
testconstants "github.com/evmos/os/testutil/constants"
"github.com/evmos/os/testutil/integration/os/factory"
"github.com/evmos/os/testutil/integration/os/grpc"
"github.com/evmos/os/testutil/integration/os/keyring"
Expand Down Expand Up @@ -187,7 +187,7 @@ var _ = Describe("Bank Extension -", func() {
err = is.precompile.UnpackIntoInterface(&balances, bank.BalancesMethod, ethRes.Ret)
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")

balanceAfter, err := is.grpcHandler.GetBalance(receiver.Bytes(), evmostestutil.ExampleAttoDenom)
balanceAfter, err := is.grpcHandler.GetBalance(receiver.Bytes(), testconstants.ExampleAttoDenom)
Expect(err).ToNot(HaveOccurred(), "failed to get balance")

Expect(math.NewInt(balances[0].Amount.Int64())).To(Equal(balanceAfter.Balance.Amount))
Expand Down Expand Up @@ -330,7 +330,7 @@ var _ = Describe("Bank Extension -", func() {
err = is.precompile.UnpackIntoInterface(&balances, bank.BalancesMethod, ethRes.Ret)
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")

balanceAfter, err := is.grpcHandler.GetBalance(receiver.Bytes(), evmostestutil.ExampleAttoDenom)
balanceAfter, err := is.grpcHandler.GetBalance(receiver.Bytes(), testconstants.ExampleAttoDenom)
Expect(err).ToNot(HaveOccurred(), "failed to get balance")

Expect(math.NewInt(balances[0].Amount.Int64())).To(Equal(balanceAfter.Balance.Amount))
Expand Down
4 changes: 2 additions & 2 deletions precompiles/distribution/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/evmos/os/precompiles/staking"
"github.com/evmos/os/precompiles/testutil"
"github.com/evmos/os/precompiles/testutil/contracts"
evmostestutil "github.com/evmos/os/testutil/constants"
testconstants "github.com/evmos/os/testutil/constants"
"github.com/evmos/os/testutil/integration/os/factory"
testutils "github.com/evmos/os/testutil/integration/os/utils"
testutiltx "github.com/evmos/os/testutil/tx"
Expand Down Expand Up @@ -50,7 +50,7 @@ var (
txArgs evmtypes.EvmTxArgs
// minExpRewardOrCommission is the minimun coins expected for validator's rewards or commission
// required for the tests
minExpRewardOrCommission = sdk.NewDecCoins(sdk.NewDecCoin(evmostestutil.ExampleAttoDenom, testRewardsAmt))
minExpRewardOrCommission = sdk.NewDecCoins(sdk.NewDecCoin(testconstants.ExampleAttoDenom, testRewardsAmt))
)

func TestPrecompileIntegrationTestSuite(t *testing.T) {
Expand Down
32 changes: 16 additions & 16 deletions precompiles/distribution/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"math/big"

evmostestutil "github.com/evmos/os/testutil/constants"
testconstants "github.com/evmos/os/testutil/constants"

"cosmossdk.io/math"
"github.com/evmos/os/precompiles/testutil"
Expand Down Expand Up @@ -198,10 +198,10 @@ func (s *PrecompileTestSuite) TestWithdrawDelegatorRewards() {
var coins []cmn.Coin
err := s.precompile.UnpackIntoInterface(&coins, distribution.WithdrawDelegatorRewardsMethod, data)
s.Require().NoError(err, "failed to unpack output")
s.Require().Equal(coins[0].Denom, evmostestutil.ExampleAttoDenom)
s.Require().Equal(coins[0].Denom, testconstants.ExampleAttoDenom)
s.Require().Equal(coins[0].Amount.Int64(), expRewardsAmt.Int64())
// Check bank balance after the withdrawal of rewards
balance := s.network.App.BankKeeper.GetBalance(ctx, s.keyring.GetAddr(0).Bytes(), evmostestutil.ExampleAttoDenom)
balance := s.network.App.BankKeeper.GetBalance(ctx, s.keyring.GetAddr(0).Bytes(), testconstants.ExampleAttoDenom)
s.Require().True(balance.Amount.GT(network.PrefundedAccountInitialBalance))
},
20000,
Expand Down Expand Up @@ -274,14 +274,14 @@ func (s *PrecompileTestSuite) TestWithdrawValidatorCommission() {
valAddr, err := sdk.ValAddressFromBech32(operatorAddress)
s.Require().NoError(err)
amt := math.LegacyNewDecWithPrec(1000000000000000000, 1)
valCommission := sdk.DecCoins{sdk.NewDecCoinFromDec(evmostestutil.ExampleAttoDenom, amt)}
valCommission := sdk.DecCoins{sdk.NewDecCoinFromDec(testconstants.ExampleAttoDenom, amt)}
// set outstanding rewards
s.Require().NoError(s.network.App.DistrKeeper.SetValidatorOutstandingRewards(ctx, valAddr, types.ValidatorOutstandingRewards{Rewards: valCommission}))
// set commission
s.Require().NoError(s.network.App.DistrKeeper.SetValidatorAccumulatedCommission(ctx, valAddr, types.ValidatorAccumulatedCommission{Commission: valCommission}))

// fund distr mod to pay for rewards + commission
coins := sdk.NewCoins(sdk.NewCoin(evmostestutil.ExampleAttoDenom, amt.Mul(math.LegacyNewDec(2)).RoundInt()))
coins := sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, amt.Mul(math.LegacyNewDec(2)).RoundInt()))
err = s.mintCoinsForDistrMod(ctx, coins)
s.Require().NoError(err)
return []interface{}{
Expand All @@ -293,15 +293,15 @@ func (s *PrecompileTestSuite) TestWithdrawValidatorCommission() {
amt := math.NewInt(100000000000000000)
err := s.precompile.UnpackIntoInterface(&coins, distribution.WithdrawValidatorCommissionMethod, data)
s.Require().NoError(err, "failed to unpack output")
s.Require().Equal(coins[0].Denom, evmostestutil.ExampleAttoDenom)
s.Require().Equal(coins[0].Denom, testconstants.ExampleAttoDenom)
s.Require().Equal(coins[0].Amount, amt.BigInt())

// Check bank balance after the withdrawal of commission
valAddr, err := sdk.ValAddressFromBech32(s.network.GetValidators()[0].GetOperator())
s.Require().NoError(err)
balance := s.network.App.BankKeeper.GetBalance(ctx, valAddr.Bytes(), evmostestutil.ExampleAttoDenom)
balance := s.network.App.BankKeeper.GetBalance(ctx, valAddr.Bytes(), testconstants.ExampleAttoDenom)
s.Require().Equal(balance.Amount, prevBalance.Amount.Add(amt))
s.Require().Equal(balance.Denom, evmostestutil.ExampleAttoDenom)
s.Require().Equal(balance.Denom, testconstants.ExampleAttoDenom)
},
20000,
false,
Expand All @@ -317,7 +317,7 @@ func (s *PrecompileTestSuite) TestWithdrawValidatorCommission() {
valAddr, err := sdk.ValAddressFromBech32(s.network.GetValidators()[0].GetOperator())
s.Require().NoError(err)

prevBalance = s.network.App.BankKeeper.GetBalance(ctx, valAddr.Bytes(), evmostestutil.ExampleAttoDenom)
prevBalance = s.network.App.BankKeeper.GetBalance(ctx, valAddr.Bytes(), testconstants.ExampleAttoDenom)

validatorAddress := common.BytesToAddress(valAddr.Bytes())
var contract *vm.Contract
Expand Down Expand Up @@ -408,7 +408,7 @@ func (s *PrecompileTestSuite) TestClaimRewards() {
}
},
func(_ []byte) {
balance := s.network.App.BankKeeper.GetBalance(ctx, s.keyring.GetAccAddr(0), evmostestutil.ExampleAttoDenom)
balance := s.network.App.BankKeeper.GetBalance(ctx, s.keyring.GetAccAddr(0), testconstants.ExampleAttoDenom)
// rewards from 3 validators - 5% commission
expRewards := expRewardsAmt.Mul(math.NewInt(3))
s.Require().Equal(balance.Amount, prevBalance.Amount.Add(expRewards))
Expand All @@ -426,7 +426,7 @@ func (s *PrecompileTestSuite) TestClaimRewards() {
}
},
func([]byte) {
balance := s.network.App.BankKeeper.GetBalance(ctx, s.keyring.GetAccAddr(0), evmostestutil.ExampleAttoDenom)
balance := s.network.App.BankKeeper.GetBalance(ctx, s.keyring.GetAccAddr(0), testconstants.ExampleAttoDenom)
// rewards from 3 validators - 5% commission
expRewards := expRewardsAmt.Mul(math.NewInt(3))
s.Require().Equal(balance.Amount, prevBalance.Amount.Add(expRewards))
Expand All @@ -444,7 +444,7 @@ func (s *PrecompileTestSuite) TestClaimRewards() {
}
},
func([]byte) {
balance := s.network.App.BankKeeper.GetBalance(ctx, s.keyring.GetAccAddr(0), evmostestutil.ExampleAttoDenom)
balance := s.network.App.BankKeeper.GetBalance(ctx, s.keyring.GetAccAddr(0), testconstants.ExampleAttoDenom)
s.Require().Equal(balance.Amount, prevBalance.Amount.Add(expRewardsAmt))
},
20000,
Expand Down Expand Up @@ -479,7 +479,7 @@ func (s *PrecompileTestSuite) TestClaimRewards() {
s.Require().NoError(err)

// get previous balance to compare final balance in the postCheck func
prevBalance = s.network.App.BankKeeper.GetBalance(ctx, addr.Bytes(), evmostestutil.ExampleAttoDenom)
prevBalance = s.network.App.BankKeeper.GetBalance(ctx, addr.Bytes(), testconstants.ExampleAttoDenom)

bz, err := s.precompile.ClaimRewards(ctx, addr, contract, s.network.GetStateDB(), &method, tc.malleate())

Expand Down Expand Up @@ -541,8 +541,8 @@ func (s *PrecompileTestSuite) TestFundCommunityPool() {
s.Require().NoError(err)
coins := pool.CommunityPool
expectedAmount := new(big.Int).Mul(big.NewInt(1e18), new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(math.LegacyPrecision)), nil))
s.Require().Equal(expectedAmount, coins.AmountOf(evmostestutil.ExampleAttoDenom).BigInt())
userBalance := s.network.App.BankKeeper.GetBalance(ctx, s.keyring.GetAddr(0).Bytes(), evmostestutil.ExampleAttoDenom)
s.Require().Equal(expectedAmount, coins.AmountOf(testconstants.ExampleAttoDenom).BigInt())
userBalance := s.network.App.BankKeeper.GetBalance(ctx, s.keyring.GetAddr(0).Bytes(), testconstants.ExampleAttoDenom)
s.Require().Equal(network.PrefundedAccountInitialBalance.Sub(math.NewInt(1e18)), userBalance.Amount)
},
20000,
Expand All @@ -560,7 +560,7 @@ func (s *PrecompileTestSuite) TestFundCommunityPool() {
contract, ctx = testutil.NewPrecompileContract(s.T(), ctx, s.keyring.GetAddr(0), s.precompile, tc.gas)

// Sanity check to make sure the starting balance is always 100k EVMOS
balance := s.network.App.BankKeeper.GetBalance(ctx, s.keyring.GetAddr(0).Bytes(), evmostestutil.ExampleAttoDenom)
balance := s.network.App.BankKeeper.GetBalance(ctx, s.keyring.GetAddr(0).Bytes(), testconstants.ExampleAttoDenom)
s.Require().Equal(balance.Amount, network.PrefundedAccountInitialBalance)

bz, err := s.precompile.FundCommunityPool(ctx, s.keyring.GetAddr(0), contract, s.network.GetStateDB(), &method, tc.malleate())
Expand Down
2 changes: 1 addition & 1 deletion rpc/backend/node_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (suite *BackendTestSuite) TestSetEtherbase() {
// queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
// RegisterStatus(client)
// RegisterValidatorAccount(queryClient, suite.acc)
// c := sdk.NewDecCoin(testutil.ExampleAttoDenom, math.NewIntFromBigInt(big.NewInt(1)))
// c := sdk.NewDecCoin(testconstants.ExampleAttoDenom, math.NewIntFromBigInt(big.NewInt(1)))
// suite.backend.cfg.SetMinGasPrices(sdk.DecCoins{c})
// delAddr, _ := suite.backend.GetCoinbase()
// account, _ := suite.backend.clientCtx.AccountRetriever.GetAccount(suite.backend.clientCtx, delAddr)
Expand Down
2 changes: 1 addition & 1 deletion testutil/integration/os/utils/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func CheckBalances(ctx context.Context, client banktypes.QueryClient, balances [
return err
}

if !balance.Balance.IsEqual(coin) {
if !balance.Balance.Equal(coin) {
return fmt.Errorf(
"expected balance %s, got %s for address %s",
coin, balance.Balance, addr,
Expand Down
6 changes: 3 additions & 3 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"testing"
"time"

evmostestutil "github.com/evmos/os/testutil/constants"
testconstants "github.com/evmos/os/testutil/constants"

"cosmossdk.io/log"
"cosmossdk.io/math"
Expand Down Expand Up @@ -121,7 +121,7 @@ func DefaultConfig() Config {
ChainID: chainID,
NumValidators: 4,
BondDenom: "aevmos",
MinGasPrices: fmt.Sprintf("0.000006%s", evmostestutil.ExampleAttoDenom),
MinGasPrices: fmt.Sprintf("0.000006%s", testconstants.ExampleAttoDenom),
AccountTokens: sdk.TokensFromConsensusPower(1000000000000000000, evmostypes.AttoPowerReduction),
StakingTokens: sdk.TokensFromConsensusPower(500000000000000000, evmostypes.AttoPowerReduction),
BondedTokens: sdk.TokensFromConsensusPower(100000000000000000, evmostypes.AttoPowerReduction),
Expand Down Expand Up @@ -476,7 +476,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
return nil, err
}

customAppTemplate, _ := chaincmd.InitAppConfig(evmostestutil.ExampleAttoDenom)
customAppTemplate, _ := chaincmd.InitAppConfig(testconstants.ExampleAttoDenom)
srvconfig.SetConfigTemplate(customAppTemplate)
srvconfig.WriteConfigFile(filepath.Join(nodeDir, "config/app.toml"), appCfg)

Expand Down
4 changes: 2 additions & 2 deletions testutil/tx/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"encoding/json"
"math/big"

evmostestutil "github.com/evmos/os/testutil/constants"
testconstants "github.com/evmos/os/testutil/constants"

errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
Expand Down Expand Up @@ -57,7 +57,7 @@ func PrepareEthTx(
msg.From = ""

txGasLimit += msg.GetGas()
txFee = txFee.Add(sdk.Coin{Denom: evmostestutil.ExampleAttoDenom, Amount: sdkmath.NewIntFromBigInt(msg.GetFee())})
txFee = txFee.Add(sdk.Coin{Denom: testconstants.ExampleAttoDenom, Amount: sdkmath.NewIntFromBigInt(msg.GetFee())})
}

if err := txBuilder.SetMsgs(msgs...); err != nil {
Expand Down

0 comments on commit 0d60901

Please sign in to comment.