Skip to content
Closed
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
19 changes: 19 additions & 0 deletions test/memoBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ describe("buildPaymentMemo", () => {
expect(Buffer.from(result, "utf8").toString("utf8")).toBe(result);
});

it("does not split 4-byte emoji code points on truncation", () => {
// "split:" = 6 bytes. 28 - 6 = 22 bytes remaining.
// Each 🚀 is 4 bytes. 22 // 4 = 5 rockets = 20 bytes (total 26 bytes).
const rocketId = "🚀".repeat(7); // 7 * 4 = 28 bytes (+ 6 = 34 bytes)
const result = buildPaymentMemo(rocketId);
expect(Buffer.byteLength(result, "utf8")).toBeLessThanOrEqual(28);
expect(result).toBe("split:" + "🚀".repeat(5));
expect(Buffer.from(result, "utf8").toString("utf8")).toBe(result);
});

it("handles tranche index 0 correctly", () => {
const result = buildPaymentMemo("inv-001", { tranche: 0 });
expect(result).toBe("split:inv-001:t0");
expect(parsePaymentMemo(result)).toEqual({
invoiceId: "inv-001",
tranche: 0,
});
});

it("tranche suffix is included when it fits within 28 bytes", () => {
const result = buildPaymentMemo("short", { tranche: 5 });
expect(result).toBe("split:short:t5");
Expand Down