aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-08-17 06:34:09 +0800
committerFabio Berger <me@fabioberger.com>2017-08-17 06:34:09 +0800
commita32b94bac440f127c0b984d7a1e763cf4cb86792 (patch)
tree22aa4b13e067017220c579958bcc8225a5b22a84 /test
parent6ec3c8728e639b74bd94ce222097fd0841bb0399 (diff)
downloaddexon-sol-tools-a32b94bac440f127c0b984d7a1e763cf4cb86792.tar
dexon-sol-tools-a32b94bac440f127c0b984d7a1e763cf4cb86792.tar.gz
dexon-sol-tools-a32b94bac440f127c0b984d7a1e763cf4cb86792.tar.bz2
dexon-sol-tools-a32b94bac440f127c0b984d7a1e763cf4cb86792.tar.lz
dexon-sol-tools-a32b94bac440f127c0b984d7a1e763cf4cb86792.tar.xz
dexon-sol-tools-a32b94bac440f127c0b984d7a1e763cf4cb86792.tar.zst
dexon-sol-tools-a32b94bac440f127c0b984d7a1e763cf4cb86792.zip
Remove isUserAddressAvailable assertion from getBalanceAsync and add regression test
Diffstat (limited to 'test')
-rw-r--r--test/token_wrapper_test.ts54
-rw-r--r--test/utils/web3_factory.ts10
2 files changed, 43 insertions, 21 deletions
diff --git a/test/token_wrapper_test.ts b/test/token_wrapper_test.ts
index 52a2507bf..d157efec4 100644
--- a/test/token_wrapper_test.ts
+++ b/test/token_wrapper_test.ts
@@ -149,25 +149,43 @@ describe('TokenWrapper', () => {
});
});
describe('#getBalanceAsync', () => {
- it('should return the balance for an existing ERC20 token', async () => {
- const token = tokens[0];
- const ownerAddress = coinbase;
- const balance = await zeroEx.token.getBalanceAsync(token.address, ownerAddress);
- const expectedBalance = new BigNumber('100000000000000000000000000');
- return expect(balance).to.be.bignumber.equal(expectedBalance);
+ describe('With web3 provider with accounts', () => {
+ it('should return the balance for an existing ERC20 token', async () => {
+ const token = tokens[0];
+ const ownerAddress = coinbase;
+ const balance = await zeroEx.token.getBalanceAsync(token.address, ownerAddress);
+ const expectedBalance = new BigNumber('100000000000000000000000000');
+ return expect(balance).to.be.bignumber.equal(expectedBalance);
+ });
+ it('should throw a CONTRACT_DOES_NOT_EXIST error for a non-existent token contract', async () => {
+ const nonExistentTokenAddress = '0x9dd402f14d67e001d8efbe6583e51bf9706aa065';
+ const ownerAddress = coinbase;
+ return expect(zeroEx.token.getBalanceAsync(nonExistentTokenAddress, ownerAddress))
+ .to.be.rejectedWith(ZeroExError.ContractDoesNotExist);
+ });
+ it('should return a balance of 0 for a non-existent owner address', async () => {
+ const token = tokens[0];
+ const nonExistentOwner = '0x198C6Ad858F213Fb31b6FE809E25040E6B964593';
+ const balance = await zeroEx.token.getBalanceAsync(token.address, nonExistentOwner);
+ const expectedBalance = new BigNumber(0);
+ return expect(balance).to.be.bignumber.equal(expectedBalance);
+ });
});
- it('should throw a CONTRACT_DOES_NOT_EXIST error for a non-existent token contract', async () => {
- const nonExistentTokenAddress = '0x9dd402f14d67e001d8efbe6583e51bf9706aa065';
- const ownerAddress = coinbase;
- return expect(zeroEx.token.getBalanceAsync(nonExistentTokenAddress, ownerAddress))
- .to.be.rejectedWith(ZeroExError.ContractDoesNotExist);
- });
- it('should return a balance of 0 for a non-existent owner address', async () => {
- const token = tokens[0];
- const nonExistentOwner = '0x198C6Ad858F213Fb31b6FE809E25040E6B964593';
- const balance = await zeroEx.token.getBalanceAsync(token.address, nonExistentOwner);
- const expectedBalance = new BigNumber(0);
- return expect(balance).to.be.bignumber.equal(expectedBalance);
+ describe('With web3 provider without accounts', () => {
+ let zeroExWithoutAccounts: ZeroEx;
+ before(async () => {
+ const hasAddresses = false;
+ const web3WithoutAccounts = web3Factory.create(hasAddresses);
+ web3WithoutAccounts.eth.getAccounts(console.log);
+ zeroExWithoutAccounts = new ZeroEx(web3WithoutAccounts.currentProvider);
+ });
+ it('should return balance even when called with Web3 provider instance without addresses', async () => {
+ const token = tokens[0];
+ const ownerAddress = coinbase;
+ const balance = await zeroExWithoutAccounts.token.getBalanceAsync(token.address, ownerAddress);
+ const expectedBalance = new BigNumber('100000000000000000000000000');
+ return expect(balance).to.be.bignumber.equal(expectedBalance);
+ });
});
});
describe('#setAllowanceAsync', () => {
diff --git a/test/utils/web3_factory.ts b/test/utils/web3_factory.ts
index ffdc0e4cf..f89c907f6 100644
--- a/test/utils/web3_factory.ts
+++ b/test/utils/web3_factory.ts
@@ -7,17 +7,21 @@ import ProviderEngine = require('web3-provider-engine');
import RpcSubprovider = require('web3-provider-engine/subproviders/rpc');
import * as Web3 from 'web3';
import {constants} from './constants';
+import {EmptyWalletSubProvider} from '../../src/subproviders/empty_wallet_subprovider';
export const web3Factory = {
- create(): Web3 {
- const provider = this.getRpcProvider();
+ create(hasAddresses: boolean = true): Web3 {
+ const provider = this.getRpcProvider(hasAddresses);
const web3 = new Web3();
web3.setProvider(provider);
return web3;
},
- getRpcProvider(): Web3.Provider {
+ getRpcProvider(hasAddresses: boolean): Web3.Provider {
const provider = new ProviderEngine();
const rpcUrl = `http://${constants.RPC_HOST}:${constants.RPC_PORT}`;
+ if (!hasAddresses) {
+ provider.addProvider(new EmptyWalletSubProvider());
+ }
provider.addProvider(new RpcSubprovider({
rpcUrl,
}));