diff options
Diffstat (limited to 'packages/contracts/test/exchange/helpers.ts')
-rw-r--r-- | packages/contracts/test/exchange/helpers.ts | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/packages/contracts/test/exchange/helpers.ts b/packages/contracts/test/exchange/helpers.ts index 33bf8b803..5fe00225e 100644 --- a/packages/contracts/test/exchange/helpers.ts +++ b/packages/contracts/test/exchange/helpers.ts @@ -1,4 +1,4 @@ -import { ZeroEx } from '0x.js'; +import { SignedOrder, ZeroEx } from '0x.js'; import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; @@ -8,7 +8,6 @@ import ethUtil = require('ethereumjs-util'); import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange'; import { constants } from '../../util/constants'; import { ExchangeWrapper } from '../../util/exchange_wrapper'; -import { Order } from '../../util/order'; import { OrderFactory } from '../../util/order_factory'; import { ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; @@ -25,7 +24,7 @@ describe('Exchange', () => { let maker: string; let feeRecipient: string; - let order: Order; + let signedOrder: SignedOrder; let exchangeWrapper: ExchangeWrapper; let orderFactory: OrderFactory; @@ -58,8 +57,8 @@ describe('Exchange', () => { makerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18), takerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18), }; - orderFactory = new OrderFactory(web3Wrapper, defaultOrderParams); - order = await orderFactory.newSignedOrderAsync(); + orderFactory = new OrderFactory(zeroEx, defaultOrderParams); + signedOrder = await orderFactory.newSignedOrderAsync(); }); beforeEach(async () => { @@ -70,28 +69,31 @@ describe('Exchange', () => { }); describe('getOrderHash', () => { it('should output the correct orderHash', async () => { - const orderHashHex = await exchangeWrapper.getOrderHashAsync(order); - expect(order.params.orderHashHex).to.be.equal(orderHashHex); + const orderHashHex = await exchangeWrapper.getOrderHashAsync(signedOrder); + expect(ZeroEx.getOrderHashHex(signedOrder)).to.be.equal(orderHashHex); }); }); describe('isValidSignature', () => { beforeEach(async () => { - order = await orderFactory.newSignedOrderAsync(); + signedOrder = await orderFactory.newSignedOrderAsync(); }); it('should return true with a valid signature', async () => { - const success = await exchangeWrapper.isValidSignatureAsync(order); - const isValidSignature = order.isValidSignature(); + const success = await exchangeWrapper.isValidSignatureAsync(signedOrder); + const orderHashHex = ZeroEx.getOrderHashHex(signedOrder); + const isValidSignature = ZeroEx.isValidSignature(orderHashHex, signedOrder.ecSignature, signedOrder.maker); expect(isValidSignature).to.be.true(); expect(success).to.be.true(); }); it('should return false with an invalid signature', async () => { - order.params.r = ethUtil.bufferToHex(ethUtil.sha3('invalidR')); - order.params.s = ethUtil.bufferToHex(ethUtil.sha3('invalidS')); - const success = await exchangeWrapper.isValidSignatureAsync(order); - expect(order.isValidSignature()).to.be.false(); + signedOrder.ecSignature.r = ethUtil.bufferToHex(ethUtil.sha3('invalidR')); + signedOrder.ecSignature.s = ethUtil.bufferToHex(ethUtil.sha3('invalidS')); + const success = await exchangeWrapper.isValidSignatureAsync(signedOrder); + const orderHashHex = ZeroEx.getOrderHashHex(signedOrder); + const isValidSignature = ZeroEx.isValidSignature(orderHashHex, signedOrder.ecSignature, signedOrder.maker); + expect(isValidSignature).to.be.false(); expect(success).to.be.false(); }); }); |