From 18ce8a2a0f4ec11248f8b21e8e7e9efe2a55631c Mon Sep 17 00:00:00 2001 From: Nikita Mescheryakov Date: Tue, 22 Oct 2024 17:29:26 +0300 Subject: [PATCH] Fix tests --- .../Nethermind.AuRa.Test/AuRaPluginTests.cs | 5 +- .../Nethermind.Ethash.Test/ChainSpecTest.cs | 216 ++++++++++++++++++ .../AuRaMergeEngineModuleTests.cs | 14 +- .../MergePluginTests.cs | 7 +- .../ChainSpecBasedSpecProviderTests.cs | 210 +---------------- .../TestChainSpecParametersProvider.cs | 19 +- .../ChainSpecBasedSpecProvider.cs | 2 +- 7 files changed, 254 insertions(+), 219 deletions(-) create mode 100644 src/Nethermind/Nethermind.Ethash.Test/ChainSpecTest.cs diff --git a/src/Nethermind/Nethermind.AuRa.Test/AuRaPluginTests.cs b/src/Nethermind/Nethermind.AuRa.Test/AuRaPluginTests.cs index 03c84f9b2b8..747d84f2a30 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/AuRaPluginTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/AuRaPluginTests.cs @@ -10,6 +10,7 @@ using Nethermind.Logging; using Nethermind.Serialization.Json; using Nethermind.Specs.ChainSpecStyle; +using Nethermind.Specs.Test.ChainSpecStyle; using NUnit.Framework; namespace Nethermind.AuRa.Test @@ -20,7 +21,9 @@ public class AuRaPluginTests public void Init_when_not_AuRa_doesnt_trow() { AuRaPlugin auRaPlugin = new(); - Action init = () => auRaPlugin.Init(new AuRaNethermindApi(new ConfigProvider(), new EthereumJsonSerializer(), new TestLogManager(), new ChainSpec())); + ChainSpec chainSpec = new(); + chainSpec.EngineChainSpecParametersProvider = new TestChainSpecParametersProvider(new AuthorityRoundChainSpecEngineParameters()); + Action init = () => auRaPlugin.Init(new AuRaNethermindApi(new ConfigProvider(), new EthereumJsonSerializer(), new TestLogManager(), chainSpec)); init.Should().NotThrow(); } diff --git a/src/Nethermind/Nethermind.Ethash.Test/ChainSpecTest.cs b/src/Nethermind/Nethermind.Ethash.Test/ChainSpecTest.cs new file mode 100644 index 00000000000..5170afe2f45 --- /dev/null +++ b/src/Nethermind/Nethermind.Ethash.Test/ChainSpecTest.cs @@ -0,0 +1,216 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System; +using System.Collections.Generic; +using FluentAssertions; +using Nethermind.Consensus.Ethash; +using Nethermind.Core; +using Nethermind.Core.Specs; +using Nethermind.Int256; +using Nethermind.Specs; +using Nethermind.Specs.ChainSpecStyle; +using Nethermind.Specs.Test.ChainSpecStyle; +using NUnit.Framework; + +namespace Nethermind.Ethash.Test; + +public class ChainSpecTest +{ + [Test] + public void Bound_divisors_set_correctly() + { + ChainSpec chainSpec = new() + { + Parameters = new ChainParameters { GasLimitBoundDivisor = 17 } + }; + + chainSpec.EngineChainSpecParametersProvider = + new TestChainSpecParametersProvider(new EthashChainSpecEngineParameters { DifficultyBoundDivisor = 19 }); + + + ChainSpecBasedSpecProvider provider = new(chainSpec); + Assert.That(provider.GenesisSpec.DifficultyBoundDivisor, Is.EqualTo(19)); + Assert.That(provider.GenesisSpec.GasLimitBoundDivisor, Is.EqualTo(17)); + } + + [Test] + public void Difficulty_bomb_delays_loaded_correctly() + { + ChainSpec chainSpec = new() + { + Parameters = new ChainParameters(), + }; + chainSpec.EngineChainSpecParametersProvider = new TestChainSpecParametersProvider( + new EthashChainSpecEngineParameters + { + DifficultyBombDelays = new Dictionary + { + { "3", 100 }, + { "7", 200 }, + { "13", 300 }, + { "17", 400 }, + { "19", 500 }, + } + }); + + ChainSpecBasedSpecProvider provider = new(chainSpec); + Assert.That(provider.GetSpec((ForkActivation)3).DifficultyBombDelay, Is.EqualTo(100)); + Assert.That(provider.GetSpec((ForkActivation)7).DifficultyBombDelay, Is.EqualTo(300)); + Assert.That(provider.GetSpec((ForkActivation)13).DifficultyBombDelay, Is.EqualTo(600)); + Assert.That(provider.GetSpec((ForkActivation)17).DifficultyBombDelay, Is.EqualTo(1000)); + Assert.That(provider.GetSpec((ForkActivation)19).DifficultyBombDelay, Is.EqualTo(1500)); + } + + [Test] + public void Eip_transitions_loaded_correctly() + { + const long maxCodeTransition = 1; + const long maxCodeSize = 1; + + ChainSpec chainSpec = new() + { + ByzantiumBlockNumber = 1960, + ConstantinopleBlockNumber = 6490, + Parameters = new ChainParameters + { + MaxCodeSizeTransition = maxCodeTransition, + MaxCodeSize = maxCodeSize, + Registrar = Address.Zero, + MinGasLimit = 11, + GasLimitBoundDivisor = 13, + MaximumExtraDataSize = 17, + Eip140Transition = 1400L, + Eip145Transition = 1450L, + Eip150Transition = 1500L, + Eip152Transition = 1520L, + Eip155Transition = 1550L, + Eip160Transition = 1600L, + Eip161abcTransition = 1580L, + Eip161dTransition = 1580L, + Eip211Transition = 2110L, + Eip214Transition = 2140L, + Eip658Transition = 6580L, + Eip1014Transition = 10140L, + Eip1052Transition = 10520L, + Eip1108Transition = 11080L, + Eip1283Transition = 12830L, + Eip1283DisableTransition = 12831L, + Eip1344Transition = 13440L, + Eip1884Transition = 18840L, + Eip2028Transition = 20280L, + Eip2200Transition = 22000L, + Eip2315Transition = 23150L, + Eip2565Transition = 25650L, + Eip2929Transition = 29290L, + Eip2930Transition = 29300L, + Eip1559Transition = 15590L, + Eip1559FeeCollectorTransition = 15591L, + FeeCollector = Address.SystemUser, + Eip1559BaseFeeMinValueTransition = 15592L, + Eip1559BaseFeeMinValue = UInt256.UInt128MaxValue, + Eip3198Transition = 31980L, + Eip3529Transition = 35290L, + Eip3541Transition = 35410L, + Eip1283ReenableTransition = 23000L, + ValidateChainIdTransition = 24000L, + ValidateReceiptsTransition = 24000L, + MergeForkIdTransition = 40000L, + Eip3651TransitionTimestamp = 1000000012, + Eip3855TransitionTimestamp = 1000000012, + Eip3860TransitionTimestamp = 1000000012, + Eip1153TransitionTimestamp = 1000000024, + Eip2537TransitionTimestamp = 1000000024, + + Eip7702TransitionTimestamp = 1000000032, + } + }; + chainSpec.EngineChainSpecParametersProvider = new TestChainSpecParametersProvider( + new EthashChainSpecEngineParameters + { + HomesteadTransition = 70, + Eip100bTransition = 1000 + }); + + + ChainSpecBasedSpecProvider provider = new(chainSpec); + Assert.That(provider.GetSpec((ForkActivation)(maxCodeTransition - 1)).MaxCodeSize, Is.EqualTo(long.MaxValue), "one before"); + Assert.That(provider.GetSpec((ForkActivation)maxCodeTransition).MaxCodeSize, Is.EqualTo(maxCodeSize), "at transition"); + Assert.That(provider.GetSpec((ForkActivation)(maxCodeTransition + 1)).MaxCodeSize, Is.EqualTo(maxCodeSize), "one after"); + + ReleaseSpec expected = new(); + + void TestTransitions(ForkActivation activation, Action changes) + { + changes(expected); + IReleaseSpec underTest = provider.GetSpec(activation); + underTest.Should().BeEquivalentTo(expected); + } + + TestTransitions((ForkActivation)0L, r => + { + // TODO: why it use to pass before with DifficultyBoundDivisor = 0 + r.DifficultyBoundDivisor = 0x800; + r.MinGasLimit = 11L; + r.GasLimitBoundDivisor = 13L; + r.MaximumExtraDataSize = 17L; + r.MaxCodeSize = long.MaxValue; + r.Eip1559TransitionBlock = 15590L; + r.IsTimeAdjustmentPostOlympic = true; + r.MaximumUncleCount = 2; + r.WithdrawalTimestamp = ulong.MaxValue; + r.Eip4844TransitionTimestamp = ulong.MaxValue; + }); + + TestTransitions((ForkActivation)1L, r => + { + r.MaxCodeSize = maxCodeSize; + r.IsEip170Enabled = true; + }); + TestTransitions((ForkActivation)70L, r => { r.IsEip2Enabled = r.IsEip7Enabled = true; }); + TestTransitions((ForkActivation)1000L, r => { r.IsEip100Enabled = true; }); + TestTransitions((ForkActivation)1400L, r => { r.IsEip140Enabled = true; }); + TestTransitions((ForkActivation)1450L, r => { r.IsEip145Enabled = true; }); + TestTransitions((ForkActivation)1500L, r => { r.IsEip150Enabled = true; }); + TestTransitions((ForkActivation)1520L, r => { r.IsEip152Enabled = true; }); + TestTransitions((ForkActivation)1550L, r => { r.IsEip155Enabled = true; }); + TestTransitions((ForkActivation)1580L, r => { r.IsEip158Enabled = true; }); + TestTransitions((ForkActivation)1600L, r => { r.IsEip160Enabled = true; }); + TestTransitions((ForkActivation)1960L, + r => { r.IsEip196Enabled = r.IsEip197Enabled = r.IsEip198Enabled = r.IsEip649Enabled = true; }); + TestTransitions((ForkActivation)2110L, r => { r.IsEip211Enabled = true; }); + TestTransitions((ForkActivation)2140L, r => { r.IsEip214Enabled = true; }); + TestTransitions((ForkActivation)6580L, r => { r.IsEip658Enabled = r.IsEip1234Enabled = true; }); + TestTransitions((ForkActivation)10140L, r => { r.IsEip1014Enabled = true; }); + TestTransitions((ForkActivation)10520L, r => { r.IsEip1052Enabled = true; }); + TestTransitions((ForkActivation)11180L, r => { r.IsEip1108Enabled = true; }); + TestTransitions((ForkActivation)12830L, r => { r.IsEip1283Enabled = true; }); + TestTransitions((ForkActivation)12831L, r => { r.IsEip1283Enabled = false; }); + TestTransitions((ForkActivation)13440L, r => { r.IsEip1344Enabled = true; }); + TestTransitions((ForkActivation)15590L, r => { r.IsEip1559Enabled = true; }); + TestTransitions((ForkActivation)15591L, r => { r.FeeCollector = Address.SystemUser; }); + TestTransitions((ForkActivation)15592L, r => { r.Eip1559BaseFeeMinValue = UInt256.UInt128MaxValue; }); + TestTransitions((ForkActivation)18840L, r => { r.IsEip1884Enabled = true; }); + TestTransitions((ForkActivation)20280L, r => { r.IsEip2028Enabled = true; }); + TestTransitions((ForkActivation)22000L, r => { r.IsEip2200Enabled = true; }); + TestTransitions((ForkActivation)23000L, r => { r.IsEip1283Enabled = r.IsEip1344Enabled = true; }); + TestTransitions((ForkActivation)24000L, r => { r.ValidateChainId = r.ValidateReceipts = true; }); + TestTransitions((ForkActivation)29290L, r => { r.IsEip2929Enabled = r.IsEip2565Enabled = true; }); + TestTransitions((ForkActivation)29300L, r => { r.IsEip2930Enabled = true; }); + TestTransitions((ForkActivation)31980L, r => { r.IsEip3198Enabled = true; }); + TestTransitions((ForkActivation)35290L, r => { r.IsEip3529Enabled = true; }); + TestTransitions((ForkActivation)35410L, r => { r.IsEip3541Enabled = true; }); + TestTransitions((ForkActivation)35410L, r => { r.IsEip3541Enabled = true; }); + + + TestTransitions((41000L, 1000000012), r => + { + r.IsEip3651Enabled = true; + r.IsEip3855Enabled = true; + r.IsEip3860Enabled = true; + }); + TestTransitions((40001L, 1000000024), r => { r.IsEip1153Enabled = r.IsEip2537Enabled = true; }); + TestTransitions((40001L, 1000000032), r => { r.IsEip7702Enabled = true; }); + } + +} diff --git a/src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs b/src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs index 77d51a72791..fdde1e1331d 100644 --- a/src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs +++ b/src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs @@ -34,6 +34,7 @@ using Nethermind.Serialization.Json; using Nethermind.Specs; using Nethermind.Specs.ChainSpecStyle; +using Nethermind.Specs.Test.ChainSpecStyle; using Nethermind.Synchronization.ParallelSync; using NSubstitute; using NUnit.Framework; @@ -118,17 +119,12 @@ protected override Task Build(ISpecProvider? specProvider = null return base.Build(specProvider, initialValues, addBlockOnStart); } - [Ignore("FIX Later")] protected override IBlockProcessor CreateBlockProcessor() { - // TODO: fix later _api = new(new ConfigProvider(), new EthereumJsonSerializer(), LogManager, new ChainSpec { - // AuRa = new() - // { - // WithdrawalContractAddress = new("0xbabe2bed00000000000000000000000000000003") - // }, + EngineChainSpecParametersProvider = TestChainSpecParametersProvider.NethDev, Parameters = new() }) { @@ -139,6 +135,12 @@ protected override IBlockProcessor CreateBlockProcessor() TransactionComparerProvider = TransactionComparerProvider, TxPool = TxPool }; + _api.ChainSpec.EngineChainSpecParametersProvider + .GetChainSpecParameters().Returns( + new AuthorityRoundChainSpecEngineParameters + { + WithdrawalContractAddress = new("0xbabe2bed00000000000000000000000000000003") + }); WithdrawalContractFactory withdrawalContractFactory = new(_api.ChainSpec!.EngineChainSpecParametersProvider .GetChainSpecParameters(), _api.AbiEncoder); diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/MergePluginTests.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/MergePluginTests.cs index 093084e7d0a..be44059e950 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/MergePluginTests.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/MergePluginTests.cs @@ -16,6 +16,7 @@ using Nethermind.JsonRpc.Modules; using Nethermind.Merge.Plugin.BlockProduction; using Nethermind.Specs.ChainSpecStyle; +using Nethermind.Specs.Test.ChainSpecStyle; using NUnit.Framework; using NSubstitute; using Build = Nethermind.Runner.Test.Ethereum.Build; @@ -58,10 +59,8 @@ public void Setup() _context.LogManager!); _context.ProcessExit = Substitute.For(); _context.ChainSpec.SealEngineType = SealEngineType.Clique; - var chainSpecParametersProvider = Substitute.For(); - chainSpecParametersProvider.GetChainSpecParameters() - .Returns( - new CliqueChainSpecEngineParameters { Epoch = CliqueConfig.Default.Epoch, Period = CliqueConfig.Default.BlockPeriod }); + var chainSpecParametersProvider = new TestChainSpecParametersProvider(new CliqueChainSpecEngineParameters + { Epoch = CliqueConfig.Default.Epoch, Period = CliqueConfig.Default.BlockPeriod }); _context.ChainSpec.EngineChainSpecParametersProvider = chainSpecParametersProvider; _plugin = new MergePlugin(); diff --git a/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/ChainSpecBasedSpecProviderTests.cs b/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/ChainSpecBasedSpecProviderTests.cs index 6a1a0bc3b65..a70c5430947 100644 --- a/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/ChainSpecBasedSpecProviderTests.cs +++ b/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/ChainSpecBasedSpecProviderTests.cs @@ -472,7 +472,7 @@ private ChainSpec LoadChainSpecFromChainFolder(string chain) public void Chain_id_is_set_correctly() { ChainSpec chainSpec = new() { Parameters = new ChainParameters(), NetworkId = 2, ChainId = 5 }; - chainSpec.EngineChainSpecParametersProvider = TestChainSpecParametersProvider.Instance; + chainSpec.EngineChainSpecParametersProvider = TestChainSpecParametersProvider.NethDev; ChainSpecBasedSpecProvider provider = new(chainSpec); Assert.That(provider.NetworkId, Is.EqualTo(2)); @@ -483,7 +483,7 @@ public void Chain_id_is_set_correctly() public void Dao_block_number_is_set_correctly() { ChainSpec chainSpec = new(); - chainSpec.EngineChainSpecParametersProvider = TestChainSpecParametersProvider.Instance; + chainSpec.EngineChainSpecParametersProvider = TestChainSpecParametersProvider.NethDev; chainSpec.Parameters = new ChainParameters(); chainSpec.DaoForkBlockNumber = 23; @@ -491,48 +491,6 @@ public void Dao_block_number_is_set_correctly() Assert.That(provider.DaoBlockNumber, Is.EqualTo(23)); } - [Test] - public void Bound_divisors_set_correctly() - { - // ChainSpec chainSpec = new() - // { - // Parameters = new ChainParameters { GasLimitBoundDivisor = 17 }, - // Ethash = new EthashParameters { DifficultyBoundDivisor = 19 } - // }; - // - // ChainSpecBasedSpecProvider provider = new(chainSpec); - // Assert.That(provider.GenesisSpec.DifficultyBoundDivisor, Is.EqualTo(19)); - // Assert.That(provider.GenesisSpec.GasLimitBoundDivisor, Is.EqualTo(17)); - } - - [Test] - public void Difficulty_bomb_delays_loaded_correctly() - { - // TODO: fix test - // ChainSpec chainSpec = new() - // { - // Parameters = new ChainParameters(), - // Ethash = new EthashParameters - // { - // DifficultyBombDelays = new Dictionary - // { - // { 3, 100 }, - // { 7, 200 }, - // { 13, 300 }, - // { 17, 400 }, - // { 19, 500 }, - // } - // } - // }; - // - // ChainSpecBasedSpecProvider provider = new(chainSpec); - // Assert.That(provider.GetSpec((ForkActivation)3).DifficultyBombDelay, Is.EqualTo(100)); - // Assert.That(provider.GetSpec((ForkActivation)7).DifficultyBombDelay, Is.EqualTo(300)); - // Assert.That(provider.GetSpec((ForkActivation)13).DifficultyBombDelay, Is.EqualTo(600)); - // Assert.That(provider.GetSpec((ForkActivation)17).DifficultyBombDelay, Is.EqualTo(1000)); - // Assert.That(provider.GetSpec((ForkActivation)19).DifficultyBombDelay, Is.EqualTo(1500)); - } - [Test] public void Max_code_transition_loaded_correctly() { @@ -547,7 +505,7 @@ public void Max_code_transition_loaded_correctly() MaxCodeSize = maxCodeSize } }; - chainSpec.EngineChainSpecParametersProvider = TestChainSpecParametersProvider.Instance; + chainSpec.EngineChainSpecParametersProvider = TestChainSpecParametersProvider.NethDev; ChainSpecBasedSpecProvider provider = new(chainSpec); Assert.That(provider.GetSpec((ForkActivation)(maxCodeTransition - 1)).MaxCodeSize, Is.EqualTo(long.MaxValue), "one before"); @@ -559,7 +517,7 @@ public void Max_code_transition_loaded_correctly() public void Eip2200_is_set_correctly_directly() { ChainSpec chainSpec = new() { Parameters = new ChainParameters { Eip2200Transition = 5 } }; - chainSpec.EngineChainSpecParametersProvider = TestChainSpecParametersProvider.Instance; + chainSpec.EngineChainSpecParametersProvider = TestChainSpecParametersProvider.NethDev; ChainSpecBasedSpecProvider provider = new(chainSpec); provider.GetSpec((ForkActivation)5).IsEip2200Enabled.Should().BeTrue(); @@ -570,7 +528,7 @@ public void Eip2200_is_set_correctly_indirectly() { ChainSpec chainSpec = new() { Parameters = new ChainParameters { Eip1706Transition = 5, Eip1283Transition = 5 } }; - chainSpec.EngineChainSpecParametersProvider = TestChainSpecParametersProvider.Instance; + chainSpec.EngineChainSpecParametersProvider = TestChainSpecParametersProvider.NethDev; ChainSpecBasedSpecProvider provider = new(chainSpec); provider.GetSpec((ForkActivation)5).IsEip2200Enabled.Should().BeTrue(); @@ -589,7 +547,7 @@ public void Eip2200_is_set_correctly_indirectly_after_disabling_eip1283_and_reen Eip1283ReenableTransition = 5 } }; - chainSpec.EngineChainSpecParametersProvider = TestChainSpecParametersProvider.Instance; + chainSpec.EngineChainSpecParametersProvider = TestChainSpecParametersProvider.NethDev; ChainSpecBasedSpecProvider provider = new(chainSpec); provider.GetSpec((ForkActivation)5).IsEip2200Enabled.Should().BeTrue(); @@ -607,7 +565,7 @@ public void Eip2200_is_not_set_correctly_indirectly_after_disabling_eip1283() Eip1283DisableTransition = 4 } }; - chainSpec.EngineChainSpecParametersProvider = TestChainSpecParametersProvider.Instance; + chainSpec.EngineChainSpecParametersProvider = TestChainSpecParametersProvider.NethDev; ChainSpecBasedSpecProvider provider = new(chainSpec); provider.GetSpec((ForkActivation)5).IsEip2200Enabled.Should().BeFalse(); @@ -625,7 +583,7 @@ public void Eip150_and_Eip2537_fork_by_block_number() MaxCodeSize = 1 } }; - chainSpec.EngineChainSpecParametersProvider = TestChainSpecParametersProvider.Instance; + chainSpec.EngineChainSpecParametersProvider = TestChainSpecParametersProvider.NethDev; ChainSpecBasedSpecProvider provider = new(chainSpec); @@ -652,7 +610,7 @@ public void Eip150_and_Eip2537_fork_by_timestamp() MaxCodeSize = 1 } }; - chainSpec.EngineChainSpecParametersProvider = TestChainSpecParametersProvider.Instance; + chainSpec.EngineChainSpecParametersProvider = TestChainSpecParametersProvider.NethDev; ChainSpecBasedSpecProvider provider = new(chainSpec); @@ -667,156 +625,6 @@ public void Eip150_and_Eip2537_fork_by_timestamp() provider.GetSpec((100, 21)).IsEip2537Enabled.Should().BeTrue(); } - [Ignore("FIX LATER")] - [Test] - public void Eip_transitions_loaded_correctly() - { - // TODO: fix test - const long maxCodeTransition = 1; - const long maxCodeSize = 1; - - ChainSpec chainSpec = new() - { - // Ethash = - // new EthashParameters - // { - // HomesteadTransition = 70, - // Eip100bTransition = 1000 - // }, - ByzantiumBlockNumber = 1960, - ConstantinopleBlockNumber = 6490, - Parameters = new ChainParameters - { - MaxCodeSizeTransition = maxCodeTransition, - MaxCodeSize = maxCodeSize, - Registrar = Address.Zero, - MinGasLimit = 11, - GasLimitBoundDivisor = 13, - MaximumExtraDataSize = 17, - Eip140Transition = 1400L, - Eip145Transition = 1450L, - Eip150Transition = 1500L, - Eip152Transition = 1520L, - Eip155Transition = 1550L, - Eip160Transition = 1600L, - Eip161abcTransition = 1580L, - Eip161dTransition = 1580L, - Eip211Transition = 2110L, - Eip214Transition = 2140L, - Eip658Transition = 6580L, - Eip1014Transition = 10140L, - Eip1052Transition = 10520L, - Eip1108Transition = 11080L, - Eip1283Transition = 12830L, - Eip1283DisableTransition = 12831L, - Eip1344Transition = 13440L, - Eip1884Transition = 18840L, - Eip2028Transition = 20280L, - Eip2200Transition = 22000L, - Eip2315Transition = 23150L, - Eip2565Transition = 25650L, - Eip2929Transition = 29290L, - Eip2930Transition = 29300L, - Eip1559Transition = 15590L, - Eip1559FeeCollectorTransition = 15591L, - FeeCollector = Address.SystemUser, - Eip1559BaseFeeMinValueTransition = 15592L, - Eip1559BaseFeeMinValue = UInt256.UInt128MaxValue, - Eip3198Transition = 31980L, - Eip3529Transition = 35290L, - Eip3541Transition = 35410L, - Eip1283ReenableTransition = 23000L, - ValidateChainIdTransition = 24000L, - ValidateReceiptsTransition = 24000L, - MergeForkIdTransition = 40000L, - Eip3651TransitionTimestamp = 1000000012, - Eip3855TransitionTimestamp = 1000000012, - Eip3860TransitionTimestamp = 1000000012, - Eip1153TransitionTimestamp = 1000000024, - Eip2537TransitionTimestamp = 1000000024, - - Eip7702TransitionTimestamp = 1000000032, - } - }; - - ChainSpecBasedSpecProvider provider = new(chainSpec); - Assert.That(provider.GetSpec((ForkActivation)(maxCodeTransition - 1)).MaxCodeSize, Is.EqualTo(long.MaxValue), "one before"); - Assert.That(provider.GetSpec((ForkActivation)maxCodeTransition).MaxCodeSize, Is.EqualTo(maxCodeSize), "at transition"); - Assert.That(provider.GetSpec((ForkActivation)(maxCodeTransition + 1)).MaxCodeSize, Is.EqualTo(maxCodeSize), "one after"); - - ReleaseSpec expected = new(); - - void TestTransitions(ForkActivation activation, Action changes) - { - changes(expected); - IReleaseSpec underTest = provider.GetSpec(activation); - underTest.Should().BeEquivalentTo(expected); - } - - TestTransitions((ForkActivation)0L, r => - { - r.MinGasLimit = 11L; - r.GasLimitBoundDivisor = 13L; - r.MaximumExtraDataSize = 17L; - r.MaxCodeSize = long.MaxValue; - r.Eip1559TransitionBlock = 15590L; - r.IsTimeAdjustmentPostOlympic = true; - r.MaximumUncleCount = 2; - r.WithdrawalTimestamp = ulong.MaxValue; - r.Eip4844TransitionTimestamp = ulong.MaxValue; - }); - - TestTransitions((ForkActivation)1L, r => - { - r.MaxCodeSize = maxCodeSize; - r.IsEip170Enabled = true; - }); - TestTransitions((ForkActivation)70L, r => { r.IsEip2Enabled = r.IsEip7Enabled = true; }); - TestTransitions((ForkActivation)1000L, r => { r.IsEip100Enabled = true; }); - TestTransitions((ForkActivation)1400L, r => { r.IsEip140Enabled = true; }); - TestTransitions((ForkActivation)1450L, r => { r.IsEip145Enabled = true; }); - TestTransitions((ForkActivation)1500L, r => { r.IsEip150Enabled = true; }); - TestTransitions((ForkActivation)1520L, r => { r.IsEip152Enabled = true; }); - TestTransitions((ForkActivation)1550L, r => { r.IsEip155Enabled = true; }); - TestTransitions((ForkActivation)1580L, r => { r.IsEip158Enabled = true; }); - TestTransitions((ForkActivation)1600L, r => { r.IsEip160Enabled = true; }); - TestTransitions((ForkActivation)1960L, - r => { r.IsEip196Enabled = r.IsEip197Enabled = r.IsEip198Enabled = r.IsEip649Enabled = true; }); - TestTransitions((ForkActivation)2110L, r => { r.IsEip211Enabled = true; }); - TestTransitions((ForkActivation)2140L, r => { r.IsEip214Enabled = true; }); - TestTransitions((ForkActivation)6580L, r => { r.IsEip658Enabled = r.IsEip1234Enabled = true; }); - TestTransitions((ForkActivation)10140L, r => { r.IsEip1014Enabled = true; }); - TestTransitions((ForkActivation)10520L, r => { r.IsEip1052Enabled = true; }); - TestTransitions((ForkActivation)11180L, r => { r.IsEip1108Enabled = true; }); - TestTransitions((ForkActivation)12830L, r => { r.IsEip1283Enabled = true; }); - TestTransitions((ForkActivation)12831L, r => { r.IsEip1283Enabled = false; }); - TestTransitions((ForkActivation)13440L, r => { r.IsEip1344Enabled = true; }); - TestTransitions((ForkActivation)15590L, r => { r.IsEip1559Enabled = true; }); - TestTransitions((ForkActivation)15591L, r => { r.FeeCollector = Address.SystemUser; }); - TestTransitions((ForkActivation)15592L, r => { r.Eip1559BaseFeeMinValue = UInt256.UInt128MaxValue; }); - TestTransitions((ForkActivation)18840L, r => { r.IsEip1884Enabled = true; }); - TestTransitions((ForkActivation)20280L, r => { r.IsEip2028Enabled = true; }); - TestTransitions((ForkActivation)22000L, r => { r.IsEip2200Enabled = true; }); - TestTransitions((ForkActivation)23000L, r => { r.IsEip1283Enabled = r.IsEip1344Enabled = true; }); - TestTransitions((ForkActivation)24000L, r => { r.ValidateChainId = r.ValidateReceipts = true; }); - TestTransitions((ForkActivation)29290L, r => { r.IsEip2929Enabled = r.IsEip2565Enabled = true; }); - TestTransitions((ForkActivation)29300L, r => { r.IsEip2930Enabled = true; }); - TestTransitions((ForkActivation)31980L, r => { r.IsEip3198Enabled = true; }); - TestTransitions((ForkActivation)35290L, r => { r.IsEip3529Enabled = true; }); - TestTransitions((ForkActivation)35410L, r => { r.IsEip3541Enabled = true; }); - TestTransitions((ForkActivation)35410L, r => { r.IsEip3541Enabled = true; }); - - - TestTransitions((41000L, 1000000012), r => - { - r.IsEip3651Enabled = true; - r.IsEip3855Enabled = true; - r.IsEip3860Enabled = true; - }); - TestTransitions((40001L, 1000000024), r => { r.IsEip1153Enabled = r.IsEip2537Enabled = true; }); - TestTransitions((40001L, 1000000032), r => { r.IsEip7702Enabled = true; }); - } - [TestCaseSource(nameof(BlockNumbersAndTimestampsNearForkActivations))] public void Forks_should_be_selected_properly_for_exact_matches(ForkActivation forkActivation, bool isEip3651Enabled, bool isEip3198Enabled, bool isEip3855Enabled) { diff --git a/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/TestChainSpecParametersProvider.cs b/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/TestChainSpecParametersProvider.cs index 6e73fc69f0b..a20c2cc1cee 100644 --- a/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/TestChainSpecParametersProvider.cs +++ b/src/Nethermind/Nethermind.Specs.Test/ChainSpecStyle/TestChainSpecParametersProvider.cs @@ -10,21 +10,28 @@ namespace Nethermind.Specs.Test.ChainSpecStyle; public class TestChainSpecParametersProvider : IChainSpecParametersProvider { - public static readonly TestChainSpecParametersProvider Instance = new(); + public static readonly TestChainSpecParametersProvider NethDev = new(new NethDevChainSpecEngineParameters()); - public string SealEngineType => TestSealEngineType.NethDev; + private readonly IChainSpecEngineParameters _parameters; + + public TestChainSpecParametersProvider(IChainSpecEngineParameters parameters) + { + _parameters = parameters; + } + + public string SealEngineType => _parameters.SealEngineType!; public IEnumerable AllChainSpecParameters => - new[] { new NethDevChainSpecEngineParameters() }; + new[] { _parameters }; public T GetChainSpecParameters() where T : IChainSpecEngineParameters { - if (typeof(T) == typeof(NethDevChainSpecEngineParameters)) + if (typeof(T) == _parameters.GetType()) { - return (T)(object)(new NethDevChainSpecEngineParameters()); + return (T)_parameters; } else { - throw new NotSupportedException($"Only NethDev engine in {nameof(TestChainSpecParametersProvider)}"); + throw new NotSupportedException($"Only {_parameters.GetType().Name} engine in {nameof(TestChainSpecParametersProvider)}"); } } } diff --git a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs index da81d65bc91..956b7a5f1e4 100644 --- a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs +++ b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs @@ -148,8 +148,8 @@ private static ForkActivation[] CreateTransitionActivations(SortedSet tran private ReleaseSpec CreateReleaseSpec(ChainSpec chainSpec, long releaseStartBlock, ulong? releaseStartTimestamp = null) { ReleaseSpec releaseSpec = new(); - // releaseSpec.MaximumUncleCount = (int)(releaseStartBlock >= (chainSpec.AuRa?.MaximumUncleCountTransition ?? long.MaxValue) ? chainSpec.AuRa?.MaximumUncleCount ?? 2 : 2); releaseSpec.MaximumUncleCount = 2; + releaseSpec.DifficultyBoundDivisor = 1; releaseSpec.IsTimeAdjustmentPostOlympic = true; // TODO: this is Duration, review releaseSpec.MaximumExtraDataSize = chainSpec.Parameters.MaximumExtraDataSize; releaseSpec.MinGasLimit = chainSpec.Parameters.MinGasLimit;