Skip to content

Commit

Permalink
test: output transaction data for all accounts in table format
Browse files Browse the repository at this point in the history
  • Loading branch information
iluxonchik committed Mar 13, 2024
1 parent dc489bd commit 512f1c8
Showing 1 changed file with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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...");
Expand Down Expand Up @@ -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<string, PublicKeyWithName>, label: string) {
const balances = [];

for (const { publicKey, name } of Object.values(publicKeyToName)) {
const balance: Record<string, string> = { '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 () => {
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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()}...`);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 512f1c8

Please sign in to comment.