From 8c877bb18a7cfe950dc895308dbd76bf25a50082 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 29 May 2017 13:39:32 +0200 Subject: Implement tests for signOrderHashAsync that test the logic for Parity < v1.6.6, >1.6.6 and other nodes --- test/0x.js_test.ts | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'test') 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); + }); + }); }); -- cgit v1.2.3 From a331943c11b8602f4c8781243dc1fac5d9c595bf Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 29 May 2017 15:59:42 +0200 Subject: Use disable-next-line instead of disable and always put rule that is being disabled --- test/0x.js_test.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index d0e4e0f30..6de054437 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -182,9 +182,8 @@ describe('ZeroEx library', () => { 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 */ + // tslint:disable-next-line: max-line-length const signature = '0x22109d11d79cb8bf96ed88625e1cd9558800c4073332a9a02857499883ee5ce3050aa3cc1f2c435e67e114cdce54b9527b4f50548342401bc5d2b77adbdacb021b'; - /* tslint:enable */ const expectedECSignature = { v: 27, r: '0x22109d11d79cb8bf96ed88625e1cd9558800c4073332a9a02857499883ee5ce3', @@ -207,9 +206,8 @@ describe('ZeroEx library', () => { 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 */ + // tslint:disable-next-line: max-line-length const signature = '0x1bc80bedc6756722672753413efdd749b5adbd4fd552595f59c13427407ee9aee02dea66f25a608bbae457e020fb6decb763deb8b7192abab624997242da248960'; - /* tslint:enable */ const expectedECSignature = { v: 27, r: '0xc80bedc6756722672753413efdd749b5adbd4fd552595f59c13427407ee9aee0', -- cgit v1.2.3 From 19581429366909038a7a3fa21eef09d466c150e0 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 29 May 2017 16:10:34 +0200 Subject: empty stubs array before next test runs --- test/0x.js_test.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 871e8c727..26684972f 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -165,6 +165,7 @@ describe('ZeroEx library', () => { afterEach(() => { // clean up any stubs after the test has completed _.each(stubs, s => s.restore()); + stubs = []; }); it ('Should return the correct ECSignature on TestPRC nodeVersion', async () => { const orderHash = '0x6927e990021d23b1eb7b8789f6a6feaf98fe104bb0cf8259421b79f9a34222b0'; -- cgit v1.2.3