aboutsummaryrefslogtreecommitdiffstats
path: root/packages/dev-utils
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-05-10 02:36:28 +0800
committerFabio Berger <me@fabioberger.com>2018-05-10 02:36:28 +0800
commit209266dbed9d7d038c90c2da8d9b99acab77c80c (patch)
treecfefd5ab15bc237716b15687629e0f41362a8e86 /packages/dev-utils
parent69a6166b6a1d39afc24b8dd950ec5d8539a03420 (diff)
downloaddexon-sol-tools-209266dbed9d7d038c90c2da8d9b99acab77c80c.tar
dexon-sol-tools-209266dbed9d7d038c90c2da8d9b99acab77c80c.tar.gz
dexon-sol-tools-209266dbed9d7d038c90c2da8d9b99acab77c80c.tar.bz2
dexon-sol-tools-209266dbed9d7d038c90c2da8d9b99acab77c80c.tar.lz
dexon-sol-tools-209266dbed9d7d038c90c2da8d9b99acab77c80c.tar.xz
dexon-sol-tools-209266dbed9d7d038c90c2da8d9b99acab77c80c.tar.zst
dexon-sol-tools-209266dbed9d7d038c90c2da8d9b99acab77c80c.zip
Split 0x.js into contract-wrappers, order-watcher but keep 0x.js as a unifying library with the same interface
Diffstat (limited to 'packages/dev-utils')
-rw-r--r--packages/dev-utils/CHANGELOG.json8
-rw-r--r--packages/dev-utils/src/callback_error_reporter.ts66
-rw-r--r--packages/dev-utils/src/index.ts1
3 files changed, 75 insertions, 0 deletions
diff --git a/packages/dev-utils/CHANGELOG.json b/packages/dev-utils/CHANGELOG.json
index 9da323f48..97ba89e3e 100644
--- a/packages/dev-utils/CHANGELOG.json
+++ b/packages/dev-utils/CHANGELOG.json
@@ -1,5 +1,13 @@
[
{
+ "version": "0.4.2",
+ "changes": [
+ {
+ "note": "Move callbackErrorReporter over from 0x.js"
+ }
+ ]
+ },
+ {
"timestamp": 1525477860,
"version": "0.4.1",
"changes": [
diff --git a/packages/dev-utils/src/callback_error_reporter.ts b/packages/dev-utils/src/callback_error_reporter.ts
new file mode 100644
index 000000000..874343ccc
--- /dev/null
+++ b/packages/dev-utils/src/callback_error_reporter.ts
@@ -0,0 +1,66 @@
+import * as chai from 'chai';
+import * as _ from 'lodash';
+
+import { DoneCallback } from '@0xproject/types';
+
+const expect = chai.expect;
+
+export const callbackErrorReporter = {
+ reportNoErrorCallbackErrors(done: DoneCallback, expectToBeCalledOnce = true) {
+ return <T>(f?: (value: T) => void) => {
+ const wrapped = (value: T) => {
+ if (_.isUndefined(f)) {
+ done();
+ return;
+ }
+ try {
+ f(value);
+ if (expectToBeCalledOnce) {
+ done();
+ }
+ } catch (err) {
+ done(err);
+ }
+ };
+ return wrapped;
+ };
+ },
+ reportNodeCallbackErrors(done: DoneCallback, expectToBeCalledOnce = true) {
+ return <T>(f?: (value: T) => void) => {
+ const wrapped = (error: Error | null, value: T | undefined) => {
+ if (!_.isNull(error)) {
+ done(error);
+ } else {
+ if (_.isUndefined(f)) {
+ done();
+ return;
+ }
+ try {
+ f(value as T);
+ if (expectToBeCalledOnce) {
+ done();
+ }
+ } catch (err) {
+ done(err);
+ }
+ }
+ };
+ return wrapped;
+ };
+ },
+ assertNodeCallbackError(done: DoneCallback, errMsg: string) {
+ const wrapped = <T>(error: Error | null, value: T | undefined) => {
+ if (_.isNull(error)) {
+ done(new Error('Expected callback to receive an error'));
+ } else {
+ try {
+ expect(error.message).to.be.equal(errMsg);
+ done();
+ } catch (err) {
+ done(err);
+ }
+ }
+ };
+ return wrapped;
+ },
+};
diff --git a/packages/dev-utils/src/index.ts b/packages/dev-utils/src/index.ts
index 2ff2a2238..9124f3e28 100644
--- a/packages/dev-utils/src/index.ts
+++ b/packages/dev-utils/src/index.ts
@@ -3,3 +3,4 @@ export { web3Factory } from './web3_factory';
export { constants as devConstants } from './constants';
export { coverage } from './coverage';
export { env, EnvVars } from './env';
+export { callbackErrorReporter } from './callback_error_reporter';