Skip to content

Commit

Permalink
UT seems it changed
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon committed Nov 22, 2024
1 parent 862fa78 commit 0569d1a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ indent_size = 2
[*.{cs,vb}]
# Use block-scoped namespace
csharp_style_namespace_declarations = block_scoped:error
dotnet_diagnostic.CA2265.severity = none
dotnet_diagnostic.IDE0160.severity = error
dotnet_diagnostic.IDE0161.severity = error

Expand Down
3 changes: 1 addition & 2 deletions src/Neo.VM/ScriptBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ public ScriptBuilder EmitPush(bool value)
/// <returns>A reference to this instance after the emit operation has completed.</returns>
public ScriptBuilder EmitPush(ReadOnlySpan<byte> data)
{
if (data == null)
if (data == null) // IsEmpty also throw null

Check warning on line 129 in src/Neo.VM/ScriptBuilder.cs

View workflow job for this annotation

GitHub Actions / Format

Comparing a span to 'null' might be redundant, the 'null' literal will be implicitly converted to a 'Span<T>.Empty'
throw new ArgumentNullException(nameof(data));

if (data.Length < 0x100)
{
Emit(OpCode.PUSHDATA1);
Expand Down
17 changes: 17 additions & 0 deletions tests/Neo.VM.Tests/UT_ScriptBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ public void TestEmit()
}
}

[TestMethod]
public void TestNullAndEmpty()
{
using (ScriptBuilder script = new())
{
Assert.ThrowsException<ArgumentNullException>(() =>
{
ReadOnlySpan<byte> span = null;
script.EmitPush(span);
});

ReadOnlySpan<byte> span = [];
script.EmitPush(span);
CollectionAssert.AreEqual(new byte[] { (byte)OpCode.PUSHDATA1, 0 }, script.ToArray());
}
}

[TestMethod]
public void TestBigInteger()
{
Expand Down

0 comments on commit 0569d1a

Please sign in to comment.