Skip to content

Commit 606a2ec

Browse files
svlachakissmartprogrammer93Copilot
authored andcommitted
Estimate Gas fix (#10559)
* Estimate Gas fix * format * format * test fix * Update src/Nethermind/Nethermind.Blockchain.Test/TransactionProcessorTests.cs * Update src/Nethermind/Nethermind.Evm.Test/Tracing/GasEstimationTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix shared method --------- Co-authored-by: Ahmad Bitar <33181301+smartprogrammer93@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent b51ad9f commit 606a2ec

File tree

3 files changed

+606
-24
lines changed

3 files changed

+606
-24
lines changed

src/Nethermind/Nethermind.Blockchain.Test/TransactionProcessorTests.cs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -466,40 +466,27 @@ public void Can_estimate_with_destroy_refund_and_below_intrinsic_pre_berlin()
466466
tracer.CalculateAdditionalGasRequired(tx, releaseSpec).Should().Be(24080);
467467
tracer.GasSpent.Should().Be(35228L);
468468
long estimate = estimator.Estimate(tx, block.Header, tracer, out string? err, 0);
469-
estimate.Should().Be(59307);
469+
estimate.Should().Be(54225);
470470
Assert.That(err, Is.Null);
471471

472472
ConfirmEnoughEstimate(tx, block, estimate);
473473
}
474474

475475
private void ConfirmEnoughEstimate(Transaction tx, Block block, long estimate)
476476
{
477-
CallOutputTracer outputTracer = new();
478-
tx.GasLimit = estimate;
479-
TestContext.Out.WriteLine(tx.GasLimit);
480-
481-
GethLikeTxMemoryTracer gethTracer = new(tx, GethTraceOptions.Default);
482477
var blkCtx = new BlockExecutionContext(block.Header, _specProvider.GetSpec(block.Header));
483-
_transactionProcessor.CallAndRestore(tx, blkCtx, gethTracer);
484-
string traceEnoughGas = new EthereumJsonSerializer().Serialize(gethTracer.BuildResult(), true);
485478

479+
CallOutputTracer outputTracer = new();
480+
tx.GasLimit = estimate;
486481
_transactionProcessor.CallAndRestore(tx, blkCtx, outputTracer);
487-
traceEnoughGas.Should().NotContain("OutOfGas");
482+
outputTracer.StatusCode.Should().Be(StatusCode.Success,
483+
$"transaction should succeed at the estimate ({estimate})");
488484

489485
outputTracer = new CallOutputTracer();
490486
tx.GasLimit = Math.Min(estimate - 1, estimate * 63 / 64);
491-
TestContext.Out.WriteLine(tx.GasLimit);
492-
493-
gethTracer = new GethLikeTxMemoryTracer(tx, GethTraceOptions.Default);
494-
_transactionProcessor.CallAndRestore(tx, blkCtx, gethTracer);
495-
496-
string traceOutOfGas = new EthereumJsonSerializer().Serialize(gethTracer.BuildResult(), true);
497-
TestContext.Out.WriteLine(traceOutOfGas);
498-
499487
_transactionProcessor.CallAndRestore(tx, blkCtx, outputTracer);
500-
501-
bool failed = traceEnoughGas.Contains("failed") || traceEnoughGas.Contains("OutOfGas");
502-
failed.Should().BeTrue();
488+
outputTracer.StatusCode.Should().Be(StatusCode.Failure,
489+
$"transaction should fail below the estimate ({tx.GasLimit})");
503490
}
504491

505492
[TestCase]

src/Nethermind/Nethermind.Blockchain/Tracing/EstimateGasTracer.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,14 @@ public void ReportActionError(EvmExceptionType exceptionType, long gasLeft)
149149

150150
public override void ReportOperationError(EvmExceptionType error)
151151
{
152-
OutOfGas |= error == EvmExceptionType.OutOfGas;
153-
154-
if (error == EvmExceptionType.Revert && _currentNestingLevel == 0)
152+
if (_currentNestingLevel == 0)
155153
{
156-
TopLevelRevert = true;
154+
OutOfGas |= error == EvmExceptionType.OutOfGas;
155+
156+
if (error == EvmExceptionType.Revert)
157+
{
158+
TopLevelRevert = true;
159+
}
157160
}
158161
}
159162

0 commit comments

Comments
 (0)