Skip to content

Commit

Permalink
Merge branch 'master' into snapshot-name
Browse files Browse the repository at this point in the history
* master:
  Fixed Publish Step (neo-project#3411)
  Fix release compilation (neo-project#3417)
  [Neo Plugin UT] Rpcserver unit test on node (neo-project#3353)
  Improve code coverage (neo-project#3354)
  `[Add]` Debug Output to `Expect` (neo-project#3407)
  [Neo Plugin Store] Unit test (neo-project#3399)
  Bump System.Text.Json from 8.0.3 to 8.0.4 in /src/Neo.Json (neo-project#3416)

# Conflicts:
#	tests/Neo.Plugins.RpcServer.Tests/TestBlockchain.cs
#	tests/Neo.UnitTests/Network/P2P/Payloads/UT_Header.cs
  • Loading branch information
Jim8y committed Jul 12, 2024
2 parents 8822ad9 + 53eaa39 commit 9b79193
Show file tree
Hide file tree
Showing 37 changed files with 1,012 additions and 163 deletions.
18 changes: 6 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Check Format (*.cs)
run: dotnet format --verify-no-changes --verbosity diagnostic

Build-Test-Neo-Cli:
Test-Everything:
needs: [Format]
timeout-minutes: 15
runs-on: ubuntu-latest
Expand All @@ -37,16 +37,16 @@ jobs:
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Build (Neo.CLI)
run: dotnet build ./src/Neo.CLI --output ./out/Neo.CLI
- name: Build (Everything)
run: dotnet build

- name: Install dependencies
run: |
sudo apt-get install libleveldb-dev expect
find ./out -name 'config.json' | xargs perl -pi -e 's|LevelDBStore|MemoryStore|g'
find ./bin -name 'config.json' | xargs perl -pi -e 's|LevelDBStore|MemoryStore|g'
- name: Run tests with expect
run: expect ./scripts/Neo.CLI/test-neo-cli.expect
run: expect ./scripts/Neo.CLI/test-neo-cli.exp

Test:
needs: [Format]
Expand Down Expand Up @@ -124,19 +124,13 @@ jobs:
- name: Set Version
run: git rev-list --count HEAD | xargs printf 'CI%05d' | xargs -I{} echo 'VERSION_SUFFIX={}' >> $GITHUB_ENV

- name : Pack (Neo)
- name : Pack (Everything)
run: |
dotnet pack \
--configuration Release \
--output ./out \
--version-suffix ${{ env.VERSION_SUFFIX }}
- name: Remove Unwanted Files
working-directory: ./out
run: |
rm -v Neo.CLI*
rm -v Neo.GUI*
- name: Publish to Github Packages
working-directory: ./out
run: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/expect -f
#!/usr/bin/expect -d -f
#
# This script uses expect to test neo-cli
#
set timeout 10

exp_internal true

# Start neo-cli
spawn dotnet out/Neo.CLI/neo-cli.dll
spawn dotnet ./bin/Neo.CLI/net8.0/neo-cli.dll

# Expect the main input prompt
expect {
Expand All @@ -18,7 +18,7 @@ expect {
#
# Test 'create wallet'
#
send "create wallet test-wallet1.json\n"
send "create wallet ./bin/Neo.CLI/test-wallet1.json\n"

expect {
"password:" { send "asd\n" }
Expand All @@ -42,7 +42,7 @@ expect {
#
# Test 'create wallet'
#
send "create wallet test-wallet2.json L2ArHTuiDL4FHu4nfyhamrG8XVYB4QyRbmhj7vD6hFMB5iAMSTf6\n"
send "create wallet ./bin/Neo.CLI/test-wallet2.json L2ArHTuiDL4FHu4nfyhamrG8XVYB4QyRbmhj7vD6hFMB5iAMSTf6\n"

expect {
"password:" { send "abcd\n" }
Expand Down
2 changes: 1 addition & 1 deletion src/Neo.Json/Neo.Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" Version="8.0.3" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions src/Neo/Ledger/MemoryPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -659,5 +659,24 @@ internal bool ReVerifyTopUnverifiedTransactionsIfNeeded(int maxToVerify, DataCac

return _unverifiedTransactions.Count > 0;
}

// This method is only for test purpose
// Do not use this method outside of unit tests
internal void Clear()
{
_txRwLock.EnterReadLock();
try
{
_unsortedTransactions.Clear();
_conflicts.Clear();
_sortedTransactions.Clear();
_unverifiedTransactions.Clear();
_unverifiedSortedTransactions.Clear();
}
finally
{
_txRwLock.ExitReadLock();
}
}
}
}
4 changes: 2 additions & 2 deletions src/Neo/SmartContract/Manifest/ContractAbi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public static ContractAbi FromJson(JObject json)
{
ContractAbi abi = new()
{
Methods = ((JArray)json["methods"]).Select(u => ContractMethodDescriptor.FromJson((JObject)u)).ToArray(),
Events = ((JArray)json["events"]).Select(u => ContractEventDescriptor.FromJson((JObject)u)).ToArray()
Methods = ((JArray)json!["methods"])?.Select(u => ContractMethodDescriptor.FromJson((JObject)u)).ToArray() ?? [],
Events = ((JArray)json!["events"])?.Select(u => ContractEventDescriptor.FromJson((JObject)u)).ToArray() ?? []
};
if (abi.Methods.Length == 0) throw new FormatException();
return abi;
Expand Down
11 changes: 6 additions & 5 deletions src/Neo/SmartContract/Manifest/ContractManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,21 @@ public static ContractManifest FromJson(JObject json)
{
ContractManifest manifest = new()
{
Name = json["name"].GetString(),
Groups = ((JArray)json["groups"]).Select(u => ContractGroup.FromJson((JObject)u)).ToArray(),
SupportedStandards = ((JArray)json["supportedstandards"]).Select(u => u.GetString()).ToArray(),
Name = json["name"]!.GetString(),
Groups = ((JArray)json["groups"])?.Select(u => ContractGroup.FromJson((JObject)u)).ToArray() ?? [],
SupportedStandards = ((JArray)json["supportedstandards"])?.Select(u => u.GetString()).ToArray() ?? [],
Abi = ContractAbi.FromJson((JObject)json["abi"]),
Permissions = ((JArray)json["permissions"]).Select(u => ContractPermission.FromJson((JObject)u)).ToArray(),
Permissions = ((JArray)json["permissions"])?.Select(u => ContractPermission.FromJson((JObject)u)).ToArray() ?? [],
Trusts = WildcardContainer<ContractPermissionDescriptor>.FromJson(json["trusts"], u => ContractPermissionDescriptor.FromJson((JString)u)),
Extra = (JObject)json["extra"]
};

if (string.IsNullOrEmpty(manifest.Name))
throw new FormatException();
_ = manifest.Groups.ToDictionary(p => p.PubKey);
if (json["features"] is not JObject features || features.Count != 0)
throw new FormatException();
if (manifest.SupportedStandards.Any(p => string.IsNullOrEmpty(p)))
if (manifest.SupportedStandards.Any(string.IsNullOrEmpty))
throw new FormatException();
_ = manifest.SupportedStandards.ToDictionary(p => p);
_ = manifest.Permissions.ToDictionary(p => p.Contract);
Expand Down
6 changes: 3 additions & 3 deletions src/Plugins/RpcServer/RpcServer.Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private static JObject GetRelayResult(VerifyResult reason, UInt256 hash)
}

[RpcMethod]
protected virtual JToken GetVersion(JArray _params)
protected internal virtual JToken GetVersion(JArray _params)
{
JObject json = new();
json["tcpport"] = localNode.ListenerTcpPort;
Expand Down Expand Up @@ -150,15 +150,15 @@ private static string StripPrefix(string s, string prefix)
}

[RpcMethod]
protected virtual JToken SendRawTransaction(JArray _params)
protected internal virtual JToken SendRawTransaction(JArray _params)
{
Transaction tx = Result.Ok_Or(() => Convert.FromBase64String(_params[0].AsString()).AsSerializable<Transaction>(), RpcError.InvalidParams.WithData($"Invalid Transaction Format: {_params[0]}"));
RelayResult reason = system.Blockchain.Ask<RelayResult>(tx).Result;
return GetRelayResult(reason.Result, tx.Hash);
}

[RpcMethod]
protected virtual JToken SubmitBlock(JArray _params)
protected internal virtual JToken SubmitBlock(JArray _params)
{
Block block = Result.Ok_Or(() => Convert.FromBase64String(_params[0].AsString()).AsSerializable<Block>(), RpcError.InvalidParams.WithData($"Invalid Block Format: {_params[0]}"));
RelayResult reason = system.Blockchain.Ask<RelayResult>(block).Result;
Expand Down
13 changes: 13 additions & 0 deletions tests/Neo.Json.UnitTests/UT_JArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,5 +254,18 @@ public void TestAsString()
var s = jArray.AsString();
Assert.AreEqual(s, "{\"name\":\"alice\",\"age\":30,\"score\":100.001,\"gender\":\"female\",\"isMarried\":true,\"pet\":{\"name\":\"Tom\",\"type\":\"cat\"}},{\"name\":\"bob\",\"age\":100000,\"score\":0.001,\"gender\":\"male\",\"isMarried\":false,\"pet\":{\"name\":\"Paul\",\"type\":\"dog\"}}");
}

[TestMethod]
public void TestClone()
{
var jArray = new JArray
{
alice,
bob,
};
var a = jArray.AsString();
var b = jArray.Clone().AsString();
a.Should().Be(b);
}
}
}
2 changes: 2 additions & 0 deletions tests/Neo.Json.UnitTests/UT_JBoolean.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public void TestEqual()
{
Assert.IsTrue(jTrue.Equals(new JBoolean(true)));
Assert.IsTrue(jTrue == new JBoolean(true));
Assert.IsTrue(jTrue != new JBoolean(false));
Assert.IsTrue(jFalse.Equals(new JBoolean()));
Assert.IsTrue(jFalse == new JBoolean());
Assert.IsTrue(jFalse.GetBoolean().ToString().ToLowerInvariant() == jFalse.ToString());
}
}
}
23 changes: 23 additions & 0 deletions tests/Neo.Json.UnitTests/UT_JNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using System.Numerics;

namespace Neo.Json.UnitTests
{
enum Woo
Expand Down Expand Up @@ -72,6 +74,27 @@ public void TestEqual()
Assert.IsTrue(minInt.Equals(JNumber.MIN_SAFE_INTEGER));
Assert.IsTrue(minInt == JNumber.MIN_SAFE_INTEGER);
Assert.IsTrue(zero == new JNumber());
Assert.IsFalse(zero != new JNumber());
Assert.IsTrue(zero.AsNumber() == zero.GetNumber());
Assert.IsFalse(zero == null);

var jnum = new JNumber(1);
jnum.Equals(new JNumber(1)).Should().BeTrue();
jnum.Equals((uint)1).Should().BeTrue();
jnum.Equals((int)1).Should().BeTrue();
jnum.Equals((ulong)1).Should().BeTrue();
jnum.Equals((long)1).Should().BeTrue();
jnum.Equals((byte)1).Should().BeTrue();
jnum.Equals((sbyte)1).Should().BeTrue();
jnum.Equals((short)1).Should().BeTrue();
jnum.Equals((ushort)1).Should().BeTrue();
jnum.Equals((decimal)1).Should().BeTrue();
jnum.Equals((float)1).Should().BeTrue();
jnum.Equals((double)1).Should().BeTrue();
jnum.Equals(null).Should().BeFalse();
var x = jnum;
jnum.Equals(x).Should().BeTrue();
Assert.ThrowsException<ArgumentOutOfRangeException>(() => jnum.Equals(new BigInteger(1)));
}
}
}
16 changes: 14 additions & 2 deletions tests/Neo.Json.UnitTests/UT_JString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,22 @@ public void TestGetEnum()
public void TestEqual()
{
var str = "hello world";
var str2 = "hello world2";
var jString = new JString(str);
Assert.IsTrue(jString.Equals(str));
var jString2 = new JString(str2);

Assert.IsTrue(jString == str);
Assert.IsTrue(jString != "hello world2");
Assert.IsFalse(jString == null);
Assert.IsTrue(jString != str2);
Assert.IsFalse(jString == str2);

Assert.AreEqual(str, jString.GetString());
Assert.IsTrue(jString.Equals(str));
Assert.IsFalse(jString.Equals(jString2));
Assert.IsFalse(jString.Equals(null));
Assert.IsFalse(jString.Equals(123));
var reference = jString;
Assert.IsTrue(jString.Equals(reference));
}
}
}
1 change: 1 addition & 0 deletions tests/Neo.Plugins.RpcServer.Tests/TestBlockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Akka.Actor;
using Neo.Ledger;
using Neo.Persistence;
using Neo.UnitTests;
using System;

namespace Neo.Plugins.RpcServer.Tests
Expand Down
65 changes: 0 additions & 65 deletions tests/Neo.Plugins.RpcServer.Tests/TestProtocolSettings.cs

This file was deleted.

6 changes: 4 additions & 2 deletions tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using Akka.Actor;
using Akka.Util.Internal;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.IO;
Expand Down Expand Up @@ -101,8 +102,9 @@ public void TestGetBlockHash()
{
var snapshot = _neoSystem.GetSnapshotCache();
var block = TestUtils.CreateBlockWithValidTransactions(snapshot, _wallet, _walletAccount, 3);
TestUtils.BlocksAdd(snapshot, block.Hash, block);
snapshot.Commit();
// TestUtils.BlocksAdd(snapshot, block.Hash, block);
// snapshot.Commit();
var reason = _neoSystem.Blockchain.Ask<Blockchain.RelayResult>(block).Result;
var expectedHash = block.Hash.ToString();
var result = _rpcServer.GetBlockHash(new JArray(block.Index));
Assert.AreEqual(expectedHash, result.AsString());
Expand Down
Loading

0 comments on commit 9b79193

Please sign in to comment.