aboutsummaryrefslogtreecommitdiffstats
path: root/packages/web3-wrapper/test
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-09-24 22:02:06 +0800
committerFabio Berger <me@fabioberger.com>2018-09-24 22:02:06 +0800
commitd0448c2bbd90c6c103f07b201886670dc4675a43 (patch)
tree27ef6bcf5d1fbdc27045228d8e633b9a4a4d062a /packages/web3-wrapper/test
parent8bce407aec414fbaf80a7132bdf43c5b9f66247b (diff)
downloaddexon-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/web3-wrapper/test')
-rw-r--r--packages/web3-wrapper/test/web3_wrapper_test.ts34
1 files changed, 23 insertions, 11 deletions
diff --git a/packages/web3-wrapper/test/web3_wrapper_test.ts b/packages/web3-wrapper/test/web3_wrapper_test.ts
index b4fd8bb44..385c469bf 100644
--- a/packages/web3-wrapper/test/web3_wrapper_test.ts
+++ b/packages/web3-wrapper/test/web3_wrapper_test.ts
@@ -85,28 +85,40 @@ describe('Web3Wrapper tests', () => {
expect(typeof blockNumber).to.be.equal('number');
});
});
- describe('#getBlockAsync', () => {
+ describe('#getBlockIfExistsAsync', () => {
it('gets block when supplied a valid BlockParamLiteral value', async () => {
const blockParamLiteral = BlockParamLiteral.Earliest;
- const block = await web3Wrapper.getBlockAsync(blockParamLiteral);
- expect(block.number).to.be.equal(0);
- expect(utils.isBigNumber(block.difficulty)).to.equal(true);
- expect(_.isNumber(block.gasLimit)).to.equal(true);
+ const blockIfExists = await web3Wrapper.getBlockIfExistsAsync(blockParamLiteral);
+ if (_.isUndefined(blockIfExists)) {
+ throw new Error('Expected block to exist');
+ }
+ expect(blockIfExists.number).to.be.equal(0);
+ expect(utils.isBigNumber(blockIfExists.difficulty)).to.equal(true);
+ expect(_.isNumber(blockIfExists.gasLimit)).to.equal(true);
});
it('gets block when supplied a block number', async () => {
const blockParamLiteral = 0;
- const block = await web3Wrapper.getBlockAsync(blockParamLiteral);
- expect(block.number).to.be.equal(0);
+ const blockIfExists = await web3Wrapper.getBlockIfExistsAsync(blockParamLiteral);
+ if (_.isUndefined(blockIfExists)) {
+ throw new Error('Expected block to exist');
+ }
+ expect(blockIfExists.number).to.be.equal(0);
});
it('gets block when supplied a block hash', async () => {
const blockParamLiteral = 0;
- const block = await web3Wrapper.getBlockAsync(blockParamLiteral);
- const sameBlock = await web3Wrapper.getBlockAsync(block.hash as string);
- expect(sameBlock.number).to.be.equal(0);
+ const blockIfExists = await web3Wrapper.getBlockIfExistsAsync(blockParamLiteral);
+ if (_.isUndefined(blockIfExists)) {
+ throw new Error('Expected block to exist');
+ }
+ const sameBlockIfExists = await web3Wrapper.getBlockIfExistsAsync(blockIfExists.hash as string);
+ if (_.isUndefined(sameBlockIfExists)) {
+ throw new Error('Expected block to exist');
+ }
+ expect(sameBlockIfExists.number).to.be.equal(0);
});
it('should throw if supplied invalid blockParam value', async () => {
const invalidBlockParam = 'deadbeef';
- expect(web3Wrapper.getBlockAsync(invalidBlockParam)).to.eventually.to.be.rejected();
+ expect(web3Wrapper.getBlockIfExistsAsync(invalidBlockParam)).to.eventually.to.be.rejected();
});
});
describe('#getBlockWithTransactionDataAsync', () => {