From 5e15c64d02224487bb5aa16850c52ffefe5f27ab Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 7 Jan 2022 21:04:16 +0800 Subject: [PATCH] fix: make gas estimation test reproducible (#890) Closes: #536 Solution: Use a fixed test account. The source of non-deterministic is tx's intrinsic gas is different according to different number of zeros in input data, so to make sure the gas number is reproducible, and the randomly generated test address is included in that. --- x/evm/keeper/keeper_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/x/evm/keeper/keeper_test.go b/x/evm/keeper/keeper_test.go index ed208e49..4973863a 100644 --- a/x/evm/keeper/keeper_test.go +++ b/x/evm/keeper/keeper_test.go @@ -72,9 +72,12 @@ type KeeperTestSuite struct { func (suite *KeeperTestSuite) DoSetupTest(t require.TestingT) { checkTx := false - // account key - priv, err := ethsecp256k1.GenerateKey() + // account key, use a constant account to keep unit test deterministic. + ecdsaPriv, err := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") require.NoError(t, err) + priv := ðsecp256k1.PrivKey{ + Key: crypto.FromECDSA(ecdsaPriv), + } suite.address = common.BytesToAddress(priv.PubKey().Address().Bytes()) suite.signer = tests.NewSigner(priv)