From b57a57ef363ac638c82be9e21685a34cf7c45bba Mon Sep 17 00:00:00 2001 From: LHerskind Date: Sat, 16 Sep 2023 16:30:54 +0000 Subject: [PATCH] test: fix cli.test.ts --- yarn-project/canary/src/cli.test.ts | 32 ++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/yarn-project/canary/src/cli.test.ts b/yarn-project/canary/src/cli.test.ts index e5d73e2a51d9..27cb1454e2f5 100644 --- a/yarn-project/canary/src/cli.test.ts +++ b/yarn-project/canary/src/cli.test.ts @@ -2,6 +2,8 @@ import { AztecAddress, AztecRPC, CompleteAddress, + Fr, + computeMessageSecretHash, createAztecRpcClient, createDebugLogger, makeFetch, @@ -59,7 +61,9 @@ describe('CLI canary', () => { if (addRpcUrl) { args.push('--rpc-url', SANDBOX_URL); } - return cli.parseAsync(args); + const res = cli.parseAsync(args); + resetCli(); + return res; }; // Returns first match across all logs collected so far @@ -123,7 +127,7 @@ describe('CLI canary', () => { const ownerAddress = AztecAddress.fromString(foundAddress!); debug('Deploy Private Token Contract using created account.'); - await run(`deploy PrivateTokenContractAbi --args ${INITIAL_BALANCE} ${ownerAddress} --salt 0`); + await run(`deploy TokenContractAbi --args ${INITIAL_BALANCE} ${ownerAddress} --salt 0`); const loggedAddress = findInLogs(/Contract\sdeployed\sat\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; expect(loggedAddress).toBeDefined(); contractAddress = AztecAddress.fromString(loggedAddress!); @@ -136,6 +140,22 @@ describe('CLI canary', () => { const checkResult = findInLogs(/Contract\sfound\sat\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; expect(checkResult).toEqual(deployedContract?.contractAddress.toString()); + debug('Initialize token contract.'); + await run( + `send _initialize --args ${ownerAddress} --contract-abi TokenContractAbi --contract-address ${contractAddress.toString()} --private-key ${privKey}`, + ); + + const secret = Fr.random(); + const secretHash = await computeMessageSecretHash(secret); + + debug('Mint initial tokens.'); + await run( + `send mint_private --args ${INITIAL_BALANCE} ${secretHash} --contract-abi TokenContractAbi --contract-address ${contractAddress.toString()} --private-key ${privKey}`, + ); + await run( + `send redeem_shield --args ${ownerAddress} ${INITIAL_BALANCE} ${secret} --contract-abi TokenContractAbi --contract-address ${contractAddress.toString()} --private-key ${privKey}`, + ); + // clear logs clearLogs(); await run(`get-contract-data ${loggedAddress}`); @@ -144,7 +164,7 @@ describe('CLI canary', () => { debug("Check owner's balance"); await run( - `call getBalance --args ${ownerAddress} --contract-abi PrivateTokenContractAbi --contract-address ${contractAddress.toString()}`, + `call balance_of_private --args ${ownerAddress} --contract-abi TokenContractAbi --contract-address ${contractAddress.toString()}`, ); const balance = findInLogs(/View\sresult:\s+(?\S+)/)?.groups?.data; expect(balance!).toEqual(`${BigInt(INITIAL_BALANCE).toString()}n`); @@ -155,7 +175,7 @@ describe('CLI canary', () => { const receiver = existingAccounts.find(acc => acc.address.toString() !== ownerAddress.toString()); await run( - `send transfer --args ${TRANSFER_BALANCE} ${receiver?.address.toString()} --contract-address ${contractAddress.toString()} --contract-abi PrivateTokenContractAbi --private-key ${privKey}`, + `send transfer --args ${ownerAddress.toString()} ${receiver?.address.toString()} ${TRANSFER_BALANCE} 0 --contract-address ${contractAddress.toString()} --contract-abi TokenContractAbi --private-key ${privKey}`, ); const txHash = findInLogs(/Transaction\shash:\s+(?\S+)/)?.groups?.txHash; @@ -166,11 +186,9 @@ describe('CLI canary', () => { expect(parsedResult.txHash).toEqual(txHash); expect(parsedResult.status).toEqual('mined'); debug("Check Receiver's balance"); - // Reset CLI as we're calling getBalance again - resetCli(); clearLogs(); await run( - `call getBalance --args ${receiver?.address.toString()} --contract-abi PrivateTokenContractAbi --contract-address ${contractAddress.toString()}`, + `call balance_of_private --args ${receiver?.address.toString()} --contract-abi TokenContractAbi --contract-address ${contractAddress.toString()}`, ); const receiverBalance = findInLogs(/View\sresult:\s+(?\S+)/)?.groups?.data; expect(receiverBalance).toEqual(`${BigInt(TRANSFER_BALANCE).toString()}n`);