diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-10-13 04:16:36 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-10-13 05:42:31 +0800 |
commit | 22abd1dfcf0ca1f7566c6ab5e0392097cf973bff (patch) | |
tree | abefa415779f7806e91ae4060ebbd73d7844986a /packages/contract-wrappers/test | |
parent | a424c2adfabbbd9313b4f5ddeeeaebd0811fd1cd (diff) | |
download | dexon-sol-tools-22abd1dfcf0ca1f7566c6ab5e0392097cf973bff.tar dexon-sol-tools-22abd1dfcf0ca1f7566c6ab5e0392097cf973bff.tar.gz dexon-sol-tools-22abd1dfcf0ca1f7566c6ab5e0392097cf973bff.tar.bz2 dexon-sol-tools-22abd1dfcf0ca1f7566c6ab5e0392097cf973bff.tar.lz dexon-sol-tools-22abd1dfcf0ca1f7566c6ab5e0392097cf973bff.tar.xz dexon-sol-tools-22abd1dfcf0ca1f7566c6ab5e0392097cf973bff.tar.zst dexon-sol-tools-22abd1dfcf0ca1f7566c6ab5e0392097cf973bff.zip |
feat(contract-wrappers): add optional validation to the forwarder wrapper
Similar to the approach taken in exchange wrapper, make a call to an rpc
node in order to simulate the transaction before actually sending the
transaction. The decorator will parse revert reasons and other types of
errors into canonical errors that a consumer of the library expects when
interacting with a contract wrapper.
Diffstat (limited to 'packages/contract-wrappers/test')
-rw-r--r-- | packages/contract-wrappers/test/forwarder_wrapper_test.ts | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/packages/contract-wrappers/test/forwarder_wrapper_test.ts b/packages/contract-wrappers/test/forwarder_wrapper_test.ts index f77b47337..4329e8770 100644 --- a/packages/contract-wrappers/test/forwarder_wrapper_test.ts +++ b/packages/contract-wrappers/test/forwarder_wrapper_test.ts @@ -17,6 +17,7 @@ chaiSetup.configure(); const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); +// tslint:disable:custom-no-magic-numbers describe('ForwarderWrapper', () => { const contractWrappersConfig = { networkId: constants.TESTRPC_NETWORK_ID, @@ -99,6 +100,25 @@ describe('ForwarderWrapper', () => { expect(ordersInfo[0].orderStatus).to.be.equal(OrderStatus.FULLY_FILLED); expect(ordersInfo[1].orderStatus).to.be.equal(OrderStatus.FULLY_FILLED); }); + it('should throw when invalid transaction and shouldValidate is true', async () => { + const signedOrders = [signedOrder]; + // request more makerAsset than what is available + const makerAssetFillAmount = signedOrder.makerAssetAmount.plus(100); + return expect( + contractWrappers.forwarder.marketBuyOrdersWithEthAsync( + signedOrders, + makerAssetFillAmount, + takerAddress, + makerAssetFillAmount, + [], + 0, + constants.NULL_ADDRESS, + { + shouldValidate: true, + }, + ), + ).to.be.rejectedWith('COMPLETE_FILL_FAILED'); + }); }); describe('#marketSellOrdersWithEthAsync', () => { it('should market sell orders with eth', async () => { @@ -115,5 +135,33 @@ describe('ForwarderWrapper', () => { expect(ordersInfo[1].orderStatus).to.be.equal(OrderStatus.FILLABLE); expect(ordersInfo[1].orderTakerAssetFilledAmount).to.be.bignumber.equal(new BigNumber(4)); // only 95% of ETH is sold }); + it('should throw when invalid transaction and shouldValidate is true', async () => { + // create an order with fees, we try to fill it but we do not provide enough ETH to cover the fees + const signedOrderWithFee = await fillScenarios.createFillableSignedOrderWithFeesAsync( + makerAssetData, + takerAssetData, + constants.ZERO_AMOUNT, + new BigNumber(100), + makerAddress, + constants.NULL_ADDRESS, + fillableAmount, + constants.NULL_ADDRESS, + ); + const signedOrders = [signedOrderWithFee]; + const makerAssetFillAmount = signedOrder.makerAssetAmount; + return expect( + contractWrappers.forwarder.marketSellOrdersWithEthAsync( + signedOrders, + takerAddress, + makerAssetFillAmount, + [], + 0, + constants.NULL_ADDRESS, + { + shouldValidate: true, + }, + ), + ).to.be.rejectedWith('COMPLETE_FILL_FAILED'); + }); }); }); |