From 512f1c8d5a8f79c697f1b54884acea653bf9c9b7 Mon Sep 17 00:00:00 2001 From: Illya Gerasymchuk Date: Wed, 13 Mar 2024 22:57:14 +0000 Subject: [PATCH] test: output transaction data for all accounts in table format --- .../tokens/ZKLTokenBase.integration.test.ts | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/contracts/src/tests/integration/blockchain/tokens/ZKLTokenBase.integration.test.ts b/contracts/src/tests/integration/blockchain/tokens/ZKLTokenBase.integration.test.ts index 7798fbd..191a31d 100644 --- a/contracts/src/tests/integration/blockchain/tokens/ZKLTokenBase.integration.test.ts +++ b/contracts/src/tests/integration/blockchain/tokens/ZKLTokenBase.integration.test.ts @@ -33,6 +33,17 @@ describe('ZKL Token Smart Contract', () => { zklSC = new ZKLContract(zklAppAddress); const bbbSC: BountyBulletinBoardContract = new BountyBulletinBoardContract(bbbAppAddress); + const firstFundedAddr: PublicKey = bbbSC.deriveBountyAccountAddress(interactor1PublicKey, UInt64.from(1)); + + + const publicKeyToName = { + [interactor1PublicKey.toBase58()]: { publicKey: interactor1PublicKey, name: 'Interactor 1' }, + [interactor2PublicKey.toBase58()]: { publicKey: interactor2PublicKey, name: 'Interactor 2' }, + [deployerPublicKey.toBase58()]: { publicKey: deployerPublicKey, name: 'Deployer' }, + [zklAppAddress.toBase58()]: { publicKey: zklAppAddress, name: 'ZKL App' }, + [bbbAppAddress.toBase58()]: { publicKey: bbbAppAddress, name: 'BBB App' }, + [firstFundedAddr.toBase58()]: { publicKey: firstFundedAddr, name: 'First Funded Public Key' }, +}; beforeAll(async () => { console.log("Compiling circuits..."); @@ -78,6 +89,38 @@ describe('ZKL Token Smart Contract', () => { console.log("$BBB smart contract deployed!"); }); +type PublicKeyWithName = { + publicKey: PublicKey; + name: string; +}; + +async function printBalances(publicKeyToName: Record, label: string) { + const balances = []; + + for (const { publicKey, name } of Object.values(publicKeyToName)) { + const balance: Record = { 'Address': publicKey.toBase58()}; + balance['Account Name'] = name; + + try { + const zklBalance = Mina.getBalance(publicKey, zklSC.token.id).value.toBigInt(); + balance['$ZKL'] = zklBalance.toString(); + } catch (error) { + balance['$ZKL'] = '-'; + } + + try { + const bbbBalance = Mina.getBalance(publicKey, bbbSC.deriveTokenId()).value.toBigInt(); + balance['$BBB'] = bbbBalance.toString(); + } catch (error) { + balance['$BBB'] = '-'; + } + + balances.push(balance); + } + + console.log(label); + console.table(balances); +} describe('Initial state checks', () => { it('Initial supply is zero', async () => { @@ -225,6 +268,8 @@ describe('ZKL Token Smart Contract', () => { const mintAmount: UInt64 = UInt64.from(100000); + await printBalances(publicKeyToName, "Initial state"); + const mintTxn: Mina.Transaction = await Mina.transaction( interactor1PublicKey, () => { AccountUpdate.fundNewAccount(interactor1PublicKey); @@ -237,6 +282,8 @@ describe('ZKL Token Smart Contract', () => { console.log(`Mint of ${mintAmount} of $ZKL proved!`); + await printBalances(publicKeyToName, "After $ZKL Mint"); + // At this point, the feePayerPublicKey should `mintAmount` of $ZKL // Now, let's mint $BBB_ZKL from $ZKL @@ -254,6 +301,8 @@ describe('ZKL Token Smart Contract', () => { await mintFromZKLtxn.sign([interactor1PrivateKey]).send(); + await printBalances(publicKeyToName, "After $BBB Mint from $ZKL"); + console.log("\tMint transaction proved!"); console.log(`Funding bounty with $BBB from ${interactor1PublicKey.toBase58()}...`); @@ -285,6 +334,9 @@ describe('ZKL Token Smart Contract', () => { console.log(`Claiming bounty by ${interactor2PublicKey.toBase58()}...`); + + await printBalances(publicKeyToName, "After Fund Bounty"); + const claimBountyTxn: Mina.Transaction = await Mina.transaction( interactor2PublicKey, () => { AccountUpdate.fundNewAccount(interactor2PublicKey, 1);