Skip to content

Commit 7b2448e

Browse files
shargonJim8y
andauthored
bug: Fix default value when Stored (#895)
* Fix default value when Stored * Fix Default value * Fix * add Int16 * Fix ut * Improve reading * Apply suggestions from code review * added types * Breaking changes reporting during releases * Delete .github/workflows/release.yml --------- Co-authored-by: Jimmy <jimmy@r3e.network>
1 parent e25fdc9 commit 7b2448e

File tree

3 files changed

+48
-19
lines changed

3 files changed

+48
-19
lines changed

src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs

+42-9
Original file line numberDiff line numberDiff line change
@@ -574,21 +574,42 @@ private void ConvertStorageBackedProperty(IPropertySymbol property, AttributeDat
574574
Call(ApplicationEngine.System_Storage_Get);
575575
switch (property.Type.Name)
576576
{
577-
case "SByte":
578-
case "Short":
579-
case "Int32":
580-
case "Int64":
577+
case "byte":
578+
case "sbyte":
581579
case "Byte":
580+
case "SByte":
581+
582+
case "short":
583+
case "ushort":
584+
case "Int16":
582585
case "UInt16":
586+
587+
case "int":
588+
case "uint":
589+
case "Int32":
583590
case "UInt32":
591+
592+
case "long":
593+
case "ulong":
594+
case "Int64":
584595
case "UInt64":
585596
case "BigInteger":
586-
ChangeType(VM.Types.StackItemType.Integer);
597+
// Replace NULL with 0
598+
AddInstruction(OpCode.DUP);
599+
AddInstruction(OpCode.ISNULL);
600+
JumpTarget ifFalse = new();
601+
Jump(OpCode.JMPIFNOT_L, ifFalse);
602+
{
603+
AddInstruction(OpCode.DROP);
604+
AddInstruction(OpCode.PUSH0);
605+
}
606+
ifFalse.Instruction = AddInstruction(OpCode.NOP);
587607
break;
588608
case "String":
589609
case "ByteString":
590610
case "UInt160":
591611
case "UInt256":
612+
case "ECPoint":
592613
break;
593614
default:
594615
Call(NativeContract.StdLib.Hash, "deserialize", 1, true);
@@ -620,19 +641,31 @@ private void ConvertStorageBackedProperty(IPropertySymbol property, AttributeDat
620641
AccessSlot(OpCode.LDARG, 1);
621642
switch (property.Type.Name)
622643
{
623-
case "SByte":
624-
case "Short":
625-
case "Int32":
626-
case "Int64":
644+
case "byte":
645+
case "sbyte":
627646
case "Byte":
647+
case "SByte":
648+
649+
case "short":
650+
case "ushort":
651+
case "Int16":
628652
case "UInt16":
653+
654+
case "int":
655+
case "uint":
656+
case "Int32":
629657
case "UInt32":
658+
659+
case "long":
660+
case "ulong":
661+
case "Int64":
630662
case "UInt64":
631663
case "BigInteger":
632664
case "String":
633665
case "ByteString":
634666
case "UInt160":
635667
case "UInt256":
668+
case "ECPoint":
636669
break;
637670
default:
638671
Call(NativeContract.StdLib.Hash, "serialize", 1, true);

tests/Neo.SmartContract.Framework.TestContracts/Contract_Stored.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
using System.Numerics;
2-
using Neo.SmartContract.Framework;
31
using Neo.SmartContract.Framework.Attributes;
4-
using Neo.SmartContract.Framework.Services;
2+
using System.Numerics;
53

64
namespace Neo.SmartContract.Framework.UnitTests.TestClasses
75
{
8-
public class Contract_StorageBacked : SmartContract
6+
public class Contract_Stored : SmartContract
97
{
108
// Test non-static
119

tests/Neo.SmartContract.Framework.UnitTests/Services/BackedStorageTest.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ public void Test_Private_Getter_Public_Setter()
5252

5353
var result = _engine.ExecuteTestCaseStandard("getPrivateGetterPublicSetter");
5454
Assert.AreEqual(VMState.HALT, _engine.State);
55-
Assert.IsTrue(result.Pop().IsNull);
56-
55+
Assert.AreEqual(0, result.Pop());
5756

5857
// Test public setter
5958
_engine.Reset();
@@ -81,8 +80,7 @@ public void Test_Non_Static_Private_Getter_Public_Setter()
8180

8281
var result = _engine.ExecuteTestCaseStandard("getNonStaticPrivateGetterPublicSetter");
8382
Assert.AreEqual(VMState.HALT, _engine.State);
84-
Assert.IsTrue(result.Pop().IsNull);
85-
83+
Assert.AreEqual(0, result.Pop());
8684

8785
// Test public setter
8886
_engine.Reset();
@@ -108,14 +106,14 @@ public void Test_Kind(string kind)
108106

109107
var result = _engine.ExecuteTestCaseStandard("get" + kind);
110108
Assert.AreEqual(VMState.HALT, _engine.State);
111-
Assert.IsTrue(result.Pop().IsNull);
109+
Assert.AreEqual(0, result.Pop());
112110

113111
// Test public getter
114112

115113
_engine.Reset();
116114
result = _engine.ExecuteTestCaseStandard(kind[0].ToString().ToLowerInvariant() + kind[1..]);
117115
Assert.AreEqual(VMState.HALT, _engine.State);
118-
Assert.IsTrue(result.Pop().IsNull);
116+
Assert.AreEqual(0, result.Pop());
119117

120118
// Put
121119

0 commit comments

Comments
 (0)