-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync update with neo pull 2119 (#402)
* Upgrade target framework. * Revert "Upgrade target framework." This reverts commit 6b0c49c. * Safe Attribute * Update Contract1.cs (#398) * Revert "publish neon to myget/github packages" (#395) * Remove Contract.Create、Contract.Update、Contract.Destroy; Add Contract.CallNative. * Update * remove CallNative * Update templates/Template.CSharp/Contract1.cs Co-authored-by: Owen Zhang <[email protected]> * Update templates/Template.CSharp/Contract1.cs Co-authored-by: Owen Zhang <[email protected]> * Update tests/Neo.SmartContract.Framework.UnitTests/TestClasses/Contract_CreateAndUpdate.cs Co-authored-by: Owen Zhang <[email protected]> * public * Update * Update call * Fix more UT * Update hashes * Mock contract create * Fix more UT * Fix UT * More fixes * More fixes * More UT * Fix UT's * dotnet-format * Fix Last test * Update * Remove private properties * Fixed UT * disable warning CS0626 Co-authored-by: Shargon <[email protected]> Co-authored-by: Owen Zhang <[email protected]> Co-authored-by: Erik Zhang <[email protected]>
- Loading branch information
1 parent
b83ec54
commit fac2847
Showing
38 changed files
with
243 additions
and
122 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
|
||
namespace Neo.SmartContract.Framework | ||
{ | ||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] | ||
public class SafeAttribute : Attribute | ||
{ | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
src/Neo.SmartContract.Framework/Services/Neo/ManagementContract.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,15 @@ | ||
#pragma warning disable CS0626 | ||
|
||
namespace Neo.SmartContract.Framework.Services.Neo | ||
{ | ||
[Contract("0xcd97b70d82d69adfcd9165374109419fade8d6ab")] | ||
public class ManagementContract | ||
{ | ||
public static extern UInt160 Hash { [ContractHash] get; } | ||
public static extern string Name { get; } | ||
public static extern Contract GetContract(UInt160 hash); | ||
public static extern Contract Deploy(byte[] nefFile, string manifest); | ||
public static extern void Update(byte[] nefFile, string manifest); | ||
public static extern void Destroy(); | ||
} | ||
} |
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
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
33 changes: 33 additions & 0 deletions
33
tests/Neo.Compiler.MSIL.UnitTests/Extensions/TestExtensions.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,33 @@ | ||
using Neo.Compiler.MSIL.UnitTests.Utils; | ||
using Neo.Ledger; | ||
using Neo.Network.P2P.Payloads; | ||
using Neo.Persistence; | ||
using Neo.SmartContract; | ||
|
||
namespace Neo.Compiler.MSIL.Extensions | ||
{ | ||
public static class TestExtensions | ||
{ | ||
public static void ContractAdd(this StoreView snapshot, ContractState contract) | ||
{ | ||
var key = new KeyBuilder(0, 8).Add(contract.Hash); | ||
snapshot.Storages.Add(key, new StorageItem(contract)); | ||
} | ||
|
||
public static void DeployNativeContracts(this StoreView snapshot) | ||
{ | ||
var method = typeof(SmartContract.Native.ManagementContract).GetMethod("OnPersist", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); | ||
var engine = new TestEngine(TriggerType.OnPersist, null, snapshot); | ||
method.Invoke(SmartContract.Native.NativeContract.Management, new object[] { engine }); | ||
} | ||
|
||
/// <summary> | ||
/// Set Persisting block for unit test | ||
/// </summary> | ||
/// <param name="block">Block</param> | ||
public static void SetPersistingBlock(this StoreView snapshot, Block block) | ||
{ | ||
snapshot.GetType().GetProperty("PersistingBlock").SetValue(snapshot, block); | ||
} | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_ABISafe.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,25 @@ | ||
using Neo.SmartContract.Framework; | ||
|
||
namespace Neo.Compiler.MSIL.UnitTests.TestClasses | ||
{ | ||
public class Contract_ABISafe : SmartContract.Framework.SmartContract | ||
{ | ||
static int s = 1; | ||
|
||
public static int UnitTest_001() | ||
{ | ||
return 1; | ||
} | ||
|
||
[Safe] | ||
public static int UnitTest_002() | ||
{ | ||
return 2; | ||
} | ||
|
||
public static int UnitTest_003() | ||
{ | ||
return 3; | ||
} | ||
} | ||
} |
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,22 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Compiler.MSIL.UnitTests.Utils; | ||
using Neo.IO.Json; | ||
|
||
namespace Neo.Compiler.MSIL.UnitTests | ||
{ | ||
[TestClass] | ||
public class UnitTest_ABI_Safe | ||
{ | ||
[TestMethod] | ||
public void UnitTest_TestSafe() | ||
{ | ||
var buildScript = NeonTestTool.BuildScript("./TestClasses/Contract_ABISafe.cs", true, false); | ||
var abi = buildScript.finalABI; | ||
|
||
var methodsABI = abi["methods"] as JArray; | ||
Assert.IsFalse(methodsABI[1]["safe"].AsBoolean()); | ||
Assert.IsTrue(methodsABI[2]["safe"].AsBoolean()); | ||
Assert.IsFalse(methodsABI[3]["safe"].AsBoolean()); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.