-
Notifications
You must be signed in to change notification settings - Fork 395
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
9 changed files
with
100 additions
and
13 deletions.
There are no files selected for viewing
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,60 @@ | ||
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using FluentAssertions; | ||
using Nethermind.Specs; | ||
using NUnit.Framework; | ||
using System; | ||
using Nethermind.Int256; | ||
using System.Linq; | ||
|
||
namespace Nethermind.Evm.Test; | ||
|
||
[TestFixture] | ||
public class Eip4844Tests : VirtualMachineTestsBase | ||
{ | ||
protected override long BlockNumber => MainnetSpecProvider.GrayGlacierBlockNumber; | ||
protected override ulong Timestamp => MainnetSpecProvider.ShardingForkBlockTimestamp; | ||
|
||
[TestCase(0, 0, Description = "Should return 0 when no hashes")] | ||
[TestCase(1, 1, Description = "Should return 0 when out of range")] | ||
[TestCase(2, 1, Description = "Should return 0 when way out of range")] | ||
[TestCase(0, 1, Description = "Should return hash, when exists")] | ||
[TestCase(1, 3, Description = "Should return hash, when exists")] | ||
public void Test_datahash_index_in_range(int index, int datahashesCount) | ||
{ | ||
byte[][] hashes = new byte[datahashesCount][]; | ||
for (int i = 0; i < datahashesCount; i++) | ||
{ | ||
hashes[i] = new byte[32]; | ||
for (int n = 0; n < datahashesCount; n++) | ||
{ | ||
hashes[i][n] = (byte)((i * 3 + 10 * 7) % 256); | ||
} | ||
} | ||
byte[] expectedOutput = datahashesCount > index ? hashes[index] : new byte[32]; | ||
|
||
// Cost of transaction call + PUSH1 x4 + MSTORE (entry cost + 1 memory cell used) | ||
const long GasCostOfCallingWrapper = GasCostOf.Transaction + GasCostOf.VeryLow * 5 + GasCostOf.Memory; | ||
|
||
byte[] code = Prepare.EvmCode | ||
.PushData(new UInt256((ulong)index)) | ||
.DATAHASH() | ||
.MSTORE(0) | ||
.Return(32, 0) | ||
.Done; | ||
|
||
TestAllTracerWithOutput result = Execute(BlockNumber, 50000, code, blobVersionedHashes: hashes, timestamp: Timestamp); | ||
|
||
result.StatusCode.Should().Be(StatusCode.Success); | ||
result.ReturnValue.SequenceEqual(expectedOutput); | ||
AssertGas(result, GasCostOfCallingWrapper + GasCostOf.DataHash); | ||
} | ||
|
||
protected override TestAllTracerWithOutput CreateTracer() | ||
{ | ||
TestAllTracerWithOutput tracer = base.CreateTracer(); | ||
tracer.IsTracingAccess = false; | ||
return tracer; | ||
} | ||
} |
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
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
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
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
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
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
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
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