Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
deffrian committed Oct 22, 2024
1 parent dde5690 commit 18ce8a2
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 219 deletions.
5 changes: 4 additions & 1 deletion src/Nethermind/Nethermind.AuRa.Test/AuRaPluginTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}

Expand Down
216 changes: 216 additions & 0 deletions src/Nethermind/Nethermind.Ethash.Test/ChainSpecTest.cs
Original file line number Diff line number Diff line change
@@ -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<string, long>
{
{ "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<ReleaseSpec> 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; });
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,17 +119,12 @@ protected override Task<TestBlockchain> 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()
})
{
Expand All @@ -139,6 +135,12 @@ protected override IBlockProcessor CreateBlockProcessor()
TransactionComparerProvider = TransactionComparerProvider,
TxPool = TxPool
};
_api.ChainSpec.EngineChainSpecParametersProvider
.GetChainSpecParameters<AuthorityRoundChainSpecEngineParameters>().Returns(
new AuthorityRoundChainSpecEngineParameters
{
WithdrawalContractAddress = new("0xbabe2bed00000000000000000000000000000003")
});

WithdrawalContractFactory withdrawalContractFactory = new(_api.ChainSpec!.EngineChainSpecParametersProvider
.GetChainSpecParameters<AuthorityRoundChainSpecEngineParameters>(), _api.AbiEncoder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,10 +59,8 @@ public void Setup()
_context.LogManager!);
_context.ProcessExit = Substitute.For<IProcessExitSource>();
_context.ChainSpec.SealEngineType = SealEngineType.Clique;
var chainSpecParametersProvider = Substitute.For<IChainSpecParametersProvider>();
chainSpecParametersProvider.GetChainSpecParameters<CliqueChainSpecEngineParameters>()
.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();

Expand Down
Loading

0 comments on commit 18ce8a2

Please sign in to comment.