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
12 changes: 11 additions & 1 deletion src/contracts-api/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ export class Action {
* Returns the size of database
*/
public async getDatabaseSize(): Promise<BigInt> {
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;
Expand All @@ -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<string> {
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.)
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/databaseSize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
)
});
Loading