Skip to content
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
17 changes: 9 additions & 8 deletions src/api/info/_methods/borrowLendUserState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,18 @@ export type BorrowLendUserStateResponse = {
},
][];
/**
* Account health status.
*
* FIXME: other literals may exist (unconfirmed).
* Account health status:
* - `"healthy"`: Collateral covers the debt.
* - `"atRisk"`: Health factor approached the liquidation threshold.
* - `"marketLiquidatable"`: Debt is being liquidated through the order book.
* - `"backstopLiquidatable"`: Debt is taken over by the liquidator vault.
*/
health: "healthy";
health: "healthy" | "atRisk" | "marketLiquidatable" | "backstopLiquidatable";
/**
* Health factor.
*
* FIXME: non-null value not found (unconfirmed).
* Health factor; `null` when the account has no borrow position.
* @pattern ^[0-9]+(\.[0-9]+)?$
*/
healthFactor: null;
healthFactor: string | null;
};

// ============================================================
Expand Down
12 changes: 7 additions & 5 deletions tests/api/info/_t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const OFFLINE = Deno.args.includes("--offline");
// Preparation
// ============================================================

const transport = new HttpTransport({ isTestnet: true, timeout: 30_000 });
const client = new InfoClient({ transport });
const testnetClient = new InfoClient({ transport: new HttpTransport({ isTestnet: true, timeout: 30_000 }) });
const mainnetClient = new InfoClient({ transport: new HttpTransport({ timeout: 30_000 }) });

// ============================================================
// Test
Expand All @@ -24,18 +24,20 @@ const client = new InfoClient({ transport });
* @param options Test options including name and test function
* @param options.name Name of the test
* @param options.ignore Whether to skip the test
* @param options.isTestnet Uses the testnet API when true; defaults to `true`
* @param options.codeTestFn Async function containing the test code, receives Deno.TestContext and shared InfoClient
*/
export function runTest(options: {
name: string;
ignore?: boolean;
codeTestFn: (t: Deno.TestContext, client_: typeof client) => Promise<void>;
isTestnet?: boolean;
codeTestFn: (t: Deno.TestContext, client_: typeof testnetClient) => Promise<void>;
}): void {
const { name, ignore, codeTestFn } = options;
const { name, ignore, isTestnet = true, codeTestFn } = options;

Deno.test(name, { ignore: OFFLINE || ignore }, async (t) => {
await new Promise((r) => setTimeout(r, WAIT)); // delay to avoid rate limits

await codeTestFn(t, client);
await codeTestFn(t, isTestnet ? testnetClient : mainnetClient);
});
}
10 changes: 8 additions & 2 deletions tests/api/info/borrowLendUserState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ const paramsSchema = valibotToJsonSchema(v.omit(BorrowLendUserStateRequest, ["ty

runTest({
name: "borrowLendUserState",
isTestnet: false,
codeTestFn: async (_t, client) => {
const params: BorrowLendUserStateParameters[] = [
{ user: "0xcb3f0bd249a89e45e86a44bcfc7113e4ffe84cd1" },
{ user: "0x0000000000000000000000000000000000000001" }, // healthFactor: null
{ user: "0xf02d16a272a842f8bac1d9a9e773aba1933454c6" }, // "healthy"
{ user: "0xe639710e64d7094f7f82ab495915559c2f612953" }, // "atRisk"
];

const data = await Promise.all(params.map((p) => client.borrowLendUserState(p)));

schemaCoverage(paramsSchema, params);
schemaCoverage(responseSchema, data);
schemaCoverage(responseSchema, data, [
"#/properties/health/enum/2", // "marketLiquidatable"
"#/properties/health/enum/3", // "backstopLiquidatable"
]);
},
});