From bac6833436960d2a7eb50d89e94fed226a16008b Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 5 Jun 2017 16:22:56 +0200 Subject: Make methods accept senderAccount --- test/0x.js_test.ts | 22 ++++++++---------- test/exchange_wrapper_test.ts | 54 +++++++++++++++++-------------------------- test/utils/fill_scenarios.ts | 13 ++--------- test/utils/order_factory.ts | 2 +- 4 files changed, 34 insertions(+), 57 deletions(-) (limited to 'test') diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 8686b42eb..a82ec45ba 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -191,6 +191,13 @@ describe('ZeroEx library', () => { }); describe('#signOrderHashAsync', () => { let stubs: Sinon.SinonStub[] = []; + let makerAccount: string; + const web3 = web3Factory.create(); + const zeroEx = new ZeroEx(web3); + before('get maker account', async () => { + const availableAccounts = await zeroEx.getAvailableAccountsAsync(); + makerAccount = availableAccounts[0]; + }); afterEach(() => { // clean up any stubs after the test has completed _.each(stubs, s => s.restore()); @@ -203,10 +210,7 @@ describe('ZeroEx library', () => { r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', }; - - const web3 = web3Factory.create(); - const zeroEx = new ZeroEx(web3); - const ecSignature = await zeroEx.signOrderHashAsync(orderHash); + const ecSignature = await zeroEx.signOrderHashAsync(orderHash, makerAccount); expect(ecSignature).to.deep.equal(expectedECSignature); }); it ('should return the correct ECSignature on Parity > V1.6.6', async () => { @@ -219,9 +223,6 @@ describe('ZeroEx library', () => { r: '0x22109d11d79cb8bf96ed88625e1cd9558800c4073332a9a02857499883ee5ce3', s: '0x050aa3cc1f2c435e67e114cdce54b9527b4f50548342401bc5d2b77adbdacb02', }; - - const web3 = web3Factory.create(); - const zeroEx = new ZeroEx(web3); stubs = [ Sinon.stub((zeroEx as any).web3Wrapper, 'getNodeVersionAsync') .returns(Promise.resolve(newParityNodeVersion)), @@ -230,7 +231,7 @@ describe('ZeroEx library', () => { Sinon.stub(ZeroEx, 'isValidSignature').returns(true), ]; - const ecSignature = await zeroEx.signOrderHashAsync(orderHash); + const ecSignature = await zeroEx.signOrderHashAsync(orderHash, makerAccount); expect(ecSignature).to.deep.equal(expectedECSignature); }); it ('should return the correct ECSignature on Parity < V1.6.6', async () => { @@ -243,9 +244,6 @@ describe('ZeroEx library', () => { r: '0xc80bedc6756722672753413efdd749b5adbd4fd552595f59c13427407ee9aee0', s: '0x2dea66f25a608bbae457e020fb6decb763deb8b7192abab624997242da248960', }; - - const web3 = web3Factory.create(); - const zeroEx = new ZeroEx(web3); stubs = [ Sinon.stub((zeroEx as any).web3Wrapper, 'getNodeVersionAsync') .returns(Promise.resolve(newParityNodeVersion)), @@ -254,7 +252,7 @@ describe('ZeroEx library', () => { Sinon.stub(ZeroEx, 'isValidSignature').returns(true), ]; - const ecSignature = await zeroEx.signOrderHashAsync(orderHash); + const ecSignature = await zeroEx.signOrderHashAsync(orderHash, makerAccount); expect(ecSignature).to.deep.equal(expectedECSignature); }); }); diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 4f3a48b26..a841f82ec 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -138,9 +138,6 @@ describe('ExchangeWrapper', () => { makerTokenAddress = makerToken.address; takerTokenAddress = takerToken.address; }); - afterEach('reset default account', () => { - zeroEx.setTransactionSenderAccount(userAddresses[0]); - }); describe('failed fills', () => { it('should throw when the fill amount is zero', async () => { const fillableAmount = new BigNumber(5); @@ -148,9 +145,8 @@ describe('ExchangeWrapper', () => { makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, ); const zeroFillAmount = new BigNumber(0); - zeroEx.setTransactionSenderAccount(takerAddress); return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, zeroFillAmount, shouldCheckTransfer, + signedOrder, zeroFillAmount, shouldCheckTransfer, takerAddress, )).to.be.rejectedWith(ExchangeContractErrs.ORDER_REMAINING_FILL_AMOUNT_ZERO); }); it('should throw when sender is not a taker', async () => { @@ -159,7 +155,7 @@ describe('ExchangeWrapper', () => { makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, ); return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmount, shouldCheckTransfer, + signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, )).to.be.rejectedWith(ExchangeContractErrs.TRANSACTION_SENDER_IS_NOT_FILL_ORDER_TAKER); }); it('should throw when order is expired', async () => { @@ -168,9 +164,8 @@ describe('ExchangeWrapper', () => { const signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, expirationInPast, ); - zeroEx.setTransactionSenderAccount(takerAddress); return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmount, shouldCheckTransfer, + signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, )).to.be.rejectedWith(ExchangeContractErrs.ORDER_FILL_EXPIRED); }); describe('should throw when not enough balance or allowance to fulfill the order', () => { @@ -187,36 +182,32 @@ describe('ExchangeWrapper', () => { await zeroEx.token.transferAsync( takerTokenAddress, takerAddress, coinbase, balanceToSubtractFromMaker, ); - zeroEx.setTransactionSenderAccount(takerAddress); return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmount, shouldCheckTransfer, + signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_TAKER_BALANCE); }); it('should throw when taker allowance is less than fill amount', async () => { const newAllowanceWhichIsLessThanFillAmount = fillTakerAmount.minus(lackingAllowance); await zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress, newAllowanceWhichIsLessThanFillAmount); - zeroEx.setTransactionSenderAccount(takerAddress); return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmount, shouldCheckTransfer, + signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_TAKER_ALLOWANCE); }); it('should throw when maker balance is less than maker fill amount', async () => { await zeroEx.token.transferAsync( makerTokenAddress, makerAddress, coinbase, balanceToSubtractFromMaker, ); - zeroEx.setTransactionSenderAccount(takerAddress); return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmount, shouldCheckTransfer, + signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_MAKER_BALANCE); }); it('should throw when maker allowance is less than maker fill amount', async () => { const newAllowanceWhichIsLessThanFillAmount = fillTakerAmount.minus(lackingAllowance); await zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress, newAllowanceWhichIsLessThanFillAmount); - zeroEx.setTransactionSenderAccount(takerAddress); return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmount, shouldCheckTransfer, + signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_MAKER_ALLOWANCE); }); }); @@ -228,9 +219,8 @@ describe('ExchangeWrapper', () => { makerAmount, takerAmount, ); const fillTakerAmountThatCausesRoundingError = new BigNumber(3); - zeroEx.setTransactionSenderAccount(takerAddress); return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmountThatCausesRoundingError, shouldCheckTransfer, + signedOrder, fillTakerAmountThatCausesRoundingError, shouldCheckTransfer, takerAddress, )).to.be.rejectedWith(ExchangeContractErrs.ORDER_FILL_ROUNDING_ERROR); }); describe('should throw when not enough balance or allowance to pay fees', () => { @@ -243,7 +233,6 @@ describe('ExchangeWrapper', () => { makerTokenAddress, takerTokenAddress, makerFee, takerFee, makerAddress, takerAddress, fillableAmount, feeRecipient, ); - zeroEx.setTransactionSenderAccount(takerAddress); }); it('should throw when maker doesn\'t have enough balance to pay fees', async () => { const balanceToSubtractFromMaker = new BigNumber(1); @@ -251,7 +240,7 @@ describe('ExchangeWrapper', () => { zrxTokenAddress, makerAddress, coinbase, balanceToSubtractFromMaker, ); return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmount, shouldCheckTransfer, + signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_MAKER_FEE_BALANCE); }); it('should throw when maker doesn\'t have enough allowance to pay fees', async () => { @@ -259,7 +248,7 @@ describe('ExchangeWrapper', () => { await zeroEx.token.setProxyAllowanceAsync(zrxTokenAddress, makerAddress, newAllowanceWhichIsLessThanFees); return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmount, shouldCheckTransfer, + signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_MAKER_FEE_ALLOWANCE); }); it('should throw when taker doesn\'t have enough balance to pay fees', async () => { @@ -268,7 +257,7 @@ describe('ExchangeWrapper', () => { zrxTokenAddress, takerAddress, coinbase, balanceToSubtractFromTaker, ); return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmount, shouldCheckTransfer, + signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_TAKER_FEE_BALANCE); }); it('should throw when taker doesn\'t have enough allowance to pay fees', async () => { @@ -276,7 +265,7 @@ describe('ExchangeWrapper', () => { await zeroEx.token.setProxyAllowanceAsync(zrxTokenAddress, takerAddress, newAllowanceWhichIsLessThanFees); return expect(zeroEx.exchange.fillOrderAsync( - signedOrder, fillTakerAmount, shouldCheckTransfer, + signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress, )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_TAKER_FEE_ALLOWANCE); }); }); @@ -295,8 +284,7 @@ describe('ExchangeWrapper', () => { .to.be.bignumber.equal(0); expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, takerAddress)) .to.be.bignumber.equal(fillableAmount); - zeroEx.setTransactionSenderAccount(takerAddress); - await zeroEx.exchange.fillOrderAsync(signedOrder, fillTakerAmount, shouldCheckTransfer); + await zeroEx.exchange.fillOrderAsync(signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress); expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, makerAddress)) .to.be.bignumber.equal(fillableAmount.minus(fillTakerAmount)); expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, makerAddress)) @@ -312,8 +300,7 @@ describe('ExchangeWrapper', () => { makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, ); const partialFillAmount = new BigNumber(3); - zeroEx.setTransactionSenderAccount(takerAddress); - await zeroEx.exchange.fillOrderAsync(signedOrder, partialFillAmount, shouldCheckTransfer); + await zeroEx.exchange.fillOrderAsync(signedOrder, partialFillAmount, shouldCheckTransfer, takerAddress); expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, makerAddress)) .to.be.bignumber.equal(fillableAmount.minus(partialFillAmount)); expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, makerAddress)) @@ -331,8 +318,7 @@ describe('ExchangeWrapper', () => { makerTokenAddress, takerTokenAddress, makerFee, takerFee, makerAddress, takerAddress, fillableAmount, feeRecipient, ); - zeroEx.setTransactionSenderAccount(takerAddress); - await zeroEx.exchange.fillOrderAsync(signedOrder, fillTakerAmount, shouldCheckTransfer); + await zeroEx.exchange.fillOrderAsync(signedOrder, fillTakerAmount, shouldCheckTransfer, takerAddress); expect(await zeroEx.token.getBalanceAsync(zrxTokenAddress, feeRecipient)) .to.be.bignumber.equal(makerFee.plus(takerFee)); }); @@ -447,8 +433,9 @@ describe('ExchangeWrapper', () => { done(); }); const fillTakerAmountInBaseUnits = new BigNumber(1); - zeroEx.setTransactionSenderAccount(takerAddress); - await zeroEx.exchange.fillOrderAsync(signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer); + await zeroEx.exchange.fillOrderAsync( + signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer, takerAddress, + ); })(); }); it('Outstanding subscriptions are cancelled when zeroEx.setProviderAsync called', (done: DoneCallback) => { @@ -473,8 +460,9 @@ describe('ExchangeWrapper', () => { }); const fillTakerAmountInBaseUnits = new BigNumber(1); - zeroEx.setTransactionSenderAccount(takerAddress); - await zeroEx.exchange.fillOrderAsync(signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer); + await zeroEx.exchange.fillOrderAsync( + signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer, takerAddress, + ); })(); }); }); diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts index d186593b9..075906eaa 100644 --- a/test/utils/fill_scenarios.ts +++ b/test/utils/fill_scenarios.ts @@ -54,19 +54,14 @@ export class FillScenarios { public async createPartiallyFilledSignedOrderAsync(makerTokenAddress: string, takerTokenAddress: string, takerAddress: string, fillableAmount: BigNumber.BigNumber, partialFillAmount: BigNumber.BigNumber) { - const prevSenderAccount = await this.zeroEx.getTransactionSenderAccountIfExistsAsync(); + const prevSenderAccount = await this.zeroEx.getAvailableAccountsAsync(); const [makerAddress] = this.userAddresses; const signedOrder = await this.createAsymmetricFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, fillableAmount, ); - - this.zeroEx.setTransactionSenderAccount(takerAddress); const shouldCheckTransfer = false; - await this.zeroEx.exchange.fillOrderAsync(signedOrder, partialFillAmount, shouldCheckTransfer); - - // Re-set sender account so as to avoid introducing side-effects - this.zeroEx.setTransactionSenderAccount(prevSenderAccount as string); + await this.zeroEx.exchange.fillOrderAsync(signedOrder, partialFillAmount, shouldCheckTransfer, takerAddress); return signedOrder; } private async createAsymmetricFillableSignedOrderWithFeesAsync( @@ -89,14 +84,10 @@ export class FillScenarios { await this.zeroEx.token.setProxyAllowanceAsync(this.zrxTokenAddress, takerAddress, takerFee); } - 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); - // We re-set the transactionSender to avoid introducing side-effects - this.zeroEx.setTransactionSenderAccount(prevTransactionSenderAccount as string); return signedOrder; } } diff --git a/test/utils/order_factory.ts b/test/utils/order_factory.ts index 373dbddc6..6f5fa7286 100644 --- a/test/utils/order_factory.ts +++ b/test/utils/order_factory.ts @@ -36,7 +36,7 @@ export const orderFactory = { expirationUnixTimestampSec, }; const orderHash = await zeroEx.getOrderHashHexAsync(order); - const ecSignature = await zeroEx.signOrderHashAsync(orderHash); + const ecSignature = await zeroEx.signOrderHashAsync(orderHash, maker); const signedOrder: SignedOrder = _.assign(order, {ecSignature}); return signedOrder; }, -- cgit From d36fa171533e5c2dd5f511e5c213c27fd7cf3e4d Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 6 Jun 2017 11:08:48 +0200 Subject: Add tests for isSenderAccountHexAsync --- test/assert_test.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/assert_test.ts (limited to 'test') diff --git a/test/assert_test.ts b/test/assert_test.ts new file mode 100644 index 000000000..2100611e9 --- /dev/null +++ b/test/assert_test.ts @@ -0,0 +1,33 @@ +import * as chai from 'chai'; +import 'mocha'; +import {ZeroEx} from '../src/0x.js'; +import {assert} from '../src/utils/assert'; +import {web3Factory} from './utils/web3_factory'; + +const expect = chai.expect; + +describe('Assertion library', () => { + const web3 = web3Factory.create(); + const zeroEx = new ZeroEx(web3); + describe('#isSenderAccountHexAsync', () => { + it('throws when address is invalid', async () => { + const address = '0xdeadbeef'; + const varName = 'account'; + return expect(assert.isSenderAccountHexAsync(varName, address, (zeroEx as any).web3Wrapper)) + .to.be.rejectedWith(`Expected ${varName} to be of type ETHAddressHex, encountered: ${address}`); + }); + it('throws when address is unavailable', async () => { + const validUnrelatedAddress = '0x8b0292b11a196601eddce54b665cafeca0347d42'; + const varName = 'account'; + return expect(assert.isSenderAccountHexAsync(varName, validUnrelatedAddress, (zeroEx as any).web3Wrapper)) + .to.be.rejectedWith(`Specified sender account ${validUnrelatedAddress} \ + isn't available through the supplied web3 instance`); + }); + it('doesn\'t throw if account is available', async () => { + const availableAccount = (await zeroEx.getAvailableAccountsAsync())[0]; + const varName = 'account'; + return expect(assert.isSenderAccountHexAsync(varName, availableAccount, (zeroEx as any).web3Wrapper)) + .to.become(undefined); + }); + }); +}); -- cgit From ed3d1a8142e6f65480f95df7c3991ae00c757e38 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 6 Jun 2017 12:37:52 +0200 Subject: Rename assert.isSenderAccountHexAsync to assert.isSenderAddressHexAsync --- test/assert_test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/assert_test.ts b/test/assert_test.ts index 2100611e9..f72956eb3 100644 --- a/test/assert_test.ts +++ b/test/assert_test.ts @@ -13,20 +13,20 @@ describe('Assertion library', () => { it('throws when address is invalid', async () => { const address = '0xdeadbeef'; const varName = 'account'; - return expect(assert.isSenderAccountHexAsync(varName, address, (zeroEx as any).web3Wrapper)) + return expect(assert.isSenderAddressHexAsync(varName, address, (zeroEx as any).web3Wrapper)) .to.be.rejectedWith(`Expected ${varName} to be of type ETHAddressHex, encountered: ${address}`); }); it('throws when address is unavailable', async () => { const validUnrelatedAddress = '0x8b0292b11a196601eddce54b665cafeca0347d42'; const varName = 'account'; - return expect(assert.isSenderAccountHexAsync(varName, validUnrelatedAddress, (zeroEx as any).web3Wrapper)) + return expect(assert.isSenderAddressHexAsync(varName, validUnrelatedAddress, (zeroEx as any).web3Wrapper)) .to.be.rejectedWith(`Specified sender account ${validUnrelatedAddress} \ isn't available through the supplied web3 instance`); }); it('doesn\'t throw if account is available', async () => { const availableAccount = (await zeroEx.getAvailableAccountsAsync())[0]; const varName = 'account'; - return expect(assert.isSenderAccountHexAsync(varName, availableAccount, (zeroEx as any).web3Wrapper)) + return expect(assert.isSenderAddressHexAsync(varName, availableAccount, (zeroEx as any).web3Wrapper)) .to.become(undefined); }); }); -- cgit From 279790117be882186685c04099e3d46ec68991b6 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 6 Jun 2017 12:43:20 +0200 Subject: Remove message param from before --- test/0x.js_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index a82ec45ba..061e0cbf4 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -194,7 +194,7 @@ describe('ZeroEx library', () => { let makerAccount: string; const web3 = web3Factory.create(); const zeroEx = new ZeroEx(web3); - before('get maker account', async () => { + before(async () => { const availableAccounts = await zeroEx.getAvailableAccountsAsync(); makerAccount = availableAccounts[0]; }); -- cgit From 67e2208a1822732ea125af0c4cd757b9f735ce86 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 6 Jun 2017 12:48:00 +0200 Subject: Rename accounts to addreses --- test/0x.js_test.ts | 2 +- test/assert_test.ts | 2 +- test/utils/fill_scenarios.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 061e0cbf4..edc2a3493 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -195,7 +195,7 @@ describe('ZeroEx library', () => { const web3 = web3Factory.create(); const zeroEx = new ZeroEx(web3); before(async () => { - const availableAccounts = await zeroEx.getAvailableAccountsAsync(); + const availableAccounts = await zeroEx.getAvailableAddressesAsync(); makerAccount = availableAccounts[0]; }); afterEach(() => { diff --git a/test/assert_test.ts b/test/assert_test.ts index f72956eb3..c8f698730 100644 --- a/test/assert_test.ts +++ b/test/assert_test.ts @@ -24,7 +24,7 @@ describe('Assertion library', () => { isn't available through the supplied web3 instance`); }); it('doesn\'t throw if account is available', async () => { - const availableAccount = (await zeroEx.getAvailableAccountsAsync())[0]; + const availableAccount = (await zeroEx.getAvailableAddressesAsync())[0]; const varName = 'account'; return expect(assert.isSenderAddressHexAsync(varName, availableAccount, (zeroEx as any).web3Wrapper)) .to.become(undefined); diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts index 075906eaa..f2daac623 100644 --- a/test/utils/fill_scenarios.ts +++ b/test/utils/fill_scenarios.ts @@ -54,7 +54,7 @@ export class FillScenarios { public async createPartiallyFilledSignedOrderAsync(makerTokenAddress: string, takerTokenAddress: string, takerAddress: string, fillableAmount: BigNumber.BigNumber, partialFillAmount: BigNumber.BigNumber) { - const prevSenderAccount = await this.zeroEx.getAvailableAccountsAsync(); + const prevSenderAccount = await this.zeroEx.getAvailableAddressesAsync(); const [makerAddress] = this.userAddresses; const signedOrder = await this.createAsymmetricFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, -- cgit From 33cf004b2927f1ddb68e370f211264a132e64544 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 6 Jun 2017 12:48:40 +0200 Subject: Remove unused variable --- test/utils/fill_scenarios.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'test') diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts index f2daac623..d8d6cd0b9 100644 --- a/test/utils/fill_scenarios.ts +++ b/test/utils/fill_scenarios.ts @@ -54,7 +54,6 @@ export class FillScenarios { public async createPartiallyFilledSignedOrderAsync(makerTokenAddress: string, takerTokenAddress: string, takerAddress: string, fillableAmount: BigNumber.BigNumber, partialFillAmount: BigNumber.BigNumber) { - const prevSenderAccount = await this.zeroEx.getAvailableAddressesAsync(); const [makerAddress] = this.userAddresses; const signedOrder = await this.createAsymmetricFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, -- cgit From abd6fbfa648a540342d9c183fc8f5b36248b6055 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 6 Jun 2017 12:50:18 +0200 Subject: Use variable name in assertin message --- test/assert_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/assert_test.ts b/test/assert_test.ts index c8f698730..147c9832f 100644 --- a/test/assert_test.ts +++ b/test/assert_test.ts @@ -20,7 +20,7 @@ describe('Assertion library', () => { const validUnrelatedAddress = '0x8b0292b11a196601eddce54b665cafeca0347d42'; const varName = 'account'; return expect(assert.isSenderAddressHexAsync(varName, validUnrelatedAddress, (zeroEx as any).web3Wrapper)) - .to.be.rejectedWith(`Specified sender account ${validUnrelatedAddress} \ + .to.be.rejectedWith(`Specified ${varName} ${validUnrelatedAddress} \ isn't available through the supplied web3 instance`); }); it('doesn\'t throw if account is available', async () => { -- cgit From 80bbfc3f0ff6d000e628d6db4baddae94c4911a0 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 6 Jun 2017 14:10:36 +0200 Subject: Last round of renamings --- test/0x.js_test.ts | 12 ++++++------ test/assert_test.ts | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index edc2a3493..43c50ef34 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -191,12 +191,12 @@ describe('ZeroEx library', () => { }); describe('#signOrderHashAsync', () => { let stubs: Sinon.SinonStub[] = []; - let makerAccount: string; + let makerAddress: string; const web3 = web3Factory.create(); const zeroEx = new ZeroEx(web3); before(async () => { - const availableAccounts = await zeroEx.getAvailableAddressesAsync(); - makerAccount = availableAccounts[0]; + const availableAddreses = await zeroEx.getAvailableAddressesAsync(); + makerAddress = availableAddreses[0]; }); afterEach(() => { // clean up any stubs after the test has completed @@ -210,7 +210,7 @@ describe('ZeroEx library', () => { r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', }; - const ecSignature = await zeroEx.signOrderHashAsync(orderHash, makerAccount); + const ecSignature = await zeroEx.signOrderHashAsync(orderHash, makerAddress); expect(ecSignature).to.deep.equal(expectedECSignature); }); it ('should return the correct ECSignature on Parity > V1.6.6', async () => { @@ -231,7 +231,7 @@ describe('ZeroEx library', () => { Sinon.stub(ZeroEx, 'isValidSignature').returns(true), ]; - const ecSignature = await zeroEx.signOrderHashAsync(orderHash, makerAccount); + const ecSignature = await zeroEx.signOrderHashAsync(orderHash, makerAddress); expect(ecSignature).to.deep.equal(expectedECSignature); }); it ('should return the correct ECSignature on Parity < V1.6.6', async () => { @@ -252,7 +252,7 @@ describe('ZeroEx library', () => { Sinon.stub(ZeroEx, 'isValidSignature').returns(true), ]; - const ecSignature = await zeroEx.signOrderHashAsync(orderHash, makerAccount); + const ecSignature = await zeroEx.signOrderHashAsync(orderHash, makerAddress); expect(ecSignature).to.deep.equal(expectedECSignature); }); }); diff --git a/test/assert_test.ts b/test/assert_test.ts index 147c9832f..ff15d6cf6 100644 --- a/test/assert_test.ts +++ b/test/assert_test.ts @@ -9,24 +9,24 @@ const expect = chai.expect; describe('Assertion library', () => { const web3 = web3Factory.create(); const zeroEx = new ZeroEx(web3); - describe('#isSenderAccountHexAsync', () => { + describe('#isSenderAddressHexAsync', () => { it('throws when address is invalid', async () => { const address = '0xdeadbeef'; - const varName = 'account'; + const varName = 'address'; return expect(assert.isSenderAddressHexAsync(varName, address, (zeroEx as any).web3Wrapper)) .to.be.rejectedWith(`Expected ${varName} to be of type ETHAddressHex, encountered: ${address}`); }); it('throws when address is unavailable', async () => { const validUnrelatedAddress = '0x8b0292b11a196601eddce54b665cafeca0347d42'; - const varName = 'account'; + const varName = 'address'; return expect(assert.isSenderAddressHexAsync(varName, validUnrelatedAddress, (zeroEx as any).web3Wrapper)) .to.be.rejectedWith(`Specified ${varName} ${validUnrelatedAddress} \ isn't available through the supplied web3 instance`); }); - it('doesn\'t throw if account is available', async () => { - const availableAccount = (await zeroEx.getAvailableAddressesAsync())[0]; - const varName = 'account'; - return expect(assert.isSenderAddressHexAsync(varName, availableAccount, (zeroEx as any).web3Wrapper)) + it('doesn\'t throw if address is available', async () => { + const availableAddress = (await zeroEx.getAvailableAddressesAsync())[0]; + const varName = 'address'; + return expect(assert.isSenderAddressHexAsync(varName, availableAddress, (zeroEx as any).web3Wrapper)) .to.become(undefined); }); }); -- cgit From ef57dd22e29057e5bd84b9a0ad36a123126695df Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 6 Jun 2017 14:29:07 +0200 Subject: Rename isSenderAddressHexAsync to isSenderAddressAsync --- test/assert_test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/assert_test.ts b/test/assert_test.ts index ff15d6cf6..560ef06d4 100644 --- a/test/assert_test.ts +++ b/test/assert_test.ts @@ -13,20 +13,20 @@ describe('Assertion library', () => { it('throws when address is invalid', async () => { const address = '0xdeadbeef'; const varName = 'address'; - return expect(assert.isSenderAddressHexAsync(varName, address, (zeroEx as any).web3Wrapper)) + return expect(assert.isSenderAddressAsync(varName, address, (zeroEx as any).web3Wrapper)) .to.be.rejectedWith(`Expected ${varName} to be of type ETHAddressHex, encountered: ${address}`); }); it('throws when address is unavailable', async () => { const validUnrelatedAddress = '0x8b0292b11a196601eddce54b665cafeca0347d42'; const varName = 'address'; - return expect(assert.isSenderAddressHexAsync(varName, validUnrelatedAddress, (zeroEx as any).web3Wrapper)) + return expect(assert.isSenderAddressAsync(varName, validUnrelatedAddress, (zeroEx as any).web3Wrapper)) .to.be.rejectedWith(`Specified ${varName} ${validUnrelatedAddress} \ isn't available through the supplied web3 instance`); }); it('doesn\'t throw if address is available', async () => { const availableAddress = (await zeroEx.getAvailableAddressesAsync())[0]; const varName = 'address'; - return expect(assert.isSenderAddressHexAsync(varName, availableAddress, (zeroEx as any).web3Wrapper)) + return expect(assert.isSenderAddressAsync(varName, availableAddress, (zeroEx as any).web3Wrapper)) .to.become(undefined); }); }); -- cgit