forked from neo-project/neo
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from neo-project/master
update
- Loading branch information
Showing
72 changed files
with
2,529 additions
and
1,084 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Cryptography.ECC; | ||
using Neo.SmartContract.Manifest; | ||
|
||
namespace Neo.UnitTests | ||
{ | ||
[TestClass] | ||
public class UT_ContractManifest | ||
{ | ||
[TestMethod] | ||
public void ParseFromJson_Default() | ||
{ | ||
var json = @"{""groups"":[],""features"":{""storage"":false,""payable"":false},""abi"":{""hash"":""0x0000000000000000000000000000000000000000"",""entryPoint"":{""name"":""Main"",""parameters"":[{""name"":""operation"",""type"":""String""},{""name"":""args"",""type"":""Array""}],""returnType"":""Any""},""methods"":[],""events"":[]},""permissions"":[{""contract"":""*"",""methods"":""*""}],""trusts"":[],""safeMethods"":[]}"; | ||
var manifest = ContractManifest.Parse(json); | ||
|
||
Assert.AreEqual(manifest.ToString(), json); | ||
Assert.AreEqual(manifest.ToString(), ContractManifest.CreateDefault(UInt160.Zero).ToString()); | ||
Assert.IsTrue(manifest.IsValid(UInt160.Zero)); | ||
} | ||
|
||
[TestMethod] | ||
public void ParseFromJson_Features() | ||
{ | ||
var json = @"{""groups"":[],""features"":{""storage"":true,""payable"":true},""abi"":{""hash"":""0x0000000000000000000000000000000000000000"",""entryPoint"":{""name"":""Main"",""parameters"":[{""name"":""operation"",""type"":""String""},{""name"":""args"",""type"":""Array""}],""returnType"":""Any""},""methods"":[],""events"":[]},""permissions"":[{""contract"":""*"",""methods"":""*""}],""trusts"":[],""safeMethods"":[]}"; | ||
var manifest = ContractManifest.Parse(json); | ||
Assert.AreEqual(manifest.ToJson().ToString(), json); | ||
|
||
var check = ContractManifest.CreateDefault(UInt160.Zero); | ||
check.Features = ContractFeatures.HasStorage | ContractFeatures.Payable; | ||
Assert.AreEqual(manifest.ToString(), check.ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void ParseFromJson_Permissions() | ||
{ | ||
var json = @"{""groups"":[],""features"":{""storage"":false,""payable"":false},""abi"":{""hash"":""0x0000000000000000000000000000000000000000"",""entryPoint"":{""name"":""Main"",""parameters"":[{""name"":""operation"",""type"":""String""},{""name"":""args"",""type"":""Array""}],""returnType"":""Any""},""methods"":[],""events"":[]},""permissions"":[{""contract"":""0x0000000000000000000000000000000000000000"",""methods"":[""method1"",""method2""]}],""trusts"":[],""safeMethods"":[]}"; | ||
var manifest = ContractManifest.Parse(json); | ||
Assert.AreEqual(manifest.ToString(), json); | ||
|
||
var check = ContractManifest.CreateDefault(UInt160.Zero); | ||
check.Permissions = new[] | ||
{ | ||
new ContractPermission() | ||
{ | ||
Contract = ContractPermissionDescriptor.Create(UInt160.Zero), | ||
Methods = WildCardContainer<string>.Create("method1", "method2") | ||
} | ||
}; | ||
Assert.AreEqual(manifest.ToString(), check.ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void ParseFromJson_SafeMethods() | ||
{ | ||
var json = @"{""groups"":[],""features"":{""storage"":false,""payable"":false},""abi"":{""hash"":""0x0000000000000000000000000000000000000000"",""entryPoint"":{""name"":""Main"",""parameters"":[{""name"":""operation"",""type"":""String""},{""name"":""args"",""type"":""Array""}],""returnType"":""Any""},""methods"":[],""events"":[]},""permissions"":[{""contract"":""*"",""methods"":""*""}],""trusts"":[],""safeMethods"":[""balanceOf""]}"; | ||
var manifest = ContractManifest.Parse(json); | ||
Assert.AreEqual(manifest.ToString(), json); | ||
|
||
var check = ContractManifest.CreateDefault(UInt160.Zero); | ||
check.SafeMethods = WildCardContainer<string>.Create("balanceOf"); | ||
Assert.AreEqual(manifest.ToString(), check.ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void ParseFromJson_Trust() | ||
{ | ||
var json = @"{""groups"":[],""features"":{""storage"":false,""payable"":false},""abi"":{""hash"":""0x0000000000000000000000000000000000000000"",""entryPoint"":{""name"":""Main"",""parameters"":[{""name"":""operation"",""type"":""String""},{""name"":""args"",""type"":""Array""}],""returnType"":""Any""},""methods"":[],""events"":[]},""permissions"":[{""contract"":""*"",""methods"":""*""}],""trusts"":[""0x0000000000000000000000000000000000000001""],""safeMethods"":[]}"; | ||
var manifest = ContractManifest.Parse(json); | ||
Assert.AreEqual(manifest.ToString(), json); | ||
|
||
var check = ContractManifest.CreateDefault(UInt160.Zero); | ||
check.Trusts = WildCardContainer<UInt160>.Create(UInt160.Parse("0x0000000000000000000000000000000000000001")); | ||
Assert.AreEqual(manifest.ToString(), check.ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void ParseFromJson_Groups() | ||
{ | ||
var json = @"{""groups"":[{""pubKey"":""03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c"",""signature"":""41414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141""}],""features"":{""storage"":false,""payable"":false},""abi"":{""hash"":""0x0000000000000000000000000000000000000000"",""entryPoint"":{""name"":""Main"",""parameters"":[{""name"":""operation"",""type"":""String""},{""name"":""args"",""type"":""Array""}],""returnType"":""Any""},""methods"":[],""events"":[]},""permissions"":[{""contract"":""*"",""methods"":""*""}],""trusts"":[],""safeMethods"":[]}"; | ||
var manifest = ContractManifest.Parse(json); | ||
Assert.AreEqual(manifest.ToString(), json); | ||
|
||
var check = ContractManifest.CreateDefault(UInt160.Zero); | ||
check.Groups = new ContractGroup[] { new ContractGroup() { PubKey = ECPoint.Parse("03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c", ECCurve.Secp256r1), Signature = "41414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141".HexToBytes() } }; | ||
Assert.AreEqual(manifest.ToString(), check.ToString()); | ||
} | ||
} | ||
} |
Oops, something went wrong.