Skip to content

Commit

Permalink
fix(tests): add test for total supply
Browse files Browse the repository at this point in the history
  • Loading branch information
atticusofsparta committed Nov 11, 2024
1 parent d4d42a6 commit 49fe59a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"aos:publish": "node tools/bundle-aos.mjs && node tools/publish-aos.mjs",
"aos:load": "node tools/bundle-aos.mjs && node tools/load-aos.mjs",
"aos:spawn": "node tools/spawn-aos.mjs",
"test": "yarn aos:build && node --test --test-concurrency 1 --experimental-wasm-memory64 **/*.test.mjs",
"integration-coverage": "node tools/analyze-handler-coverage.mjs --luaEntryFile src/common/main.lua --testFilePattern test/**/*.test.mjs --ignoredHandlers ['Evolve']",
"test": "yarn aos:build && node --test --test-concurrency 1 --experimental-wasm-memory64 **/*.test.mjs && yarn integration-coverage",
"integration-coverage": "node tools/analyze-handler-coverage.mjs --luaEntryFile src/common/main.lua --testFilePattern test/**/*.test.mjs",
"prepare": "husky"
},
"devDependencies": {
Expand Down
7 changes: 4 additions & 3 deletions src/common/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ function ant.init()
Balance = "Balance",
Transfer = "Transfer",
TotalSupply = "Total-Supply",
CreditNotice = "Credit-Notice",

-- not implemented
Mint = "Mint",
Burn = "Burn",
-- CreditNotice = "Credit-Notice",
-- Mint = "Mint",
-- Burn = "Burn",
}

Handlers.add(
Expand Down
16 changes: 16 additions & 0 deletions test/balances.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ describe('aos Balances', async () => {
);
}

async function getTotalSupply(mem) {
return handle(
{
Tags: [{ name: 'Action', value: 'Total-Supply' }],
},
mem,
);
}

it('should fetch the owner balance', async () => {
const result = await handle({
Tags: [
Expand Down Expand Up @@ -99,4 +108,11 @@ describe('aos Balances', async () => {
),
);
});
it('should get total supply', async () => {
const res = await getTotalSupply();

const totalSupply = res.Messages[0];
assert(totalSupply, 'failed to get total supply');
assert(totalSupply.Data == 1, 'total supply should be equal to 1');
});
});
2 changes: 1 addition & 1 deletion tools/analyze-handler-coverage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function generateCoverageReport(luaHandlers, testedHandlers) {
((luaHandlers.length - untestedHandlers.length) / luaHandlers.length) * 100;
const reportLines = [];

reportLines.push(chalk.bold('\nCoverage Report'));
reportLines.push(chalk.bold('\nHandlers Coverage Report'));
reportLines.push(`Total Handlers: ${chalk.cyan(luaHandlers.length)}`);
reportLines.push(
`Tested Handlers: ${chalk.green(luaHandlers.length - untestedHandlers.length)}`,
Expand Down

0 comments on commit 49fe59a

Please sign in to comment.