Skip to content

Commit

Permalink
Remove iterator wrappers (#2439)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang authored Apr 18, 2021
1 parent 116bc24 commit eed9087
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 320 deletions.
26 changes: 0 additions & 26 deletions src/neo/SmartContract/ApplicationEngine.Iterator.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
using Neo.SmartContract.Iterators;
using Neo.VM.Types;
using System;
using Array = Neo.VM.Types.Array;

namespace Neo.SmartContract
{
partial class ApplicationEngine
{
/// <summary>
/// The <see cref="InteropDescriptor"/> of System.Iterator.Create.
/// Creates an <see cref="IIterator"/> with the specified <see cref="StackItem"/>.
/// </summary>
public static readonly InteropDescriptor System_Iterator_Create = Register("System.Iterator.Create", nameof(CreateIterator), 1 << 4, CallFlags.None);

/// <summary>
/// The <see cref="InteropDescriptor"/> of System.Iterator.Next.
/// Advances the iterator to the next element of the collection.
Expand All @@ -25,24 +17,6 @@ partial class ApplicationEngine
/// </summary>
public static readonly InteropDescriptor System_Iterator_Value = Register("System.Iterator.Value", nameof(IteratorValue), 1 << 4, CallFlags.None);

/// <summary>
/// The implementation of System.Iterator.Create.
/// Creates an <see cref="IIterator"/> with the specified <see cref="StackItem"/>.
/// </summary>
/// <param name="item">The <see cref="StackItem"/> wrapped by the iterator.</param>
/// <returns>The created iterator.</returns>
protected internal IIterator CreateIterator(StackItem item)
{
return item switch
{
Array array => new ArrayWrapper(array),
Map map => new MapWrapper(map, ReferenceCounter),
VM.Types.Buffer buffer => new ByteArrayWrapper(buffer),
PrimitiveType primitive => new ByteArrayWrapper(primitive),
_ => throw new ArgumentException(null, nameof(item))
};
}

/// <summary>
/// The implementation of System.Iterator.Next.
/// Advances the iterator to the next element of the collection.
Expand Down
37 changes: 0 additions & 37 deletions src/neo/SmartContract/Iterators/ArrayWrapper.cs

This file was deleted.

39 changes: 0 additions & 39 deletions src/neo/SmartContract/Iterators/ByteArrayWrapper.cs

This file was deleted.

33 changes: 0 additions & 33 deletions src/neo/SmartContract/Iterators/MapWrapper.cs

This file was deleted.

46 changes: 0 additions & 46 deletions tests/neo.UnitTests/SmartContract/Iterators/UT_ArrayWrapper.cs

This file was deleted.

43 changes: 0 additions & 43 deletions tests/neo.UnitTests/SmartContract/Iterators/UT_MapWrapper.cs

This file was deleted.

44 changes: 0 additions & 44 deletions tests/neo.UnitTests/SmartContract/Iterators/UT_PrimitiveWrapper.cs

This file was deleted.

52 changes: 0 additions & 52 deletions tests/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
using Neo.Network.P2P;
using Neo.Network.P2P.Payloads;
using Neo.SmartContract;
using Neo.SmartContract.Iterators;
using Neo.SmartContract.Manifest;
using Neo.SmartContract.Native;
using Neo.UnitTests.Extensions;
using Neo.VM;
using Neo.VM.Types;
using Neo.Wallets;
using System;
using System.Linq;
using VMArray = Neo.VM.Types.Array;

namespace Neo.UnitTests.SmartContract
{
Expand Down Expand Up @@ -256,54 +253,5 @@ public void TestStorage_Find()
var ele = iterator.Value();
ele.GetSpan().ToHexString().Should().Be(storageItem.Value.ToHexString());
}

[TestMethod]
public void TestIterator_Next()
{
var arr = new VMArray {
new byte[]{ 0x01 },
new byte[]{ 0x02 }
};
ApplicationEngine.IteratorNext(new ArrayWrapper(arr)).Should().BeTrue();
}

[TestMethod]
public void TestIterator_Value()
{
var arr = new VMArray {
new byte[]{ 0x01 },
new byte[]{ 0x02 }
};
var wrapper = new ArrayWrapper(arr);
wrapper.Next();
ApplicationEngine.IteratorValue(wrapper).GetSpan().ToHexString().Should().Be(new byte[] { 0x01 }.ToHexString());
}

[TestMethod]
public void TestIterator_Create()
{
var engine = GetEngine();
var arr = new VMArray {
new byte[]{ 0x01 },
new byte[]{ 0x02 }
};
var ret = engine.CreateIterator(arr);
ret.Next();
ret.Value().GetSpan().ToHexString().Should().Be(new byte[] { 0x01 }.ToHexString());

var interop = new InteropInterface(1);
Assert.ThrowsException<ArgumentException>(() => engine.CreateIterator(interop));

var map = new Map
{
[1] = 2,
[3] = 4
};
ret = engine.CreateIterator(map);
ret.Next();
Struct @struct = (Struct)ret.Value();
@struct[0].GetInteger().Should().Be(1);
@struct[1].GetInteger().Should().Be(2);
}
}
}

0 comments on commit eed9087

Please sign in to comment.