-
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.
Add ContractCall and UTs, delete Appcall (#327)
* add ConTractCall and UTs, delete Appcall * fix * Disable warnings * spilt and fix * del ID * fix Neo and Policy, Add UT * del blank line * fix internal Co-authored-by: erikzhang <[email protected]> Co-authored-by: Shargon <[email protected]>
- Loading branch information
1 parent
ea65ad0
commit 742945c
Showing
16 changed files
with
334 additions
and
120 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 was deleted.
Oops, something went wrong.
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 System; | ||
using System.Globalization; | ||
|
||
namespace Neo.SmartContract.Framework | ||
{ | ||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] | ||
public class ContractAttribute : Attribute | ||
{ | ||
public byte[] Hash { get; } | ||
|
||
public ContractAttribute(byte[] hash) | ||
{ | ||
if (hash == null) throw new ArgumentNullException(); | ||
if (hash.Length != 20) throw new ArgumentException(); | ||
Hash = hash; | ||
} | ||
|
||
public ContractAttribute(string hash) | ||
{ | ||
if (hash == null) throw new ArgumentNullException(); | ||
|
||
if (hash.StartsWith("0x")) | ||
{ | ||
hash = hash.Remove(0, 2); | ||
} | ||
|
||
if (hash.Length != 40) throw new ArgumentException(); | ||
Hash = new byte[hash.Length / 2]; | ||
for (int i = 0; i < Hash.Length; i++) | ||
Hash[i] = byte.Parse(hash.Substring(i * 2, 2), NumberStyles.AllowHexSpecifier); | ||
} | ||
} | ||
} |
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,16 @@ | ||
#pragma warning disable CS0626 | ||
|
||
using System.Numerics; | ||
|
||
namespace Neo.SmartContract.Framework.Services.Neo | ||
{ | ||
[Contract("0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc")] | ||
public class GAS | ||
{ | ||
public static extern string Name(); | ||
public static extern string Symbol(); | ||
public static extern byte Decimals(); | ||
public static extern BigInteger TotalSupply(); | ||
public static extern BigInteger BalanceOf(byte[] account); | ||
} | ||
} |
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,27 @@ | ||
#pragma warning disable CS0626 | ||
|
||
using System; | ||
using System.Numerics; | ||
|
||
namespace Neo.SmartContract.Framework.Services.Neo | ||
{ | ||
[Contract("0xde5f57d430d3dece511cf975a8d37848cb9e0525")] | ||
public class NEO | ||
{ | ||
public static extern string Name(); | ||
public static extern string Symbol(); | ||
public static extern BigInteger Decimals(); | ||
public static extern BigInteger TotalSupply(); | ||
public static extern BigInteger BalanceOf(byte[] account); | ||
|
||
public static extern BigInteger UnclaimedGas(byte[] account, uint end); | ||
|
||
public static extern bool RegisterCandidate(byte[] pubkey); | ||
public static extern bool UnRegisterCandidate(byte[] pubkey); | ||
public static extern bool Vote(byte[] account, byte[] voteTo); | ||
public static extern (string, BigInteger)[] GetCandidates(); | ||
public static extern string[] GetValidators(); | ||
public static extern string[] GetCommittee(); | ||
public static extern string[] GetNextBlockValidators(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,24 @@ | ||
#pragma warning disable CS0626 | ||
|
||
using System; | ||
using System.Numerics; | ||
|
||
namespace Neo.SmartContract.Framework.Services.Neo | ||
{ | ||
[Contract("0xce06595079cd69583126dbfd1d2e25cca74cffe9")] | ||
public class Policy | ||
{ | ||
public static extern string Name(); | ||
public static extern uint GetMaxTransactionsPerBlock(); | ||
public static extern uint GetMaxBlockSize(); | ||
public static extern long GetMaxBlockSystemFee(); | ||
public static extern BigInteger GetFeePerByte(); | ||
public static extern string[] GetBlockedAccounts(); | ||
public static extern bool SetMaxBlockSize(uint value); | ||
public static extern bool SetMaxTransactionsPerBlock(uint value); | ||
public static extern bool SetMaxBlockSystemFee(long value); | ||
public static extern bool SetFeePerByte(long value); | ||
public static extern bool BlockAccount(byte[] account); | ||
public static extern bool UnblockAccount(byte[] account); | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_ContractCall.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,24 @@ | ||
using Neo.SmartContract.Framework; | ||
|
||
namespace Neo.Compiler.MSIL.UnitTests.TestClasses | ||
{ | ||
[Contract("0102030405060708090A0102030405060708090A")] | ||
public class Contract1 | ||
{ | ||
public static extern byte[] testArgs(byte a); | ||
public static extern void testVoid(); | ||
} | ||
|
||
public class Contract_ContractCall : SmartContract.Framework.SmartContract | ||
{ | ||
public static byte[] testContractCall() | ||
{ | ||
return Contract1.testArgs((byte)4); | ||
} | ||
|
||
public static void testContractCallVoid() | ||
{ | ||
Contract1.testVoid(); | ||
} | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_appcall.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
tests/Neo.Compiler.MSIL.UnitTests/UnitTest_ContractCall.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,49 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Compiler.MSIL.UnitTests.Utils; | ||
using Neo.IO.Json; | ||
using Neo.SmartContract.Manifest; | ||
using Neo.VM; | ||
using Neo.VM.Types; | ||
|
||
namespace Neo.Compiler.MSIL.UnitTests | ||
{ | ||
[TestClass] | ||
public class UnitTest_ContractCall | ||
{ | ||
private TestEngine _engine; | ||
|
||
[TestInitialize] | ||
public void Init() | ||
{ | ||
var hash = UInt160.Parse("0102030405060708090A0102030405060708090A"); | ||
_engine = new TestEngine(); | ||
_engine.Snapshot.Contracts.Add(hash, new Ledger.ContractState() | ||
{ | ||
Script = _engine.Build("./TestClasses/Contract1.cs").finalNEF, | ||
Manifest = ContractManifest.FromJson(JObject.Parse(_engine.Build("./TestClasses/Contract1.cs").finalManifest)), | ||
}); | ||
|
||
//will ContractCall 0102030405060708090A0102030405060708090A | ||
_engine.AddEntryScript("./TestClasses/Contract_ContractCall.cs"); | ||
} | ||
|
||
[TestMethod] | ||
public void Test_ContractCall() | ||
{ | ||
var result = _engine.GetMethod("testContractCall").Run().ConvertTo(StackItemType.ByteString); | ||
Assert.AreEqual(VMState.HALT, _engine.State); | ||
|
||
StackItem wantresult = new byte[] { 1, 2, 3, 4 }; | ||
var bequal = wantresult.Equals(result); | ||
Assert.IsTrue(bequal); | ||
} | ||
|
||
[TestMethod] | ||
public void Test_ContractCall_Void() | ||
{ | ||
var result = _engine.ExecuteTestCaseStandard("testContractCallVoid"); | ||
Assert.AreEqual(VMState.HALT, _engine.State); | ||
Assert.AreEqual(0, result.Count); | ||
} | ||
} | ||
} |
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.