diff --git a/package-lock.json b/package-lock.json index 31a8dda6dae8..041e61a1b438 100644 --- a/package-lock.json +++ b/package-lock.json @@ -144,6 +144,15 @@ } } }, + "@polkadot/api-format": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@polkadot/api-format/-/api-format-0.2.1.tgz", + "integrity": "sha512-xv9KRA+tmMCyO0TF7UmAqZ0eT63G+q3OrH47TCXQA/+RkNUMRMkM8Z80zHpmnhXd7qSS8QqJoFn0s40VjWaXSg==", + "requires": { + "@polkadot/util": "0.2.1", + "babel-runtime": "6.26.0" + } + }, "@polkadot/jsonrpc": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/@polkadot/jsonrpc/-/jsonrpc-0.2.1.tgz", @@ -1497,6 +1506,7 @@ "requires": { "anymatch": "1.3.2", "async-each": "1.0.1", + "fsevents": "1.1.3", "glob-parent": "2.0.0", "inherits": "2.0.3", "is-binary-path": "1.0.1", @@ -2325,6 +2335,910 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, + "fsevents": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.1.3.tgz", + "integrity": "sha512-WIr7iDkdmdbxu/Gh6eKEZJL6KPE74/5MEsf2whTOFNxbIoIixogroLdKYqB6FDav4Wavh/lZdzzd3b2KxIXC5Q==", + "dev": true, + "optional": true, + "requires": { + "nan": "2.8.0", + "node-pre-gyp": "0.6.39" + }, + "dependencies": { + "abbrev": { + "version": "1.1.0", + "bundled": true, + "dev": true, + "optional": true + }, + "ajv": { + "version": "4.11.8", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "co": "4.6.0", + "json-stable-stringify": "1.0.1" + } + }, + "ansi-regex": { + "version": "2.1.1", + "bundled": true, + "dev": true + }, + "aproba": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "are-we-there-yet": { + "version": "1.1.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "delegates": "1.0.0", + "readable-stream": "2.2.9" + } + }, + "asn1": { + "version": "0.2.3", + "bundled": true, + "dev": true, + "optional": true + }, + "assert-plus": { + "version": "0.2.0", + "bundled": true, + "dev": true, + "optional": true + }, + "asynckit": { + "version": "0.4.0", + "bundled": true, + "dev": true, + "optional": true + }, + "aws-sign2": { + "version": "0.6.0", + "bundled": true, + "dev": true, + "optional": true + }, + "aws4": { + "version": "1.6.0", + "bundled": true, + "dev": true, + "optional": true + }, + "balanced-match": { + "version": "0.4.2", + "bundled": true, + "dev": true + }, + "bcrypt-pbkdf": { + "version": "1.0.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "tweetnacl": "0.14.5" + } + }, + "block-stream": { + "version": "0.0.9", + "bundled": true, + "dev": true, + "requires": { + "inherits": "2.0.3" + } + }, + "boom": { + "version": "2.10.1", + "bundled": true, + "dev": true, + "requires": { + "hoek": "2.16.3" + } + }, + "brace-expansion": { + "version": "1.1.7", + "bundled": true, + "dev": true, + "requires": { + "balanced-match": "0.4.2", + "concat-map": "0.0.1" + } + }, + "buffer-shims": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "caseless": { + "version": "0.12.0", + "bundled": true, + "dev": true, + "optional": true + }, + "co": { + "version": "4.6.0", + "bundled": true, + "dev": true, + "optional": true + }, + "code-point-at": { + "version": "1.1.0", + "bundled": true, + "dev": true + }, + "combined-stream": { + "version": "1.0.5", + "bundled": true, + "dev": true, + "requires": { + "delayed-stream": "1.0.0" + } + }, + "concat-map": { + "version": "0.0.1", + "bundled": true, + "dev": true + }, + "console-control-strings": { + "version": "1.1.0", + "bundled": true, + "dev": true + }, + "core-util-is": { + "version": "1.0.2", + "bundled": true, + "dev": true + }, + "cryptiles": { + "version": "2.0.5", + "bundled": true, + "dev": true, + "requires": { + "boom": "2.10.1" + } + }, + "dashdash": { + "version": "1.14.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "assert-plus": "1.0.0" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "debug": { + "version": "2.6.8", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "ms": "2.0.0" + } + }, + "deep-extend": { + "version": "0.4.2", + "bundled": true, + "dev": true, + "optional": true + }, + "delayed-stream": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "delegates": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "detect-libc": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "ecc-jsbn": { + "version": "0.1.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "jsbn": "0.1.1" + } + }, + "extend": { + "version": "3.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "extsprintf": { + "version": "1.0.2", + "bundled": true, + "dev": true + }, + "forever-agent": { + "version": "0.6.1", + "bundled": true, + "dev": true, + "optional": true + }, + "form-data": { + "version": "2.1.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "asynckit": "0.4.0", + "combined-stream": "1.0.5", + "mime-types": "2.1.15" + } + }, + "fs.realpath": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "fstream": { + "version": "1.0.11", + "bundled": true, + "dev": true, + "requires": { + "graceful-fs": "4.1.11", + "inherits": "2.0.3", + "mkdirp": "0.5.1", + "rimraf": "2.6.1" + } + }, + "fstream-ignore": { + "version": "1.0.5", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "fstream": "1.0.11", + "inherits": "2.0.3", + "minimatch": "3.0.4" + } + }, + "gauge": { + "version": "2.7.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "aproba": "1.1.1", + "console-control-strings": "1.1.0", + "has-unicode": "2.0.1", + "object-assign": "4.1.1", + "signal-exit": "3.0.2", + "string-width": "1.0.2", + "strip-ansi": "3.0.1", + "wide-align": "1.1.2" + } + }, + "getpass": { + "version": "0.1.7", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "assert-plus": "1.0.0" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "glob": { + "version": "7.1.2", + "bundled": true, + "dev": true, + "requires": { + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "graceful-fs": { + "version": "4.1.11", + "bundled": true, + "dev": true + }, + "har-schema": { + "version": "1.0.5", + "bundled": true, + "dev": true, + "optional": true + }, + "har-validator": { + "version": "4.2.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "ajv": "4.11.8", + "har-schema": "1.0.5" + } + }, + "has-unicode": { + "version": "2.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "hawk": { + "version": "3.1.3", + "bundled": true, + "dev": true, + "requires": { + "boom": "2.10.1", + "cryptiles": "2.0.5", + "hoek": "2.16.3", + "sntp": "1.0.9" + } + }, + "hoek": { + "version": "2.16.3", + "bundled": true, + "dev": true + }, + "http-signature": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "assert-plus": "0.2.0", + "jsprim": "1.4.0", + "sshpk": "1.13.0" + } + }, + "inflight": { + "version": "1.0.6", + "bundled": true, + "dev": true, + "requires": { + "once": "1.4.0", + "wrappy": "1.0.2" + } + }, + "inherits": { + "version": "2.0.3", + "bundled": true, + "dev": true + }, + "ini": { + "version": "1.3.4", + "bundled": true, + "dev": true, + "optional": true + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "requires": { + "number-is-nan": "1.0.1" + } + }, + "is-typedarray": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "isarray": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "isstream": { + "version": "0.1.2", + "bundled": true, + "dev": true, + "optional": true + }, + "jodid25519": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "jsbn": "0.1.1" + } + }, + "jsbn": { + "version": "0.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "json-schema": { + "version": "0.2.3", + "bundled": true, + "dev": true, + "optional": true + }, + "json-stable-stringify": { + "version": "1.0.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "jsonify": "0.0.0" + } + }, + "json-stringify-safe": { + "version": "5.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "jsonify": { + "version": "0.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "jsprim": { + "version": "1.4.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "assert-plus": "1.0.0", + "extsprintf": "1.0.2", + "json-schema": "0.2.3", + "verror": "1.3.6" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "mime-db": { + "version": "1.27.0", + "bundled": true, + "dev": true + }, + "mime-types": { + "version": "2.1.15", + "bundled": true, + "dev": true, + "requires": { + "mime-db": "1.27.0" + } + }, + "minimatch": { + "version": "3.0.4", + "bundled": true, + "dev": true, + "requires": { + "brace-expansion": "1.1.7" + } + }, + "minimist": { + "version": "0.0.8", + "bundled": true, + "dev": true + }, + "mkdirp": { + "version": "0.5.1", + "bundled": true, + "dev": true, + "requires": { + "minimist": "0.0.8" + } + }, + "ms": { + "version": "2.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "node-pre-gyp": { + "version": "0.6.39", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "detect-libc": "1.0.2", + "hawk": "3.1.3", + "mkdirp": "0.5.1", + "nopt": "4.0.1", + "npmlog": "4.1.0", + "rc": "1.2.1", + "request": "2.81.0", + "rimraf": "2.6.1", + "semver": "5.3.0", + "tar": "2.2.1", + "tar-pack": "3.4.0" + } + }, + "nopt": { + "version": "4.0.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "abbrev": "1.1.0", + "osenv": "0.1.4" + } + }, + "npmlog": { + "version": "4.1.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "are-we-there-yet": "1.1.4", + "console-control-strings": "1.1.0", + "gauge": "2.7.4", + "set-blocking": "2.0.0" + } + }, + "number-is-nan": { + "version": "1.0.1", + "bundled": true, + "dev": true + }, + "oauth-sign": { + "version": "0.8.2", + "bundled": true, + "dev": true, + "optional": true + }, + "object-assign": { + "version": "4.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "once": { + "version": "1.4.0", + "bundled": true, + "dev": true, + "requires": { + "wrappy": "1.0.2" + } + }, + "os-homedir": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "os-tmpdir": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "osenv": { + "version": "0.1.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "os-homedir": "1.0.2", + "os-tmpdir": "1.0.2" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "bundled": true, + "dev": true + }, + "performance-now": { + "version": "0.2.0", + "bundled": true, + "dev": true, + "optional": true + }, + "process-nextick-args": { + "version": "1.0.7", + "bundled": true, + "dev": true + }, + "punycode": { + "version": "1.4.1", + "bundled": true, + "dev": true, + "optional": true + }, + "qs": { + "version": "6.4.0", + "bundled": true, + "dev": true, + "optional": true + }, + "rc": { + "version": "1.2.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "deep-extend": "0.4.2", + "ini": "1.3.4", + "minimist": "1.2.0", + "strip-json-comments": "2.0.1" + }, + "dependencies": { + "minimist": { + "version": "1.2.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "readable-stream": { + "version": "2.2.9", + "bundled": true, + "dev": true, + "requires": { + "buffer-shims": "1.0.0", + "core-util-is": "1.0.2", + "inherits": "2.0.3", + "isarray": "1.0.0", + "process-nextick-args": "1.0.7", + "string_decoder": "1.0.1", + "util-deprecate": "1.0.2" + } + }, + "request": { + "version": "2.81.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "aws-sign2": "0.6.0", + "aws4": "1.6.0", + "caseless": "0.12.0", + "combined-stream": "1.0.5", + "extend": "3.0.1", + "forever-agent": "0.6.1", + "form-data": "2.1.4", + "har-validator": "4.2.1", + "hawk": "3.1.3", + "http-signature": "1.1.1", + "is-typedarray": "1.0.0", + "isstream": "0.1.2", + "json-stringify-safe": "5.0.1", + "mime-types": "2.1.15", + "oauth-sign": "0.8.2", + "performance-now": "0.2.0", + "qs": "6.4.0", + "safe-buffer": "5.0.1", + "stringstream": "0.0.5", + "tough-cookie": "2.3.2", + "tunnel-agent": "0.6.0", + "uuid": "3.0.1" + } + }, + "rimraf": { + "version": "2.6.1", + "bundled": true, + "dev": true, + "requires": { + "glob": "7.1.2" + } + }, + "safe-buffer": { + "version": "5.0.1", + "bundled": true, + "dev": true + }, + "semver": { + "version": "5.3.0", + "bundled": true, + "dev": true, + "optional": true + }, + "set-blocking": { + "version": "2.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "signal-exit": { + "version": "3.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "sntp": { + "version": "1.0.9", + "bundled": true, + "dev": true, + "requires": { + "hoek": "2.16.3" + } + }, + "sshpk": { + "version": "1.13.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "asn1": "0.2.3", + "assert-plus": "1.0.0", + "bcrypt-pbkdf": "1.0.1", + "dashdash": "1.14.1", + "ecc-jsbn": "0.1.1", + "getpass": "0.1.7", + "jodid25519": "1.0.2", + "jsbn": "0.1.1", + "tweetnacl": "0.14.5" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "string-width": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "requires": { + "code-point-at": "1.1.0", + "is-fullwidth-code-point": "1.0.0", + "strip-ansi": "3.0.1" + } + }, + "string_decoder": { + "version": "1.0.1", + "bundled": true, + "dev": true, + "requires": { + "safe-buffer": "5.0.1" + } + }, + "stringstream": { + "version": "0.0.5", + "bundled": true, + "dev": true, + "optional": true + }, + "strip-ansi": { + "version": "3.0.1", + "bundled": true, + "dev": true, + "requires": { + "ansi-regex": "2.1.1" + } + }, + "strip-json-comments": { + "version": "2.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "tar": { + "version": "2.2.1", + "bundled": true, + "dev": true, + "requires": { + "block-stream": "0.0.9", + "fstream": "1.0.11", + "inherits": "2.0.3" + } + }, + "tar-pack": { + "version": "3.4.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "debug": "2.6.8", + "fstream": "1.0.11", + "fstream-ignore": "1.0.5", + "once": "1.4.0", + "readable-stream": "2.2.9", + "rimraf": "2.6.1", + "tar": "2.2.1", + "uid-number": "0.0.6" + } + }, + "tough-cookie": { + "version": "2.3.2", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "punycode": "1.4.1" + } + }, + "tunnel-agent": { + "version": "0.6.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "safe-buffer": "5.0.1" + } + }, + "tweetnacl": { + "version": "0.14.5", + "bundled": true, + "dev": true, + "optional": true + }, + "uid-number": { + "version": "0.0.6", + "bundled": true, + "dev": true, + "optional": true + }, + "util-deprecate": { + "version": "1.0.2", + "bundled": true, + "dev": true + }, + "uuid": { + "version": "3.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "verror": { + "version": "1.3.6", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "extsprintf": "1.0.2" + } + }, + "wide-align": { + "version": "1.1.2", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "string-width": "1.0.2" + } + }, + "wrappy": { + "version": "1.0.2", + "bundled": true, + "dev": true + } + } + }, "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -3245,6 +4159,13 @@ "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=", "dev": true }, + "nan": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.8.0.tgz", + "integrity": "sha1-7XFfP+neArV6XmJS2QqWZ14fCFo=", + "dev": true, + "optional": true + }, "natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", diff --git a/package.json b/package.json index efacedbeee5c..eaa6e8b39a40 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "sinon-chai": "^2.14.0" }, "dependencies": { + "@polkadot/api-format": "^0.2.0", "@polkadot/jsonrpc": "^0.2.0", "@polkadot/util": "^0.2.0", "babel-runtime": "^6.26.0", diff --git a/src/api.js b/src/api.js index 5e6e56c81846..4cdcad8c6634 100644 --- a/src/api.js +++ b/src/api.js @@ -5,10 +5,11 @@ import type { InterfaceDefinition } from '@polkadot/jsonrpc/src/types'; import type { ApiInterface } from './types'; import type { ProviderInterface } from './provider/types'; +const { formatInputs, formatOutput } = require('@polkadot/api-format'); const interfaces = require('@polkadot/jsonrpc'); const { callSignature } = require('@polkadot/jsonrpc/lib/util'); const { isFunction } = require('@polkadot/util/lib/is'); -const { formatInputs, formatOutput } = require('./format'); + const { HttpProvider } = require('./provider'); module.exports = class Api implements ApiInterface { diff --git a/src/format/index.js b/src/format/index.js deleted file mode 100644 index 18a3031f6954..000000000000 --- a/src/format/index.js +++ /dev/null @@ -1,10 +0,0 @@ -// ISC, Copyright 2017 Jaco Greeff -// @flow - -const formatInputs = require('./input'); -const formatOutput = require('./output'); - -module.exports = { - formatInputs, - formatOutput -}; diff --git a/src/format/input/address.js b/src/format/input/address.js deleted file mode 100644 index 9809ffc21266..000000000000 --- a/src/format/input/address.js +++ /dev/null @@ -1,10 +0,0 @@ -// ISC, Copyright 2017 Jaco Greeff -// @flow - -const { formatH160 } = require('./hex'); - -// TODO: Currently the format assumes 160-bit values (like Ethereum) -// this will probably change along the way as things get firmed up -module.exports = function format (value: ?string): string { - return formatH160(value); -}; diff --git a/src/format/input/address.spec.js b/src/format/input/address.spec.js deleted file mode 100644 index 954ce0b3408d..000000000000 --- a/src/format/input/address.spec.js +++ /dev/null @@ -1,13 +0,0 @@ -// ISC, Copyright 2017 Jaco Greeff - -const format = require('./address'); - -describe('format/input/address', () => { - describe('format', () => { - it('pads to H160 value', () => { - expect( - format('0x1234567890') - ).to.equal('0x0000000000000000000000000000001234567890'); - }); - }); -}); diff --git a/src/format/input/hex.js b/src/format/input/hex.js deleted file mode 100644 index 25586deff9d5..000000000000 --- a/src/format/input/hex.js +++ /dev/null @@ -1,33 +0,0 @@ -// ISC, Copyright 2017 Jaco Greeff -// @flow - -const { addHexPrefix, hasHexPrefix, stripHexPrefix } = require('@polkadot/util/lib/hex'); - -const H64_ZERO: string = '00000000000000000000000000000000'; -const H128_ZERO: string = `${H64_ZERO}${H64_ZERO}`; -const H256_ZERO: string = `${H128_ZERO}${H128_ZERO}`; -// const H512_ZERO: string = `${H256_ZERO}${H256_ZERO}`; - -function leftHexPad (value: ?string, bitLength: number): string { - const length = 2 * bitLength / 8; - - if (hasHexPrefix(value)) { - value = stripHexPrefix(value); - } - - return addHexPrefix(`${H256_ZERO}${value || ''}`.slice(-length)); -} - -function formatH160 (value: ?string): string { - return leftHexPad(value, 160); -} - -function formatH256 (value: ?string): string { - return leftHexPad(value, 256); -} - -module.exports = { - leftHexPad, - formatH160, - formatH256 -}; diff --git a/src/format/input/hex.spec.js b/src/format/input/hex.spec.js deleted file mode 100644 index 5f777cefa05d..000000000000 --- a/src/format/input/hex.spec.js +++ /dev/null @@ -1,53 +0,0 @@ -// ISC, Copyright 2017 Jaco Greeff - -const { leftHexPad, formatH160, formatH256 } = require('./hex'); - -describe('format/input/hex', () => { - describe('leftHexPad', () => { - it('padds to the required length', () => { - expect( - leftHexPad('0x123', 16) - ).to.equal('0x0123'); - }); - - it('padds to the required length (no prefix)', () => { - expect( - leftHexPad('123', 16) - ).to.equal('0x0123'); - }); - - it('pads null values correctly', () => { - expect( - leftHexPad(null, 16) - ).to.equal('0x0000'); - }); - }); - - describe('formatH160', () => { - it('pads to 40 bytes', () => { - expect( - formatH160('0x1234567890') - ).to.equal('0x0000000000000000000000000000001234567890'); - }); - - it('pads null values correctly', () => { - expect( - formatH160(null) - ).to.match(/^0x(00){20,}$/); - }); - }); - - describe('formatH256', () => { - it('pads to 64 bytes', () => { - expect( - formatH256('0x1234567890') - ).to.equal('0x0000000000000000000000000000000000000000000000000000001234567890'); - }); - - it('pads null values correctly', () => { - expect( - formatH256(null) - ).to.match(/^0x(00){32,}$/); - }); - }); -}); diff --git a/src/format/input/index.js b/src/format/input/index.js deleted file mode 100644 index aa96545e8f65..000000000000 --- a/src/format/input/index.js +++ /dev/null @@ -1,24 +0,0 @@ -// ISC, Copyright 2017 Jaco Greeff -// @flow - -import type { FormatInputType, InterfaceInputType } from '@polkadot/jsonrpc/src/types'; -import type { FormatterFunction } from '../types'; - -const formatAddress = require('./address'); -const { formatH256 } = require('./hex'); -const formatNoop = require('../noop'); -const util = require('../util'); - -const formatters: { [FormatInputType]: FormatterFunction } = { - 'Address': formatAddress, - 'CallData': formatNoop, - 'H256': formatH256, - 'HeaderHash': formatH256, - 'String': formatNoop -}; - -module.exports = function format (inputs: Array, values: Array): Array { - const types = inputs.map(({ type }) => type); - - return util.formatArray(formatters, types, values); -}; diff --git a/src/format/input/index.spec.js b/src/format/input/index.spec.js deleted file mode 100644 index 2c6c3abf3fbb..000000000000 --- a/src/format/input/index.spec.js +++ /dev/null @@ -1,22 +0,0 @@ -// ISC, Copyright 2017 Jaco Greeff - -const format = require('./index'); - -describe('format/input', () => { - describe('format', () => { - it('formats each value in an array', () => { - expect( - format( - [ - { name: 'foo', type: 'Address' }, - { name: 'bar', type: 'H256' } - ], - ['0x1234', '0xabcd'] - ) - ).to.deep.equal([ - '0x0000000000000000000000000000000000001234', - '0x000000000000000000000000000000000000000000000000000000000000abcd' - ]); - }); - }); -}); diff --git a/src/format/noop.js b/src/format/noop.js deleted file mode 100644 index 6fc35ab9e808..000000000000 --- a/src/format/noop.js +++ /dev/null @@ -1,6 +0,0 @@ -// ISC, Copyright 2017 Jaco Greeff -// @flow - -module.exports = function format (value: any): any { - return value; -}; diff --git a/src/format/noop.spec.js b/src/format/noop.spec.js deleted file mode 100644 index 87502f00a42a..000000000000 --- a/src/format/noop.spec.js +++ /dev/null @@ -1,13 +0,0 @@ -// ISC, Copyright 2017 Jaco Greeff - -const format = require('./noop'); - -describe('format/noop', () => { - it('returns input value as output value', () => { - const input = { 'some': 'object' }; - - expect( - format(input) - ).to.equal(input); - }); -}); diff --git a/src/format/output/index.js b/src/format/output/index.js deleted file mode 100644 index d1d74151fc40..000000000000 --- a/src/format/output/index.js +++ /dev/null @@ -1,18 +0,0 @@ -// ISC, Copyright 2017 Jaco Greeff -// @flow - -import type { FormatOutputType, InterfaceOutputType } from '@polkadot/jsonrpc/src/types'; -import type { FormatterFunction } from '../types'; - -const formatNoop = require('../noop'); -const util = require('../util'); - -const formatters: { [FormatOutputType]: FormatterFunction } = { - 'Header': formatNoop, - 'OutData': formatNoop, - 'StorageData': formatNoop -}; - -module.exports = function format (output: InterfaceOutputType, value: any): any { - return util.format(formatters, output.type, value); -}; diff --git a/src/format/output/index.spec.js b/src/format/output/index.spec.js deleted file mode 100644 index 73ed7ff1477b..000000000000 --- a/src/format/output/index.spec.js +++ /dev/null @@ -1,13 +0,0 @@ -// ISC, Copyright 2017 Jaco Greeff - -const format = require('./index'); - -describe('format/output', () => { - describe('format', () => { - it('formats the value', () => { - expect( - format('Header', 'test') - ).to.deep.equal('test'); - }); - }); -}); diff --git a/src/format/types.js b/src/format/types.js deleted file mode 100644 index 7099809f172a..000000000000 --- a/src/format/types.js +++ /dev/null @@ -1,4 +0,0 @@ -// ISC, Copyright 2017 Jaco Greeff -// @flow - -export type FormatterFunction = (value: any) => any; diff --git a/src/format/util.js b/src/format/util.js deleted file mode 100644 index 874263b6de20..000000000000 --- a/src/format/util.js +++ /dev/null @@ -1,36 +0,0 @@ -// ISC, Copyright 2017 Jaco Greeff -// @flow - -import type { FormatterFunction } from './types'; - -const { isUndefined } = require('@polkadot/util/lib/is'); -const formatNoop = require('./noop'); - -function format (formatters: { [any]: FormatterFunction }, type: string, value: any): any { - const formatter = formatters[type]; - - if (isUndefined(formatter)) { - console.warn(`Unable to find default formatter for '${type}', falling back to noop`); - - return formatNoop(value); - } - - try { - return formatter(value); - } catch (error) { - throw new Error(`Error formatting '${value}' as '${type}'': ${error.message}`); - } -} - -function formatArray (formatters: { [any]: FormatterFunction }, types: Array, values: Array): Array { - return types.map((type, index) => { - const value = values[index]; - - return format(formatters, type, value); - }); -} - -module.exports = { - format, - formatArray -}; diff --git a/src/format/util.spec.js b/src/format/util.spec.js deleted file mode 100644 index ee6ecf29ddb4..000000000000 --- a/src/format/util.spec.js +++ /dev/null @@ -1,59 +0,0 @@ -// ISC, Copyright 2017 Jaco Greeff - -const sinon = require('sinon'); - -const { format, formatArray } = require('./util'); - -describe('format/util', () => { - let formatters; - let addressStub; - let warnSpy; - - beforeEach(() => { - addressStub = sinon.stub(); - formatters = { - 'Address': addressStub, - 'Exception': () => { - throw new Error('something went wrong'); - } - }; - warnSpy = sinon.spy(console, 'warn'); - }); - - afterEach(() => { - console.warn.restore(); - }); - - describe('format', () => { - it('formats unknown types with a fallback', () => { - expect( - format(formatters, 'Unknown', 'test') - ).to.equal('test'); - }); - - it('logs a warning with unknown types', () => { - format(formatters, 'Unknown', 'test'); - expect(warnSpy).to.have.been.calledWith("Unable to find default formatter for 'Unknown', falling back to noop"); - }); - - it('formats known types using the supplied formatter', () => { - format(formatters, 'Address', '0xaddress'); - - expect(addressStub).to.have.been.calledWith('0xaddress'); - }); - - it('wraps exceptions with the type', () => { - expect( - () => format(formatters, 'Exception', 'test') - ).to.throw(/Error formatting 'test' as 'Exception'/); - }); - }); - - describe('formatArray', () => { - it('formats each value in an array', () => { - expect( - formatArray(formatters, ['Unknown', 'Unknown'], ['test', 'blah']) - ).to.deep.equal(['test', 'blah']); - }); - }); -}); diff --git a/src/polyfill.spec.js b/src/polyfill.spec.js new file mode 100644 index 000000000000..7bc3997a7355 --- /dev/null +++ b/src/polyfill.spec.js @@ -0,0 +1,15 @@ +// ISC, Copyright 2017 Jaco Greeff + +/* eslint-disable no-unused-expressions */ + +describe('polyfill', () => { + it('adds polyfills with no exceptions', () => { + expect(require('./polyfill')).to.be.ok; + }); + + describe('interfaces', () => { + it('fetch is available', () => { + expect(fetch).to.be.ok; + }); + }); +}); diff --git a/src/provider/ws.spec.js b/src/provider/ws.spec.js index 8e939e0d9efa..92e32effbaa8 100644 --- a/src/provider/ws.spec.js +++ b/src/provider/ws.spec.js @@ -4,6 +4,7 @@ const { mockWs, TEST_WS_URL } = require('../../test/mockWs'); +const { isUndefined } = require('@polkadot/util/lib/is'); const sinon = require('sinon'); const Ws = require('./ws'); @@ -11,8 +12,8 @@ const Ws = require('./ws'); let ws; let mock; -function createWs (requests, autoConnect = true) { - mock = autoConnect +function createWs (requests, autoConnect) { + mock = autoConnect || isUndefined(autoConnect) ? mockWs(requests) : null; @@ -69,6 +70,24 @@ describe('provider/Ws', () => { clock.restore(); }); + + it('does not reconnect when autoConnect false', () => { + mock.done(); + ws = createWs([], false); + + const clock = sinon.useFakeTimers(); + + ws.connect = sinon.stub(); + ws._onClose(); + + expect(ws.connect).not.to.have.been.called; + + clock.tick(1001); + + expect(ws.connect).not.to.have.been.called; + + clock.restore(); + }); }); describe('_onError', () => {