Skip to content

Commit

Permalink
nuked isMined method
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 23, 2023
1 parent 4c0fc14 commit 4879039
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 49 deletions.
16 changes: 0 additions & 16 deletions yarn-project/aztec.js/src/contract/sent_tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,6 @@ export class SentTx {
return receipt;
}

/**
* Checks whether the transaction is mined or not within the specified timeout and retry interval.
* Resolves to true if the transaction status is 'MINED', false otherwise.
* Throws an error if the transaction receipt cannot be fetched after the given timeout.
*
* @deprecated Use wait() instead as it throws if the tx is not mined,
* while this would silently fail if the return value isn't checked explicitly.
*
* @param opts - Options for configuring the waiting for the tx to be mined.
* @returns A Promise that resolves to a boolean indicating if the transaction is mined or not.
*/
public async isMined(opts?: WaitOpts): Promise<boolean> {
const receipt = await this.waitForReceipt(opts);
return receipt.status === TxStatus.MINED;
}

/**
* Gets unencrypted logs emitted by this tx.
* @remarks This function will wait for the tx to be mined if it hasn't been already.
Expand Down
15 changes: 3 additions & 12 deletions yarn-project/end-to-end/src/e2e_deploy_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ describe('e2e_deploy_contract', () => {
}),
);
logger(`Receipt received and expecting contract deployment at ${receipt.contractAddress}`);
const isMined = await tx.isMined({ interval: 0.1 });
const receiptAfterMined = await tx.getReceipt();
const receiptAfterMined = await tx.wait();

expect(isMined).toBe(true);
expect(receiptAfterMined).toEqual(
expect.objectContaining({
status: TxStatus.MINED,
Expand All @@ -62,10 +60,7 @@ describe('e2e_deploy_contract', () => {

for (let index = 0; index < 2; index++) {
logger(`Deploying contract ${index + 1}...`);
const tx = deployer.deploy().send({ contractAddressSalt: Fr.random() });
const isMined = await tx.isMined({ interval: 0.1 });
expect(isMined).toBe(true);
const receipt = await tx.getReceipt();
const receipt = await deployer.deploy().send({ contractAddressSalt: Fr.random() }).wait();
expect(receipt.status).toBe(TxStatus.MINED);
}
}, 30_000);
Expand Down Expand Up @@ -95,11 +90,7 @@ describe('e2e_deploy_contract', () => {
const deployer = new ContractDeployer(TestContractArtifact, pxe);

{
const tx = deployer.deploy().send({ contractAddressSalt });
const isMined = await tx.isMined({ interval: 0.1 });

expect(isMined).toBe(true);
const receipt = await tx.getReceipt();
const receipt = await deployer.deploy().send({ contractAddressSalt }).wait();

expect(receipt.status).toBe(TxStatus.MINED);
expect(receipt.error).toBe('');
Expand Down
8 changes: 3 additions & 5 deletions yarn-project/end-to-end/src/e2e_p2p_network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ describe('e2e_p2p_network', () => {
// now ensure that all txs were successfully mined
for (const context of contexts) {
for (const tx of context.txs) {
const isMined = await tx.isMined({ interval: 0.1 });
const receiptAfterMined = await tx.getReceipt();
const receipt = await tx.wait();

expect(isMined).toBe(true);
expect(receiptAfterMined.status).toBe(TxStatus.MINED);
const contractAddress = receiptAfterMined.contractAddress!;
expect(receipt.status).toBe(TxStatus.MINED);
const contractAddress = receipt.contractAddress!;
expect(await isContractDeployed(context.pxeService, contractAddress)).toBeTruthy();
expect(await isContractDeployed(context.pxeService, AztecAddress.random())).toBeFalsy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ describe('e2e_pending_commitments_contract', () => {

const deployedContract = await deployContract();

const tx = deployedContract.methods.test_insert_then_get_then_nullify_flat(mintAmount, owner).send();

await tx.isMined({ interval: 0.1 });
const receipt = await tx.getReceipt();
const receipt = await deployedContract.methods
.test_insert_then_get_then_nullify_flat(mintAmount, owner)
.send()
.wait();
expect(receipt.status).toBe(TxStatus.MINED);
}, 60_000);

Expand All @@ -75,18 +75,17 @@ describe('e2e_pending_commitments_contract', () => {

const deployedContract = await deployContract();

const tx = deployedContract.methods
const receipt = await deployedContract.methods
.test_insert_then_get_then_nullify_all_in_nested_calls(
mintAmount,
owner,
deployedContract.methods.insert_note.selector.toField(),
deployedContract.methods.get_then_nullify_note.selector.toField(),
deployedContract.methods.get_note_zero_balance.selector.toField(),
)
.send();
.send()
.wait();

await tx.isMined({ interval: 0.1 });
const receipt = await tx.getReceipt();
expect(receipt.status).toBe(TxStatus.MINED);

await expectCommitmentsSquashedExcept(0);
Expand All @@ -100,17 +99,16 @@ describe('e2e_pending_commitments_contract', () => {

const deployedContract = await deployContract();

const tx = deployedContract.methods
const receipt = await deployedContract.methods
.test_insert2_then_get2_then_nullify2_all_in_nested_calls(
mintAmount,
owner,
deployedContract.methods.insert_note.selector.toField(),
deployedContract.methods.get_then_nullify_note.selector.toField(),
)
.send();
.send()
.wait();

await tx.isMined({ interval: 0.1 });
const receipt = await tx.getReceipt();
expect(receipt.status).toBe(TxStatus.MINED);

await expectCommitmentsSquashedExcept(0);
Expand All @@ -125,17 +123,16 @@ describe('e2e_pending_commitments_contract', () => {

const deployedContract = await deployContract();

const tx = deployedContract.methods
const receipt = await deployedContract.methods
.test_insert2_then_get2_then_nullify1_all_in_nested_calls(
mintAmount,
owner,
deployedContract.methods.insert_note.selector.toField(),
deployedContract.methods.get_then_nullify_note.selector.toField(),
)
.send();
.send()
.wait();

await tx.isMined({ interval: 0.1 });
const receipt = await tx.getReceipt();
expect(receipt.status).toBe(TxStatus.MINED);

await expectCommitmentsSquashedExcept(1);
Expand Down

0 comments on commit 4879039

Please sign in to comment.