Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync neo changes #391

Merged
merged 55 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
4c2e79d
Initial commit
shargon Nov 12, 2020
f5f161b
Remove hash from ABI
shargon Nov 12, 2020
38e0590
Clean lines
shargon Nov 12, 2020
9c8e7db
Fixes
shargon Nov 13, 2020
5379d41
Merge remote-tracking branch 'neo-project/master' into sync-nep17
shargon Nov 13, 2020
7ad9b72
Fix some UT
shargon Nov 13, 2020
4448877
Change name to manifest
shargon Nov 16, 2020
cc4cced
Merge branch 'master' into sync-nep17
shargon Nov 19, 2020
88fa514
Update nuget
shargon Nov 19, 2020
6947047
Update NEP17.cs
shargon Nov 20, 2020
c0db531
Merge branch 'master' into sync-nep17
shargon Nov 20, 2020
f4df31a
Fix more UT
shargon Nov 20, 2020
2ec0748
Some fixes
shargon Nov 20, 2020
9894e83
Fix Contract
shargon Nov 20, 2020
821f834
Update NEP17.Owner.cs
shargon Nov 21, 2020
057d5ba
Update NEP17.Methods.cs
shargon Nov 26, 2020
9e79f27
Merge branch 'master' into sync-nep17
shargon Nov 26, 2020
af62c81
Add data to Transfer
shargon Nov 26, 2020
32905b6
add data to onPayment
shargon Nov 26, 2020
1650325
Remove name
shargon Nov 27, 2020
afad1b1
Merge branch 'master' into sync-nep17
shargon Dec 1, 2020
425718f
Update src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj
shargon Dec 1, 2020
ecdb308
Fix NEF Version
shargon Dec 1, 2020
0fafec4
Fix UT
shargon Dec 1, 2020
0633281
Fix test
shargon Dec 1, 2020
3de92ed
Add OnPayment() for Mint()
superboyiii Dec 4, 2020
9110b42
Fix
superboyiii Dec 4, 2020
ba8a716
Fix
superboyiii Dec 4, 2020
c496fe8
Format
superboyiii Dec 4, 2020
da701ad
Format
superboyiii Dec 4, 2020
2e4fc2c
Format
superboyiii Dec 4, 2020
1cfec66
Update NEP17.Owner.cs
shargon Dec 4, 2020
e1eff81
Update templates/Template.NEP17.CSharp/NEP17.cs
shargon Dec 4, 2020
560e161
Update templates/Template.NEP17.CSharp/NEP17.Methods.cs
shargon Dec 4, 2020
0ef68d9
Update AssetStorage.cs
shargon Dec 4, 2020
b7d657a
Update AssetStorage.cs
shargon Dec 4, 2020
c75bb6b
Update AssetStorage.cs
shargon Dec 4, 2020
a33b14b
Merge pull request #9 from superboyiii/sync-nep17
shargon Dec 4, 2020
d1d2300
Update templates/Template.NEP17.CSharp/NEP17.cs
shargon Dec 4, 2020
0b9fd67
Update templates/Template.NEP17.CSharp/NEP17.Methods.cs
shargon Dec 4, 2020
0c27e44
Rename to ContractNameAttribute & fix invocation counter
shargon Dec 7, 2020
e3d02dc
Change mint
shargon Dec 8, 2020
5db20de
Rename to IsDeployed
shargon Dec 8, 2020
ad2d89e
Use DisplayName
shargon Dec 8, 2020
c903184
Fix mint
shargon Dec 8, 2020
882a721
Fix
shargon Dec 8, 2020
bd4c246
Optimize Mint
erikzhang Dec 9, 2020
8d0d298
Remove GetTransactionAmount
erikzhang Dec 9, 2020
493b278
Fix claim gas
erikzhang Dec 9, 2020
15f9de1
Add IsValid
shargon Dec 9, 2020
8d1e266
Update NEP17.Crowdsale.cs
erikzhang Dec 10, 2020
0823a31
Update src/Neo.SmartContract.Framework/UInt160.cs
shargon Dec 10, 2020
7992c3a
Remove Size from UInt160 and UInt256
erikzhang Dec 10, 2020
befe380
Update UInt256.cs
erikzhang Dec 10, 2020
a572293
Fix UT
erikzhang Dec 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/Neo.SmartContract.Framework/UInt160.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@ public extern bool IsZero
get;
}

public extern int Size
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
{
[OpCode(OpCode.SIZE)]
get;
}

public extern bool IsValid
{
[OpCode(OpCode.DUP)]
[OpCode(OpCode.ISNULL)]
[OpCode(OpCode.JMPIF, "0x08")]
[OpCode(OpCode.SIZE)]
[OpCode(OpCode.PUSHINT8, "14")] // 0x14 == 20 bytes expected array size
[OpCode(OpCode.NUMEQUAL)]
[OpCode(OpCode.JMP, "0x04")]
[OpCode(OpCode.DROP)]
[OpCode(OpCode.PUSH0)]
shargon marked this conversation as resolved.
Show resolved Hide resolved
get;
}

[OpCode(OpCode.CONVERT, StackItemType.ByteString)]
[OpCode(OpCode.DUP)]
[OpCode(OpCode.SIZE)]
Expand Down
20 changes: 20 additions & 0 deletions src/Neo.SmartContract.Framework/UInt256.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@ public extern bool IsZero
get;
}

public extern int Size
{
[OpCode(OpCode.SIZE)]
get;
}

public extern bool IsValid
{
[OpCode(OpCode.DUP)]
[OpCode(OpCode.ISNULL)]
[OpCode(OpCode.JMPIF, "0x08")]
[OpCode(OpCode.SIZE)]
[OpCode(OpCode.PUSHINT8, "20")] // 0x20 == 32 bytes expected array size
[OpCode(OpCode.NUMEQUAL)]
[OpCode(OpCode.JMP, "0x04")]
[OpCode(OpCode.DROP)]
[OpCode(OpCode.PUSH0)]
get;
}

[OpCode(OpCode.CONVERT, StackItemType.ByteString)]
[OpCode(OpCode.DUP)]
[OpCode(OpCode.SIZE)]
Expand Down
2 changes: 1 addition & 1 deletion templates/Template.NEP17.CSharp/NEP17.Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Template.NEP17.CSharp
{
public partial class NEP17 : SmartContract
{
private static bool ValidateAddress(UInt160 address) => !address.IsZero;
private static bool ValidateAddress(UInt160 address) => address.IsValid && !address.IsZero;
private static bool IsDeployed(UInt160 address) => Blockchain.GetContract(address) != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ class Contract_UIntTypes : SmartContract.Framework.SmartContract
public static bool checkZeroStatic(UInt160 owner) { return owner == UInt160.Zero; }

public static UInt160 constructUInt160(byte[] bytes) { return (UInt160)bytes; }

public static bool validateAddress(UInt160 address) => address.IsValid && !address.IsZero;
}
}
108 changes: 87 additions & 21 deletions tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Types.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Compiler.MSIL.UnitTests.Utils;
using Neo.IO;
using Neo.VM;
using Neo.VM.Types;
using Neo.Wallets;
using System.Linq;
using System.Numerics;

namespace Neo.Compiler.MSIL.UnitTests
{
Expand Down Expand Up @@ -193,8 +193,8 @@ public void byteArray_Test()
var result = testengine.ExecuteTestCaseStandard("checkByteArray");

var item = result.Pop();
Assert.IsInstanceOfType(item, typeof(Buffer));
CollectionAssert.AreEqual(new byte[] { 1, 2, 3 }, ((Buffer)item).GetSpan().ToArray());
Assert.IsInstanceOfType(item, typeof(VM.Types.Buffer));
CollectionAssert.AreEqual(new byte[] { 1, 2, 3 }, ((VM.Types.Buffer)item).GetSpan().ToArray());
}

[TestMethod]
Expand Down Expand Up @@ -229,9 +229,9 @@ public void arrayObj_Test()
var result = testengine.ExecuteTestCaseStandard("checkArrayObj");

var item = result.Pop();
Assert.IsInstanceOfType(item, typeof(Array));
Assert.AreEqual(1, ((Array)item).Count);
Assert.AreEqual("neo", (((Array)item)[0] as ByteString).GetString());
Assert.IsInstanceOfType(item, typeof(VM.Types.Array));
Assert.AreEqual(1, ((VM.Types.Array)item).Count);
Assert.AreEqual("neo", (((VM.Types.Array)item)[0] as ByteString).GetString());
}

[TestMethod]
Expand All @@ -254,9 +254,9 @@ public void class_Test()
var result = testengine.ExecuteTestCaseStandard("checkClass");

var item = result.Pop();
Assert.IsInstanceOfType(item, typeof(Array));
Assert.AreEqual(1, ((Array)item).Count);
Assert.AreEqual("neo", (((Array)item)[0] as ByteString).GetString());
Assert.IsInstanceOfType(item, typeof(VM.Types.Array));
Assert.AreEqual(1, ((VM.Types.Array)item).Count);
Assert.AreEqual("neo", (((VM.Types.Array)item)[0] as ByteString).GetString());
}

[TestMethod]
Expand All @@ -280,10 +280,10 @@ public void tuple_Test()
var result = testengine.ExecuteTestCaseStandard("checkTuple");

var item = result.Pop();
Assert.IsInstanceOfType(item, typeof(Array));
Assert.AreEqual(2, ((Array)item).Count);
Assert.AreEqual("neo", (((Array)item)[0] as ByteString).GetString());
Assert.AreEqual("smart economy", (((Array)item)[1] as ByteString).GetString());
Assert.IsInstanceOfType(item, typeof(VM.Types.Array));
Assert.AreEqual(2, ((VM.Types.Array)item).Count);
Assert.AreEqual("neo", (((VM.Types.Array)item)[0] as ByteString).GetString());
Assert.AreEqual("smart economy", (((VM.Types.Array)item)[1] as ByteString).GetString());
}

[TestMethod]
Expand All @@ -294,10 +294,10 @@ public void tuple2_Test()
var result = testengine.ExecuteTestCaseStandard("checkTuple2");

var item = result.Pop();
Assert.IsInstanceOfType(item, typeof(Array));
Assert.AreEqual(2, ((Array)item).Count);
Assert.AreEqual("neo", (((Array)item)[0] as ByteString).GetString());
Assert.AreEqual("smart economy", (((Array)item)[1] as ByteString).GetString());
Assert.IsInstanceOfType(item, typeof(VM.Types.Array));
Assert.AreEqual(2, ((VM.Types.Array)item).Count);
Assert.AreEqual("neo", (((VM.Types.Array)item)[0] as ByteString).GetString());
Assert.AreEqual("smart economy", (((VM.Types.Array)item)[1] as ByteString).GetString());
}

[TestMethod]
Expand All @@ -308,10 +308,10 @@ public void tuple3_Test()
var result = testengine.ExecuteTestCaseStandard("checkTuple3");

var item = result.Pop();
Assert.IsInstanceOfType(item, typeof(Array));
Assert.AreEqual(2, ((Array)item).Count);
Assert.AreEqual("neo", (((Array)item)[0] as ByteString).GetString());
Assert.AreEqual("smart economy", (((Array)item)[1] as ByteString).GetString());
Assert.IsInstanceOfType(item, typeof(VM.Types.Array));
Assert.AreEqual(2, ((VM.Types.Array)item).Count);
Assert.AreEqual("neo", (((VM.Types.Array)item)[0] as ByteString).GetString());
Assert.AreEqual("smart economy", (((VM.Types.Array)item)[1] as ByteString).GetString());
}

[TestMethod]
Expand Down Expand Up @@ -354,6 +354,72 @@ public void delegate_Test()
Assert.IsInstanceOfType(item, typeof(Pointer));
}

[TestMethod]
public void UInt160_ValidateAddress()
{
var address = "NiNmXL8FjEUEs1nfX9uHFBNaenxDHJtmuB".ToScriptHash();

var testengine = new TestEngine();
testengine.AddEntryScript("./TestClasses/Contract_UIntTypes.cs");

// True

var result = testengine.ExecuteTestCaseStandard("validateAddress", address.ToArray());
Assert.AreEqual(1, result.Count);
var item = result.Pop();
Assert.IsTrue(item.GetBoolean());

testengine.Reset();
result = testengine.ExecuteTestCaseStandard("validateAddress", new ByteString(address.ToArray()));
Assert.AreEqual(1, result.Count);
item = result.Pop();
Assert.IsTrue(item.GetBoolean());

// False

testengine.Reset();
result = testengine.ExecuteTestCaseStandard("validateAddress", new byte[1] { 1 }.Concat(address.ToArray()).ToArray());
Assert.AreEqual(1, result.Count);
item = result.Pop();
Assert.IsFalse(item.GetBoolean());

testengine.Reset();
result = testengine.ExecuteTestCaseStandard("validateAddress", BigInteger.One);
Assert.AreEqual(1, result.Count);
item = result.Pop();
Assert.IsFalse(item.GetBoolean());

testengine.Reset();
result = testengine.ExecuteTestCaseStandard("validateAddress", StackItem.Null);
Assert.AreEqual(1, result.Count);
item = result.Pop();
Assert.IsFalse(item.GetBoolean());

testengine.Reset();
result = testengine.ExecuteTestCaseStandard("validateAddress", new VM.Types.Array());
Assert.AreEqual(1, result.Count);
item = result.Pop();
Assert.IsFalse(item.GetBoolean());

testengine.Reset();
result = testengine.ExecuteTestCaseStandard("validateAddress", new Struct());
Assert.AreEqual(1, result.Count);
item = result.Pop();
Assert.IsFalse(item.GetBoolean());

testengine.Reset();
result = testengine.ExecuteTestCaseStandard("validateAddress", new Map());
Assert.AreEqual(1, result.Count);
item = result.Pop();
Assert.IsFalse(item.GetBoolean());

testengine.Reset();
result = testengine.ExecuteTestCaseStandard("validateAddress", new VM.Types.Boolean(true));
Assert.AreEqual(1, result.Count);
item = result.Pop();
Assert.IsFalse(item.GetBoolean());
}

[TestMethod]
public void UInt160_equals_test()
{
Expand Down