Skip to content

Commit

Permalink
feat: 🎸 fix flakey createAsset test
Browse files Browse the repository at this point in the history
  • Loading branch information
sansan committed Oct 1, 2024
1 parent 42995de commit e58266c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/__tests__/sdk/assets/createAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { KnownAssetType, SecurityIdentifierType } from '@polymeshassociation/pol

import { TestFactory } from '~/helpers';
import { createAsset } from '~/sdk/assets/createAsset';
import { awaitMiddlewareSynced } from '~/util';

let factory: TestFactory;

Expand Down Expand Up @@ -44,14 +45,11 @@ describe('createAsset', () => {
// Validates arguments (e.g. ticker is not taken) and returns a Transaction to be ran.
const createAssetTx = await sdk.assets.createAsset(params);

const middlewareSyncedOnAsset = () =>
new Promise((resolve) => createAssetTx.onProcessedByMiddleware(resolve));

const asset = await createAssetTx.run();

expect(asset.ticker).toEqual(params.ticker);

await middlewareSyncedOnAsset();
await awaitMiddlewareSynced(createAssetTx, sdk, 15, 2000);

const createdAt = await asset.createdAt();

Expand Down
4 changes: 2 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export const awaitMiddlewareSynced = async (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
tx: GenericPolymeshTransaction<any, any>,
sdk: Polymesh,
retries: number,
delay: number
retries = 15,
delay = 2000
): Promise<void> => {
if (![TransactionStatus.Succeeded, TransactionStatus.Failed].includes(tx.status)) {
throw new Error('Transaction was not successful or failed and does not have a block number');
Expand Down

0 comments on commit e58266c

Please sign in to comment.