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

[RpcClient] Policy API mismatch #388

Merged
merged 13 commits into from
Nov 10, 2020
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);
}
}
}