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

Fix 309 #341

Merged
merged 2 commits into from
Aug 26, 2020
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
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);
}
}
}