-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix BeaconBlockRootHandler #7604
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
eef4fcb
Fix Eip4788 BeaconBlockRootHandler
yerke26 cb3fd59
Merge branch 'master' into fix/7594
yerke26 e6b5585
add BeaconBlockRootHandlerTests
yerke26 c8f0aba
pass worldState to BeaconBlockRootHandler constructor
yerke26 ad34ceb
revert tests
yerke26 f6c8001
Merge branch 'master' into fix/7594
yerke26 4e6fea9
fix Benchmarks
yerke26 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
156 changes: 156 additions & 0 deletions
156
src/Nethermind/Nethermind.Blockchain.Test/BeaconBlockRootHandlerTests.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,156 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Nethermind.Blockchain.BeaconBlockRoot; | ||
using Nethermind.Core; | ||
using Nethermind.Core.Crypto; | ||
using Nethermind.Core.Eip2930; | ||
using Nethermind.Core.Test.Builders; | ||
using Nethermind.Crypto; | ||
using Nethermind.Evm; | ||
using Nethermind.Evm.Tracing; | ||
using Nethermind.Evm.TransactionProcessing; | ||
using Nethermind.Int256; | ||
using Nethermind.Specs.Forks; | ||
using Nethermind.State; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace Nethermind.Blockchain.Test; | ||
|
||
public class BeaconBlockRootHandlerTests | ||
{ | ||
private BeaconBlockRootHandler _beaconBlockRootHandler; | ||
private ITransactionProcessor _transactionProcessor; | ||
private IWorldState _worldState; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
_worldState = Substitute.For<IWorldState>(); | ||
_transactionProcessor = Substitute.For<ITransactionProcessor>(); | ||
_beaconBlockRootHandler = new BeaconBlockRootHandler(_transactionProcessor); | ||
} | ||
|
||
[Test] | ||
public void Test_BeaconRootsAccessList_IsBeaconBlockRootAvailableFalse() | ||
{ | ||
BlockHeader header = Build.A.BlockHeader.WithNumber(1).WithParentBeaconBlockRoot(Hash256.Zero).TestObject; | ||
Block block = Build.A.Block.WithHeader(header).TestObject; | ||
_worldState.AccountExists(Arg.Any<Address>()).Returns(true); | ||
|
||
(Address? toAddress, AccessList? accessList) result = _beaconBlockRootHandler | ||
.BeaconRootsAccessList(block, Shanghai.Instance, _worldState); | ||
|
||
Assert.That(result.accessList, Is.Null); | ||
Assert.That(result.toAddress, Is.Null); | ||
} | ||
|
||
[Test] | ||
public void Test_BeaconRootsAccessList_HeaderIsGenesis() | ||
{ | ||
BlockHeader header = Build.A.BlockHeader.WithParentBeaconBlockRoot(Hash256.Zero).TestObject; | ||
Block block = Build.A.Block.WithHeader(header).TestObject; | ||
_worldState.AccountExists(Arg.Any<Address>()).Returns(true); | ||
|
||
(Address? toAddress, AccessList? accessList) result = _beaconBlockRootHandler | ||
.BeaconRootsAccessList(block, Cancun.Instance, _worldState); | ||
|
||
Assert.That(result.accessList, Is.Null); | ||
Assert.That(result.toAddress, Is.Null); | ||
} | ||
|
||
[Test] | ||
public void Test_BeaconRootsAccessList_ParentBeaconBlockRootIsNull() | ||
{ | ||
BlockHeader header = Build.A.BlockHeader.WithNumber(1).TestObject; | ||
Block block = Build.A.Block.WithHeader(header).TestObject; | ||
_worldState.AccountExists(Arg.Any<Address>()).Returns(true); | ||
|
||
(Address? toAddress, AccessList? accessList) result = _beaconBlockRootHandler | ||
.BeaconRootsAccessList(block, Cancun.Instance, _worldState); | ||
|
||
Assert.That(result.accessList, Is.Null); | ||
Assert.That(result.toAddress, Is.Null); | ||
} | ||
|
||
[Test] | ||
public void Test_BeaconRootsAccessList_canInsertBeaconRootIsTrue_AccountNotExist() | ||
{ | ||
BlockHeader header = Build.A.BlockHeader.WithNumber(1).WithParentBeaconBlockRoot(Hash256.Zero).TestObject; | ||
Block block = Build.A.Block.WithHeader(header).TestObject; | ||
_worldState.AccountExists(Arg.Any<Address>()).Returns(false); | ||
|
||
(Address? toAddress, AccessList? accessList) result = _beaconBlockRootHandler | ||
.BeaconRootsAccessList(block, Cancun.Instance, _worldState); | ||
|
||
Assert.That(result.accessList, Is.Null); | ||
Assert.That(result.toAddress, Is.Null); | ||
} | ||
|
||
[Test] | ||
public void Test_BeaconRootsAccessList_canInsertBeaconRootIsTrue_AccountExists() | ||
{ | ||
BlockHeader header = Build.A.BlockHeader.WithNumber(1).WithParentBeaconBlockRoot(Hash256.Zero).TestObject; | ||
Block block = Build.A.Block.WithHeader(header).TestObject; | ||
_worldState.AccountExists(Arg.Any<Address>()).Returns(true); | ||
|
||
(Address? toAddress, AccessList? accessList) result = _beaconBlockRootHandler | ||
.BeaconRootsAccessList(block, Cancun.Instance, _worldState); | ||
|
||
Assert.That(result.accessList, Is.Not.Null); | ||
Assert.That(result.accessList.Count.AddressesCount, Is.EqualTo(1)); | ||
Assert.That(result.accessList.Count.StorageKeysCount, Is.EqualTo(1)); | ||
} | ||
|
||
[Test] | ||
public void Test_BeaconRootsAccessList_canInsertBeaconRootIsTrue_AccountExists_IncludeStorageCellsIsFalse() | ||
{ | ||
BlockHeader header = Build.A.BlockHeader.WithNumber(1).WithParentBeaconBlockRoot(Hash256.Zero).TestObject; | ||
Block block = Build.A.Block.WithHeader(header).TestObject; | ||
_worldState.AccountExists(Arg.Any<Address>()).Returns(true); | ||
|
||
(Address? toAddress, AccessList? accessList) result = _beaconBlockRootHandler | ||
.BeaconRootsAccessList(block, Cancun.Instance, _worldState, false); | ||
|
||
Assert.That(result.accessList, Is.Not.Null); | ||
Assert.That(result.accessList.Count.AddressesCount, Is.EqualTo(1)); | ||
Assert.That(result.accessList.Count.StorageKeysCount, Is.EqualTo(0)); | ||
} | ||
|
||
[Test] | ||
public void Test_StoreBeaconRoot_AccessListIsNull() | ||
{ | ||
BlockHeader header = Build.A.BlockHeader.TestObject; | ||
Block block = Build.A.Block.WithHeader(header).TestObject; | ||
|
||
_beaconBlockRootHandler.StoreBeaconRoot(block, Cancun.Instance, _worldState); | ||
|
||
_transactionProcessor.DidNotReceive().Execute(Arg.Any<Transaction>(), Arg.Any<BlockExecutionContext>(), Arg.Any<ITxTracer>()); | ||
} | ||
|
||
[Test] | ||
public void Test_StoreBeaconRoot_AccessListNotNull() | ||
{ | ||
BlockHeader header = Build.A.BlockHeader.WithNumber(1).WithParentBeaconBlockRoot(Hash256.Zero).TestObject; | ||
Block block = Build.A.Block.WithHeader(header).TestObject; | ||
_worldState.AccountExists(Arg.Any<Address>()).Returns(true); | ||
|
||
_beaconBlockRootHandler.StoreBeaconRoot(block, Cancun.Instance, _worldState); | ||
|
||
Transaction transaction = new() | ||
{ | ||
Value = UInt256.Zero, | ||
Data = header.ParentBeaconBlockRoot!.Bytes.ToArray(), | ||
To = Eip4788Constants.BeaconRootsAddress, | ||
SenderAddress = Address.SystemUser, | ||
GasLimit = 30_000_000L, | ||
GasPrice = UInt256.Zero, | ||
AccessList = new AccessList.Builder().AddAddress(Eip4788Constants.BeaconRootsAddress).Build() | ||
}; | ||
|
||
transaction.Hash = transaction.CalculateHash(); | ||
_transactionProcessor.Received().Execute(Arg.Is<Transaction>(t => | ||
t.Hash == transaction.Hash), header, NullTxTracer.Instance); | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you pass StateProvider in constructor?