diff --git a/src/contracts-api/action.ts b/src/contracts-api/action.ts index 2ab76df..062e51d 100644 --- a/src/contracts-api/action.ts +++ b/src/contracts-api/action.ts @@ -937,7 +937,7 @@ export class Action { * Returns the size of database */ public async getDatabaseSize(): Promise { - const result = await this.call<{ database_size: BigInt }[]>("get_database_size", {}) + const result = await this.call<{ database_size: BigInt }[]>("get_database_size_v2", {}) return result .map((rows) => { const raw = rows[0].database_size; @@ -946,6 +946,16 @@ export class Action { }).throw(); } + /** + * Returns the size of database in human-readable format (e.g., "22 GB", "1.5 TB") + */ + public async getDatabaseSizePretty(): Promise { + const result = await this.call<{ database_size_pretty: string }[]>("get_database_size_v2_pretty", {}) + return result + .map((rows) => rows[0].database_size_pretty) + .throw(); + } + /** * Gets the wallet balance on any supported blockchain network * @param chain The chain identifier (e.g., "sepolia", "mainnet", "polygon", etc.) diff --git a/tests/integration/databaseSize.test.ts b/tests/integration/databaseSize.test.ts index cf35bf9..c059adb 100644 --- a/tests/integration/databaseSize.test.ts +++ b/tests/integration/databaseSize.test.ts @@ -22,4 +22,17 @@ describe.sequential("Get Database Size", { timeout: 360000 }, () => { expect(databaseSize).toBeGreaterThan(0n) } ) + + testWithDefaultWallet( + "should get database size in human-readable format", + async ({ defaultClient }) => { + const actions = defaultClient.loadAction() + const databaseSizePretty = await actions.getDatabaseSizePretty() + + expect(databaseSizePretty).toBeTruthy() + expect(typeof databaseSizePretty).toBe("string") + // Should contain a number followed by a unit (e.g., "22 GB", "1.5 MB") + expect(databaseSizePretty).toMatch(/\d+.*\s*(bytes|kB|MB|GB|TB)/i) + } + ) }); \ No newline at end of file