Skip to content

Commit

Permalink
refactor: removing redundant receipts check
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Mar 18, 2024
1 parent 047f11c commit d139c53
Show file tree
Hide file tree
Showing 17 changed files with 153 additions and 328 deletions.
24 changes: 5 additions & 19 deletions yarn-project/end-to-end/src/e2e_2_pxes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
GrumpkinScalar,
Note,
PXE,
TxStatus,
Wallet,
computeMessageSecretHash,
retryUntil,
Expand Down Expand Up @@ -106,7 +105,6 @@ describe('e2e_2_pxes', () => {
const secretHash = computeMessageSecretHash(secret);

const receipt = await contract.methods.mint_private(balance, secretHash).send().wait();
expect(receipt.status).toEqual(TxStatus.MINED);

const storageSlot = new Fr(5);
const noteTypeId = new Fr(84114971101151129711410111011678111116101n); // TransparentNote
Expand All @@ -115,9 +113,7 @@ describe('e2e_2_pxes', () => {
const extendedNote = new ExtendedNote(note, recipient, contract.address, storageSlot, noteTypeId, receipt.txHash);
await pxe.addNote(extendedNote);

expect((await contract.methods.redeem_shield(recipient, balance, secret).send().wait()).status).toEqual(
TxStatus.MINED,
);
await contract.methods.redeem_shield(recipient, balance, secret).send().wait();
};

it('transfers funds from user A to B via PXE A followed by transfer from B to A via PXE B', async () => {
Expand Down Expand Up @@ -148,11 +144,7 @@ describe('e2e_2_pxes', () => {

// Transfer funds from A to B via PXE A
const contractWithWalletA = await TokenContract.at(tokenAddress, walletA);
const receiptAToB = await contractWithWalletA.methods
.transfer(userA.address, userB.address, transferAmount1, 0)
.send()
.wait();
expect(receiptAToB.status).toBe(TxStatus.MINED);
await contractWithWalletA.methods.transfer(userA.address, userB.address, transferAmount1, 0).send().wait();

// Check balances and logs are as expected
await expectTokenBalance(walletA, tokenAddress, userA.address, initialBalance - transferAmount1);
Expand Down Expand Up @@ -292,11 +284,7 @@ describe('e2e_2_pxes', () => {

// Transfer funds from A to B via PXE A
const contractWithWalletA = await TokenContract.at(tokenAddress, walletA);
const receiptAToB = await contractWithWalletA.methods
.transfer(userA.address, userB.address, transferAmount1, 0)
.send()
.wait();
expect(receiptAToB.status).toBe(TxStatus.MINED);
await contractWithWalletA.methods.transfer(userA.address, userB.address, transferAmount1, 0).send().wait();

// now add the contract and check balances
await pxeB.addContracts([
Expand Down Expand Up @@ -333,19 +321,17 @@ describe('e2e_2_pxes', () => {

// Transfer funds from A to Shared Wallet via PXE A
const contractWithWalletA = await TokenContract.at(tokenAddress, walletA);
const receiptAToShared = await contractWithWalletA.methods
await contractWithWalletA.methods
.transfer(userA.address, sharedAccountAddress.address, transferAmount1, 0)
.send()
.wait();
expect(receiptAToShared.status).toBe(TxStatus.MINED);

// Now send funds from Shared Wallet to B via PXE A
const contractWithSharedWalletA = await TokenContract.at(tokenAddress, sharedWalletOnA);
const receiptSharedToB = await contractWithSharedWalletA.methods
await contractWithSharedWalletA.methods
.transfer(sharedAccountAddress.address, userB.address, transferAmount2, 0)
.send()
.wait();
expect(receiptSharedToB.status).toBe(TxStatus.MINED);

// check balances from PXE-A's perspective
await expectTokenBalance(walletA, tokenAddress, userA.address, initialBalance - transferAmount1);
Expand Down
100 changes: 28 additions & 72 deletions yarn-project/end-to-end/src/e2e_blacklist_token_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
FunctionSelector,
Note,
TxHash,
TxStatus,
Wallet,
computeAuthWitMessageHash,
computeMessageSecretHash,
Expand Down Expand Up @@ -174,8 +173,7 @@ describe('e2e_blacklist_token_contract', () => {
getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), false)),
);

const tx = await asset.methods.update_roles(newMinter, newRoles).send().wait();
expect(tx.status).toBe(TxStatus.MINED);
await asset.methods.update_roles(newMinter, newRoles).send().wait();
await slowUpdateTreeSimulator.commit();

const afterLeaf = await slowTree.methods.un_read_leaf_at(asset.address, newMinter).view();
Expand All @@ -186,9 +184,7 @@ describe('e2e_blacklist_token_contract', () => {
const time = await cheatCodes.eth.timestamp();
await cheatCodes.aztec.warp(time + 200);

/* const tx = asset.withWallet(wallets[1]).methods.set_minter(accounts[1].address, true).send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
/* asset.withWallet(wallets[1]).methods.set_minter(accounts[1].address, true).send().wait();
expect(await asset.methods.is_minter(accounts[1].address).view()).toBe(true);*/
});

Expand All @@ -205,8 +201,7 @@ describe('e2e_blacklist_token_contract', () => {
getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), false)),
);

const tx = await asset.methods.update_roles(newAdmin, newRoles).send().wait();
expect(tx.status).toBe(TxStatus.MINED);
await asset.methods.update_roles(newAdmin, newRoles).send().wait();
await slowUpdateTreeSimulator.commit();

v = await slowTree.methods.un_read_leaf_at(asset.address, newAdmin).view();
Expand Down Expand Up @@ -235,8 +230,7 @@ describe('e2e_blacklist_token_contract', () => {
getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), false)),
);

const tx = await asset.methods.update_roles(actor, newRoles).send().wait();
expect(tx.status).toBe(TxStatus.MINED);
await asset.methods.update_roles(actor, newRoles).send().wait();
await slowUpdateTreeSimulator.commit();

const afterLeaf = await slowTree.methods.un_read_leaf_at(asset.address, actor).view();
Expand All @@ -248,9 +242,7 @@ describe('e2e_blacklist_token_contract', () => {
await cheatCodes.aztec.warp(time + 200);

/*
const tx = asset.withWallet(wallets[1]).methods.set_minter(accounts[1].address, false).send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
asset.withWallet(wallets[1]).methods.set_minter(accounts[1].address, false).send().wait();
expect(await asset.methods.is_minter(accounts[1].address).view()).toBe(false);*/
});

Expand All @@ -264,8 +256,7 @@ describe('e2e_blacklist_token_contract', () => {
getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), false)),
);

const tx = await asset.methods.update_roles(accounts[3].address, 1n).send().wait();
expect(tx.status).toBe(TxStatus.MINED);
await asset.methods.update_roles(accounts[3].address, 1n).send().wait();
await slowUpdateTreeSimulator.commit();

v = await slowTree.methods.un_read_leaf_at(asset.address, accounts[3].address).view();
Expand Down Expand Up @@ -324,9 +315,7 @@ describe('e2e_blacklist_token_contract', () => {
describe('Public', () => {
it('as minter', async () => {
const amount = 10000n;
const tx = asset.methods.mint_public(accounts[0].address, amount).send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
await asset.methods.mint_public(accounts[0].address, amount).send().wait();

tokenSim.mintPublic(accounts[0].address, amount);
expect(await asset.methods.balance_of_public(accounts[0].address).view()).toEqual(
Expand Down Expand Up @@ -384,9 +373,7 @@ describe('e2e_blacklist_token_contract', () => {

describe('Mint flow', () => {
it('mint_private as minter', async () => {
const tx = asset.methods.mint_private(amount, secretHash).send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
const receipt = await asset.methods.mint_private(amount, secretHash).send().wait();
tokenSim.mintPrivate(amount);
txHash = receipt.txHash;
});
Expand All @@ -396,9 +383,10 @@ describe('e2e_blacklist_token_contract', () => {
await wallets[0].addCapsule(
getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)),
);
const txClaim = asset.methods.redeem_shield(accounts[0].address, amount, secret).send();
const receiptClaim = await txClaim.wait({ debug: true });
expect(receiptClaim.status).toBe(TxStatus.MINED);
const receiptClaim = await asset.methods
.redeem_shield(accounts[0].address, amount, secret)
.send()
.wait({ debug: true });
tokenSim.redeemShield(accounts[0].address, amount);
// 1 note should be created containing `amount` of tokens
const { visibleNotes } = receiptClaim.debugInfo!;
Expand Down Expand Up @@ -467,9 +455,7 @@ describe('e2e_blacklist_token_contract', () => {
const balance0 = await asset.methods.balance_of_public(accounts[0].address).view();
const amount = balance0 / 2n;
expect(amount).toBeGreaterThan(0n);
const tx = asset.methods.transfer_public(accounts[0].address, accounts[1].address, amount, 0).send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
await asset.methods.transfer_public(accounts[0].address, accounts[1].address, amount, 0).send().wait();

tokenSim.transferPublic(accounts[0].address, accounts[1].address, amount);
});
Expand All @@ -478,9 +464,7 @@ describe('e2e_blacklist_token_contract', () => {
const balance = await asset.methods.balance_of_public(accounts[0].address).view();
const amount = balance / 2n;
expect(amount).toBeGreaterThan(0n);
const tx = asset.methods.transfer_public(accounts[0].address, accounts[0].address, amount, 0).send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
await asset.methods.transfer_public(accounts[0].address, accounts[0].address, amount, 0).send().wait();

tokenSim.transferPublic(accounts[0].address, accounts[0].address, amount);
});
Expand All @@ -501,9 +485,7 @@ describe('e2e_blacklist_token_contract', () => {
// docs:end:authwit_public_transfer_example

// Perform the transfer
const tx = action.send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
await action.send().wait();

tokenSim.transferPublic(accounts[0].address, accounts[1].address, amount);

Expand Down Expand Up @@ -643,9 +625,7 @@ describe('e2e_blacklist_token_contract', () => {
await wallets[0].addCapsule(
getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)),
);
const tx = asset.methods.transfer(accounts[0].address, accounts[1].address, amount, 0).send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
await asset.methods.transfer(accounts[0].address, accounts[1].address, amount, 0).send().wait();
tokenSim.transferPrivate(accounts[0].address, accounts[1].address, amount);
});

Expand All @@ -659,9 +639,7 @@ describe('e2e_blacklist_token_contract', () => {
await wallets[0].addCapsule(
getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)),
);
const tx = asset.methods.transfer(accounts[0].address, accounts[0].address, amount, 0).send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
await asset.methods.transfer(accounts[0].address, accounts[0].address, amount, 0).send().wait();
tokenSim.transferPrivate(accounts[0].address, accounts[0].address, amount);
});

Expand Down Expand Up @@ -691,9 +669,7 @@ describe('e2e_blacklist_token_contract', () => {
);

// Perform the transfer
const tx = action.send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
await action.send().wait();
tokenSim.transferPrivate(accounts[0].address, accounts[1].address, amount);

await wallets[1].addCapsule(
Expand Down Expand Up @@ -871,19 +847,15 @@ describe('e2e_blacklist_token_contract', () => {
const amount = balancePub / 2n;
expect(amount).toBeGreaterThan(0n);

const tx = asset.methods.shield(accounts[0].address, amount, secretHash, 0).send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
const receipt = await asset.methods.shield(accounts[0].address, amount, secretHash, 0).send().wait();

tokenSim.shield(accounts[0].address, amount);
await tokenSim.check();

// Redeem it
await addPendingShieldNoteToPXE(0, amount, secretHash, receipt.txHash);
await wallets[0].addCapsule(getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)));
const txClaim = asset.methods.redeem_shield(accounts[0].address, amount, secret).send();
const receiptClaim = await txClaim.wait();
expect(receiptClaim.status).toBe(TxStatus.MINED);
await asset.methods.redeem_shield(accounts[0].address, amount, secret).send().wait();

tokenSim.redeemShield(accounts[0].address, amount);
});
Expand All @@ -899,9 +871,7 @@ describe('e2e_blacklist_token_contract', () => {
const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request());
await wallets[0].setPublicAuth(messageHash, true).send().wait();

const tx = action.send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
const receipt = await action.send().wait();

tokenSim.shield(accounts[0].address, amount);
await tokenSim.check();
Expand All @@ -916,9 +886,7 @@ describe('e2e_blacklist_token_contract', () => {
// Redeem it
await addPendingShieldNoteToPXE(0, amount, secretHash, receipt.txHash);
await wallets[0].addCapsule(getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)));
const txClaim = asset.methods.redeem_shield(accounts[0].address, amount, secret).send();
const receiptClaim = await txClaim.wait();
expect(receiptClaim.status).toBe(TxStatus.MINED);
await asset.methods.redeem_shield(accounts[0].address, amount, secret).send().wait();

tokenSim.redeemShield(accounts[0].address, amount);
});
Expand Down Expand Up @@ -1002,9 +970,7 @@ describe('e2e_blacklist_token_contract', () => {

await wallets[1].addCapsule(getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)));
await wallets[1].addCapsule(getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)));
const tx = asset.methods.unshield(accounts[0].address, accounts[0].address, amount, 0).send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
await asset.methods.unshield(accounts[0].address, accounts[0].address, amount, 0).send().wait();

tokenSim.unshield(accounts[0].address, accounts[0].address, amount);
});
Expand All @@ -1029,9 +995,7 @@ describe('e2e_blacklist_token_contract', () => {
const witness = await wallets[0].createAuthWitness(messageHash);
await wallets[1].addAuthWitness(witness);

const tx = action.send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
await action.send().wait();
tokenSim.unshield(accounts[0].address, accounts[1].address, amount);

// Perform the transfer again, should fail
Expand Down Expand Up @@ -1169,9 +1133,7 @@ describe('e2e_blacklist_token_contract', () => {
const balance0 = await asset.methods.balance_of_public(accounts[0].address).view();
const amount = balance0 / 2n;
expect(amount).toBeGreaterThan(0n);
const tx = asset.methods.burn_public(accounts[0].address, amount, 0).send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
await asset.methods.burn_public(accounts[0].address, amount, 0).send().wait();

tokenSim.burnPublic(accounts[0].address, amount);
});
Expand All @@ -1187,9 +1149,7 @@ describe('e2e_blacklist_token_contract', () => {
const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request());
await wallets[0].setPublicAuth(messageHash, true).send().wait();

const tx = action.send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
await action.send().wait();

tokenSim.burnPublic(accounts[0].address, amount);

Expand Down Expand Up @@ -1273,9 +1233,7 @@ describe('e2e_blacklist_token_contract', () => {
await wallets[0].addCapsule(
getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)),
);
const tx = asset.methods.burn(accounts[0].address, amount, 0).send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
await asset.methods.burn(accounts[0].address, amount, 0).send().wait();
tokenSim.burnPrivate(accounts[0].address, amount);
});

Expand All @@ -1298,9 +1256,7 @@ describe('e2e_blacklist_token_contract', () => {
getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)),
);

const tx = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce).send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
await asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce).send().wait();
tokenSim.burnPrivate(accounts[0].address, amount);

// Perform the transfer again, should fail
Expand Down
2 changes: 0 additions & 2 deletions yarn-project/end-to-end/src/e2e_block_building.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
PXE,
SentTx,
TxReceipt,
TxStatus,
Wallet,
} from '@aztec/aztec.js';
import { times } from '@aztec/foundation/collection';
Expand Down Expand Up @@ -69,7 +68,6 @@ describe('e2e_block_building', () => {

// Await txs to be mined and assert they are all mined on the same block
const receipts = await Promise.all(txs.map(tx => tx.wait()));
expect(receipts.map(r => r.status)).toEqual(times(TX_COUNT, () => TxStatus.MINED));
expect(receipts.map(r => r.blockNumber)).toEqual(times(TX_COUNT, () => receipts[0].blockNumber));

// Assert all contracts got deployed
Expand Down
Loading

0 comments on commit d139c53

Please sign in to comment.