Skip to content

Commit

Permalink
Network dependant signature (#1550)
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon authored Apr 11, 2020
1 parent dc6b833 commit bf16df9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/neo/Network/P2P/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static byte[] GetHashData(this IVerifiable verifiable)
using (MemoryStream ms = new MemoryStream())
using (BinaryWriter writer = new BinaryWriter(ms))
{
writer.Write(ProtocolSettings.Default.Magic);
verifiable.SerializeUnsigned(writer);
writer.Flush();
return ms.ToArray();
Expand Down
6 changes: 3 additions & 3 deletions tests/neo.UnitTests/Ledger/UT_Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ public void TestContainsTransaction()
[TestMethod]
public void TestGetCurrentBlockHash()
{
Blockchain.Singleton.CurrentBlockHash.Should().Be(UInt256.Parse("0x2b8a21dfaf989dc1a5f2694517aefdbda1dd340f3cf177187d73e038a58ad2bb"));
Blockchain.Singleton.CurrentBlockHash.Should().Be(UInt256.Parse("0xdba446947a90b2862ef050703b44828ad8b02d11978f8ef59bd3e1c97aabf6e5"));
}

[TestMethod]
public void TestGetCurrentHeaderHash()
{
Blockchain.Singleton.CurrentHeaderHash.Should().Be(UInt256.Parse("0x2b8a21dfaf989dc1a5f2694517aefdbda1dd340f3cf177187d73e038a58ad2bb"));
Blockchain.Singleton.CurrentHeaderHash.Should().Be(UInt256.Parse("0xdba446947a90b2862ef050703b44828ad8b02d11978f8ef59bd3e1c97aabf6e5"));
}

[TestMethod]
Expand All @@ -88,7 +88,7 @@ public void TestGetBlock()
[TestMethod]
public void TestGetBlockHash()
{
Blockchain.Singleton.GetBlockHash(0).Should().Be(UInt256.Parse("0x2b8a21dfaf989dc1a5f2694517aefdbda1dd340f3cf177187d73e038a58ad2bb"));
Blockchain.Singleton.GetBlockHash(0).Should().Be(UInt256.Parse("0xdba446947a90b2862ef050703b44828ad8b02d11978f8ef59bd3e1c97aabf6e5"));
Blockchain.Singleton.GetBlockHash(10).Should().BeNull();
}

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 = "0000000000000000000000000000000000000000000000000000000000000000000000007227ba7b747f1a98f68679d4a98b68927646ab195a6f56b542ca5a0e6a412662e913ff854c000000000000000000000000000000000000000000000000000000010001110200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100010000";
var hex = "000000000000000000000000000000000000000000000000000000000000000000000000c2f713d5d23bee9da2a298ef1ab6a7a454e51e813265d71c85f68ecafc8f774de913ff854c000000000000000000000000000000000000000000000000000000010001110200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100010000";
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 = "0000000000000000000000000000000000000000000000000000000000000000000000007227ba7b747f1a98f68679d4a98b68927646ab195a6f56b542ca5a0e6a412662e913ff854c000000000000000000000000000000000000000000000000000000010001110200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100010000";
var hex = "000000000000000000000000000000000000000000000000000000000000000000000000c2f713d5d23bee9da2a298ef1ab6a7a454e51e813265d71c85f68ecafc8f774de913ff854c000000000000000000000000000000000000000000000000000000010001110200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100010000";

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

JObject jObj = uut.ToJson();
jObj.Should().NotBeNull();
jObj["hash"].AsString().Should().Be("0x865b348426952d2eaa978cf5d37dc85ec5f95bc56c57c1379d1be21898e74c1e");
jObj["hash"].AsString().Should().Be("0xa8bb713f8a2a1ed7e625e440d954dacdd504be1ff39c133c93bad77f150ffeb3");
jObj["size"].AsNumber().Should().Be(166);
jObj["version"].AsNumber().Should().Be(0);
jObj["previousblockhash"].AsString().Should().Be("0x0000000000000000000000000000000000000000000000000000000000000000");
jObj["merkleroot"].AsString().Should().Be("0x6226416a0e5aca42b5566f5a19ab467692688ba9d47986f6981a7f747bba2772");
jObj["merkleroot"].AsString().Should().Be("0x4d778ffcca8ef6851cd76532811ee554a4a7b61aef98a2a29dee3bd2d513f7c2");
jObj["time"].AsNumber().Should().Be(328665601001);
jObj["index"].AsNumber().Should().Be(0);
jObj["nextconsensus"].AsString().Should().Be("NKuyBkoGdZZSLyPbJEetheRhMjeznFZszf");
Expand All @@ -214,7 +214,7 @@ public void ToJson()

jObj["tx"].Should().NotBeNull();
JArray txObj = (JArray)jObj["tx"];
txObj[0]["hash"].AsString().Should().Be("0xf374032ea013e3d9272f7a25dc1fe497a489ae36e94aa06270b26e60ab693435");
txObj[0]["hash"].AsString().Should().Be("0x606d39d98d1732fc1c9931f194aba8b2e40a5db5a26fdf4b513d4a6e0d69a8c8");
txObj[0]["size"].AsNumber().Should().Be(52);
txObj[0]["version"].AsNumber().Should().Be(0);
((JArray)txObj[0]["attributes"]).Count.Should().Be(0);
Expand Down
2 changes: 1 addition & 1 deletion tests/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ public void ToJson()

JObject jObj = uut.ToJson();
jObj.Should().NotBeNull();
jObj["hash"].AsString().Should().Be("0x11e3ee692015f0cd3cb8b6db7a4fc37568540f020cb9ca497a9917c81f20b62f");
jObj["hash"].AsString().Should().Be("0x8b86429eb984728752552ee8d69536d36ab985bbe383c6a6eeb2100f6f29b81b");
jObj["size"].AsNumber().Should().Be(83);
jObj["version"].AsNumber().Should().Be(0);
((JArray)jObj["attributes"]).Count.Should().Be(0);
Expand Down
4 changes: 2 additions & 2 deletions tests/neo.UnitTests/SmartContract/UT_Syscalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void System_Blockchain_GetBlock()
Assert.AreEqual(1, engine.ResultStack.Count);
Assert.IsInstanceOfType(engine.ResultStack.Peek(), typeof(ByteString));
Assert.AreEqual(engine.ResultStack.Pop().GetSpan().ToHexString(),
"5b22366b4139757552614430373634585358466c706674686b436b5954702f6e34623878715057476c6a6659303d222c332c22414141414141414141414141414141414141414141414141414141414141414141414141414141414141413d222c22414141414141414141414141414141414141414141414141414141414141414141414141414141414141413d222c322c302c224141414141414141414141414141414141414141414141414141413d222c315d");
"5b2261564e62466b35384f51717547373870747154766561762f48677941566a72634e41434d4e59705c7530303242366f6f3d222c332c22414141414141414141414141414141414141414141414141414141414141414141414141414141414141413d222c22414141414141414141414141414141414141414141414141414141414141414141414141414141414141413d222c322c302c224141414141414141414141414141414141414141414141414141413d222c315d");
Assert.AreEqual(0, engine.ResultStack.Count);

// Clean
Expand Down Expand Up @@ -261,7 +261,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(),
@"5b225c75303032426b53415959527a4c4b69685a676464414b50596f754655737a63544d7867445a6572584a3172784c37303d222c362c342c222f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f383d222c332c322c352c2241513d3d225d");
@"5b226770564846625133316969517a614f4c7a33523546394d6256715932596b7a5164324461785536677154303d222c362c342c222f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f383d222c332c322c352c2241513d3d225d");
Assert.AreEqual(0, engine.ResultStack.Count);
}
}
Expand Down
7 changes: 1 addition & 6 deletions tests/neo.UnitTests/UT_Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ public void GetHashData()
{
TestVerifiable verifiable = new TestVerifiable();
byte[] res = verifiable.GetHashData();
res.Length.Should().Be(8);
byte[] requiredData = new byte[] { 7, 116, 101, 115, 116, 83, 116, 114 };
for (int i = 0; i < requiredData.Length; i++)
{
res[i].Should().Be(requiredData[i]);
}
res.ToHexString().Should().Be("4e454f000774657374537472");
}

[TestMethod]
Expand Down

0 comments on commit bf16df9

Please sign in to comment.