Skip to content

Commit

Permalink
Refresh native contracts' function (#381)
Browse files Browse the repository at this point in the history
* Func add and remove

* Update ut & neo version

Co-authored-by: Jin Qiao <jinqiao@neo.org>
  • Loading branch information
Qiao-Jin and Jin Qiao authored Oct 22, 2020
1 parent e3d8da3 commit 936fa5d
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.4.0" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="3.4.0" />
<PackageReference Include="Mono.Cecil" Version="0.11.2" />
<PackageReference Include="Neo" Version="3.0.0-CI01036" />
<PackageReference Include="Neo" Version="3.0.0-CI01048" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Neo.SmartContract.Framework/Services/Neo/GAS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public class GAS
public static extern byte Decimals { get; }
public static extern BigInteger TotalSupply();
public static extern BigInteger BalanceOf(byte[] account);
public static extern bool Transfer(byte[] from, byte[] to, BigInteger amount);
}
}
4 changes: 3 additions & 1 deletion src/Neo.SmartContract.Framework/Services/Neo/NEO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ public class NEO
public static extern byte Decimals { get; }
public static extern BigInteger TotalSupply();
public static extern BigInteger BalanceOf(byte[] account);
public static extern bool Transfer(byte[] from, byte[] to, BigInteger amount);

public static extern bool SetGasPerBlock(BigInteger gasPerBlock);
public static extern BigInteger GetGasPerBlock();
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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Neo.SmartContract.Framework/Services/Neo/Policy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Policy
public static extern uint GetMaxBlockSize();
public static extern long GetMaxBlockSystemFee();
public static extern BigInteger GetFeePerByte();
public static extern string[] GetBlockedAccounts();
public static extern string[] IsBlocked(byte[] account);
public static extern bool SetMaxBlockSize(uint value);
public static extern bool SetMaxTransactionsPerBlock(uint value);
public static extern bool SetMaxBlockSystemFee(long value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class NativeTest
{
private TestEngine _engine;
private readonly byte[] pubKey = NeonTestTool.HexString2Bytes("03ea01cb94bdaf0cd1c01b159d474f9604f4af35a3e2196f6bdfdb33b2aa4961fa");
byte[] account = new byte[] { 0xf6, 0x64, 0x43, 0x49, 0x8d, 0x38, 0x78, 0xd3, 0x2b, 0x99, 0x4e, 0x4e, 0x12, 0x83, 0xc6, 0x93, 0x44, 0x21, 0xda, 0xfe };

[TestInitialize]
public void Init()
Expand Down Expand Up @@ -67,7 +68,6 @@ public void Test_NEO()
Assert.AreEqual("NEO", item.GetString());

_engine.Reset();
var account = new byte[] { 0xf6, 0x64, 0x43, 0x49, 0x8d, 0x38, 0x78, 0xd3, 0x2b, 0x99, 0x4e, 0x4e, 0x12, 0x83, 0xc6, 0x93, 0x44, 0x21, 0xda, 0xfe };
result = _engine.ExecuteTestCaseStandard("NEO_BalanceOf", account);
Assert.AreEqual(VMState.HALT, _engine.State);
Assert.AreEqual(1, result.Count);
Expand Down Expand Up @@ -113,6 +113,33 @@ public void Test_NEO()
Assert.AreEqual(true, candidatePubKey.Equals((VM.Types.ByteString)pubKey));
Assert.IsInstanceOfType(candidateVotes, typeof(Integer));
Assert.AreEqual(0, candidateVotes.GetInteger());

_engine.Reset();
result = _engine.ExecuteTestCaseStandard("NEO_Transfer", account, account, 0);
Assert.AreEqual(VMState.HALT, _engine.State);
Assert.AreEqual(1, result.Count);

item = result.Pop();
Assert.IsInstanceOfType(item, typeof(Boolean));
Assert.AreEqual(false, item.GetBoolean());

_engine.Reset();
result = _engine.ExecuteTestCaseStandard("NEO_UnclaimedGas", account, 0);
Assert.AreEqual(VMState.HALT, _engine.State);
Assert.AreEqual(1, result.Count);

item = result.Pop();
Assert.IsInstanceOfType(item, typeof(Integer));
Assert.AreEqual(0, item.GetInteger());

_engine.Reset();
result = _engine.ExecuteTestCaseStandard("NEO_GetGasPerBlock");
Assert.AreEqual(VMState.HALT, _engine.State);
Assert.AreEqual(1, result.Count);

item = result.Pop();
Assert.IsInstanceOfType(item, typeof(Integer));
Assert.AreEqual(500000000, item.GetInteger());
}

[TestMethod]
Expand Down Expand Up @@ -141,7 +168,7 @@ public void Test_GAS()
public void Test_Policy()
{
_engine.Reset();
var result = _engine.ExecuteTestCaseStandard("policy_GetFeePerByte");
var result = _engine.ExecuteTestCaseStandard("Policy_GetFeePerByte");
Assert.AreEqual(VMState.HALT, _engine.State);
Assert.AreEqual(1, result.Count);

Expand All @@ -150,7 +177,7 @@ public void Test_Policy()
Assert.AreEqual(1000L, item.GetInteger());

_engine.Reset();
result = _engine.ExecuteTestCaseStandard("policy_GetMaxTransactionsPerBlock");
result = _engine.ExecuteTestCaseStandard("Policy_GetMaxTransactionsPerBlock");
Assert.AreEqual(VMState.HALT, _engine.State);
Assert.AreEqual(1, result.Count);

Expand All @@ -159,13 +186,13 @@ public void Test_Policy()
Assert.AreEqual(512, item.GetInteger());

_engine.Reset();
result = _engine.ExecuteTestCaseStandard("policy_GetBlockedAccounts");
result = _engine.ExecuteTestCaseStandard("Policy_IsBlocked", account);
Assert.AreEqual(VMState.HALT, _engine.State);
Assert.AreEqual(1, result.Count);

item = result.Pop();
Assert.IsInstanceOfType(item, typeof(Array));
Assert.AreEqual(0, ((Array)item).Count);
Assert.IsInstanceOfType(item, typeof(Boolean));
Assert.AreEqual(false, item.GetBoolean());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,28 @@ public static string NEO_Name()
return NEO.Name;
}

[DisplayName("NEO_Transfer")]
public static bool NEO_Transfer(byte[] from, byte[] to, BigInteger amount)
{
return NEO.Transfer(from, to, amount);
}

[DisplayName("NEO_BalanceOf")]
public static BigInteger NEO_BalanceOf(byte[] account)
{
return NEO.BalanceOf(account);
}

[DisplayName("NEO_GetValidators")]
public static string[] NEO_GetValidators()
[DisplayName("NEO_GetGasPerBlock")]
public static BigInteger NEO_GetGasPerBlock()
{
return NEO.GetGasPerBlock();
}

[DisplayName("NEO_UnclaimedGas")]
public static BigInteger NEO_UnclaimedGas(byte[] account, uint end)
{
return NEO.GetValidators();
return NEO.UnclaimedGas(account, end);
}

[DisplayName("NEO_RegisterCandidate")]
Expand All @@ -55,29 +67,22 @@ public static string GAS_Name()
return GAS.Name;
}

[DisplayName("Policy_GetFeePerByte")]
public static BigInteger Policy_GetFeePerByte()
{
return Policy.GetFeePerByte();
}

public static bool Policy_SetMaxTransactionsPerBlock(uint value)
{
return Policy.SetMaxTransactionsPerBlock(value);
}

[DisplayName("Policy_GetMaxTransactionsPerBlock")]
public static uint Policy_GetMaxTransactionsPerBlock()
{
return Policy.GetMaxTransactionsPerBlock();
}

public static bool Policy_BlockAccount(byte[] account)
{
return Policy.BlockAccount(account);
}

public static object[] Policy_GetBlockedAccounts()
[DisplayName("Policy_IsBlocked")]
public static object[] Policy_IsBlocked(byte[] account)
{
return Policy.GetBlockedAccounts();
return Policy.IsBlocked(account);
}
}
}

0 comments on commit 936fa5d

Please sign in to comment.