diff --git a/x/evm/keeper/benchmark_test.go b/x/evm/keeper/benchmark_test.go index f08e044a..9264629b 100644 --- a/x/evm/keeper/benchmark_test.go +++ b/x/evm/keeper/benchmark_test.go @@ -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) @@ -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) diff --git a/x/evm/keeper/keeper_test.go b/x/evm/keeper/keeper_test.go index 599b9e3b..1138f19c 100644 --- a/x/evm/keeper/keeper_test.go +++ b/x/evm/keeper/keeper_test.go @@ -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) diff --git a/x/evm/keeper/state_transition_benchmark_test.go b/x/evm/keeper/state_transition_benchmark_test.go index 795f6ff5..5ab86a04 100644 --- a/x/evm/keeper/state_transition_benchmark_test.go +++ b/x/evm/keeper/state_transition_benchmark_test.go @@ -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()) @@ -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()) @@ -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()) @@ -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()) @@ -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()) @@ -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()) diff --git a/x/evm/keeper/statedb_benchmark_test.go b/x/evm/keeper/statedb_benchmark_test.go index 7245e2e6..bf141052 100644 --- a/x/evm/keeper/statedb_benchmark_test.go +++ b/x/evm/keeper/statedb_benchmark_test.go @@ -15,7 +15,7 @@ import ( func BenchmarkCreateAccountNew(b *testing.B) { suite := KeeperTestSuite{} - suite.SetupTest() + suite.SetupTestWithT(b) vmdb := suite.StateDB() b.ResetTimer() @@ -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() @@ -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) @@ -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() @@ -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() @@ -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")) @@ -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() @@ -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) @@ -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() @@ -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() @@ -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()