Skip to content

Commit

Permalink
refactor: expectUnencryptedLogsFromLastBlockToBe using AztecRPC
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Aug 23, 2023
1 parent ca19401 commit 523d352
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 22 deletions.
6 changes: 3 additions & 3 deletions yarn-project/end-to-end/src/e2e_2_rpc_servers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('e2e_2_rpc_servers', () => {
await expectTokenBalance(walletA, tokenAddress, userA.address, initialBalance);
await expectTokenBalance(walletB, tokenAddress, userB.address, 0n);
await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1);
await expectUnencryptedLogsFromLastBlockToBe(aztecNode!, ['Balance set in constructor']);
await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServerA, ['Balance set in constructor']);

// Transfer funds from A to B via RPC server A
const contractWithWalletA = await PrivateTokenContract.at(tokenAddress, walletA);
Expand All @@ -130,7 +130,7 @@ describe('e2e_2_rpc_servers', () => {
await expectTokenBalance(walletA, tokenAddress, userA.address, initialBalance - transferAmount1);
await expectTokenBalance(walletB, tokenAddress, userB.address, transferAmount1);
await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 2);
await expectUnencryptedLogsFromLastBlockToBe(aztecNode!, ['Coins transferred']);
await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServerA, ['Coins transferred']);

// Transfer funds from B to A via RPC server B
const contractWithWalletB = await PrivateTokenContract.at(tokenAddress, walletB);
Expand All @@ -147,7 +147,7 @@ describe('e2e_2_rpc_servers', () => {
await expectTokenBalance(walletA, tokenAddress, userA.address, initialBalance - transferAmount1 + transferAmount2);
await expectTokenBalance(walletB, tokenAddress, userB.address, transferAmount1 - transferAmount2);
await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 2);
await expectUnencryptedLogsFromLastBlockToBe(aztecNode!, ['Coins transferred']);
await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServerA, ['Coins transferred']);
}, 120_000);

const deployChildContractViaServerA = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('e2e_multiple_accounts_1_enc_key', () => {
}

await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 2);
await expectUnencryptedLogsFromLastBlockToBe(aztecNode!, ['Coins transferred']);
await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServer, ['Coins transferred']);

logger(`Transfer ${transferAmount} from ${sender} to ${receiver} successful`);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('e2e_private_token_contract', () => {
await expectBalance(receiver, 0n);

await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1);
await expectUnencryptedLogsFromLastBlockToBe(aztecNode!, ['Balance set in constructor']);
await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServer, ['Balance set in constructor']);
}, 30_000);

/**
Expand All @@ -81,7 +81,7 @@ describe('e2e_private_token_contract', () => {
await expectBalance(owner, mintAmount);

await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1);
await expectUnencryptedLogsFromLastBlockToBe(aztecNode!, ['Coins minted']);
await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServer, ['Coins minted']);
}, 60_000);

/**
Expand All @@ -97,7 +97,7 @@ describe('e2e_private_token_contract', () => {
await expectBalance(receiver, 0n);

await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1);
await expectUnencryptedLogsFromLastBlockToBe(aztecNode!, ['Balance set in constructor']);
await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServer, ['Balance set in constructor']);

const tx = contract.methods.transfer(transferAmount, owner, receiver).send({ origin: owner });

Expand All @@ -110,6 +110,6 @@ describe('e2e_private_token_contract', () => {
await expectBalance(receiver, transferAmount);

await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 2);
await expectUnencryptedLogsFromLastBlockToBe(aztecNode!, ['Coins transferred']);
await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServer, ['Coins transferred']);
}, 60_000);
});
18 changes: 4 additions & 14 deletions yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,23 +426,13 @@ export const expectsNumOfEncryptedLogsInTheLastBlockToBe = async (

/**
* Checks that the last block contains the given expected unencrypted log messages.
* @param aztecNode - The instance of aztec node for retrieving the logs.
* @param rpc - The instance of AztecRPC for retrieving the logs.
* @param logMessages - The set of expected log messages.
* @returns
*/
export const expectUnencryptedLogsFromLastBlockToBe = async (
aztecNode: AztecNodeService | AztecRPC,
logMessages: string[],
) => {
let l2BlockNum: number;
let unencryptedLogs: L2BlockL2Logs[];
if (aztecNode instanceof AztecNodeService) {
l2BlockNum = await aztecNode.getBlockHeight();
unencryptedLogs = await aztecNode.getLogs(l2BlockNum, 1, LogType.UNENCRYPTED);
} else {
l2BlockNum = await aztecNode.getBlockNum();
unencryptedLogs = await aztecNode.getUnencryptedLogs(l2BlockNum, 1);
}
export const expectUnencryptedLogsFromLastBlockToBe = async (rpc: AztecRPC, logMessages: string[]) => {
const l2BlockNum = await rpc.getBlockNum();
const unencryptedLogs = await rpc.getUnencryptedLogs(l2BlockNum, 1);
const unrolledLogs = L2BlockL2Logs.unrollLogs(unencryptedLogs);
const asciiLogs = unrolledLogs.map(log => log.toString('ascii'));

Expand Down

0 comments on commit 523d352

Please sign in to comment.