etf: add MAP_EXT (tag 116) for Erlang/Elixir maps

Python dict round-trips as an Erlang/Elixir map. Golden vectors from
real Erlang term_to_binary verify wire compatibility for:
  - empty map (#{})
  - keyed map with binary keys + mixed values
  - {ok, #{status => ok, balance => N}} (Elixir gen_server reply shape)

122 tests green. Required for the unfeed ErlangDistTransport which
decodes Elixir wallet RPC replies.
This commit is contained in:
russell@unturf.com 2026-06-16 12:16:35 -04:00
parent 271d712237
commit 531c26fcfb
No known key found for this signature in database
2 changed files with 27 additions and 0 deletions

View file

@ -49,6 +49,13 @@ GOLDEN = [
("nested",
"83680364000867656e5f63616c6c6c0000000168026400046e6f646564000c77616c6c65744063616d6d796a680264000b6765745f62616c616e6365640003786d72",
(Atom("gen_call"), [(Atom("node"), Atom("wallet@cammy"))], (Atom("get_balance"), Atom("xmr")))),
("empty_map", "837400000000", {}),
("addr_map",
"8374000000026d00000007616464726573736d00000005786d722d316d0000000863757272656e6379640003786d72",
{b"address": b"xmr-1", b"currency": Atom("xmr")}),
("nested_ok",
"8368026400026f6b740000000264000762616c616e6365620012d6876400067374617475736400026f6b",
(Atom("ok"), {Atom("balance"): 1234567, Atom("status"): Atom("ok")})),
]
@ -67,6 +74,8 @@ def test_decode_golden(name, hex_in, expected):
(), (1,), (Atom("ok"), b"value"),
[], [1, 2, 3], [Atom("a"), b"b", 3],
(Atom("gen_call"), [], (Atom("ping"),)),
{}, {Atom("k"): 1}, {b"a": b"b", b"c": 42},
(Atom("ok"), {Atom("status"): Atom("ok"), Atom("count"): 7}),
])
def test_round_trip(term):
assert decode(encode(term)) == term