aboutsummaryrefslogtreecommitdiffstats
path: root/packages/web3-wrapper/test
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-07-04 14:54:43 +0800
committerFabio Berger <me@fabioberger.com>2018-07-04 14:54:43 +0800
commitcd766ea2a1fb56282fc45a1a19d991bbcae8db99 (patch)
tree2e7c8dc464131b3afae269b7384a21d5d6c802a2 /packages/web3-wrapper/test
parent590033bcb27c9e8299c1cb56b75f9a64d674affb (diff)
downloaddexon-sol-tools-cd766ea2a1fb56282fc45a1a19d991bbcae8db99.tar
dexon-sol-tools-cd766ea2a1fb56282fc45a1a19d991bbcae8db99.tar.gz
dexon-sol-tools-cd766ea2a1fb56282fc45a1a19d991bbcae8db99.tar.bz2
dexon-sol-tools-cd766ea2a1fb56282fc45a1a19d991bbcae8db99.tar.lz
dexon-sol-tools-cd766ea2a1fb56282fc45a1a19d991bbcae8db99.tar.xz
dexon-sol-tools-cd766ea2a1fb56282fc45a1a19d991bbcae8db99.tar.zst
dexon-sol-tools-cd766ea2a1fb56282fc45a1a19d991bbcae8db99.zip
Add more assertions to Web3Wrapper public methods
Diffstat (limited to 'packages/web3-wrapper/test')
-rw-r--r--packages/web3-wrapper/test/web3_wrapper_test.ts50
1 files changed, 50 insertions, 0 deletions
diff --git a/packages/web3-wrapper/test/web3_wrapper_test.ts b/packages/web3-wrapper/test/web3_wrapper_test.ts
index 35eab3aa2..8919775c2 100644
--- a/packages/web3-wrapper/test/web3_wrapper_test.ts
+++ b/packages/web3-wrapper/test/web3_wrapper_test.ts
@@ -1,4 +1,5 @@
import * as chai from 'chai';
+import { BlockParamLiteral } from 'ethereum-types';
import * as Ganache from 'ganache-core';
import 'mocha';
@@ -9,6 +10,8 @@ chaiSetup.configure();
const { expect } = chai;
+const NUM_GANACHE_ADDRESSES = 10;
+
describe('Web3Wrapper tests', () => {
const NETWORK_ID = 50;
const provider = Ganache.provider({ network_id: NETWORK_ID });
@@ -36,4 +39,51 @@ describe('Web3Wrapper tests', () => {
expect(networkId).to.be.equal(NETWORK_ID);
});
});
+ describe('#getNetworkIdAsync', () => {
+ it('gets the network id', async () => {
+ const networkId = await web3Wrapper.getNetworkIdAsync();
+ expect(networkId).to.be.equal(NETWORK_ID);
+ });
+ });
+ describe('#getAvailableAddressesAsync', () => {
+ it('gets the available addresses', async () => {
+ const addresses = await web3Wrapper.getAvailableAddressesAsync();
+ expect(addresses.length).to.be.equal(NUM_GANACHE_ADDRESSES);
+ });
+ });
+ describe('#getBalanceInWeiAsync', () => {
+ it('gets the users balance in wei', async () => {
+ const addresses = await web3Wrapper.getAvailableAddressesAsync();
+ const secondAccount = addresses[1];
+ const balanceInWei = await web3Wrapper.getBalanceInWeiAsync(secondAccount);
+ const tenEthInWei = 100000000000000000000;
+ expect(balanceInWei).to.be.bignumber.equal(tenEthInWei);
+ });
+ it('should throw if supplied owner not an Ethereum address hex string', async () => {
+ const invalidEthAddress = 'deadbeef';
+ expect(web3Wrapper.getBalanceInWeiAsync(invalidEthAddress)).to.eventually.to.be.rejected();
+ });
+ });
+ describe('#getBlockAsync', () => {
+ 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);
+ });
+ 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);
+ });
+ 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);
+ });
+ it('should throw if supplied invalid blockParam value', async () => {
+ const invalidBlockParam = 'deadbeef';
+ expect(web3Wrapper.getBlockAsync(invalidBlockParam)).to.eventually.to.be.rejected();
+ });
+ });
});