From 6844c61b485301ac6fc13161419b6c3fbcfeb0f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Mon, 21 Dec 2020 22:06:31 -0600 Subject: [PATCH 1/2] dotnet 5.0 (#407) --- .github/workflows/main.yml | 6 ++-- src/Directory.Build.props | 8 +++--- src/RpcClient/ContractClient.cs | 4 +-- src/RpcNep17Tracker/RpcNep17Tracker.cs | 3 +- src/RpcServer/RpcServer.Blockchain.cs | 4 +-- src/RpcServer/RpcServer.SmartContract.cs | 2 +- tests/Directory.Build.props | 15 ++++++++++ .../Neo.Network.RPC.Tests.csproj | 5 ---- tests/Neo.Network.RPC.Tests/RpcTestCases.json | 16 ++++++----- .../UT_ContractClient.cs | 4 +-- .../Neo.Plugins.StateService.Tests.csproj | 28 +++++++------------ .../Neo.Plugins.Storage.Tests.csproj | 8 ------ 12 files changed, 49 insertions(+), 54 deletions(-) create mode 100644 tests/Directory.Build.props diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4a5401c3d..2f9ffe2c5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,7 +6,7 @@ on: pull_request: env: - DOTNET_VERSION: 3.1.100 + DOTNET_VERSION: 5.0.100 jobs: @@ -21,8 +21,8 @@ jobs: dotnet-version: ${{ env.DOTNET_VERSION }} - name: Check format run: | - dotnet tool install --version 3.2.111002 --tool-path ./ dotnet-format --add-source https://dotnet.myget.org/F/format/api/v3/index.json - ./dotnet-format --check --dry-run -v diagnostic + dotnet tool install --version 5.0.142902 --tool-path ./ dotnet-format --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json + ./dotnet-format . --check -v diagnostic - name: Test run: | sudo apt-get --assume-yes install libleveldb-dev libsnappy-dev libc6-dev diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 28635c471..d2c7dfa9c 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,10 +1,10 @@ - + 3.0.0 preview4 - netstandard2.1 + net5.0 Neo.Plugins The Neo Project NEO;Blockchain @@ -15,7 +15,7 @@ - + - \ No newline at end of file + diff --git a/src/RpcClient/ContractClient.cs b/src/RpcClient/ContractClient.cs index bc664c82f..296c2e12b 100644 --- a/src/RpcClient/ContractClient.cs +++ b/src/RpcClient/ContractClient.cs @@ -1,4 +1,3 @@ -using System.Threading.Tasks; using Neo.Network.P2P.Payloads; using Neo.Network.RPC.Models; using Neo.SmartContract; @@ -6,6 +5,7 @@ using Neo.SmartContract.Native; using Neo.VM; using Neo.Wallets; +using System.Threading.Tasks; namespace Neo.Network.RPC { @@ -57,7 +57,7 @@ public async Task CreateDeployContractTxAsync(byte[] nefFile, Contr byte[] script; using (ScriptBuilder sb = new ScriptBuilder()) { - sb.EmitAppCall(NativeContract.Management.Hash, "deploy", nefFile, manifest.ToString()); + sb.EmitAppCall(NativeContract.ContractManagement.Hash, "deploy", nefFile, manifest.ToString()); script = sb.ToArray(); } UInt160 sender = Contract.CreateSignatureRedeemScript(key.PublicKey).ToScriptHash(); diff --git a/src/RpcNep17Tracker/RpcNep17Tracker.cs b/src/RpcNep17Tracker/RpcNep17Tracker.cs index 9dcef2318..79fbafa7c 100644 --- a/src/RpcNep17Tracker/RpcNep17Tracker.cs +++ b/src/RpcNep17Tracker/RpcNep17Tracker.cs @@ -1,4 +1,3 @@ -using Microsoft.AspNetCore.Http; using Neo.IO; using Neo.IO.Caching; using Neo.IO.Data.LevelDB; @@ -287,7 +286,7 @@ public JObject GetNep17Balances(JArray _params) foreach (var (key, value) in dbCache.Find(prefix)) { JObject balance = new JObject(); - if (NativeContract.Management.GetContract(snapshot, key.AssetScriptHash) is null) + if (NativeContract.ContractManagement.GetContract(snapshot, key.AssetScriptHash) is null) continue; balance["assethash"] = key.AssetScriptHash.ToString(); balance["amount"] = value.Balance.ToString(); diff --git a/src/RpcServer/RpcServer.Blockchain.cs b/src/RpcServer/RpcServer.Blockchain.cs index adccfbf38..16eb2a990 100644 --- a/src/RpcServer/RpcServer.Blockchain.cs +++ b/src/RpcServer/RpcServer.Blockchain.cs @@ -106,7 +106,7 @@ protected virtual JObject GetContractState(JArray _params) { using SnapshotView snapshot = Blockchain.Singleton.GetSnapshot(); UInt160 script_hash = ToScriptHash(_params[0].AsString()); - ContractState contract = NativeContract.Management.GetContract(snapshot, script_hash); + ContractState contract = NativeContract.ContractManagement.GetContract(snapshot, script_hash); return contract?.ToJson() ?? throw new RpcException(-100, "Unknown contract"); } @@ -170,7 +170,7 @@ protected virtual JObject GetStorage(JArray _params) { using SnapshotView snapshot = Blockchain.Singleton.GetSnapshot(); UInt160 script_hash = UInt160.Parse(_params[0].AsString()); - ContractState contract = NativeContract.Management.GetContract(snapshot, script_hash); + ContractState contract = NativeContract.ContractManagement.GetContract(snapshot, script_hash); if (contract == null) return null; id = contract.Id; } diff --git a/src/RpcServer/RpcServer.SmartContract.cs b/src/RpcServer/RpcServer.SmartContract.cs index ca635f896..475a12bf6 100644 --- a/src/RpcServer/RpcServer.SmartContract.cs +++ b/src/RpcServer/RpcServer.SmartContract.cs @@ -110,7 +110,7 @@ private static Signers SignersFromJson(JArray _params) private JObject GetVerificationResult(UInt160 scriptHash, ContractParameter[] args, Signers signers = null) { var snapshot = Blockchain.Singleton.GetSnapshot(); - var contract = NativeContract.Management.GetContract(snapshot, scriptHash); + var contract = NativeContract.ContractManagement.GetContract(snapshot, scriptHash); if (contract is null) { throw new RpcException(-100, "Unknown contract"); diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props new file mode 100644 index 000000000..3a7fa1350 --- /dev/null +++ b/tests/Directory.Build.props @@ -0,0 +1,15 @@ + + + + + net5.0 + false + + + + + + + + + diff --git a/tests/Neo.Network.RPC.Tests/Neo.Network.RPC.Tests.csproj b/tests/Neo.Network.RPC.Tests/Neo.Network.RPC.Tests.csproj index af5c7c416..3209d575a 100644 --- a/tests/Neo.Network.RPC.Tests/Neo.Network.RPC.Tests.csproj +++ b/tests/Neo.Network.RPC.Tests/Neo.Network.RPC.Tests.csproj @@ -1,16 +1,11 @@ - netcoreapp3.1 Neo.Network.RPC.Tests - false - - - diff --git a/tests/Neo.Network.RPC.Tests/RpcTestCases.json b/tests/Neo.Network.RPC.Tests/RpcTestCases.json index 1e97c3832..c62c64d5e 100644 --- a/tests/Neo.Network.RPC.Tests/RpcTestCases.json +++ b/tests/Neo.Network.RPC.Tests/RpcTestCases.json @@ -1112,24 +1112,26 @@ "Name": "invokescriptasync", "Request": { "jsonrpc": "2.0", + "id": 1, "method": "invokescript", - "params": [ "EMMMCGRlY2ltYWxzDBQ7fTcRxvDM+bHcqQPRv6HYlvEjjEFifVtS" ], - "id": 1 + "params": [ + "HxDDDAhkZWNpbWFscwwU\u002B\u002B3\u002BLtIiZZK2SMTal7nJzV3BpqZB7vQM2w==" + ] }, "Response": { "jsonrpc": "2.0", "id": 1, "result": { - "script": "EMMMCGRlY2ltYWxzDBQ7fTcRxvDM+bHcqQPRv6HYlvEjjEFifVtS", + "script": "HxDDDAhkZWNpbWFscwwU++3+LtIiZZK2SMTal7nJzV3BpqZB7vQM2w==", "state": "HALT", - "gasconsumed": "0.0506156", + "gasconsumed": "0.0099918", + "exception": null, "stack": [ { "type": "Integer", "value": "8" } - ], - "tx": "00769d16556925aa554712439a9c613ba114efa3fac23ddbca00e1f505000000009e021400000000005620200000009910c30c046e616d650c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b5210c30c0673796d626f6c0c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b5210c30c08646563696d616c730c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b5210c30c0b746f74616c537570706c790c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b5201420c40c848d0fcbf5e6a820508242ea8b7ccbeed3caefeed5db570537279c2154f7cfd8b0d8f477f37f4e6ca912935b732684d57c455dff7aa525ad4ab000931f22208290c2103aa052fbcb8e5b33a4eefd662536f8684641f04109f1d5e69cdda6f084890286a0b410a906ad4" + ] } } }, @@ -1152,7 +1154,7 @@ "Request": { "jsonrpc": "2.0", "method": "getwalletbalance", - "params": [ "0x8c23f196d8a1bfd103a9dcb1f9ccf0c611377d3b" ], + "params": [ "0xa6a6c15dcdc9b997dac448b6926522d22efeedfb" ], "id": 1 }, "Response": { diff --git a/tests/Neo.Network.RPC.Tests/UT_ContractClient.cs b/tests/Neo.Network.RPC.Tests/UT_ContractClient.cs index 0de9a0958..06b331595 100644 --- a/tests/Neo.Network.RPC.Tests/UT_ContractClient.cs +++ b/tests/Neo.Network.RPC.Tests/UT_ContractClient.cs @@ -1,4 +1,3 @@ -using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using Neo.SmartContract; @@ -6,6 +5,7 @@ using Neo.SmartContract.Native; using Neo.VM; using Neo.Wallets; +using System.Threading.Tasks; namespace Neo.Network.RPC.Tests { @@ -55,7 +55,7 @@ public async Task TestDeployContract() }; using (ScriptBuilder sb = new ScriptBuilder()) { - sb.EmitAppCall(NativeContract.Management.Hash, "deploy", new byte[1], manifest.ToString()); + sb.EmitAppCall(NativeContract.ContractManagement.Hash, "deploy", new byte[1], manifest.ToString()); script = sb.ToArray(); } diff --git a/tests/Neo.Plugins.StateService.Tests/Neo.Plugins.StateService.Tests.csproj b/tests/Neo.Plugins.StateService.Tests/Neo.Plugins.StateService.Tests.csproj index 4f0dfa232..94b2e2355 100644 --- a/tests/Neo.Plugins.StateService.Tests/Neo.Plugins.StateService.Tests.csproj +++ b/tests/Neo.Plugins.StateService.Tests/Neo.Plugins.StateService.Tests.csproj @@ -1,18 +1,10 @@ - - - - netcoreapp3.0 - Neo.Plugins.StateService.Tests - false - - - - - - - - - - - - + + + + Neo.Plugins.StateService.Tests + + + + + + diff --git a/tests/Neo.Plugins.Storage.Tests/Neo.Plugins.Storage.Tests.csproj b/tests/Neo.Plugins.Storage.Tests/Neo.Plugins.Storage.Tests.csproj index ac7f99449..c6798b71a 100644 --- a/tests/Neo.Plugins.Storage.Tests/Neo.Plugins.Storage.Tests.csproj +++ b/tests/Neo.Plugins.Storage.Tests/Neo.Plugins.Storage.Tests.csproj @@ -1,17 +1,9 @@ - netcoreapp3.0 Neo.Plugins.Storage.Tests - false - - - - - - From b520c528ddae63275e9d420b21eff5a46f4cae10 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Tue, 22 Dec 2020 12:19:32 +0800 Subject: [PATCH 2/2] CI01123 (#435) --- src/Directory.Build.props | 2 +- src/LevelDBStore/LevelDBStore.csproj | 7 ------ src/LevelDBStore/LevelDBStore/config.json | 5 ---- .../Plugins/Storage/LevelDBStore.cs | 10 ++------ .../Plugins/Storage/RocksDBStore.cs | 14 ++++------- src/RocksDBStore/Plugins/Storage/Settings.cs | 21 ----------------- src/RocksDBStore/RocksDBStore.csproj | 7 ------ src/RocksDBStore/RocksDBStore/config.json | 5 ---- tests/Neo.Plugins.Storage.Tests/StoreTest.cs | 23 +++++++++++-------- 9 files changed, 21 insertions(+), 73 deletions(-) delete mode 100644 src/LevelDBStore/LevelDBStore/config.json delete mode 100644 src/RocksDBStore/Plugins/Storage/Settings.cs delete mode 100644 src/RocksDBStore/RocksDBStore/config.json diff --git a/src/Directory.Build.props b/src/Directory.Build.props index d2c7dfa9c..c8dcf12f9 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -15,7 +15,7 @@ - + diff --git a/src/LevelDBStore/LevelDBStore.csproj b/src/LevelDBStore/LevelDBStore.csproj index d49bce97d..42232fbd1 100644 --- a/src/LevelDBStore/LevelDBStore.csproj +++ b/src/LevelDBStore/LevelDBStore.csproj @@ -6,11 +6,4 @@ true - - - PreserveNewest - PreserveNewest - - - diff --git a/src/LevelDBStore/LevelDBStore/config.json b/src/LevelDBStore/LevelDBStore/config.json deleted file mode 100644 index f31d07fd6..000000000 --- a/src/LevelDBStore/LevelDBStore/config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "PluginConfiguration": { - "Path": "Data_LevelDB_{0}" - } -} diff --git a/src/LevelDBStore/Plugins/Storage/LevelDBStore.cs b/src/LevelDBStore/Plugins/Storage/LevelDBStore.cs index 61118a57a..246052af3 100644 --- a/src/LevelDBStore/Plugins/Storage/LevelDBStore.cs +++ b/src/LevelDBStore/Plugins/Storage/LevelDBStore.cs @@ -7,17 +7,11 @@ namespace Neo.Plugins.Storage { public class LevelDBStore : Plugin, IStorageProvider { - private string path; - public override string Description => "Uses LevelDB to store the blockchain data"; - protected override void Configure() - { - path = string.Format(GetConfiguration().GetSection("Path").Value ?? "Data_LevelDB_{0}", ProtocolSettings.Default.Magic.ToString("X8")); - } - - public IStore GetStore() + public IStore GetStore(string path) { + path = string.Format(path, ProtocolSettings.Default.Magic.ToString("X8")); if (Environment.CommandLine.Split(' ').Any(p => p == "/repair" || p == "--repair")) DB.Repair(path, Options.Default); return new Store(path); diff --git a/src/RocksDBStore/Plugins/Storage/RocksDBStore.cs b/src/RocksDBStore/Plugins/Storage/RocksDBStore.cs index 6377845e6..e82b5a815 100644 --- a/src/RocksDBStore/Plugins/Storage/RocksDBStore.cs +++ b/src/RocksDBStore/Plugins/Storage/RocksDBStore.cs @@ -6,18 +6,14 @@ public class RocksDBStore : Plugin, IStorageProvider { public override string Description => "Uses RocksDBStore to store the blockchain data"; - /// - /// Configure - /// - protected override void Configure() - { - Settings.Load(GetConfiguration()); - } - /// /// Get store /// /// RocksDbStore - public IStore GetStore() => new Store(Settings.Default.Path); + public IStore GetStore(string path) + { + path = string.Format(path, ProtocolSettings.Default.Magic.ToString("X8")); + return new Store(path); + } } } diff --git a/src/RocksDBStore/Plugins/Storage/Settings.cs b/src/RocksDBStore/Plugins/Storage/Settings.cs deleted file mode 100644 index 253be9751..000000000 --- a/src/RocksDBStore/Plugins/Storage/Settings.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Microsoft.Extensions.Configuration; - -namespace Neo.Plugins.Storage -{ - internal class Settings - { - public string Path { get; } - - public static Settings Default { get; private set; } - - private Settings(IConfigurationSection section) - { - this.Path = string.Format(section.GetSection("Path").Value ?? "Data_RocksDB_{0}", ProtocolSettings.Default.Magic.ToString("X8")); - } - - public static void Load(IConfigurationSection section) - { - Default = new Settings(section); - } - } -} diff --git a/src/RocksDBStore/RocksDBStore.csproj b/src/RocksDBStore/RocksDBStore.csproj index e1f5bad60..f86fae3c0 100644 --- a/src/RocksDBStore/RocksDBStore.csproj +++ b/src/RocksDBStore/RocksDBStore.csproj @@ -5,13 +5,6 @@ Neo.Plugins.Storage - - - PreserveNewest - PreserveNewest - - - diff --git a/src/RocksDBStore/RocksDBStore/config.json b/src/RocksDBStore/RocksDBStore/config.json deleted file mode 100644 index 5ded6dfe1..000000000 --- a/src/RocksDBStore/RocksDBStore/config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "PluginConfiguration": { - "Path": "Data_RocksDB_{0}" - } -} diff --git a/tests/Neo.Plugins.Storage.Tests/StoreTest.cs b/tests/Neo.Plugins.Storage.Tests/StoreTest.cs index a09bedacb..af2e51342 100644 --- a/tests/Neo.Plugins.Storage.Tests/StoreTest.cs +++ b/tests/Neo.Plugins.Storage.Tests/StoreTest.cs @@ -6,6 +6,9 @@ namespace Neo.Plugins.Storage.Tests [TestClass] public class StoreTest { + private const string path_leveldb = "Data_LevelDB_{0}"; + private const string path_rocksdb = "Data_RocksDB_{0}"; + [TestMethod] public void TestLevelDb() { @@ -13,14 +16,14 @@ public void TestLevelDb() { // Test all with the same store - TestStorage(plugin.GetStore()); + TestStorage(plugin.GetStore(path_leveldb)); // Test with different storages - TestPersistenceWrite(plugin.GetStore()); - TestPersistenceRead(plugin.GetStore(), true); - TestPersistenceDelete(plugin.GetStore()); - TestPersistenceRead(plugin.GetStore(), false); + TestPersistenceWrite(plugin.GetStore(path_leveldb)); + TestPersistenceRead(plugin.GetStore(path_leveldb), true); + TestPersistenceDelete(plugin.GetStore(path_leveldb)); + TestPersistenceRead(plugin.GetStore(path_leveldb), false); } } @@ -31,14 +34,14 @@ public void TestRocksDb() { // Test all with the same store - TestStorage(plugin.GetStore()); + TestStorage(plugin.GetStore(path_rocksdb)); // Test with different storages - TestPersistenceWrite(plugin.GetStore()); - TestPersistenceRead(plugin.GetStore(), true); - TestPersistenceDelete(plugin.GetStore()); - TestPersistenceRead(plugin.GetStore(), false); + TestPersistenceWrite(plugin.GetStore(path_rocksdb)); + TestPersistenceRead(plugin.GetStore(path_rocksdb), true); + TestPersistenceDelete(plugin.GetStore(path_rocksdb)); + TestPersistenceRead(plugin.GetStore(path_rocksdb), false); } }