Icon LinkProducing Blocks

You can force-produce blocks using the produceBlocks helper to achieve an arbitrary block height. This is especially useful when you want to do some testing regarding transaction maturity.

const provider = new Provider('http://127.0.0.1:4000/graphql');
 
const block = await provider.getBlock('latest');
if (!block) {
	throw new Error('No latest block');
}
const { height: latestBlockNumberBeforeProduce } = block;
 
const amountOfBlocksToProduce = 3;
const latestBlockNumber = await provider.produceBlocks(amountOfBlocksToProduce);
 
expect(latestBlockNumber.toHex()).toEqual(
	latestBlockNumberBeforeProduce.add(amountOfBlocksToProduce).toHex()
);

Icon LinkProducing Blocks With Custom Timestamps

You can also produce blocks with a custom block time using the produceBlocks helper by specifying the second optional parameter.

	const lastBlockTimestamp = fromTai64ToUnix(latestBlock.time);
	const latestBlockNumber = await provider.produceBlocks(3, lastBlockTimestamp + 1000);