Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BOOST-5221] feat(sdk): update tuple support helpers to add terminators #371

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/breezy-jokes-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@boostxyz/sdk": patch
---

[BOOST-5221] feat(sdk): update tuple support helpers to add terminators
9 changes: 9 additions & 0 deletions packages/sdk/src/Actions/EventAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,15 @@ describe("Tuple & bitpacked fieldIndex support", () => {
expect(result).toEqual(resultIndexes);
});

test("packs 3 indexes with the automatic addition of a terminator and unpacks them correctly", () => {
const indexes = [0, 3, 5]; // sample indexes
const packed = packFieldIndexes(indexes);
const result = unpackFieldIndexes(packed);
const resultIndexes = [0, 3, 5]; // should terminate on it's own even if a terminator isn't passed in

expect(result).toEqual(resultIndexes);
});

test("throws if more than five indexes are provided", () => {
expect(() => packFieldIndexes([1, 2, 3, 4, 5, 6])).toThrowError(
"Can only pack up to 5 indexes.",
Expand Down
3 changes: 3 additions & 0 deletions packages/sdk/src/Actions/EventAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,9 @@ export function packFieldIndexes(indexes: number[]): number {
}
packed |= (index & MAX_FIELD_INDEX) << (i * 6); // Each index occupies 6 bits
});
if (indexes.length < 5) {
packed |= MAX_FIELD_INDEX << (indexes.length * 6); // Terminator
}

return packed;
}
Expand Down
Loading