Skip to content

Commit

Permalink
bug: Fix default value when Stored (neo-project#895)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
2 people authored and cschuchardt88 committed Mar 21, 2024
1 parent 339daaa commit 6853501
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 19 deletions.
51 changes: 42 additions & 9 deletions src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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

Expand Down

0 comments on commit 6853501

Please sign in to comment.