From a1bdf84079a2d413a15388dff51b1b1203fdbfdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Thu, 7 Jan 2021 02:43:08 -0600 Subject: [PATCH 1/6] Fixed "RpcClient doesn't compile against Neo master" (#449) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [RpcServer] Querying contracts by ID/name (#378) * fixed-bug-1021 * Update src/RpcServer/RpcServer.SmartContract.cs * 😂 * draft * draft * update * fixed bug with decimal of GAS consumed in invokefunction/invokescript * remove modify of invokescript * Querying contracts by ID/name, server side * update * Enable using native.name for search Enable using native.name for search * Using keyword instead of addressOrScriptHash * revert * _initialize * split * update * Update exception message in ApplicationLog * Update src/ApplicationLogs/LogReader.cs Co-authored-by: Luchuan * update * a * More fix * fix * Fixed UT * Simplify Code * Simplify Code 2 * Update RpcServer * update Co-authored-by: Shargon Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Co-authored-by: superboyiii <573504781@qq.com> Co-authored-by: Vitor Nazário Coelho Co-authored-by: Luchuan * MPT in StateService from core (#410) * Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal (#413) * Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal * fix * Fixed UT (Neo CI01089) (#416) * [RpcServer] Querying contracts by ID/name (#378) * fixed-bug-1021 * Update src/RpcServer/RpcServer.SmartContract.cs * 😂 * draft * draft * update * fixed bug with decimal of GAS consumed in invokefunction/invokescript * remove modify of invokescript * Querying contracts by ID/name, server side * update * Enable using native.name for search Enable using native.name for search * Using keyword instead of addressOrScriptHash * revert * _initialize * split * update * Update exception message in ApplicationLog * Update src/ApplicationLogs/LogReader.cs Co-authored-by: Luchuan * update * a * More fix * fix * Fixed UT * Simplify Code * Simplify Code 2 * Update RpcServer * update Co-authored-by: Shargon Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Co-authored-by: superboyiii <573504781@qq.com> Co-authored-by: Vitor Nazário Coelho Co-authored-by: Luchuan * MPT in StateService from core (#410) * Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal (#413) * Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal * fix * Fixed UT (Neo CI01089) Co-authored-by: Shargon Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Co-authored-by: superboyiii <573504781@qq.com> Co-authored-by: Vitor Nazário Coelho Co-authored-by: Luchuan Co-authored-by: ZhangTao * Nep17 (#412) * [RpcServer] Querying contracts by ID/name (#378) * fixed-bug-1021 * Update src/RpcServer/RpcServer.SmartContract.cs * 😂 * draft * draft * update * fixed bug with decimal of GAS consumed in invokefunction/invokescript * remove modify of invokescript * Querying contracts by ID/name, server side * update * Enable using native.name for search Enable using native.name for search * Using keyword instead of addressOrScriptHash * revert * _initialize * split * update * Update exception message in ApplicationLog * Update src/ApplicationLogs/LogReader.cs Co-authored-by: Luchuan * update * a * More fix * fix * Fixed UT * Simplify Code * Simplify Code 2 * Update RpcServer * update Co-authored-by: Shargon Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Co-authored-by: superboyiii <573504781@qq.com> Co-authored-by: Vitor Nazário Coelho Co-authored-by: Luchuan * String Substitution * Modify filename and name methods * update * update * Update src/RpcClient/Models/RpcNep5TokenInfo.cs Co-authored-by: Vitor Nazário Coelho * Update src/RpcClient/Nep17API.cs Co-authored-by: Vitor Nazário Coelho * MPT in StateService from core (#410) * Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal (#413) * Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal * fix * Fixed UT (Neo CI01089) * Update Nep17API.cs * Update README.md Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> * update filename * Fix UT * Format * fix * update * update UT * Add Unit Tests * update Co-authored-by: Shargon Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Co-authored-by: superboyiii <573504781@qq.com> Co-authored-by: Vitor Nazário Coelho Co-authored-by: Luchuan Co-authored-by: ZhangTao * merge * clear * Transfer bug fix (#429) * [RpcServer] Querying contracts by ID/name (#378) * fixed-bug-1021 * Update src/RpcServer/RpcServer.SmartContract.cs * 😂 * draft * draft * update * fixed bug with decimal of GAS consumed in invokefunction/invokescript * remove modify of invokescript * Querying contracts by ID/name, server side * update * Enable using native.name for search Enable using native.name for search * Using keyword instead of addressOrScriptHash * revert * _initialize * split * update * Update exception message in ApplicationLog * Update src/ApplicationLogs/LogReader.cs Co-authored-by: Luchuan * update * a * More fix * fix * Fixed UT * Simplify Code * Simplify Code 2 * Update RpcServer * update Co-authored-by: Shargon Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Co-authored-by: superboyiii <573504781@qq.com> Co-authored-by: Vitor Nazário Coelho Co-authored-by: Luchuan * MPT in StateService from core (#410) * Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal (#413) * Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal * fix * Fixed UT (Neo CI01089) (#416) * [RpcServer] Querying contracts by ID/name (#378) * fixed-bug-1021 * Update src/RpcServer/RpcServer.SmartContract.cs * 😂 * draft * draft * update * fixed bug with decimal of GAS consumed in invokefunction/invokescript * remove modify of invokescript * Querying contracts by ID/name, server side * update * Enable using native.name for search Enable using native.name for search * Using keyword instead of addressOrScriptHash * revert * _initialize * split * update * Update exception message in ApplicationLog * Update src/ApplicationLogs/LogReader.cs Co-authored-by: Luchuan * update * a * More fix * fix * Fixed UT * Simplify Code * Simplify Code 2 * Update RpcServer * update Co-authored-by: Shargon Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Co-authored-by: superboyiii <573504781@qq.com> Co-authored-by: Vitor Nazário Coelho Co-authored-by: Luchuan * MPT in StateService from core (#410) * Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal (#413) * Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal * fix * Fixed UT (Neo CI01089) Co-authored-by: Shargon Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Co-authored-by: superboyiii <573504781@qq.com> Co-authored-by: Vitor Nazário Coelho Co-authored-by: Luchuan Co-authored-by: ZhangTao * Nep17 (#412) * [RpcServer] Querying contracts by ID/name (#378) * fixed-bug-1021 * Update src/RpcServer/RpcServer.SmartContract.cs * 😂 * draft * draft * update * fixed bug with decimal of GAS consumed in invokefunction/invokescript * remove modify of invokescript * Querying contracts by ID/name, server side * update * Enable using native.name for search Enable using native.name for search * Using keyword instead of addressOrScriptHash * revert * _initialize * split * update * Update exception message in ApplicationLog * Update src/ApplicationLogs/LogReader.cs Co-authored-by: Luchuan * update * a * More fix * fix * Fixed UT * Simplify Code * Simplify Code 2 * Update RpcServer * update Co-authored-by: Shargon Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Co-authored-by: superboyiii <573504781@qq.com> Co-authored-by: Vitor Nazário Coelho Co-authored-by: Luchuan * String Substitution * Modify filename and name methods * update * update * Update src/RpcClient/Models/RpcNep5TokenInfo.cs Co-authored-by: Vitor Nazário Coelho * Update src/RpcClient/Nep17API.cs Co-authored-by: Vitor Nazário Coelho * MPT in StateService from core (#410) * Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal (#413) * Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal * fix * Fixed UT (Neo CI01089) * Update Nep17API.cs * Update README.md Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> * update filename * Fix UT * Format * fix * update * update UT * Add Unit Tests * update Co-authored-by: Shargon Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Co-authored-by: superboyiii <573504781@qq.com> Co-authored-by: Vitor Nazário Coelho Co-authored-by: Luchuan Co-authored-by: ZhangTao * merge * fixed bug * clear * UT * Add a little code coverage Co-authored-by: Shargon Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Co-authored-by: superboyiii <573504781@qq.com> Co-authored-by: Vitor Nazário Coelho Co-authored-by: Luchuan Co-authored-by: ZhangTao * Preview4 (#430) * Preview4 * Remove syslog in README.md * dotnet 5.0 (#407) * CI01123 (#435) * Fix dotnet5 (#442) * Update * Add RpcMethodToken and RpcNefFile * Format? * Increase test coverage * Increase test coverage * Increase test coverage * Increase test coverage * Increase test coverage * Clean code * format Co-authored-by: 陈志同 Co-authored-by: Shargon Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Co-authored-by: superboyiii <573504781@qq.com> Co-authored-by: Vitor Nazário Coelho Co-authored-by: Luchuan Co-authored-by: ZhangTao Co-authored-by: Erik Zhang Co-authored-by: Shine Li --- src/Directory.Build.props | 2 +- src/RpcClient/Models/RpcContractState.cs | 4 +- src/RpcClient/Models/RpcMethodToken.cs | 25 ++ src/RpcClient/Models/RpcNefFile.cs | 25 ++ src/RpcClient/Nep17API.cs | 24 +- src/RpcClient/RpcClient.cs | 2 +- tests/Neo.Network.RPC.Tests/RpcTestCases.json | 394 +++++++++++++++++- tests/Neo.Network.RPC.Tests/UT_Nep17API.cs | 25 +- tests/Neo.Network.RPC.Tests/UT_RpcClient.cs | 11 + tests/Neo.Network.RPC.Tests/UT_RpcModels.cs | 9 + 10 files changed, 496 insertions(+), 25 deletions(-) create mode 100644 src/RpcClient/Models/RpcMethodToken.cs create mode 100644 src/RpcClient/Models/RpcNefFile.cs diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 4b3679871..2d56584c7 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -15,7 +15,7 @@ - + diff --git a/src/RpcClient/Models/RpcContractState.cs b/src/RpcClient/Models/RpcContractState.cs index e4e0f711d..797fa1a79 100644 --- a/src/RpcClient/Models/RpcContractState.cs +++ b/src/RpcClient/Models/RpcContractState.cs @@ -1,5 +1,7 @@ using Neo; +using Neo.IO; using Neo.IO.Json; +using Neo.Network.RPC.Models; using Neo.SmartContract; using Neo.SmartContract.Manifest; using System; @@ -22,7 +24,7 @@ public static RpcContractState FromJson(JObject json) Id = (int)json["id"].AsNumber(), UpdateCounter = (ushort)json["updatecounter"].AsNumber(), Hash = UInt160.Parse(json["hash"].AsString()), - Script = Convert.FromBase64String(json["script"].AsString()), + Nef = RpcNefFile.FromJson(json["nef"]), Manifest = ContractManifest.FromJson(json["manifest"]) } }; diff --git a/src/RpcClient/Models/RpcMethodToken.cs b/src/RpcClient/Models/RpcMethodToken.cs new file mode 100644 index 000000000..02bf31ead --- /dev/null +++ b/src/RpcClient/Models/RpcMethodToken.cs @@ -0,0 +1,25 @@ +using Neo.IO.Json; +using Neo.SmartContract; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Neo.Network.RPC.Models +{ + class RpcMethodToken + { + public static MethodToken FromJson(JObject json) + { + return new MethodToken + { + Hash = UInt160.Parse(json["hash"].AsString()), + Method = json["method"].AsString(), + ParametersCount = (ushort)json["paramcount"].AsNumber(), + HasReturnValue = json["hasreturnvalue"].AsBoolean(), + CallFlags = (CallFlags)Enum.Parse(typeof(CallFlags), json["callflags"].AsString()) + }; + } + } +} diff --git a/src/RpcClient/Models/RpcNefFile.cs b/src/RpcClient/Models/RpcNefFile.cs new file mode 100644 index 000000000..d366d5294 --- /dev/null +++ b/src/RpcClient/Models/RpcNefFile.cs @@ -0,0 +1,25 @@ +using Neo.IO.Json; +using Neo.SmartContract; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Neo.Network.RPC.Models +{ + class RpcNefFile + { + public static NefFile FromJson(JObject json) + { + return new NefFile + { + Compiler = json["compiler"].AsString(), + Version = json["version"].AsString(), + Tokens = ((JArray)json["tokens"]).Select(p => RpcMethodToken.FromJson(p)).ToArray(), + Script = Convert.FromBase64String(json["script"].AsString()), + CheckSum = (uint)json["checksum"].AsNumber() + }; + } + } +} diff --git a/src/RpcClient/Nep17API.cs b/src/RpcClient/Nep17API.cs index 14312e841..e3d7a8c53 100644 --- a/src/RpcClient/Nep17API.cs +++ b/src/RpcClient/Nep17API.cs @@ -76,14 +76,32 @@ public async Task TotalSupplyAsync(UInt160 scriptHash) /// public async Task GetTokenInfoAsync(UInt160 scriptHash) { + var contractState = await rpcClient.GetContractStateAsync(scriptHash.ToString()).ConfigureAwait(false); byte[] script = Concat( scriptHash.MakeScript("symbol", true), scriptHash.MakeScript("decimals", true), scriptHash.MakeScript("totalSupply", true)); - - var contractState = await rpcClient.GetContractStateAsync(scriptHash.ToString()).ConfigureAwait(false); var name = contractState.Manifest.Name; + var result = await rpcClient.InvokeScriptAsync(script).ConfigureAwait(false); + var stack = result.Stack; + return new RpcNep17TokenInfo + { + Name = name, + Symbol = stack[0].GetString(), + Decimals = (byte)stack[1].GetInteger(), + TotalSupply = stack[2].GetInteger() + }; + } + + public async Task GetTokenInfoAsync(string contractName) + { + var contractState = await rpcClient.GetContractStateAsync(contractName).ConfigureAwait(false); + byte[] script = Concat( + contractState.Hash.MakeScript("symbol", true), + contractState.Hash.MakeScript("decimals", true), + contractState.Hash.MakeScript("totalSupply", true)); + var name = contractState.Manifest.Name; var result = await rpcClient.InvokeScriptAsync(script).ConfigureAwait(false); var stack = result.Stack; @@ -109,7 +127,6 @@ public async Task CreateTransferTxAsync(UInt160 scriptHash, KeyPair { var sender = Contract.CreateSignatureRedeemScript(fromKey.PublicKey).ToScriptHash(); Signer[] signers = new[] { new Signer { Scopes = WitnessScope.CalledByEntry, Account = sender } }; - byte[] script = scriptHash.MakeScript("transfer", true, sender, to, amount, data); TransactionManagerFactory factory = new TransactionManagerFactory(rpcClient, magic); @@ -136,7 +153,6 @@ public async Task CreateTransferTxAsync(UInt160 scriptHash, int m, throw new ArgumentException($"Need at least {m} KeyPairs for signing!"); var sender = Contract.CreateMultiSigContract(m, pubKeys).ScriptHash; Signer[] signers = new[] { new Signer { Scopes = WitnessScope.CalledByEntry, Account = sender } }; - byte[] script = scriptHash.MakeScript("transfer", true, sender, to, amount, data); TransactionManagerFactory factory = new TransactionManagerFactory(rpcClient, magic); diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index ca47d82a5..a02447e4a 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -203,7 +203,7 @@ public static ContractState ContractStateFromJson(JObject json) Id = (int)json["id"].AsNumber(), UpdateCounter = (ushort)json["updatecounter"].AsNumber(), Hash = UInt160.Parse(json["hash"].AsString()), - Script = Convert.FromBase64String(json["script"].AsString()), + Nef = RpcNefFile.FromJson(json["nef"]), Manifest = ContractManifest.FromJson(json["manifest"]) }; } diff --git a/tests/Neo.Network.RPC.Tests/RpcTestCases.json b/tests/Neo.Network.RPC.Tests/RpcTestCases.json index 4ffadec7a..bcfe69d59 100644 --- a/tests/Neo.Network.RPC.Tests/RpcTestCases.json +++ b/tests/Neo.Network.RPC.Tests/RpcTestCases.json @@ -313,12 +313,28 @@ "result": "300000000" } }, + { + "Name": "getcommitteeasync", + "Request": { + "jsonrpc": "2.0", + "method": "getcommittee", + "params": [], + "id": 1 + }, + "Response": { + "jsonrpc": "2.0", + "id": 1, + "result": [ + "02ced432397ddc44edba031c0bc3b933f28fdd9677792d7b20e6c036ddaaacf1e2" + ] + } + }, { "Name": "getcontractstateasync", "Request": { "jsonrpc": "2.0", "method": "getcontractstate", - "params": [ "0xa6a6c15dcdc9b997dac448b6926522d22efeedfb" ], + "params": [ "gastoken" ], "id": 1 }, "Response": { @@ -327,8 +343,15 @@ "result": { "id": -2, "updatecounter": 0, - "hash": "0xa6a6c15dcdc9b997dac448b6926522d22efeedfb", - "script": "DAhHYXNUb2tlbkEa93tn", + "hash": "0x149a7f61eb3b4763b9655836ec7e75ddafdd1717", + "nef": { + "magic": 860243278, + "compiler": "ScriptBuilder", + "version": "3.0", + "tokens": [], + "script": "DAhHYXNUb2tlbkEa93tn", + "checksum": 4072842264 + }, "manifest": { "name": "GasToken", "groups": [], @@ -349,7 +372,7 @@ "parameters": [ { "name": "account", - "type": "ByteArray" + "type": "Hash160" } ], "offset": 0, @@ -361,11 +384,132 @@ "parameters": [ { "name": "from", - "type": "ByteArray" + "type": "Hash160" }, { "name": "to", - "type": "ByteArray" + "type": "Hash160" + }, + { + "name": "amount", + "type": "Integer" + }, + { + "name": "data", + "type": "Any" + } + ], + "offset": 0, + "returntype": "Boolean", + "safe": false + }, + { + "name": "symbol", + "parameters": [], + "offset": 0, + "returntype": "String", + "safe": true + }, + { + "name": "decimals", + "parameters": [], + "offset": 0, + "returntype": "Integer", + "safe": true + } + ], + "events": [ + { + "name": "Transfer", + "parameters": [ + { + "name": "from", + "type": "Hash160" + }, + { + "name": "to", + "type": "Hash160" + }, + { + "name": "amount", + "type": "Integer" + } + ] + } + ] + }, + "permissions": [ + { + "contract": "*", + "methods": "*" + } + ], + "trusts": [], + "extra": null + } + } + } + }, + { + "Name": "getcontractstateasync", + "Request": { + "jsonrpc": "2.0", + "method": "getcontractstate", + "params": [ "0x149a7f61eb3b4763b9655836ec7e75ddafdd1717" ], + "id": 1 + }, + "Response": { + "jsonrpc": "2.0", + "id": 1, + "result": { + "id": -2, + "updatecounter": 0, + "hash": "0x149a7f61eb3b4763b9655836ec7e75ddafdd1717", + "nef": { + "magic": 860243278, + "compiler": "ScriptBuilder", + "version": "3.0", + "tokens": [], + "script": "DAhHYXNUb2tlbkEa93tn", + "checksum": 4072842264 + }, + "manifest": { + "name": "GasToken", + "groups": [], + "supportedstandards": [ + "NEP-17" + ], + "abi": { + "methods": [ + { + "name": "totalSupply", + "parameters": [], + "offset": 0, + "returntype": "Integer", + "safe": true + }, + { + "name": "balanceOf", + "parameters": [ + { + "name": "account", + "type": "Hash160" + } + ], + "offset": 0, + "returntype": "Integer", + "safe": true + }, + { + "name": "transfer", + "parameters": [ + { + "name": "from", + "type": "Hash160" + }, + { + "name": "to", + "type": "Hash160" }, { "name": "amount", @@ -433,7 +577,7 @@ "jsonrpc": "2.0", "id": 1, "method": "getcontractstate", - "params": [ "0x0a46e2e37c9987f570b4af253fb77e7eef0f72b6" ] + "params": [ "neotoken" ] }, "Response": { "jsonrpc": "2.0", @@ -441,8 +585,15 @@ "result": { "id": -1, "updatecounter": 0, - "hash": "0x0a46e2e37c9987f570b4af253fb77e7eef0f72b6", - "script": "DAhOZW9Ub2tlbkEa93tn", + "hash": "0x0e1b9bfaa44e60311f6f3c96cfcd6d12c2fc3add", + "nef": { + "magic": 860243278, + "compiler": "ScriptBuilder", + "version": "3.0", + "tokens": [], + "script": "DAhOZW9Ub2tlbkEa93tn", + "checksum": 1698415525 + }, "manifest": { "name": "NeoToken", "groups": [], @@ -482,7 +633,7 @@ "parameters": [ { "name": "account", - "type": "ByteArray" + "type": "Hash160" }, { "name": "end", @@ -522,7 +673,7 @@ "parameters": [ { "name": "account", - "type": "ByteArray" + "type": "Hash160" }, { "name": "voteTo", @@ -559,7 +710,7 @@ "parameters": [ { "name": "account", - "type": "ByteArray" + "type": "Hash160" } ], "offset": 0, @@ -571,11 +722,228 @@ "parameters": [ { "name": "from", - "type": "ByteArray" + "type": "Hash160" + }, + { + "name": "to", + "type": "Hash160" + }, + { + "name": "amount", + "type": "Integer" + }, + { + "name": "data", + "type": "Any" + } + ], + "offset": 0, + "returntype": "Boolean", + "safe": false + }, + { + "name": "symbol", + "parameters": [], + "offset": 0, + "returntype": "String", + "safe": true + }, + { + "name": "decimals", + "parameters": [], + "offset": 0, + "returntype": "Integer", + "safe": true + } + ], + "events": [ + { + "name": "Transfer", + "parameters": [ + { + "name": "from", + "type": "Hash160" }, { "name": "to", + "type": "Hash160" + }, + { + "name": "amount", + "type": "Integer" + } + ] + } + ] + }, + "permissions": [ + { + "contract": "*", + "methods": "*" + } + ], + "trusts": [], + "extra": null + } + } + } + }, + { + "Name": "getcontractstateasync", + "Request": { + "jsonrpc": "2.0", + "id": 1, + "method": "getcontractstate", + "params": [ "0x0e1b9bfaa44e60311f6f3c96cfcd6d12c2fc3add" ] + }, + "Response": { + "jsonrpc": "2.0", + "id": 1, + "result": { + "id": -1, + "updatecounter": 0, + "hash": "0x0e1b9bfaa44e60311f6f3c96cfcd6d12c2fc3add", + "nef": { + "magic": 860243278, + "compiler": "ScriptBuilder", + "version": "3.0", + "tokens": [], + "script": "DAhOZW9Ub2tlbkEa93tn", + "checksum": 1698415525 + }, + "manifest": { + "name": "NeoToken", + "groups": [], + "supportedstandards": [ + "NEP-17" + ], + "abi": { + "methods": [ + { + "name": "totalSupply", + "parameters": [], + "offset": 0, + "returntype": "Integer", + "safe": true + }, + { + "name": "setGasPerBlock", + "parameters": [ + { + "name": "gasPerBlock", + "type": "Integer" + } + ], + "offset": 0, + "returntype": "Boolean", + "safe": false + }, + { + "name": "getGasPerBlock", + "parameters": [], + "offset": 0, + "returntype": "Integer", + "safe": true + }, + { + "name": "unclaimedGas", + "parameters": [ + { + "name": "account", + "type": "Hash160" + }, + { + "name": "end", + "type": "Integer" + } + ], + "offset": 0, + "returntype": "Integer", + "safe": true + }, + { + "name": "registerCandidate", + "parameters": [ + { + "name": "pubkey", + "type": "ByteArray" + } + ], + "offset": 0, + "returntype": "Boolean", + "safe": false + }, + { + "name": "unregisterCandidate", + "parameters": [ + { + "name": "pubkey", "type": "ByteArray" + } + ], + "offset": 0, + "returntype": "Boolean", + "safe": false + }, + { + "name": "vote", + "parameters": [ + { + "name": "account", + "type": "Hash160" + }, + { + "name": "voteTo", + "type": "ByteArray" + } + ], + "offset": 0, + "returntype": "Boolean", + "safe": false + }, + { + "name": "getCandidates", + "parameters": [], + "offset": 0, + "returntype": "Array", + "safe": true + }, + { + "name": "getCommittee", + "parameters": [], + "offset": 0, + "returntype": "Array", + "safe": true + }, + { + "name": "getNextBlockValidators", + "parameters": [], + "offset": 0, + "returntype": "Array", + "safe": true + }, + { + "name": "balanceOf", + "parameters": [ + { + "name": "account", + "type": "Hash160" + } + ], + "offset": 0, + "returntype": "Integer", + "safe": true + }, + { + "name": "transfer", + "parameters": [ + { + "name": "from", + "type": "Hash160" + }, + { + "name": "to", + "type": "Hash160" }, { "name": "amount", diff --git a/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs b/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs index 4d4582f11..a3d7bb63e 100644 --- a/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs +++ b/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs @@ -97,18 +97,33 @@ public async Task TestGetTokenInfo() rpcClientMock.Setup(p => p.RpcSendAsync("getcontractstate", It.Is(u => true))) .ReturnsAsync(test.Response.Result) .Verifiable(); - - if (test.Request.Params[0].AsString() == "0xa6a6c15dcdc9b997dac448b6926522d22efeedfb") + var gasToken = "0x149a7f61eb3b4763b9655836ec7e75ddafdd1717"; + Assert.AreEqual(NativeContract.GAS.Hash.ToString(), gasToken); + var neoToken = "0x0e1b9bfaa44e60311f6f3c96cfcd6d12c2fc3add"; + Assert.AreEqual(NativeContract.NEO.Hash.ToString(), neoToken); + if (test.Request.Params[0].AsString() == gasToken || test.Request.Params[0].AsString().Equals(NativeContract.GAS.Name, System.StringComparison.OrdinalIgnoreCase)) { - var result = await nep17API.GetTokenInfoAsync(NativeContract.GAS.Hash); + var result = await nep17API.GetTokenInfoAsync(NativeContract.GAS.Name.ToLower()); + Assert.AreEqual(NativeContract.GAS.Symbol, result.Symbol); + Assert.AreEqual(8, (int)result.Decimals); + Assert.AreEqual(1_00000000, (int)result.TotalSupply); + Assert.AreEqual("GasToken", result.Name); + + result = await nep17API.GetTokenInfoAsync(NativeContract.GAS.Hash); Assert.AreEqual(NativeContract.GAS.Symbol, result.Symbol); Assert.AreEqual(8, (int)result.Decimals); Assert.AreEqual(1_00000000, (int)result.TotalSupply); Assert.AreEqual("GasToken", result.Name); } - else if (test.Request.Params[0].AsString() == "0x0a46e2e37c9987f570b4af253fb77e7eef0f72b6") + else if (test.Request.Params[0].AsString() == neoToken || test.Request.Params[0].AsString().Equals(NativeContract.NEO.Name, System.StringComparison.OrdinalIgnoreCase)) { - var result = await nep17API.GetTokenInfoAsync(NativeContract.NEO.Hash); + var result = await nep17API.GetTokenInfoAsync(NativeContract.NEO.Name.ToLower()); + Assert.AreEqual(NativeContract.NEO.Symbol, result.Symbol); + Assert.AreEqual(0, (int)result.Decimals); + Assert.AreEqual(1_00000000, (int)result.TotalSupply); + Assert.AreEqual("NeoToken", result.Name); + + result = await nep17API.GetTokenInfoAsync(NativeContract.NEO.Hash); Assert.AreEqual(NativeContract.NEO.Symbol, result.Symbol); Assert.AreEqual(0, (int)result.Decimals); Assert.AreEqual(1_00000000, (int)result.TotalSupply); diff --git a/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs b/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs index f4f2f5c12..9add97bec 100644 --- a/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs +++ b/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs @@ -155,6 +155,17 @@ public async Task TestGetBlockHeader() } } + [TestMethod] + public async Task TestGetCommittee() + { + var tests = TestUtils.RpcTestCases.Where(p => p.Name == nameof(rpc.GetCommitteeAsync).ToLower()); + foreach (var test in tests) + { + var result = await rpc.GetCommitteeAsync(); + Assert.AreEqual(test.Response.Result.ToString(), ((JArray)result.Select(p => (JObject)p).ToArray()).ToString()); + } + } + [TestMethod] public async Task TestGetContractState() { diff --git a/tests/Neo.Network.RPC.Tests/UT_RpcModels.cs b/tests/Neo.Network.RPC.Tests/UT_RpcModels.cs index 18b55c603..bb557da6a 100644 --- a/tests/Neo.Network.RPC.Tests/UT_RpcModels.cs +++ b/tests/Neo.Network.RPC.Tests/UT_RpcModels.cs @@ -46,6 +46,9 @@ public void TestGetContractState() JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetContractStateAsync).ToLower()).Response.Result; var item = RpcContractState.FromJson(json); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); + + var nef = RpcNefFile.FromJson(json["nef"]); + Assert.AreEqual(json["nef"].ToString(), nef.ToJson().ToString()); } [TestMethod()] @@ -56,6 +59,12 @@ public void TestRpcInvokeResult() Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } + [TestMethod()] + public void TestRpcMethodToken() + { + RpcMethodToken.FromJson(JObject.Parse("{\"hash\": \"0x0e1b9bfaa44e60311f6f3c96cfcd6d12c2fc3add\", \"method\":\"test\",\"paramcount\":\"1\",\"hasreturnvalue\":\"true\",\"callflags\":\"All\"}")); + } + [TestMethod()] public void TestRpcNep17Balances() { From 9891b379cd0a8d0dbbae75fb9fc12a2c9534d63d Mon Sep 17 00:00:00 2001 From: Shargon Date: Sun, 10 Jan 2021 11:35:43 +0100 Subject: [PATCH 2/6] Update config.json (#452) --- src/RpcServer/RpcServer/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RpcServer/RpcServer/config.json b/src/RpcServer/RpcServer/config.json index d51daac31..460294a5f 100644 --- a/src/RpcServer/RpcServer/config.json +++ b/src/RpcServer/RpcServer/config.json @@ -7,7 +7,7 @@ "TrustedAuthorities": [], "RpcUser": "", "RpcPass": "", - "MaxGasInvoke": 10, + "MaxGasInvoke": 20, "MaxFee": 0.1, "MaxConcurrentConnections": 40, "DisabledMethods": [ "openwallet" ] From 69940c58e8a1626795ad65fe668b7bd7966f3411 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Mon, 11 Jan 2021 00:12:27 +0800 Subject: [PATCH 3/6] Neo 3.0.0-CI01148 --- src/ApplicationLogs/LogReader.cs | 27 +++++++++------------------ src/Directory.Build.props | 2 +- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/ApplicationLogs/LogReader.cs b/src/ApplicationLogs/LogReader.cs index f68ebaede..8405cab54 100644 --- a/src/ApplicationLogs/LogReader.cs +++ b/src/ApplicationLogs/LogReader.cs @@ -2,6 +2,7 @@ using Neo.IO.Data.LevelDB; using Neo.IO.Json; using Neo.Ledger; +using Neo.Network.P2P.Payloads; using Neo.Persistence; using Neo.SmartContract; using Neo.SmartContract.Native; @@ -9,7 +10,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using static System.IO.Path; namespace Neo.Plugins @@ -96,14 +96,14 @@ public static JObject TxLogToJson(Blockchain.ApplicationExecuted appExec) return txJson; } - public static JObject BlockLogToJson(StoreView snapshot, IReadOnlyList applicationExecutedList) + public static JObject BlockLogToJson(Block block, IReadOnlyList applicationExecutedList) { - var blocks = applicationExecutedList.Where(p => p.Transaction == null); - if (blocks.Count() > 0) + var blocks = applicationExecutedList.Where(p => p.Transaction is null).ToArray(); + if (blocks.Length > 0) { var blockJson = new JObject(); - var blockHash = snapshot.PersistingBlock.Hash.ToArray(); - blockJson["blockhash"] = snapshot.PersistingBlock.Hash.ToString(); + var blockHash = block.Hash.ToArray(); + blockJson["blockhash"] = block.Hash.ToString(); var triggerList = new List(); foreach (var appExec in blocks) { @@ -143,7 +143,7 @@ public static JObject BlockLogToJson(StoreView snapshot, IReadOnlyList applicationExecutedList) + void IPersistencePlugin.OnPersist(Block block, StoreView snapshot, IReadOnlyList applicationExecutedList) { WriteBatch writeBatch = new WriteBatch(); @@ -155,23 +155,14 @@ public void OnPersist(StoreView snapshot, IReadOnlyList - + From 6c33396038d36b8f490d0db31b4b124be2d850fd Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Mon, 11 Jan 2021 00:19:06 +0800 Subject: [PATCH 4/6] Fix UT --- src/RpcClient/ContractClient.cs | 2 +- src/RpcNep17Tracker/RpcNep17Tracker.cs | 3 +-- src/RpcServer/RpcServer.SmartContract.cs | 4 ++-- tests/Neo.Network.RPC.Tests/UT_ContractClient.cs | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/RpcClient/ContractClient.cs b/src/RpcClient/ContractClient.cs index 280ea08a1..0252da2b2 100644 --- a/src/RpcClient/ContractClient.cs +++ b/src/RpcClient/ContractClient.cs @@ -57,7 +57,7 @@ public async Task CreateDeployContractTxAsync(byte[] nefFile, Contr byte[] script; using (ScriptBuilder sb = new ScriptBuilder()) { - sb.EmitDynamicCall(NativeContract.ContractManagement.Hash, "deploy", true, nefFile, manifest.ToString()); + sb.EmitDynamicCall(NativeContract.ContractManagement.Hash, "deploy", nefFile, manifest.ToString()); script = sb.ToArray(); } UInt160 sender = Contract.CreateSignatureRedeemScript(key.PublicKey).ToScriptHash(); diff --git a/src/RpcNep17Tracker/RpcNep17Tracker.cs b/src/RpcNep17Tracker/RpcNep17Tracker.cs index 573e1633c..331c84ede 100644 --- a/src/RpcNep17Tracker/RpcNep17Tracker.cs +++ b/src/RpcNep17Tracker/RpcNep17Tracker.cs @@ -170,8 +170,7 @@ public void OnPersist(StoreView snapshot, IReadOnlyList Date: Mon, 11 Jan 2021 00:24:36 +0800 Subject: [PATCH 5/6] more fix --- src/RpcClient/ContractClient.cs | 2 +- src/RpcClient/Nep17API.cs | 16 ++++++------- .../UT_ContractClient.cs | 2 +- tests/Neo.Network.RPC.Tests/UT_Nep17API.cs | 24 +++++++++---------- tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs | 8 +++---- .../UT_TransactionManager.cs | 8 +++---- tests/Neo.Network.RPC.Tests/UT_WalletAPI.cs | 24 +++++++++---------- 7 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/RpcClient/ContractClient.cs b/src/RpcClient/ContractClient.cs index 0252da2b2..0db46c74c 100644 --- a/src/RpcClient/ContractClient.cs +++ b/src/RpcClient/ContractClient.cs @@ -41,7 +41,7 @@ public ContractClient(RpcClient rpc, uint? magic = null) /// public Task TestInvokeAsync(UInt160 scriptHash, string operation, params object[] args) { - byte[] script = scriptHash.MakeScript(operation, true, args); + byte[] script = scriptHash.MakeScript(operation, args); return rpcClient.InvokeScriptAsync(script); } diff --git a/src/RpcClient/Nep17API.cs b/src/RpcClient/Nep17API.cs index e3d7a8c53..6a7945c1d 100644 --- a/src/RpcClient/Nep17API.cs +++ b/src/RpcClient/Nep17API.cs @@ -78,9 +78,9 @@ public async Task GetTokenInfoAsync(UInt160 scriptHash) { var contractState = await rpcClient.GetContractStateAsync(scriptHash.ToString()).ConfigureAwait(false); byte[] script = Concat( - scriptHash.MakeScript("symbol", true), - scriptHash.MakeScript("decimals", true), - scriptHash.MakeScript("totalSupply", true)); + scriptHash.MakeScript("symbol"), + scriptHash.MakeScript("decimals"), + scriptHash.MakeScript("totalSupply")); var name = contractState.Manifest.Name; var result = await rpcClient.InvokeScriptAsync(script).ConfigureAwait(false); var stack = result.Stack; @@ -98,9 +98,9 @@ public async Task GetTokenInfoAsync(string contractName) { var contractState = await rpcClient.GetContractStateAsync(contractName).ConfigureAwait(false); byte[] script = Concat( - contractState.Hash.MakeScript("symbol", true), - contractState.Hash.MakeScript("decimals", true), - contractState.Hash.MakeScript("totalSupply", true)); + contractState.Hash.MakeScript("symbol"), + contractState.Hash.MakeScript("decimals"), + contractState.Hash.MakeScript("totalSupply")); var name = contractState.Manifest.Name; var result = await rpcClient.InvokeScriptAsync(script).ConfigureAwait(false); var stack = result.Stack; @@ -127,7 +127,7 @@ public async Task CreateTransferTxAsync(UInt160 scriptHash, KeyPair { var sender = Contract.CreateSignatureRedeemScript(fromKey.PublicKey).ToScriptHash(); Signer[] signers = new[] { new Signer { Scopes = WitnessScope.CalledByEntry, Account = sender } }; - byte[] script = scriptHash.MakeScript("transfer", true, sender, to, amount, data); + byte[] script = scriptHash.MakeScript("transfer", sender, to, amount, data); TransactionManagerFactory factory = new TransactionManagerFactory(rpcClient, magic); TransactionManager manager = await factory.MakeTransactionAsync(script, signers).ConfigureAwait(false); @@ -153,7 +153,7 @@ public async Task CreateTransferTxAsync(UInt160 scriptHash, int m, throw new ArgumentException($"Need at least {m} KeyPairs for signing!"); var sender = Contract.CreateMultiSigContract(m, pubKeys).ScriptHash; Signer[] signers = new[] { new Signer { Scopes = WitnessScope.CalledByEntry, Account = sender } }; - byte[] script = scriptHash.MakeScript("transfer", true, sender, to, amount, data); + byte[] script = scriptHash.MakeScript("transfer", sender, to, amount, data); TransactionManagerFactory factory = new TransactionManagerFactory(rpcClient, magic); TransactionManager manager = await factory.MakeTransactionAsync(script, signers).ConfigureAwait(false); diff --git a/tests/Neo.Network.RPC.Tests/UT_ContractClient.cs b/tests/Neo.Network.RPC.Tests/UT_ContractClient.cs index bee6b5140..1c180f7da 100644 --- a/tests/Neo.Network.RPC.Tests/UT_ContractClient.cs +++ b/tests/Neo.Network.RPC.Tests/UT_ContractClient.cs @@ -27,7 +27,7 @@ public void TestSetup() [TestMethod] public async Task TestInvoke() { - byte[] testScript = NativeContract.GAS.Hash.MakeScript("balanceOf", true, UInt160.Zero); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("balanceOf", UInt160.Zero); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.ByteArray, Value = "00e057eb481b".HexToBytes() }); ContractClient contractClient = new ContractClient(rpcClientMock.Object); diff --git a/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs b/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs index a3d7bb63e..c568e0388 100644 --- a/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs +++ b/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs @@ -31,7 +31,7 @@ public void TestSetup() [TestMethod] public async Task TestBalanceOf() { - byte[] testScript = NativeContract.GAS.Hash.MakeScript("balanceOf", true, UInt160.Zero); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("balanceOf", UInt160.Zero); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(10000) }); var balance = await nep17API.BalanceOfAsync(NativeContract.GAS.Hash, UInt160.Zero); @@ -41,7 +41,7 @@ public async Task TestBalanceOf() [TestMethod] public async Task TestGetSymbol() { - byte[] testScript = NativeContract.GAS.Hash.MakeScript("symbol", true); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("symbol"); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.String, Value = NativeContract.GAS.Symbol }); var result = await nep17API.SymbolAsync(NativeContract.GAS.Hash); @@ -51,7 +51,7 @@ public async Task TestGetSymbol() [TestMethod] public async Task TestGetDecimals() { - byte[] testScript = NativeContract.GAS.Hash.MakeScript("decimals", true); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("decimals"); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(NativeContract.GAS.Decimals) }); var result = await nep17API.DecimalsAsync(NativeContract.GAS.Hash); @@ -61,7 +61,7 @@ public async Task TestGetDecimals() [TestMethod] public async Task TestGetTotalSupply() { - byte[] testScript = NativeContract.GAS.Hash.MakeScript("totalSupply", true); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("totalSupply"); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_00000000) }); var result = await nep17API.TotalSupplyAsync(NativeContract.GAS.Hash); @@ -72,9 +72,9 @@ public async Task TestGetTotalSupply() public async Task TestGetTokenInfo() { UInt160 scriptHash = NativeContract.GAS.Hash; - byte[] testScript = scriptHash.MakeScript("symbol", true) - .Concat(scriptHash.MakeScript("decimals", true)) - .Concat(scriptHash.MakeScript("totalSupply", true)) + byte[] testScript = scriptHash.MakeScript("symbol") + .Concat(scriptHash.MakeScript("decimals")) + .Concat(scriptHash.MakeScript("totalSupply")) .ToArray(); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.String, Value = NativeContract.GAS.Symbol }, @@ -82,9 +82,9 @@ public async Task TestGetTokenInfo() new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_00000000) }); scriptHash = NativeContract.NEO.Hash; - testScript = scriptHash.MakeScript("symbol", true) - .Concat(scriptHash.MakeScript("decimals", true)) - .Concat(scriptHash.MakeScript("totalSupply", true)) + testScript = scriptHash.MakeScript("symbol") + .Concat(scriptHash.MakeScript("decimals")) + .Concat(scriptHash.MakeScript("totalSupply")) .ToArray(); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.String, Value = NativeContract.NEO.Symbol }, @@ -135,12 +135,12 @@ public async Task TestGetTokenInfo() [TestMethod] public async Task TestTransfer() { - byte[] testScript = NativeContract.GAS.Hash.MakeScript("transfer", true, sender, UInt160.Zero, new BigInteger(1_00000000), null); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("transfer", sender, UInt160.Zero, new BigInteger(1_00000000), null); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter()); var result = await nep17API.CreateTransferTxAsync(NativeContract.GAS.Hash, keyPair1, UInt160.Zero, new BigInteger(1_00000000)); - testScript = NativeContract.GAS.Hash.MakeScript("transfer", true, sender, UInt160.Zero, new BigInteger(1_00000000), string.Empty); + testScript = NativeContract.GAS.Hash.MakeScript("transfer", sender, UInt160.Zero, new BigInteger(1_00000000), string.Empty); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter()); result = await nep17API.CreateTransferTxAsync(NativeContract.GAS.Hash, keyPair1, UInt160.Zero, new BigInteger(1_00000000), string.Empty); diff --git a/tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs b/tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs index 9a32320de..245636e93 100644 --- a/tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs +++ b/tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs @@ -29,7 +29,7 @@ public void TestSetup() [TestMethod] public async Task TestGetMaxTransactionsPerBlock() { - byte[] testScript = NativeContract.Policy.Hash.MakeScript("getMaxTransactionsPerBlock", true); + byte[] testScript = NativeContract.Policy.Hash.MakeScript("getMaxTransactionsPerBlock"); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(512) }); var result = await policyAPI.GetMaxTransactionsPerBlockAsync(); @@ -39,7 +39,7 @@ public async Task TestGetMaxTransactionsPerBlock() [TestMethod] public async Task TestGetMaxBlockSize() { - byte[] testScript = NativeContract.Policy.Hash.MakeScript("getMaxBlockSize", true); + byte[] testScript = NativeContract.Policy.Hash.MakeScript("getMaxBlockSize"); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1024u * 256u) }); var result = await policyAPI.GetMaxBlockSizeAsync(); @@ -49,7 +49,7 @@ public async Task TestGetMaxBlockSize() [TestMethod] public async Task TestGetFeePerByte() { - byte[] testScript = NativeContract.Policy.Hash.MakeScript("getFeePerByte", true); + byte[] testScript = NativeContract.Policy.Hash.MakeScript("getFeePerByte"); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1000) }); var result = await policyAPI.GetFeePerByteAsync(); @@ -59,7 +59,7 @@ public async Task TestGetFeePerByte() [TestMethod] public async Task TestIsBlocked() { - byte[] testScript = NativeContract.Policy.Hash.MakeScript("isBlocked", true, 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.IsBlockedAsync(UInt160.Zero); Assert.AreEqual(true, result); diff --git a/tests/Neo.Network.RPC.Tests/UT_TransactionManager.cs b/tests/Neo.Network.RPC.Tests/UT_TransactionManager.cs index 06010849a..bc740fd1c 100644 --- a/tests/Neo.Network.RPC.Tests/UT_TransactionManager.cs +++ b/tests/Neo.Network.RPC.Tests/UT_TransactionManager.cs @@ -54,13 +54,13 @@ public static Mock MockRpcClient(UInt160 sender, byte[] script) .Verifiable(); // MockGasBalance - byte[] balanceScript = NativeContract.GAS.Hash.MakeScript("balanceOf", true, sender); + byte[] balanceScript = NativeContract.GAS.Hash.MakeScript("balanceOf", sender); var balanceResult = new ContractParameter() { Type = ContractParameterType.Integer, Value = BigInteger.Parse("10000000000000000") }; MockInvokeScript(mockRpc, balanceScript, balanceResult); // MockFeePerByte - byte[] policyScript = NativeContract.Policy.Hash.MakeScript("getFeePerByte", true); + byte[] policyScript = NativeContract.Policy.Hash.MakeScript("getFeePerByte"); var policyResult = new ContractParameter() { Type = ContractParameterType.Integer, Value = BigInteger.Parse("1000") }; MockInvokeScript(mockRpc, policyScript, policyResult); @@ -87,13 +87,13 @@ public static Mock MockMultiSig(UInt160 multiHash, byte[] script) .Verifiable(); // MockGasBalance - byte[] balanceScript = NativeContract.GAS.Hash.MakeScript("balanceOf", true, multiHash); + byte[] balanceScript = NativeContract.GAS.Hash.MakeScript("balanceOf", multiHash); var balanceResult = new ContractParameter() { Type = ContractParameterType.Integer, Value = BigInteger.Parse("10000000000000000") }; MockInvokeScript(mockRpc, balanceScript, balanceResult); // MockFeePerByte - byte[] policyScript = NativeContract.Policy.Hash.MakeScript("getFeePerByte", true); + byte[] policyScript = NativeContract.Policy.Hash.MakeScript("getFeePerByte"); var policyResult = new ContractParameter() { Type = ContractParameterType.Integer, Value = BigInteger.Parse("1000") }; MockInvokeScript(mockRpc, policyScript, policyResult); diff --git a/tests/Neo.Network.RPC.Tests/UT_WalletAPI.cs b/tests/Neo.Network.RPC.Tests/UT_WalletAPI.cs index 594f02654..7ec348ebe 100644 --- a/tests/Neo.Network.RPC.Tests/UT_WalletAPI.cs +++ b/tests/Neo.Network.RPC.Tests/UT_WalletAPI.cs @@ -36,7 +36,7 @@ public void TestSetup() [TestMethod] public async Task TestGetUnclaimedGas() { - byte[] testScript = NativeContract.NEO.Hash.MakeScript("unclaimedGas", true, sender, 99); + byte[] testScript = NativeContract.NEO.Hash.MakeScript("unclaimedGas", sender, 99); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) }); var balance = await walletAPI.GetUnclaimedGasAsync(address1); @@ -46,7 +46,7 @@ public async Task TestGetUnclaimedGas() [TestMethod] public async Task TestGetNeoBalance() { - byte[] testScript = NativeContract.NEO.Hash.MakeScript("balanceOf", true, sender); + byte[] testScript = NativeContract.NEO.Hash.MakeScript("balanceOf", sender); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_00000000) }); var balance = await walletAPI.GetNeoBalanceAsync(address1); @@ -56,7 +56,7 @@ public async Task TestGetNeoBalance() [TestMethod] public async Task TestGetGasBalance() { - byte[] testScript = NativeContract.GAS.Hash.MakeScript("balanceOf", true, sender); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("balanceOf", sender); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) }); var balance = await walletAPI.GetGasBalanceAsync(address1); @@ -66,7 +66,7 @@ public async Task TestGetGasBalance() [TestMethod] public async Task TestGetTokenBalance() { - byte[] testScript = UInt160.Zero.MakeScript("balanceOf", true, sender); + byte[] testScript = UInt160.Zero.MakeScript("balanceOf", sender); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) }); var balance = await walletAPI.GetTokenBalanceAsync(UInt160.Zero.ToString(), address1); @@ -76,10 +76,10 @@ public async Task TestGetTokenBalance() [TestMethod] public async Task TestClaimGas() { - byte[] balanceScript = NativeContract.NEO.Hash.MakeScript("balanceOf", true, sender); + byte[] balanceScript = NativeContract.NEO.Hash.MakeScript("balanceOf", sender); UT_TransactionManager.MockInvokeScript(rpcClientMock, balanceScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_00000000) }); - byte[] testScript = NativeContract.NEO.Hash.MakeScript("transfer", true, sender, sender, new BigInteger(1_00000000), null); + byte[] testScript = NativeContract.NEO.Hash.MakeScript("transfer", sender, sender, new BigInteger(1_00000000), null); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) }); var json = new JObject(); @@ -93,10 +93,10 @@ public async Task TestClaimGas() [TestMethod] public async Task TestTransfer() { - byte[] decimalsScript = NativeContract.GAS.Hash.MakeScript("decimals", true); + byte[] decimalsScript = NativeContract.GAS.Hash.MakeScript("decimals"); UT_TransactionManager.MockInvokeScript(rpcClientMock, decimalsScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(8) }); - byte[] testScript = NativeContract.GAS.Hash.MakeScript("transfer", true, sender, UInt160.Zero, NativeContract.GAS.Factor * 100, null); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("transfer", sender, UInt160.Zero, NativeContract.GAS.Factor * 100, null); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) }); var json = new JObject(); @@ -110,15 +110,15 @@ public async Task TestTransfer() [TestMethod] public async Task TestTransferfromMultiSigAccount() { - byte[] balanceScript = NativeContract.GAS.Hash.MakeScript("balanceOf", true, multiSender); + byte[] balanceScript = NativeContract.GAS.Hash.MakeScript("balanceOf", multiSender); var balanceResult = new ContractParameter() { Type = ContractParameterType.Integer, Value = BigInteger.Parse("10000000000000000") }; UT_TransactionManager.MockInvokeScript(rpcClientMock, balanceScript, balanceResult); - byte[] decimalsScript = NativeContract.GAS.Hash.MakeScript("decimals", true); + byte[] decimalsScript = NativeContract.GAS.Hash.MakeScript("decimals"); UT_TransactionManager.MockInvokeScript(rpcClientMock, decimalsScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(8) }); - byte[] testScript = NativeContract.GAS.Hash.MakeScript("transfer", true, multiSender, UInt160.Zero, NativeContract.GAS.Factor * 100, null); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("transfer", multiSender, UInt160.Zero, NativeContract.GAS.Factor * 100, null); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) }); var json = new JObject(); @@ -138,7 +138,7 @@ public async Task TestTransferfromMultiSigAccount() Assert.AreEqual(e.Message, $"Need at least 2 KeyPairs for signing!"); } - testScript = NativeContract.GAS.Hash.MakeScript("transfer", true, multiSender, UInt160.Zero, NativeContract.GAS.Factor * 100, string.Empty); + testScript = NativeContract.GAS.Hash.MakeScript("transfer", multiSender, UInt160.Zero, NativeContract.GAS.Factor * 100, string.Empty); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) }); tranaction = await walletAPI.TransferAsync(NativeContract.GAS.Hash, 1, new[] { keyPair1.PublicKey }, new[] { keyPair1 }, UInt160.Zero, NativeContract.GAS.Factor * 100, string.Empty); From 6d249320eeab4c9cce2f8483d99b5f00c5c5ec95 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Mon, 11 Jan 2021 00:36:39 +0800 Subject: [PATCH 6/6] More fix --- tests/Neo.Network.RPC.Tests/UT_Nep17API.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs b/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs index c568e0388..2c3559330 100644 --- a/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs +++ b/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs @@ -97,10 +97,10 @@ public async Task TestGetTokenInfo() rpcClientMock.Setup(p => p.RpcSendAsync("getcontractstate", It.Is(u => true))) .ReturnsAsync(test.Response.Result) .Verifiable(); - var gasToken = "0x149a7f61eb3b4763b9655836ec7e75ddafdd1717"; - Assert.AreEqual(NativeContract.GAS.Hash.ToString(), gasToken); - var neoToken = "0x0e1b9bfaa44e60311f6f3c96cfcd6d12c2fc3add"; - Assert.AreEqual(NativeContract.NEO.Hash.ToString(), neoToken); + var gasToken = "0x9ac04cf223f646de5f7faccafe34e30e5d4382a2"; + Assert.AreEqual(gasToken, NativeContract.GAS.Hash.ToString()); + var neoToken = "0x4961bf0ab79370b23dc45cde29f568d0e0fa6e93"; + Assert.AreEqual(neoToken, NativeContract.NEO.Hash.ToString()); if (test.Request.Params[0].AsString() == gasToken || test.Request.Params[0].AsString().Equals(NativeContract.GAS.Name, System.StringComparison.OrdinalIgnoreCase)) { var result = await nep17API.GetTokenInfoAsync(NativeContract.GAS.Name.ToLower());