Skip to content

Commit

Permalink
fix 309 (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawnYun authored Aug 26, 2020
1 parent 6dabc1f commit 792e1d3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Neo.Compiler.MSIL/MSIL/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mono.Cecil.CustomAttribute> ca = ev.CustomAttributes;
to.lastsfieldname = d.Name;
foreach (var attr in ca)
Expand All @@ -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 });
Expand Down
Original file line number Diff line number Diff line change
@@ -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<byte[]> 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;
}
}
}
19 changes: 19 additions & 0 deletions tests/Neo.Compiler.MSIL.UnitTests/UnitTest_StaticByteArray.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit 792e1d3

Please sign in to comment.