diff --git a/examples/Example.SmartContract.Transfer/TransferContract.cs b/examples/Example.SmartContract.Transfer/TransferContract.cs
index 237aafa93..2d72165b1 100644
--- a/examples/Example.SmartContract.Transfer/TransferContract.cs
+++ b/examples/Example.SmartContract.Transfer/TransferContract.cs
@@ -31,8 +31,8 @@ namespace Transfer;
[ContractPermission(Permission.WildCard, Method.WildCard)]
public class TransferContract : SmartContract
{
- [Hash160("NUuJw4C4XJFzxAvSZnFTfsNoWZytmQKXQP")]
- private static readonly UInt160 Owner = default;
+ // [Hash160("NUuJw4C4XJFzxAvSZnFTfsNoWZytmQKXQP")]
+ private static readonly UInt160 Owner = "NUuJw4C4XJFzxAvSZnFTfsNoWZytmQKXQP";
///
/// Transfer method that demonstrate how to transfer NEO and GAS
diff --git a/src/Neo.Compiler.CSharp/MethodConvert/Expression/Expression.cs b/src/Neo.Compiler.CSharp/MethodConvert/Expression/Expression.cs
index 89ae863de..b317ddf7c 100644
--- a/src/Neo.Compiler.CSharp/MethodConvert/Expression/Expression.cs
+++ b/src/Neo.Compiler.CSharp/MethodConvert/Expression/Expression.cs
@@ -15,19 +15,67 @@
using Neo.SmartContract.Native;
using Neo.VM;
using System.Numerics;
+using Neo.Cryptography.ECC;
+using Neo.IO;
+using Neo.Wallets;
namespace Neo.Compiler;
partial class MethodConvert
{
- private void ConvertExpression(SemanticModel model, ExpressionSyntax syntax)
+ private void ConvertExpression(SemanticModel model, ExpressionSyntax syntax, SyntaxNode? syntaxNode = null)
{
using var sequence = InsertSequencePoint(syntax);
Optional
- [PublicKey("024700db2e90d9f02c4f9fc862abaca92725f95b4fddcc8d7ffa538693ecf463a9")]
- private static readonly ECPoint eCPoint = default;
+ // [PublicKey("024700db2e90d9f02c4f9fc862abaca92725f95b4fddcc8d7ffa538693ecf463a9")]
+ private static readonly ECPoint eCPoint = "024700db2e90d9f02c4f9fc862abaca92725f95b4fddcc8d7ffa538693ecf463a9";
///
/// A static field of type UInt160 initialized with the InitialValue attribute. This allows for compile-time
/// initialization of blockchain-specific types like addresses, represented here as Hash160.
///
- [Hash160("NXV7ZhHiyM1aHXwpVsRZC6BwNFP2jghXAq")]
- private static readonly UInt160 uInt160 = default;
+ // [Hash160("NXV7ZhHiyM1aHXwpVsRZC6BwNFP2jghXAq")]
+ private static readonly UInt160 uInt160 = "NXV7ZhHiyM1aHXwpVsRZC6BwNFP2jghXAq";
///
/// A static string field initialized with the InitialValue attribute. This demonstrates initializing contract fields that cannot be directly assigned with their value at compile time.
///
- [String("hello world")]
- public static readonly string a4 = default;
+ // [String("hello world")]
+ public static readonly string a4 = "hello world";
///
/// Tests retrieval of the static field initialized with an initial value.
@@ -82,5 +82,10 @@ public static ECPoint testGetECPoint()
{
return eCPoint;
}
+
+ public static string testGetString()
+ {
+ return a4;
+ }
}
}
diff --git a/tests/Neo.Compiler.CSharp.TestContracts/Contract_StaticVarInit.cs b/tests/Neo.Compiler.CSharp.TestContracts/Contract_StaticVarInit.cs
index e94c79044..606dc6721 100644
--- a/tests/Neo.Compiler.CSharp.TestContracts/Contract_StaticVarInit.cs
+++ b/tests/Neo.Compiler.CSharp.TestContracts/Contract_StaticVarInit.cs
@@ -4,7 +4,7 @@ namespace Neo.Compiler.CSharp.UnitTests.TestClasses
{
public class Contract_staticvar : SmartContract.Framework.SmartContract
{
- //define and staticvar and initit with a runtime code.
+ //define and static var and init it with a runtime code.
static byte[] callscript = (byte[])Runtime.EntryScriptHash;
public static object StaticInit()
diff --git a/tests/Neo.Compiler.CSharp.TestContracts/Contract_TryCatch.cs b/tests/Neo.Compiler.CSharp.TestContracts/Contract_TryCatch.cs
index 681b735d2..e3663bb4c 100644
--- a/tests/Neo.Compiler.CSharp.TestContracts/Contract_TryCatch.cs
+++ b/tests/Neo.Compiler.CSharp.TestContracts/Contract_TryCatch.cs
@@ -11,8 +11,8 @@ public class Contract_TryCatch : SmartContract.Framework.SmartContract
private static readonly ByteString byteString2Ecpoint = default;
[Hash160("NXV7ZhHiyM1aHXwpVsRZC6BwNFP2jghXAq")]
private static readonly ByteString validUInt160 = default;
- [ByteArray("edcf8679104ec2911a4fe29ad7db232a493e5b990fb1da7af0c7b989948c8925")]
- private static readonly byte[] validUInt256 = default;
+ // [ByteArray("edcf8679104ec2911a4fe29ad7db232a493e5b990fb1da7af0c7b989948c8925")]
+ private static readonly UInt256 validUInt256 = "edcf8679104ec2911a4fe29ad7db232a493e5b990fb1da7af0c7b989948c8925";
public static object try01()
{
int v = 0;
diff --git a/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_DirectInit.cs b/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_DirectInit.cs
new file mode 100644
index 000000000..75ae8cf96
--- /dev/null
+++ b/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_DirectInit.cs
@@ -0,0 +1,55 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Neo.VM.Types;
+using System;
+using Neo.SmartContract.TestEngine;
+
+namespace Neo.Compiler.CSharp.UnitTests
+{
+ [TestClass]
+ public class UnitTest_DirectInit
+ {
+
+ [TestMethod]
+ public void Test_GetUInt160()
+ {
+ using var testengine = new TestEngine(snapshot: new TestDataCache());
+ testengine.AddEntryScript(Utils.Extensions.TestContractRoot + "Contract_DirectInit.cs");
+ var result = testengine.ExecuteTestCaseStandard("testGetUInt160");
+ var value = result.Pop().GetSpan();
+
+ Assert.AreEqual(value.ToArray().ToHexString(), "7eee1aabeb67ed1d791d44e4f5fcf3ae9171a871");
+ }
+
+ [TestMethod]
+ public void Test_GetECPoint()
+ {
+ using var testengine = new TestEngine(snapshot: new TestDataCache());
+ testengine.AddEntryScript(Utils.Extensions.TestContractRoot + "Contract_DirectInit.cs");
+ var result = testengine.ExecuteTestCaseStandard("testGetECPoint");
+ var value = result.Pop().GetSpan();
+ Assert.AreEqual(value.ToHexString(), "024700db2e90d9f02c4f9fc862abaca92725f95b4fddcc8d7ffa538693ecf463a9");
+ }
+
+ [TestMethod]
+ public void Test_GetUInt256()
+ {
+ using var testengine = new TestEngine(snapshot: new TestDataCache());
+ testengine.AddEntryScript(Utils.Extensions.TestContractRoot + "Contract_DirectInit.cs");
+ var result = testengine.ExecuteTestCaseStandard("testGetUInt256");
+ var value = result.Pop().GetSpan();
+
+ Assert.AreEqual(value.ToArray().ToHexString(), "edcf8679104ec2911a4fe29ad7db232a493e5b990fb1da7af0c7b989948c8925");
+ }
+
+ [TestMethod]
+ public void Test_GetString()
+ {
+ using var testengine = new TestEngine(snapshot: new TestDataCache());
+ testengine.AddEntryScript(Utils.Extensions.TestContractRoot + "Contract_DirectInit.cs");
+ var result = testengine.ExecuteTestCaseStandard("testGetString");
+ var value = result.Pop().GetString();
+
+ Assert.AreEqual(value, "hello world");
+ }
+ }
+}
diff --git a/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_StaticVar.cs b/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_StaticVar.cs
index e8fe8c405..0fdf92a11 100644
--- a/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_StaticVar.cs
+++ b/tests/Neo.Compiler.CSharp.UnitTests/UnitTest_StaticVar.cs
@@ -124,5 +124,16 @@ public void Test_GetECPoint()
Assert.AreEqual(value.ToArray().ToHexString(), "024700db2e90d9f02c4f9fc862abaca92725f95b4fddcc8d7ffa538693ecf463a9");
}
+
+ [TestMethod]
+ public void Test_GetString()
+ {
+ using var testengine = new TestEngine(snapshot: new TestDataCache());
+ testengine.AddEntryScript(Utils.Extensions.TestContractRoot + "Contract_StaticVar.cs");
+ var result = testengine.ExecuteTestCaseStandard("testGetString");
+ var value = result.Pop().GetString();
+
+ Assert.AreEqual(value, "hello world");
+ }
}
}