Skip to content

Commit 7d1c105

Browse files
committed
fix(ethereum): deflake monitor timeout tests in l1_tx_utils
1 parent 5e0e53f commit 7d1c105

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

yarn-project/ethereum/src/l1_tx_utils/l1_tx_utils.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,13 +1040,14 @@ describe('L1TxUtils', () => {
10401040
const txRequest: L1TxRequest = { to: '0x1234567890123456789012345678901234567890', data: '0x', value: 0n };
10411041
const { txHash, state } = await gasUtils.sendTransaction(txRequest);
10421042
const testState: L1TxState = { ...state, txConfigOverrides: { ...state.txConfigOverrides, txTimeoutAt } };
1043-
const monitorPromise = gasUtils.monitorTransaction(testState);
1043+
// Attach the rejection handler synchronously so an early timeout does not surface as an unhandled rejection
1044+
const monitorPromise = gasUtils.monitorTransaction(testState).catch(err => err);
10441045

10451046
await sleep(100);
10461047
await cheatCodes.dropTransaction(txHash);
10471048
await cheatCodes.setNextBlockTimestamp(txTimeoutAt);
10481049
await cheatCodes.mine();
1049-
await expect(monitorPromise).rejects.toThrow(/timed out/);
1050+
await expect(monitorPromise).resolves.toBeInstanceOf(TimeoutError);
10501051
expect(dateProvider.now() - now).toBeGreaterThanOrEqual(90);
10511052
}, 20_000);
10521053

@@ -1073,14 +1074,15 @@ describe('L1TxUtils', () => {
10731074
...state,
10741075
txConfigOverrides: { ...state.txConfigOverrides, txTimeoutMs: 100 },
10751076
};
1076-
const monitorPromise = gasUtils.monitorTransaction(testState);
1077+
// Attach the rejection handler synchronously so an early timeout does not surface as an unhandled rejection
1078+
const monitorPromise = gasUtils.monitorTransaction(testState).catch(err => err);
10771079
logger.warn(`Monitoring tx ${txHash}`);
10781080

10791081
// Mine a block to advance the timestamp and trigger the timeout
10801082
await cheatCodes.mineEmptyBlock();
10811083

10821084
// Wait for timeout and catch the error
1083-
await expect(monitorPromise).rejects.toThrow('timed out');
1085+
await expect(monitorPromise).resolves.toBeInstanceOf(TimeoutError);
10841086
logger.warn(`Tx monitor has timed out`);
10851087

10861088
// Wait for cancellation tx to be sent
@@ -1173,12 +1175,13 @@ describe('L1TxUtils', () => {
11731175
// Monitor the tx. We will think it has timed out and submit a cancellation.
11741176
state.txConfigOverrides.txTimeoutMs = 200;
11751177
state.txConfigOverrides.checkIntervalMs = 100;
1176-
const monitorPromise = gasUtils.monitorTransaction(state);
1178+
// Attach the rejection handler synchronously so an early timeout does not surface as an unhandled rejection
1179+
const monitorPromise = gasUtils.monitorTransaction(state).catch(err => err);
11771180

11781181
// Wait for timeout and catch the error
11791182
await sleep(100);
11801183
await cheatCodes.mineEmptyBlock();
1181-
await expect(monitorPromise).rejects.toThrow('timed out');
1184+
await expect(monitorPromise).resolves.toBeInstanceOf(TimeoutError);
11821185
logger.warn('Monitor has thrown for timeout');
11831186

11841187
// Wait for cancellation to be sent

0 commit comments

Comments
 (0)