Skip to content

Commit

Permalink
Add more tests for storage_usage, account_balance,
Browse files Browse the repository at this point in the history
account_locked_balance
  • Loading branch information
vgrichina committed Oct 18, 2024
1 parent 0c1721d commit 23d3908
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/runtime.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,43 @@ test('storage_usage returns 0 when not set', async t => {
t.equal(Number(result), 0);
});

test('storage_usage returns non-zero value', async t => {
const ctx = createContext({
storageUsage: new Uint8Array([0xf1, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef])
});
const importFunctions = imports(ctx);

const result = importFunctions.storage_usage();

t.equal(result, 0xefcdab89674523f1n);
});

test('account_balance returns non-zero value', async t => {
const ctx = createContext({
accountBalance: new Uint8Array([0xf1, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe])
});
const importFunctions = imports(ctx);

importFunctions.account_balance(0);

const [low, high] = new BigUint64Array(ctx.memory.buffer, 0, 2);
t.equal(low, 0xefcdab89674523f1n);
t.equal(high, 0xfedcba9876543210n);
});

test('account_locked_balance returns non-zero value', async t => {
const ctx = createContext({
accountLockedBalance: new Uint8Array([0xf1, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe])
});
const importFunctions = imports(ctx);

importFunctions.account_locked_balance(0);

const [low, high] = new BigUint64Array(ctx.memory.buffer, 0, 2);
t.equal(low, 0xefcdab89674523f1n);
t.equal(high, 0xfedcba9876543210n);
});

test('log_utf16 adds log message', async t => {
const ctx = createContext();
const importFunctions = imports(ctx);
Expand Down

0 comments on commit 23d3908

Please sign in to comment.