accounts/abi: return detail insufficient error in simulate tx

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2023-09-20 09:27:35 +08:00
parent 30d5d7c1b3
commit 7c6d721564

View file

@ -531,11 +531,11 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs
if feeCap.BitLen() != 0 { if feeCap.BitLen() != 0 {
balance := b.pendingState.GetBalance(call.From) // from can't be nil balance := b.pendingState.GetBalance(call.From) // from can't be nil
available := new(big.Int).Set(balance) available := new(big.Int).Set(balance)
if call.Value != nil { if value := call.Value; value != nil {
if call.Value.Cmp(available) >= 0 { if value.Cmp(available) >= 0 {
return 0, core.ErrInsufficientFundsForTransfer return 0, fmt.Errorf("%w: address: %s, have: %v, want: %v", core.ErrInsufficientFundsForTransfer, call.From, available, value)
} }
available.Sub(available, call.Value) available.Sub(available, value)
} }
allowance := new(big.Int).Div(available, feeCap) allowance := new(big.Int).Div(available, feeCap)
if allowance.IsUint64() && hi > allowance.Uint64() { if allowance.IsUint64() && hi > allowance.Uint64() {