From 792e1d30af3c7780d254639b7078f4fa3385d422 Mon Sep 17 00:00:00 2001 From: ShawnYun Date: Wed, 26 Aug 2020 19:06:37 +0800 Subject: [PATCH] fix 309 (#341) --- src/Neo.Compiler.MSIL/MSIL/Converter.cs | 5 +++-- .../TestClasses/Contract_StaticByteArray.cs | 19 +++++++++++++++++++ .../UnitTest_StaticByteArray.cs | 19 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_StaticByteArray.cs create mode 100644 tests/Neo.Compiler.MSIL.UnitTests/UnitTest_StaticByteArray.cs diff --git a/src/Neo.Compiler.MSIL/MSIL/Converter.cs b/src/Neo.Compiler.MSIL/MSIL/Converter.cs index eabd44400..dff61484f 100644 --- a/src/Neo.Compiler.MSIL/MSIL/Converter.cs +++ b/src/Neo.Compiler.MSIL/MSIL/Converter.cs @@ -953,13 +953,14 @@ private int ConvertCode(ILMethod method, OpCode src, NeoMethod to) } //If this code was called by event, just find its name + var findEventFlag = false; if (d.DeclaringType.HasEvents) { foreach (var ev in d.DeclaringType.Events) { if (ev.FullName == d.FullName && ev.EventType.FullName == d.FieldType.FullName) { - + findEventFlag = true; Mono.Collections.Generic.Collection ca = ev.CustomAttributes; to.lastsfieldname = d.Name; foreach (var attr in ca) @@ -973,7 +974,7 @@ private int ConvertCode(ILMethod method, OpCode src, NeoMethod to) } } } - else + if (!findEventFlag) { var field = this.outModule.mapFields[d.FullName]; Convert1by1(VM.OpCode.LDSFLD, src, to, new byte[] { (byte)field.index }); diff --git a/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_StaticByteArray.cs b/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_StaticByteArray.cs new file mode 100644 index 000000000..3ae6f5898 --- /dev/null +++ b/tests/Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_StaticByteArray.cs @@ -0,0 +1,19 @@ +using System; +using System.ComponentModel; +using System.Numerics; + +namespace Neo.Compiler.MSIL.TestClasses +{ + class Contract_StaticByteArray : SmartContract.Framework.SmartContract + { + [DisplayName("TestEvent")] + public static event Action OnEvent; + + static byte[] NeoToken = new byte[] { 0x89, 0x77, 0x20, 0xd8, 0xcd, 0x76, 0xf4, 0xf0, 0x0a, 0xbf, 0xa3, 0x7c, 0x0e, 0xdd, 0x88, 0x9c, 0x20, 0x8f, 0xde, 0x9b }; + + public static byte[] TestStaticByteArray() + { + return NeoToken; + } + } +} diff --git a/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_StaticByteArray.cs b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_StaticByteArray.cs new file mode 100644 index 000000000..9c2103605 --- /dev/null +++ b/tests/Neo.Compiler.MSIL.UnitTests/UnitTest_StaticByteArray.cs @@ -0,0 +1,19 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Neo.Compiler.MSIL.UnitTests.Utils; + +namespace Neo.Compiler.MSIL.UnitTests +{ + [TestClass] + public class UnitTest_StaticByteArray + { + [TestMethod] + public void TestStaticByteArray() + { + var testengine = new TestEngine(); + testengine.AddEntryScript("./TestClasses/Contract_StaticByteArray.cs"); + var result = testengine.ExecuteTestCaseStandard("testStaticByteArray").Pop(); + var wantResult = new byte[] { 0x89, 0x77, 0x20, 0xd8, 0xcd, 0x76, 0xf4, 0xf0, 0x0a, 0xbf, 0xa3, 0x7c, 0x0e, 0xdd, 0x88, 0x9c, 0x20, 0x8f, 0xde, 0x9b }; + Assert.AreEqual(wantResult, result); + } + } +}