-
Notifications
You must be signed in to change notification settings - Fork 1k
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
test RpcServer.Utilities, .SmartContract and .Wallet #3461
Changes from 4 commits
dcf3e32
3c51bd4
07e506d
14d409a
c3f7f4b
e975765
851b4b4
54ae25f
eefa8c9
b53a686
c0b9892
50df712
ac8992e
60527f4
87dbe59
0295089
b8a28fb
4683943
a7197cb
bbb783d
b00a83e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// UT_RpcServer.Wallet.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.IO; | ||
using Neo.Json; | ||
using Neo.Network.P2P.Payloads; | ||
using Neo.SmartContract; | ||
using Neo.SmartContract.Native; | ||
using Neo.UnitTests; | ||
using Neo.UnitTests.Extensions; | ||
using Neo.Wallets; | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace Neo.Plugins.RpcServer.Tests; | ||
|
||
public partial class UT_RpcServer | ||
{ | ||
static readonly string neoScriptHash = "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5"; | ||
static readonly string NeoTotalSupplyScript = "wh8MC3RvdGFsU3VwcGx5DBT1Y\u002BpAvCg9TQ4FxI6jBbPyoHNA70FifVtS"; | ||
static readonly JArray signers = [new JObject() | ||
{ | ||
["account"] = "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5", | ||
["scopes"] = "CalledByEntry", | ||
}]; | ||
|
||
[TestMethod] | ||
public void TestInvokeFunction() | ||
{ | ||
JObject resp = (JObject)_rpcServer.InvokeFunction(new JArray(neoScriptHash, "totalSupply", new JArray([]), signers, true)); | ||
Assert.AreEqual(resp.Count, 7); | ||
Assert.AreEqual(resp["script"], NeoTotalSupplyScript); | ||
Assert.IsTrue(resp.ContainsProperty("gasconsumed")); | ||
Assert.IsTrue(resp.ContainsProperty("diagnostics")); | ||
Assert.AreEqual(resp["diagnostics"]["invokedcontracts"]["call"][0]["hash"], neoScriptHash); | ||
Assert.AreEqual(resp["state"], "HALT"); | ||
Assert.AreEqual(resp["exception"], null); | ||
Assert.AreEqual(((JArray)resp["notifications"]).Count, 0); | ||
Assert.AreEqual(resp["stack"][0]["type"], "Integer"); | ||
Assert.AreEqual(resp["stack"][0]["value"], "100000000"); | ||
} | ||
|
||
[TestMethod] | ||
public void TestInvokeScript() | ||
{ | ||
JObject resp = (JObject)_rpcServer.InvokeScript(new JArray(NeoTotalSupplyScript, signers, true)); | ||
Assert.AreEqual(resp.Count, 7); | ||
Assert.IsTrue(resp.ContainsProperty("gasconsumed")); | ||
Assert.IsTrue(resp.ContainsProperty("diagnostics")); | ||
Assert.AreEqual(resp["diagnostics"]["invokedcontracts"]["call"][0]["hash"], neoScriptHash); | ||
Assert.AreEqual(resp["state"], "HALT"); | ||
Assert.AreEqual(resp["exception"], null); | ||
Assert.AreEqual(((JArray)resp["notifications"]).Count, 0); | ||
Assert.AreEqual(resp["stack"][0]["type"], "Integer"); | ||
Assert.AreEqual(resp["stack"][0]["value"], "100000000"); | ||
} | ||
|
||
[TestMethod] | ||
public void TestTraverseIterator() | ||
{ | ||
JObject resp = (JObject)_rpcServer.InvokeFunction(new JArray(neoScriptHash, "getAllCandidates", new JArray([]), signers, true)); | ||
string sessionId = resp["session"].AsString(); | ||
string iteratorId = resp["stack"][0]["id"].AsString(); | ||
JArray respArray = (JArray)_rpcServer.TraverseIterator([sessionId, iteratorId, 100]); | ||
Assert.AreEqual(respArray.Count, 0); | ||
_rpcServer.TerminateSession([sessionId]); | ||
try | ||
{ | ||
respArray = (JArray)_rpcServer.TraverseIterator([sessionId, iteratorId, 100]); | ||
} | ||
catch (RpcException e) | ||
{ | ||
Assert.AreEqual(e.Message, "Unknown session"); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void TestGetUnclaimedGas() | ||
{ | ||
string address = Contract | ||
.CreateSignatureRedeemScript(TestProtocolSettings.SoleNode.StandbyCommittee[0]) | ||
.ToScriptHash().ToAddress(ProtocolSettings.Default.AddressVersion); | ||
JObject resp = (JObject)_rpcServer.GetUnclaimedGas([address]); | ||
Assert.AreEqual(resp["unclaimed"], "0"); | ||
Assert.AreEqual(resp["address"], address); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// UT_RpcServer.Wallet.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.IO; | ||
using Neo.Json; | ||
using Neo.Network.P2P.Payloads; | ||
using Neo.SmartContract; | ||
using Neo.SmartContract.Native; | ||
using Neo.UnitTests; | ||
using Neo.UnitTests.Extensions; | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace Neo.Plugins.RpcServer.Tests; | ||
|
||
public partial class UT_RpcServer | ||
{ | ||
[TestMethod] | ||
public void TestListPlugins() | ||
{ | ||
JArray resp = (JArray)_rpcServer.ListPlugins([]); | ||
Assert.AreEqual(resp.Count, 0); | ||
Plugins.Plugin.Plugins.Add(new RpcServerPlugin()); | ||
resp = (JArray)_rpcServer.ListPlugins([]); | ||
Assert.AreEqual(resp.Count, 2); | ||
foreach (JObject p in resp) | ||
Assert.AreEqual(p["name"], "RpcServer"); | ||
} | ||
|
||
[TestMethod] | ||
public void TestValidateAddress() | ||
{ | ||
string validAddr = "NM7Aky765FG8NhhwtxjXRx7jEL1cnw7PBP"; | ||
JObject resp = (JObject)_rpcServer.ValidateAddress([validAddr]); | ||
Assert.AreEqual(resp["address"], validAddr); | ||
Assert.AreEqual(resp["isvalid"], true); | ||
string invalidAddr = "ANeo2toNeo3MigrationAddressxwPB2Hz"; | ||
resp = (JObject)_rpcServer.ValidateAddress([invalidAddr]); | ||
Assert.AreEqual(resp["address"], invalidAddr); | ||
Assert.AreEqual(resp["isvalid"], false); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
using Neo.Wallets; | ||
using Neo.Wallets.NEP6; | ||
using System; | ||
using System.Net; | ||
using System.Text; | ||
|
||
namespace Neo.Plugins.RpcServer.Tests | ||
|
@@ -39,7 +40,28 @@ public void TestSetup() | |
_memoryStore = new MemoryStore(); | ||
_memoryStoreProvider = new TestMemoryStoreProvider(_memoryStore); | ||
_neoSystem = new NeoSystem(TestProtocolSettings.SoleNode, _memoryStoreProvider); | ||
_rpcServer = new RpcServer(_neoSystem, RpcServerSettings.Default); | ||
_rpcServer = new RpcServer(_neoSystem, new RpcServerSettings | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why change this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need RpcServer session enabled to traverse iterator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this can work. _rpcServer = new RpcServer(_neoSystem, RpcServerSettings.Default with { SessionEnabled = true }); |
||
{ | ||
Network = 5195086u, | ||
BindAddress = IPAddress.None, | ||
SslCert = string.Empty, | ||
SslCertPassword = string.Empty, | ||
MaxGasInvoke = (long)new BigDecimal(10M, NativeContract.GAS.Decimals).Value, | ||
MaxFee = (long)new BigDecimal(0.1M, NativeContract.GAS.Decimals).Value, | ||
TrustedAuthorities = Array.Empty<string>(), | ||
EnableCors = true, | ||
AllowOrigins = Array.Empty<string>(), | ||
KeepAliveTimeout = 60, | ||
RequestHeadersTimeout = 15, | ||
MaxIteratorResultItems = 100, | ||
MaxStackSize = ushort.MaxValue, | ||
DisabledMethods = Array.Empty<string>(), | ||
MaxConcurrentConnections = 40, | ||
MaxRequestBodySize = 5 * 1024 * 1024, | ||
SessionEnabled = true, | ||
SessionExpirationTime = TimeSpan.FromSeconds(60), | ||
FindStoragePageSize = 50 | ||
}); | ||
_walletAccount = _wallet.Import("KxuRSsHgJMb3AMSN6B9P3JHNGMFtxmuimqgR9MmXPcv3CLLfusTd"); | ||
var key = new KeyBuilder(NativeContract.GAS.Id, 20).Add(_walletAccount.ScriptHash); | ||
var snapshot = _neoSystem.GetSnapshotCache(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we do abnormal test with tons of signers, tons of opened sessions, invalid address