aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contract-wrappers/test
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-09-28 19:08:12 +0800
committerFabio Berger <me@fabioberger.com>2018-09-28 19:08:12 +0800
commitba7de7204d29d4004c347190be7a3b8c84951b82 (patch)
tree9dddbd1ded45484a6cb968cdf799bf5ce991477b /packages/contract-wrappers/test
parentf3ad64aa1c2930affbfd074316b5f407580b7523 (diff)
parenta737cfa004ee1dc18be935f61fb9c289ed5623fd (diff)
downloaddexon-sol-tools-ba7de7204d29d4004c347190be7a3b8c84951b82.tar
dexon-sol-tools-ba7de7204d29d4004c347190be7a3b8c84951b82.tar.gz
dexon-sol-tools-ba7de7204d29d4004c347190be7a3b8c84951b82.tar.bz2
dexon-sol-tools-ba7de7204d29d4004c347190be7a3b8c84951b82.tar.lz
dexon-sol-tools-ba7de7204d29d4004c347190be7a3b8c84951b82.tar.xz
dexon-sol-tools-ba7de7204d29d4004c347190be7a3b8c84951b82.tar.zst
dexon-sol-tools-ba7de7204d29d4004c347190be7a3b8c84951b82.zip
merge development
Diffstat (limited to 'packages/contract-wrappers/test')
-rw-r--r--packages/contract-wrappers/test/exchange_wrapper_test.ts2
-rw-r--r--packages/contract-wrappers/test/forwarder_wrapper_test.ts3
-rw-r--r--packages/contract-wrappers/test/order_validator_wrapper_test.ts142
-rw-r--r--packages/contract-wrappers/test/revert_validation_test.ts122
-rw-r--r--packages/contract-wrappers/test/subscription_test.ts2
-rw-r--r--packages/contract-wrappers/test/transaction_encoder_test.ts2
-rw-r--r--packages/contract-wrappers/test/utils/constants.ts1
7 files changed, 268 insertions, 6 deletions
diff --git a/packages/contract-wrappers/test/exchange_wrapper_test.ts b/packages/contract-wrappers/test/exchange_wrapper_test.ts
index 6762c1d43..b3bd7c633 100644
--- a/packages/contract-wrappers/test/exchange_wrapper_test.ts
+++ b/packages/contract-wrappers/test/exchange_wrapper_test.ts
@@ -358,7 +358,7 @@ describe('ExchangeWrapper', () => {
describe('#getVersionAsync', () => {
it('should return version the hash', async () => {
const version = await contractWrappers.exchange.getVersionAsync();
- const VERSION = '2.0.1-alpha';
+ const VERSION = '2.0.0';
expect(version).to.be.equal(VERSION);
});
});
diff --git a/packages/contract-wrappers/test/forwarder_wrapper_test.ts b/packages/contract-wrappers/test/forwarder_wrapper_test.ts
index d0b21225c..a969807b2 100644
--- a/packages/contract-wrappers/test/forwarder_wrapper_test.ts
+++ b/packages/contract-wrappers/test/forwarder_wrapper_test.ts
@@ -25,10 +25,8 @@ describe('ForwarderWrapper', () => {
blockPollingIntervalMs: 0,
};
const fillableAmount = new BigNumber(5);
- const takerTokenFillAmount = new BigNumber(5);
let contractWrappers: ContractWrappers;
let fillScenarios: FillScenarios;
- let forwarderContractAddress: string;
let exchangeContractAddress: string;
let zrxTokenAddress: string;
let userAddresses: string[];
@@ -46,7 +44,6 @@ describe('ForwarderWrapper', () => {
before(async () => {
await blockchainLifecycle.startAsync();
contractWrappers = new ContractWrappers(provider, contractWrappersConfig);
- forwarderContractAddress = contractWrappers.forwarder.getContractAddress();
exchangeContractAddress = contractWrappers.exchange.getContractAddress();
userAddresses = await web3Wrapper.getAvailableAddressesAsync();
zrxTokenAddress = tokenUtils.getProtocolTokenAddress();
diff --git a/packages/contract-wrappers/test/order_validator_wrapper_test.ts b/packages/contract-wrappers/test/order_validator_wrapper_test.ts
new file mode 100644
index 000000000..2fdb00a71
--- /dev/null
+++ b/packages/contract-wrappers/test/order_validator_wrapper_test.ts
@@ -0,0 +1,142 @@
+import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils';
+import { FillScenarios } from '@0xproject/fill-scenarios';
+import { assetDataUtils, orderHashUtils } from '@0xproject/order-utils';
+import { DoneCallback, SignedOrder } from '@0xproject/types';
+import { BigNumber } from '@0xproject/utils';
+import * as chai from 'chai';
+import { BlockParamLiteral } from 'ethereum-types';
+import * as _ from 'lodash';
+import 'mocha';
+
+import { ContractWrappers, ExchangeCancelEventArgs, ExchangeEvents, ExchangeFillEventArgs, OrderStatus } from '../src';
+import { DecodedLogEvent, OrderInfo, TraderInfo } from '../src/types';
+
+import { chaiSetup } from './utils/chai_setup';
+import { constants } from './utils/constants';
+import { tokenUtils } from './utils/token_utils';
+import { provider, web3Wrapper } from './utils/web3_wrapper';
+
+chaiSetup.configure();
+const expect = chai.expect;
+const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
+
+describe('OrderValidator', () => {
+ const contractWrappersConfig = {
+ networkId: constants.TESTRPC_NETWORK_ID,
+ blockPollingIntervalMs: 0,
+ };
+ const fillableAmount = new BigNumber(5);
+ const partialFillAmount = new BigNumber(2);
+ let contractWrappers: ContractWrappers;
+ let fillScenarios: FillScenarios;
+ let exchangeContractAddress: string;
+ let zrxTokenAddress: string;
+ let zrxTokenAssetData: string;
+ let userAddresses: string[];
+ let coinbase: string;
+ let makerAddress: string;
+ let takerAddress: string;
+ let feeRecipient: string;
+ let anotherMakerAddress: string;
+ let makerTokenAddress: string;
+ let takerTokenAddress: string;
+ let makerAssetData: string;
+ let takerAssetData: string;
+ let signedOrder: SignedOrder;
+ let anotherSignedOrder: SignedOrder;
+ before(async () => {
+ await blockchainLifecycle.startAsync();
+ contractWrappers = new ContractWrappers(provider, contractWrappersConfig);
+ exchangeContractAddress = contractWrappers.exchange.getContractAddress();
+ userAddresses = await web3Wrapper.getAvailableAddressesAsync();
+ zrxTokenAddress = tokenUtils.getProtocolTokenAddress();
+ zrxTokenAssetData = assetDataUtils.encodeERC20AssetData(zrxTokenAddress);
+ fillScenarios = new FillScenarios(
+ provider,
+ userAddresses,
+ zrxTokenAddress,
+ exchangeContractAddress,
+ contractWrappers.erc20Proxy.getContractAddress(),
+ contractWrappers.erc721Proxy.getContractAddress(),
+ );
+ [coinbase, makerAddress, takerAddress, feeRecipient, anotherMakerAddress] = userAddresses;
+ [makerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses();
+ takerTokenAddress = tokenUtils.getWethTokenAddress();
+ [makerAssetData, takerAssetData] = [
+ assetDataUtils.encodeERC20AssetData(makerTokenAddress),
+ assetDataUtils.encodeERC20AssetData(takerTokenAddress),
+ ];
+
+ signedOrder = await fillScenarios.createFillableSignedOrderAsync(
+ makerAssetData,
+ takerAssetData,
+ makerAddress,
+ constants.NULL_ADDRESS,
+ fillableAmount,
+ );
+ anotherSignedOrder = await fillScenarios.createFillableSignedOrderAsync(
+ zrxTokenAssetData,
+ takerAssetData,
+ makerAddress,
+ constants.NULL_ADDRESS,
+ fillableAmount,
+ );
+ });
+ after(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
+ beforeEach(async () => {
+ await blockchainLifecycle.startAsync();
+ });
+ afterEach(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
+ describe('#getOrdersAndTradersInfoAsync', () => {
+ let signedOrders: SignedOrder[];
+ let takerAddresses: string[];
+ let ordersInfo: OrderInfo[];
+ let tradersInfo: TraderInfo[];
+ beforeEach(async () => {
+ signedOrders = [signedOrder, anotherSignedOrder];
+ takerAddresses = [takerAddress, takerAddress];
+ const ordersAndTradersInfo = await contractWrappers.orderValidator.getOrdersAndTradersInfoAsync(
+ signedOrders,
+ takerAddresses,
+ );
+ ordersInfo = _.map(ordersAndTradersInfo, orderAndTraderInfo => orderAndTraderInfo.orderInfo);
+ tradersInfo = _.map(ordersAndTradersInfo, orderAndTraderInfo => orderAndTraderInfo.traderInfo);
+ });
+ it('should return the same number of order infos and trader infos as input orders', async () => {
+ expect(ordersInfo.length).to.be.equal(signedOrders.length);
+ expect(tradersInfo.length).to.be.equal(takerAddresses.length);
+ });
+ it('should return correct on-chain order info for input orders', async () => {
+ const firstOrderInfo = ordersInfo[0];
+ const secondOrderInfo = ordersInfo[1];
+ expect(firstOrderInfo.orderStatus).to.be.equal(OrderStatus.FILLABLE);
+ expect(firstOrderInfo.orderTakerAssetFilledAmount).to.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(secondOrderInfo.orderStatus).to.be.equal(OrderStatus.FILLABLE);
+ expect(secondOrderInfo.orderTakerAssetFilledAmount).to.bignumber.equal(constants.ZERO_AMOUNT);
+ });
+ it('should return correct on-chain trader info for input takers', async () => {
+ const firstTraderInfo = tradersInfo[0];
+ const secondTraderInfo = tradersInfo[1];
+ expect(firstTraderInfo.makerBalance).to.bignumber.equal(new BigNumber(5));
+ expect(firstTraderInfo.makerAllowance).to.bignumber.equal(new BigNumber(5));
+ expect(firstTraderInfo.takerBalance).to.bignumber.equal(new BigNumber(0));
+ expect(firstTraderInfo.takerAllowance).to.bignumber.equal(new BigNumber(0));
+ expect(firstTraderInfo.makerZrxBalance).to.bignumber.equal(new BigNumber(5));
+ expect(firstTraderInfo.makerZrxAllowance).to.bignumber.equal(new BigNumber(5));
+ expect(firstTraderInfo.takerZrxBalance).to.bignumber.equal(new BigNumber(0));
+ expect(firstTraderInfo.takerZrxAllowance).to.bignumber.equal(new BigNumber(0));
+ expect(secondTraderInfo.makerBalance).to.bignumber.equal(new BigNumber(5));
+ expect(secondTraderInfo.makerAllowance).to.bignumber.equal(new BigNumber(5));
+ expect(secondTraderInfo.takerBalance).to.bignumber.equal(new BigNumber(0));
+ expect(secondTraderInfo.takerAllowance).to.bignumber.equal(new BigNumber(0));
+ expect(secondTraderInfo.makerZrxBalance).to.bignumber.equal(new BigNumber(5));
+ expect(secondTraderInfo.makerZrxAllowance).to.bignumber.equal(new BigNumber(5));
+ expect(secondTraderInfo.takerZrxBalance).to.bignumber.equal(new BigNumber(0));
+ expect(secondTraderInfo.takerZrxAllowance).to.bignumber.equal(new BigNumber(0));
+ });
+ });
+});
diff --git a/packages/contract-wrappers/test/revert_validation_test.ts b/packages/contract-wrappers/test/revert_validation_test.ts
new file mode 100644
index 000000000..da011c1d7
--- /dev/null
+++ b/packages/contract-wrappers/test/revert_validation_test.ts
@@ -0,0 +1,122 @@
+import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
+import { FillScenarios } from '@0xproject/fill-scenarios';
+import { runV2MigrationsAsync } from '@0xproject/migrations';
+import { assetDataUtils } from '@0xproject/order-utils';
+import { SignedOrder } from '@0xproject/types';
+import { BigNumber } from '@0xproject/utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
+import * as chai from 'chai';
+import 'mocha';
+
+import { ContractWrappers } from '../src';
+
+import { chaiSetup } from './utils/chai_setup';
+import { constants } from './utils/constants';
+import { tokenUtils } from './utils/token_utils';
+
+chaiSetup.configure();
+const expect = chai.expect;
+
+describe('Revert Validation ExchangeWrapper', () => {
+ let contractWrappers: ContractWrappers;
+ let userAddresses: string[];
+ let zrxTokenAddress: string;
+ let fillScenarios: FillScenarios;
+ let exchangeContractAddress: string;
+ let makerTokenAddress: string;
+ let takerTokenAddress: string;
+ let coinbase: string;
+ let makerAddress: string;
+ let anotherMakerAddress: string;
+ let takerAddress: string;
+ let makerAssetData: string;
+ let takerAssetData: string;
+ let feeRecipient: string;
+ let txHash: string;
+ let blockchainLifecycle: BlockchainLifecycle;
+ let web3Wrapper: Web3Wrapper;
+ const fillableAmount = new BigNumber(5);
+ const takerTokenFillAmount = new BigNumber(5);
+ let signedOrder: SignedOrder;
+ const config = {
+ networkId: constants.TESTRPC_NETWORK_ID,
+ blockPollingIntervalMs: 0,
+ };
+ before(async () => {
+ // vmErrorsOnRPCResponse is useful for quick feedback and testing during development
+ // but is not the default behaviour in production. Here we ensure our failure cases
+ // are handled in an environment which behaves similar to production
+ const provider = web3Factory.getRpcProvider({
+ shouldUseInProcessGanache: true,
+ shouldThrowErrorsOnGanacheRPCResponse: false,
+ });
+ web3Wrapper = new Web3Wrapper(provider);
+ blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
+ const txDefaults = {
+ gas: devConstants.GAS_LIMIT,
+ from: devConstants.TESTRPC_FIRST_ADDRESS,
+ };
+ const artifactsDir = `src/artifacts`;
+ // Re-deploy the artifacts in this provider, rather than in the default provider exposed in
+ // the beforeAll hook. This is due to the fact that the default provider enabled vmErrorsOnRPCResponse
+ // and we are explicity testing with vmErrorsOnRPCResponse disabled.
+ await runV2MigrationsAsync(provider, artifactsDir, txDefaults);
+ await blockchainLifecycle.startAsync();
+ contractWrappers = new ContractWrappers(provider, config);
+ exchangeContractAddress = contractWrappers.exchange.getContractAddress();
+ userAddresses = await web3Wrapper.getAvailableAddressesAsync();
+ zrxTokenAddress = tokenUtils.getProtocolTokenAddress();
+ fillScenarios = new FillScenarios(
+ provider,
+ userAddresses,
+ zrxTokenAddress,
+ exchangeContractAddress,
+ contractWrappers.erc20Proxy.getContractAddress(),
+ contractWrappers.erc721Proxy.getContractAddress(),
+ );
+ [coinbase, makerAddress, takerAddress, feeRecipient, anotherMakerAddress] = userAddresses;
+ [makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses();
+ [makerAssetData, takerAssetData] = [
+ assetDataUtils.encodeERC20AssetData(makerTokenAddress),
+ assetDataUtils.encodeERC20AssetData(takerTokenAddress),
+ ];
+ signedOrder = await fillScenarios.createFillableSignedOrderAsync(
+ makerAssetData,
+ takerAssetData,
+ makerAddress,
+ takerAddress,
+ fillableAmount,
+ );
+ });
+ after(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
+ beforeEach(async () => {
+ await blockchainLifecycle.startAsync();
+ });
+ afterEach(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
+ describe('#fillOrderAsync', () => {
+ it('should throw the revert reason when shouldValidate is true and a fill would revert', async () => {
+ // Create a scenario where the fill will revert
+ const makerTokenBalance = await contractWrappers.erc20Token.getBalanceAsync(
+ makerTokenAddress,
+ makerAddress,
+ );
+ // Transfer all of the tokens from maker to create a failure scenario
+ txHash = await contractWrappers.erc20Token.transferAsync(
+ makerTokenAddress,
+ makerAddress,
+ takerAddress,
+ makerTokenBalance,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
+ expect(
+ contractWrappers.exchange.fillOrderAsync(signedOrder, takerTokenFillAmount, takerAddress, {
+ shouldValidate: true,
+ }),
+ ).to.be.rejectedWith('TRANSFER_FAILED');
+ });
+ });
+});
diff --git a/packages/contract-wrappers/test/subscription_test.ts b/packages/contract-wrappers/test/subscription_test.ts
index 81b9012bd..68ef7225e 100644
--- a/packages/contract-wrappers/test/subscription_test.ts
+++ b/packages/contract-wrappers/test/subscription_test.ts
@@ -61,7 +61,7 @@ describe('SubscriptionTest', () => {
callback,
);
stubs = [
- Sinon.stub((contractWrappers as any)._web3Wrapper, 'getBlockAsync').throws(
+ Sinon.stub((contractWrappers as any)._web3Wrapper, 'getBlockIfExistsAsync').throws(
new Error('JSON RPC error'),
),
];
diff --git a/packages/contract-wrappers/test/transaction_encoder_test.ts b/packages/contract-wrappers/test/transaction_encoder_test.ts
index e76c5b12d..a397e43a8 100644
--- a/packages/contract-wrappers/test/transaction_encoder_test.ts
+++ b/packages/contract-wrappers/test/transaction_encoder_test.ts
@@ -1,6 +1,6 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { FillScenarios } from '@0xproject/fill-scenarios';
-import { assetDataUtils, signatureUtils, generatePseudoRandomSalt, orderHashUtils } from '@0xproject/order-utils';
+import { assetDataUtils, generatePseudoRandomSalt, orderHashUtils, signatureUtils } from '@0xproject/order-utils';
import { SignedOrder, SignerType } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import 'mocha';
diff --git a/packages/contract-wrappers/test/utils/constants.ts b/packages/contract-wrappers/test/utils/constants.ts
index 60c3370a2..f38728b77 100644
--- a/packages/contract-wrappers/test/utils/constants.ts
+++ b/packages/contract-wrappers/test/utils/constants.ts
@@ -15,4 +15,5 @@ export const constants = {
DUMMY_TOKEN_TOTAL_SUPPLY: new BigNumber(10 ** 27), // tslint:disable-line:custom-no-magic-numbers
NUM_DUMMY_ERC20_TO_DEPLOY: 3,
NUM_DUMMY_ERC721_TO_DEPLOY: 1,
+ ZERO_AMOUNT: new BigNumber(0),
};