mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
internal/ethapi: update estimation tests with the error ratio
This commit is contained in:
parent
a0b41b670f
commit
cc3d58dbdf
2 changed files with 6 additions and 2 deletions
|
|
@ -51,6 +51,10 @@ import (
|
|||
"github.com/tyler-smith/go-bip39"
|
||||
)
|
||||
|
||||
// estimateGasErrorRatio is the amount of overestimation eth_estimateGas is
|
||||
// allowed to produce in order to speed up calculations.
|
||||
const estimateGasErrorRatio = 0.015
|
||||
|
||||
// EthereumAPI provides an API to access Ethereum related information.
|
||||
type EthereumAPI struct {
|
||||
b Backend
|
||||
|
|
@ -1193,7 +1197,7 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
|
|||
Chain: NewChainContext(ctx, b),
|
||||
Header: header,
|
||||
State: state,
|
||||
ErrorRatio: 0.015,
|
||||
ErrorRatio: estimateGasErrorRatio,
|
||||
}
|
||||
// Run the gas estimation andwrap any revertals into a custom return
|
||||
call, err := args.ToMessage(gasCap, header.BaseFee)
|
||||
|
|
|
|||
|
|
@ -735,7 +735,7 @@ func TestEstimateGas(t *testing.T) {
|
|||
t.Errorf("test %d: want no error, have %v", i, err)
|
||||
continue
|
||||
}
|
||||
if uint64(result) != tc.want {
|
||||
if float64(result) > float64(tc.want)*(1+estimateGasErrorRatio) {
|
||||
t.Errorf("test %d, result mismatch, have\n%v\n, want\n%v\n", i, uint64(result), tc.want)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue