aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/0x.js_test.ts28
-rw-r--r--test/ether_token_wrapper_test.ts6
-rw-r--r--test/exchange_wrapper_test.ts70
-rw-r--r--test/token_wrapper_test.ts7
-rw-r--r--test/utils/web3_factory.ts6
-rw-r--r--test/web3_beta_test.ts16
6 files changed, 56 insertions, 77 deletions
diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts
index 2b4e80ea3..c453b8dab 100644
--- a/test/0x.js_test.ts
+++ b/test/0x.js_test.ts
@@ -6,8 +6,11 @@ import * as BigNumber from 'bignumber.js';
import * as Sinon from 'sinon';
import {ZeroEx, Order} from '../src';
import {constants} from './utils/constants';
+import {TokenUtils} from './utils/token_utils';
import {web3Factory} from './utils/web3_factory';
+import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
+const blockchainLifecycle = new BlockchainLifecycle();
chaiSetup.configure();
const expect = chai.expect;
@@ -204,4 +207,29 @@ describe('ZeroEx library', () => {
expect(ecSignature).to.deep.equal(expectedECSignature);
});
});
+ describe('#awaitTransactionMinedAsync', () => {
+ beforeEach(async () => {
+ await blockchainLifecycle.startAsync();
+ });
+ afterEach(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
+ it('returns transaction receipt with decoded logs', async () => {
+ const availableAddresses = await zeroEx.getAvailableAddressesAsync();
+ const coinbase = availableAddresses[0];
+ const tokens = await zeroEx.tokenRegistry.getTokensAsync();
+ const tokenUtils = new TokenUtils(tokens);
+ const zrxTokenAddress = tokenUtils.getProtocolTokenOrThrow().address;
+ const proxyAddress = await zeroEx.proxy.getContractAddressAsync();
+ const txHash = await zeroEx.token.setUnlimitedProxyAllowanceAsync(zrxTokenAddress, coinbase);
+ const txReceiptWithDecodedLogs = await zeroEx.awaitTransactionMinedAsync(txHash);
+ const log = txReceiptWithDecodedLogs.logs[0];
+ expect(log.event).to.be.equal('Approval');
+ expect(log.args).to.be.deep.equal({
+ _owner: coinbase,
+ _spender: proxyAddress,
+ _value: zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS.toString(),
+ });
+ });
+ });
});
diff --git a/test/ether_token_wrapper_test.ts b/test/ether_token_wrapper_test.ts
index 601800cd1..f50aac48b 100644
--- a/test/ether_token_wrapper_test.ts
+++ b/test/ether_token_wrapper_test.ts
@@ -52,7 +52,8 @@ describe('EtherTokenWrapper', () => {
expect(preETHBalance).to.be.bignumber.gt(0);
expect(preWETHBalance).to.be.bignumber.equal(0);
- await zeroEx.etherToken.depositAsync(depositWeiAmount, addressWithETH);
+ const txHash = await zeroEx.etherToken.depositAsync(depositWeiAmount, addressWithETH);
+ await zeroEx.awaitTransactionMinedAsync(txHash);
const postETHBalanceInWei = await (zeroEx as any)._web3Wrapper.getBalanceInWeiAsync(addressWithETH);
const postWETHBalanceInBaseUnits = await zeroEx.token.getBalanceAsync(wethContractAddress, addressWithETH);
@@ -86,7 +87,8 @@ describe('EtherTokenWrapper', () => {
expect(gasCost).to.be.bignumber.lte(MAX_REASONABLE_GAS_COST_IN_WEI);
expect(preWETHBalance).to.be.bignumber.equal(depositWeiAmount);
- await zeroEx.etherToken.withdrawAsync(depositWeiAmount, addressWithETH);
+ const txHash = await zeroEx.etherToken.withdrawAsync(depositWeiAmount, addressWithETH);
+ await zeroEx.awaitTransactionMinedAsync(txHash);
const postETHBalance = await (zeroEx as any)._web3Wrapper.getBalanceInWeiAsync(addressWithETH);
const postWETHBalanceInBaseUnits = await zeroEx.token.getBalanceAsync(wethContractAddress, addressWithETH);
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts
index 90ac37387..f72e7f64f 100644
--- a/test/exchange_wrapper_test.ts
+++ b/test/exchange_wrapper_test.ts
@@ -169,8 +169,9 @@ describe('ExchangeWrapper', () => {
.to.be.bignumber.equal(0);
expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, takerAddress))
.to.be.bignumber.equal(fillableAmount);
- await zeroEx.exchange.fillOrderAsync(
+ const txHash = await zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress);
+ await zeroEx.awaitTransactionMinedAsync(txHash);
expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, makerAddress))
.to.be.bignumber.equal(fillableAmount.minus(fillTakerAmount));
expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, makerAddress))
@@ -185,8 +186,9 @@ describe('ExchangeWrapper', () => {
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
const partialFillAmount = new BigNumber(3);
- await zeroEx.exchange.fillOrderAsync(
+ const txHash = await zeroEx.exchange.fillOrderAsync(
signedOrder, partialFillAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress);
+ await zeroEx.awaitTransactionMinedAsync(txHash);
expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, makerAddress))
.to.be.bignumber.equal(fillableAmount.minus(partialFillAmount));
expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, makerAddress))
@@ -196,34 +198,6 @@ describe('ExchangeWrapper', () => {
expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, takerAddress))
.to.be.bignumber.equal(fillableAmount.minus(partialFillAmount));
});
- it('should return filled amount', async () => {
- const signedOrder = await fillScenarios.createFillableSignedOrderAsync(
- makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
- );
- const partialFillAmount = new BigNumber(3);
- const filledAmount = await zeroEx.exchange.fillOrderAsync(
- signedOrder, partialFillAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress);
- expect(filledAmount).to.be.bignumber.equal(partialFillAmount);
- });
- it('should return the partially filled amount \
- if the fill amount specified is greater then the amount available', async () => {
- const signedOrder = await fillScenarios.createFillableSignedOrderAsync(
- makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
- );
- const partialFillAmount = new BigNumber(3);
- await zeroEx.exchange.fillOrderAsync(
- signedOrder, partialFillAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress);
- const missingBalance = new BigNumber(1);
- const totalBalance = partialFillAmount.plus(missingBalance);
- await zeroEx.token.transferAsync(takerTokenAddress, coinbase, takerAddress, missingBalance);
- await zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress, totalBalance);
- await zeroEx.token.transferAsync(makerTokenAddress, coinbase, makerAddress, missingBalance);
- await zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress, totalBalance);
- const remainingFillAmount = fillableAmount.minus(partialFillAmount);
- const filledAmount = await zeroEx.exchange.fillOrderAsync(
- signedOrder, partialFillAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress);
- expect(filledAmount).to.be.bignumber.equal(remainingFillAmount);
- });
it('should fill the valid orders with fees', async () => {
const makerFee = new BigNumber(1);
const takerFee = new BigNumber(2);
@@ -231,8 +205,9 @@ describe('ExchangeWrapper', () => {
makerTokenAddress, takerTokenAddress, makerFee, takerFee,
makerAddress, takerAddress, fillableAmount, feeRecipient,
);
- await zeroEx.exchange.fillOrderAsync(
+ const txHash = await zeroEx.exchange.fillOrderAsync(
signedOrder, fillTakerAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress);
+ await zeroEx.awaitTransactionMinedAsync(txHash);
expect(await zeroEx.token.getBalanceAsync(zrxTokenAddress, feeRecipient))
.to.be.bignumber.equal(makerFee.plus(takerFee));
});
@@ -265,13 +240,15 @@ describe('ExchangeWrapper', () => {
];
});
describe('successful batch fills', () => {
- it('should no-op for an empty batch', async () => {
- await zeroEx.exchange.batchFillOrdersAsync(
- [], shouldThrowOnInsufficientBalanceOrAllowance, takerAddress);
+ it('should throw if a batch is empty', async () => {
+ return expect(zeroEx.exchange.batchFillOrdersAsync(
+ [], shouldThrowOnInsufficientBalanceOrAllowance, takerAddress),
+ ).to.be.rejectedWith(ExchangeContractErrs.BatchOrdersMustHaveAtLeastOneItem);
});
it('should successfully fill multiple orders', async () => {
- await zeroEx.exchange.batchFillOrdersAsync(
+ const txHash = await zeroEx.exchange.batchFillOrdersAsync(
orderFillBatch, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress);
+ await zeroEx.awaitTransactionMinedAsync(txHash);
const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(signedOrderHashHex);
const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(anotherOrderHashHex);
expect(filledAmount).to.be.bignumber.equal(fillTakerAmount);
@@ -298,26 +275,22 @@ describe('ExchangeWrapper', () => {
signedOrders = [signedOrder, anotherSignedOrder];
});
describe('successful batch fills', () => {
- it('should no-op for an empty batch', async () => {
- await zeroEx.exchange.fillOrdersUpToAsync(
- [], fillUpToAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress);
+ it('should throw if a batch is empty', async () => {
+ return expect(zeroEx.exchange.fillOrdersUpToAsync(
+ [], fillUpToAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress),
+ ).to.be.rejectedWith(ExchangeContractErrs.BatchOrdersMustHaveAtLeastOneItem);
});
it('should successfully fill up to specified amount', async () => {
- await zeroEx.exchange.fillOrdersUpToAsync(
+ const txHash = await zeroEx.exchange.fillOrdersUpToAsync(
signedOrders, fillUpToAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress,
);
+ await zeroEx.awaitTransactionMinedAsync(txHash);
const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(signedOrderHashHex);
const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(anotherOrderHashHex);
expect(filledAmount).to.be.bignumber.equal(fillableAmount);
const remainingFillAmount = fillableAmount.minus(1);
expect(anotherFilledAmount).to.be.bignumber.equal(remainingFillAmount);
});
- it('should return filled amount', async () => {
- const filledTakerTokenAmount = await zeroEx.exchange.fillOrdersUpToAsync(
- signedOrders, fillUpToAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress,
- );
- expect(filledTakerTokenAmount).to.be.bignumber.equal(fillUpToAmount);
- });
});
});
});
@@ -344,14 +317,11 @@ describe('ExchangeWrapper', () => {
describe('#cancelOrderAsync', () => {
describe('successful cancels', () => {
it('should cancel an order', async () => {
- await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmount);
+ const txHash = await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmount);
+ await zeroEx.awaitTransactionMinedAsync(txHash);
const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHashHex);
expect(cancelledAmount).to.be.bignumber.equal(cancelAmount);
});
- it('should return cancelled amount', async () => {
- const cancelledAmount = await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmount);
- expect(cancelledAmount).to.be.bignumber.equal(cancelAmount);
- });
});
});
describe('#batchCancelOrdersAsync', () => {
diff --git a/test/token_wrapper_test.ts b/test/token_wrapper_test.ts
index 88833e612..68dca0769 100644
--- a/test/token_wrapper_test.ts
+++ b/test/token_wrapper_test.ts
@@ -58,7 +58,8 @@ describe('TokenWrapper', () => {
const toAddress = addressWithoutFunds;
const preBalance = await zeroEx.token.getBalanceAsync(token.address, toAddress);
expect(preBalance).to.be.bignumber.equal(0);
- await zeroEx.token.transferAsync(token.address, fromAddress, toAddress, transferAmount);
+ const txHash = await zeroEx.token.transferAsync(token.address, fromAddress, toAddress, transferAmount);
+ await zeroEx.awaitTransactionMinedAsync(txHash);
const postBalance = await zeroEx.token.getBalanceAsync(token.address, toAddress);
return expect(postBalance).to.be.bignumber.equal(transferAmount);
});
@@ -356,7 +357,7 @@ describe('TokenWrapper', () => {
// we do need both. A hack is to make the top-level a sync fn w/ a done callback and then
// wrap the rest of the test in an async block
// Source: https://github.com/mochajs/mocha/issues/2407
- it('Should receive the Transfer event when an order is filled', (done: DoneCallback) => {
+ it('Should receive the Transfer event when tokens are transfered', (done: DoneCallback) => {
(async () => {
const zeroExEvent = await zeroEx.token.subscribeAsync(
tokenAddress, TokenEvents.Transfer, subscriptionOpts, indexFilterValues);
@@ -372,7 +373,7 @@ describe('TokenWrapper', () => {
await zeroEx.token.transferAsync(tokenAddress, coinbase, addressWithoutFunds, transferAmount);
})().catch(done);
});
- it('Should receive the Approval event when an order is cancelled', (done: DoneCallback) => {
+ it('Should receive the Approval event when allowance is being set', (done: DoneCallback) => {
(async () => {
const zeroExEvent = await zeroEx.token.subscribeAsync(
tokenAddress, TokenEvents.Approval, subscriptionOpts, indexFilterValues);
diff --git a/test/utils/web3_factory.ts b/test/utils/web3_factory.ts
index 4785fa858..b20070c74 100644
--- a/test/utils/web3_factory.ts
+++ b/test/utils/web3_factory.ts
@@ -6,7 +6,6 @@
import ProviderEngine = require('web3-provider-engine');
import RpcSubprovider = require('web3-provider-engine/subproviders/rpc');
import * as Web3 from 'web3';
-import * as Web3_beta from 'web3_beta';
import {constants} from './constants';
import {EmptyWalletSubProvider} from '../../src/subproviders/empty_wallet_subprovider';
@@ -29,9 +28,4 @@ export const web3Factory = {
provider.start();
return provider;
},
- getProviderBeta(): Web3.Provider {
- const rpcUrl = `http://${constants.RPC_HOST}:${constants.RPC_PORT}`;
- const providerBeta = new Web3_beta.providers.HttpProvider(rpcUrl);
- return providerBeta;
- },
};
diff --git a/test/web3_beta_test.ts b/test/web3_beta_test.ts
deleted file mode 100644
index e34812243..000000000
--- a/test/web3_beta_test.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import * as chai from 'chai';
-import {chaiSetup} from './utils/chai_setup';
-import 'mocha';
-import {ZeroEx, Order, SubscriptionOpts, TokenEvents, ContractEvent} from '../src';
-import {web3Factory} from './utils/web3_factory';
-
-chaiSetup.configure();
-const expect = chai.expect;
-
-describe('ZeroEx with beta web3', () => {
- const web3_beta_provider = web3Factory.getProviderBeta();
- const zeroEx = new ZeroEx(web3_beta_provider);
- it('is able to make a call using a beta provider', async () => {
- await zeroEx.tokenRegistry.getTokenAddressesAsync();
- });
-});