From 8619d1503c31aca32474d618a8a0eda650cb9d16 Mon Sep 17 00:00:00 2001 From: alvarius <89248902+alvrs@users.noreply.github.com> Date: Mon, 3 Jul 2023 20:28:37 +0100 Subject: [PATCH] fix(protocol-parser): only append packed counter if there is dynamic data (#1097) --- packages/protocol-parser/src/encodeRecord.test.ts | 6 ++++++ packages/protocol-parser/src/encodeRecord.ts | 2 ++ 2 files changed, 8 insertions(+) diff --git a/packages/protocol-parser/src/encodeRecord.test.ts b/packages/protocol-parser/src/encodeRecord.test.ts index 395cbeaa6a..e85bec0b39 100644 --- a/packages/protocol-parser/src/encodeRecord.test.ts +++ b/packages/protocol-parser/src/encodeRecord.test.ts @@ -9,4 +9,10 @@ describe("encodeRecord", () => { "0x0000000100000000000000000000000000000002000000000000130000000008000000000b0000000000000000000000000000000000000300000004736f6d6520737472696e67" ); }); + + it("should not include the packed dynamic lengths if there are no dynamic fields", () => { + const schema = { staticFields: ["uint32", "uint128"], dynamicFields: [] } as const; + const hex = encodeRecord(schema, [1, 2n]); + expect(hex).toBe("0x0000000100000000000000000000000000000002"); + }); }); diff --git a/packages/protocol-parser/src/encodeRecord.ts b/packages/protocol-parser/src/encodeRecord.ts index 14c3f19a07..23a1c16fea 100644 --- a/packages/protocol-parser/src/encodeRecord.ts +++ b/packages/protocol-parser/src/encodeRecord.ts @@ -11,6 +11,8 @@ export function encodeRecord(schema: Schema, values: readonly (StaticPrimitiveTy .map((value, i) => encodeField(schema.staticFields[i], value).replace(/^0x/, "")) .join(""); + if (schema.dynamicFields.length === 0) return `0x${staticData}`; + const dynamicDataItems = dynamicValues.map((value, i) => encodeField(schema.dynamicFields[i], value).replace(/^0x/, "") );