-
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
dcf3e32
test RpcServer.Utilities
Hecate2 3c51bd4
test invoke function and script
Hecate2 07e506d
TestTraverseIterator
Hecate2 14d409a
TestGetUnclaimedGas
Hecate2 c3f7f4b
RpcServerSettings.Default with { SessionEnabled = true }
Hecate2 e975765
test call with storage changes and events
Hecate2 851b4b4
use wallet in invokefunction
Hecate2 54ae25f
use invalid wallet
Hecate2 eefa8c9
invoke without signer
Hecate2 b53a686
all cases for TraverseIterator
Hecate2 c0b9892
traversing same session twice; not expired session
Hecate2 50df712
cover OnTimer
Hecate2 ac8992e
test deserializing complex signers
Hecate2 60527f4
use Assert.ThrowsException
Hecate2 87dbe59
TestSendFrom and TestSendMany
Hecate2 0295089
apply code review with `nameof`
Hecate2 b8a28fb
test cancel transaction
Hecate2 4683943
TestInvokeContractVerify
Hecate2 a7197cb
improve error message
Hecate2 bbb783d
Merge branch 'master' into rpcserver-tests
shargon b00a83e
Merge branch 'master' into rpcserver-tests
NGDAdmin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.SmartContract.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Utilities.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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