aboutsummaryrefslogtreecommitdiffstats
path: root/packages/web3-wrapper/test
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-07-05 06:36:01 +0800
committerFabio Berger <me@fabioberger.com>2018-07-05 06:36:01 +0800
commit1050ecdf3c9e0dbc881342b8ff377180ed1b0dad (patch)
tree5f1fd590b3a21237eaf35c8cb8e68b069be46ce8 /packages/web3-wrapper/test
parentd712dc47d97d3051e2938bf11b9088aba657b869 (diff)
downloaddexon-0x-contracts-1050ecdf3c9e0dbc881342b8ff377180ed1b0dad.tar
dexon-0x-contracts-1050ecdf3c9e0dbc881342b8ff377180ed1b0dad.tar.gz
dexon-0x-contracts-1050ecdf3c9e0dbc881342b8ff377180ed1b0dad.tar.bz2
dexon-0x-contracts-1050ecdf3c9e0dbc881342b8ff377180ed1b0dad.tar.lz
dexon-0x-contracts-1050ecdf3c9e0dbc881342b8ff377180ed1b0dad.tar.xz
dexon-0x-contracts-1050ecdf3c9e0dbc881342b8ff377180ed1b0dad.tar.zst
dexon-0x-contracts-1050ecdf3c9e0dbc881342b8ff377180ed1b0dad.zip
Refactor Web3Wrapper to no longer use Web3.js & add more test coverage
Diffstat (limited to 'packages/web3-wrapper/test')
-rw-r--r--packages/web3-wrapper/test/web3_wrapper_test.ts51
1 files changed, 47 insertions, 4 deletions
diff --git a/packages/web3-wrapper/test/web3_wrapper_test.ts b/packages/web3-wrapper/test/web3_wrapper_test.ts
index 8919775c2..b4fd8bb44 100644
--- a/packages/web3-wrapper/test/web3_wrapper_test.ts
+++ b/packages/web3-wrapper/test/web3_wrapper_test.ts
@@ -1,9 +1,11 @@
import * as chai from 'chai';
import { BlockParamLiteral } from 'ethereum-types';
import * as Ganache from 'ganache-core';
+import * as _ from 'lodash';
import 'mocha';
-import { Web3Wrapper } from '../src';
+import { utils } from '../src/utils';
+import { Web3Wrapper } from '../src/web3_wrapper';
import { chaiSetup } from './utils/chai_setup';
chaiSetup.configure();
@@ -16,6 +18,10 @@ describe('Web3Wrapper tests', () => {
const NETWORK_ID = 50;
const provider = Ganache.provider({ network_id: NETWORK_ID });
const web3Wrapper = new Web3Wrapper(provider);
+ let addresses: string[];
+ before(async () => {
+ addresses = await web3Wrapper.getAvailableAddressesAsync();
+ });
describe('#isAddress', () => {
it('correctly checks if a string is a valid ethereum address', () => {
expect(Web3Wrapper.isAddress('0x0')).to.be.false();
@@ -47,13 +53,13 @@ describe('Web3Wrapper tests', () => {
});
describe('#getAvailableAddressesAsync', () => {
it('gets the available addresses', async () => {
- const addresses = await web3Wrapper.getAvailableAddressesAsync();
- expect(addresses.length).to.be.equal(NUM_GANACHE_ADDRESSES);
+ const availableAddresses = await web3Wrapper.getAvailableAddressesAsync();
+ expect(availableAddresses.length).to.be.equal(NUM_GANACHE_ADDRESSES);
+ expect(Web3Wrapper.isAddress(availableAddresses[0])).to.equal(true);
});
});
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;
@@ -64,11 +70,28 @@ describe('Web3Wrapper tests', () => {
expect(web3Wrapper.getBalanceInWeiAsync(invalidEthAddress)).to.eventually.to.be.rejected();
});
});
+ describe('#signMessageAsync', () => {
+ it('should sign message', async () => {
+ const message = '0xdeadbeef';
+ const signer = addresses[1];
+ const signature = await web3Wrapper.signMessageAsync(signer, message);
+ const signatureLength = 132;
+ expect(signature.length).to.be.equal(signatureLength);
+ });
+ });
+ describe('#getBlockNumberAsync', () => {
+ it('get block number', async () => {
+ const blockNumber = await web3Wrapper.getBlockNumberAsync();
+ expect(typeof blockNumber).to.be.equal('number');
+ });
+ });
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);
+ expect(utils.isBigNumber(block.difficulty)).to.equal(true);
+ expect(_.isNumber(block.gasLimit)).to.equal(true);
});
it('gets block when supplied a block number', async () => {
const blockParamLiteral = 0;
@@ -86,4 +109,24 @@ describe('Web3Wrapper tests', () => {
expect(web3Wrapper.getBlockAsync(invalidBlockParam)).to.eventually.to.be.rejected();
});
});
+ describe('#getBlockWithTransactionDataAsync', () => {
+ it('gets block when supplied a valid BlockParamLiteral value', async () => {
+ const blockParamLiteral = BlockParamLiteral.Earliest;
+ const block = await web3Wrapper.getBlockWithTransactionDataAsync(blockParamLiteral);
+ expect(block.number).to.be.equal(0);
+ expect(utils.isBigNumber(block.difficulty)).to.equal(true);
+ expect(_.isNumber(block.gasLimit)).to.equal(true);
+ });
+ it('should throw if supplied invalid blockParam value', async () => {
+ const invalidBlockParam = 'deadbeef';
+ expect(web3Wrapper.getBlockWithTransactionDataAsync(invalidBlockParam)).to.eventually.to.be.rejected();
+ });
+ });
+ describe('#getBlockTimestampAsync', () => {
+ it('gets block timestamp', async () => {
+ const blockParamLiteral = BlockParamLiteral.Earliest;
+ const timestamp = await web3Wrapper.getBlockTimestampAsync(blockParamLiteral);
+ expect(_.isNumber(timestamp)).to.be.equal(true);
+ });
+ });
});