Skip to content

Commit

Permalink
test: fix cli.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Sep 16, 2023
1 parent 8ea6b3c commit b57a57e
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions yarn-project/canary/src/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {
AztecAddress,
AztecRPC,
CompleteAddress,
Fr,
computeMessageSecretHash,
createAztecRpcClient,
createDebugLogger,
makeFetch,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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+(?<address>0x[a-fA-F0-9]+)/)?.groups?.address;
expect(loggedAddress).toBeDefined();
contractAddress = AztecAddress.fromString(loggedAddress!);
Expand All @@ -136,6 +140,22 @@ describe('CLI canary', () => {
const checkResult = findInLogs(/Contract\sfound\sat\s+(?<address>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}`);
Expand All @@ -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+(?<data>\S+)/)?.groups?.data;
expect(balance!).toEqual(`${BigInt(INITIAL_BALANCE).toString()}n`);
Expand All @@ -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+(?<txHash>\S+)/)?.groups?.txHash;

Expand All @@ -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+(?<data>\S+)/)?.groups?.data;
expect(receiverBalance).toEqual(`${BigInt(TRANSFER_BALANCE).toString()}n`);
Expand Down

0 comments on commit b57a57e

Please sign in to comment.