Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal authored and Stefan-Ethernal committed Feb 13, 2024
1 parent 4e072ff commit 77d2a31
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions state/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,9 @@ func (t *Transition) subGasLimitPrice(msg *types.Transaction) error {
balanceCheck := new(big.Int).Set(upfrontGasCost)
if msg.Type() == types.DynamicFeeTx {
balanceCheck.Add(balanceCheck, msg.Value())
balanceCheck.SetUint64(msg.Gas())
balanceCheck = balanceCheck.Mul(balanceCheck, msg.GasFeeCap())
balanceCheck.Add(balanceCheck, msg.Value())
}

if have, want := t.state.GetBalance(msg.From()), balanceCheck; have.Cmp(want) < 0 {
Expand Down
9 changes: 7 additions & 2 deletions state/transition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestSubGasLimitPrice(t *testing.T) {
gas: 10,
gasPrice: 10,
// should return ErrNotEnoughFundsForGas when state.SubBalance returns ErrNotEnoughFunds
expectedErr: ErrNotEnoughFundsForGas,
expectedErr: ErrInsufficientFunds,
},
}

Expand All @@ -78,7 +78,12 @@ func TestSubGasLimitPrice(t *testing.T) {

err := transition.subGasLimitPrice(msg)

assert.Equal(t, tt.expectedErr, err)
if tt.expectedErr != nil {
assert.ErrorContains(t, err, tt.expectedErr.Error())
} else {
assert.NoError(t, err)
}

if err == nil {
// should reduce cost for gas from balance
reducedAmount := new(big.Int).Mul(msg.GasPrice(), big.NewInt(int64(msg.Gas())))
Expand Down

0 comments on commit 77d2a31

Please sign in to comment.