imp(evm): define minimum GasUsed proportional to GasLimit (#1087)

* min gas denominator implementation

* update changelog

* modify MinGasDenominator type to sdk.Dec

* fix typo in comments

* add comments

* update comment

* refactor logic

* remove unnecesary test

* fix typo on proto

* rename param

* fix tests

* use truncate and run mod tidy

* comment to default value

* update changelog

* rename temporary gas used

* integration tests

* add migrations

* add default as var

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
crypto-facs
2022-05-25 13:52:34 +00:00
committed by GitHub
co-authored by Federico Kunze Küllmer
parent f06df8c265
commit c4417713fa
15 changed files with 364 additions and 129 deletions
+55
View File
@@ -837,3 +837,58 @@ func (s *IntegrationTestSuite) TestBatchETHTransactions() {
s.Require().Equal(accountNonce+uint64(i)+1, tx.Nonce())
}
}
func (s *IntegrationTestSuite) TestGasConsumptionOnNormalTransfer() {
testCases := []struct {
name string
gasLimit uint64
expectedGasUsed uint64
}{
{
"gas used is the same as gas limit",
21000,
21000,
},
{
"gas used is half of Gas limit",
70000,
35000,
},
{
"gas used is less than half of gasLimit",
30000,
21000,
},
}
recipient := common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec")
chainID, err := s.network.Validators[0].JSONRPCClient.ChainID(s.ctx)
s.Require().NoError(err)
from := common.BytesToAddress(s.network.Validators[0].Address)
for _, tc := range testCases {
s.Run(tc.name, func() {
nonce := s.getAccountNonce(from)
s.Require().NoError(err)
gasPrice := s.getGasPrice()
msgTx := evmtypes.NewTx(
chainID,
nonce,
&recipient,
nil,
tc.gasLimit,
gasPrice,
nil, nil,
nil,
nil,
)
msgTx.From = from.Hex()
err = msgTx.Sign(s.ethSigner, s.network.Validators[0].ClientCtx.Keyring)
s.Require().NoError(err)
err := s.network.Validators[0].JSONRPCClient.SendTransaction(s.ctx, msgTx.AsTransaction())
s.Require().NoError(err)
s.waitForTransaction()
receipt := s.expectSuccessReceipt(msgTx.AsTransaction().Hash())
s.Equal(receipt.GasUsed, tc.expectedGasUsed)
})
}
}