Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Aug 5, 2024
1 parent b0675aa commit 239c032
Show file tree
Hide file tree
Showing 25 changed files with 92 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('e2e_sandbox_example', () => {

// Add the newly created "pending shield" note to PXE
const note = new Note([new Fr(initialSupply), aliceSecretHash]);
await pxe.addNote(
await aliceWallet.addNote(
new ExtendedNote(
note,
alice,
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('e2e_sandbox_example', () => {
const mintPrivateReceipt = await tokenContractBob.methods.mint_private(mintQuantity, bobSecretHash).send().wait();

const bobPendingShield = new Note([new Fr(mintQuantity), bobSecretHash]);
await pxe.addNote(
await bobWallet.addNote(
new ExtendedNote(
bobPendingShield,
bob,
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_2_pxes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('e2e_2_pxes', () => {
TokenContract.notes.TransparentNote.id,
receipt.txHash,
);
await recipientPxe.addNote(extendedNote);
await recipientPxe.addNote(extendedNote, recipient);

await contractAsRecipient.methods.redeem_shield(recipient, balance, secret).send().wait();
};
Expand Down
4 changes: 4 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,12 +60,16 @@ describe('e2e_authwit_tests', () => {
isValidInPublic: false,
});

wallets[0].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]);

// Check that the authwit is NOT valid in private for wallets[1]
expect(await wallets[0].lookupValidity(wallets[1].getAddress(), intent)).toEqual({
isValidInPrivate: false,
isValidInPublic: false,
});

wallets[1].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]);

// Consume the inner hash using the wallets[0] as the "on behalf of".
await auth.withWallet(wallets[1]).methods.consume(wallets[0].getAddress(), innerHash).send().wait();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ describe('e2e_blacklist_token_contract burn', () => {
const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action });
await wallets[1].addAuthWitness(witness);

wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]);

await asset.withWallet(wallets[1]).methods.burn(wallets[0].getAddress(), amount, nonce).send().wait();
tokenSim.burnPrivate(wallets[0].getAddress(), amount);

Expand Down Expand Up @@ -198,6 +200,8 @@ describe('e2e_blacklist_token_contract burn', () => {
{ chainId: wallets[0].getChainId(), version: wallets[0].getVersion() },
);

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 @@ -217,6 +221,8 @@ describe('e2e_blacklist_token_contract burn', () => {
const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action });
await wallets[2].addAuthWitness(witness);

wallets[2].setScopes([wallets[2].getAddress(), wallets[0].getAddress()]);

await expect(action.prove()).rejects.toThrow(
`Unknown auth witness for message hash ${expectedMessageHash.toString()}`,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ describe('e2e_blacklist_token_contract transfer private', () => {
expect(amount).toBeGreaterThan(0n);
await asset.methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, 0).send().wait();
tokenSim.transferPrivate(wallets[0].getAddress(), wallets[1].getAddress(), amount);

wallets[0].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]);
});

it('transfer to self', async () => {
Expand Down Expand Up @@ -62,6 +64,8 @@ describe('e2e_blacklist_token_contract transfer private', () => {
// docs:end:add_authwit
// docs:end:authwit_transfer_example

wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]);

// Perform the transfer
await action.send().wait();
tokenSim.transferPrivate(wallets[0].getAddress(), wallets[1].getAddress(), amount);
Expand All @@ -72,6 +76,8 @@ describe('e2e_blacklist_token_contract transfer private', () => {
.methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce)
.send();
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);

wallets[0].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]);
});

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

wallets[2].setScopes([wallets[2].getAddress(), wallets[0].getAddress()]);

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

wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]);

await action.send().wait();
tokenSim.unshield(wallets[0].getAddress(), wallets[1].getAddress(), amount);

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

wallets[2].setScopes([wallets[2].getAddress(), wallets[0].getAddress()]);

await expect(action.prove()).rejects.toThrow(
`Unknown auth witness for message hash ${expectedMessageHash.toString()}`,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ 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]);
}
Expand All @@ -254,6 +256,7 @@ describe('e2e_crowdfunding_and_claim', () => {
.simulate();
expect(balanceDNTBeforeWithdrawal).toEqual(0n);

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 @@ -399,6 +402,9 @@ describe('e2e_crowdfunding_and_claim', () => {
// a non-entrypoint function (withdraw never calls context.end_setup()), meaning the min revertible counter will remain 0.
// 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)

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

await expect(donorWallets[1].simulateTx(request, true, operatorWallet.getAddress())).rejects.toThrow(
'Assertion failed: Users cannot set msg_sender in first call',
);
Expand Down
6 changes: 4 additions & 2 deletions yarn-project/end-to-end/src/e2e_escrow_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ describe('e2e_escrow_contract', () => {
TokenContract.notes.TransparentNote.id,
receipt.txHash,
);
await pxe.addNote(extendedNote);
await wallet.addNote(extendedNote);

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

wallet.setScopes([wallet.getAddress(), escrowContract.address]);

logger.info(`Token contract deployed at ${token.address}`);
});

Expand Down Expand Up @@ -123,7 +125,7 @@ describe('e2e_escrow_contract', () => {
TokenContract.notes.TransparentNote.id,
receipt.txHash,
);
await pxe.addNote(extendedNote);
await wallet.addNote(extendedNote);

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

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_fees/account_init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('e2e_fees account_init', () => {
await expect(t.getGasBalanceFn(bananaFPC.address)).resolves.toEqual([fpcsInitialGas - actualFee]);

// the new account should have received a refund
await t.addPendingShieldNoteToPXE(bobsAddress, maxFee - actualFee, computeSecretHash(rebateSecret), tx.txHash);
await t.addPendingShieldNoteToPXE(aliceAddress, maxFee - actualFee, computeSecretHash(rebateSecret), tx.txHash);

// and it can redeem the refund
await bananaCoin.methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ describe('e2e_fees dapp_subscription', () => {
new PrivateFeePaymentMethod(bananaCoin.address, bananaFPC.address, aliceWallet),
);

aliceWallet.setScopes([aliceAddress, bobAddress]);

await expectMapping(
t.getGasBalanceFn,
[sequencerAddress, bananaFPC.address],
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_fees/fees_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class FeesTest {
BananaCoin.notes.TransparentNote.id,
txHash,
);
await this.pxe.addNote(extendedNote);
await this.pxe.addNote(extendedNote, ownerAddress);
}

public async applyBaseSnapshots() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('e2e_fees gas_estimation', () => {
({ aliceWallet, aliceAddress, bobAddress, bananaCoin, bananaFPC, gasSettings, logger } = await t.setup());

teardownFixedFee = gasSettings.teardownGasLimits.computeFee(GasFees.default()).toBigInt();
aliceWallet.setScopes([aliceAddress, bobAddress]);
});

afterAll(async () => {
Expand Down
11 changes: 9 additions & 2 deletions yarn-project/end-to-end/src/e2e_fees/native_payments.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { type AztecAddress, NativeFeePaymentMethod, NativeFeePaymentMethodWithClaim } from '@aztec/aztec.js';
import {
type AccountWallet,
type AztecAddress,
NativeFeePaymentMethod,
NativeFeePaymentMethodWithClaim,
} from '@aztec/aztec.js';
import { type GasSettings } from '@aztec/circuits.js';
import { type TokenContract as BananaCoin, type GasTokenContract } from '@aztec/noir-contracts.js';

import { FeesTest } from './fees_test.js';

describe('e2e_fees native_payments', () => {
let aliceAddress: AztecAddress;
let aliceWallet: AccountWallet;
let bobAddress: AztecAddress;
let bananaCoin: BananaCoin;
let gasSettings: GasSettings;
Expand All @@ -17,9 +23,10 @@ describe('e2e_fees native_payments', () => {
beforeAll(async () => {
await t.applyBaseSnapshots();
await t.applyFundAliceWithBananas();
({ gasTokenContract, aliceAddress, bobAddress, bananaCoin, gasSettings } = await t.setup());
({ gasTokenContract, aliceAddress, aliceWallet, bobAddress, bananaCoin, gasSettings } = await t.setup());

paymentMethod = new NativeFeePaymentMethod(aliceAddress);
aliceWallet.setScopes([aliceAddress, bobAddress]);
});

afterAll(async () => {
Expand Down
6 changes: 4 additions & 2 deletions yarn-project/end-to-end/src/e2e_fees/private_payments.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
type AccountWallet,
type AztecAddress,
BatchCall,
Fr,
PrivateFeePaymentMethod,
type TxReceipt,
type Wallet,
computeSecretHash,
} from '@aztec/aztec.js';
import { type GasSettings } from '@aztec/circuits.js';
Expand All @@ -14,7 +14,7 @@ import { expectMapping } from '../fixtures/utils.js';
import { FeesTest } from './fees_test.js';

describe('e2e_fees private_payment', () => {
let aliceWallet: Wallet;
let aliceWallet: AccountWallet;
let aliceAddress: AztecAddress;
let bobAddress: AztecAddress;
let sequencerAddress: AztecAddress;
Expand Down Expand Up @@ -73,6 +73,8 @@ describe('e2e_fees private_payment', () => {
t.getBananaPublicBalanceFn(aliceAddress, bobAddress, bananaFPC.address),
t.getGasBalanceFn(aliceAddress, bananaFPC.address, sequencerAddress),
]);

aliceWallet.setScopes([aliceAddress, bobAddress]);
});

const getFeeAndRefund = (tx: Pick<TxReceipt, 'transactionFee'>) => [tx.transactionFee!, maxFee - tx.transactionFee!];
Expand Down
8 changes: 6 additions & 2 deletions yarn-project/end-to-end/src/e2e_fees/private_refunds.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
type AccountWallet,
type AztecAddress,
ExtendedNote,
type FeePaymentMethod,
Expand All @@ -16,8 +17,9 @@ import { expectMapping } from '../fixtures/utils.js';
import { FeesTest } from './fees_test.js';

describe('e2e_fees/private_refunds', () => {
let aliceWallet: Wallet;
let aliceWallet: AccountWallet;
let aliceAddress: AztecAddress;
let bobAddress: AztecAddress;
let tokenWithRefunds: TokenWithRefundsContract;
let privateFPC: PrivateFPCContract;

Expand All @@ -34,8 +36,10 @@ describe('e2e_fees/private_refunds', () => {
await t.applyDeployGasTokenSnapshot();
await t.applyTokenWithRefundsAndFPC();
await t.applyFundAliceWithTokens();
({ aliceWallet, aliceAddress, privateFPC, tokenWithRefunds } = await t.setup());
({ aliceWallet, aliceAddress, bobAddress, privateFPC, tokenWithRefunds } = await t.setup());
t.logger.debug(`Alice address: ${aliceAddress}`);

aliceWallet.setScopes([aliceAddress, bobAddress]);
});

afterAll(async () => {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_keys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('Key Registry', () => {

expect(await getNumNullifiedNotes(nskApp, testContract.address)).toEqual(0);

await testContract.methods.call_destroy_note(noteStorageSlot).send().wait();
await testContract.withWallet(account).methods.call_destroy_note(noteStorageSlot).send().wait();

expect(await getNumNullifiedNotes(nskApp, testContract.address)).toEqual(1);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('e2e_multiple_accounts_1_enc_key', () => {
TokenContract.notes.TransparentNote.id,
receipt.txHash,
);
await pxe.addNote(extendedNote);
await wallets[0].addNote(extendedNote);

await token.methods.redeem_shield(accounts[0], initialBalance, secret).send().wait();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export class PublicCrossChainMessagingContractTest {
walletClient,
this.ownerAddress,
this.aztecNodeConfig.l1Contracts,
this.user1Wallet,
);

this.publicClient = publicClient;
Expand Down
6 changes: 6 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,8 @@ describe('e2e_token_contract burn', () => {
const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action });
await wallets[1].addAuthWitness(witness);

wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]);

await asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce).send().wait();
tokenSim.burnPrivate(accounts[0].address, amount);

Expand Down Expand Up @@ -191,6 +193,8 @@ describe('e2e_token_contract burn', () => {
{ chainId: wallets[0].getChainId(), version: wallets[0].getVersion() },
);

wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]);

await expect(action.simulate()).rejects.toThrow(
`Unknown auth witness for message hash ${messageHash.toString()}`,
);
Expand All @@ -212,6 +216,8 @@ describe('e2e_token_contract burn', () => {
const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action });
await wallets[2].addAuthWitness(witness);

wallets[2].setScopes([wallets[2].getAddress(), wallets[0].getAddress()]);

await expect(action.simulate()).rejects.toThrow(
`Unknown auth witness for message hash ${expectedMessageHash.toString()}`,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ describe('e2e_token_contract transfer private', () => {
const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate();
const amount = balance0 / 2n;
expect(amount).toBeGreaterThan(0n);

wallets[0].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]);

const tx = await asset.methods.transfer(accounts[1].address, amount).send().wait();
tokenSim.transferPrivate(accounts[0].address, accounts[1].address, amount);

Expand Down Expand Up @@ -90,6 +93,8 @@ describe('e2e_token_contract transfer private', () => {
});
// docs:end:authwit_transfer_example

wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]);

// Perform the transfer
await action.send().wait();
tokenSim.transferPrivate(accounts[0].address, accounts[1].address, amount);
Expand All @@ -100,6 +105,8 @@ describe('e2e_token_contract transfer private', () => {
.methods.transfer_from(accounts[0].address, accounts[1].address, amount, nonce)
.send();
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);

wallets[0].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]);
});

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

wallets[2].setScopes([wallets[2].getAddress(), wallets[0].getAddress()]);

await expect(action.simulate()).rejects.toThrow(
`Unknown auth witness for message hash ${expectedMessageHash.toString()}`,
);
Expand Down
Loading

0 comments on commit 239c032

Please sign in to comment.