diff options
author | Leonid <logvinov.leon@gmail.com> | 2018-02-09 01:15:10 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-09 01:15:10 +0800 |
commit | 254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd (patch) | |
tree | ff8e4c1e59bcc71253f39ee92dc9740941504f37 /packages/contracts/test/exchange/helpers.ts | |
parent | eebf205817d3d812a40158d146110c7868a42bf0 (diff) | |
parent | 876517d4580c864359898c572df8e081430c32ce (diff) | |
download | dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.tar dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.tar.gz dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.tar.bz2 dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.tar.lz dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.tar.xz dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.tar.zst dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.zip |
Merge pull request #377 from 0xProject/feature/signed_unsigned_order_contracts
Use SignedOrder and Order types from 0x.js
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(); }); }); |