From c7997a93e0b878c75bddf24dd41e57efb003c337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Wed, 21 Oct 2020 14:59:01 +0800 Subject: [PATCH 1/9] fixed-bug-1021 --- src/RpcServer/RpcServer.SmartContract.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RpcServer/RpcServer.SmartContract.cs b/src/RpcServer/RpcServer.SmartContract.cs index f5cf6cbfc..3de9c924f 100644 --- a/src/RpcServer/RpcServer.SmartContract.cs +++ b/src/RpcServer/RpcServer.SmartContract.cs @@ -79,7 +79,7 @@ private JObject GetInvokeResult(byte[] script, Signers signers = null) } if (engine.State != VMState.FAULT) { - ProcessInvokeWithWallet(json, signers); + ProcessInvokeWithWallet(json, null, signers); } return json; } From 7c9f02bb4bb73841a3cc2cd85dc67b59d643edc9 Mon Sep 17 00:00:00 2001 From: Shargon Date: Wed, 21 Oct 2020 09:22:58 +0200 Subject: [PATCH 2/9] Update src/RpcServer/RpcServer.SmartContract.cs --- src/RpcServer/RpcServer.SmartContract.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RpcServer/RpcServer.SmartContract.cs b/src/RpcServer/RpcServer.SmartContract.cs index 3de9c924f..8203bd7c6 100644 --- a/src/RpcServer/RpcServer.SmartContract.cs +++ b/src/RpcServer/RpcServer.SmartContract.cs @@ -79,7 +79,7 @@ private JObject GetInvokeResult(byte[] script, Signers signers = null) } if (engine.State != VMState.FAULT) { - ProcessInvokeWithWallet(json, null, signers); + ProcessInvokeWithWallet(json, signers: signers); } return json; } From 1079aa36eb031f2d2672033ecd3cdb2e689672ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Wed, 21 Oct 2020 17:48:21 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=F0=9F=98=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/RpcServer/RpcServer.SmartContract.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RpcServer/RpcServer.SmartContract.cs b/src/RpcServer/RpcServer.SmartContract.cs index 8203bd7c6..f5cf6cbfc 100644 --- a/src/RpcServer/RpcServer.SmartContract.cs +++ b/src/RpcServer/RpcServer.SmartContract.cs @@ -79,7 +79,7 @@ private JObject GetInvokeResult(byte[] script, Signers signers = null) } if (engine.State != VMState.FAULT) { - ProcessInvokeWithWallet(json, signers: signers); + ProcessInvokeWithWallet(json, signers); } return json; } From 7b7a1a5a1920cf366192e58f092e8b75390063af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Fri, 6 Nov 2020 14:58:32 +0800 Subject: [PATCH 4/9] NEO3: RPC client Policy API mismatch --- src/RpcClient/Nep5API.cs | 10 +++++----- src/RpcClient/PolicyAPI.cs | 14 +++++++------- src/RpcClient/RpcClient.cs | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/RpcClient/Nep5API.cs b/src/RpcClient/Nep5API.cs index 59cadd67e..03ae95882 100644 --- a/src/RpcClient/Nep5API.cs +++ b/src/RpcClient/Nep5API.cs @@ -31,7 +31,7 @@ public Nep5API(RpcClient rpcClient) : base(rpcClient) { } /// public async Task BalanceOfAsync(UInt160 scriptHash, UInt160 account) { - var result = await TestInvokeAsync(scriptHash, "balanceOf", account).ConfigureAwait(false); + var result = await TestInvokeAsync(scriptHash, RpcClient.GetRpcName(), account).ConfigureAwait(false); BigInteger balance = result.Stack.Single().GetInteger(); return balance; } @@ -43,7 +43,7 @@ public async Task BalanceOfAsync(UInt160 scriptHash, UInt160 account /// public async Task NameAsync(UInt160 scriptHash) { - var result = await TestInvokeAsync(scriptHash, "name").ConfigureAwait(false); + var result = await TestInvokeAsync(scriptHash, RpcClient.GetRpcName()).ConfigureAwait(false); return result.Stack.Single().GetString(); } @@ -54,7 +54,7 @@ public async Task NameAsync(UInt160 scriptHash) /// public async Task SymbolAsync(UInt160 scriptHash) { - var result = await TestInvokeAsync(scriptHash, "symbol").ConfigureAwait(false); + var result = await TestInvokeAsync(scriptHash, RpcClient.GetRpcName()).ConfigureAwait(false); return result.Stack.Single().GetString(); } @@ -65,7 +65,7 @@ public async Task SymbolAsync(UInt160 scriptHash) /// public async Task DecimalsAsync(UInt160 scriptHash) { - var result = await TestInvokeAsync(scriptHash, "decimals").ConfigureAwait(false); + var result = await TestInvokeAsync(scriptHash, RpcClient.GetRpcName()).ConfigureAwait(false); return (byte)result.Stack.Single().GetInteger(); } @@ -76,7 +76,7 @@ public async Task DecimalsAsync(UInt160 scriptHash) /// public async Task TotalSupplyAsync(UInt160 scriptHash) { - var result = await TestInvokeAsync(scriptHash, "totalSupply").ConfigureAwait(false); + var result = await TestInvokeAsync(scriptHash, RpcClient.GetRpcName()).ConfigureAwait(false); return result.Stack.Single().GetInteger(); } diff --git a/src/RpcClient/PolicyAPI.cs b/src/RpcClient/PolicyAPI.cs index 540f945da..673cbaf0f 100644 --- a/src/RpcClient/PolicyAPI.cs +++ b/src/RpcClient/PolicyAPI.cs @@ -2,6 +2,7 @@ using Neo.VM; using System.Linq; using System.Threading.Tasks; +using Neo.IO.Json; namespace Neo.Network.RPC { @@ -24,7 +25,7 @@ public PolicyAPI(RpcClient rpcClient) : base(rpcClient) { } /// public async Task GetMaxTransactionsPerBlockAsync() { - var result = await TestInvokeAsync(scriptHash, "getMaxTransactionsPerBlock").ConfigureAwait(false); + var result = await TestInvokeAsync(scriptHash, RpcClient.GetRpcName()).ConfigureAwait(false); return (uint)result.Stack.Single().GetInteger(); } @@ -34,7 +35,7 @@ public async Task GetMaxTransactionsPerBlockAsync() /// public async Task GetMaxBlockSizeAsync() { - var result = await TestInvokeAsync(scriptHash, "getMaxBlockSize").ConfigureAwait(false); + var result = await TestInvokeAsync(scriptHash, RpcClient.GetRpcName()).ConfigureAwait(false); return (uint)result.Stack.Single().GetInteger(); } @@ -44,7 +45,7 @@ public async Task GetMaxBlockSizeAsync() /// public async Task GetFeePerByteAsync() { - var result = await TestInvokeAsync(scriptHash, "getFeePerByte").ConfigureAwait(false); + var result = await TestInvokeAsync(scriptHash, RpcClient.GetRpcName()).ConfigureAwait(false); return (long)result.Stack.Single().GetInteger(); } @@ -52,11 +53,10 @@ public async Task GetFeePerByteAsync() /// Get Ploicy Blocked Accounts /// /// - public async Task GetBlockedAccountsAsync() + public async Task IsBlockedAsync(UInt160 account) { - var result = await TestInvokeAsync(scriptHash, "getBlockedAccounts").ConfigureAwait(false); - var array = (VM.Types.Array)result.Stack.Single(); - return array.Select(p => new UInt160(p.GetSpan().ToArray())).ToArray(); + var result = await TestInvokeAsync(scriptHash, RpcClient.GetRpcName(), new object[] { account }).ConfigureAwait(false); + return result.Stack.Single().GetBoolean(); } } } diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index ca43fc744..077a2c04d 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -95,7 +95,7 @@ public virtual async Task RpcSendAsync(string method, params JObject[] return response.Result; } - public static string GetRpcName() + internal static string GetRpcName() { var methodName = ""; for (int i = 1; i < 5; i++) From 38e6c9aaaea238cffea947bf2ac7d678af6ba236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Mon, 9 Nov 2020 16:07:50 +0800 Subject: [PATCH 5/9] update --- src/RpcClient/Nep5API.cs | 10 +++++----- src/RpcClient/RpcClient.cs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/RpcClient/Nep5API.cs b/src/RpcClient/Nep5API.cs index 03ae95882..59cadd67e 100644 --- a/src/RpcClient/Nep5API.cs +++ b/src/RpcClient/Nep5API.cs @@ -31,7 +31,7 @@ public Nep5API(RpcClient rpcClient) : base(rpcClient) { } /// public async Task BalanceOfAsync(UInt160 scriptHash, UInt160 account) { - var result = await TestInvokeAsync(scriptHash, RpcClient.GetRpcName(), account).ConfigureAwait(false); + var result = await TestInvokeAsync(scriptHash, "balanceOf", account).ConfigureAwait(false); BigInteger balance = result.Stack.Single().GetInteger(); return balance; } @@ -43,7 +43,7 @@ public async Task BalanceOfAsync(UInt160 scriptHash, UInt160 account /// public async Task NameAsync(UInt160 scriptHash) { - var result = await TestInvokeAsync(scriptHash, RpcClient.GetRpcName()).ConfigureAwait(false); + var result = await TestInvokeAsync(scriptHash, "name").ConfigureAwait(false); return result.Stack.Single().GetString(); } @@ -54,7 +54,7 @@ public async Task NameAsync(UInt160 scriptHash) /// public async Task SymbolAsync(UInt160 scriptHash) { - var result = await TestInvokeAsync(scriptHash, RpcClient.GetRpcName()).ConfigureAwait(false); + var result = await TestInvokeAsync(scriptHash, "symbol").ConfigureAwait(false); return result.Stack.Single().GetString(); } @@ -65,7 +65,7 @@ public async Task SymbolAsync(UInt160 scriptHash) /// public async Task DecimalsAsync(UInt160 scriptHash) { - var result = await TestInvokeAsync(scriptHash, RpcClient.GetRpcName()).ConfigureAwait(false); + var result = await TestInvokeAsync(scriptHash, "decimals").ConfigureAwait(false); return (byte)result.Stack.Single().GetInteger(); } @@ -76,7 +76,7 @@ public async Task DecimalsAsync(UInt160 scriptHash) /// public async Task TotalSupplyAsync(UInt160 scriptHash) { - var result = await TestInvokeAsync(scriptHash, RpcClient.GetRpcName()).ConfigureAwait(false); + var result = await TestInvokeAsync(scriptHash, "totalSupply").ConfigureAwait(false); return result.Stack.Single().GetInteger(); } diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index 077a2c04d..a99d2bdf4 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -98,7 +98,7 @@ public virtual async Task RpcSendAsync(string method, params JObject[] internal static string GetRpcName() { var methodName = ""; - for (int i = 1; i < 5; i++) + for (int i = 1; i <= 5; i++) { var method = new System.Diagnostics.StackTrace(true).GetFrame(i).GetMethod(); if (method.IsPublic && !method.IsGenericMethod) From b696f26fa005c4b139ce4214d6f6d976631e0d0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Mon, 9 Nov 2020 16:09:44 +0800 Subject: [PATCH 6/9] update --- src/RpcClient/PolicyAPI.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/RpcClient/PolicyAPI.cs b/src/RpcClient/PolicyAPI.cs index 673cbaf0f..808906a39 100644 --- a/src/RpcClient/PolicyAPI.cs +++ b/src/RpcClient/PolicyAPI.cs @@ -25,7 +25,7 @@ public PolicyAPI(RpcClient rpcClient) : base(rpcClient) { } /// public async Task GetMaxTransactionsPerBlockAsync() { - var result = await TestInvokeAsync(scriptHash, RpcClient.GetRpcName()).ConfigureAwait(false); + var result = await TestInvokeAsync(scriptHash, "getMaxTransactionsPerBlock").ConfigureAwait(false); return (uint)result.Stack.Single().GetInteger(); } @@ -35,7 +35,7 @@ public async Task GetMaxTransactionsPerBlockAsync() /// public async Task GetMaxBlockSizeAsync() { - var result = await TestInvokeAsync(scriptHash, RpcClient.GetRpcName()).ConfigureAwait(false); + var result = await TestInvokeAsync(scriptHash, "getMaxBlockSize").ConfigureAwait(false); return (uint)result.Stack.Single().GetInteger(); } @@ -45,7 +45,7 @@ public async Task GetMaxBlockSizeAsync() /// public async Task GetFeePerByteAsync() { - var result = await TestInvokeAsync(scriptHash, RpcClient.GetRpcName()).ConfigureAwait(false); + var result = await TestInvokeAsync(scriptHash, "getFeePerByte").ConfigureAwait(false); return (long)result.Stack.Single().GetInteger(); } @@ -55,7 +55,7 @@ public async Task GetFeePerByteAsync() /// public async Task IsBlockedAsync(UInt160 account) { - var result = await TestInvokeAsync(scriptHash, RpcClient.GetRpcName(), new object[] { account }).ConfigureAwait(false); + var result = await TestInvokeAsync(scriptHash, "isBlocked", new object[] { account }).ConfigureAwait(false); return result.Stack.Single().GetBoolean(); } } From 75a1cc2a3c95fa51dc93a19708445ac6c1cce17d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Mon, 9 Nov 2020 16:10:45 +0800 Subject: [PATCH 7/9] update --- src/RpcClient/RpcClient.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index a99d2bdf4..ca43fc744 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -95,10 +95,10 @@ public virtual async Task RpcSendAsync(string method, params JObject[] return response.Result; } - internal static string GetRpcName() + public static string GetRpcName() { var methodName = ""; - for (int i = 1; i <= 5; i++) + for (int i = 1; i < 5; i++) { var method = new System.Diagnostics.StackTrace(true).GetFrame(i).GetMethod(); if (method.IsPublic && !method.IsGenericMethod) From 92145727e392628f928be6301191646cbd684ea3 Mon Sep 17 00:00:00 2001 From: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Date: Tue, 10 Nov 2020 14:16:04 +0800 Subject: [PATCH 8/9] UT --- tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs b/tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs index 546e250e1..71d5285df 100644 --- a/tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs +++ b/tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs @@ -57,13 +57,13 @@ public async Task TestGetFeePerByte() } [TestMethod] - public async Task TestGetBlockedAccounts() + public async Task TestIsBlocked() { - byte[] testScript = NativeContract.Policy.Hash.MakeScript("getBlockedAccounts"); - UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Array, Value = new[] { new ContractParameter { Type = ContractParameterType.Hash160, Value = UInt160.Zero } } }); + byte[] testScript = NativeContract.Policy.Hash.MakeScript("isBlocked", UInt160.Zero); + UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Boolean, Value = true } ); - var result = await policyAPI.GetBlockedAccountsAsync(); - Assert.AreEqual(UInt160.Zero, result[0]); + var result = await policyAPI.IsBlockedAsync(UInt160.Zero); + Assert.AreEqual(true, result); } } } From 930fe1121885fad32fca5f3c0e06d0f8cb4d84d8 Mon Sep 17 00:00:00 2001 From: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Date: Tue, 10 Nov 2020 14:19:06 +0800 Subject: [PATCH 9/9] Format --- tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs b/tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs index 71d5285df..245636e93 100644 --- a/tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs +++ b/tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs @@ -60,8 +60,7 @@ public async Task TestGetFeePerByte() public async Task TestIsBlocked() { byte[] testScript = NativeContract.Policy.Hash.MakeScript("isBlocked", UInt160.Zero); - UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Boolean, Value = true } ); - + UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Boolean, Value = true }); var result = await policyAPI.IsBlockedAsync(UInt160.Zero); Assert.AreEqual(true, result); }