diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-04-25 07:35:57 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-04-27 01:33:37 +0800 |
commit | 185e7d43fbf308cd6b2c6032adb5e8160a206d89 (patch) | |
tree | 3fc4af77f66478e42868e0b64e943bc66f006362 /packages/contracts | |
parent | 0e0a46f373e076843fd4118cdafb325fb754141a (diff) | |
download | dexon-sol-tools-185e7d43fbf308cd6b2c6032adb5e8160a206d89.tar dexon-sol-tools-185e7d43fbf308cd6b2c6032adb5e8160a206d89.tar.gz dexon-sol-tools-185e7d43fbf308cd6b2c6032adb5e8160a206d89.tar.bz2 dexon-sol-tools-185e7d43fbf308cd6b2c6032adb5e8160a206d89.tar.lz dexon-sol-tools-185e7d43fbf308cd6b2c6032adb5e8160a206d89.tar.xz dexon-sol-tools-185e7d43fbf308cd6b2c6032adb5e8160a206d89.tar.zst dexon-sol-tools-185e7d43fbf308cd6b2c6032adb5e8160a206d89.zip |
Add tests
Diffstat (limited to 'packages/contracts')
-rw-r--r-- | packages/contracts/test/exchange/transactions.ts | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/packages/contracts/test/exchange/transactions.ts b/packages/contracts/test/exchange/transactions.ts index 697fb70e2..62bba0ab8 100644 --- a/packages/contracts/test/exchange/transactions.ts +++ b/packages/contracts/test/exchange/transactions.ts @@ -51,7 +51,8 @@ describe('Exchange transactions', () => { let signedOrder: SignedOrder; let order: OrderStruct; let orderFactory: OrderFactory; - let transactionFactory: TransactionFactory; + let makerTransactionFactory: TransactionFactory; + let takerTransactionFactory: TransactionFactory; let exchangeWrapper: ExchangeWrapper; let erc20Wrapper: ERC20Wrapper; @@ -98,7 +99,8 @@ describe('Exchange transactions', () => { const makerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)]; const takerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(takerAddress)]; orderFactory = new OrderFactory(makerPrivateKey, defaultOrderParams); - transactionFactory = new TransactionFactory(takerPrivateKey, exchange.address); + makerTransactionFactory = new TransactionFactory(makerPrivateKey, exchange.address); + takerTransactionFactory = new TransactionFactory(takerPrivateKey, exchange.address); }); beforeEach(async () => { await blockchainLifecycle.startAsync(); @@ -115,6 +117,19 @@ describe('Exchange transactions', () => { order = orderUtils.getOrderStruct(signedOrder); }); + it('should throw if not called by specified sender', async () => { + const takerAssetFillAmount = signedOrder.takerAssetAmount.div(2); + const data = exchange.fillOrder.getABIEncodedTransactionData( + order, + takerAssetFillAmount, + signedOrder.signature, + ); + const signedTx = takerTransactionFactory.newSignedTransaction(data); + return expect(exchangeWrapper.executeTransactionAsync(signedTx, takerAddress)).to.be.rejectedWith( + constants.REVERT, + ); + }); + it('should transfer the correct amounts when signed by taker and called by sender', async () => { const takerAssetFillAmount = signedOrder.takerAssetAmount.div(2); const data = exchange.fillOrder.getABIEncodedTransactionData( @@ -122,8 +137,8 @@ describe('Exchange transactions', () => { takerAssetFillAmount, signedOrder.signature, ); - const signedTx = transactionFactory.newSignedTransaction(data); - const res = await exchangeWrapper.executeTransactionAsync(signedTx, senderAddress); + const signedTx = takerTransactionFactory.newSignedTransaction(data); + await exchangeWrapper.executeTransactionAsync(signedTx, senderAddress); const newBalances = await erc20Wrapper.getBalancesAsync(); const makerAssetFillAmount = takerAssetFillAmount .times(signedOrder.makerAssetAmount) @@ -157,5 +172,24 @@ describe('Exchange transactions', () => { ); }); }); + + describe('cancelOrder', () => { + it('should throw if not called by specified sender', async () => { + const data = exchange.cancelOrder.getABIEncodedTransactionData(order); + const signedTx = makerTransactionFactory.newSignedTransaction(data); + return expect(exchangeWrapper.executeTransactionAsync(signedTx, makerAddress)).to.be.rejectedWith( + constants.REVERT, + ); + }); + + it('should cancel the order when signed by maker and called by sender', async () => { + const data = exchange.cancelOrder.getABIEncodedTransactionData(order); + const signedTx = makerTransactionFactory.newSignedTransaction(data); + await exchangeWrapper.executeTransactionAsync(signedTx, senderAddress); + const res = await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress); + const newBalances = await erc20Wrapper.getBalancesAsync(); + expect(newBalances).to.deep.equal(erc20Balances); + }); + }); }); }); |