Producing 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.
ts
See code in contextconst provider = await Provider.create(FUEL_NETWORK_URL);
const block = await provider.getBlock('latest');
if (!block) {
throw new Error('No latest block');
}
const { time: timeLastBlockProduced } = block;
const amountOfBlocksToProduce = 3;
const producedBlockHeigh = await provider.produceBlocks(amountOfBlocksToProduce);
const producedBlock = await provider.getBlock(producedBlockHeigh.toNumber());
expect(producedBlock).toBeDefined();
const oldest: Date = DateTime.fromTai64(timeLastBlockProduced);
const newest: Date = DateTime.fromTai64(producedBlock?.time || DateTime.TAI64_NULL);
expect(newest >= oldest).toBeTruthy();
Producing Blocks With Custom Timestamps
You can also produce blocks with a custom block time using the produceBlocks
helper by specifying the second optional parameter.
ts
See code in contextconst lastBlockTimestamp = DateTime.fromTai64(latestBlock.time).toUnixMilliseconds();
const latestBlockNumber = await provider.produceBlocks(3, lastBlockTimestamp + 1000);