diff --git a/src/transactions/decoders.ts b/src/transactions/decoders.ts index 33e799f..f5f3350 100644 --- a/src/transactions/decoders.ts +++ b/src/transactions/decoders.ts @@ -142,6 +142,21 @@ export const simplifyTransactionReceipt = (tx: GenLayerTransaction): GenLayerTra return obj.map(item => simplifyObject(item, path)).filter(item => item !== undefined); } + // Decoded calldata (`txDataDecoded.callData` / `constructorArgs`, see + // abi/calldata/decoder.ts's TYPE_MAP) is a `Map`, + // not a plain object. `Object.entries()` below only sees a plain object's + // own enumerable properties, so a Map falls through it as `{}` — the + // decoded method name and arguments are silently dropped instead of + // simplified. Convert it to a plain object first so its entries go + // through the same simplification as everything else. + if (obj instanceof Map) { + const result: any = {}; + for (const [key, value] of obj.entries()) { + result[key] = simplifyObject(value, path ? `${path}.${key}` : key); + } + return result; + } + if (typeof obj === "object") { const result: any = {}; diff --git a/tests/transactions.test.ts b/tests/transactions.test.ts index 548c57e..b803c54 100644 --- a/tests/transactions.test.ts +++ b/tests/transactions.test.ts @@ -1112,4 +1112,40 @@ describe("simplifyTransactionReceipt", () => { expect(genvm.stderr).toBe("some error"); expect(genvm.exit_code).toBe(1); }); + + it("should preserve decoded calldata Map (method + args) instead of dropping it", () => { + // Matches decodeCalldata's TYPE_MAP output: a Map, + // not a plain object. + const tx = { + txDataDecoded: { + callData: new Map([ + ["", "inspect_delivery"], + ["args", ["synthetic-reference"]], + ]), + leaderOnly: false, + type: "call", + }, + } as any; + + const simplified = simplifyTransactionReceipt(tx) as any; + + expect(simplified.txDataDecoded.callData).toEqual({ + "": "inspect_delivery", + args: ["synthetic-reference"], + }); + expect(simplified.txDataDecoded.leaderOnly).toBe(false); + }); + + it("should preserve a Map-shaped constructorArgs the same way", () => { + const tx = { + txDataDecoded: { + constructorArgs: new Map([["owner", "0xabc"]]), + type: "deploy", + }, + } as any; + + const simplified = simplifyTransactionReceipt(tx) as any; + + expect(simplified.txDataDecoded.constructorArgs).toEqual({owner: "0xabc"}); + }); });