Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Sep 25, 2023
1 parent 5c53f9a commit 4cccc05
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
7 changes: 5 additions & 2 deletions yarn-project/aztec-rpc/src/synchronizer/synchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,18 @@ export class Synchronizer {
* @returns True if the account is fully synched, false otherwise.
* @remarks Checks whether all the notes from all the blocks have been processed. If it is not the case, the
* retrieved information from contracts might be old/stale (e.g. old token balance).
* @throws If checking a sync status of account which is not registered.
*/
public async isAccountStateSynchronized(account: AztecAddress) {
const completeAddress = await this.db.getCompleteAddress(account);
if (!completeAddress) {
return false;
throw new Error(`Checking if account is synched is not possible for ${account} because it is not registered.`);
}
const processor = this.noteProcessors.find(x => x.publicKey.equals(completeAddress.publicKey));
if (!processor) {
return false;
throw new Error(
`Checking if account is synched is not possible for ${account} because it is only registered as a recipient.`,
);
}
return await processor.isSynchronized();
}
Expand Down
19 changes: 10 additions & 9 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 @@ -72,9 +72,12 @@ describe('e2e_2_rpc_servers', () => {
tokenAddress: AztecAddress,
owner: AztecAddress,
expectedBalance: bigint,
checkIfSynchronized = true,
) => {
// First wait until the corresponding RPC server has synchronized the account
await awaitUserSynchronized(wallet, owner);
if (checkIfSynchronized) {
// First wait until the corresponding RPC server has synchronized the account
await awaitUserSynchronized(wallet, owner);
}

// Then check the balance
const contractWithWallet = await TokenContract.at(tokenAddress, wallet);
Expand Down Expand Up @@ -203,7 +206,7 @@ describe('e2e_2_rpc_servers', () => {
expect(storedValue).toBe(newValueToSet);
});

it.only('private state is "zero" when Aztec RPC Server does not have the account private key', async () => {
it('private state is "zero" when Aztec RPC Server does not have the account private key', async () => {
const userABalance = 100n;
const userBBalance = 150n;

Expand All @@ -227,19 +230,17 @@ describe('e2e_2_rpc_servers', () => {
// Mint tokens to user B
await mintTokens(contractWithWalletA, userB.address, userBBalance);

// Ensure that both servers are synchronized
await awaitServerSynchronized(aztecRpcServerA);
await awaitServerSynchronized(aztecRpcServerB);

// Check that user A balance is 100 on server A
await expectTokenBalance(walletA, completeTokenAddress.address, userA.address, userABalance);
// Check that user B balance is 150 on server B
await expectTokenBalance(walletB, completeTokenAddress.address, userB.address, userBBalance);

// CHECK THAT PRIVATE BALANCES ARE 0 WHEN ACCOUNT'S PRIVATE KEYS ARE NOT REGISTERED
// Note: Not checking if the account is synchronized because it is not registered as an account (it would throw).
const checkIfSynchronized = false;
// Check that user A balance is 0 on server B
await expectTokenBalance(walletB, completeTokenAddress.address, userA.address, 0n);
await expectTokenBalance(walletB, completeTokenAddress.address, userA.address, 0n, checkIfSynchronized);
// Check that user B balance is 0 on server A
await expectTokenBalance(walletA, completeTokenAddress.address, userB.address, 0n);
await expectTokenBalance(walletA, completeTokenAddress.address, userB.address, 0n, checkIfSynchronized);
});
});
1 change: 1 addition & 0 deletions yarn-project/types/src/interfaces/aztec_rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ export interface AztecRPC {
* @deprecated Use `getSyncStatus` instead.
* @remarks Checks whether all the notes from all the blocks have been processed. If it is not the case, the
* retrieved information from contracts might be old/stale (e.g. old token balance).
* @throws If checking a sync status of account which is not registered.
*/
isAccountStateSynchronized(account: AztecAddress): Promise<boolean>;

Expand Down

0 comments on commit 4cccc05

Please sign in to comment.