Skip to content

Commit

Permalink
[RpcClient] Policy API mismatch (#388)
Browse files Browse the repository at this point in the history
* fixed-bug-1021

* Update src/RpcServer/RpcServer.SmartContract.cs

* 😂

* NEO3: RPC client Policy API mismatch

* update

* update

* update

* UT

* Format

Co-authored-by: Shargon <[email protected]>
Co-authored-by: Owen Zhang <[email protected]>
  • Loading branch information
3 people authored Nov 10, 2020
1 parent f88961d commit 3ab2871
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/RpcClient/PolicyAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Neo.VM;
using System.Linq;
using System.Threading.Tasks;
using Neo.IO.Json;

namespace Neo.Network.RPC
{
Expand Down Expand Up @@ -52,11 +53,10 @@ public async Task<long> GetFeePerByteAsync()
/// Get Ploicy Blocked Accounts
/// </summary>
/// <returns></returns>
public async Task<UInt160[]> GetBlockedAccountsAsync()
public async Task<bool> 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, "isBlocked", new object[] { account }).ConfigureAwait(false);
return result.Stack.Single().GetBoolean();
}
}
}
11 changes: 5 additions & 6 deletions tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@ 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 } } });

var result = await policyAPI.GetBlockedAccountsAsync();
Assert.AreEqual(UInt160.Zero, result[0]);
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.IsBlockedAsync(UInt160.Zero);
Assert.AreEqual(true, result);
}
}
}

0 comments on commit 3ab2871

Please sign in to comment.