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

Limit notifications #2747

Merged
merged 10 commits into from
May 24, 2022
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
2 changes: 1 addition & 1 deletion src/neo/SmartContract/ApplicationEngine.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ protected internal void RuntimeNotify(byte[] eventName, Array state)
/// <param name="state">The arguments of the event.</param>
protected internal void SendNotification(UInt160 hash, string eventName, Array state)
{
NotifyEventArgs notification = new(ScriptContainer, hash, eventName, (Array)state.DeepCopy());
NotifyEventArgs notification = new(ScriptContainer, hash, eventName, (Array)state.DeepCopy(asImmutable: true));
Notify?.Invoke(this, notification);
notifications ??= new List<NotifyEventArgs>();
notifications.Add(notification);
Expand Down
2 changes: 1 addition & 1 deletion src/neo/SmartContract/NotifyEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public StackItem ToStackItem(ReferenceCounter referenceCounter)
{
ScriptHash.ToArray(),
EventName,
State.DeepCopy()
State
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/neo/neo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<PackageReference Include="BouncyCastle.NetCore" Version="1.8.10" />
<PackageReference Include="K4os.Compression.LZ4" Version="1.2.16" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.4" />
<PackageReference Include="Neo.VM" Version="3.2.0-CI00307" />
<PackageReference Include="Neo.VM" Version="3.2.0-CI00312" />
</ItemGroup>

</Project>
36 changes: 36 additions & 0 deletions tests/neo.UnitTests/SmartContract/UT_ApplicationEngine.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,42 @@ public void TestGetNetworkAndAddressVersion()
engine.GetAddressVersion().Should().Be(TestBlockchain.TheNeoSystem.Settings.AddressVersion);
}

[TestMethod]
public void TestNotSupportedNotification()
{
using var engine = ApplicationEngine.Create(TriggerType.Application, null, null, TestBlockchain.TheNeoSystem.GenesisBlock, settings: TestBlockchain.TheNeoSystem.Settings, gas: 1100_00000000);
engine.LoadScript(Array.Empty<byte>());

// circular

VM.Types.Array array = new();
array.Add(array);

Assert.ThrowsException<NotSupportedException>(() => engine.RuntimeNotify(new byte[] { 0x01 }, array));

// Buffer

array.Clear();
array.Add(new VM.Types.Buffer(1));

engine.RuntimeNotify(new byte[] { 0x01 }, array);
engine.Notifications[0].State[0].Type.Should().Be(VM.Types.StackItemType.ByteString);

// Pointer

array.Clear();
array.Add(new VM.Types.Pointer(Array.Empty<byte>(), 1));

Assert.ThrowsException<NotSupportedException>(() => engine.RuntimeNotify(new byte[] { 0x01 }, array));

// InteropInterface

array.Clear();
array.Add(new VM.Types.InteropInterface(new object()));

Assert.ThrowsException<NotSupportedException>(() => engine.RuntimeNotify(new byte[] { 0x01 }, array));
}

[TestMethod]
public void TestGetRandomSameBlock()
{
Expand Down