From d0448c2bbd90c6c103f07b201886670dc4675a43 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 24 Sep 2018 15:02:06 +0100 Subject: Fix bug where if block wasn't found, getBlockAsync would throw. Now it returns `undefined` --- packages/contracts/test/multisig/multi_sig_with_time_lock.ts | 5 ++++- packages/contracts/test/utils/block_timestamp.ts | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/test/multisig/multi_sig_with_time_lock.ts b/packages/contracts/test/multisig/multi_sig_with_time_lock.ts index 05d8bbb36..0b17c298b 100644 --- a/packages/contracts/test/multisig/multi_sig_with_time_lock.ts +++ b/packages/contracts/test/multisig/multi_sig_with_time_lock.ts @@ -269,7 +269,10 @@ describe('MultiSigWalletWithTimeLock', () => { expect(confirmRes.logs).to.have.length(2); const blockNum = await web3Wrapper.getBlockNumberAsync(); - const blockInfo = await web3Wrapper.getBlockAsync(blockNum); + const blockInfo = await web3Wrapper.getBlockIfExistsAsync(blockNum); + if (_.isUndefined(blockInfo)) { + throw new Error(`Unexpectedly failed to fetch block at #${blockNum}`); + } const timestamp = new BigNumber(blockInfo.timestamp); const confirmationTimeBigNum = new BigNumber(await multiSig.confirmationTimes.callAsync(txId)); diff --git a/packages/contracts/test/utils/block_timestamp.ts b/packages/contracts/test/utils/block_timestamp.ts index 1159792c4..66c13eed1 100644 --- a/packages/contracts/test/utils/block_timestamp.ts +++ b/packages/contracts/test/utils/block_timestamp.ts @@ -35,6 +35,9 @@ export async function increaseTimeAndMineBlockAsync(seconds: number): Promise { - const currentBlock = await web3Wrapper.getBlockAsync('latest'); - return currentBlock.timestamp; + const currentBlockIfExists = await web3Wrapper.getBlockIfExistsAsync('latest'); + if (_.isUndefined(currentBlockIfExists)) { + throw new Error(`Unable to fetch latest block.`); + } + return currentBlockIfExists.timestamp; } -- cgit v1.2.3