diff --git a/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs b/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs index baad88674..80957e60c 100644 --- a/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs +++ b/src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs @@ -574,21 +574,42 @@ private void ConvertStorageBackedProperty(IPropertySymbol property, AttributeDat Call(ApplicationEngine.System_Storage_Get); switch (property.Type.Name) { - case "SByte": - case "Short": - case "Int32": - case "Int64": + case "byte": + case "sbyte": case "Byte": + case "SByte": + + case "short": + case "ushort": + case "Int16": case "UInt16": + + case "int": + case "uint": + case "Int32": case "UInt32": + + case "long": + case "ulong": + case "Int64": 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); @@ -620,19 +641,31 @@ private void ConvertStorageBackedProperty(IPropertySymbol property, AttributeDat AccessSlot(OpCode.LDARG, 1); switch (property.Type.Name) { - case "SByte": - case "Short": - case "Int32": - case "Int64": + case "byte": + case "sbyte": case "Byte": + case "SByte": + + case "short": + case "ushort": + case "Int16": case "UInt16": + + case "int": + case "uint": + case "Int32": case "UInt32": + + case "long": + case "ulong": + case "Int64": case "UInt64": case "BigInteger": case "String": 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 2a1c8df08..400efb98c 100644 --- a/tests/Neo.SmartContract.Framework.TestContracts/Contract_Stored.cs +++ b/tests/Neo.SmartContract.Framework.TestContracts/Contract_Stored.cs @@ -1,11 +1,9 @@ -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 non-static diff --git a/tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs index 4e0d3eb65..ab0f3d43f 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs @@ -52,8 +52,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 +80,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,14 +106,14 @@ 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 _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