From 0e78d534b60c2234fb4cf3cd67d685507652d0f9 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Sun, 30 Jun 2024 00:50:49 +0800 Subject: [PATCH] add a dbft unit test system --- neo.sln | 7 +++ src/Plugins/DBFTPlugin/DBFTPlugin.cs | 8 +++ .../TestP2PSettings.cs | 55 +++++++++++++++++++ .../TestWalletProvider.cs | 35 ++++++++++++ .../Neo.Plugins.DBFTPlugin.Tests/config.json | 11 ++++ 5 files changed, 116 insertions(+) create mode 100644 tests/Neo.Plugins.DBFTPlugin.Tests/TestP2PSettings.cs create mode 100644 tests/Neo.Plugins.DBFTPlugin.Tests/TestWalletProvider.cs create mode 100644 tests/Neo.Plugins.DBFTPlugin.Tests/config.json diff --git a/neo.sln b/neo.sln index b0de1c27b1..7489ff8e5c 100644 --- a/neo.sln +++ b/neo.sln @@ -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 @@ -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 @@ -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} diff --git a/src/Plugins/DBFTPlugin/DBFTPlugin.cs b/src/Plugins/DBFTPlugin/DBFTPlugin.cs index 65fc5011dc..e05f4221a3 100644 --- a/src/Plugins/DBFTPlugin/DBFTPlugin.cs +++ b/src/Plugins/DBFTPlugin/DBFTPlugin.cs @@ -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; diff --git a/tests/Neo.Plugins.DBFTPlugin.Tests/TestP2PSettings.cs b/tests/Neo.Plugins.DBFTPlugin.Tests/TestP2PSettings.cs new file mode 100644 index 0000000000..231f426d25 --- /dev/null +++ b/tests/Neo.Plugins.DBFTPlugin.Tests/TestP2PSettings.cs @@ -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 + }; +} diff --git a/tests/Neo.Plugins.DBFTPlugin.Tests/TestWalletProvider.cs b/tests/Neo.Plugins.DBFTPlugin.Tests/TestWalletProvider.cs new file mode 100644 index 0000000000..a46ae17751 --- /dev/null +++ b/tests/Neo.Plugins.DBFTPlugin.Tests/TestWalletProvider.cs @@ -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 WalletChanged; + + private Wallet Wallet + { + get + { + var wallet = TestUtils.GenerateTestWallet("123"); + var privateKey = Wallet.GetPrivateKeyFromWIF(wif); + wallet.CreateAccount(privateKey); + return wallet; + } + } + + public Wallet GetWallet() => Wallet; +} diff --git a/tests/Neo.Plugins.DBFTPlugin.Tests/config.json b/tests/Neo.Plugins.DBFTPlugin.Tests/config.json new file mode 100644 index 0000000000..7a33ed1f16 --- /dev/null +++ b/tests/Neo.Plugins.DBFTPlugin.Tests/config.json @@ -0,0 +1,11 @@ +{ + "PluginConfiguration": { + "RecoveryLogs": "ConsensusState", + "IgnoreRecoveryLogs": false, + "AutoStart": true, + "Network": 860833102, + "MaxBlockSize": 2097152, + "MaxBlockSystemFee": 150000000000, + "UnhandledExceptionPolicy": "StopNode" + } +}