Move constants and exchangeDataEncoder into test-utils package
This commit is contained in:
parent
e80abad19a
commit
f4b3b69b2f
@ -9,7 +9,8 @@ import {
|
|||||||
} from '@0x/contracts-exchange';
|
} from '@0x/contracts-exchange';
|
||||||
import {
|
import {
|
||||||
chaiSetup,
|
chaiSetup,
|
||||||
constants as devConstants,
|
constants,
|
||||||
|
exchangeDataEncoder,
|
||||||
expectTransactionFailedAsync,
|
expectTransactionFailedAsync,
|
||||||
getLatestBlockTimestampAsync,
|
getLatestBlockTimestampAsync,
|
||||||
OrderFactory,
|
OrderFactory,
|
||||||
@ -25,7 +26,7 @@ import { BigNumber, providerUtils } from '@0x/utils';
|
|||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
import { LogWithDecodedArgs } from 'ethereum-types';
|
import { LogWithDecodedArgs } from 'ethereum-types';
|
||||||
|
|
||||||
import { ApprovalFactory, artifacts, constants, CoordinatorContract, exchangeDataEncoder } from '../src';
|
import { ApprovalFactory, artifacts, CoordinatorContract } from '../src';
|
||||||
|
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
@ -68,7 +69,7 @@ describe('Coordinator tests', () => {
|
|||||||
const numDummyErc20ToDeploy = 3;
|
const numDummyErc20ToDeploy = 3;
|
||||||
[erc20TokenA, erc20TokenB, zrxToken] = await erc20Wrapper.deployDummyTokensAsync(
|
[erc20TokenA, erc20TokenB, zrxToken] = await erc20Wrapper.deployDummyTokensAsync(
|
||||||
numDummyErc20ToDeploy,
|
numDummyErc20ToDeploy,
|
||||||
devConstants.DUMMY_TOKEN_DECIMALS,
|
constants.DUMMY_TOKEN_DECIMALS,
|
||||||
);
|
);
|
||||||
await erc20Wrapper.setBalancesAndAllowancesAsync();
|
await erc20Wrapper.setBalancesAndAllowancesAsync();
|
||||||
|
|
||||||
@ -82,12 +83,12 @@ describe('Coordinator tests', () => {
|
|||||||
|
|
||||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||||
await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: owner }),
|
await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: owner }),
|
||||||
devConstants.AWAIT_TRANSACTION_MINED_MS,
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
);
|
);
|
||||||
|
|
||||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||||
await exchange.registerAssetProxy.sendTransactionAsync(erc20Proxy.address, { from: owner }),
|
await exchange.registerAssetProxy.sendTransactionAsync(erc20Proxy.address, { from: owner }),
|
||||||
devConstants.AWAIT_TRANSACTION_MINED_MS,
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
);
|
);
|
||||||
|
|
||||||
coordinatorContract = await CoordinatorContract.deployFrom0xArtifactAsync(
|
coordinatorContract = await CoordinatorContract.deployFrom0xArtifactAsync(
|
||||||
@ -100,7 +101,7 @@ describe('Coordinator tests', () => {
|
|||||||
|
|
||||||
// Configure order defaults
|
// Configure order defaults
|
||||||
const defaultOrderParams = {
|
const defaultOrderParams = {
|
||||||
...devConstants.STATIC_ORDER_PARAMS,
|
...constants.STATIC_ORDER_PARAMS,
|
||||||
senderAddress: coordinatorContract.address,
|
senderAddress: coordinatorContract.address,
|
||||||
makerAddress,
|
makerAddress,
|
||||||
feeRecipientAddress,
|
feeRecipientAddress,
|
||||||
@ -111,9 +112,9 @@ describe('Coordinator tests', () => {
|
|||||||
chainId,
|
chainId,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const makerPrivateKey = devConstants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
const makerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
||||||
const takerPrivateKey = devConstants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(takerAddress)];
|
const takerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(takerAddress)];
|
||||||
const feeRecipientPrivateKey = devConstants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(feeRecipientAddress)];
|
const feeRecipientPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(feeRecipientAddress)];
|
||||||
orderFactory = new OrderFactory(makerPrivateKey, defaultOrderParams);
|
orderFactory = new OrderFactory(makerPrivateKey, defaultOrderParams);
|
||||||
makerTransactionFactory = new TransactionFactory(makerPrivateKey, exchange.address, chainId);
|
makerTransactionFactory = new TransactionFactory(makerPrivateKey, exchange.address, chainId);
|
||||||
takerTransactionFactory = new TransactionFactory(takerPrivateKey, exchange.address, chainId);
|
takerTransactionFactory = new TransactionFactory(takerPrivateKey, exchange.address, chainId);
|
||||||
@ -148,7 +149,7 @@ describe('Coordinator tests', () => {
|
|||||||
[approval.signature],
|
[approval.signature],
|
||||||
{ from: takerAddress },
|
{ from: takerAddress },
|
||||||
),
|
),
|
||||||
devConstants.AWAIT_TRANSACTION_MINED_MS,
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
);
|
);
|
||||||
const fillLogs = transactionReceipt.logs.filter(
|
const fillLogs = transactionReceipt.logs.filter(
|
||||||
log => (log as LogWithDecodedArgs<ExchangeFillEventArgs>).event === 'Fill',
|
log => (log as LogWithDecodedArgs<ExchangeFillEventArgs>).event === 'Fill',
|
||||||
@ -180,7 +181,7 @@ describe('Coordinator tests', () => {
|
|||||||
[],
|
[],
|
||||||
{ from: feeRecipientAddress },
|
{ from: feeRecipientAddress },
|
||||||
),
|
),
|
||||||
devConstants.AWAIT_TRANSACTION_MINED_MS,
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
);
|
);
|
||||||
const fillLogs = transactionReceipt.logs.filter(
|
const fillLogs = transactionReceipt.logs.filter(
|
||||||
log => (log as LogWithDecodedArgs<ExchangeFillEventArgs>).event === 'Fill',
|
log => (log as LogWithDecodedArgs<ExchangeFillEventArgs>).event === 'Fill',
|
||||||
@ -212,7 +213,7 @@ describe('Coordinator tests', () => {
|
|||||||
[],
|
[],
|
||||||
{
|
{
|
||||||
from: takerAddress,
|
from: takerAddress,
|
||||||
gas: devConstants.MAX_EXECUTE_TRANSACTION_GAS,
|
gas: constants.MAX_EXECUTE_TRANSACTION_GAS,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
RevertReason.InvalidApprovalSignature,
|
RevertReason.InvalidApprovalSignature,
|
||||||
@ -310,9 +311,9 @@ describe('Coordinator tests', () => {
|
|||||||
transaction.signature,
|
transaction.signature,
|
||||||
[approvalExpirationTimeSeconds],
|
[approvalExpirationTimeSeconds],
|
||||||
[approval.signature],
|
[approval.signature],
|
||||||
{ from: takerAddress, gas: devConstants.MAX_EXECUTE_TRANSACTION_GAS },
|
{ from: takerAddress, gas: constants.MAX_EXECUTE_TRANSACTION_GAS },
|
||||||
),
|
),
|
||||||
devConstants.AWAIT_TRANSACTION_MINED_MS,
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
);
|
);
|
||||||
const fillLogs = transactionReceipt.logs.filter(
|
const fillLogs = transactionReceipt.logs.filter(
|
||||||
log => (log as LogWithDecodedArgs<ExchangeFillEventArgs>).event === 'Fill',
|
log => (log as LogWithDecodedArgs<ExchangeFillEventArgs>).event === 'Fill',
|
||||||
@ -344,9 +345,9 @@ describe('Coordinator tests', () => {
|
|||||||
transaction.signature,
|
transaction.signature,
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
{ from: feeRecipientAddress, gas: devConstants.MAX_EXECUTE_TRANSACTION_GAS },
|
{ from: feeRecipientAddress, gas: constants.MAX_EXECUTE_TRANSACTION_GAS },
|
||||||
),
|
),
|
||||||
devConstants.AWAIT_TRANSACTION_MINED_MS,
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
);
|
);
|
||||||
const fillLogs = transactionReceipt.logs.filter(
|
const fillLogs = transactionReceipt.logs.filter(
|
||||||
log => (log as LogWithDecodedArgs<ExchangeFillEventArgs>).event === 'Fill',
|
log => (log as LogWithDecodedArgs<ExchangeFillEventArgs>).event === 'Fill',
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import {
|
import {
|
||||||
addressUtils,
|
addressUtils,
|
||||||
chaiSetup,
|
chaiSetup,
|
||||||
constants as devConstants,
|
constants,
|
||||||
|
exchangeDataEncoder,
|
||||||
expectContractCallFailedAsync,
|
expectContractCallFailedAsync,
|
||||||
getLatestBlockTimestampAsync,
|
getLatestBlockTimestampAsync,
|
||||||
provider,
|
provider,
|
||||||
@ -16,7 +17,7 @@ import { BigNumber, providerUtils } from '@0x/utils';
|
|||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
import * as ethUtil from 'ethereumjs-util';
|
import * as ethUtil from 'ethereumjs-util';
|
||||||
|
|
||||||
import { ApprovalFactory, artifacts, constants, CoordinatorContract, exchangeDataEncoder } from '../src';
|
import { ApprovalFactory, artifacts, CoordinatorContract } from '../src';
|
||||||
|
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
@ -53,29 +54,28 @@ describe('Mixins tests', () => {
|
|||||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||||
[transactionSignerAddress, approvalSignerAddress1, approvalSignerAddress2] = accounts.slice(0, 3);
|
[transactionSignerAddress, approvalSignerAddress1, approvalSignerAddress2] = accounts.slice(0, 3);
|
||||||
exchangeDomain = {
|
exchangeDomain = {
|
||||||
verifyingContractAddress: devConstants.NULL_ADDRESS,
|
verifyingContractAddress: constants.NULL_ADDRESS,
|
||||||
chainId,
|
chainId,
|
||||||
};
|
};
|
||||||
defaultOrder = {
|
defaultOrder = {
|
||||||
makerAddress: devConstants.NULL_ADDRESS,
|
makerAddress: constants.NULL_ADDRESS,
|
||||||
takerAddress: devConstants.NULL_ADDRESS,
|
takerAddress: constants.NULL_ADDRESS,
|
||||||
senderAddress: mixins.address,
|
senderAddress: mixins.address,
|
||||||
feeRecipientAddress: approvalSignerAddress1,
|
feeRecipientAddress: approvalSignerAddress1,
|
||||||
makerAssetData: devConstants.NULL_BYTES,
|
makerAssetData: constants.NULL_BYTES,
|
||||||
takerAssetData: devConstants.NULL_BYTES,
|
takerAssetData: constants.NULL_BYTES,
|
||||||
makerAssetAmount: devConstants.ZERO_AMOUNT,
|
makerAssetAmount: constants.ZERO_AMOUNT,
|
||||||
takerAssetAmount: devConstants.ZERO_AMOUNT,
|
takerAssetAmount: constants.ZERO_AMOUNT,
|
||||||
makerFee: devConstants.ZERO_AMOUNT,
|
makerFee: constants.ZERO_AMOUNT,
|
||||||
takerFee: devConstants.ZERO_AMOUNT,
|
takerFee: constants.ZERO_AMOUNT,
|
||||||
expirationTimeSeconds: devConstants.ZERO_AMOUNT,
|
expirationTimeSeconds: constants.ZERO_AMOUNT,
|
||||||
salt: devConstants.ZERO_AMOUNT,
|
salt: constants.ZERO_AMOUNT,
|
||||||
signature: devConstants.NULL_BYTES,
|
signature: constants.NULL_BYTES,
|
||||||
domain: exchangeDomain,
|
domain: exchangeDomain,
|
||||||
};
|
};
|
||||||
const transactionSignerPrivateKey =
|
const transactionSignerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(transactionSignerAddress)];
|
||||||
devConstants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(transactionSignerAddress)];
|
const approvalSignerPrivateKey1 = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(approvalSignerAddress1)];
|
||||||
const approvalSignerPrivateKey1 = devConstants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(approvalSignerAddress1)];
|
const approvalSignerPrivateKey2 = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(approvalSignerAddress2)];
|
||||||
const approvalSignerPrivateKey2 = devConstants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(approvalSignerAddress2)];
|
|
||||||
transactionFactory = new TransactionFactory(transactionSignerPrivateKey, exchangeAddress, chainId);
|
transactionFactory = new TransactionFactory(transactionSignerPrivateKey, exchangeAddress, chainId);
|
||||||
approvalFactory1 = new ApprovalFactory(approvalSignerPrivateKey1, mixins.address);
|
approvalFactory1 = new ApprovalFactory(approvalSignerPrivateKey1, mixins.address);
|
||||||
approvalFactory2 = new ApprovalFactory(approvalSignerPrivateKey2, mixins.address);
|
approvalFactory2 = new ApprovalFactory(approvalSignerPrivateKey2, mixins.address);
|
||||||
@ -89,21 +89,21 @@ describe('Mixins tests', () => {
|
|||||||
|
|
||||||
describe('getSignerAddress', () => {
|
describe('getSignerAddress', () => {
|
||||||
it('should return the correct address using the EthSign signature type', async () => {
|
it('should return the correct address using the EthSign signature type', async () => {
|
||||||
const data = devConstants.NULL_BYTES;
|
const data = constants.NULL_BYTES;
|
||||||
const transaction = transactionFactory.newSignedTransaction(data, SignatureType.EthSign);
|
const transaction = transactionFactory.newSignedTransaction(data, SignatureType.EthSign);
|
||||||
const transactionHash = transactionHashUtils.getTransactionHashHex(transaction);
|
const transactionHash = transactionHashUtils.getTransactionHashHex(transaction);
|
||||||
const signerAddress = await mixins.getSignerAddress.callAsync(transactionHash, transaction.signature);
|
const signerAddress = await mixins.getSignerAddress.callAsync(transactionHash, transaction.signature);
|
||||||
expect(transaction.signerAddress).to.eq(signerAddress);
|
expect(transaction.signerAddress).to.eq(signerAddress);
|
||||||
});
|
});
|
||||||
it('should return the correct address using the EIP712 signature type', async () => {
|
it('should return the correct address using the EIP712 signature type', async () => {
|
||||||
const data = devConstants.NULL_BYTES;
|
const data = constants.NULL_BYTES;
|
||||||
const transaction = transactionFactory.newSignedTransaction(data, SignatureType.EIP712);
|
const transaction = transactionFactory.newSignedTransaction(data, SignatureType.EIP712);
|
||||||
const transactionHash = transactionHashUtils.getTransactionHashHex(transaction);
|
const transactionHash = transactionHashUtils.getTransactionHashHex(transaction);
|
||||||
const signerAddress = await mixins.getSignerAddress.callAsync(transactionHash, transaction.signature);
|
const signerAddress = await mixins.getSignerAddress.callAsync(transactionHash, transaction.signature);
|
||||||
expect(transaction.signerAddress).to.eq(signerAddress);
|
expect(transaction.signerAddress).to.eq(signerAddress);
|
||||||
});
|
});
|
||||||
it('should revert with with the Illegal signature type', async () => {
|
it('should revert with with the Illegal signature type', async () => {
|
||||||
const data = devConstants.NULL_BYTES;
|
const data = constants.NULL_BYTES;
|
||||||
const transaction = transactionFactory.newSignedTransaction(data);
|
const transaction = transactionFactory.newSignedTransaction(data);
|
||||||
const illegalSignatureByte = ethUtil.toBuffer(SignatureType.Illegal).toString('hex');
|
const illegalSignatureByte = ethUtil.toBuffer(SignatureType.Illegal).toString('hex');
|
||||||
transaction.signature = `${transaction.signature.slice(
|
transaction.signature = `${transaction.signature.slice(
|
||||||
@ -117,7 +117,7 @@ describe('Mixins tests', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('should revert with with the Invalid signature type', async () => {
|
it('should revert with with the Invalid signature type', async () => {
|
||||||
const data = devConstants.NULL_BYTES;
|
const data = constants.NULL_BYTES;
|
||||||
const transaction = transactionFactory.newSignedTransaction(data);
|
const transaction = transactionFactory.newSignedTransaction(data);
|
||||||
const invalidSignatureByte = ethUtil.toBuffer(SignatureType.Invalid).toString('hex');
|
const invalidSignatureByte = ethUtil.toBuffer(SignatureType.Invalid).toString('hex');
|
||||||
transaction.signature = `0x${invalidSignatureByte}`;
|
transaction.signature = `0x${invalidSignatureByte}`;
|
||||||
@ -128,7 +128,7 @@ describe('Mixins tests', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
it("should revert with with a signature type that doesn't exist", async () => {
|
it("should revert with with a signature type that doesn't exist", async () => {
|
||||||
const data = devConstants.NULL_BYTES;
|
const data = constants.NULL_BYTES;
|
||||||
const transaction = transactionFactory.newSignedTransaction(data);
|
const transaction = transactionFactory.newSignedTransaction(data);
|
||||||
const invalidSignatureByte = '04';
|
const invalidSignatureByte = '04';
|
||||||
transaction.signature = `${transaction.signature.slice(
|
transaction.signature = `${transaction.signature.slice(
|
||||||
@ -151,7 +151,7 @@ describe('Mixins tests', () => {
|
|||||||
const decodedOrders = await mixins.decodeOrdersFromFillData.callAsync(data);
|
const decodedOrders = await mixins.decodeOrdersFromFillData.callAsync(data);
|
||||||
const decodedSignedOrders = decodedOrders.map(order => ({
|
const decodedSignedOrders = decodedOrders.map(order => ({
|
||||||
...order,
|
...order,
|
||||||
signature: devConstants.NULL_BYTES,
|
signature: constants.NULL_BYTES,
|
||||||
domain: exchangeDomain,
|
domain: exchangeDomain,
|
||||||
}));
|
}));
|
||||||
expect(orders).to.deep.eq(decodedSignedOrders);
|
expect(orders).to.deep.eq(decodedSignedOrders);
|
||||||
@ -164,7 +164,7 @@ describe('Mixins tests', () => {
|
|||||||
const decodedOrders = await mixins.decodeOrdersFromFillData.callAsync(data);
|
const decodedOrders = await mixins.decodeOrdersFromFillData.callAsync(data);
|
||||||
const decodedSignedOrders = decodedOrders.map(order => ({
|
const decodedSignedOrders = decodedOrders.map(order => ({
|
||||||
...order,
|
...order,
|
||||||
signature: devConstants.NULL_BYTES,
|
signature: constants.NULL_BYTES,
|
||||||
domain: exchangeDomain,
|
domain: exchangeDomain,
|
||||||
}));
|
}));
|
||||||
expect(orders).to.deep.eq(decodedSignedOrders);
|
expect(orders).to.deep.eq(decodedSignedOrders);
|
||||||
@ -177,7 +177,7 @@ describe('Mixins tests', () => {
|
|||||||
const decodedOrders = await mixins.decodeOrdersFromFillData.callAsync(data);
|
const decodedOrders = await mixins.decodeOrdersFromFillData.callAsync(data);
|
||||||
const decodedSignedOrders = decodedOrders.map(order => ({
|
const decodedSignedOrders = decodedOrders.map(order => ({
|
||||||
...order,
|
...order,
|
||||||
signature: devConstants.NULL_BYTES,
|
signature: constants.NULL_BYTES,
|
||||||
domain: exchangeDomain,
|
domain: exchangeDomain,
|
||||||
}));
|
}));
|
||||||
expect(orders).to.deep.eq(decodedSignedOrders);
|
expect(orders).to.deep.eq(decodedSignedOrders);
|
||||||
@ -232,7 +232,7 @@ describe('Mixins tests', () => {
|
|||||||
it(`Should be successful: function=${fnName}, caller=tx_signer, senderAddress=[null], approval_sig=[approver1], expiration=[valid]`, async () => {
|
it(`Should be successful: function=${fnName}, caller=tx_signer, senderAddress=[null], approval_sig=[approver1], expiration=[valid]`, async () => {
|
||||||
const order = {
|
const order = {
|
||||||
...defaultOrder,
|
...defaultOrder,
|
||||||
senderAddress: devConstants.NULL_ADDRESS,
|
senderAddress: constants.NULL_ADDRESS,
|
||||||
};
|
};
|
||||||
const orders = [order];
|
const orders = [order];
|
||||||
const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders);
|
const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders);
|
||||||
@ -404,7 +404,7 @@ describe('Mixins tests', () => {
|
|||||||
it(`Should be successful: function=${fnName} caller=tx_signer, senderAddress=[null,null], feeRecipient=[approver1,approver1], approval_sig=[approver1], expiration=[valid]`, async () => {
|
it(`Should be successful: function=${fnName} caller=tx_signer, senderAddress=[null,null], feeRecipient=[approver1,approver1], approval_sig=[approver1], expiration=[valid]`, async () => {
|
||||||
const orders = [defaultOrder, defaultOrder].map(order => ({
|
const orders = [defaultOrder, defaultOrder].map(order => ({
|
||||||
...order,
|
...order,
|
||||||
senderAddress: devConstants.NULL_ADDRESS,
|
senderAddress: constants.NULL_ADDRESS,
|
||||||
}));
|
}));
|
||||||
const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders);
|
const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders);
|
||||||
const transaction = transactionFactory.newSignedTransaction(data);
|
const transaction = transactionFactory.newSignedTransaction(data);
|
||||||
@ -427,7 +427,7 @@ describe('Mixins tests', () => {
|
|||||||
it(`Should be successful: function=${fnName} caller=tx_signer, senderAddress=[null,null], feeRecipient=[approver1,approver1], approval_sig=[], expiration=[]`, async () => {
|
it(`Should be successful: function=${fnName} caller=tx_signer, senderAddress=[null,null], feeRecipient=[approver1,approver1], approval_sig=[], expiration=[]`, async () => {
|
||||||
const orders = [defaultOrder, defaultOrder].map(order => ({
|
const orders = [defaultOrder, defaultOrder].map(order => ({
|
||||||
...order,
|
...order,
|
||||||
senderAddress: devConstants.NULL_ADDRESS,
|
senderAddress: constants.NULL_ADDRESS,
|
||||||
}));
|
}));
|
||||||
const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders);
|
const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders);
|
||||||
const transaction = transactionFactory.newSignedTransaction(data);
|
const transaction = transactionFactory.newSignedTransaction(data);
|
||||||
@ -441,7 +441,7 @@ describe('Mixins tests', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
it(`Should be successful: function=${fnName} caller=tx_signer, senderAddress=[verifier,null], feeRecipient=[approver1,approver1], approval_sig=[approver1], expiration=[valid]`, async () => {
|
it(`Should be successful: function=${fnName} caller=tx_signer, senderAddress=[verifier,null], feeRecipient=[approver1,approver1], approval_sig=[approver1], expiration=[valid]`, async () => {
|
||||||
const orders = [defaultOrder, { ...defaultOrder, senderAddress: devConstants.NULL_ADDRESS }];
|
const orders = [defaultOrder, { ...defaultOrder, senderAddress: constants.NULL_ADDRESS }];
|
||||||
const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders);
|
const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders);
|
||||||
const transaction = transactionFactory.newSignedTransaction(data);
|
const transaction = transactionFactory.newSignedTransaction(data);
|
||||||
const currentTimestamp = await getLatestBlockTimestampAsync();
|
const currentTimestamp = await getLatestBlockTimestampAsync();
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
import { BigNumber } from '@0x/utils';
|
|
||||||
|
|
||||||
export const constants = {
|
|
||||||
SINGLE_FILL_FN_NAMES: ['fillOrder', 'fillOrKillOrder', 'fillOrderNoThrow'],
|
|
||||||
BATCH_FILL_FN_NAMES: ['batchFillOrders', 'batchFillOrKillOrders', 'batchFillOrdersNoThrow'],
|
|
||||||
MARKET_FILL_FN_NAMES: ['marketBuyOrders', 'marketBuyOrdersNoThrow', 'marketSellOrders', 'marketSellOrdersNoThrow'],
|
|
||||||
MATCH_ORDERS: 'matchOrders',
|
|
||||||
CANCEL_ORDER: 'cancelOrder',
|
|
||||||
BATCH_CANCEL_ORDERS: 'batchCancelOrders',
|
|
||||||
CANCEL_ORDERS_UP_TO: 'cancelOrdersUpTo',
|
|
||||||
TIME_BUFFER: new BigNumber(1000),
|
|
||||||
};
|
|
@ -1,5 +1,3 @@
|
|||||||
export { hashUtils } from './hash_utils';
|
export { hashUtils } from './hash_utils';
|
||||||
export { ApprovalFactory } from './approval_factory';
|
export { ApprovalFactory } from './approval_factory';
|
||||||
export { constants } from './constants';
|
|
||||||
export { exchangeDataEncoder } from './exchange_data_encoder';
|
|
||||||
export * from './types';
|
export * from './types';
|
||||||
|
@ -71,4 +71,12 @@ export const constants = {
|
|||||||
'SET_SIGNATURE_VALIDATOR_APPROVAL',
|
'SET_SIGNATURE_VALIDATOR_APPROVAL',
|
||||||
],
|
],
|
||||||
KECCAK256_NULL: ethUtil.addHexPrefix(ethUtil.bufferToHex(ethUtil.SHA3_NULL)),
|
KECCAK256_NULL: ethUtil.addHexPrefix(ethUtil.bufferToHex(ethUtil.SHA3_NULL)),
|
||||||
|
SINGLE_FILL_FN_NAMES: ['fillOrder', 'fillOrKillOrder', 'fillOrderNoThrow'],
|
||||||
|
BATCH_FILL_FN_NAMES: ['batchFillOrders', 'batchFillOrKillOrders', 'batchFillOrdersNoThrow'],
|
||||||
|
MARKET_FILL_FN_NAMES: ['marketBuyOrders', 'marketBuyOrdersNoThrow', 'marketSellOrders', 'marketSellOrdersNoThrow'],
|
||||||
|
MATCH_ORDERS: 'matchOrders',
|
||||||
|
CANCEL_ORDER: 'cancelOrder',
|
||||||
|
BATCH_CANCEL_ORDERS: 'batchCancelOrders',
|
||||||
|
CANCEL_ORDERS_UP_TO: 'cancelOrdersUpTo',
|
||||||
|
TIME_BUFFER: new BigNumber(1000),
|
||||||
};
|
};
|
||||||
|
@ -2,10 +2,10 @@ import { IExchangeContract } from '@0x/contracts-exchange';
|
|||||||
import { constants as devConstants, provider } from '@0x/contracts-test-utils';
|
import { constants as devConstants, provider } from '@0x/contracts-test-utils';
|
||||||
import { SignedOrder } from '@0x/types';
|
import { SignedOrder } from '@0x/types';
|
||||||
|
|
||||||
import { constants } from './index';
|
import { constants, provider } from './index';
|
||||||
|
|
||||||
export const exchangeDataEncoder = {
|
export const exchangeDataEncoder = {
|
||||||
encodeOrdersToExchangeData(fnName: string, orders: SignedOrder[]): string {
|
encodeOrdersToExchangeData(fnName: string, orders: SignedOrder[] = []): string {
|
||||||
const exchangeInstance = new IExchangeContract(devConstants.NULL_ADDRESS, provider);
|
const exchangeInstance = new IExchangeContract(devConstants.NULL_ADDRESS, provider);
|
||||||
let data;
|
let data;
|
||||||
if (constants.SINGLE_FILL_FN_NAMES.indexOf(fnName) !== -1) {
|
if (constants.SINGLE_FILL_FN_NAMES.indexOf(fnName) !== -1) {
|
||||||
@ -38,7 +38,7 @@ export const exchangeDataEncoder = {
|
|||||||
} else if (fnName === constants.BATCH_CANCEL_ORDERS) {
|
} else if (fnName === constants.BATCH_CANCEL_ORDERS) {
|
||||||
data = exchangeInstance.batchCancelOrders.getABIEncodedTransactionData(orders);
|
data = exchangeInstance.batchCancelOrders.getABIEncodedTransactionData(orders);
|
||||||
} else if (fnName === constants.CANCEL_ORDERS_UP_TO) {
|
} else if (fnName === constants.CANCEL_ORDERS_UP_TO) {
|
||||||
data = exchangeInstance.cancelOrdersUpTo.getABIEncodedTransactionData(devConstants.ZERO_AMOUNT);
|
data = exchangeInstance.cancelOrdersUpTo.getABIEncodedTransactionData(constants.ZERO_AMOUNT);
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Error: ${fnName} not a supported function`);
|
throw new Error(`Error: ${fnName} not a supported function`);
|
||||||
}
|
}
|
@ -28,6 +28,7 @@ export { OrderFactory } from './order_factory';
|
|||||||
export { bytes32Values, testCombinatoriallyWithReferenceFuncAsync, uint256Values } from './combinatorial_utils';
|
export { bytes32Values, testCombinatoriallyWithReferenceFuncAsync, uint256Values } from './combinatorial_utils';
|
||||||
export { TransactionFactory } from './transaction_factory';
|
export { TransactionFactory } from './transaction_factory';
|
||||||
export { testWithReferenceFuncAsync } from './test_with_reference';
|
export { testWithReferenceFuncAsync } from './test_with_reference';
|
||||||
|
export { exchangeDataEncoder } from './exchange_data_encoder';
|
||||||
export {
|
export {
|
||||||
MarketBuyOrders,
|
MarketBuyOrders,
|
||||||
MarketSellOrders,
|
MarketSellOrders,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user