-
Notifications
You must be signed in to change notification settings - Fork 333
/
Copy pathsent_tx.test.ts
41 lines (32 loc) · 1.37 KB
/
sent_tx.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { type PXE, TxHash, type TxReceipt, TxStatus } from '@aztec/circuit-types';
import { type MockProxy, mock } from 'jest-mock-extended';
import { SentTx } from './sent_tx.js';
describe('SentTx', () => {
let pxe: MockProxy<PXE>;
let txHashPromise: Promise<TxHash>;
let sentTx: SentTx;
beforeEach(() => {
pxe = mock();
txHashPromise = Promise.resolve(TxHash.fromBigInt(1n));
sentTx = new SentTx(pxe, txHashPromise);
});
describe('wait', () => {
let txReceipt: TxReceipt;
beforeEach(() => {
txReceipt = { status: TxStatus.SUCCESS, blockNumber: 20 } as TxReceipt;
pxe.getTxReceipt.mockResolvedValue(txReceipt);
});
it('throws if tx is dropped', async () => {
pxe.getTxReceipt.mockResolvedValue({ ...txReceipt, status: TxStatus.DROPPED } as TxReceipt);
await expect(sentTx.wait({ timeout: 1, interval: 0.4, ignoreDroppedReceiptsFor: 0 })).rejects.toThrow(/dropped/);
});
it('waits for the tx to be proven', async () => {
const waitOpts = { timeout: 1, interval: 0.4, waitForNotesAvailable: false, proven: true, provenTimeout: 2 };
pxe.getProvenBlockNumber.mockResolvedValue(10);
await expect(sentTx.wait(waitOpts)).rejects.toThrow(/timeout/i);
pxe.getProvenBlockNumber.mockResolvedValue(20);
const actual = await sentTx.wait(waitOpts);
expect(actual).toEqual(txReceipt);
});
});
});