-
Notifications
You must be signed in to change notification settings - Fork 719
test: add hand-derived golden tests for eth/71 and snap serializers #12699
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,20 @@ public void Roundtrip() | |
| { | ||
| ArrayPoolList<byte[]> data = new(2) { new byte[] { 0xde, 0xad, 0xc0, 0xde }, new byte[] { 0xfe, 0xed } }; | ||
|
|
||
| ByteCodesMessage message = new(new ByteArrayListAdapter(data)) { RequestId = 1 }; | ||
|
|
||
|
|
||
| ByteCodesMessageSerializer serializer = new(); | ||
|
|
||
| // The message encodes as [requestId, codes]. | ||
| SerializerTester.TestZero(serializer, message, "ca01c884deadc0de82feed"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Roundtrip_random_request_id() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Low — this new fixture member is the one place the PR moves against its own thesis: it adds a fresh non-deterministic test ( It also duplicates the three setup lines of [TestCase(1L, "ca01c884deadc0de82feed")]
[TestCase(long.MaxValue, "d2887fffffffffffffffc884deadc0de82feed")]
public void Roundtrip(long requestId, string expectedData)
{
ArrayPoolList<byte[]> data = new(2) { new byte[] { 0xde, 0xad, 0xc0, 0xde }, new byte[] { 0xfe, 0xed } };
ByteCodesMessage message = new(new ByteArrayListAdapter(data)) { RequestId = requestId };
ByteCodesMessageSerializer serializer = new();
// The message encodes as [requestId, codes].
SerializerTester.TestZero(serializer, message, expectedData);
}That keeps the multi-byte-id path covered and deterministic. (Second vector derived the same way: |
||
| { | ||
| ArrayPoolList<byte[]> data = new(2) { new byte[] { 0xde, 0xad, 0xc0, 0xde }, new byte[] { 0xfe, 0xed } }; | ||
|
|
||
| // The constructor assigns a random request id; it must roundtrip unchanged. | ||
| ByteCodesMessage message = new(new ByteArrayListAdapter(data)); | ||
|
|
||
| ByteCodesMessageSerializer serializer = new(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // SPDX-FileCopyrightText: 2026 Demerzel Solutions Limited | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
|
|
||
| using Nethermind.Core.Crypto; | ||
|
|
||
| namespace Nethermind.Network.Test.P2P.Subprotocols.Snap.V1.Messages; | ||
|
|
||
| /// <summary> | ||
| /// Shared inputs and hand-derived RLP fragments for the snap serializer goldens. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Each golden fragment and its input come from one hex constant, so the | ||
| /// expectation cannot drift from the input. The values are verified with an | ||
| /// independent encoder (pyrlp + pycryptodome keccak). | ||
| /// </remarks> | ||
| internal static class SnapSerializerGoldens | ||
| { | ||
| private const string EmptyStringKeccakHex = "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"; | ||
| private const string RangeStartHex = "15d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"; | ||
| private const string RangeLimitHex = "20d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"; | ||
|
|
||
| /// <summary>Request id 1111 as an RLP item: 0x82 length prefix + 0x0457.</summary> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Low — two nits on the drift-proofing story in this file.
/// <summary>The request id the range/bytecode request tests use.</summary>
public const long RequestId1111 = 1111;
/// <summary>Request id 1111 as an RLP item: 0x82 length prefix + 0x0457.</summary>
public const string RequestId1111Rlp = "820457";Neither is a correctness problem — the values themselves all check out. |
||
| public const string RequestId1111Rlp = "820457"; | ||
|
|
||
| /// <summary>keccak("") as an RLP item: 0xa0 + 32 bytes.</summary> | ||
| public const string EmptyStringKeccakRlp = "a0" + EmptyStringKeccakHex; | ||
|
|
||
| /// <summary><see cref="RangeStart"/> as an RLP item.</summary> | ||
| public const string RangeStartRlp = "a0" + RangeStartHex; | ||
|
|
||
| /// <summary><see cref="RangeLimit"/> as an RLP item.</summary> | ||
| public const string RangeLimitRlp = "a0" + RangeLimitHex; | ||
|
|
||
| /// <summary>The starting hash the range request tests use.</summary> | ||
| public static readonly Hash256 RangeStart = new(RangeStartHex); | ||
|
|
||
| /// <summary>The limit hash the range request tests use.</summary> | ||
| public static readonly Hash256 RangeLimit = new(RangeLimitHex); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Low — this comment restates the three lines directly below it (
Keccak.Zero, TestItem.KeccakA, TestItem.KeccakB), which AGENTS.md asks you to skip ("Comments that merely restate the code are noise"). The other two comments added in this file earn their keep —// Each hash encodes as 0xa0 + 32 bytes.and// A negative request id encodes as its unsigned two's-complement value.both explain a derivation a reader can't get from the code. This one doesn't.If the intent was to make the two 32-byte literals traceable to their inputs, the useful version says that instead — e.g.
// keccak("A") and keccak("B"); the same values #12696 pins in EthSerializerGoldens.— otherwise dropping the line is cleaner.Fix this →