aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-05-29 22:32:32 +0800
committerGitHub <noreply@github.com>2017-05-29 22:32:32 +0800
commit041394e652db09b6f90e1057beb657b159dc0e56 (patch)
treec3547c43f02c119798af6f15485d73be570392e7 /test
parentabd0228ba8b71b35ff089fc647674caa08d7a24e (diff)
parent19581429366909038a7a3fa21eef09d466c150e0 (diff)
downloaddexon-sol-tools-041394e652db09b6f90e1057beb657b159dc0e56.tar
dexon-sol-tools-041394e652db09b6f90e1057beb657b159dc0e56.tar.gz
dexon-sol-tools-041394e652db09b6f90e1057beb657b159dc0e56.tar.bz2
dexon-sol-tools-041394e652db09b6f90e1057beb657b159dc0e56.tar.lz
dexon-sol-tools-041394e652db09b6f90e1057beb657b159dc0e56.tar.xz
dexon-sol-tools-041394e652db09b6f90e1057beb657b159dc0e56.tar.zst
dexon-sol-tools-041394e652db09b6f90e1057beb657b159dc0e56.zip
Merge pull request #17 from 0xProject/addSignOrderHashAndTests
Add signOrderHashAsync and tests
Diffstat (limited to 'test')
-rw-r--r--test/0x.js_test.ts71
1 files changed, 71 insertions, 0 deletions
diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts
index 289c823af..26684972f 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 './utils/constants';
+import {web3Factory} from './utils/web3_factory';
// Use BigNumber chai add-on
chai.use(ChaiBigNumber());
@@ -158,4 +160,73 @@ 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());
+ stubs = [];
+ });
+ 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-next-line: max-line-length
+ const signature = '0x22109d11d79cb8bf96ed88625e1cd9558800c4073332a9a02857499883ee5ce3050aa3cc1f2c435e67e114cdce54b9527b4f50548342401bc5d2b77adbdacb021b';
+ 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-next-line: max-line-length
+ const signature = '0x1bc80bedc6756722672753413efdd749b5adbd4fd552595f59c13427407ee9aee02dea66f25a608bbae457e020fb6decb763deb8b7192abab624997242da248960';
+ 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);
+ });
+ });
});