From 7b0adda9e2d9df94b001ed93f7332311dd33836b Mon Sep 17 00:00:00 2001 From: Shargon Date: Thu, 7 May 2020 15:16:57 +0200 Subject: [PATCH] Move cosigners to transaction attributes (#1620) * First draft * Remove dictonary * Move json methods * format * Fix UT * Fix Size * clean code * Fix UT * Clean code * Remove const * Remove blank line * Pluralize * Allow multiple attributes of the same type * Update src/neo/Wallets/Wallet.cs * Fix some UT * Fix UT * Fix UT * Update src/neo/Network/P2P/Payloads/CosignerAttribute.cs Co-authored-by: Erik Zhang * Singular * Move Cosigner to TransactionCollection * Optimize empty * Use ReflectionCache * Change json format * Rename * Remove FromJson * Optimize TransactionAttribute.ToJson() * Rename * Refactor * Change the value of TransactionAttributeType.Cosigner * Fix UTs * Fix attribute order * Remove TransactionAttributeCollection * Reorder * Revert some changes * Revert some changes Co-authored-by: Erik Zhang --- src/neo/Ledger/Blockchain.cs | 3 +- src/neo/Network/P2P/Payloads/Cosigner.cs | 20 ++++--- src/neo/Network/P2P/Payloads/Transaction.cs | 30 ++++------ .../P2P/Payloads/TransactionAttribute.cs | 43 +++++++++----- .../P2P/Payloads/TransactionAttributeType.cs | 10 ++++ .../P2P/Payloads/TransactionAttributeUsage.cs | 7 --- .../SmartContract/InteropService.Runtime.cs | 16 ++--- src/neo/Wallets/Wallet.cs | 14 ++--- .../Consensus/UT_ConsensusContext.cs | 3 +- .../Cryptography/UT_Cryptography_Helper.cs | 3 +- .../neo.UnitTests/IO/Caching/UT_RelayCache.cs | 4 +- tests/neo.UnitTests/Ledger/UT_Blockchain.cs | 6 +- tests/neo.UnitTests/Ledger/UT_MemoryPool.cs | 6 +- tests/neo.UnitTests/Ledger/UT_PoolItem.cs | 4 +- .../Ledger/UT_SendersFeeMonitor.cs | 3 +- .../Ledger/UT_TransactionState.cs | 2 +- .../Network/P2P/Payloads/UT_Block.cs | 19 +++--- .../Network/P2P/Payloads/UT_Cosigner.cs | 16 ++--- .../Network/P2P/Payloads/UT_Transaction.cs | 59 ++++++++----------- .../Network/P2P/Payloads/UT_Witness.cs | 3 +- .../UT_ContractParameterContext.cs | 6 +- .../SmartContract/UT_Syscalls.cs | 11 ++-- tests/neo.UnitTests/TestUtils.cs | 6 +- 23 files changed, 138 insertions(+), 156 deletions(-) create mode 100644 src/neo/Network/P2P/Payloads/TransactionAttributeType.cs delete mode 100644 src/neo/Network/P2P/Payloads/TransactionAttributeUsage.cs diff --git a/src/neo/Ledger/Blockchain.cs b/src/neo/Ledger/Blockchain.cs index 0a535f9a5b..a0153063d1 100644 --- a/src/neo/Ledger/Blockchain.cs +++ b/src/neo/Ledger/Blockchain.cs @@ -167,8 +167,7 @@ private static Transaction DeployNativeContracts() Script = script, Sender = (new[] { (byte)OpCode.PUSH1 }).ToScriptHash(), SystemFee = 0, - Attributes = new TransactionAttribute[0], - Cosigners = new Cosigner[0], + Attributes = Array.Empty(), Witnesses = new[] { new Witness diff --git a/src/neo/Network/P2P/Payloads/Cosigner.cs b/src/neo/Network/P2P/Payloads/Cosigner.cs index f75b8fa7eb..7a045967fa 100644 --- a/src/neo/Network/P2P/Payloads/Cosigner.cs +++ b/src/neo/Network/P2P/Payloads/Cosigner.cs @@ -6,28 +6,30 @@ namespace Neo.Network.P2P.Payloads { - public class Cosigner : ISerializable + public class Cosigner : TransactionAttribute { + // This limits maximum number of AllowedContracts or AllowedGroups here + private const int MaxSubitems = 16; + public UInt160 Account; public WitnessScope Scopes; public UInt160[] AllowedContracts; public ECPoint[] AllowedGroups; + public override TransactionAttributeType Type => TransactionAttributeType.Cosigner; + public Cosigner() { this.Scopes = WitnessScope.Global; } - // This limits maximum number of AllowedContracts or AllowedGroups here - private int MaxSubitems = 16; - - public int Size => + public override int Size => base.Size + /*Account*/ UInt160.Length + /*Scopes*/ sizeof(WitnessScope) + /*AllowedContracts*/ (Scopes.HasFlag(WitnessScope.CustomContracts) ? AllowedContracts.GetVarSize() : 0) + /*AllowedGroups*/ (Scopes.HasFlag(WitnessScope.CustomGroups) ? AllowedGroups.GetVarSize() : 0); - void ISerializable.Deserialize(BinaryReader reader) + protected override void DeserializeWithoutType(BinaryReader reader) { Account = reader.ReadSerializable(); Scopes = (WitnessScope)reader.ReadByte(); @@ -39,7 +41,7 @@ void ISerializable.Deserialize(BinaryReader reader) : new ECPoint[0]; } - void ISerializable.Serialize(BinaryWriter writer) + protected override void SerializeWithoutType(BinaryWriter writer) { writer.Write(Account); writer.Write((byte)Scopes); @@ -49,9 +51,9 @@ void ISerializable.Serialize(BinaryWriter writer) writer.Write(AllowedGroups); } - public JObject ToJson() + public override JObject ToJson() { - JObject json = new JObject(); + JObject json = base.ToJson(); json["account"] = Account.ToString(); json["scopes"] = Scopes; if (Scopes.HasFlag(WitnessScope.CustomContracts)) diff --git a/src/neo/Network/P2P/Payloads/Transaction.cs b/src/neo/Network/P2P/Payloads/Transaction.cs index 45f5ff0b3f..1d8cfe539f 100644 --- a/src/neo/Network/P2P/Payloads/Transaction.cs +++ b/src/neo/Network/P2P/Payloads/Transaction.cs @@ -24,11 +24,7 @@ public class Transaction : IEquatable, IInventory, IInteroperable /// /// Maximum number of attributes that can be contained within a transaction /// - private const int MaxTransactionAttributes = 16; - /// - /// Maximum number of cosigners that can be contained within a transaction - /// - private const int MaxCosigners = 16; + public const int MaxTransactionAttributes = 16; private byte version; private uint nonce; @@ -37,7 +33,6 @@ public class Transaction : IEquatable, IInventory, IInteroperable private long netfee; private uint validUntilBlock; private TransactionAttribute[] attributes; - private Cosigner[] cosigners; private byte[] script; private Witness[] witnesses; @@ -52,14 +47,11 @@ public class Transaction : IEquatable, IInventory, IInteroperable public TransactionAttribute[] Attributes { get => attributes; - set { attributes = value; _hash = null; _size = 0; } + set { attributes = value; _cosigners = null; _hash = null; _size = 0; } } - public Cosigner[] Cosigners - { - get => cosigners; - set { cosigners = value; _hash = null; _size = 0; } - } + private Cosigner[] _cosigners; + public Cosigner[] Cosigners => _cosigners ??= attributes.OfType().ToArray(); /// /// The NetworkFee for the transaction divided by its Size. @@ -117,10 +109,9 @@ public int Size if (_size == 0) { _size = HeaderSize + - Attributes.GetVarSize() + //Attributes - Cosigners.GetVarSize() + //Cosigners - Script.GetVarSize() + //Script - Witnesses.GetVarSize(); //Witnesses + Attributes.GetVarSize() + // Attributes + Script.GetVarSize() + // Script + Witnesses.GetVarSize(); // Witnesses } return _size; } @@ -176,8 +167,9 @@ public void DeserializeUnsigned(BinaryReader reader) if (NetworkFee < 0) throw new FormatException(); if (SystemFee + NetworkFee < SystemFee) throw new FormatException(); ValidUntilBlock = reader.ReadUInt32(); - Attributes = reader.ReadSerializableArray(MaxTransactionAttributes); - Cosigners = reader.ReadSerializableArray(MaxCosigners); + Attributes = new TransactionAttribute[reader.ReadVarInt(MaxTransactionAttributes)]; + for (int i = 0; i < Attributes.Length; i++) + Attributes[i] = TransactionAttribute.DeserializeFrom(reader); if (Cosigners.Select(u => u.Account).Distinct().Count() != Cosigners.Length) throw new FormatException(); Script = reader.ReadVarBytes(ushort.MaxValue); if (Script.Length == 0) throw new FormatException(); @@ -227,7 +219,6 @@ void IVerifiable.SerializeUnsigned(BinaryWriter writer) writer.Write(NetworkFee); writer.Write(ValidUntilBlock); writer.Write(Attributes); - writer.Write(Cosigners); writer.WriteVarBytes(Script); } @@ -243,7 +234,6 @@ public JObject ToJson() json["net_fee"] = NetworkFee.ToString(); json["valid_until_block"] = ValidUntilBlock; json["attributes"] = Attributes.Select(p => p.ToJson()).ToArray(); - json["cosigners"] = Cosigners.Select(p => p.ToJson()).ToArray(); json["script"] = Convert.ToBase64String(Script); json["witnesses"] = Witnesses.Select(p => p.ToJson()).ToArray(); return json; diff --git a/src/neo/Network/P2P/Payloads/TransactionAttribute.cs b/src/neo/Network/P2P/Payloads/TransactionAttribute.cs index dd592284e6..344c23f052 100644 --- a/src/neo/Network/P2P/Payloads/TransactionAttribute.cs +++ b/src/neo/Network/P2P/Payloads/TransactionAttribute.cs @@ -1,37 +1,48 @@ using Neo.IO; +using Neo.IO.Caching; using Neo.IO.Json; using System; using System.IO; namespace Neo.Network.P2P.Payloads { - public class TransactionAttribute : ISerializable + public abstract class TransactionAttribute : ISerializable { - public TransactionAttributeUsage Usage; - public byte[] Data; + public abstract TransactionAttributeType Type { get; } + public virtual int Size => sizeof(TransactionAttributeType); - public int Size => sizeof(TransactionAttributeUsage) + Data.GetVarSize(); + public void Deserialize(BinaryReader reader) + { + if (reader.ReadByte() != (byte)Type) + throw new FormatException(); + DeserializeWithoutType(reader); + } - void ISerializable.Deserialize(BinaryReader reader) + public static TransactionAttribute DeserializeFrom(BinaryReader reader) { - Usage = (TransactionAttributeUsage)reader.ReadByte(); - if (!Enum.IsDefined(typeof(TransactionAttributeUsage), Usage)) + TransactionAttributeType type = (TransactionAttributeType)reader.ReadByte(); + if (!(ReflectionCache.CreateInstance(type) is TransactionAttribute attribute)) throw new FormatException(); - Data = reader.ReadVarBytes(252); + attribute.DeserializeWithoutType(reader); + return attribute; } - void ISerializable.Serialize(BinaryWriter writer) + protected abstract void DeserializeWithoutType(BinaryReader reader); + + public virtual JObject ToJson() { - writer.Write((byte)Usage); - writer.WriteVarBytes(Data); + return new JObject + { + ["type"] = Type + }; } - public JObject ToJson() + public void Serialize(BinaryWriter writer) { - JObject json = new JObject(); - json["usage"] = Usage; - json["data"] = Convert.ToBase64String(Data); - return json; + writer.Write((byte)Type); + SerializeWithoutType(writer); } + + protected abstract void SerializeWithoutType(BinaryWriter writer); } } diff --git a/src/neo/Network/P2P/Payloads/TransactionAttributeType.cs b/src/neo/Network/P2P/Payloads/TransactionAttributeType.cs new file mode 100644 index 0000000000..f1e2d704da --- /dev/null +++ b/src/neo/Network/P2P/Payloads/TransactionAttributeType.cs @@ -0,0 +1,10 @@ +using Neo.IO.Caching; + +namespace Neo.Network.P2P.Payloads +{ + public enum TransactionAttributeType : byte + { + [ReflectionCache(typeof(Cosigner))] + Cosigner = 0x01 + } +} diff --git a/src/neo/Network/P2P/Payloads/TransactionAttributeUsage.cs b/src/neo/Network/P2P/Payloads/TransactionAttributeUsage.cs deleted file mode 100644 index 9bf5cc204c..0000000000 --- a/src/neo/Network/P2P/Payloads/TransactionAttributeUsage.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Neo.Network.P2P.Payloads -{ - public enum TransactionAttributeUsage : byte - { - Url = 0x81 - } -} diff --git a/src/neo/SmartContract/InteropService.Runtime.cs b/src/neo/SmartContract/InteropService.Runtime.cs index 9942555cba..ff58e0a897 100644 --- a/src/neo/SmartContract/InteropService.Runtime.cs +++ b/src/neo/SmartContract/InteropService.Runtime.cs @@ -81,24 +81,24 @@ internal static bool CheckWitnessInternal(ApplicationEngine engine, UInt160 hash { if (engine.ScriptContainer is Transaction tx) { - Cosigner usage = tx.Cosigners.FirstOrDefault(p => p.Account.Equals(hash)); - if (usage is null) return false; - if (usage.Scopes == WitnessScope.Global) return true; - if (usage.Scopes.HasFlag(WitnessScope.CalledByEntry)) + Cosigner cosigner = tx.Cosigners.FirstOrDefault(p => p.Account.Equals(hash)); + if (cosigner is null) return false; + if (cosigner.Scopes == WitnessScope.Global) return true; + if (cosigner.Scopes.HasFlag(WitnessScope.CalledByEntry)) { if (engine.CallingScriptHash == engine.EntryScriptHash) return true; } - if (usage.Scopes.HasFlag(WitnessScope.CustomContracts)) + if (cosigner.Scopes.HasFlag(WitnessScope.CustomContracts)) { - if (usage.AllowedContracts.Contains(engine.CurrentScriptHash)) + if (cosigner.AllowedContracts.Contains(engine.CurrentScriptHash)) return true; } - if (usage.Scopes.HasFlag(WitnessScope.CustomGroups)) + if (cosigner.Scopes.HasFlag(WitnessScope.CustomGroups)) { var contract = engine.Snapshot.Contracts[engine.CallingScriptHash]; // check if current group is the required one - if (contract.Manifest.Groups.Select(p => p.PubKey).Intersect(usage.AllowedGroups).Any()) + if (contract.Manifest.Groups.Select(p => p.PubKey).Intersect(cosigner.AllowedGroups).Any()) return true; } return false; diff --git a/src/neo/Wallets/Wallet.cs b/src/neo/Wallets/Wallet.cs index adf5dcde7a..b6665aadf9 100644 --- a/src/neo/Wallets/Wallet.cs +++ b/src/neo/Wallets/Wallet.cs @@ -285,11 +285,11 @@ public Transaction MakeTransaction(TransferOutput[] outputs, UInt160 from = null Account = new UInt160(p.ToArray()) }).ToArray(); - return MakeTransaction(snapshot, script, new TransactionAttribute[0], cosigners, balances_gas); + return MakeTransaction(snapshot, script, cosigners, balances_gas); } } - public Transaction MakeTransaction(byte[] script, UInt160 sender = null, TransactionAttribute[] attributes = null, Cosigner[] cosigners = null) + public Transaction MakeTransaction(byte[] script, UInt160 sender = null, TransactionAttribute[] attributes = null) { UInt160[] accounts; if (sender is null) @@ -305,11 +305,11 @@ public Transaction MakeTransaction(byte[] script, UInt160 sender = null, Transac using (SnapshotView snapshot = Blockchain.Singleton.GetSnapshot()) { var balances_gas = accounts.Select(p => (Account: p, Value: NativeContract.GAS.BalanceOf(snapshot, p))).Where(p => p.Value.Sign > 0).ToList(); - return MakeTransaction(snapshot, script, attributes ?? new TransactionAttribute[0], cosigners ?? new Cosigner[0], balances_gas); + return MakeTransaction(snapshot, script, attributes ?? new TransactionAttribute[0], balances_gas); } } - private Transaction MakeTransaction(StoreView snapshot, byte[] script, TransactionAttribute[] attributes, Cosigner[] cosigners, List<(UInt160 Account, BigInteger Value)> balances_gas) + private Transaction MakeTransaction(StoreView snapshot, byte[] script, TransactionAttribute[] attributes, List<(UInt160 Account, BigInteger Value)> balances_gas) { Random rand = new Random(); foreach (var (account, value) in balances_gas) @@ -322,8 +322,8 @@ private Transaction MakeTransaction(StoreView snapshot, byte[] script, Transacti Sender = account, ValidUntilBlock = snapshot.Height + Transaction.MaxValidUntilBlockIncrement, Attributes = attributes, - Cosigners = cosigners }; + // will try to execute 'transfer' script to check if it works using (ApplicationEngine engine = ApplicationEngine.Run(script, snapshot.Clone(), tx, testMode: true)) { @@ -334,8 +334,8 @@ private Transaction MakeTransaction(StoreView snapshot, byte[] script, Transacti UInt160[] hashes = tx.GetScriptHashesForVerifying(snapshot); - // base size for transaction: includes const_header + attributes + cosigners with scopes + script + hashes - int size = Transaction.HeaderSize + attributes.GetVarSize() + cosigners.GetVarSize() + script.GetVarSize() + IO.Helper.GetVarSize(hashes.Length); + // base size for transaction: includes const_header + attributes + script + hashes + int size = Transaction.HeaderSize + tx.Attributes.GetVarSize() + script.GetVarSize() + IO.Helper.GetVarSize(hashes.Length); foreach (UInt160 hash in hashes) { diff --git a/tests/neo.UnitTests/Consensus/UT_ConsensusContext.cs b/tests/neo.UnitTests/Consensus/UT_ConsensusContext.cs index 469c28d3ba..5fab8d80d2 100644 --- a/tests/neo.UnitTests/Consensus/UT_ConsensusContext.cs +++ b/tests/neo.UnitTests/Consensus/UT_ConsensusContext.cs @@ -98,8 +98,7 @@ private Transaction CreateTransactionWithSize(int v) var r = new Random(); var tx = new Transaction() { - Cosigners = new Cosigner[0], - Attributes = new TransactionAttribute[0], + Attributes = Array.Empty(), NetworkFee = 0, Nonce = (uint)Environment.TickCount, Script = new byte[0], diff --git a/tests/neo.UnitTests/Cryptography/UT_Cryptography_Helper.cs b/tests/neo.UnitTests/Cryptography/UT_Cryptography_Helper.cs index b44d0a74d1..0e17d0913c 100644 --- a/tests/neo.UnitTests/Cryptography/UT_Cryptography_Helper.cs +++ b/tests/neo.UnitTests/Cryptography/UT_Cryptography_Helper.cs @@ -145,8 +145,7 @@ public void TestTest() Script = TestUtils.GetByteArray(32, 0x42), Sender = UInt160.Zero, SystemFee = 4200000000, - Attributes = new TransactionAttribute[0], - Cosigners = new Cosigner[0], + Attributes = Array.Empty(), Witnesses = new[] { new Witness diff --git a/tests/neo.UnitTests/IO/Caching/UT_RelayCache.cs b/tests/neo.UnitTests/IO/Caching/UT_RelayCache.cs index 4608dd0e14..d442a018e9 100644 --- a/tests/neo.UnitTests/IO/Caching/UT_RelayCache.cs +++ b/tests/neo.UnitTests/IO/Caching/UT_RelayCache.cs @@ -2,6 +2,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.IO.Caching; using Neo.Network.P2P.Payloads; +using System; namespace Neo.UnitTests.IO.Caching { @@ -27,8 +28,7 @@ public void TestGetKeyForItem() SystemFee = 0, NetworkFee = 0, ValidUntilBlock = 100, - Cosigners = new Cosigner[0], - Attributes = new TransactionAttribute[0], + Attributes = Array.Empty(), Script = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04 }, Witnesses = new Witness[0] }; diff --git a/tests/neo.UnitTests/Ledger/UT_Blockchain.cs b/tests/neo.UnitTests/Ledger/UT_Blockchain.cs index 681e36489f..6faf336290 100644 --- a/tests/neo.UnitTests/Ledger/UT_Blockchain.cs +++ b/tests/neo.UnitTests/Ledger/UT_Blockchain.cs @@ -70,13 +70,13 @@ public void TestContainsTransaction() [TestMethod] public void TestGetCurrentBlockHash() { - Blockchain.Singleton.CurrentBlockHash.Should().Be(UInt256.Parse("0xc9387b803c8b4c6c1f69f6c876ed7848482c414b0225eb2a3a5395af39425455")); + Blockchain.Singleton.CurrentBlockHash.Should().Be(UInt256.Parse("0x557f5c9d0c865a211a749899681e5b4fbf745b3bcf0c395e6d6a7f1edb0d86f1")); } [TestMethod] public void TestGetCurrentHeaderHash() { - Blockchain.Singleton.CurrentHeaderHash.Should().Be(UInt256.Parse("0xc9387b803c8b4c6c1f69f6c876ed7848482c414b0225eb2a3a5395af39425455")); + Blockchain.Singleton.CurrentHeaderHash.Should().Be(UInt256.Parse("0x557f5c9d0c865a211a749899681e5b4fbf745b3bcf0c395e6d6a7f1edb0d86f1")); } [TestMethod] @@ -88,7 +88,7 @@ public void TestGetBlock() [TestMethod] public void TestGetBlockHash() { - Blockchain.Singleton.GetBlockHash(0).Should().Be(UInt256.Parse("0xc9387b803c8b4c6c1f69f6c876ed7848482c414b0225eb2a3a5395af39425455")); + Blockchain.Singleton.GetBlockHash(0).Should().Be(UInt256.Parse("0x557f5c9d0c865a211a749899681e5b4fbf745b3bcf0c395e6d6a7f1edb0d86f1")); Blockchain.Singleton.GetBlockHash(10).Should().BeNull(); } diff --git a/tests/neo.UnitTests/Ledger/UT_MemoryPool.cs b/tests/neo.UnitTests/Ledger/UT_MemoryPool.cs index 08d18ce58f..4e96605b7b 100644 --- a/tests/neo.UnitTests/Ledger/UT_MemoryPool.cs +++ b/tests/neo.UnitTests/Ledger/UT_MemoryPool.cs @@ -79,8 +79,7 @@ private Transaction CreateTransactionWithFee(long fee) mock.Object.Script = randomBytes; mock.Object.Sender = UInt160.Zero; mock.Object.NetworkFee = fee; - mock.Object.Attributes = new TransactionAttribute[0]; - mock.Object.Cosigners = new Cosigner[0]; + mock.Object.Attributes = Array.Empty(); mock.Object.Witnesses = new[] { new Witness @@ -104,8 +103,7 @@ private Transaction CreateTransactionWithFeeAndBalanceVerify(long fee) mock.Object.Script = randomBytes; mock.Object.Sender = sender; mock.Object.NetworkFee = fee; - mock.Object.Attributes = new TransactionAttribute[0]; - mock.Object.Cosigners = new Cosigner[0]; + mock.Object.Attributes = Array.Empty(); mock.Object.Witnesses = new[] { new Witness diff --git a/tests/neo.UnitTests/Ledger/UT_PoolItem.cs b/tests/neo.UnitTests/Ledger/UT_PoolItem.cs index 0d37e6edfd..a3c55712b8 100644 --- a/tests/neo.UnitTests/Ledger/UT_PoolItem.cs +++ b/tests/neo.UnitTests/Ledger/UT_PoolItem.cs @@ -2,7 +2,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using Neo.Ledger; -using Neo.IO; using Neo.Network.P2P.Payloads; using System; @@ -121,8 +120,7 @@ public static Transaction GenerateTx(long networkFee, int size, byte[] overrideS Script = overrideScriptBytes ?? new byte[0], Sender = UInt160.Zero, NetworkFee = networkFee, - Attributes = new TransactionAttribute[0], - Cosigners = new Cosigner[0], + Attributes = Array.Empty(), Witnesses = new[] { new Witness diff --git a/tests/neo.UnitTests/Ledger/UT_SendersFeeMonitor.cs b/tests/neo.UnitTests/Ledger/UT_SendersFeeMonitor.cs index 2b0d7a349b..cd8a5af463 100644 --- a/tests/neo.UnitTests/Ledger/UT_SendersFeeMonitor.cs +++ b/tests/neo.UnitTests/Ledger/UT_SendersFeeMonitor.cs @@ -24,8 +24,7 @@ private Transaction CreateTransactionWithFee(long networkFee, long systemFee) mock.Object.Sender = UInt160.Zero; mock.Object.NetworkFee = networkFee; mock.Object.SystemFee = systemFee; - mock.Object.Attributes = new TransactionAttribute[0]; - mock.Object.Cosigners = new Cosigner[0]; + mock.Object.Attributes = Array.Empty(); mock.Object.Witnesses = new[] { new Witness diff --git a/tests/neo.UnitTests/Ledger/UT_TransactionState.cs b/tests/neo.UnitTests/Ledger/UT_TransactionState.cs index 11ef772556..9446b954d2 100644 --- a/tests/neo.UnitTests/Ledger/UT_TransactionState.cs +++ b/tests/neo.UnitTests/Ledger/UT_TransactionState.cs @@ -61,7 +61,7 @@ public void TestDeserialize() [TestMethod] public void TestGetSize() { - ((ISerializable)origin).Size.Should().Be(62); + ((ISerializable)origin).Size.Should().Be(61); } } } diff --git a/tests/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs b/tests/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs index fb9bc84a5d..0e36930f0b 100644 --- a/tests/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs +++ b/tests/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs @@ -59,7 +59,7 @@ public void Size_Get_1_Transaction() TestUtils.GetTransaction() }; - uut.Size.Should().Be(166); + uut.Size.Should().Be(165); } [TestMethod] @@ -75,7 +75,7 @@ public void Size_Get_3_Transaction() TestUtils.GetTransaction() }; - uut.Size.Should().Be(270); + uut.Size.Should().Be(267); } [TestMethod] @@ -84,7 +84,7 @@ public void Serialize() UInt256 val256 = UInt256.Zero; TestUtils.SetupBlockWithValues(uut, val256, out var _, out var _, out var _, out var _, out var _, out var _, 1); - var hex = "000000000000000000000000000000000000000000000000000000000000000000000000c2f713d5d23bee9da2a298ef1ab6a7a454e51e813265d71c85f68ecafc8f774de913ff854c000000000000000000000000000000000000000000000000000000010001110200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100010000"; + var hex = "000000000000000000000000000000000000000000000000000000000000000000000000bc72014eb4f1fcdd27831b79c42ffa71e1b949086a97c87654a644585dd616f6e913ff854c0000000000000000000000000000000000000000000000000000000100011102000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100010000"; uut.ToArray().ToHexString().Should().Be(hex); } @@ -94,7 +94,7 @@ public void Deserialize() UInt256 val256 = UInt256.Zero; TestUtils.SetupBlockWithValues(new Block(), val256, out var merkRoot, out var val160, out var timestampVal, out var indexVal, out var scriptVal, out var transactionsVal, 1); - var hex = "000000000000000000000000000000000000000000000000000000000000000000000000c2f713d5d23bee9da2a298ef1ab6a7a454e51e813265d71c85f68ecafc8f774de913ff854c000000000000000000000000000000000000000000000000000000010001110200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100010000"; + var hex = "000000000000000000000000000000000000000000000000000000000000000000000000bc72014eb4f1fcdd27831b79c42ffa71e1b949086a97c87654a644585dd616f6e913ff854c0000000000000000000000000000000000000000000000000000000100011102000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100010000"; using (MemoryStream ms = new MemoryStream(hex.HexToBytes(), false)) using (BinaryReader reader = new BinaryReader(ms)) @@ -199,11 +199,11 @@ public void ToJson() JObject jObj = uut.ToJson(); jObj.Should().NotBeNull(); - jObj["hash"].AsString().Should().Be("0xa8bb713f8a2a1ed7e625e440d954dacdd504be1ff39c133c93bad77f150ffeb3"); - jObj["size"].AsNumber().Should().Be(166); + jObj["hash"].AsString().Should().Be("0xac84cebc5825cbe78941b301789bc43e8906bb9d86edd80cc94591088a26d9cc"); + jObj["size"].AsNumber().Should().Be(165); jObj["version"].AsNumber().Should().Be(0); jObj["previousblockhash"].AsString().Should().Be("0x0000000000000000000000000000000000000000000000000000000000000000"); - jObj["merkleroot"].AsString().Should().Be("0x4d778ffcca8ef6851cd76532811ee554a4a7b61aef98a2a29dee3bd2d513f7c2"); + jObj["merkleroot"].AsString().Should().Be("0xf616d65d5844a65476c8976a0849b9e171fa2fc4791b8327ddfcf1b44e0172bc"); jObj["time"].AsNumber().Should().Be(328665601001); jObj["index"].AsNumber().Should().Be(0); jObj["nextconsensus"].AsString().Should().Be("NKuyBkoGdZZSLyPbJEetheRhMjeznFZszf"); @@ -214,11 +214,10 @@ public void ToJson() jObj["tx"].Should().NotBeNull(); JArray txObj = (JArray)jObj["tx"]; - txObj[0]["hash"].AsString().Should().Be("0x606d39d98d1732fc1c9931f194aba8b2e40a5db5a26fdf4b513d4a6e0d69a8c8"); - txObj[0]["size"].AsNumber().Should().Be(52); + txObj[0]["hash"].AsString().Should().Be("0x5f9b7409b6cf21fb0bf63c3890f62cccfe5fb9c3277ea33935e0a09f4255407c"); + txObj[0]["size"].AsNumber().Should().Be(51); txObj[0]["version"].AsNumber().Should().Be(0); ((JArray)txObj[0]["attributes"]).Count.Should().Be(0); - ((JArray)txObj[0]["cosigners"]).Count.Should().Be(0); txObj[0]["net_fee"].AsString().Should().Be("0"); } } diff --git a/tests/neo.UnitTests/Network/P2P/Payloads/UT_Cosigner.cs b/tests/neo.UnitTests/Network/P2P/Payloads/UT_Cosigner.cs index 50cdfcea25..87ea4c8c26 100644 --- a/tests/neo.UnitTests/Network/P2P/Payloads/UT_Cosigner.cs +++ b/tests/neo.UnitTests/Network/P2P/Payloads/UT_Cosigner.cs @@ -18,7 +18,7 @@ public void Serialize_Deserialize_Global() Account = UInt160.Zero }; - var hex = "000000000000000000000000000000000000000000"; + var hex = "01000000000000000000000000000000000000000000"; attr.ToArray().ToHexString().Should().Be(hex); var copy = hex.HexToBytes().AsSerializable(); @@ -36,7 +36,7 @@ public void Serialize_Deserialize_CalledByEntry() Account = UInt160.Zero }; - var hex = "000000000000000000000000000000000000000001"; + var hex = "01000000000000000000000000000000000000000001"; attr.ToArray().ToHexString().Should().Be(hex); var copy = hex.HexToBytes().AsSerializable(); @@ -55,7 +55,7 @@ public void Serialize_Deserialize_CustomContracts() Account = UInt160.Zero }; - var hex = "000000000000000000000000000000000000000010010000000000000000000000000000000000000000"; + var hex = "01000000000000000000000000000000000000000010010000000000000000000000000000000000000000"; attr.ToArray().ToHexString().Should().Be(hex); var copy = hex.HexToBytes().AsSerializable(); @@ -75,7 +75,7 @@ public void Serialize_Deserialize_CustomGroups() Account = UInt160.Zero }; - var hex = "0000000000000000000000000000000000000000200103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c"; + var hex = "010000000000000000000000000000000000000000200103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c"; attr.ToArray().ToHexString().Should().Be(hex); var copy = hex.HexToBytes().AsSerializable(); @@ -94,7 +94,7 @@ public void Json_Global() Account = UInt160.Zero }; - var json = "{\"account\":\"0x0000000000000000000000000000000000000000\",\"scopes\":\"Global\"}"; + var json = "{\"type\":\"Cosigner\",\"account\":\"0x0000000000000000000000000000000000000000\",\"scopes\":\"Global\"}"; attr.ToJson().ToString().Should().Be(json); } @@ -107,7 +107,7 @@ public void Json_CalledByEntry() Account = UInt160.Zero }; - var json = "{\"account\":\"0x0000000000000000000000000000000000000000\",\"scopes\":\"CalledByEntry\"}"; + var json = "{\"type\":\"Cosigner\",\"account\":\"0x0000000000000000000000000000000000000000\",\"scopes\":\"CalledByEntry\"}"; attr.ToJson().ToString().Should().Be(json); } @@ -121,7 +121,7 @@ public void Json_CustomContracts() Account = UInt160.Zero }; - var json = "{\"account\":\"0x0000000000000000000000000000000000000000\",\"scopes\":\"CustomContracts\",\"allowedContracts\":[\"0x0000000000000000000000000000000000000000\"]}"; + var json = "{\"type\":\"Cosigner\",\"account\":\"0x0000000000000000000000000000000000000000\",\"scopes\":\"CustomContracts\",\"allowedContracts\":[\"0x0000000000000000000000000000000000000000\"]}"; attr.ToJson().ToString().Should().Be(json); } @@ -135,7 +135,7 @@ public void Json_CustomGroups() Account = UInt160.Zero }; - var json = "{\"account\":\"0x0000000000000000000000000000000000000000\",\"scopes\":\"CustomGroups\",\"allowedGroups\":[\"03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c\"]}"; + var json = "{\"type\":\"Cosigner\",\"account\":\"0x0000000000000000000000000000000000000000\",\"scopes\":\"CustomGroups\",\"allowedGroups\":[\"03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c\"]}"; attr.ToJson().ToString().Should().Be(json); } } diff --git a/tests/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs b/tests/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs index 4fc2f9cc4a..4267f8931e 100644 --- a/tests/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs +++ b/tests/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs @@ -64,8 +64,7 @@ public void Size_Get() { uut.Script = TestUtils.GetByteArray(32, 0x42); uut.Sender = UInt160.Zero; - uut.Attributes = new TransactionAttribute[0]; - uut.Cosigners = new Cosigner[0]; + uut.Attributes = Array.Empty(); uut.Witnesses = new[] { new Witness @@ -78,7 +77,7 @@ public void Size_Get() uut.Version.Should().Be(0); uut.Script.Length.Should().Be(32); uut.Script.GetVarSize().Should().Be(33); - uut.Size.Should().Be(83); + uut.Size.Should().Be(82); } [TestMethod] @@ -249,12 +248,12 @@ public void FeeIsSignatureContractDetailed() // Part I Assert.AreEqual(45, Transaction.HeaderSize); // Part II - Assert.AreEqual(1, tx.Attributes.GetVarSize()); - Assert.AreEqual(0, tx.Attributes.Length); + Assert.AreEqual(23, tx.Attributes.GetVarSize()); + Assert.AreEqual(1, tx.Attributes.Length); Assert.AreEqual(1, tx.Cosigners.Length); - Assert.AreEqual(22, tx.Cosigners.GetVarSize()); + Assert.AreEqual(23, tx.Cosigners.GetVarSize()); // Note that Data size and Usage size are different (because of first byte on GetVarSize()) - Assert.AreEqual(21, tx.Cosigners[0].Size); + Assert.AreEqual(22, tx.Cosigners[0].Size); // Part III Assert.AreEqual(86, tx.Script.GetVarSize()); // Part IV @@ -316,7 +315,7 @@ public void FeeIsSignatureContract_TestScope_Global() // using this... - var tx = wallet.MakeTransaction(script, acc.ScriptHash, new TransactionAttribute[0], cosigners); + var tx = wallet.MakeTransaction(script, acc.ScriptHash, cosigners); Assert.IsNotNull(tx); Assert.IsNull(tx.Witnesses); @@ -403,7 +402,7 @@ public void FeeIsSignatureContract_TestScope_CurrentHash_GAS() // using this... - var tx = wallet.MakeTransaction(script, acc.ScriptHash, new TransactionAttribute[0], cosigners); + var tx = wallet.MakeTransaction(script, acc.ScriptHash, cosigners); Assert.IsNotNull(tx); Assert.IsNull(tx.Witnesses); @@ -493,7 +492,7 @@ public void FeeIsSignatureContract_TestScope_CalledByEntry_Plus_GAS() // using this... - var tx = wallet.MakeTransaction(script, acc.ScriptHash, new TransactionAttribute[0], cosigners); + var tx = wallet.MakeTransaction(script, acc.ScriptHash, cosigners); Assert.IsNotNull(tx); Assert.IsNull(tx.Witnesses); @@ -581,8 +580,7 @@ public void FeeIsSignatureContract_TestScope_CurrentHash_NEO_FAULT() // expects FAULT on execution of 'transfer' Application script // due to lack of a valid witness validation Transaction tx = null; - Assert.ThrowsException(() => - tx = wallet.MakeTransaction(script, acc.ScriptHash, new TransactionAttribute[0], cosigners)); + Assert.ThrowsException(() => tx = wallet.MakeTransaction(script, acc.ScriptHash, cosigners)); Assert.IsNull(tx); } } @@ -631,7 +629,7 @@ public void FeeIsSignatureContract_TestScope_CurrentHash_NEO_GAS() // using this... - var tx = wallet.MakeTransaction(script, acc.ScriptHash, new TransactionAttribute[0], cosigners); + var tx = wallet.MakeTransaction(script, acc.ScriptHash, cosigners); Assert.IsNotNull(tx); Assert.IsNull(tx.Witnesses); @@ -649,7 +647,7 @@ public void FeeIsSignatureContract_TestScope_CurrentHash_NEO_GAS() // only a single witness should exist tx.Witnesses.Length.Should().Be(1); // no attributes must exist - tx.Attributes.Length.Should().Be(0); + tx.Attributes.Length.Should().Be(1); // one cosigner must exist tx.Cosigners.Length.Should().Be(1); @@ -713,14 +711,13 @@ public void FeeIsSignatureContract_TestScope_NoScopeFAULT() // trying with no scope var attributes = new TransactionAttribute[] { }; - var cosigners = new Cosigner[] { }; // using this... // expects FAULT on execution of 'transfer' Application script // due to lack of a valid witness validation Transaction tx = null; - Assert.ThrowsException(() => tx = wallet.MakeTransaction(script, acc.ScriptHash, attributes, cosigners)); + Assert.ThrowsException(() => tx = wallet.MakeTransaction(script, acc.ScriptHash, attributes)); Assert.IsNull(tx); } } @@ -737,8 +734,8 @@ public void Transaction_Reverify_Hashes_Length_Unequal_To_Witnesses_Length() SystemFee = (long)BigInteger.Pow(10, 8), // 1 GAS NetworkFee = 0x0000000000000001, ValidUntilBlock = 0x01020304, - Attributes = new TransactionAttribute[0] { }, - Cosigners = new Cosigner[] { + Attributes = new[] + { new Cosigner { Account = UInt160.Parse("0x0001020304050607080900010203040506070809"), @@ -765,8 +762,7 @@ public void Transaction_Serialize_Deserialize_Simple() SystemFee = (long)BigInteger.Pow(10, 8), // 1 GAS NetworkFee = 0x0000000000000001, ValidUntilBlock = 0x01020304, - Attributes = new TransactionAttribute[0] { }, - Cosigners = new Cosigner[0] { }, + Attributes = Array.Empty(), Script = new byte[] { (byte)OpCode.PUSH1 }, Witnesses = new Witness[0] { } }; @@ -781,7 +777,6 @@ public void Transaction_Serialize_Deserialize_Simple() "0100000000000000" + // network fee (1 satoshi) "04030201" + // timelimit "00" + // no attributes - "00" + // no cosigners "0111" + // push1 script "00"); // no witnesses @@ -813,8 +808,8 @@ public void Transaction_Serialize_Deserialize_DistinctCosigners() SystemFee = (long)BigInteger.Pow(10, 8), // 1 GAS NetworkFee = 0x0000000000000001, ValidUntilBlock = 0x01020304, - Attributes = new TransactionAttribute[0] { }, - Cosigners = new Cosigner[] { + Attributes = new[] + { new Cosigner { Account = UInt160.Parse("0x0001020304050607080900010203040506070809"), @@ -833,7 +828,7 @@ public void Transaction_Serialize_Deserialize_DistinctCosigners() byte[] sTx = txDoubleCosigners.ToArray(); // no need for detailed hexstring here (see basic tests for it) - sTx.ToHexString().Should().Be("0004030201000000000000000000000000000000000000000000e1f505000000000100000000000000040302010002090807060504030201000908070605040302010000090807060504030201000908070605040302010001011100"); + sTx.ToHexString().Should().Be("0004030201000000000000000000000000000000000000000000e1f50500000000010000000000000004030201020109080706050403020100090807060504030201000001090807060504030201000908070605040302010001011100"); // back to transaction (should fail, due to non-distinct cosigners) Transaction tx2 = null; @@ -874,8 +869,7 @@ public void Transaction_Serialize_Deserialize_MaxSizeCosigners() SystemFee = (long)BigInteger.Pow(10, 8), // 1 GAS NetworkFee = 0x0000000000000001, ValidUntilBlock = 0x01020304, - Attributes = new TransactionAttribute[0] { }, - Cosigners = cosigners1, // max + 1 (should fail) + Attributes = cosigners1, // max + 1 (should fail) Script = new byte[] { (byte)OpCode.PUSH1 }, Witnesses = new Witness[0] { } }; @@ -909,8 +903,7 @@ public void Transaction_Serialize_Deserialize_MaxSizeCosigners() SystemFee = (long)BigInteger.Pow(10, 8), // 1 GAS NetworkFee = 0x0000000000000001, ValidUntilBlock = 0x01020304, - Attributes = new TransactionAttribute[0] { }, - Cosigners = cosigners, // max + 1 (should fail) + Attributes = cosigners, // max + 1 (should fail) Script = new byte[] { (byte)OpCode.PUSH1 }, Witnesses = new Witness[0] { } }; @@ -972,7 +965,7 @@ public void FeeIsSignatureContract_TestScope_Global_Default() // using this... - var tx = wallet.MakeTransaction(script, acc.ScriptHash, new TransactionAttribute[0], cosigners); + var tx = wallet.MakeTransaction(script, acc.ScriptHash, cosigners); Assert.IsNotNull(tx); Assert.IsNull(tx.Witnesses); @@ -1021,8 +1014,7 @@ public void ToJson() uut.Script = TestUtils.GetByteArray(32, 0x42); uut.Sender = UInt160.Zero; uut.SystemFee = 4200000000; - uut.Attributes = new TransactionAttribute[] { }; - uut.Cosigners = new Cosigner[] { }; + uut.Attributes = Array.Empty(); uut.Witnesses = new[] { new Witness @@ -1034,11 +1026,10 @@ public void ToJson() JObject jObj = uut.ToJson(); jObj.Should().NotBeNull(); - jObj["hash"].AsString().Should().Be("0x8b86429eb984728752552ee8d69536d36ab985bbe383c6a6eeb2100f6f29b81b"); - jObj["size"].AsNumber().Should().Be(83); + jObj["hash"].AsString().Should().Be("0xfe08a23db645733a95914622ead5e738b03918680e927e00928116395e571758"); + jObj["size"].AsNumber().Should().Be(82); jObj["version"].AsNumber().Should().Be(0); ((JArray)jObj["attributes"]).Count.Should().Be(0); - ((JArray)jObj["cosigners"]).Count.Should().Be(0); jObj["net_fee"].AsString().Should().Be("0"); jObj["script"].AsString().Should().Be("QiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA="); jObj["sys_fee"].AsString().Should().Be("4200000000"); diff --git a/tests/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs b/tests/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs index aebda4d9da..a6cc76682f 100644 --- a/tests/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs +++ b/tests/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs @@ -54,9 +54,8 @@ private Witness PrepareDummyWitness(int maxAccounts) var data = new ContractParametersContext(new Transaction() { - Cosigners = new Cosigner[0], Sender = multiSignContract.ScriptHash, - Attributes = new TransactionAttribute[0], + Attributes = Array.Empty(), NetworkFee = 0, Nonce = 0, Script = new byte[0], diff --git a/tests/neo.UnitTests/SmartContract/UT_ContractParameterContext.cs b/tests/neo.UnitTests/SmartContract/UT_ContractParameterContext.cs index bfb0a53391..aaf6511997 100644 --- a/tests/neo.UnitTests/SmartContract/UT_ContractParameterContext.cs +++ b/tests/neo.UnitTests/SmartContract/UT_ContractParameterContext.cs @@ -47,14 +47,14 @@ public void TestToString() var context = new ContractParametersContext(tx); context.Add(contract, 0, new byte[] { 0x01 }); string str = context.ToString(); - str.Should().Be(@"{""type"":""Neo.Network.P2P.Payloads.Transaction"",""hex"":""AAAAAABmUJDLobcPtqo9vZKIdjXsd8fVGwAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAA=="",""items"":{}}"); + str.Should().Be(@"{""type"":""Neo.Network.P2P.Payloads.Transaction"",""hex"":""AAAAAABmUJDLobcPtqo9vZKIdjXsd8fVGwAAAAAAAAAAAAAAAAAAAAAAAAAAAAEA"",""items"":{}}"); } [TestMethod] public void TestParse() { - var ret = ContractParametersContext.Parse("{\"type\":\"Neo.Network.P2P.Payloads.Transaction\",\"hex\":\"AAAAAADyd\\/EUQDWkOJf5\\u002BhFSWOrAFa3KvgAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAA==\",\"items\":{\"0xbecaad15c0ea585211faf99738a4354014f177f2\":{\"script\":\"IQJv8DuUkkHOHa3UNRnmlg4KhbQaaaBcMoEDqivOFZTKFmh0dHaq\",\"parameters\":[{\"type\":\"Signature\",\"value\":\"AQ==\"}]}}}"); - ret.ScriptHashes[0].ToString().Should().Be("0xbecaad15c0ea585211faf99738a4354014f177f2"); + var ret = ContractParametersContext.Parse("{\"type\":\"Neo.Network.P2P.Payloads.Transaction\",\"hex\":\"AAAAAABmUJDLobcPtqo9vZKIdjXsd8fVGwAAAAAAAAAAAAAAAAAAAAAAAAAAAAEA\",\"items\":{\"0xbecaad15c0ea585211faf99738a4354014f177f2\":{\"script\":\"IQJv8DuUkkHOHa3UNRnmlg4KhbQaaaBcMoEDqivOFZTKFmh0dHaq\",\"parameters\":[{\"type\":\"Signature\",\"value\":\"AQ==\"}]}}}"); + ret.ScriptHashes[0].ToString().Should().Be("0x1bd5c777ec35768892bd3daab60fb7a1cb905066"); ((Transaction)ret.Verifiable).Script.ToHexString().Should().Be(new byte[1].ToHexString()); } diff --git a/tests/neo.UnitTests/SmartContract/UT_Syscalls.cs b/tests/neo.UnitTests/SmartContract/UT_Syscalls.cs index 4a6bd90689..0fc198f3d5 100644 --- a/tests/neo.UnitTests/SmartContract/UT_Syscalls.cs +++ b/tests/neo.UnitTests/SmartContract/UT_Syscalls.cs @@ -3,11 +3,10 @@ using Neo.Ledger; using Neo.Network.P2P.Payloads; using Neo.SmartContract; -using Neo.SmartContract.Manifest; using Neo.VM; using Neo.VM.Types; -using System.Collections.Generic; using System.Linq; +using Array = System.Array; namespace Neo.UnitTests.SmartContract { @@ -26,8 +25,7 @@ public void System_Blockchain_GetBlock() var tx = new Transaction() { Script = new byte[] { 0x01 }, - Attributes = new TransactionAttribute[0], - Cosigners = new Cosigner[0], + Attributes = Array.Empty(), NetworkFee = 0x02, SystemFee = 0x03, Nonce = 0x04, @@ -245,8 +243,7 @@ public void System_ExecutionEngine_GetScriptContainer() var tx = new Transaction() { Script = new byte[] { 0x01 }, - Attributes = new TransactionAttribute[0], - Cosigners = new Cosigner[0], + Attributes = Array.Empty(), NetworkFee = 0x02, SystemFee = 0x03, Nonce = 0x04, @@ -263,7 +260,7 @@ public void System_ExecutionEngine_GetScriptContainer() Assert.AreEqual(1, engine.ResultStack.Count); Assert.IsInstanceOfType(engine.ResultStack.Peek(), typeof(ByteString)); Assert.AreEqual(engine.ResultStack.Pop().GetSpan().ToHexString(), - @"5b226770564846625133316969517a614f4c7a33523546394d6256715932596b7a5164324461785536677154303d222c362c342c222f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f383d222c332c322c352c2241513d3d225d"); + @"5b224435724a376f755c753030324256574845456c5c75303032426e74486b414a424f614c4a6737496776303356337a4953646d6750413d222c362c342c222f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f383d222c332c322c352c2241513d3d225d"); Assert.AreEqual(0, engine.ResultStack.Count); } } diff --git a/tests/neo.UnitTests/TestUtils.cs b/tests/neo.UnitTests/TestUtils.cs index 0338ff32c1..fd8e6fd620 100644 --- a/tests/neo.UnitTests/TestUtils.cs +++ b/tests/neo.UnitTests/TestUtils.cs @@ -73,8 +73,7 @@ public static Transaction GetTransaction() { Script = new byte[1], Sender = UInt160.Zero, - Attributes = new TransactionAttribute[0], - Cosigners = new Cosigner[0], + Attributes = Array.Empty(), Witnesses = new Witness[]{ new Witness { InvocationScript = new byte[0], @@ -170,8 +169,7 @@ public static Transaction CreateRandomHashTransaction() { Script = randomBytes, Sender = UInt160.Zero, - Attributes = new TransactionAttribute[0], - Cosigners = new Cosigner[0], + Attributes = Array.Empty(), Witnesses = new[] { new Witness