Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
fix(tests): avoid error when run benchmark (#1573)
Browse files Browse the repository at this point in the history
* avoid error when run benchmark

* fix rest benchmark test

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
  • Loading branch information
mmsqe and fedekunze committed Dec 27, 2022
1 parent edddd9e commit 7b4c1d9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
4 changes: 2 additions & 2 deletions x/evm/keeper/benchmark_test.go
Expand Up @@ -18,7 +18,7 @@ import (

func SetupContract(b *testing.B) (*KeeperTestSuite, common.Address) {
suite := KeeperTestSuite{}
suite.SetupTest()
suite.SetupTestWithT(b)

amt := sdk.Coins{ethermint.NewPhotonCoinInt64(1000000000000000000)}
err := suite.app.BankKeeper.MintCoins(suite.ctx, types.ModuleName, amt)
Expand All @@ -34,7 +34,7 @@ func SetupContract(b *testing.B) (*KeeperTestSuite, common.Address) {

func SetupTestMessageCall(b *testing.B) (*KeeperTestSuite, common.Address) {
suite := KeeperTestSuite{}
suite.SetupTest()
suite.SetupTestWithT(b)

amt := sdk.Coins{ethermint.NewPhotonCoinInt64(1000000000000000000)}
err := suite.app.BankKeeper.MintCoins(suite.ctx, types.ModuleName, amt)
Expand Down
13 changes: 11 additions & 2 deletions x/evm/keeper/keeper_test.go
Expand Up @@ -93,9 +93,18 @@ func (suite *KeeperTestSuite) SetupTest() {
suite.SetupApp(checkTx)
}

// SetupApp setup test environment, it uses`require.TestingT` to support both `testing.T` and `testing.B`.
func (suite *KeeperTestSuite) SetupTestWithT(t require.TestingT) {
checkTx := false
suite.app = app.Setup(checkTx, nil)
suite.SetupAppWithT(checkTx, t)
}

func (suite *KeeperTestSuite) SetupApp(checkTx bool) {
t := suite.T()
suite.SetupAppWithT(checkTx, suite.T())
}

// SetupApp setup test environment, it uses`require.TestingT` to support both `testing.T` and `testing.B`.
func (suite *KeeperTestSuite) SetupAppWithT(checkTx bool, t require.TestingT) {
// account key, use a constant account to keep unit test deterministic.
ecdsaPriv, err := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
require.NoError(t, err)
Expand Down
12 changes: 6 additions & 6 deletions x/evm/keeper/state_transition_benchmark_test.go
Expand Up @@ -158,7 +158,7 @@ func newNativeMessage(

func BenchmarkApplyTransaction(b *testing.B) {
suite := KeeperTestSuite{enableLondonHF: true}
suite.SetupTest()
suite.SetupTestWithT(b)

ethSigner := ethtypes.LatestSignerForChainID(suite.app.EvmKeeper.ChainID())

Expand All @@ -185,7 +185,7 @@ func BenchmarkApplyTransaction(b *testing.B) {

func BenchmarkApplyTransactionWithLegacyTx(b *testing.B) {
suite := KeeperTestSuite{enableLondonHF: true}
suite.SetupTest()
suite.SetupTestWithT(b)

ethSigner := ethtypes.LatestSignerForChainID(suite.app.EvmKeeper.ChainID())

Expand All @@ -212,7 +212,7 @@ func BenchmarkApplyTransactionWithLegacyTx(b *testing.B) {

func BenchmarkApplyTransactionWithDynamicFeeTx(b *testing.B) {
suite := KeeperTestSuite{enableFeemarket: true, enableLondonHF: true}
suite.SetupTest()
suite.SetupTestWithT(b)

ethSigner := ethtypes.LatestSignerForChainID(suite.app.EvmKeeper.ChainID())

Expand All @@ -239,7 +239,7 @@ func BenchmarkApplyTransactionWithDynamicFeeTx(b *testing.B) {

func BenchmarkApplyMessage(b *testing.B) {
suite := KeeperTestSuite{enableLondonHF: true}
suite.SetupTest()
suite.SetupTestWithT(b)

params := suite.app.EvmKeeper.GetParams(suite.ctx)
ethCfg := params.ChainConfig.EthereumConfig(suite.app.EvmKeeper.ChainID())
Expand Down Expand Up @@ -274,7 +274,7 @@ func BenchmarkApplyMessage(b *testing.B) {

func BenchmarkApplyMessageWithLegacyTx(b *testing.B) {
suite := KeeperTestSuite{enableLondonHF: true}
suite.SetupTest()
suite.SetupTestWithT(b)

params := suite.app.EvmKeeper.GetParams(suite.ctx)
ethCfg := params.ChainConfig.EthereumConfig(suite.app.EvmKeeper.ChainID())
Expand Down Expand Up @@ -309,7 +309,7 @@ func BenchmarkApplyMessageWithLegacyTx(b *testing.B) {

func BenchmarkApplyMessageWithDynamicFeeTx(b *testing.B) {
suite := KeeperTestSuite{enableFeemarket: true, enableLondonHF: true}
suite.SetupTest()
suite.SetupTestWithT(b)

params := suite.app.EvmKeeper.GetParams(suite.ctx)
ethCfg := params.ChainConfig.EthereumConfig(suite.app.EvmKeeper.ChainID())
Expand Down
22 changes: 11 additions & 11 deletions x/evm/keeper/statedb_benchmark_test.go
Expand Up @@ -15,7 +15,7 @@ import (

func BenchmarkCreateAccountNew(b *testing.B) {
suite := KeeperTestSuite{}
suite.SetupTest()
suite.SetupTestWithT(b)
vmdb := suite.StateDB()

b.ResetTimer()
Expand All @@ -31,7 +31,7 @@ func BenchmarkCreateAccountNew(b *testing.B) {

func BenchmarkCreateAccountExisting(b *testing.B) {
suite := KeeperTestSuite{}
suite.SetupTest()
suite.SetupTestWithT(b)
vmdb := suite.StateDB()

b.ResetTimer()
Expand All @@ -44,7 +44,7 @@ func BenchmarkCreateAccountExisting(b *testing.B) {

func BenchmarkAddBalance(b *testing.B) {
suite := KeeperTestSuite{}
suite.SetupTest()
suite.SetupTestWithT(b)
vmdb := suite.StateDB()

amt := big.NewInt(10)
Expand All @@ -59,7 +59,7 @@ func BenchmarkAddBalance(b *testing.B) {

func BenchmarkSetCode(b *testing.B) {
suite := KeeperTestSuite{}
suite.SetupTest()
suite.SetupTestWithT(b)
vmdb := suite.StateDB()

hash := crypto.Keccak256Hash([]byte("code")).Bytes()
Expand All @@ -74,7 +74,7 @@ func BenchmarkSetCode(b *testing.B) {

func BenchmarkSetState(b *testing.B) {
suite := KeeperTestSuite{}
suite.SetupTest()
suite.SetupTestWithT(b)
vmdb := suite.StateDB()

hash := crypto.Keccak256Hash([]byte("topic")).Bytes()
Expand All @@ -89,7 +89,7 @@ func BenchmarkSetState(b *testing.B) {

func BenchmarkAddLog(b *testing.B) {
suite := KeeperTestSuite{}
suite.SetupTest()
suite.SetupTestWithT(b)
vmdb := suite.StateDB()

topic := crypto.Keccak256Hash([]byte("topic"))
Expand All @@ -116,7 +116,7 @@ func BenchmarkAddLog(b *testing.B) {

func BenchmarkSnapshot(b *testing.B) {
suite := KeeperTestSuite{}
suite.SetupTest()
suite.SetupTestWithT(b)
vmdb := suite.StateDB()

b.ResetTimer()
Expand All @@ -136,7 +136,7 @@ func BenchmarkSnapshot(b *testing.B) {

func BenchmarkSubBalance(b *testing.B) {
suite := KeeperTestSuite{}
suite.SetupTest()
suite.SetupTestWithT(b)
vmdb := suite.StateDB()

amt := big.NewInt(10)
Expand All @@ -151,7 +151,7 @@ func BenchmarkSubBalance(b *testing.B) {

func BenchmarkSetNonce(b *testing.B) {
suite := KeeperTestSuite{}
suite.SetupTest()
suite.SetupTestWithT(b)
vmdb := suite.StateDB()

b.ResetTimer()
Expand All @@ -164,7 +164,7 @@ func BenchmarkSetNonce(b *testing.B) {

func BenchmarkAddRefund(b *testing.B) {
suite := KeeperTestSuite{}
suite.SetupTest()
suite.SetupTestWithT(b)
vmdb := suite.StateDB()

b.ResetTimer()
Expand All @@ -177,7 +177,7 @@ func BenchmarkAddRefund(b *testing.B) {

func BenchmarkSuicide(b *testing.B) {
suite := KeeperTestSuite{}
suite.SetupTest()
suite.SetupTestWithT(b)
vmdb := suite.StateDB()

b.ResetTimer()
Expand Down

0 comments on commit 7b4c1d9

Please sign in to comment.