Skip to content

Commit

Permalink
Fix test; ws
Browse files Browse the repository at this point in the history
  • Loading branch information
flcl42 committed Dec 25, 2023
1 parent 0d0892b commit 56167cb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 40 deletions.
71 changes: 35 additions & 36 deletions src/Nethermind/Nethermind.Specs.Test/CustomSpecProvider.cs
Original file line number Diff line number Diff line change
@@ -1,60 +1,59 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections.Generic;
using System.Linq;
using Nethermind.Core;
using Nethermind.Core.Specs;
using Nethermind.Int256;
using Nethermind.Specs.ChainSpecStyle;
using Nethermind.Specs.Forks;

namespace Nethermind.Specs.Test
namespace Nethermind.Specs.Test;

public class CustomSpecProvider : SpecProviderBase, ISpecProvider
{
public class CustomSpecProvider : SpecProviderBase, ISpecProvider
{
private ForkActivation? _theMergeBlock = null;
private ForkActivation? _theMergeBlock = null;

public ulong NetworkId { get; }
public ulong ChainId { get; }
public ulong NetworkId { get; }
public ulong ChainId { get; }

public CustomSpecProvider(params (ForkActivation Activation, IReleaseSpec Spec)[] transitions) : this(TestBlockchainIds.NetworkId, TestBlockchainIds.ChainId, transitions)
{
}
public CustomSpecProvider(params (ForkActivation Activation, IReleaseSpec Spec)[] transitions) : this(TestBlockchainIds.NetworkId, TestBlockchainIds.ChainId, transitions)
{
}

public CustomSpecProvider(ulong networkId, ulong chainId, params (ForkActivation Activation, IReleaseSpec Spec)[] transitions)
{
NetworkId = networkId;
ChainId = chainId;
public CustomSpecProvider(ulong networkId, ulong chainId, params (ForkActivation Activation, IReleaseSpec Spec)[] transitions)
{
NetworkId = networkId;
ChainId = chainId;

(ForkActivation Activation, IReleaseSpec Spec)[] orderedTransitions = transitions.OrderBy(r => r.Activation).ToArray();
(ForkActivation Activation, IReleaseSpec Spec)[] orderedTransitions = transitions.OrderBy(r => r.Activation).ToArray();

LoadTransitions(orderedTransitions);
TransitionActivations = orderedTransitions.Select(t => t.Activation).ToArray();
}
LoadTransitions(orderedTransitions);

public void UpdateMergeTransitionInfo(long? blockNumber, UInt256? terminalTotalDifficulty = null)
{
if (blockNumber is not null)
_theMergeBlock = (ForkActivation)blockNumber;
if (terminalTotalDifficulty is not null)
TerminalTotalDifficulty = terminalTotalDifficulty;
}
TransitionActivations = orderedTransitions.Select(t => t.Activation).ToArray();
}

public void UpdateMergeTransitionInfo(long? blockNumber, UInt256? terminalTotalDifficulty = null)
{
if (blockNumber is not null)
_theMergeBlock = (ForkActivation)blockNumber;
if (terminalTotalDifficulty is not null)
TerminalTotalDifficulty = terminalTotalDifficulty;
}

public ForkActivation? MergeBlockNumber => _theMergeBlock;
public ForkActivation? MergeBlockNumber => _theMergeBlock;

public ulong TimestampFork { get; set; } = ISpecProvider.TimestampForkNever;
public UInt256? TerminalTotalDifficulty { get; set; }
public ulong TimestampFork { get; set; } = ISpecProvider.TimestampForkNever;
public UInt256? TerminalTotalDifficulty { get; set; }

public long? DaoBlockNumber
public long? DaoBlockNumber
{
get
{
get
{
(ForkActivation forkActivation, IReleaseSpec? daoRelease) = _blockTransitions.SingleOrDefault(t => t.Spec == Dao.Instance);
return daoRelease is not null ? forkActivation.BlockNumber : null;
}
(ForkActivation forkActivation, IReleaseSpec? daoRelease) = _blockTransitions.SingleOrDefault(t => t.Spec == Dao.Instance);
return daoRelease is not null ? forkActivation.BlockNumber : null;
}

}

}

Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ public void When_no_transitions_specified_throws_argument_exception()
public void When_first_release_is_not_at_block_zero_then_throws_argument_exception()
{
Assert.Throws<ArgumentException>(() => _ = new CustomSpecProvider(((ForkActivation)1, Byzantium.Instance)), "ordered");

Assert.Throws<ArgumentException>(() => _ = new CustomSpecProvider(
((ForkActivation)1, Byzantium.Instance),
((ForkActivation)0, Frontier.Instance)), "not ordered");
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected void LoadTransitions((ForkActivation Activation, IReleaseSpec Spec)[]
{
throw new ArgumentException($"There must be at least one release specified when instantiating {GetType()}", $"{nameof(transitions)}");
}

if (transitions.First().Activation.BlockNumber != 0L)
{
throw new ArgumentException($"First release specified when instantiating {GetType()} should be at genesis block (0)", $"{nameof(transitions)}");
Expand Down

0 comments on commit 56167cb

Please sign in to comment.