diff --git a/src/Neo/Network/P2P/Peer.cs b/src/Neo/Network/P2P/Peer.cs
index 767d747b1d..2cad442b95 100644
--- a/src/Neo/Network/P2P/Peer.cs
+++ b/src/Neo/Network/P2P/Peer.cs
@@ -145,7 +145,7 @@ static Peer()
/// Tries to add a set of peers to the immutable ImmutableHashSet of UnconnectedPeers.
///
/// Peers that the method will try to add (union) to (with) UnconnectedPeers.
- protected void AddPeers(IEnumerable peers)
+ protected internal void AddPeers(IEnumerable peers)
{
if (UnconnectedPeers.Count < UnconnectedMax)
{
diff --git a/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs b/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs
index ef96322d64..6a71bd774f 100644
--- a/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs
+++ b/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs
@@ -13,6 +13,7 @@
using Akka.Util.Internal;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Neo.Cryptography.ECC;
using Neo.IO;
using Neo.Json;
using Neo.Ledger;
@@ -23,6 +24,8 @@
using Neo.UnitTests.Extensions;
using System;
using System.Linq;
+using System.Security.Policy;
+using static Neo.SmartContract.Native.NeoToken;
namespace Neo.Plugins.RpcServer.Tests
{
@@ -188,12 +191,17 @@ public void TestGetRawTransaction()
var snapshot = _neoSystem.GetSnapshotCache();
var tx = TestUtils.CreateValidTx(snapshot, _wallet, _walletAccount);
_neoSystem.MemPool.TryAdd(tx, snapshot);
- var parameters = new JArray(tx.Hash.ToString(), true);
snapshot.Commit();
+ var parameters = new JArray(tx.Hash.ToString(), true);
var result = _rpcServer.GetRawTransaction(parameters);
var json = Utility.TransactionToJson(tx, _neoSystem.Settings);
Assert.AreEqual(json.ToString(), result.ToString());
+
+ parameters = new JArray(tx.Hash.ToString(), false);
+ result = _rpcServer.GetRawTransaction(parameters);
+ var tx2 = Convert.FromBase64String(result.AsString()).AsSerializable();
+ tx2.ToJson(_neoSystem.Settings).ToString().Should().Be(tx.ToJson(_neoSystem.Settings).ToString());
}
[TestMethod]
@@ -279,11 +287,14 @@ public void TestGetNextBlockValidators()
public void TestGetCandidates()
{
var snapshot = _neoSystem.GetSnapshotCache();
- var result = _rpcServer.GetCandidates(new JArray());
var json = new JArray();
var validators = NativeContract.NEO.GetNextBlockValidators(snapshot, _neoSystem.Settings.ValidatorsCount);
+
+ var key = new KeyBuilder(NativeContract.NEO.Id, 33).Add(ECPoint.Parse("02237309a0633ff930d51856db01d17c829a5b2e5cc2638e9c03b4cfa8e9c9f971", ECCurve.Secp256r1));
+ snapshot.Add(key, new StorageItem(new CandidateState() { Registered = true, Votes = 10000 }));
snapshot.Commit();
var candidates = NativeContract.NEO.GetCandidates(_neoSystem.GetSnapshotCache());
+ var result = _rpcServer.GetCandidates(new JArray());
foreach (var candidate in candidates)
{
diff --git a/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Node.cs b/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Node.cs
index f4677135b7..cf674a449c 100644
--- a/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Node.cs
+++ b/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Node.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Akka.Actor;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.IO;
@@ -18,6 +19,8 @@
using Neo.SmartContract.Native;
using Neo.UnitTests;
using System;
+using System.Collections.Generic;
+using System.Net;
namespace Neo.Plugins.RpcServer.Tests
{
@@ -33,10 +36,19 @@ public void TestGetConnectionCount()
[TestMethod]
public void TestGetPeers()
{
- var result = _rpcServer.GetPeers(new JArray());
+ var settings = TestProtocolSettings.SoleNode;
+ var neoSystem = new NeoSystem(settings, _memoryStoreProvider);
+ var localNode = neoSystem.LocalNode.Ask(new LocalNode.GetInstance()).Result;
+ localNode.AddPeers(new List() { new IPEndPoint(new IPAddress(new byte[] { 127, 0, 0, 1 }), 11332) });
+ localNode.AddPeers(new List() { new IPEndPoint(new IPAddress(new byte[] { 127, 0, 0, 1 }), 12332) });
+ localNode.AddPeers(new List() { new IPEndPoint(new IPAddress(new byte[] { 127, 0, 0, 1 }), 13332) });
+ var rpcServer = new RpcServer(neoSystem, RpcServerSettings.Default);
+
+ var result = rpcServer.GetPeers(new JArray());
Assert.IsInstanceOfType(result, typeof(JObject));
var json = (JObject)result;
json.ContainsProperty("unconnected").Should().BeTrue();
+ (json["unconnected"] as JArray).Count.Should().Be(3);
json.ContainsProperty("bad").Should().BeTrue();
json.ContainsProperty("connected").Should().BeTrue();
}