-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
src/Nethermind/Nethermind.Evm.Test/FibonacciComputeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System.Diagnostics; | ||
using FluentAssertions; | ||
using Nethermind.Consensus.Tracing; | ||
using Nethermind.Evm.Tracing; | ||
using Nethermind.Evm.Tracing.GethStyle; | ||
using Nethermind.Evm.TransactionProcessing; | ||
using NUnit.Framework; | ||
|
||
namespace Nethermind.Evm.Test; | ||
|
||
public class FibonacciComputeTests : VirtualMachineTestsBase | ||
{ | ||
[Test] | ||
public void Run() | ||
{ | ||
byte[] data = [9, 255]; | ||
|
||
byte[] code = Prepare.EvmCode | ||
.PushData(data) | ||
.COMMENT("1st/2nd fib number") | ||
.PushData(0) | ||
.PushData(1) | ||
.COMMENT("MAINLOOP:") | ||
.JUMPDEST() | ||
.DUPx(3) | ||
.ISZERO() | ||
.PushData(26 + data.Length) | ||
.JUMPI() | ||
.COMMENT("fib step") | ||
.DUPx(2) | ||
.DUPx(2) | ||
.ADD() | ||
.SWAPx(2) | ||
.POP() | ||
.SWAPx(1) | ||
.COMMENT("decrement fib step counter") | ||
.SWAPx(2) | ||
.PushData(1) | ||
.SWAPx(1) | ||
.SUB() | ||
.SWAPx(2) | ||
.PushData(5 + data.Length).COMMENT("goto MAINLOOP") | ||
.JUMP() | ||
.COMMENT("CLEANUP:") | ||
.JUMPDEST() | ||
.SWAPx(2) | ||
.POP() | ||
.POP() | ||
.COMMENT("done: requested fib number is the only element on the stack!") | ||
.STOP() | ||
.Done; | ||
|
||
ITxTracer tracer = Debugger.IsAttached | ||
? new GethLikeTxMemoryTracer(GethTraceOptions.Default) | ||
: NullTxTracer.Instance; | ||
|
||
TransactionResult result = ExecuteWithTracer(code, tracer); | ||
result.Success.Should().BeTrue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters