aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-07-31 10:43:44 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-07-31 15:11:29 +0800
commitbc93ff0cb5c846fcb534f90b93e54bba0747f562 (patch)
tree17130dce53b94cfe992332ae7e44c0ac82349197
parent44498f2263ccfec805a6815a1ab673e2dd423e8d (diff)
downloaddexon-sol-tools-bc93ff0cb5c846fcb534f90b93e54bba0747f562.tar
dexon-sol-tools-bc93ff0cb5c846fcb534f90b93e54bba0747f562.tar.gz
dexon-sol-tools-bc93ff0cb5c846fcb534f90b93e54bba0747f562.tar.bz2
dexon-sol-tools-bc93ff0cb5c846fcb534f90b93e54bba0747f562.tar.lz
dexon-sol-tools-bc93ff0cb5c846fcb534f90b93e54bba0747f562.tar.xz
dexon-sol-tools-bc93ff0cb5c846fcb534f90b93e54bba0747f562.tar.zst
dexon-sol-tools-bc93ff0cb5c846fcb534f90b93e54bba0747f562.zip
Write initial test for forwarder_wrapper
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts8
-rw-r--r--packages/contract-wrappers/test/forwarder_wrapper_test.ts81
2 files changed, 73 insertions, 16 deletions
diff --git a/packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts
index 56533fb78..db1e5390a 100644
--- a/packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts
@@ -62,8 +62,8 @@ export class ForwarderWrapper extends ContractWrapper {
assert.doesConformToSchema('txOpts', txOpts, txOptsSchema);
const normalizedTakerAddress = takerAddress.toLowerCase();
const normalizedFeeRecipientAddress = feeRecipientAddress.toLowerCase();
- const ForwarderContractInstance = await this._getForwarderContractAsync();
- const txHash = await ForwarderContractInstance.marketSellOrdersWithEth.sendTransactionAsync(
+ const forwarderContractInstance = await this._getForwarderContractAsync();
+ const txHash = await forwarderContractInstance.marketSellOrdersWithEth.sendTransactionAsync(
signedOrders,
_.map(signedOrders, order => order.signature),
signedFeeOrders,
@@ -117,8 +117,8 @@ export class ForwarderWrapper extends ContractWrapper {
assert.doesConformToSchema('txOpts', txOpts, txOptsSchema);
const normalizedTakerAddress = takerAddress.toLowerCase();
const normalizedFeeRecipientAddress = feeRecipientAddress.toLowerCase();
- const ForwarderContractInstance = await this._getForwarderContractAsync();
- const txHash = await ForwarderContractInstance.marketBuyOrdersWithEth.sendTransactionAsync(
+ const forwarderContractInstance = await this._getForwarderContractAsync();
+ const txHash = await forwarderContractInstance.marketBuyOrdersWithEth.sendTransactionAsync(
signedOrders,
makerAssetFillAmount,
_.map(signedOrders, order => order.signature),
diff --git a/packages/contract-wrappers/test/forwarder_wrapper_test.ts b/packages/contract-wrappers/test/forwarder_wrapper_test.ts
index 61a21a0d7..0fb695b9e 100644
--- a/packages/contract-wrappers/test/forwarder_wrapper_test.ts
+++ b/packages/contract-wrappers/test/forwarder_wrapper_test.ts
@@ -26,18 +26,65 @@ const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('ForwarderWrapper', () => {
- let contractWrappers: ContractWrappers;
- let forwarderContractAddress: string;
- let userAddresses: string[];
- const config = {
+ const contractWrappersConfig = {
networkId: constants.TESTRPC_NETWORK_ID,
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[];
+ 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, config);
- forwarderContractAddress = contractWrappers.exchange.getContractAddress();
+ contractWrappers = new ContractWrappers(provider, contractWrappersConfig);
+ forwarderContractAddress = contractWrappers.forwarder.getContractAddress();
+ 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] = 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(
+ makerAssetData,
+ takerAssetData,
+ makerAddress,
+ constants.NULL_ADDRESS,
+ fillableAmount,
+ );
});
after(async () => {
await blockchainLifecycle.revertAsync();
@@ -48,10 +95,20 @@ describe('ForwarderWrapper', () => {
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
- // describe('#fillOrderAsync', () => {
- // it('should fill a valid order', async () => {
- // // txHash = await contractWrappers.exchange.fillOrderAsync(signedOrder, takerTokenFillAmount, takerAddress);
- // // await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
- // });
- // });
+ describe('#marketBuyOrdersWithEthAsync', () => {
+ it('should market buy orders with eth', async () => {
+ const signedOrders = [signedOrder, anotherSignedOrder];
+ const makerAssetFillAmount = signedOrder.makerAssetAmount.plus(anotherSignedOrder.makerAssetAmount);
+ const txHash = await contractWrappers.forwarder.marketBuyOrdersWithEthAsync(
+ signedOrders,
+ makerAssetFillAmount,
+ takerAddress,
+ makerAssetFillAmount,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
+ const ordersInfo = await contractWrappers.exchange.getOrdersInfoAsync([signedOrder, anotherSignedOrder]);
+ expect(ordersInfo[0].orderStatus).to.be.equal(OrderStatus.FULLY_FILLED);
+ expect(ordersInfo[1].orderStatus).to.be.equal(OrderStatus.FULLY_FILLED);
+ });
+ });
});