Skip to content

Commit cc1fde1

Browse files
authored
Merge pull request #1488 from input-output-hk/test/LW-11574-reduce-test-flakiness
test(e2e): reduce test flakiness
2 parents 297958a + 452bb95 commit cc1fde1

File tree

9 files changed

+29
-145
lines changed

9 files changed

+29
-145
lines changed

packages/e2e/test/wallet_epoch_0/PersonalWallet/byron.test.ts

+2-13
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
import { BaseWallet } from '@cardano-sdk/wallet';
33
import { Cardano } from '@cardano-sdk/core';
44
import { createLogger } from '@cardano-sdk/util-dev';
5-
import { filter, firstValueFrom, map, take } from 'rxjs';
65
import { getEnv, walletVariables } from '../../../src/environment';
7-
import { getWallet, normalizeTxBody, walletReady } from '../../../src';
8-
import { isNotNil } from '@cardano-sdk/util';
6+
import { getWallet, normalizeTxBody, submitAndConfirm, walletReady } from '../../../src';
97

108
const env = getEnv(walletVariables);
119
const logger = createLogger();
@@ -33,16 +31,7 @@ describe('PersonalWallet/byron', () => {
3331
.build();
3432

3533
const { tx: signedTx } = await txBuilder.addOutput(txOutput).build().sign();
36-
await wallet.submitTx(signedTx);
37-
38-
// Search chain history to see if the transaction is there.
39-
const txFoundInHistory = await firstValueFrom(
40-
wallet.transactions.history$.pipe(
41-
map((txs) => txs.find((tx) => tx.id === signedTx.id)),
42-
filter(isNotNil),
43-
take(1)
44-
)
45-
);
34+
const [, txFoundInHistory] = await submitAndConfirm(wallet, signedTx, 1);
4635

4736
// Assert
4837
expect(txFoundInHistory).toBeDefined();

packages/e2e/test/wallet_epoch_0/PersonalWallet/metadata.test.ts

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { BaseWallet, createWalletUtil } from '@cardano-sdk/wallet';
22
import { Cardano } from '@cardano-sdk/core';
3-
import { filter, firstValueFrom, map } from 'rxjs';
4-
import { getEnv, getWallet, walletReady, walletVariables } from '../../../src';
5-
import { isNotNil } from '@cardano-sdk/util';
3+
import { firstValueFrom } from 'rxjs';
4+
import { getEnv, getWallet, submitAndConfirm, walletReady, walletVariables } from '../../../src';
65
import { logger } from '@cardano-sdk/util-dev';
76

87
const env = getEnv(walletVariables);
@@ -35,15 +34,8 @@ describe('PersonalWallet/metadata', () => {
3534
.build()
3635
.sign();
3736

38-
const outgoingTx = signedTx;
39-
await wallet.submitTx(signedTx);
37+
const [, loadedTx] = await submitAndConfirm(wallet, signedTx, 1);
4038

41-
const loadedTx = await firstValueFrom(
42-
wallet.transactions.history$.pipe(
43-
map((txs) => txs.find((tx) => tx.id === outgoingTx.id)),
44-
filter(isNotNil)
45-
)
46-
);
4739
expect(loadedTx.auxiliaryData?.blob).toEqual(metadata);
4840
});
4941
});

packages/e2e/test/wallet_epoch_0/PersonalWallet/mint.test.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import {
1313
walletVariables
1414
} from '../../../src';
1515
import { createLogger } from '@cardano-sdk/util-dev';
16-
import { filter, firstValueFrom, map, take } from 'rxjs';
17-
import { isNotNil } from '@cardano-sdk/util';
16+
import { filter, firstValueFrom } from 'rxjs';
1817

1918
const env = getEnv(walletVariables);
2019
const logger = createLogger();
@@ -99,16 +98,7 @@ describe('PersonalWallet/mint', () => {
9998
};
10099

101100
const signedTx = await wallet.finalizeTx(finalizeProps);
102-
await submitAndConfirm(wallet, signedTx);
103-
104-
// Search chain history to see if the transaction is there.
105-
const txFoundInHistory = await firstValueFrom(
106-
wallet.transactions.history$.pipe(
107-
map((txs) => txs.find((tx) => tx.id === signedTx.id)),
108-
filter(isNotNil),
109-
take(1)
110-
)
111-
);
101+
const [, txFoundInHistory] = await submitAndConfirm(wallet, signedTx, 1);
112102

113103
expect(txFoundInHistory.id).toEqual(signedTx.id);
114104

packages/e2e/test/wallet_epoch_0/PersonalWallet/multiAddress.test.ts

+4-22
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ import {
99
firstValueFromTimed,
1010
getWallet,
1111
normalizeTxBody,
12+
submitAndConfirm,
1213
walletReady
1314
} from '../../../src';
1415
import { createLogger } from '@cardano-sdk/util-dev';
15-
import { filter, map, take } from 'rxjs';
1616
import { getEnv, walletVariables } from '../../../src/environment';
17-
import { isNotNil } from '@cardano-sdk/util';
1817

1918
const env = getEnv(walletVariables);
2019
const logger = createLogger();
@@ -77,16 +76,7 @@ describe('PersonalWallet/multiAddress', () => {
7776

7877
const { tx: signedTx } = await txBuilder.build().sign();
7978

80-
await wallet.submitTx(signedTx);
81-
82-
// Search chain history to see if the transaction is there.
83-
const txFoundInHistory = await firstValueFromTimed(
84-
wallet.transactions.history$.pipe(
85-
map((txs) => txs.find((tx) => tx.id === signedTx.id)),
86-
filter(isNotNil),
87-
take(1)
88-
)
89-
);
79+
const [, txFoundInHistory] = await submitAndConfirm(wallet, signedTx, 1);
9080

9181
expect(txFoundInHistory.id).toEqual(signedTx.id);
9282
expect(normalizeTxBody(txFoundInHistory.body)).toEqual(normalizeTxBody(signedTx.body));
@@ -143,16 +133,8 @@ describe('PersonalWallet/multiAddress', () => {
143133
)
144134
.build()
145135
.sign();
146-
await newWallet.wallet.submitTx(returnAdaSignedTx);
147-
148-
// Search chain history to see if the transaction is there.
149-
const returnAdaTxFoundInHistory = await firstValueFromTimed(
150-
newWallet.wallet.transactions.history$.pipe(
151-
map((txs) => txs.find((tx) => tx.id === returnAdaSignedTx.id)),
152-
filter(isNotNil),
153-
take(1)
154-
)
155-
);
136+
137+
const [, returnAdaTxFoundInHistory] = await submitAndConfirm(newWallet.wallet, returnAdaSignedTx, 1);
156138

157139
expect(returnAdaTxFoundInHistory.id).toEqual(returnAdaSignedTx.id);
158140
expect(normalizeTxBody(returnAdaTxFoundInHistory.body)).toEqual(normalizeTxBody(returnAdaSignedTx.body));

packages/e2e/test/wallet_epoch_0/PersonalWallet/phase2validation.test.ts

+4-22
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { HexBlob, isNotNil } from '@cardano-sdk/util';
44
import { InitializeTxProps, computeScriptDataHash } from '@cardano-sdk/tx-construction';
55
import { createLogger } from '@cardano-sdk/util-dev';
66
import { filter, firstValueFrom, map, take } from 'rxjs';
7-
import { firstValueFromTimed, getEnv, getWallet, walletReady, walletVariables } from '../../../src';
7+
import { firstValueFromTimed, getEnv, getWallet, submitAndConfirm, walletReady, walletVariables } from '../../../src';
88

99
const env = getEnv(walletVariables);
1010
const logger = createLogger();
@@ -37,16 +37,7 @@ const createCollateral = async (
3737
const txOutput = await txBuilder.buildOutput().address(address).coin(5_000_000n).build();
3838

3939
const { tx: signedTx } = await txBuilder.addOutput(txOutput).build().sign();
40-
await wallet.submitTx(signedTx);
41-
42-
// Wait for transaction to be on chain.
43-
await firstValueFrom(
44-
wallet.transactions.history$.pipe(
45-
map((txs) => txs.find((tx) => tx.id === signedTx.id)),
46-
filter(isNotNil),
47-
take(1)
48-
)
49-
);
40+
await submitAndConfirm(wallet, signedTx, 1);
5041

5142
// Find the collateral UTxO in the UTxO set.
5243
const utxo = await firstValueFrom(
@@ -151,17 +142,8 @@ describe('PersonalWallet/phase2validation', () => {
151142

152143
const signedTx = await wallet.finalizeTx(finalizeProps);
153144

154-
const [, failedTx, txFoundInHistory] = await Promise.all([
155-
wallet.submitTx(signedTx),
156-
firstValueFromTimed(wallet.transactions.outgoing.failed$),
157-
firstValueFromTimed(
158-
wallet.transactions.history$.pipe(
159-
map((txs) => txs.find((tx) => tx.id === signedTx.id)),
160-
filter(isNotNil),
161-
take(1)
162-
)
163-
)
164-
]);
145+
const [, txFoundInHistory] = await submitAndConfirm(wallet, signedTx, 1);
146+
const failedTx = await firstValueFromTimed(wallet.transactions.outgoing.failed$);
165147

166148
// Transaction should be part of the history
167149
expect(txFoundInHistory).toBeTruthy();

packages/e2e/test/wallet_epoch_0/PersonalWallet/plutusTest.test.ts

+7-39
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { BaseWallet } from '@cardano-sdk/wallet';
22
import { Cardano, Serialization, UtxoProvider } from '@cardano-sdk/core';
3-
import { HexBlob, isNotNil } from '@cardano-sdk/util';
4-
import { Observable, filter, firstValueFrom, interval, map, switchMap, take } from 'rxjs';
3+
import { HexBlob } from '@cardano-sdk/util';
4+
import { Observable, filter, firstValueFrom, interval, switchMap } from 'rxjs';
55
import { createLogger } from '@cardano-sdk/util-dev';
6-
import { getEnv, getWallet, utxoProviderFactory, walletReady, walletVariables } from '../../../src';
6+
import { getEnv, getWallet, submitAndConfirm, utxoProviderFactory, walletReady, walletVariables } from '../../../src';
77

88
const env = getEnv(walletVariables);
99
const logger = createLogger();
@@ -85,7 +85,7 @@ const fundScript = async (wallet: BaseWallet, receivingAddress: Cardano.PaymentA
8585
const txBuilder = wallet.createTxBuilder();
8686
const txOutput = await txBuilder.buildOutput().address(receivingAddress).coin(tAdaToSend).datum(datum).build();
8787
const signedTx = (await txBuilder.addOutput(txOutput).build().sign()).tx;
88-
await wallet.submitTx(signedTx);
88+
const [, txFoundInHistory] = await submitAndConfirm(wallet, signedTx, 1);
8989

9090
logger.info(
9191
`Submitted transaction id: ${signedTx.id}, inputs: ${JSON.stringify(
@@ -95,14 +95,6 @@ const fundScript = async (wallet: BaseWallet, receivingAddress: Cardano.PaymentA
9595
)}.`
9696
);
9797

98-
const txFoundInHistory = await firstValueFrom(
99-
wallet.transactions.history$.pipe(
100-
map((txs) => txs.find((tx) => tx.id === signedTx.id)),
101-
filter(isNotNil),
102-
take(1)
103-
)
104-
);
105-
10698
logger.info(`Found transaction id in chain history: ${txFoundInHistory.id}`);
10799

108100
// Assert
@@ -135,7 +127,7 @@ const createScriptRefInput = async (wallet: BaseWallet, script: Cardano.Script):
135127
.build();
136128

137129
const signedTx = (await txBuilder.addOutput(txOutput).build().sign()).tx;
138-
await wallet.submitTx(signedTx);
130+
const [, txFoundInHistory] = await submitAndConfirm(wallet, signedTx, 1);
139131

140132
logger.info(
141133
`Submitted transaction id: ${signedTx.id}, inputs: ${JSON.stringify(
@@ -145,14 +137,6 @@ const createScriptRefInput = async (wallet: BaseWallet, script: Cardano.Script):
145137
)}.`
146138
);
147139

148-
const txFoundInHistory = await firstValueFrom(
149-
wallet.transactions.history$.pipe(
150-
map((txs) => txs.find((tx) => tx.id === signedTx.id)),
151-
filter(isNotNil),
152-
take(1)
153-
)
154-
);
155-
156140
logger.info(`Found transaction id in chain history: ${txFoundInHistory.id}`);
157141

158142
// Assert
@@ -243,7 +227,7 @@ describe.skip('PersonalWallet/plutus', () => {
243227
.sign()
244228
).tx;
245229

246-
await wallet.submitTx(signedTx);
230+
const [, txFoundInHistory] = await submitAndConfirm(wallet, signedTx, 1);
247231

248232
logger.info(
249233
`Submitted transaction id: ${signedTx.id}, inputs: ${JSON.stringify(
@@ -253,14 +237,6 @@ describe.skip('PersonalWallet/plutus', () => {
253237
)}.`
254238
);
255239

256-
const txFoundInHistory = await firstValueFrom(
257-
wallet.transactions.history$.pipe(
258-
map((txs) => txs.find((tx) => tx.id === signedTx.id)),
259-
filter(isNotNil),
260-
take(1)
261-
)
262-
);
263-
264240
logger.info(`Found transaction id in chain history: ${txFoundInHistory.id}`);
265241

266242
// Assert
@@ -327,7 +303,7 @@ describe.skip('PersonalWallet/plutus', () => {
327303
.sign()
328304
).tx;
329305

330-
await wallet.submitTx(signedTx);
306+
const [, txFoundInHistory] = await submitAndConfirm(wallet, signedTx, 1);
331307

332308
logger.info(
333309
`Submitted transaction id: ${signedTx.id}, inputs: ${JSON.stringify(
@@ -337,14 +313,6 @@ describe.skip('PersonalWallet/plutus', () => {
337313
)}.`
338314
);
339315

340-
const txFoundInHistory = await firstValueFrom(
341-
wallet.transactions.history$.pipe(
342-
map((txs) => txs.find((tx) => tx.id === signedTx.id)),
343-
filter(isNotNil),
344-
take(1)
345-
)
346-
);
347-
348316
logger.info(`Found transaction id in chain history: ${txFoundInHistory.id}`);
349317

350318
// Assert

packages/e2e/test/wallet_epoch_0/PersonalWallet/txChainHistory.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BaseWallet } from '@cardano-sdk/wallet';
22
import { Cardano, CardanoNodeUtil } from '@cardano-sdk/core';
33
import { filter, firstValueFrom, map, take } from 'rxjs';
4-
import { getEnv, getWallet, normalizeTxBody, walletReady, walletVariables } from '../../../src';
4+
import { getEnv, getWallet, normalizeTxBody, submitAndConfirm, walletReady, walletVariables } from '../../../src';
55
import { isNotNil } from '@cardano-sdk/util';
66
import { logger } from '@cardano-sdk/util-dev';
77

@@ -28,7 +28,7 @@ describe('PersonalWallet/txChainHistory', () => {
2828
const txBuilder = wallet.createTxBuilder();
2929
const txOutput = await txBuilder.buildOutput().address(receivingAddress).coin(tAdaToSend).build();
3030
signedTx = (await txBuilder.addOutput(txOutput).build().sign()).tx;
31-
await wallet.submitTx(signedTx);
31+
await submitAndConfirm(wallet, signedTx, 1);
3232

3333
logger.info(
3434
`Submitted transaction id: ${signedTx.id}, inputs: ${JSON.stringify(

packages/e2e/test/wallet_epoch_0/PersonalWallet/unspendableUtxos.test.ts

+3-23
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { BaseWallet, utxoEquals } from '@cardano-sdk/wallet';
33
import { createLogger } from '@cardano-sdk/util-dev';
44
import { filter, firstValueFrom, map, take } from 'rxjs';
5-
import { firstValueFromTimed, getEnv, getWallet, walletReady, walletVariables } from '../../../src';
5+
import { firstValueFromTimed, getEnv, getWallet, submitAndConfirm, walletReady, walletVariables } from '../../../src';
66
import { isNotNil } from '@cardano-sdk/util';
77

88
const env = getEnv(walletVariables);
@@ -37,17 +37,7 @@ describe('PersonalWallet/unspendableUtxos', () => {
3737
const txOutput = await txBuilder1.buildOutput().address(address).coin(5_000_000n).build();
3838

3939
const { tx: signedTx } = await txBuilder1.addOutput(txOutput).build().sign();
40-
await wallet1.submitTx(signedTx);
41-
42-
// Search chain history to see if the transaction is there.
43-
let txFoundInHistory = await firstValueFromTimed(
44-
wallet1.transactions.history$.pipe(
45-
map((txs) => txs.find((tx) => tx.id === signedTx.id)),
46-
filter(isNotNil),
47-
take(1)
48-
),
49-
`Failed to find transaction ${signedTx.id} in src wallet history`
50-
);
40+
let [, txFoundInHistory] = await submitAndConfirm(wallet1, signedTx, 1);
5141

5242
// Find the UTxO in the UTxO set.
5343
const utxo = await firstValueFromTimed(
@@ -97,17 +87,7 @@ describe('PersonalWallet/unspendableUtxos', () => {
9787
.addOutput(await txBuilder2.buildOutput().address(address).value(totalBalance).build())
9888
.build()
9989
.sign();
100-
await wallet2.submitTx(signedMoveAdaTx);
101-
102-
// Search chain history to see if the transaction is there.
103-
txFoundInHistory = await firstValueFromTimed(
104-
wallet1.transactions.history$.pipe(
105-
map((txs) => txs.find((tx) => tx.id === signedMoveAdaTx.id)),
106-
filter(isNotNil),
107-
take(1)
108-
),
109-
`Failed to find second transaction ${signedMoveAdaTx.id} in dest wallet history`
110-
);
90+
[, txFoundInHistory] = await submitAndConfirm(wallet2, signedMoveAdaTx, 1);
11191

11292
expect(txFoundInHistory.id).toEqual(signedMoveAdaTx.id);
11393

packages/e2e/test/wallet_epoch_0/SharedWallet/simpleTx.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
getEnv,
77
getWallet,
88
normalizeTxBody,
9+
submitAndConfirm,
910
waitForWalletStateSettle,
1011
walletReady,
1112
walletVariables
@@ -52,7 +53,7 @@ describe('SharedWallet/simpleTx', () => {
5253
const txBuilder = faucetWallet.createTxBuilder();
5354
const txOutput = await txBuilder.buildOutput().address(receivingAddress).coin(initialFunds).build();
5455
fundingTx = (await txBuilder.addOutput(txOutput).build().sign()).tx;
55-
await faucetWallet.submitTx(fundingTx);
56+
await submitAndConfirm(faucetWallet, fundingTx, 1);
5657

5758
logger.info(
5859
`Submitted transaction id: ${fundingTx.id}, inputs: ${JSON.stringify(

0 commit comments

Comments
 (0)