Merge branch 'master' into addSignOrderHashAndTests

# Conflicts:
#	package.json
#	src/globals.d.ts
#	test/0x.js_test.ts
This commit is contained in:
Fabio Berger 2017-05-29 16:06:04 +02:00
commit c513a5a5bd
5 changed files with 39 additions and 26 deletions

View File

@ -10,18 +10,27 @@
"exchange" "exchange"
], ],
"scripts": { "scripts": {
"clean": "shx rm -rf _bundles lib", "build": "npm run clean && run-p build:*:prod",
"build:bundle": "webpack",
"build:commonjs": "tsc; copyfiles -u 2 ./src/artifacts/*.json ../0x.js/lib/src/artifacts;",
"build": "npm run clean && run-p build:*",
"lint": "tslint src/**/*.ts", "lint": "tslint src/**/*.ts",
"test": "run-s clean build:commonjs && mocha lib/test/**/*_test.js", "test": "run-s test:commonjs test:umd",
"test:coverage": "nyc npm run test --all", "test:coverage": "nyc npm run test --all",
"update_contracts": "for i in ${npm_package_config_artifacts}; do copyfiles -u 4 ../contracts/build/contracts/$i.json ../0x.js/src/artifacts; done;",
"testrpc": "testrpc -p 8545 --networkId 50 -m \"concert load couple harbor equip island argue ramp clarify fence smart topic\"",
"docs:json": "typedoc --json docs/index.json .", "docs:json": "typedoc --json docs/index.json .",
"docs:generate": "typedoc --out docs .", "docs:generate": "typedoc --out docs .",
"docs:open": "opn docs/index.html", "docs:open": "opn docs/index.html",
"update_contracts": "for i in ${npm_package_config_artifacts}; do copyfiles -u 4 ../contracts/build/contracts/$i.json ../0x.js/src/artifacts; done;",
"testrpc": "testrpc -p 8545 --networkId 50 -m \"concert load couple harbor equip island argue ramp clarify fence smart topic\"" "clean": "shx rm -rf _bundles lib test_temp",
"build:dev": "npm run clean && run-p build:*:dev",
"build:umd:dev": "webpack",
"build:umd:prod": "webpack -p",
"build:commonjs:dev": "tsc; copyfiles -u 2 ./src/artifacts/*.json ../0x.js/lib/src/artifacts;",
"run_mocha": "mocha test_temp/test/**/*_test.js",
"test:commonjs": "run-s build:commonjs:dev setup_commonjs run_mocha tear_down",
"test:umd": "run-s build:*:dev setup_umd run_mocha tear_down",
"setup_commonjs": "shx cp -r lib test_temp",
"setup_umd": "shx mkdir -p test_temp/src && shx cp _bundles/* test_temp/src && shx cp -r lib/test test_temp/test",
"tear_down": "shx rm -rf test_temp"
}, },
"config": { "config": {
"artifacts": "Proxy Exchange TokenRegistry Token Mintable EtherToken" "artifacts": "Proxy Exchange TokenRegistry Token Mintable EtherToken"

1
src/globals.d.ts vendored
View File

@ -15,6 +15,7 @@ declare interface Schema {
declare namespace Chai { declare namespace Chai {
interface Assertion { interface Assertion {
bignumber: Assertion; bignumber: Assertion;
// HACK: In order to comply with chai-as-promised we make eventually a `PromisedAssertion` not an `Assertion`
eventually: PromisedAssertion; eventually: PromisedAssertion;
} }
} }

View File

@ -5,7 +5,7 @@ import * as BigNumber from 'bignumber.js';
import ChaiBigNumber = require('chai-bignumber'); import ChaiBigNumber = require('chai-bignumber');
import * as Sinon from 'sinon'; import * as Sinon from 'sinon';
import {ZeroEx} from '../src/0x.js'; import {ZeroEx} from '../src/0x.js';
import {constants} from '../src/utils/constants'; import {constants} from './utils/constants';
import {web3Factory} from './utils/web3_factory'; import {web3Factory} from './utils/web3_factory';
// Use BigNumber chai add-on // Use BigNumber chai add-on

View File

@ -3,21 +3,18 @@ import * as chai from 'chai';
import chaiAsPromised = require('chai-as-promised'); import chaiAsPromised = require('chai-as-promised');
import * as Web3 from 'web3'; import * as Web3 from 'web3';
import {web3Factory} from './utils/web3_factory'; import {web3Factory} from './utils/web3_factory';
import {ExchangeWrapper} from '../src/contract_wrappers/exchange_wrapper'; import {ZeroEx} from '../src/0x.js';
import {BlockchainLifecycle} from './utils/blockchain_lifecycle'; import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
import {Web3Wrapper} from './../src/web3_wrapper';
const expect = chai.expect; const expect = chai.expect;
chai.use(chaiAsPromised); chai.use(chaiAsPromised);
const blockchainLifecycle = new BlockchainLifecycle(); const blockchainLifecycle = new BlockchainLifecycle();
describe('ExchangeWrapper', () => { describe('ExchangeWrapper', () => {
let web3Wrapper: Web3Wrapper; let zeroEx: ZeroEx;
let exchangeWrapper: ExchangeWrapper;
before(async () => { before(async () => {
const web3 = web3Factory.create(); const web3 = web3Factory.create();
web3Wrapper = new Web3Wrapper(web3); zeroEx = new ZeroEx(web3);
exchangeWrapper = new ExchangeWrapper(web3Wrapper);
}); });
beforeEach(async () => { beforeEach(async () => {
await blockchainLifecycle.startAsync(); await blockchainLifecycle.startAsync();
@ -42,7 +39,7 @@ describe('ExchangeWrapper', () => {
r: signature.r, r: signature.r,
s: signature.s, s: signature.s,
}; };
expect(exchangeWrapper.isValidSignatureAsync(dataHex, malformedSignature, address)) expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address))
.to.be.rejected; .to.be.rejected;
}); });
it('r lacks 0x prefix', () => { it('r lacks 0x prefix', () => {
@ -52,7 +49,7 @@ describe('ExchangeWrapper', () => {
r: malformedR, r: malformedR,
s: signature.s, s: signature.s,
}; };
expect(exchangeWrapper.isValidSignatureAsync(dataHex, malformedSignature, address)) expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address))
.to.be.rejected; .to.be.rejected;
}); });
it('r is too short', () => { it('r is too short', () => {
@ -62,7 +59,7 @@ describe('ExchangeWrapper', () => {
r: malformedR, r: malformedR,
s: signature.s.replace('0', 'z'), s: signature.s.replace('0', 'z'),
}; };
expect(exchangeWrapper.isValidSignatureAsync(dataHex, malformedSignature, address)) expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address))
.to.be.rejected; .to.be.rejected;
}); });
it('s is not hex', () => { it('s is not hex', () => {
@ -72,26 +69,26 @@ describe('ExchangeWrapper', () => {
r: signature.r, r: signature.r,
s: malformedS, s: malformedS,
}; };
expect(exchangeWrapper.isValidSignatureAsync(dataHex, malformedSignature, address)) expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address))
.to.be.rejected; .to.be.rejected;
}); });
}); });
it('should return false if the data doesn\'t pertain to the signature & address', async () => { it('should return false if the data doesn\'t pertain to the signature & address', async () => {
const isValid = await exchangeWrapper.isValidSignatureAsync('0x0', signature, address); const isValid = await zeroEx.exchange.isValidSignatureAsync('0x0', signature, address);
expect(isValid).to.be.false; expect(isValid).to.be.false;
}); });
it('should return false if the address doesn\'t pertain to the signature & dataHex', async () => { it('should return false if the address doesn\'t pertain to the signature & dataHex', async () => {
const validUnrelatedAddress = '0x8b0292B11a196601eD2ce54B665CaFEca0347D42'; const validUnrelatedAddress = '0x8b0292B11a196601eD2ce54B665CaFEca0347D42';
const isValid = await exchangeWrapper.isValidSignatureAsync(dataHex, signature, validUnrelatedAddress); const isValid = await zeroEx.exchange.isValidSignatureAsync(dataHex, signature, validUnrelatedAddress);
expect(isValid).to.be.false; expect(isValid).to.be.false;
}); });
it('should return false if the signature doesn\'t pertain to the dataHex & address', async () => { it('should return false if the signature doesn\'t pertain to the dataHex & address', async () => {
const wrongSignature = Object.assign({}, signature, {v: 28}); const wrongSignature = Object.assign({}, signature, {v: 28});
const isValid = await exchangeWrapper.isValidSignatureAsync(dataHex, wrongSignature, address); const isValid = await zeroEx.exchange.isValidSignatureAsync(dataHex, wrongSignature, address);
expect(isValid).to.be.false; expect(isValid).to.be.false;
}); });
it('should return true if the signature does pertain to the dataHex & address', async () => { it('should return true if the signature does pertain to the dataHex & address', async () => {
const isValid = await exchangeWrapper.isValidSignatureAsync(dataHex, signature, address); const isValid = await zeroEx.exchange.isValidSignatureAsync(dataHex, signature, address);
expect(isValid).to.be.true; expect(isValid).to.be.true;
}); });
}); });

View File

@ -1,14 +1,20 @@
/** /**
* This is to generate the umd bundle only * This is to generate the umd bundle only
*/ */
const lodash = require('lodash');
const webpack = require('webpack'); const webpack = require('webpack');
const path = require('path'); const path = require('path');
const production = process.env.NODE_ENV === 'production';
let entry = {
'0x': './src/0x.js.ts',
};
if (production) {
entry = _.assign({}, entry, {'0x.min': './src/0x.js.ts'});
}
module.exports = { module.exports = {
entry: { entry,
'0x': './src/ts/0x.js.ts',
'0x.min': './src/ts/0x.js.ts'
},
output: { output: {
path: path.resolve(__dirname, '_bundles'), path: path.resolve(__dirname, '_bundles'),
filename: '[name].js', filename: '[name].js',