From be7dfec304587ea5ad07e2b889739ef44d76bbc1 Mon Sep 17 00:00:00 2001 From: Fernando Diaz Toledano Date: Tue, 13 Feb 2024 09:06:49 +0100 Subject: [PATCH 01/10] Fix default value when Stored --- .../Contract_Stored.cs | 11 ++++++---- .../Services/BackedStorageTest.cs | 20 ++++++++++++++----- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/tests/Neo.SmartContract.Framework.TestContracts/Contract_Stored.cs b/tests/Neo.SmartContract.Framework.TestContracts/Contract_Stored.cs index 2a1c8df08..4ab79dde0 100644 --- a/tests/Neo.SmartContract.Framework.TestContracts/Contract_Stored.cs +++ b/tests/Neo.SmartContract.Framework.TestContracts/Contract_Stored.cs @@ -1,12 +1,15 @@ -using System.Numerics; -using Neo.SmartContract.Framework; using Neo.SmartContract.Framework.Attributes; -using Neo.SmartContract.Framework.Services; +using System.Numerics; namespace Neo.SmartContract.Framework.UnitTests.TestClasses { - public class Contract_StorageBacked : SmartContract + public class Contract_Stored : SmartContract { + // Test static + + [Stored] + public BigInteger StaticValue { [Safe] get; protected set; } + // Test non-static [Stored] diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs index 4e0d3eb65..7ae5a0c4b 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs @@ -41,6 +41,18 @@ public void Test() Assert.AreEqual(3, _engine.Snapshot.GetChangeSet().Count(u => u.Key.Id == 0)); } + [TestMethod] + public void Test_StaticDefaultValue() + { + _engine.Reset(); + + // Test default static value + + var result = _engine.ExecuteTestCaseStandard("getStaticValue"); + Assert.AreEqual(VMState.HALT, _engine.State); + Assert.AreEqual(0, result.Pop()); + } + [TestMethod] public void Test_Private_Getter_Public_Setter() { @@ -52,8 +64,7 @@ public void Test_Private_Getter_Public_Setter() var result = _engine.ExecuteTestCaseStandard("getPrivateGetterPublicSetter"); Assert.AreEqual(VMState.HALT, _engine.State); - Assert.IsTrue(result.Pop().IsNull); - + Assert.AreEqual(0, result.Pop()); // Test public setter _engine.Reset(); @@ -81,8 +92,7 @@ public void Test_Non_Static_Private_Getter_Public_Setter() var result = _engine.ExecuteTestCaseStandard("getNonStaticPrivateGetterPublicSetter"); Assert.AreEqual(VMState.HALT, _engine.State); - Assert.IsTrue(result.Pop().IsNull); - + Assert.AreEqual(0, result.Pop()); // Test public setter _engine.Reset(); @@ -108,7 +118,7 @@ public void Test_Kind(string kind) var result = _engine.ExecuteTestCaseStandard("get" + kind); Assert.AreEqual(VMState.HALT, _engine.State); - Assert.IsTrue(result.Pop().IsNull); + Assert.AreEqual(0, result.Pop()); // Test public getter From 04e252e02c516e301b7b828c38067e387d5f122e Mon Sep 17 00:00:00 2001 From: Fernando Diaz Toledano Date: Tue, 13 Feb 2024 09:19:45 +0100 Subject: [PATCH 02/10] Fix Default value --- .../MethodConvert/MethodConvert.cs | 11 ++++++++++- .../Contract_Stored.cs | 2 +- .../Services/BackedStorageTest.cs | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs b/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs index baad88674..a6cbbe03b 100644 --- a/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs +++ b/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs @@ -583,12 +583,20 @@ private void ConvertStorageBackedProperty(IPropertySymbol property, AttributeDat case "UInt32": case "UInt64": case "BigInteger": - ChangeType(VM.Types.StackItemType.Integer); + // Replace NULL with 0 + AddInstruction(OpCode.DUP); + AddInstruction(OpCode.ISNULL); + JumpTarget ifFalse = new(); + Jump(OpCode.JMPIFNOT_L, ifFalse); + AddInstruction(OpCode.DROP); + AddInstruction(OpCode.PUSH0); + ifFalse.Instruction = AddInstruction(OpCode.NOP); break; case "String": case "ByteString": case "UInt160": case "UInt256": + case "ECPoint": break; default: Call(NativeContract.StdLib.Hash, "deserialize", 1, true); @@ -633,6 +641,7 @@ private void ConvertStorageBackedProperty(IPropertySymbol property, AttributeDat case "ByteString": case "UInt160": case "UInt256": + case "ECPoint": break; default: Call(NativeContract.StdLib.Hash, "serialize", 1, true); diff --git a/tests/Neo.SmartContract.Framework.TestContracts/Contract_Stored.cs b/tests/Neo.SmartContract.Framework.TestContracts/Contract_Stored.cs index 4ab79dde0..0003391aa 100644 --- a/tests/Neo.SmartContract.Framework.TestContracts/Contract_Stored.cs +++ b/tests/Neo.SmartContract.Framework.TestContracts/Contract_Stored.cs @@ -8,7 +8,7 @@ public class Contract_Stored : SmartContract // Test static [Stored] - public BigInteger StaticValue { [Safe] get; protected set; } + public static BigInteger StaticValue { [Safe] get; protected set; } // Test non-static diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs index 7ae5a0c4b..1cf3a1367 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs @@ -48,7 +48,7 @@ public void Test_StaticDefaultValue() // Test default static value - var result = _engine.ExecuteTestCaseStandard("getStaticValue"); + var result = _engine.ExecuteTestCaseStandard("staticValue"); Assert.AreEqual(VMState.HALT, _engine.State); Assert.AreEqual(0, result.Pop()); } From 32a14c85071633a3bd67aecf78b669965b02682a Mon Sep 17 00:00:00 2001 From: Fernando Diaz Toledano Date: Tue, 13 Feb 2024 09:23:02 +0100 Subject: [PATCH 03/10] Fix --- .../Contract_Stored.cs | 5 ----- .../Services/BackedStorageTest.cs | 12 ------------ 2 files changed, 17 deletions(-) diff --git a/tests/Neo.SmartContract.Framework.TestContracts/Contract_Stored.cs b/tests/Neo.SmartContract.Framework.TestContracts/Contract_Stored.cs index 0003391aa..400efb98c 100644 --- a/tests/Neo.SmartContract.Framework.TestContracts/Contract_Stored.cs +++ b/tests/Neo.SmartContract.Framework.TestContracts/Contract_Stored.cs @@ -5,11 +5,6 @@ namespace Neo.SmartContract.Framework.UnitTests.TestClasses { public class Contract_Stored : SmartContract { - // Test static - - [Stored] - public static BigInteger StaticValue { [Safe] get; protected set; } - // Test non-static [Stored] diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs index 1cf3a1367..a843bfca3 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs @@ -41,18 +41,6 @@ public void Test() Assert.AreEqual(3, _engine.Snapshot.GetChangeSet().Count(u => u.Key.Id == 0)); } - [TestMethod] - public void Test_StaticDefaultValue() - { - _engine.Reset(); - - // Test default static value - - var result = _engine.ExecuteTestCaseStandard("staticValue"); - Assert.AreEqual(VMState.HALT, _engine.State); - Assert.AreEqual(0, result.Pop()); - } - [TestMethod] public void Test_Private_Getter_Public_Setter() { From a32baf550a62f0730801563fe921055e52cf68ed Mon Sep 17 00:00:00 2001 From: Fernando Diaz Toledano Date: Tue, 13 Feb 2024 09:25:07 +0100 Subject: [PATCH 04/10] add Int16 --- src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs b/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs index a6cbbe03b..053ac779e 100644 --- a/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs +++ b/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs @@ -574,11 +574,12 @@ private void ConvertStorageBackedProperty(IPropertySymbol property, AttributeDat Call(ApplicationEngine.System_Storage_Get); switch (property.Type.Name) { - case "SByte": case "Short": + case "Byte": + case "SByte": + case "Int16": case "Int32": case "Int64": - case "Byte": case "UInt16": case "UInt32": case "UInt64": @@ -628,11 +629,12 @@ private void ConvertStorageBackedProperty(IPropertySymbol property, AttributeDat AccessSlot(OpCode.LDARG, 1); switch (property.Type.Name) { - case "SByte": case "Short": + case "Byte": + case "SByte": + case "Int16": case "Int32": case "Int64": - case "Byte": case "UInt16": case "UInt32": case "UInt64": From f47eed235aa006a41b76791fb7a791cce892e19c Mon Sep 17 00:00:00 2001 From: Fernando Diaz Toledano Date: Tue, 13 Feb 2024 09:26:16 +0100 Subject: [PATCH 05/10] Fix ut --- .../Services/BackedStorageTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs index a843bfca3..ab0f3d43f 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs @@ -113,7 +113,7 @@ public void Test_Kind(string kind) _engine.Reset(); result = _engine.ExecuteTestCaseStandard(kind[0].ToString().ToLowerInvariant() + kind[1..]); Assert.AreEqual(VMState.HALT, _engine.State); - Assert.IsTrue(result.Pop().IsNull); + Assert.AreEqual(0, result.Pop()); // Put From 8f722add1b03a3b1265e612f24702d060548936d Mon Sep 17 00:00:00 2001 From: Fernando Diaz Toledano Date: Tue, 13 Feb 2024 09:27:50 +0100 Subject: [PATCH 06/10] Improve reading --- src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs b/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs index 053ac779e..8ae59a29b 100644 --- a/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs +++ b/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs @@ -589,8 +589,10 @@ private void ConvertStorageBackedProperty(IPropertySymbol property, AttributeDat AddInstruction(OpCode.ISNULL); JumpTarget ifFalse = new(); Jump(OpCode.JMPIFNOT_L, ifFalse); - AddInstruction(OpCode.DROP); - AddInstruction(OpCode.PUSH0); + { + AddInstruction(OpCode.DROP); + AddInstruction(OpCode.PUSH0); + } ifFalse.Instruction = AddInstruction(OpCode.NOP); break; case "String": From b454f74828b4021e83744ca67d233ff54423c638 Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 13 Feb 2024 09:28:36 -0800 Subject: [PATCH 07/10] Apply suggestions from code review --- src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs b/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs index 8ae59a29b..75d90d60f 100644 --- a/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs +++ b/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs @@ -574,9 +574,9 @@ private void ConvertStorageBackedProperty(IPropertySymbol property, AttributeDat Call(ApplicationEngine.System_Storage_Get); switch (property.Type.Name) { - case "Short": case "Byte": case "SByte": + case "Short": case "Int16": case "Int32": case "Int64": @@ -631,9 +631,9 @@ private void ConvertStorageBackedProperty(IPropertySymbol property, AttributeDat AccessSlot(OpCode.LDARG, 1); switch (property.Type.Name) { - case "Short": case "Byte": case "SByte": + case "Short": case "Int16": case "Int32": case "Int64": From 74e7b72fadb3947540589bbee01ace03d3727f04 Mon Sep 17 00:00:00 2001 From: Fernando Diaz Toledano Date: Wed, 14 Feb 2024 09:48:11 +0100 Subject: [PATCH 08/10] added types --- .../MethodConvert/MethodConvert.cs | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs b/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs index 75d90d60f..80957e60c 100644 --- a/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs +++ b/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs @@ -574,14 +574,24 @@ private void ConvertStorageBackedProperty(IPropertySymbol property, AttributeDat Call(ApplicationEngine.System_Storage_Get); switch (property.Type.Name) { + case "byte": + case "sbyte": case "Byte": case "SByte": - case "Short": + + case "short": + case "ushort": case "Int16": - case "Int32": - case "Int64": case "UInt16": + + case "int": + case "uint": + case "Int32": case "UInt32": + + case "long": + case "ulong": + case "Int64": case "UInt64": case "BigInteger": // Replace NULL with 0 @@ -631,14 +641,24 @@ private void ConvertStorageBackedProperty(IPropertySymbol property, AttributeDat AccessSlot(OpCode.LDARG, 1); switch (property.Type.Name) { + case "byte": + case "sbyte": case "Byte": case "SByte": - case "Short": + + case "short": + case "ushort": case "Int16": - case "Int32": - case "Int64": case "UInt16": + + case "int": + case "uint": + case "Int32": case "UInt32": + + case "long": + case "ulong": + case "Int64": case "UInt64": case "BigInteger": case "String": From edcd9fa1690c5b15afda0b6a9acd68b10e20ea40 Mon Sep 17 00:00:00 2001 From: Shargon Date: Wed, 14 Feb 2024 04:37:13 -0800 Subject: [PATCH 09/10] Breaking changes reporting during releases --- .github/workflows/release.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..805b7c334 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,16 @@ +changelog: + exclude: + labels: + - ignore-for-release + authors: + - octocat + categories: + - title: Breaking Changes 🛠 + labels: + - breaking-change + - title: Exciting New Features 🎉 + labels: + - enhancement + - title: What's Changed + labels: + - "*" From e8f42a5ab0830652a69380681d76f343b27da775 Mon Sep 17 00:00:00 2001 From: Shargon Date: Wed, 14 Feb 2024 04:41:27 -0800 Subject: [PATCH 10/10] Delete .github/workflows/release.yml --- .github/workflows/release.yml | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 805b7c334..000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,16 +0,0 @@ -changelog: - exclude: - labels: - - ignore-for-release - authors: - - octocat - categories: - - title: Breaking Changes 🛠 - labels: - - breaking-change - - title: Exciting New Features 🎉 - labels: - - enhancement - - title: What's Changed - labels: - - "*"