From e1ee6b84945e729d894f6535be02f3541e43dbf0 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 2 Jun 2017 12:57:21 +0200 Subject: Add check for ROUNDING_ERROR and test for it --- test/utils/fill_scenarios.ts | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'test/utils/fill_scenarios.ts') diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts index 3b66937e6..568b11ef8 100644 --- a/test/utils/fill_scenarios.ts +++ b/test/utils/fill_scenarios.ts @@ -14,20 +14,29 @@ export class FillScenarios { this.tokens = tokens; this.coinBase = userAddresses[0]; } - public async createAFillableSignedOrderAsync(makerTokenAddress: string, takerTokenAddress: string, - makerAddress: string, takerAddress: string, - fillableAmount: BigNumber.BigNumber, - expirationUnixTimestampSec?: BigNumber.BigNumber): + public async createFillableSignedOrderAsync(makerTokenAddress: string, takerTokenAddress: string, + makerAddress: string, takerAddress: string, + fillableAmount: BigNumber.BigNumber, + expirationUnixTimestampSec?: BigNumber.BigNumber): Promise { - await this.zeroEx.token.transferAsync(makerTokenAddress, this.coinBase, makerAddress, fillableAmount); - await this.zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress, fillableAmount); - await this.zeroEx.token.transferAsync(takerTokenAddress, this.coinBase, takerAddress, fillableAmount); - await this.zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress, fillableAmount); + return this.createAsymetricFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, + fillableAmount, fillableAmount, expirationUnixTimestampSec, + ); + } + public async createAsymetricFillableSignedOrderAsync( + makerTokenAddress: string, takerTokenAddress: string, makerAddress: string, takerAddress: string, + makerFillableAmount: BigNumber.BigNumber, takerFillableAmount: BigNumber.BigNumber, + expirationUnixTimestampSec?: BigNumber.BigNumber): Promise { + await this.zeroEx.token.transferAsync(makerTokenAddress, this.coinBase, makerAddress, makerFillableAmount); + await this.zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress, makerFillableAmount); + await this.zeroEx.token.transferAsync(takerTokenAddress, this.coinBase, takerAddress, takerFillableAmount); + await this.zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress, takerFillableAmount); const transactionSenderAccount = await this.zeroEx.getTransactionSenderAccountIfExistsAsync(); this.zeroEx.setTransactionSenderAccount(makerAddress); const signedOrder = await orderFactory.createSignedOrderAsync(this.zeroEx, makerAddress, - takerAddress, fillableAmount, makerTokenAddress, fillableAmount, takerTokenAddress, + takerAddress, makerFillableAmount, makerTokenAddress, takerFillableAmount, takerTokenAddress, expirationUnixTimestampSec); this.zeroEx.setTransactionSenderAccount(transactionSenderAccount as string); return signedOrder; -- cgit v1.2.3 From 832d2ff5ca1e82c4580e47c0b101069ee7cc0fca Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 2 Jun 2017 13:08:59 +0200 Subject: Add fill scenario with fees --- test/utils/fill_scenarios.ts | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'test/utils/fill_scenarios.ts') diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts index 568b11ef8..31f93618f 100644 --- a/test/utils/fill_scenarios.ts +++ b/test/utils/fill_scenarios.ts @@ -2,6 +2,7 @@ import * as BigNumber from 'bignumber.js'; import {ZeroEx} from '../../src/0x.js'; import {Token, SignedOrder} from '../../src/types'; import {orderFactory} from '../utils/order_factory'; +import {constants} from './constants'; export class FillScenarios { private zeroEx: ZeroEx; @@ -24,10 +25,36 @@ export class FillScenarios { fillableAmount, fillableAmount, expirationUnixTimestampSec, ); } + public async createFillableSignedOrderWithFeesAsync( + makerTokenAddress: string, takerTokenAddress: string, + makerFee: BigNumber.BigNumber, takerFee: BigNumber.BigNumber, + makerAddress: string, takerAddress: string, + fillableAmount: BigNumber.BigNumber, + feeRecepient: string, expirationUnixTimestampSec?: BigNumber.BigNumber, + ): Promise { + return this.createAsymetricFillableSignedOrderWithFeesAsync( + makerTokenAddress, takerTokenAddress, makerFee, takerFee, makerAddress, takerAddress, + fillableAmount, fillableAmount, feeRecepient, expirationUnixTimestampSec, + ); + } public async createAsymetricFillableSignedOrderAsync( makerTokenAddress: string, takerTokenAddress: string, makerAddress: string, takerAddress: string, makerFillableAmount: BigNumber.BigNumber, takerFillableAmount: BigNumber.BigNumber, expirationUnixTimestampSec?: BigNumber.BigNumber): Promise { + const makerFee = new BigNumber(0); + const takerFee = new BigNumber(0); + const feeRecepient = constants.NULL_ADDRESS; + return this.createAsymetricFillableSignedOrderWithFeesAsync( + makerTokenAddress, takerTokenAddress, makerFee, takerFee, makerAddress, takerAddress, + makerFillableAmount, takerFillableAmount, feeRecepient, expirationUnixTimestampSec, + ); + } + private async createAsymetricFillableSignedOrderWithFeesAsync( + makerTokenAddress: string, takerTokenAddress: string, + makerFee: BigNumber.BigNumber, takerFee: BigNumber.BigNumber, + makerAddress: string, takerAddress: string, + makerFillableAmount: BigNumber.BigNumber, takerFillableAmount: BigNumber.BigNumber, + feeRecepient: string, expirationUnixTimestampSec?: BigNumber.BigNumber): Promise { await this.zeroEx.token.transferAsync(makerTokenAddress, this.coinBase, makerAddress, makerFillableAmount); await this.zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress, makerFillableAmount); await this.zeroEx.token.transferAsync(takerTokenAddress, this.coinBase, takerAddress, takerFillableAmount); @@ -35,9 +62,10 @@ export class FillScenarios { const transactionSenderAccount = await this.zeroEx.getTransactionSenderAccountIfExistsAsync(); this.zeroEx.setTransactionSenderAccount(makerAddress); - const signedOrder = await orderFactory.createSignedOrderAsync(this.zeroEx, makerAddress, - takerAddress, makerFillableAmount, makerTokenAddress, takerFillableAmount, takerTokenAddress, - expirationUnixTimestampSec); + const signedOrder = await orderFactory.createSignedOrderAsync(this.zeroEx, + makerAddress, takerAddress, makerFee, takerFee, + makerFillableAmount, makerTokenAddress, takerFillableAmount, takerTokenAddress, + feeRecepient, expirationUnixTimestampSec); this.zeroEx.setTransactionSenderAccount(transactionSenderAccount as string); return signedOrder; } -- cgit v1.2.3 From d8587875b82ae2fde6dad1334a586c36cda2bfec Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 2 Jun 2017 15:24:42 +0200 Subject: Add success test for fill with fees --- test/utils/fill_scenarios.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'test/utils/fill_scenarios.ts') 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, -- cgit v1.2.3 From 3c71506022a827f37916f981a57e3ad8cc0c5abb Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 2 Jun 2017 16:26:47 +0200 Subject: Rename coinBase to coinbase --- test/utils/fill_scenarios.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'test/utils/fill_scenarios.ts') diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts index 706f3f281..8260b76ab 100644 --- a/test/utils/fill_scenarios.ts +++ b/test/utils/fill_scenarios.ts @@ -8,13 +8,13 @@ export class FillScenarios { private zeroEx: ZeroEx; private userAddresses: string[]; private tokens: Token[]; - private coinBase: string; + private coinbase: string; 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.coinbase = userAddresses[0]; this.zrxTokenAddress = zrxTokenAddress; } public async createFillableSignedOrderAsync(makerTokenAddress: string, takerTokenAddress: string, @@ -57,17 +57,17 @@ export class FillScenarios { makerAddress: string, takerAddress: string, makerFillableAmount: BigNumber.BigNumber, takerFillableAmount: BigNumber.BigNumber, feeRecepient: string, expirationUnixTimestampSec?: BigNumber.BigNumber): Promise { - await this.zeroEx.token.transferAsync(makerTokenAddress, this.coinBase, makerAddress, makerFillableAmount); + await this.zeroEx.token.transferAsync(makerTokenAddress, this.coinbase, makerAddress, makerFillableAmount); await this.zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress, makerFillableAmount); - await this.zeroEx.token.transferAsync(takerTokenAddress, this.coinBase, takerAddress, takerFillableAmount); + 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.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.transferAsync(this.zrxTokenAddress, this.coinbase, takerAddress, takerFee); await this.zeroEx.token.setProxyAllowanceAsync(this.zrxTokenAddress, takerAddress, takerFee); } -- cgit v1.2.3 From 7cf60b589b280c578bcde4b9209e70d07c92c241 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 2 Jun 2017 18:20:17 +0200 Subject: Address feedback --- test/utils/fill_scenarios.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test/utils/fill_scenarios.ts') diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts index 8260b76ab..f95b06663 100644 --- a/test/utils/fill_scenarios.ts +++ b/test/utils/fill_scenarios.ts @@ -22,7 +22,7 @@ export class FillScenarios { fillableAmount: BigNumber.BigNumber, expirationUnixTimestampSec?: BigNumber.BigNumber): Promise { - return this.createAsymetricFillableSignedOrderAsync( + return this.createAsymmetricFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, fillableAmount, expirationUnixTimestampSec, ); @@ -34,24 +34,24 @@ export class FillScenarios { fillableAmount: BigNumber.BigNumber, feeRecepient: string, expirationUnixTimestampSec?: BigNumber.BigNumber, ): Promise { - return this.createAsymetricFillableSignedOrderWithFeesAsync( + return this.createAsymmetricFillableSignedOrderWithFeesAsync( makerTokenAddress, takerTokenAddress, makerFee, takerFee, makerAddress, takerAddress, fillableAmount, fillableAmount, feeRecepient, expirationUnixTimestampSec, ); } - public async createAsymetricFillableSignedOrderAsync( + public async createAsymmetricFillableSignedOrderAsync( makerTokenAddress: string, takerTokenAddress: string, makerAddress: string, takerAddress: string, makerFillableAmount: BigNumber.BigNumber, takerFillableAmount: BigNumber.BigNumber, expirationUnixTimestampSec?: BigNumber.BigNumber): Promise { const makerFee = new BigNumber(0); const takerFee = new BigNumber(0); const feeRecepient = constants.NULL_ADDRESS; - return this.createAsymetricFillableSignedOrderWithFeesAsync( + return this.createAsymmetricFillableSignedOrderWithFeesAsync( makerTokenAddress, takerTokenAddress, makerFee, takerFee, makerAddress, takerAddress, makerFillableAmount, takerFillableAmount, feeRecepient, expirationUnixTimestampSec, ); } - private async createAsymetricFillableSignedOrderWithFeesAsync( + private async createAsymmetricFillableSignedOrderWithFeesAsync( makerTokenAddress: string, takerTokenAddress: string, makerFee: BigNumber.BigNumber, takerFee: BigNumber.BigNumber, makerAddress: string, takerAddress: string, -- cgit v1.2.3 From 9620b18fecb59b5ce4c2fec483e426f79852c034 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 2 Jun 2017 18:34:43 +0200 Subject: Address feedback --- test/utils/fill_scenarios.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test/utils/fill_scenarios.ts') diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts index f95b06663..a44d6b18a 100644 --- a/test/utils/fill_scenarios.ts +++ b/test/utils/fill_scenarios.ts @@ -71,13 +71,14 @@ export class FillScenarios { await this.zeroEx.token.setProxyAllowanceAsync(this.zrxTokenAddress, takerAddress, takerFee); } - const transactionSenderAccount = await this.zeroEx.getTransactionSenderAccountIfExistsAsync(); + const prevTransactionSenderAccount = await this.zeroEx.getTransactionSenderAccountIfExistsAsync(); this.zeroEx.setTransactionSenderAccount(makerAddress); const signedOrder = await orderFactory.createSignedOrderAsync(this.zeroEx, makerAddress, takerAddress, makerFee, takerFee, makerFillableAmount, makerTokenAddress, takerFillableAmount, takerTokenAddress, feeRecepient, expirationUnixTimestampSec); - this.zeroEx.setTransactionSenderAccount(transactionSenderAccount as string); + // We re-set the transactionSender to avoid introducing side-effects + this.zeroEx.setTransactionSenderAccount(prevTransactionSenderAccount as string); return signedOrder; } } -- cgit v1.2.3