forked from neo-project/neo-devpack-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from simplitech/Boa-263
Boa 263 - Include CheckWitness in the TestEngine
- Loading branch information
Showing
6 changed files
with
179 additions
and
11 deletions.
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
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
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
13 changes: 13 additions & 0 deletions
13
tests/TestEngine.UnitTests/TestClasses/Contract_CheckWitness.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,13 @@ | ||
using Neo; | ||
using Neo.SmartContract.Framework.Services.Neo; | ||
|
||
namespace Neo.Compiler.MSIL.UnitTests.TestClasses | ||
{ | ||
public class Contract_CheckWitness : SmartContract.Framework.SmartContract | ||
{ | ||
public static bool testWitness(UInt160 signature) | ||
{ | ||
return Runtime.CheckWitness(signature); | ||
} | ||
} | ||
} |
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
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,109 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo; | ||
using Neo.IO.Json; | ||
using Neo.SmartContract; | ||
using Neo.TestingEngine; | ||
using Neo.VM; | ||
using Neo.VM.Types; | ||
using Neo.Wallets; | ||
using System.IO; | ||
using Compiler = Neo.Compiler.Program; | ||
|
||
namespace TestEngine.UnitTests | ||
{ | ||
[TestClass] | ||
public class UnitTest_CheckWitness | ||
{ | ||
[TestInitialize] | ||
public void Init() | ||
{ | ||
string path = Directory.GetCurrentDirectory(); | ||
var option = new Compiler.Options() | ||
{ | ||
File = path + "/TestClasses/Contract_CheckWitness.cs" | ||
}; | ||
Compiler.Compile(option); | ||
|
||
//Compile changes the path, reseting so that other UT won't break | ||
Directory.SetCurrentDirectory(path); | ||
Engine.Instance.Reset(); | ||
} | ||
|
||
[TestMethod] | ||
public void Test_Check_Witness() | ||
{ | ||
var scripthash = "NiNmXL8FjEUEs1nfX9uHFBNaenxDHJtmuB".ToScriptHash(); | ||
var param = new ContractParameter(ContractParameterType.Hash160) | ||
{ | ||
Value = scripthash.ToString().Substring(2) | ||
}; | ||
|
||
var json = new JObject(); | ||
json["path"] = "./TestClasses/Contract_CheckWitness.nef"; | ||
json["method"] = "testWitness"; | ||
json["arguments"] = new JArray() { param.ToJson() }; | ||
|
||
var args = new string[] { | ||
json.AsString() | ||
}; | ||
var result = Program.Run(args); | ||
|
||
// mustn't have an error | ||
Assert.IsTrue(result.ContainsProperty("error")); | ||
Assert.IsNull(result["error"]); | ||
|
||
// vm state must've faulted | ||
Assert.IsTrue(result.ContainsProperty("vm_state")); | ||
Assert.AreEqual(result["vm_state"].AsString(), VMState.HALT.ToString()); | ||
|
||
// result stack must be empty | ||
StackItem wantresult = false; | ||
Assert.IsTrue(result.ContainsProperty("result_stack")); | ||
Assert.IsInstanceOfType(result["result_stack"], typeof(JArray)); | ||
|
||
var resultStack = result["result_stack"] as JArray; | ||
Assert.IsTrue(resultStack.Count == 1); | ||
Assert.IsTrue(resultStack[0].ContainsProperty("value")); | ||
Assert.AreEqual(resultStack[0]["value"].AsString(), wantresult.ToJson()["value"].AsString()); | ||
} | ||
|
||
[TestMethod] | ||
public void Test_Check_Witness_With_Sign() | ||
{ | ||
var scripthash = "NiNmXL8FjEUEs1nfX9uHFBNaenxDHJtmuB".ToScriptHash(); | ||
var param = new ContractParameter(ContractParameterType.Hash160) | ||
{ | ||
Value = scripthash.ToString().Substring(2) | ||
}; | ||
|
||
var json = new JObject(); | ||
json["path"] = "./TestClasses/Contract_CheckWitness.nef"; | ||
json["method"] = "testWitness"; | ||
json["arguments"] = new JArray() { param.ToJson() }; | ||
json["signerAccounts"] = new JArray() { scripthash.ToString() }; | ||
|
||
var args = new string[] { | ||
json.AsString() | ||
}; | ||
var result = Program.Run(args); | ||
|
||
// mustn't have an error | ||
Assert.IsTrue(result.ContainsProperty("error")); | ||
Assert.IsNull(result["error"]); | ||
|
||
// vm state must've faulted | ||
Assert.IsTrue(result.ContainsProperty("vm_state")); | ||
Assert.AreEqual(result["vm_state"].AsString(), VMState.HALT.ToString()); | ||
|
||
// result stack must be empty | ||
StackItem wantresult = true; | ||
Assert.IsTrue(result.ContainsProperty("result_stack")); | ||
Assert.IsInstanceOfType(result["result_stack"], typeof(JArray)); | ||
|
||
var resultStack = result["result_stack"] as JArray; | ||
Assert.IsTrue(resultStack.Count == 1); | ||
Assert.IsTrue(resultStack[0].ContainsProperty("value")); | ||
Assert.AreEqual(resultStack[0]["value"].AsString(), wantresult.ToJson()["value"].AsString()); | ||
} | ||
} | ||
} |