git.delta.rocks / unique-network / refs/commits / e4dd4c0eeff5

difftreelog

source

tests/src/blocks-production.test.ts1.1 KiBsourcehistory
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 usingApi from "./substrate/substrate-api";7import { expect } from "chai";8import { ApiPromise } from "@polkadot/api";910const BlockTimeMs = 6000;11const ToleranceMs = 1000;1213async function getBlocks(api: ApiPromise): Promise<number[]> {14  return new Promise<number[]>(async (resolve, reject) => {15    const blockNumbers: number[] = [];16    setTimeout(() => reject('Block production test failed due to timeout.'), BlockTimeMs + ToleranceMs);17    const unsubscribe = await api.rpc.chain.subscribeNewHeads((head) => {18      blockNumbers.push(head.number.toNumber());19      if(blockNumbers.length >= 2) {20        unsubscribe();21        resolve(blockNumbers);22      }23    });24  });25}2627describe('Block Production smoke test', () => {28  it('Node produces new blocks', async () => {29    await usingApi(async (api) => {30      let blocks: number[] | undefined = await getBlocks(api);31      expect(blocks[0]).to.be.lessThan(blocks[1]);32    });33  });34});