diff --git a/src/neo/IO/Helper.cs b/src/neo/IO/Helper.cs index 531ce4827d..3acc4b2c2f 100644 --- a/src/neo/IO/Helper.cs +++ b/src/neo/IO/Helper.cs @@ -89,6 +89,16 @@ public static byte[] DecompressLz4(this byte[] data, int maxOutput) return result; } + public static void FillBuffer(this BinaryReader reader, Span buffer) + { + while (!buffer.IsEmpty) + { + int count = reader.Read(buffer); + if (count == 0) throw new EndOfStreamException(); + buffer = buffer[count..]; + } + } + public static int GetVarSize(int value) { if (value < 0xFD) diff --git a/src/neo/SmartContract/ApplicationEngine.OpCodePrices.cs b/src/neo/SmartContract/ApplicationEngine.OpCodePrices.cs index f9b04527f6..29552e4397 100644 --- a/src/neo/SmartContract/ApplicationEngine.OpCodePrices.cs +++ b/src/neo/SmartContract/ApplicationEngine.OpCodePrices.cs @@ -78,28 +78,73 @@ partial class ApplicationEngine [OpCode.REVERSE3] = 60, [OpCode.REVERSE4] = 60, [OpCode.REVERSEN] = 400, - [OpCode.TOALTSTACK] = 60, - [OpCode.FROMALTSTACK] = 60, - [OpCode.DUPFROMALTSTACK] = 60, - [OpCode.DUPFROMALTSTACKBOTTOM] = 60, - [OpCode.ISNULL] = 60, + [OpCode.INITSSLOT] = 400, + [OpCode.INITSLOT] = 800, + [OpCode.LDSFLD0] = 60, + [OpCode.LDSFLD1] = 60, + [OpCode.LDSFLD2] = 60, + [OpCode.LDSFLD3] = 60, + [OpCode.LDSFLD4] = 60, + [OpCode.LDSFLD5] = 60, + [OpCode.LDSFLD6] = 60, + [OpCode.LDSFLD] = 60, + [OpCode.STSFLD0] = 60, + [OpCode.STSFLD1] = 60, + [OpCode.STSFLD2] = 60, + [OpCode.STSFLD3] = 60, + [OpCode.STSFLD4] = 60, + [OpCode.STSFLD5] = 60, + [OpCode.STSFLD6] = 60, + [OpCode.STSFLD] = 60, + [OpCode.LDLOC0] = 60, + [OpCode.LDLOC1] = 60, + [OpCode.LDLOC2] = 60, + [OpCode.LDLOC3] = 60, + [OpCode.LDLOC4] = 60, + [OpCode.LDLOC5] = 60, + [OpCode.LDLOC6] = 60, + [OpCode.LDLOC] = 60, + [OpCode.STLOC0] = 60, + [OpCode.STLOC1] = 60, + [OpCode.STLOC2] = 60, + [OpCode.STLOC3] = 60, + [OpCode.STLOC4] = 60, + [OpCode.STLOC5] = 60, + [OpCode.STLOC6] = 60, + [OpCode.STLOC] = 60, + [OpCode.LDARG0] = 60, + [OpCode.LDARG1] = 60, + [OpCode.LDARG2] = 60, + [OpCode.LDARG3] = 60, + [OpCode.LDARG4] = 60, + [OpCode.LDARG5] = 60, + [OpCode.LDARG6] = 60, + [OpCode.LDARG] = 60, + [OpCode.STARG0] = 60, + [OpCode.STARG1] = 60, + [OpCode.STARG2] = 60, + [OpCode.STARG3] = 60, + [OpCode.STARG4] = 60, + [OpCode.STARG5] = 60, + [OpCode.STARG6] = 60, + [OpCode.STARG] = 60, + [OpCode.NEWBUFFER] = 80000, + [OpCode.MEMCPY] = 80000, [OpCode.CAT] = 80000, [OpCode.SUBSTR] = 80000, [OpCode.LEFT] = 80000, [OpCode.RIGHT] = 80000, - [OpCode.SIZE] = 60, [OpCode.INVERT] = 100, [OpCode.AND] = 200, [OpCode.OR] = 200, [OpCode.XOR] = 200, [OpCode.EQUAL] = 200, - [OpCode.INC] = 100, - [OpCode.DEC] = 100, + [OpCode.NOTEQUAL] = 200, [OpCode.SIGN] = 100, - [OpCode.NEGATE] = 100, [OpCode.ABS] = 100, - [OpCode.NOT] = 100, - [OpCode.NZ] = 100, + [OpCode.NEGATE] = 100, + [OpCode.INC] = 100, + [OpCode.DEC] = 100, [OpCode.ADD] = 200, [OpCode.SUB] = 200, [OpCode.MUL] = 300, @@ -107,31 +152,40 @@ partial class ApplicationEngine [OpCode.MOD] = 300, [OpCode.SHL] = 300, [OpCode.SHR] = 300, + [OpCode.NOT] = 100, [OpCode.BOOLAND] = 200, [OpCode.BOOLOR] = 200, + [OpCode.NZ] = 100, [OpCode.NUMEQUAL] = 200, [OpCode.NUMNOTEQUAL] = 200, [OpCode.LT] = 200, + [OpCode.LE] = 200, [OpCode.GT] = 200, - [OpCode.LTE] = 200, - [OpCode.GTE] = 200, + [OpCode.GE] = 200, [OpCode.MIN] = 200, [OpCode.MAX] = 200, [OpCode.WITHIN] = 200, - [OpCode.ARRAYSIZE] = 150, [OpCode.PACK] = 7000, [OpCode.UNPACK] = 7000, - [OpCode.PICKITEM] = 270000, - [OpCode.SETITEM] = 270000, + [OpCode.NEWARRAY0] = 400, [OpCode.NEWARRAY] = 15000, + [OpCode.NEWARRAY_T] = 15000, + [OpCode.NEWSTRUCT0] = 400, [OpCode.NEWSTRUCT] = 15000, [OpCode.NEWMAP] = 200, - [OpCode.APPEND] = 15000, - [OpCode.REVERSE] = 500, - [OpCode.REMOVE] = 500, + [OpCode.SIZE] = 150, [OpCode.HASKEY] = 270000, [OpCode.KEYS] = 500, [OpCode.VALUES] = 7000, + [OpCode.PICKITEM] = 270000, + [OpCode.APPEND] = 15000, + [OpCode.SETITEM] = 270000, + [OpCode.REVERSEITEMS] = 500, + [OpCode.REMOVE] = 500, + [OpCode.CLEARITEMS] = 400, + [OpCode.ISNULL] = 60, + [OpCode.ISTYPE] = 60, + [OpCode.CONVERT] = 80000, }; } } diff --git a/src/neo/SmartContract/ApplicationEngine.cs b/src/neo/SmartContract/ApplicationEngine.cs index 29a8d9a414..53bc8c68a8 100644 --- a/src/neo/SmartContract/ApplicationEngine.cs +++ b/src/neo/SmartContract/ApplicationEngine.cs @@ -5,6 +5,7 @@ using Neo.VM.Types; using System; using System.Collections.Generic; +using System.Text; using Array = System.Array; namespace Neo.SmartContract @@ -140,5 +141,19 @@ internal void SendNotification(UInt160 script_hash, StackItem state) Notify?.Invoke(this, notification); notifications.Add(notification); } + + public bool TryPop(out string s) + { + if (TryPop(out ReadOnlySpan b)) + { + s = Encoding.UTF8.GetString(b); + return true; + } + else + { + s = default; + return false; + } + } } } diff --git a/src/neo/SmartContract/BinarySerializer.cs b/src/neo/SmartContract/BinarySerializer.cs index 1c8f2f9088..3f4d9b44bd 100644 --- a/src/neo/SmartContract/BinarySerializer.cs +++ b/src/neo/SmartContract/BinarySerializer.cs @@ -8,30 +8,31 @@ using System.Numerics; using Array = Neo.VM.Types.Array; using Boolean = Neo.VM.Types.Boolean; +using Buffer = Neo.VM.Types.Buffer; namespace Neo.SmartContract { internal static class BinarySerializer { - public static StackItem Deserialize(byte[] data, uint maxItemSize, ReferenceCounter referenceCounter = null) + public static StackItem Deserialize(byte[] data, uint maxArraySize, uint maxItemSize, ReferenceCounter referenceCounter = null) { using MemoryStream ms = new MemoryStream(data, false); using BinaryReader reader = new BinaryReader(ms); - return Deserialize(reader, maxItemSize, referenceCounter); + return Deserialize(reader, maxArraySize, maxItemSize, referenceCounter); } - public static unsafe StackItem Deserialize(ReadOnlySpan data, uint maxItemSize, ReferenceCounter referenceCounter = null) + public static unsafe StackItem Deserialize(ReadOnlySpan data, uint maxArraySize, uint maxItemSize, ReferenceCounter referenceCounter = null) { if (data.IsEmpty) throw new FormatException(); fixed (byte* pointer = data) { using UnmanagedMemoryStream ms = new UnmanagedMemoryStream(pointer, data.Length); using BinaryReader reader = new BinaryReader(ms); - return Deserialize(reader, maxItemSize, referenceCounter); + return Deserialize(reader, maxArraySize, maxItemSize, referenceCounter); } } - private static StackItem Deserialize(BinaryReader reader, uint maxItemSize, ReferenceCounter referenceCounter) + private static StackItem Deserialize(BinaryReader reader, uint maxArraySize, uint maxItemSize, ReferenceCounter referenceCounter) { Stack deserialized = new Stack(); int undeserialized = 1; @@ -40,41 +41,38 @@ private static StackItem Deserialize(BinaryReader reader, uint maxItemSize, Refe StackItemType type = (StackItemType)reader.ReadByte(); switch (type) { - case StackItemType.ByteArray: - deserialized.Push(new ByteArray(reader.ReadVarBytes((int)maxItemSize))); + case StackItemType.Any: + deserialized.Push(StackItem.Null); break; case StackItemType.Boolean: - deserialized.Push(new Boolean(reader.ReadBoolean())); + deserialized.Push(reader.ReadBoolean()); break; case StackItemType.Integer: - deserialized.Push(new Integer(new BigInteger(reader.ReadVarBytes(Integer.MaxSize)))); + deserialized.Push(new BigInteger(reader.ReadVarBytes(Integer.MaxSize))); + break; + case StackItemType.ByteArray: + deserialized.Push(reader.ReadVarBytes((int)maxItemSize)); + break; + case StackItemType.Buffer: + Buffer buffer = new Buffer((int)reader.ReadVarInt(maxItemSize)); + reader.FillBuffer(buffer.InnerBuffer); + deserialized.Push(buffer); break; case StackItemType.Array: case StackItemType.Struct: { - int count = (int)reader.ReadVarInt(maxItemSize); - deserialized.Push(new ContainerPlaceholder - { - Type = type, - ElementCount = count - }); + int count = (int)reader.ReadVarInt(maxArraySize); + deserialized.Push(new ContainerPlaceholder(type, count)); undeserialized += count; } break; case StackItemType.Map: { - int count = (int)reader.ReadVarInt(maxItemSize); - deserialized.Push(new ContainerPlaceholder - { - Type = type, - ElementCount = count - }); + int count = (int)reader.ReadVarInt(maxArraySize); + deserialized.Push(new ContainerPlaceholder(type, count)); undeserialized += count * 2; } break; - case StackItemType.Null: - deserialized.Push(StackItem.Null); - break; default: throw new FormatException(); } @@ -127,36 +125,33 @@ public static byte[] Serialize(StackItem item, uint maxSize) private static void Serialize(StackItem item, BinaryWriter writer, uint maxSize) { - List serialized = new List(); + List serialized = new List(); Stack unserialized = new Stack(); unserialized.Push(item); while (unserialized.Count > 0) { item = unserialized.Pop(); + writer.Write((byte)item.Type); switch (item) { - case ByteArray bytes: - writer.Write((byte)StackItemType.ByteArray); - writer.WriteVarBytes(bytes.ToByteArray()); + case Null _: break; case Boolean _: - writer.Write((byte)StackItemType.Boolean); writer.Write(item.ToBoolean()); break; case Integer integer: - writer.Write((byte)StackItemType.Integer); - writer.WriteVarBytes(integer.ToByteArray()); + writer.WriteVarBytes(integer.Span); + break; + case ByteArray bytes: + writer.WriteVarBytes(bytes.Span); + break; + case Buffer buffer: + writer.WriteVarBytes(buffer.InnerBuffer); break; - case InteropInterface _: - throw new NotSupportedException(); case Array array: if (serialized.Any(p => ReferenceEquals(p, array))) throw new NotSupportedException(); serialized.Add(array); - if (array is Struct) - writer.Write((byte)StackItemType.Struct); - else - writer.Write((byte)StackItemType.Array); writer.WriteVarInt(array.Count); for (int i = array.Count - 1; i >= 0; i--) unserialized.Push(array[i]); @@ -165,7 +160,6 @@ private static void Serialize(StackItem item, BinaryWriter writer, uint maxSize) if (serialized.Any(p => ReferenceEquals(p, map))) throw new NotSupportedException(); serialized.Add(map); - writer.Write((byte)StackItemType.Map); writer.WriteVarInt(map.Count); foreach (var pair in map.Reverse()) { @@ -173,9 +167,8 @@ private static void Serialize(StackItem item, BinaryWriter writer, uint maxSize) unserialized.Push(pair.Key); } break; - case Null _: - writer.Write((byte)StackItemType.Null); - break; + default: + throw new NotSupportedException(); } if (writer.BaseStream.Position > maxSize) throw new InvalidOperationException(); diff --git a/src/neo/SmartContract/ContainerPlaceholder.cs b/src/neo/SmartContract/ContainerPlaceholder.cs index 29fa0f6e6e..72eb68e48d 100644 --- a/src/neo/SmartContract/ContainerPlaceholder.cs +++ b/src/neo/SmartContract/ContainerPlaceholder.cs @@ -5,10 +5,16 @@ namespace Neo.SmartContract { internal class ContainerPlaceholder : StackItem { - public StackItemType Type; - public int ElementCount; + public override StackItemType Type { get; } + public int ElementCount { get; } - public override bool Equals(StackItem other) => throw new NotSupportedException(); + public ContainerPlaceholder(StackItemType type, int count) + { + Type = type; + ElementCount = count; + } + + public override bool Equals(object obj) => throw new NotSupportedException(); public override int GetHashCode() => throw new NotSupportedException(); diff --git a/src/neo/SmartContract/InteropService.Binary.cs b/src/neo/SmartContract/InteropService.Binary.cs index f2e2d22a7b..fa33dbe4ba 100644 --- a/src/neo/SmartContract/InteropService.Binary.cs +++ b/src/neo/SmartContract/InteropService.Binary.cs @@ -1,7 +1,5 @@ -using Neo.VM; using Neo.VM.Types; using System; -using System.IO; namespace Neo.SmartContract { @@ -29,19 +27,8 @@ private static bool Binary_Serialize(ApplicationEngine engine) private static bool Binary_Deserialize(ApplicationEngine engine) { - StackItem item; - try - { - item = BinarySerializer.Deserialize(engine.CurrentContext.EvaluationStack.Pop().GetSpan(), engine.MaxItemSize, engine.ReferenceCounter); - } - catch (FormatException) - { - return false; - } - catch (IOException) - { - return false; - } + if (!engine.TryPop(out ReadOnlySpan data)) return false; + StackItem item = BinarySerializer.Deserialize(data, engine.MaxStackSize, engine.MaxItemSize, engine.ReferenceCounter); engine.CurrentContext.EvaluationStack.Push(item); return true; } diff --git a/src/neo/SmartContract/Iterators/ByteArrayWrapper.cs b/src/neo/SmartContract/Iterators/ByteArrayWrapper.cs index d5baff7da0..c60c839543 100644 --- a/src/neo/SmartContract/Iterators/ByteArrayWrapper.cs +++ b/src/neo/SmartContract/Iterators/ByteArrayWrapper.cs @@ -10,7 +10,7 @@ internal class ByteArrayWrapper : IIterator public ByteArrayWrapper(PrimitiveType value) { - this.array = value.ToByteArray().ToArray(); + this.array = value.Span.ToArray(); } public void Dispose() { } diff --git a/src/neo/SmartContract/Native/NativeContract.cs b/src/neo/SmartContract/Native/NativeContract.cs index 17f053ddf8..60c1d6c8db 100644 --- a/src/neo/SmartContract/Native/NativeContract.cs +++ b/src/neo/SmartContract/Native/NativeContract.cs @@ -75,8 +75,7 @@ protected StorageKey CreateStorageKey(byte prefix, byte[] key = null) Key = new byte[sizeof(byte) + (key?.Length ?? 0)] }; storageKey.Key[0] = prefix; - if (key != null) - Buffer.BlockCopy(key, 0, storageKey.Key, 1, key.Length); + key?.CopyTo(storageKey.Key.AsSpan(1)); return storageKey; } diff --git a/src/neo/SmartContract/Native/Tokens/Nep5AccountState.cs b/src/neo/SmartContract/Native/Tokens/Nep5AccountState.cs index 76671d92c1..b2d62be6d1 100644 --- a/src/neo/SmartContract/Native/Tokens/Nep5AccountState.cs +++ b/src/neo/SmartContract/Native/Tokens/Nep5AccountState.cs @@ -19,7 +19,7 @@ public Nep5AccountState(byte[] data) public void FromByteArray(byte[] data) { - FromStruct((Struct)BinarySerializer.Deserialize(data, 34)); + FromStruct((Struct)BinarySerializer.Deserialize(data, 16, 34)); } protected virtual void FromStruct(Struct @struct) diff --git a/src/neo/SmartContract/StackItemType.cs b/src/neo/SmartContract/StackItemType.cs deleted file mode 100644 index 7e19c2982b..0000000000 --- a/src/neo/SmartContract/StackItemType.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Neo.SmartContract -{ - internal enum StackItemType : byte - { - ByteArray = 0x00, - Boolean = 0x01, - Integer = 0x02, - InteropInterface = 0x40, - Array = 0x80, - Struct = 0x81, - Map = 0x82, - Null = 0xff - } -} diff --git a/src/neo/VM/Helper.cs b/src/neo/VM/Helper.cs index 28dcb11904..83b4aaf3e2 100644 --- a/src/neo/VM/Helper.cs +++ b/src/neo/VM/Helper.cs @@ -9,6 +9,7 @@ using System.Text; using Array = Neo.VM.Types.Array; using Boolean = Neo.VM.Types.Boolean; +using Buffer = Neo.VM.Types.Buffer; namespace Neo.VM { @@ -175,16 +176,22 @@ public static BigInteger GetBigInteger(this StackItem item) public static int GetByteLength(this StackItem item) { - if (!(item is PrimitiveType primitive)) - throw new ArgumentException(); - return primitive.GetByteLength(); + return item switch + { + PrimitiveType p => p.Size, + Buffer b => b.Size, + _ => throw new ArgumentException(), + }; } public static ReadOnlySpan GetSpan(this StackItem item) { - if (!(item is PrimitiveType primitive)) - throw new ArgumentException(); - return primitive.ToByteArray(); + return item switch + { + PrimitiveType p => p.Span, + Buffer b => b.InnerBuffer, + _ => throw new ArgumentException(), + }; } public static string GetString(this StackItem item) @@ -252,18 +259,18 @@ private static ContractParameter ToParameter(StackItem item, List<(StackItem, Co Value = item.ToBoolean() }; break; - case ByteArray _: + case ByteArray array: parameter = new ContractParameter { Type = ContractParameterType.ByteArray, - Value = item.GetSpan().ToArray() + Value = array.Span.ToArray() }; break; - case Integer _: + case Integer i: parameter = new ContractParameter { Type = ContractParameterType.Integer, - Value = item.GetBigInteger() + Value = i.ToBigInteger() }; break; case InteropInterface _: @@ -278,7 +285,7 @@ private static ContractParameter ToParameter(StackItem item, List<(StackItem, Co Type = ContractParameterType.Any }; break; - default: // Null included + default: throw new ArgumentException(); } return parameter; diff --git a/src/neo/neo.csproj b/src/neo/neo.csproj index ebac81c4bc..075d17fb7f 100644 --- a/src/neo/neo.csproj +++ b/src/neo/neo.csproj @@ -27,7 +27,7 @@ - + diff --git a/tests/neo.UnitTests/SmartContract/Native/Tokens/UT_GasToken.cs b/tests/neo.UnitTests/SmartContract/Native/Tokens/UT_GasToken.cs index 2693a40690..51caa8db9c 100644 --- a/tests/neo.UnitTests/SmartContract/Native/Tokens/UT_GasToken.cs +++ b/tests/neo.UnitTests/SmartContract/Native/Tokens/UT_GasToken.cs @@ -165,10 +165,10 @@ public void TestGetSysFeeAmount2() StorageKey storageKey = new StorageKey { ScriptHash = NativeContract.GAS.Hash, - Key = new byte[sizeof(byte) + (key?.Length ?? 0)] + Key = new byte[sizeof(byte) + key.Length] }; storageKey.Key[0] = 15; - Buffer.BlockCopy(key, 0, storageKey.Key, 1, key.Length); + key.CopyTo(storageKey.Key.AsSpan(1)); BigInteger sys_fee = new BigInteger(10); snapshot.Storages.Add(storageKey, new StorageItem diff --git a/tests/neo.UnitTests/SmartContract/Native/Tokens/UT_NeoToken.cs b/tests/neo.UnitTests/SmartContract/Native/Tokens/UT_NeoToken.cs index 411a2139ca..6111c9b052 100644 --- a/tests/neo.UnitTests/SmartContract/Native/Tokens/UT_NeoToken.cs +++ b/tests/neo.UnitTests/SmartContract/Native/Tokens/UT_NeoToken.cs @@ -687,7 +687,7 @@ internal static void CheckValidator(ECPoint eCPoint, DataCache.Trackable trackable, BigInteger balance, BigInteger height, ECPoint[] votes) { - var st = (VM.Types.Struct)BinarySerializer.Deserialize(trackable.Item.Value, 32); + var st = (VM.Types.Struct)BinarySerializer.Deserialize(trackable.Item.Value, 16, 32); st.Count.Should().Be(3); st.Select(u => u.GetType()).ToArray().Should().BeEquivalentTo(new Type[] { typeof(VM.Types.Integer), typeof(VM.Types.Integer), typeof(VM.Types.ByteArray) }); // Balance @@ -708,8 +708,7 @@ internal static StorageKey CreateStorageKey(byte prefix, byte[] key = null) Key = new byte[sizeof(byte) + (key?.Length ?? 0)] }; storageKey.Key[0] = prefix; - if (key != null) - Buffer.BlockCopy(key, 0, storageKey.Key, 1, key.Length); + key?.CopyTo(storageKey.Key.AsSpan(1)); return storageKey; } } diff --git a/tests/neo.UnitTests/SmartContract/Native/Tokens/UT_Nep5Token.cs b/tests/neo.UnitTests/SmartContract/Native/Tokens/UT_Nep5Token.cs index 5e9dbe9617..3cb10defe3 100644 --- a/tests/neo.UnitTests/SmartContract/Native/Tokens/UT_Nep5Token.cs +++ b/tests/neo.UnitTests/SmartContract/Native/Tokens/UT_Nep5Token.cs @@ -82,8 +82,7 @@ public StorageKey CreateStorageKey(byte prefix, byte[] key = null) Key = new byte[sizeof(byte) + (key?.Length ?? 0)] }; storageKey.Key[0] = prefix; - if (key != null) - Buffer.BlockCopy(key, 0, storageKey.Key, 1, key.Length); + key?.CopyTo(storageKey.Key.AsSpan(1)); return storageKey; } } diff --git a/tests/neo.UnitTests/SmartContract/UT_BinarySerializer.cs b/tests/neo.UnitTests/SmartContract/UT_BinarySerializer.cs index 888af9a23a..39330334d9 100644 --- a/tests/neo.UnitTests/SmartContract/UT_BinarySerializer.cs +++ b/tests/neo.UnitTests/SmartContract/UT_BinarySerializer.cs @@ -19,38 +19,31 @@ public void TestSerialize() { byte[] result1 = BinarySerializer.Serialize(new byte[5], MaxItemSize); byte[] expectedArray1 = new byte[] { - 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00 + 0x28, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00 }; Assert.AreEqual(Encoding.Default.GetString(expectedArray1), Encoding.Default.GetString(result1)); byte[] result2 = BinarySerializer.Serialize(true, MaxItemSize); byte[] expectedArray2 = new byte[] { - 0x01, 0x01 + 0x20, 0x01 }; Assert.AreEqual(Encoding.Default.GetString(expectedArray2), Encoding.Default.GetString(result2)); byte[] result3 = BinarySerializer.Serialize(1, MaxItemSize); byte[] expectedArray3 = new byte[] { - 0x02, 0x01, 0x01 + 0x21, 0x01, 0x01 }; Assert.AreEqual(Encoding.Default.GetString(expectedArray3), Encoding.Default.GetString(result3)); - StackItem stackItem4 = new InteropInterface(new object()); + StackItem stackItem4 = new InteropInterface(new object()); Action action4 = () => BinarySerializer.Serialize(stackItem4, MaxItemSize); action4.Should().Throw(); - byte[] result5 = BinarySerializer.Serialize(1, MaxItemSize); - byte[] expectedArray5 = new byte[] { - 0x02, 0x01, 0x01 - }; - Assert.AreEqual(Encoding.Default.GetString(expectedArray5), Encoding.Default.GetString(result5)); - - List list6 = new List { 1 }; StackItem stackItem62 = new VM.Types.Array(list6); byte[] result6 = BinarySerializer.Serialize(stackItem62, MaxItemSize); byte[] expectedArray6 = new byte[] { - 0x80,0x01,0x02,0x01,0x01 + 0x40,0x01,0x21,0x01,0x01 }; Assert.AreEqual(Encoding.Default.GetString(expectedArray6), Encoding.Default.GetString(result6)); @@ -58,14 +51,14 @@ public void TestSerialize() StackItem stackItem72 = new Struct(list7); byte[] result7 = BinarySerializer.Serialize(stackItem72, MaxItemSize); byte[] expectedArray7 = new byte[] { - 0x81,0x01,0x02,0x01,0x01 + 0x41,0x01,0x21,0x01,0x01 }; Assert.AreEqual(Encoding.Default.GetString(expectedArray7), Encoding.Default.GetString(result7)); StackItem stackItem82 = new Map { [2] = 1 }; byte[] result8 = BinarySerializer.Serialize(stackItem82, MaxItemSize); byte[] expectedArray8 = new byte[] { - 0x82,0x01,0x02,0x01,0x02,0x02,0x01,0x01 + 0x48,0x01,0x21,0x01,0x02,0x21,0x01,0x01 }; Assert.AreEqual(Encoding.Default.GetString(expectedArray8), Encoding.Default.GetString(result8)); @@ -85,41 +78,41 @@ public void TestDeserializeStackItem() { StackItem stackItem1 = new ByteArray(new byte[5]); byte[] byteArray1 = BinarySerializer.Serialize(stackItem1, MaxItemSize); - StackItem result1 = BinarySerializer.Deserialize(byteArray1, (uint)byteArray1.Length); + StackItem result1 = BinarySerializer.Deserialize(byteArray1, 2048, (uint)byteArray1.Length); Assert.AreEqual(stackItem1, result1); StackItem stackItem2 = new VM.Types.Boolean(true); byte[] byteArray2 = BinarySerializer.Serialize(stackItem2, MaxItemSize); - StackItem result2 = BinarySerializer.Deserialize(byteArray2, (uint)byteArray2.Length); + StackItem result2 = BinarySerializer.Deserialize(byteArray2, 2048, (uint)byteArray2.Length); Assert.AreEqual(stackItem2, result2); StackItem stackItem3 = new Integer(1); byte[] byteArray3 = BinarySerializer.Serialize(stackItem3, MaxItemSize); - StackItem result3 = BinarySerializer.Deserialize(byteArray3, (uint)byteArray3.Length); + StackItem result3 = BinarySerializer.Deserialize(byteArray3, 2048, (uint)byteArray3.Length); Assert.AreEqual(stackItem3, result3); byte[] byteArray4 = BinarySerializer.Serialize(1, MaxItemSize); byteArray4[0] = 0x40; - Action action4 = () => BinarySerializer.Deserialize(byteArray4, (uint)byteArray4.Length); + Action action4 = () => BinarySerializer.Deserialize(byteArray4, 2048, (uint)byteArray4.Length); action4.Should().Throw(); List list5 = new List { 1 }; StackItem stackItem52 = new VM.Types.Array(list5); byte[] byteArray5 = BinarySerializer.Serialize(stackItem52, MaxItemSize); - StackItem result5 = BinarySerializer.Deserialize(byteArray5, (uint)byteArray5.Length); + StackItem result5 = BinarySerializer.Deserialize(byteArray5, 2048, (uint)byteArray5.Length); Assert.AreEqual(((VM.Types.Array)stackItem52).Count, ((VM.Types.Array)result5).Count); Assert.AreEqual(((VM.Types.Array)stackItem52).GetEnumerator().Current, ((VM.Types.Array)result5).GetEnumerator().Current); List list6 = new List { 1 }; StackItem stackItem62 = new Struct(list6); byte[] byteArray6 = BinarySerializer.Serialize(stackItem62, MaxItemSize); - StackItem result6 = BinarySerializer.Deserialize(byteArray6, (uint)byteArray6.Length); + StackItem result6 = BinarySerializer.Deserialize(byteArray6, 2048, (uint)byteArray6.Length); Assert.AreEqual(((Struct)stackItem62).Count, ((Struct)result6).Count); Assert.AreEqual(((Struct)stackItem62).GetEnumerator().Current, ((Struct)result6).GetEnumerator().Current); StackItem stackItem72 = new Map { [2] = 1 }; byte[] byteArray7 = BinarySerializer.Serialize(stackItem72, MaxItemSize); - StackItem result7 = BinarySerializer.Deserialize(byteArray7, (uint)byteArray7.Length); + StackItem result7 = BinarySerializer.Deserialize(byteArray7, 2048, (uint)byteArray7.Length); Assert.AreEqual(((Map)stackItem72).Count, ((Map)result7).Count); CollectionAssert.AreEqual(((Map)stackItem72).Keys.ToArray(), ((Map)result7).Keys.ToArray()); CollectionAssert.AreEqual(((Map)stackItem72).Values.ToArray(), ((Map)result7).Values.ToArray()); diff --git a/tests/neo.UnitTests/SmartContract/UT_ContainerPlaceholder.cs b/tests/neo.UnitTests/SmartContract/UT_ContainerPlaceholder.cs index 0ba48e78a9..73023d6db8 100644 --- a/tests/neo.UnitTests/SmartContract/UT_ContainerPlaceholder.cs +++ b/tests/neo.UnitTests/SmartContract/UT_ContainerPlaceholder.cs @@ -12,14 +12,14 @@ public class UT_ContainerPlaceholder [TestMethod] public void TestGenerator() { - ContainerPlaceholder containerPlaceholder = new ContainerPlaceholder(); + ContainerPlaceholder containerPlaceholder = new ContainerPlaceholder(StackItemType.Any, 0); Assert.IsNotNull(containerPlaceholder); } [TestMethod] public void TestEquals() { - ContainerPlaceholder containerPlaceholder = new ContainerPlaceholder(); + ContainerPlaceholder containerPlaceholder = new ContainerPlaceholder(StackItemType.Any, 0); Action action = () => containerPlaceholder.Equals(new Integer(0)); action.Should().Throw(); } @@ -27,7 +27,7 @@ public void TestEquals() [TestMethod] public void TestGetBoolean() { - ContainerPlaceholder containerPlaceholder = new ContainerPlaceholder(); + ContainerPlaceholder containerPlaceholder = new ContainerPlaceholder(StackItemType.Any, 0); Action action = () => containerPlaceholder.ToBoolean(); action.Should().Throw(); } diff --git a/tests/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs b/tests/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs index 83700f33a0..959eeecae8 100644 --- a/tests/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs +++ b/tests/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs @@ -276,13 +276,13 @@ public void TestStorage_Find() engine.LoadScript(new byte[] { 0x01 }); engine.CurrentContext.EvaluationStack.Push(new byte[] { 0x01 }); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(new StorageContext + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(new StorageContext { ScriptHash = state.ScriptHash, IsReadOnly = false })); InteropService.Invoke(engine, InteropService.Storage.Find).Should().BeTrue(); - var iterator = ((InteropInterface)engine.CurrentContext.EvaluationStack.Pop()).GetInterface(); + var iterator = ((InteropInterface)engine.CurrentContext.EvaluationStack.Pop()).GetInterface(); iterator.Next(); var ele = iterator.Value(); ele.GetSpan().ToHexString().Should().Be(storageItem.Value.ToHexString()); @@ -301,7 +301,7 @@ public void TestEnumerator_Create() }; engine.CurrentContext.EvaluationStack.Push(arr); InteropService.Invoke(engine, InteropService.Enumerator.Create).Should().BeTrue(); - var ret = (InteropInterface)engine.CurrentContext.EvaluationStack.Pop(); + var ret = (InteropInterface)engine.CurrentContext.EvaluationStack.Pop(); ret.GetInterface().Next(); ret.GetInterface().Value().GetSpan().ToHexString() .Should().Be(new byte[] { 0x01 }.ToHexString()); @@ -318,7 +318,7 @@ public void TestEnumerator_Next() new byte[]{ 0x01 }, new byte[]{ 0x02 } }; - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(new ArrayWrapper(arr))); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(new ArrayWrapper(arr))); InteropService.Invoke(engine, InteropService.Enumerator.Next).Should().BeTrue(); engine.CurrentContext.EvaluationStack.Pop().ToBoolean().Should().BeTrue(); @@ -336,7 +336,7 @@ public void TestEnumerator_Value() }; var wrapper = new ArrayWrapper(arr); wrapper.Next(); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(wrapper)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(wrapper)); InteropService.Invoke(engine, InteropService.Enumerator.Value).Should().BeTrue(); engine.CurrentContext.EvaluationStack.Pop().GetSpan().ToHexString().Should().Be(new byte[] { 0x01 }.ToHexString()); @@ -358,10 +358,10 @@ public void TestEnumerator_Concat() }; var wrapper1 = new ArrayWrapper(arr1); var wrapper2 = new ArrayWrapper(arr2); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(wrapper2)); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(wrapper1)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(wrapper2)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(wrapper1)); InteropService.Invoke(engine, InteropService.Enumerator.Concat).Should().BeTrue(); - var ret = ((InteropInterface)engine.CurrentContext.EvaluationStack.Pop()).GetInterface(); + var ret = ((InteropInterface)engine.CurrentContext.EvaluationStack.Pop()).GetInterface(); ret.Next().Should().BeTrue(); ret.Value().GetSpan().ToHexString().Should().Be(new byte[] { 0x01 }.ToHexString()); } @@ -376,12 +376,12 @@ public void TestIterator_Create() }; engine.CurrentContext.EvaluationStack.Push(arr); InteropService.Invoke(engine, InteropService.Iterator.Create).Should().BeTrue(); - var ret = (InteropInterface)engine.CurrentContext.EvaluationStack.Pop(); + var ret = (InteropInterface)engine.CurrentContext.EvaluationStack.Pop(); ret.GetInterface().Next(); ret.GetInterface().Value().GetSpan().ToHexString() .Should().Be(new byte[] { 0x01 }.ToHexString()); - var interop = new InteropInterface(1); + var interop = new InteropInterface(1); engine.CurrentContext.EvaluationStack.Push(interop); InteropService.Invoke(engine, InteropService.Iterator.Create).Should().BeFalse(); @@ -392,7 +392,7 @@ public void TestIterator_Create() }; engine.CurrentContext.EvaluationStack.Push(map); InteropService.Invoke(engine, InteropService.Iterator.Create).Should().BeTrue(); - ret = (InteropInterface)engine.CurrentContext.EvaluationStack.Pop(); + ret = (InteropInterface)engine.CurrentContext.EvaluationStack.Pop(); ret.GetInterface().Next(); ret.GetInterface().Key().GetBigInteger().Should().Be(1); ret.GetInterface().Value().GetBigInteger().Should().Be(2); @@ -411,7 +411,7 @@ public void TestIterator_Key() }; var wrapper = new ArrayWrapper(arr); wrapper.Next(); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(wrapper)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(wrapper)); InteropService.Invoke(engine, InteropService.Iterator.Key).Should().BeTrue(); engine.CurrentContext.EvaluationStack.Pop().GetBigInteger().Should().Be(0); @@ -428,9 +428,9 @@ public void TestIterator_Keys() new byte[]{ 0x02 } }; var wrapper = new ArrayWrapper(arr); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(wrapper)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(wrapper)); InteropService.Invoke(engine, InteropService.Iterator.Keys).Should().BeTrue(); - var ret = ((InteropInterface)engine.CurrentContext.EvaluationStack.Pop()).GetInterface(); + var ret = ((InteropInterface)engine.CurrentContext.EvaluationStack.Pop()).GetInterface(); ret.Next(); ret.Value().GetBigInteger().Should().Be(0); @@ -447,9 +447,9 @@ public void TestIterator_Values() new byte[]{ 0x02 } }; var wrapper = new ArrayWrapper(arr); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(wrapper)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(wrapper)); InteropService.Invoke(engine, InteropService.Iterator.Values).Should().BeTrue(); - var ret = ((InteropInterface)engine.CurrentContext.EvaluationStack.Pop()).GetInterface(); + var ret = ((InteropInterface)engine.CurrentContext.EvaluationStack.Pop()).GetInterface(); ret.Next(); ret.Value().GetSpan().ToHexString().Should().Be(new byte[] { 0x01 }.ToHexString()); @@ -471,10 +471,10 @@ public void TestIterator_Concat() }; var wrapper1 = new ArrayWrapper(arr1); var wrapper2 = new ArrayWrapper(arr2); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(wrapper2)); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(wrapper1)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(wrapper2)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(wrapper1)); InteropService.Invoke(engine, InteropService.Iterator.Concat).Should().BeTrue(); - var ret = ((InteropInterface)engine.CurrentContext.EvaluationStack.Pop()).GetInterface(); + var ret = ((InteropInterface)engine.CurrentContext.EvaluationStack.Pop()).GetInterface(); ret.Next().Should().BeTrue(); ret.Value().GetSpan().ToHexString().Should().Be(new byte[] { 0x01 }.ToHexString()); } diff --git a/tests/neo.UnitTests/SmartContract/UT_InteropService.cs b/tests/neo.UnitTests/SmartContract/UT_InteropService.cs index 597da60adc..1fa676af60 100644 --- a/tests/neo.UnitTests/SmartContract/UT_InteropService.cs +++ b/tests/neo.UnitTests/SmartContract/UT_InteropService.cs @@ -36,9 +36,7 @@ public void Runtime_GetNotifications_Test() { // Drop arguments - script.Emit(VM.OpCode.TOALTSTACK); - script.Emit(VM.OpCode.DROP); - script.Emit(VM.OpCode.FROMALTSTACK); + script.Emit(OpCode.NIP); // Notify method @@ -337,12 +335,12 @@ public void TestRuntime_Serialize() engine.CurrentContext.EvaluationStack.Push(100); InteropService.Invoke(engine, InteropService.Binary.Serialize).Should().BeTrue(); engine.CurrentContext.EvaluationStack.Pop().GetSpan().ToHexString() - .Should().Be(new byte[] { 0x02, 0x01, 0x64 }.ToHexString()); + .Should().Be(new byte[] { 0x21, 0x01, 0x64 }.ToHexString()); engine.CurrentContext.EvaluationStack.Push(new byte[1024 * 1024 * 2]); //Larger than MaxItemSize InteropService.Invoke(engine, InteropService.Binary.Serialize).Should().BeFalse(); - engine.CurrentContext.EvaluationStack.Push(new TestInteropInterface()); //NotSupportedException + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(new object())); //NotSupportedException InteropService.Invoke(engine, InteropService.Binary.Serialize).Should().BeFalse(); } @@ -356,7 +354,7 @@ public void TestRuntime_Deserialize() engine.CurrentContext.EvaluationStack.Pop().GetBigInteger().Should().Be(100); engine.CurrentContext.EvaluationStack.Push(new byte[] { 0xfa, 0x01 }); //FormatException - InteropService.Invoke(engine, InteropService.Binary.Deserialize).Should().BeFalse(); + Assert.ThrowsException(() => InteropService.Invoke(engine, InteropService.Binary.Deserialize)); } [TestMethod] @@ -391,7 +389,7 @@ public void TestCrypto_Verify() wrongkey[0] = 5; engine.CurrentContext.EvaluationStack.Push(signature); engine.CurrentContext.EvaluationStack.Push(wrongkey); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(engine.ScriptContainer)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(engine.ScriptContainer)); InteropService.Invoke(engine, InteropService.Crypto.ECDsaVerify).Should().BeTrue(); engine.CurrentContext.EvaluationStack.Peek().ToBoolean().Should().BeFalse(); } @@ -484,7 +482,7 @@ public void TestStorage_GetContext() { var engine = GetEngine(); InteropService.Invoke(engine, InteropService.Storage.GetContext).Should().BeTrue(); - var ret = (InteropInterface)engine.CurrentContext.EvaluationStack.Pop(); + var ret = (InteropInterface)engine.CurrentContext.EvaluationStack.Pop(); ret.GetInterface().ScriptHash.Should().Be(engine.CurrentScriptHash); ret.GetInterface().IsReadOnly.Should().BeFalse(); } @@ -494,7 +492,7 @@ public void TestStorage_GetReadOnlyContext() { var engine = GetEngine(); InteropService.Invoke(engine, InteropService.Storage.GetReadOnlyContext).Should().BeTrue(); - var ret = (InteropInterface)engine.CurrentContext.EvaluationStack.Pop(); + var ret = (InteropInterface)engine.CurrentContext.EvaluationStack.Pop(); ret.GetInterface().ScriptHash.Should().Be(engine.CurrentScriptHash); ret.GetInterface().IsReadOnly.Should().BeTrue(); } @@ -523,7 +521,7 @@ public void TestStorage_Get() engine.LoadScript(new byte[] { 0x01 }); engine.CurrentContext.EvaluationStack.Push(new byte[] { 0x01 }); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(new StorageContext + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(new StorageContext { ScriptHash = state.ScriptHash, IsReadOnly = false @@ -535,7 +533,7 @@ public void TestStorage_Get() engine = new ApplicationEngine(TriggerType.Application, null, snapshot, 0); engine.LoadScript(new byte[] { 0x01 }); engine.CurrentContext.EvaluationStack.Push(new byte[] { 0x01 }); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(new StorageContext + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(new StorageContext { ScriptHash = state.ScriptHash, IsReadOnly = false @@ -564,7 +562,7 @@ public void TestStorage_Put() ScriptHash = state.ScriptHash, IsReadOnly = false }; - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); InteropService.Invoke(engine, InteropService.Storage.Put).Should().BeFalse(); //key.Length > MaxStorageKeySize @@ -572,7 +570,7 @@ public void TestStorage_Put() value = new byte[] { 0x02 }; engine.CurrentContext.EvaluationStack.Push(value); engine.CurrentContext.EvaluationStack.Push(key); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); InteropService.Invoke(engine, InteropService.Storage.Put).Should().BeFalse(); //value.Length > MaxStorageValueSize @@ -580,7 +578,7 @@ public void TestStorage_Put() value = new byte[ushort.MaxValue + 1]; engine.CurrentContext.EvaluationStack.Push(value); engine.CurrentContext.EvaluationStack.Push(key); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); InteropService.Invoke(engine, InteropService.Storage.Put).Should().BeFalse(); //context.IsReadOnly @@ -589,7 +587,7 @@ public void TestStorage_Put() storageContext.IsReadOnly = true; engine.CurrentContext.EvaluationStack.Push(value); engine.CurrentContext.EvaluationStack.Push(key); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); InteropService.Invoke(engine, InteropService.Storage.Put).Should().BeFalse(); //storage value is constant @@ -615,14 +613,14 @@ public void TestStorage_Put() storageContext.IsReadOnly = false; engine.CurrentContext.EvaluationStack.Push(value); engine.CurrentContext.EvaluationStack.Push(key); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); InteropService.Invoke(engine, InteropService.Storage.Put).Should().BeFalse(); //success storageItem.IsConstant = false; engine.CurrentContext.EvaluationStack.Push(value); engine.CurrentContext.EvaluationStack.Push(key); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); InteropService.Invoke(engine, InteropService.Storage.Put).Should().BeTrue(); //value length == 0 @@ -630,7 +628,7 @@ public void TestStorage_Put() value = new byte[0]; engine.CurrentContext.EvaluationStack.Push(value); engine.CurrentContext.EvaluationStack.Push(key); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); InteropService.Invoke(engine, InteropService.Storage.Put).Should().BeTrue(); } @@ -668,7 +666,7 @@ public void TestStorage_PutEx() engine.CurrentContext.EvaluationStack.Push((int)StorageFlags.None); engine.CurrentContext.EvaluationStack.Push(value); engine.CurrentContext.EvaluationStack.Push(key); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); InteropService.Invoke(engine, InteropService.Storage.PutEx).Should().BeTrue(); } @@ -705,20 +703,20 @@ public void TestStorage_Delete() IsReadOnly = false }; engine.CurrentContext.EvaluationStack.Push(key); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); InteropService.Invoke(engine, InteropService.Storage.Delete).Should().BeTrue(); //context is readonly storageContext.IsReadOnly = true; engine.CurrentContext.EvaluationStack.Push(key); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); InteropService.Invoke(engine, InteropService.Storage.Delete).Should().BeFalse(); //CheckStorageContext fail storageContext.IsReadOnly = false; state.Manifest.Features = ContractFeatures.NoProperty; engine.CurrentContext.EvaluationStack.Push(key); - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); InteropService.Invoke(engine, InteropService.Storage.Delete).Should().BeFalse(); } @@ -735,9 +733,9 @@ public void TestStorageContext_AsReadOnly() ScriptHash = state.ScriptHash, IsReadOnly = false }; - engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); + engine.CurrentContext.EvaluationStack.Push(new InteropInterface(storageContext)); InteropService.Invoke(engine, InteropService.Storage.AsReadOnly).Should().BeTrue(); - var ret = (InteropInterface)engine.CurrentContext.EvaluationStack.Pop(); + var ret = (InteropInterface)engine.CurrentContext.EvaluationStack.Pop(); ret.GetInterface().IsReadOnly.Should().Be(true); } @@ -909,11 +907,4 @@ private static ApplicationEngine GetEngine(bool hasContainer = false, bool hasSn return engine; } } - - internal class TestInteropInterface : InteropInterface - { - public override bool Equals(StackItem other) => true; - public override bool ToBoolean() => true; - public override T GetInterface() => throw new NotImplementedException(); - } } diff --git a/tests/neo.UnitTests/SmartContract/UT_NotifyEventArgs.cs b/tests/neo.UnitTests/SmartContract/UT_NotifyEventArgs.cs index 1dfd6a6ec5..d86a9d208e 100644 --- a/tests/neo.UnitTests/SmartContract/UT_NotifyEventArgs.cs +++ b/tests/neo.UnitTests/SmartContract/UT_NotifyEventArgs.cs @@ -2,7 +2,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.Network.P2P.Payloads; using Neo.SmartContract; -using Neo.VM.Types; namespace Neo.UnitTests.SmartContract { @@ -14,8 +13,7 @@ public void TestGetScriptContainer() { IVerifiable container = new TestVerifiable(); UInt160 script_hash = new byte[] { 0x00 }.ToScriptHash(); - StackItem state = new ContainerPlaceholder(); - NotifyEventArgs args = new NotifyEventArgs(container, script_hash, state); + NotifyEventArgs args = new NotifyEventArgs(container, script_hash, 0); args.ScriptContainer.Should().Be(container); } } diff --git a/tests/neo.UnitTests/VM/UT_Helper.cs b/tests/neo.UnitTests/VM/UT_Helper.cs index 559f9013ae..809e00c94d 100644 --- a/tests/neo.UnitTests/VM/UT_Helper.cs +++ b/tests/neo.UnitTests/VM/UT_Helper.cs @@ -96,7 +96,7 @@ public void TestMakeScript() { byte[] testScript = NativeContract.GAS.Hash.MakeScript("balanceOf", UInt160.Zero); - Assert.AreEqual("0c14000000000000000000000000000000000000000011c10c0962616c616e63654f660c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b52", + Assert.AreEqual("0c14000000000000000000000000000000000000000011c00c0962616c616e63654f660c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b52", testScript.ToHexString()); } @@ -112,7 +112,7 @@ public void TestToParameter() StackItem intItem = new BigInteger(1000); Assert.AreEqual(1000, (BigInteger)intItem.ToParameter().Value); - StackItem interopItem = new VM.Types.InteropInterface("test"); + StackItem interopItem = new VM.Types.InteropInterface("test"); Assert.AreEqual(null, interopItem.ToParameter().Value); StackItem arrayItem = new VM.Types.Array(new[] { byteItem, boolItem, intItem, interopItem }); @@ -493,7 +493,7 @@ public void TestToParameter2() private void TestToParameter2InteropInterface() { - StackItem item = new VM.Types.InteropInterface(new VM.Types.Boolean(true)); + StackItem item = new InteropInterface(new object()); ContractParameter parameter = VM.Helper.ToParameter(item); Assert.AreEqual(ContractParameterType.InteropInterface, parameter.Type); }