Skip to content

Commit

Permalink
Remove TestSealEngineType.cs and JsonConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
deffrian committed Nov 1, 2024
1 parent fed3fdd commit bbff932
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public async Task Process_long_running_branch(int blocksAmount)
{
Address address = TestItem.Addresses[0];
TestSingleReleaseSpecProvider spec = new TestSingleReleaseSpecProvider(ConstantinopleFix.Instance);
TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest(TestSealEngineType.NethDev)
TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev)
.Build(spec);
testRpc.TestWallet.UnlockAccount(address, new SecureString());
await testRpc.AddFunds(address, 1.Ether());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private async Task<ScenarioBuilder> CreateTestBlockchainAsync(long gasLimit)
IsEip155Enabled = true
});
BlockBuilder blockBuilder = Build.A.Block.Genesis.WithGasLimit(gasLimit);
_testRpcBlockchain = await TestRpcBlockchain.ForTest(TestSealEngineType.NethDev)
_testRpcBlockchain = await TestRpcBlockchain.ForTest(SealEngineType.NethDev)
.WithGenesisBlockBuilder(blockBuilder)
.Build(spec);
_testRpcBlockchain.TestWallet.UnlockAccount(_address, new SecureString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private async Task<TestRpcBlockchain> CreateTestRpc()
{
Address address = TestItem.Addresses[0];
TestSingleReleaseSpecProvider spec = new(ConstantinopleFix.Instance);
TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest(TestSealEngineType.NethDev)
TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev)
.Build(spec);
testRpc.TestWallet.UnlockAccount(address, new SecureString());
await testRpc.AddFunds(address, 1.Ether());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static IEnumerable<BlockProcessorIntervalHint> BlockProcessorIntervalHint
{
yield return new BlockProcessorIntervalHint
{
ChainSpec = new ChainSpec { SealEngineType = TestSealEngineType.NethDev, }
ChainSpec = new ChainSpec { SealEngineType = SealEngineType.NethDev, }
};
yield return new BlockProcessorIntervalHint
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public async Task Deletes_everything_after_the_missing_level()
[TestCase(65)]
public async Task Suggesting_blocks_works_correctly_after_processor_restart(int suggestedBlocksAmount)
{
TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest(TestSealEngineType.NethDev).Build();
TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build();
await testRpc.BlockchainProcessor.StopAsync();
IBlockTree tree = testRpc.BlockTree;
long startingBlockNumber = tree.Head!.Number;
Expand Down Expand Up @@ -131,7 +131,7 @@ public async Task Suggesting_blocks_works_correctly_after_processor_restart(int
[TestCase(6)]
public async Task Fixer_should_not_suggest_block_without_state(int suggestedBlocksAmount)
{
TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest(TestSealEngineType.NethDev).Build();
TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build();
await testRpc.BlockchainProcessor.StopAsync();
IBlockTree tree = testRpc.BlockTree;

Expand All @@ -153,7 +153,7 @@ public async Task Fixer_should_not_suggest_block_without_state(int suggestedBloc
[Test, MaxTime(Timeout.MaxTestTime)]
public async Task Fixer_should_not_suggest_block_with_null_block()
{
TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest(TestSealEngineType.NethDev).Build();
TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build();
await testRpc.BlockchainProcessor.StopAsync();
IBlockTree tree = testRpc.BlockTree;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using Nethermind.Core;
using Nethermind.Int256;
Expand Down Expand Up @@ -32,7 +30,6 @@ public class EthashChainSpecEngineParameters : IChainSpecEngineParameters
[JsonConverter(typeof(LongUInt256DictionaryConverter))]
public SortedDictionary<long, UInt256>? BlockReward { get; set; }

[JsonConverter(typeof(DifficultyBombDelaysJsonConverter))]
public IDictionary<long, long>? DifficultyBombDelays { get; set; }

public void AddTransitions(SortedSet<long> blockNumbers, SortedSet<ulong> timestamps)
Expand Down Expand Up @@ -102,61 +99,4 @@ public void ApplyToChainSpec(ChainSpec chainSpec)
chainSpec.HomesteadBlockNumber = HomesteadTransition;
chainSpec.DaoForkBlockNumber = DaoHardforkTransition;
}

private class DifficultyBombDelaysJsonConverter : JsonConverter<IDictionary<long, long>>
{
public override void Write(Utf8JsonWriter writer, IDictionary<long, long> value, JsonSerializerOptions options)
{
throw new NotSupportedException();
}

public override IDictionary<long, long> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var value = new Dictionary<long, long>();
if (reader.TokenType == JsonTokenType.String)
{
value.Add(0, JsonSerializer.Deserialize<long>(ref reader, options));
}
else if (reader.TokenType == JsonTokenType.Number)
{
value.Add(0, reader.GetInt64());
}
else if (reader.TokenType == JsonTokenType.StartObject)
{
reader.Read();
while (reader.TokenType != JsonTokenType.EndObject)
{
if (reader.TokenType != JsonTokenType.PropertyName)
{
throw new ArgumentException("Cannot deserialize DifficultyBombDelays.");
}
string keyString = reader.GetString();
var key = keyString.StartsWith("0x") ? Convert.ToInt64(keyString, 16) : long.Parse(keyString);
reader.Read();
if (reader.TokenType == JsonTokenType.String)
{
string valueString = reader.GetString();
value.Add(key, valueString.StartsWith("0x") ? Convert.ToInt64(valueString, 16) : long.Parse(valueString));
}
else if (reader.TokenType == JsonTokenType.Number)
{
value.Add(key, reader.GetInt64());
}
else
{
throw new ArgumentException("Cannot deserialize DifficultyBombDelays.");
}

reader.Read();
}
}
else
{
throw new ArgumentException("Cannot deserialize DifficultyBombDelays.");
}

return value;
}
}

}
2 changes: 2 additions & 0 deletions src/Nethermind/Nethermind.Core/SealEngineType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ public static class SealEngineType
public const string None = nameof(None);
public const string AuRa = nameof(AuRa);
public const string Clique = nameof(Clique);
public const string NethDev = nameof(NethDev);
public const string Ethash = nameof(Ethash);
public const string BeaconChain = nameof(BeaconChain);
public const string Optimism = nameof(Optimism);
public const string Taiko = nameof(Taiko);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public async Task Eth_estimateGas_web3_above_block_gas_limit()
[TestCase(true, 17)]
public async Task Eth_create_access_list_calculates_proper_gas(bool optimize, long loads)
{
var test = await TestRpcBlockchain.ForTest(TestSealEngineType.NethDev)
var test = await TestRpcBlockchain.ForTest(SealEngineType.NethDev)
.Build(new TestSpecProvider(Berlin.Instance));

(byte[] code, _) = GetTestAccessList(loads);
Expand Down Expand Up @@ -113,7 +113,7 @@ public async Task Eth_create_access_list_calculates_proper_gas(bool optimize, lo
public async Task Eth_estimate_gas_with_accessList(bool senderAccessList, long gasPriceWithoutAccessList,
long gasPriceWithAccessList)
{
var test = await TestRpcBlockchain.ForTest(TestSealEngineType.NethDev).WithConfig(new JsonRpcConfig() { EstimateErrorMargin = 0 })
var test = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).WithConfig(new JsonRpcConfig() { EstimateErrorMargin = 0 })
.Build(new TestSpecProvider(Berlin.Instance));

(byte[] code, AccessListForRpc accessList) = GetTestAccessList(2, senderAccessList);
Expand All @@ -134,7 +134,7 @@ public async Task Eth_estimate_gas_with_accessList(bool senderAccessList, long g
[Test]
public async Task Eth_estimate_gas_is_lower_with_optimized_access_list()
{
var test = await TestRpcBlockchain.ForTest(TestSealEngineType.NethDev)
var test = await TestRpcBlockchain.ForTest(SealEngineType.NethDev)
.Build(new TestSpecProvider(Berlin.Instance));

(byte[] code, AccessListForRpc accessList) = GetTestAccessList(2, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public async Task Eth_call_missing_state_after_fast_sync()
[Test]
public async Task Eth_call_with_accessList()
{
var test = await TestRpcBlockchain.ForTest(TestSealEngineType.NethDev)
var test = await TestRpcBlockchain.ForTest(SealEngineType.NethDev)
.Build(new TestSpecProvider(Berlin.Instance));

(byte[] code, AccessListForRpc accessList) = GetTestAccessList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task Eth_gasPrice_BlocksAvailableLessThanBlocksToCheck_ShouldGiveCo
Block[] blocks = GetThreeTestBlocks();
BlockTree blockTree = Build.A.BlockTree(blocks[0]).WithBlocks(blocks).TestObject;
GasPriceOracle gasPriceOracle = new(blockTree, GetSpecProviderWithEip1559EnabledAs(eip1559Enabled), LimboLogs.Instance);
ctx.Test = await TestRpcBlockchain.ForTest(TestSealEngineType.NethDev).WithBlockFinder(blockTree).WithGasPriceOracle(gasPriceOracle)
ctx.Test = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).WithBlockFinder(blockTree).WithGasPriceOracle(gasPriceOracle)
.Build();

string serialized = await ctx.Test.TestEthRpc("eth_gasPrice");
Expand All @@ -44,7 +44,7 @@ public async Task<string> Eth_blobBaseFee_ShouldGiveCorrectResult(ulong? excessB
Build.A.Block.WithNumber(0).WithExcessBlobGas(excessBlobGas).TestObject,
];
BlockTree blockTree = Build.A.BlockTree(blocks[0]).WithBlocks(blocks).TestObject;
ctx.Test = await TestRpcBlockchain.ForTest(TestSealEngineType.NethDev).WithBlockFinder(blockTree).Build();
ctx.Test = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).WithBlockFinder(blockTree).Build();

return await ctx.Test.TestEthRpc("eth_blobBaseFee");
}
Expand All @@ -57,7 +57,7 @@ public async Task Eth_gasPrice_BlocksAvailableLessThanBlocksToCheckWith1559Tx_Sh
Block[] blocks = GetThreeTestBlocksWith1559Tx();
BlockTree blockTree = Build.A.BlockTree(blocks[0]).WithBlocks(blocks).TestObject;
GasPriceOracle gasPriceOracle = new(blockTree, GetSpecProviderWithEip1559EnabledAs(eip1559Enabled), LimboLogs.Instance);
ctx.Test = await TestRpcBlockchain.ForTest(TestSealEngineType.NethDev).WithBlockFinder(blockTree).WithGasPriceOracle(gasPriceOracle)
ctx.Test = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).WithBlockFinder(blockTree).WithGasPriceOracle(gasPriceOracle)
.Build();

string serialized = await ctx.Test.TestEthRpc("eth_gasPrice");
Expand Down
Loading

0 comments on commit bbff932

Please sign in to comment.