diff --git a/tests/Neo.Network.RPC.Tests/RpcTestCases.json b/tests/Neo.Network.RPC.Tests/RpcTestCases.json index c2e4f4b5a2..623b59f0d9 100644 --- a/tests/Neo.Network.RPC.Tests/RpcTestCases.json +++ b/tests/Neo.Network.RPC.Tests/RpcTestCases.json @@ -355,7 +355,7 @@ "jsonrpc": "2.0", "id": 1, "result": { - "id": -4, + "id": -6, "updatecounter": 0, "hash": "0xd2a4cff31913016155e38e474a2c06d08be276cf", "nef": { @@ -363,8 +363,8 @@ "compiler": "neo-core-v3.0", "source": "", "tokens": [], - "script": "APxBGvd7Zw==", - "checksum": 3155977747 + "script": "EEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0A=", + "checksum": 2663858513 }, "manifest": { "name": "GasToken", @@ -391,21 +391,21 @@ "name": "decimals", "parameters": [], "returntype": "Integer", - "offset": 0, + "offset": 7, "safe": true }, { "name": "symbol", "parameters": [], "returntype": "String", - "offset": 0, + "offset": 14, "safe": true }, { "name": "totalSupply", "parameters": [], "returntype": "Integer", - "offset": 0, + "offset": 21, "safe": true }, { @@ -429,7 +429,7 @@ } ], "returntype": "Boolean", - "offset": 0, + "offset": 28, "safe": false } ], @@ -470,14 +470,14 @@ "Request": { "jsonrpc": "2.0", "method": "getcontractstate", - "params": [ "0xd2a4cff31913016155e38e474a2c06d08be276cf" ], + "params": [ -6 ], "id": 1 }, "Response": { "jsonrpc": "2.0", "id": 1, "result": { - "id": -4, + "id": -6, "updatecounter": 0, "hash": "0xd2a4cff31913016155e38e474a2c06d08be276cf", "nef": { @@ -485,8 +485,8 @@ "compiler": "neo-core-v3.0", "source": "", "tokens": [], - "script": "APxBGvd7Zw==", - "checksum": 3155977747 + "script": "EEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0A=", + "checksum": 2663858513 }, "manifest": { "name": "GasToken", @@ -513,21 +513,21 @@ "name": "decimals", "parameters": [], "returntype": "Integer", - "offset": 0, + "offset": 7, "safe": true }, { "name": "symbol", "parameters": [], "returntype": "String", - "offset": 0, + "offset": 14, "safe": true }, { "name": "totalSupply", "parameters": [], "returntype": "Integer", - "offset": 0, + "offset": 21, "safe": true }, { @@ -551,7 +551,7 @@ } ], "returntype": "Boolean", - "offset": 0, + "offset": 28, "safe": false } ], @@ -591,27 +591,27 @@ "Name": "getcontractstateasync", "Request": { "jsonrpc": "2.0", - "id": 1, "method": "getcontractstate", - "params": [ "neotoken" ] + "params": [ "0xd2a4cff31913016155e38e474a2c06d08be276cf" ], + "id": 1 }, "Response": { "jsonrpc": "2.0", "id": 1, "result": { - "id": -3, + "id": -6, "updatecounter": 0, - "hash": "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5", + "hash": "0xd2a4cff31913016155e38e474a2c06d08be276cf", "nef": { "magic": 860243278, "compiler": "neo-core-v3.0", "source": "", "tokens": [], - "script": "AP1BGvd7Zw==", - "checksum": 3921333105 + "script": "EEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0A=", + "checksum": 2663858513 }, "manifest": { - "name": "NeoToken", + "name": "GasToken", "groups": [], "features": {}, "supportedstandards": [ @@ -635,73 +635,21 @@ "name": "decimals", "parameters": [], "returntype": "Integer", - "offset": 0, - "safe": true - }, - { - "name": "getCandidates", - "parameters": [], - "returntype": "Array", - "offset": 0, - "safe": true - }, - { - "name": "getCommittee", - "parameters": [], - "returntype": "Array", - "offset": 0, - "safe": true - }, - { - "name": "getGasPerBlock", - "parameters": [], - "returntype": "Integer", - "offset": 0, - "safe": true - }, - { - "name": "getNextBlockValidators", - "parameters": [], - "returntype": "Array", - "offset": 0, + "offset": 7, "safe": true }, - { - "name": "registerCandidate", - "parameters": [ - { - "name": "pubkey", - "type": "ByteArray" - } - ], - "returntype": "Boolean", - "offset": 0, - "safe": false - }, - { - "name": "setGasPerBlock", - "parameters": [ - { - "name": "gasPerBlock", - "type": "Integer" - } - ], - "returntype": "Boolean", - "offset": 0, - "safe": false - }, { "name": "symbol", "parameters": [], "returntype": "String", - "offset": 0, + "offset": 14, "safe": true }, { "name": "totalSupply", "parameters": [], "returntype": "Integer", - "offset": 0, + "offset": 21, "safe": true }, { @@ -725,51 +673,7 @@ } ], "returntype": "Boolean", - "offset": 0, - "safe": false - }, - { - "name": "unclaimedGas", - "parameters": [ - { - "name": "account", - "type": "Hash160" - }, - { - "name": "end", - "type": "Integer" - } - ], - "returntype": "Integer", - "offset": 0, - "safe": true - }, - { - "name": "unregisterCandidate", - "parameters": [ - { - "name": "pubkey", - "type": "ByteArray" - } - ], - "returntype": "Boolean", - "offset": 0, - "safe": false - }, - { - "name": "vote", - "parameters": [ - { - "name": "account", - "type": "Hash160" - }, - { - "name": "voteTo", - "type": "ByteArray" - } - ], - "returntype": "Boolean", - "offset": 0, + "offset": 28, "safe": false } ], @@ -811,22 +715,22 @@ "jsonrpc": "2.0", "id": 1, "method": "getcontractstate", - "params": [ "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5" ] + "params": [ "neotoken" ] }, "Response": { "jsonrpc": "2.0", "id": 1, "result": { - "id": -3, - "updatecounter": 0, + "id": -5, + "updatecounter": 1, "hash": "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5", "nef": { "magic": 860243278, "compiler": "neo-core-v3.0", "source": "", "tokens": [], - "script": "AP1BGvd7Zw==", - "checksum": 3921333105 + "script": "EEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0A=", + "checksum": 1325686241 }, "manifest": { "name": "NeoToken", @@ -853,35 +757,80 @@ "name": "decimals", "parameters": [], "returntype": "Integer", - "offset": 0, + "offset": 7, + "safe": true + }, + { + "name": "getAccountState", + "parameters": [ + { + "name": "account", + "type": "Hash160" + } + ], + "returntype": "Array", + "offset": 14, + "safe": true + }, + { + "name": "getAllCandidates", + "parameters": [], + "returntype": "InteropInterface", + "offset": 21, + "safe": true + }, + { + "name": "getCandidateVote", + "parameters": [ + { + "name": "pubKey", + "type": "PublicKey" + } + ], + "returntype": "Integer", + "offset": 28, "safe": true }, { "name": "getCandidates", "parameters": [], "returntype": "Array", - "offset": 0, + "offset": 35, "safe": true }, { "name": "getCommittee", "parameters": [], "returntype": "Array", - "offset": 0, + "offset": 42, + "safe": true + }, + { + "name": "getCommitteeAddress", + "parameters": [], + "returntype": "Hash160", + "offset": 49, "safe": true }, { "name": "getGasPerBlock", "parameters": [], "returntype": "Integer", - "offset": 0, + "offset": 56, "safe": true }, { "name": "getNextBlockValidators", "parameters": [], "returntype": "Array", - "offset": 0, + "offset": 63, + "safe": true + }, + { + "name": "getRegisterPrice", + "parameters": [], + "returntype": "Integer", + "offset": 70, "safe": true }, { @@ -889,11 +838,11 @@ "parameters": [ { "name": "pubkey", - "type": "ByteArray" + "type": "PublicKey" } ], "returntype": "Boolean", - "offset": 0, + "offset": 77, "safe": false }, { @@ -904,22 +853,34 @@ "type": "Integer" } ], - "returntype": "Boolean", - "offset": 0, + "returntype": "Void", + "offset": 84, + "safe": false + }, + { + "name": "setRegisterPrice", + "parameters": [ + { + "name": "registerPrice", + "type": "Integer" + } + ], + "returntype": "Void", + "offset": 91, "safe": false }, { "name": "symbol", "parameters": [], "returntype": "String", - "offset": 0, + "offset": 98, "safe": true }, { "name": "totalSupply", "parameters": [], "returntype": "Integer", - "offset": 0, + "offset": 105, "safe": true }, { @@ -943,7 +904,7 @@ } ], "returntype": "Boolean", - "offset": 0, + "offset": 112, "safe": false }, { @@ -959,7 +920,7 @@ } ], "returntype": "Integer", - "offset": 0, + "offset": 119, "safe": true }, { @@ -967,11 +928,11 @@ "parameters": [ { "name": "pubkey", - "type": "ByteArray" + "type": "PublicKey" } ], "returntype": "Boolean", - "offset": 0, + "offset": 126, "safe": false }, { @@ -983,11 +944,11 @@ }, { "name": "voteTo", - "type": "ByteArray" + "type": "PublicKey" } ], "returntype": "Boolean", - "offset": 0, + "offset": 133, "safe": false } ], @@ -1008,6 +969,709 @@ "type": "Integer" } ] + }, + { + "name": "CandidateStateChanged", + "parameters": [ + { + "name": "pubkey", + "type": "PublicKey" + }, + { + "name": "registered", + "type": "Boolean" + }, + { + "name": "votes", + "type": "Integer" + } + ] + }, + { + "name": "Vote", + "parameters": [ + { + "name": "account", + "type": "Hash160" + }, + { + "name": "from", + "type": "PublicKey" + }, + { + "name": "to", + "type": "PublicKey" + }, + { + "name": "amount", + "type": "Integer" + } + ] + }, + { + "name": "CommitteeChanged", + "parameters": [ + { + "name": "old", + "type": "Array" + }, + { + "name": "new", + "type": "Array" + } + ] + } + ] + }, + "permissions": [ + { + "contract": "*", + "methods": "*" + } + ], + "trusts": [], + "extra": null + } + } + } + }, + { + "Name": "getcontractstateasync", + "Request": { + "jsonrpc": "2.0", + "id": 1, + "method": "getcontractstate", + "params": [ -5 ] + }, + "Response": { + "jsonrpc": "2.0", + "id": 1, + "result": { + "id": -5, + "updatecounter": 1, + "hash": "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5", + "nef": { + "magic": 860243278, + "compiler": "neo-core-v3.0", + "source": "", + "tokens": [], + "script": "EEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0A=", + "checksum": 1325686241 + }, + "manifest": { + "name": "NeoToken", + "groups": [], + "features": {}, + "supportedstandards": [ + "NEP-17" + ], + "abi": { + "methods": [ + { + "name": "balanceOf", + "parameters": [ + { + "name": "account", + "type": "Hash160" + } + ], + "returntype": "Integer", + "offset": 0, + "safe": true + }, + { + "name": "decimals", + "parameters": [], + "returntype": "Integer", + "offset": 7, + "safe": true + }, + { + "name": "getAccountState", + "parameters": [ + { + "name": "account", + "type": "Hash160" + } + ], + "returntype": "Array", + "offset": 14, + "safe": true + }, + { + "name": "getAllCandidates", + "parameters": [], + "returntype": "InteropInterface", + "offset": 21, + "safe": true + }, + { + "name": "getCandidateVote", + "parameters": [ + { + "name": "pubKey", + "type": "PublicKey" + } + ], + "returntype": "Integer", + "offset": 28, + "safe": true + }, + { + "name": "getCandidates", + "parameters": [], + "returntype": "Array", + "offset": 35, + "safe": true + }, + { + "name": "getCommittee", + "parameters": [], + "returntype": "Array", + "offset": 42, + "safe": true + }, + { + "name": "getCommitteeAddress", + "parameters": [], + "returntype": "Hash160", + "offset": 49, + "safe": true + }, + { + "name": "getGasPerBlock", + "parameters": [], + "returntype": "Integer", + "offset": 56, + "safe": true + }, + { + "name": "getNextBlockValidators", + "parameters": [], + "returntype": "Array", + "offset": 63, + "safe": true + }, + { + "name": "getRegisterPrice", + "parameters": [], + "returntype": "Integer", + "offset": 70, + "safe": true + }, + { + "name": "registerCandidate", + "parameters": [ + { + "name": "pubkey", + "type": "PublicKey" + } + ], + "returntype": "Boolean", + "offset": 77, + "safe": false + }, + { + "name": "setGasPerBlock", + "parameters": [ + { + "name": "gasPerBlock", + "type": "Integer" + } + ], + "returntype": "Void", + "offset": 84, + "safe": false + }, + { + "name": "setRegisterPrice", + "parameters": [ + { + "name": "registerPrice", + "type": "Integer" + } + ], + "returntype": "Void", + "offset": 91, + "safe": false + }, + { + "name": "symbol", + "parameters": [], + "returntype": "String", + "offset": 98, + "safe": true + }, + { + "name": "totalSupply", + "parameters": [], + "returntype": "Integer", + "offset": 105, + "safe": true + }, + { + "name": "transfer", + "parameters": [ + { + "name": "from", + "type": "Hash160" + }, + { + "name": "to", + "type": "Hash160" + }, + { + "name": "amount", + "type": "Integer" + }, + { + "name": "data", + "type": "Any" + } + ], + "returntype": "Boolean", + "offset": 112, + "safe": false + }, + { + "name": "unclaimedGas", + "parameters": [ + { + "name": "account", + "type": "Hash160" + }, + { + "name": "end", + "type": "Integer" + } + ], + "returntype": "Integer", + "offset": 119, + "safe": true + }, + { + "name": "unregisterCandidate", + "parameters": [ + { + "name": "pubkey", + "type": "PublicKey" + } + ], + "returntype": "Boolean", + "offset": 126, + "safe": false + }, + { + "name": "vote", + "parameters": [ + { + "name": "account", + "type": "Hash160" + }, + { + "name": "voteTo", + "type": "PublicKey" + } + ], + "returntype": "Boolean", + "offset": 133, + "safe": false + } + ], + "events": [ + { + "name": "Transfer", + "parameters": [ + { + "name": "from", + "type": "Hash160" + }, + { + "name": "to", + "type": "Hash160" + }, + { + "name": "amount", + "type": "Integer" + } + ] + }, + { + "name": "CandidateStateChanged", + "parameters": [ + { + "name": "pubkey", + "type": "PublicKey" + }, + { + "name": "registered", + "type": "Boolean" + }, + { + "name": "votes", + "type": "Integer" + } + ] + }, + { + "name": "Vote", + "parameters": [ + { + "name": "account", + "type": "Hash160" + }, + { + "name": "from", + "type": "PublicKey" + }, + { + "name": "to", + "type": "PublicKey" + }, + { + "name": "amount", + "type": "Integer" + } + ] + }, + { + "name": "CommitteeChanged", + "parameters": [ + { + "name": "old", + "type": "Array" + }, + { + "name": "new", + "type": "Array" + } + ] + } + ] + }, + "permissions": [ + { + "contract": "*", + "methods": "*" + } + ], + "trusts": [], + "extra": null + } + } + } + }, + { + "Name": "getcontractstateasync", + "Request": { + "jsonrpc": "2.0", + "id": 1, + "method": "getcontractstate", + "params": [ "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5" ] + }, + "Response": { + "jsonrpc": "2.0", + "id": 1, + "result": { + "id": -5, + "updatecounter": 1, + "hash": "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5", + "nef": { + "magic": 860243278, + "compiler": "neo-core-v3.0", + "source": "", + "tokens": [], + "script": "EEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0A=", + "checksum": 1325686241 + }, + "manifest": { + "name": "NeoToken", + "groups": [], + "features": {}, + "supportedstandards": [ + "NEP-17" + ], + "abi": { + "methods": [ + { + "name": "balanceOf", + "parameters": [ + { + "name": "account", + "type": "Hash160" + } + ], + "returntype": "Integer", + "offset": 0, + "safe": true + }, + { + "name": "decimals", + "parameters": [], + "returntype": "Integer", + "offset": 7, + "safe": true + }, + { + "name": "getAccountState", + "parameters": [ + { + "name": "account", + "type": "Hash160" + } + ], + "returntype": "Array", + "offset": 14, + "safe": true + }, + { + "name": "getAllCandidates", + "parameters": [], + "returntype": "InteropInterface", + "offset": 21, + "safe": true + }, + { + "name": "getCandidateVote", + "parameters": [ + { + "name": "pubKey", + "type": "PublicKey" + } + ], + "returntype": "Integer", + "offset": 28, + "safe": true + }, + { + "name": "getCandidates", + "parameters": [], + "returntype": "Array", + "offset": 35, + "safe": true + }, + { + "name": "getCommittee", + "parameters": [], + "returntype": "Array", + "offset": 42, + "safe": true + }, + { + "name": "getCommitteeAddress", + "parameters": [], + "returntype": "Hash160", + "offset": 49, + "safe": true + }, + { + "name": "getGasPerBlock", + "parameters": [], + "returntype": "Integer", + "offset": 56, + "safe": true + }, + { + "name": "getNextBlockValidators", + "parameters": [], + "returntype": "Array", + "offset": 63, + "safe": true + }, + { + "name": "getRegisterPrice", + "parameters": [], + "returntype": "Integer", + "offset": 70, + "safe": true + }, + { + "name": "registerCandidate", + "parameters": [ + { + "name": "pubkey", + "type": "PublicKey" + } + ], + "returntype": "Boolean", + "offset": 77, + "safe": false + }, + { + "name": "setGasPerBlock", + "parameters": [ + { + "name": "gasPerBlock", + "type": "Integer" + } + ], + "returntype": "Void", + "offset": 84, + "safe": false + }, + { + "name": "setRegisterPrice", + "parameters": [ + { + "name": "registerPrice", + "type": "Integer" + } + ], + "returntype": "Void", + "offset": 91, + "safe": false + }, + { + "name": "symbol", + "parameters": [], + "returntype": "String", + "offset": 98, + "safe": true + }, + { + "name": "totalSupply", + "parameters": [], + "returntype": "Integer", + "offset": 105, + "safe": true + }, + { + "name": "transfer", + "parameters": [ + { + "name": "from", + "type": "Hash160" + }, + { + "name": "to", + "type": "Hash160" + }, + { + "name": "amount", + "type": "Integer" + }, + { + "name": "data", + "type": "Any" + } + ], + "returntype": "Boolean", + "offset": 112, + "safe": false + }, + { + "name": "unclaimedGas", + "parameters": [ + { + "name": "account", + "type": "Hash160" + }, + { + "name": "end", + "type": "Integer" + } + ], + "returntype": "Integer", + "offset": 119, + "safe": true + }, + { + "name": "unregisterCandidate", + "parameters": [ + { + "name": "pubkey", + "type": "PublicKey" + } + ], + "returntype": "Boolean", + "offset": 126, + "safe": false + }, + { + "name": "vote", + "parameters": [ + { + "name": "account", + "type": "Hash160" + }, + { + "name": "voteTo", + "type": "PublicKey" + } + ], + "returntype": "Boolean", + "offset": 133, + "safe": false + } + ], + "events": [ + { + "name": "Transfer", + "parameters": [ + { + "name": "from", + "type": "Hash160" + }, + { + "name": "to", + "type": "Hash160" + }, + { + "name": "amount", + "type": "Integer" + } + ] + }, + { + "name": "CandidateStateChanged", + "parameters": [ + { + "name": "pubkey", + "type": "PublicKey" + }, + { + "name": "registered", + "type": "Boolean" + }, + { + "name": "votes", + "type": "Integer" + } + ] + }, + { + "name": "Vote", + "parameters": [ + { + "name": "account", + "type": "Hash160" + }, + { + "name": "from", + "type": "PublicKey" + }, + { + "name": "to", + "type": "PublicKey" + }, + { + "name": "amount", + "type": "Integer" + } + ] + }, + { + "name": "CommitteeChanged", + "parameters": [ + { + "name": "old", + "type": "Array" + }, + { + "name": "new", + "type": "Array" + } + ] } ] }, diff --git a/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs b/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs index 4af0f557e3..b87960e76d 100644 --- a/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs +++ b/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs @@ -220,8 +220,17 @@ public async Task TestGetContractState() var tests = TestUtils.RpcTestCases.Where(p => p.Name == nameof(rpc.GetContractStateAsync).ToLower()); foreach (var test in tests) { - var result = await rpc.GetContractStateAsync(test.Request.Params[0].AsString()); - Assert.AreEqual(test.Response.Result.ToString(), result.ToJson().ToString()); + var type = test.Request.Params[0].GetType().Name; + if (type == "JString") + { + var result = await rpc.GetContractStateAsync(test.Request.Params[0].AsString()); + Assert.AreEqual(test.Response.Result.ToString(), result.ToJson().ToString()); + } + if (type == "JNumber") + { + var result = await rpc.GetContractStateAsync((int)test.Request.Params[0].AsNumber()); + Assert.AreEqual(test.Response.Result.ToString(), result.ToJson().ToString()); + } } } diff --git a/tests/Neo.Network.RPC.Tests/UT_Utility.cs b/tests/Neo.Network.RPC.Tests/UT_Utility.cs index 53e381b836..3c30069219 100644 --- a/tests/Neo.Network.RPC.Tests/UT_Utility.cs +++ b/tests/Neo.Network.RPC.Tests/UT_Utility.cs @@ -9,12 +9,16 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. +using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Extensions; +using Neo.Network.P2P.Payloads; using Neo.SmartContract; +using Neo.SmartContract.Native; using Neo.Wallets; using System; using System.Numerics; +using System.Security.Cryptography; namespace Neo.Network.RPC.Tests { @@ -33,6 +37,16 @@ public void TestSetup() protocolSettings = ProtocolSettings.Load("protocol.json"); } + [TestMethod] + public void TestAsScriptHash() + { + var scriptHash1 = Utility.AsScriptHash(NativeContract.NEO.Id.ToString()); + var scriptHash2 = Utility.AsScriptHash(NativeContract.NEO.Hash.ToString()); + var scriptHash3 = Utility.AsScriptHash(NativeContract.NEO.Name); + scriptHash2.Should().Be(scriptHash1); + scriptHash3.Should().Be(scriptHash1); + } + [TestMethod] public void TestGetKeyPair() { @@ -46,6 +60,13 @@ public void TestGetKeyPair() string privateKey = keyPair.PrivateKey.ToHexString(); result = Utility.GetKeyPair(privateKey); Assert.AreEqual(keyPair, result); + + string hexWith0x = $"0x{result.PrivateKey.ToHexString()}"; + result = Utility.GetKeyPair(hexWith0x); + Assert.AreEqual(keyPair, result); + + var action = () => { Utility.GetKeyPair("00"); }; + action.Should().Throw(); } [TestMethod] @@ -65,6 +86,124 @@ public void TestGetScriptHash() string publicKey = keyPair.PublicKey.ToString(); result = Utility.GetScriptHash(publicKey, protocolSettings); Assert.AreEqual(scriptHash, result); + + var action = () => { Utility.GetScriptHash("00", protocolSettings); }; + action.Should().Throw(); + } + + [TestMethod] + public void TestTransactionAttribute() + { + var attribute = new Conflicts(); + attribute.Hash = UInt256.Zero; + var json = attribute.ToJson(); + var result = Utility.TransactionAttributeFromJson(json).ToJson(); + result.ToString().Should().Be(json.ToString()); + + var attribute2 = new OracleResponse(); + attribute2.Id = 1234; + attribute2.Code = 0; + attribute2.Result = new ReadOnlyMemory { }; + json = attribute2.ToJson(); + result = Utility.TransactionAttributeFromJson(json).ToJson(); + result.ToString().Should().Be(json.ToString()); + + var attribute3 = new NotValidBefore(); + attribute3.Height = 10000; + json = attribute3.ToJson(); + result = Utility.TransactionAttributeFromJson(json).ToJson(); + result.ToString().Should().Be(json.ToString()); + + var attribute4 = new HighPriorityAttribute(); + json = attribute4.ToJson(); + result = Utility.TransactionAttributeFromJson(json).ToJson(); + result.ToString().Should().Be(json.ToString()); + } + + [TestMethod] + public void TestWitnessRule() + { + var rule = new WitnessRule(); + rule.Action = WitnessRuleAction.Allow; + rule.Condition = new Neo.Network.P2P.Payloads.Conditions.CalledByEntryCondition(); + var json = rule.ToJson(); + var result = Utility.RuleFromJson(json, ProtocolSettings.Default).ToJson(); + result.ToString().Should().Be(json.ToString()); + + rule.Condition = new Neo.Network.P2P.Payloads.Conditions.OrCondition() + { + Expressions = new P2P.Payloads.Conditions.WitnessCondition[] + { + new Neo.Network.P2P.Payloads.Conditions.BooleanCondition() + { + Expression = true + }, + new Neo.Network.P2P.Payloads.Conditions.BooleanCondition() + { + Expression = false + } + } + }; + json = rule.ToJson(); + result = Utility.RuleFromJson(json, ProtocolSettings.Default).ToJson(); + result.ToString().Should().Be(json.ToString()); + + rule.Condition = new Neo.Network.P2P.Payloads.Conditions.AndCondition() + { + Expressions = new P2P.Payloads.Conditions.WitnessCondition[] + { + new Neo.Network.P2P.Payloads.Conditions.BooleanCondition() + { + Expression = true + }, + new Neo.Network.P2P.Payloads.Conditions.BooleanCondition() + { + Expression = false + } + } + }; + json = rule.ToJson(); + result = Utility.RuleFromJson(json, ProtocolSettings.Default).ToJson(); + result.ToString().Should().Be(json.ToString()); + + rule.Condition = new Neo.Network.P2P.Payloads.Conditions.BooleanCondition() { Expression = true }; + json = rule.ToJson(); + result = Utility.RuleFromJson(json, ProtocolSettings.Default).ToJson(); + result.ToString().Should().Be(json.ToString()); + + rule.Condition = new Neo.Network.P2P.Payloads.Conditions.NotCondition() + { + Expression = new Neo.Network.P2P.Payloads.Conditions.BooleanCondition() + { + Expression = true + } + }; + json = rule.ToJson(); + result = Utility.RuleFromJson(json, ProtocolSettings.Default).ToJson(); + result.ToString().Should().Be(json.ToString()); + + var kp = Utility.GetKeyPair("KyXwTh1hB76RRMquSvnxZrJzQx7h9nQP2PCRL38v6VDb5ip3nf1p"); + rule.Condition = new Neo.Network.P2P.Payloads.Conditions.GroupCondition() { Group = kp.PublicKey }; + json = rule.ToJson(); + result = Utility.RuleFromJson(json, ProtocolSettings.Default).ToJson(); + result.ToString().Should().Be(json.ToString()); + + rule.Condition = new Neo.Network.P2P.Payloads.Conditions.CalledByContractCondition() { Hash = UInt160.Zero }; + json = rule.ToJson(); + result = Utility.RuleFromJson(json, ProtocolSettings.Default).ToJson(); + result.ToString().Should().Be(json.ToString()); + + rule.Condition = new Neo.Network.P2P.Payloads.Conditions.ScriptHashCondition() { Hash = UInt160.Zero }; + json = rule.ToJson(); + result = Utility.RuleFromJson(json, ProtocolSettings.Default).ToJson(); + result.ToString().Should().Be(json.ToString()); + result.ToString().Should().Be(json.ToString()); + + rule.Condition = new Neo.Network.P2P.Payloads.Conditions.CalledByGroupCondition() { Group = kp.PublicKey }; + json = rule.ToJson(); + result = Utility.RuleFromJson(json, ProtocolSettings.Default).ToJson(); + result.ToString().Should().Be(json.ToString()); + result.ToString().Should().Be(json.ToString()); } [TestMethod]