From cd988e85222f4d9df614f969668d2a915094b2e2 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Tue, 23 Jun 2020 20:04:57 +0800 Subject: [PATCH] Neo.VM.3.0.0-CI00230 (#1725) --- src/neo/SmartContract/ApplicationEngine.cs | 2 +- src/neo/SmartContract/BinarySerializer.cs | 32 +++++++--- src/neo/SmartContract/ContainerPlaceholder.cs | 23 -------- src/neo/SmartContract/Helper.cs | 2 +- .../InteropParameterDescriptor.cs | 21 ++++--- .../Iterators/ByteArrayWrapper.cs | 2 +- src/neo/SmartContract/JsonSerializer.cs | 14 ++--- .../SmartContract/Native/NativeContract.cs | 2 +- .../Native/Tokens/AccountState.cs | 2 +- .../SmartContract/Native/Tokens/NeoToken.cs | 6 +- src/neo/VM/Helper.cs | 52 +++-------------- src/neo/Wallets/AssetDescriptor.cs | 2 +- src/neo/Wallets/Wallet.cs | 6 +- src/neo/neo.csproj | 2 +- .../Nep5NativeContractExtensions.cs | 8 +-- .../Network/P2P/Payloads/UT_Transaction.cs | 14 ++--- .../Iterators/UT_PrimitiveWrapper.cs | 5 +- .../Native/Tokens/UT_NeoToken.cs | 26 ++++----- .../SmartContract/Native/UT_PolicyContract.cs | 58 +++++++++---------- .../SmartContract/UT_ContainerPlaceholder.cs | 35 ----------- .../SmartContract/UT_InteropService.NEO.cs | 11 ++-- .../SmartContract/UT_InteropService.cs | 2 +- .../SmartContract/UT_JsonSerializer.cs | 23 ++++---- .../SmartContract/UT_Syscalls.Callback.cs | 2 +- .../SmartContract/UT_Syscalls.cs | 8 +-- tests/neo.UnitTests/VM/UT_Helper.cs | 14 ++--- 26 files changed, 143 insertions(+), 231 deletions(-) delete mode 100644 src/neo/SmartContract/ContainerPlaceholder.cs delete mode 100644 tests/neo.UnitTests/SmartContract/UT_ContainerPlaceholder.cs diff --git a/src/neo/SmartContract/ApplicationEngine.cs b/src/neo/SmartContract/ApplicationEngine.cs index 2602397ebc..ca994e836f 100644 --- a/src/neo/SmartContract/ApplicationEngine.cs +++ b/src/neo/SmartContract/ApplicationEngine.cs @@ -165,7 +165,7 @@ internal object Convert(StackItem item, InteropParameterDescriptor descriptor) } else { - int count = (int)item.GetBigInteger(); + int count = (int)item.GetInteger(); if (count > MaxStackSize) throw new InvalidOperationException(); av = Array.CreateInstance(descriptor.Type.GetElementType(), count); for (int i = 0; i < av.Length; i++) diff --git a/src/neo/SmartContract/BinarySerializer.cs b/src/neo/SmartContract/BinarySerializer.cs index 5083be59a7..89bf477e3a 100644 --- a/src/neo/SmartContract/BinarySerializer.cs +++ b/src/neo/SmartContract/BinarySerializer.cs @@ -14,6 +14,24 @@ namespace Neo.SmartContract { internal static class BinarySerializer { + private class ContainerPlaceholder : StackItem + { + public override StackItemType Type { get; } + public int ElementCount { get; } + + public ContainerPlaceholder(StackItemType type, int count) + { + Type = type; + ElementCount = count; + } + + public override bool Equals(StackItem other) => throw new NotSupportedException(); + + public override int GetHashCode() => throw new NotSupportedException(); + + public override bool GetBoolean() => throw new NotSupportedException(); + } + public static StackItem Deserialize(byte[] data, uint maxArraySize, uint maxItemSize, ReferenceCounter referenceCounter = null) { using MemoryStream ms = new MemoryStream(data, false); @@ -137,16 +155,12 @@ private static void Serialize(StackItem item, BinaryWriter writer, uint maxSize) case Null _: break; case Boolean _: - writer.Write(item.ToBoolean()); - break; - case Integer integer: - writer.WriteVarBytes(integer.Span); - break; - case ByteString bytes: - writer.WriteVarBytes(bytes.Span); + writer.Write(item.GetBoolean()); break; - case Buffer buffer: - writer.WriteVarBytes(buffer.InnerBuffer); + case Integer _: + case ByteString _: + case Buffer _: + writer.WriteVarBytes(item.GetSpan()); break; case Array array: if (serialized.Any(p => ReferenceEquals(p, array))) diff --git a/src/neo/SmartContract/ContainerPlaceholder.cs b/src/neo/SmartContract/ContainerPlaceholder.cs deleted file mode 100644 index 757d77ccbc..0000000000 --- a/src/neo/SmartContract/ContainerPlaceholder.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Neo.VM.Types; -using System; - -namespace Neo.SmartContract -{ - internal class ContainerPlaceholder : StackItem - { - public override StackItemType Type { get; } - public int ElementCount { get; } - - public ContainerPlaceholder(StackItemType type, int count) - { - Type = type; - ElementCount = count; - } - - public override bool Equals(StackItem other) => throw new NotSupportedException(); - - public override int GetHashCode() => throw new NotSupportedException(); - - public override bool ToBoolean() => throw new NotSupportedException(); - } -} diff --git a/src/neo/SmartContract/Helper.cs b/src/neo/SmartContract/Helper.cs index d9299e30f3..a365806b87 100644 --- a/src/neo/SmartContract/Helper.cs +++ b/src/neo/SmartContract/Helper.cs @@ -164,7 +164,7 @@ internal static bool VerifyWitnesses(this IVerifiable verifiable, StoreView snap engine.LoadScript(verification, CallFlags.ReadOnly).InstructionPointer = offset; engine.LoadScript(verifiable.Witnesses[i].InvocationScript, CallFlags.None); if (engine.Execute() == VMState.FAULT) return false; - if (engine.ResultStack.Count != 1 || !engine.ResultStack.Pop().ToBoolean()) return false; + if (engine.ResultStack.Count != 1 || !engine.ResultStack.Pop().GetBoolean()) return false; gas -= engine.GasConsumed; } } diff --git a/src/neo/SmartContract/InteropParameterDescriptor.cs b/src/neo/SmartContract/InteropParameterDescriptor.cs index 440e4588af..fd380ffb68 100644 --- a/src/neo/SmartContract/InteropParameterDescriptor.cs +++ b/src/neo/SmartContract/InteropParameterDescriptor.cs @@ -1,5 +1,4 @@ using Neo.Cryptography.ECC; -using Neo.VM; using Neo.VM.Types; using System; using System.Collections.Generic; @@ -23,16 +22,16 @@ internal class InteropParameterDescriptor [typeof(VM.Types.Pointer)] = p => p, [typeof(VM.Types.Array)] = p => p, [typeof(InteropInterface)] = p => p, - [typeof(bool)] = p => p.ToBoolean(), - [typeof(sbyte)] = p => (sbyte)p.GetBigInteger(), - [typeof(byte)] = p => (byte)p.GetBigInteger(), - [typeof(short)] = p => (short)p.GetBigInteger(), - [typeof(ushort)] = p => (ushort)p.GetBigInteger(), - [typeof(int)] = p => (int)p.GetBigInteger(), - [typeof(uint)] = p => (uint)p.GetBigInteger(), - [typeof(long)] = p => (long)p.GetBigInteger(), - [typeof(ulong)] = p => (ulong)p.GetBigInteger(), - [typeof(BigInteger)] = p => p.GetBigInteger(), + [typeof(bool)] = p => p.GetBoolean(), + [typeof(sbyte)] = p => (sbyte)p.GetInteger(), + [typeof(byte)] = p => (byte)p.GetInteger(), + [typeof(short)] = p => (short)p.GetInteger(), + [typeof(ushort)] = p => (ushort)p.GetInteger(), + [typeof(int)] = p => (int)p.GetInteger(), + [typeof(uint)] = p => (uint)p.GetInteger(), + [typeof(long)] = p => (long)p.GetInteger(), + [typeof(ulong)] = p => (ulong)p.GetInteger(), + [typeof(BigInteger)] = p => p.GetInteger(), [typeof(byte[])] = p => p.IsNull ? null : p.GetSpan().ToArray(), [typeof(string)] = p => p.IsNull ? null : p.GetString(), [typeof(UInt160)] = p => p.IsNull ? null : new UInt160(p.GetSpan()), diff --git a/src/neo/SmartContract/Iterators/ByteArrayWrapper.cs b/src/neo/SmartContract/Iterators/ByteArrayWrapper.cs index c60c839543..f409b3beed 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.Span.ToArray(); + this.array = value.GetSpan().ToArray(); } public void Dispose() { } diff --git a/src/neo/SmartContract/JsonSerializer.cs b/src/neo/SmartContract/JsonSerializer.cs index ff79e0a4ae..ef772183c9 100644 --- a/src/neo/SmartContract/JsonSerializer.cs +++ b/src/neo/SmartContract/JsonSerializer.cs @@ -35,14 +35,14 @@ public static JObject Serialize(StackItem item) } case Integer num: { - var integer = num.GetBigInteger(); + var integer = num.GetInteger(); if (integer > JNumber.MAX_SAFE_INTEGER || integer < JNumber.MIN_SAFE_INTEGER) - return integer.ToString(); - return (double)num.GetBigInteger(); + throw new InvalidOperationException(); + return (double)integer; } case Boolean boolean: { - return boolean.ToBoolean(); + return boolean.GetBoolean(); } case Map map: { @@ -96,14 +96,14 @@ public static byte[] SerializeToByteArray(StackItem item, uint maxSize) break; case Integer num: { - var integer = num.GetBigInteger(); + var integer = num.GetInteger(); if (integer > JNumber.MAX_SAFE_INTEGER || integer < JNumber.MIN_SAFE_INTEGER) throw new InvalidOperationException(); - writer.WriteNumberValue((double)num.GetBigInteger()); + writer.WriteNumberValue((double)integer); break; } case Boolean boolean: - writer.WriteBooleanValue(boolean.ToBoolean()); + writer.WriteBooleanValue(boolean.GetBoolean()); break; case Map map: writer.WriteStartObject(); diff --git a/src/neo/SmartContract/Native/NativeContract.cs b/src/neo/SmartContract/Native/NativeContract.cs index 21c9b429a1..4d649ac627 100644 --- a/src/neo/SmartContract/Native/NativeContract.cs +++ b/src/neo/SmartContract/Native/NativeContract.cs @@ -112,7 +112,7 @@ internal void Invoke(ApplicationEngine engine) { if (!engine.CurrentScriptHash.Equals(Hash)) throw new InvalidOperationException("It is not allowed to use Neo.Native.Call directly to call native contracts. System.Contract.Call should be used."); - string operation = engine.PopString(); + string operation = engine.Pop().GetString(); Array args = engine.Pop(); ContractMethodMetadata method = methods[operation]; ExecutionContextState state = engine.CurrentContext.GetState(); diff --git a/src/neo/SmartContract/Native/Tokens/AccountState.cs b/src/neo/SmartContract/Native/Tokens/AccountState.cs index 4cffcc406c..30d3d02e49 100644 --- a/src/neo/SmartContract/Native/Tokens/AccountState.cs +++ b/src/neo/SmartContract/Native/Tokens/AccountState.cs @@ -10,7 +10,7 @@ public class AccountState : IInteroperable public virtual void FromStackItem(StackItem stackItem) { - Balance = ((Struct)stackItem)[0].GetBigInteger(); + Balance = ((Struct)stackItem)[0].GetInteger(); } public virtual StackItem ToStackItem(ReferenceCounter referenceCounter) diff --git a/src/neo/SmartContract/Native/Tokens/NeoToken.cs b/src/neo/SmartContract/Native/Tokens/NeoToken.cs index 494bf4afc6..3d814cbe2f 100644 --- a/src/neo/SmartContract/Native/Tokens/NeoToken.cs +++ b/src/neo/SmartContract/Native/Tokens/NeoToken.cs @@ -242,7 +242,7 @@ public override void FromStackItem(StackItem stackItem) { base.FromStackItem(stackItem); Struct @struct = (Struct)stackItem; - BalanceHeight = (uint)@struct[1].GetBigInteger(); + BalanceHeight = (uint)@struct[1].GetInteger(); VoteTo = @struct[2].IsNull ? null : @struct[2].GetSpan().AsSerializable(); } @@ -263,8 +263,8 @@ internal class CandidateState : IInteroperable public void FromStackItem(StackItem stackItem) { Struct @struct = (Struct)stackItem; - Registered = @struct[0].ToBoolean(); - Votes = @struct[1].GetBigInteger(); + Registered = @struct[0].GetBoolean(); + Votes = @struct[1].GetInteger(); } public StackItem ToStackItem(ReferenceCounter referenceCounter) diff --git a/src/neo/VM/Helper.cs b/src/neo/VM/Helper.cs index c31c12d512..6437b75118 100644 --- a/src/neo/VM/Helper.cs +++ b/src/neo/VM/Helper.cs @@ -7,7 +7,6 @@ using System.Collections.Generic; using System.Linq; using System.Numerics; -using System.Text; using Array = Neo.VM.Types.Array; using Boolean = Neo.VM.Types.Boolean; using Buffer = Neo.VM.Types.Buffer; @@ -168,39 +167,6 @@ public static ScriptBuilder EmitSysCall(this ScriptBuilder sb, uint method, para return sb.EmitSysCall(method); } - public static BigInteger GetBigInteger(this StackItem item) - { - if (!(item is PrimitiveType primitive)) - throw new ArgumentException(); - return primitive.ToBigInteger(); - } - - public static int GetByteLength(this StackItem item) - { - return item switch - { - PrimitiveType p => p.Size, - Buffer b => b.Size, - Null _ => 0, - _ => throw new ArgumentException(), - }; - } - - public static ReadOnlySpan GetSpan(this StackItem item) - { - return item switch - { - PrimitiveType p => p.Span, - Buffer b => b.InnerBuffer, - _ => throw new ArgumentException(), - }; - } - - public static string GetString(this StackItem item) - { - return Utility.StrictUTF8.GetString(item.GetSpan()); - } - /// /// Generate scripts to call a specific method from a specific contract. /// @@ -237,16 +203,14 @@ private static JObject ToJson(StackItem item, HashSet context) json["value"] = new JArray(array.Select(p => ToJson(p, context))); break; case Boolean boolean: - json["value"] = boolean.ToBoolean(); - break; - case Buffer buffer: - json["value"] = Convert.ToBase64String(buffer.InnerBuffer); + json["value"] = boolean.GetBoolean(); break; - case ByteString byteString: - json["value"] = Convert.ToBase64String(byteString.Span); + case Buffer _: + case ByteString _: + json["value"] = Convert.ToBase64String(item.GetSpan()); break; case Integer integer: - json["value"] = integer.ToBigInteger().ToString(); + json["value"] = integer.GetInteger().ToString(); break; case Map map: context ??= new HashSet(ReferenceEqualityComparer.Default); @@ -305,21 +269,21 @@ private static ContractParameter ToParameter(StackItem item, List<(StackItem, Co parameter = new ContractParameter { Type = ContractParameterType.Boolean, - Value = item.ToBoolean() + Value = item.GetBoolean() }; break; case ByteString array: parameter = new ContractParameter { Type = ContractParameterType.ByteArray, - Value = array.Span.ToArray() + Value = array.GetSpan().ToArray() }; break; case Integer i: parameter = new ContractParameter { Type = ContractParameterType.Integer, - Value = i.ToBigInteger() + Value = i.GetInteger() }; break; case InteropInterface _: diff --git a/src/neo/Wallets/AssetDescriptor.cs b/src/neo/Wallets/AssetDescriptor.cs index 46a80a0f5c..c49712f7ec 100644 --- a/src/neo/Wallets/AssetDescriptor.cs +++ b/src/neo/Wallets/AssetDescriptor.cs @@ -23,7 +23,7 @@ public AssetDescriptor(UInt160 asset_id) if (engine.State.HasFlag(VMState.FAULT)) throw new ArgumentException(); this.AssetId = asset_id; this.AssetName = engine.ResultStack.Pop().GetString(); - this.Decimals = (byte)engine.ResultStack.Pop().GetBigInteger(); + this.Decimals = (byte)engine.ResultStack.Pop().GetInteger(); } public override string ToString() diff --git a/src/neo/Wallets/Wallet.cs b/src/neo/Wallets/Wallet.cs index def6977959..69708cca42 100644 --- a/src/neo/Wallets/Wallet.cs +++ b/src/neo/Wallets/Wallet.cs @@ -146,8 +146,8 @@ public BigDecimal GetBalance(UInt160 asset_id, params UInt160[] accounts) using ApplicationEngine engine = ApplicationEngine.Run(script, extraGAS: 20000000L * accounts.Length); if (engine.State.HasFlag(VMState.FAULT)) return new BigDecimal(0, 0); - byte decimals = (byte)engine.ResultStack.Pop().GetBigInteger(); - BigInteger amount = engine.ResultStack.Pop().GetBigInteger(); + byte decimals = (byte)engine.ResultStack.Pop().GetInteger(); + BigInteger amount = engine.ResultStack.Pop().GetInteger(); return new BigDecimal(amount, decimals); } @@ -251,7 +251,7 @@ public Transaction MakeTransaction(TransferOutput[] outputs, UInt160 from = null { if (engine.State.HasFlag(VMState.FAULT)) throw new InvalidOperationException($"Execution for {assetId.ToString()}.balanceOf('{account.ToString()}' fault"); - BigInteger value = engine.ResultStack.Pop().GetBigInteger(); + BigInteger value = engine.ResultStack.Pop().GetInteger(); if (value.Sign > 0) balances.Add((account, value)); } } diff --git a/src/neo/neo.csproj b/src/neo/neo.csproj index 3cd431d612..e3ee5b5259 100644 --- a/src/neo/neo.csproj +++ b/src/neo/neo.csproj @@ -27,7 +27,7 @@ - + diff --git a/tests/neo.UnitTests/Extensions/Nep5NativeContractExtensions.cs b/tests/neo.UnitTests/Extensions/Nep5NativeContractExtensions.cs index 70098c9c04..e3a5fc9adf 100644 --- a/tests/neo.UnitTests/Extensions/Nep5NativeContractExtensions.cs +++ b/tests/neo.UnitTests/Extensions/Nep5NativeContractExtensions.cs @@ -65,7 +65,7 @@ public static bool Transfer(this NativeContract contract, StoreView snapshot, by var result = engine.ResultStack.Pop(); result.Should().BeOfType(typeof(VM.Types.Boolean)); - return result.ToBoolean(); + return result.GetBoolean(); } public static string[] SupportedStandards(this NativeContract contract) @@ -107,7 +107,7 @@ public static BigInteger TotalSupply(this NativeContract contract, StoreView sna var result = engine.ResultStack.Pop(); result.Should().BeOfType(typeof(VM.Types.Integer)); - return (result as VM.Types.Integer).GetBigInteger(); + return result.GetInteger(); } public static BigInteger BalanceOf(this NativeContract contract, StoreView snapshot, byte[] account) @@ -128,7 +128,7 @@ public static BigInteger BalanceOf(this NativeContract contract, StoreView snaps var result = engine.ResultStack.Pop(); result.Should().BeOfType(typeof(VM.Types.Integer)); - return (result as VM.Types.Integer).GetBigInteger(); + return result.GetInteger(); } public static BigInteger Decimals(this NativeContract contract) @@ -148,7 +148,7 @@ public static BigInteger Decimals(this NativeContract contract) var result = engine.ResultStack.Pop(); result.Should().BeOfType(typeof(VM.Types.Integer)); - return (result as VM.Types.Integer).GetBigInteger(); + return result.GetInteger(); } public static string Symbol(this NativeContract contract) diff --git a/tests/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs b/tests/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs index 7e025ad4cd..5425b71974 100644 --- a/tests/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs +++ b/tests/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs @@ -151,7 +151,7 @@ public void FeeIsMultiSigContract() engine.LoadScript(witness.InvocationScript); Assert.AreEqual(VMState.HALT, engine.Execute()); Assert.AreEqual(1, engine.ResultStack.Count); - Assert.IsTrue(engine.ResultStack.Pop().ToBoolean()); + Assert.IsTrue(engine.ResultStack.Pop().GetBoolean()); verificationGas += engine.GasConsumed; } } @@ -233,7 +233,7 @@ public void FeeIsSignatureContractDetailed() engine.LoadScript(witness.InvocationScript); Assert.AreEqual(VMState.HALT, engine.Execute()); Assert.AreEqual(1, engine.ResultStack.Count); - Assert.IsTrue(engine.ResultStack.Pop().ToBoolean()); + Assert.IsTrue(engine.ResultStack.Pop().GetBoolean()); verificationGas += engine.GasConsumed; } } @@ -346,7 +346,7 @@ public void FeeIsSignatureContract_TestScope_Global() engine.LoadScript(witness.InvocationScript); Assert.AreEqual(VMState.HALT, engine.Execute()); Assert.AreEqual(1, engine.ResultStack.Count); - Assert.IsTrue(engine.ResultStack.Pop().ToBoolean()); + Assert.IsTrue(engine.ResultStack.Pop().GetBoolean()); verificationGas += engine.GasConsumed; } } @@ -433,7 +433,7 @@ public void FeeIsSignatureContract_TestScope_CurrentHash_GAS() engine.LoadScript(witness.InvocationScript); Assert.AreEqual(VMState.HALT, engine.Execute()); Assert.AreEqual(1, engine.ResultStack.Count); - Assert.IsTrue(engine.ResultStack.Pop().ToBoolean()); + Assert.IsTrue(engine.ResultStack.Pop().GetBoolean()); verificationGas += engine.GasConsumed; } } @@ -523,7 +523,7 @@ public void FeeIsSignatureContract_TestScope_CalledByEntry_Plus_GAS() engine.LoadScript(witness.InvocationScript); Assert.AreEqual(VMState.HALT, engine.Execute()); Assert.AreEqual(1, engine.ResultStack.Count); - Assert.IsTrue(engine.ResultStack.Pop().ToBoolean()); + Assert.IsTrue(engine.ResultStack.Pop().GetBoolean()); verificationGas += engine.GasConsumed; } } @@ -665,7 +665,7 @@ public void FeeIsSignatureContract_TestScope_CurrentHash_NEO_GAS() engine.LoadScript(witness.InvocationScript); Assert.AreEqual(VMState.HALT, engine.Execute()); Assert.AreEqual(1, engine.ResultStack.Count); - Assert.IsTrue(engine.ResultStack.Pop().ToBoolean()); + Assert.IsTrue(engine.ResultStack.Pop().GetBoolean()); verificationGas += engine.GasConsumed; } } @@ -996,7 +996,7 @@ public void FeeIsSignatureContract_TestScope_Global_Default() engine.LoadScript(witness.InvocationScript); Assert.AreEqual(VMState.HALT, engine.Execute()); Assert.AreEqual(1, engine.ResultStack.Count); - Assert.IsTrue(engine.ResultStack.Pop().ToBoolean()); + Assert.IsTrue(engine.ResultStack.Pop().GetBoolean()); verificationGas += engine.GasConsumed; } } diff --git a/tests/neo.UnitTests/SmartContract/Iterators/UT_PrimitiveWrapper.cs b/tests/neo.UnitTests/SmartContract/Iterators/UT_PrimitiveWrapper.cs index 72c4750225..c097986de3 100644 --- a/tests/neo.UnitTests/SmartContract/Iterators/UT_PrimitiveWrapper.cs +++ b/tests/neo.UnitTests/SmartContract/Iterators/UT_PrimitiveWrapper.cs @@ -1,7 +1,6 @@ using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.SmartContract.Iterators; -using Neo.VM; using Neo.VM.Types; using System; @@ -28,10 +27,10 @@ public void TestKeyAndValue() Action action2 = () => arrayWrapper.Value(); action2.Should().Throw(); arrayWrapper.Next(); - Assert.AreEqual(0x00, arrayWrapper.Key().GetBigInteger()); + Assert.AreEqual(0x00, arrayWrapper.Key().GetInteger()); Assert.AreEqual(0x01, arrayWrapper.Value()); arrayWrapper.Next(); - Assert.AreEqual(0x01, arrayWrapper.Key().GetBigInteger()); + Assert.AreEqual(0x01, arrayWrapper.Key().GetInteger()); Assert.AreEqual(0x02, arrayWrapper.Value()); } diff --git a/tests/neo.UnitTests/SmartContract/Native/Tokens/UT_NeoToken.cs b/tests/neo.UnitTests/SmartContract/Native/Tokens/UT_NeoToken.cs index 14b6536ccc..dafb1f9a72 100644 --- a/tests/neo.UnitTests/SmartContract/Native/Tokens/UT_NeoToken.cs +++ b/tests/neo.UnitTests/SmartContract/Native/Tokens/UT_NeoToken.cs @@ -286,19 +286,19 @@ public void TestGetRegisteredValidators1() var array = engine.ResultStack.Pop(); array.Count.Should().Be(21); ((VM.Types.Struct)array[0])[0].GetSpan().ToHexString().Should().Be("020f2887f41474cfeb11fd262e982051c1541418137c02a0f4961af911045de639"); - ((VM.Types.Struct)array[0])[1].GetBigInteger().Should().Be(new BigInteger(1785714)); + ((VM.Types.Struct)array[0])[1].GetInteger().Should().Be(new BigInteger(1785714)); ((VM.Types.Struct)array[1])[0].GetSpan().ToHexString().Should().Be("0222038884bbd1d8ff109ed3bdef3542e768eef76c1247aea8bc8171f532928c30"); - ((VM.Types.Struct)array[1])[1].GetBigInteger().Should().Be(new BigInteger(1785714)); + ((VM.Types.Struct)array[1])[1].GetInteger().Should().Be(new BigInteger(1785714)); ((VM.Types.Struct)array[2])[0].GetSpan().ToHexString().Should().Be("0226933336f1b75baa42d42b71d9091508b638046d19abd67f4e119bf64a7cfb4d"); - ((VM.Types.Struct)array[2])[1].GetBigInteger().Should().Be(new BigInteger(1785714)); + ((VM.Types.Struct)array[2])[1].GetInteger().Should().Be(new BigInteger(1785714)); ((VM.Types.Struct)array[3])[0].GetSpan().ToHexString().Should().Be("023a36c72844610b4d34d1968662424011bf783ca9d984efa19a20babf5582f3fe"); - ((VM.Types.Struct)array[3])[1].GetBigInteger().Should().Be(new BigInteger(1785714)); + ((VM.Types.Struct)array[3])[1].GetInteger().Should().Be(new BigInteger(1785714)); ((VM.Types.Struct)array[4])[0].GetSpan().ToHexString().Should().Be("02486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a70"); - ((VM.Types.Struct)array[4])[1].GetBigInteger().Should().Be(new BigInteger(3571428)); + ((VM.Types.Struct)array[4])[1].GetInteger().Should().Be(new BigInteger(3571428)); ((VM.Types.Struct)array[5])[0].GetSpan().ToHexString().Should().Be("024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d"); - ((VM.Types.Struct)array[5])[1].GetBigInteger().Should().Be(new BigInteger(3571428)); + ((VM.Types.Struct)array[5])[1].GetInteger().Should().Be(new BigInteger(3571428)); ((VM.Types.Struct)array[6])[0].GetSpan().ToHexString().Should().Be("02504acbc1f4b3bdad1d86d6e1a08603771db135a73e61c9d565ae06a1938cd2ad"); - ((VM.Types.Struct)array[6])[1].GetBigInteger().Should().Be(new BigInteger(1785714)); + ((VM.Types.Struct)array[6])[1].GetInteger().Should().Be(new BigInteger(1785714)); } } @@ -453,7 +453,7 @@ public void TestVote() engine.Execute(); var result = engine.ResultStack.Peek(); result.GetType().Should().Be(typeof(VM.Types.Boolean)); - return (true, result.ToBoolean()); + return (true, result.GetBoolean()); } internal static (bool State, bool Result) Check_Vote(StoreView snapshot, byte[] account, byte[] pubkey, bool signAccount) @@ -483,7 +483,7 @@ internal static (bool State, bool Result) Check_Vote(StoreView snapshot, byte[] var result = engine.ResultStack.Pop(); result.Should().BeOfType(typeof(VM.Types.Boolean)); - return (true, result.ToBoolean()); + return (true, result.GetBoolean()); } internal static (bool State, bool Result) Check_RegisterValidator(StoreView snapshot, byte[] pubkey) @@ -508,7 +508,7 @@ internal static (bool State, bool Result) Check_RegisterValidator(StoreView snap var result = engine.ResultStack.Pop(); result.Should().BeOfType(typeof(VM.Types.Boolean)); - return (true, result.ToBoolean()); + return (true, result.GetBoolean()); } internal static ECPoint[] Check_GetValidators(StoreView snapshot) @@ -553,7 +553,7 @@ internal static (BigInteger Value, bool State) Check_UnclaimedGas(StoreView snap var result = engine.ResultStack.Pop(); result.Should().BeOfType(typeof(VM.Types.Integer)); - return ((result as VM.Types.Integer).GetBigInteger(), true); + return (result.GetInteger(), true); } internal static void CheckValidator(ECPoint eCPoint, DataCache.Trackable trackable) @@ -572,8 +572,8 @@ internal static void CheckBalance(byte[] account, DataCache u.GetType()).ToArray().Should().BeEquivalentTo(new Type[] { typeof(VM.Types.Integer), typeof(VM.Types.Integer), typeof(VM.Types.ByteString) }); // Balance - st[0].GetBigInteger().Should().Be(balance); // Balance - st[1].GetBigInteger().Should().Be(height); // BalanceHeight + st[0].GetInteger().Should().Be(balance); // Balance + st[1].GetInteger().Should().Be(height); // BalanceHeight st[2].GetSpan().AsSerializable().Should().BeEquivalentTo(voteTo); // Votes trackable.Key.Key.Should().BeEquivalentTo(new byte[] { 20 }.Concat(account)); diff --git a/tests/neo.UnitTests/SmartContract/Native/UT_PolicyContract.cs b/tests/neo.UnitTests/SmartContract/Native/UT_PolicyContract.cs index 5695f3d105..a33b209a12 100644 --- a/tests/neo.UnitTests/SmartContract/Native/UT_PolicyContract.cs +++ b/tests/neo.UnitTests/SmartContract/Native/UT_PolicyContract.cs @@ -5,9 +5,7 @@ using Neo.Network.P2P.Payloads; using Neo.SmartContract; using Neo.SmartContract.Native; -using Neo.SmartContract.Native.Tokens; using Neo.UnitTests.Extensions; -using Neo.VM; using System.Linq; namespace Neo.UnitTests.SmartContract.Native @@ -36,19 +34,19 @@ public void Check_Initialize() var ret = NativeContract.Policy.Call(snapshot, "getMaxTransactionsPerBlock"); ret.Should().BeOfType(); - ret.GetBigInteger().Should().Be(512); + ret.GetInteger().Should().Be(512); ret = NativeContract.Policy.Call(snapshot, "getMaxBlockSize"); ret.Should().BeOfType(); - ret.GetBigInteger().Should().Be(1024 * 256); + ret.GetInteger().Should().Be(1024 * 256); ret = NativeContract.Policy.Call(snapshot, "getMaxBlockSystemFee"); ret.Should().BeOfType(); - ret.GetBigInteger().Should().Be(9000 * 100000000L); + ret.GetInteger().Should().Be(9000 * 100000000L); ret = NativeContract.Policy.Call(snapshot, "getFeePerByte"); ret.Should().BeOfType(); - ret.GetBigInteger().Should().Be(1000); + ret.GetInteger().Should().Be(1000); ret = NativeContract.Policy.Call(snapshot, "getBlockedAccounts"); ret.Should().BeOfType(); @@ -74,33 +72,33 @@ public void Check_SetMaxBlockSize() var ret = NativeContract.Policy.Call(snapshot, new Nep5NativeContractExtensions.ManualWitness(null), "setMaxBlockSize", new ContractParameter(ContractParameterType.Integer) { Value = 1024 }); ret.Should().BeOfType(); - ret.ToBoolean().Should().BeFalse(); + ret.GetBoolean().Should().BeFalse(); ret = NativeContract.Policy.Call(snapshot, "getMaxBlockSize"); ret.Should().BeOfType(); - ret.GetBigInteger().Should().Be(1024 * 256); + ret.GetInteger().Should().Be(1024 * 256); // More than expected ret = NativeContract.Policy.Call(snapshot, new Nep5NativeContractExtensions.ManualWitness(committeeMultiSigAddr), "setMaxBlockSize", new ContractParameter(ContractParameterType.Integer) { Value = Neo.Network.P2P.Message.PayloadMaxSize }); ret.Should().BeOfType(); - ret.ToBoolean().Should().BeFalse(); + ret.GetBoolean().Should().BeFalse(); ret = NativeContract.Policy.Call(snapshot, "getMaxBlockSize"); ret.Should().BeOfType(); - ret.GetBigInteger().Should().Be(1024 * 256); + ret.GetInteger().Should().Be(1024 * 256); // With signature ret = NativeContract.Policy.Call(snapshot, new Nep5NativeContractExtensions.ManualWitness(committeeMultiSigAddr), "setMaxBlockSize", new ContractParameter(ContractParameterType.Integer) { Value = 1024 }); ret.Should().BeOfType(); - ret.ToBoolean().Should().BeTrue(); + ret.GetBoolean().Should().BeTrue(); ret = NativeContract.Policy.Call(snapshot, "getMaxBlockSize"); ret.Should().BeOfType(); - ret.GetBigInteger().Should().Be(1024); + ret.GetInteger().Should().Be(1024); } [TestMethod] @@ -122,33 +120,33 @@ public void Check_SetMaxBlockSystemFee() var ret = NativeContract.Policy.Call(snapshot, new Nep5NativeContractExtensions.ManualWitness(null), "setMaxBlockSystemFee", new ContractParameter(ContractParameterType.Integer) { Value = 1024 * (long)NativeContract.GAS.Factor }); ret.Should().BeOfType(); - ret.ToBoolean().Should().BeFalse(); + ret.GetBoolean().Should().BeFalse(); ret = NativeContract.Policy.Call(snapshot, "getMaxBlockSystemFee"); ret.Should().BeOfType(); - ret.GetBigInteger().Should().Be(9000 * (long)NativeContract.GAS.Factor); + ret.GetInteger().Should().Be(9000 * (long)NativeContract.GAS.Factor); // Less than expected ret = NativeContract.Policy.Call(snapshot, new Nep5NativeContractExtensions.ManualWitness(committeeMultiSigAddr), "setMaxBlockSystemFee", new ContractParameter(ContractParameterType.Integer) { Value = -1000 }); ret.Should().BeOfType(); - ret.ToBoolean().Should().BeFalse(); + ret.GetBoolean().Should().BeFalse(); ret = NativeContract.Policy.Call(snapshot, "getMaxBlockSystemFee"); ret.Should().BeOfType(); - ret.GetBigInteger().Should().Be(9000 * (long)NativeContract.GAS.Factor); + ret.GetInteger().Should().Be(9000 * (long)NativeContract.GAS.Factor); // With signature ret = NativeContract.Policy.Call(snapshot, new Nep5NativeContractExtensions.ManualWitness(committeeMultiSigAddr), "setMaxBlockSystemFee", new ContractParameter(ContractParameterType.Integer) { Value = 1024 * (long)NativeContract.GAS.Factor }); ret.Should().BeOfType(); - ret.ToBoolean().Should().BeTrue(); + ret.GetBoolean().Should().BeTrue(); ret = NativeContract.Policy.Call(snapshot, "getMaxBlockSystemFee"); ret.Should().BeOfType(); - ret.GetBigInteger().Should().Be(1024 * (long)NativeContract.GAS.Factor); + ret.GetInteger().Should().Be(1024 * (long)NativeContract.GAS.Factor); } [TestMethod] @@ -168,22 +166,22 @@ public void Check_SetMaxTransactionsPerBlock() var ret = NativeContract.Policy.Call(snapshot, new Nep5NativeContractExtensions.ManualWitness(), "setMaxTransactionsPerBlock", new ContractParameter(ContractParameterType.Integer) { Value = 1 }); ret.Should().BeOfType(); - ret.ToBoolean().Should().BeFalse(); + ret.GetBoolean().Should().BeFalse(); ret = NativeContract.Policy.Call(snapshot, "getMaxTransactionsPerBlock"); ret.Should().BeOfType(); - ret.GetBigInteger().Should().Be(512); + ret.GetInteger().Should().Be(512); // With signature ret = NativeContract.Policy.Call(snapshot, new Nep5NativeContractExtensions.ManualWitness(NativeContract.NEO.GetCommitteeAddress(snapshot)), "setMaxTransactionsPerBlock", new ContractParameter(ContractParameterType.Integer) { Value = 1 }); ret.Should().BeOfType(); - ret.ToBoolean().Should().BeTrue(); + ret.GetBoolean().Should().BeTrue(); ret = NativeContract.Policy.Call(snapshot, "getMaxTransactionsPerBlock"); ret.Should().BeOfType(); - ret.GetBigInteger().Should().Be(1); + ret.GetInteger().Should().Be(1); } [TestMethod] @@ -203,22 +201,22 @@ public void Check_SetFeePerByte() var ret = NativeContract.Policy.Call(snapshot, new Nep5NativeContractExtensions.ManualWitness(), "setFeePerByte", new ContractParameter(ContractParameterType.Integer) { Value = 1 }); ret.Should().BeOfType(); - ret.ToBoolean().Should().BeFalse(); + ret.GetBoolean().Should().BeFalse(); ret = NativeContract.Policy.Call(snapshot, "getFeePerByte"); ret.Should().BeOfType(); - ret.GetBigInteger().Should().Be(1000); + ret.GetInteger().Should().Be(1000); // With signature UInt160 committeeMultiSigAddr = NativeContract.NEO.GetCommitteeAddress(snapshot); ret = NativeContract.Policy.Call(snapshot, new Nep5NativeContractExtensions.ManualWitness(committeeMultiSigAddr), "setFeePerByte", new ContractParameter(ContractParameterType.Integer) { Value = 1 }); ret.Should().BeOfType(); - ret.ToBoolean().Should().BeTrue(); + ret.GetBoolean().Should().BeTrue(); ret = NativeContract.Policy.Call(snapshot, "getFeePerByte"); ret.Should().BeOfType(); - ret.GetBigInteger().Should().Be(1); + ret.GetInteger().Should().Be(1); } [TestMethod] @@ -240,7 +238,7 @@ public void Check_Block_UnblockAccount() var ret = NativeContract.Policy.Call(snapshot, new Nep5NativeContractExtensions.ManualWitness(), "blockAccount", new ContractParameter(ContractParameterType.Hash160) { Value = UInt160.Zero }); ret.Should().BeOfType(); - ret.ToBoolean().Should().BeFalse(); + ret.GetBoolean().Should().BeFalse(); ret = NativeContract.Policy.Call(snapshot, "getBlockedAccounts"); ret.Should().BeOfType(); @@ -251,7 +249,7 @@ public void Check_Block_UnblockAccount() ret = NativeContract.Policy.Call(snapshot, new Nep5NativeContractExtensions.ManualWitness(committeeMultiSigAddr), "blockAccount", new ContractParameter(ContractParameterType.Hash160) { Value = UInt160.Zero }); ret.Should().BeOfType(); - ret.ToBoolean().Should().BeTrue(); + ret.GetBoolean().Should().BeTrue(); ret = NativeContract.Policy.Call(snapshot, "getBlockedAccounts"); ret.Should().BeOfType(); @@ -263,7 +261,7 @@ public void Check_Block_UnblockAccount() ret = NativeContract.Policy.Call(snapshot, new Nep5NativeContractExtensions.ManualWitness(), "unblockAccount", new ContractParameter(ContractParameterType.Hash160) { Value = UInt160.Zero }); ret.Should().BeOfType(); - ret.ToBoolean().Should().BeFalse(); + ret.GetBoolean().Should().BeFalse(); ret = NativeContract.Policy.Call(snapshot, "getBlockedAccounts"); ret.Should().BeOfType(); @@ -275,7 +273,7 @@ public void Check_Block_UnblockAccount() ret = NativeContract.Policy.Call(snapshot, new Nep5NativeContractExtensions.ManualWitness(committeeMultiSigAddr), "unblockAccount", new ContractParameter(ContractParameterType.Hash160) { Value = UInt160.Zero }); ret.Should().BeOfType(); - ret.ToBoolean().Should().BeTrue(); + ret.GetBoolean().Should().BeTrue(); ret = NativeContract.Policy.Call(snapshot, "getBlockedAccounts"); ret.Should().BeOfType(); diff --git a/tests/neo.UnitTests/SmartContract/UT_ContainerPlaceholder.cs b/tests/neo.UnitTests/SmartContract/UT_ContainerPlaceholder.cs deleted file mode 100644 index 73023d6db8..0000000000 --- a/tests/neo.UnitTests/SmartContract/UT_ContainerPlaceholder.cs +++ /dev/null @@ -1,35 +0,0 @@ -using FluentAssertions; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Neo.SmartContract; -using Neo.VM.Types; -using System; - -namespace Neo.UnitTests.SmartContract -{ - [TestClass] - public class UT_ContainerPlaceholder - { - [TestMethod] - public void TestGenerator() - { - ContainerPlaceholder containerPlaceholder = new ContainerPlaceholder(StackItemType.Any, 0); - Assert.IsNotNull(containerPlaceholder); - } - - [TestMethod] - public void TestEquals() - { - ContainerPlaceholder containerPlaceholder = new ContainerPlaceholder(StackItemType.Any, 0); - Action action = () => containerPlaceholder.Equals(new Integer(0)); - action.Should().Throw(); - } - - [TestMethod] - public void TestGetBoolean() - { - 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 b0a2547107..283fdc1d3f 100644 --- a/tests/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs +++ b/tests/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs @@ -9,7 +9,6 @@ using Neo.SmartContract; using Neo.SmartContract.Iterators; using Neo.SmartContract.Manifest; -using Neo.VM; using Neo.VM.Types; using Neo.Wallets; using System; @@ -296,8 +295,8 @@ public void TestIterator_Create() }; ret = engine.CreateIterator(map); ret.Next(); - ret.Key().GetBigInteger().Should().Be(1); - ret.Value().GetBigInteger().Should().Be(2); + ret.Key().GetInteger().Should().Be(1); + ret.Value().GetInteger().Should().Be(2); } [TestMethod] @@ -310,7 +309,7 @@ public void TestIterator_Key() }; var wrapper = new ArrayWrapper(arr); wrapper.Next(); - engine.IteratorKey(wrapper).GetBigInteger().Should().Be(0); + engine.IteratorKey(wrapper).GetInteger().Should().Be(0); } [TestMethod] @@ -324,7 +323,7 @@ public void TestIterator_Keys() var wrapper = new ArrayWrapper(arr); var ret = engine.IteratorKeys(wrapper); ret.Next(); - ret.Value().GetBigInteger().Should().Be(0); + ret.Value().GetInteger().Should().Be(0); } [TestMethod] @@ -363,7 +362,7 @@ public void TestIterator_Concat() [TestMethod] public void TestJson_Deserialize() { - GetEngine().JsonDeserialize(new byte[] { (byte)'1' }).GetBigInteger().Should().Be(1); + GetEngine().JsonDeserialize(new byte[] { (byte)'1' }).GetInteger().Should().Be(1); } [TestMethod] diff --git a/tests/neo.UnitTests/SmartContract/UT_InteropService.cs b/tests/neo.UnitTests/SmartContract/UT_InteropService.cs index a72fb896c3..670c2530a5 100644 --- a/tests/neo.UnitTests/SmartContract/UT_InteropService.cs +++ b/tests/neo.UnitTests/SmartContract/UT_InteropService.cs @@ -297,7 +297,7 @@ public void TestRuntime_Serialize() public void TestRuntime_Deserialize() { var engine = GetEngine(); - engine.BinaryDeserialize(engine.BinarySerialize(100)).GetBigInteger().Should().Be(100); + engine.BinaryDeserialize(engine.BinarySerialize(100)).GetInteger().Should().Be(100); //FormatException Assert.ThrowsException(() => engine.BinaryDeserialize(new byte[] { 0xfa, 0x01 })); diff --git a/tests/neo.UnitTests/SmartContract/UT_JsonSerializer.cs b/tests/neo.UnitTests/SmartContract/UT_JsonSerializer.cs index 93100368a4..220627d5d0 100644 --- a/tests/neo.UnitTests/SmartContract/UT_JsonSerializer.cs +++ b/tests/neo.UnitTests/SmartContract/UT_JsonSerializer.cs @@ -1,7 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.IO.Json; using Neo.SmartContract; -using Neo.VM; using Neo.VM.Types; using System; using System.Linq; @@ -204,9 +203,7 @@ public void Serialize_EmptyObject() public void Serialize_Number() { var entry = new VM.Types.Array { 1, 9007199254740992 }; - var json = JsonSerializer.Serialize(entry).ToString(); - - Assert.AreEqual(json, "[1,\"9007199254740992\"]"); + Assert.ThrowsException(() => JsonSerializer.Serialize(entry)); } [TestMethod] @@ -262,12 +259,12 @@ public void Deserialize_Map_Test() var map = (Map)items; Assert.IsTrue(map.TryGetValue("test1", out var value)); - Assert.AreEqual(value.GetBigInteger(), 123); + Assert.AreEqual(value.GetInteger(), 123); Assert.IsTrue(map.TryGetValue("test2", out value)); - Assert.AreEqual(value.GetBigInteger(), 321); + Assert.AreEqual(value.GetInteger(), 321); - CollectionAssert.AreEqual(map.Values.Select(u => u.GetBigInteger()).ToArray(), new BigInteger[] { 123, 321 }); + CollectionAssert.AreEqual(map.Values.Select(u => u.GetInteger()).ToArray(), new BigInteger[] { 123, 321 }); } [TestMethod] @@ -290,9 +287,9 @@ public void Deserialize_Array_Bool_Str_Num() var array = (VM.Types.Array)items; - Assert.IsTrue(array[0].ToBoolean()); + Assert.IsTrue(array[0].GetBoolean()); Assert.AreEqual(array[1].GetString(), "test"); - Assert.AreEqual(array[2].GetBigInteger(), 123); + Assert.AreEqual(array[2].GetInteger(), 123); } [TestMethod] @@ -325,17 +322,17 @@ public void Deserialize_Array_OfArray() array = (VM.Types.Array)array[0]; Assert.AreEqual(array.Count, 3); - Assert.IsTrue(array[0].ToBoolean()); + Assert.IsTrue(array[0].GetBoolean()); Assert.AreEqual(array[1].GetString(), "test1"); - Assert.AreEqual(array[2].GetBigInteger(), 123); + Assert.AreEqual(array[2].GetInteger(), 123); array = (VM.Types.Array)items; array = (VM.Types.Array)array[1]; Assert.AreEqual(array.Count, 3); - Assert.IsTrue(array[0].ToBoolean()); + Assert.IsTrue(array[0].GetBoolean()); Assert.AreEqual(array[1].GetString(), "test2"); - Assert.AreEqual(array[2].GetBigInteger(), 321); + Assert.AreEqual(array[2].GetInteger(), 321); } } } diff --git a/tests/neo.UnitTests/SmartContract/UT_Syscalls.Callback.cs b/tests/neo.UnitTests/SmartContract/UT_Syscalls.Callback.cs index 633df8e7d7..e97e144637 100644 --- a/tests/neo.UnitTests/SmartContract/UT_Syscalls.Callback.cs +++ b/tests/neo.UnitTests/SmartContract/UT_Syscalls.Callback.cs @@ -62,7 +62,7 @@ public void InvokeCallbackTest() Assert.AreEqual(1, engine.ResultStack.Count); var item = engine.ResultStack.Pop(); - Assert.AreEqual(4, item.GetBigInteger()); + Assert.AreEqual(4, item.GetInteger()); } [TestMethod] diff --git a/tests/neo.UnitTests/SmartContract/UT_Syscalls.cs b/tests/neo.UnitTests/SmartContract/UT_Syscalls.cs index 12f576a092..192e7292ff 100644 --- a/tests/neo.UnitTests/SmartContract/UT_Syscalls.cs +++ b/tests/neo.UnitTests/SmartContract/UT_Syscalls.cs @@ -125,7 +125,7 @@ public void Json_Deserialize() Assert.AreEqual(2, engine.ResultStack.Count); engine.ResultStack.Pop(); - Assert.IsTrue(engine.ResultStack.Pop().GetBigInteger() == 123); + Assert.IsTrue(engine.ResultStack.Pop().GetInteger() == 123); } } @@ -286,7 +286,7 @@ public void System_Runtime_GasLeft() CollectionAssert.AreEqual ( - engine.ResultStack.Select(u => (int)((VM.Types.Integer)u).GetBigInteger()).ToArray(), + engine.ResultStack.Select(u => (int)u.GetInteger()).ToArray(), new int[] { 99_999_570, 99_999_140, 99_998_650 } ); } @@ -307,7 +307,7 @@ public void System_Runtime_GasLeft() Assert.AreEqual(engine.Execute(), VMState.HALT); Assert.AreEqual(1, engine.ResultStack.Count); Assert.IsInstanceOfType(engine.ResultStack.Peek(), typeof(Integer)); - Assert.AreEqual(-1, engine.ResultStack.Pop().GetBigInteger()); + Assert.AreEqual(-1, engine.ResultStack.Pop().GetInteger()); } } @@ -361,7 +361,7 @@ public void System_Runtime_GetInvocationCounter() CollectionAssert.AreEqual ( - engine.ResultStack.Select(u => (int)((VM.Types.Integer)u).GetBigInteger()).ToArray(), + engine.ResultStack.Select(u => (int)u.GetInteger()).ToArray(), new int[] { 1, /* A */ diff --git a/tests/neo.UnitTests/VM/UT_Helper.cs b/tests/neo.UnitTests/VM/UT_Helper.cs index 4c89fe09a5..9c22266069 100644 --- a/tests/neo.UnitTests/VM/UT_Helper.cs +++ b/tests/neo.UnitTests/VM/UT_Helper.cs @@ -150,19 +150,19 @@ public void TestToStackItem() Assert.ThrowsException(() => parameter.ToStackItem()); ContractParameter byteParameter = new ContractParameter { Type = ContractParameterType.ByteArray, Value = "00e057eb481b".HexToBytes() }; - Assert.AreEqual(30000000000000L, (long)byteParameter.ToStackItem().GetBigInteger()); + Assert.AreEqual(30000000000000L, (long)byteParameter.ToStackItem().GetInteger()); ContractParameter boolParameter = new ContractParameter { Type = ContractParameterType.Boolean, Value = false }; - Assert.AreEqual(false, boolParameter.ToStackItem().ToBoolean()); + Assert.AreEqual(false, boolParameter.ToStackItem().GetBoolean()); ContractParameter intParameter = new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1000) }; - Assert.AreEqual(1000, intParameter.ToStackItem().GetBigInteger()); + Assert.AreEqual(1000, intParameter.ToStackItem().GetInteger()); ContractParameter h160Parameter = new ContractParameter { Type = ContractParameterType.Hash160, Value = UInt160.Zero }; - Assert.AreEqual(0, h160Parameter.ToStackItem().GetBigInteger()); + Assert.AreEqual(0, h160Parameter.ToStackItem().GetInteger()); ContractParameter h256Parameter = new ContractParameter { Type = ContractParameterType.Hash256, Value = UInt256.Zero }; - Assert.AreEqual(0, h256Parameter.ToStackItem().GetBigInteger()); + Assert.AreEqual(0, h256Parameter.ToStackItem().GetInteger()); ContractParameter pkParameter = new ContractParameter { Type = ContractParameterType.PublicKey, Value = ECPoint.Parse("02f9ec1fd0a98796cf75b586772a4ddd41a0af07a1dbdf86a7238f74fb72503575", ECCurve.Secp256r1) }; Assert.AreEqual("02f9ec1fd0a98796cf75b586772a4ddd41a0af07a1dbdf86a7238f74fb72503575", pkParameter.ToStackItem().GetSpan().ToHexString()); @@ -177,10 +177,10 @@ public void TestToStackItem() Assert.AreEqual(StackItem.Null, interopParameter2.ToStackItem()); ContractParameter arrayParameter = new ContractParameter { Type = ContractParameterType.Array, Value = new[] { byteParameter, boolParameter, intParameter, h160Parameter, h256Parameter, pkParameter, strParameter }.ToList() }; - Assert.AreEqual(1000, ((VM.Types.Array)arrayParameter.ToStackItem())[2].GetBigInteger()); + Assert.AreEqual(1000, ((VM.Types.Array)arrayParameter.ToStackItem())[2].GetInteger()); ContractParameter mapParameter = new ContractParameter { Type = ContractParameterType.Map, Value = new[] { new KeyValuePair(byteParameter, pkParameter) } }; - Assert.AreEqual(30000000000000L, (long)((VM.Types.Map)mapParameter.ToStackItem()).Keys.First().GetBigInteger()); + Assert.AreEqual(30000000000000L, (long)((VM.Types.Map)mapParameter.ToStackItem()).Keys.First().GetInteger()); } [TestMethod]