Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add null check for transferaddress #373

Merged
merged 10 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from 8 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
4 changes: 2 additions & 2 deletions src/RpcClient/Models/RpcNep5Transfers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public JObject ToJson()
JObject json = new JObject();
json["timestamp"] = TimestampMS;
json["assethash"] = AssetHash.ToString();
json["transferaddress"] = UserScriptHash.ToAddress();
json["transferaddress"] = UserScriptHash?.ToAddress();
json["amount"] = Amount.ToString();
json["blockindex"] = BlockIndex;
json["transfernotifyindex"] = TransferNotifyIndex;
Expand All @@ -70,7 +70,7 @@ public static RpcNep5Transfer FromJson(JObject json)
RpcNep5Transfer transfer = new RpcNep5Transfer();
transfer.TimestampMS = (ulong)json["timestamp"].AsNumber();
transfer.AssetHash = json["assethash"].ToScriptHash();
transfer.UserScriptHash = json["transferaddress"].ToScriptHash();
transfer.UserScriptHash = json["transferaddress"]?.ToScriptHash();
transfer.Amount = BigInteger.Parse(json["amount"].AsString());
transfer.BlockIndex = (uint)json["blockindex"].AsNumber();
transfer.TransferNotifyIndex = (ushort)json["transfernotifyindex"].AsNumber();
Expand Down
47 changes: 47 additions & 0 deletions tests/Neo.Network.RPC.Tests/RpcTestCases.json
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,53 @@
}
}
},
{
"Name": "getnep5transfersasync_with_null_transferaddress",
"Request": {
"jsonrpc": "2.0",
"method": "getnep5transfers",
"params": [ "Ncb7jVsYWBt1q5T5k3ZTP8bn5eK4DuanLd", 0, 1868595301000 ],
"id": 1
},
"Response": {
"jsonrpc": "2.0",
"id": 1,
"result": {
"sent": [
{
"timestamp": 1579250114541,
"assethash": "0x8c23f196d8a1bfd103a9dcb1f9ccf0c611377d3b",
"transferaddress": null,
"amount": "1000000000",
"blockindex": 603,
"transfernotifyindex": 0,
"txhash": "0x5e177b8d1dc33e9103c0cfd42f6dbf4efbe43029e2d6a18ea5ba0cb8437056b3"
},
{
"timestamp": 1579406581635,
"assethash": "0x8c23f196d8a1bfd103a9dcb1f9ccf0c611377d3b",
"transferaddress": "Ncb7jVsYWBt1q5T5k3ZTP8bn5eK4DuanLd",
"amount": "1000000000",
"blockindex": 1525,
"transfernotifyindex": 0,
"txhash": "0xc9c618b48972b240e0058d97b8d79b807ad51015418c84012765298526aeb77d"
}
],
"received": [
{
"timestamp": 1579250114541,
"assethash": "0x8c23f196d8a1bfd103a9dcb1f9ccf0c611377d3b",
"transferaddress": null,
"amount": "1000000000",
"blockindex": 603,
"transfernotifyindex": 0,
"txhash": "0x5e177b8d1dc33e9103c0cfd42f6dbf4efbe43029e2d6a18ea5ba0cb8437056b3"
}
],
"address": "Ncb7jVsYWBt1q5T5k3ZTP8bn5eK4DuanLd"
}
}
},
{
"Name": "getnep5balancesasync",
"Request": {
Expand Down
8 changes: 5 additions & 3 deletions tests/Neo.Network.RPC.Tests/UT_RpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private void MockResponse(RpcRequest request, RpcResponse response)
ItExpr.Is<HttpRequestMessage>(p => p.Content.ReadAsStringAsync().Result == request.ToJson().ToString()),
ItExpr.IsAny<CancellationToken>()
)
// prepare the expected response of the mocked http call
// prepare the expected response of the mocked http call
.ReturnsAsync(new HttpResponseMessage()
{
StatusCode = HttpStatusCode.OK,
Expand Down Expand Up @@ -424,8 +424,10 @@ public async Task GetApplicationLogTest()
public async Task GetNep5TransfersTest()
{
var test = TestUtils.RpcTestCases.Find(p => p.Name == nameof(rpc.GetNep5TransfersAsync).ToLower());
var result = await rpc.GetNep5TransfersAsync(test.Request.Params[0].AsString(), (ulong)test.Request.Params[1].AsNumber(),
(ulong)test.Request.Params[2].AsNumber());
var result = await rpc.GetNep5TransfersAsync(test.Request.Params[0].AsString(), (ulong)test.Request.Params[1].AsNumber(), (ulong)test.Request.Params[2].AsNumber());
Assert.AreEqual(test.Response.Result.ToString(), result.ToJson().ToString());
test = TestUtils.RpcTestCases.Find(p => p.Name == (nameof(rpc.GetNep5TransfersAsync).ToLower() + "_with_null_transferaddress"));
result = await rpc.GetNep5TransfersAsync(test.Request.Params[0].AsString(), (ulong)test.Request.Params[1].AsNumber(), (ulong)test.Request.Params[2].AsNumber());
Assert.AreEqual(test.Response.Result.ToString(), result.ToJson().ToString());
}

Expand Down