diff --git a/src/RpcClient/Models/RpcNep5Transfers.cs b/src/RpcClient/Models/RpcNep5Transfers.cs index e166d41fe..ee9abc18f 100644 --- a/src/RpcClient/Models/RpcNep5Transfers.cs +++ b/src/RpcClient/Models/RpcNep5Transfers.cs @@ -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; @@ -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(); diff --git a/tests/Neo.Network.RPC.Tests/RpcTestCases.json b/tests/Neo.Network.RPC.Tests/RpcTestCases.json index 2a98356c9..e3f03d4df 100644 --- a/tests/Neo.Network.RPC.Tests/RpcTestCases.json +++ b/tests/Neo.Network.RPC.Tests/RpcTestCases.json @@ -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": { diff --git a/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs b/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs index dd38fd9fe..dd08d6024 100644 --- a/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs +++ b/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs @@ -44,7 +44,7 @@ private void MockResponse(RpcRequest request, RpcResponse response) ItExpr.Is(p => p.Content.ReadAsStringAsync().Result == request.ToJson().ToString()), ItExpr.IsAny() ) - // prepare the expected response of the mocked http call + // prepare the expected response of the mocked http call .ReturnsAsync(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, @@ -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()); }