-
Notifications
You must be signed in to change notification settings - Fork 461
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
Added GnosisSpecProvider and gnosis_loads_properly test #5775
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -232,6 +232,47 @@ public void Chiado_loads_properly() | |
provider.GetSpec((1, ChiadoSpecProvider.ShanghaiTimestamp)).MaxInitCodeSize.Should().Be(2 * 24576L); | ||
} | ||
|
||
[Test] | ||
public void Gnosis_loads_properly() | ||
{ | ||
ChainSpecLoader loader = new(new EthereumJsonSerializer()); | ||
string path = Path.Combine(TestContext.CurrentContext.WorkDirectory, "../../../../Chains/gnosis.json"); | ||
ChainSpec chainSpec = loader.Load(File.ReadAllText(path)); | ||
|
||
ChainSpecBasedSpecProvider provider = new(chainSpec); | ||
GnosisSpecProvider gnosisSpecProvider = GnosisSpecProvider.Instance; | ||
|
||
List<ForkActivation> forkActivationsToTest = new() | ||
{ | ||
(ForkActivation)0, | ||
(ForkActivation)1, | ||
(ForkActivation)(GnosisSpecProvider.ConstantinopoleBlockNumber -1), | ||
(ForkActivation)(GnosisSpecProvider.ConstantinopoleBlockNumber), | ||
(ForkActivation)(GnosisSpecProvider.ConstantinopoleFixBlockNumber -1), | ||
(ForkActivation)(GnosisSpecProvider.ConstantinopoleFixBlockNumber), | ||
(ForkActivation)(GnosisSpecProvider.IstanbulBlockNumber -1), | ||
(ForkActivation)(GnosisSpecProvider.IstanbulBlockNumber), | ||
(ForkActivation)(GnosisSpecProvider.BerlinBlockNumber -1), | ||
(ForkActivation)(GnosisSpecProvider.BerlinBlockNumber), | ||
(ForkActivation)(GnosisSpecProvider.LondonBlockNumber -1), | ||
(ForkActivation)(GnosisSpecProvider.LondonBlockNumber), | ||
(1, GnosisSpecProvider.ShanghaiTimestamp - 1), | ||
(1, GnosisSpecProvider.ShanghaiTimestamp), | ||
(999_999_999, 999_999_999) // far in the future | ||
}; | ||
Comment on lines
+245
to
+262
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similarly to some extent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, it might be a bit harder though. Of course, doable ;) |
||
|
||
CompareSpecProviders(gnosisSpecProvider, provider, forkActivationsToTest, CompareSpecsOptions.IsGnosis); | ||
Assert.That(provider.TerminalTotalDifficulty, Is.EqualTo(GnosisSpecProvider.Instance.TerminalTotalDifficulty)); | ||
Assert.That(provider.ChainId, Is.EqualTo(BlockchainIds.Gnosis)); | ||
Assert.That(provider.NetworkId, Is.EqualTo(BlockchainIds.Gnosis)); | ||
|
||
provider.GetSpec((1, GnosisSpecProvider.ShanghaiTimestamp - 1)).MaxCodeSize.Should().Be(long.MaxValue); | ||
|
||
/* ToDo uncomment when we have gnosis shapella timestamp | ||
provider.GetSpec((1, GnosisSpecProvider.ShanghaiTimestamp)).MaxCodeSize.Should().Be(24576L); | ||
provider.GetSpec((1, GnosisSpecProvider.ShanghaiTimestamp)).MaxInitCodeSize.Should().Be(2 * 24576L);*/ | ||
} | ||
|
||
|
||
[Test] | ||
public void Mainnet_loads_properly() | ||
|
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,58 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Nethermind.Core; | ||
using Nethermind.Core.Specs; | ||
using Nethermind.Int256; | ||
using Nethermind.Specs.Forks; | ||
|
||
namespace Nethermind.Specs; | ||
|
||
public class GnosisSpecProvider : ISpecProvider | ||
{ | ||
private GnosisSpecProvider() { } | ||
|
||
public IReleaseSpec GetSpec(ForkActivation forkActivation) | ||
{ | ||
return forkActivation.BlockNumber switch | ||
{ | ||
< ConstantinopoleBlockNumber => GenesisSpec, | ||
< ConstantinopoleFixBlockNumber => Constantinople.Instance, | ||
< IstanbulBlockNumber => ConstantinopleFix.Instance, | ||
< BerlinBlockNumber => Istanbul.Instance, | ||
< LondonBlockNumber => Berlin.Instance, | ||
_ => forkActivation.Timestamp switch | ||
{ | ||
null or < ShanghaiTimestamp => London.Instance, | ||
_ => Shanghai.Instance | ||
} | ||
}; | ||
} | ||
|
||
public void UpdateMergeTransitionInfo(long? blockNumber, UInt256? terminalTotalDifficulty = null) | ||
{ | ||
if (blockNumber is not null) | ||
MergeBlockNumber = (ForkActivation)blockNumber; | ||
|
||
if (terminalTotalDifficulty is not null) | ||
TerminalTotalDifficulty = terminalTotalDifficulty; | ||
} | ||
|
||
public ForkActivation? MergeBlockNumber { get; private set; } | ||
public ulong TimestampFork => ShanghaiTimestamp; | ||
public UInt256? TerminalTotalDifficulty { get; private set; } = UInt256.Parse("8626000000000000000000058750000000000000000000"); | ||
public IReleaseSpec GenesisSpec => Byzantium.Instance; | ||
public long? DaoBlockNumber => null; | ||
public ulong NetworkId => BlockchainIds.Gnosis; | ||
public ulong ChainId => BlockchainIds.Gnosis; | ||
public ForkActivation[] TransitionActivations { get; } | ||
|
||
public const long ConstantinopoleBlockNumber = 1_604_400; | ||
public const long ConstantinopoleFixBlockNumber = 2_508_800; | ||
public const long IstanbulBlockNumber = 7_298_030; | ||
public const long BerlinBlockNumber = 16_101_500; | ||
public const long LondonBlockNumber = 19_040_000; | ||
public const ulong ShanghaiTimestamp = long.MaxValue; | ||
|
||
public static GnosisSpecProvider Instance { get; } = new(); | ||
} |
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.
This is used all over those test would be good to make it a method.
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.
agreed, will do in next PR