test_alice_and_bob fails: relay leaks internal size field on outgoing events #5
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Symptom
tests/test_clients.py::test_alice_and_bobfails with:The relay is appending
"size": <bytes>to every outgoing event payload. Test fixtures (tests/fixture/...) don't carry that field, so dict comparisons viadumps(...)blow up.Pre-existing — confirmed via
git log -S '"size"' -- '*.py': the field was introduced in commit73054fd feat: update to v1.0.0 (#30), well before the recent4811fcf feat(nip17): support gift-wrapped private direct messages. NIP-17 is not the cause; just the time when the failure was noticed during a full test run.Root cause
relay/event.py:26addssize: int = 0to the relay's event model:It's populated in
relay/client_connection.py:126:This field is internal accounting used by
event_validator._validate_storage(per-pubkey storage quotas, prune_old_events, etc.) — it has no place in the wire format defined by NIP-01. When the model is serialized to JSON for delivery to clients,sizegets included.This means:
Suggested fix (preferred)
Strip
size(and any other internal-only fields) from the dict that gets shipped to clients. Either:Config.fields = {"size": {"exclude": True}}on the pydantic model, orto_wire_dict()method that returns only NIP-01 fields, used in the broadcast path.Option 2 is more explicit — easier to evolve without surprising other call sites that legitimately want
size(DB writes, validators).Alternative
Update
tests/fixture/*.jsonto include"size"everywhere. Cheap but brittle: every test fixture has to track a relay-internal accounting detail that has nothing to do with what the relay actually exposes per spec.Verification
After the fix,
make testshould pass cleanly:Currently 14/15 pass; this is the one remaining failure.