Skip to content

Commit 4e622b7

Browse files
committed
fixup! test(e2e): hoist some utils out of rewards test
1 parent e40f638 commit 4e622b7

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

packages/e2e/test/wallet/SingleAddressWallet/delegation-rewards.test.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { TestWallet, getWallet } from '../../../src';
55
import { assertTxIsValid, waitForWalletStateSettle } from '../../../../wallet/test/util';
66
import { filter, firstValueFrom } from 'rxjs';
77
import { logger } from '@cardano-sdk/util-dev';
8-
import { requestCoins, submitAndConfirm, transferCoins, waitForEpoch } from '../util';
8+
import { requestCoins, runningAgainstLocalNetwork, submitAndConfirm, transferCoins, waitForEpoch } from '../util';
99

1010
// Verify environment.
1111
export const env = envalid.cleanEnv(process.env, {
@@ -58,12 +58,7 @@ describe('delegation rewards', () => {
5858
});
5959

6060
it('will receive rewards for delegated tADA and can spend them', async () => {
61-
const { epochLength, slotLength } = await providers.networkInfoProvider.genesisParameters();
62-
63-
const estimatedTestDurationInEpochs = 4;
64-
const localNetworkEpochDuration = 1000 * 0.2;
65-
const estimatedTestDuration = epochLength * slotLength * estimatedTestDurationInEpochs;
66-
if (estimatedTestDuration > localNetworkEpochDuration * estimatedTestDurationInEpochs) {
61+
if (!(await runningAgainstLocalNetwork())) {
6762
return logger.fatal(
6863
"Skipping test 'will receive rewards for delegated tADA' as it should only run with a fast test network"
6964
);

packages/e2e/test/wallet/util.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import {
1919
} from 'rxjs';
2020
import { ObservableWallet, SignedTx, buildTx } from '@cardano-sdk/wallet';
2121
import { assertTxIsValid } from '../../../wallet/test/util';
22-
import { faucetProviderFactory } from '../../src';
22+
import { env } from './environment';
23+
import { faucetProviderFactory, networkInfoProviderFactory } from '../../src';
2324
import { logger } from '@cardano-sdk/util-dev';
2425
import sortBy from 'lodash/sortBy';
2526

@@ -121,12 +122,12 @@ export const requestCoins = async ({ coins, wallet }: RequestCoinsProps) => {
121122
const [{ address }] = await firstValueFrom(wallet.addresses$);
122123
logger.info(`Address ${address.toString()} will be funded with ${coins} tLovelace.`);
123124

124-
const env = envalid.cleanEnv(process.env, {
125+
const { FAUCET_PROVIDER, FAUCET_PROVIDER_PARAMS } = envalid.cleanEnv(process.env, {
125126
FAUCET_PROVIDER: envalid.str(),
126127
FAUCET_PROVIDER_PARAMS: envalid.json({ default: {} })
127128
});
128129

129-
const faucetProvider = await faucetProviderFactory.create(env.FAUCET_PROVIDER, env.FAUCET_PROVIDER_PARAMS, logger);
130+
const faucetProvider = await faucetProviderFactory.create(FAUCET_PROVIDER, FAUCET_PROVIDER_PARAMS, logger);
130131
await faucetProvider.start();
131132
const healthCheck = await faucetProvider.healthCheck();
132133
if (!healthCheck.ok) throw new Error('Faucet provider could not be started.');
@@ -176,3 +177,20 @@ export const waitForEpoch = (wallet: Pick<ObservableWallet, 'currentEpoch$'>, wa
176177
)
177178
);
178179
};
180+
181+
export const runningAgainstLocalNetwork = async () => {
182+
const networkInfoProvider = await networkInfoProviderFactory.create(
183+
env.NETWORK_INFO_PROVIDER,
184+
env.NETWORK_INFO_PROVIDER_PARAMS,
185+
logger
186+
);
187+
const { epochLength, slotLength } = await networkInfoProvider.genesisParameters();
188+
189+
const estimatedTestDurationInEpochs = 4;
190+
const localNetworkEpochDuration = 1000 * 0.2;
191+
const estimatedTestDuration = epochLength * slotLength * estimatedTestDurationInEpochs;
192+
if (estimatedTestDuration > localNetworkEpochDuration * estimatedTestDurationInEpochs) {
193+
return false;
194+
}
195+
return true;
196+
};

0 commit comments

Comments
 (0)