You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: resolve double serialization in GenesisOption for InternalTransaction (#106) (#113)
## Description
This PR fixes a double serialization bug in the `GenesisOption` type
that caused deserialization of `InternalTransaction` to fail. The
changes ensure that serialization and deserialization work correctly,
allowing for a successful round-trip.
## The Problem
Previously, the `genesis_string::serialize` function was performing a
**double serialization**:
1. First, it serialized an inner value (like an `Address`) into a JSON
string using `serde_json::to_string(value)`.
2. Then, it serialized that resulting string *again* with
`serializer.serialize_str(&json)`.
This created malformed JSON with incorrectly escaped quotes, which could
not be deserialized:
```json
{
"contractAddress": "\"0x0a36f9565c6fb862509ad8d148941968344a55d8\""
}
```
## The Solution
The fix addresses both serialization and deserialization for a complete
and robust solution:
* **Corrected Serialization**: The `serialize` function was updated to
delegate serialization directly using `value.serialize(serializer)`.
This avoids the intermediate string conversion and eliminates the double
serialization bug.
* **Updated Deserialization**: The corresponding `deserialize` function
was updated to correctly parse the clean, well-formed JSON produced by
the fixed serializer.
As a result, the serialization process now produces the correct output,
which can be successfully deserialized:
```json
{
"contractAddress": "0x0a36f9565c6fb862509ad8d148941968344a55d8"
}
```
## Verification & Testing
The fix has been thoroughly verified with a new **round-trip test case**
for `InternalTransaction`. This test:
* Serializes an `InternalTransaction` instance to JSON.
* Asserts that the output **does not contain** escaped quotes (`\\\"`),
confirming the serialization bug is fixed.
* Successfully deserializes the JSON back into an `InternalTransaction`
instance.
* Asserts that the data remains identical after the full cycle, ensuring
data integrity.
The new test is passing, confirming the effectiveness of the solution. ✅
Closes#106
0 commit comments