Skip to content

Commit

Permalink
fix(protocol-parser): only append packed counter if there is dynamic …
Browse files Browse the repository at this point in the history
…data (#1097)
  • Loading branch information
alvrs authored Jul 3, 2023
1 parent b9319d1 commit 8619d15
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/protocol-parser/src/encodeRecord.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
2 changes: 2 additions & 0 deletions packages/protocol-parser/src/encodeRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/, "")
);
Expand Down

0 comments on commit 8619d15

Please sign in to comment.