Skip to content

Commit

Permalink
refactor(e2e): check wallet balance before running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceahasegan committed Mar 17, 2023
1 parent cdfdc15 commit 450dd33
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 15 deletions.
Expand Up @@ -87,14 +87,13 @@ describe('SingleAddressWallet/delegation', () => {
// source wallet has the highest balance to begin with
const [sourceWallet, destWallet] = await chooseWallets();

await walletReady(sourceWallet);
const tx1OutputCoins = 1_000_000n;
await walletReady(sourceWallet, tx1OutputCoins);

const protocolParameters = await firstValueFrom(sourceWallet.protocolParameters$);
const stakeKeyDeposit = BigInt(protocolParameters.stakeKeyDeposit);
const initialState = await getWalletStateSnapshot(sourceWallet);
expect(initialState.balance.total.coins).toBeGreaterThan(0n);
expect(initialState.balance.total.coins).toBe(initialState.balance.available.coins);
const tx1OutputCoins = 1_000_000n;
const poolId = await chooseDifferentPoolIdRandomly(initialState.rewardAccount.delegatee?.nextNextEpoch?.id);
expect(poolId).toBeDefined();
const initialDeposit = initialState.isStakeKeyRegistered ? stakeKeyDeposit : 0n;
Expand Down
3 changes: 3 additions & 0 deletions packages/e2e/test/wallet/SingleAddressWallet/metadata.test.ts
Expand Up @@ -26,6 +26,9 @@ describe('SingleAddressWallet/metadata', () => {
const walletUtil = createWalletUtil(wallet);
const { minimumCoin } = await walletUtil.validateValue({ coins: 0n });

// Make sure the wallet has sufficient funds to run this test
walletReady(wallet, minimumCoin);

Check failure on line 30 in packages/e2e/test/wallet/SingleAddressWallet/metadata.test.ts

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-20.04)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

const builtTx = await buildTx({ logger, observableWallet: wallet })
.addOutput({ address: ownAddress, value: { coins: minimumCoin } })
.setMetadata(metadata)
Expand Down
5 changes: 3 additions & 2 deletions packages/e2e/test/wallet/SingleAddressWallet/mint.test.ts
Expand Up @@ -20,7 +20,8 @@ describe('SingleAddressWallet/mint', () => {
it('can mint a token with no asset name', async () => {
wallet = (await getWallet({ env, logger, name: 'Minting Wallet', polling: { interval: 50 } })).wallet;

await walletReady(wallet);
const coins = 3_000_000n;
await walletReady(wallet, coins);

const genesis = await firstValueFrom(wallet.genesisParameters$);

Expand Down Expand Up @@ -65,7 +66,7 @@ describe('SingleAddressWallet/mint', () => {
address: walletAddress,
value: {
assets: tokens,
coins: 3_000_000n
coins
}
}
]),
Expand Down
Expand Up @@ -21,7 +21,8 @@ describe('SingleAddressWallet/multisignature', () => {
it('can create a transaction with multiple signatures to mint an asset', async () => {
wallet = (await getWallet({ env, logger, name: 'Minting Wallet', polling: { interval: 50 } })).wallet;

await walletReady(wallet);
const coins = 3_000_000n;
await walletReady(wallet, coins);

const genesis = await firstValueFrom(wallet.genesisParameters$);

Expand Down Expand Up @@ -85,7 +86,7 @@ describe('SingleAddressWallet/multisignature', () => {
address: walletAddress,
value: {
assets: tokens,
coins: 3_000_000n
coins
}
}
]),
Expand Down
15 changes: 11 additions & 4 deletions packages/e2e/test/wallet/SingleAddressWallet/nft.test.ts
Expand Up @@ -24,11 +24,12 @@ describe('SingleAddressWallet.assets/nft', () => {
const assetNames = ['4e46542d66696c6573', '4e46542d303031', '4e46542d303032'];
let walletAddress: Cardano.PaymentAddress;
let allMintedTokens: Cardano.TokenMap = new Map();
const coins = 10_000_000n; // number of coins to use in each transaction

beforeAll(async () => {
wallet = (await getWallet({ env, logger, name: 'Minting Wallet', polling: { interval: 50 } })).wallet;

await walletReady(wallet);
await walletReady(wallet, coins);

const genesis = await firstValueFrom(wallet.genesisParameters$);

Expand Down Expand Up @@ -132,7 +133,7 @@ describe('SingleAddressWallet.assets/nft', () => {
address: walletAddress,
value: {
assets: tokens,
coins: 50_000_000n
coins
}
}
]),
Expand Down Expand Up @@ -255,6 +256,9 @@ describe('SingleAddressWallet.assets/nft', () => {
});

it('supports burning tokens', async () => {
// Make sure the wallet has sufficient funds to run this test
walletReady(wallet, coins);

Check failure on line 260 in packages/e2e/test/wallet/SingleAddressWallet/nft.test.ts

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-20.04)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

// spend entire balance of test asset
const availableBalance = await firstValueFrom(wallet.balance.utxo.available$);
const assetBalance = availableBalance.assets!.get(assetIds[TOKEN_BURN_INDEX])!;
Expand All @@ -265,7 +269,7 @@ describe('SingleAddressWallet.assets/nft', () => {
{
address: walletAddress,
value: {
coins: 50_000_000n
coins
}
}
]),
Expand Down Expand Up @@ -305,6 +309,9 @@ describe('SingleAddressWallet.assets/nft', () => {
// eslint-disable-next-line unicorn/consistent-function-scoping
const CIP0025Test = (testName: string, assetName: string, version: 1 | 2, encoding?: 'hex' | 'utf8') =>
it(testName, async () => {
// Make sure the wallet has sufficient funds to run this test
walletReady(wallet, coins);

Check failure on line 313 in packages/e2e/test/wallet/SingleAddressWallet/nft.test.ts

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-20.04)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

const assetNameHex = Buffer.from(assetName).toString('hex');
const assetId = Cardano.AssetId(`${policyId}${assetNameHex}`);
const fingerprint = Cardano.AssetFingerprint.fromParts(policyId, Cardano.AssetName(assetNameHex));
Expand Down Expand Up @@ -336,7 +343,7 @@ describe('SingleAddressWallet.assets/nft', () => {
address: walletAddress,
value: {
assets: tokens,
coins: 50_000_000n
coins
}
}
]),
Expand Down
Expand Up @@ -5,7 +5,7 @@ import { filter, firstValueFrom, map, take } from 'rxjs';
import { getEnv, getWallet, walletVariables } from '../../../src';
import { isNotNil } from '@cardano-sdk/util';
import { logger } from '@cardano-sdk/util-dev';
import { normalizeTxBody } from '../../util';
import { normalizeTxBody, walletReady } from '../../util';

const env = getEnv(walletVariables);

Expand All @@ -22,6 +22,8 @@ describe('SingleAddressWallet/txChainHistory', () => {

it('submit a transaction and find it in chain history', async () => {
const tAdaToSend = 10_000_000n;
// Make sure the wallet has sufficient funds to run this test
walletReady(wallet, tAdaToSend);

Check failure on line 26 in packages/e2e/test/wallet/SingleAddressWallet/txChainHistory.test.ts

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-20.04)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

await firstValueFrom(wallet.syncStatus.isSettled$.pipe(filter((isSettled) => isSettled)));

Expand Down
Expand Up @@ -13,7 +13,7 @@ describe('SingleAddressWallet/txChaining', () => {
jest.setTimeout(180_000);
wallet = (await getWallet({ env, logger, name: 'Test Wallet' })).wallet;

await walletReady(wallet);
await walletReady(wallet, 1_000_000n);
});

afterAll(() => {
Expand Down
Expand Up @@ -25,8 +25,9 @@ describe('SingleAddressWallet/unspendableUtxos', () => {
wallet1 = (await getWallet({ env, logger, name: 'Wallet 1', polling: { interval: 50 } })).wallet;
wallet2 = (await getWallet({ env, logger, name: 'Wallet 2', polling: { interval: 50 } })).wallet;

await walletReady(wallet1);
await walletReady(wallet2);
const coins = 5_000_000n;
await walletReady(wallet1, coins);
await walletReady(wallet2, coins);

const txBuilder1 = buildTx({ logger, observableWallet: wallet1 });
const txBuilder2 = buildTx({ logger, observableWallet: wallet2 });
Expand Down

0 comments on commit 450dd33

Please sign in to comment.