Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Aug 5, 2024
1 parent f83fb3e commit 98738ea
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions yarn-project/end-to-end/src/e2e_authwit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('e2e_authwit_tests', () => {
isValidInPublic: false,
});

// We give wallets[0] access to wallets[1]'s notes.
wallets[0].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]);

// Check that the authwit is NOT valid in private for wallets[1]
Expand All @@ -68,6 +69,7 @@ describe('e2e_authwit_tests', () => {
isValidInPublic: false,
});

// We give wallets[1] access to wallets[0]'s notes.
wallets[1].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]);

// Consume the inner hash using the wallets[0] as the "on behalf of".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ describe('e2e_blacklist_token_contract burn', () => {
const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action });
await wallets[1].addAuthWitness(witness);

// We give wallets[1] access to wallets[0]'s notes to be able to burn the notes.
wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]);

await asset.withWallet(wallets[1]).methods.burn(wallets[0].getAddress(), amount, nonce).send().wait();
Expand Down Expand Up @@ -200,6 +201,7 @@ describe('e2e_blacklist_token_contract burn', () => {
{ chainId: wallets[0].getChainId(), version: wallets[0].getVersion() },
);

// We give wallets[1] access to wallets[0]'s notes to test the authwit.
wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]);

await expect(action.prove()).rejects.toThrow(`Unknown auth witness for message hash ${messageHash.toString()}`);
Expand All @@ -221,6 +223,7 @@ describe('e2e_blacklist_token_contract burn', () => {
const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action });
await wallets[2].addAuthWitness(witness);

// We give wallets[2] access to wallets[0]'s notes to test the authwit.
wallets[2].setScopes([wallets[2].getAddress(), wallets[0].getAddress()]);

await expect(action.prove()).rejects.toThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('e2e_blacklist_token_contract transfer private', () => {
await asset.methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, 0).send().wait();
tokenSim.transferPrivate(wallets[0].getAddress(), wallets[1].getAddress(), amount);

// We give wallets[0] access to wallets[1]'s notes to be able to check balances after the test.
wallets[0].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]);
});

Expand Down Expand Up @@ -64,6 +65,7 @@ describe('e2e_blacklist_token_contract transfer private', () => {
// docs:end:add_authwit
// docs:end:authwit_transfer_example

// We give wallets[1] access to wallets[0]'s notes to be able to transfer the notes.
wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]);

// Perform the transfer
Expand All @@ -77,6 +79,7 @@ describe('e2e_blacklist_token_contract transfer private', () => {
.send();
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);

// We give wallets[0] access to wallets[1]'s notes to be able to check balances after the test.
wallets[0].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]);
});

Expand Down Expand Up @@ -167,6 +170,7 @@ describe('e2e_blacklist_token_contract transfer private', () => {
const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action });
await wallets[2].addAuthWitness(witness);

// We give wallets[2] access to wallets[0]'s notes to test the authwit.
wallets[2].setScopes([wallets[2].getAddress(), wallets[0].getAddress()]);

await expect(action.prove()).rejects.toThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe('e2e_blacklist_token_contract unshielding', () => {
const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action });
await wallets[1].addAuthWitness(witness);

// We give wallets[1] access to wallets[0]'s notes to unshield the note.
wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]);

await action.send().wait();
Expand Down Expand Up @@ -124,6 +125,7 @@ describe('e2e_blacklist_token_contract unshielding', () => {
const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action });
await wallets[2].addAuthWitness(witness);

// We give wallets[2] access to wallets[0]'s notes to test the authwit.
wallets[2].setScopes([wallets[2].getAddress(), wallets[0].getAddress()]);

await expect(action.prove()).rejects.toThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,15 @@ describe('e2e_crowdfunding_and_claim', () => {
);
expect(notes!.length).toEqual(1);

donorWallets[0].setScopes([donorWallets[0].getAddress(), crowdfundingContract.address]);

// Set the value note in a format which can be passed to claim function
valueNote = await processExtendedNote(notes![0]);
}

// 3) We claim the reward token via the Claim contract
{
// We allow the donor wallet to use the crowdfunding contract's notes
donorWallets[0].setScopes([donorWallets[0].getAddress(), crowdfundingContract.address]);

await claimContract
.withWallet(donorWallets[0])
.methods.claim(valueNote, donorWallets[0].getAddress())
Expand All @@ -256,6 +257,7 @@ describe('e2e_crowdfunding_and_claim', () => {
.simulate();
expect(balanceDNTBeforeWithdrawal).toEqual(0n);

// We allow the operator wallet to use the crowdfunding contract's notes
operatorWallet.setScopes([operatorWallet.getAddress(), crowdfundingContract.address]);
// 4) At last, we withdraw the raised funds from the crowdfunding contract to the operator's address
await crowdfundingContract.methods.withdraw(donationAmount).send().wait();
Expand Down Expand Up @@ -403,6 +405,7 @@ describe('e2e_crowdfunding_and_claim', () => {
// This does not protect fully against impersonation as the contract could just call context.end_setup() and the below would pass.
// => the private_init msg_sender assertion is required (#7190, #7404)

// We allow the donor wallet to use the crowdfunding contract's notes
donorWallets[1].setScopes([donorWallets[1].getAddress(), crowdfundingContract.address]);

await expect(donorWallets[1].simulateTx(request, true, operatorWallet.getAddress())).rejects.toThrow(
Expand Down
1 change: 1 addition & 0 deletions yarn-project/end-to-end/src/e2e_escrow_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe('e2e_escrow_contract', () => {

await token.methods.redeem_shield(escrowContract.address, mintAmount, secret).send().wait();

// We allow our wallet to see the escrow contract's notes.
wallet.setScopes([wallet.getAddress(), escrowContract.address]);

logger.info(`Token contract deployed at ${token.address}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ describe('e2e_fees dapp_subscription', () => {
new PrivateFeePaymentMethod(bananaCoin.address, bananaFPC.address, aliceWallet),
);

// We let Alice see Bob's notes because the expect uses Alice's wallet to interact with the contracts to "get" state.
aliceWallet.setScopes([aliceAddress, bobAddress]);

await expectMapping(
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/end-to-end/src/e2e_fees/gas_estimation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ describe('e2e_fees gas_estimation', () => {
({ aliceWallet, aliceAddress, bobAddress, bananaCoin, bananaFPC, gasSettings, logger } = await t.setup());

teardownFixedFee = gasSettings.teardownGasLimits.computeFee(GasFees.default()).toBigInt();

// We let Alice see Bob's notes because the expect uses Alice's wallet to interact with the contracts to "get" state.
aliceWallet.setScopes([aliceAddress, bobAddress]);
});

Expand Down
2 changes: 2 additions & 0 deletions yarn-project/end-to-end/src/e2e_fees/native_payments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ describe('e2e_fees native_payments', () => {
({ gasTokenContract, aliceAddress, aliceWallet, bobAddress, bananaCoin, gasSettings } = await t.setup());

paymentMethod = new NativeFeePaymentMethod(aliceAddress);

// We let Alice see Bob's notes because the expect uses Alice's wallet to interact with the contracts to "get" state.
aliceWallet.setScopes([aliceAddress, bobAddress]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ describe('e2e_fees private_payment', () => {
t.getGasBalanceFn(aliceAddress, bananaFPC.address, sequencerAddress),
]);

// We let Alice see Bob's notes because the expect uses Alice's wallet to interact with the contracts to "get" state.
aliceWallet.setScopes([aliceAddress, bobAddress]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('e2e_fees/private_refunds', () => {
({ aliceWallet, aliceAddress, bobAddress, privateFPC, tokenWithRefunds } = await t.setup());
t.logger.debug(`Alice address: ${aliceAddress}`);

// We give Alice access to Bob's notes because Alice is used to check if balances are correct.
aliceWallet.setScopes([aliceAddress, bobAddress]);
});

Expand Down
3 changes: 3 additions & 0 deletions yarn-project/end-to-end/src/e2e_token_contract/burn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ describe('e2e_token_contract burn', () => {
const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action });
await wallets[1].addAuthWitness(witness);

// We give wallets[1] access to wallets[0]'s notes to burn the note.
wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]);

await asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce).send().wait();
Expand Down Expand Up @@ -193,6 +194,7 @@ describe('e2e_token_contract burn', () => {
{ chainId: wallets[0].getChainId(), version: wallets[0].getVersion() },
);

// We give wallets[1] access to wallets[0]'s notes to test the authwit.
wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]);

await expect(action.simulate()).rejects.toThrow(
Expand All @@ -216,6 +218,7 @@ describe('e2e_token_contract burn', () => {
const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action });
await wallets[2].addAuthWitness(witness);

// We give wallets[2] access to wallets[0]'s notes to test the authwit.
wallets[2].setScopes([wallets[2].getAddress(), wallets[0].getAddress()]);

await expect(action.simulate()).rejects.toThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('e2e_token_contract transfer private', () => {
const amount = balance0 / 2n;
expect(amount).toBeGreaterThan(0n);

// We give wallets[0] access to wallets[1]'s notes to be able to transfer the notes.
wallets[0].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]);

const tx = await asset.methods.transfer(accounts[1].address, amount).send().wait();
Expand Down Expand Up @@ -93,6 +94,7 @@ describe('e2e_token_contract transfer private', () => {
});
// docs:end:authwit_transfer_example

// We give wallets[1] access to wallets[0]'s notes to be able to transfer the notes.
wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]);

// Perform the transfer
Expand All @@ -106,6 +108,7 @@ describe('e2e_token_contract transfer private', () => {
.send();
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);

// We let wallets[0] see wallets[1]'s notes because the check uses wallets[0]'s wallet to interact with the contracts to "get" state.
wallets[0].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]);
});

Expand Down Expand Up @@ -203,6 +206,7 @@ describe('e2e_token_contract transfer private', () => {
const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action });
await wallets[2].addAuthWitness(witness);

// We give wallets[2] access to wallets[0]'s notes to test the authwit.
wallets[2].setScopes([wallets[2].getAddress(), wallets[0].getAddress()]);

await expect(action.simulate()).rejects.toThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('e2e_token_contract unshielding', () => {
const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action });
await wallets[1].addAuthWitness(witness);

// We give wallets[1] access to wallets[0]'s notes to unshield the note.
wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]);

await action.send().wait();
Expand Down Expand Up @@ -122,6 +123,7 @@ describe('e2e_token_contract unshielding', () => {
const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action });
await wallets[2].addAuthWitness(witness);

// We give wallets[2] access to wallets[0]'s notes to test the authwit.
wallets[2].setScopes([wallets[2].getAddress(), wallets[0].getAddress()]);

await expect(action.simulate()).rejects.toThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ export class CrossChainTestHarness {

/** Deployment addresses for all L1 contracts */
public readonly l1ContractAddresses: L1ContractAddresses,

/** Wallet of the owner. */
public readonly ownerWallet: Wallet,
) {}

Expand Down

0 comments on commit 98738ea

Please sign in to comment.