fix(tests): avoid error when run benchmark (#1573)

* avoid error when run benchmark

* fix rest benchmark test

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
mmsqe 2022-12-28 01:59:33 +08:00 committed by GitHub
parent edddd9eac6
commit 7b4c1d9ae6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 21 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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())

View File

@ -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()