Skip to content

Commit

Permalink
[Neo Plugin UT] Rpcserver unit test on node (#3353)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: NGD Admin <[email protected]>
  • Loading branch information
3 people authored Jul 11, 2024
1 parent bfb3440 commit 3351533
Show file tree
Hide file tree
Showing 15 changed files with 612 additions and 169 deletions.
21 changes: 21 additions & 0 deletions src/Neo/Ledger/MemoryPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -659,5 +659,26 @@ internal bool ReVerifyTopUnverifiedTransactionsIfNeeded(int maxToVerify, DataCac

return _unverifiedTransactions.Count > 0;
}

#if DEBUG
// This method is only for test purpose
// Do not remove it from the DEBUG build
internal void Clear()
{
_txRwLock.EnterReadLock();
try
{
_unsortedTransactions.Clear();
_conflicts.Clear();
_sortedTransactions.Clear();
_unverifiedTransactions.Clear();
_unverifiedSortedTransactions.Clear();
}
finally
{
_txRwLock.ExitReadLock();
}
}
#endif
}
}
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
49 changes: 0 additions & 49 deletions tests/Neo.Plugins.RpcServer.Tests/TestBlockchain.cs

This file was deleted.

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.GetSnapshot();
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 3351533

Please sign in to comment.