Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion plugins/RpcServer/RpcServer.Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ private static JObject GetRelayResult(VerifyResult reason, UInt256 hash)
/// "result": {
/// "tcpport": 10333, // The TCP port,
/// "nonce": 1, // The nonce,
/// "useragent": "The user agent",
/// "useragent": "The Neo library user agent",
/// "version": "The neo-node / RpcServer assembly version",
/// "rpc": {
/// "maxiteratorresultitems": 100, // The maximum number of items in the iterator result,
/// "sessionenabled": false // Whether session is enabled,
Expand Down Expand Up @@ -153,6 +154,8 @@ protected internal virtual JToken GetVersion()
json["tcpport"] = localNode.ListenerTcpPort;
json["nonce"] = LocalNode.Nonce;
json["useragent"] = LocalNode.UserAgent;
// UserAgent comes from Neo.dll; version is this node/plugin assembly (neo-node#983).
json["version"] = typeof(RpcServer).Assembly.GetName().Version?.ToString(3);
// rpc settings
JObject rpc = new();
rpc["maxiteratorresultitems"] = settings.MaxIteratorResultItems;
Expand Down
22 changes: 22 additions & 0 deletions tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ public void TestGetVersion()
Assert.IsTrue(json.ContainsProperty("tcpport"));
Assert.IsTrue(json.ContainsProperty("nonce"));
Assert.IsTrue(json.ContainsProperty("useragent"));
Assert.IsTrue(json.ContainsProperty("version"));
Assert.AreEqual(_rpcServer.GetType().Assembly.GetName().Version?.ToString(3), json["version"]!.AsString());
Assert.IsFalse(string.IsNullOrEmpty(json["version"]!.AsString()));
Assert.HasCount(3, json["version"]!.AsString().Split('.'));

Assert.IsTrue(json.ContainsProperty("rpc"));
var rpc = (JObject)json["rpc"]!;
Assert.IsTrue(rpc.ContainsProperty("maxiteratorresultitems"));
Assert.IsTrue(rpc.ContainsProperty("sessionenabled"));
Assert.AreEqual(_rpcServerSettings.MaxIteratorResultItems, rpc["maxiteratorresultitems"]!.AsNumber());
Assert.AreEqual(_rpcServerSettings.SessionEnabled, rpc["sessionenabled"]!.AsBoolean());

Assert.IsTrue(json.ContainsProperty("protocol"));
var protocol = (JObject)json["protocol"];
Expand All @@ -132,6 +143,17 @@ public void TestGetVersion()
Assert.IsTrue(protocol.ContainsProperty("seedlist"));
}

[TestMethod]
public void TestGetVersion_VersionIsNodeAssemblyNotUserAgent()
{
var json = (JObject)_rpcServer.GetVersion();
var version = json["version"]!.AsString();
var useragent = json["useragent"]!.AsString();
Assert.AreEqual(_rpcServer.GetType().Assembly.GetName().Version?.ToString(3), version);
Assert.IsFalse(string.IsNullOrEmpty(useragent));
Assert.AreNotEqual(version, useragent);
}

[TestMethod]
public void TestGetVersion_HardforksStructure()
{
Expand Down
Loading