Chainscore / Chainscore/tessera

bug: Dictionary.from_json cannot deserialize when key_type is a complex dataclass (e.g. LookupTable)

Open
#147 0 comments 0 reactions 1 assignee Claimed by @prasad-kumkar View on GitHub
bug
Dominant language
Python
Stars
1
Forks
0
PR merge metrics
No merged PRs in 30d

Description

## Bug Description
When calling Dictionary.from_json(...) on a dictionary whose key type is itself a non‑primitive dataclass (for example, LookupTimestamps whose keys are LookupTable instances), the JSON-based deserializer rejects the input. It expects the JSON representation of the dictionary to use only primitive string keys, but our keys are JSON objects (or tuples), so it raises:

## Steps to Reproduce
```
state.delta = Delta.from_json({
1: {
"balance": 0,
"storage": { "": "" },
"lookup": { "": "" },
"timestamps": {
{ "hash": "", "length": 0 }: []
},
"code_hash": "",
"gas_limit": 0,
"min_gas": 0
}
})
```

## Expected Behavior
Dictionary.from_json should support non‑primitive keys whose key_type implements its own from_json (e.g. a dataclass with "hash" and "length" fields). The JSON loader should accept JSON objects as keys (by serializing them to strings, or by iterating the mapping as arrays of [key, value] pairs), then hand each object to the key type’s from_json.

## Actual Behavior
The loader refuses to accept any non‑string key. It attempts to treat the literal map’s keys directly as Python primitives (tuples, ByteArray32, etc.), then fails when it tries to feed them to LookupTable.from_json, which expects a dict.

## Screenshots

![Image](https://github.com/user-attachments/assets/451a70ad-9d8f-46ab-9ee7-35268c6020be)

## Possible Solution
Might be-> Support the “array of pairs” format ([[keyJson, valueJson], …]) for complex keys.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.