diff options
-rw-r--r-- | test/exchange_wrapper_test.ts | 25 | ||||
-rw-r--r-- | test/utils/fill_scenarios.ts | 13 |
2 files changed, 33 insertions, 5 deletions
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 7f8bad377..ecb5a408b 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -9,9 +9,9 @@ import promisify = require('es6-promisify'); import {web3Factory} from './utils/web3_factory'; import {ZeroEx} from '../src/0x.js'; import {BlockchainLifecycle} from './utils/blockchain_lifecycle'; -import {orderFactory} from './utils/order_factory'; import {FillOrderValidationErrs, Token} from '../src/types'; import {FillScenarios} from './utils/fill_scenarios'; +import {TokenUtils} from './utils/token_utils'; chai.use(dirtyChai); chai.use(ChaiBigNumber()); @@ -111,15 +111,19 @@ describe('ExchangeWrapper', () => { let coinBase: string; let makerAddress: string; let takerAddress: string; + let feeRecipient: string; + let zrxTokenAddress: string; const fillTakerAmountInBaseUnits = new BigNumber(5); const shouldCheckTransfer = false; before('fetch tokens', async () => { - [coinBase, makerAddress, takerAddress] = userAddresses; + [coinBase, makerAddress, takerAddress, feeRecipient] = userAddresses; tokens = await zeroEx.tokenRegistry.getTokensAsync(); - const [makerToken, takerToken] = tokens; + const tokenUtils = new TokenUtils(tokens); + const [makerToken, takerToken] = tokenUtils.getNonProtocolTokens(); makerTokenAddress = makerToken.address; takerTokenAddress = takerToken.address; - fillScenarios = new FillScenarios(zeroEx, userAddresses, tokens); + zrxTokenAddress = tokenUtils.getProtocolTokenOrThrow().address; + fillScenarios = new FillScenarios(zeroEx, userAddresses, tokens, zrxTokenAddress); }); afterEach('reset default account', () => { zeroEx.setTransactionSenderAccount(userAddresses[0]); @@ -262,6 +266,19 @@ describe('ExchangeWrapper', () => { expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, takerAddress)) .to.be.bignumber.equal(fillableAmount.minus(partialFillAmount)); }); + it('should fill the valid orders with fees', async () => { + const fillableAmount = new BigNumber(5); + const makerFee = new BigNumber(1); + const takerFee = new BigNumber(2); + const signedOrder = await fillScenarios.createFillableSignedOrderWithFeesAsync( + makerTokenAddress, takerTokenAddress, makerFee, takerFee, + makerAddress, takerAddress, fillableAmount, feeRecipient, + ); + zeroEx.setTransactionSenderAccount(takerAddress); + await zeroEx.exchange.fillOrderAsync(signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer); + expect(await zeroEx.token.getBalanceAsync(zrxTokenAddress, feeRecipient)) + .to.be.bignumber.equal(makerFee.plus(takerFee)); + }); }); }); }); diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts index 31f93618f..706f3f281 100644 --- a/test/utils/fill_scenarios.ts +++ b/test/utils/fill_scenarios.ts @@ -9,11 +9,13 @@ export class FillScenarios { private userAddresses: string[]; private tokens: Token[]; private coinBase: string; - constructor(zeroEx: ZeroEx, userAddresses: string[], tokens: Token[]) { + private zrxTokenAddress: string; + constructor(zeroEx: ZeroEx, userAddresses: string[], tokens: Token[], zrxTokenAddress: string) { this.zeroEx = zeroEx; this.userAddresses = userAddresses; this.tokens = tokens; this.coinBase = userAddresses[0]; + this.zrxTokenAddress = zrxTokenAddress; } public async createFillableSignedOrderAsync(makerTokenAddress: string, takerTokenAddress: string, makerAddress: string, takerAddress: string, @@ -60,6 +62,15 @@ export class FillScenarios { await this.zeroEx.token.transferAsync(takerTokenAddress, this.coinBase, takerAddress, takerFillableAmount); await this.zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress, takerFillableAmount); + if (!makerFee.isZero()) { + await this.zeroEx.token.transferAsync(this.zrxTokenAddress, this.coinBase, makerAddress, makerFee); + await this.zeroEx.token.setProxyAllowanceAsync(this.zrxTokenAddress, makerAddress, makerFee); + } + if (!takerFee.isZero()) { + await this.zeroEx.token.transferAsync(this.zrxTokenAddress, this.coinBase, takerAddress, takerFee); + await this.zeroEx.token.setProxyAllowanceAsync(this.zrxTokenAddress, takerAddress, takerFee); + } + const transactionSenderAccount = await this.zeroEx.getTransactionSenderAccountIfExistsAsync(); this.zeroEx.setTransactionSenderAccount(makerAddress); const signedOrder = await orderFactory.createSignedOrderAsync(this.zeroEx, |