diff options
author | Fabio Berger <me@fabioberger.com> | 2017-05-29 19:39:32 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-05-29 19:39:32 +0800 |
commit | 8c877bb18a7cfe950dc895308dbd76bf25a50082 (patch) | |
tree | 52f748fb37df516e0f0aaf079344e9d6093d069f /test/0x.js_test.ts | |
parent | eb90367fc4fc666786398ab9803b77bfb900c661 (diff) | |
download | dexon-0x-contracts-8c877bb18a7cfe950dc895308dbd76bf25a50082.tar dexon-0x-contracts-8c877bb18a7cfe950dc895308dbd76bf25a50082.tar.gz dexon-0x-contracts-8c877bb18a7cfe950dc895308dbd76bf25a50082.tar.bz2 dexon-0x-contracts-8c877bb18a7cfe950dc895308dbd76bf25a50082.tar.lz dexon-0x-contracts-8c877bb18a7cfe950dc895308dbd76bf25a50082.tar.xz dexon-0x-contracts-8c877bb18a7cfe950dc895308dbd76bf25a50082.tar.zst dexon-0x-contracts-8c877bb18a7cfe950dc895308dbd76bf25a50082.zip |
Implement tests for signOrderHashAsync that test the logic for Parity < v1.6.6, >1.6.6 and other nodes
Diffstat (limited to 'test/0x.js_test.ts')
-rw-r--r-- | test/0x.js_test.ts | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index b8eece5d4..d0e4e0f30 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -3,8 +3,10 @@ import * as chai from 'chai'; import 'mocha'; import * as BigNumber from 'bignumber.js'; import ChaiBigNumber = require('chai-bignumber'); +import * as Sinon from 'sinon'; import {ZeroEx} from '../src/0x.js'; import {constants} from '../src/utils/constants'; +import {web3Factory} from './utils/web3_factory'; // Use BigNumber chai add-on chai.use(ChaiBigNumber()); @@ -158,4 +160,74 @@ describe('ZeroEx library', () => { expect(baseUnitAmount).to.be.bignumber.equal(expectedUnitAmount); }); }); + describe('#signOrderHashAsync', () => { + let stubs: Sinon.SinonStub[] = []; + afterEach(() => { + // clean up any stubs after the test has completed + _.each(stubs, s => s.restore()); + }); + it ('Should return the correct ECSignature on TestPRC nodeVersion', async () => { + const orderHash = '0x6927e990021d23b1eb7b8789f6a6feaf98fe104bb0cf8259421b79f9a34222b0'; + const expectedECSignature = { + v: 27, + r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', + s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', + }; + + const web3 = web3Factory.create(); + const zeroEx = new ZeroEx(web3); + const ecSignature = await zeroEx.signOrderHashAsync(orderHash); + expect(ecSignature).to.deep.equal(expectedECSignature); + }); + it ('should return the correct ECSignature on Party > V1.6.6', async () => { + const newParityNodeVersion = 'Parity//v1.6.7-beta-e128418-20170518/x86_64-macos/rustc1.17.0'; + const orderHash = '0x34decbedc118904df65f379a175bb39ca18209d6ce41d5ed549d54e6e0a95004'; + /* tslint:disable */ + const signature = '0x22109d11d79cb8bf96ed88625e1cd9558800c4073332a9a02857499883ee5ce3050aa3cc1f2c435e67e114cdce54b9527b4f50548342401bc5d2b77adbdacb021b'; + /* tslint:enable */ + const expectedECSignature = { + v: 27, + r: '0x22109d11d79cb8bf96ed88625e1cd9558800c4073332a9a02857499883ee5ce3', + s: '0x050aa3cc1f2c435e67e114cdce54b9527b4f50548342401bc5d2b77adbdacb02', + }; + + const web3 = web3Factory.create(); + const zeroEx = new ZeroEx(web3); + stubs = [ + Sinon.stub(zeroEx.web3Wrapper, 'getNodeVersionAsync') + .returns(Promise.resolve(newParityNodeVersion)), + Sinon.stub(zeroEx.web3Wrapper, 'signTransactionAsync') + .returns(Promise.resolve(signature)), + Sinon.stub(ZeroEx, 'isValidSignature').returns(true), + ]; + + const ecSignature = await zeroEx.signOrderHashAsync(orderHash); + expect(ecSignature).to.deep.equal(expectedECSignature); + }); + it ('should return the correct ECSignature on Party < V1.6.6', async () => { + const newParityNodeVersion = 'Parity//v1.6.6-beta-8c6e3f3-20170411/x86_64-macos/rustc1.16.0'; + const orderHash = '0xc793e33ffded933b76f2f48d9aa3339fc090399d5e7f5dec8d3660f5480793f7'; + /* tslint:disable */ + const signature = '0x1bc80bedc6756722672753413efdd749b5adbd4fd552595f59c13427407ee9aee02dea66f25a608bbae457e020fb6decb763deb8b7192abab624997242da248960'; + /* tslint:enable */ + const expectedECSignature = { + v: 27, + r: '0xc80bedc6756722672753413efdd749b5adbd4fd552595f59c13427407ee9aee0', + s: '0x2dea66f25a608bbae457e020fb6decb763deb8b7192abab624997242da248960', + }; + + const web3 = web3Factory.create(); + const zeroEx = new ZeroEx(web3); + stubs = [ + Sinon.stub(zeroEx.web3Wrapper, 'getNodeVersionAsync') + .returns(Promise.resolve(newParityNodeVersion)), + Sinon.stub(zeroEx.web3Wrapper, 'signTransactionAsync') + .returns(Promise.resolve(signature)), + Sinon.stub(ZeroEx, 'isValidSignature').returns(true), + ]; + + const ecSignature = await zeroEx.signOrderHashAsync(orderHash); + expect(ecSignature).to.deep.equal(expectedECSignature); + }); + }); }); |