Skip to content

Commit

Permalink
add a dbft unit test system
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim8y committed Jun 29, 2024
1 parent 07fb5ce commit 0e78d53
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 0 deletions.
7 changes: 7 additions & 0 deletions neo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TokensTracker", "src\Plugin
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RpcClient", "src\Plugins\RpcClient\RpcClient.csproj", "{185ADAFC-BFC6-413D-BC2E-97F9FB0A8AF0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo.Plugins.DBFTPlugin.Tests", "tests\Neo.Plugins.DBFTPlugin.Tests\Neo.Plugins.DBFTPlugin.Tests.csproj", "{4E42A911-8B39-41BE-A8C8-8463D82E0D45}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -216,6 +218,10 @@ Global
{185ADAFC-BFC6-413D-BC2E-97F9FB0A8AF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{185ADAFC-BFC6-413D-BC2E-97F9FB0A8AF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{185ADAFC-BFC6-413D-BC2E-97F9FB0A8AF0}.Release|Any CPU.Build.0 = Release|Any CPU
{4E42A911-8B39-41BE-A8C8-8463D82E0D45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E42A911-8B39-41BE-A8C8-8463D82E0D45}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E42A911-8B39-41BE-A8C8-8463D82E0D45}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E42A911-8B39-41BE-A8C8-8463D82E0D45}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -255,6 +261,7 @@ Global
{FF76D8A4-356B-461A-8471-BC1B83E57BBC} = {C2DC830A-327A-42A7-807D-295216D30DBB}
{5E4947F3-05D3-4806-B0F3-30DAC71B5986} = {C2DC830A-327A-42A7-807D-295216D30DBB}
{185ADAFC-BFC6-413D-BC2E-97F9FB0A8AF0} = {C2DC830A-327A-42A7-807D-295216D30DBB}
{4E42A911-8B39-41BE-A8C8-8463D82E0D45} = {7F257712-D033-47FF-B439-9D4320D06599}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BCBA19D9-F868-4C6D-8061-A2B91E06E3EC}
Expand Down
8 changes: 8 additions & 0 deletions src/Plugins/DBFTPlugin/DBFTPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public DBFTPlugin()
RemoteNode.MessageReceived += ((IMessageReceivedHandler)this).RemoteNode_MessageReceived_Handler;
}

#if DEBUG
public DBFTPlugin(NeoSystem neoSystem, IWalletProvider wallet) : this()
{
this.neoSystem = neoSystem;
walletProvider = wallet;
}
#endif

public DBFTPlugin(Settings settings) : this()
{
this.settings = settings;
Expand Down
55 changes: 55 additions & 0 deletions tests/Neo.Plugins.DBFTPlugin.Tests/TestP2PSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// TestP2PSettings.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

namespace Neo.Plugins.RpcServer.Tests;

public class TestP2PSettings
{
public ushort Port { get; init; }
public int MinDesiredConnections { get; } = 5;
public int MaxConnections { get; } = 20;
public int MaxConnectionsPerAddress { get; } = 10;

public static readonly TestP2PSettings Node1 = new()
{
Port = 30333
};

public static readonly TestP2PSettings Node2 = new()
{
Port = 30334
};

public static readonly TestP2PSettings Node3 = new()
{
Port = 30335
};

public static readonly TestP2PSettings Node4 = new()
{
Port = 30336
};

public static readonly TestP2PSettings Node5 = new()
{
Port = 30337
};

public static readonly TestP2PSettings Node6 = new()
{
Port = 30338
};

public static readonly TestP2PSettings Node7 = new()
{
Port = 30339
};
}
35 changes: 35 additions & 0 deletions tests/Neo.Plugins.DBFTPlugin.Tests/TestWalletProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// TestWalletProvider.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using Neo.UnitTests;
using Neo.Wallets;
using Neo.Wallets.NEP6;
using System;

namespace Neo.Plugins.RpcServer.Tests;

public class TestWalletProvider(string wif) : IWalletProvider
{
public event EventHandler<Wallet> WalletChanged;

private Wallet Wallet
{
get
{
var wallet = TestUtils.GenerateTestWallet("123");
var privateKey = Wallet.GetPrivateKeyFromWIF(wif);
wallet.CreateAccount(privateKey);
return wallet;
}
}

public Wallet GetWallet() => Wallet;
}
11 changes: 11 additions & 0 deletions tests/Neo.Plugins.DBFTPlugin.Tests/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"PluginConfiguration": {
"RecoveryLogs": "ConsensusState",
"IgnoreRecoveryLogs": false,
"AutoStart": true,
"Network": 860833102,
"MaxBlockSize": 2097152,
"MaxBlockSystemFee": 150000000000,
"UnhandledExceptionPolicy": "StopNode"
}
}

0 comments on commit 0e78d53

Please sign in to comment.