Skip to content

Commit 3351533

Browse files
Jim8yshargonNGDAdmin
authored
[Neo Plugin UT] Rpcserver unit test on node (#3353)
* try mock * not use mock * test * fix test * use neo testutils * complete rpcserver blockchain tests. * revert change to ByteArrayComparer * revert cache change * add more detail to comments * add more exception test cases * fix warning * Apply suggestions from code review * update TODO mark * add node rpc tests * fix build error * set the mempool to 5. * remove memory pool test. * fix tests * fix test issue * Update tests/Neo.UnitTests/TestUtils.Transaction.cs --------- Co-authored-by: Shargon <shargon@gmail.com> Co-authored-by: NGD Admin <154295625+NGDAdmin@users.noreply.github.com>
1 parent bfb3440 commit 3351533

15 files changed

+612
-169
lines changed

src/Neo/Ledger/MemoryPool.cs

+21
Original file line numberDiff line numberDiff line change
@@ -659,5 +659,26 @@ internal bool ReVerifyTopUnverifiedTransactionsIfNeeded(int maxToVerify, DataCac
659659

660660
return _unverifiedTransactions.Count > 0;
661661
}
662+
663+
#if DEBUG
664+
// This method is only for test purpose
665+
// Do not remove it from the DEBUG build
666+
internal void Clear()
667+
{
668+
_txRwLock.EnterReadLock();
669+
try
670+
{
671+
_unsortedTransactions.Clear();
672+
_conflicts.Clear();
673+
_sortedTransactions.Clear();
674+
_unverifiedTransactions.Clear();
675+
_unverifiedSortedTransactions.Clear();
676+
}
677+
finally
678+
{
679+
_txRwLock.ExitReadLock();
680+
}
681+
}
682+
#endif
662683
}
663684
}

src/Plugins/RpcServer/RpcServer.Node.cs

+3-3
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.Plugins.RpcServer.Tests/TestBlockchain.cs

-49
This file was deleted.

tests/Neo.Plugins.RpcServer.Tests/TestProtocolSettings.cs

-65
This file was deleted.

tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// Redistribution and use in source and binary forms with or without
1010
// modifications are permitted.
1111

12+
using Akka.Actor;
1213
using Akka.Util.Internal;
1314
using Microsoft.VisualStudio.TestTools.UnitTesting;
1415
using Neo.IO;
@@ -101,8 +102,9 @@ public void TestGetBlockHash()
101102
{
102103
var snapshot = _neoSystem.GetSnapshot();
103104
var block = TestUtils.CreateBlockWithValidTransactions(snapshot, _wallet, _walletAccount, 3);
104-
TestUtils.BlocksAdd(snapshot, block.Hash, block);
105-
snapshot.Commit();
105+
// TestUtils.BlocksAdd(snapshot, block.Hash, block);
106+
// snapshot.Commit();
107+
var reason = _neoSystem.Blockchain.Ask<Blockchain.RelayResult>(block).Result;
106108
var expectedHash = block.Hash.ToString();
107109
var result = _rpcServer.GetBlockHash(new JArray(block.Index));
108110
Assert.AreEqual(expectedHash, result.AsString());

0 commit comments

Comments
 (0)