Skip to content
Merged
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
39 changes: 39 additions & 0 deletions packages/stellar-sdk-helpers/src/keeper-tx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,50 @@ describe("keeper-tx", () => {
);
});

it("isTransientKeeperError ignores status-code digits embedded in a longer number", () => {
// A ledger sequence or amount that merely contains "503" is not a
// status code; misreading it would retry a permanent failure forever.
expect(isTransientKeeperError(new Error("ledger 15034 rejected"))).toBe(
false
);
expect(isTransientKeeperError(new Error("amount 4290000 too low"))).toBe(
false
);
});

it("isTransientKeeperError matches every retryable status code on its own", () => {
for (const code of [429, 500, 502, 503, 504]) {
expect(isTransientKeeperError(new Error(`HTTP ${code}`))).toBe(true);
}
});

it("isTransientKeeperError matches transient keywords regardless of case", () => {
expect(isTransientKeeperError(new Error("Request TIMEOUT"))).toBe(true);
expect(isTransientKeeperError(new Error("Timed Out waiting"))).toBe(true);
});

it("isDefinitiveOnChainFailure does not match a still-unknown timeout outcome", () => {
// Distinct from a confirmed failure: the client gave up waiting, but
// the transaction may still land, so it must not be treated the same
// as a confirmed on-chain failure.
expect(
isDefinitiveOnChainFailure(
new Error("Timed out waiting for transaction abc123 to confirm")
)
).toBe(false);
});

it("expectString validates strings", () => {
expect(expectString("valid", "method", "contract")).toBe("valid");
expect(() => expectString(123, "method", "contract")).toThrow(
"method() on contract did not return a string (got number)"
);
expect(() => expectString(null, "method", "contract")).toThrow(
"(got object)"
);
expect(() => expectString(undefined, "method", "contract")).toThrow(
"(got undefined)"
);
});

it("StaleAdapterError and isStaleAdapterError", () => {
Expand Down
Loading