-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
459 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Network.P2P.Payloads; | ||
using Neo.Network.RPC.Models; | ||
using System; | ||
|
||
namespace Neo.UnitTests.Network.RPC.Models | ||
{ | ||
[TestClass] | ||
public class UT_RpcBlock | ||
{ | ||
[TestMethod] | ||
public void TestToJson() | ||
{ | ||
var rpcBlock = new RpcBlock(); | ||
var block = new Block(); | ||
TestUtils.SetupBlockWithValues(block, UInt256.Zero, out UInt256 _, out UInt160 _, out ulong _, out uint _, out Witness _, out Transaction[] _, 1); | ||
rpcBlock.Block = block; | ||
var json = rpcBlock.ToJson(); | ||
json["previousblockhash"].AsString().Should().Be("0x0000000000000000000000000000000000000000000000000000000000000000"); | ||
json.Should().NotBeNull(); | ||
|
||
rpcBlock.Confirmations = 1; | ||
rpcBlock.NextBlockHash = UInt256.Zero; | ||
json = rpcBlock.ToJson(); | ||
json["confirmations"].AsNumber().Should().Be(1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Network.P2P.Payloads; | ||
using Neo.Network.RPC.Models; | ||
using System; | ||
|
||
namespace Neo.UnitTests.Network.RPC.Models | ||
{ | ||
[TestClass] | ||
public class UT_RpcBlockHeader | ||
{ | ||
[TestMethod] | ||
public void TestToJson() | ||
{ | ||
var rpcBlockHeader = new RpcBlockHeader(); | ||
var header = new Header(); | ||
TestUtils.SetupHeaderWithValues(header, UInt256.Zero, out UInt256 _, out UInt160 _, out ulong _, out uint _, out Witness _); | ||
rpcBlockHeader.Header = header; | ||
var json = rpcBlockHeader.ToJson(); | ||
json["previousblockhash"].AsString().Should().Be("0x0000000000000000000000000000000000000000000000000000000000000000"); | ||
json.Should().NotBeNull(); | ||
|
||
rpcBlockHeader.Confirmations = 1; | ||
rpcBlockHeader.NextBlockHash = UInt256.Zero; | ||
json = rpcBlockHeader.ToJson(); | ||
json["confirmations"].AsNumber().Should().Be(1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.IO.Json; | ||
using Neo.Network.RPC.Models; | ||
using System.Numerics; | ||
|
||
namespace Neo.UnitTests.Network.RPC.Models | ||
{ | ||
[TestClass] | ||
public class UT_RpcNep5Balance | ||
{ | ||
private RpcNep5Balance balance; | ||
|
||
[TestInitialize] | ||
public void Setup() | ||
{ | ||
balance = new RpcNep5Balance(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestAssetHash() | ||
{ | ||
balance.AssetHash = UInt160.Zero; | ||
balance.AssetHash.Should().Be(UInt160.Zero); | ||
} | ||
|
||
[TestMethod] | ||
public void TestAmount() | ||
{ | ||
balance.Amount = BigInteger.Zero; | ||
balance.Amount.Should().Be(BigInteger.Zero); | ||
} | ||
|
||
[TestMethod] | ||
public void TestLastUpdatedBlock() | ||
{ | ||
balance.LastUpdatedBlock = 0; | ||
balance.LastUpdatedBlock.Should().Be(0); | ||
} | ||
|
||
[TestMethod] | ||
public void TestToJson() | ||
{ | ||
balance.AssetHash = UInt160.Zero; | ||
balance.Amount = BigInteger.Zero; | ||
balance.LastUpdatedBlock = 0; | ||
var json = balance.ToJson(); | ||
json["asset_hash"].AsString().Should().Be("0000000000000000000000000000000000000000"); | ||
json["amount"].AsNumber().Should().Be(0); | ||
json["last_updated_block"].AsNumber().Should().Be(0); | ||
} | ||
|
||
[TestMethod] | ||
public void TestFromJson() | ||
{ | ||
var json = new JObject(); | ||
json["asset_hash"] = "0000000000000000000000000000000000000000"; | ||
json["amount"] = "0"; | ||
json["last_updated_block"] = "0"; | ||
var rpcNep5Balance = RpcNep5Balance.FromJson(json); | ||
rpcNep5Balance.AssetHash.Should().Be(UInt160.Zero); | ||
rpcNep5Balance.Amount.Should().Be(BigInteger.Zero); | ||
rpcNep5Balance.LastUpdatedBlock.Should().Be(0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.IO.Json; | ||
using Neo.Network.RPC.Models; | ||
using System.Numerics; | ||
|
||
namespace Neo.UnitTests.Network.RPC.Models | ||
{ | ||
[TestClass] | ||
public class UT_RpcNep5Balances | ||
{ | ||
private RpcNep5Balances balances; | ||
|
||
[TestInitialize] | ||
public void Setup() | ||
{ | ||
balances = new RpcNep5Balances() | ||
{ | ||
Address = "abc", | ||
Balances = new RpcNep5Balance[] { | ||
new RpcNep5Balance() | ||
{ | ||
AssetHash = UInt160.Zero, | ||
Amount = BigInteger.Zero, | ||
LastUpdatedBlock = 0 | ||
}, | ||
new RpcNep5Balance() | ||
{ | ||
AssetHash = UInt160.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff01"), | ||
Amount = new BigInteger(1), | ||
LastUpdatedBlock = 1 | ||
} | ||
} | ||
}; | ||
} | ||
|
||
[TestMethod] | ||
public void TestAddress() | ||
{ | ||
balances.Address.Should().Be("abc"); | ||
} | ||
|
||
[TestMethod] | ||
public void TestBalances() | ||
{ | ||
balances.Balances.Length.Should().Be(2); | ||
} | ||
|
||
[TestMethod] | ||
public void TestToJson() | ||
{ | ||
var json = balances.ToJson(); | ||
json["address"].AsString().Should().Be("abc"); | ||
((JArray)json["balance"]).Count.Should().Be(2); | ||
} | ||
|
||
[TestMethod] | ||
public void TestFromJson() | ||
{ | ||
var json = balances.ToJson(); | ||
var rpcNep5Balances = RpcNep5Balances.FromJson(json); | ||
rpcNep5Balances.Address.Should().Be("abc"); | ||
rpcNep5Balances.Balances.Length.Should().Be(2); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Network.RPC.Models; | ||
|
||
namespace Neo.UnitTests.Network.RPC.Models | ||
{ | ||
[TestClass] | ||
public class UT_RpcPeer | ||
{ | ||
[TestMethod] | ||
public void TestToJson() | ||
{ | ||
var rpcPeer = new RpcPeer() | ||
{ | ||
Address = "abc", | ||
Port = 800 | ||
}; | ||
var json = rpcPeer.ToJson(); | ||
json["address"].AsString().Should().Be("abc"); | ||
json["port"].AsNumber().Should().Be(800); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.IO.Json; | ||
using Neo.Network.RPC.Models; | ||
|
||
namespace Neo.UnitTests.Network.RPC.Models | ||
{ | ||
[TestClass] | ||
public class UT_RpcPeers | ||
{ | ||
[TestMethod] | ||
public void TestToJson() | ||
{ | ||
var rpcPeers = new RpcPeers() | ||
{ | ||
Unconnected = new RpcPeer[] { | ||
new RpcPeer() | ||
{ | ||
Address = "Unconnected", | ||
Port = 600 | ||
} | ||
}, | ||
Bad = new RpcPeer[] { | ||
new RpcPeer() | ||
{ | ||
Address = "Bad", | ||
Port = 700 | ||
} | ||
}, | ||
Connected = new RpcPeer[] { | ||
new RpcPeer() | ||
{ | ||
Address = "Connected", | ||
Port = 800 | ||
} | ||
} | ||
}; | ||
var json = rpcPeers.ToJson(); | ||
((JArray)json["unconnected"]).Count.Should().Be(1); | ||
((JArray)json["bad"]).Count.Should().Be(1); | ||
((JArray)json["connected"]).Count.Should().Be(1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Network.RPC.Models; | ||
|
||
namespace Neo.UnitTests.Network.RPC.Models | ||
{ | ||
[TestClass] | ||
public class UT_RpcRawMemPool | ||
{ | ||
[TestMethod] | ||
public void TestToJson() | ||
{ | ||
var pool = new RpcRawMemPool | ||
{ | ||
Height = 1, | ||
Verified = new string[] { | ||
"a", "b" | ||
}, | ||
UnVerified = new string[] { | ||
"c", "d" | ||
} | ||
}; | ||
var json = pool.ToJson(); | ||
json["height"].AsNumber().Should().Be(1); | ||
json["verified"].AsString().Should().Be("a,b"); | ||
json["unverified"].AsString().Should().Be("c,d"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.IO.Json; | ||
using Neo.Network.RPC.Models; | ||
|
||
namespace Neo.UnitTests.Network.RPC.Models | ||
{ | ||
[TestClass] | ||
public class UT_RpcRequest | ||
{ | ||
[TestMethod] | ||
public void TestFromJson() | ||
{ | ||
var req = new RpcRequest() | ||
{ | ||
Id = 1, | ||
Jsonrpc = "myrpc", | ||
Method = "get", | ||
Params = new JObject[] { | ||
new JBoolean(true) | ||
} | ||
}; | ||
var json = req.ToJson(); | ||
var rpcRequest = RpcRequest.FromJson(json); | ||
rpcRequest.Jsonrpc.Should().Be("myrpc"); | ||
rpcRequest.Method.Should().Be("get"); | ||
rpcRequest.Id.Should().Be(1); | ||
rpcRequest.Params.Length.Should().Be(1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.IO.Json; | ||
using Neo.Network.RPC.Models; | ||
|
||
namespace Neo.UnitTests.Network.RPC.Models | ||
{ | ||
[TestClass] | ||
public class UT_RpcResponse | ||
{ | ||
[TestMethod] | ||
public void TestToJson() | ||
{ | ||
var error = new RpcResponseError() | ||
{ | ||
Code = 0, | ||
Message = "msg", | ||
Data = new JBoolean(true) | ||
}; | ||
var rep = new RpcResponse() | ||
{ | ||
Id = 1, | ||
Jsonrpc = "rpc", | ||
Error = error, | ||
Result = new JBoolean(true) | ||
}; | ||
var json = rep.ToJson(); | ||
json["id"].AsNumber().Should().Be(1); | ||
json["jsonrpc"].AsString().Should().Be("rpc"); | ||
json["error"].AsString().Should().Be(error.ToJson().AsString()); | ||
json["result"].AsBoolean().Should().BeTrue(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Network.RPC.Models; | ||
|
||
namespace Neo.UnitTests.Network.RPC.Models | ||
{ | ||
[TestClass] | ||
public class UT_RpcVersion | ||
{ | ||
[TestMethod] | ||
public void TestToJson() | ||
{ | ||
var version = new RpcVersion() | ||
{ | ||
TcpPort = 800, | ||
WsPort = 900, | ||
Nonce = 1, | ||
UserAgent = "agent" | ||
}; | ||
var json = version.ToJson(); | ||
json["topPort"].AsNumber().Should().Be(800); | ||
json["wsPort"].AsNumber().Should().Be(900); | ||
json["nonce"].AsNumber().Should().Be(1); | ||
json["useragent"].AsString().Should().Be("agent"); | ||
} | ||
} | ||
} |
Oops, something went wrong.