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

test misc expression #1272

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Services;
using System.Numerics;

namespace Neo.Compiler.CSharp.TestContracts
{
public class Contract_BinaryExpression : SmartContract.Framework.SmartContract
{
public static void BinaryIs()
{
ByteString a = "a";
ExecutionEngine.Assert(a is ByteString);
string b = $"";
#pragma warning disable CS0184
ExecutionEngine.Assert(b is ByteString);
#pragma warning restore CS0184
}

public static void BinaryAs()
{
UInt160 a = UInt160.Zero;
ExecutionEngine.Assert(a as ByteString == UInt160.Zero);
}
}
}
16 changes: 16 additions & 0 deletions tests/Neo.Compiler.CSharp.TestContracts/Contract_ComplexAssign.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Neo.SmartContract.Framework;
using System;
using System.ComponentModel;

Expand Down Expand Up @@ -124,5 +125,20 @@ public static (uint, int) UnitTest_Right_Shift_Assign_UnChecked()
}
return (value1, value2);
}

public class TestClass
{
public byte Property = 7;
public byte[] ArrayProperty = [0, 1, 2, 3];
}

public static void UnitTest_Member_Element_Complex_Assign()
{
TestClass t = new();
t.Property %= 3;
ExecutionEngine.Assert(t.Property == 1);
t.ArrayProperty[3] &= 4;
ExecutionEngine.Assert(t.ArrayProperty[0] == 0);
}
}
}
19 changes: 19 additions & 0 deletions tests/Neo.Compiler.CSharp.TestContracts/Contract_NULL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,31 @@ public void VoidMethod()
{
}
public int IntProperty => 42;
public byte? NullableProperty;
public byte?[]? NullableArray { get; set; }
}

public static void NullType()
{
TestClass? obj1 = null;
obj1?.VoidMethod();
}

public static void NullCoalescingAssignment()
{
TestClass t = new() { NullableProperty = 1 };
ExecutionEngine.Assert(t.NullableProperty == 1);
t.NullableProperty = null;
ExecutionEngine.Assert(t.NullableArray == null);
t.NullableArray ??= [0, null, 2, 3, t.NullableProperty];
t.NullableProperty ??= t.NullableArray[0];
ExecutionEngine.Assert(t.NullableProperty == 0);
t.NullableProperty ??= t.NullableArray[1];
ExecutionEngine.Assert(t.NullableProperty == 0);
t.NullableArray[1] ??= 1;
ExecutionEngine.Assert(t.NullableArray[1] == 1);
t.NullableArray[1] ??= 2;
ExecutionEngine.Assert(t.NullableArray[1] == 1);
}
}
}
25 changes: 24 additions & 1 deletion tests/Neo.Compiler.CSharp.TestContracts/Contract_PostfixUnary.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Microsoft.ApplicationInsights.DataContracts;
using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Native;
using Neo.SmartContract.Framework.Services;
using System;
Expand All @@ -13,7 +15,7 @@ public class Person

public int Age;

public int[] BWH = { 80, 60, 80 };
public int[] BWH { get; set; } = { 80, 60, 80 };

public Person(string name) { Name = name; }
}
Expand All @@ -33,5 +35,26 @@ public class Person
}

public static bool IsValid(Person? person) => person is not null && person.Name is not null;

public static void TestUndefinedCase()
{
Person p = new("Undefined");
ExecutionEngine.Assert(p.Age == 0);
p.Age = p.Age++; // This is undefined; typically should be just p.Age++
ExecutionEngine.Assert(p.Age == 0);
p.Age = ++p.Age;
ExecutionEngine.Assert(p.Age == 1);

ExecutionEngine.Assert(p.BWH[0] == 80);
p.BWH[0] = p.BWH[0]++;
ExecutionEngine.Assert(p.BWH[0] == 80);
p.BWH[0] = ++p.BWH[0];
ExecutionEngine.Assert(p.BWH[0] == 81);
}

public static void TestInvert()
{
ExecutionEngine.Assert(~1 == -2);
}
}
}
1 change: 1 addition & 0 deletions tests/Neo.Compiler.CSharp.TestContracts/Contract_Tuple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static object T1()
state.data = new StructB();
BigInteger index = 0;
(state.amount, state.data.height, _, index) = GetResult();
_ = GetResult();
state.index = index;
return state;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\Neo.SmartContract.Framework\Neo.SmartContract.Framework.csproj" />
<ProjectReference Include="..\..\src\Neo.SmartContract.Analyzer\Neo.SmartContract.Analyzer.csproj"
OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
<ProjectReference Include="..\..\src\Neo.SmartContract.Analyzer\Neo.SmartContract.Analyzer.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Neo.Cryptography.ECC;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Numerics;

namespace Neo.SmartContract.Testing;

public abstract class Contract_BinaryExpression(Neo.SmartContract.Testing.SmartContractInitialize initialize) : Neo.SmartContract.Testing.SmartContract(initialize), IContractInfo
{
#region Compiled data

public static Neo.SmartContract.Manifest.ContractManifest Manifest => Neo.SmartContract.Manifest.ContractManifest.Parse(@"{""name"":""Contract_BinaryExpression"",""groups"":[],""features"":{},""supportedstandards"":[],""abi"":{""methods"":[{""name"":""binaryIs"",""parameters"":[],""returntype"":""Void"",""offset"":0,""safe"":false},{""name"":""binaryAs"",""parameters"":[],""returntype"":""Void"",""offset"":19,""safe"":false}],""events"":[]},""permissions"":[],""trusts"":[],""extra"":{""nef"":{""optimization"":""All""}}}");

/// <summary>
/// Optimization: "All"
/// </summary>
public static Neo.SmartContract.NefFile Nef => Neo.IO.Helper.AsSerializable<Neo.SmartContract.NefFile>(Convert.FromBase64String(@"TkVGM1Rlc3RpbmdFbmdpbmUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAE5XAgAMAWFwaNkoOQwAcWnZKDlAVwEADBQAAAAAAAAAAAAAAAAAAAAAAAAAAHBoStkoJARFCwwUAAAAAAAAAAAAAAAAAAAAAAAAAACXOUBlVuZG"));

#endregion

#region Unsafe methods

/// <summary>
/// Unsafe method
/// </summary>
/// <remarks>
/// Script: VwEADBQAAAAAAAAAAAAAAAAAAAAAAAAAAHBoStkoJARFCwwUAAAAAAAAAAAAAAAAAAAAAAAAAACXOUA=
/// INITSLOT 0100 [64 datoshi]
/// PUSHDATA1 0000000000000000000000000000000000000000 [8 datoshi]
/// STLOC0 [2 datoshi]
/// LDLOC0 [2 datoshi]
/// DUP [2 datoshi]
/// ISTYPE 28 'ByteString' [2 datoshi]
/// JMPIF 04 [2 datoshi]
/// DROP [2 datoshi]
/// PUSHNULL [1 datoshi]
/// PUSHDATA1 0000000000000000000000000000000000000000 [8 datoshi]
/// EQUAL [32 datoshi]
/// ASSERT [1 datoshi]
/// RET [0 datoshi]
/// </remarks>
[DisplayName("binaryAs")]
public abstract void BinaryAs();

/// <summary>
/// Unsafe method
/// </summary>
/// <remarks>
/// Script: VwIADAFhcGjZKDkMAHFp2Sg5QA==
/// INITSLOT 0200 [64 datoshi]
/// PUSHDATA1 61 'a' [8 datoshi]
/// STLOC0 [2 datoshi]
/// LDLOC0 [2 datoshi]
/// ISTYPE 28 'ByteString' [2 datoshi]
/// ASSERT [1 datoshi]
/// PUSHDATA1 [8 datoshi]
/// STLOC1 [2 datoshi]
/// LDLOC1 [2 datoshi]
/// ISTYPE 28 'ByteString' [2 datoshi]
/// ASSERT [1 datoshi]
/// RET [0 datoshi]
/// </remarks>
[DisplayName("binaryIs")]
public abstract void BinaryIs();

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public abstract class Contract_ComplexAssign(Neo.SmartContract.Testing.SmartCont
{
#region Compiled data

public static Neo.SmartContract.Manifest.ContractManifest Manifest => Neo.SmartContract.Manifest.ContractManifest.Parse(@"{""name"":""Contract_ComplexAssign"",""groups"":[],""features"":{},""supportedstandards"":[],""abi"":{""methods"":[{""name"":""unitTest_Add_Assign_Checked"",""parameters"":[],""returntype"":""Array"",""offset"":0,""safe"":false},{""name"":""unitTest_Add_Assign_UnChecked"",""parameters"":[],""returntype"":""Array"",""offset"":68,""safe"":false},{""name"":""unitTest_Sub_Assign_Checked"",""parameters"":[],""returntype"":""Array"",""offset"":174,""safe"":false},{""name"":""unitTest_Sub_Assign_UnChecked"",""parameters"":[],""returntype"":""Array"",""offset"":234,""safe"":false},{""name"":""unitTest_Mul_Assign_Checked"",""parameters"":[],""returntype"":""Array"",""offset"":332,""safe"":false},{""name"":""unitTest_Mul_Assign_UnChecked"",""parameters"":[],""returntype"":""Array"",""offset"":400,""safe"":false},{""name"":""unitTest_Left_Shift_Assign_Checked"",""parameters"":[],""returntype"":""Array"",""offset"":506,""safe"":false},{""name"":""unitTest_Left_Shift_Assign_UnChecked"",""parameters"":[],""returntype"":""Array"",""offset"":574,""safe"":false},{""name"":""unitTest_Right_Shift_Assign_Checked"",""parameters"":[],""returntype"":""Array"",""offset"":680,""safe"":false},{""name"":""unitTest_Right_Shift_Assign_UnChecked"",""parameters"":[],""returntype"":""Array"",""offset"":740,""safe"":false}],""events"":[]},""permissions"":[],""trusts"":[],""extra"":{""nef"":{""optimization"":""All""}}}");
public static Neo.SmartContract.Manifest.ContractManifest Manifest => Neo.SmartContract.Manifest.ContractManifest.Parse(@"{""name"":""Contract_ComplexAssign"",""groups"":[],""features"":{},""supportedstandards"":[],""abi"":{""methods"":[{""name"":""unitTest_Add_Assign_Checked"",""parameters"":[],""returntype"":""Array"",""offset"":0,""safe"":false},{""name"":""unitTest_Add_Assign_UnChecked"",""parameters"":[],""returntype"":""Array"",""offset"":68,""safe"":false},{""name"":""unitTest_Sub_Assign_Checked"",""parameters"":[],""returntype"":""Array"",""offset"":174,""safe"":false},{""name"":""unitTest_Sub_Assign_UnChecked"",""parameters"":[],""returntype"":""Array"",""offset"":234,""safe"":false},{""name"":""unitTest_Mul_Assign_Checked"",""parameters"":[],""returntype"":""Array"",""offset"":332,""safe"":false},{""name"":""unitTest_Mul_Assign_UnChecked"",""parameters"":[],""returntype"":""Array"",""offset"":400,""safe"":false},{""name"":""unitTest_Left_Shift_Assign_Checked"",""parameters"":[],""returntype"":""Array"",""offset"":506,""safe"":false},{""name"":""unitTest_Left_Shift_Assign_UnChecked"",""parameters"":[],""returntype"":""Array"",""offset"":574,""safe"":false},{""name"":""unitTest_Right_Shift_Assign_Checked"",""parameters"":[],""returntype"":""Array"",""offset"":680,""safe"":false},{""name"":""unitTest_Right_Shift_Assign_UnChecked"",""parameters"":[],""returntype"":""Array"",""offset"":740,""safe"":false},{""name"":""unitTest_Member_Element_Complex_Assign"",""parameters"":[],""returntype"":""Void"",""offset"":838,""safe"":false}],""events"":[]},""permissions"":[],""trusts"":[],""extra"":{""nef"":{""optimization"":""All""}}}");

/// <summary>
/// Optimization: "All"
/// </summary>
public static Neo.SmartContract.NefFile Nef => Neo.IO.Helper.AsSerializable<Neo.SmartContract.NefFile>(Convert.FromBase64String(@"TkVGM1Rlc3RpbmdFbmdpbmUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP1GA1cCAAP/////AAAAAHAC////f3FoEZ5KEC4DOkoD/////wAAAAAyAzpwaRGeSgIAAACALgM6SgL///9/MgM6cWloEr9AVwIAA/////8AAAAAcAL///9/cWgRnkoQLgQiDkoD/////wAAAAAyDAP/////AAAAAJFwaRGeSgIAAACALgQiCkoC////fzIeA/////8AAAAAkUoC////fzIMAwAAAAABAAAAn3FpaBK/QFcCABBwAgAAAIBxaBGfShAuAzpKA/////8AAAAAMgM6cGkRn0oCAAAAgC4DOkoC////fzIDOnFpaBK/QFcCABBwAgAAAIBxaBGfShAuBCIOSgP/////AAAAADIMA/////8AAAAAkXBpEZ9KAgAAAIAuBCIKSgL///9/Mh4D/////wAAAACRSgL///9/MgwDAAAAAAEAAACfcWloEr9AVwIAA/////8AAAAAcAL///9/cWgSoEoQLgM6SgP/////AAAAADIDOnBpEqBKAgAAAIAuAzpKAv///38yAzpxaWgSv0BXAgAD/////wAAAABwAv///39xaBKgShAuBCIOSgP/////AAAAADIMA/////8AAAAAkXBpEqBKAgAAAIAuBCIKSgL///9/Mh4D/////wAAAACRSgL///9/MgwDAAAAAAEAAACfcWloEr9AVwIAA/////8AAAAAcAL///9/cWgRqEoQLgM6SgP/////AAAAADIDOnBpEahKAgAAAIAuAzpKAv///38yAzpxaWgSv0BXAgAD/////wAAAABwAv///39xaBGoShAuBCIOSgP/////AAAAADIMA/////8AAAAAkXBpEahKAgAAAIAuBCIKSgL///9/Mh4D/////wAAAACRSgL///9/MgwDAAAAAAEAAACfcWloEr9AVwIAEHACAAAAgHFoEalKEC4DOkoD/////wAAAAAyAzpwaRGpSgIAAACALgM6SgL///9/MgM6cWloEr9AVwIAEHACAAAAgHFoEalKEC4EIg5KA/////8AAAAAMgwD/////wAAAACRcGkRqUoCAAAAgC4EIgpKAv///38yHgP/////AAAAAJFKAv///38yDAMAAAAAAQAAAJ9xaWgSv0Cow2c0"));
public static Neo.SmartContract.NefFile Nef => Neo.IO.Helper.AsSerializable<Neo.SmartContract.NefFile>(Convert.FromBase64String(@"TkVGM1Rlc3RpbmdFbmdpbmUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP2dA1cCAAP/////AAAAAHAC////f3FoEZ5KEC4DOkoD/////wAAAAAyAzpwaRGeSgIAAACALgM6SgL///9/MgM6cWloEr9AVwIAA/////8AAAAAcAL///9/cWgRnkoQLgQiDkoD/////wAAAAAyDAP/////AAAAAJFwaRGeSgIAAACALgQiCkoC////fzIeA/////8AAAAAkUoC////fzIMAwAAAAABAAAAn3FpaBK/QFcCABBwAgAAAIBxaBGfShAuAzpKA/////8AAAAAMgM6cGkRn0oCAAAAgC4DOkoC////fzIDOnFpaBK/QFcCABBwAgAAAIBxaBGfShAuBCIOSgP/////AAAAADIMA/////8AAAAAkXBpEZ9KAgAAAIAuBCIKSgL///9/Mh4D/////wAAAACRSgL///9/MgwDAAAAAAEAAACfcWloEr9AVwIAA/////8AAAAAcAL///9/cWgSoEoQLgM6SgP/////AAAAADIDOnBpEqBKAgAAAIAuAzpKAv///38yAzpxaWgSv0BXAgAD/////wAAAABwAv///39xaBKgShAuBCIOSgP/////AAAAADIMA/////8AAAAAkXBpEqBKAgAAAIAuBCIKSgL///9/Mh4D/////wAAAACRSgL///9/MgwDAAAAAAEAAACfcWloEr9AVwIAA/////8AAAAAcAL///9/cWgRqEoQLgM6SgP/////AAAAADIDOnBpEahKAgAAAIAuAzpKAv///38yAzpxaWgSv0BXAgAD/////wAAAABwAv///39xaBGoShAuBCIOSgP/////AAAAADIMA/////8AAAAAkXBpEahKAgAAAIAuBCIKSgL///9/Mh4D/////wAAAACRSgL///9/MgwDAAAAAAEAAACfcWloEr9AVwIAEHACAAAAgHFoEalKEC4DOkoD/////wAAAAAyAzpwaRGpSgIAAACALgM6SgL///9/MgM6cWloEr9AVwIAEHACAAAAgHFoEalKEC4EIg5KA/////8AAAAAMgwD/////wAAAACRcGkRqUoCAAAAgC4EIgpKAv///38yHgP/////AAAAAJFKAv///38yDAMAAAAAAQAAAJ9xaWgSv0BXAQAMBAABAgPbMBcSwHBoShDOE6JKEC4EIghKAf8AMgYB/wCRThBQ0EVoEM4RlzloEc4TS0vOFJFKEC4EIghKAf8AMgYB/wCRSlRT0EVoEc4QzhCXOUCPzZu8"));

#endregion

Expand Down Expand Up @@ -207,6 +207,80 @@ public abstract class Contract_ComplexAssign(Neo.SmartContract.Testing.SmartCont
[DisplayName("unitTest_Left_Shift_Assign_UnChecked")]
public abstract IList<object>? UnitTest_Left_Shift_Assign_UnChecked();

/// <summary>
/// Unsafe method
/// </summary>
/// <remarks>
/// Script: VwEADAQAAQID2zAXEsBwaEoQzhOiShAuBCIISgH/ADIGAf8AkU4QUNBFaBDOEZc5aBHOE0tLzhSRShAuBCIISgH/ADIGAf8AkUpUU9BFaBHOEM4QlzlA
/// INITSLOT 0100 [64 datoshi]
/// PUSHDATA1 00010203 [8 datoshi]
/// CONVERT 30 'Buffer' [8192 datoshi]
/// PUSH7 [1 datoshi]
/// PUSH2 [1 datoshi]
/// PACK [2048 datoshi]
/// STLOC0 [2 datoshi]
/// LDLOC0 [2 datoshi]
/// DUP [2 datoshi]
/// PUSH0 [1 datoshi]
/// PICKITEM [64 datoshi]
/// PUSH3 [1 datoshi]
/// MOD [8 datoshi]
/// DUP [2 datoshi]
/// PUSH0 [1 datoshi]
/// JMPGE 04 [2 datoshi]
/// JMP 08 [2 datoshi]
/// DUP [2 datoshi]
/// PUSHINT16 FF00 [1 datoshi]
/// JMPLE 06 [2 datoshi]
/// PUSHINT16 FF00 [1 datoshi]
/// AND [8 datoshi]
/// TUCK [2 datoshi]
/// PUSH0 [1 datoshi]
/// SWAP [2 datoshi]
/// SETITEM [8192 datoshi]
/// DROP [2 datoshi]
/// LDLOC0 [2 datoshi]
/// PUSH0 [1 datoshi]
/// PICKITEM [64 datoshi]
/// PUSH1 [1 datoshi]
/// EQUAL [32 datoshi]
/// ASSERT [1 datoshi]
/// LDLOC0 [2 datoshi]
/// PUSH1 [1 datoshi]
/// PICKITEM [64 datoshi]
/// PUSH3 [1 datoshi]
/// OVER [2 datoshi]
/// OVER [2 datoshi]
/// PICKITEM [64 datoshi]
/// PUSH4 [1 datoshi]
/// AND [8 datoshi]
/// DUP [2 datoshi]
/// PUSH0 [1 datoshi]
/// JMPGE 04 [2 datoshi]
/// JMP 08 [2 datoshi]
/// DUP [2 datoshi]
/// PUSHINT16 FF00 [1 datoshi]
/// JMPLE 06 [2 datoshi]
/// PUSHINT16 FF00 [1 datoshi]
/// AND [8 datoshi]
/// DUP [2 datoshi]
/// REVERSE4 [2 datoshi]
/// REVERSE3 [2 datoshi]
/// SETITEM [8192 datoshi]
/// DROP [2 datoshi]
/// LDLOC0 [2 datoshi]
/// PUSH1 [1 datoshi]
/// PICKITEM [64 datoshi]
/// PUSH0 [1 datoshi]
/// PICKITEM [64 datoshi]
/// PUSH0 [1 datoshi]
/// EQUAL [32 datoshi]
/// ASSERT [1 datoshi]
/// RET [0 datoshi]
/// </remarks>
[DisplayName("unitTest_Member_Element_Complex_Assign")]
public abstract void UnitTest_Member_Element_Complex_Assign();

/// <summary>
/// Unsafe method
/// </summary>
Expand Down
Loading
Loading