Skip to content

Commit

Permalink
Update neo (#1285)
Browse files Browse the repository at this point in the history
* Update neo

* update neo

* Revert some of them

* Fix

* Fix ut

---------

Co-authored-by: Jimmy <[email protected]>
  • Loading branch information
shargon and Jim8y authored Jan 24, 2025
1 parent 465637f commit 83e6095
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 55 deletions.
2 changes: 1 addition & 1 deletion neo
Submodule neo updated 96 files
+1 −1 .devcontainer/devcontainer.dockerfile
+4 −0 benchmarks/Directory.Build.props
+59 −0 benchmarks/Neo.Benchmarks/Persistence/Bechmarks_LevelDB.cs
+1 −0 benchmarks/Neo.Benchmarks/Program.cs
+38 −46 benchmarks/Neo.Json.Benchmarks/Benchmark_JsonDeserialize.cs
+1 −7 benchmarks/Neo.Json.Benchmarks/Benchmark_OrderedDictionary.cs
+0 −1 benchmarks/Neo.Json.Benchmarks/Neo.Json.Benchmarks.csproj
+2 −2 benchmarks/Neo.Json.Benchmarks/Program.cs
+1 −1 global.json
+3 −0 src/Directory.Build.props
+3 −3 src/Neo.CLI/CLI/MainService.cs
+5 −5 src/Neo.Extensions/ByteExtensions.cs
+1 −1 src/Neo.Extensions/Collections/CollectionExtensions.cs
+3 −1 src/Neo.Extensions/StringExtensions.cs
+1 −1 src/Neo.VM/JumpTable/JumpTable.Splice.cs
+99 −0 src/Neo/Cryptography/Ed25519.cs
+2 −1 src/Neo/Hardfork.cs
+2 −0 src/Neo/Neo.csproj
+7 −4 src/Neo/Persistence/IReadOnlyStore.cs
+4 −3 src/Neo/Persistence/MemorySnapshot.cs
+6 −7 src/Neo/Persistence/MemoryStore.cs
+59 −7 src/Neo/ProtocolSettings.cs
+37 −1 src/Neo/SmartContract/ApplicationEngine.cs
+1 −1 src/Neo/SmartContract/Contract.cs
+2 −1 src/Neo/SmartContract/Native/ContractMethodAttribute.cs
+2 −1 src/Neo/SmartContract/Native/ContractMethodMetadata.cs
+31 −0 src/Neo/SmartContract/Native/CryptoLib.cs
+1 −1 src/Neo/SmartContract/Native/FungibleToken.cs
+18 −11 src/Neo/SmartContract/Native/NativeContract.cs
+48 −4 src/Neo/SmartContract/Native/NeoToken.cs
+21 −2 src/Neo/SmartContract/Native/RoleManagement.cs
+23 −0 src/Neo/SmartContract/Native/StdLib.cs
+2 −4 src/Plugins/LevelDBStore/IO/Data/LevelDB/DB.cs
+8 −6 src/Plugins/LevelDBStore/IO/Data/LevelDB/Helper.cs
+2 −2 src/Plugins/LevelDBStore/IO/Data/LevelDB/Iterator.cs
+19 −4 src/Plugins/LevelDBStore/IO/Data/LevelDB/Native.cs
+1 −0 src/Plugins/LevelDBStore/LevelDBStore.csproj
+20 −10 src/Plugins/LevelDBStore/Plugins/Storage/Snapshot.cs
+4 −3 src/Plugins/LevelDBStore/Plugins/Storage/Store.cs
+3 −3 src/Plugins/RocksDBStore/Plugins/Storage/Options.cs
+36 −23 src/Plugins/RocksDBStore/Plugins/Storage/Snapshot.cs
+16 −15 src/Plugins/RocksDBStore/Plugins/Storage/Store.cs
+1 −0 src/Plugins/RocksDBStore/RocksDBStore.csproj
+7 −5 src/Plugins/RpcServer/Result.cs
+0 −0 src/Plugins/StatelessBlock/StatelessBlock.cs
+0 −0 src/Plugins/StatelessBlock/StatelessBlock.csproj
+4 −2 tests/Directory.Build.props
+4 −2 tests/Neo.Cryptography.MPTTrie.Tests/Cryptography/MPTTrie/UT_Node.cs
+2 −2 tests/Neo.Cryptography.MPTTrie.Tests/Cryptography/MPTTrie/UT_Trie.cs
+0 −1 tests/Neo.Extensions.Tests/Collections/UT_CollectionExtensions.cs
+1 −2 tests/Neo.Extensions.Tests/Collections/UT_HashSetExtensions.cs
+1 −2 tests/Neo.Extensions.Tests/UT_ByteArrayComparer.cs
+2 −3 tests/Neo.Extensions.Tests/UT_ByteExtensions.cs
+2 −5 tests/Neo.Extensions.Tests/UT_StringExtensions.cs
+11 −0 tests/Neo.Extensions.Tests/UT_UnsafeData.cs
+4 −2 tests/Neo.Json.UnitTests/UT_JArray.cs
+19 −11 tests/Neo.Network.RPC.Tests/UT_Utility.cs
+1 −1 tests/Neo.Plugins.ApplicationLogs.Tests/Setup/TestStorage.cs
+15 −25 tests/Neo.Plugins.ApplicationLogs.Tests/UT_LogReader.cs
+1 −1 tests/Neo.Plugins.OracleService.Tests/E2E_Https.cs
+36 −20 tests/Neo.Plugins.OracleService.Tests/TestBlockchain.cs
+2 −0 tests/Neo.Plugins.RpcServer.Tests/UT_Result.cs
+2 −8 tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.SmartContract.cs
+1 −1 tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Utilities.cs
+3 −18 tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Wallet.cs
+19 −1 tests/Neo.Plugins.Storage.Tests/StoreTest.cs
+162 −0 tests/Neo.UnitTests/Cryptography/UT_Ed25519.cs
+3 −7 tests/Neo.UnitTests/IO/Caching/UT_KeyedCollectionSlim.cs
+4 −2 tests/Neo.UnitTests/Ledger/UT_HeaderCache.cs
+1 −1 tests/Neo.UnitTests/Network/P2P/Capabilities/UT_ArchivalNodeCapability.cs
+1 −1 tests/Neo.UnitTests/Network/P2P/Capabilities/UT_UnknownCapability.cs
+1 −2 tests/Neo.UnitTests/Network/P2P/Payloads/UT_Header.cs
+1 −2 tests/Neo.UnitTests/Persistence/UT_CloneCache.cs
+2 −1 tests/Neo.UnitTests/Persistence/UT_MemoryClonedCache.cs
+4 −2 tests/Neo.UnitTests/Persistence/UT_MemorySnapshot.cs
+55 −0 tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs
+25 −7 tests/Neo.UnitTests/SmartContract/Native/UT_NativeContract.cs
+109 −0 tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs
+20 −0 tests/Neo.UnitTests/SmartContract/Native/UT_StdLib.cs
+13 −2 tests/Neo.UnitTests/SmartContract/UT_ApplicationEngine.Contract.cs
+8 −3 tests/Neo.UnitTests/SmartContract/UT_ApplicationEngineProvider.cs
+15 −2 tests/Neo.UnitTests/SmartContract/UT_Contract.cs
+8 −3 tests/Neo.UnitTests/SmartContract/UT_Helper.cs
+29 −19 tests/Neo.UnitTests/SmartContract/UT_InteropPrices.cs
+4 −4 tests/Neo.UnitTests/SmartContract/UT_InteropService.NEO.cs
+24 −18 tests/Neo.UnitTests/SmartContract/UT_InteropService.cs
+21 −6 tests/Neo.UnitTests/SmartContract/UT_JsonSerializer.cs
+11 −2 tests/Neo.UnitTests/SmartContract/UT_NotifyEventArgs.cs
+1 −3 tests/Neo.UnitTests/SmartContract/UT_SmartContractHelper.cs
+31 −22 tests/Neo.UnitTests/SmartContract/UT_Syscalls.cs
+1 −1 tests/Neo.UnitTests/TestBlockchain.cs
+3 −3 tests/Neo.UnitTests/UT_DataCache.cs
+5 −5 tests/Neo.UnitTests/UT_ProtocolSettings.cs
+4 −1 tests/Neo.UnitTests/UT_UInt160.cs
+17 −5 tests/Neo.UnitTests/VM/UT_Helper.cs
+44 −0 tests/Neo.VM.Tests/Tests/OpCodes/Splice/SUBSTR.json
7 changes: 3 additions & 4 deletions src/Neo.Compiler.CSharp/MethodConvert/System/SystemCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
using System.Reflection;
using System.Runtime.InteropServices;
using Array = System.Array;
using Akka.Util.Internal;

namespace Neo.Compiler;

internal partial class MethodConvert
{
private delegate void SystemCallHandler(MethodConvert methodConvert, SemanticModel model, IMethodSymbol symbol, ExpressionSyntax? instanceExpression, IReadOnlyList<SyntaxNode>? arguments);

private static readonly Dictionary<string, SystemCallHandler> SystemCallHandlers = new();
private static readonly Dictionary<string, SystemCallHandler> SystemCallHandlers = [];

static MethodConvert()
{
Expand All @@ -44,13 +43,13 @@ private static void RegisterHandler<TResult>(Expression<Func<TResult>> expressio

private static void RegisterHandler<T, TResult>(Expression<Func<T, TResult>> expression, SystemCallHandler handler, string? key = null)
{
key = key ?? GetKeyFromExpression(expression, typeof(T));
key ??= GetKeyFromExpression(expression, typeof(T));
SystemCallHandlers[key] = handler;
}

private static void RegisterHandler<T1, T2, TResult>(Expression<Func<T1, T2, TResult>> expression, SystemCallHandler handler, string? key = null)
{
key = key ?? GetKeyFromExpression(expression, typeof(T1), typeof(T2));
key ??= GetKeyFromExpression(expression, typeof(T1), typeof(T2));
SystemCallHandlers[key] = handler;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<ItemGroup>
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="MSTest.TestFramework" Version="3.7.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.7.2" />
<PackageReference Include="ReportGenerator.Core" Version="5.4.3" />
</ItemGroup>

Expand Down
8 changes: 2 additions & 6 deletions src/Neo.SmartContract.Testing/TestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,8 @@ public T Deploy<T>(NefFile nef, ContractManifest manifest, object? data = null,
// Deploy

//UInt160 expectedHash = GetDeployHash(nef, manifest);
var state = Native.ContractManagement.Deploy(nef.ToArray(), Encoding.UTF8.GetBytes(manifest.ToJson().ToString(false)), data);

if (state is null)
{
throw new Exception("Can't get the ContractState");
}
var state = Native.ContractManagement.Deploy(nef.ToArray(), Encoding.UTF8.GetBytes(manifest.ToJson().ToString(false)), data)
?? throw new Exception("Can't get the ContractState");

// Mock contract

Expand Down
4 changes: 2 additions & 2 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.7.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.7.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.7.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.7.2" />
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
2 changes: 2 additions & 0 deletions tests/Neo.Compiler.CSharp.TestContracts/Contract_Continue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public static void ContinueInTryCatch(bool exception)
{
j += 1;
continue;
#pragma warning disable CS0162 // Unreachable code detected
j = 10;
#pragma warning restore CS0162 // Unreachable code detected
}
ExecutionEngine.Assert(j == 3);
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,16 @@
// modifications are permitted.

using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Attributes;
using Neo.SmartContract.Framework.Native;
using Neo.SmartContract.Framework.Services;

namespace Neo.Compiler.CSharp.TestContracts
{
#pragma warning disable CS8625
public class Contract_CheckWitness : SmartContract.Framework.SmartContract
{
public static void Main(UInt160 u)
{
Runtime.CheckWitness(u);
ExecutionEngine.Assert(Runtime.CheckWitness(u));
}
#pragma warning restore CS8625
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

<ItemGroup>
<ProjectReference Include="..\..\src\Neo.SmartContract.Framework\Neo.SmartContract.Framework.csproj" />
<ProjectReference Include="..\..\src\Neo.SmartContract.Analyzer\Neo.SmartContract.Analyzer.csproj"
OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
<ProjectReference Include="..\..\src\Neo.SmartContract.Analyzer\Neo.SmartContract.Analyzer.csproj"
OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void Test_VerifySignatureWithMessage()

// Check

Assert.IsFalse(Contract.Secp256r1VerifySignatureWithMessage(System.Array.Empty<byte>(), key.PublicKey, signature));
Assert.IsFalse(Contract.Secp256r1VerifySignatureWithMessage([], key.PublicKey, signature));
Assert.IsTrue(Contract.Secp256r1VerifySignatureWithMessage(data, key.PublicKey, signature));

// secp256r1 with Keccak hash
Expand All @@ -74,7 +74,7 @@ public void Test_VerifySignatureWithMessage()

// Check

Assert.IsFalse(Contract.Secp256r1VerifyKeccakSignatureWithMessage(System.Array.Empty<byte>(), key.PublicKey, signatureKeccak));
Assert.IsFalse(Contract.Secp256r1VerifyKeccakSignatureWithMessage([], key.PublicKey, signatureKeccak));
Assert.IsTrue(Contract.Secp256r1VerifyKeccakSignatureWithMessage(data, key.PublicKey, signatureKeccak));

// secp256k1 with SHA256 hash
Expand All @@ -85,16 +85,16 @@ public void Test_VerifySignatureWithMessage()

// Check

Assert.IsFalse(Contract.Secp256k1VerifySignatureWithMessage(System.Array.Empty<byte>(), pubkey, signature));
Assert.IsFalse(Contract.Secp256k1VerifySignatureWithMessage([], pubkey, signature));
Assert.IsTrue(Contract.Secp256k1VerifySignatureWithMessage(data, pubkey, signature));

// secp256k1 with Keccak hash

signature = Crypto.Sign(data, key.PrivateKey, ecCurve: Cryptography.ECC.ECCurve.Secp256k1, hasher: Hasher.Keccak256);
signature = Crypto.Sign(data, key.PrivateKey, Cryptography.ECC.ECCurve.Secp256k1, Cryptography.HashAlgorithm.Keccak256);

// Check

Assert.IsFalse(Contract.Secp256k1VerifyKeccakSignatureWithMessage(System.Array.Empty<byte>(), pubkey, signature));
Assert.IsFalse(Contract.Secp256k1VerifyKeccakSignatureWithMessage([], pubkey, signature));
Assert.IsTrue(Contract.Secp256k1VerifyKeccakSignatureWithMessage(data, pubkey, signature));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,36 @@ public void TestDump()
Assert.AreEqual(100_000_000, engine.Native.NEO.TotalSupply);

Assert.AreEqual(WhiteSpaceRegex.Replace(@"
NeoToken [0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5] [5.00 % - 100.00 %]
┌-───────────────────────────────-┬-────────-┬-────────-┐
│ Method │ Line │ Branch │
├-───────────────────────────────-┼-────────-┼-────────-┤
│ totalSupply() │ 100.00 % │ 100.00 % │
│ balanceOf(account) │ 0.00 % │ 100.00 % │
│ decimals() │ 0.00 % │ 100.00 % │
│ getAccountState(account) │ 0.00 % │ 100.00 % │
│ getAllCandidates() │ 0.00 % │ 100.00 % │
│ getCandidates() │ 0.00 % │ 100.00 % │
│ getCandidateVote(pubKey) │ 0.00 % │ 100.00 % │
│ getCommittee() │ 0.00 % │ 100.00 % │
│ getCommitteeAddress() │ 0.00 % │ 100.00 % │
│ getGasPerBlock() │ 0.00 % │ 100.00 % │
│ getNextBlockValidators() │ 0.00 % │ 100.00 % │
│ getRegisterPrice() │ 0.00 % │ 100.00 % │
│ registerCandidate(pubkey) │ 0.00 % │ 100.00 % │
│ setGasPerBlock(gasPerBlock) │ 0.00 % │ 100.00 % │
│ setRegisterPrice(registerPrice) │ 0.00 % │ 100.00 % │
│ symbol() │ 0.00 % │ 100.00 % │
│ transfer(from,to,amount,data) │ 0.00 % │ 100.00 % │
│ unclaimedGas(account,end) │ 0.00 % │ 100.00 % │
│ unregisterCandidate(pubkey) │ 0.00 % │ 100.00 % │
│ vote(account,voteTo) │ 0.00 % │ 100.00 % │
└-───────────────────────────────-┴-────────-┴-────────-┘
NeoToken [0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5] [4.76 % - 100.00 %]
┌-────────────────────────────────-┬-────────-┬-────────-┐
│ Method │ Line │ Branch │
├-────────────────────────────────-┼-────────-┼-────────-┤
│ totalSupply() │ 100.00 % │ 100.00 % │
│ balanceOf(account) │ 0.00 % │ 100.00 % │
│ decimals() │ 0.00 % │ 100.00 % │
│ getAccountState(account) │ 0.00 % │ 100.00 % │
│ getAllCandidates() │ 0.00 % │ 100.00 % │
│ getCandidates() │ 0.00 % │ 100.00 % │
│ getCandidateVote(pubKey) │ 0.00 % │ 100.00 % │
│ getCommittee() │ 0.00 % │ 100.00 % │
│ getCommitteeAddress() │ 0.00 % │ 100.00 % │
│ getGasPerBlock() │ 0.00 % │ 100.00 % │
│ getNextBlockValidators() │ 0.00 % │ 100.00 % │
│ getRegisterPrice() │ 0.00 % │ 100.00 % │
│ onNEP17Payment(from,amount,data) │ 0.00 % │ 100.00 % │
│ registerCandidate(pubkey) │ 0.00 % │ 100.00 % │
│ setGasPerBlock(gasPerBlock) │ 0.00 % │ 100.00 % │
│ setRegisterPrice(registerPrice) │ 0.00 % │ 100.00 % │
│ symbol() │ 0.00 % │ 100.00 % │
│ transfer(from,to,amount,data) │ 0.00 % │ 100.00 % │
│ unclaimedGas(account,end) │ 0.00 % │ 100.00 % │
│ unregisterCandidate(pubkey) │ 0.00 % │ 100.00 % │
│ vote(account,voteTo) │ 0.00 % │ 100.00 % │
└-────────────────────────────────-┴-────────-┴-────────-┘
", ""), WhiteSpaceRegex.Replace(engine.GetCoverage(engine.Native.NEO)?.Dump()!, ""));

Assert.AreEqual(WhiteSpaceRegex.Replace(@"
NeoToken [0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5] [5.00 % - 100.00 %]
NeoToken [0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5] [4.76 % - 100.00 %]
┌-─────────────-┬-────────-┬-────────-┐
│ Method │ Line │ Branch │
├-─────────────-┼-────────-┼-────────-┤
Expand Down Expand Up @@ -89,15 +90,15 @@ public void TestCoverageByEngine()
Assert.AreEqual(100_000_000, engine.Native.NEO.TotalSupply);

Assert.AreEqual(engine.Native.NEO.Hash, engine.GetCoverage(engine.Native.NEO)?.Hash);
Assert.AreEqual(60, engine.GetCoverage(engine.Native.NEO)?.TotalLines);
Assert.AreEqual(63, engine.GetCoverage(engine.Native.NEO)?.TotalLines);
Assert.AreEqual(3, engine.GetCoverage(engine.Native.NEO)?.CoveredLines);
Assert.AreEqual(3, engine.GetCoverage(engine.Native.NEO)?.CoveredLinesAll);

// Check balanceOf

Assert.AreEqual(0, engine.Native.NEO.BalanceOf(engine.Native.NEO.Hash));

Assert.AreEqual(60, engine.GetCoverage(engine.Native.NEO)?.TotalLines);
Assert.AreEqual(63, engine.GetCoverage(engine.Native.NEO)?.TotalLines);
Assert.AreEqual(6, engine.GetCoverage(engine.Native.NEO)?.CoveredLines);
Assert.AreEqual(6, engine.GetCoverage(engine.Native.NEO)?.CoveredLinesAll);

Expand Down Expand Up @@ -160,15 +161,15 @@ public void TestCoverageByExtension()
Assert.AreEqual(100_000_000, engine.Native.NEO.TotalSupply);

Assert.AreEqual(engine.Native.NEO.Hash, engine.Native.NEO.GetCoverage()?.Hash);
Assert.AreEqual(60, engine.Native.NEO.GetCoverage()?.TotalLines);
Assert.AreEqual(63, engine.Native.NEO.GetCoverage()?.TotalLines);
Assert.AreEqual(3, engine.Native.NEO.GetCoverage()?.CoveredLines);
Assert.AreEqual(3, engine.Native.NEO.GetCoverage()?.CoveredLinesAll);

// Check balanceOf

Assert.AreEqual(0, engine.Native.NEO.BalanceOf(engine.Native.NEO.Hash));

Assert.AreEqual(60, engine.Native.NEO.GetCoverage()?.TotalLines);
Assert.AreEqual(63, engine.Native.NEO.GetCoverage()?.TotalLines);
Assert.AreEqual(6, engine.Native.NEO.GetCoverage()?.CoveredLines);
Assert.AreEqual(6, engine.Native.NEO.GetCoverage()?.CoveredLinesAll);

Expand Down

0 comments on commit 83e6095

Please sign in to comment.