diff --git a/src/Neo.Extensions/StringExtensions.cs b/src/Neo.Extensions/StringExtensions.cs
index 8d851bf905..b84869b2e1 100644
--- a/src/Neo.Extensions/StringExtensions.cs
+++ b/src/Neo.Extensions/StringExtensions.cs
@@ -32,5 +32,16 @@ public static byte[] HexToBytes(this string value)
result[i] = byte.Parse(value.Substring(i * 2, 2), NumberStyles.AllowHexSpecifier);
return result;
}
+
+ ///
+ /// Gets the size of the specified encoded in variable-length encoding.
+ ///
+ /// The specified .
+ /// The size of the .
+ public static int GetVarSize(this string value)
+ {
+ var size = Utility.StrictUTF8.GetByteCount(value);
+ return UnsafeData.GetVarSize(size) + size;
+ }
}
}
diff --git a/src/Neo.Extensions/UnsafeData.cs b/src/Neo.Extensions/UnsafeData.cs
new file mode 100644
index 0000000000..6d4c9a6f8e
--- /dev/null
+++ b/src/Neo.Extensions/UnsafeData.cs
@@ -0,0 +1,31 @@
+// Copyright (C) 2015-2024 The Neo Project.
+//
+// UnsafeData.cs file belongs to the neo project and is free
+// software distributed under the MIT software license, see the
+// accompanying file LICENSE in the main directory of the
+// repository or http://www.opensource.org/licenses/mit-license.php
+// for more details.
+//
+// Redistribution and use in source and binary forms with or without
+// modifications are permitted.
+
+namespace Neo.Extensions
+{
+ public static class UnsafeData
+ {
+ ///
+ /// Gets the size of variable-length of the data.
+ ///
+ /// The length of the data.
+ /// The size of variable-length of the data.
+ public static int GetVarSize(int value)
+ {
+ if (value < 0xFD)
+ return sizeof(byte);
+ else if (value <= 0xFFFF)
+ return sizeof(byte) + sizeof(ushort);
+ else
+ return sizeof(byte) + sizeof(uint);
+ }
+ }
+}
diff --git a/src/Neo/Extensions/Collections/ICollectionExtensions.cs b/src/Neo/Extensions/Collections/ICollectionExtensions.cs
new file mode 100644
index 0000000000..724def6d80
--- /dev/null
+++ b/src/Neo/Extensions/Collections/ICollectionExtensions.cs
@@ -0,0 +1,74 @@
+// Copyright (C) 2015-2024 The Neo Project.
+//
+// ICollectionExtensions.cs file belongs to the neo project and is free
+// software distributed under the MIT software license, see the
+// accompanying file LICENSE in the main directory of the
+// repository or http://www.opensource.org/licenses/mit-license.php
+// for more details.
+//
+// Redistribution and use in source and binary forms with or without
+// modifications are permitted.
+
+using Neo.IO;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.InteropServices;
+
+namespace Neo.Extensions
+{
+ public static class ICollectionExtensions
+ {
+ ///
+ /// Gets the size of the specified array encoded in variable-length encoding.
+ ///
+ /// The type of the array element.
+ /// The specified array.
+ /// The size of the array.
+ public static int GetVarSize(this IReadOnlyCollection value)
+ {
+ int value_size;
+ var t = typeof(T);
+ if (typeof(ISerializable).IsAssignableFrom(t))
+ {
+ value_size = value.OfType().Sum(p => p.Size);
+ }
+ else if (t.GetTypeInfo().IsEnum)
+ {
+ int element_size;
+ var u = t.GetTypeInfo().GetEnumUnderlyingType();
+ if (u == typeof(sbyte) || u == typeof(byte))
+ element_size = 1;
+ else if (u == typeof(short) || u == typeof(ushort))
+ element_size = 2;
+ else if (u == typeof(int) || u == typeof(uint))
+ element_size = 4;
+ else //if (u == typeof(long) || u == typeof(ulong))
+ element_size = 8;
+ value_size = value.Count * element_size;
+ }
+ else
+ {
+ value_size = value.Count * Marshal.SizeOf();
+ }
+ return UnsafeData.GetVarSize(value.Count) + value_size;
+ }
+
+ ///
+ /// Converts an array to a byte array.
+ ///
+ /// The type of the array element.
+ /// The array to be converted.
+ /// The converted byte array.
+ public static byte[] ToByteArray(this IReadOnlyCollection value)
+ where T : ISerializable
+ {
+ using MemoryStream ms = new();
+ using BinaryWriter writer = new(ms, Utility.StrictUTF8, true);
+ writer.Write(value);
+ writer.Flush();
+ return ms.ToArray();
+ }
+ }
+}
diff --git a/src/Neo/Extensions/MemoryExtensions.cs b/src/Neo/Extensions/MemoryExtensions.cs
new file mode 100644
index 0000000000..f6576387de
--- /dev/null
+++ b/src/Neo/Extensions/MemoryExtensions.cs
@@ -0,0 +1,60 @@
+// Copyright (C) 2015-2024 The Neo Project.
+//
+// MemoryExtensions.cs file belongs to the neo project and is free
+// software distributed under the MIT software license, see the
+// accompanying file LICENSE in the main directory of the
+// repository or http://www.opensource.org/licenses/mit-license.php
+// for more details.
+//
+// Redistribution and use in source and binary forms with or without
+// modifications are permitted.
+
+using Neo.IO;
+using System;
+using System.Reflection;
+
+namespace Neo.Extensions
+{
+ public static class MemoryExtensions
+ {
+ ///
+ /// Converts a byte array to an object.
+ ///
+ /// The type to convert to.
+ /// The byte array to be converted.
+ /// The converted object.
+ public static T AsSerializable(this ReadOnlyMemory value)
+ where T : ISerializable, new()
+ {
+ if (value.IsEmpty) throw new FormatException();
+ MemoryReader reader = new(value);
+ return reader.ReadSerializable();
+ }
+
+ ///
+ /// Converts a byte array to an object.
+ ///
+ /// The byte array to be converted.
+ /// The type to convert to.
+ /// The converted object.
+ public static ISerializable AsSerializable(this ReadOnlyMemory value, Type type)
+ {
+ if (!typeof(ISerializable).GetTypeInfo().IsAssignableFrom(type))
+ throw new InvalidCastException();
+ var serializable = (ISerializable)Activator.CreateInstance(type);
+ MemoryReader reader = new(value);
+ serializable.Deserialize(ref reader);
+ return serializable;
+ }
+
+ ///
+ /// Gets the size of the specified array encoded in variable-length encoding.
+ ///
+ /// The specified array.
+ /// The size of the array.
+ public static int GetVarSize(this ReadOnlyMemory value)
+ {
+ return UnsafeData.GetVarSize(value.Length) + value.Length;
+ }
+ }
+}
diff --git a/src/Neo/IO/Caching/ReflectionCache.cs b/src/Neo/IO/Caching/ReflectionCache.cs
index 5007b67740..f24f4e5ab6 100644
--- a/src/Neo/IO/Caching/ReflectionCache.cs
+++ b/src/Neo/IO/Caching/ReflectionCache.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using System;
using System.Collections.Generic;
using System.Reflection;
diff --git a/src/Neo/IO/Helper.cs b/src/Neo/IO/Helper.cs
index 2e6d362ee1..d0e5a00ec9 100644
--- a/src/Neo/IO/Helper.cs
+++ b/src/Neo/IO/Helper.cs
@@ -14,9 +14,6 @@
using System.Buffers.Binary;
using System.Collections.Generic;
using System.IO;
-using System.Linq;
-using System.Reflection;
-using System.Runtime.InteropServices;
namespace Neo.IO
{
@@ -38,35 +35,6 @@ public static class Helper
return reader.ReadSerializable();
}
- ///
- /// Converts a byte array to an object.
- ///
- /// The type to convert to.
- /// The byte array to be converted.
- /// The converted object.
- public static T AsSerializable(this ReadOnlyMemory value) where T : ISerializable, new()
- {
- if (value.IsEmpty) throw new FormatException();
- MemoryReader reader = new(value);
- return reader.ReadSerializable();
- }
-
- ///
- /// Converts a byte array to an object.
- ///
- /// The byte array to be converted.
- /// The type to convert to.
- /// The converted object.
- public static ISerializable AsSerializable(this ReadOnlyMemory value, Type type)
- {
- if (!typeof(ISerializable).GetTypeInfo().IsAssignableFrom(type))
- throw new InvalidCastException();
- ISerializable serializable = (ISerializable)Activator.CreateInstance(type);
- MemoryReader reader = new(value);
- serializable.Deserialize(ref reader);
- return serializable;
- }
-
///
/// Converts a byte array to an array.
///
@@ -124,77 +92,6 @@ public static byte[] DecompressLz4(this ReadOnlySpan data, int maxOutput)
return result;
}
- ///
- /// Gets the size of variable-length of the data.
- ///
- /// The length of the data.
- /// The size of variable-length of the data.
- public static int GetVarSize(int value)
- {
- if (value < 0xFD)
- return sizeof(byte);
- else if (value <= 0xFFFF)
- return sizeof(byte) + sizeof(ushort);
- else
- return sizeof(byte) + sizeof(uint);
- }
-
- ///
- /// Gets the size of the specified array encoded in variable-length encoding.
- ///
- /// The type of the array element.
- /// The specified array.
- /// The size of the array.
- public static int GetVarSize(this IReadOnlyCollection value)
- {
- int value_size;
- Type t = typeof(T);
- if (typeof(ISerializable).IsAssignableFrom(t))
- {
- value_size = value.OfType().Sum(p => p.Size);
- }
- else if (t.GetTypeInfo().IsEnum)
- {
- int element_size;
- Type u = t.GetTypeInfo().GetEnumUnderlyingType();
- if (u == typeof(sbyte) || u == typeof(byte))
- element_size = 1;
- else if (u == typeof(short) || u == typeof(ushort))
- element_size = 2;
- else if (u == typeof(int) || u == typeof(uint))
- element_size = 4;
- else //if (u == typeof(long) || u == typeof(ulong))
- element_size = 8;
- value_size = value.Count * element_size;
- }
- else
- {
- value_size = value.Count * Marshal.SizeOf();
- }
- return GetVarSize(value.Count) + value_size;
- }
-
- ///
- /// Gets the size of the specified array encoded in variable-length encoding.
- ///
- /// The specified array.
- /// The size of the array.
- public static int GetVarSize(this ReadOnlyMemory value)
- {
- return GetVarSize(value.Length) + value.Length;
- }
-
- ///
- /// Gets the size of the specified encoded in variable-length encoding.
- ///
- /// The specified .
- /// The size of the .
- public static int GetVarSize(this string value)
- {
- int size = Utility.StrictUTF8.GetByteCount(value);
- return GetVarSize(size) + size;
- }
-
///
/// Reads a byte array of the specified size from a .
///
@@ -315,21 +212,6 @@ public static byte[] ToArray(this ISerializable value)
return ms.ToArray();
}
- ///
- /// Converts an array to a byte array.
- ///
- /// The type of the array element.
- /// The array to be converted.
- /// The converted byte array.
- public static byte[] ToByteArray(this IReadOnlyCollection value) where T : ISerializable
- {
- using MemoryStream ms = new();
- using BinaryWriter writer = new(ms, Utility.StrictUTF8, true);
- writer.Write(value);
- writer.Flush();
- return ms.ToArray();
- }
-
///
/// Writes an object into a .
///
diff --git a/src/Neo/Network/P2P/Message.cs b/src/Neo/Network/P2P/Message.cs
index 9d3c63a85b..96c79f2b10 100644
--- a/src/Neo/Network/P2P/Message.cs
+++ b/src/Neo/Network/P2P/Message.cs
@@ -10,6 +10,7 @@
// modifications are permitted.
using Akka.IO;
+using Neo.Extensions;
using Neo.IO;
using Neo.IO.Caching;
using System;
diff --git a/src/Neo/Network/P2P/Payloads/AddrPayload.cs b/src/Neo/Network/P2P/Payloads/AddrPayload.cs
index ebdceb65ec..90958a38ef 100644
--- a/src/Neo/Network/P2P/Payloads/AddrPayload.cs
+++ b/src/Neo/Network/P2P/Payloads/AddrPayload.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using System;
using System.IO;
diff --git a/src/Neo/Network/P2P/Payloads/Block.cs b/src/Neo/Network/P2P/Payloads/Block.cs
index 3c727b9886..ab28c6c363 100644
--- a/src/Neo/Network/P2P/Payloads/Block.cs
+++ b/src/Neo/Network/P2P/Payloads/Block.cs
@@ -10,6 +10,7 @@
// modifications are permitted.
using Neo.Cryptography;
+using Neo.Extensions;
using Neo.IO;
using Neo.Json;
using Neo.Ledger;
diff --git a/src/Neo/Network/P2P/Payloads/Conditions/AndCondition.cs b/src/Neo/Network/P2P/Payloads/Conditions/AndCondition.cs
index e395b10d5d..2fed4d32fb 100644
--- a/src/Neo/Network/P2P/Payloads/Conditions/AndCondition.cs
+++ b/src/Neo/Network/P2P/Payloads/Conditions/AndCondition.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using Neo.Json;
using Neo.SmartContract;
diff --git a/src/Neo/Network/P2P/Payloads/Conditions/OrCondition.cs b/src/Neo/Network/P2P/Payloads/Conditions/OrCondition.cs
index b06fc922a8..72b27529c4 100644
--- a/src/Neo/Network/P2P/Payloads/Conditions/OrCondition.cs
+++ b/src/Neo/Network/P2P/Payloads/Conditions/OrCondition.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using Neo.Json;
using Neo.SmartContract;
diff --git a/src/Neo/Network/P2P/Payloads/ExtensiblePayload.cs b/src/Neo/Network/P2P/Payloads/ExtensiblePayload.cs
index 306f6327ab..6e2b94a17d 100644
--- a/src/Neo/Network/P2P/Payloads/ExtensiblePayload.cs
+++ b/src/Neo/Network/P2P/Payloads/ExtensiblePayload.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using Neo.Persistence;
using Neo.SmartContract;
diff --git a/src/Neo/Network/P2P/Payloads/FilterAddPayload.cs b/src/Neo/Network/P2P/Payloads/FilterAddPayload.cs
index ff4aa1287b..4f4e9df152 100644
--- a/src/Neo/Network/P2P/Payloads/FilterAddPayload.cs
+++ b/src/Neo/Network/P2P/Payloads/FilterAddPayload.cs
@@ -10,6 +10,7 @@
// modifications are permitted.
using Neo.Cryptography;
+using Neo.Extensions;
using Neo.IO;
using System;
using System.IO;
diff --git a/src/Neo/Network/P2P/Payloads/FilterLoadPayload.cs b/src/Neo/Network/P2P/Payloads/FilterLoadPayload.cs
index 2608e0e7b0..f0eae27278 100644
--- a/src/Neo/Network/P2P/Payloads/FilterLoadPayload.cs
+++ b/src/Neo/Network/P2P/Payloads/FilterLoadPayload.cs
@@ -10,6 +10,7 @@
// modifications are permitted.
using Neo.Cryptography;
+using Neo.Extensions;
using Neo.IO;
using System;
using System.IO;
diff --git a/src/Neo/Network/P2P/Payloads/HeadersPayload.cs b/src/Neo/Network/P2P/Payloads/HeadersPayload.cs
index 152ba32857..e5800d4544 100644
--- a/src/Neo/Network/P2P/Payloads/HeadersPayload.cs
+++ b/src/Neo/Network/P2P/Payloads/HeadersPayload.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using System;
using System.IO;
diff --git a/src/Neo/Network/P2P/Payloads/InvPayload.cs b/src/Neo/Network/P2P/Payloads/InvPayload.cs
index aa4d340d99..17625f6dc4 100644
--- a/src/Neo/Network/P2P/Payloads/InvPayload.cs
+++ b/src/Neo/Network/P2P/Payloads/InvPayload.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using System;
using System.Collections.Generic;
diff --git a/src/Neo/Network/P2P/Payloads/MerkleBlockPayload.cs b/src/Neo/Network/P2P/Payloads/MerkleBlockPayload.cs
index aebb17d5d9..97f9ed0f27 100644
--- a/src/Neo/Network/P2P/Payloads/MerkleBlockPayload.cs
+++ b/src/Neo/Network/P2P/Payloads/MerkleBlockPayload.cs
@@ -10,6 +10,7 @@
// modifications are permitted.
using Neo.Cryptography;
+using Neo.Extensions;
using Neo.IO;
using System;
using System.Collections;
diff --git a/src/Neo/Network/P2P/Payloads/OracleResponse.cs b/src/Neo/Network/P2P/Payloads/OracleResponse.cs
index 2770f556a8..bf3aa70cf4 100644
--- a/src/Neo/Network/P2P/Payloads/OracleResponse.cs
+++ b/src/Neo/Network/P2P/Payloads/OracleResponse.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using Neo.Json;
using Neo.Persistence;
diff --git a/src/Neo/Network/P2P/Payloads/Signer.cs b/src/Neo/Network/P2P/Payloads/Signer.cs
index 79065408f4..9b5e317abc 100644
--- a/src/Neo/Network/P2P/Payloads/Signer.cs
+++ b/src/Neo/Network/P2P/Payloads/Signer.cs
@@ -10,6 +10,7 @@
// modifications are permitted.
using Neo.Cryptography.ECC;
+using Neo.Extensions;
using Neo.IO;
using Neo.Json;
using Neo.Network.P2P.Payloads.Conditions;
diff --git a/src/Neo/Network/P2P/Payloads/Transaction.cs b/src/Neo/Network/P2P/Payloads/Transaction.cs
index b922674d91..6f41b5141b 100644
--- a/src/Neo/Network/P2P/Payloads/Transaction.cs
+++ b/src/Neo/Network/P2P/Payloads/Transaction.cs
@@ -11,6 +11,7 @@
using Neo.Cryptography;
using Neo.Cryptography.ECC;
+using Neo.Extensions;
using Neo.IO;
using Neo.Json;
using Neo.Ledger;
diff --git a/src/Neo/Network/P2P/Payloads/Witness.cs b/src/Neo/Network/P2P/Payloads/Witness.cs
index 34932cc7fb..b3da47d2b7 100644
--- a/src/Neo/Network/P2P/Payloads/Witness.cs
+++ b/src/Neo/Network/P2P/Payloads/Witness.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using Neo.Json;
using Neo.SmartContract;
diff --git a/src/Neo/SmartContract/MethodToken.cs b/src/Neo/SmartContract/MethodToken.cs
index 1b391edd32..1b8fa00242 100644
--- a/src/Neo/SmartContract/MethodToken.cs
+++ b/src/Neo/SmartContract/MethodToken.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using Neo.Json;
using System;
diff --git a/src/Neo/SmartContract/Native/LedgerContract.cs b/src/Neo/SmartContract/Native/LedgerContract.cs
index 329e0565d5..3d2d16e023 100644
--- a/src/Neo/SmartContract/Native/LedgerContract.cs
+++ b/src/Neo/SmartContract/Native/LedgerContract.cs
@@ -11,6 +11,7 @@
#pragma warning disable IDE0051
+using Neo.Extensions;
using Neo.IO;
using Neo.Network.P2P.Payloads;
using Neo.Persistence;
diff --git a/src/Neo/SmartContract/Native/NeoToken.cs b/src/Neo/SmartContract/Native/NeoToken.cs
index 40f63355df..d639a55caf 100644
--- a/src/Neo/SmartContract/Native/NeoToken.cs
+++ b/src/Neo/SmartContract/Native/NeoToken.cs
@@ -12,6 +12,7 @@
#pragma warning disable IDE0051
using Neo.Cryptography.ECC;
+using Neo.Extensions;
using Neo.IO;
using Neo.Persistence;
using Neo.SmartContract.Iterators;
diff --git a/src/Neo/SmartContract/Native/TransactionState.cs b/src/Neo/SmartContract/Native/TransactionState.cs
index b17296b42d..050358f179 100644
--- a/src/Neo/SmartContract/Native/TransactionState.cs
+++ b/src/Neo/SmartContract/Native/TransactionState.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using Neo.Network.P2P.Payloads;
using Neo.VM;
diff --git a/src/Neo/SmartContract/Native/TrimmedBlock.cs b/src/Neo/SmartContract/Native/TrimmedBlock.cs
index 4cc4c39c0f..c2bab2567c 100644
--- a/src/Neo/SmartContract/Native/TrimmedBlock.cs
+++ b/src/Neo/SmartContract/Native/TrimmedBlock.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using Neo.Network.P2P.Payloads;
using Neo.VM;
diff --git a/src/Neo/SmartContract/NefFile.cs b/src/Neo/SmartContract/NefFile.cs
index 3e343d3be2..5638447688 100644
--- a/src/Neo/SmartContract/NefFile.cs
+++ b/src/Neo/SmartContract/NefFile.cs
@@ -10,6 +10,7 @@
// modifications are permitted.
using Neo.Cryptography;
+using Neo.Extensions;
using Neo.IO;
using Neo.Json;
using Neo.VM;
diff --git a/src/Neo/Wallets/Helper.cs b/src/Neo/Wallets/Helper.cs
index 5beae49ab9..9f24e54764 100644
--- a/src/Neo/Wallets/Helper.cs
+++ b/src/Neo/Wallets/Helper.cs
@@ -10,6 +10,7 @@
// modifications are permitted.
using Neo.Cryptography;
+using Neo.Extensions;
using Neo.IO;
using Neo.Network.P2P;
using Neo.Network.P2P.Payloads;
@@ -93,7 +94,7 @@ public static long CalculateNetworkFee(this Transaction tx, DataCache snapshot,
UInt160[] hashes = tx.GetScriptHashesForVerifying(snapshot);
// base size for transaction: includes const_header + signers + attributes + script + hashes
- int size = Transaction.HeaderSize + tx.Signers.GetVarSize() + tx.Attributes.GetVarSize() + tx.Script.GetVarSize() + IO.Helper.GetVarSize(hashes.Length), index = -1;
+ int size = Transaction.HeaderSize + tx.Signers.GetVarSize() + tx.Attributes.GetVarSize() + tx.Script.GetVarSize() + UnsafeData.GetVarSize(hashes.Length), index = -1;
uint exec_fee_factor = NativeContract.Policy.GetExecFeeFactor(snapshot);
long networkFee = 0;
foreach (UInt160 hash in hashes)
@@ -152,7 +153,7 @@ public static long CalculateNetworkFee(this Transaction tx, DataCache snapshot,
else if (IsMultiSigContract(witnessScript, out int m, out int n))
{
int size_inv = 66 * m;
- size += IO.Helper.GetVarSize(size_inv) + size_inv + witnessScript.GetVarSize();
+ size += UnsafeData.GetVarSize(size_inv) + size_inv + witnessScript.GetVarSize();
networkFee += exec_fee_factor * MultiSignatureContractCost(m, n);
}
// We can support more contract types in the future.
diff --git a/src/Plugins/ApplicationLogs/Store/States/BlockLogState.cs b/src/Plugins/ApplicationLogs/Store/States/BlockLogState.cs
index 54369a672a..ce957b79f6 100644
--- a/src/Plugins/ApplicationLogs/Store/States/BlockLogState.cs
+++ b/src/Plugins/ApplicationLogs/Store/States/BlockLogState.cs
@@ -9,7 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
-using Neo;
+using Neo.Extensions;
using Neo.IO;
namespace Neo.Plugins.ApplicationLogs.Store.States
diff --git a/src/Plugins/ApplicationLogs/Store/States/EngineLogState.cs b/src/Plugins/ApplicationLogs/Store/States/EngineLogState.cs
index 96f9041aaf..4a997757f5 100644
--- a/src/Plugins/ApplicationLogs/Store/States/EngineLogState.cs
+++ b/src/Plugins/ApplicationLogs/Store/States/EngineLogState.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
namespace Neo.Plugins.ApplicationLogs.Store.States
diff --git a/src/Plugins/ApplicationLogs/Store/States/ExecutionLogState.cs b/src/Plugins/ApplicationLogs/Store/States/ExecutionLogState.cs
index 210ac36283..ace7f0e42f 100644
--- a/src/Plugins/ApplicationLogs/Store/States/ExecutionLogState.cs
+++ b/src/Plugins/ApplicationLogs/Store/States/ExecutionLogState.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using Neo.Ledger;
using Neo.VM;
diff --git a/src/Plugins/ApplicationLogs/Store/States/NotifyLogState.cs b/src/Plugins/ApplicationLogs/Store/States/NotifyLogState.cs
index 70b53268e5..87cc5e60ae 100644
--- a/src/Plugins/ApplicationLogs/Store/States/NotifyLogState.cs
+++ b/src/Plugins/ApplicationLogs/Store/States/NotifyLogState.cs
@@ -9,7 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
-using Neo;
+using Neo.Extensions;
using Neo.IO;
using Neo.SmartContract;
diff --git a/src/Plugins/ApplicationLogs/Store/States/TransactionEngineLogState.cs b/src/Plugins/ApplicationLogs/Store/States/TransactionEngineLogState.cs
index 9417f984e2..80e5be7e97 100644
--- a/src/Plugins/ApplicationLogs/Store/States/TransactionEngineLogState.cs
+++ b/src/Plugins/ApplicationLogs/Store/States/TransactionEngineLogState.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
namespace Neo.Plugins.ApplicationLogs.Store.States
diff --git a/src/Plugins/ApplicationLogs/Store/States/TransactionLogState.cs b/src/Plugins/ApplicationLogs/Store/States/TransactionLogState.cs
index 1667478509..bca012ec50 100644
--- a/src/Plugins/ApplicationLogs/Store/States/TransactionLogState.cs
+++ b/src/Plugins/ApplicationLogs/Store/States/TransactionLogState.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
namespace Neo.Plugins.ApplicationLogs.Store.States
diff --git a/src/Plugins/DBFTPlugin/Consensus/ConsensusContext.Get.cs b/src/Plugins/DBFTPlugin/Consensus/ConsensusContext.Get.cs
index edffc1cb09..d055ddbb4a 100644
--- a/src/Plugins/DBFTPlugin/Consensus/ConsensusContext.Get.cs
+++ b/src/Plugins/DBFTPlugin/Consensus/ConsensusContext.Get.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.Network.P2P.Payloads;
using Neo.Plugins.DBFTPlugin.Messages;
using Neo.SmartContract;
@@ -110,7 +111,7 @@ internal int GetExpectedBlockSizeWithoutTransactions(int expectedTransactions)
sizeof(byte) + // PrimaryIndex
UInt160.Length + // NextConsensus
1 + _witnessSize + // Witness
- IO.Helper.GetVarSize(expectedTransactions);
+ UnsafeData.GetVarSize(expectedTransactions);
}
}
}
diff --git a/src/Plugins/DBFTPlugin/Messages/ConsensusMessage.cs b/src/Plugins/DBFTPlugin/Messages/ConsensusMessage.cs
index de030d166d..f8cd8cbc14 100644
--- a/src/Plugins/DBFTPlugin/Messages/ConsensusMessage.cs
+++ b/src/Plugins/DBFTPlugin/Messages/ConsensusMessage.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using Neo.Plugins.DBFTPlugin.Types;
using System;
diff --git a/src/Plugins/DBFTPlugin/Messages/PrepareRequest.cs b/src/Plugins/DBFTPlugin/Messages/PrepareRequest.cs
index 495ccbd726..c5b150b572 100644
--- a/src/Plugins/DBFTPlugin/Messages/PrepareRequest.cs
+++ b/src/Plugins/DBFTPlugin/Messages/PrepareRequest.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using Neo.Plugins.DBFTPlugin.Types;
using System;
diff --git a/src/Plugins/DBFTPlugin/Messages/RecoveryMessage/RecoveryMessage.ChangeViewPayloadCompact.cs b/src/Plugins/DBFTPlugin/Messages/RecoveryMessage/RecoveryMessage.ChangeViewPayloadCompact.cs
index 2d7283cd22..40528d8aaf 100644
--- a/src/Plugins/DBFTPlugin/Messages/RecoveryMessage/RecoveryMessage.ChangeViewPayloadCompact.cs
+++ b/src/Plugins/DBFTPlugin/Messages/RecoveryMessage/RecoveryMessage.ChangeViewPayloadCompact.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using System;
using System.IO;
diff --git a/src/Plugins/DBFTPlugin/Messages/RecoveryMessage/RecoveryMessage.CommitPayloadCompact.cs b/src/Plugins/DBFTPlugin/Messages/RecoveryMessage/RecoveryMessage.CommitPayloadCompact.cs
index 6d3880f3c0..dc7d532d30 100644
--- a/src/Plugins/DBFTPlugin/Messages/RecoveryMessage/RecoveryMessage.CommitPayloadCompact.cs
+++ b/src/Plugins/DBFTPlugin/Messages/RecoveryMessage/RecoveryMessage.CommitPayloadCompact.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using System;
using System.IO;
diff --git a/src/Plugins/DBFTPlugin/Messages/RecoveryMessage/RecoveryMessage.PreparationPayloadCompact.cs b/src/Plugins/DBFTPlugin/Messages/RecoveryMessage/RecoveryMessage.PreparationPayloadCompact.cs
index 8fae1596ef..cec8a45a3a 100644
--- a/src/Plugins/DBFTPlugin/Messages/RecoveryMessage/RecoveryMessage.PreparationPayloadCompact.cs
+++ b/src/Plugins/DBFTPlugin/Messages/RecoveryMessage/RecoveryMessage.PreparationPayloadCompact.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using System;
using System.IO;
diff --git a/src/Plugins/DBFTPlugin/Messages/RecoveryMessage/RecoveryMessage.cs b/src/Plugins/DBFTPlugin/Messages/RecoveryMessage/RecoveryMessage.cs
index 2de33470ea..2feb919520 100644
--- a/src/Plugins/DBFTPlugin/Messages/RecoveryMessage/RecoveryMessage.cs
+++ b/src/Plugins/DBFTPlugin/Messages/RecoveryMessage/RecoveryMessage.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using Neo.Network.P2P.Payloads;
using Neo.Plugins.DBFTPlugin.Consensus;
diff --git a/src/Plugins/MPTTrie/Cryptography/MPTTrie/Node.Extension.cs b/src/Plugins/MPTTrie/Cryptography/MPTTrie/Node.Extension.cs
index 510db49250..0d68564732 100644
--- a/src/Plugins/MPTTrie/Cryptography/MPTTrie/Node.Extension.cs
+++ b/src/Plugins/MPTTrie/Cryptography/MPTTrie/Node.Extension.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using Neo.SmartContract;
using System;
diff --git a/src/Plugins/MPTTrie/Cryptography/MPTTrie/Node.Leaf.cs b/src/Plugins/MPTTrie/Cryptography/MPTTrie/Node.Leaf.cs
index 024a07f8c8..b1b7707729 100644
--- a/src/Plugins/MPTTrie/Cryptography/MPTTrie/Node.Leaf.cs
+++ b/src/Plugins/MPTTrie/Cryptography/MPTTrie/Node.Leaf.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using Neo.SmartContract;
using System;
diff --git a/src/Plugins/MPTTrie/Cryptography/MPTTrie/Node.cs b/src/Plugins/MPTTrie/Cryptography/MPTTrie/Node.cs
index ef45548645..2e20f03a9d 100644
--- a/src/Plugins/MPTTrie/Cryptography/MPTTrie/Node.cs
+++ b/src/Plugins/MPTTrie/Cryptography/MPTTrie/Node.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using System;
using System.IO;
@@ -31,11 +32,11 @@ public int Size
switch (type)
{
case NodeType.BranchNode:
- return size + BranchSize + IO.Helper.GetVarSize(Reference);
+ return size + BranchSize + UnsafeData.GetVarSize(Reference);
case NodeType.ExtensionNode:
- return size + ExtensionSize + IO.Helper.GetVarSize(Reference);
+ return size + ExtensionSize + UnsafeData.GetVarSize(Reference);
case NodeType.LeafNode:
- return size + LeafSize + IO.Helper.GetVarSize(Reference);
+ return size + LeafSize + UnsafeData.GetVarSize(Reference);
case NodeType.HashNode:
return size + HashSize;
case NodeType.Empty:
diff --git a/src/Plugins/OracleService/OracleService.cs b/src/Plugins/OracleService/OracleService.cs
index fbdee148db..f17df8167c 100644
--- a/src/Plugins/OracleService/OracleService.cs
+++ b/src/Plugins/OracleService/OracleService.cs
@@ -446,8 +446,8 @@ public static Transaction CreateResponseTx(DataCache snapshot, OracleRequest req
int size_inv = 66 * m;
int size = Transaction.HeaderSize + tx.Signers.GetVarSize() + tx.Script.GetVarSize()
- + IO.Helper.GetVarSize(hashes.Length) + witnessDict[NativeContract.Oracle.Hash].Size
- + IO.Helper.GetVarSize(size_inv) + size_inv + oracleSignContract.Script.GetVarSize();
+ + UnsafeData.GetVarSize(hashes.Length) + witnessDict[NativeContract.Oracle.Hash].Size
+ + UnsafeData.GetVarSize(size_inv) + size_inv + oracleSignContract.Script.GetVarSize();
var feePerByte = NativeContract.Policy.GetFeePerByte(snapshot);
if (response.Result.Length > OracleResponse.MaxResultSize)
diff --git a/src/Plugins/RpcServer/RpcServer.SmartContract.cs b/src/Plugins/RpcServer/RpcServer.SmartContract.cs
index a3de939f4b..11e1218e57 100644
--- a/src/Plugins/RpcServer/RpcServer.SmartContract.cs
+++ b/src/Plugins/RpcServer/RpcServer.SmartContract.cs
@@ -10,6 +10,7 @@
// modifications are permitted.
using Neo.Cryptography.ECC;
+using Neo.Extensions;
using Neo.IO;
using Neo.Json;
using Neo.Network.P2P.Payloads;
@@ -189,7 +190,7 @@ private static Signer[] SignersFromJson(JArray _params, ProtocolSettings setting
// Validate format
- _ = IO.Helper.ToByteArray(ret).AsSerializableArray();
+ _ = ret.ToByteArray().AsSerializableArray();
return ret;
}
diff --git a/src/Plugins/SQLiteWallet/VerificationContract.cs b/src/Plugins/SQLiteWallet/VerificationContract.cs
index e128045adb..2f62a7174b 100644
--- a/src/Plugins/SQLiteWallet/VerificationContract.cs
+++ b/src/Plugins/SQLiteWallet/VerificationContract.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using Neo.SmartContract;
diff --git a/src/Plugins/StateService/Network/Vote.cs b/src/Plugins/StateService/Network/Vote.cs
index e6840c7a9f..bba40f6a54 100644
--- a/src/Plugins/StateService/Network/Vote.cs
+++ b/src/Plugins/StateService/Network/Vote.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using System;
using System.IO;
diff --git a/src/Plugins/StateService/Storage/StateStore.cs b/src/Plugins/StateService/Storage/StateStore.cs
index f2ca6d7d05..beb19818bb 100644
--- a/src/Plugins/StateService/Storage/StateStore.cs
+++ b/src/Plugins/StateService/Storage/StateStore.cs
@@ -10,6 +10,7 @@
// modifications are permitted.
using Akka.Actor;
+using Neo.Extensions;
using Neo.IO;
using Neo.Ledger;
using Neo.Network.P2P.Payloads;
diff --git a/src/Plugins/StateService/Verification/VerificationService.cs b/src/Plugins/StateService/Verification/VerificationService.cs
index a8eb9fd030..3d77bc3501 100644
--- a/src/Plugins/StateService/Verification/VerificationService.cs
+++ b/src/Plugins/StateService/Verification/VerificationService.cs
@@ -11,6 +11,7 @@
using Akka.Actor;
using Akka.Util.Internal;
+using Neo.Extensions;
using Neo.IO;
using Neo.Ledger;
using Neo.Network.P2P.Payloads;
diff --git a/src/Plugins/TokensTracker/Extensions.cs b/src/Plugins/TokensTracker/Extensions.cs
index 7805056280..83b4371435 100644
--- a/src/Plugins/TokensTracker/Extensions.cs
+++ b/src/Plugins/TokensTracker/Extensions.cs
@@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
+using Neo.Extensions;
using Neo.IO;
using Neo.Persistence;
using Neo.VM.Types;
@@ -33,13 +34,13 @@ public static string ToBase64(this ReadOnlySpan item)
public static int GetVarSize(this ByteString item)
{
var length = item.GetSpan().Length;
- return IO.Helper.GetVarSize(length) + length;
+ return UnsafeData.GetVarSize(length) + length;
}
public static int GetVarSize(this BigInteger item)
{
var length = item.GetByteCount();
- return IO.Helper.GetVarSize(length) + length;
+ return UnsafeData.GetVarSize(length) + length;
}
public static IEnumerable<(TKey, TValue)> FindPrefix(this IStore db, byte[] prefix)
diff --git a/tests/Neo.Extensions.Tests/UT_StringExtensions.cs b/tests/Neo.Extensions.Tests/UT_StringExtensions.cs
index 9954f24765..6e823d2493 100644
--- a/tests/Neo.Extensions.Tests/UT_StringExtensions.cs
+++ b/tests/Neo.Extensions.Tests/UT_StringExtensions.cs
@@ -35,5 +35,12 @@ public void TestHexToBytes()
byte[] bytes = str2.HexToBytes();
bytes.ToHexString().Should().Be(new byte[] { 0x01, 0x02 }.ToHexString());
}
+
+ [TestMethod]
+ public void TestGetVarSizeString()
+ {
+ int result = "AA".GetVarSize();
+ Assert.AreEqual(3, result);
+ }
}
}
diff --git a/tests/Neo.Extensions.Tests/UT_UnsafeData.cs b/tests/Neo.Extensions.Tests/UT_UnsafeData.cs
new file mode 100644
index 0000000000..5c8bb310c3
--- /dev/null
+++ b/tests/Neo.Extensions.Tests/UT_UnsafeData.cs
@@ -0,0 +1,163 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Neo.Extensions.Tests
+{
+ [TestClass]
+ public class UT_UnsafeData
+ {
+ [TestMethod]
+ public void TestGetVarSizeInt()
+ {
+ for (int i = 0; i < 3; i++)
+ {
+ if (i == 0)
+ {
+ int result = UnsafeData.GetVarSize(1);
+ Assert.AreEqual(1, result);
+ }
+ else if (i == 1)
+ {
+ int result = UnsafeData.GetVarSize(0xFFFF);
+ Assert.AreEqual(3, result);
+ }
+ else
+ {
+ int result = UnsafeData.GetVarSize(0xFFFFFF);
+ Assert.AreEqual(5, result);
+ }
+ }
+ }
+
+ [TestMethod]
+ public void TestGetVarSizeGeneric()
+ {
+ for (int i = 0; i < 9; i++)
+ {
+ if (i == 0)
+ {
+ int result = new UInt160[] { UInt160.Zero }.GetVarSize();
+ Assert.AreEqual(21, result);
+ }
+ else if (i == 1)//sbyte
+ {
+ List initList = new()
+ {
+ TestEnum0.case1
+ };
+ IReadOnlyCollection testList = initList.AsReadOnly();
+ int result = testList.GetVarSize();
+ Assert.AreEqual(2, result);
+ }
+ else if (i == 2)//byte
+ {
+ List initList = new()
+ {
+ TestEnum1.case1
+ };
+ IReadOnlyCollection testList = initList.AsReadOnly();
+ int result = testList.GetVarSize();
+ Assert.AreEqual(2, result);
+ }
+ else if (i == 3)//short
+ {
+ List initList = new()
+ {
+ TestEnum2.case1
+ };
+ IReadOnlyCollection testList = initList.AsReadOnly();
+ int result = testList.GetVarSize();
+ Assert.AreEqual(3, result);
+ }
+ else if (i == 4)//ushort
+ {
+ List initList = new()
+ {
+ TestEnum3.case1
+ };
+ IReadOnlyCollection testList = initList.AsReadOnly();
+ int result = testList.GetVarSize();
+ Assert.AreEqual(3, result);
+ }
+ else if (i == 5)//int
+ {
+ List initList = new()
+ {
+ TestEnum4.case1
+ };
+ IReadOnlyCollection testList = initList.AsReadOnly();
+ int result = testList.GetVarSize();
+ Assert.AreEqual(5, result);
+ }
+ else if (i == 6)//uint
+ {
+ List initList = new()
+ {
+ TestEnum5.case1
+ };
+ IReadOnlyCollection testList = initList.AsReadOnly();
+ int result = testList.GetVarSize();
+ Assert.AreEqual(5, result);
+ }
+ else if (i == 7)//long
+ {
+ List initList = new()
+ {
+ TestEnum6.case1
+ };
+ IReadOnlyCollection testList = initList.AsReadOnly();
+ int result = testList.GetVarSize();
+ Assert.AreEqual(9, result);
+ }
+ else if (i == 8)
+ {
+ List initList = new()
+ {
+ 1
+ };
+ IReadOnlyCollection testList = initList.AsReadOnly();
+ int result = testList.GetVarSize();
+ Assert.AreEqual(5, result);
+ }
+ }
+ }
+
+ enum TestEnum0 : sbyte
+ {
+ case1 = 1, case2 = 2
+ }
+
+ enum TestEnum1 : byte
+ {
+ case1 = 1, case2 = 2
+ }
+
+ enum TestEnum2 : short
+ {
+ case1 = 1, case2 = 2
+ }
+
+ enum TestEnum3 : ushort
+ {
+ case1 = 1, case2 = 2
+ }
+
+ enum TestEnum4 : int
+ {
+ case1 = 1, case2 = 2
+ }
+
+ enum TestEnum5 : uint
+ {
+ case1 = 1, case2 = 2
+ }
+
+ enum TestEnum6 : long
+ {
+ case1 = 1, case2 = 2
+ }
+ }
+}
diff --git a/tests/Neo.UnitTests/IO/UT_IOHelper.cs b/tests/Neo.UnitTests/IO/UT_IOHelper.cs
index 48453c992a..d9d753e292 100644
--- a/tests/Neo.UnitTests/IO/UT_IOHelper.cs
+++ b/tests/Neo.UnitTests/IO/UT_IOHelper.cs
@@ -110,23 +110,9 @@ public void TestNullableArray()
[TestMethod]
public void TestAsSerializable()
{
- for (int i = 0; i < 2; i++)
- {
- if (i == 0)
- {
- byte[] caseArray = new byte[] { 0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00 };
- ISerializable result = Neo.IO.Helper.AsSerializable(caseArray, typeof(UInt160));
- Assert.AreEqual(UInt160.Zero, result);
- }
- else
- {
- Action action = () => Neo.IO.Helper.AsSerializable(Array.Empty(), typeof(double));
- action.Should().Throw();
- }
- }
+ byte[] caseArray = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
+ ISerializable result = caseArray.AsSerializable();
+ Assert.AreEqual(UInt160.Zero, result);
}
[TestMethod]
@@ -164,169 +150,12 @@ public void TestCompression()
[TestMethod]
public void TestAsSerializableArray()
{
- byte[] byteArray = Neo.IO.Helper.ToByteArray(new UInt160[] { UInt160.Zero });
+ byte[] byteArray = new UInt160[] { UInt160.Zero }.ToByteArray();
UInt160[] result = Neo.IO.Helper.AsSerializableArray(byteArray);
Assert.AreEqual(1, result.Length);
Assert.AreEqual(UInt160.Zero, result[0]);
}
- [TestMethod]
- public void TestGetVarSizeInt()
- {
- for (int i = 0; i < 3; i++)
- {
- if (i == 0)
- {
- int result = Neo.IO.Helper.GetVarSize(1);
- Assert.AreEqual(1, result);
- }
- else if (i == 1)
- {
- int result = Neo.IO.Helper.GetVarSize(0xFFFF);
- Assert.AreEqual(3, result);
- }
- else
- {
- int result = Neo.IO.Helper.GetVarSize(0xFFFFFF);
- Assert.AreEqual(5, result);
- }
- }
- }
- enum TestEnum0 : sbyte
- {
- case1 = 1, case2 = 2
- }
-
- enum TestEnum1 : byte
- {
- case1 = 1, case2 = 2
- }
-
- enum TestEnum2 : short
- {
- case1 = 1, case2 = 2
- }
-
- enum TestEnum3 : ushort
- {
- case1 = 1, case2 = 2
- }
-
- enum TestEnum4 : int
- {
- case1 = 1, case2 = 2
- }
-
- enum TestEnum5 : uint
- {
- case1 = 1, case2 = 2
- }
-
- enum TestEnum6 : long
- {
- case1 = 1, case2 = 2
- }
-
- [TestMethod]
- public void TestGetVarSizeGeneric()
- {
- for (int i = 0; i < 9; i++)
- {
- if (i == 0)
- {
- int result = Neo.IO.Helper.GetVarSize(new UInt160[] { UInt160.Zero });
- Assert.AreEqual(21, result);
- }
- else if (i == 1)//sbyte
- {
- List initList = new()
- {
- TestEnum0.case1
- };
- IReadOnlyCollection testList = initList.AsReadOnly();
- int result = Neo.IO.Helper.GetVarSize(testList);
- Assert.AreEqual(2, result);
- }
- else if (i == 2)//byte
- {
- List initList = new()
- {
- TestEnum1.case1
- };
- IReadOnlyCollection testList = initList.AsReadOnly();
- int result = Neo.IO.Helper.GetVarSize(testList);
- Assert.AreEqual(2, result);
- }
- else if (i == 3)//short
- {
- List initList = new()
- {
- TestEnum2.case1
- };
- IReadOnlyCollection testList = initList.AsReadOnly();
- int result = Neo.IO.Helper.GetVarSize(testList);
- Assert.AreEqual(3, result);
- }
- else if (i == 4)//ushort
- {
- List initList = new()
- {
- TestEnum3.case1
- };
- IReadOnlyCollection testList = initList.AsReadOnly();
- int result = Neo.IO.Helper.GetVarSize(testList);
- Assert.AreEqual(3, result);
- }
- else if (i == 5)//int
- {
- List initList = new()
- {
- TestEnum4.case1
- };
- IReadOnlyCollection testList = initList.AsReadOnly();
- int result = Neo.IO.Helper.GetVarSize(testList);
- Assert.AreEqual(5, result);
- }
- else if (i == 6)//uint
- {
- List initList = new()
- {
- TestEnum5.case1
- };
- IReadOnlyCollection testList = initList.AsReadOnly();
- int result = Neo.IO.Helper.GetVarSize(testList);
- Assert.AreEqual(5, result);
- }
- else if (i == 7)//long
- {
- List initList = new()
- {
- TestEnum6.case1
- };
- IReadOnlyCollection testList = initList.AsReadOnly();
- int result = Neo.IO.Helper.GetVarSize(testList);
- Assert.AreEqual(9, result);
- }
- else if (i == 8)
- {
- List initList = new()
- {
- 1
- };
- IReadOnlyCollection testList = initList.AsReadOnly();
- int result = Neo.IO.Helper.GetVarSize(testList);
- Assert.AreEqual(5, result);
- }
- }
- }
-
- [TestMethod]
- public void TestGetVarSizeString()
- {
- int result = Neo.IO.Helper.GetVarSize("AA");
- Assert.AreEqual(3, result);
- }
-
[TestMethod]
public void TestReadSerializable()
{
@@ -413,7 +242,7 @@ public void TestToArray()
[TestMethod]
public void TestToByteArrayGeneric()
{
- byte[] byteArray = Neo.IO.Helper.ToByteArray(new UInt160[] { UInt160.Zero });
+ byte[] byteArray = new UInt160[] { UInt160.Zero }.ToByteArray();
Assert.AreEqual(Encoding.Default.GetString(new byte[] { 0x01,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,
diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_NetworkAddressWithTime.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_NetworkAddressWithTime.cs
index 2ed86e4da7..3e2c6c336c 100644
--- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_NetworkAddressWithTime.cs
+++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_NetworkAddressWithTime.cs
@@ -11,6 +11,7 @@
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Neo.Extensions;
using Neo.IO;
using Neo.Network.P2P.Capabilities;
using Neo.Network.P2P.Payloads;
diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_VersionPayload.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_VersionPayload.cs
index a77740a1e5..66bebf68d8 100644
--- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_VersionPayload.cs
+++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_VersionPayload.cs
@@ -11,6 +11,7 @@
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Neo.Extensions;
using Neo.IO;
using Neo.Network.P2P.Capabilities;
using Neo.Network.P2P.Payloads;
diff --git a/tests/Neo.UnitTests/TestUtils.Transaction.cs b/tests/Neo.UnitTests/TestUtils.Transaction.cs
index 12e9b4ec0e..70ac264a19 100644
--- a/tests/Neo.UnitTests/TestUtils.Transaction.cs
+++ b/tests/Neo.UnitTests/TestUtils.Transaction.cs
@@ -11,6 +11,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Cryptography;
+using Neo.Cryptography.ECC;
using Neo.Extensions;
using Neo.IO;
using Neo.Network.P2P.Payloads;