Skip to content

Commit 9b79193

Browse files
committed
Merge branch 'master' into snapshot-name
* master: Fixed Publish Step (#3411) Fix release compilation (#3417) [Neo Plugin UT] Rpcserver unit test on node (#3353) Improve code coverage (#3354) `[Add]` Debug Output to `Expect` (#3407) [Neo Plugin Store] Unit test (#3399) Bump System.Text.Json from 8.0.3 to 8.0.4 in /src/Neo.Json (#3416) # Conflicts: # tests/Neo.Plugins.RpcServer.Tests/TestBlockchain.cs # tests/Neo.UnitTests/Network/P2P/Payloads/UT_Header.cs
2 parents 8822ad9 + 53eaa39 commit 9b79193

37 files changed

+1012
-163
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Check Format (*.cs)
2525
run: dotnet format --verify-no-changes --verbosity diagnostic
2626

27-
Build-Test-Neo-Cli:
27+
Test-Everything:
2828
needs: [Format]
2929
timeout-minutes: 15
3030
runs-on: ubuntu-latest
@@ -37,16 +37,16 @@ jobs:
3737
with:
3838
dotnet-version: ${{ env.DOTNET_VERSION }}
3939

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

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

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

127-
- name : Pack (Neo)
127+
- name : Pack (Everything)
128128
run: |
129129
dotnet pack \
130130
--configuration Release \
131131
--output ./out \
132132
--version-suffix ${{ env.VERSION_SUFFIX }}
133133
134-
- name: Remove Unwanted Files
135-
working-directory: ./out
136-
run: |
137-
rm -v Neo.CLI*
138-
rm -v Neo.GUI*
139-
140134
- name: Publish to Github Packages
141135
working-directory: ./out
142136
run: |

scripts/Neo.CLI/test-neo-cli.expect renamed to scripts/Neo.CLI/test-neo-cli.exp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#!/usr/bin/expect -f
1+
#!/usr/bin/expect -d -f
22
#
33
# This script uses expect to test neo-cli
44
#
55
set timeout 10
6-
6+
exp_internal true
77

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

1111
# Expect the main input prompt
1212
expect {
@@ -18,7 +18,7 @@ expect {
1818
#
1919
# Test 'create wallet'
2020
#
21-
send "create wallet test-wallet1.json\n"
21+
send "create wallet ./bin/Neo.CLI/test-wallet1.json\n"
2222

2323
expect {
2424
"password:" { send "asd\n" }
@@ -42,7 +42,7 @@ expect {
4242
#
4343
# Test 'create wallet'
4444
#
45-
send "create wallet test-wallet2.json L2ArHTuiDL4FHu4nfyhamrG8XVYB4QyRbmhj7vD6hFMB5iAMSTf6\n"
45+
send "create wallet ./bin/Neo.CLI/test-wallet2.json L2ArHTuiDL4FHu4nfyhamrG8XVYB4QyRbmhj7vD6hFMB5iAMSTf6\n"
4646

4747
expect {
4848
"password:" { send "abcd\n" }

src/Neo.Json/Neo.Json.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="System.Text.Json" Version="8.0.3" />
13+
<PackageReference Include="System.Text.Json" Version="8.0.4" />
1414
</ItemGroup>
1515

1616
</Project>

src/Neo/Ledger/MemoryPool.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,5 +659,24 @@ internal bool ReVerifyTopUnverifiedTransactionsIfNeeded(int maxToVerify, DataCac
659659

660660
return _unverifiedTransactions.Count > 0;
661661
}
662+
663+
// This method is only for test purpose
664+
// Do not use this method outside of unit tests
665+
internal void Clear()
666+
{
667+
_txRwLock.EnterReadLock();
668+
try
669+
{
670+
_unsortedTransactions.Clear();
671+
_conflicts.Clear();
672+
_sortedTransactions.Clear();
673+
_unverifiedTransactions.Clear();
674+
_unverifiedSortedTransactions.Clear();
675+
}
676+
finally
677+
{
678+
_txRwLock.ExitReadLock();
679+
}
680+
}
662681
}
663682
}

src/Neo/SmartContract/Manifest/ContractAbi.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public static ContractAbi FromJson(JObject json)
6262
{
6363
ContractAbi abi = new()
6464
{
65-
Methods = ((JArray)json["methods"]).Select(u => ContractMethodDescriptor.FromJson((JObject)u)).ToArray(),
66-
Events = ((JArray)json["events"]).Select(u => ContractEventDescriptor.FromJson((JObject)u)).ToArray()
65+
Methods = ((JArray)json!["methods"])?.Select(u => ContractMethodDescriptor.FromJson((JObject)u)).ToArray() ?? [],
66+
Events = ((JArray)json!["events"])?.Select(u => ContractEventDescriptor.FromJson((JObject)u)).ToArray() ?? []
6767
};
6868
if (abi.Methods.Length == 0) throw new FormatException();
6969
return abi;

src/Neo/SmartContract/Manifest/ContractManifest.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,21 @@ public static ContractManifest FromJson(JObject json)
112112
{
113113
ContractManifest manifest = new()
114114
{
115-
Name = json["name"].GetString(),
116-
Groups = ((JArray)json["groups"]).Select(u => ContractGroup.FromJson((JObject)u)).ToArray(),
117-
SupportedStandards = ((JArray)json["supportedstandards"]).Select(u => u.GetString()).ToArray(),
115+
Name = json["name"]!.GetString(),
116+
Groups = ((JArray)json["groups"])?.Select(u => ContractGroup.FromJson((JObject)u)).ToArray() ?? [],
117+
SupportedStandards = ((JArray)json["supportedstandards"])?.Select(u => u.GetString()).ToArray() ?? [],
118118
Abi = ContractAbi.FromJson((JObject)json["abi"]),
119-
Permissions = ((JArray)json["permissions"]).Select(u => ContractPermission.FromJson((JObject)u)).ToArray(),
119+
Permissions = ((JArray)json["permissions"])?.Select(u => ContractPermission.FromJson((JObject)u)).ToArray() ?? [],
120120
Trusts = WildcardContainer<ContractPermissionDescriptor>.FromJson(json["trusts"], u => ContractPermissionDescriptor.FromJson((JString)u)),
121121
Extra = (JObject)json["extra"]
122122
};
123+
123124
if (string.IsNullOrEmpty(manifest.Name))
124125
throw new FormatException();
125126
_ = manifest.Groups.ToDictionary(p => p.PubKey);
126127
if (json["features"] is not JObject features || features.Count != 0)
127128
throw new FormatException();
128-
if (manifest.SupportedStandards.Any(p => string.IsNullOrEmpty(p)))
129+
if (manifest.SupportedStandards.Any(string.IsNullOrEmpty))
129130
throw new FormatException();
130131
_ = manifest.SupportedStandards.ToDictionary(p => p);
131132
_ = manifest.Permissions.ToDictionary(p => p.Contract);

src/Plugins/RpcServer/RpcServer.Node.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private static JObject GetRelayResult(VerifyResult reason, UInt256 hash)
110110
}
111111

112112
[RpcMethod]
113-
protected virtual JToken GetVersion(JArray _params)
113+
protected internal virtual JToken GetVersion(JArray _params)
114114
{
115115
JObject json = new();
116116
json["tcpport"] = localNode.ListenerTcpPort;
@@ -150,15 +150,15 @@ private static string StripPrefix(string s, string prefix)
150150
}
151151

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

160160
[RpcMethod]
161-
protected virtual JToken SubmitBlock(JArray _params)
161+
protected internal virtual JToken SubmitBlock(JArray _params)
162162
{
163163
Block block = Result.Ok_Or(() => Convert.FromBase64String(_params[0].AsString()).AsSerializable<Block>(), RpcError.InvalidParams.WithData($"Invalid Block Format: {_params[0]}"));
164164
RelayResult reason = system.Blockchain.Ask<RelayResult>(block).Result;

tests/Neo.Json.UnitTests/UT_JArray.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,5 +254,18 @@ public void TestAsString()
254254
var s = jArray.AsString();
255255
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\"}}");
256256
}
257+
258+
[TestMethod]
259+
public void TestClone()
260+
{
261+
var jArray = new JArray
262+
{
263+
alice,
264+
bob,
265+
};
266+
var a = jArray.AsString();
267+
var b = jArray.Clone().AsString();
268+
a.Should().Be(b);
269+
}
257270
}
258271
}

tests/Neo.Json.UnitTests/UT_JBoolean.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ public void TestEqual()
3636
{
3737
Assert.IsTrue(jTrue.Equals(new JBoolean(true)));
3838
Assert.IsTrue(jTrue == new JBoolean(true));
39+
Assert.IsTrue(jTrue != new JBoolean(false));
3940
Assert.IsTrue(jFalse.Equals(new JBoolean()));
4041
Assert.IsTrue(jFalse == new JBoolean());
42+
Assert.IsTrue(jFalse.GetBoolean().ToString().ToLowerInvariant() == jFalse.ToString());
4143
}
4244
}
4345
}

tests/Neo.Json.UnitTests/UT_JNumber.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
// Redistribution and use in source and binary forms with or without
1010
// modifications are permitted.
1111

12+
using System.Numerics;
13+
1214
namespace Neo.Json.UnitTests
1315
{
1416
enum Woo
@@ -72,6 +74,27 @@ public void TestEqual()
7274
Assert.IsTrue(minInt.Equals(JNumber.MIN_SAFE_INTEGER));
7375
Assert.IsTrue(minInt == JNumber.MIN_SAFE_INTEGER);
7476
Assert.IsTrue(zero == new JNumber());
77+
Assert.IsFalse(zero != new JNumber());
78+
Assert.IsTrue(zero.AsNumber() == zero.GetNumber());
79+
Assert.IsFalse(zero == null);
80+
81+
var jnum = new JNumber(1);
82+
jnum.Equals(new JNumber(1)).Should().BeTrue();
83+
jnum.Equals((uint)1).Should().BeTrue();
84+
jnum.Equals((int)1).Should().BeTrue();
85+
jnum.Equals((ulong)1).Should().BeTrue();
86+
jnum.Equals((long)1).Should().BeTrue();
87+
jnum.Equals((byte)1).Should().BeTrue();
88+
jnum.Equals((sbyte)1).Should().BeTrue();
89+
jnum.Equals((short)1).Should().BeTrue();
90+
jnum.Equals((ushort)1).Should().BeTrue();
91+
jnum.Equals((decimal)1).Should().BeTrue();
92+
jnum.Equals((float)1).Should().BeTrue();
93+
jnum.Equals((double)1).Should().BeTrue();
94+
jnum.Equals(null).Should().BeFalse();
95+
var x = jnum;
96+
jnum.Equals(x).Should().BeTrue();
97+
Assert.ThrowsException<ArgumentOutOfRangeException>(() => jnum.Equals(new BigInteger(1)));
7598
}
7699
}
77100
}

0 commit comments

Comments
 (0)