Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #2266 #2268

Merged
merged 1 commit into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tests/neo.UnitTests/Ledger/UT_TransactionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Neo.Network.P2P.Payloads;
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.VM;
using System;
using System.IO;

Expand All @@ -22,7 +23,7 @@ public void Initialize()
Transaction = new Transaction()
{
Attributes = Array.Empty<TransactionAttribute>(),
Script = new byte[] { 0x01 },
Script = new byte[] { (byte)OpCode.PUSH1 },
Signers = new Signer[] { new Signer() { Account = UInt160.Zero } },
Witnesses = new Witness[] { new Witness() {
InvocationScript=Array.Empty<byte>(),
Expand Down
10 changes: 5 additions & 5 deletions tests/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "000000000000000000000000000000000000000000000000000000000000000000000000add6632f6f3d29cdf94555bb191fb5296683e5446f9937c56bb94c8608023044e913ff854c00000000000000000000000000000000000000000000000000000001000111020000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000001000100010000";
var hex = "0000000000000000000000000000000000000000000000000000000000000000000000007ee5991fa69cf4d7902430f5fad89ba13b253b5680cb13167f80bfc3593947e7e913ff854c00000000000000000000000000000000000000000000000000000001000111020000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000001000112010000";
uut.ToArray().ToHexString().Should().Be(hex);
}

Expand All @@ -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 = "000000000000000000000000000000000000000000000000000000000000000000000000add6632f6f3d29cdf94555bb191fb5296683e5446f9937c56bb94c8608023044e913ff854c00000000000000000000000000000000000000000000000000000001000111020000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000001000100010000";
var hex = "0000000000000000000000000000000000000000000000000000000000000000000000007ee5991fa69cf4d7902430f5fad89ba13b253b5680cb13167f80bfc3593947e7e913ff854c00000000000000000000000000000000000000000000000000000001000111020000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000001000112010000";

using (MemoryStream ms = new MemoryStream(hex.HexToBytes(), false))
using (BinaryReader reader = new BinaryReader(ms))
Expand Down Expand Up @@ -178,11 +178,11 @@ public void ToJson()

JObject jObj = uut.ToJson();
jObj.Should().NotBeNull();
jObj["hash"].AsString().Should().Be("0x9a164d5b9a1ab8745c97dbaaaef8eb30b0d80a00205acdc82daf502bee69bc20");
jObj["hash"].AsString().Should().Be("0xaf156a193ba2d7f05a37dd4e6fdfd1167cb6db3df5474df43a71a645a449fbc8");
jObj["size"].AsNumber().Should().Be(167);
jObj["version"].AsNumber().Should().Be(0);
jObj["previousblockhash"].AsString().Should().Be("0x0000000000000000000000000000000000000000000000000000000000000000");
jObj["merkleroot"].AsString().Should().Be("0x44300208864cb96bc537996f44e5836629b51f19bb5545f9cd293d6f2f63d6ad");
jObj["merkleroot"].AsString().Should().Be("0xe7473959c3bf807f1613cb80563b253ba19bd8faf5302490d7f49ca61f99e57e");
jObj["time"].AsNumber().Should().Be(328665601001);
jObj["index"].AsNumber().Should().Be(0);
jObj["nextconsensus"].AsString().Should().Be("NKuyBkoGdZZSLyPbJEetheRhMjeznFZszf");
Expand All @@ -193,7 +193,7 @@ public void ToJson()

jObj["tx"].Should().NotBeNull();
JArray txObj = (JArray)jObj["tx"];
txObj[0]["hash"].AsString().Should().Be("0x995ce8ff19c30f6b0d6b03e5ed8bd30b08027c92177923782d3a64f573421931");
txObj[0]["hash"].AsString().Should().Be("0x0ee830a3b3e93679e23a9ee7e2a55287d79b6d67d056b03aa7ca917bd3d2923c");
txObj[0]["size"].AsNumber().Should().Be(53);
txObj[0]["version"].AsNumber().Should().Be(0);
((JArray)txObj[0]["attributes"]).Count.Should().Be(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Neo.IO;
using Neo.Network.P2P.Payloads;
using Neo.SmartContract;
using Neo.VM;
using System;

namespace Neo.UnitTests.Network.P2P.Payloads
Expand Down Expand Up @@ -33,7 +34,7 @@ public void DeserializeAndSerialize()
ValidBlockEnd = 789,
Sender = Array.Empty<byte>().ToScriptHash(),
Data = new byte[] { 1, 2, 3 },
Witness = new Witness() { InvocationScript = new byte[] { 3, 5, 6 }, VerificationScript = Array.Empty<byte>() }
Witness = new Witness() { InvocationScript = new byte[] { (byte)OpCode.PUSH1, (byte)OpCode.PUSH2, (byte)OpCode.PUSH3 }, VerificationScript = Array.Empty<byte>() }
};
var clone = test.ToArray().AsSerializable<ExtensiblePayload>();

Expand Down
10 changes: 6 additions & 4 deletions tests/neo.UnitTests/Network/P2P/UT_Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Neo.IO;
using Neo.Network.P2P;
using Neo.Network.P2P.Payloads;
using Neo.VM;
using System;
using System.Linq;

Expand Down Expand Up @@ -131,21 +132,22 @@ public void Compression()
Nonce = 1,
Version = 0,
Attributes = new TransactionAttribute[0],
Script = new byte[75],
Script = new byte[] { (byte)OpCode.PUSH1 },
Signers = new Signer[] { new Signer() { Account = UInt160.Zero } },
Witnesses = new Witness[0],
};

var msg = Message.Create(MessageCommand.Transaction, payload);
var buffer = msg.ToArray();

buffer.Length.Should().Be(128);
buffer.Length.Should().Be(54);

payload.Script = new byte[payload.Script.Length + 10];
payload.Script = new byte[100];
for (int i = 0; i < payload.Script.Length; i++) payload.Script[i] = (byte)OpCode.PUSH2;
msg = Message.Create(MessageCommand.Transaction, payload);
buffer = msg.ToArray();

buffer.Length.Should().Be(33);
buffer.Length.Should().Be(30);

var copy = buffer.AsSerializable<Message>();
var payloadCopy = (Transaction)copy.Payload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ 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"":""AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFmUJDLobcPtqo9vZKIdjXsd8fVGwEAAQA="",""items"":{}}");
str.Should().Be(@"{""type"":""Neo.Network.P2P.Payloads.Transaction"",""hex"":""AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFmUJDLobcPtqo9vZKIdjXsd8fVGwEAARI="",""items"":{}}");
}

[TestMethod]
public void TestParse()
{
var ret = ContractParametersContext.Parse("{\"type\":\"Neo.Network.P2P.Payloads.Transaction\",\"hex\":\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFmUJDLobcPtqo9vZKIdjXsd8fVGwEAAQA=\",\"items\":{\"0xbecaad15c0ea585211faf99738a4354014f177f2\":{\"script\":\"IQJv8DuUkkHOHa3UNRnmlg4KhbQaaaBcMoEDqivOFZTKFmh0dHaq\",\"parameters\":[{\"type\":\"Signature\",\"value\":\"AQ==\"}]}}}");
var ret = ContractParametersContext.Parse("{\"type\":\"Neo.Network.P2P.Payloads.Transaction\",\"hex\":\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFmUJDLobcPtqo9vZKIdjXsd8fVGwEAARI=\",\"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());
((Transaction)ret.Verifiable).Script.ToHexString().Should().Be(new byte[] { 18 }.ToHexString());
}

[TestMethod]
Expand Down
2 changes: 1 addition & 1 deletion tests/neo.UnitTests/TestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static Transaction GetTransaction(UInt160 sender)
{
return new Transaction
{
Script = new byte[1],
Script = new byte[] { (byte)OpCode.PUSH2 },
Attributes = Array.Empty<TransactionAttribute>(),
Signers = new[]{ new Signer()
{
Expand Down