Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public override void Write(
ValueHash256 keccak,
JsonSerializerOptions options)
{
ByteArrayConverter.Convert(writer, keccak.Bytes, skipLeadingZeros: true);
ByteArrayConverter.Convert(writer, keccak.Bytes, skipLeadingZeros: false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,37 @@ public void TestL1OriginById_WithBuildPayloadArgsId()

rpc.taiko_l1OriginByID(0).Result.Data.Should().Be(origin);
}

[Test]
public void TestL1OriginById_ValueHash256_EvenLengthHex()
{
IL1OriginStore originStore = Substitute.For<IL1OriginStore>();
TaikoExtendedEthModule rpc = new TaikoExtendedEthModule(new SyncConfig(), originStore);
int expectedLengthInChars = ValueHash256.Length * 2 + 2;

// Create odd length hash values
var l2BlockHash = new ValueHash256("0x35a48c5b3ee5b1b2a365fcd1aa68c738d1c06474578087a78fa79dd45de6214");
var l1BlockHash = new Hash256("0x2daf7e4b06ca2d3a82c775d9e9ad0c973545a608684146cda0df5f7d71188a5");

L1Origin origin = new L1Origin(0, l2BlockHash, 1, l1BlockHash, null);
originStore.ReadL1Origin((UInt256)0).Returns(origin);

var result = rpc.taiko_l1OriginByID(0).Result.Data;
result.Should().Be(origin);

// Serialize the RPC result and verify hash values have even-length hex string
var serializer = new Serialization.Json.EthereumJsonSerializer();
var json = serializer.Serialize(result);

// Parse the JSON to extract the hash values
var jsonDoc = System.Text.Json.JsonDocument.Parse(json);
var l2BlockHashString = jsonDoc.RootElement.GetProperty("l2BlockHash").GetString();
var l1BlockHashString = jsonDoc.RootElement.GetProperty("l1BlockHash").GetString();

l2BlockHashString.Should().NotBeNull();
l2BlockHashString!.Length.Should().Be(expectedLengthInChars);

l1BlockHashString.Should().NotBeNull();
l1BlockHashString!.Length.Should().Be(expectedLengthInChars);
}
}
Loading