From 0499541e114e6dd36565428f4f914e0dbdece2b8 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 24 Apr 2018 16:36:35 +0200 Subject: Move order utils to @0xproject/order-utils --- packages/order-utils/test/order_hash_test.ts | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 packages/order-utils/test/order_hash_test.ts (limited to 'packages/order-utils/test/order_hash_test.ts') diff --git a/packages/order-utils/test/order_hash_test.ts b/packages/order-utils/test/order_hash_test.ts new file mode 100644 index 000000000..b6dda1a43 --- /dev/null +++ b/packages/order-utils/test/order_hash_test.ts @@ -0,0 +1,46 @@ +import { web3Factory } from '@0xproject/dev-utils'; +import { BigNumber } from '@0xproject/utils'; +import * as chai from 'chai'; +import 'mocha'; + +import { constants, getOrderHashHex } from '../src'; + +import { chaiSetup } from './utils/chai_setup'; +import { web3Wrapper } from './utils/web3_wrapper'; + +chaiSetup.configure(); +const expect = chai.expect; + +describe('Order hashing', () => { + describe('#getOrderHashHex', () => { + const expectedOrderHash = '0x39da987067a3c9e5f1617694f1301326ba8c8b0498ebef5df4863bed394e3c83'; + const fakeExchangeContractAddress = '0xb69e673309512a9d726f87304c6984054f87a93b'; + const order = { + maker: constants.NULL_ADDRESS, + taker: constants.NULL_ADDRESS, + feeRecipient: constants.NULL_ADDRESS, + makerTokenAddress: constants.NULL_ADDRESS, + takerTokenAddress: constants.NULL_ADDRESS, + exchangeContractAddress: fakeExchangeContractAddress, + salt: new BigNumber(0), + makerFee: new BigNumber(0), + takerFee: new BigNumber(0), + makerTokenAmount: new BigNumber(0), + takerTokenAmount: new BigNumber(0), + expirationUnixTimestampSec: new BigNumber(0), + }; + it('calculates the order hash', async () => { + const orderHash = getOrderHashHex(order); + expect(orderHash).to.be.equal(expectedOrderHash); + }); + it('throws a readable error message if taker format is invalid', async () => { + const orderWithInvalidtakerFormat = { + ...order, + taker: (null as any) as string, + }; + const expectedErrorMessage = + 'Order taker must be of type string. If you want anyone to be able to fill an order - pass ZeroEx.NULL_ADDRESS'; + expect(() => getOrderHashHex(orderWithInvalidtakerFormat)).to.throw(expectedErrorMessage); + }); + }); +}); -- cgit v1.2.3