Skip to content

Commit

Permalink
Make fields readonly (#6356)
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams authored Dec 12, 2023
1 parent 2af3d8f commit 7cc8358
Show file tree
Hide file tree
Showing 177 changed files with 354 additions and 354 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ namespace Nethermind.AccountAbstraction.Test
[TestFixture]
public class AccountAbstractionPeerManagerTests
{
private IDictionary<Address, IUserOperationPool> _userOperationPools = new Dictionary<Address, IUserOperationPool>();
private IUserOperationSimulator _simulator = Substitute.For<IUserOperationSimulator>();
private IBlockTree _blockTree = Substitute.For<IBlockTree>();
private ILogger _logger = Substitute.For<ILogger>();
private ILogFinder _logFinder = Substitute.For<ILogFinder>();
private IWorldState _stateProvider = Substitute.For<IWorldState>();
private ISpecProvider _specProvider = Substitute.For<ISpecProvider>();
private readonly IDictionary<Address, IUserOperationPool> _userOperationPools = new Dictionary<Address, IUserOperationPool>();
private readonly IUserOperationSimulator _simulator = Substitute.For<IUserOperationSimulator>();
private readonly IBlockTree _blockTree = Substitute.For<IBlockTree>();
private readonly ILogger _logger = Substitute.For<ILogger>();
private readonly ILogFinder _logFinder = Substitute.For<ILogFinder>();
private readonly IWorldState _stateProvider = Substitute.For<IWorldState>();
private readonly ISpecProvider _specProvider = Substitute.For<ISpecProvider>();
private readonly ISigner _signer = Substitute.For<ISigner>();
private readonly string[] _entryPointContractAddress = { "0x8595dd9e0438640b5e1254f9df579ac12a86865f", "0x96cc609c8f5458fb8a7da4d94b678e38ebf3d04e" };
private static Address _notAnAddress = new("0x373f2D08b1C195fF08B9AbEdE3C78575FAAC2aCf");
private static readonly Address _notAnAddress = new("0x373f2D08b1C195fF08B9AbEdE3C78575FAAC2aCf");

[Test]
public void should_add_peers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public TestAccountAbstractionRpcBlockchain(UInt256? initialBaseFeePerGas)

public IAccountAbstractionRpcModule AccountAbstractionRpcModule { get; set; } = Substitute.For<IAccountAbstractionRpcModule>();
public ManualGasLimitCalculator GasLimitCalculator = new() { GasLimit = 10_000_000 };
private AccountAbstractionConfig _accountAbstractionConfig = new AccountAbstractionConfig()
private readonly AccountAbstractionConfig _accountAbstractionConfig = new AccountAbstractionConfig()
{
Enabled = true,
EntryPointContractAddresses = "0xb0894727fe4ff102e1f1c8a16f38afc7b859f215,0x96cc609c8f5458fb8a7da4d94b678e38ebf3d04e",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ namespace Nethermind.AccountAbstraction.Test;
[TestFixture]
public partial class AccountAbstractionRpcModuleTests
{
private Contracts _contracts = new();
private AbiEncoder _encoder = new();
private static int entryPointNum = 2;
private readonly Contracts _contracts = new();
private readonly AbiEncoder _encoder = new();
private static readonly int entryPointNum = 2;

public class Contracts
{
Expand All @@ -43,7 +43,7 @@ public class Contracts
internal AbiDefinition TestCounterAbi;
internal AbiDefinition TokenPaymasterAbi;

private AbiEncoder _encoder = new();
private readonly AbiEncoder _encoder = new();

public Contracts()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ public class UserOperationPoolTests
#pragma warning disable NUnit1032
private IUserOperationPool _userOperationPool = Substitute.For<IUserOperationPool>();
#pragma warning restore NUnit1032
private IUserOperationSimulator _simulator = Substitute.For<IUserOperationSimulator>();
private IBlockTree _blockTree = Substitute.For<IBlockTree>();
private IReceiptFinder _receiptFinder = Substitute.For<IReceiptFinder>();
private ILogFinder _logFinder = Substitute.For<ILogFinder>();
private IWorldState _stateProvider = Substitute.For<IWorldState>();
private ISpecProvider _specProvider = Substitute.For<ISpecProvider>();
private readonly IUserOperationSimulator _simulator = Substitute.For<IUserOperationSimulator>();
private readonly IBlockTree _blockTree = Substitute.For<IBlockTree>();
private readonly IReceiptFinder _receiptFinder = Substitute.For<IReceiptFinder>();
private readonly ILogFinder _logFinder = Substitute.For<ILogFinder>();
private readonly IWorldState _stateProvider = Substitute.For<IWorldState>();
private readonly ISpecProvider _specProvider = Substitute.For<ISpecProvider>();
private readonly ISigner _signer = Substitute.For<ISigner>();
private readonly Hash256 _userOperationEventTopic = new("0x33fd4d1f25a5461bea901784a6571de6debc16cd0831932c22c6969cd73ba994");
private readonly string _entryPointContractAddress = "0x8595dd9e0438640b5e1254f9df579ac12a86865f";
private static Address _notAnAddress = new("0x373f2D08b1C195fF08B9AbEdE3C78575FAAC2aCf");
private static readonly Address _notAnAddress = new("0x373f2D08b1C195fF08B9AbEdE3C78575FAAC2aCf");

[Test]
public void Can_add_user_operation_correctly()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public class UserOperationSubscribeTests
private IJsonRpcDuplexClient _jsonRpcDuplexClient = null!;
private IJsonSerializer _jsonSerializer = null!;
private ISpecProvider _specProvider = null!;
private ISyncConfig _syncConfig = new SyncConfig();
private IDictionary<Address, IUserOperationPool> _userOperationPools = new Dictionary<Address, IUserOperationPool>();
private readonly ISyncConfig _syncConfig = new SyncConfig();
private readonly IDictionary<Address, IUserOperationPool> _userOperationPools = new Dictionary<Address, IUserOperationPool>();
//Any test pool and entry point addresses should work for testing.
private Address _testPoolAddress = Address.Zero;
private Address _entryPointAddress = new("0x90f3e1105e63c877bf9587de5388c23cdb702c6b");
private readonly Address _testPoolAddress = Address.Zero;
private readonly Address _entryPointAddress = new("0x90f3e1105e63c877bf9587de5388c23cdb702c6b");

[SetUp]
public void Setup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ namespace Nethermind.AccountAbstraction.Bundler
{
public class MevBundler : IBundler
{
private IBundleTrigger _trigger;
private ITxSource _txSource;
private IBundlePool _bundlePool;
private ILogger _logger;
private readonly IBundleTrigger _trigger;
private readonly ITxSource _txSource;
private readonly IBundlePool _bundlePool;
private readonly ILogger _logger;

public MevBundler(IBundleTrigger trigger, ITxSource txSource, IBundlePool bundlePool, ILogger logger)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Nethermind.AccountAbstraction.Network
public class AaProtocolHandler : ProtocolHandlerBase, IZeroProtocolHandler, IUserOperationPoolPeer
{
private readonly ISession _session;
private IDictionary<Address, IUserOperationPool> _userOperationPools;
private readonly IDictionary<Address, IUserOperationPool> _userOperationPools;
private readonly IAccountAbstractionPeerManager _peerManager;

public AaProtocolHandler(ISession session,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Nethermind.AccountAbstraction.Network
{
public class AccountAbstractionPeerManager : IAccountAbstractionPeerManager
{
private IDictionary<Address, IUserOperationPool> _userOperationPools;
private readonly IDictionary<Address, IUserOperationPool> _userOperationPools;
private readonly IUserOperationBroadcaster _broadcaster;
private readonly ILogger _logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Nethermind.AccountAbstraction.Network
{
public class UserOperationsMessageSerializer : IZeroInnerMessageSerializer<UserOperationsMessage>
{
private UserOperationDecoder _decoder = new();
private readonly UserOperationDecoder _decoder = new();

public void Serialize(IByteBuffer byteBuffer, UserOperationsMessage message)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Analytics/RewardsVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ namespace Nethermind.Analytics
{
public class RewardsVerifier : IBlockTreeVisitor
{
private ILogger _logger;
private readonly ILogger _logger;
public bool PreventsAcceptingNewBlocks => true;
public long StartLevelInclusive => 0;
public long EndLevelExclusive { get; }

private UInt256 _genesisAllocations = UInt256.Parse("72009990499480000000000000");
private readonly UInt256 _genesisAllocations = UInt256.Parse("72009990499480000000000000");
private UInt256 _uncles;

public UInt256 BlockRewards { get; private set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Analytics/SupplyVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Nethermind.Analytics
public class SupplyVerifier : ITreeVisitor
{
private readonly ILogger _logger;
private HashSet<Hash256> _ignoreThisOne = new HashSet<Hash256>();
private readonly HashSet<Hash256> _ignoreThisOne = new HashSet<Hash256>();
private int _accountsVisited;
private int _nodesVisited;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Nethermind.AuRa.Test.Transactions
{
public class PermissionTxComparerTests
{
private static Address[] WhitelistedSenders = new[] { TestItem.AddressC, TestItem.AddressD };
private static readonly Address[] WhitelistedSenders = new[] { TestItem.AddressC, TestItem.AddressD };

public static IEnumerable OrderingTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ContractBasedValidatorTests
private BlockHeader _parentHeader;
private IReadOnlyTransactionProcessor _transactionProcessor;
private IAuRaBlockFinalizationManager _blockFinalizationManager;
private static Address _contractAddress = Address.FromNumber(1000);
private static readonly Address _contractAddress = Address.FromNumber(1000);
private (Address Sender, byte[] TransactionData) _getValidatorsData = (Address.Zero, new byte[] { 0, 1, 2 });
private (Address Sender, byte[] TransactionData) _finalizeChangeData = (Address.SystemUser, new byte[] { 3, 4, 5 });
private Address[] _initialValidators;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ public void Loads_lowest_inserted_body_correctly(long beginIndex, long insertedB
}


private static object[] SourceOfBSearchTestCases =
private static readonly object[] SourceOfBSearchTestCases =
{
new object[] {1L, 0L},
new object[] {1L, 1L},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ public class BlockchainProcessorTests
{
private class ProcessingTestContext
{
private ILogManager _logManager = LimboLogs.Instance;
private readonly ILogManager _logManager = LimboLogs.Instance;

private class BlockProcessorMock : IBlockProcessor
{
private ILogger _logger;
private readonly ILogger _logger;

private HashSet<Hash256> _allowed = new();
private readonly HashSet<Hash256> _allowed = new();

private HashSet<Hash256> _allowedToFail = new();
private readonly HashSet<Hash256> _allowedToFail = new();

private HashSet<Hash256> _rootProcessed = new();
private readonly HashSet<Hash256> _rootProcessed = new();

public BlockProcessorMock(ILogManager logManager, IStateReader stateReader)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Nethermind.Blockchain.Test.Consensus
{
public class SinglePendingTxSelectorTests
{
private BlockHeader _anyParent = Build.A.BlockHeader.TestObject;
private readonly BlockHeader _anyParent = Build.A.BlockHeader.TestObject;

[Test, Timeout(Timeout.MaxTestTime)]
public void To_string_does_not_throw()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Nethermind.Blockchain.Test.Receipts;

public class ReceiptsIteratorTests
{
ReceiptArrayStorageDecoder _decoder = ReceiptArrayStorageDecoder.Instance;
readonly ReceiptArrayStorageDecoder _decoder = ReceiptArrayStorageDecoder.Instance;

[Test]
public void SmokeTestWithRecovery()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class TestTxValidator : ITxValidator
public static TestTxValidator NeverValid = new(false);

private readonly Queue<bool> _validationResults = new();
private bool? _alwaysSameResult;
private readonly bool? _alwaysSameResult;

public TestTxValidator(Queue<bool> validationResults)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Blockchain/BlockTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public partial class BlockTree : IBlockTree
{
// there is not much logic in the addressing here
public static readonly byte[] LowestInsertedBodyNumberDbEntryAddress = ((long)0).ToBigEndianByteArrayWithoutLeadingZeros();
private static byte[] StateHeadHashDbEntryAddress = new byte[16];
private static readonly byte[] StateHeadHashDbEntryAddress = new byte[16];
internal static Hash256 DeletePointerAddressInDb = new(new BitArray(32 * 8, true).ToBytes());
internal static Hash256 HeadAddressInDb = Keccak.Zero;

Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Blockchain/BlockhashProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Nethermind.Blockchain
{
public class BlockhashProvider : IBlockhashProvider
{
private static int _maxDepth = 256;
private static readonly int _maxDepth = 256;
private readonly IBlockTree _blockTree;
private readonly ILogger _logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CopyTreeVisitor : ITreeVisitor, IDisposable
private readonly Stopwatch _stopwatch;
private long _persistedNodes = 0;
private bool _finished = false;
private WriteFlags _writeFlags;
private readonly WriteFlags _writeFlags;
private readonly CancellationToken _cancellationToken;
private const int Million = 1_000_000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public ref struct LogEntriesIterator
private readonly LogEntry[]? _logs;
private readonly int _length;
private Rlp.ValueDecoderContext _decoderContext;
private IReceiptRefDecoder _receiptRefDecoder;
private readonly IReceiptRefDecoder _receiptRefDecoder;
public long Index { get; private set; }

public LogEntriesIterator(Span<byte> data, IReceiptRefDecoder receiptRefDecoder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public ref struct ReceiptsIterator
private readonly IDb _blocksDb;
private readonly int _length;
private Rlp.ValueDecoderContext _decoderContext;
private int _startingPosition;
private readonly int _startingPosition;

private readonly TxReceipt[]? _receipts;
private int _receiptIndex;

private readonly Func<IReceiptsRecovery.IRecoveryContext>? _recoveryContextFactory;
private IReceiptsRecovery.IRecoveryContext? _recoveryContext;
private IReceiptRefDecoder _receiptRefDecoder;
private readonly IReceiptRefDecoder _receiptRefDecoder;
private bool _recoveryContextConfigured;

public ReceiptsIterator(scoped in Span<byte> receiptsData, IDb blocksDb, Func<IReceiptsRecovery.IRecoveryContext?>? recoveryContextFactory, IReceiptRefDecoder receiptRefDecoder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class StartupBlockTreeFixer : IBlockTreeVisitor
private readonly IBlockTree _blockTree;
private readonly IStateReader _stateReader;
private readonly ILogger _logger;
private long _startNumber;
private long _blocksToLoad;
private readonly long _startNumber;
private readonly long _blocksToLoad;

private ChainLevelInfo _currentLevel;
private long _currentLevelNumber;
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Cli.Test/ProofCliModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Nethermind.Cli.Test
{
public class ProofCliModuleTests
{
private ICliConsole _cliConsole = Substitute.For<ICliConsole>();
private readonly ICliConsole _cliConsole = Substitute.For<ICliConsole>();
private EthereumJsonSerializer _serializer;
private IJsonRpcClient _jsonRpcClient;
private CliEngine _engine;
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Cli/Modules/CliModuleLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void LoadModule(Type type)
}
}

private Dictionary<string, ObjectInstance> _objects = new Dictionary<string, ObjectInstance>();
private readonly Dictionary<string, ObjectInstance> _objects = new Dictionary<string, ObjectInstance>();

private static void AddMethod(ObjectInstance instance, string name, DelegateWrapper delegateWrapper)
{
Expand Down
30 changes: 15 additions & 15 deletions src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ public class CliqueBlockProducerTests
{
private class On
{
private ILogManager _logManager = LimboLogs.Instance;
private readonly ILogManager _logManager = LimboLogs.Instance;
// private ILogManager _logManager = new OneLoggerLogManager(new ConsoleAsyncLogger(LogLevel.Debug));
private ILogger _logger;
private static ITimestamper _timestamper = Timestamper.Default;
private CliqueConfig _cliqueConfig;
private EthereumEcdsa _ethereumEcdsa = new(BlockchainIds.Goerli, LimboLogs.Instance);
private Dictionary<PrivateKey, ILogManager> _logManagers = new();
private Dictionary<PrivateKey, ISnapshotManager> _snapshotManager = new();
private Dictionary<PrivateKey, BlockTree> _blockTrees = new();
private Dictionary<PrivateKey, AutoResetEvent> _blockEvents = new();
private Dictionary<PrivateKey, CliqueBlockProducer> _producers = new();
private Dictionary<PrivateKey, TxPool.TxPool> _pools = new();
private readonly ILogger _logger;
private static readonly ITimestamper _timestamper = Timestamper.Default;
private readonly CliqueConfig _cliqueConfig;
private readonly EthereumEcdsa _ethereumEcdsa = new(BlockchainIds.Goerli, LimboLogs.Instance);
private readonly Dictionary<PrivateKey, ILogManager> _logManagers = new();
private readonly Dictionary<PrivateKey, ISnapshotManager> _snapshotManager = new();
private readonly Dictionary<PrivateKey, BlockTree> _blockTrees = new();
private readonly Dictionary<PrivateKey, AutoResetEvent> _blockEvents = new();
private readonly Dictionary<PrivateKey, CliqueBlockProducer> _producers = new();
private readonly Dictionary<PrivateKey, TxPool.TxPool> _pools = new();

private On()
: this(15)
Expand Down Expand Up @@ -198,9 +198,9 @@ public On CreateNode(PrivateKey privateKey, bool withGenesisAlreadyProcessed = f

public static On FastGoerli => new(1);

private Block _genesis3Validators;
private readonly Block _genesis3Validators;

private Block _genesis;
private readonly Block _genesis;

private Block GetGenesis(int validatorsCount = 2)
{
Expand Down Expand Up @@ -438,7 +438,7 @@ public async Task<On> StopNode(PrivateKey privateKeyA)
return this;
}

private UInt256 _currentNonce = 0;
private readonly UInt256 _currentNonce = 0;

public On AddPendingTransaction(PrivateKey nodeKey)
{
Expand Down Expand Up @@ -553,7 +553,7 @@ public On Wait(int i)
}
}

private static int _timeout = 2000; // this has to cover block period of second + wiggle of up to 500ms * (signers - 1) + 100ms delay of the block readiness check
private static readonly int _timeout = 2000; // this has to cover block period of second + wiggle of up to 500ms * (signers - 1) + 100ms delay of the block readiness check

[Test]
public async Task Can_produce_block_with_transactions()
Expand Down
Loading

0 comments on commit 7cc8358

Please sign in to comment.