git.delta.rocks / unique-network / refs/commits / 061409929b86

difftreelog

source

tests/src/substrate/wait-new-blocks.ts565 Bsourcehistory
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import { ApiPromise } from "@polkadot/api";78export default function waitNewBlocks(api: ApiPromise, blocksCount: number = 1): Promise<void> {9  const promise = new Promise<void>(async (resolve, reject) => {10    11    const unsubscribe = await api.rpc.chain.subscribeNewHeads(head => {12      if(blocksCount > 0) {13        blocksCount--;14      }else {15        unsubscribe();16        resolve();17      }18    });19  });2021  return promise;22}