Skip to content

Commit

Permalink
Merge branch 'TriggerType' of https://github.com/chenzhitong/neo-modules
Browse files Browse the repository at this point in the history
 into TriggerType
  • Loading branch information
陈志同 committed Nov 11, 2020
2 parents edf8e5b + 24744d1 commit 934dd90
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 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();
}
}
}
2 changes: 1 addition & 1 deletion src/RpcServer/RpcServer.SmartContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected virtual JObject InvokeFunction(JArray _params)
[RpcMethod]
protected virtual JObject InvokeScript(JArray _params)
{
byte[] script = _params[0].AsString().HexToBytes();
byte[] script = Convert.FromBase64String(_params[0].AsString());
Signers signers = _params.Count >= 2 ? SignersFromJson((JArray)_params[1]) : null;
return GetInvokeResult(script, signers);
}
Expand Down
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 934dd90

Please sign in to comment.