Skip to content

Commit

Permalink
One more balance fix (#3241)
Browse files Browse the repository at this point in the history
* One more balance fix

* fix test

* fix test
  • Loading branch information
MarekM25 authored Jul 22, 2021
1 parent 5f4ee51 commit e45db5f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,23 @@ public static IEnumerable ProperTransactionsSelectedTestCases
GasLimit = 10000000
};
yield return new TestCaseData(balanceBelowMaxFeeTimesGasLimit).SetName("EIP1559 transactions: none transactions selected because balance is lower than MaxFeePerGas times GasLimit");

ProperTransactionsSelectedTestCase balanceFailingWithMaxFeePerGasCheck =
new ProperTransactionsSelectedTestCase()
{
Eip1559Enabled = true,
BaseFee = 5,
AccountStates = {{TestItem.AddressA, (400, 1)}},
Transactions =
{
Build.A.Transaction.WithSenderAddress(TestItem.AddressA).WithNonce(1)
.WithMaxFeePerGas(300).WithMaxPriorityFeePerGas(10).WithGasLimit(10)
.WithType(TxType.EIP1559).WithValue(101).SignedAndResolved(TestItem.PrivateKeyA)
.TestObject,
},
GasLimit = 10000000
};
yield return new TestCaseData(balanceFailingWithMaxFeePerGasCheck).SetName("EIP1559 transactions: None transactions selected - sender balance and max fee per gas check");
}
}

Expand All @@ -196,6 +213,7 @@ public void Proper_transactions_selected(ProperTransactionsSelectedTestCase test
{
IsEip1559Enabled = testCase.Eip1559Enabled
};
specProvider.GetSpec(Arg.Any<long>()).Returns(spec);

ITransactionProcessor transactionProcessor = Substitute.For<ITransactionProcessor>();
transactionProcessor.When(t => t.BuildUp(Arg.Any<Transaction>(), Arg.Any<BlockHeader>(), Arg.Any<ITxTracer>()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private bool HasEnoughFounds(Transaction transaction, UInt256 senderBalance, Add
return false;
}

if (transaction.IsEip1559 && !transaction.IsServiceTransaction && senderBalance < (UInt256)transaction.GasLimit * transaction.MaxFeePerGas)
if (eip1559Enabled && !transaction.IsServiceTransaction && senderBalance < (UInt256)transaction.GasLimit * transaction.MaxFeePerGas + transaction.Value)
{
e.Set(TxAction.Skip, $"MaxFeePerGas ({transaction.MaxFeePerGas}) times GasLimit {transaction.GasLimit} is higher than sender balance ({senderBalance})");
return false;
Expand Down

0 comments on commit e45db5f

Please sign in to comment.