diff --git a/tests/invariants.mjs b/tests/invariants.mjs index abc4ab9b..6aac43b7 100644 --- a/tests/invariants.mjs +++ b/tests/invariants.mjs @@ -1,9 +1,11 @@ import assert from 'node:assert'; import { getBalances, getVaults } from './helpers.mjs'; -function assertValidBalance(balance) { +function assertValidBalance(balance, expectedMin = 1) { assert( - balance > 0 && balance <= 1_000_000_000_000_000, + Number.isInteger(balance) && + balance >= expectedMin && + balance <= 1_000_000_000_000_000, `Invariant violated: balance ${balance} is invalid`, ); } @@ -39,7 +41,7 @@ async function assertNoBalanceInvariants({ timestamp, memory }) { timestamp, }); for (const [address, balance] of Object.entries(balances)) { - assertValidBalance(balance); + assertValidBalance(balance, 0); assertValidAddress(address); } } @@ -61,3 +63,35 @@ async function assertNoBalanceVaultInvariants({ timestamp, memory }) { }); } } + +async function assertNoTotalSupplyInvariants({ timestamp, memory }) { + const supplyResult = await handle({ + Tags: [ + { + name: 'Action', + value: 'Total-Token-Supply', + }, + ], + }); + + // assert no errors + assert.deepEqual(supplyResult.Messages?.[0]?.Error, undefined); + // assert correct tag in message by finding the index of the tag in the message + const notice = supplyResult.Messages?.[0]?.Tags?.find( + (tag) => tag.name === 'Action' && tag.value === 'Total-Token-Supply-Notice', + ); + assert.ok(notice, 'should have a Total-Token-Supply-Notice tag'); + + const supplyData = JSON.parse(supplyResult.Messages?.[0]?.Data); + + assert.ok( + supplyData.total === 1000000000 * 1000000, + 'total supply should be 1 billion IO but was ' + supplyData.total, + ); + assertValidBalance(supplyData.circulating); + assertValidBalance(supplyData.locked, 0); + assertValidBalance(supplyData.staked, 0); + assertValidBalance(supplyData.delegated, 0); + assertValidBalance(supplyData.withdrawn, 0); + assertValidBalance(supplyData.protocolBalance, 0); +}