From 405857fa8137eeb45a690ccd18ce2281bf3a7319 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 29 May 2017 11:50:03 +0200 Subject: Use constants from test utils --- test/0x.js_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 5dbb781ab..7106b6a7a 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -4,7 +4,7 @@ import 'mocha'; import * as BigNumber from 'bignumber.js'; import ChaiBigNumber = require('chai-bignumber'); import {ZeroEx} from '../src/0x.js'; -import {constants} from '../src/utils/constants'; +import {constants} from './utils/constants'; // Use BigNumber chai add-on chai.use(ChaiBigNumber()); -- cgit v1.2.3 From bb3e7a2b7d206cec772c5026df6194d22836dc7a Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 29 May 2017 11:55:43 +0200 Subject: Use only 0x public interface in contract wrapper tests --- test/contract_wrapper_test.ts | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/test/contract_wrapper_test.ts b/test/contract_wrapper_test.ts index 4ff56ea3e..4bfc49374 100644 --- a/test/contract_wrapper_test.ts +++ b/test/contract_wrapper_test.ts @@ -3,21 +3,18 @@ import * as chai from 'chai'; import chaiAsPromised = require('chai-as-promised'); import * as Web3 from 'web3'; 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 {Web3Wrapper} from './../src/web3_wrapper'; const expect = chai.expect; chai.use(chaiAsPromised); const blockchainLifecycle = new BlockchainLifecycle(); describe('ExchangeWrapper', () => { - let web3Wrapper: Web3Wrapper; - let exchangeWrapper: ExchangeWrapper; + let zeroEx: ZeroEx; before(async () => { const web3 = web3Factory.create(); - web3Wrapper = new Web3Wrapper(web3); - exchangeWrapper = new ExchangeWrapper(web3Wrapper); + zeroEx = new ZeroEx(web3); }); beforeEach(async () => { await blockchainLifecycle.startAsync(); @@ -42,7 +39,7 @@ describe('ExchangeWrapper', () => { r: signature.r, s: signature.s, }; - expect(exchangeWrapper.isValidSignatureAsync(dataHex, malformedSignature, address)) + expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address)) .to.be.rejected; }); it('r lacks 0x prefix', () => { @@ -52,7 +49,7 @@ describe('ExchangeWrapper', () => { r: malformedR, s: signature.s, }; - expect(exchangeWrapper.isValidSignatureAsync(dataHex, malformedSignature, address)) + expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address)) .to.be.rejected; }); it('r is too short', () => { @@ -62,7 +59,7 @@ describe('ExchangeWrapper', () => { r: malformedR, s: signature.s.replace('0', 'z'), }; - expect(exchangeWrapper.isValidSignatureAsync(dataHex, malformedSignature, address)) + expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address)) .to.be.rejected; }); it('s is not hex', () => { @@ -72,26 +69,26 @@ describe('ExchangeWrapper', () => { r: signature.r, s: malformedS, }; - expect(exchangeWrapper.isValidSignatureAsync(dataHex, malformedSignature, address)) + expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address)) .to.be.rejected; }); }); 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; }); it('should return false if the address doesn\'t pertain to the signature & dataHex', async () => { 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; }); it('should return false if the signature doesn\'t pertain to the dataHex & address', async () => { 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; }); 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; }); }); -- cgit v1.2.3 From b08855985066467e16a1ecc7cf2624ebbb6f68ad Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 29 May 2017 12:01:18 +0200 Subject: Rename build:bundle to build:umd --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5c352bc88..3628608bd 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ ], "scripts": { "clean": "shx rm -rf _bundles lib", - "build:bundle": "webpack", + "build:umd": "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", -- cgit v1.2.3 From 144456503ce2ff476c050f88af30e3a5f07f907e Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 29 May 2017 12:19:50 +0200 Subject: Make eventually a PromisedAssertion --- src/globals.d.ts | 3 ++- webpack.config.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/globals.d.ts b/src/globals.d.ts index dee957f2f..4c9adcd48 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -15,7 +15,8 @@ declare interface Schema { declare namespace Chai { interface Assertion { bignumber: Assertion; - eventually: Assertion; + // HACK: In order t comply with chai-as-promised we make eventually a PromisedAssertion not an assertion + eventually: PromisedAssertion; } } /* tslint:enable */ diff --git a/webpack.config.js b/webpack.config.js index 67af51f7a..7b7b10b52 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -6,8 +6,8 @@ const path = require('path'); module.exports = { entry: { - '0x': './src/ts/0x.js.ts', - '0x.min': './src/ts/0x.js.ts' + '0x': './src/0x.js.ts', + '0x.min': './src/0x.js.ts' }, output: { path: path.resolve(__dirname, '_bundles'), -- cgit v1.2.3 From 055763cd373c5203182bc269ee3f8f737a34ba8e Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 29 May 2017 12:44:22 +0200 Subject: Add umd test command and separate public and private npm scripts --- package.json | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 3628608bd..ab6b4d928 100644 --- a/package.json +++ b/package.json @@ -10,18 +10,21 @@ "exchange" ], "scripts": { - "clean": "shx rm -rf _bundles lib", - "build:umd": "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", - "test": "run-s clean build:commonjs && mocha lib/test/**/*_test.js", + "test": "run-s build test:commonjs test:umd", "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", + + "clean": "shx rm -rf _bundles lib", + "build:umd": "webpack", + "build:commonjs": "tsc; copyfiles -u 2 ./src/artifacts/*.json ../0x.js/lib/src/artifacts;", + "test:commonjs": "mocha lib/test/**/*_test.js", + "test:umd": "shx rm -rf lib/src/* && mv _bundles/* lib/src && npm run test:commonjs", "docs:json": "typedoc --json docs/index.json .", "docs:generate": "typedoc --out docs .", - "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" + "docs:open": "opn docs/index.html" }, "config": { "artifacts": "Proxy Exchange TokenRegistry Token Mintable EtherToken" -- cgit v1.2.3 From 6213407f544e34c13a4d125136d14a1d888d8c6a Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 29 May 2017 13:27:26 +0200 Subject: Refactor test commands --- package.json | 24 +++++++++++++++--------- webpack.config.js | 13 +++++++++---- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index ab6b4d928..b2c7d4b19 100644 --- a/package.json +++ b/package.json @@ -10,21 +10,27 @@ "exchange" ], "scripts": { - "build": "npm run clean && run-p build:*", + "build": "npm run clean && run-p build:*:prod", "lint": "tslint src/**/*.ts", - "test": "run-s build test:commonjs test:umd", + "test": "run-s build:dev test:commonjs test:umd", "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", - - "clean": "shx rm -rf _bundles lib", - "build:umd": "webpack", - "build:commonjs": "tsc; copyfiles -u 2 ./src/artifacts/*.json ../0x.js/lib/src/artifacts;", - "test:commonjs": "mocha lib/test/**/*_test.js", - "test:umd": "shx rm -rf lib/src/* && mv _bundles/* lib/src && npm run test:commonjs", "docs:json": "typedoc --json docs/index.json .", "docs:generate": "typedoc --out docs .", - "docs:open": "opn docs/index.html" + "docs:open": "opn docs/index.html", + + "clean": "shx rm -rf _bundles lib", + "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": { "artifacts": "Proxy Exchange TokenRegistry Token Mintable EtherToken" diff --git a/webpack.config.js b/webpack.config.js index 7b7b10b52..9718477aa 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -3,12 +3,17 @@ */ const webpack = require('webpack'); const path = require('path'); +const PROD = process.env.NODE_ENV === 'production'; + +let entry = { + '0x': './src/0x.js.ts', +}; +if (PROD) { + entry = Object.assign({}, entry, {'0x.min': './src/0x.js.ts'}); +} module.exports = { - entry: { - '0x': './src/0x.js.ts', - '0x.min': './src/0x.js.ts' - }, + entry, output: { path: path.resolve(__dirname, '_bundles'), filename: '[name].js', -- cgit v1.2.3 From fa156531bf2aad507a0e644655dc9f34f6fcff28 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 29 May 2017 13:36:48 +0200 Subject: Don't build before test --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b2c7d4b19..7f92dbb9a 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "scripts": { "build": "npm run clean && run-p build:*:prod", "lint": "tslint src/**/*.ts", - "test": "run-s build:dev test:commonjs test:umd", + "test": "run-s test:commonjs test:umd", "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", -- cgit v1.2.3 From 7bd3d87f7a7d7c54b08e3e62b8075ec569498c63 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 29 May 2017 15:54:52 +0200 Subject: Address feedback --- package.json | 2 +- src/globals.d.ts | 2 +- webpack.config.js | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 7f92dbb9a..3b29795a8 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "docs:generate": "typedoc --out docs .", "docs:open": "opn docs/index.html", - "clean": "shx rm -rf _bundles lib", + "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", diff --git a/src/globals.d.ts b/src/globals.d.ts index 4c9adcd48..0062a05cb 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -15,7 +15,7 @@ declare interface Schema { declare namespace Chai { interface Assertion { bignumber: Assertion; - // HACK: In order t comply with chai-as-promised we make eventually a PromisedAssertion not an assertion + // HACK: In order to comply with chai-as-promised we make eventually a `PromisedAssertion` not an `Assertion` eventually: PromisedAssertion; } } diff --git a/webpack.config.js b/webpack.config.js index 9718477aa..03a7c6cac 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,15 +1,16 @@ /** * This is to generate the umd bundle only */ +const lodash = require('lodash'); const webpack = require('webpack'); const path = require('path'); -const PROD = process.env.NODE_ENV === 'production'; +const production = process.env.NODE_ENV === 'production'; let entry = { '0x': './src/0x.js.ts', }; -if (PROD) { - entry = Object.assign({}, entry, {'0x.min': './src/0x.js.ts'}); +if (production) { + entry = _.assign({}, entry, {'0x.min': './src/0x.js.ts'}); } module.exports = { -- cgit v1.2.3