diff --git a/packages/e2e/test/wallet/SingleAddressWallet/delegation.test.ts b/packages/e2e/test/wallet/SingleAddressWallet/delegation.test.ts index f7028541a4b..67ae23477e2 100644 --- a/packages/e2e/test/wallet/SingleAddressWallet/delegation.test.ts +++ b/packages/e2e/test/wallet/SingleAddressWallet/delegation.test.ts @@ -2,7 +2,7 @@ import { Awaited } from '@cardano-sdk/util'; import { Cardano } from '@cardano-sdk/core'; import { ObservableWallet, StakeKeyStatus, buildTx } from '@cardano-sdk/wallet'; -import { TX_TIMEOUT, firstValueFromTimed, waitForWalletStateSettle } from '../util'; +import { TX_TIMEOUT, firstValueFromTimed, waitForWalletStateSettle, walletReady } from '../util'; import { assertTxIsValid } from '../../../../wallet/test/util'; import { env } from '../environment'; import { getWallet } from '../../../src/factories'; @@ -85,6 +85,8 @@ describe('SingleAddressWallet/delegation', () => { // source wallet has the highest balance to begin with const [sourceWallet, destWallet] = await chooseWallets(); + await walletReady(sourceWallet); + const protocolParameters = await firstValueFrom(sourceWallet.protocolParameters$); const stakeKeyDeposit = BigInt(protocolParameters.stakeKeyDeposit); const initialState = await getWalletStateSnapshot(sourceWallet); diff --git a/packages/e2e/test/wallet/SingleAddressWallet/metadata.test.ts b/packages/e2e/test/wallet/SingleAddressWallet/metadata.test.ts index a3351f98995..163c7afa27b 100644 --- a/packages/e2e/test/wallet/SingleAddressWallet/metadata.test.ts +++ b/packages/e2e/test/wallet/SingleAddressWallet/metadata.test.ts @@ -5,6 +5,7 @@ import { filter, firstValueFrom, map } from 'rxjs'; import { getWallet } from '../../../src/factories'; import { isNotNil } from '@cardano-sdk/util'; import { logger } from '@cardano-sdk/util-dev'; +import { walletReady } from '../util'; describe('SingleAddressWallet/metadata', () => { let wallet: SingleAddressWallet; @@ -13,6 +14,8 @@ describe('SingleAddressWallet/metadata', () => { beforeAll(async () => { wallet = (await getWallet({ env, logger, name: 'Test Wallet' })).wallet; ownAddress = (await firstValueFrom(wallet.addresses$))[0].address; + + await walletReady(wallet); }); afterAll(() => wallet.shutdown()); diff --git a/packages/e2e/test/wallet/SingleAddressWallet/multisignature.test.ts b/packages/e2e/test/wallet/SingleAddressWallet/multisignature.test.ts index 6806d6eaae9..bd6d64ed0d6 100644 --- a/packages/e2e/test/wallet/SingleAddressWallet/multisignature.test.ts +++ b/packages/e2e/test/wallet/SingleAddressWallet/multisignature.test.ts @@ -5,6 +5,7 @@ import { SingleAddressWallet } from '@cardano-sdk/wallet'; import { env } from '../environment'; import { filter, firstValueFrom } from 'rxjs'; import { getLogger, getWallet } from '../../../src/factories'; +import { walletReady } from '../util'; const logger = getLogger(env.LOGGER_MIN_SEVERITY); @@ -35,7 +36,7 @@ describe('SingleAddressWallet/multisignature', () => { it('can create a transaction with multiple signatures to mint an asset', async () => { wallet = (await getWallet({ env, idx: 0, logger, name: 'Minting Wallet', polling: { interval: 50 } })).wallet; - await firstValueFrom(wallet.syncStatus.isSettled$.pipe(filter((isSettled) => isSettled))); + await walletReady(wallet); const params = await firstValueFrom(wallet.genesisParameters$); diff --git a/packages/e2e/test/wallet/SingleAddressWallet/nft.test.ts b/packages/e2e/test/wallet/SingleAddressWallet/nft.test.ts index f9f280339a9..d96eee0aae5 100644 --- a/packages/e2e/test/wallet/SingleAddressWallet/nft.test.ts +++ b/packages/e2e/test/wallet/SingleAddressWallet/nft.test.ts @@ -5,6 +5,7 @@ import { SingleAddressWallet } from '@cardano-sdk/wallet'; import { combineLatest, filter, firstValueFrom, map } from 'rxjs'; import { env } from '../environment'; import { getLogger, getWallet } from '../../../src/factories'; +import { walletReady } from '../util'; const logger = getLogger(env.LOGGER_MIN_SEVERITY); @@ -26,7 +27,7 @@ describe('SingleAddressWallet.assets/nft', () => { beforeAll(async () => { wallet = (await getWallet({ env, idx: 0, logger, name: 'Minting Wallet', polling: { interval: 50 } })).wallet; - await firstValueFrom(wallet.syncStatus.isSettled$.pipe(filter((isSettled) => isSettled))); + await walletReady(wallet); const params = await firstValueFrom(wallet.genesisParameters$); diff --git a/packages/e2e/test/wallet/SingleAddressWallet/pouchDbWalletStores.test.ts b/packages/e2e/test/wallet/SingleAddressWallet/pouchDbWalletStores.test.ts index 95fd5263f8e..0119707525a 100644 --- a/packages/e2e/test/wallet/SingleAddressWallet/pouchDbWalletStores.test.ts +++ b/packages/e2e/test/wallet/SingleAddressWallet/pouchDbWalletStores.test.ts @@ -3,7 +3,7 @@ import { filter, firstValueFrom } from 'rxjs'; import { getWallet } from '../../../src/factories'; import { logger } from '@cardano-sdk/util-dev'; import { storage } from '@cardano-sdk/wallet'; -import { waitForWalletStateSettle } from '../util'; +import { waitForWalletStateSettle, walletReady } from '../util'; import delay from 'delay'; describe('SingleAddressWallet/pouchDbWalletStores', () => { @@ -16,8 +16,10 @@ describe('SingleAddressWallet/pouchDbWalletStores', () => { it('stores and restores SingleAddressWallet, continues sync after initial load', async () => { const wallet1 = (await getWallet({ env, logger, name: 'Test Wallet', stores: stores1 })).wallet; + // wallet1 fetched all responses from wallet provider - await waitForWalletStateSettle(wallet1); + await walletReady(wallet1); + // give it a second to store data to PouchDb, this is technically a race condition await delay(1000); // loading reward accounts involves loading many other pieces (transactions, stake pools etc.) diff --git a/packages/e2e/test/wallet/SingleAddressWallet/txChaining.test.ts b/packages/e2e/test/wallet/SingleAddressWallet/txChaining.test.ts index ffad2daca0d..eee5e8d4cb8 100644 --- a/packages/e2e/test/wallet/SingleAddressWallet/txChaining.test.ts +++ b/packages/e2e/test/wallet/SingleAddressWallet/txChaining.test.ts @@ -4,7 +4,7 @@ import { env } from '../environment'; import { filter, firstValueFrom } from 'rxjs'; import { getWallet } from '../../../src/factories'; import { logger } from '@cardano-sdk/util-dev'; -import { waitForWalletStateSettle } from '../util'; +import { walletReady } from '../util'; describe('SingleAddressWallet', () => { let wallet: ObservableWallet; @@ -12,7 +12,8 @@ describe('SingleAddressWallet', () => { beforeAll(async () => { jest.setTimeout(180_000); wallet = (await getWallet({ env, logger, name: 'Test Wallet' })).wallet; - await waitForWalletStateSettle(wallet); + + await walletReady(wallet); }); afterAll(() => { diff --git a/packages/e2e/test/wallet/util.ts b/packages/e2e/test/wallet/util.ts index 538de5963c1..77017f624cc 100644 --- a/packages/e2e/test/wallet/util.ts +++ b/packages/e2e/test/wallet/util.ts @@ -1,10 +1,12 @@ -import { Observable, catchError, filter, firstValueFrom, throwError, timeout } from 'rxjs'; +import { Observable, catchError, combineLatest, filter, firstValueFrom, throwError, timeout } from 'rxjs'; import { ObservableWallet } from '@cardano-sdk/wallet'; const SECOND = 1000; const MINUTE = 60 * SECOND; export const TX_TIMEOUT = 7 * MINUTE; const SYNC_TIMEOUT = 3 * MINUTE; +const BALANCE_TIMEOUT = 3 * MINUTE; + export const FAST_OPERATION_TIMEOUT = 15 * SECOND; export const firstValueFromTimed = ( @@ -22,6 +24,22 @@ export const firstValueFromTimed = ( export const waitForWalletStateSettle = (wallet: ObservableWallet) => firstValueFromTimed( wallet.syncStatus.isSettled$.pipe(filter((isSettled) => isSettled)), - 'Took too long to load', + 'Took too long to settle', + SYNC_TIMEOUT + ); + +export const waitForWalletBalance = (wallet: ObservableWallet) => + firstValueFromTimed( + wallet.balance.utxo.total$.pipe(filter(({ coins }) => coins > 0)), + 'Took too long to load balance', + BALANCE_TIMEOUT + ); + +export const walletReady = (wallet: ObservableWallet) => + firstValueFromTimed( + combineLatest([wallet.syncStatus.isSettled$, wallet.balance.utxo.total$]).pipe( + filter(([isSettled, balance]) => isSettled && balance.coins > 0n) + ), + 'Took too long to be ready', SYNC_TIMEOUT );