Fix bug where if block wasn't found, getBlockAsync would throw. Now it returns undefined

This commit is contained in:
Fabio Berger
2018-09-24 15:02:06 +01:00
parent 8bce407aec
commit d0448c2bbd
7 changed files with 78 additions and 31 deletions

View File

@@ -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));

View File

@@ -35,6 +35,9 @@ export async function increaseTimeAndMineBlockAsync(seconds: number): Promise<nu
* @returns a new Promise which will resolve with the timestamp in seconds.
*/
export async function getLatestBlockTimestampAsync(): Promise<number> {
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;
}