diff options
author | Fabio Berger <me@fabioberger.com> | 2018-09-24 22:02:06 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-09-24 22:02:06 +0800 |
commit | d0448c2bbd90c6c103f07b201886670dc4675a43 (patch) | |
tree | 27ef6bcf5d1fbdc27045228d8e633b9a4a4d062a /packages/contracts/test/utils | |
parent | 8bce407aec414fbaf80a7132bdf43c5b9f66247b (diff) | |
download | dexon-sol-tools-d0448c2bbd90c6c103f07b201886670dc4675a43.tar dexon-sol-tools-d0448c2bbd90c6c103f07b201886670dc4675a43.tar.gz dexon-sol-tools-d0448c2bbd90c6c103f07b201886670dc4675a43.tar.bz2 dexon-sol-tools-d0448c2bbd90c6c103f07b201886670dc4675a43.tar.lz dexon-sol-tools-d0448c2bbd90c6c103f07b201886670dc4675a43.tar.xz dexon-sol-tools-d0448c2bbd90c6c103f07b201886670dc4675a43.tar.zst dexon-sol-tools-d0448c2bbd90c6c103f07b201886670dc4675a43.zip |
Fix bug where if block wasn't found, getBlockAsync would throw. Now it returns `undefined`
Diffstat (limited to 'packages/contracts/test/utils')
-rw-r--r-- | packages/contracts/test/utils/block_timestamp.ts | 7 |
1 files changed, 5 insertions, 2 deletions
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<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; } |