From 3cedd251e59b975b51d0338c31f274e0eeef90b2 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Sat, 2 Jan 2021 15:41:12 -0800 Subject: [PATCH] fix(linting): Adding standard linting rules --- .editorconfig | 30 + .eslintrc.json | 57 +- package-lock.json | 1738 +++++++++++++++-- package.json | 8 +- src/address.js | 157 +- src/bch-js.js | 74 +- src/bitcoincash.js | 80 +- src/blockchain.js | 84 +- src/control.js | 8 +- src/crypto.js | 14 +- src/ecpair.js | 34 +- src/electrumx.js | 46 +- src/encryption.js | 9 +- src/generating.js | 6 +- src/hdnode.js | 66 +- src/ipfs.js | 104 +- src/mining.js | 14 +- src/mnemonic.js | 66 +- src/ninsight.js | 30 +- src/openbazaar.js | 28 +- src/price.js | 12 +- src/raw-transactions.js | 40 +- src/schnorr.js | 36 +- src/script.js | 20 +- src/slp/address.js | 46 +- src/slp/ecpair.js | 10 +- src/slp/nft1.js | 114 +- src/slp/slp.js | 14 +- src/slp/tokentype1.js | 86 +- src/slp/utils.js | 180 +- src/socket.js | 15 +- src/transaction-builder.js | 36 +- src/util.js | 12 +- test/e2e/bch-js-e2e-tests.js | 14 +- test/e2e/ipfs/ipfs-e2e.js | 10 +- test/e2e/rate-limits/anonymous-rate-limits.js | 24 +- .../e2e/rate-limits/basic-auth-rate-limits.js | 24 +- test/e2e/rate-limits/free-rate-limits.js | 40 +- test/e2e/rate-limits/full-node-rate-limits.js | 28 +- test/e2e/rate-limits/indexer-rate-limits.js | 24 +- .../sendrawtransaction.js | 71 +- .../sendrawtransaction.js | 54 +- test/e2e/send-token/send-token.js | 28 +- test/e2e/util/e2e-util.js | 37 +- test/integration/blockchain.js | 174 +- test/integration/chains/abc/rawtransaction.js | 36 +- test/integration/chains/abc/slp.js | 90 +- .../integration/chains/bchn/rawtransaction.js | 36 +- test/integration/chains/bchn/slp.js | 90 +- test/integration/chains/testnet/blockchain.js | 144 +- test/integration/chains/testnet/control.js | 16 +- test/integration/chains/testnet/electrumx.js | 246 ++- test/integration/chains/testnet/ninsight.js | 138 +- .../chains/testnet/rawtransaction.js | 200 +- test/integration/chains/testnet/slp.js | 126 +- test/integration/chains/testnet/util.js | 78 +- test/integration/control.js | 14 +- test/integration/electrumx.js | 238 ++- test/integration/encryption.js | 28 +- .../implementations/sweet/rawtransaction.js | 36 +- test/integration/implementations/sweet/slp.js | 90 +- test/integration/ninsight.js | 138 +- test/integration/openbazaar.js | 86 +- test/integration/price.js | 32 +- test/integration/rawtransaction.js | 174 +- test/integration/slp.js | 448 ++--- test/integration/util.js | 76 +- test/unit/address.js | 272 +-- test/unit/bitcoin-cash.js | 52 +- test/unit/blockchain.js | 235 +-- test/unit/control.js | 26 +- test/unit/crypto.js | 70 +- test/unit/ecpairs.js | 58 +- test/unit/electrumx.js | 290 +-- test/unit/encryption.js | 40 +- test/unit/fixtures/bitcore-mock.js | 28 +- test/unit/fixtures/block-mock.js | 14 +- test/unit/fixtures/blockchain-mock.js | 30 +- test/unit/fixtures/electrumx-mock.js | 38 +- test/unit/fixtures/encryption-mock.js | 4 +- test/unit/fixtures/ipfs-mock.js | 78 +- test/unit/fixtures/ninsight-mock.js | 72 +- test/unit/fixtures/openbazaar-mock.js | 48 +- test/unit/fixtures/price-mocks.js | 408 ++-- test/unit/fixtures/slp/mock-utils.js | 722 +++---- test/unit/generating.js | 18 +- test/unit/hdnode.js | 124 +- test/unit/ipfs.js | 328 ++-- test/unit/mining.js | 46 +- test/unit/mnemonic.js | 180 +- test/unit/ninsight.js | 226 +-- test/unit/openbazaar.js | 124 +- test/unit/price.js | 40 +- test/unit/raw-tranactions.js | 58 +- test/unit/scripts.js | 278 +-- test/unit/slp-address.js | 204 +- test/unit/slp-ecpair.js | 12 +- test/unit/slp-nft1.js | 166 +- test/unit/slp-tokentype1.js | 1042 +++++----- test/unit/slp-utils.js | 1292 ++++++------ test/unit/transaction-builder.js | 228 +-- test/unit/util.js | 22 +- 102 files changed, 7280 insertions(+), 5955 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..90913b4 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,30 @@ +# http://editorconfig.org + +# A special property that should be specified at the top of the file outside of +# any sections. Set to true to stop .editor config file search on current file +root = true + +[*] +# Indentation style +# Possible values - tab, space +indent_style = space + +# Indentation size in single-spaced characters +# Possible values - an integer, tab +indent_size = 2 + +# Line ending file format +# Possible values - lf, crlf, cr +end_of_line = lf + +# File character encoding +# Possible values - latin1, utf-8, utf-16be, utf-16le +charset = utf-8 + +# Denotes whether to trim whitespace at the end of lines +# Possible values - true, false +trim_trailing_whitespace = true + +# Denotes whether file should end with a newline +# Possible values - true, false +insert_final_newline = true diff --git a/.eslintrc.json b/.eslintrc.json index 9b0b426..4eef771 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,55 +1,10 @@ { - "root": true, - "parserOptions": { - "ecmaVersion": 2018, - "sourceType": "module" + "extends": "standard", + "env": { + "node": true, + "mocha": true }, - "plugins": ["prettier"], - "rules": { - "no-debugger": ["warn"], - "no-regex-spaces": ["error"], - "no-unsafe-negation": ["error"], - "curly": ["error", "multi-or-nest", "consistent"], - "dot-location": ["error", "property"], - "dot-notation": ["error"], - "eqeqeq": ["error", "smart"], - "no-else-return": ["error"], - "no-extra-bind": ["error"], - "no-extra-label": ["error"], - "no-floating-decimal": ["error"], - "no-implicit-coercion": ["error", { "allow": ["!!"] }], - "wrap-iife": ["error", "inside"], - "strict": ["error", "global"], - "func-call-spacing": ["error", "never"], - "comma-style": ["error", "last"], - "keyword-spacing": ["error"], - "linebreak-style": ["error", "unix"], - "new-parens": ["error"], - "no-lonely-if": ["error"], - "no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1 }], - "no-whitespace-before-property": ["error"], - "semi": ["error", "never"], - "arrow-body-style": ["error", "as-needed"], - "arrow-parens": ["error", "as-needed"], - "arrow-spacing": ["error"], - "no-useless-computed-key": ["error"], - "no-useless-rename": ["error"], - "no-var": ["off"], - "prefer-spread": ["off"], - "prefer-template": ["error"], - "rest-spread-spacing": ["error", "never"], - "prefer-const": ["warn", { "destructuring": "all" }], - "no-unreachable": ["warn"], - "no-unused-vars": ["warn", { "args": "none" }], - - "prettier/prettier": [ - "warn", - { - "printWidth": 80, - "trailingComma": "none", - "singleQuote": false, - "semi": false - } - ] + "parserOptions": { + "ecmaVersion": 8 } } diff --git a/package-lock.json b/package-lock.json index febae79..76d0947 100644 --- a/package-lock.json +++ b/package-lock.json @@ -115,6 +115,56 @@ "to-fast-properties": "^2.0.0" } }, + "@eslint/eslintrc": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.2.2.tgz", + "integrity": "sha512-EfB5OHNYp1F4px/LI/FEnGylop7nOqkQ1LRzCM0KccA2U8tvV8w01KBv37LbO7nW4H+YhKyo2LcJhRwjjV17QQ==", + "dev": true, + "requires": { + "ajv": "^6.12.4", + "debug": "^4.1.1", + "espree": "^7.3.0", + "globals": "^12.1.0", + "ignore": "^4.0.6", + "import-fresh": "^3.2.1", + "js-yaml": "^3.13.1", + "lodash": "^4.17.19", + "minimatch": "^3.0.4", + "strip-json-comments": "^3.1.1" + }, + "dependencies": { + "debug": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", + "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", + "dev": true, + "requires": { + "ms": "2.1.2" + } + }, + "globals": { + "version": "12.4.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-12.4.0.tgz", + "integrity": "sha512-BWICuzzDvDoH54NHKCseDanAhE3CeDorgDL5MT6LMXXj2WCnd9UC2szdk4AWLfjdgNBCXLUanXYcpBBKOSWGwg==", + "dev": true, + "requires": { + "type-fest": "^0.8.1" + } + }, + "strip-json-comments": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", + "dev": true + }, + "type-fest": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", + "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", + "dev": true + } + } + }, "@nodelib/fs.scandir": { "version": "2.1.4", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.4.tgz", @@ -283,6 +333,351 @@ "nyc": "*", "standard": "^11.0.1", "tape": "*" + }, + "dependencies": { + "acorn": { + "version": "5.7.4", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.4.tgz", + "integrity": "sha512-1D++VG7BhrtvQpNbBzovKNc1FLGGEE/oGe7b9xJm/RFHMBeUaUGpluV9RLjZa47YFdPcDAenEYuq9pQPcMdLJg==" + }, + "acorn-jsx": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-3.0.1.tgz", + "integrity": "sha1-r9+UiPsezvyDSPb7IvRk4ypYs2s=", + "requires": { + "acorn": "^3.0.4" + }, + "dependencies": { + "acorn": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-3.3.0.tgz", + "integrity": "sha1-ReN/s56No/JbruP/U2niu18iAXo=" + } + } + }, + "ajv": { + "version": "5.5.2", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", + "integrity": "sha1-c7Xuyj+rZT49P5Qis0GtQiBdyWU=", + "requires": { + "co": "^4.6.0", + "fast-deep-equal": "^1.0.0", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.3.0" + } + }, + "ansi-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=" + }, + "cross-spawn": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", + "integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=", + "requires": { + "lru-cache": "^4.0.1", + "shebang-command": "^1.2.0", + "which": "^1.2.9" + } + }, + "doctrine": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", + "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==", + "requires": { + "esutils": "^2.0.2" + } + }, + "eslint": { + "version": "4.18.2", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-4.18.2.tgz", + "integrity": "sha512-qy4i3wODqKMYfz9LUI8N2qYDkHkoieTbiHpMrYUI/WbjhXJQr7lI4VngixTgaG+yHX+NBCv7nW4hA0ShbvaNKw==", + "requires": { + "ajv": "^5.3.0", + "babel-code-frame": "^6.22.0", + "chalk": "^2.1.0", + "concat-stream": "^1.6.0", + "cross-spawn": "^5.1.0", + "debug": "^3.1.0", + "doctrine": "^2.1.0", + "eslint-scope": "^3.7.1", + "eslint-visitor-keys": "^1.0.0", + "espree": "^3.5.2", + "esquery": "^1.0.0", + "esutils": "^2.0.2", + "file-entry-cache": "^2.0.0", + "functional-red-black-tree": "^1.0.1", + "glob": "^7.1.2", + "globals": "^11.0.1", + "ignore": "^3.3.3", + "imurmurhash": "^0.1.4", + "inquirer": "^3.0.6", + "is-resolvable": "^1.0.0", + "js-yaml": "^3.9.1", + "json-stable-stringify-without-jsonify": "^1.0.1", + "levn": "^0.3.0", + "lodash": "^4.17.4", + "minimatch": "^3.0.2", + "mkdirp": "^0.5.1", + "natural-compare": "^1.4.0", + "optionator": "^0.8.2", + "path-is-inside": "^1.0.2", + "pluralize": "^7.0.0", + "progress": "^2.0.0", + "require-uncached": "^1.0.3", + "semver": "^5.3.0", + "strip-ansi": "^4.0.0", + "strip-json-comments": "~2.0.1", + "table": "4.0.2", + "text-table": "~0.2.0" + } + }, + "eslint-config-standard": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/eslint-config-standard/-/eslint-config-standard-11.0.0.tgz", + "integrity": "sha512-oDdENzpViEe5fwuRCWla7AXQd++/oyIp8zP+iP9jiUPG6NBj3SHgdgtl/kTn00AjeN+1HNvavTKmYbMo+xMOlw==" + }, + "eslint-config-standard-jsx": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/eslint-config-standard-jsx/-/eslint-config-standard-jsx-5.0.0.tgz", + "integrity": "sha512-rLToPAEqLMPBfWnYTu6xRhm2OWziS2n40QFqJ8jAM8NSVzeVKTa3nclhsU4DpPJQRY60F34Oo1wi/71PN/eITg==" + }, + "eslint-plugin-import": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.9.0.tgz", + "integrity": "sha1-JgAu+/ylmJtyiKwEdQi9JPIXsWk=", + "requires": { + "builtin-modules": "^1.1.1", + "contains-path": "^0.1.0", + "debug": "^2.6.8", + "doctrine": "1.5.0", + "eslint-import-resolver-node": "^0.3.1", + "eslint-module-utils": "^2.1.1", + "has": "^1.0.1", + "lodash": "^4.17.4", + "minimatch": "^3.0.3", + "read-pkg-up": "^2.0.0" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "doctrine": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz", + "integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=", + "requires": { + "esutils": "^2.0.2", + "isarray": "^1.0.0" + } + } + } + }, + "eslint-plugin-node": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-node/-/eslint-plugin-node-6.0.1.tgz", + "integrity": "sha512-Q/Cc2sW1OAISDS+Ji6lZS2KV4b7ueA/WydVWd1BECTQwVvfQy5JAi3glhINoKzoMnfnuRgNP+ZWKrGAbp3QDxw==", + "requires": { + "ignore": "^3.3.6", + "minimatch": "^3.0.4", + "resolve": "^1.3.3", + "semver": "^5.4.1" + }, + "dependencies": { + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" + } + } + }, + "eslint-plugin-promise": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-3.7.0.tgz", + "integrity": "sha512-2WO+ZFh7vxUKRfR0cOIMrWgYKdR6S1AlOezw6pC52B6oYpd5WFghN+QHxvrRdZMtbo8h3dfUZ2o1rWb0UPbKtg==" + }, + "eslint-plugin-react": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.7.0.tgz", + "integrity": "sha512-KC7Snr4YsWZD5flu6A5c0AcIZidzW3Exbqp7OT67OaD2AppJtlBr/GuPrW/vaQM/yfZotEvKAdrxrO+v8vwYJA==", + "requires": { + "doctrine": "^2.0.2", + "has": "^1.0.1", + "jsx-ast-utils": "^2.0.1", + "prop-types": "^15.6.0" + } + }, + "eslint-scope": { + "version": "3.7.3", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.3.tgz", + "integrity": "sha512-W+B0SvF4gamyCTmUc+uITPY0989iXVfKvhwtmJocTaYoc/3khEHmEmvfY/Gn9HA9VV75jrQECsHizkNw1b68FA==", + "requires": { + "esrecurse": "^4.1.0", + "estraverse": "^4.1.1" + } + }, + "espree": { + "version": "3.5.4", + "resolved": "https://registry.npmjs.org/espree/-/espree-3.5.4.tgz", + "integrity": "sha512-yAcIQxtmMiB/jL32dzEp2enBeidsB7xWPLNiw3IIkpVds1P+h7qF9YwJq1yUNzp2OKXgAprs4F61ih66UsoD1A==", + "requires": { + "acorn": "^5.5.0", + "acorn-jsx": "^3.0.0" + } + }, + "fast-deep-equal": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz", + "integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=" + }, + "file-entry-cache": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-2.0.0.tgz", + "integrity": "sha1-w5KZDD5oR4PYOLjISkXYoEhFg2E=", + "requires": { + "flat-cache": "^1.2.1", + "object-assign": "^4.0.1" + } + }, + "flat-cache": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-1.3.4.tgz", + "integrity": "sha512-VwyB3Lkgacfik2vhqR4uv2rvebqmDvFu4jlN/C1RzWoJEo8I7z4Q404oiqYCkq41mni8EzQnm95emU9seckwtg==", + "requires": { + "circular-json": "^0.3.1", + "graceful-fs": "^4.1.2", + "rimraf": "~2.6.2", + "write": "^0.2.1" + } + }, + "ignore": { + "version": "3.3.10", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.10.tgz", + "integrity": "sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==" + }, + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" + }, + "json-schema-traverse": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz", + "integrity": "sha1-NJptRMU6Ud6JtAgFxdXlm0F9M0A=" + }, + "jsx-ast-utils": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-2.4.1.tgz", + "integrity": "sha512-z1xSldJ6imESSzOjd3NNkieVJKRlKYSOtMG8SFyCj2FIrvSaSuli/WjpBkEzCBoR9bYYYFgqJw61Xhu7Lcgk+w==", + "requires": { + "array-includes": "^3.1.1", + "object.assign": "^4.1.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "shebang-command": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", + "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", + "requires": { + "shebang-regex": "^1.0.0" + } + }, + "shebang-regex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", + "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=" + }, + "slice-ansi": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-1.0.0.tgz", + "integrity": "sha512-POqxBK6Lb3q6s047D/XsDVNPnF9Dl8JSaqe9h9lURl0OdNqy/ujDrOiIHtsqXMGbWWTIomRzAMaTyawAU//Reg==", + "requires": { + "is-fullwidth-code-point": "^2.0.0" + } + }, + "standard": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/standard/-/standard-11.0.1.tgz", + "integrity": "sha512-nu0jAcHiSc8H+gJCXeiziMVZNDYi8MuqrYJKxTgjP4xKXZMKm311boqQIzDrYI/ktosltxt2CbDjYQs9ANC8IA==", + "requires": { + "eslint": "~4.18.0", + "eslint-config-standard": "11.0.0", + "eslint-config-standard-jsx": "5.0.0", + "eslint-plugin-import": "~2.9.0", + "eslint-plugin-node": "~6.0.0", + "eslint-plugin-promise": "~3.7.0", + "eslint-plugin-react": "~7.7.0", + "standard-engine": "~8.0.0" + } + }, + "standard-engine": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/standard-engine/-/standard-engine-8.0.1.tgz", + "integrity": "sha512-LA531C3+nljom/XRvdW/hGPXwmilRkaRkENhO3FAGF1Vtq/WtCXzgmnc5S6vUHHsgv534MRy02C1ikMwZXC+tw==", + "requires": { + "deglob": "^2.1.0", + "get-stdin": "^6.0.0", + "minimist": "^1.1.0", + "pkg-conf": "^2.0.0" + } + }, + "string-width": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", + "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "requires": { + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^4.0.0" + } + }, + "strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "requires": { + "ansi-regex": "^3.0.0" + } + }, + "table": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/table/-/table-4.0.2.tgz", + "integrity": "sha512-UUkEAPdSGxtRpiV9ozJ5cMTtYiqz7Ni1OGqLXRCynrvzdtR1p+cfOWe2RJLwvUG8hNanaSRjecIqwOjqeatDsA==", + "requires": { + "ajv": "^5.2.3", + "ajv-keywords": "^2.1.0", + "chalk": "^2.1.0", + "lodash": "^4.17.4", + "slice-ansi": "1.0.0", + "string-width": "^2.1.1" + } + }, + "which": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", + "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", + "requires": { + "isexe": "^2.0.0" + } + }, + "write": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/write/-/write-0.2.1.tgz", + "integrity": "sha1-X8A4KOJkzqP+kUVUdvejxWbLB1c=", + "requires": { + "mkdirp": "^0.5.1" + } + } } }, "@psf/bitcoincash-ops": { @@ -719,6 +1114,12 @@ "resolved": "https://registry.npmjs.org/@transloadit/prettier-bytes/-/prettier-bytes-0.0.7.tgz", "integrity": "sha512-VeJbUb0wEKbcwaSlj5n+LscBl9IPgLPkHVGBkh00cztv6X4L/TJXK58LzFuBKX7/GAfiGhIwH67YTLTlzvIzBA==" }, + "@types/json5": { + "version": "0.0.29", + "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", + "integrity": "sha1-7ihweulOEdK4J7y+UnC86n8+ce4=", + "dev": true + }, "@types/minimist": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.1.tgz", @@ -826,24 +1227,16 @@ } }, "acorn": { - "version": "5.7.4", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.4.tgz", - "integrity": "sha512-1D++VG7BhrtvQpNbBzovKNc1FLGGEE/oGe7b9xJm/RFHMBeUaUGpluV9RLjZa47YFdPcDAenEYuq9pQPcMdLJg==" + "version": "7.4.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", + "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", + "dev": true }, "acorn-jsx": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-3.0.1.tgz", - "integrity": "sha1-r9+UiPsezvyDSPb7IvRk4ypYs2s=", - "requires": { - "acorn": "^3.0.4" - }, - "dependencies": { - "acorn": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-3.3.0.tgz", - "integrity": "sha1-ReN/s56No/JbruP/U2niu18iAXo=" - } - } + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.1.tgz", + "integrity": "sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng==", + "dev": true }, "after": { "version": "0.8.2", @@ -881,14 +1274,15 @@ } }, "ajv": { - "version": "5.5.2", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", - "integrity": "sha1-c7Xuyj+rZT49P5Qis0GtQiBdyWU=", + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, "requires": { - "co": "^4.6.0", - "fast-deep-equal": "^1.0.0", + "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.3.0" + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" } }, "ajv-keywords": { @@ -1009,13 +1403,65 @@ "dev": true }, "array-includes": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.1.tgz", - "integrity": "sha512-c2VXaCHl7zPsvpkFsw4nxvFie4fh1ur9bpcgsVkIjqn0H/Xwdg+7fv3n2r/isyS8EBj5b06M9kHyZuIr4El6WQ==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.2.tgz", + "integrity": "sha512-w2GspexNQpx+PutG3QpT437/BenZBj0M/MZGn5mzv/MofYqo0xmRHzn4lFsoDlWJ+THYsGJmFlW68WlDFx7VRw==", "requires": { + "call-bind": "^1.0.0", "define-properties": "^1.1.3", - "es-abstract": "^1.17.0", + "es-abstract": "^1.18.0-next.1", + "get-intrinsic": "^1.0.1", "is-string": "^1.0.5" + }, + "dependencies": { + "es-abstract": { + "version": "1.18.0-next.1", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.0-next.1.tgz", + "integrity": "sha512-I4UGspA0wpZXWENrdA0uHbnhte683t3qT/1VFH9aX2dA5PPSf6QW5HHXf5HImaqPmjXaVeVk4RGWnaylmV7uAA==", + "requires": { + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1", + "is-callable": "^1.2.2", + "is-negative-zero": "^2.0.0", + "is-regex": "^1.1.1", + "object-inspect": "^1.8.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.1", + "string.prototype.trimend": "^1.0.1", + "string.prototype.trimstart": "^1.0.1" + } + }, + "is-callable": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.2.tgz", + "integrity": "sha512-dnMqspv5nU3LoewK2N/y7KLtxtakvTuaCsU9FU50/QDmdbHNy/4/JuRtMHqRU22o3q+W89YQndQEeCVwK+3qrA==" + }, + "is-regex": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.1.tgz", + "integrity": "sha512-1+QkEcxiLlB7VEyFtyBg94e08OAsvq7FUBgApTq/w2ymCLyKJgDPsybBENVtA7XCQEgEXxKPonG+mvYRxh/LIg==", + "requires": { + "has-symbols": "^1.0.1" + } + }, + "object-inspect": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.9.0.tgz", + "integrity": "sha512-i3Bp9iTqwhaLZBxGkRfo5ZbE07BQRT7MGu8+nNgwW9ItGp1TzCTw2DLEoWwjClxBjOFI/hWljTAmYGCEwmtnOw==" + }, + "object.assign": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.2.tgz", + "integrity": "sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ==", + "requires": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3", + "has-symbols": "^1.0.1", + "object-keys": "^1.1.1" + } + } } }, "array-union": { @@ -1024,6 +1470,139 @@ "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", "dev": true }, + "array.prototype.flat": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/array.prototype.flat/-/array.prototype.flat-1.2.4.tgz", + "integrity": "sha512-4470Xi3GAPAjZqFcljX2xzckv1qeKPizoNkiS0+O4IoPR2ZNpcjE0pkhdihlDouK+x6QOast26B4Q/O9DJnwSg==", + "dev": true, + "requires": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3", + "es-abstract": "^1.18.0-next.1" + }, + "dependencies": { + "es-abstract": { + "version": "1.18.0-next.1", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.0-next.1.tgz", + "integrity": "sha512-I4UGspA0wpZXWENrdA0uHbnhte683t3qT/1VFH9aX2dA5PPSf6QW5HHXf5HImaqPmjXaVeVk4RGWnaylmV7uAA==", + "dev": true, + "requires": { + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1", + "is-callable": "^1.2.2", + "is-negative-zero": "^2.0.0", + "is-regex": "^1.1.1", + "object-inspect": "^1.8.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.1", + "string.prototype.trimend": "^1.0.1", + "string.prototype.trimstart": "^1.0.1" + } + }, + "is-callable": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.2.tgz", + "integrity": "sha512-dnMqspv5nU3LoewK2N/y7KLtxtakvTuaCsU9FU50/QDmdbHNy/4/JuRtMHqRU22o3q+W89YQndQEeCVwK+3qrA==", + "dev": true + }, + "is-regex": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.1.tgz", + "integrity": "sha512-1+QkEcxiLlB7VEyFtyBg94e08OAsvq7FUBgApTq/w2ymCLyKJgDPsybBENVtA7XCQEgEXxKPonG+mvYRxh/LIg==", + "dev": true, + "requires": { + "has-symbols": "^1.0.1" + } + }, + "object-inspect": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.9.0.tgz", + "integrity": "sha512-i3Bp9iTqwhaLZBxGkRfo5ZbE07BQRT7MGu8+nNgwW9ItGp1TzCTw2DLEoWwjClxBjOFI/hWljTAmYGCEwmtnOw==", + "dev": true + }, + "object.assign": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.2.tgz", + "integrity": "sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ==", + "dev": true, + "requires": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3", + "has-symbols": "^1.0.1", + "object-keys": "^1.1.1" + } + } + } + }, + "array.prototype.flatmap": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/array.prototype.flatmap/-/array.prototype.flatmap-1.2.4.tgz", + "integrity": "sha512-r9Z0zYoxqHz60vvQbWEdXIEtCwHF0yxaWfno9qzXeNHvfyl3BZqygmGzb84dsubyaXLH4husF+NFgMSdpZhk2Q==", + "dev": true, + "requires": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3", + "es-abstract": "^1.18.0-next.1", + "function-bind": "^1.1.1" + }, + "dependencies": { + "es-abstract": { + "version": "1.18.0-next.1", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.0-next.1.tgz", + "integrity": "sha512-I4UGspA0wpZXWENrdA0uHbnhte683t3qT/1VFH9aX2dA5PPSf6QW5HHXf5HImaqPmjXaVeVk4RGWnaylmV7uAA==", + "dev": true, + "requires": { + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1", + "is-callable": "^1.2.2", + "is-negative-zero": "^2.0.0", + "is-regex": "^1.1.1", + "object-inspect": "^1.8.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.1", + "string.prototype.trimend": "^1.0.1", + "string.prototype.trimstart": "^1.0.1" + } + }, + "is-callable": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.2.tgz", + "integrity": "sha512-dnMqspv5nU3LoewK2N/y7KLtxtakvTuaCsU9FU50/QDmdbHNy/4/JuRtMHqRU22o3q+W89YQndQEeCVwK+3qrA==", + "dev": true + }, + "is-regex": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.1.tgz", + "integrity": "sha512-1+QkEcxiLlB7VEyFtyBg94e08OAsvq7FUBgApTq/w2ymCLyKJgDPsybBENVtA7XCQEgEXxKPonG+mvYRxh/LIg==", + "dev": true, + "requires": { + "has-symbols": "^1.0.1" + } + }, + "object-inspect": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.9.0.tgz", + "integrity": "sha512-i3Bp9iTqwhaLZBxGkRfo5ZbE07BQRT7MGu8+nNgwW9ItGp1TzCTw2DLEoWwjClxBjOFI/hWljTAmYGCEwmtnOw==", + "dev": true + }, + "object.assign": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.2.tgz", + "integrity": "sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ==", + "dev": true, + "requires": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3", + "has-symbols": "^1.0.1", + "object-keys": "^1.1.1" + } + } + } + }, "arraybuffer.slice": { "version": "0.0.7", "resolved": "https://registry.npmjs.org/arraybuffer.slice/-/arraybuffer.slice-0.0.7.tgz", @@ -1462,6 +2041,15 @@ "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=" }, + "call-bind": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.0.tgz", + "integrity": "sha512-AEXsYIyyDY3MCzbwdhzG3Jx1R0J2wetQyUynn6dYHAO+bg8l1k7jwZtRv4ryryFs7EP+NDlikJlVe59jr0cM2w==", + "requires": { + "function-bind": "^1.1.1", + "get-intrinsic": "^1.0.0" + } + }, "caller-path": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/caller-path/-/caller-path-0.1.0.tgz", @@ -2117,6 +2705,13 @@ "pkg-config": "^1.1.0", "run-parallel": "^1.1.2", "uniq": "^1.0.1" + }, + "dependencies": { + "ignore": { + "version": "3.3.10", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.10.tgz", + "integrity": "sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==" + } } }, "del": { @@ -2212,9 +2807,10 @@ } }, "doctrine": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", - "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", + "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", + "dev": true, "requires": { "esutils": "^2.0.2" } @@ -2419,6 +3015,23 @@ "has-binary2": "~1.0.2" } }, + "enquirer": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz", + "integrity": "sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==", + "dev": true, + "requires": { + "ansi-colors": "^4.1.1" + }, + "dependencies": { + "ansi-colors": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", + "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", + "dev": true + } + } + }, "entities": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", @@ -2885,14 +3498,16 @@ } }, "eslint-config-standard": { - "version": "11.0.0", - "resolved": "https://registry.npmjs.org/eslint-config-standard/-/eslint-config-standard-11.0.0.tgz", - "integrity": "sha512-oDdENzpViEe5fwuRCWla7AXQd++/oyIp8zP+iP9jiUPG6NBj3SHgdgtl/kTn00AjeN+1HNvavTKmYbMo+xMOlw==" + "version": "14.1.1", + "resolved": "https://registry.npmjs.org/eslint-config-standard/-/eslint-config-standard-14.1.1.tgz", + "integrity": "sha512-Z9B+VR+JIXRxz21udPTL9HpFMyoMUEeX1G251EQ6e05WD9aPVtVBn09XUmZ259wCMlCDmYDSZG62Hhm+ZTJcUg==", + "dev": true }, "eslint-config-standard-jsx": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/eslint-config-standard-jsx/-/eslint-config-standard-jsx-5.0.0.tgz", - "integrity": "sha512-rLToPAEqLMPBfWnYTu6xRhm2OWziS2n40QFqJ8jAM8NSVzeVKTa3nclhsU4DpPJQRY60F34Oo1wi/71PN/eITg==" + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/eslint-config-standard-jsx/-/eslint-config-standard-jsx-10.0.0.tgz", + "integrity": "sha512-hLeA2f5e06W1xyr/93/QJulN/rLbUVUmqTlexv9PRKHFwEC9ffJcH2LvJhMoEqYQBEYafedgGZXH2W8NUpt5lA==", + "dev": true }, "eslint-import-resolver-node": { "version": "0.3.4", @@ -2953,26 +3568,31 @@ } }, "eslint-plugin-import": { - "version": "2.9.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.9.0.tgz", - "integrity": "sha1-JgAu+/ylmJtyiKwEdQi9JPIXsWk=", + "version": "2.22.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.22.1.tgz", + "integrity": "sha512-8K7JjINHOpH64ozkAhpT3sd+FswIZTfMZTjdx052pnWrgRCVfp8op9tbjpAk3DdUeI/Ba4C8OjdC0r90erHEOw==", + "dev": true, "requires": { - "builtin-modules": "^1.1.1", + "array-includes": "^3.1.1", + "array.prototype.flat": "^1.2.3", "contains-path": "^0.1.0", - "debug": "^2.6.8", + "debug": "^2.6.9", "doctrine": "1.5.0", - "eslint-import-resolver-node": "^0.3.1", - "eslint-module-utils": "^2.1.1", - "has": "^1.0.1", - "lodash": "^4.17.4", - "minimatch": "^3.0.3", - "read-pkg-up": "^2.0.0" + "eslint-import-resolver-node": "^0.3.4", + "eslint-module-utils": "^2.6.0", + "has": "^1.0.3", + "minimatch": "^3.0.4", + "object.values": "^1.1.1", + "read-pkg-up": "^2.0.0", + "resolve": "^1.17.0", + "tsconfig-paths": "^3.9.0" }, "dependencies": { "debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, "requires": { "ms": "2.0.0" } @@ -2981,6 +3601,7 @@ "version": "1.5.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz", "integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=", + "dev": true, "requires": { "esutils": "^2.0.2", "isarray": "^1.0.0" @@ -2989,7 +3610,8 @@ "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true } } }, @@ -3031,33 +3653,84 @@ } }, "eslint-plugin-promise": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-3.7.0.tgz", - "integrity": "sha512-2WO+ZFh7vxUKRfR0cOIMrWgYKdR6S1AlOezw6pC52B6oYpd5WFghN+QHxvrRdZMtbo8h3dfUZ2o1rWb0UPbKtg==" + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-4.2.1.tgz", + "integrity": "sha512-VoM09vT7bfA7D+upt+FjeBO5eHIJQBUWki1aPvB+vbNiHS3+oGIJGIeyBtKQTME6UPXXy3vV07OL1tHd3ANuDw==", + "dev": true }, "eslint-plugin-react": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.7.0.tgz", - "integrity": "sha512-KC7Snr4YsWZD5flu6A5c0AcIZidzW3Exbqp7OT67OaD2AppJtlBr/GuPrW/vaQM/yfZotEvKAdrxrO+v8vwYJA==", + "version": "7.21.5", + "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.21.5.tgz", + "integrity": "sha512-8MaEggC2et0wSF6bUeywF7qQ46ER81irOdWS4QWxnnlAEsnzeBevk1sWh7fhpCghPpXb+8Ks7hvaft6L/xsR6g==", + "dev": true, "requires": { - "doctrine": "^2.0.2", - "has": "^1.0.1", - "jsx-ast-utils": "^2.0.1", - "prop-types": "^15.6.0" + "array-includes": "^3.1.1", + "array.prototype.flatmap": "^1.2.3", + "doctrine": "^2.1.0", + "has": "^1.0.3", + "jsx-ast-utils": "^2.4.1 || ^3.0.0", + "object.entries": "^1.1.2", + "object.fromentries": "^2.0.2", + "object.values": "^1.1.1", + "prop-types": "^15.7.2", + "resolve": "^1.18.1", + "string.prototype.matchall": "^4.0.2" + }, + "dependencies": { + "doctrine": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", + "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==", + "dev": true, + "requires": { + "esutils": "^2.0.2" + } + }, + "resolve": { + "version": "1.19.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.19.0.tgz", + "integrity": "sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==", + "dev": true, + "requires": { + "is-core-module": "^2.1.0", + "path-parse": "^1.0.6" + } + } } }, "eslint-plugin-standard": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-standard/-/eslint-plugin-standard-3.0.1.tgz", - "integrity": "sha1-NNDJFbRe3G8BA5PH7vOCOwhWXPI=" + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-standard/-/eslint-plugin-standard-4.1.0.tgz", + "integrity": "sha512-ZL7+QRixjTR6/528YNGyDotyffm5OQst/sGxKDwGb9Uqs4In5Egi4+jbobhqJoyoCM6/7v/1A5fhQ7ScMtDjaQ==", + "dev": true }, "eslint-scope": { - "version": "3.7.3", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.3.tgz", - "integrity": "sha512-W+B0SvF4gamyCTmUc+uITPY0989iXVfKvhwtmJocTaYoc/3khEHmEmvfY/Gn9HA9VV75jrQECsHizkNw1b68FA==", + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", + "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", + "dev": true, "requires": { - "esrecurse": "^4.1.0", + "esrecurse": "^4.3.0", "estraverse": "^4.1.1" + }, + "dependencies": { + "esrecurse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", + "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", + "dev": true, + "requires": { + "estraverse": "^5.2.0" + }, + "dependencies": { + "estraverse": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.2.0.tgz", + "integrity": "sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ==", + "dev": true + } + } + } } }, "eslint-utils": { @@ -3075,12 +3748,22 @@ "integrity": "sha512-WFb4ihckKil6hu3Dp798xdzSfddwKKU3+nGniKF6HfeW6OLd2OUDEPP7TcHtB5+QXOKg2s6B2DaMPE1Nn/kxKQ==" }, "espree": { - "version": "3.5.4", - "resolved": "https://registry.npmjs.org/espree/-/espree-3.5.4.tgz", - "integrity": "sha512-yAcIQxtmMiB/jL32dzEp2enBeidsB7xWPLNiw3IIkpVds1P+h7qF9YwJq1yUNzp2OKXgAprs4F61ih66UsoD1A==", + "version": "7.3.1", + "resolved": "https://registry.npmjs.org/espree/-/espree-7.3.1.tgz", + "integrity": "sha512-v3JCNCE64umkFpmkFGqzVKsOT0tN1Zr+ueqLZfpV1Ob8e+CEgPWa+OxCoGH3tnhimMKIaBm4m/vaRpJ/krRz2g==", + "dev": true, "requires": { - "acorn": "^5.5.0", - "acorn-jsx": "^3.0.0" + "acorn": "^7.4.0", + "acorn-jsx": "^5.3.1", + "eslint-visitor-keys": "^1.3.0" + }, + "dependencies": { + "eslint-visitor-keys": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz", + "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==", + "dev": true + } } }, "esprima": { @@ -3198,9 +3881,10 @@ "dev": true }, "fast-deep-equal": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz", - "integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=" + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "dev": true }, "fast-diff": { "version": "1.2.0", @@ -3265,12 +3949,12 @@ } }, "file-entry-cache": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-2.0.0.tgz", - "integrity": "sha1-w5KZDD5oR4PYOLjISkXYoEhFg2E=", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-5.0.1.tgz", + "integrity": "sha512-bCg29ictuBaKUwwArK4ouCaqDgLZcysCFLmM/Yn/FDoqndh/9vNuQfXRDvTuXKLxfD/JtZQGKFT8MGcJBK644g==", + "dev": true, "requires": { - "flat-cache": "^1.2.1", - "object-assign": "^4.0.1" + "flat-cache": "^2.0.1" } }, "file-uri-to-path": { @@ -3321,14 +4005,14 @@ } }, "flat-cache": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-1.3.4.tgz", - "integrity": "sha512-VwyB3Lkgacfik2vhqR4uv2rvebqmDvFu4jlN/C1RzWoJEo8I7z4Q404oiqYCkq41mni8EzQnm95emU9seckwtg==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-2.0.1.tgz", + "integrity": "sha512-LoQe6yDuUMDzQAEH8sgmh4Md6oZnc/7PjtwjNFSzveXqSHt6ka9fPBuso7IGf9Rz4uqnSnWiFH2B/zj24a5ReA==", + "dev": true, "requires": { - "circular-json": "^0.3.1", - "graceful-fs": "^4.1.2", - "rimraf": "~2.6.2", - "write": "^0.2.1" + "flatted": "^2.0.0", + "rimraf": "2.6.3", + "write": "1.0.3" } }, "flatted": { @@ -3469,6 +4153,16 @@ "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", "dev": true }, + "get-intrinsic": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.0.2.tgz", + "integrity": "sha512-aeX0vrFm21ILl3+JpFFRNe9aUvp6VFZb2/CTbgLb8j75kOhvoNYjt9d8KA/tJG4gSo8nzEDedRl0h7vDmBYRVg==", + "requires": { + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1" + } + }, "get-stdin": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz", @@ -3869,9 +4563,10 @@ "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==" }, "ignore": { - "version": "3.3.10", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.10.tgz", - "integrity": "sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==" + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", + "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", + "dev": true }, "import-fresh": { "version": "3.2.1", @@ -3985,6 +4680,17 @@ } } }, + "internal-slot": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.2.tgz", + "integrity": "sha512-2cQNfwhAfJIkU4KZPkDI+Gj5yNNnbqi40W9Gge6dfnk4TocEVm00B3bdiL+JINrbGJil2TeHvM4rETGzk/f/0g==", + "dev": true, + "requires": { + "es-abstract": "^1.17.0-next.1", + "has": "^1.0.3", + "side-channel": "^1.0.2" + } + }, "into-stream": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/into-stream/-/into-stream-5.1.1.tgz", @@ -4026,6 +4732,15 @@ "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.0.tgz", "integrity": "sha512-pyVD9AaGLxtg6srb2Ng6ynWJqkHU9bEM087AKck0w8QwDarTfNcpIYoU8x8Hv2Icm8u6kFJM18Dag8lyqGkviw==" }, + "is-core-module": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.2.0.tgz", + "integrity": "sha512-XRAfAdyyY5F5cOXn7hYQDqh2Xmii+DEfIcQGxK/uNwMHhIkPWO0g8msXcbzLe+MpGoR951MlqM/2iIlU4vKDdQ==", + "dev": true, + "requires": { + "has": "^1.0.3" + } + }, "is-date-object": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.2.tgz", @@ -4070,6 +4785,11 @@ "define-properties": "^1.1.3" } }, + "is-negative-zero": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.1.tgz", + "integrity": "sha512-2z6JzQvZRa9A2Y7xC6dQQm4FSTSTNWjKIYYTt4246eMTJmIo0Q+ZyOsU66X8lxK1AbB92dFeglPLrhwpeRKO6w==" + }, "is-number": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", @@ -4279,9 +4999,10 @@ "dev": true }, "json-schema-traverse": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz", - "integrity": "sha1-NJptRMU6Ud6JtAgFxdXlm0F9M0A=" + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true }, "json-stable-stringify-without-jsonify": { "version": "1.0.1", @@ -4294,6 +5015,15 @@ "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", "dev": true }, + "json5": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", + "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", + "dev": true, + "requires": { + "minimist": "^1.2.0" + } + }, "jsonfile": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-3.0.1.tgz", @@ -4321,12 +5051,27 @@ } }, "jsx-ast-utils": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-2.4.1.tgz", - "integrity": "sha512-z1xSldJ6imESSzOjd3NNkieVJKRlKYSOtMG8SFyCj2FIrvSaSuli/WjpBkEzCBoR9bYYYFgqJw61Xhu7Lcgk+w==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-3.2.0.tgz", + "integrity": "sha512-EIsmt3O3ljsU6sot/J4E1zDRxfBNrhjyf/OKjlydwgEimQuznlM4Wv7U+ueONJMyEn1WRE0K8dhi3dVAXYT24Q==", + "dev": true, "requires": { - "array-includes": "^3.1.1", - "object.assign": "^4.1.0" + "array-includes": "^3.1.2", + "object.assign": "^4.1.2" + }, + "dependencies": { + "object.assign": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.2.tgz", + "integrity": "sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ==", + "dev": true, + "requires": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3", + "has-symbols": "^1.0.1", + "object-keys": "^1.1.1" + } + } } }, "just-extend": { @@ -9464,6 +10209,140 @@ "object-keys": "^1.0.11" } }, + "object.entries": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/object.entries/-/object.entries-1.1.3.tgz", + "integrity": "sha512-ym7h7OZebNS96hn5IJeyUmaWhaSM4SVtAPPfNLQEI2MYWCO2egsITb9nab2+i/Pwibx+R0mtn+ltKJXRSeTMGg==", + "dev": true, + "requires": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3", + "es-abstract": "^1.18.0-next.1", + "has": "^1.0.3" + }, + "dependencies": { + "es-abstract": { + "version": "1.18.0-next.1", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.0-next.1.tgz", + "integrity": "sha512-I4UGspA0wpZXWENrdA0uHbnhte683t3qT/1VFH9aX2dA5PPSf6QW5HHXf5HImaqPmjXaVeVk4RGWnaylmV7uAA==", + "dev": true, + "requires": { + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1", + "is-callable": "^1.2.2", + "is-negative-zero": "^2.0.0", + "is-regex": "^1.1.1", + "object-inspect": "^1.8.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.1", + "string.prototype.trimend": "^1.0.1", + "string.prototype.trimstart": "^1.0.1" + } + }, + "is-callable": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.2.tgz", + "integrity": "sha512-dnMqspv5nU3LoewK2N/y7KLtxtakvTuaCsU9FU50/QDmdbHNy/4/JuRtMHqRU22o3q+W89YQndQEeCVwK+3qrA==", + "dev": true + }, + "is-regex": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.1.tgz", + "integrity": "sha512-1+QkEcxiLlB7VEyFtyBg94e08OAsvq7FUBgApTq/w2ymCLyKJgDPsybBENVtA7XCQEgEXxKPonG+mvYRxh/LIg==", + "dev": true, + "requires": { + "has-symbols": "^1.0.1" + } + }, + "object-inspect": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.9.0.tgz", + "integrity": "sha512-i3Bp9iTqwhaLZBxGkRfo5ZbE07BQRT7MGu8+nNgwW9ItGp1TzCTw2DLEoWwjClxBjOFI/hWljTAmYGCEwmtnOw==", + "dev": true + }, + "object.assign": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.2.tgz", + "integrity": "sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ==", + "dev": true, + "requires": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3", + "has-symbols": "^1.0.1", + "object-keys": "^1.1.1" + } + } + } + }, + "object.fromentries": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/object.fromentries/-/object.fromentries-2.0.3.tgz", + "integrity": "sha512-IDUSMXs6LOSJBWE++L0lzIbSqHl9KDCfff2x/JSEIDtEUavUnyMYC2ZGay/04Zq4UT8lvd4xNhU4/YHKibAOlw==", + "dev": true, + "requires": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3", + "es-abstract": "^1.18.0-next.1", + "has": "^1.0.3" + }, + "dependencies": { + "es-abstract": { + "version": "1.18.0-next.1", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.0-next.1.tgz", + "integrity": "sha512-I4UGspA0wpZXWENrdA0uHbnhte683t3qT/1VFH9aX2dA5PPSf6QW5HHXf5HImaqPmjXaVeVk4RGWnaylmV7uAA==", + "dev": true, + "requires": { + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1", + "is-callable": "^1.2.2", + "is-negative-zero": "^2.0.0", + "is-regex": "^1.1.1", + "object-inspect": "^1.8.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.1", + "string.prototype.trimend": "^1.0.1", + "string.prototype.trimstart": "^1.0.1" + } + }, + "is-callable": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.2.tgz", + "integrity": "sha512-dnMqspv5nU3LoewK2N/y7KLtxtakvTuaCsU9FU50/QDmdbHNy/4/JuRtMHqRU22o3q+W89YQndQEeCVwK+3qrA==", + "dev": true + }, + "is-regex": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.1.tgz", + "integrity": "sha512-1+QkEcxiLlB7VEyFtyBg94e08OAsvq7FUBgApTq/w2ymCLyKJgDPsybBENVtA7XCQEgEXxKPonG+mvYRxh/LIg==", + "dev": true, + "requires": { + "has-symbols": "^1.0.1" + } + }, + "object-inspect": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.9.0.tgz", + "integrity": "sha512-i3Bp9iTqwhaLZBxGkRfo5ZbE07BQRT7MGu8+nNgwW9ItGp1TzCTw2DLEoWwjClxBjOFI/hWljTAmYGCEwmtnOw==", + "dev": true + }, + "object.assign": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.2.tgz", + "integrity": "sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ==", + "dev": true, + "requires": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3", + "has-symbols": "^1.0.1", + "object-keys": "^1.1.1" + } + } + } + }, "object.getownpropertydescriptors": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.1.0.tgz", @@ -9474,6 +10353,73 @@ "es-abstract": "^1.17.0-next.1" } }, + "object.values": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/object.values/-/object.values-1.1.2.tgz", + "integrity": "sha512-MYC0jvJopr8EK6dPBiO8Nb9mvjdypOachO5REGk6MXzujbBrAisKo3HmdEI6kZDL6fC31Mwee/5YbtMebixeag==", + "dev": true, + "requires": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3", + "es-abstract": "^1.18.0-next.1", + "has": "^1.0.3" + }, + "dependencies": { + "es-abstract": { + "version": "1.18.0-next.1", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.0-next.1.tgz", + "integrity": "sha512-I4UGspA0wpZXWENrdA0uHbnhte683t3qT/1VFH9aX2dA5PPSf6QW5HHXf5HImaqPmjXaVeVk4RGWnaylmV7uAA==", + "dev": true, + "requires": { + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1", + "is-callable": "^1.2.2", + "is-negative-zero": "^2.0.0", + "is-regex": "^1.1.1", + "object-inspect": "^1.8.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.1", + "string.prototype.trimend": "^1.0.1", + "string.prototype.trimstart": "^1.0.1" + } + }, + "is-callable": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.2.tgz", + "integrity": "sha512-dnMqspv5nU3LoewK2N/y7KLtxtakvTuaCsU9FU50/QDmdbHNy/4/JuRtMHqRU22o3q+W89YQndQEeCVwK+3qrA==", + "dev": true + }, + "is-regex": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.1.tgz", + "integrity": "sha512-1+QkEcxiLlB7VEyFtyBg94e08OAsvq7FUBgApTq/w2ymCLyKJgDPsybBENVtA7XCQEgEXxKPonG+mvYRxh/LIg==", + "dev": true, + "requires": { + "has-symbols": "^1.0.1" + } + }, + "object-inspect": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.9.0.tgz", + "integrity": "sha512-i3Bp9iTqwhaLZBxGkRfo5ZbE07BQRT7MGu8+nNgwW9ItGp1TzCTw2DLEoWwjClxBjOFI/hWljTAmYGCEwmtnOw==", + "dev": true + }, + "object.assign": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.2.tgz", + "integrity": "sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ==", + "dev": true, + "requires": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3", + "has-symbols": "^1.0.1", + "object-keys": "^1.1.1" + } + } + } + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -10759,17 +11705,21 @@ "dev": true }, "slice-ansi": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-1.0.0.tgz", - "integrity": "sha512-POqxBK6Lb3q6s047D/XsDVNPnF9Dl8JSaqe9h9lURl0OdNqy/ujDrOiIHtsqXMGbWWTIomRzAMaTyawAU//Reg==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-2.1.0.tgz", + "integrity": "sha512-Qu+VC3EwYLldKa1fCxuuvULvSJOKEgk9pi8dZeCVK7TqBfUNTH4sFkk4joj8afVSfAYgJoSOetjx9QWOJ5mYoQ==", + "dev": true, "requires": { + "ansi-styles": "^3.2.0", + "astral-regex": "^1.0.0", "is-fullwidth-code-point": "^2.0.0" }, "dependencies": { "is-fullwidth-code-point": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "dev": true } } }, @@ -11030,138 +11980,380 @@ "integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA=" }, "standard": { - "version": "11.0.1", - "resolved": "https://registry.npmjs.org/standard/-/standard-11.0.1.tgz", - "integrity": "sha512-nu0jAcHiSc8H+gJCXeiziMVZNDYi8MuqrYJKxTgjP4xKXZMKm311boqQIzDrYI/ktosltxt2CbDjYQs9ANC8IA==", + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/standard/-/standard-16.0.3.tgz", + "integrity": "sha512-70F7NH0hSkNXosXRltjSv6KpTAOkUkSfyu3ynyM5dtRUiLtR+yX9EGZ7RKwuGUqCJiX/cnkceVM6HTZ4JpaqDg==", + "dev": true, "requires": { - "eslint": "~4.18.0", - "eslint-config-standard": "11.0.0", - "eslint-config-standard-jsx": "5.0.0", - "eslint-plugin-import": "~2.9.0", - "eslint-plugin-node": "~6.0.0", - "eslint-plugin-promise": "~3.7.0", - "eslint-plugin-react": "~7.7.0", - "eslint-plugin-standard": "~3.0.1", - "standard-engine": "~8.0.0" + "eslint": "~7.13.0", + "eslint-config-standard": "16.0.2", + "eslint-config-standard-jsx": "10.0.0", + "eslint-plugin-import": "~2.22.1", + "eslint-plugin-node": "~11.1.0", + "eslint-plugin-promise": "~4.2.1", + "eslint-plugin-react": "~7.21.5", + "standard-engine": "^14.0.1" }, "dependencies": { - "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=" - }, - "cross-spawn": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", - "integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=", + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, "requires": { - "lru-cache": "^4.0.1", - "shebang-command": "^1.2.0", - "which": "^1.2.9" + "color-convert": "^2.0.1" + } + }, + "chalk": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", + "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "debug": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", + "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", + "dev": true, + "requires": { + "ms": "2.1.2" } }, "eslint": { - "version": "4.18.2", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-4.18.2.tgz", - "integrity": "sha512-qy4i3wODqKMYfz9LUI8N2qYDkHkoieTbiHpMrYUI/WbjhXJQr7lI4VngixTgaG+yHX+NBCv7nW4hA0ShbvaNKw==", + "version": "7.13.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.13.0.tgz", + "integrity": "sha512-uCORMuOO8tUzJmsdRtrvcGq5qposf7Rw0LwkTJkoDbOycVQtQjmnhZSuLQnozLE4TmAzlMVV45eCHmQ1OpDKUQ==", + "dev": true, "requires": { - "ajv": "^5.3.0", - "babel-code-frame": "^6.22.0", - "chalk": "^2.1.0", - "concat-stream": "^1.6.0", - "cross-spawn": "^5.1.0", - "debug": "^3.1.0", - "doctrine": "^2.1.0", - "eslint-scope": "^3.7.1", - "eslint-visitor-keys": "^1.0.0", - "espree": "^3.5.2", - "esquery": "^1.0.0", + "@babel/code-frame": "^7.0.0", + "@eslint/eslintrc": "^0.2.1", + "ajv": "^6.10.0", + "chalk": "^4.0.0", + "cross-spawn": "^7.0.2", + "debug": "^4.0.1", + "doctrine": "^3.0.0", + "enquirer": "^2.3.5", + "eslint-scope": "^5.1.1", + "eslint-utils": "^2.1.0", + "eslint-visitor-keys": "^2.0.0", + "espree": "^7.3.0", + "esquery": "^1.2.0", "esutils": "^2.0.2", - "file-entry-cache": "^2.0.0", + "file-entry-cache": "^5.0.1", "functional-red-black-tree": "^1.0.1", - "glob": "^7.1.2", - "globals": "^11.0.1", - "ignore": "^3.3.3", + "glob-parent": "^5.0.0", + "globals": "^12.1.0", + "ignore": "^4.0.6", + "import-fresh": "^3.0.0", "imurmurhash": "^0.1.4", - "inquirer": "^3.0.6", - "is-resolvable": "^1.0.0", - "js-yaml": "^3.9.1", + "is-glob": "^4.0.0", + "js-yaml": "^3.13.1", "json-stable-stringify-without-jsonify": "^1.0.1", - "levn": "^0.3.0", - "lodash": "^4.17.4", - "minimatch": "^3.0.2", - "mkdirp": "^0.5.1", + "levn": "^0.4.1", + "lodash": "^4.17.19", + "minimatch": "^3.0.4", "natural-compare": "^1.4.0", - "optionator": "^0.8.2", - "path-is-inside": "^1.0.2", - "pluralize": "^7.0.0", + "optionator": "^0.9.1", "progress": "^2.0.0", - "require-uncached": "^1.0.3", - "semver": "^5.3.0", - "strip-ansi": "^4.0.0", - "strip-json-comments": "~2.0.1", - "table": "4.0.2", - "text-table": "~0.2.0" + "regexpp": "^3.1.0", + "semver": "^7.2.1", + "strip-ansi": "^6.0.0", + "strip-json-comments": "^3.1.0", + "table": "^5.2.3", + "text-table": "^0.2.0", + "v8-compile-cache": "^2.0.3" + } + }, + "eslint-config-standard": { + "version": "16.0.2", + "resolved": "https://registry.npmjs.org/eslint-config-standard/-/eslint-config-standard-16.0.2.tgz", + "integrity": "sha512-fx3f1rJDsl9bY7qzyX8SAtP8GBSk6MfXFaTfaGgk12aAYW4gJSyRm7dM790L6cbXv63fvjY4XeSzXnb4WM+SKw==", + "dev": true + }, + "eslint-plugin-es": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-es/-/eslint-plugin-es-3.0.1.tgz", + "integrity": "sha512-GUmAsJaN4Fc7Gbtl8uOBlayo2DqhwWvEzykMHSCZHU3XdJ+NSzzZcVhXh3VxX5icqQ+oQdIEawXX8xkR3mIFmQ==", + "dev": true, + "requires": { + "eslint-utils": "^2.0.0", + "regexpp": "^3.0.0" } }, "eslint-plugin-node": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-node/-/eslint-plugin-node-6.0.1.tgz", - "integrity": "sha512-Q/Cc2sW1OAISDS+Ji6lZS2KV4b7ueA/WydVWd1BECTQwVvfQy5JAi3glhINoKzoMnfnuRgNP+ZWKrGAbp3QDxw==", + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-node/-/eslint-plugin-node-11.1.0.tgz", + "integrity": "sha512-oUwtPJ1W0SKD0Tr+wqu92c5xuCeQqB3hSCHasn/ZgjFdA9iDGNkNf2Zi9ztY7X+hNuMib23LNGRm6+uN+KLE3g==", + "dev": true, "requires": { - "ignore": "^3.3.6", + "eslint-plugin-es": "^3.0.0", + "eslint-utils": "^2.0.0", + "ignore": "^5.1.1", "minimatch": "^3.0.4", - "resolve": "^1.3.3", - "semver": "^5.4.1" + "resolve": "^1.10.1", + "semver": "^6.1.0" }, "dependencies": { + "ignore": { + "version": "5.1.8", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.8.tgz", + "integrity": "sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==", + "dev": true + }, "semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true } } }, - "shebang-command": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", - "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", + "eslint-utils": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.1.0.tgz", + "integrity": "sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg==", + "dev": true, "requires": { - "shebang-regex": "^1.0.0" + "eslint-visitor-keys": "^1.1.0" + }, + "dependencies": { + "eslint-visitor-keys": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz", + "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==", + "dev": true + } } }, - "shebang-regex": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", - "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=" + "eslint-visitor-keys": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.0.0.tgz", + "integrity": "sha512-QudtT6av5WXels9WjIM7qz1XD1cWGvX4gGXvp/zBn9nXG02D0utdU3Em2m/QjTnrsk6bBjmCygl3rmj118msQQ==", + "dev": true }, - "strip-ansi": { + "globals": { + "version": "12.4.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-12.4.0.tgz", + "integrity": "sha512-BWICuzzDvDoH54NHKCseDanAhE3CeDorgDL5MT6LMXXj2WCnd9UC2szdk4AWLfjdgNBCXLUanXYcpBBKOSWGwg==", + "dev": true, + "requires": { + "type-fest": "^0.8.1" + } + }, + "has-flag": { "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, + "levn": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", + "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", + "dev": true, "requires": { - "ansi-regex": "^3.0.0" + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" } }, - "which": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", - "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, "requires": { - "isexe": "^2.0.0" + "yallist": "^4.0.0" } + }, + "optionator": { + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz", + "integrity": "sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==", + "dev": true, + "requires": { + "deep-is": "^0.1.3", + "fast-levenshtein": "^2.0.6", + "levn": "^0.4.1", + "prelude-ls": "^1.2.1", + "type-check": "^0.4.0", + "word-wrap": "^1.2.3" + } + }, + "prelude-ls": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", + "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", + "dev": true + }, + "regexpp": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.1.0.tgz", + "integrity": "sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q==", + "dev": true + }, + "semver": { + "version": "7.3.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.4.tgz", + "integrity": "sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + }, + "strip-json-comments": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", + "dev": true + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "requires": { + "has-flag": "^4.0.0" + } + }, + "type-check": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", + "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", + "dev": true, + "requires": { + "prelude-ls": "^1.2.1" + } + }, + "type-fest": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", + "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", + "dev": true + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true } } }, "standard-engine": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/standard-engine/-/standard-engine-8.0.1.tgz", - "integrity": "sha512-LA531C3+nljom/XRvdW/hGPXwmilRkaRkENhO3FAGF1Vtq/WtCXzgmnc5S6vUHHsgv534MRy02C1ikMwZXC+tw==", + "version": "14.0.1", + "resolved": "https://registry.npmjs.org/standard-engine/-/standard-engine-14.0.1.tgz", + "integrity": "sha512-7FEzDwmHDOGva7r9ifOzD3BGdTbA7ujJ50afLVdW/tK14zQEptJjbFuUfn50irqdHDcTbNh0DTIoMPynMCXb0Q==", + "dev": true, "requires": { - "deglob": "^2.1.0", - "get-stdin": "^6.0.0", - "minimist": "^1.1.0", - "pkg-conf": "^2.0.0" + "get-stdin": "^8.0.0", + "minimist": "^1.2.5", + "pkg-conf": "^3.1.0", + "xdg-basedir": "^4.0.0" + }, + "dependencies": { + "find-up": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", + "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "dev": true, + "requires": { + "locate-path": "^3.0.0" + } + }, + "get-stdin": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-8.0.0.tgz", + "integrity": "sha512-sY22aA6xchAzprjyqmSEQv4UbAAzRN0L2dQB0NlN5acTTK9Don6nhoc3eAbUnpZiCANAMfd/+40kVdKfFygohg==", + "dev": true + }, + "load-json-file": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-5.3.0.tgz", + "integrity": "sha512-cJGP40Jc/VXUsp8/OrnyKyTZ1y6v/dphm3bioS+RrKXjK2BB6wHUd6JptZEFDGgGahMT+InnZO5i1Ei9mpC8Bw==", + "dev": true, + "requires": { + "graceful-fs": "^4.1.15", + "parse-json": "^4.0.0", + "pify": "^4.0.1", + "strip-bom": "^3.0.0", + "type-fest": "^0.3.0" + } + }, + "locate-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", + "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", + "dev": true, + "requires": { + "p-locate": "^3.0.0", + "path-exists": "^3.0.0" + } + }, + "p-locate": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", + "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", + "dev": true, + "requires": { + "p-limit": "^2.0.0" + } + }, + "parse-json": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", + "integrity": "sha1-vjX1Qlvh9/bHRxhPmKeIy5lHfuA=", + "dev": true, + "requires": { + "error-ex": "^1.3.1", + "json-parse-better-errors": "^1.0.1" + } + }, + "path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", + "dev": true + }, + "pify": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz", + "integrity": "sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==", + "dev": true + }, + "pkg-conf": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/pkg-conf/-/pkg-conf-3.1.0.tgz", + "integrity": "sha512-m0OTbR/5VPNPqO1ph6Fqbj7Hv6QU7gR/tQW40ZqrL1rjgCU85W6C1bJn0BItuJqnR98PWzw7Z8hHeChD1WrgdQ==", + "dev": true, + "requires": { + "find-up": "^3.0.0", + "load-json-file": "^5.2.0" + } + }, + "type-fest": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.3.1.tgz", + "integrity": "sha512-cUGJnCdr4STbePCgqNFbpVNCepa+kAVohJs1sLhxzdH+gnEoOd8VhbYa7pD3zZYGiURWM2xzEII3fQcRizDkYQ==", + "dev": true + } } }, "stream-combiner2": { @@ -11217,6 +12409,87 @@ "strip-ansi": "^6.0.0" } }, + "string.prototype.matchall": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/string.prototype.matchall/-/string.prototype.matchall-4.0.3.tgz", + "integrity": "sha512-OBxYDA2ifZQ2e13cP82dWFMaCV9CGF8GzmN4fljBVw5O5wep0lu4gacm1OL6MjROoUnB8VbkWRThqkV2YFLNxw==", + "dev": true, + "requires": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3", + "es-abstract": "^1.18.0-next.1", + "has-symbols": "^1.0.1", + "internal-slot": "^1.0.2", + "regexp.prototype.flags": "^1.3.0", + "side-channel": "^1.0.3" + }, + "dependencies": { + "es-abstract": { + "version": "1.18.0-next.1", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.0-next.1.tgz", + "integrity": "sha512-I4UGspA0wpZXWENrdA0uHbnhte683t3qT/1VFH9aX2dA5PPSf6QW5HHXf5HImaqPmjXaVeVk4RGWnaylmV7uAA==", + "dev": true, + "requires": { + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1", + "is-callable": "^1.2.2", + "is-negative-zero": "^2.0.0", + "is-regex": "^1.1.1", + "object-inspect": "^1.8.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.1", + "string.prototype.trimend": "^1.0.1", + "string.prototype.trimstart": "^1.0.1" + } + }, + "is-callable": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.2.tgz", + "integrity": "sha512-dnMqspv5nU3LoewK2N/y7KLtxtakvTuaCsU9FU50/QDmdbHNy/4/JuRtMHqRU22o3q+W89YQndQEeCVwK+3qrA==", + "dev": true + }, + "is-regex": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.1.tgz", + "integrity": "sha512-1+QkEcxiLlB7VEyFtyBg94e08OAsvq7FUBgApTq/w2ymCLyKJgDPsybBENVtA7XCQEgEXxKPonG+mvYRxh/LIg==", + "dev": true, + "requires": { + "has-symbols": "^1.0.1" + } + }, + "object-inspect": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.9.0.tgz", + "integrity": "sha512-i3Bp9iTqwhaLZBxGkRfo5ZbE07BQRT7MGu8+nNgwW9ItGp1TzCTw2DLEoWwjClxBjOFI/hWljTAmYGCEwmtnOw==", + "dev": true + }, + "object.assign": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.2.tgz", + "integrity": "sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ==", + "dev": true, + "requires": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3", + "has-symbols": "^1.0.1", + "object-keys": "^1.1.1" + } + }, + "side-channel": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", + "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "dev": true, + "requires": { + "call-bind": "^1.0.0", + "get-intrinsic": "^1.0.2", + "object-inspect": "^1.9.0" + } + } + } + }, "string.prototype.trim": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/string.prototype.trim/-/string.prototype.trim-1.2.1.tgz", @@ -11343,43 +12616,53 @@ } }, "table": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/table/-/table-4.0.2.tgz", - "integrity": "sha512-UUkEAPdSGxtRpiV9ozJ5cMTtYiqz7Ni1OGqLXRCynrvzdtR1p+cfOWe2RJLwvUG8hNanaSRjecIqwOjqeatDsA==", + "version": "5.4.6", + "resolved": "https://registry.npmjs.org/table/-/table-5.4.6.tgz", + "integrity": "sha512-wmEc8m4fjnob4gt5riFRtTu/6+4rSe12TpAELNSqHMfF3IqnA+CH37USM6/YR3qRZv7e56kAEAtd6nKZaxe0Ug==", + "dev": true, "requires": { - "ajv": "^5.2.3", - "ajv-keywords": "^2.1.0", - "chalk": "^2.1.0", - "lodash": "^4.17.4", - "slice-ansi": "1.0.0", - "string-width": "^2.1.1" + "ajv": "^6.10.2", + "lodash": "^4.17.14", + "slice-ansi": "^2.1.0", + "string-width": "^3.0.0" }, "dependencies": { "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=" + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "dev": true + }, + "emoji-regex": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", + "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", + "dev": true }, "is-fullwidth-code-point": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "dev": true }, "string-width": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "dev": true, "requires": { + "emoji-regex": "^7.0.1", "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.0.0" + "strip-ansi": "^5.1.0" } }, "strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "dev": true, "requires": { - "ansi-regex": "^3.0.0" + "ansi-regex": "^4.1.0" } } } @@ -11539,6 +12822,18 @@ "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.3.0.tgz", "integrity": "sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==" }, + "tsconfig-paths": { + "version": "3.9.0", + "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz", + "integrity": "sha512-dRcuzokWhajtZWkQsDVKbWyY+jgcLC5sqJhg2PSgf4ZkH2aHPvaOY8YWGhmjb68b5qqTfasSsDO9k7RUiEmZAw==", + "dev": true, + "requires": { + "@types/json5": "^0.0.29", + "json5": "^1.0.1", + "minimist": "^1.2.0", + "strip-bom": "^3.0.0" + } + }, "tslib": { "version": "1.13.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.13.0.tgz", @@ -11698,6 +12993,12 @@ "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==" }, + "v8-compile-cache": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.2.0.tgz", + "integrity": "sha512-gTpR5XQNKFwOd4clxfnhaqvfqMpqEwr4tOtCyz4MtYZX2JYhfr1JvBFKdS+7K/9rfpZR3VLX+YWBbKoxCgS43Q==", + "dev": true + }, "validate-npm-package-license": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", @@ -11939,9 +13240,10 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "write": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/write/-/write-0.2.1.tgz", - "integrity": "sha1-X8A4KOJkzqP+kUVUdvejxWbLB1c=", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/write/-/write-1.0.3.tgz", + "integrity": "sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig==", + "dev": true, "requires": { "mkdirp": "^0.5.1" } @@ -11951,6 +13253,12 @@ "resolved": "https://registry.npmjs.org/ws/-/ws-7.3.0.tgz", "integrity": "sha512-iFtXzngZVXPGgpTlP1rBqsUK82p9tKqsWRPg5L56egiljujJT3vGAYnHANvFxBieXrTFavhzhxW52jnaWV+w2w==" }, + "xdg-basedir": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-4.0.0.tgz", + "integrity": "sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q==", + "dev": true + }, "xmlhttprequest-ssl": { "version": "1.5.5", "resolved": "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.5.tgz", diff --git a/package.json b/package.json index b2230e5..bec7f30 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "test:temp2": "mocha --timeout 30000 -g '#getStatus' test/unit/", "coverage": "nyc report --reporter=text-lcov | coveralls", "coverage:report": "nyc --reporter=html mocha --timeout 25000 test/unit/", - "docs": "./node_modules/.bin/apidoc -i src/ -o docs" + "docs": "./node_modules/.bin/apidoc -i src/ -o docs", + "lint": "standard --env mocha --fix" }, "license": "MIT", "homepage": "https://github.com/Permissionless-Software-Foundation/bch-js", @@ -79,8 +80,10 @@ "coveralls": "^3.0.2", "eslint": "5.16.0", "eslint-config-prettier": "^6.0.0", + "eslint-config-standard": "^14.1.0", "eslint-plugin-node": "^9.1.0", "eslint-plugin-prettier": "^3.1.0", + "eslint-plugin-standard": "^4.0.0", "lodash.clonedeep": "^4.5.0", "mocha": "^6.1.4", "nock": "^10.0.6", @@ -88,7 +91,8 @@ "nyc": "^14.1.0", "prettier": "^1.18.2", "semantic-release": "^17.3.1", - "sinon": "^7.3.2" + "sinon": "^7.3.2", + "standard": "^16.0.3" }, "apidoc": { "title": "bch-js", diff --git a/src/address.js b/src/address.js index 4889971..dc93bba 100644 --- a/src/address.js +++ b/src/address.js @@ -1,12 +1,12 @@ -//const axios = require("axios") -const Bitcoin = require("@psf/bitcoincashjs-lib") -const cashaddr = require("cashaddrjs") -const coininfo = require("@psf/coininfo") +// const axios = require("axios") +const Bitcoin = require('@psf/bitcoincashjs-lib') +const cashaddr = require('cashaddrjs') +const coininfo = require('@psf/coininfo') class Address { - constructor(config) { + constructor (config) { const tmp = {} - if (!config || !config.restURL) tmp.restURL = `https://api.bchjs.cash/v4/` + if (!config || !config.restURL) tmp.restURL = 'https://api.bchjs.cash/v4/' else tmp.restURL = config.restURL this.restURL = tmp.restURL @@ -54,34 +54,34 @@ class Address { * // mqc1tmwY2368LLGktnePzEyPAsgADxbksi */ // Translate address from any address format into a specific format. - toLegacyAddress(address) { + toLegacyAddress (address) { const { prefix, type, hash } = this._decode(address) let bitcoincash switch (prefix) { - case "bitcoincash": + case 'bitcoincash': bitcoincash = coininfo.bitcoincash.main break - case "bchtest": + case 'bchtest': bitcoincash = coininfo.bitcoincash.test break - case "bchreg": + case 'bchreg': bitcoincash = coininfo.bitcoincash.regtest break default: - throw `unsupported prefix : ${prefix}` + throw new Error(`unsupported prefix : ${prefix}`) } let version switch (type) { - case "P2PKH": + case 'P2PKH': version = bitcoincash.versions.public break - case "P2SH": + case 'P2SH': version = bitcoincash.versions.scripthash break default: - throw `unsupported address type : ${type}` + throw new Error(`unsupported address type : ${type}`) } const hashBuf = Buffer.from(hash) @@ -112,11 +112,11 @@ class Address { * bchjs.Address.toCashAddress('msDbtTj7kWXPpYaR7PQmMK84i66fJqQMLx', false) * // qzq9je6pntpva3wf6scr7mlnycr54sjgeqxgrr9ku3 */ - toCashAddress(address, prefix = true, regtest = false) { + toCashAddress (address, prefix = true, regtest = false) { const decoded = this._decode(address) let prefixString - if (regtest) prefixString = "bchreg" + if (regtest) prefixString = 'bchreg' else prefixString = decoded.prefix const cashAddress = cashaddr.encode( @@ -126,14 +126,14 @@ class Address { ) if (prefix) return cashAddress - return cashAddress.split(":")[1] + return cashAddress.split(':')[1] } // Converts any address format to hash160 - toHash160(address) { + toHash160 (address) { const legacyAddress = this.toLegacyAddress(address) const bytes = Bitcoin.address.fromBase58Check(legacyAddress) - return bytes.hash.toString("hex") + return bytes.hash.toString('hex') } /** @@ -156,8 +156,8 @@ class Address { * // mhTg9sgNgvAGfmJs192oUzQWqAXHH5nqLE */ // Converts hash160 to Legacy Address - hash160ToLegacy(hash160, network = Bitcoin.networks.bitcoin.pubKeyHash) { - const buffer = Buffer.from(hash160, "hex") + hash160ToLegacy (hash160, network = Bitcoin.networks.bitcoin.pubKeyHash) { + const buffer = Buffer.from(hash160, 'hex') const legacyAddress = Bitcoin.address.toBase58Check(buffer, network) return legacyAddress } @@ -177,7 +177,7 @@ class Address { * 'bchtest:qq24rpar9qas3vc9r8d4p0prhwaf7jmx2u22nzt946' */ // Converts hash160 to Cash Address - hash160ToCash( + hash160ToCash ( hash160, network = Bitcoin.networks.bitcoin.pubKeyHash, regtest = false @@ -186,7 +186,7 @@ class Address { return this.toCashAddress(legacyAddress, true, regtest) } - _decode(address) { + _decode (address) { try { return this._decodeLegacyAddress(address) } catch (error) {} @@ -202,56 +202,56 @@ class Address { throw new Error(`Unsupported address format : ${address}`) } - _decodeLegacyAddress(address) { + _decodeLegacyAddress (address) { const { version, hash } = Bitcoin.address.fromBase58Check(address) const info = coininfo.bitcoincash switch (version) { case info.main.versions.public: return { - prefix: "bitcoincash", - type: "P2PKH", + prefix: 'bitcoincash', + type: 'P2PKH', hash: hash, - format: "legacy" + format: 'legacy' } case info.main.versions.scripthash: return { - prefix: "bitcoincash", - type: "P2SH", + prefix: 'bitcoincash', + type: 'P2SH', hash: hash, - format: "legacy" + format: 'legacy' } case info.test.versions.public: return { - prefix: "bchtest", - type: "P2PKH", + prefix: 'bchtest', + type: 'P2PKH', hash: hash, - format: "legacy" + format: 'legacy' } case info.test.versions.scripthash: return { - prefix: "bchtest", - type: "P2SH", + prefix: 'bchtest', + type: 'P2SH', hash: hash, - format: "legacy" + format: 'legacy' } default: throw new Error(`Invalid format : ${address}`) } } - _decodeCashAddress(address) { - if (address.indexOf(":") !== -1) { + _decodeCashAddress (address) { + if (address.indexOf(':') !== -1) { const decoded = cashaddr.decode(address) - decoded.format = "cashaddr" + decoded.format = 'cashaddr' return decoded } - const prefixes = ["bitcoincash", "bchtest", "bchreg"] + const prefixes = ['bitcoincash', 'bchtest', 'bchreg'] for (let i = 0; i < prefixes.length; ++i) { try { const decoded = cashaddr.decode(`${prefixes[i]}:${address}`) - decoded.format = "cashaddr" + decoded.format = 'cashaddr' return decoded } catch (error) {} } @@ -259,12 +259,12 @@ class Address { throw new Error(`Invalid format : ${address}`) } - _encodeAddressFromHash160(address) { + _encodeAddressFromHash160 (address) { try { return { legacyAddress: this.hash160ToLegacy(address), cashAddress: this.hash160ToCash(address), - format: "hash160" + format: 'hash160' } } catch (error) {} @@ -303,8 +303,8 @@ class Address { * // true */ // Test for address format. - isLegacyAddress(address) { - return this.detectAddressFormat(address) === "legacy" + isLegacyAddress (address) { + return this.detectAddressFormat(address) === 'legacy' } /** @@ -338,8 +338,8 @@ class Address { * bchjs.Address.isCashAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') * // false */ - isCashAddress(address) { - return this.detectAddressFormat(address) === "cashaddr" + isCashAddress (address) { + return this.detectAddressFormat(address) === 'cashaddr' } /** @@ -357,8 +357,8 @@ class Address { * bchjs.Address.isHash160(notHash160Address); * // false */ - isHash160(address) { - return this.detectAddressFormat(address) === "hash160" + isHash160 (address) { + return this.detectAddressFormat(address) === 'hash160' } /** @@ -393,11 +393,11 @@ class Address { * // false */ // Test for address network. - isMainnetAddress(address) { - if (address[0] === "x") return true - else if (address[0] === "t") return false + isMainnetAddress (address) { + if (address[0] === 'x') return true + else if (address[0] === 't') return false - return this.detectAddressNetwork(address) === "mainnet" + return this.detectAddressNetwork(address) === 'mainnet' } /** @@ -431,11 +431,11 @@ class Address { * bchjs.Address.isTestnetAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') * // true */ - isTestnetAddress(address) { - if (address[0] === "x") return false - else if (address[0] === "t") return true + isTestnetAddress (address) { + if (address[0] === 'x') return false + else if (address[0] === 't') return true - return this.detectAddressNetwork(address) === "testnet" + return this.detectAddressNetwork(address) === 'testnet' } /** @@ -473,8 +473,8 @@ class Address { * bchjs.Address.isRegTestAddress('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggt9t0a6zy') * // false */ - isRegTestAddress(address) { - return this.detectAddressNetwork(address) === "regtest" + isRegTestAddress (address) { + return this.detectAddressNetwork(address) === 'regtest' } /** @@ -510,8 +510,8 @@ class Address { */ // Test for address type. - isP2PKHAddress(address) { - return this.detectAddressType(address) === "p2pkh" + isP2PKHAddress (address) { + return this.detectAddressType(address) === 'p2pkh' } /** @@ -546,8 +546,8 @@ class Address { * // false */ - isP2SHAddress(address) { - return this.detectAddressType(address) === "p2sh" + isP2SHAddress (address) { + return this.detectAddressType(address) === 'p2sh' } /** @@ -582,7 +582,7 @@ class Address { * // legacy */ // Detect address format. - detectAddressFormat(address) { + detectAddressFormat (address) { const decoded = this._decode(address) return decoded.format @@ -620,19 +620,19 @@ class Address { * // testnet */ // Detect address network. - detectAddressNetwork(address) { - if (address[0] === "x") return "mainnet" - else if (address[0] === "t") return "testnet" + detectAddressNetwork (address) { + if (address[0] === 'x') return 'mainnet' + else if (address[0] === 't') return 'testnet' const decoded = this._decode(address) switch (decoded.prefix) { - case "bitcoincash": - return "mainnet" - case "bchtest": - return "testnet" - case "bchreg": - return "regtest" + case 'bitcoincash': + return 'mainnet' + case 'bchtest': + return 'testnet' + case 'bchreg': + return 'regtest' default: throw new Error(`Invalid prefix : ${decoded.prefix}`) } @@ -670,7 +670,7 @@ class Address { * // p2pkh */ // Detect address type. - detectAddressType(address) { + detectAddressType (address) { const decoded = this._decode(address) return decoded.type.toLowerCase() @@ -705,7 +705,7 @@ class Address { * // bchtest:qzd7dvlnfukggjqsf5ju0qqwwltakfumjsck33js6m * // bchtest:qq322ataqeas4n0pdn4gz2sdereh5ae43ylk4qdvus */ - fromXPub(xpub, path = "0/0") { + fromXPub (xpub, path = '0/0') { const HDNode = Bitcoin.HDNode.fromBase58( xpub, Bitcoin.networks[this.detectAddressNetwork(xpub)] @@ -738,12 +738,13 @@ class Address { * bchjs.Address.fromOutputScript(scriptPubKey, 'testnet'); * // bchtest:pz0qcslrqn7hr44hsszwl4lw5r6udkg6zqh2hmtpyr */ - fromOutputScript(scriptPubKey, network = "mainnet") { + fromOutputScript (scriptPubKey, network = 'mainnet') { let netParam - if (network !== "bitcoincash" && network !== "mainnet") + if (network !== 'bitcoincash' && network !== 'mainnet') { netParam = Bitcoin.networks.testnet + } - const regtest = network === "bchreg" + const regtest = network === 'bchreg' return this.toCashAddress( Bitcoin.address.fromOutputScript(scriptPubKey, netParam), diff --git a/src/bch-js.js b/src/bch-js.js index affa887..5daab35 100644 --- a/src/bch-js.js +++ b/src/bch-js.js @@ -7,66 +7,56 @@ */ // bch-api mainnet. -const DEFAULT_REST_API = "https://api.fullstack.cash/v4/" +const DEFAULT_REST_API = 'https://api.fullstack.cash/v4/' // const DEFAULT_REST_API = "http://localhost:3000/v4/" // local deps -const BitcoinCash = require("./bitcoincash") -const Crypto = require("./crypto") -const Util = require("./util") -const Blockchain = require("./blockchain") -const Control = require("./control") -const Generating = require("./generating") -const Mining = require("./mining") -const RawTransactions = require("./raw-transactions") -const Mnemonic = require("./mnemonic") -const Address = require("./address") -const HDNode = require("./hdnode") -const TransactionBuilder = require("./transaction-builder") -const ECPair = require("./ecpair") -const Script = require("./script") -const Price = require("./price") -const Socket = require("./socket") -const Schnorr = require("./schnorr") -const SLP = require("./slp/slp") -const IPFS = require("./ipfs") -const Encryption = require("./encryption") +const BitcoinCash = require('./bitcoincash') +const Crypto = require('./crypto') +const Util = require('./util') +const Blockchain = require('./blockchain') +const Control = require('./control') +const Generating = require('./generating') +const Mining = require('./mining') +const RawTransactions = require('./raw-transactions') +const Mnemonic = require('./mnemonic') +const Address = require('./address') +const HDNode = require('./hdnode') +const TransactionBuilder = require('./transaction-builder') +const ECPair = require('./ecpair') +const Script = require('./script') +const Price = require('./price') +const Socket = require('./socket') +const Schnorr = require('./schnorr') +const SLP = require('./slp/slp') +const IPFS = require('./ipfs') +const Encryption = require('./encryption') // Indexers -const OpenBazaar = require("./openbazaar") -const Ninsight = require("./ninsight") -const Electrumx = require("./electrumx") +const OpenBazaar = require('./openbazaar') +const Ninsight = require('./ninsight') +const Electrumx = require('./electrumx') class BCHJS { - constructor(config) { + constructor (config) { // Try to retrieve the REST API URL from different sources. - if (config && config.restURL && config.restURL !== "") - this.restURL = config.restURL - else if (process.env.RESTURL && process.env.RESTURL !== "") - this.restURL = process.env.RESTURL - else this.restURL = DEFAULT_REST_API + if (config && config.restURL && config.restURL !== '') { this.restURL = config.restURL } else if (process.env.RESTURL && process.env.RESTURL !== '') { this.restURL = process.env.RESTURL } else this.restURL = DEFAULT_REST_API // Retrieve the apiToken - this.apiToken = "" // default value. - if (config && config.apiToken && config.apiToken !== "") - this.apiToken = config.apiToken - else if (process.env.BCHJSTOKEN && process.env.BCHJSTOKEN !== "") - this.apiToken = process.env.BCHJSTOKEN + this.apiToken = '' // default value. + if (config && config.apiToken && config.apiToken !== '') { this.apiToken = config.apiToken } else if (process.env.BCHJSTOKEN && process.env.BCHJSTOKEN !== '') { this.apiToken = process.env.BCHJSTOKEN } // Retrieve the Basic Authentication password. - this.authPass = "" // default value. - if (config && config.authPass && config.authPass !== "") - this.authPass = config.authPass - else if (process.env.BCHJSAUTHPASS && process.env.BCHJSAUTHPASS !== "") - this.authPass = process.env.BCHJSAUTHPASS + this.authPass = '' // default value. + if (config && config.authPass && config.authPass !== '') { this.authPass = config.authPass } else if (process.env.BCHJSAUTHPASS && process.env.BCHJSAUTHPASS !== '') { this.authPass = process.env.BCHJSAUTHPASS } // Generate a Basic Authentication token from an auth password - this.authToken = "" + this.authToken = '' if (this.authPass) { // console.log(`bch-js initialized with authPass: ${this.authPass}`) // Generate the header for Basic Authentication. const combined = `fullstackcash:${this.authPass}` - var base64Credential = Buffer.from(combined).toString("base64") + const base64Credential = Buffer.from(combined).toString('base64') this.authToken = `Basic ${base64Credential}` } diff --git a/src/bitcoincash.js b/src/bitcoincash.js index de69f6f..9fcc0d7 100644 --- a/src/bitcoincash.js +++ b/src/bitcoincash.js @@ -1,16 +1,16 @@ -const Bitcoin = require("@psf/bitcoincashjs-lib") -const sb = require("satoshi-bitcoin") -const bitcoinMessage = require("bitcoinjs-message") -const bs58 = require("bs58") -const bip21 = require("@psf/bip21") -const coininfo = require("@psf/coininfo") -const bip38 = require("bip38") -const wif = require("wif") +const Bitcoin = require('@psf/bitcoincashjs-lib') +const sb = require('satoshi-bitcoin') +const bitcoinMessage = require('bitcoinjs-message') +const bs58 = require('bs58') +const bip21 = require('@psf/bip21') +const coininfo = require('@psf/coininfo') +const bip38 = require('bip38') +const wif = require('wif') -const Buffer = require("safe-buffer").Buffer +const Buffer = require('safe-buffer').Buffer class BitcoinCash { - constructor(address) { + constructor (address) { this._address = address } @@ -43,7 +43,7 @@ class BitcoinCash { * // 50700000000 */ // Translate coins to satoshi value - toSatoshi(coins) { + toSatoshi (coins) { return sb.toSatoshi(coins) } @@ -76,7 +76,7 @@ class BitcoinCash { * // 507 */ // Translate satoshi to coin value - toBitcoinCash(satoshis) { + toBitcoinCash (satoshis) { return sb.toBitcoin(satoshis) } @@ -105,13 +105,13 @@ class BitcoinCash { * // 0.123 */ // Translate satoshi to bits denomination - toBits(satoshis) { + toBits (satoshis) { return parseFloat(satoshis) / 100 } // Translate satoshi to bits denomination // TODO remove in 2.0 - satsToBits(satoshis) { + satsToBits (satoshis) { return parseFloat(satoshis) / 100 } @@ -147,10 +147,10 @@ class BitcoinCash { * // IIYVhlo2Z6TWFjYX1+YM+7vQKz0m+zYdSe4eYpFLuAQDEZXqll7lZC8Au22VI2LLP5x+IerZckVk3QQPsA3e8/8= */ // sign message - signMessageWithPrivKey(privateKeyWIF, message) { - const network = privateKeyWIF.charAt(0) === "c" ? "testnet" : "mainnet" + signMessageWithPrivKey (privateKeyWIF, message) { + const network = privateKeyWIF.charAt(0) === 'c' ? 'testnet' : 'mainnet' let bitcoincash - if (network === "mainnet") bitcoincash = coininfo.bitcoincash.main + if (network === 'mainnet') bitcoincash = coininfo.bitcoincash.main else bitcoincash = coininfo.bitcoincash.test const bitcoincashBitcoinJSLib = bitcoincash.toBitcoinJS() @@ -161,7 +161,7 @@ class BitcoinCash { const privateKey = keyPair.d.toBuffer(32) return bitcoinMessage .sign(message, privateKey, keyPair.compressed) - .toString("base64") + .toString('base64') } /** @@ -180,7 +180,7 @@ class BitcoinCash { * // true */ // verify message - verifyMessage(address, signature, message) { + verifyMessage (address, signature, message) { return bitcoinMessage.verify( message, this._address.toLegacyAddress(address), @@ -222,8 +222,8 @@ class BitcoinCash { * // 1Ly4gqPddveYHMNkfjoXHanVszXpD3duKg */ // encode base58Check - encodeBase58Check(hex) { - return bs58.encode(Buffer.from(hex, "hex")) + encodeBase58Check (hex) { + return bs58.encode(Buffer.from(hex, 'hex')) } /** @@ -260,8 +260,8 @@ class BitcoinCash { * // 00db04c2e6f104997cb04c956bf25da6078e559d303127f08b */ // decode base58Check - decodeBase58Check(address) { - return bs58.decode(address).toString("hex") + decodeBase58Check (address) { + return bs58.decode(address).toString('hex') } /** @@ -298,7 +298,7 @@ class BitcoinCash { * // bitcoincash:qzw6tfrh8p0jh834uf9rhg77pjg5rgnt3qw0e54u03?amount=42&label=no%20prefix */ // encode bip21 url - encodeBIP21(address, options, regtest = false) { + encodeBIP21 (address, options, regtest = false) { return bip21.encode( this._address.toCashAddress(address, true, regtest), options @@ -335,7 +335,7 @@ class BitcoinCash { * // { address: 'qzw6tfrh8p0jh834uf9rhg77pjg5rgnt3qw0e54u03', options: { amount: 42, label: 'no prefix' } } */ // decode bip21 url - decodeBIP21(url) { + decodeBIP21 (url) { return bip21.decode(url) } @@ -405,19 +405,19 @@ class BitcoinCash { * bchjs.BitcoinCash.getByteCount(inputs, outputs) * // 1780 */ - getByteCount(inputs, outputs) { + getByteCount (inputs, outputs) { // from https://github.com/bitcoinjs/bitcoinjs-lib/issues/921#issuecomment-354394004 let totalWeight = 0 let hasWitness = false // assumes compressed pubkeys in all cases. const types = { inputs: { - "MULTISIG-P2SH": 49 * 4, - "MULTISIG-P2WSH": 6 + 41 * 4, - "MULTISIG-P2SH-P2WSH": 6 + 76 * 4, + 'MULTISIG-P2SH': 49 * 4, + 'MULTISIG-P2WSH': 6 + 41 * 4, + 'MULTISIG-P2SH-P2WSH': 6 + 76 * 4, P2PKH: 148 * 4, P2WPKH: 108 + 41 * 4, - "P2SH-P2WPKH": 108 + 64 * 4 + 'P2SH-P2WPKH': 108 + 64 * 4 }, outputs: { P2SH: 32 * 4, @@ -427,26 +427,26 @@ class BitcoinCash { } } - Object.keys(inputs).forEach(function(key) { - if (key.slice(0, 8) === "MULTISIG") { + Object.keys(inputs).forEach(function (key) { + if (key.slice(0, 8) === 'MULTISIG') { // ex. "MULTISIG-P2SH:2-3" would mean 2 of 3 P2SH MULTISIG - const keyParts = key.split(":") + const keyParts = key.split(':') if (keyParts.length !== 2) throw new Error(`invalid input: ${key}`) const newKey = keyParts[0] - const mAndN = keyParts[1].split("-").map(function(item) { + const mAndN = keyParts[1].split('-').map(function (item) { return parseInt(item) }) totalWeight += types.inputs[newKey] * inputs[key] - const multiplyer = newKey === "MULTISIG-P2SH" ? 4 : 1 + const multiplyer = newKey === 'MULTISIG-P2SH' ? 4 : 1 totalWeight += (73 * mAndN[0] + 34 * mAndN[1]) * multiplyer } else { totalWeight += types.inputs[key] * inputs[key] } - if (key.indexOf("W") >= 0) hasWitness = true + if (key.indexOf('W') >= 0) hasWitness = true }) - Object.keys(outputs).forEach(function(key) { + Object.keys(outputs).forEach(function (key) { totalWeight += types.outputs[key] * outputs[key] }) @@ -479,7 +479,7 @@ class BitcoinCash { * ) * // 6PYUAPLwLSEjWSAfoe9NTSPkMZXnJA8j8EFJtKaeSnP18RCouutBrS2735 */ - encryptBIP38(privKeyWIF, passphrase) { + encryptBIP38 (privKeyWIF, passphrase) { const decoded = wif.decode(privKeyWIF) return bip38.encrypt(decoded.privateKey, decoded.compressed, passphrase) @@ -509,10 +509,10 @@ class BitcoinCash { * ) * // cSx7KzdH9EcvDEireu2WYpGnXdFYpta7sJUNt5kVCJgA7kcAU8Gm */ - decryptBIP38(encryptedKey, passphrase, network = "mainnet") { + decryptBIP38 (encryptedKey, passphrase, network = 'mainnet') { const decryptedKey = bip38.decrypt(encryptedKey, passphrase) let prefix - if (network === "testnet") prefix = 0xef + if (network === 'testnet') prefix = 0xef else prefix = 0x80 return wif.encode(prefix, decryptedKey.privateKey, decryptedKey.compressed) diff --git a/src/blockchain.js b/src/blockchain.js index f76e3fb..6677797 100644 --- a/src/blockchain.js +++ b/src/blockchain.js @@ -3,12 +3,12 @@ - Add blockhash functionality back into getTxOutProof */ -const axios = require("axios") +const axios = require('axios') let _this class Blockchain { - constructor(config) { + constructor (config) { this.restURL = config.restURL this.apiToken = config.apiToken this.authToken = config.authToken @@ -50,7 +50,7 @@ class Blockchain { * })() * // 241decef88889efac8e6ce428a8ac696fdde5972eceed97e1fb58d6106af31d5 */ - async getBestBlockHash() { + async getBestBlockHash () { try { const response = await axios.get( `${this.restURL}blockchain/getBestBlockHash`, @@ -98,7 +98,7 @@ class Blockchain { * // previousblockhash: '0000000008e647742775a230787d66fdf92c46a48c896bfbc85cdc8acc67e87d', * // nextblockhash: '00000000a2887344f8db859e372e7e4bc26b23b9de340f725afbf2edb265b4c6' } */ - async getBlock(blockhash, verbose = true) { + async getBlock (blockhash, verbose = true) { try { const response = await axios.get( `${this.restURL}blockchain/getBlock/${blockhash}?verbose=${verbose}`, @@ -148,7 +148,7 @@ class Blockchain { * // timeout: 1493596800, * // since: 419328 } } } */ - async getBlockchainInfo() { + async getBlockchainInfo () { try { const response = await axios.get( `${this.restURL}blockchain/getBlockchainInfo`, @@ -179,7 +179,7 @@ class Blockchain { * })() * // 529235 */ - async getBlockCount() { + async getBlockCount () { try { const response = await axios.get( `${this.restURL}blockchain/getBlockCount`, @@ -210,8 +210,8 @@ class Blockchain { * })() * // [ '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f' ] */ - async getBlockHash(height = 1) { - if (typeof height !== "string") height = JSON.stringify(height) + async getBlockHash (height = 1) { + if (typeof height !== 'string') height = JSON.stringify(height) try { const response = await axios.get( @@ -257,10 +257,10 @@ class Blockchain { * // previousblockhash: '0000000008e647742775a230787d66fdf92c46a48c896bfbc85cdc8acc67e87d', * // nextblockhash: '00000000a2887344f8db859e372e7e4bc26b23b9de340f725afbf2edb265b4c6' }] */ - async getBlockHeader(hash, verbose = true) { + async getBlockHeader (hash, verbose = true) { try { // Handle single hash. - if (typeof hash === "string") { + if (typeof hash === 'string') { const response = await axios.get( `${this.restURL}blockchain/getBlockHeader/${hash}?verbose=${verbose}`, _this.axiosOptions @@ -283,7 +283,7 @@ class Blockchain { return response.data } - throw new Error(`Input hash must be a string or array of strings.`) + throw new Error('Input hash must be a string or array of strings.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error @@ -320,7 +320,7 @@ class Blockchain { * // branchlen: 1, * // status: 'valid-headers' } ] */ - async getChainTips() { + async getChainTips () { try { const response = await axios.get( `${this.restURL}blockchain/getChainTips`, @@ -352,7 +352,7 @@ class Blockchain { * * // 702784497476.8376 */ - async getDifficulty() { + async getDifficulty () { try { const response = await axios.get( `${this.restURL}blockchain/getDifficulty`, @@ -366,8 +366,8 @@ class Blockchain { } // getMempoolAncestors - async getMempoolAncestors(txid, verbose = false) { - if (typeof txid !== "string") txid = JSON.stringify(txid) + async getMempoolAncestors (txid, verbose = false) { + if (typeof txid !== 'string') txid = JSON.stringify(txid) try { const response = await axios.get( @@ -381,8 +381,8 @@ class Blockchain { } } - async getMempoolDescendants(txid, verbose = false) { - if (typeof txid !== "string") txid = JSON.stringify(txid) + async getMempoolDescendants (txid, verbose = false) { + if (typeof txid !== 'string') txid = JSON.stringify(txid) try { const response = await axios.get( @@ -477,11 +477,11 @@ class Blockchain { * // } * // ] */ - async getMempoolEntry(txid) { - //if (typeof txid !== "string") txid = JSON.stringify(txid) + async getMempoolEntry (txid) { + // if (typeof txid !== "string") txid = JSON.stringify(txid) try { - if (typeof txid === "string") { + if (typeof txid === 'string') { const response = await axios.get( `${this.restURL}blockchain/getMempoolEntry/${txid}`, _this.axiosOptions @@ -501,7 +501,7 @@ class Blockchain { return response.data } - throw new Error(`Input must be a string or array of strings.`) + throw new Error('Input must be a string or array of strings.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error @@ -531,7 +531,7 @@ class Blockchain { * // maxmempool: 300000000, * // mempoolminfee: 0 } */ - async getMempoolInfo() { + async getMempoolInfo () { try { const response = await axios.get( `${this.restURL}blockchain/getMempoolInfo`, @@ -578,7 +578,7 @@ class Blockchain { * // depends: * // [ 'e25682caafc7000645d59f4c11d8d594b2943979b9d8fafb9f946e2b35c21b7e' ] },] */ - async getRawMempool(verbose = false) { + async getRawMempool (verbose = false) { try { const response = await axios.get( `${this.restURL}blockchain/getRawMempool?vebose=${verbose}`, @@ -610,20 +610,22 @@ class Blockchain { * * // null */ - async getTxOut(txid, n, include_mempool = true) { + async getTxOut (txid, n, includeMempool = true) { try { // Input validation - if (typeof txid !== "string" || txid.length !== 64) - throw new Error(`txid needs to be a proper transaction ID`) + if (typeof txid !== 'string' || txid.length !== 64) { + throw new Error('txid needs to be a proper transaction ID') + } - if (isNaN(n)) throw new Error(`n must be an integer`) + if (isNaN(n)) throw new Error('n must be an integer') - if (typeof include_mempool !== "boolean") - throw new Error(`include_mempool input must be of type boolean`) + if (typeof includeMempool !== 'boolean') { + throw new Error('includeMempool input must be of type boolean') + } // Send the request to the REST API. // const response = await axios.get( - // `${this.restURL}blockchain/getTxOut/${txid}/${n}?include_mempool=${include_mempool}`, + // `${this.restURL}blockchain/getTxOut/${txid}/${n}?includeMempool=${includeMempool}`, // _this.axiosOptions // ) const response = await axios.post( @@ -631,7 +633,7 @@ class Blockchain { { txid: txid, vout: n, - mempool: include_mempool + mempool: includeMempool }, _this.axiosOptions ) @@ -679,12 +681,12 @@ class Blockchain { * // "010000007de867cc8adc5cc8fb6b898ca4462cf9fd667d7830a275277447e60800000000338f121232e169d3100edd82004dc2a1f0e1f030c6c488fa61eafa930b0528fe021f7449ffff001d36b4af9a0100000001338f121232e169d3100edd82004dc2a1f0e1f030c6c488fa61eafa930b0528fe0101" * // ] */ - async getTxOutProof(txids) { + async getTxOutProof (txids) { try { // Single txid. - if (typeof txids === "string") { + if (typeof txids === 'string') { const path = `${this.restURL}blockchain/getTxOutProof/${txids}` - //if (blockhash) path = `${path}?blockhash=${blockhash}` + // if (blockhash) path = `${path}?blockhash=${blockhash}` const response = await axios.get(path, _this.axiosOptions) return response.data @@ -703,14 +705,14 @@ class Blockchain { return response.data } - throw new Error(`Input must be a string or array of strings.`) + throw new Error('Input must be a string or array of strings.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error } } - async preciousBlock(blockhash) { + async preciousBlock (blockhash) { try { const response = await axios.get( `${this.restURL}blockchain/preciousBlock/${blockhash}`, @@ -723,7 +725,7 @@ class Blockchain { } } - async pruneBlockchain(height) { + async pruneBlockchain (height) { try { const response = await axios.post( `${this.restURL}blockchain/pruneBlockchain/${height}`, @@ -736,7 +738,7 @@ class Blockchain { } } - async verifyChain(checklevel = 3, nblocks = 6) { + async verifyChain (checklevel = 3, nblocks = 6) { try { const response = await axios.get( `${this.restURL}blockchain/verifyChain?checklevel=${checklevel}&nblocks=${nblocks}`, @@ -786,10 +788,10 @@ class Blockchain { * // "03f69502ca32e7927fd4f38c1d3f950bff650c1eea3d09a70e9df5a9d7f989f7" * // ] */ - async verifyTxOutProof(proof) { + async verifyTxOutProof (proof) { try { // Single block - if (typeof proof === "string") { + if (typeof proof === 'string') { const response = await axios.get( `${this.restURL}blockchain/verifyTxOutProof/${proof}`, _this.axiosOptions @@ -810,7 +812,7 @@ class Blockchain { return response.data } - throw new Error(`Input must be a string or array of strings.`) + throw new Error('Input must be a string or array of strings.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error diff --git a/src/control.js b/src/control.js index e11cab6..8904270 100644 --- a/src/control.js +++ b/src/control.js @@ -2,12 +2,12 @@ API endpoints for basic control and information of the full node. */ -const axios = require("axios") +const axios = require('axios') let _this // Global reference to the instance of this class. class Control { - constructor(config) { + constructor (config) { this.restURL = config.restURL this.apiToken = config.apiToken this.authToken = config.authToken @@ -77,7 +77,7 @@ class Control { * warnings: * 'Warning: Unknown block versions being mined! It\'s possible unknown rules are in effect' }} */ - async getNetworkInfo() { + async getNetworkInfo () { try { const response = await axios.get( `${this.restURL}control/getNetworkInfo`, @@ -90,7 +90,7 @@ class Control { } } - async getMemoryInfo() { + async getMemoryInfo () { try { const response = await axios.get( `${this.restURL}control/getMemoryInfo`, diff --git a/src/crypto.js b/src/crypto.js index 24371be..46dc2d5 100644 --- a/src/crypto.js +++ b/src/crypto.js @@ -1,5 +1,5 @@ -const randomBytes = require("randombytes") -const Bitcoin = require("@psf/bitcoincashjs-lib") +const randomBytes = require('randombytes') +const Bitcoin = require('@psf/bitcoincashjs-lib') class Crypto { /** @@ -26,7 +26,7 @@ class Crypto { * * */ // Translate address from any address format into a specific format. - static sha256(buffer) { + static sha256 (buffer) { return Bitcoin.crypto.sha256(buffer) } @@ -52,7 +52,7 @@ class Crypto { * bchjs.Crypto.ripemd160(buffer) * // * */ - static ripemd160(buffer) { + static ripemd160 (buffer) { return Bitcoin.crypto.ripemd160(buffer) } @@ -78,7 +78,7 @@ class Crypto { * bchjs.Crypto.hash256(buffer) * // * */ - static hash256(buffer) { + static hash256 (buffer) { return Bitcoin.crypto.hash256(buffer) } @@ -104,7 +104,7 @@ class Crypto { * bchjs.Crypto.hash160(buffer) * * */ - static hash160(buffer) { + static hash160 (buffer) { return Bitcoin.crypto.hash160(buffer) } @@ -130,7 +130,7 @@ class Crypto { * bchjs.Crypto.randomBytes(32) * // * */ - static randomBytes(size = 16) { + static randomBytes (size = 16) { return randomBytes(size) } } diff --git a/src/ecpair.js b/src/ecpair.js index d5c069d..ce4fc42 100644 --- a/src/ecpair.js +++ b/src/ecpair.js @@ -1,10 +1,11 @@ -const Bitcoin = require("@psf/bitcoincashjs-lib") -const coininfo = require("@psf/coininfo") +const Bitcoin = require('@psf/bitcoincashjs-lib') +const coininfo = require('@psf/coininfo') class ECPair { - static setAddress(address) { + static setAddress (address) { ECPair._address = address } + /** * @api Ecpair.fromWIF() fromWIF() * @apiName fromWIF @@ -20,20 +21,19 @@ class ECPair { * let wif = 'cSNLj6xeg3Yg2rfcgKoWNx4MiAgn9ugCUUro37UDEhn6CzeYqjWW' * bchjs.ECPair.fromWIF(wif) * */ - static fromWIF(privateKeyWIF) { + static fromWIF (privateKeyWIF) { let network - if (privateKeyWIF[0] === "L" || privateKeyWIF[0] === "K") - network = "mainnet" - else if (privateKeyWIF[0] === "c") network = "testnet" + if (privateKeyWIF[0] === 'L' || privateKeyWIF[0] === 'K') { network = 'mainnet' } else if (privateKeyWIF[0] === 'c') network = 'testnet' let bitcoincash - if (network === "mainnet") bitcoincash = coininfo.bitcoincash.main + if (network === 'mainnet') bitcoincash = coininfo.bitcoincash.main else bitcoincash = coininfo.bitcoincash.test const bitcoincashBitcoinJSLib = bitcoincash.toBitcoinJS() return Bitcoin.ECPair.fromWIF(privateKeyWIF, bitcoincashBitcoinJSLib) } + /** * @api Ecpair.toWIF() toWIF() * @apiName toWIF @@ -57,17 +57,18 @@ class ECPair { * bchjs.ECPair.toWIF(ecpair); * // cT3tJP7BnjFJSAHbooMXrY8E9t2AFj37amSBAYFMeHfqPqPgD4ZA * */ - static toWIF(ecpair) { + static toWIF (ecpair) { return ecpair.toWIF() } - static sign(ecpair, buffer) { + static sign (ecpair, buffer) { return ecpair.sign(buffer) } - static verify(ecpair, buffer, signature) { + static verify (ecpair, buffer, signature) { return ecpair.verify(buffer, signature) } + /** * @api Ecpair.fromPublicKey() fromPublicKey() * @apiName fromPublicKey @@ -83,9 +84,10 @@ class ECPair { * let pubkeyBuffer = Buffer.from("024a6d0737a23c472d078d78c1cbc3c2bbf8767b48e72684ff03a911b463da7fa6", 'hex'); * bchjs.ECPair.fromPublicKey(pubkeyBuffer); * */ - static fromPublicKey(pubkeyBuffer) { + static fromPublicKey (pubkeyBuffer) { return Bitcoin.ECPair.fromPublicKeyBuffer(pubkeyBuffer) } + /** * @api Ecpair.toPublicKey() toPublicKey() * @apiName toPublicKey @@ -105,9 +107,10 @@ class ECPair { * bchjs.ECPair.toPublicKey(ecpair); * // * */ - static toPublicKey(ecpair) { + static toPublicKey (ecpair) { return ecpair.getPublicKeyBuffer() } + /** * @api Ecpair.toLegacyAddress() toLegacyAddress() * @apiName toLegacyAddress @@ -131,9 +134,10 @@ class ECPair { * bchjs.ECPair.toLegacyAddress(ecpair); * // mg4PygFcXoyNJGJkM2Dcpe25av9wXzz1My * */ - static toLegacyAddress(ecpair) { + static toLegacyAddress (ecpair) { return ecpair.getAddress() } + /** * @api Ecpair.toCashAddress() toCashAddress() * @apiName toCashAddress @@ -157,7 +161,7 @@ class ECPair { * bchjs.ECPair.toCashAddress(ecpair); * // bchtest:qqzly4vrcxcjw62u4yq4nv86ltk2mc9v0yvq8mvj6m * */ - static toCashAddress(ecpair, regtest = false) { + static toCashAddress (ecpair, regtest = false) { return ECPair._address.toCashAddress(ecpair.getAddress(), true, regtest) } } diff --git a/src/electrumx.js b/src/electrumx.js index 2d38a88..45013cd 100644 --- a/src/electrumx.js +++ b/src/electrumx.js @@ -3,12 +3,12 @@ by FullStack.cash */ -const axios = require("axios") +const axios = require('axios') let _this class ElectrumX { - constructor(config) { + constructor (config) { this.restURL = config.restURL this.apiToken = config.apiToken this.authToken = config.authToken @@ -97,10 +97,10 @@ class ElectrumX { * } * */ - async utxo(address) { + async utxo (address) { try { // Handle single address. - if (typeof address === "string") { + if (typeof address === 'string') { const response = await axios.get( `${this.restURL}electrumx/utxos/${address}`, _this.axiosOptions @@ -120,7 +120,7 @@ class ElectrumX { return response.data } - throw new Error(`Input address must be a string or array of strings.`) + throw new Error('Input address must be a string or array of strings.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error @@ -181,10 +181,10 @@ class ElectrumX { * } * */ - async balance(address) { + async balance (address) { try { // Handle single address. - if (typeof address === "string") { + if (typeof address === 'string') { const response = await axios.get( `${this.restURL}electrumx/balance/${address}`, _this.axiosOptions @@ -204,7 +204,7 @@ class ElectrumX { return response.data } - throw new Error(`Input address must be a string or array of strings.`) + throw new Error('Input address must be a string or array of strings.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error @@ -279,10 +279,10 @@ class ElectrumX { * } * */ - async transactions(address) { + async transactions (address) { try { // Handle single address. - if (typeof address === "string") { + if (typeof address === 'string') { const response = await axios.get( `${this.restURL}electrumx/transactions/${address}`, _this.axiosOptions @@ -302,7 +302,7 @@ class ElectrumX { return response.data } - throw new Error(`Input address must be a string or array of strings.`) + throw new Error('Input address must be a string or array of strings.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error @@ -371,10 +371,10 @@ class ElectrumX { * } * */ - async unconfirmed(address) { + async unconfirmed (address) { try { // Handle single address. - if (typeof address === "string") { + if (typeof address === 'string') { const response = await axios.get( `${this.restURL}electrumx/unconfirmed/${address}`, _this.axiosOptions @@ -394,7 +394,7 @@ class ElectrumX { return response.data } - throw new Error(`Input address must be a string or array of strings.`) + throw new Error('Input address must be a string or array of strings.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error @@ -442,7 +442,7 @@ class ElectrumX { * } * */ - async blockHeader(height, count = 1) { + async blockHeader (height, count = 1) { try { const response = await axios.get( `${this.restURL}electrumx/block/headers/${height}?count=${count}`, @@ -452,9 +452,7 @@ class ElectrumX { } catch (error) { // console.log("error: ", error) if (error.response && error.response.data) { - if (error.response && error.response.data) - throw new Error(error.response.data.error) - else throw error.response.data + if (error.response && error.response.data) { throw new Error(error.response.data.error) } else throw error.response.data } else { throw error } @@ -531,10 +529,10 @@ class ElectrumX { * ] * } */ - async txData(txid) { + async txData (txid) { try { // Handle single transaction. - if (typeof txid === "string") { + if (typeof txid === 'string') { const response = await axios.get( `${this.restURL}electrumx/tx/data/${txid}`, _this.axiosOptions @@ -552,7 +550,7 @@ class ElectrumX { return response.data } - throw new Error(`Input txId must be a string or array of strings.`) + throw new Error('Input txId must be a string or array of strings.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error @@ -580,9 +578,9 @@ class ElectrumX { * "txid": "..." * } */ - async broadcast(txHex) { + async broadcast (txHex) { try { - if (typeof txHex === "string") { + if (typeof txHex === 'string') { const response = await axios.post( `${this.restURL}electrumx/tx/broadcast`, { txHex }, @@ -592,7 +590,7 @@ class ElectrumX { return response.data } - throw new Error(`Input txHex must be a string.`) + throw new Error('Input txHex must be a string.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error diff --git a/src/encryption.js b/src/encryption.js index f035380..ce0ae37 100644 --- a/src/encryption.js +++ b/src/encryption.js @@ -2,12 +2,12 @@ This library contains useful functions that deal with encryption. */ -const axios = require("axios") +const axios = require('axios') let _this class Encryption { - constructor(config) { + constructor (config) { this.restURL = config.restURL this.apiToken = config.apiToken this.axios = axios @@ -33,10 +33,9 @@ class Encryption { } // Search the blockchain for a public key associated with a BCH address. - async getPubKey(addr) { + async getPubKey (addr) { try { - if (!addr || typeof addr !== "string") - throw new Error(`Input must be a valid Bitcoin Cash address.`) + if (!addr || typeof addr !== 'string') { throw new Error('Input must be a valid Bitcoin Cash address.') } const response = await _this.axios.get( `${this.restURL}encryption/publickey/${addr}`, diff --git a/src/generating.js b/src/generating.js index e8e6230..df0efb5 100644 --- a/src/generating.js +++ b/src/generating.js @@ -1,9 +1,9 @@ -const axios = require("axios") +const axios = require('axios') let _this class Generating { - constructor(config) { + constructor (config) { this.restURL = config.restURL this.apiToken = config.apiToken this.authToken = config.authToken @@ -27,7 +27,7 @@ class Generating { _this = this } - async generateToAddress(blocks, address, maxtries = 1000000) { + async generateToAddress (blocks, address, maxtries = 1000000) { try { const response = await axios.post( `${this.restURL}generating/generateToAddress/${blocks}/${address}?maxtries=${maxtries}`, diff --git a/src/hdnode.js b/src/hdnode.js index dfc5b96..797e28f 100644 --- a/src/hdnode.js +++ b/src/hdnode.js @@ -1,10 +1,10 @@ -const Bitcoin = require("@psf/bitcoincashjs-lib") -const coininfo = require("@psf/coininfo") -const bip32utils = require("@psf/bip32-utils") -const bchaddrjs = require("bchaddrjs-slp") +const Bitcoin = require('@psf/bitcoincashjs-lib') +const coininfo = require('@psf/coininfo') +const bip32utils = require('@psf/bip32-utils') +const bchaddrjs = require('bchaddrjs-slp') class HDNode { - constructor(address) { + constructor (address) { this._address = address } @@ -32,11 +32,9 @@ class HDNode { * // create HDNode from seed buffer * bchjs.HDNode.fromSeed(seedBuffer); */ - fromSeed(rootSeedBuffer, network = "mainnet") { + fromSeed (rootSeedBuffer, network = 'mainnet') { let bitcoincash - if (network === "bitcoincash" || network === "mainnet") - bitcoincash = coininfo.bitcoincash.main - else bitcoincash = coininfo.bitcoincash.test + if (network === 'bitcoincash' || network === 'mainnet') { bitcoincash = coininfo.bitcoincash.main } else bitcoincash = coininfo.bitcoincash.test const bitcoincashBitcoinJSLib = bitcoincash.toBitcoinJS() return Bitcoin.HDNode.fromSeedBuffer( @@ -75,7 +73,7 @@ class HDNode { * bchjs.HDNode.toLegacyAddress(hdNode); * // 14mVsq3H5Ep2Jb6AqoKsmY1BFHKCBGPDLi */ - toLegacyAddress(hdNode) { + toLegacyAddress (hdNode) { return hdNode.getAddress() } @@ -109,7 +107,7 @@ class HDNode { * bchjs.HDNode.toCashAddress(hdNode); * // bitcoincash:qq549jxsjv66kw0smdju4es2axnk7hhe9cquhjg4gt */ - toCashAddress(hdNode, regtest = false) { + toCashAddress (hdNode, regtest = false) { return this._address.toCashAddress(hdNode.getAddress(), true, regtest) } @@ -142,7 +140,7 @@ class HDNode { * bchjs.SLP.HDNode.toSLPAddress(hdNode); * // simpleledger:qqxh2z2z397m4c6u9s5x6wjtku742q8rpvm6al2nrf */ - toSLPAddress(hdNode) { + toSLPAddress (hdNode) { const cashAddr = this.toCashAddress(hdNode) return bchaddrjs.toSlpAddress(cashAddr) } @@ -177,7 +175,7 @@ class HDNode { * bchjs.HDNode.toWIF(hdNode); * // KwobPFhv3AuXc3ps6YtWfMVRpLBDBA7jnJddurfELTyTNcFhZYpJ */ - toWIF(hdNode) { + toWIF (hdNode) { return hdNode.keyPair.toWIF() } @@ -211,7 +209,7 @@ class HDNode { * bchjs.HDNode.toXPub(hdNode); * // xpub661MyMwAqRbcFuMLeHkSbTNwNHG9MQyrAZqV1Q4MEAsmj9MYa5sxg8WC2LKqW6EHviHVucBjWi1n38juZpDDeX3U6YrsMeACdcNSTHkM8BQ */ - toXPub(hdNode) { + toXPub (hdNode) { return hdNode.neutered().toBase58() } @@ -245,7 +243,7 @@ class HDNode { * bchjs.HDNode.toXPriv(hdNode); * // xprv9s21ZrQH143K2b5GPP6zHz22E6LeCgQXJtwNbC3MA3Kz7Se7tveKo96EhqwFtSkYWkyenVcMqM7uq35PcUNG8cUdpsJEgwKG3dvfP7TmL3v */ - toXPriv(hdNode) { + toXPriv (hdNode) { return hdNode.toBase58() } @@ -277,7 +275,7 @@ class HDNode { * // create public key buffer from HDNode * bchjs.HDNode.toKeyPair(hdNode); */ - toKeyPair(hdNode) { + toKeyPair (hdNode) { return hdNode.keyPair } @@ -311,7 +309,7 @@ class HDNode { * bchjs.HDNode.toPublicKey(hdNode); * // */ - toPublicKey(hdNode) { + toPublicKey (hdNode) { return hdNode.getPublicKeyBuffer() } @@ -329,10 +327,10 @@ class HDNode { * // testnet xpriv * bchjs.HDNode.fromXPriv('tprv8gQ3zr1F5pRHMebqqhorrorYNvUG3XkcZjSWVs2cEtRwwJy1TRhgRx4XcF8dYHM2eyTbTCcdKYNhqgyBQphxwRoVyVKr9zuyoA8WxNDRvom'); */ - fromXPriv(xpriv) { + fromXPriv (xpriv) { let bitcoincash - if (xpriv[0] === "x") bitcoincash = coininfo.bitcoincash.main - else if (xpriv[0] === "t") bitcoincash = coininfo.bitcoincash.test + if (xpriv[0] === 'x') bitcoincash = coininfo.bitcoincash.main + else if (xpriv[0] === 't') bitcoincash = coininfo.bitcoincash.test const bitcoincashBitcoinJSLib = bitcoincash.toBitcoinJS() return Bitcoin.HDNode.fromBase58(xpriv, bitcoincashBitcoinJSLib) @@ -352,10 +350,10 @@ class HDNode { * // testnet xpub * bchjs.HDNode.fromXPub('tpubDD669G3VEC6xF7ddjMUTGDWewwzCCrwX933HnP4ufAELmoDn5pXGcSgPnLodjFvWQwRXkG94f77BatEDA8dfQ99yy97kRYynUpNLENEqTBo'); */ - fromXPub(xpub) { + fromXPub (xpub) { let bitcoincash - if (xpub[0] === "x") bitcoincash = coininfo.bitcoincash.main - else if (xpub[0] === "t") bitcoincash = coininfo.bitcoincash.test + if (xpub[0] === 'x') bitcoincash = coininfo.bitcoincash.main + else if (xpub[0] === 't') bitcoincash = coininfo.bitcoincash.test const bitcoincashBitcoinJSLib = bitcoincash.toBitcoinJS() return Bitcoin.HDNode.fromBase58(xpub, bitcoincashBitcoinJSLib) @@ -378,7 +376,7 @@ class HDNode { * // derive hardened child HDNode * bchjs.HDNode.derivePath(hdNode, "m/44'/145'/0'"); */ - derivePath(hdnode, path) { + derivePath (hdnode, path) { return hdnode.derivePath(path) } @@ -399,7 +397,7 @@ class HDNode { * // derive unhardened child HDNode * bchjs.HDNode.derive(hdNode, 0); */ - derive(hdnode, path) { + derive (hdnode, path) { return hdnode.derive(path) } @@ -420,7 +418,7 @@ class HDNode { * // derive hardened child HDNode * bchjs.HDNode.deriveHardened(hdNode, 0); */ - deriveHardened(hdnode, path) { + deriveHardened (hdnode, path) { return hdnode.deriveHardened(path) } @@ -450,7 +448,7 @@ class HDNode { * // sign * bchjs.HDNode.sign(hdnode, buf); */ - sign(hdnode, buffer) { + sign (hdnode, buffer) { return hdnode.sign(buffer) } @@ -494,7 +492,7 @@ class HDNode { * bchjs.HDNode.verify(hdnode2, buf, signature); * // false */ - verify(hdnode, buffer, signature) { + verify (hdnode, buffer, signature) { return hdnode.verify(buffer, signature) } @@ -530,7 +528,7 @@ class HDNode { * bchjs.HDNode.isPublic(node); * // false */ - isPublic(hdnode) { + isPublic (hdnode) { return hdnode.isNeutered() } @@ -566,7 +564,7 @@ class HDNode { * bchjs.HDNode.isPrivate(node); * // true */ - isPrivate(hdnode) { + isPrivate (hdnode) { return !hdnode.isNeutered() } @@ -598,11 +596,11 @@ class HDNode { * bchjs.Crypto.hash160(publicKeyBuffer); * // */ - toIdentifier(hdnode) { + toIdentifier (hdnode) { return hdnode.getIdentifier() } - fromBase58(base58, network) { + fromBase58 (base58, network) { return Bitcoin.HDNode.fromBase58(base58, network) } @@ -625,14 +623,14 @@ class HDNode { * // create account * let account = bchjs.HDNode.createAccount([childNode]); */ - createAccount(hdNodes) { + createAccount (hdNodes) { const arr = hdNodes.map( (item, index) => new bip32utils.Chain(item.neutered()) ) return new bip32utils.Account(arr) } - createChain(hdNode) { + createChain (hdNode) { return new bip32utils.Chain(hdNode) } } diff --git a/src/ipfs.js b/src/ipfs.js index 623aa13..eb85080 100644 --- a/src/ipfs.js +++ b/src/ipfs.js @@ -3,19 +3,19 @@ and downloading data from the IPFS network. */ -const axios = require("axios") -const Uppy = require("@uppy/core") -const Tus = require("@uppy/tus") -const fs = require("fs") +const axios = require('axios') +const Uppy = require('@uppy/core') +const Tus = require('@uppy/tus') +const fs = require('fs') let _this class IPFS { - constructor(config) { + constructor (config) { this.IPFS_API = process.env.IPFS_API ? process.env.IPFS_API - : // : `http://localhost:5001` - `https://ipfs-api.fullstack.cash` + : 'https://ipfs-api.fullstack.cash' + // : `http://localhost:5001` // Default options when calling axios. this.axiosOptions = { @@ -35,16 +35,16 @@ class IPFS { } // Initializes Uppy, which is used for file uploads. - initUppy() { + initUppy () { const uppy = Uppy({ allowMultipleUploads: false, - meta: { test: "avatar" }, + meta: { test: 'avatar' }, debug: false, restrictions: { maxFileSize: null, maxNumberOfFiles: 1, minNumberOfFiles: 1, - allowedFileTypes: null //type of files allowed to load + allowedFileTypes: null // type of files allowed to load } }) uppy.use(Tus, { endpoint: `${_this.IPFS_API}/uppy-files` }) @@ -90,11 +90,12 @@ class IPFS { * "__v": 0 * } */ - async createFileModelServer(path) { + async createFileModelServer (path) { try { // Ensure the file exists. - if (!_this.fs.existsSync(path)) + if (!_this.fs.existsSync(path)) { throw new Error(`Could not find this file: ${path}`) + } // Read in the file. const fileBuf = _this.fs.readFileSync(path) @@ -103,11 +104,11 @@ class IPFS { // console.log(`Buffer length: ${fileBuf.length}`) // Get the file name from the path. - const splitPath = path.split("/") + const splitPath = path.split('/') const fileName = splitPath[splitPath.length - 1] // Get the file extension. - const splitExt = fileName.split(".") + const splitExt = fileName.split('.') const fileExt = splitExt[splitExt.length - 1] const fileObj = { @@ -125,7 +126,7 @@ class IPFS { return fileData.data } catch (err) { - console.error(`Error in createFileModel()`) + console.error('Error in createFileModel()') throw err } } @@ -157,15 +158,16 @@ class IPFS { * "fileExtension": "js" * } */ - async uploadFileServer(path, modelId) { + async uploadFileServer (path, modelId) { try { // Ensure the file exists. - if (!_this.fs.existsSync(path)) + if (!_this.fs.existsSync(path)) { throw new Error(`Could not find this file: ${path}`) + } if (!modelId) { throw new Error( - `Must include a file model ID in order to upload a file.` + 'Must include a file model ID in order to upload a file.' ) } @@ -173,14 +175,14 @@ class IPFS { const fileBuf = _this.fs.readFileSync(path) // Get the file name from the path. - const splitPath = path.split("/") + const splitPath = path.split('/') const fileName = splitPath[splitPath.length - 1] // Prepare the upload object. Get a file ID from Uppy. const id = _this.uppy.addFile({ name: fileName, data: fileBuf, - source: "Local", + source: 'Local', isRemote: false }) // console.log(`id: ${JSON.stringify(id, null, 2)}`) @@ -191,8 +193,9 @@ class IPFS { // Upload the file to the server. const upData = await _this.uppy.upload() - if (upData.failed.length) - throw new Error("The file could not be uploaded") + if (upData.failed.length) { + throw new Error('The file could not be uploaded') + } if (upData.successful.length) { delete upData.successful[0].data @@ -213,7 +216,7 @@ class IPFS { return false } catch (err) { - console.error(`Error in bch-js/src/ipfs.js/upload(): `) + console.error('Error in bch-js/src/ipfs.js/upload(): ') throw err } } @@ -246,9 +249,9 @@ class IPFS { * "fileName": "ipfs-e2e.js" * } */ - async getStatus(modelId) { + async getStatus (modelId) { try { - if (!modelId) throw new Error(`Must include a file model ID.`) + if (!modelId) throw new Error('Must include a file model ID.') const fileData = await _this.axios.get( `${this.IPFS_API}/files/${modelId}` @@ -266,10 +269,11 @@ class IPFS { return fileObj } catch (err) { - console.error(`Error in getStatus()`) + console.error('Error in getStatus()') throw err } } + /** * @api IPFS.createFileModelWeb() createFileModelWeb() * @apiName createFileModelWeb() @@ -311,20 +315,22 @@ class IPFS { * "__v": 0 * } */ - async createFileModelWeb(file) { + async createFileModelWeb (file) { try { - if (!file) throw new Error(`File is required`) + if (!file) throw new Error('File is required') const { name, size } = file - if (!name || typeof name !== "string") - throw new Error(`File should have the property 'name' of string type`) + if (!name || typeof name !== 'string') { + throw new Error("File should have the property 'name' of string type") + } - if (!size || typeof size !== "number") - throw new Error(`File should have the property 'size' of number type`) + if (!size || typeof size !== 'number') { + throw new Error("File should have the property 'size' of number type") + } // Get the file extension. - const splitExt = name.split(".") + const splitExt = name.split('.') const fileExt = splitExt[splitExt.length - 1] const fileObj = { @@ -342,7 +348,7 @@ class IPFS { return fileData.data } catch (err) { - console.error(`Error in createFileModelWeb()`) + console.error('Error in createFileModelWeb()') throw err } } @@ -377,24 +383,27 @@ class IPFS { * "fileExtension": "js" * } */ - async uploadFileWeb(file, modelId) { + async uploadFileWeb (file, modelId) { try { - if (!file) throw new Error(`File is required`) + if (!file) throw new Error('File is required') const { name, type, size } = file - if (!name || typeof name !== "string") - throw new Error(`File should have the property 'name' of string type`) + if (!name || typeof name !== 'string') { + throw new Error("File should have the property 'name' of string type") + } - if (!type || typeof type !== "string") - throw new Error(`File should have the property 'type' of string type`) + if (!type || typeof type !== 'string') { + throw new Error("File should have the property 'type' of string type") + } - if (!size || typeof size !== "number") - throw new Error(`File should have the property 'size' of number type`) + if (!size || typeof size !== 'number') { + throw new Error("File should have the property 'size' of number type") + } if (!modelId) { throw new Error( - `Must include a file model ID in order to upload a file.` + 'Must include a file model ID in order to upload a file.' ) } @@ -402,7 +411,7 @@ class IPFS { const id = _this.uppy.addFile({ name: name, data: file, - source: "Local", + source: 'Local', isRemote: false }) // console.log(`id: ${JSON.stringify(id, null, 2)}`) @@ -413,8 +422,9 @@ class IPFS { // Upload the file to the server. const upData = await _this.uppy.upload() - if (upData.failed.length) - throw new Error("The file could not be uploaded") + if (upData.failed.length) { + throw new Error('The file could not be uploaded') + } if (upData.successful.length) { delete upData.successful[0].data @@ -435,7 +445,7 @@ class IPFS { return false } catch (err) { - console.error(`Error in bch-js/src/ipfs.js/uploadFileWeb(): `) + console.error('Error in bch-js/src/ipfs.js/uploadFileWeb(): ') throw err } } diff --git a/src/mining.js b/src/mining.js index 6890936..8c3e348 100644 --- a/src/mining.js +++ b/src/mining.js @@ -1,9 +1,9 @@ -const axios = require("axios") +const axios = require('axios') let _this class Mining { - constructor(config) { + constructor (config) { this.restURL = config.restURL this.apiToken = config.apiToken this.authToken = config.authToken @@ -27,10 +27,10 @@ class Mining { _this = this } - async getBlockTemplate(template_request) { + async getBlockTemplate (templateRequest) { try { const response = await axios.get( - `${this.restURL}mining/getBlockTemplate/${template_request}`, + `${this.restURL}mining/getBlockTemplate/${templateRequest}`, _this.axiosOptions ) return response.data @@ -40,7 +40,7 @@ class Mining { } } - async getMiningInfo() { + async getMiningInfo () { try { const response = await axios.get( `${this.restURL}mining/getMiningInfo`, @@ -53,7 +53,7 @@ class Mining { } } - async getNetworkHashps(nblocks = 120, height = 1) { + async getNetworkHashps (nblocks = 120, height = 1) { try { const response = await axios.get( `${this.restURL}mining/getNetworkHashps?nblocks=${nblocks}&height=${height}`, @@ -66,7 +66,7 @@ class Mining { } } - async submitBlock(hex, parameters) { + async submitBlock (hex, parameters) { let path = `${this.restURL}mining/submitBlock/${hex}` if (parameters) path = `${path}?parameters=${parameters}` diff --git a/src/mnemonic.js b/src/mnemonic.js index 8184d1c..587c2d1 100644 --- a/src/mnemonic.js +++ b/src/mnemonic.js @@ -1,11 +1,14 @@ -const BIP39 = require("bip39") -const randomBytes = require("randombytes") -const Bitcoin = require("@psf/bitcoincashjs-lib") -const Buffer = require("safe-buffer").Buffer -const wif = require("wif") +/* eslint no-prototype-builtins: "off" */ +/* eslint node/no-callback-literal: "off" */ + +const BIP39 = require('bip39') +const randomBytes = require('randombytes') +const Bitcoin = require('@psf/bitcoincashjs-lib') +const Buffer = require('safe-buffer').Buffer +const wif = require('wif') class Mnemonic { - constructor(address) { + constructor (address) { this._address = address } @@ -45,7 +48,7 @@ class Mnemonic { * bchjs.Mnemonic.generate(256, bitbox.Mnemonic.wordLists().korean) * // 기능 단추 교육 비난 시집 근육 운동 코미디 숟가락 과목 한동안 유적 시리즈 삼월 앞날 유난히 흰색 사실 논문 장사 어른 논문 의논 장차 */ - generate(bits = 128, wordlist) { + generate (bits = 128, wordlist) { return BIP39.generateMnemonic(bits, randomBytes, wordlist) } @@ -95,11 +98,8 @@ class Mnemonic { * // generate 16 bytes of entropy * let entropy = bchjs.Crypto.randomBytes(16); * // - * // turn entropy to 12 japanese word mnemonic - * bchjs.Mnemonic.fromEntropy(entropy.toString('hex'), bchjs.Mnemonic.wordLists().japanese) - * // ぱそこん にあう にんめい きどく ちそう せんきょ かいが きおく いれる いねむり しいく きかんしゃ */ - fromEntropy(bytes, wordlist) { + fromEntropy (bytes, wordlist) { return BIP39.entropyToMnemonic(bytes, wordlist) } @@ -136,8 +136,8 @@ class Mnemonic { * bchjs.Mnemonic.toEntropy(mnemonic) * // */ - toEntropy(mnemonic, wordlist) { - return Buffer.from(BIP39.mnemonicToEntropy(mnemonic, wordlist), "hex") + toEntropy (mnemonic, wordlist) { + return Buffer.from(BIP39.mnemonicToEntropy(mnemonic, wordlist), 'hex') } /** @@ -157,11 +157,11 @@ class Mnemonic { * bchjs.Mnemonic.validate('boil lonely casino manage habit where total glory muffin name limit mansion boil lonely casino manage habit where total glory muffin name limit mansion', bitbox.Mnemonic.wordLists().english) * // Invalid mnemonic */ - validate(mnemonic, wordlist) { + validate (mnemonic, wordlist) { // Preprocess the words - const words = mnemonic.split(" ") + const words = mnemonic.split(' ') // Detect blank phrase - if (words.length === 0) return "Blank mnemonic" + if (words.length === 0) return 'Blank mnemonic' // Check each word for (let i = 0; i < words.length; i++) { @@ -173,11 +173,11 @@ class Mnemonic { } } // Check the words are valid - //const properPhrase = words.join() + // const properPhrase = words.join() const isValid = BIP39.validateMnemonic(mnemonic, wordlist) - if (!isValid) return "Invalid mnemonic" + if (!isValid) return 'Invalid mnemonic' - return "Valid mnemonic" + return 'Valid mnemonic' } /** @@ -203,7 +203,7 @@ class Mnemonic { * await bchjs.Mnemonic.toSeed('frost deliver coin clutch upon round scene wonder various wise luggage country', 'yayayayay'); * // */ - toSeed(mnemonic, password = "") { + toSeed (mnemonic, password = '') { return BIP39.mnemonicToSeed(mnemonic, password) } @@ -229,7 +229,7 @@ class Mnemonic { * // spanish: [] * // } */ - wordLists() { + wordLists () { return BIP39.wordlists } @@ -260,10 +260,10 @@ class Mnemonic { * // { privateKeyWIF: 'L5gB66JqhfouEtZG5aRMQ9JaVS2ggkK3YozGfzZegBupaPXqdfaz', * // address: 'bitcoincash:qphwlpu2wzjxrjts94pn4wh778fwsu2afg2aj5her9' } ] */ - async toKeypairs(mnemonic, numberOfKeypairs = 1, regtest = false) { - const rootSeedBuffer = await this.toSeed(mnemonic, "") + async toKeypairs (mnemonic, numberOfKeypairs = 1, regtest = false) { + const rootSeedBuffer = await this.toSeed(mnemonic, '') const hdNode = Bitcoin.HDNode.fromSeedBuffer(rootSeedBuffer) - const HDPath = `44'/145'/0'/0/` + const HDPath = "44'/145'/0'/0/" const accounts = [] @@ -321,7 +321,7 @@ class Mnemonic { * bchjs.Mnemonic.findNearestWord(word, wordlist); * // neve */ - findNearestWord(word, wordlist) { + findNearestWord (word, wordlist) { let minDistance = 99 let closestWord = wordlist[0] for (let i = 0; i < wordlist.length; i++) { @@ -352,7 +352,7 @@ module.exports = Mnemonic * @return Object the final object. */ -const _extend = function(dst) { +const _extend = function (dst) { const sources = Array.prototype.slice.call(arguments, 1) for (let i = 0; i < sources.length; ++i) { const src = sources[i] @@ -365,8 +365,8 @@ const _extend = function(dst) { * Defer execution of given function. * @param {Function} func */ -const _defer = function(func) { - if (typeof setImmediate === "function") return setImmediate(func) +const _defer = function (func) { + if (typeof setImmediate === 'function') return setImmediate(func) return setTimeout(func, 0) } @@ -374,7 +374,7 @@ const _defer = function(func) { /** * Based on the algorithm at http://en.wikipedia.org/wiki/Levenshtein_distance. */ -var Levenshtein = { +const Levenshtein = { /** * Calculate levenshtein distance of the two strings. * @@ -382,7 +382,7 @@ var Levenshtein = { * @param str2 String the second string. * @return Integer the levenshtein distance (0 and above). */ - get: function(str1, str2) { + get: function (str1, str2) { // base cases if (str1 === str2) return 0 if (str1.length === 0) return str2.length @@ -432,7 +432,7 @@ var Levenshtein = { * @param [options] Object additional options. * @param [options.progress] Function progress callback with signature: function(percentComplete) */ - getAsync: function(str1, str2, cb, options) { + getAsync: function (str1, str2, cb, options) { options = _extend( {}, { @@ -457,7 +457,7 @@ var Levenshtein = { i = 0 j = -1 - var __calculate = function() { + const __calculate = function () { // reset timer startTime = new Date().valueOf() currentTime = startTime @@ -499,7 +499,7 @@ var Levenshtein = { } // send a progress update? - if (null !== options.progress) { + if (options.progress !== null) { try { options.progress.call(null, (i * 100.0) / str1.length) } catch (err) { diff --git a/src/ninsight.js b/src/ninsight.js index fe2e0e5..4396db8 100644 --- a/src/ninsight.js +++ b/src/ninsight.js @@ -3,12 +3,12 @@ Bitcoin.com */ -const axios = require("axios") +const axios = require('axios') let _this class Ninsight { - constructor(config) { + constructor (config) { // this.restURL = config.restURL // this.apiToken = config.apiToken @@ -16,7 +16,7 @@ class Ninsight { if (config) { this.ninsightURL = config.ninsightURL ? config.ninsightURL - : `https://rest.bitcoin.com/v2` + : 'https://rest.bitcoin.com/v2' } // Add JWT token to the authorization header. @@ -66,10 +66,10 @@ class Ninsight { * // ] * */ - async utxo(address) { + async utxo (address) { try { // Handle single address. - if (typeof address === "string") { + if (typeof address === 'string') { const response = await axios.post( `${this.ninsightURL}/address/utxo`, { @@ -92,7 +92,7 @@ class Ninsight { return response.data } - throw new Error(`Input address must be a string or array of strings.`) + throw new Error('Input address must be a string or array of strings.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error @@ -135,9 +135,9 @@ class Ninsight { * // ] * */ - async unconfirmed(address) { + async unconfirmed (address) { try { - if (typeof address === "string") { + if (typeof address === 'string') { const response = await axios.post( `${this.ninsightURL}/address/unconfirmed`, { @@ -159,7 +159,7 @@ class Ninsight { return response.data } - throw new Error(`Input address must be a string or array of strings.`) + throw new Error('Input address must be a string or array of strings.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error @@ -211,9 +211,9 @@ class Ninsight { * // * */ - async transactions(address) { + async transactions (address) { try { - if (typeof address === "string") { + if (typeof address === 'string') { const response = await axios.post( `${this.ninsightURL}/address/transactions`, { @@ -235,7 +235,7 @@ class Ninsight { return response.data } - throw new Error(`Input address must be a string or array of strings.`) + throw new Error('Input address must be a string or array of strings.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error @@ -284,9 +284,9 @@ class Ninsight { * // ] * */ - async txDetails(txid) { + async txDetails (txid) { try { - if (typeof txid === "string") { + if (typeof txid === 'string') { const response = await axios.post( `${this.ninsightURL}/transaction/details`, { @@ -308,7 +308,7 @@ class Ninsight { return response.data } - throw new Error(`Transaction ID must be a string or array of strings.`) + throw new Error('Transaction ID must be a string or array of strings.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error diff --git a/src/openbazaar.js b/src/openbazaar.js index 3ffd790..995e78c 100644 --- a/src/openbazaar.js +++ b/src/openbazaar.js @@ -3,12 +3,12 @@ provides for their application. */ -const axios = require("axios") +const axios = require('axios') let _this class OpenBazaar { - constructor(config) { + constructor (config) { this.restURL = config.restURL this.apiToken = config.apiToken @@ -55,12 +55,12 @@ class OpenBazaar { * } * */ - async balance(address) { + async balance (address) { try { // Handle single address. - if (typeof address === "string") { + if (typeof address === 'string') { let response - if (process.env.NETWORK === "testnet") { + if (process.env.NETWORK === 'testnet') { response = await axios.get( `https://tbch.blockbook.api.openbazaar.org/api/address/${address}`, _this.axiosOptions @@ -75,7 +75,7 @@ class OpenBazaar { return response.data } - throw new Error(`Input address must be a string.`) + throw new Error('Input address must be a string.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error @@ -109,12 +109,12 @@ class OpenBazaar { * } * ] */ - async utxo(address) { + async utxo (address) { try { // Handle single address. - if (typeof address === "string") { + if (typeof address === 'string') { let response - if (process.env.NETWORK === "testnet") { + if (process.env.NETWORK === 'testnet') { response = await axios.get( `https://tbch.blockbook.api.openbazaar.org/api/utxo/${address}`, _this.axiosOptions @@ -127,7 +127,7 @@ class OpenBazaar { } return response.data } - throw new Error(`Input address must be a string.`) + throw new Error('Input address must be a string.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error @@ -199,12 +199,12 @@ class OpenBazaar { * } * */ - async tx(txid) { + async tx (txid) { try { // Handle single txid. - if (typeof txid === "string") { + if (typeof txid === 'string') { let response - if (process.env.NETWORK === "testnet") { + if (process.env.NETWORK === 'testnet') { response = await axios.get( `https://tbch.blockbook.api.openbazaar.org/api/tx/${txid}`, _this.axiosOptions @@ -218,7 +218,7 @@ class OpenBazaar { return response.data } - throw new Error(`Input txid must be a string.`) + throw new Error('Input txid must be a string.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error diff --git a/src/price.js b/src/price.js index 7908f3e..834c53f 100644 --- a/src/price.js +++ b/src/price.js @@ -1,9 +1,9 @@ -const axios = require("axios") +const axios = require('axios') let _this class Price { - constructor(config) { + constructor (config) { _this = this this.restURL = config.restURL @@ -30,7 +30,7 @@ class Price { } // This endpoint is deprecated. Documentation removed. - async current(currency = "usd") { + async current (currency = 'usd') { try { const response = await this.axios.get( `https://index-api.bitcoin.com/api/v0/cash/price/${currency.toLowerCase()}` @@ -64,7 +64,7 @@ class Price { * * // 266.81 */ - async getUsd() { + async getUsd () { try { const response = await this.axios.get( `${this.restURL}price/usd`, @@ -107,7 +107,7 @@ class Price { * ZWL: "80215.03" * } */ - async rates() { + async rates () { try { const response = await this.axios.get( `${this.restURL}price/rates`, @@ -142,7 +142,7 @@ class Price { * * // 18.81 */ - async getBchaUsd() { + async getBchaUsd () { try { const response = await this.axios.get( `${this.restURL}price/bchausd`, diff --git a/src/raw-transactions.js b/src/raw-transactions.js index 3bd1aec..5cff4c4 100644 --- a/src/raw-transactions.js +++ b/src/raw-transactions.js @@ -1,9 +1,9 @@ -const axios = require("axios") +const axios = require('axios') let _this class RawTransactions { - constructor(config) { + constructor (config) { this.restURL = config.restURL this.apiToken = config.apiToken this.authToken = config.authToken @@ -92,10 +92,10 @@ class RawTransactions { * // vin: [ [Object] ], * // vout: [ [Object] ] } ] */ - async decodeRawTransaction(hex) { + async decodeRawTransaction (hex) { try { // Single hex - if (typeof hex === "string") { + if (typeof hex === 'string') { const response = await axios.get( `${this.restURL}rawtransactions/decodeRawTransaction/${hex}`, _this.axiosOptions @@ -106,7 +106,7 @@ class RawTransactions { // Array of hexes } else if (Array.isArray(hex)) { const options = { - method: "POST", + method: 'POST', url: `${this.restURL}rawtransactions/decodeRawTransaction`, data: { hexes: hex @@ -120,7 +120,7 @@ class RawTransactions { return response.data } - throw new Error(`Input must be a string or array of strings.`) + throw new Error('Input must be a string or array of strings.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error @@ -160,11 +160,11 @@ class RawTransactions { * // type: 'nonstandard', * // p2sh: 'bitcoincash:pqwndulzwft8dlmqrteqyc9hf823xr3lcc7ypt74ts' }] */ - async decodeScript(script) { - //if (typeof script !== "string") script = JSON.stringify(script) + async decodeScript (script) { + // if (typeof script !== "string") script = JSON.stringify(script) try { - if (typeof script === "string") { + if (typeof script === 'string') { const response = await axios.get( `${this.restURL}rawtransactions/decodeScript/${script}`, _this.axiosOptions @@ -173,7 +173,7 @@ class RawTransactions { return response.data } else if (Array.isArray(script)) { const options = { - method: "POST", + method: 'POST', url: `${this.restURL}rawtransactions/decodeScript`, data: { hexes: script @@ -187,7 +187,7 @@ class RawTransactions { return response.data } - throw new Error(`Input must be a string or array of strings.`) + throw new Error('Input must be a string or array of strings.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error @@ -258,9 +258,9 @@ class RawTransactions { * // time: 1547752564, * // blocktime: 1547752564 } ] */ - async getRawTransaction(txid, verbose = false) { + async getRawTransaction (txid, verbose = false) { try { - if (typeof txid === "string") { + if (typeof txid === 'string') { const response = await axios.get( `${this.restURL}rawtransactions/getRawTransaction/${txid}?verbose=${verbose}`, _this.axiosOptions @@ -269,7 +269,7 @@ class RawTransactions { return response.data } else if (Array.isArray(txid)) { const options = { - method: "POST", + method: 'POST', url: `${this.restURL}rawtransactions/getRawTransaction`, data: { txids: txid, @@ -282,7 +282,7 @@ class RawTransactions { return response.data } - throw new Error(`Input must be a string or array of strings.`) + throw new Error('Input must be a string or array of strings.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error @@ -321,16 +321,16 @@ class RawTransactions { * })() * // ['0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098'] */ - async sendRawTransaction(hex, allowhighfees = false) { + async sendRawTransaction (hex, allowhighfees = false) { try { // Single tx hex. - if (typeof hex === "string") { + if (typeof hex === 'string') { const response = await this.axios.get( `${this.restURL}rawtransactions/sendRawTransaction/${hex}`, _this.axiosOptions ) - if (response.data === "66: insufficient priority") { + if (response.data === '66: insufficient priority') { console.warn( `WARN: Insufficient Priority! This is likely due to a fee that is too low, or insufficient funds. Please ensure that there is BCH in the given wallet. If you are running on the testnet, get some @@ -343,7 +343,7 @@ class RawTransactions { // Array input } else if (Array.isArray(hex)) { const options = { - method: "POST", + method: 'POST', url: `${this.restURL}rawtransactions/sendRawTransaction`, data: { hexes: hex @@ -355,7 +355,7 @@ class RawTransactions { return response.data } - throw new Error(`Input hex must be a string or array of strings.`) + throw new Error('Input hex must be a string or array of strings.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error diff --git a/src/schnorr.js b/src/schnorr.js index c947526..ca01095 100644 --- a/src/schnorr.js +++ b/src/schnorr.js @@ -1,7 +1,7 @@ -const schnorr = require("bip-schnorr") +const schnorr = require('bip-schnorr') class Schnorr { - constructor(config) { + constructor (config) { this.restURL = config.restURL this.apiToken = config.apiToken this.authToken = config.authToken @@ -46,7 +46,7 @@ class Schnorr { * console.log("The signature is: " + createdSignature.toString("hex")) * // The signature is: 2a298dacae57395a15d0795ddbfd1dcb564da82b0f269bc70a74f8220429ba1d1e51a22ccec35599b8f266912281f8365ffc2d035a230434a1a64dc59f7013fd */ - sign(privateKey, message) { + sign (privateKey, message) { return schnorr.sign(privateKey, message) } @@ -78,7 +78,7 @@ class Schnorr { * console.error("The signature verification failed: " + e) * } */ - verify(publicKey, message, signatureToVerify) { + verify (publicKey, message, signatureToVerify) { return schnorr.verify(publicKey, message, signatureToVerify) } @@ -140,7 +140,7 @@ class Schnorr { * console.error("The signature verification failed: " + e) * } */ - batchVerify(publicKeys, messages, signaturesToVerify) { + batchVerify (publicKeys, messages, signaturesToVerify) { return schnorr.batchVerify(publicKeys, messages, signaturesToVerify) } @@ -189,7 +189,7 @@ class Schnorr { * console.error("The signature verification failed: " + e) * } */ - nonInteractive(privateKeys, message) { + nonInteractive (privateKeys, message) { return schnorr.muSig.nonInteractive(privateKeys, message) } @@ -263,7 +263,7 @@ class Schnorr { * // ----------------------------------------------------------------------- * publicData.pubKeyHash = bchjs.Schnorr.computeEll(publicData.pubKeys) */ - computeEll(publicKeys) { + computeEll (publicKeys) { return schnorr.muSig.computeEll(publicKeys) } @@ -281,7 +281,7 @@ class Schnorr { * publicData.pubKeyHash * ) */ - publicKeyCombine(publicKeys, publicKeyHash) { + publicKeyCombine (publicKeys, publicKeyHash) { return schnorr.muSig.pubKeyCombine(publicKeys, publicKeyHash) } @@ -313,7 +313,7 @@ class Schnorr { * }) * const signerSession = signerPrivateData[0].session */ - sessionInitialize(sessionId, privateKey, message, pubKeyCombined, ell, idx) { + sessionInitialize (sessionId, privateKey, message, pubKeyCombined, ell, idx) { return schnorr.muSig.sessionInitialize( sessionId, privateKey, @@ -365,7 +365,7 @@ class Schnorr { * data => (data.session.nonceIsNegated = signerSession.nonceIsNegated) * ) */ - sessionNonceCombine(session, nonces) { + sessionNonceCombine (session, nonces) { return schnorr.muSig.sessionNonceCombine(session, nonces) } @@ -392,7 +392,7 @@ class Schnorr { * ) * }) */ - partialSign(session, message, nonceCombined, pubKeyCombined) { + partialSign (session, message, nonceCombined, pubKeyCombined) { return schnorr.muSig.partialSign( session, message, @@ -436,7 +436,7 @@ class Schnorr { * ) * } */ - partialSignatureVerify( + partialSignatureVerify ( session, partialSignature, nonceCombined, @@ -484,27 +484,27 @@ class Schnorr { * publicData.signature * ) */ - partialSignaturesCombine(nonceCombined, partialSignatures) { + partialSignaturesCombine (nonceCombined, partialSignatures) { return schnorr.muSig.partialSigCombine(nonceCombined, partialSignatures) } - bufferToInt(buffer) { + bufferToInt (buffer) { return schnorr.convert.bufferToInt(buffer) } - intToBuffer(bigInteger) { + intToBuffer (bigInteger) { return schnorr.convert.intToBuffer(bigInteger) } - hash(buffer) { + hash (buffer) { return schnorr.convert.hash(buffer) } - pointToBuffer(point) { + pointToBuffer (point) { return schnorr.convert.pointToBuffer(point) } - pubKeyToPoint(publicKey) { + pubKeyToPoint (publicKey) { return schnorr.convert.pubKeyToPoint(publicKey) } } diff --git a/src/script.js b/src/script.js index 7e8352e..a4ba2ed 100644 --- a/src/script.js +++ b/src/script.js @@ -1,8 +1,8 @@ -const Bitcoin = require("@psf/bitcoincashjs-lib") -const opcodes = require("@psf/bitcoincash-ops") +const Bitcoin = require('@psf/bitcoincashjs-lib') +const opcodes = require('@psf/bitcoincash-ops') class Script { - constructor() { + constructor () { this.opcodes = opcodes this.nullData = Bitcoin.script.nullData this.multisig = { @@ -58,7 +58,7 @@ class Script { * bchjs.Script.classifyInput(bchjs.Script.fromASM(scripthashInput)); * // scripthash */ - classifyInput(script) { + classifyInput (script) { return Bitcoin.script.classifyInput(script) } @@ -90,7 +90,7 @@ class Script { * bchjs.Script.classifyOutput(bchjs.Script.fromASM(scripthashOutput)); * // scripthash */ - classifyOutput(script) { + classifyOutput (script) { return Bitcoin.script.classifyOutput(script) } @@ -116,7 +116,7 @@ class Script { * // 136, * // 172 ] */ - decode(scriptBuffer) { + decode (scriptBuffer) { return Bitcoin.script.decompile(scriptBuffer) } @@ -150,7 +150,7 @@ class Script { * bchjs.Script.encode(scriptPubKey); * // */ - encode(scriptChunks) { + encode (scriptChunks) { const arr = [] scriptChunks.forEach(chunk => { arr.push(chunk) @@ -187,7 +187,7 @@ class Script { * bchjs.Script.encode2(scriptPubKey); * // */ - encode2(scriptChunks) { + encode2 (scriptChunks) { const arr = [] scriptChunks.forEach(chunk => { arr.push(chunk) @@ -213,7 +213,7 @@ class Script { * bchjs.Script.toASM(scriptBuffer); * // OP_DUP OP_HASH160 bee4182d9fbc8931a728410a0cd3e0f340f2995a OP_EQUALVERIFY OP_CHECKSIG */ - toASM(buffer) { + toASM (buffer) { return Bitcoin.script.toASM(buffer) } @@ -235,7 +235,7 @@ class Script { * bchjs.Script.fromASM(scriptPubKeyASM); * // */ - fromASM(asm) { + fromASM (asm) { return Bitcoin.script.fromASM(asm) } } diff --git a/src/slp/address.js b/src/slp/address.js index fe92a19..7163069 100644 --- a/src/slp/address.js +++ b/src/slp/address.js @@ -1,11 +1,11 @@ -const BCHJSAddress = require("../address") +const BCHJSAddress = require('../address') // const bchAddress = new BCHJSAddress() let bchAddress -const bchaddrjs = require("bchaddrjs-slp") +const bchaddrjs = require('bchaddrjs-slp') class Address extends BCHJSAddress { - constructor(config) { + constructor (config) { super(config) this.restURL = config.restURL @@ -52,11 +52,11 @@ class Address extends BCHJSAddress { * bchjs.SLP.Address.toSLPAddress('msDbtTj7kWXPpYaR7PQmMK84i66fJqQMLx', false) * // qzq9je6pntpva3wf6scr7mlnycr54sjgeqauyclpwv */ - toSLPAddress(address, prefix = true, regtest = false) { + toSLPAddress (address, prefix = true, regtest = false) { this._ensureValidAddress(address) const slpAddress = bchaddrjs.toSlpAddress(address) if (prefix) return slpAddress - return slpAddress.split(":")[1] + return slpAddress.split(':')[1] } /** @@ -98,11 +98,11 @@ class Address extends BCHJSAddress { * bchjs.SLP.Address.toCashAddress('msDbtTj7kWXPpYaR7PQmMK84i66fJqQMLx', false) * // qzq9je6pntpva3wf6scr7mlnycr54sjgeqxgrr9ku3 */ - toCashAddress(address, prefix = true, regtest = false) { + toCashAddress (address, prefix = true, regtest = false) { this._ensureValidAddress(address) const cashAddress = bchaddrjs.toCashAddress(address) if (prefix) return cashAddress - return cashAddress.split(":")[1] + return cashAddress.split(':')[1] } /** @@ -145,18 +145,18 @@ class Address extends BCHJSAddress { * bchjs.SLP.Address.toLegacyAddress('qph2v4mkxjgdqgmlyjx6njmey0ftrxlnggs3v58dse') * // mqc1tmwY2368LLGktnePzEyPAsgADxbksi */ - toLegacyAddress(address) { + toLegacyAddress (address) { this._ensureValidAddress(address) const cashAddr = bchaddrjs.toCashAddress(address) return bchAddress.toLegacyAddress(cashAddr) } - isLegacyAddress(address) { + isLegacyAddress (address) { this._ensureValidAddress(address) return bchAddress.isLegacyAddress(address) } - isCashAddress(address) { + isCashAddress (address) { this._ensureValidAddress(address) if (bchaddrjs.isSlpAddress(address)) return false @@ -195,7 +195,7 @@ class Address extends BCHJSAddress { * bchjs.SLP.Address.isSLPAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') * // false */ - isSLPAddress(address) { + isSLPAddress (address) { this._ensureValidAddress(address) return bchaddrjs.isSlpAddress(address) } @@ -248,7 +248,7 @@ class Address extends BCHJSAddress { * bchjs.SLP.Address.isMainnetAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') * // false */ - isMainnetAddress(address) { + isMainnetAddress (address) { this._ensureValidAddress(address) const cashaddr = bchaddrjs.toCashAddress(address) return bchAddress.isMainnetAddress(cashaddr) @@ -301,11 +301,12 @@ class Address extends BCHJSAddress { * bchjs.SLP.Address.isTestnetAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') * // true */ - isTestnetAddress(address) { + isTestnetAddress (address) { this._ensureValidAddress(address) const cashAddr = bchaddrjs.toCashAddress(address) return bchAddress.isTestnetAddress(cashAddr) } + /** * @api SLP.Address.isP2PKHAddress() isP2PKHAddress() * @apiName isP2PKHAddress @@ -353,11 +354,12 @@ class Address extends BCHJSAddress { * bchjs.SLP.Address.isP2PKHAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') * // true */ - isP2PKHAddress(address) { + isP2PKHAddress (address) { this._ensureValidAddress(address) const cashAddr = bchaddrjs.toCashAddress(address) return bchAddress.isP2PKHAddress(cashAddr) } + /** * @api SLP.Address.isP2SHAddress() isP2SHAddress() * @apiName isP2SHAddress @@ -405,11 +407,12 @@ class Address extends BCHJSAddress { * bchjs.SLP.Address.isP2SHAddress('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') * // false */ - isP2SHAddress(address) { + isP2SHAddress (address) { this._ensureValidAddress(address) const cashAddr = bchaddrjs.toCashAddress(address) return bchAddress.isP2SHAddress(cashAddr) } + /** * @api SLP.Address.detectAddressFormat() detectAddressFormat() * @apiName detectAddressFormat @@ -457,12 +460,13 @@ class Address extends BCHJSAddress { * bchjs.SLP.Address.detectAddressFormat('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') * // legacy */ - detectAddressFormat(address) { + detectAddressFormat (address) { this._ensureValidAddress(address) - if (bchaddrjs.isSlpAddress(address)) return "slpaddr" + if (bchaddrjs.isSlpAddress(address)) return 'slpaddr' return bchAddress.detectAddressFormat(address) } + /** * @api SLP.Address.detectAddressNetwork() detectAddressNetwork() * @apiName detectAddressNetwork @@ -510,11 +514,12 @@ class Address extends BCHJSAddress { * bchjs.SLP.Address.detectAddressNetwork('mqc1tmwY2368LLGktnePzEyPAsgADxbksi') * // testnet */ - detectAddressNetwork(address) { + detectAddressNetwork (address) { this._ensureValidAddress(address) const cashAddr = bchaddrjs.toCashAddress(address) return bchAddress.detectAddressNetwork(cashAddr) } + /** * @api SLP.Address.detectAddressType() detectAddressType() * @apiName detectAddressType @@ -562,11 +567,12 @@ class Address extends BCHJSAddress { * bchjs.SLP.Address.detectAddressType('mqc1tmwY2368LLGktnePzEyPAsgADxbksi'); * // p2pkh */ - detectAddressType(address) { + detectAddressType (address) { this._ensureValidAddress(address) const cashAddr = bchaddrjs.toCashAddress(address) return bchAddress.detectAddressType(cashAddr) } + /* async details(address) { let tmpBITBOX @@ -644,7 +650,7 @@ class Address extends BCHJSAddress { return tmpBITBOX.Address.transactions(address) } */ - _ensureValidAddress(address) { + _ensureValidAddress (address) { try { bchaddrjs.toCashAddress(address) } catch (err) { diff --git a/src/slp/ecpair.js b/src/slp/ecpair.js index b939fb9..91852d0 100644 --- a/src/slp/ecpair.js +++ b/src/slp/ecpair.js @@ -1,9 +1,9 @@ -//const BCHJS = require("../bch-js") -//const bchjs = new BCHJS() +// const BCHJS = require("../bch-js") +// const bchjs = new BCHJS() -const BCHJSECPair = require("../ecpair") +const BCHJSECPair = require('../ecpair') -const bchaddrjs = require("bchaddrjs-slp") +const bchaddrjs = require('bchaddrjs-slp') class ECPair extends BCHJSECPair { /* @@ -25,7 +25,7 @@ class ECPair extends BCHJSECPair { * bchjs.SLP.ECPair.toSLPAddress(ecpair); * // slptest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcqag6fk03 */ - static toSLPAddress(ecpair) { + static toSLPAddress (ecpair) { const slpAddress = bchaddrjs.toSlpAddress(this.toCashAddress(ecpair)) return slpAddress } diff --git a/src/slp/nft1.js b/src/slp/nft1.js index 631ec3a..762f817 100644 --- a/src/slp/nft1.js +++ b/src/slp/nft1.js @@ -8,17 +8,17 @@ (Parent) token. */ -const Address = require("./address") +const Address = require('./address') -const BigNumber = require("bignumber.js") -const slpMdm = require("slp-mdm") +// const BigNumber = require('bignumber.js') +const slpMdm = require('slp-mdm') // const addy = new Address() let addy -const TransactionBuilder = require("../transaction-builder") +const TransactionBuilder = require('../transaction-builder') class TokenType1 { - constructor(config) { + constructor (config) { this.restURL = config.restURL addy = new Address(config) @@ -59,12 +59,12 @@ class TokenType1 { * // https://github.com/Permissionless-Software-Foundation/bch-js-examples/tree/master/applications/slp/nft * */ - newNFTGroupOpReturn(configObj) { + newNFTGroupOpReturn (configObj) { try { // TODO: Add input validation. // Prevent error if user fails to add the document hash. - if (!configObj.documentHash) configObj.documentHash = "" + if (!configObj.documentHash) configObj.documentHash = '' // If mint baton is not specified, then replace it with null. if (!configObj.mintBatonVout) configObj.mintBatonVout = null @@ -81,7 +81,7 @@ class TokenType1 { return script } catch (err) { - console.log(`Error in generateNFTParentOpReturn()`) + console.log('Error in generateNFTParentOpReturn()') throw err } } @@ -130,43 +130,47 @@ class TokenType1 { * // See additional code here: * // https://github.com/Permissionless-Software-Foundation/bch-js-examples/tree/master/applications/slp/nft */ - mintNFTGroupOpReturn(tokenUtxos, mintQty, destroyBaton = false) { - try { - // Throw error if input is not an array. - if (!Array.isArray(tokenUtxos)) - throw new Error(`tokenUtxos must be an array.`) - - // Loop through the tokenUtxos array and find the minting baton. - let mintBatonUtxo - for (let i = 0; i < tokenUtxos.length; i++) { - if (tokenUtxos[i].utxoType === "minting-baton") - mintBatonUtxo = tokenUtxos[i] - } - - // Throw an error if the minting baton could not be found. - if (!mintBatonUtxo) - throw new Error(`Minting baton could not be found in tokenUtxos array.`) - - const tokenId = mintBatonUtxo.tokenId - - if (!tokenId) - throw new Error(`tokenId property not found in mint-baton UTXO.`) - - // Signal that the baton should be passed or detroyed. - let batonVout = 2 - if (destroyBaton) batonVout = null - - const script = slpMdm.NFT1.Group.mint( - tokenId, - batonVout, - new slpMdm.BN(mintQty) - ) - - return script - } catch (err) { - // console.log(`Error in generateMintOpReturn()`) - throw err + mintNFTGroupOpReturn (tokenUtxos, mintQty, destroyBaton = false) { + // try { + // Throw error if input is not an array. + if (!Array.isArray(tokenUtxos)) { + throw new Error('tokenUtxos must be an array.') } + + // Loop through the tokenUtxos array and find the minting baton. + let mintBatonUtxo + for (let i = 0; i < tokenUtxos.length; i++) { + if (tokenUtxos[i].utxoType === 'minting-baton') { + mintBatonUtxo = tokenUtxos[i] + } + } + + // Throw an error if the minting baton could not be found. + if (!mintBatonUtxo) { + throw new Error('Minting baton could not be found in tokenUtxos array.') + } + + const tokenId = mintBatonUtxo.tokenId + + if (!tokenId) { + throw new Error('tokenId property not found in mint-baton UTXO.') + } + + // Signal that the baton should be passed or detroyed. + let batonVout = 2 + if (destroyBaton) batonVout = null + + const script = slpMdm.NFT1.Group.mint( + tokenId, + batonVout, + new slpMdm.BN(mintQty) + ) + + return script + // } catch (err) { + // // console.log(`Error in generateMintOpReturn()`) + // throw err + // } } /** @@ -200,12 +204,12 @@ class TokenType1 { * // https://github.com/Permissionless-Software-Foundation/bch-js-examples/tree/master/applications/slp/nft * */ - generateNFTChildGenesisOpReturn(configObj) { + generateNFTChildGenesisOpReturn (configObj) { try { // TODO: Add input validation. // Prevent error if user fails to add the document hash. - if (!configObj.documentHash) configObj.documentHash = "" + if (!configObj.documentHash) configObj.documentHash = '' // If mint baton is not specified, then replace it with null. if (!configObj.mintBatonVout) configObj.mintBatonVout = null @@ -217,12 +221,12 @@ class TokenType1 { configObj.documentHash, 0, configObj.mintBatonVout, - new slpMdm.BN("1") + new slpMdm.BN('1') ) return script } catch (err) { - console.log(`Error in generateNFTChildGenesisOpReturn()`) + console.log('Error in generateNFTChildGenesisOpReturn()') throw err } } @@ -270,7 +274,7 @@ class TokenType1 { * // See additional code here: * // https://github.com/Permissionless-Software-Foundation/bch-js-examples/tree/master/applications/slp/nft */ - generateNFTChildSendOpReturn(tokenUtxos, sendQty) { + generateNFTChildSendOpReturn (tokenUtxos, sendQty) { try { // TODO: Add input validation. @@ -278,8 +282,9 @@ class TokenType1 { // Calculate the total amount of tokens owned by the wallet. let totalTokens = 0 - for (let i = 0; i < tokenUtxos.length; i++) + for (let i = 0; i < tokenUtxos.length; i++) { totalTokens += tokenUtxos[i].tokenQty + } const change = totalTokens - sendQty @@ -312,7 +317,7 @@ class TokenType1 { return { script, outputs } } catch (err) { - console.log(`Error in generateNFTChildSendOpReturn()`) + console.log('Error in generateNFTChildSendOpReturn()') throw err } } @@ -360,7 +365,7 @@ class TokenType1 { * // See additional code here: * // https://github.com/Permissionless-Software-Foundation/bch-js-examples/tree/master/applications/slp/nft */ - generateNFTGroupSendOpReturn(tokenUtxos, sendQty) { + generateNFTGroupSendOpReturn (tokenUtxos, sendQty) { try { // TODO: Add input validation. @@ -368,8 +373,9 @@ class TokenType1 { // Calculate the total amount of tokens owned by the wallet. let totalTokens = 0 - for (let i = 0; i < tokenUtxos.length; i++) + for (let i = 0; i < tokenUtxos.length; i++) { totalTokens += tokenUtxos[i].tokenQty + } const change = totalTokens - sendQty @@ -402,7 +408,7 @@ class TokenType1 { return { script, outputs } } catch (err) { - console.log(`Error in generateNFTGroupSendOpReturn()`) + console.log('Error in generateNFTGroupSendOpReturn()') throw err } } diff --git a/src/slp/slp.js b/src/slp/slp.js index 478ba33..e535650 100644 --- a/src/slp/slp.js +++ b/src/slp/slp.js @@ -7,17 +7,17 @@ // imports // require deps -//const BCHJS = require("../bch-js") -const Address = require("./address") -const ECPair = require("./ecpair") +// const BCHJS = require("../bch-js") +const Address = require('./address') +const ECPair = require('./ecpair') // const HDNode = require("./hdnode") -const TokenType1 = require("./tokentype1") -const NFT1 = require("./nft1") -const Utils = require("./utils") +const TokenType1 = require('./tokentype1') +const NFT1 = require('./nft1') +const Utils = require('./utils') // SLP is a superset of BITBOX class SLP { - constructor(config) { + constructor (config) { this.restURL = config.restURL this.apiToken = config.apiToken this.authToken = config.authToken diff --git a/src/slp/tokentype1.js b/src/slp/tokentype1.js index fd59717..63baccc 100644 --- a/src/slp/tokentype1.js +++ b/src/slp/tokentype1.js @@ -2,24 +2,24 @@ This library handles the OP_RETURN of SLP TokenType1 transactions. */ -//const BCHJS = require("../bch-js") -//const bchjs = new BCHJS() +// const BCHJS = require("../bch-js") +// const bchjs = new BCHJS() -const Address = require("./address") -const Script = require("../script") +const Address = require('./address') +const Script = require('../script') -const BigNumber = require("bignumber.js") -const slpMdm = require("slp-mdm") -const axios = require("axios") +const BigNumber = require('bignumber.js') +const slpMdm = require('slp-mdm') +const axios = require('axios') // const addy = new Address() let addy -const TransactionBuilder = require("../transaction-builder") +const TransactionBuilder = require('../transaction-builder') let _this // local global class TokenType1 { - constructor(config) { + constructor (config) { this.restURL = config.restURL this.apiToken = config.apiToken this.authToken = config.authToken @@ -92,7 +92,7 @@ class TokenType1 { * // See additional code here: * // https://github.com/Permissionless-Software-Foundation/bch-js-examples/blob/master/applications/slp/send-token/send-token.js */ - generateSendOpReturn(tokenUtxos, sendQty) { + generateSendOpReturn (tokenUtxos, sendQty) { try { const tokenId = tokenUtxos[0].tokenId const decimals = tokenUtxos[0].decimals @@ -125,11 +125,14 @@ class TokenType1 { // console.log(`baseChange: `, baseChange) // Check for potential burns - const outputQty = new BigNumber(baseChange).plus(new BigNumber(baseQty)) + const outputQty = new BigNumber(baseChange).plus( + new BigNumber(baseQty) + ) const inputQty = new BigNumber(totalTokens) - const tokenOutputDelta = outputQty.minus(inputQty).toString() !== "0" - if (tokenOutputDelta) - throw "Token transaction inputs do not match outputs, cannot send transaction" + const tokenOutputDelta = outputQty.minus(inputQty).toString() !== '0' + if (tokenOutputDelta) { + throw new Error('Token transaction inputs do not match outputs, cannot send transaction') + } // Generate the OP_RETURN as a Buffer. script = slpMdm.TokenType1.send(tokenId, [ @@ -147,9 +150,10 @@ class TokenType1 { const noChangeOutputQty = new BigNumber(baseQty) const noChangeInputQty = new BigNumber(totalTokens) const tokenSingleOutputError = - noChangeOutputQty.minus(noChangeInputQty).toString() !== "0" - if (tokenSingleOutputError) - throw "Token transaction inputs do not match outputs, cannot send transaction" + noChangeOutputQty.minus(noChangeInputQty).toString() !== '0' + if (tokenSingleOutputError) { + throw new Error('Token transaction inputs do not match outputs, cannot send transaction') + } // Generate the OP_RETURN as a Buffer. script = slpMdm.TokenType1.send(tokenId, [new slpMdm.BN(baseQty)]) @@ -157,7 +161,7 @@ class TokenType1 { return { script, outputs } } catch (err) { - console.log(`Error in generateSendOpReturn()`) + console.log('Error in generateSendOpReturn()') throw err } } @@ -208,15 +212,16 @@ class TokenType1 { * // https://github.com/Permissionless-Software-Foundation/bch-js-examples/blob/master/applications/slp/burn-tokens/burn-tokens.js * */ - generateBurnOpReturn(tokenUtxos, burnQty) { + generateBurnOpReturn (tokenUtxos, burnQty) { try { const tokenId = tokenUtxos[0].tokenId const decimals = tokenUtxos[0].decimals // Calculate the total amount of tokens owned by the wallet. let totalTokens = 0 - for (let i = 0; i < tokenUtxos.length; i++) + for (let i = 0; i < tokenUtxos.length; i++) { totalTokens += tokenUtxos[i].tokenQty + } const remainder = totalTokens - burnQty @@ -232,7 +237,7 @@ class TokenType1 { return script } catch (err) { - console.log(`Error in generateBurnOpReturn()`) + console.log('Error in generateBurnOpReturn()') throw err } } @@ -271,7 +276,7 @@ class TokenType1 { * // https://github.com/Permissionless-Software-Foundation/bch-js-examples/blob/master/applications/slp/create-token/create-token.js * */ - generateGenesisOpReturn(configObj) { + generateGenesisOpReturn (configObj) { try { // TODO: Add input validation. @@ -283,7 +288,7 @@ class TokenType1 { baseQty = baseQty.toString() // Prevent error if user fails to add the document hash. - if (!configObj.documentHash) configObj.documentHash = "" + if (!configObj.documentHash) configObj.documentHash = '' // If mint baton is not specified, then replace it with null. if (!configObj.mintBatonVout) configObj.mintBatonVout = null @@ -300,7 +305,7 @@ class TokenType1 { return script } catch (err) { - console.log(`Error in generateGenesisOpReturn()`) + console.log('Error in generateGenesisOpReturn()') throw err } } @@ -351,30 +356,37 @@ class TokenType1 { * // See additional code here: * // https://github.com/Permissionless-Software-Foundation/bch-js-examples/blob/master/applications/slp/mint-token/mint-token.js */ - generateMintOpReturn(tokenUtxos, mintQty, destroyBaton = false) { + generateMintOpReturn (tokenUtxos, mintQty, destroyBaton = false) { try { // Throw error if input is not an array. - if (!Array.isArray(tokenUtxos)) - throw new Error(`tokenUtxos must be an array.`) + if (!Array.isArray(tokenUtxos)) { + throw new Error('tokenUtxos must be an array.') + } // Loop through the tokenUtxos array and find the minting baton. let mintBatonUtxo for (let i = 0; i < tokenUtxos.length; i++) { - if (tokenUtxos[i].utxoType === "minting-baton") + if (tokenUtxos[i].utxoType === 'minting-baton') { mintBatonUtxo = tokenUtxos[i] + } } // Throw an error if the minting baton could not be found. - if (!mintBatonUtxo) - throw new Error(`Minting baton could not be found in tokenUtxos array.`) + if (!mintBatonUtxo) { + throw new Error( + 'Minting baton could not be found in tokenUtxos array.' + ) + } const tokenId = mintBatonUtxo.tokenId const decimals = mintBatonUtxo.decimals - if (!tokenId) - throw new Error(`tokenId property not found in mint-baton UTXO.`) - if (!decimals) - throw new Error(`decimals property not found in mint-baton UTXO.`) + if (!tokenId) { + throw new Error('tokenId property not found in mint-baton UTXO.') + } + if (!decimals) { + throw new Error('decimals property not found in mint-baton UTXO.') + } let baseQty = new BigNumber(mintQty).times(10 ** decimals) baseQty = baseQty.absoluteValue() @@ -393,7 +405,7 @@ class TokenType1 { return script } catch (err) { - // console.log(`Error in generateMintOpReturn()`) + console.log('Error in generateMintOpReturn()') throw err } } @@ -425,7 +437,7 @@ class TokenType1 { * "outputs": 2 * } */ - async getHexOpReturn(tokenUtxos, sendQty) { + async getHexOpReturn (tokenUtxos, sendQty) { try { // TODO: Add input filtering. @@ -449,7 +461,7 @@ class TokenType1 { return slpSendObj } catch (err) { - // console.log(err) + console.log('Error in getHexOpReturn()') throw err } } diff --git a/src/slp/utils.js b/src/slp/utils.js index 24ee1a8..d6a6512 100644 --- a/src/slp/utils.js +++ b/src/slp/utils.js @@ -1,7 +1,7 @@ // Public npm libraries -const axios = require("axios") -const slpParser = require("slp-parser") -const BigNumber = require("bignumber.js") +const axios = require('axios') +const slpParser = require('slp-parser') +const BigNumber = require('bignumber.js') // const Script = require("../script") // const scriptLib = new Script() @@ -11,7 +11,7 @@ const BigNumber = require("bignumber.js") let _this class Utils { - constructor(config) { + constructor (config) { this.restURL = config.restURL this.apiToken = config.apiToken this.slpParser = slpParser @@ -195,18 +195,18 @@ class Utils { * circulatingSupply: 19882.03820723, * mintingBatonStatus: 'ALIVE' } ] */ - async list(id) { + async list (id) { let path let method if (!id) { - method = "get" + method = 'get' path = `${this.restURL}slp/list` - } else if (typeof id === "string") { - method = "get" + } else if (typeof id === 'string') { + method = 'get' path = `${this.restURL}slp/list/${id}` - } else if (typeof id === "object") { - method = "post" + } else if (typeof id === 'object') { + method = 'post' path = `${this.restURL}slp/list` } @@ -214,7 +214,7 @@ class Utils { try { let response - if (method === "get") { + if (method === 'get') { response = await _this.axios.get(path, _this.axiosOptions) } else { response = await _this.axios.post( @@ -307,10 +307,10 @@ class Utils { * array of addresses. */ // Retrieve token balances for a given address. - async balancesForAddress(address) { + async balancesForAddress (address) { try { // Single address. - if (typeof address === "string") { + if (typeof address === 'string') { const path = `${this.restURL}slp/balancesForAddress/${address}` const response = await _this.axios.get(path, _this.axiosOptions) @@ -332,7 +332,7 @@ class Utils { return response.data } - throw new Error("Input address must be a string or array of strings.") + throw new Error('Input address must be a string or array of strings.') } catch (error) { if (error.response && error.response.data) throw error.response.data throw error @@ -374,7 +374,7 @@ class Utils { * */ // Retrieve token balances for a given tokenId. - async balancesForToken(tokenId) { + async balancesForToken (tokenId) { try { const path = `${this.restURL}slp/balancesForToken/${tokenId}` @@ -436,14 +436,14 @@ class Utils { // will be like the examples above. If SLPDB has fallen behind real-time // processing, it will return this output: // [ null ] - async validateTxid(txid) { + async validateTxid (txid) { const path = `${this.restURL}slp/validateTxid` // console.log(`txid: ${JSON.stringify(txid, null, 2)}`) // Handle a single TXID or an array of TXIDs. let txids - if (typeof txid === "string") txids = [txid] + if (typeof txid === 'string') txids = [txid] else txids = txid try { @@ -501,17 +501,18 @@ class Utils { * 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb', * valid: true } ] */ - async validateTxid2(txid) { + async validateTxid2 (txid) { try { // console.log(`txid: ${JSON.stringify(txid, null, 2)}`) if ( !txid || - txid === "" || - typeof txid !== "string" || + txid === '' || + typeof txid !== 'string' || txid.length !== 64 - ) - throw new Error("txid must be 64 character string.") + ) { + throw new Error('txid must be 64 character string.') + } const path = `${this.restURL}slp/validateTxid2/${txid}` @@ -520,8 +521,9 @@ class Utils { } catch (error) { if (error.response && error.response.data) throw error.response.data - if (error.error && error.error.indexOf("Network error") > -1) - throw new Error("slp-validate timed out") + if (error.error && error.error.indexOf('Network error') > -1) { + throw new Error('slp-validate timed out') + } throw error } @@ -577,7 +579,7 @@ class Utils { * } * ] */ - async getWhitelist() { + async getWhitelist () { try { const path = `${this.restURL}slp/whitelist` @@ -646,14 +648,14 @@ class Utils { * '00ea27261196a411776f81029c0ebe34362936b4a9847deb1f7a40a02b3a1476', * valid: true } ] */ - async validateTxid3(txid) { + async validateTxid3 (txid) { const path = `${this.restURL}slp/validateTxid3` // console.log(`txid: ${JSON.stringify(txid, null, 2)}`) // Handle a single TXID or an array of TXIDs. let txids - if (typeof txid === "string") txids = [txid] + if (typeof txid === 'string') txids = [txid] else txids = txid try { @@ -710,7 +712,7 @@ class Utils { * satoshisLockedUp: 135408 * } */ - async tokenStats(tokenId) { + async tokenStats (tokenId) { try { const path = `${this.restURL}slp/tokenStats/${tokenId}` @@ -781,7 +783,7 @@ class Utils { * ] */ // Retrieve token transactions for a given tokenId and address. - async transactions(tokenId, address) { + async transactions (tokenId, address) { try { const path = `${this.restURL}slp/transactions/${tokenId}/${address}` @@ -821,7 +823,7 @@ class Utils { * burnTotal: 100 * } */ - async burnTotal(transactionId) { + async burnTotal (transactionId) { try { const path = `${this.restURL}slp/burnTotal/${transactionId}` @@ -855,15 +857,16 @@ class Utils { * })() * */ - async txDetails(txid) { + async txDetails (txid) { try { if ( !txid || - txid === "" || - typeof txid !== "string" || + txid === '' || + typeof txid !== 'string' || txid.length !== 64 - ) - throw new Error("txid string must be included.") + ) { + throw new Error('txid string must be included.') + } // console.log(`this.restURL: ${this.restURL}`) const path = `${this.restURL}slp/txDetails/${txid}` @@ -920,7 +923,7 @@ class Utils { * } */ // Reimplementation of decodeOpReturn() using slp-parser. - async decodeOpReturn(txid, cache = null) { + async decodeOpReturn (txid, cache = null) { // The cache object is an in-memory cache (JS Object) that can be passed // into this function. It helps if multiple vouts from the same TXID are // being evaluated. In that case, it can significantly reduce the number @@ -929,8 +932,9 @@ class Utils { // cache[txid] = returnValue // Then pass that cache object back into this function every time its called. if (cache) { - if (!(cache instanceof Object)) - throw new Error("decodeOpReturn cache parameter must be Object") + if (!(cache instanceof Object)) { + throw new Error('decodeOpReturn cache parameter must be Object') + } const cachedVal = cache[txid] if (cachedVal) return cachedVal @@ -938,8 +942,9 @@ class Utils { try { // Validate the txid input. - if (!txid || txid === "" || typeof txid !== "string") - throw new Error("txid string must be included.") + if (!txid || txid === '' || typeof txid !== 'string') { + throw new Error('txid string must be included.') + } // Retrieve the transaction object from the full node. const path = `${this.restURL}rawtransactions/getRawTransaction/${txid}?verbose=true` @@ -951,19 +956,19 @@ class Utils { const opReturn = txDetails.vout[0].scriptPubKey.hex // console.log(`opReturn hex: ${opReturn}`) - const parsedData = _this.slpParser.parseSLP(Buffer.from(opReturn, "hex")) + const parsedData = _this.slpParser.parseSLP(Buffer.from(opReturn, 'hex')) // console.log(`parsedData: ${JSON.stringify(parsedData, null, 2)}`) // Convert Buffer data to hex strings or utf8 strings. let tokenData = {} - if (parsedData.transactionType === "SEND") { + if (parsedData.transactionType === 'SEND') { tokenData = { tokenType: parsedData.tokenType, txType: parsedData.transactionType, - tokenId: parsedData.data.tokenId.toString("hex"), + tokenId: parsedData.data.tokenId.toString('hex'), amounts: parsedData.data.amounts } - } else if (parsedData.transactionType === "GENESIS") { + } else if (parsedData.transactionType === 'GENESIS') { tokenData = { tokenType: parsedData.tokenType, txType: parsedData.transactionType, @@ -976,11 +981,11 @@ class Utils { mintBatonVout: parsedData.data.mintBatonVout, qty: parsedData.data.qty } - } else if (parsedData.transactionType === "MINT") { + } else if (parsedData.transactionType === 'MINT') { tokenData = { tokenType: parsedData.tokenType, txType: parsedData.transactionType, - tokenId: parsedData.data.tokenId.toString("hex"), + tokenId: parsedData.data.tokenId.toString('hex'), mintBatonVout: parsedData.data.mintBatonVout, qty: parsedData.data.qty } @@ -1054,14 +1059,14 @@ class Utils { // https://github.com/Bitcoin-com/slp-sdk/issues/84 // CT 5/31/20: Refactored to use slp-parse library. - async tokenUtxoDetails(utxos) { + async tokenUtxoDetails (utxos) { try { // utxo list may have duplicate tx_hash, varying tx_pos // only need to call decodeOpReturn once for those const decodeOpReturnCache = {} const cachedTxValidation = {} // Throw error if input is not an array. - if (!Array.isArray(utxos)) throw new Error("Input must be an array.") + if (!Array.isArray(utxos)) throw new Error('Input must be an array.') // Loop through each element in the array and validate the input before // further processing. @@ -1072,9 +1077,8 @@ class Utils { // If Electrumx, convert the value to satoshis. if (utxo.value) { utxo.satoshis = utxo.value - } - // If there is neither a satoshis or value property, throw an error. - else { + } else { + // If there is neither a satoshis or value property, throw an error. throw new Error( `utxo ${i} does not have a satoshis or value property.` ) @@ -1085,9 +1089,8 @@ class Utils { // If Electrumx, convert the tx_hash property to txid. if (utxo.tx_hash) { utxo.txid = utxo.tx_hash - } - // If there is neither a txid or tx_hash property, throw an error. - else { + } else { + // If there is neither a txid or tx_hash property, throw an error. throw new Error( `utxo ${i} does not have a txid or tx_hash property.` ) @@ -1128,9 +1131,9 @@ class Utils { // to display the unknown state. if ( !err.message || - (err.message.indexOf("scriptpubkey not op_return") === -1 && - err.message.indexOf("lokad id") === -1 && - err.message.indexOf("trailing data") === -1) + (err.message.indexOf('scriptpubkey not op_return') === -1 && + err.message.indexOf('lokad id') === -1 && + err.message.indexOf('trailing data') === -1) ) { // console.log( // `unknown error from decodeOpReturn(). Marking as 'null'`, @@ -1159,7 +1162,7 @@ class Utils { // If there is an OP_RETURN, attempt to decode it. // Handle Genesis SLP transactions. - if (txType === "genesis") { + if (txType === 'genesis') { if ( utxo.vout !== slpData.mintBatonVout && // UTXO is not a mint baton output. utxo.vout !== 1 // UTXO is not the reciever of the genesis or mint tokens. @@ -1168,17 +1171,15 @@ class Utils { // outAry[i] = false utxo.isValid = false outAry[i] = utxo - } - - // If this is a valid SLP UTXO, then return the decoded OP_RETURN data. - else { + } else { + // If this is a valid SLP UTXO, then return the decoded OP_RETURN data. // Minting Baton if (utxo.vout === slpData.mintBatonVout) { - utxo.utxoType = "minting-baton" - } - // Tokens - else { - utxo.utxoType = "token" + utxo.utxoType = 'minting-baton' + } else { + // Tokens + + utxo.utxoType = 'token' utxo.tokenQty = new BigNumber(slpData.qty) .div(Math.pow(10, slpData.decimals)) .toString() @@ -1198,7 +1199,7 @@ class Utils { } // Handle Mint SLP transactions. - if (txType === "mint") { + if (txType === 'mint') { if ( utxo.vout !== slpData.mintBatonVout && // UTXO is not a mint baton output. utxo.vout !== 1 // UTXO is not the reciever of the genesis or mint tokens. @@ -1207,10 +1208,9 @@ class Utils { // outAry[i] = false utxo.isValid = false outAry[i] = utxo - } + } else { + // If UTXO passes validation, then return formatted token data. - // If UTXO passes validation, then return formatted token data. - else { const genesisData = await this.decodeOpReturn( slpData.tokenId, decodeOpReturnCache @@ -1219,18 +1219,18 @@ class Utils { // Minting Baton if (utxo.vout === slpData.mintBatonVout) { - utxo.utxoType = "minting-baton" - } - // Tokens - else { - utxo.utxoType = "token" + utxo.utxoType = 'minting-baton' + } else { + // Tokens + + utxo.utxoType = 'token' utxo.tokenQty = new BigNumber(slpData.qty) .div(Math.pow(10, genesisData.decimals)) .toString() } // Hydrate the UTXO object with information about the SLP token. - utxo.transactionType = "mint" + utxo.transactionType = 'mint' utxo.tokenId = slpData.tokenId utxo.tokenType = slpData.tokenType @@ -1247,7 +1247,7 @@ class Utils { } // Handle Send SLP transactions. - if (txType === "send") { + if (txType === 'send') { // Filter out any vouts that match. // const voutMatch = slpData.spendData.filter(x => utxo.vout === x.vout) // console.log(`voutMatch: ${JSON.stringify(voutMatch, null, 2)}`) @@ -1260,10 +1260,9 @@ class Utils { // outAry[i] = false utxo.isValid = false outAry[i] = utxo - } + } else { + // If UTXO passes validation, then return formatted token data. - // If UTXO passes validation, then return formatted token data. - else { const genesisData = await this.decodeOpReturn( slpData.tokenId, decodeOpReturnCache @@ -1273,8 +1272,8 @@ class Utils { // console.log(`utxo: ${JSON.stringify(utxo, null, 2)}`) // Hydrate the UTXO object with information about the SLP token. - utxo.utxoType = "token" - utxo.transactionType = "send" + utxo.utxoType = 'token' + utxo.transactionType = 'send' utxo.tokenId = slpData.tokenId utxo.tokenTicker = genesisData.ticker utxo.tokenName = genesisData.name @@ -1288,7 +1287,7 @@ class Utils { const tokenQtyBig = new BigNumber(tokenQty).div( Math.pow(10, genesisData.decimals) ) - //console.log(`tokenQtyBig`, tokenQtyBig.toString()) + // console.log(`tokenQtyBig`, tokenQtyBig.toString()) utxo.tokenQty = tokenQtyBig.toString() // console.log(`utxo: ${JSON.stringify(utxo, null, 2)}`) @@ -1315,8 +1314,8 @@ class Utils { // correctly, then validateTxid() will return this: // isValid: [ // { - // "txid": "ff0c0354f8d3ddb34fa36f73494eb58ea24f8b8da6904aa8ed43b7a74886c583", - // "valid": true + // "txid": "ff0c0354f8d3ddb34fa36f73494eb58ea24f8b8da6904aa8ed43b7a74886c583", + // "valid": true // } // ] // @@ -1337,8 +1336,9 @@ class Utils { // ) // Handle corner case where SLPDB returns an array with a null element. - if (isValid[0] === null) + if (isValid[0] === null) { isValid = [{ txid: utxo.txid, valid: null }] + } isValid = isValid[0].valid @@ -1593,10 +1593,10 @@ class Utils { */ // Same as tokenUtxoDetails(), but reduces API calls by having bch-api server // do the heavy lifting. - async hydrateUtxos(utxos) { + async hydrateUtxos (utxos) { try { // Throw error if input is not an array. - if (!Array.isArray(utxos)) throw new Error("Input must be an array.") + if (!Array.isArray(utxos)) throw new Error('Input must be an array.') const response = await _this.axios.post( `${this.restURL}slp/hydrateUtxos`, @@ -1639,7 +1639,7 @@ class Utils { * valid: true } ] * */ - async getStatus(txid) { + async getStatus (txid) { const path = `${this.restURL}slp/status` try { diff --git a/src/socket.js b/src/socket.js index 7151088..313bd6c 100644 --- a/src/socket.js +++ b/src/socket.js @@ -1,15 +1,15 @@ -const io = require("socket.io-client") +const io = require('socket.io-client') class Socket { - constructor(config = {}) { - if (typeof config === "string") { + constructor (config = {}) { + if (typeof config === 'string') { // TODO remove this check in v2.0 this.socket = io(`${config}`) } else { if (config.restURL) { this.socket = io(`${config.restURL}`) } else { - const restURL = "https://rest.bitcoin.com" + const restURL = 'https://rest.bitcoin.com' this.socket = io(`${restURL}`) } @@ -17,12 +17,11 @@ class Socket { } } - listen(endpoint, cb) { + listen (endpoint, cb) { this.socket.emit(endpoint) - if (endpoint === "blocks") this.socket.on("blocks", msg => cb(msg)) - else if (endpoint === "transactions") - this.socket.on("transactions", msg => cb(msg)) + if (endpoint === 'blocks') this.socket.on('blocks', msg => cb(msg)) + else if (endpoint === 'transactions') { this.socket.on('transactions', msg => cb(msg)) } } } diff --git a/src/transaction-builder.js b/src/transaction-builder.js index ab15f0a..a2ca33e 100644 --- a/src/transaction-builder.js +++ b/src/transaction-builder.js @@ -1,18 +1,16 @@ -const Bitcoin = require("@psf/bitcoincashjs-lib") -const coininfo = require("@psf/coininfo") -const bip66 = require("bip66") -const bip68 = require("bc-bip68") +const Bitcoin = require('@psf/bitcoincashjs-lib') +const coininfo = require('@psf/coininfo') +const bip66 = require('bip66') +const bip68 = require('bc-bip68') class TransactionBuilder { - static setAddress(address) { + static setAddress (address) { TransactionBuilder._address = address } - constructor(network = "mainnet") { + constructor (network = 'mainnet') { let bitcoincash - if (network === "bitcoincash" || network === "mainnet") - bitcoincash = coininfo.bitcoincash.main - else bitcoincash = coininfo.bitcoincash.test + if (network === 'bitcoincash' || network === 'mainnet') { bitcoincash = coininfo.bitcoincash.main } else bitcoincash = coininfo.bitcoincash.test const bitcoincashBitcoinJSLib = bitcoincash.toBitcoinJS() this.transaction = new Bitcoin.TransactionBuilder(bitcoincashBitcoinJSLib) @@ -33,7 +31,7 @@ class TransactionBuilder { this.bip66 = bip66 this.bip68 = bip68 this.p2shInput = false - this.tx + // this.tx } /** @@ -48,23 +46,24 @@ class TransactionBuilder { * // add input with txid and index of vout * transactionBuilder.addInput(txid, 0); */ - addInput(txHash, vout, sequence = this.DEFAULT_SEQUENCE, prevOutScript) { + addInput (txHash, vout, sequence = this.DEFAULT_SEQUENCE, prevOutScript) { this.transaction.addInput(txHash, vout, sequence, prevOutScript) } - addInputScript(vout, script) { + addInputScript (vout, script) { this.tx = this.transaction.buildIncomplete() this.tx.setInputScript(vout, script) this.p2shInput = true } - addInputScripts(scripts) { + addInputScripts (scripts) { this.tx = this.transaction.buildIncomplete() scripts.forEach(script => { this.tx.setInputScript(script.vout, script.script) }) this.p2shInput = true } + /** * @api Transaction-Builder.addOutput() addOutput() * @apiName AddOutput @@ -79,7 +78,7 @@ class TransactionBuilder { * // add output w/ address and amount to send * transactionBuilder.addOutput('bitcoincash:qpuax2tarq33f86wccwlx8ge7tad2wgvqgjqlwshpw', sendAmount); */ - addOutput(scriptPubKey, amount) { + addOutput (scriptPubKey, amount) { try { this.transaction.addOutput( TransactionBuilder._address.toLegacyAddress(scriptPubKey), @@ -89,6 +88,7 @@ class TransactionBuilder { this.transaction.addOutput(scriptPubKey, amount) } } + /** * @api Transaction-Builder.setLockTime() setLockTime() * @apiName SetLockTime @@ -104,9 +104,10 @@ class TransactionBuilder { * transactionBuilder.addOutput('bitcoincash:qpuax2tarq33f86wccwlx8ge7tad2wgvqgjqlwshpw', sendAmount); * transactionBuilder.setLockTime(50000) */ - setLockTime(locktime) { + setLockTime (locktime) { this.transaction.setLockTime(locktime) } + /** * @api Transaction-Builder.sign() sign() * @apiName Sign. @@ -124,7 +125,7 @@ class TransactionBuilder { * // sign w/ keyPair * transactionBuilder.sign(0, keyPair, redeemScript, transactionBuilder.hashTypes.SIGHASH_ALL, originalAmount, transactionBuilder.signatureAlgorithms.SCHNORR); */ - sign( + sign ( vin, keyPair, redeemScript, @@ -144,6 +145,7 @@ class TransactionBuilder { signatureAlgorithm ) } + /** * @api Transaction-Builder.build() build() * @apiName Build. @@ -154,7 +156,7 @@ class TransactionBuilder { * // build tx * let tx = bchjs.transactionBuilder.build(); */ - build() { + build () { if (this.p2shInput === true) return this.tx return this.transaction.build() diff --git a/src/util.js b/src/util.js index ce3eab2..ab1a675 100644 --- a/src/util.js +++ b/src/util.js @@ -1,9 +1,9 @@ -const axios = require("axios") +const axios = require('axios') let _this class Util { - constructor(config) { + constructor (config) { this.restURL = config.restURL this.apiToken = config.apiToken this.authToken = config.authToken @@ -72,10 +72,10 @@ class Util { * // iscompressed: true, * // account: 'Test' }] */ - async validateAddress(address) { + async validateAddress (address) { try { // Single block - if (typeof address === "string") { + if (typeof address === 'string') { const response = await axios.get( `${this.restURL}util/validateAddress/${address}`, _this.axiosOptions @@ -85,7 +85,7 @@ class Util { // Array of blocks. } else if (Array.isArray(address)) { const options = { - method: "POST", + method: 'POST', url: `${this.restURL}util/validateAddress`, data: { addresses: address @@ -99,7 +99,7 @@ class Util { return response.data } - throw new Error(`Input must be a string or array of strings.`) + throw new Error('Input must be a string or array of strings.') } catch (error) { if (error.response && error.response.data) throw error.response.data else throw error diff --git a/test/e2e/bch-js-e2e-tests.js b/test/e2e/bch-js-e2e-tests.js index 63f4a00..819af6d 100644 --- a/test/e2e/bch-js-e2e-tests.js +++ b/test/e2e/bch-js-e2e-tests.js @@ -2,17 +2,17 @@ A Mocha test file for running end-to-end (e2e) tests. */ -//const mocha = require("mocha") -const assert = require("chai").assert +// const mocha = require("mocha") +const assert = require('chai').assert -const sendToken = require("./send-token/send-token") +const sendToken = require('./send-token/send-token') -describe("#end-to-end tests", () => { - describe("#send-tokens", () => { - it("SLPDB should update balances in less than 10 seconds", async () => { +describe('#end-to-end tests', () => { + describe('#send-tokens', () => { + it('SLPDB should update balances in less than 10 seconds', async () => { const result = await sendToken.sendTokenTest() - assert(result, true, "True expected if test passed successfully.") + assert(result, true, 'True expected if test passed successfully.') }) }) }) diff --git a/test/e2e/ipfs/ipfs-e2e.js b/test/e2e/ipfs/ipfs-e2e.js index 7111a5e..8e4527e 100644 --- a/test/e2e/ipfs/ipfs-e2e.js +++ b/test/e2e/ipfs/ipfs-e2e.js @@ -3,15 +3,15 @@ IPFS is working. */ -process.env.IPFS_API = `http://localhost:5001` +process.env.IPFS_API = 'http://localhost:5001' // process.env.IPFS_API = `https://ipfs-api.fullstack.cash` -const BCHJS = require("../../../src/bch-js") +const BCHJS = require('../../../src/bch-js') const bchjs = new BCHJS() -describe(`#IPFS`, () => { - it("should upload a file to the server", async () => { - const path = `${__dirname}/ipfs-e2e.js` +describe('#IPFS', () => { + it('should upload a file to the server', async () => { + const path = `${__dirname.toString()}/ipfs-e2e.js` const fileModel = await bchjs.IPFS.createFileModel(path) console.log(`fileModel: ${JSON.stringify(fileModel, null, 2)}`) diff --git a/test/e2e/rate-limits/anonymous-rate-limits.js b/test/e2e/rate-limits/anonymous-rate-limits.js index 4c2585c..5e7e619 100644 --- a/test/e2e/rate-limits/anonymous-rate-limits.js +++ b/test/e2e/rate-limits/anonymous-rate-limits.js @@ -12,37 +12,37 @@ mocha --timeout=30000 anonymous-rate-limits.js */ -const assert = require("chai").assert +const assert = require('chai').assert // const RESTURL = `https://abc.fullstack.cash/v4/` -const RESTURL = `https://bchn.fullstack.cash/v4/` +const RESTURL = 'https://bchn.fullstack.cash/v4/' // const RESTURL = `http://localhost:3000/v4/` -const BCHJS = require("../../../src/bch-js") +const BCHJS = require('../../../src/bch-js') const bchjs = new BCHJS({ restURL: RESTURL }) -describe("#anonymous rate limits", () => { - it("should allow an anonymous call to a full node endpoint", async () => { +describe('#anonymous rate limits', () => { + it('should allow an anonymous call to a full node endpoint', async () => { const result = await bchjs.Control.getNetworkInfo() - assert.property(result, "version") + assert.property(result, 'version') }).timeout(5000) - it("should allow an anonymous call to an indexer", async () => { - const addr = "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf" + it('should allow an anonymous call to an indexer', async () => { + const addr = 'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf' const result = await bchjs.Electrumx.balance(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "balance") + assert.property(result, 'balance') }).timeout(5000) - it("should throw error when rate limit exceeded", async () => { + it('should throw error when rate limit exceeded', async () => { try { for (let i = 0; i < 35; i++) await bchjs.Control.getNetworkInfo() - assert.fail("Unexpected result") + assert.fail('Unexpected result') } catch (err) { - assert.include(err.error, "Too many requests") + assert.include(err.error, 'Too many requests') } }).timeout(20000) }) diff --git a/test/e2e/rate-limits/basic-auth-rate-limits.js b/test/e2e/rate-limits/basic-auth-rate-limits.js index 958d1a8..9166dc0 100644 --- a/test/e2e/rate-limits/basic-auth-rate-limits.js +++ b/test/e2e/rate-limits/basic-auth-rate-limits.js @@ -7,49 +7,49 @@ - Update the PRO_PASS value with a current PRO_PASSES string used by bch-api. */ -const assert = require("chai").assert +const assert = require('chai').assert -const PRO_PASS = "testpassword" +const PRO_PASS = 'testpassword' -const BCHJS = require("../../../src/bch-js") +const BCHJS = require('../../../src/bch-js') const bchjs = new BCHJS({ // restURL: `https://bchn.fullstack.cash/v4/`, - restURL: `https://abc.fullstack.cash/v4/`, + restURL: 'https://abc.fullstack.cash/v4/', // restURL: `http://localhost:3000/v4/`, authPass: PRO_PASS }) -describe("#Basic Authentication rate limits", () => { - it("should allow more than 20 RPM to full node", async () => { +describe('#Basic Authentication rate limits', () => { + it('should allow more than 20 RPM to full node', async () => { for (let i = 0; i < 22; i++) { const result = await bchjs.Control.getNetworkInfo() if (i === 5) { // console.log(`validating 5th call: ${i}`) - assert.property(result, "version", "more than 3 calls allowed") + assert.property(result, 'version', 'more than 3 calls allowed') } if (i === 15) { // console.log(`validating 5th call: ${i}`) - assert.property(result, "version", "more than 10 calls allowed") + assert.property(result, 'version', 'more than 10 calls allowed') } } }).timeout(45000) - it("should allow more than 20 RPM to an indexer", async () => { - const addr = "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf" + it('should allow more than 20 RPM to an indexer', async () => { + const addr = 'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf' for (let i = 0; i < 22; i++) { const result = await bchjs.Blockbook.balance(addr) if (i === 5) { // console.log(`validating 5th call: ${i}`) - assert.property(result, "balance", "more than 3 calls allowed") + assert.property(result, 'balance', 'more than 3 calls allowed') } if (i === 15) { // console.log(`validating 5th call: ${i}`) - assert.property(result, "balance", "more than 10 calls allowed") + assert.property(result, 'balance', 'more than 10 calls allowed') } } }).timeout(45000) diff --git a/test/e2e/rate-limits/free-rate-limits.js b/test/e2e/rate-limits/free-rate-limits.js index e540be5..65b8573 100644 --- a/test/e2e/rate-limits/free-rate-limits.js +++ b/test/e2e/rate-limits/free-rate-limits.js @@ -11,59 +11,59 @@ - Update the JWT_TOKEN value with a current free-level JWT token. */ -const assert = require("chai").assert +const assert = require('chai').assert const JWT_TOKEN = - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlODhhY2YyMDIyMWMxMDAxMmFkOTQwMSIsImVtYWlsIjoiZGVtb0BkZW1vLmNvbSIsImFwaUxldmVsIjoxMCwicmF0ZUxpbWl0IjozLCJpYXQiOjE2MDQ4NTQ2OTEsImV4cCI6MTYwNzQ0NjY5MX0.iwse0z0KDKHx9graCxcOwj6lSlfKQAb1zLhmjvygvts" + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlODhhY2YyMDIyMWMxMDAxMmFkOTQwMSIsImVtYWlsIjoiZGVtb0BkZW1vLmNvbSIsImFwaUxldmVsIjoxMCwicmF0ZUxpbWl0IjozLCJpYXQiOjE2MDQ4NTQ2OTEsImV4cCI6MTYwNzQ0NjY5MX0.iwse0z0KDKHx9graCxcOwj6lSlfKQAb1zLhmjvygvts' -const BCHJS = require("../../../src/bch-js") +const BCHJS = require('../../../src/bch-js') const bchjs = new BCHJS({ - restURL: `https://api.fullstack.cash/v4/`, + restURL: 'https://api.fullstack.cash/v4/', // restURL: `http://localhost:3000/v4/`, apiToken: JWT_TOKEN }) -describe("#free rate limits", () => { - it("should allow an free call to an indexer", async () => { - const addr = "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf" +describe('#free rate limits', () => { + it('should allow an free call to an indexer', async () => { + const addr = 'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf' const result = await bchjs.Blockbook.balance(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "balance") + assert.property(result, 'balance') }).timeout(5000) - it("should allow up to 10 RPM to indexer, then throw error", async () => { + it('should allow up to 10 RPM to indexer, then throw error', async () => { try { - const addr = "bitcoincash:qrehqueqhw629p6e57994436w730t4rzasnly00ht0" + const addr = 'bitcoincash:qrehqueqhw629p6e57994436w730t4rzasnly00ht0' for (let i = 0; i < 15; i++) { const result = await await bchjs.Blockbook.balance(addr) if (i === 5) { // console.log(`validating 5th call: ${i}`) - assert.property(result, "address", "more than 3 calls allowed") + assert.property(result, 'address', 'more than 3 calls allowed') } } } catch (err) { // console.log(`err: `, err) assert.include( err.error, - "currently 10 requests", - "more than 10 not allowed" + 'currently 10 requests', + 'more than 10 not allowed' ) assert.include(err.error, 10) assert.notInclude(err.error, 3) } }).timeout(20000) - it("should allow up to 10 RPM to full node, then throw error", async () => { + it('should allow up to 10 RPM to full node, then throw error', async () => { try { for (let i = 0; i < 15; i++) { const result = await bchjs.Control.getNetworkInfo() if (i === 5) { // console.log(`validating 5th call: ${i}`) - assert.property(result, "version", "more than 3 calls allowed") + assert.property(result, 'version', 'more than 3 calls allowed') } } } catch (err) { @@ -71,22 +71,22 @@ describe("#free rate limits", () => { // console.log(`err: `, err) assert.include( err.error, - "currently 10 requests", - "more than 10 not allowed" + 'currently 10 requests', + 'more than 10 not allowed' ) assert.include(err.error, 10) assert.notInclude(err.error, 3) } }).timeout(20000) - it("should throw error when rate limit exceeded 20 RPM for indexer endpoints", async () => { + it('should throw error when rate limit exceeded 20 RPM for indexer endpoints', async () => { try { for (let i = 0; i < 22; i++) await bchjs.Control.getNetworkInfo() - assert.fail("unexpected result") + assert.fail('unexpected result') } catch (err) { // console.log(`err: `, err) - assert.include(err.error, "Too many requests") + assert.include(err.error, 'Too many requests') } }).timeout(20000) }) diff --git a/test/e2e/rate-limits/full-node-rate-limits.js b/test/e2e/rate-limits/full-node-rate-limits.js index 51d142a..879bbbd 100644 --- a/test/e2e/rate-limits/full-node-rate-limits.js +++ b/test/e2e/rate-limits/full-node-rate-limits.js @@ -11,26 +11,26 @@ - Update the JWT_TOKEN value with a paid tier JWT token. */ -const assert = require("chai").assert +const assert = require('chai').assert const JWT_TOKEN = - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlODhhY2JmMDIyMWMxMDAxMmFkOTNmZiIsImVtYWlsIjoiY2hyaXMudHJvdXRuZXJAZ21haWwuY29tIiwiYXBpTGV2ZWwiOjQwLCJyYXRlTGltaXQiOjMsImlhdCI6MTYwMzIyNzEwNCwiZXhwIjoxNjA1ODE5MTA0fQ.CV36grzdD36Ht3BwZGHG4XU40CVDzMRw9Ars1x1r27M" + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlODhhY2JmMDIyMWMxMDAxMmFkOTNmZiIsImVtYWlsIjoiY2hyaXMudHJvdXRuZXJAZ21haWwuY29tIiwiYXBpTGV2ZWwiOjQwLCJyYXRlTGltaXQiOjMsImlhdCI6MTYwMzIyNzEwNCwiZXhwIjoxNjA1ODE5MTA0fQ.CV36grzdD36Ht3BwZGHG4XU40CVDzMRw9Ars1x1r27M' -const BCHJS = require("../../../src/bch-js") +const BCHJS = require('../../../src/bch-js') const bchjs = new BCHJS({ // restURL: `https://bchn.fullstack.cash/v4/`, - restURL: `https:/abc.fullstack.cash/v4/`, + restURL: 'https:/abc.fullstack.cash/v4/', // restURL: `http://localhost:3000/v4/`, apiToken: JWT_TOKEN }) -describe("#full node rate limits", () => { - it("should allow an free call to an indexer", async () => { - const addr = "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf" +describe('#full node rate limits', () => { + it('should allow an free call to an indexer', async () => { + const addr = 'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf' const result = await bchjs.Electrumx.balance(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "balance") + assert.property(result, 'balance') }).timeout(5000) // CT 11/8/20: New rate limits make this test invalid. @@ -47,30 +47,30 @@ describe("#full node rate limits", () => { // } // }).timeout(10000) - it("should allow more than 20 RPM to full node", async () => { + it('should allow more than 20 RPM to full node', async () => { for (let i = 0; i < 22; i++) { const result = await bchjs.Control.getNetworkInfo() if (i === 5) { // console.log(`validating 5th call: ${i}`) - assert.property(result, "version", "more than 3 calls allowed") + assert.property(result, 'version', 'more than 3 calls allowed') } if (i === 15) { // console.log(`validating 5th call: ${i}`) - assert.property(result, "version", "more than 10 calls allowed") + assert.property(result, 'version', 'more than 10 calls allowed') } } }).timeout(20000) - it("should throw error for more than 100 RPM to fullnode", async () => { + it('should throw error for more than 100 RPM to fullnode', async () => { try { - console.log(`This test usually doesn't pass, because of latency.`) + console.log('This test usually doesn\'t pass, because of latency.') for (let i = 0; i < 100; i++) await bchjs.Control.getNetworkInfo() } catch (err) { // console.log(`validating after 10th call`) // console.log(`err: `, err) - assert.include(err.error, "Too many requests") + assert.include(err.error, 'Too many requests') assert.include(err.error, 100) } }).timeout(45000) diff --git a/test/e2e/rate-limits/indexer-rate-limits.js b/test/e2e/rate-limits/indexer-rate-limits.js index a17ee9e..6fe7f9a 100644 --- a/test/e2e/rate-limits/indexer-rate-limits.js +++ b/test/e2e/rate-limits/indexer-rate-limits.js @@ -7,50 +7,50 @@ - Update the JWT_TOKEN value with a current indexer-level JWT token. */ -const assert = require("chai").assert +const assert = require('chai').assert const JWT_TOKEN = - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlODhhY2JmMDIyMWMxMDAxMmFkOTNmZiIsImVtYWlsIjoiY2hyaXMudHJvdXRuZXJAZ21haWwuY29tIiwiYXBpTGV2ZWwiOjQwLCJyYXRlTGltaXQiOjMsImlhdCI6MTYwMzIyNzEwNCwiZXhwIjoxNjA1ODE5MTA0fQ.CV36grzdD36Ht3BwZGHG4XU40CVDzMRw9Ars1x1r27M" + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlODhhY2JmMDIyMWMxMDAxMmFkOTNmZiIsImVtYWlsIjoiY2hyaXMudHJvdXRuZXJAZ21haWwuY29tIiwiYXBpTGV2ZWwiOjQwLCJyYXRlTGltaXQiOjMsImlhdCI6MTYwMzIyNzEwNCwiZXhwIjoxNjA1ODE5MTA0fQ.CV36grzdD36Ht3BwZGHG4XU40CVDzMRw9Ars1x1r27M' -const BCHJS = require("../../../src/bch-js") +const BCHJS = require('../../../src/bch-js') const bchjs = new BCHJS({ // restURL: `https://bchn.fullstack.cash/v4/`, - restURL: `https://abc.fullstack.cash/v4/`, + restURL: 'https://abc.fullstack.cash/v4/', // restURL: `http://localhost:3000/v4/`, apiToken: JWT_TOKEN }) -describe("#Indexer rate limits", () => { - it("should allow more than 20 RPM to full node", async () => { +describe('#Indexer rate limits', () => { + it('should allow more than 20 RPM to full node', async () => { for (let i = 0; i < 22; i++) { const result = await bchjs.Control.getNetworkInfo() if (i === 5) { // console.log(`validating 5th call: ${i}`) - assert.property(result, "version", "more than 3 calls allowed") + assert.property(result, 'version', 'more than 3 calls allowed') } if (i === 15) { // console.log(`validating 5th call: ${i}`) - assert.property(result, "version", "more than 10 calls allowed") + assert.property(result, 'version', 'more than 10 calls allowed') } } }).timeout(45000) - it("should allow more than 20 RPM to an indexer", async () => { - const addr = "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf" + it('should allow more than 20 RPM to an indexer', async () => { + const addr = 'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf' for (let i = 0; i < 22; i++) { const result = await bchjs.Electrumx.balance(addr) if (i === 5) { // console.log(`validating 5th call: ${i}`) - assert.property(result, "balance", "more than 3 calls allowed") + assert.property(result, 'balance', 'more than 3 calls allowed') } if (i === 15) { // console.log(`validating 5th call: ${i}`) - assert.property(result, "balance", "more than 10 calls allowed") + assert.property(result, 'balance', 'more than 10 calls allowed') } } }).timeout(45000) diff --git a/test/e2e/send-raw-transaction-bulk/sendrawtransaction.js b/test/e2e/send-raw-transaction-bulk/sendrawtransaction.js index 6f45ecc..4a99c92 100644 --- a/test/e2e/send-raw-transaction-bulk/sendrawtransaction.js +++ b/test/e2e/send-raw-transaction-bulk/sendrawtransaction.js @@ -13,24 +13,25 @@ */ // Replace the address below with the address you want to send the BCH to. -const RECV_ADDR1 = `bchtest:qzfn2mly05t6fjsh5kjj0dqq0jjtct27ng089dgg05` -const RECV_ADDR2 = `bchtest:qz6yw0kqgfkknfy6jh2jvlfnkzmre3lt2u0pgcckdk` +const RECV_ADDR1 = 'bchtest:qzfn2mly05t6fjsh5kjj0dqq0jjtct27ng089dgg05' +const RECV_ADDR2 = 'bchtest:qz6yw0kqgfkknfy6jh2jvlfnkzmre3lt2u0pgcckdk' const SATOSHIS_TO_SEND = 1000 // Instantiate BITBOX. -const bitboxLib = "../../../lib/BITBOX" +const bitboxLib = '../../../lib/BITBOX' const BITBOXSDK = require(bitboxLib) -const BITBOX = new BITBOXSDK({ restURL: "https://trest.bitcoin.com/v2/" }) -//const BITBOX = new BITBOXSDK({ restURL: "http://localhost:3000/v2/" }) +const BITBOX = new BITBOXSDK({ restURL: 'https://trest.bitcoin.com/v2/' }) +// const BITBOX = new BITBOXSDK({ restURL: "http://localhost:3000/v2/" }) -const util = require("util") +// const util = require('util') // Open the wallet generated with create-wallet. +let walletInfo = {} try { - var walletInfo = require(`./wallet.json`) + walletInfo = require('./wallet.json') } catch (err) { console.log( - `Could not open wallet.json. Generate a wallet with create-wallet first.` + 'Could not open wallet.json. Generate a wallet with create-wallet first.' ) process.exit(0) } @@ -38,7 +39,7 @@ try { const SEND_ADDR = walletInfo.cashAddress const SEND_MNEMONIC = walletInfo.mnemonic -async function testSend() { +async function testSend () { try { const hex1 = await buildTx1(RECV_ADDR1) const hex2 = await buildTx2(RECV_ADDR2) @@ -51,15 +52,15 @@ async function testSend() { hex2 ]) console.log(`Transaction IDs: ${JSON.stringify(broadcast, null, 2)}`) - console.log(`Should return an array of TXID strings.`) + console.log('Should return an array of TXID strings.') } catch (err) { - console.log(`Error in testSend: `, err) + console.log('Error in testSend: ', err) } } testSend() // Build a TX hex with the largest UTXO. -async function buildTx1(recAddr) { +async function buildTx1 (recAddr) { try { // Get the balance of the sending address. const balance = await getBCHBalance(SEND_ADDR, false) @@ -68,7 +69,7 @@ async function buildTx1(recAddr) { // Exit if the balance is zero. if (balance <= 0.0) { - console.log(`Balance of sending address is zero. Exiting.`) + console.log('Balance of sending address is zero. Exiting.') process.exit(0) } @@ -77,16 +78,17 @@ async function buildTx1(recAddr) { console.log(`Sender Legacy Address: ${SEND_ADDR_LEGACY}`) console.log(`Receiver Legacy Address: ${RECV_ADDR_LEGACY}`) - const balance2 = await getBCHBalance(recAddr, false) - //console.log(`Balance of recieving address ${recAddr} is ${balance2} BCH.`) + // const balance2 = await getBCHBalance(recAddr, false) + // console.log(`Balance of recieving address ${recAddr} is ${balance2} BCH.`) + await getBCHBalance(recAddr, false) const u = await BITBOX.Address.utxo(SEND_ADDR) - //console.log(`u: ${JSON.stringify(u, null, 2)}`) + // console.log(`u: ${JSON.stringify(u, null, 2)}`) const utxo = findBiggestUtxo(u.utxos) console.log(`utxo: ${JSON.stringify(utxo, null, 2)}`) // instance of transaction builder - const transactionBuilder = new BITBOX.TransactionBuilder("testnet") + const transactionBuilder = new BITBOX.TransactionBuilder('testnet') const satoshisToSend = SATOSHIS_TO_SEND const originalAmount = utxo.satoshis @@ -137,13 +139,13 @@ async function buildTx1(recAddr) { return hex } catch (err) { - console.log(`Error in buildTx().`) + console.log('Error in buildTx().') throw err } } // Build a TX hex with the SECOND largest UTXO. -async function buildTx2(recAddr) { +async function buildTx2 (recAddr) { try { // Get the balance of the sending address. const balance = await getBCHBalance(SEND_ADDR, false) @@ -152,7 +154,7 @@ async function buildTx2(recAddr) { // Exit if the balance is zero. if (balance <= 0.0) { - console.log(`Balance of sending address is zero. Exiting.`) + console.log('Balance of sending address is zero. Exiting.') process.exit(0) } @@ -161,16 +163,17 @@ async function buildTx2(recAddr) { console.log(`Sender Legacy Address: ${SEND_ADDR_LEGACY}`) console.log(`Receiver Legacy Address: ${RECV_ADDR_LEGACY}`) - const balance2 = await getBCHBalance(recAddr, false) - //console.log(`Balance of recieving address ${recAddr} is ${balance2} BCH.`) + // const balance2 = await getBCHBalance(recAddr, false) + // console.log(`Balance of recieving address ${recAddr} is ${balance2} BCH.`) + await getBCHBalance(recAddr, false) const u = await BITBOX.Address.utxo(SEND_ADDR) - //console.log(`u: ${JSON.stringify(u, null, 2)}`) + // console.log(`u: ${JSON.stringify(u, null, 2)}`) const utxo = findNextBiggestUtxo(u.utxos) console.log(`utxo: ${JSON.stringify(utxo, null, 2)}`) // instance of transaction builder - const transactionBuilder = new BITBOX.TransactionBuilder("testnet") + const transactionBuilder = new BITBOX.TransactionBuilder('testnet') const satoshisToSend = SATOSHIS_TO_SEND const originalAmount = utxo.satoshis @@ -221,30 +224,30 @@ async function buildTx2(recAddr) { return hex } catch (err) { - console.log(`Error in buildTx().`) + console.log('Error in buildTx().') throw err } } // Generate a change address from a Mnemonic of a private key. -function changeAddrFromMnemonic(mnemonic) { +function changeAddrFromMnemonic (mnemonic) { // root seed buffer const rootSeed = BITBOX.Mnemonic.toSeed(mnemonic) // master HDNode - const masterHDNode = BITBOX.HDNode.fromSeed(rootSeed, "testnet") + const masterHDNode = BITBOX.HDNode.fromSeed(rootSeed, 'testnet') // HDNode of BIP44 account const account = BITBOX.HDNode.derivePath(masterHDNode, "m/44'/145'/0'") // derive the first external change address HDNode which is going to spend utxo - const change = BITBOX.HDNode.derivePath(account, "0/0") + const change = BITBOX.HDNode.derivePath(account, '0/0') return change } // Get the balance in BCH of a BCH address. -async function getBCHBalance(addr, verbose) { +async function getBCHBalance (addr, verbose) { try { const result = await BITBOX.Address.details(addr) @@ -254,16 +257,16 @@ async function getBCHBalance(addr, verbose) { return bchBalance.balance } catch (err) { - console.error(`Error in getBCHBalance: `, err) + console.error('Error in getBCHBalance: ', err) console.log(`addr: ${addr}`) throw err } } // Returns the utxo with the biggest balance from an array of utxos. -function findBiggestUtxo(utxos) { +function findBiggestUtxo (utxos) { // Sort the utxos by the amount of satoshis, largest first. - utxos.sort(function(a, b) { + utxos.sort(function (a, b) { return b.satoshis - a.satoshis }) @@ -271,9 +274,9 @@ function findBiggestUtxo(utxos) { } // Returns the utxo with the 2nd biggest balance from an array of utxos. -function findNextBiggestUtxo(utxos) { +function findNextBiggestUtxo (utxos) { // Sort the utxos by the amount of satoshis, largest first. - utxos.sort(function(a, b) { + utxos.sort(function (a, b) { return b.satoshis - a.satoshis }) diff --git a/test/e2e/send-raw-transaction-single/sendrawtransaction.js b/test/e2e/send-raw-transaction-single/sendrawtransaction.js index 372baee..d7e48ca 100644 --- a/test/e2e/send-raw-transaction-single/sendrawtransaction.js +++ b/test/e2e/send-raw-transaction-single/sendrawtransaction.js @@ -13,23 +13,24 @@ */ // Replace the address below with the address you want to send the BCH to. -const RECV_ADDR1 = `bchtest:qzfn2mly05t6fjsh5kjj0dqq0jjtct27ng089dgg05` +const RECV_ADDR1 = 'bchtest:qzfn2mly05t6fjsh5kjj0dqq0jjtct27ng089dgg05' const SATOSHIS_TO_SEND = 1000 // Instantiate BITBOX. -const bitboxLib = "../../../lib/BITBOX" +const bitboxLib = '../../../lib/BITBOX' const BITBOXSDK = require(bitboxLib) -const BITBOX = new BITBOXSDK({ restURL: "https://trest.bitcoin.com/v2/" }) -//const BITBOX = new BITBOXSDK({ restURL: "http://localhost:3000/v2/" }) +const BITBOX = new BITBOXSDK({ restURL: 'https://trest.bitcoin.com/v2/' }) +// const BITBOX = new BITBOXSDK({ restURL: "http://localhost:3000/v2/" }) -const util = require("util") +// const util = require('util') // Open the wallet generated with create-wallet. +let walletInfo = {} try { - var walletInfo = require(`./wallet.json`) + walletInfo = require('./wallet.json') } catch (err) { console.log( - `Could not open wallet.json. Generate a wallet with create-wallet first.` + 'Could not open wallet.json. Generate a wallet with create-wallet first.' ) process.exit(0) } @@ -37,26 +38,26 @@ try { const SEND_ADDR = walletInfo.cashAddress const SEND_MNEMONIC = walletInfo.mnemonic -async function testSend() { +async function testSend () { try { const hex1 = await buildTx1(RECV_ADDR1) - //const hex2 = await buildTx2(RECV_ADDR2) + // const hex2 = await buildTx2(RECV_ADDR2) console.log(`hex1: ${hex1}\n\n`) - //console.log(`hex2: ${hex2}\n\n`) + // console.log(`hex2: ${hex2}\n\n`) const broadcast = await BITBOX.RawTransactions.sendRawTransaction(hex1) console.log(`Transaction IDs: ${JSON.stringify(broadcast, null, 2)}`) - console.log(`Should return a TXID string.`) + console.log('Should return a TXID string.') } catch (err) { - console.log(`Error in testSend: `, err) + console.log('Error in testSend: ', err) } } testSend() // Build a TX hex with the largest UTXO. -async function buildTx1(recAddr) { +async function buildTx1 (recAddr) { try { // Get the balance of the sending address. const balance = await getBCHBalance(SEND_ADDR, false) @@ -65,7 +66,7 @@ async function buildTx1(recAddr) { // Exit if the balance is zero. if (balance <= 0.0) { - console.log(`Balance of sending address is zero. Exiting.`) + console.log('Balance of sending address is zero. Exiting.') process.exit(0) } @@ -74,16 +75,17 @@ async function buildTx1(recAddr) { console.log(`Sender Legacy Address: ${SEND_ADDR_LEGACY}`) console.log(`Receiver Legacy Address: ${RECV_ADDR_LEGACY}`) - const balance2 = await getBCHBalance(recAddr, false) - //console.log(`Balance of recieving address ${recAddr} is ${balance2} BCH.`) + // const balance2 = await getBCHBalance(recAddr, false) + // console.log(`Balance of recieving address ${recAddr} is ${balance2} BCH.`) + await getBCHBalance(recAddr, false) const u = await BITBOX.Address.utxo(SEND_ADDR) - //console.log(`u: ${JSON.stringify(u, null, 2)}`) + // console.log(`u: ${JSON.stringify(u, null, 2)}`) const utxo = findBiggestUtxo(u.utxos) console.log(`utxo: ${JSON.stringify(utxo, null, 2)}`) // instance of transaction builder - const transactionBuilder = new BITBOX.TransactionBuilder("testnet") + const transactionBuilder = new BITBOX.TransactionBuilder('testnet') const satoshisToSend = SATOSHIS_TO_SEND const originalAmount = utxo.satoshis @@ -134,30 +136,30 @@ async function buildTx1(recAddr) { return hex } catch (err) { - console.log(`Error in buildTx().`) + console.log('Error in buildTx().') throw err } } // Generate a change address from a Mnemonic of a private key. -function changeAddrFromMnemonic(mnemonic) { +function changeAddrFromMnemonic (mnemonic) { // root seed buffer const rootSeed = BITBOX.Mnemonic.toSeed(mnemonic) // master HDNode - const masterHDNode = BITBOX.HDNode.fromSeed(rootSeed, "testnet") + const masterHDNode = BITBOX.HDNode.fromSeed(rootSeed, 'testnet') // HDNode of BIP44 account const account = BITBOX.HDNode.derivePath(masterHDNode, "m/44'/145'/0'") // derive the first external change address HDNode which is going to spend utxo - const change = BITBOX.HDNode.derivePath(account, "0/0") + const change = BITBOX.HDNode.derivePath(account, '0/0') return change } // Get the balance in BCH of a BCH address. -async function getBCHBalance(addr, verbose) { +async function getBCHBalance (addr, verbose) { try { const result = await BITBOX.Address.details(addr) @@ -167,16 +169,16 @@ async function getBCHBalance(addr, verbose) { return bchBalance.balance } catch (err) { - console.error(`Error in getBCHBalance: `, err) + console.error('Error in getBCHBalance: ', err) console.log(`addr: ${addr}`) throw err } } // Returns the utxo with the biggest balance from an array of utxos. -function findBiggestUtxo(utxos) { +function findBiggestUtxo (utxos) { // Sort the utxos by the amount of satoshis, largest first. - utxos.sort(function(a, b) { + utxos.sort(function (a, b) { return b.satoshis - a.satoshis }) diff --git a/test/e2e/send-token/send-token.js b/test/e2e/send-token/send-token.js index a40c094..12237bc 100644 --- a/test/e2e/send-token/send-token.js +++ b/test/e2e/send-token/send-token.js @@ -8,7 +8,7 @@ */ // Inspect utility used for debugging. -const util = require("util") +const util = require('util') util.inspect.defaultOptions = { showHidden: true, colors: true, @@ -18,22 +18,22 @@ util.inspect.defaultOptions = { // const SLPSDK = require("../../../lib/SLP") // const slpsdk = new SLPSDK() -const WALLET1 = `../wallet1.json` -const WALLET2 = `../wallet2.json` +const WALLET1 = '../wallet1.json' +const WALLET2 = '../wallet2.json' -const lib = require("../util/e2e-util") +const lib = require('../util/e2e-util') // The main test function. // Sends a token and reports on how long it takes to show up in SLPDB production. -async function sendTokenTest() { +async function sendTokenTest () { try { // Open the sending wallet. const sendWallet = await lib.openWallet(WALLET1) - //console.log(`sendWallet: ${JSON.stringify(walletInfo, null, 2)}`) + // console.log(`sendWallet: ${JSON.stringify(walletInfo, null, 2)}`) // Open the recieving wallet. const recvWallet = await lib.openWallet(WALLET2) - //console.log(`recvWallet: ${JSON.stringify(walletInfo, null, 2)}`) + // console.log(`recvWallet: ${JSON.stringify(walletInfo, null, 2)}`) // Get the balance of the recieving wallet. // const testTokens = recvWallet.tokenBalance.filter( @@ -46,7 +46,7 @@ async function sendTokenTest() { // Send a token to the recieving wallet. await lib.sendToken(sendWallet, recvWallet) - console.log(`Sent test token.`) + console.log('Sent test token.') // Track the time until the balance for the recieving wallet has been updated. const startTime = new Date() @@ -56,7 +56,7 @@ async function sendTokenTest() { for (let i = 0; i < 50; i++) { await sleep(waitTime) // Wait for a while before checking - console.log(`Checking token balance...`) + console.log('Checking token balance...') newBalance = await lib.getTestTokenBalance(recvWallet) // Break out of the loop once a new balance is detected. @@ -65,12 +65,12 @@ async function sendTokenTest() { // Provide high-level warnings. const secondsPassed = (i * waitTime) / 1000 if (secondsPassed > 60 * 10) { - console.log(`More than 10 minutes passed.`) + console.log('More than 10 minutes passed.') return false // Fail the test. } else if (secondsPassed > 60 * 5) { - console.log(`More than 5 minutes passed.`) + console.log('More than 5 minutes passed.') } else if (secondsPassed > 60) { - console.log(`More than 1 minute passed.`) + console.log('More than 1 minute passed.') } } @@ -85,13 +85,13 @@ async function sendTokenTest() { return deltaTime // Return the time in minutes it took for SLPDB to update. } catch (err) { - console.log(`Error in e2e/send-token.js/sendTokenTest(): `, err) + console.log('Error in e2e/send-token.js/sendTokenTest(): ', err) return false } } // Promise based sleep function. -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/e2e/util/e2e-util.js b/test/e2e/util/e2e-util.js index 56fac06..1b605cd 100644 --- a/test/e2e/util/e2e-util.js +++ b/test/e2e/util/e2e-util.js @@ -10,19 +10,19 @@ module.exports = { threeDecimals } -const SLPSDK = require("../../../lib/SLP") +const SLPSDK = require('../../../lib/SLP') const slpsdk = new SLPSDK() const testTokenId = - "cc1b2084a9c43bb5a633df7f38201adde5c5f5cef2fed945d12f8dcd4e505c67" + 'cc1b2084a9c43bb5a633df7f38201adde5c5f5cef2fed945d12f8dcd4e505c67' // Open a wallet and return an object with its address, BCH balance, and SLP // token balance. -async function openWallet(filename) { +async function openWallet (filename) { try { - walletInfo = require(filename) + const walletInfo = require(filename) - //const walletBalance = await getBalance(walletInfo) + // const walletBalance = await getBalance(walletInfo) // const walletBalance = await slpsdk.Utils.balancesForAddress( // walletInfo.slpAddress // ) @@ -40,7 +40,7 @@ async function openWallet(filename) { } // Send a token from wallet1 to wallet2. -async function sendToken(wallet1, wallet2) { +async function sendToken (wallet1, wallet2) { try { const mnemonic = wallet1.mnemonic @@ -53,11 +53,11 @@ async function sendToken(wallet1, wallet2) { // HDNode of BIP44 account const account = slpsdk.HDNode.derivePath(masterHDNode, "m/44'/145'/0'") - const change = slpsdk.HDNode.derivePath(account, "0/0") + const change = slpsdk.HDNode.derivePath(account, '0/0') // get the cash address - //const cashAddress = slpsdk.HDNode.toCashAddress(change) - //const slpAddress = slpsdk.HDNode.toSLPAddress(change) + // const cashAddress = slpsdk.HDNode.toCashAddress(change) + // const slpAddress = slpsdk.HDNode.toSLPAddress(change) const fundingAddress = wallet1.slpAddress const fundingWif = slpsdk.HDNode.toWIF(change) // <-- compressed WIF format @@ -71,25 +71,26 @@ async function sendToken(wallet1, wallet2) { tokenReceiverAddress, bchChangeReceiverAddress, tokenId: - "cc1b2084a9c43bb5a633df7f38201adde5c5f5cef2fed945d12f8dcd4e505c67", + 'cc1b2084a9c43bb5a633df7f38201adde5c5f5cef2fed945d12f8dcd4e505c67', amount: 1 } - //console.log(`createConfig: ${util.inspect(createConfig)}`) + // console.log(`createConfig: ${util.inspect(createConfig)}`) // Generate, sign, and broadcast a hex-encoded transaction for sending // the tokens. - const sendTxId = await slpsdk.TokenType1.send(sendConfig) + // const sendTxId = await slpsdk.TokenType1.send(sendConfig) + await slpsdk.TokenType1.send(sendConfig) - //console.log(`sendTxId: ${sendTxId}`) + // console.log(`sendTxId: ${sendTxId}`) } catch (err) { - console.log(`Error in e2e-util.js/sendToken()`) + console.log('Error in e2e-util.js/sendToken()') throw err } } // Returns just the test token balance for a wallet. -async function getTestTokenBalance(walletData) { +async function getTestTokenBalance (walletData) { try { const tokenBalance = await slpsdk.Util.balancesForAddress( walletData.slpAddress @@ -100,20 +101,20 @@ async function getTestTokenBalance(walletData) { return testTokens[0].balance } catch (err) { - console.log(`Error in e2e-util.js/getTestTokenBalance()`) + console.log('Error in e2e-util.js/getTestTokenBalance()') throw err } } // Round a number to three decimal places. -function threeDecimals(inNum) { +function threeDecimals (inNum) { try { let tempNum = inNum * 1000 tempNum = Math.round(tempNum) tempNum = tempNum / 1000 return tempNum } catch (err) { - console.log(`Error in e2e-util.js/threeDecimals()`) + console.log('Error in e2e-util.js/threeDecimals()') throw err } } diff --git a/test/integration/blockchain.js b/test/integration/blockchain.js index 6c339d2..3cdb90d 100644 --- a/test/integration/blockchain.js +++ b/test/integration/blockchain.js @@ -7,109 +7,109 @@ of an e2e test to be properly tested. */ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') const bchjs = new BCHJS() // Inspect utility used for debugging. -const util = require("util") +const util = require('util') util.inspect.defaultOptions = { showHidden: true, colors: true, depth: 3 } -describe(`#blockchain`, () => { +describe('#blockchain', () => { beforeEach(async () => { if (process.env.IS_USING_FREE_TIER) await sleep(1000) }) - describe(`#getBestBlockHash`, () => { - it(`should GET best block hash`, async () => { + describe('#getBestBlockHash', () => { + it('should GET best block hash', async () => { const result = await bchjs.Blockchain.getBestBlockHash() - //console.log(`result: ${util.inspect(result)}`) + // console.log(`result: ${util.inspect(result)}`) assert.isString(result) - assert.equal(result.length, 64, "Specific hash length") + assert.equal(result.length, 64, 'Specific hash length') }) }) - describe("#getBlockHeader", () => { - it(`should GET block header for a single hash`, async () => { + describe('#getBlockHeader', () => { + it('should GET block header for a single hash', async () => { const hash = - "000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201" + '000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201' const result = await bchjs.Blockchain.getBlockHeader(hash) assert.hasAllKeys(result, [ - "hash", - "confirmations", - "height", - "version", - "versionHex", - "merkleroot", - "time", - "mediantime", - "nonce", - "bits", - "difficulty", - "chainwork", - "previousblockhash", - "nextblockhash", - "nTx" + 'hash', + 'confirmations', + 'height', + 'version', + 'versionHex', + 'merkleroot', + 'time', + 'mediantime', + 'nonce', + 'bits', + 'difficulty', + 'chainwork', + 'previousblockhash', + 'nextblockhash', + 'nTx' ]) }) - it(`should GET block headers for an array of hashes`, async () => { + it('should GET block headers for an array of hashes', async () => { const hash = [ - "000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201", - "00000000000000000568f0a96bf4348847bc84e455cbfec389f27311037a20f3" + '000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201', + '00000000000000000568f0a96bf4348847bc84e455cbfec389f27311037a20f3' ] const result = await bchjs.Blockchain.getBlockHeader(hash) assert.isArray(result) assert.hasAllKeys(result[0], [ - "hash", - "confirmations", - "height", - "version", - "versionHex", - "merkleroot", - "time", - "mediantime", - "nonce", - "bits", - "difficulty", - "chainwork", - "previousblockhash", - "nextblockhash", - "nTx" + 'hash', + 'confirmations', + 'height', + 'version', + 'versionHex', + 'merkleroot', + 'time', + 'mediantime', + 'nonce', + 'bits', + 'difficulty', + 'chainwork', + 'previousblockhash', + 'nextblockhash', + 'nTx' ]) }) - it(`should throw error on array size rate limit`, async () => { + it('should throw error on array size rate limit', async () => { try { const data = [] for (let i = 0; i < 25; i++) { data.push( - "000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201" + '000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201' ) } const result = await bchjs.Blockchain.getBlockHeader(data) console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) - describe("#getMempoolEntry", () => { + describe('#getMempoolEntry', () => { /* // To run this test, the txid must be unconfirmed. const txid = @@ -161,77 +161,77 @@ describe(`#blockchain`, () => { }) */ - it(`should throw an error if txid is not in mempool`, async () => { + it('should throw an error if txid is not in mempool', async () => { try { const txid = - "03f69502ca32e7927fd4f38c1d3f950bff650c1eea3d09a70e9df5a9d7f989f7" + '03f69502ca32e7927fd4f38c1d3f950bff650c1eea3d09a70e9df5a9d7f989f7' await bchjs.Blockchain.getMempoolEntry(txid) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - //console.log(`err: ${util.inspect(err)}`) - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, `Transaction not in mempool`) + // console.log(`err: ${util.inspect(err)}`) + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Transaction not in mempool') } }) }) - describe(`#getTxOutProof`, () => { - it(`should get single tx out proof`, async () => { + describe('#getTxOutProof', () => { + it('should get single tx out proof', async () => { const txid = - "03f69502ca32e7927fd4f38c1d3f950bff650c1eea3d09a70e9df5a9d7f989f7" + '03f69502ca32e7927fd4f38c1d3f950bff650c1eea3d09a70e9df5a9d7f989f7' const result = await bchjs.Blockchain.getTxOutProof(txid) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isString(result) }) - it(`should get an array of tx out proofs`, async () => { + it('should get an array of tx out proofs', async () => { const txid = [ - "03f69502ca32e7927fd4f38c1d3f950bff650c1eea3d09a70e9df5a9d7f989f7", - "fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33" + '03f69502ca32e7927fd4f38c1d3f950bff650c1eea3d09a70e9df5a9d7f989f7', + 'fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33' ] const result = await bchjs.Blockchain.getTxOutProof(txid) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) assert.isString(result[0]) }) }) - describe(`#verifyTxOutProof`, () => { + describe('#verifyTxOutProof', () => { const mockTxOutProof = - "0000002086a4a3161f9ba2174883ec0b93acceac3b2f37b36ed1f90000000000000000009cb02406d1094ecf3e0b4c0ca7c585125e721147c39daf6b48c90b512741e13a12333e5cb38705180f441d8c7100000008fee9b60f1edb57e5712839186277ed39e0a004a32be9096ee47472efde8eae62f789f9d7a9f59d0ea7093dea1e0c65ff0b953f1d8cf3d47f92e732ca0295f603c272d5f4a63509f7a887f2549d78af7444aa0ecbb4f66d9cbe13bc6a89f59e05a199df8325d490818ffefe6b6321d32d7496a68580459836c0183f89082fc1b491cc91b23ecdcaa4c347bf599a62904d61f1c15b400ebbd5c90149010c139d9c1e31b774b796977393a238080ab477e1d240d0c4f155d36f519668f49bae6bd8cd5b8e40522edf76faa09cca6188d83ff13af6967cc6a569d1a5e9aeb1fdb7f531ddd2d0cbb81879741d5f38166ac1932136264366a4065cc96a42e41f96294f02df01" + '0000002086a4a3161f9ba2174883ec0b93acceac3b2f37b36ed1f90000000000000000009cb02406d1094ecf3e0b4c0ca7c585125e721147c39daf6b48c90b512741e13a12333e5cb38705180f441d8c7100000008fee9b60f1edb57e5712839186277ed39e0a004a32be9096ee47472efde8eae62f789f9d7a9f59d0ea7093dea1e0c65ff0b953f1d8cf3d47f92e732ca0295f603c272d5f4a63509f7a887f2549d78af7444aa0ecbb4f66d9cbe13bc6a89f59e05a199df8325d490818ffefe6b6321d32d7496a68580459836c0183f89082fc1b491cc91b23ecdcaa4c347bf599a62904d61f1c15b400ebbd5c90149010c139d9c1e31b774b796977393a238080ab477e1d240d0c4f155d36f519668f49bae6bd8cd5b8e40522edf76faa09cca6188d83ff13af6967cc6a569d1a5e9aeb1fdb7f531ddd2d0cbb81879741d5f38166ac1932136264366a4065cc96a42e41f96294f02df01' - it(`should verify a single proof`, async () => { + it('should verify a single proof', async () => { const result = await bchjs.Blockchain.verifyTxOutProof(mockTxOutProof) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) assert.isString(result[0]) assert.equal( result[0], - "03f69502ca32e7927fd4f38c1d3f950bff650c1eea3d09a70e9df5a9d7f989f7" + '03f69502ca32e7927fd4f38c1d3f950bff650c1eea3d09a70e9df5a9d7f989f7' ) }) - it(`should verify an array of proofs`, async () => { + it('should verify an array of proofs', async () => { const proofs = [mockTxOutProof, mockTxOutProof] const result = await bchjs.Blockchain.verifyTxOutProof(proofs) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) assert.isString(result[0]) assert.equal( result[0], - "03f69502ca32e7927fd4f38c1d3f950bff650c1eea3d09a70e9df5a9d7f989f7" + '03f69502ca32e7927fd4f38c1d3f950bff650c1eea3d09a70e9df5a9d7f989f7' ) }) - it(`should throw error on array size rate limit`, async () => { + it('should throw error on array size rate limit', async () => { try { const data = [] for (let i = 0; i < 25; i++) data.push(mockTxOutProof) @@ -239,35 +239,35 @@ describe(`#blockchain`, () => { const result = await bchjs.Blockchain.verifyTxOutProof(data) console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) - describe("#getTxOut", () => { - it("should get information on an unspent tx", async () => { + describe('#getTxOut', () => { + it('should get information on an unspent tx', async () => { const result = await bchjs.Blockchain.getTxOut( - "62a3ea958a463a372bc0caf2c374a7f60be9c624be63a0db8db78f05809df6d8", + '62a3ea958a463a372bc0caf2c374a7f60be9c624be63a0db8db78f05809df6d8', 0, true ) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.hasAllKeys(result, [ - "bestblock", - "confirmations", - "value", - "scriptPubKey", - "coinbase" + 'bestblock', + 'confirmations', + 'value', + 'scriptPubKey', + 'coinbase' ]) }) - it("should get information on a spent tx", async () => { + it('should get information on a spent tx', async () => { const result = await bchjs.Blockchain.getTxOut( - "87380e52d151856b23173d6d8a3db01b984c6b50f77ea045a5a1cf4f54497871", + '87380e52d151856b23173d6d8a3db01b984c6b50f77ea045a5a1cf4f54497871', 0, true ) @@ -278,6 +278,6 @@ describe(`#blockchain`, () => { }) }) -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/chains/abc/rawtransaction.js b/test/integration/chains/abc/rawtransaction.js index 66a2322..e383274 100644 --- a/test/integration/chains/abc/rawtransaction.js +++ b/test/integration/chains/abc/rawtransaction.js @@ -5,20 +5,20 @@ TODO */ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert -const BCHJS = require("../../../../src/bch-js") +const BCHJS = require('../../../../src/bch-js') const bchjs = new BCHJS() // Inspect utility used for debugging. -const util = require("util") +const util = require('util') util.inspect.defaultOptions = { showHidden: true, colors: true, depth: 3 } -describe("#rawtransaction", () => { +describe('#rawtransaction', () => { beforeEach(async () => { if (process.env.IS_USING_FREE_TIER) await sleep(1000) }) @@ -29,29 +29,29 @@ describe("#rawtransaction", () => { below expect error messages returned from the server, but at least test that the server is responding on those endpoints, and responds consistently. */ - describe("sendRawTransaction", () => { - it("should send a single transaction hex", async () => { + describe('sendRawTransaction', () => { + it('should send a single transaction hex', async () => { try { const hex = - "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000" + '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000' await bchjs.RawTransactions.sendRawTransaction(hex) - //console.log(`result ${JSON.stringify(result, null, 2)}`) + // console.log(`result ${JSON.stringify(result, null, 2)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - //console.log(`err: ${util.inspect(err)}`) + // console.log(`err: ${util.inspect(err)}`) - assert.hasAllKeys(err, ["error"]) - assert.include(err.error, "bad-txns-inputs-missingorspent") + assert.hasAllKeys(err, ['error']) + assert.include(err.error, 'bad-txns-inputs-missingorspent') } }) - it("should send an array of tx hexes", async () => { + it('should send an array of tx hexes', async () => { try { const hexes = [ - "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000", - "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000" + '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000', + '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000' ] const result = await bchjs.RawTransactions.sendRawTransaction(hexes) @@ -59,13 +59,13 @@ describe("#rawtransaction", () => { } catch (err) { // console.log(`err: ${util.inspect(err)}`) - assert.hasAllKeys(err, ["error"]) - assert.include(err.error, "bad-txns-inputs-missingorspent") + assert.hasAllKeys(err, ['error']) + assert.include(err.error, 'bad-txns-inputs-missingorspent') } }) }) }) -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/chains/abc/slp.js b/test/integration/chains/abc/slp.js index ef3b87f..ad7023d 100644 --- a/test/integration/chains/abc/slp.js +++ b/test/integration/chains/abc/slp.js @@ -3,21 +3,21 @@ These tests are specific to the ABC chain. */ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert -const BCHJS = require("../../../../src/bch-js") +const BCHJS = require('../../../../src/bch-js') let bchjs // Inspect utility used for debugging. -const util = require("util") +const util = require('util') util.inspect.defaultOptions = { showHidden: true, colors: true, depth: 1 } -describe(`#SLP`, () => { +describe('#SLP', () => { // before(() => { // console.log(`bchjs.SLP.restURL: ${bchjs.SLP.restURL}`) // console.log(`bchjs.SLP.apiToken: ${bchjs.SLP.apiToken}`) @@ -30,63 +30,63 @@ describe(`#SLP`, () => { bchjs = new BCHJS() }) - describe("#util", () => { - describe("#tokenUtxoDetails", () => { - it("should handle a range of UTXO types", async () => { + describe('#util', () => { + describe('#tokenUtxoDetails', () => { + it('should handle a range of UTXO types', async () => { const utxos = [ // Malformed SLP tx { - note: "Malformed SLP tx", + note: 'Malformed SLP tx', tx_hash: - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a", + 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a', tx_pos: 1, value: 546 }, // Normal TX (non-SLP) { - note: "Normal TX (non-SLP)", + note: 'Normal TX (non-SLP)', tx_hash: - "01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0", + '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0', tx_pos: 0, value: 400000 }, // Valid PSF SLP tx { - note: "Valid PSF SLP tx", + note: 'Valid PSF SLP tx', tx_hash: - "daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd", + 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd', tx_pos: 1, value: 546 }, // Valid SLP token not in whitelist { - note: "Valid SLP token not in whitelist", + note: 'Valid SLP token not in whitelist', tx_hash: - "3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488", + '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488', tx_pos: 1, value: 546 }, // Token send on BCHN network. { - note: "Token send on BCHN network", + note: 'Token send on BCHN network', tx_hash: - "402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019", + '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019', tx_pos: 1, value: 546 }, // Token send on ABC network. { - note: "Token send on ABC network", + note: 'Token send on ABC network', tx_hash: - "336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d", + '336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d', tx_pos: 1, value: 546 }, // Known invalid SLP token send of PSF tokens. { - note: "Known invalid SLP token send of PSF tokens", + note: 'Known invalid SLP token send of PSF tokens', tx_hash: - "2bf691ad3679d928fef880b8a45b93b233f8fa0d0a92cf792313dbe77b1deb74", + '2bf691ad3679d928fef880b8a45b93b233f8fa0d0a92cf792313dbe77b1deb74', tx_pos: 1, value: 546 } @@ -125,52 +125,52 @@ describe(`#SLP`, () => { }) }) - describe("#validateTxid3", () => { - it("should invalidate a known invalid TXID", async () => { + describe('#validateTxid3', () => { + it('should invalidate a known invalid TXID', async () => { const txid = - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a" + 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a' const result = await bchjs.SLP.Utils.validateTxid3(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) - assert.property(result[0], "txid") + assert.property(result[0], 'txid') assert.equal(result[0].txid, txid) - assert.property(result[0], "valid") + assert.property(result[0], 'valid') assert.equal(result[0].valid, null) }) - it("should validate a known valid TXID", async () => { + it('should validate a known valid TXID', async () => { const txid = - "daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd" + 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd' const result = await bchjs.SLP.Utils.validateTxid3(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) - assert.property(result[0], "txid") + assert.property(result[0], 'txid') assert.equal(result[0].txid, txid) - assert.property(result[0], "valid") + assert.property(result[0], 'valid') assert.equal(result[0].valid, true) }) - it("should handle a mix of valid, invalid, and non-SLP txs", async () => { + it('should handle a mix of valid, invalid, and non-SLP txs', async () => { const txids = [ // Malformed SLP tx - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a", + 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a', // Normal TX (non-SLP) - "01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0", + '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0', // Valid PSF SLP tx - "daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd", + 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd', // Valid SLP token not in whitelist - "3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488", + '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488', // Unprocessed SLP TX // "a0d6406eecfd8634158efa9314ff15b4cbf451938e9dc7b5678c46b41eabc6ed" // Mint baton - "402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019" + '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019' ] const result = await bchjs.SLP.Utils.validateTxid3(txids) @@ -185,21 +185,21 @@ describe(`#SLP`, () => { }) }) - describe("#validateTxid", () => { - it("should handle a mix of valid, invalid, and non-SLP txs", async () => { + describe('#validateTxid', () => { + it('should handle a mix of valid, invalid, and non-SLP txs', async () => { const txids = [ // Malformed SLP tx - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a", + 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a', // Normal TX (non-SLP) - "01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0", + '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0', // Valid PSF SLP tx - "daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd", + 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd', // Valid SLP token not in whitelist - "3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488", + '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488', // Token send on BCHN network. - "402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019", + '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019', // Token send on ABC network. - "336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d" + '336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d' ] const result = await bchjs.SLP.Utils.validateTxid(txids) @@ -218,6 +218,6 @@ describe(`#SLP`, () => { }) // Promise-based sleep function -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/chains/bchn/rawtransaction.js b/test/integration/chains/bchn/rawtransaction.js index d512dc1..0c4f251 100644 --- a/test/integration/chains/bchn/rawtransaction.js +++ b/test/integration/chains/bchn/rawtransaction.js @@ -5,20 +5,20 @@ TODO */ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert -const BCHJS = require("../../../../src/bch-js") +const BCHJS = require('../../../../src/bch-js') const bchjs = new BCHJS() // Inspect utility used for debugging. -const util = require("util") +const util = require('util') util.inspect.defaultOptions = { showHidden: true, colors: true, depth: 3 } -describe("#rawtransaction", () => { +describe('#rawtransaction', () => { beforeEach(async () => { if (process.env.IS_USING_FREE_TIER) await sleep(1000) }) @@ -29,29 +29,29 @@ describe("#rawtransaction", () => { below expect error messages returned from the server, but at least test that the server is responding on those endpoints, and responds consistently. */ - describe("sendRawTransaction", () => { - it("should send a single transaction hex", async () => { + describe('sendRawTransaction', () => { + it('should send a single transaction hex', async () => { try { const hex = - "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000" + '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000' await bchjs.RawTransactions.sendRawTransaction(hex) - //console.log(`result ${JSON.stringify(result, null, 2)}`) + // console.log(`result ${JSON.stringify(result, null, 2)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - //console.log(`err: ${util.inspect(err)}`) + // console.log(`err: ${util.inspect(err)}`) - assert.hasAllKeys(err, ["error"]) - assert.include(err.error, "Missing inputs") + assert.hasAllKeys(err, ['error']) + assert.include(err.error, 'Missing inputs') } }) - it("should send an array of tx hexes", async () => { + it('should send an array of tx hexes', async () => { try { const hexes = [ - "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000", - "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000" + '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000', + '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000' ] const result = await bchjs.RawTransactions.sendRawTransaction(hexes) @@ -59,13 +59,13 @@ describe("#rawtransaction", () => { } catch (err) { // console.log(`err: ${util.inspect(err)}`) - assert.hasAllKeys(err, ["error"]) - assert.include(err.error, "Missing inputs") + assert.hasAllKeys(err, ['error']) + assert.include(err.error, 'Missing inputs') } }) }) }) -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/chains/bchn/slp.js b/test/integration/chains/bchn/slp.js index 8e356ff..14e270c 100644 --- a/test/integration/chains/bchn/slp.js +++ b/test/integration/chains/bchn/slp.js @@ -3,21 +3,21 @@ These tests are specific to the ABC chain. */ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert -const BCHJS = require("../../../../src/bch-js") +const BCHJS = require('../../../../src/bch-js') let bchjs // Inspect utility used for debugging. -const util = require("util") +const util = require('util') util.inspect.defaultOptions = { showHidden: true, colors: true, depth: 1 } -describe(`#SLP`, () => { +describe('#SLP', () => { // before(() => { // console.log(`bchjs.SLP.restURL: ${bchjs.SLP.restURL}`) // console.log(`bchjs.SLP.apiToken: ${bchjs.SLP.apiToken}`) @@ -30,63 +30,63 @@ describe(`#SLP`, () => { bchjs = new BCHJS() }) - describe("#util", () => { - describe("#tokenUtxoDetails", () => { - it("should handle a range of UTXO types", async () => { + describe('#util', () => { + describe('#tokenUtxoDetails', () => { + it('should handle a range of UTXO types', async () => { const utxos = [ // Malformed SLP tx { - note: "Malformed SLP tx", + note: 'Malformed SLP tx', tx_hash: - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a", + 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a', tx_pos: 1, value: 546 }, // Normal TX (non-SLP) { - note: "Normal TX (non-SLP)", + note: 'Normal TX (non-SLP)', tx_hash: - "01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0", + '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0', tx_pos: 0, value: 400000 }, // Valid PSF SLP tx { - note: "Valid PSF SLP tx", + note: 'Valid PSF SLP tx', tx_hash: - "daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd", + 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd', tx_pos: 1, value: 546 }, // Valid SLP token not in whitelist { - note: "Valid SLP token not in whitelist", + note: 'Valid SLP token not in whitelist', tx_hash: - "3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488", + '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488', tx_pos: 1, value: 546 }, // Token send on BCHN network. { - note: "Token send on BCHN network", + note: 'Token send on BCHN network', tx_hash: - "402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019", + '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019', tx_pos: 1, value: 546 }, // Token send on ABC network. { - note: "Token send on ABC network", + note: 'Token send on ABC network', tx_hash: - "336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d", + '336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d', tx_pos: 1, value: 546 }, // Known invalid SLP token send of PSF tokens. { - note: "Known invalid SLP token send of PSF tokens", + note: 'Known invalid SLP token send of PSF tokens', tx_hash: - "2bf691ad3679d928fef880b8a45b93b233f8fa0d0a92cf792313dbe77b1deb74", + '2bf691ad3679d928fef880b8a45b93b233f8fa0d0a92cf792313dbe77b1deb74', tx_pos: 1, value: 546 } @@ -125,51 +125,51 @@ describe(`#SLP`, () => { }) }) - describe("#validateTxid3", () => { - it("should invalidate a known invalid TXID", async () => { + describe('#validateTxid3', () => { + it('should invalidate a known invalid TXID', async () => { const txid = - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a" + 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a' const result = await bchjs.SLP.Utils.validateTxid3(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) - assert.property(result[0], "txid") + assert.property(result[0], 'txid') assert.equal(result[0].txid, txid) - assert.property(result[0], "valid") + assert.property(result[0], 'valid') assert.equal(result[0].valid, null) }) - it("should validate a known valid TXID", async () => { + it('should validate a known valid TXID', async () => { const txid = - "daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd" + 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd' const result = await bchjs.SLP.Utils.validateTxid3(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) - assert.property(result[0], "txid") + assert.property(result[0], 'txid') assert.equal(result[0].txid, txid) - assert.property(result[0], "valid") + assert.property(result[0], 'valid') assert.equal(result[0].valid, true) }) - it("should handle a mix of valid, invalid, and non-SLP txs", async () => { + it('should handle a mix of valid, invalid, and non-SLP txs', async () => { const txids = [ // Malformed SLP tx - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a", + 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a', // Normal TX (non-SLP) - "01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0", + '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0', // Valid PSF SLP tx - "daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd", + 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd', // Valid SLP token not in whitelist - "3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488", + '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488', // Unprocessed SLP TX - "402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019" + '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019' ] const result = await bchjs.SLP.Utils.validateTxid3(txids) @@ -196,21 +196,21 @@ describe(`#SLP`, () => { }) }) - describe("#validateTxid", () => { - it("should handle a mix of valid, invalid, and non-SLP txs", async () => { + describe('#validateTxid', () => { + it('should handle a mix of valid, invalid, and non-SLP txs', async () => { const txids = [ // Malformed SLP tx - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a", + 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a', // Normal TX (non-SLP) - "01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0", + '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0', // Valid PSF SLP tx - "daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd", + 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd', // Valid SLP token not in whitelist - "3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488", + '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488', // Token send on BCHN network. - "402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019", + '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019', // Token send on ABC network. - "336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d" + '336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d' ] const result = await bchjs.SLP.Utils.validateTxid(txids) @@ -242,6 +242,6 @@ describe(`#SLP`, () => { }) // Promise-based sleep function -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/chains/testnet/blockchain.js b/test/integration/chains/testnet/blockchain.js index f1f73ac..a91b5ae 100644 --- a/test/integration/chains/testnet/blockchain.js +++ b/test/integration/chains/testnet/blockchain.js @@ -7,116 +7,116 @@ of an e2e test to be properly tested. */ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert const RESTURL = process.env.RESTURL ? process.env.RESTURL - : "https://testnet3.fullstack.cash/v4/" + : 'https://testnet3.fullstack.cash/v4/' // if (process.env.RESTURL) RESTURL = process.env.RESTURL -const BCHJS = require("../../../../src/bch-js") +const BCHJS = require('../../../../src/bch-js') // const bchjs = new BCHJS({ restURL: `https://testnet.bchjs.cash/v4/` }) const bchjs = new BCHJS({ restURL: RESTURL, apiToken: process.env.BCHJSTOKEN }) // Inspect utility used for debugging. -const util = require("util") +const util = require('util') util.inspect.defaultOptions = { showHidden: true, colors: true, depth: 3 } -describe("#blockchain", () => { +describe('#blockchain', () => { beforeEach(async () => { if (process.env.IS_USING_FREE_TIER) await sleep(1000) }) - describe("#getBestBlockHash", () => { - it("should GET best block hash", async () => { + describe('#getBestBlockHash', () => { + it('should GET best block hash', async () => { const result = await bchjs.Blockchain.getBestBlockHash() // console.log(`result: ${util.inspect(result)}`) assert.isString(result) - assert.equal(result.length, 64, "Specific hash length") + assert.equal(result.length, 64, 'Specific hash length') }) }) - describe("#getBlockHeader", () => { - it("should GET block header for a single hash", async () => { + describe('#getBlockHeader', () => { + it('should GET block header for a single hash', async () => { const hash = - "000000000000c57178ace90210289e6b5383134c5b5306e1cdd8395176e10aaf" + '000000000000c57178ace90210289e6b5383134c5b5306e1cdd8395176e10aaf' const result = await bchjs.Blockchain.getBlockHeader(hash) assert.hasAllKeys(result, [ - "hash", - "confirmations", - "height", - "version", - "versionHex", - "merkleroot", - "time", - "mediantime", - "nonce", - "bits", - "difficulty", - "chainwork", - "previousblockhash", - "nextblockhash", - "nTx" + 'hash', + 'confirmations', + 'height', + 'version', + 'versionHex', + 'merkleroot', + 'time', + 'mediantime', + 'nonce', + 'bits', + 'difficulty', + 'chainwork', + 'previousblockhash', + 'nextblockhash', + 'nTx' ]) }) - it("should GET block headers for an array of hashes", async () => { + it('should GET block headers for an array of hashes', async () => { const hash = [ - "000000000000c57178ace90210289e6b5383134c5b5306e1cdd8395176e10aaf", - "00000000000b7db4cbae48d852fcbef32f728014582094ad613fe12af6600ff2" + '000000000000c57178ace90210289e6b5383134c5b5306e1cdd8395176e10aaf', + '00000000000b7db4cbae48d852fcbef32f728014582094ad613fe12af6600ff2' ] const result = await bchjs.Blockchain.getBlockHeader(hash) assert.isArray(result) assert.hasAllKeys(result[0], [ - "hash", - "confirmations", - "height", - "version", - "versionHex", - "merkleroot", - "time", - "mediantime", - "nonce", - "bits", - "difficulty", - "chainwork", - "previousblockhash", - "nextblockhash", - "nTx" + 'hash', + 'confirmations', + 'height', + 'version', + 'versionHex', + 'merkleroot', + 'time', + 'mediantime', + 'nonce', + 'bits', + 'difficulty', + 'chainwork', + 'previousblockhash', + 'nextblockhash', + 'nTx' ]) }) - it("should throw error on array size rate limit", async () => { + it('should throw error on array size rate limit', async () => { try { const data = [] for (let i = 0; i < 25; i++) { data.push( - "00000000000b7db4cbae48d852fcbef32f728014582094ad613fe12af6600ff2" + '00000000000b7db4cbae48d852fcbef32f728014582094ad613fe12af6600ff2' ) } await bchjs.Blockchain.getBlockHeader(data) // console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) - describe("#getMempoolEntry", () => { + describe('#getMempoolEntry', () => { /* // To run this test, the txid must be unconfirmed. const txid = @@ -168,26 +168,26 @@ describe("#blockchain", () => { }) */ - it("should throw an error if txid is not in mempool", async () => { + it('should throw an error if txid is not in mempool', async () => { try { const txid = - "1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04" + '1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04' await bchjs.Blockchain.getMempoolEntry(txid) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { // console.log(`err: ${util.inspect(err)}`) - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Transaction not in mempool") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Transaction not in mempool') } }) }) - describe("#getTxOutProof", () => { - it("should get single tx out proof", async () => { + describe('#getTxOutProof', () => { + it('should get single tx out proof', async () => { const txid = - "1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04" + '1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04' const result = await bchjs.Blockchain.getTxOutProof(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) @@ -195,10 +195,10 @@ describe("#blockchain", () => { assert.isString(result) }) - it("should get an array of tx out proofs", async () => { + it('should get an array of tx out proofs', async () => { const txid = [ - "1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04", - "fc4f696c0ebb3d0994b3975f57d85be75ef752b9fd52c17e361ec3be2fa3e752" + '1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04', + 'fc4f696c0ebb3d0994b3975f57d85be75ef752b9fd52c17e361ec3be2fa3e752' ] const result = await bchjs.Blockchain.getTxOutProof(txid) @@ -209,11 +209,11 @@ describe("#blockchain", () => { }) }) - describe("#verifyTxOutProof", () => { + describe('#verifyTxOutProof', () => { const mockTxOutProof = - "00000020ac86ce8f2bda235c0dc135d18f6a777c44b121e8f41db8a51ca65000000000000cd4de3c49337712f3a1092c47c3bf73ec2f9b1cfd289ee991ede0b6eab4df229d5b8c5dffff001d82ce005b0700000003ec55d9142eac2c1d2229e5af24898b2590c111b62e2787fa1998d3d713fd432fd557124ed758fa156a6cdc6d317d5575aec2b86dfb159c62ecb4743f28bef1cb52e7a32fbec31e367ec152fdb952f75ee75bd8575f97b394093dbb0e6c694ffc0135" + '00000020ac86ce8f2bda235c0dc135d18f6a777c44b121e8f41db8a51ca65000000000000cd4de3c49337712f3a1092c47c3bf73ec2f9b1cfd289ee991ede0b6eab4df229d5b8c5dffff001d82ce005b0700000003ec55d9142eac2c1d2229e5af24898b2590c111b62e2787fa1998d3d713fd432fd557124ed758fa156a6cdc6d317d5575aec2b86dfb159c62ecb4743f28bef1cb52e7a32fbec31e367ec152fdb952f75ee75bd8575f97b394093dbb0e6c694ffc0135' - it("should verify a single proof", async () => { + it('should verify a single proof', async () => { const result = await bchjs.Blockchain.verifyTxOutProof(mockTxOutProof) // console.log(`result: ${JSON.stringify(result, null, 2)}`) @@ -221,11 +221,11 @@ describe("#blockchain", () => { assert.isString(result[0]) assert.equal( result[0], - "fc4f696c0ebb3d0994b3975f57d85be75ef752b9fd52c17e361ec3be2fa3e752" + 'fc4f696c0ebb3d0994b3975f57d85be75ef752b9fd52c17e361ec3be2fa3e752' ) }) - it("should verify an array of proofs", async () => { + it('should verify an array of proofs', async () => { const proofs = [mockTxOutProof, mockTxOutProof] const result = await bchjs.Blockchain.verifyTxOutProof(proofs) // console.log(`result: ${JSON.stringify(result, null, 2)}`) @@ -234,11 +234,11 @@ describe("#blockchain", () => { assert.isString(result[0]) assert.equal( result[0], - "fc4f696c0ebb3d0994b3975f57d85be75ef752b9fd52c17e361ec3be2fa3e752" + 'fc4f696c0ebb3d0994b3975f57d85be75ef752b9fd52c17e361ec3be2fa3e752' ) }) - it("should throw error on array size rate limit", async () => { + it('should throw error on array size rate limit', async () => { try { const data = [] for (let i = 0; i < 25; i++) data.push(mockTxOutProof) @@ -246,15 +246,15 @@ describe("#blockchain", () => { const result = await bchjs.Blockchain.verifyTxOutProof(data) console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) }) -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/chains/testnet/control.js b/test/integration/chains/testnet/control.js index 83d1466..aee47a9 100644 --- a/test/integration/chains/testnet/control.js +++ b/test/integration/chains/testnet/control.js @@ -2,31 +2,31 @@ Integration tests for bchjs control library. */ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert const RESTURL = process.env.RESTURL ? process.env.RESTURL - : `https://testnet3.fullstack.cash/v4/` + : 'https://testnet3.fullstack.cash/v4/' -const BCHJS = require("../../../../src/bch-js") +const BCHJS = require('../../../../src/bch-js') const bchjs = new BCHJS({ restURL: RESTURL, apiToken: process.env.BCHJSTOKEN }) -describe(`#control`, () => { +describe('#control', () => { beforeEach(async () => { if (process.env.IS_USING_FREE_TIER) await sleep(1000) }) - describe(`#getNetworkInfo`, () => { - it("should get info on the full node", async () => { + describe('#getNetworkInfo', () => { + it('should get info on the full node', async () => { const result = await bchjs.Control.getNetworkInfo() console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "version") + assert.property(result, 'version') }) }) }) -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/chains/testnet/electrumx.js b/test/integration/chains/testnet/electrumx.js index 1c1d7f6..acdaeec 100644 --- a/test/integration/chains/testnet/electrumx.js +++ b/test/integration/chains/testnet/electrumx.js @@ -1,15 +1,15 @@ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert -const sinon = require("sinon") +const sinon = require('sinon') const RESTURL = process.env.RESTURL ? process.env.RESTURL - : `https://testnet3.fullstack.cash/v4/` + : 'https://testnet3.fullstack.cash/v4/' -const BCHJS = require("../../../../src/bch-js") +const BCHJS = require('../../../../src/bch-js') const bchjs = new BCHJS({ restURL: RESTURL, apiToken: process.env.BCHJSTOKEN }) -describe(`#ElectrumX`, () => { +describe('#ElectrumX', () => { let sandbox beforeEach(async () => { @@ -20,176 +20,173 @@ describe(`#ElectrumX`, () => { afterEach(() => sandbox.restore()) - describe(`#utxo`, () => { - it(`should GET utxos for a single address`, async () => { - const addr = "bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2" + describe('#utxo', () => { + it('should GET utxos for a single address', async () => { + const addr = 'bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2' const result = await bchjs.Electrumx.utxo(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "utxos") + assert.property(result, 'utxos') assert.isArray(result.utxos) - assert.property(result.utxos[0], "height") - assert.property(result.utxos[0], "tx_hash") - assert.property(result.utxos[0], "tx_pos") - assert.property(result.utxos[0], "value") + assert.property(result.utxos[0], 'height') + assert.property(result.utxos[0], 'tx_hash') + assert.property(result.utxos[0], 'tx_pos') + assert.property(result.utxos[0], 'value') }) - it(`should POST utxo details for an array of addresses`, async () => { + it('should POST utxo details for an array of addresses', async () => { const addr = [ - "bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2", - "bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2" + 'bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2', + 'bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2' ] const result = await bchjs.Electrumx.utxo(addr) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "utxos") + assert.property(result, 'utxos') assert.isArray(result.utxos) - assert.property(result.utxos[0], "utxos") + assert.property(result.utxos[0], 'utxos') assert.isArray(result.utxos[0].utxos) - assert.property(result.utxos[0], "address") + assert.property(result.utxos[0], 'address') - assert.property(result.utxos[0].utxos[0], "height") - assert.property(result.utxos[0].utxos[0], "tx_hash") - assert.property(result.utxos[0].utxos[0], "tx_pos") - assert.property(result.utxos[0].utxos[0], "value") + assert.property(result.utxos[0].utxos[0], 'height') + assert.property(result.utxos[0].utxos[0], 'tx_hash') + assert.property(result.utxos[0].utxos[0], 'tx_pos') + assert.property(result.utxos[0].utxos[0], 'value') }) - it(`should throw error on array size rate limit`, async () => { + it('should throw error on array size rate limit', async () => { try { const addr = [] - for (let i = 0; i < 25; i++) - addr.push("bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2") + for (let i = 0; i < 25; i++) { addr.push('bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2') } const result = await bchjs.Electrumx.utxo(addr) - //console.log(`result: ${util.inspect(result)}`) + // console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) - describe(`#balance`, () => { - it(`should GET balance for a single address`, async () => { - const addr = "bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2" + describe('#balance', () => { + it('should GET balance for a single address', async () => { + const addr = 'bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2' const result = await bchjs.Electrumx.balance(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "balance") - assert.property(result.balance, "confirmed") - assert.property(result.balance, "unconfirmed") + assert.property(result, 'balance') + assert.property(result.balance, 'confirmed') + assert.property(result.balance, 'unconfirmed') }) - it(`should POST request for balances for an array of addresses`, async () => { + it('should POST request for balances for an array of addresses', async () => { const addr = [ - "bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2", - "bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2" + 'bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2', + 'bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2' ] const result = await bchjs.Electrumx.balance(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "balances") + assert.property(result, 'balances') assert.isArray(result.balances) - assert.property(result.balances[0], "address") - assert.property(result.balances[0], "balance") - assert.property(result.balances[0].balance, "confirmed") - assert.property(result.balances[0].balance, "unconfirmed") + assert.property(result.balances[0], 'address') + assert.property(result.balances[0], 'balance') + assert.property(result.balances[0].balance, 'confirmed') + assert.property(result.balances[0].balance, 'unconfirmed') }) - it(`should throw error on array size rate limit`, async () => { + it('should throw error on array size rate limit', async () => { try { const addr = [] - for (let i = 0; i < 25; i++) - addr.push("bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2") + for (let i = 0; i < 25; i++) { addr.push('bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2') } const result = await bchjs.Electrumx.balance(addr) console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) - describe(`#transactions`, () => { - it(`should GET transaction history for a single address`, async () => { - const addr = "bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2" + describe('#transactions', () => { + it('should GET transaction history for a single address', async () => { + const addr = 'bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2' const result = await bchjs.Electrumx.transactions(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "transactions") + assert.property(result, 'transactions') assert.isArray(result.transactions) - assert.property(result.transactions[0], "height") - assert.property(result.transactions[0], "tx_hash") + assert.property(result.transactions[0], 'height') + assert.property(result.transactions[0], 'tx_hash') }) - it(`should POST request for transaction history for an array of addresses`, async () => { + it('should POST request for transaction history for an array of addresses', async () => { const addr = [ - "bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2", - "bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2" + 'bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2', + 'bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2' ] const result = await bchjs.Electrumx.transactions(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "transactions") + assert.property(result, 'transactions') assert.isArray(result.transactions) - assert.property(result.transactions[0], "address") - assert.property(result.transactions[0], "transactions") + assert.property(result.transactions[0], 'address') + assert.property(result.transactions[0], 'transactions') assert.isArray(result.transactions[0].transactions) - assert.property(result.transactions[0].transactions[0], "height") - assert.property(result.transactions[0].transactions[0], "tx_hash") + assert.property(result.transactions[0].transactions[0], 'height') + assert.property(result.transactions[0].transactions[0], 'tx_hash') }) - it(`should throw error on array size rate limit`, async () => { + it('should throw error on array size rate limit', async () => { try { const addr = [] - for (let i = 0; i < 25; i++) - addr.push("bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2") + for (let i = 0; i < 25; i++) { addr.push('bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2') } const result = await bchjs.Electrumx.transactions(addr) console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) - describe(`#unconfirmed`, () => { + describe('#unconfirmed', () => { // These tests won't work because unconfirmed transactions are transient in nature. /* it(`should GET unconfirmed UTXOs (mempool) for a single address`, async () => { @@ -234,137 +231,136 @@ describe(`#ElectrumX`, () => { }) */ - it(`should throw error on array size rate limit`, async () => { + it('should throw error on array size rate limit', async () => { try { const addr = [] - for (let i = 0; i < 25; i++) - addr.push("bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2") + for (let i = 0; i < 25; i++) { addr.push('bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2') } await bchjs.Electrumx.unconfirmed(addr) - //console.log(`result: ${util.inspect(result)}`) + // console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) - describe(`#blockHeader`, () => { - it(`should GET block headers for given height and count`, async () => { + describe('#blockHeader', () => { + it('should GET block headers for given height and count', async () => { const height = 42 const count = 2 const result = await bchjs.Electrumx.blockHeader(height, count) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "headers") + assert.property(result, 'headers') assert.isArray(result.headers) assert.equal(result.headers.length, 2) }) - it(`should GET block headers for given height with default count = 1`, async () => { + it('should GET block headers for given height with default count = 1', async () => { const height = 42 const result = await bchjs.Electrumx.blockHeader(height) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "headers") + assert.property(result, 'headers') assert.isArray(result.headers) assert.equal(result.headers.length, 1) }) }) - describe(`#txData`, () => { - it(`should GET details for a single transaction`, async () => { + describe('#txData', () => { + it('should GET details for a single transaction', async () => { const txid = - "76d2ee0ebd8b978742f6478ff9a12f478c34e4cee0a2b919059101d961bd01ee" + '76d2ee0ebd8b978742f6478ff9a12f478c34e4cee0a2b919059101d961bd01ee' const result = await bchjs.Electrumx.txData(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "details") + assert.property(result, 'details') assert.isObject(result.details) - assert.property(result.details, "blockhash") - assert.property(result.details, "hash") - assert.property(result.details, "hex") - assert.property(result.details, "vin") - assert.property(result.details, "vout") + assert.property(result.details, 'blockhash') + assert.property(result.details, 'hash') + assert.property(result.details, 'hex') + assert.property(result.details, 'vin') + assert.property(result.details, 'vout') assert.equal(result.details.hash, txid) }) - it(`should POST details for an array of transactions`, async () => { + it('should POST details for an array of transactions', async () => { const txids = [ - "76d2ee0ebd8b978742f6478ff9a12f478c34e4cee0a2b919059101d961bd01ee", - "76d2ee0ebd8b978742f6478ff9a12f478c34e4cee0a2b919059101d961bd01ee" + '76d2ee0ebd8b978742f6478ff9a12f478c34e4cee0a2b919059101d961bd01ee', + '76d2ee0ebd8b978742f6478ff9a12f478c34e4cee0a2b919059101d961bd01ee' ] const result = await bchjs.Electrumx.txData(txids) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "transactions") + assert.property(result, 'transactions') assert.isArray(result.transactions) - assert.property(result.transactions[0], "txid") - assert.property(result.transactions[0], "details") + assert.property(result.transactions[0], 'txid') + assert.property(result.transactions[0], 'details') - assert.property(result.transactions[0].details, "blockhash") - assert.property(result.transactions[0].details, "hash") - assert.property(result.transactions[0].details, "hex") - assert.property(result.transactions[0].details, "vin") - assert.property(result.transactions[0].details, "vout") + assert.property(result.transactions[0].details, 'blockhash') + assert.property(result.transactions[0].details, 'hash') + assert.property(result.transactions[0].details, 'hex') + assert.property(result.transactions[0].details, 'vin') + assert.property(result.transactions[0].details, 'vout') }) - it(`should throw error on array size rate limit`, async () => { + it('should throw error on array size rate limit', async () => { try { const txids = [] for (let i = 0; i < 25; i++) { txids.push( - "76d2ee0ebd8b978742f6478ff9a12f478c34e4cee0a2b919059101d961bd01ee" + '76d2ee0ebd8b978742f6478ff9a12f478c34e4cee0a2b919059101d961bd01ee' ) } await bchjs.Electrumx.txData(txids) console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) - describe(`#broadcast`, () => { - it(`should broadcast a single transaction`, async () => { + describe('#broadcast', () => { + it('should broadcast a single transaction', async () => { const txHex = - "020000000265d13ef402840c8a51f39779afb7ae4d49e4b0a3c24a3d0e7742038f2c679667010000006441dd1dd72770cadede1a7fd0363574846c48468a398ddfa41a9677c74cac8d2652b682743725a3b08c6c2021a629011e11a264d9036e9d5311e35b5f4937ca7b4e4121020797d8fd4d2fa6fd7cdeabe2526bfea2b90525d6e8ad506ec4ee3c53885aa309ffffffff65d13ef402840c8a51f39779afb7ae4d49e4b0a3c24a3d0e7742038f2c679667000000006441347d7f218c11c04487c1ad8baac28928fb10e5054cd4494b94d078cfa04ccf68e064fb188127ff656c0b98e9ce87f036d183925d0d0860605877d61e90375f774121028a53f95eb631b460854fc836b2e5d31cad16364b4dc3d970babfbdcc3f2e4954ffffffff035ac355000000000017a914189ce02e332548f4804bac65cba68202c9dbf822878dfd0800000000001976a914285bb350881b21ac89724c6fb6dc914d096cd53b88acf9ef3100000000001976a91445f1f1c4a9b9419a5088a3e9c24a293d7a150e6488ac00000000" + '020000000265d13ef402840c8a51f39779afb7ae4d49e4b0a3c24a3d0e7742038f2c679667010000006441dd1dd72770cadede1a7fd0363574846c48468a398ddfa41a9677c74cac8d2652b682743725a3b08c6c2021a629011e11a264d9036e9d5311e35b5f4937ca7b4e4121020797d8fd4d2fa6fd7cdeabe2526bfea2b90525d6e8ad506ec4ee3c53885aa309ffffffff65d13ef402840c8a51f39779afb7ae4d49e4b0a3c24a3d0e7742038f2c679667000000006441347d7f218c11c04487c1ad8baac28928fb10e5054cd4494b94d078cfa04ccf68e064fb188127ff656c0b98e9ce87f036d183925d0d0860605877d61e90375f774121028a53f95eb631b460854fc836b2e5d31cad16364b4dc3d970babfbdcc3f2e4954ffffffff035ac355000000000017a914189ce02e332548f4804bac65cba68202c9dbf822878dfd0800000000001976a914285bb350881b21ac89724c6fb6dc914d096cd53b88acf9ef3100000000001976a91445f1f1c4a9b9419a5088a3e9c24a293d7a150e6488ac00000000' try { await bchjs.Electrumx.broadcast(txHex) } catch (err) { - assert.property(err, "success") + assert.property(err, 'success') assert.equal(err.success, false) assert.include( err.error, - "the transaction was rejected by network rules" + 'the transaction was rejected by network rules' ) } }) }) }) -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/chains/testnet/ninsight.js b/test/integration/chains/testnet/ninsight.js index 583d14a..eee1c5f 100644 --- a/test/integration/chains/testnet/ninsight.js +++ b/test/integration/chains/testnet/ninsight.js @@ -1,11 +1,11 @@ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert -const sinon = require("sinon") +const sinon = require('sinon') -const BCHJS = require("../../../../src/bch-js") -const bchjs = new BCHJS({ ninsightURL: "https://trest.bitcoin.com/v2" }) +const BCHJS = require('../../../../src/bch-js') +const bchjs = new BCHJS({ ninsightURL: 'https://trest.bitcoin.com/v2' }) -describe(`#Ninsight`, () => { +describe('#Ninsight', () => { let sandbox beforeEach(async () => { @@ -16,34 +16,34 @@ describe(`#Ninsight`, () => { afterEach(() => sandbox.restore()) - describe(`#utxo`, () => { - it(`should GET utxos for a single address`, async () => { - const addr = "bchtest:qzjtnzcvzxx7s0na88yrg3zl28wwvfp97538sgrrmr" + describe('#utxo', () => { + it('should GET utxos for a single address', async () => { + const addr = 'bchtest:qzjtnzcvzxx7s0na88yrg3zl28wwvfp97538sgrrmr' const result = await bchjs.Ninsight.utxo(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result[0], "utxos") - assert.property(result[0], "legacyAddress") - assert.property(result[0], "cashAddress") - assert.property(result[0], "slpAddress") - assert.property(result[0], "scriptPubKey") - assert.property(result[0], "asm") + assert.property(result[0], 'utxos') + assert.property(result[0], 'legacyAddress') + assert.property(result[0], 'cashAddress') + assert.property(result[0], 'slpAddress') + assert.property(result[0], 'scriptPubKey') + assert.property(result[0], 'asm') assert.isArray(result[0].utxos) - assert.property(result[0].utxos[0], "txid") - assert.property(result[0].utxos[0], "vout") - assert.property(result[0].utxos[0], "amount") - assert.property(result[0].utxos[0], "satoshis") - assert.property(result[0].utxos[0], "height") - assert.property(result[0].utxos[0], "confirmations") + assert.property(result[0].utxos[0], 'txid') + assert.property(result[0].utxos[0], 'vout') + assert.property(result[0].utxos[0], 'amount') + assert.property(result[0].utxos[0], 'satoshis') + assert.property(result[0].utxos[0], 'height') + assert.property(result[0].utxos[0], 'confirmations') }) - it(`should POST utxo details for an array of addresses`, async () => { + it('should POST utxo details for an array of addresses', async () => { const addr = [ - "bchtest:qzjtnzcvzxx7s0na88yrg3zl28wwvfp97538sgrrmr", - "bchtest:qp6hgvevf4gzz6l7pgcte3gaaud9km0l459fa23dul" + 'bchtest:qzjtnzcvzxx7s0na88yrg3zl28wwvfp97538sgrrmr', + 'bchtest:qp6hgvevf4gzz6l7pgcte3gaaud9km0l459fa23dul' ] const result = await bchjs.Ninsight.utxo(addr) @@ -52,12 +52,12 @@ describe(`#Ninsight`, () => { assert.isArray(result) assert.isArray(result[0].utxos) - assert.property(result[0], "utxos") - assert.property(result[0], "legacyAddress") - assert.property(result[0], "cashAddress") - assert.property(result[0], "slpAddress") - assert.property(result[0], "scriptPubKey") - assert.property(result[0], "asm") + assert.property(result[0], 'utxos') + assert.property(result[0], 'legacyAddress') + assert.property(result[0], 'cashAddress') + assert.property(result[0], 'slpAddress') + assert.property(result[0], 'scriptPubKey') + assert.property(result[0], 'asm') // assert.hasAnyKeys(result[0][0], [ // "txid", @@ -68,80 +68,80 @@ describe(`#Ninsight`, () => { // ]) }) }) - describe(`#transactions`, () => { - it(`should POST transactions history for a single address`, async () => { - const addr = "bchtest:qzjtnzcvzxx7s0na88yrg3zl28wwvfp97538sgrrmr" + describe('#transactions', () => { + it('should POST transactions history for a single address', async () => { + const addr = 'bchtest:qzjtnzcvzxx7s0na88yrg3zl28wwvfp97538sgrrmr' const result = await bchjs.Ninsight.transactions(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) - assert.property(result[0], "cashAddress") - assert.property(result[0], "legacyAddress") - assert.property(result[0], "txs") + assert.property(result[0], 'cashAddress') + assert.property(result[0], 'legacyAddress') + assert.property(result[0], 'txs') assert.isArray(result[0].txs) - assert.property(result[0].txs[0], "txid") - assert.property(result[0].txs[0], "vin") - assert.property(result[0].txs[0], "vout") + assert.property(result[0].txs[0], 'txid') + assert.property(result[0].txs[0], 'vin') + assert.property(result[0].txs[0], 'vout') }) - it(`should POST transactions history for an array of addresses`, async () => { + it('should POST transactions history for an array of addresses', async () => { const addr = [ - "bchtest:qzjtnzcvzxx7s0na88yrg3zl28wwvfp97538sgrrmr", - "bchtest:qp6hgvevf4gzz6l7pgcte3gaaud9km0l459fa23dul" + 'bchtest:qzjtnzcvzxx7s0na88yrg3zl28wwvfp97538sgrrmr', + 'bchtest:qp6hgvevf4gzz6l7pgcte3gaaud9km0l459fa23dul' ] const result = await bchjs.Ninsight.transactions(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) - assert.property(result[0], "cashAddress") - assert.property(result[0], "legacyAddress") - assert.property(result[0], "txs") + assert.property(result[0], 'cashAddress') + assert.property(result[0], 'legacyAddress') + assert.property(result[0], 'txs') assert.isArray(result[0].txs) - assert.property(result[0].txs[0], "txid") - assert.property(result[0].txs[0], "vin") - assert.property(result[0].txs[0], "vout") + assert.property(result[0].txs[0], 'txid') + assert.property(result[0].txs[0], 'vin') + assert.property(result[0].txs[0], 'vout') }) }) - describe(`#txDetails`, () => { - it(`should POST transactions details for a single address`, async () => { + describe('#txDetails', () => { + it('should POST transactions details for a single address', async () => { const txid = - "76856d82e00b2696acd8d989e1fa6c46b431005046a285ce905814cac0ff8fea" + '76856d82e00b2696acd8d989e1fa6c46b431005046a285ce905814cac0ff8fea' const result = await bchjs.Ninsight.txDetails(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) - assert.property(result[0], "txid") - assert.property(result[0], "version") - assert.property(result[0], "locktime") - assert.property(result[0], "vin") - assert.property(result[0], "vout") - assert.property(result[0], "blockhash") - assert.property(result[0], "blockheight") - assert.property(result[0], "confirmations") - assert.property(result[0], "time") - assert.property(result[0], "blocktime") - assert.property(result[0], "valueOut") - assert.property(result[0], "size") + assert.property(result[0], 'txid') + assert.property(result[0], 'version') + assert.property(result[0], 'locktime') + assert.property(result[0], 'vin') + assert.property(result[0], 'vout') + assert.property(result[0], 'blockhash') + assert.property(result[0], 'blockheight') + assert.property(result[0], 'confirmations') + assert.property(result[0], 'time') + assert.property(result[0], 'blocktime') + assert.property(result[0], 'valueOut') + assert.property(result[0], 'size') }) - it(`should POST transactions details for an array of addresses`, async () => { + it('should POST transactions details for an array of addresses', async () => { const txid = [ - "f191d1062789d7071da6f2168ba306869a829294f6b1c09d03492db4ca3a8e77", - "76856d82e00b2696acd8d989e1fa6c46b431005046a285ce905814cac0ff8fea" + 'f191d1062789d7071da6f2168ba306869a829294f6b1c09d03492db4ca3a8e77', + '76856d82e00b2696acd8d989e1fa6c46b431005046a285ce905814cac0ff8fea' ] const result = await bchjs.Ninsight.txDetails(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) - assert.property(result[0], "txid") - assert.property(result[0], "vin") - assert.property(result[0], "vout") + assert.property(result[0], 'txid') + assert.property(result[0], 'vin') + assert.property(result[0], 'vout') }) }) }) -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/chains/testnet/rawtransaction.js b/test/integration/chains/testnet/rawtransaction.js index 6010c6d..966bdb5 100644 --- a/test/integration/chains/testnet/rawtransaction.js +++ b/test/integration/chains/testnet/rawtransaction.js @@ -5,143 +5,143 @@ TODO */ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert const RESTURL = process.env.RESTURL ? process.env.RESTURL - : `https://testnet3.fullstack.cash/v4/` + : 'https://testnet3.fullstack.cash/v4/' // if (process.env.RESTURL) RESTURL = process.env.RESTURL -const BCHJS = require("../../../../src/bch-js") +const BCHJS = require('../../../../src/bch-js') // const bchjs = new BCHJS({ restURL: `https://testnet.bchjs.cash/v4/` }) const bchjs = new BCHJS({ restURL: RESTURL, apiToken: process.env.BCHJSTOKEN }) // Inspect utility used for debugging. -const util = require("util") +const util = require('util') util.inspect.defaultOptions = { showHidden: true, colors: true, depth: 3 } -describe("#rawtransaction", () => { +describe('#rawtransaction', () => { beforeEach(async () => { if (process.env.IS_USING_FREE_TIER) await sleep(1000) }) - describe("#decodeRawTransaction", () => { - it("should decode tx for a single hex", async () => { + describe('#decodeRawTransaction', () => { + it('should decode tx for a single hex', async () => { const hex = - "0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000" + '0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000' const result = await bchjs.RawTransactions.decodeRawTransaction(hex) - //console.log(`result ${JSON.stringify(result, null, 2)}`) + // console.log(`result ${JSON.stringify(result, null, 2)}`) assert.hasAnyKeys(result, [ - "txid", - "hash", - "size", - "version", - "locktime", - "vin", - "vout" + 'txid', + 'hash', + 'size', + 'version', + 'locktime', + 'vin', + 'vout' ]) assert.isArray(result.vin) assert.isArray(result.vout) }) - it("should decode an array of tx hexes", async () => { + it('should decode an array of tx hexes', async () => { const hexes = [ - "0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000", - "0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000" + '0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000', + '0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000' ] const result = await bchjs.RawTransactions.decodeRawTransaction(hexes) - //console.log(`result ${JSON.stringify(result, null, 2)}`) + // console.log(`result ${JSON.stringify(result, null, 2)}`) assert.isArray(result) assert.hasAnyKeys(result[0], [ - "txid", - "hash", - "size", - "version", - "locktime", - "vin", - "vout" + 'txid', + 'hash', + 'size', + 'version', + 'locktime', + 'vin', + 'vout' ]) assert.isArray(result[0].vin) assert.isArray(result[0].vout) }) - it(`should throw error on array size rate limit`, async () => { + it('should throw error on array size rate limit', async () => { try { const data = [] for (let i = 0; i < 25; i++) { data.push( - "0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000" + '0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000' ) } const result = await bchjs.RawTransactions.decodeRawTransaction(data) console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) - describe("#getRawTransaction", () => { - it("should decode a single txid, with concise output", async () => { + describe('#getRawTransaction', () => { + it('should decode a single txid, with concise output', async () => { const txid = - "1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04" + '1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04' const verbose = false const result = await bchjs.RawTransactions.getRawTransaction( txid, verbose ) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isString(result) }) - it("should decode a single txid, with verbose output", async () => { + it('should decode a single txid, with verbose output', async () => { const txid = - "1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04" + '1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04' const verbose = true const result = await bchjs.RawTransactions.getRawTransaction( txid, verbose ) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.hasAnyKeys(result, [ - "hex", - "txid", - "hash", - "size", - "version", - "locktime", - "vin", - "vout", - "blockhash", - "confirmations", - "time", - "blocktime" + 'hex', + 'txid', + 'hash', + 'size', + 'version', + 'locktime', + 'vin', + 'vout', + 'blockhash', + 'confirmations', + 'time', + 'blocktime' ]) assert.isArray(result.vin) assert.isArray(result.vout) }) - it("should decode an array of txids, with a concise output", async () => { + it('should decode an array of txids, with a concise output', async () => { const txid = [ - "1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04", - "1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04" + '1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04', + '1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04' ] const verbose = false @@ -149,16 +149,16 @@ describe("#rawtransaction", () => { txid, verbose ) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) assert.isString(result[0]) }) - it("should decode an array of txids, with a verbose output", async () => { + it('should decode an array of txids, with a verbose output', async () => { const txid = [ - "1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04", - "1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04" + '1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04', + '1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04' ] const verbose = true @@ -166,54 +166,54 @@ describe("#rawtransaction", () => { txid, verbose ) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) assert.hasAnyKeys(result[0], [ - "hex", - "txid", - "hash", - "size", - "version", - "locktime", - "vin", - "vout", - "blockhash", - "confirmations", - "time", - "blocktime" + 'hex', + 'txid', + 'hash', + 'size', + 'version', + 'locktime', + 'vin', + 'vout', + 'blockhash', + 'confirmations', + 'time', + 'blocktime' ]) assert.isArray(result[0].vin) assert.isArray(result[0].vout) }) - it(`should throw error on array size limit`, async () => { + it('should throw error on array size limit', async () => { try { const dataMock = - "1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04" + '1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04' const data = [] for (let i = 0; i < 25; i++) data.push(dataMock) const result = await bchjs.RawTransactions.getRawTransaction(data) console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) - describe("#decodeScript", () => { - it("should decode script for a single hex", async () => { + describe('#decodeScript', () => { + it('should decode script for a single hex', async () => { const hex = - "4830450221009a51e00ec3524a7389592bc27bea4af5104a59510f5f0cfafa64bbd5c164ca2e02206c2a8bbb47eabdeed52f17d7df668d521600286406930426e3a9415fe10ed592012102e6e1423f7abde8b70bca3e78a7d030e5efabd3eb35c19302542b5fe7879c1a16" + '4830450221009a51e00ec3524a7389592bc27bea4af5104a59510f5f0cfafa64bbd5c164ca2e02206c2a8bbb47eabdeed52f17d7df668d521600286406930426e3a9415fe10ed592012102e6e1423f7abde8b70bca3e78a7d030e5efabd3eb35c19302542b5fe7879c1a16' const result = await bchjs.RawTransactions.decodeScript(hex) - //console.log(`result ${JSON.stringify(result, null, 2)}`) + // console.log(`result ${JSON.stringify(result, null, 2)}`) - assert.hasAllKeys(result, ["asm", "type", "p2sh"]) + assert.hasAllKeys(result, ['asm', 'type', 'p2sh']) }) // CT 2/20/19 - Waiting for this PR to be merged complete the test: @@ -237,29 +237,29 @@ describe("#rawtransaction", () => { below expect error messages returned from the server, but at least test that the server is responding on those endpoints, and responds consistently. */ - describe("sendRawTransaction", () => { - it("should send a single transaction hex", async () => { + describe('sendRawTransaction', () => { + it('should send a single transaction hex', async () => { try { const hex = - "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000" + '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000' await bchjs.RawTransactions.sendRawTransaction(hex) - //console.log(`result ${JSON.stringify(result, null, 2)}`) + // console.log(`result ${JSON.stringify(result, null, 2)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - //console.log(`err: ${util.inspect(err)}`) + // console.log(`err: ${util.inspect(err)}`) - assert.hasAllKeys(err, ["error"]) - assert.include(err.error, "Missing inputs") + assert.hasAllKeys(err, ['error']) + assert.include(err.error, 'Missing inputs') } }) - it("should send an array of tx hexes", async () => { + it('should send an array of tx hexes', async () => { try { const hexes = [ - "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000", - "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000" + '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000', + '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000' ] const result = await bchjs.RawTransactions.sendRawTransaction(hexes) @@ -267,30 +267,30 @@ describe("#rawtransaction", () => { } catch (err) { // console.log(`err: ${util.inspect(err)}`) - assert.hasAllKeys(err, ["error"]) - assert.include(err.error, "Missing inputs") + assert.hasAllKeys(err, ['error']) + assert.include(err.error, 'Missing inputs') } }) - it(`should throw error on array size rate limit`, async () => { + it('should throw error on array size rate limit', async () => { try { const dataMock = - "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000" + '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000' const data = [] for (let i = 0; i < 25; i++) data.push(dataMock) const result = await bchjs.RawTransactions.sendRawTransaction(data) console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) }) -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/chains/testnet/slp.js b/test/integration/chains/testnet/slp.js index fc8e8ff..330c259 100644 --- a/test/integration/chains/testnet/slp.js +++ b/test/integration/chains/testnet/slp.js @@ -2,110 +2,110 @@ Integration tests for the bchjs covering SLP tokens. */ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert const RESTURL = process.env.RESTURL ? process.env.RESTURL - : `https://testnet3.fullstack.cash/v4/` + : 'https://testnet3.fullstack.cash/v4/' // if (process.env.RESTURL) RESTURL = process.env.RESTURL -const BCHJS = require("../../../../src/bch-js") +const BCHJS = require('../../../../src/bch-js') // const bchjs = new BCHJS({ restURL: `https://testnet.bchjs.cash/v4/` }) const bchjs = new BCHJS({ restURL: RESTURL, apiToken: process.env.BCHJSTOKEN }) // Inspect utility used for debugging. -const util = require("util") +const util = require('util') util.inspect.defaultOptions = { showHidden: true, colors: true, depth: 1 } -describe(`#SLP`, () => { +describe('#SLP', () => { beforeEach(async () => { // Introduce a delay so that the BVT doesn't trip the rate limits. if (process.env.IS_USING_FREE_TIER) await sleep(1000) }) - describe("#util", () => { - it(`should get information on the Oasis token`, async () => { - const tokenId = `a371e9934c7695d08a5eb7f31d3bceb4f3644860cc67520cda1e149423b9ec39` + describe('#util', () => { + it('should get information on the Oasis token', async () => { + const tokenId = 'a371e9934c7695d08a5eb7f31d3bceb4f3644860cc67520cda1e149423b9ec39' const result = await bchjs.SLP.Utils.list(tokenId) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.hasAnyKeys(result, [ - "decimals", - "timestamp", - "timestamp_unix", - "versionType", - "documentUri", - "symbol", - "name", - "containsBaton", - "id", - "documentHash", - "initialTokenQty", - "blockCreated", - "blockLastActiveSend", - "blockLastActiveMint", - "txnsSinceGenesis", - "validAddress", - "totalMinted", - "totalBurned", - "circulatingSupply", - "mintingBatonStatus" + 'decimals', + 'timestamp', + 'timestamp_unix', + 'versionType', + 'documentUri', + 'symbol', + 'name', + 'containsBaton', + 'id', + 'documentHash', + 'initialTokenQty', + 'blockCreated', + 'blockLastActiveSend', + 'blockLastActiveMint', + 'txnsSinceGenesis', + 'validAddress', + 'totalMinted', + 'totalBurned', + 'circulatingSupply', + 'mintingBatonStatus' ]) }) }) - describe("#decodeOpReturn", () => { - it("should decode the OP_RETURN for a SEND txid", async () => { + describe('#decodeOpReturn', () => { + it('should decode the OP_RETURN for a SEND txid', async () => { const txid = - "ad28116e0818339342dddfc5f58ca8a5379ceb9679b4e4cbd72f4de905415ec1" + 'ad28116e0818339342dddfc5f58ca8a5379ceb9679b4e4cbd72f4de905415ec1' const result = await bchjs.SLP.Utils.decodeOpReturn(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.hasAllKeys(result, ["amounts", "tokenType", "tokenId", "txType"]) + assert.hasAllKeys(result, ['amounts', 'tokenType', 'tokenId', 'txType']) }) }) - describe("#balancesForAddress", () => { - it(`should fetch all balances for address: slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9`, async () => { + describe('#balancesForAddress', () => { + it('should fetch all balances for address: slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9', async () => { // Mock the call to rest.bitcoin.com - if (process.env.TEST === "unit") { + if (process.env.TEST === 'unit') { sandbox - .stub(axios, "get") + .stub(axios, 'get') .resolves({ data: mockData.balancesForAddress }) } const balances = await bchjs.SLP.Utils.balancesForAddress( - "slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9" + 'slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9' ) // console.log(`balances: ${JSON.stringify(balances, null, 2)}`) assert.isArray(balances) assert.hasAllKeys(balances[0], [ - "tokenId", - "balanceString", - "balance", - "decimalCount", - "slpAddress" + 'tokenId', + 'balanceString', + 'balance', + 'decimalCount', + 'slpAddress' ]) }) - it(`should fetch balances for multiple addresses`, async () => { + it('should fetch balances for multiple addresses', async () => { const addresses = [ - "slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9", - "slptest:qr5uy4h8ysyhwkp9s245scckdnc7teyjqc5ft2z43h" + 'slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9', + 'slptest:qr5uy4h8ysyhwkp9s245scckdnc7teyjqc5ft2z43h' ] // Mock the call to rest.bitcoin.com - if (process.env.TEST === "unit") { + if (process.env.TEST === 'unit') { sandbox - .stub(axios, "post") + .stub(axios, 'post') .resolves({ data: mockData.balancesForAddresses }) } @@ -115,19 +115,19 @@ describe(`#SLP`, () => { assert.isArray(balances) assert.isArray(balances[0]) assert.hasAllKeys(balances[0][0], [ - "tokenId", - "balanceString", - "balance", - "decimalCount", - "slpAddress" + 'tokenId', + 'balanceString', + 'balance', + 'decimalCount', + 'slpAddress' ]) }) }) - describe("#tokenUtxoDetails", () => { - it("should hydrate UTXOs", async () => { + describe('#tokenUtxoDetails', () => { + it('should hydrate UTXOs', async () => { const bchAddr = bchjs.SLP.Address.toCashAddress( - "slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9" + 'slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9' ) const utxos = await bchjs.Electrumx.utxo([bchAddr]) @@ -145,12 +145,12 @@ describe(`#SLP`, () => { }) }) - describe("#hydrateUtxos", () => { + describe('#hydrateUtxos', () => { // This test will error out if the LOCAL_RESTURL settings is not set properly // in bch-api. - it("should hydrate UTXOs", async () => { + it('should hydrate UTXOs', async () => { const bchAddr = bchjs.SLP.Address.toCashAddress( - "slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9" + 'slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9' ) const utxos = await bchjs.Electrumx.utxo([bchAddr]) @@ -166,10 +166,10 @@ describe(`#SLP`, () => { }) }) - describe("#validateTxid2", () => { - it("should validate a token txid", async () => { + describe('#validateTxid2', () => { + it('should validate a token txid', async () => { const txid = - "ad28116e0818339342dddfc5f58ca8a5379ceb9679b4e4cbd72f4de905415ec1" + 'ad28116e0818339342dddfc5f58ca8a5379ceb9679b4e4cbd72f4de905415ec1' const validated = await bchjs.SLP.Utils.validateTxid(txid) // console.log(validated) @@ -180,6 +180,6 @@ describe(`#SLP`, () => { }) // Promise-based sleep function -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/chains/testnet/util.js b/test/integration/chains/testnet/util.js index 1a2ab9e..a5b1578 100644 --- a/test/integration/chains/testnet/util.js +++ b/test/integration/chains/testnet/util.js @@ -3,107 +3,107 @@ rest.bitcoin.com. */ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert const RESTURL = process.env.RESTURL ? process.env.RESTURL - : `https://testnet3.fullstack.cash/v4/` + : 'https://testnet3.fullstack.cash/v4/' // if (process.env.RESTURL) RESTURL = process.env.RESTURL -const BCHJS = require("../../../../src/bch-js") +const BCHJS = require('../../../../src/bch-js') // const bchjs = new BCHJS({ restURL: `https://testnet.bchjs.cash/v4/` }) const bchjs = new BCHJS({ restURL: RESTURL, apiToken: process.env.BCHJSTOKEN }) // Inspect utility used for debugging. -const util = require("util") +const util = require('util') util.inspect.defaultOptions = { showHidden: true, colors: true, depth: 3 } -describe(`#util`, () => { +describe('#util', () => { beforeEach(async () => { if (process.env.IS_USING_FREE_TIER) await sleep(1000) }) - describe(`#validateAddress`, () => { - it(`should return false for testnet addr on mainnet`, async () => { - const address = `bitcoincash:qp4k8fjtgunhdr7yq30ha4peu` + describe('#validateAddress', () => { + it('should return false for testnet addr on mainnet', async () => { + const address = 'bitcoincash:qp4k8fjtgunhdr7yq30ha4peu' const result = await bchjs.Util.validateAddress(address) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.hasAllKeys(result, ["isvalid"]) + assert.hasAllKeys(result, ['isvalid']) assert.equal(result.isvalid, false) }) - it(`should return false for bad address`, async () => { - const address = `bchtest:qqqk4y6lsl5da64sg53xezmplyu5kmpyz2ysaa5y` + it('should return false for bad address', async () => { + const address = 'bchtest:qqqk4y6lsl5da64sg53xezmplyu5kmpyz2ysaa5y' const result = await bchjs.Util.validateAddress(address) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.hasAllKeys(result, ["isvalid"]) + assert.hasAllKeys(result, ['isvalid']) assert.equal(result.isvalid, false) }) - it(`should validate valid address`, async () => { - const address = `bchtest:qqqk4y6lsl5da64sg5qc3xezmplyu5kmpyz2ysaa5y` + it('should validate valid address', async () => { + const address = 'bchtest:qqqk4y6lsl5da64sg5qc3xezmplyu5kmpyz2ysaa5y' const result = await bchjs.Util.validateAddress(address) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.hasAnyKeys(result, [ - "isvalid", - "address", - "scriptPubKey", - //"ismine", - //"iswatchonly", - "isscript" + 'isvalid', + 'address', + 'scriptPubKey', + // "ismine", + // "iswatchonly", + 'isscript' ]) assert.equal(result.isvalid, true) }) - it(`should validate an array of addresses`, async () => { + it('should validate an array of addresses', async () => { const address = [ - `bchtest:qqqk4y6lsl5da64sg5qc3xezmplyu5kmpyz2ysaa5y`, - `bchtest:pq6k9969f6v6sg7a75jkru4n7wn9sknv5cztcp0dnh` + 'bchtest:qqqk4y6lsl5da64sg5qc3xezmplyu5kmpyz2ysaa5y', + 'bchtest:pq6k9969f6v6sg7a75jkru4n7wn9sknv5cztcp0dnh' ] const result = await bchjs.Util.validateAddress(address) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) assert.hasAnyKeys(result[0], [ - "isvalid", - "address", - "scriptPubKey", - //"ismine", - //"iswatchonly", - "isscript" + 'isvalid', + 'address', + 'scriptPubKey', + // "ismine", + // "iswatchonly", + 'isscript' ]) }) - it(`should throw error on array size rate limit`, async () => { + it('should throw error on array size rate limit', async () => { try { - const dataMock = `bchtest:pq6k9969f6v6sg7a75jkru4n7wn9sknv5cztcp0dnh` + const dataMock = 'bchtest:pq6k9969f6v6sg7a75jkru4n7wn9sknv5cztcp0dnh' const data = [] for (let i = 0; i < 25; i++) data.push(dataMock) const result = await bchjs.Util.validateAddress(data) console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) }) -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/control.js b/test/integration/control.js index e6ce678..a99f320 100644 --- a/test/integration/control.js +++ b/test/integration/control.js @@ -2,26 +2,26 @@ Integration tests for bchjs control library. */ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') const bchjs = new BCHJS() -describe(`#control`, () => { +describe('#control', () => { beforeEach(async () => { if (process.env.IS_USING_FREE_TIER) await sleep(1000) }) - describe(`#getNetworkInfo`, () => { - it("should get info on the full node", async () => { + describe('#getNetworkInfo', () => { + it('should get info on the full node', async () => { const result = await bchjs.Control.getNetworkInfo() console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "version") + assert.property(result, 'version') }) }) }) -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/electrumx.js b/test/integration/electrumx.js index 38dc38d..cdd5c53 100644 --- a/test/integration/electrumx.js +++ b/test/integration/electrumx.js @@ -1,11 +1,11 @@ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert -const sinon = require("sinon") +const sinon = require('sinon') -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') const bchjs = new BCHJS() -describe(`#ElectrumX`, () => { +describe('#ElectrumX', () => { let sandbox beforeEach(async () => { @@ -16,176 +16,173 @@ describe(`#ElectrumX`, () => { afterEach(() => sandbox.restore()) - describe(`#utxo`, () => { - it(`should GET utxos for a single address`, async () => { - const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9" + describe('#utxo', () => { + it('should GET utxos for a single address', async () => { + const addr = 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9' const result = await bchjs.Electrumx.utxo(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "utxos") + assert.property(result, 'utxos') assert.isArray(result.utxos) - assert.property(result.utxos[0], "height") - assert.property(result.utxos[0], "tx_hash") - assert.property(result.utxos[0], "tx_pos") - assert.property(result.utxos[0], "value") + assert.property(result.utxos[0], 'height') + assert.property(result.utxos[0], 'tx_hash') + assert.property(result.utxos[0], 'tx_pos') + assert.property(result.utxos[0], 'value') }) - it(`should POST request for UTXOs for an array of addresses`, async () => { + it('should POST request for UTXOs for an array of addresses', async () => { const addr = [ - "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf", - "bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v" + 'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf', + 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v' ] const result = await bchjs.Electrumx.utxo(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "utxos") + assert.property(result, 'utxos') assert.isArray(result.utxos) - assert.property(result.utxos[0], "utxos") + assert.property(result.utxos[0], 'utxos') assert.isArray(result.utxos[0].utxos) - assert.property(result.utxos[0], "address") + assert.property(result.utxos[0], 'address') - assert.property(result.utxos[0].utxos[0], "height") - assert.property(result.utxos[0].utxos[0], "tx_hash") - assert.property(result.utxos[0].utxos[0], "tx_pos") - assert.property(result.utxos[0].utxos[0], "value") + assert.property(result.utxos[0].utxos[0], 'height') + assert.property(result.utxos[0].utxos[0], 'tx_hash') + assert.property(result.utxos[0].utxos[0], 'tx_pos') + assert.property(result.utxos[0].utxos[0], 'value') }) - it(`should throw error on array size rate limit`, async () => { + it('should throw error on array size rate limit', async () => { try { const addr = [] - for (let i = 0; i < 25; i++) - addr.push("bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf") + for (let i = 0; i < 25; i++) { addr.push('bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf') } const result = await bchjs.Electrumx.utxo(addr) console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) - describe(`#balance`, () => { - it(`should GET balance for a single address`, async () => { - const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9" + describe('#balance', () => { + it('should GET balance for a single address', async () => { + const addr = 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9' const result = await bchjs.Electrumx.balance(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "balance") - assert.property(result.balance, "confirmed") - assert.property(result.balance, "unconfirmed") + assert.property(result, 'balance') + assert.property(result.balance, 'confirmed') + assert.property(result.balance, 'unconfirmed') }) - it(`should POST request for balances for an array of addresses`, async () => { + it('should POST request for balances for an array of addresses', async () => { const addr = [ - "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf", - "bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v" + 'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf', + 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v' ] const result = await bchjs.Electrumx.balance(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "balances") + assert.property(result, 'balances') assert.isArray(result.balances) - assert.property(result.balances[0], "address") - assert.property(result.balances[0], "balance") - assert.property(result.balances[0].balance, "confirmed") - assert.property(result.balances[0].balance, "unconfirmed") + assert.property(result.balances[0], 'address') + assert.property(result.balances[0], 'balance') + assert.property(result.balances[0].balance, 'confirmed') + assert.property(result.balances[0].balance, 'unconfirmed') }) - it(`should throw error on array size rate limit`, async () => { + it('should throw error on array size rate limit', async () => { try { const addr = [] - for (let i = 0; i < 25; i++) - addr.push("bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf") + for (let i = 0; i < 25; i++) { addr.push('bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf') } const result = await bchjs.Electrumx.balance(addr) console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) - describe(`#transactions`, () => { - it(`should GET transaction history for a single address`, async () => { - const addr = "bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v" + describe('#transactions', () => { + it('should GET transaction history for a single address', async () => { + const addr = 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v' const result = await bchjs.Electrumx.transactions(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "transactions") + assert.property(result, 'transactions') assert.isArray(result.transactions) - assert.property(result.transactions[0], "height") - assert.property(result.transactions[0], "tx_hash") + assert.property(result.transactions[0], 'height') + assert.property(result.transactions[0], 'tx_hash') }) - it(`should POST request for transaction history for an array of addresses`, async () => { + it('should POST request for transaction history for an array of addresses', async () => { const addr = [ - "bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj", - "bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v" + 'bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj', + 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v' ] const result = await bchjs.Electrumx.transactions(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "transactions") + assert.property(result, 'transactions') assert.isArray(result.transactions) - assert.property(result.transactions[0], "address") - assert.property(result.transactions[0], "transactions") + assert.property(result.transactions[0], 'address') + assert.property(result.transactions[0], 'transactions') assert.isArray(result.transactions[0].transactions) - assert.property(result.transactions[0].transactions[0], "height") - assert.property(result.transactions[0].transactions[0], "tx_hash") + assert.property(result.transactions[0].transactions[0], 'height') + assert.property(result.transactions[0].transactions[0], 'tx_hash') }) - it(`should throw error on array size rate limit`, async () => { + it('should throw error on array size rate limit', async () => { try { const addr = [] - for (let i = 0; i < 25; i++) - addr.push("bitcoincash:qrehqueqhw629p6e57994436w730t4rzasnly00ht0") + for (let i = 0; i < 25; i++) { addr.push('bitcoincash:qrehqueqhw629p6e57994436w730t4rzasnly00ht0') } const result = await bchjs.Electrumx.transactions(addr) console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) - describe(`#unconfirmed`, () => { + describe('#unconfirmed', () => { // These tests won't work because unconfirmed transactions are transient in nature. /* it(`should GET unconfirmed UTXOs (mempool) for a single address`, async () => { @@ -230,137 +227,136 @@ describe(`#ElectrumX`, () => { }) */ - it(`should throw error on array size rate limit`, async () => { + it('should throw error on array size rate limit', async () => { try { const addr = [] - for (let i = 0; i < 25; i++) - addr.push("bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf") + for (let i = 0; i < 25; i++) { addr.push('bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf') } await bchjs.Electrumx.unconfirmed(addr) // console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) - describe(`#blockHeader`, () => { - it(`should GET block headers for given height and count`, async () => { + describe('#blockHeader', () => { + it('should GET block headers for given height and count', async () => { const height = 42 const count = 2 const result = await bchjs.Electrumx.blockHeader(height, count) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "headers") + assert.property(result, 'headers') assert.isArray(result.headers) assert.equal(result.headers.length, 2) }) - it(`should GET block headers for given height with default count = 1`, async () => { + it('should GET block headers for given height with default count = 1', async () => { const height = 42 const result = await bchjs.Electrumx.blockHeader(height) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "headers") + assert.property(result, 'headers') assert.isArray(result.headers) assert.equal(result.headers.length, 1) }) }) - describe(`#txData`, () => { - it(`should GET details for a single transaction`, async () => { + describe('#txData', () => { + it('should GET details for a single transaction', async () => { const txid = - "4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251" + '4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251' const result = await bchjs.Electrumx.txData(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "details") + assert.property(result, 'details') assert.isObject(result.details) - assert.property(result.details, "blockhash") - assert.property(result.details, "hash") - assert.property(result.details, "hex") - assert.property(result.details, "vin") - assert.property(result.details, "vout") + assert.property(result.details, 'blockhash') + assert.property(result.details, 'hash') + assert.property(result.details, 'hex') + assert.property(result.details, 'vin') + assert.property(result.details, 'vout') assert.equal(result.details.hash, txid) }) - it(`should POST details for an array of transactions`, async () => { + it('should POST details for an array of transactions', async () => { const txids = [ - "4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251", - "4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251" + '4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251', + '4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251' ] const result = await bchjs.Electrumx.txData(txids) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "transactions") + assert.property(result, 'transactions') assert.isArray(result.transactions) - assert.property(result.transactions[0], "txid") - assert.property(result.transactions[0], "details") + assert.property(result.transactions[0], 'txid') + assert.property(result.transactions[0], 'details') - assert.property(result.transactions[0].details, "blockhash") - assert.property(result.transactions[0].details, "hash") - assert.property(result.transactions[0].details, "hex") - assert.property(result.transactions[0].details, "vin") - assert.property(result.transactions[0].details, "vout") + assert.property(result.transactions[0].details, 'blockhash') + assert.property(result.transactions[0].details, 'hash') + assert.property(result.transactions[0].details, 'hex') + assert.property(result.transactions[0].details, 'vin') + assert.property(result.transactions[0].details, 'vout') }) - it(`should throw error on array size rate limit`, async () => { + it('should throw error on array size rate limit', async () => { try { const txids = [] for (let i = 0; i < 25; i++) { txids.push( - "4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251" + '4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251' ) } await bchjs.Electrumx.txData(txids) console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) - describe(`#broadcast`, () => { - it(`should broadcast a single transaction`, async () => { + describe('#broadcast', () => { + it('should broadcast a single transaction', async () => { const txHex = - "020000000265d13ef402840c8a51f39779afb7ae4d49e4b0a3c24a3d0e7742038f2c679667010000006441dd1dd72770cadede1a7fd0363574846c48468a398ddfa41a9677c74cac8d2652b682743725a3b08c6c2021a629011e11a264d9036e9d5311e35b5f4937ca7b4e4121020797d8fd4d2fa6fd7cdeabe2526bfea2b90525d6e8ad506ec4ee3c53885aa309ffffffff65d13ef402840c8a51f39779afb7ae4d49e4b0a3c24a3d0e7742038f2c679667000000006441347d7f218c11c04487c1ad8baac28928fb10e5054cd4494b94d078cfa04ccf68e064fb188127ff656c0b98e9ce87f036d183925d0d0860605877d61e90375f774121028a53f95eb631b460854fc836b2e5d31cad16364b4dc3d970babfbdcc3f2e4954ffffffff035ac355000000000017a914189ce02e332548f4804bac65cba68202c9dbf822878dfd0800000000001976a914285bb350881b21ac89724c6fb6dc914d096cd53b88acf9ef3100000000001976a91445f1f1c4a9b9419a5088a3e9c24a293d7a150e6488ac00000000" + '020000000265d13ef402840c8a51f39779afb7ae4d49e4b0a3c24a3d0e7742038f2c679667010000006441dd1dd72770cadede1a7fd0363574846c48468a398ddfa41a9677c74cac8d2652b682743725a3b08c6c2021a629011e11a264d9036e9d5311e35b5f4937ca7b4e4121020797d8fd4d2fa6fd7cdeabe2526bfea2b90525d6e8ad506ec4ee3c53885aa309ffffffff65d13ef402840c8a51f39779afb7ae4d49e4b0a3c24a3d0e7742038f2c679667000000006441347d7f218c11c04487c1ad8baac28928fb10e5054cd4494b94d078cfa04ccf68e064fb188127ff656c0b98e9ce87f036d183925d0d0860605877d61e90375f774121028a53f95eb631b460854fc836b2e5d31cad16364b4dc3d970babfbdcc3f2e4954ffffffff035ac355000000000017a914189ce02e332548f4804bac65cba68202c9dbf822878dfd0800000000001976a914285bb350881b21ac89724c6fb6dc914d096cd53b88acf9ef3100000000001976a91445f1f1c4a9b9419a5088a3e9c24a293d7a150e6488ac00000000' try { await bchjs.Electrumx.broadcast(txHex) } catch (err) { - assert.property(err, "success") + assert.property(err, 'success') assert.equal(err.success, false) assert.include( err.error, - "the transaction was rejected by network rules" + 'the transaction was rejected by network rules' ) } }) }) }) -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/encryption.js b/test/integration/encryption.js index 8ab9d64..c7b932c 100644 --- a/test/integration/encryption.js +++ b/test/integration/encryption.js @@ -1,39 +1,39 @@ -const assert = require("chai").assert +const assert = require('chai').assert -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') const bchjs = new BCHJS() -describe("#Encryption", () => { +describe('#Encryption', () => { beforeEach(async () => { if (process.env.IS_USING_FREE_TIER) await sleep(1000) }) - describe("#getPubKey", () => { - it("should get a public key", async () => { - const addr = "bitcoincash:qpf8jv9hmqcda0502gjp7nm3g24y5h5s4unutghsxq" + describe('#getPubKey', () => { + it('should get a public key', async () => { + const addr = 'bitcoincash:qpf8jv9hmqcda0502gjp7nm3g24y5h5s4unutghsxq' const result = await bchjs.encryption.getPubKey(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "publicKey") + assert.property(result, 'publicKey') }) - it("should report when public key can not be found", async () => { - const addr = "bitcoincash:qrgqqkky28jdkv3w0ctrah0mz3jcsnsklc34gtukrh" + it('should report when public key can not be found', async () => { + const addr = 'bitcoincash:qrgqqkky28jdkv3w0ctrah0mz3jcsnsklc34gtukrh' const result = await bchjs.encryption.getPubKey(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, false) - assert.property(result, "publicKey") - assert.equal(result.publicKey, "not found") + assert.property(result, 'publicKey') + assert.equal(result.publicKey, 'not found') }) }) }) -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/implementations/sweet/rawtransaction.js b/test/integration/implementations/sweet/rawtransaction.js index d512dc1..0c4f251 100644 --- a/test/integration/implementations/sweet/rawtransaction.js +++ b/test/integration/implementations/sweet/rawtransaction.js @@ -5,20 +5,20 @@ TODO */ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert -const BCHJS = require("../../../../src/bch-js") +const BCHJS = require('../../../../src/bch-js') const bchjs = new BCHJS() // Inspect utility used for debugging. -const util = require("util") +const util = require('util') util.inspect.defaultOptions = { showHidden: true, colors: true, depth: 3 } -describe("#rawtransaction", () => { +describe('#rawtransaction', () => { beforeEach(async () => { if (process.env.IS_USING_FREE_TIER) await sleep(1000) }) @@ -29,29 +29,29 @@ describe("#rawtransaction", () => { below expect error messages returned from the server, but at least test that the server is responding on those endpoints, and responds consistently. */ - describe("sendRawTransaction", () => { - it("should send a single transaction hex", async () => { + describe('sendRawTransaction', () => { + it('should send a single transaction hex', async () => { try { const hex = - "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000" + '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000' await bchjs.RawTransactions.sendRawTransaction(hex) - //console.log(`result ${JSON.stringify(result, null, 2)}`) + // console.log(`result ${JSON.stringify(result, null, 2)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - //console.log(`err: ${util.inspect(err)}`) + // console.log(`err: ${util.inspect(err)}`) - assert.hasAllKeys(err, ["error"]) - assert.include(err.error, "Missing inputs") + assert.hasAllKeys(err, ['error']) + assert.include(err.error, 'Missing inputs') } }) - it("should send an array of tx hexes", async () => { + it('should send an array of tx hexes', async () => { try { const hexes = [ - "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000", - "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000" + '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000', + '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000' ] const result = await bchjs.RawTransactions.sendRawTransaction(hexes) @@ -59,13 +59,13 @@ describe("#rawtransaction", () => { } catch (err) { // console.log(`err: ${util.inspect(err)}`) - assert.hasAllKeys(err, ["error"]) - assert.include(err.error, "Missing inputs") + assert.hasAllKeys(err, ['error']) + assert.include(err.error, 'Missing inputs') } }) }) }) -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/implementations/sweet/slp.js b/test/integration/implementations/sweet/slp.js index 41e8fd5..f25fb4f 100644 --- a/test/integration/implementations/sweet/slp.js +++ b/test/integration/implementations/sweet/slp.js @@ -3,21 +3,21 @@ These tests are specific to the ABC chain. */ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert -const BCHJS = require("../../../../src/bch-js") +const BCHJS = require('../../../../src/bch-js') let bchjs // Inspect utility used for debugging. -const util = require("util") +const util = require('util') util.inspect.defaultOptions = { showHidden: true, colors: true, depth: 1 } -describe(`#SLP`, () => { +describe('#SLP', () => { // before(() => { // console.log(`bchjs.SLP.restURL: ${bchjs.SLP.restURL}`) // console.log(`bchjs.SLP.apiToken: ${bchjs.SLP.apiToken}`) @@ -30,63 +30,63 @@ describe(`#SLP`, () => { bchjs = new BCHJS() }) - describe("#util", () => { - describe("#tokenUtxoDetails", () => { - it("should handle a range of UTXO types", async () => { + describe('#util', () => { + describe('#tokenUtxoDetails', () => { + it('should handle a range of UTXO types', async () => { const utxos = [ // Malformed SLP tx { - note: "Malformed SLP tx", + note: 'Malformed SLP tx', tx_hash: - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a", + 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a', tx_pos: 1, value: 546 }, // Normal TX (non-SLP) { - note: "Normal TX (non-SLP)", + note: 'Normal TX (non-SLP)', tx_hash: - "01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0", + '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0', tx_pos: 0, value: 400000 }, // Valid PSF SLP tx { - note: "Valid PSF SLP tx", + note: 'Valid PSF SLP tx', tx_hash: - "daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd", + 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd', tx_pos: 1, value: 546 }, // Valid SLP token not in whitelist { - note: "Valid SLP token not in whitelist", + note: 'Valid SLP token not in whitelist', tx_hash: - "3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488", + '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488', tx_pos: 1, value: 546 }, // Token send on BCHN network. { - note: "Token send on BCHN network", + note: 'Token send on BCHN network', tx_hash: - "402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019", + '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019', tx_pos: 1, value: 546 }, // Token send on ABC network. { - note: "Token send on ABC network", + note: 'Token send on ABC network', tx_hash: - "336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d", + '336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d', tx_pos: 1, value: 546 }, // Known invalid SLP token send of PSF tokens. { - note: "Known invalid SLP token send of PSF tokens", + note: 'Known invalid SLP token send of PSF tokens', tx_hash: - "2bf691ad3679d928fef880b8a45b93b233f8fa0d0a92cf792313dbe77b1deb74", + '2bf691ad3679d928fef880b8a45b93b233f8fa0d0a92cf792313dbe77b1deb74', tx_pos: 1, value: 546 } @@ -125,51 +125,51 @@ describe(`#SLP`, () => { }) }) - describe("#validateTxid3", () => { - it("should invalidate a known invalid TXID", async () => { + describe('#validateTxid3', () => { + it('should invalidate a known invalid TXID', async () => { const txid = - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a" + 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a' const result = await bchjs.SLP.Utils.validateTxid3(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) - assert.property(result[0], "txid") + assert.property(result[0], 'txid') assert.equal(result[0].txid, txid) - assert.property(result[0], "valid") + assert.property(result[0], 'valid') assert.equal(result[0].valid, null) }) - it("should validate a known valid TXID", async () => { + it('should validate a known valid TXID', async () => { const txid = - "daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd" + 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd' const result = await bchjs.SLP.Utils.validateTxid3(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) - assert.property(result[0], "txid") + assert.property(result[0], 'txid') assert.equal(result[0].txid, txid) - assert.property(result[0], "valid") + assert.property(result[0], 'valid') assert.equal(result[0].valid, true) }) - it("should handle a mix of valid, invalid, and non-SLP txs", async () => { + it('should handle a mix of valid, invalid, and non-SLP txs', async () => { const txids = [ // Malformed SLP tx - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a", + 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a', // Normal TX (non-SLP) - "01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0", + '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0', // Valid PSF SLP tx - "daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd", + 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd', // Valid SLP token not in whitelist - "3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488", + '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488', // Unprocessed SLP TX - "402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019" + '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019' ] const result = await bchjs.SLP.Utils.validateTxid3(txids) @@ -195,21 +195,21 @@ describe(`#SLP`, () => { }) }) - describe("#validateTxid", () => { - it("should handle a mix of valid, invalid, and non-SLP txs", async () => { + describe('#validateTxid', () => { + it('should handle a mix of valid, invalid, and non-SLP txs', async () => { const txids = [ // Malformed SLP tx - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a", + 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a', // Normal TX (non-SLP) - "01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0", + '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0', // Valid PSF SLP tx - "daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd", + 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd', // Valid SLP token not in whitelist - "3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488", + '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488', // Token send on BCHN network. - "402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019", + '402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019', // Token send on ABC network. - "336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d" + '336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d' ] const result = await bchjs.SLP.Utils.validateTxid(txids) @@ -241,6 +241,6 @@ describe(`#SLP`, () => { }) // Promise-based sleep function -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/ninsight.js b/test/integration/ninsight.js index 911fef0..587938d 100644 --- a/test/integration/ninsight.js +++ b/test/integration/ninsight.js @@ -1,11 +1,11 @@ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert -const sinon = require("sinon") +const sinon = require('sinon') -const BCHJS = require("../../src/bch-js") -const bchjs = new BCHJS({ ninsightURL: "https://rest.bitcoin.com/v2" }) +const BCHJS = require('../../src/bch-js') +const bchjs = new BCHJS({ ninsightURL: 'https://rest.bitcoin.com/v2' }) -describe(`#Ninsight`, () => { +describe('#Ninsight', () => { let sandbox beforeEach(async () => { @@ -16,34 +16,34 @@ describe(`#Ninsight`, () => { afterEach(() => sandbox.restore()) - describe(`#utxo`, () => { - it(`should GET utxos for a single address`, async () => { - const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9" + describe('#utxo', () => { + it('should GET utxos for a single address', async () => { + const addr = 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9' const result = await bchjs.Ninsight.utxo(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result[0], "utxos") - assert.property(result[0], "legacyAddress") - assert.property(result[0], "cashAddress") - assert.property(result[0], "slpAddress") - assert.property(result[0], "scriptPubKey") - assert.property(result[0], "asm") + assert.property(result[0], 'utxos') + assert.property(result[0], 'legacyAddress') + assert.property(result[0], 'cashAddress') + assert.property(result[0], 'slpAddress') + assert.property(result[0], 'scriptPubKey') + assert.property(result[0], 'asm') assert.isArray(result[0].utxos) - assert.property(result[0].utxos[0], "txid") - assert.property(result[0].utxos[0], "vout") - assert.property(result[0].utxos[0], "amount") - assert.property(result[0].utxos[0], "satoshis") - assert.property(result[0].utxos[0], "height") - assert.property(result[0].utxos[0], "confirmations") + assert.property(result[0].utxos[0], 'txid') + assert.property(result[0].utxos[0], 'vout') + assert.property(result[0].utxos[0], 'amount') + assert.property(result[0].utxos[0], 'satoshis') + assert.property(result[0].utxos[0], 'height') + assert.property(result[0].utxos[0], 'confirmations') }) - it(`should POST utxo details for an array of addresses`, async () => { + it('should POST utxo details for an array of addresses', async () => { const addr = [ - "bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7", - "bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr" + 'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7', + 'bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr' ] const result = await bchjs.Ninsight.utxo(addr) @@ -52,87 +52,87 @@ describe(`#Ninsight`, () => { assert.isArray(result) assert.isArray(result[0].utxos) - assert.property(result[0], "utxos") - assert.property(result[0], "legacyAddress") - assert.property(result[0], "cashAddress") - assert.property(result[0], "slpAddress") - assert.property(result[0], "scriptPubKey") - assert.property(result[0], "asm") + assert.property(result[0], 'utxos') + assert.property(result[0], 'legacyAddress') + assert.property(result[0], 'cashAddress') + assert.property(result[0], 'slpAddress') + assert.property(result[0], 'scriptPubKey') + assert.property(result[0], 'asm') }) }) - describe(`#transactions`, () => { - it(`should POST transactions history for a single address`, async () => { - const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9" + describe('#transactions', () => { + it('should POST transactions history for a single address', async () => { + const addr = 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9' const result = await bchjs.Ninsight.transactions(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) - assert.property(result[0], "cashAddress") - assert.property(result[0], "legacyAddress") - assert.property(result[0], "txs") + assert.property(result[0], 'cashAddress') + assert.property(result[0], 'legacyAddress') + assert.property(result[0], 'txs') assert.isArray(result[0].txs) - assert.property(result[0].txs[0], "txid") - assert.property(result[0].txs[0], "vin") - assert.property(result[0].txs[0], "vout") + assert.property(result[0].txs[0], 'txid') + assert.property(result[0].txs[0], 'vin') + assert.property(result[0].txs[0], 'vout') }) - it(`should POST transactions history for an array of addresses`, async () => { + it('should POST transactions history for an array of addresses', async () => { const addr = [ - "bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7", - "bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr" + 'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7', + 'bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr' ] const result = await bchjs.Ninsight.transactions(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) - assert.property(result[0], "cashAddress") - assert.property(result[0], "legacyAddress") - assert.property(result[0], "txs") + assert.property(result[0], 'cashAddress') + assert.property(result[0], 'legacyAddress') + assert.property(result[0], 'txs') assert.isArray(result[0].txs) - assert.property(result[0].txs[0], "txid") - assert.property(result[0].txs[0], "vin") - assert.property(result[0].txs[0], "vout") + assert.property(result[0].txs[0], 'txid') + assert.property(result[0].txs[0], 'vin') + assert.property(result[0].txs[0], 'vout') }) }) - describe(`#txDetails`, () => { - it(`should POST transactions details for a single address`, async () => { - const txid = "fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33" + describe('#txDetails', () => { + it('should POST transactions details for a single address', async () => { + const txid = 'fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33' const result = await bchjs.Ninsight.txDetails(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) - assert.property(result[0], "txid") - assert.property(result[0], "version") - assert.property(result[0], "locktime") - assert.property(result[0], "vin") - assert.property(result[0], "vout") - assert.property(result[0], "blockhash") - assert.property(result[0], "blockheight") - assert.property(result[0], "confirmations") - assert.property(result[0], "time") - assert.property(result[0], "blocktime") - assert.property(result[0], "valueOut") - assert.property(result[0], "size") + assert.property(result[0], 'txid') + assert.property(result[0], 'version') + assert.property(result[0], 'locktime') + assert.property(result[0], 'vin') + assert.property(result[0], 'vout') + assert.property(result[0], 'blockhash') + assert.property(result[0], 'blockheight') + assert.property(result[0], 'confirmations') + assert.property(result[0], 'time') + assert.property(result[0], 'blocktime') + assert.property(result[0], 'valueOut') + assert.property(result[0], 'size') }) - it(`should POST transactions details for an array of addresses`, async () => { + it('should POST transactions details for an array of addresses', async () => { const txid = [ - "fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33", - "4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251" + 'fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33', + '4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251' ] const result = await bchjs.Ninsight.txDetails(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) - assert.property(result[0], "txid") - assert.property(result[0], "vin") - assert.property(result[0], "vout") + assert.property(result[0], 'txid') + assert.property(result[0], 'vin') + assert.property(result[0], 'vout') }) }) }) -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/openbazaar.js b/test/integration/openbazaar.js index f888b0b..48d495b 100644 --- a/test/integration/openbazaar.js +++ b/test/integration/openbazaar.js @@ -2,81 +2,81 @@ tests for OpenBazaar library. */ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') const bchjs = new BCHJS() -describe(`#OpenBazaar`, () => { +describe('#OpenBazaar', () => { beforeEach(async () => { if (process.env.IS_USING_FREE_TIER) await sleep(1000) }) - describe(`#Balance`, () => { - it(`should GET balance for a single address`, async () => { - const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9" + describe('#Balance', () => { + it('should GET balance for a single address', async () => { + const addr = 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9' const result = await bchjs.OpenBazaar.balance(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.hasAllKeys(result, [ - "page", - "totalPages", - "itemsOnPage", - "addrStr", - "balance", - "totalReceived", - "totalSent", - "unconfirmedBalance", - "unconfirmedTxApperances", - "txApperances", - "transactions" + 'page', + 'totalPages', + 'itemsOnPage', + 'addrStr', + 'balance', + 'totalReceived', + 'totalSent', + 'unconfirmedBalance', + 'unconfirmedTxApperances', + 'txApperances', + 'transactions' ]) assert.isArray(result.transactions) }) }) - describe(`#utxo`, () => { - it(`should GET utxos for a single address`, async () => { - const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9" + describe('#utxo', () => { + it('should GET utxos for a single address', async () => { + const addr = 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9' const result = await bchjs.OpenBazaar.utxo(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) assert.hasAllKeys(result[0], [ - "txid", - "vout", - "amount", - "height", - "confirmations", - "satoshis" + 'txid', + 'vout', + 'amount', + 'height', + 'confirmations', + 'satoshis' ]) }) }) - describe(`#tx`, () => { - it(`should GET transactions for a single address`, async () => { + describe('#tx', () => { + it('should GET transactions for a single address', async () => { const addr = - "2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7" + '2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7' const result = await bchjs.OpenBazaar.tx(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.hasAllKeys(result, [ - "txid", - "version", - "vin", - "vout", - "blockhash", - "blockheight", - "confirmations", - "blocktime", - "valueOut", - "valueIn", - "fees", - "hex", - "time" + 'txid', + 'version', + 'vin', + 'vout', + 'blockhash', + 'blockheight', + 'confirmations', + 'blocktime', + 'valueOut', + 'valueIn', + 'fees', + 'hex', + 'time' ]) assert.isArray(result.vin) assert.isArray(result.vout) @@ -84,6 +84,6 @@ describe(`#OpenBazaar`, () => { }) }) -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/price.js b/test/integration/price.js index a0eb20f..695969e 100644 --- a/test/integration/price.js +++ b/test/integration/price.js @@ -1,23 +1,23 @@ -const assert = require("chai").assert -const BCHJS = require("../../src/bch-js") +const assert = require('chai').assert +const BCHJS = require('../../src/bch-js') const bchjs = new BCHJS() -describe("#price", () => { +describe('#price', () => { beforeEach(async () => { if (process.env.IS_USING_FREE_TIER) await sleep(1000) }) - describe("#current", () => { - describe("#single currency", () => { - it("should get current price for single currency", async () => { - const result = await bchjs.Price.current("usd") + describe('#current', () => { + describe('#single currency', () => { + it('should get current price for single currency', async () => { + const result = await bchjs.Price.current('usd') assert.notEqual(0, result) }) }) }) - describe("#getUsd", () => { - it("should get the USD price of BCH", async () => { + describe('#getUsd', () => { + it('should get the USD price of BCH', async () => { const result = await bchjs.Price.getUsd() // console.log(result) @@ -25,8 +25,8 @@ describe("#price", () => { }) }) - describe("#getBchaUsd", () => { - it("should get the USD price of BCHA", async () => { + describe('#getBchaUsd', () => { + it('should get the USD price of BCHA', async () => { const result = await bchjs.Price.getBchaUsd() console.log(result) @@ -34,17 +34,17 @@ describe("#price", () => { }) }) - describe("#rates", () => { - it("should get the price of BCH in several currencies", async () => { + describe('#rates', () => { + it('should get the price of BCH in several currencies', async () => { const result = await bchjs.Price.rates() // console.log(result) - assert.property(result, "USD") - assert.property(result, "CAD") + assert.property(result, 'USD') + assert.property(result, 'CAD') }) }) }) -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/rawtransaction.js b/test/integration/rawtransaction.js index ede2a4c..5bfcd85 100644 --- a/test/integration/rawtransaction.js +++ b/test/integration/rawtransaction.js @@ -5,136 +5,136 @@ TODO */ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') const bchjs = new BCHJS() // Inspect utility used for debugging. -const util = require("util") +const util = require('util') util.inspect.defaultOptions = { showHidden: true, colors: true, depth: 3 } -describe("#rawtransaction", () => { +describe('#rawtransaction', () => { beforeEach(async () => { if (process.env.IS_USING_FREE_TIER) await sleep(1000) }) - describe("#decodeRawTransaction", () => { - it("should decode tx for a single hex", async () => { + describe('#decodeRawTransaction', () => { + it('should decode tx for a single hex', async () => { const hex = - "0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000" + '0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000' const result = await bchjs.RawTransactions.decodeRawTransaction(hex) - //console.log(`result ${JSON.stringify(result, null, 2)}`) + // console.log(`result ${JSON.stringify(result, null, 2)}`) assert.hasAnyKeys(result, [ - "txid", - "hash", - "size", - "version", - "locktime", - "vin", - "vout" + 'txid', + 'hash', + 'size', + 'version', + 'locktime', + 'vin', + 'vout' ]) assert.isArray(result.vin) assert.isArray(result.vout) }) - it("should decode an array of tx hexes", async () => { + it('should decode an array of tx hexes', async () => { const hexes = [ - "0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000", - "0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000" + '0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000', + '0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000' ] const result = await bchjs.RawTransactions.decodeRawTransaction(hexes) - //console.log(`result ${JSON.stringify(result, null, 2)}`) + // console.log(`result ${JSON.stringify(result, null, 2)}`) assert.isArray(result) assert.hasAnyKeys(result[0], [ - "txid", - "hash", - "size", - "version", - "locktime", - "vin", - "vout" + 'txid', + 'hash', + 'size', + 'version', + 'locktime', + 'vin', + 'vout' ]) assert.isArray(result[0].vin) assert.isArray(result[0].vout) }) - it(`should throw error on array size rate limit`, async () => { + it('should throw error on array size rate limit', async () => { try { const data = [] for (let i = 0; i < 25; i++) { data.push( - "0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000" + '0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000' ) } const result = await bchjs.RawTransactions.decodeRawTransaction(data) console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) - describe("#getRawTransaction", () => { - it("should decode a single txid, with concise output", async () => { + describe('#getRawTransaction', () => { + it('should decode a single txid, with concise output', async () => { const txid = - "23213453b4642a73b4fc30d3112d72549ca153a8707255b14373b59e43558de1" + '23213453b4642a73b4fc30d3112d72549ca153a8707255b14373b59e43558de1' const verbose = false const result = await bchjs.RawTransactions.getRawTransaction( txid, verbose ) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isString(result) }) - it("should decode a single txid, with verbose output", async () => { + it('should decode a single txid, with verbose output', async () => { const txid = - "23213453b4642a73b4fc30d3112d72549ca153a8707255b14373b59e43558de1" + '23213453b4642a73b4fc30d3112d72549ca153a8707255b14373b59e43558de1' const verbose = true const result = await bchjs.RawTransactions.getRawTransaction( txid, verbose ) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.hasAnyKeys(result, [ - "hex", - "txid", - "hash", - "size", - "version", - "locktime", - "vin", - "vout", - "blockhash", - "confirmations", - "time", - "blocktime" + 'hex', + 'txid', + 'hash', + 'size', + 'version', + 'locktime', + 'vin', + 'vout', + 'blockhash', + 'confirmations', + 'time', + 'blocktime' ]) assert.isArray(result.vin) assert.isArray(result.vout) }) - it("should decode an array of txids, with a concise output", async () => { + it('should decode an array of txids, with a concise output', async () => { const txid = [ - "23213453b4642a73b4fc30d3112d72549ca153a8707255b14373b59e43558de1", - "b25d24fbb42d84812ed2cb55797f10fdec41afc7906ab563d1ec8c8676a2037f" + '23213453b4642a73b4fc30d3112d72549ca153a8707255b14373b59e43558de1', + 'b25d24fbb42d84812ed2cb55797f10fdec41afc7906ab563d1ec8c8676a2037f' ] const verbose = false @@ -142,16 +142,16 @@ describe("#rawtransaction", () => { txid, verbose ) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) assert.isString(result[0]) }) - it("should decode an array of txids, with a verbose output", async () => { + it('should decode an array of txids, with a verbose output', async () => { const txid = [ - "23213453b4642a73b4fc30d3112d72549ca153a8707255b14373b59e43558de1", - "b25d24fbb42d84812ed2cb55797f10fdec41afc7906ab563d1ec8c8676a2037f" + '23213453b4642a73b4fc30d3112d72549ca153a8707255b14373b59e43558de1', + 'b25d24fbb42d84812ed2cb55797f10fdec41afc7906ab563d1ec8c8676a2037f' ] const verbose = true @@ -159,54 +159,54 @@ describe("#rawtransaction", () => { txid, verbose ) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) assert.hasAnyKeys(result[0], [ - "hex", - "txid", - "hash", - "size", - "version", - "locktime", - "vin", - "vout", - "blockhash", - "confirmations", - "time", - "blocktime" + 'hex', + 'txid', + 'hash', + 'size', + 'version', + 'locktime', + 'vin', + 'vout', + 'blockhash', + 'confirmations', + 'time', + 'blocktime' ]) assert.isArray(result[0].vin) assert.isArray(result[0].vout) }) - it(`should throw error on array size rate limit`, async () => { + it('should throw error on array size rate limit', async () => { try { const dataMock = - "23213453b4642a73b4fc30d3112d72549ca153a8707255b14373b59e43558de1" + '23213453b4642a73b4fc30d3112d72549ca153a8707255b14373b59e43558de1' const data = [] for (let i = 0; i < 25; i++) data.push(dataMock) const result = await bchjs.RawTransactions.getRawTransaction(data) console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) - describe("#decodeScript", () => { - it("should decode script for a single hex", async () => { + describe('#decodeScript', () => { + it('should decode script for a single hex', async () => { const hex = - "4830450221009a51e00ec3524a7389592bc27bea4af5104a59510f5f0cfafa64bbd5c164ca2e02206c2a8bbb47eabdeed52f17d7df668d521600286406930426e3a9415fe10ed592012102e6e1423f7abde8b70bca3e78a7d030e5efabd3eb35c19302542b5fe7879c1a16" + '4830450221009a51e00ec3524a7389592bc27bea4af5104a59510f5f0cfafa64bbd5c164ca2e02206c2a8bbb47eabdeed52f17d7df668d521600286406930426e3a9415fe10ed592012102e6e1423f7abde8b70bca3e78a7d030e5efabd3eb35c19302542b5fe7879c1a16' const result = await bchjs.RawTransactions.decodeScript(hex) - //console.log(`result ${JSON.stringify(result, null, 2)}`) + // console.log(`result ${JSON.stringify(result, null, 2)}`) - assert.hasAllKeys(result, ["asm", "type", "p2sh"]) + assert.hasAllKeys(result, ['asm', 'type', 'p2sh']) }) // CT 2/20/19 - Waiting for this PR to be merged complete the test: @@ -230,26 +230,26 @@ describe("#rawtransaction", () => { below expect error messages returned from the server, but at least test that the server is responding on those endpoints, and responds consistently. */ - describe("sendRawTransaction", () => { - it(`should throw error on array size rate limit`, async () => { + describe('sendRawTransaction', () => { + it('should throw error on array size rate limit', async () => { try { const dataMock = - "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000" + '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000' const data = [] for (let i = 0; i < 25; i++) data.push(dataMock) const result = await bchjs.RawTransactions.sendRawTransaction(data) console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) }) -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/slp.js b/test/integration/slp.js index faa0b8b..e535988 100644 --- a/test/integration/slp.js +++ b/test/integration/slp.js @@ -2,21 +2,21 @@ Integration tests for the bchjs covering SLP tokens. */ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') let bchjs // Inspect utility used for debugging. -const util = require("util") +const util = require('util') util.inspect.defaultOptions = { showHidden: true, colors: true, depth: 1 } -describe(`#SLP`, () => { +describe('#SLP', () => { // before(() => { // console.log(`bchjs.SLP.restURL: ${bchjs.SLP.restURL}`) // console.log(`bchjs.SLP.apiToken: ${bchjs.SLP.apiToken}`) @@ -29,35 +29,35 @@ describe(`#SLP`, () => { bchjs = new BCHJS() }) - describe("#util", () => { - describe("#list", () => { - it(`should get information on the Spice token`, async () => { - const tokenId = `4de69e374a8ed21cbddd47f2338cc0f479dc58daa2bbe11cd604ca488eca0ddf` + describe('#util', () => { + describe('#list', () => { + it('should get information on the Spice token', async () => { + const tokenId = '4de69e374a8ed21cbddd47f2338cc0f479dc58daa2bbe11cd604ca488eca0ddf' const result = await bchjs.SLP.Utils.list(tokenId) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.hasAnyKeys(result, [ - "decimals", - "timestamp", - "timestamp_unix", - "versionType", - "documentUri", - "symbol", - "name", - "containsBaton", - "id", - "documentHash", - "initialTokenQty", - "blockCreated", - "blockLastActiveSend", - "blockLastActiveMint", - "txnsSinceGenesis", - "validAddress", - "totalMinted", - "totalBurned", - "circulatingSupply", - "mintingBatonStatus" + 'decimals', + 'timestamp', + 'timestamp_unix', + 'versionType', + 'documentUri', + 'symbol', + 'name', + 'containsBaton', + 'id', + 'documentHash', + 'initialTokenQty', + 'blockCreated', + 'blockLastActiveSend', + 'blockLastActiveMint', + 'txnsSinceGenesis', + 'validAddress', + 'totalMinted', + 'totalBurned', + 'circulatingSupply', + 'mintingBatonStatus' ]) }) }) @@ -134,109 +134,109 @@ describe(`#SLP`, () => { // }) // }) - describe("#decodeOpReturn", () => { - it("should decode the OP_RETURN for a SEND txid", async () => { + describe('#decodeOpReturn', () => { + it('should decode the OP_RETURN for a SEND txid', async () => { const txid = - "266844d53e46bbd7dd37134688dffea6e54d944edff27a0add63dd0908839bc1" + '266844d53e46bbd7dd37134688dffea6e54d944edff27a0add63dd0908839bc1' const result = await bchjs.SLP.Utils.decodeOpReturn(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.hasAllKeys(result, ["tokenType", "txType", "tokenId", "amounts"]) + assert.hasAllKeys(result, ['tokenType', 'txType', 'tokenId', 'amounts']) assert.equal( result.tokenId, - "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7" + '497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7' ) // Verify outputs assert.equal(result.amounts.length, 2) - assert.equal(result.amounts[0], "100000000") - assert.equal(result.amounts[1], "99883300000000") + assert.equal(result.amounts[0], '100000000') + assert.equal(result.amounts[1], '99883300000000') }) - it("should decode the OP_RETURN for a GENESIS txid", async () => { + it('should decode the OP_RETURN for a GENESIS txid', async () => { const txid = - "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7" + '497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7' const result = await bchjs.SLP.Utils.decodeOpReturn(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.hasAllKeys(result, [ - "tokenType", - "txType", - "tokenId", - "ticker", - "name", - "documentUri", - "documentHash", - "decimals", - "mintBatonVout", - "qty" + 'tokenType', + 'txType', + 'tokenId', + 'ticker', + 'name', + 'documentUri', + 'documentHash', + 'decimals', + 'mintBatonVout', + 'qty' ]) assert.equal( result.tokenId, - "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7" + '497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7' ) - assert.equal(result.txType, "GENESIS") - assert.equal(result.ticker, "TOK-CH") - assert.equal(result.name, "TokyoCash") + assert.equal(result.txType, 'GENESIS') + assert.equal(result.ticker, 'TOK-CH') + assert.equal(result.name, 'TokyoCash') }) - it("should decode the OP_RETURN for a MINT txid", async () => { + it('should decode the OP_RETURN for a MINT txid', async () => { const txid = - "65f21bbfcd545e5eb515e38e861a9dfe2378aaa2c4e458eb9e59e4d40e38f3a4" + '65f21bbfcd545e5eb515e38e861a9dfe2378aaa2c4e458eb9e59e4d40e38f3a4' const result = await bchjs.SLP.Utils.decodeOpReturn(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.hasAllKeys(result, [ - "tokenType", - "txType", - "tokenId", - "mintBatonVout", - "qty" + 'tokenType', + 'txType', + 'tokenId', + 'mintBatonVout', + 'qty' ]) }) - it("should throw an error for a non-SLP transaction", async () => { + it('should throw an error for a non-SLP transaction', async () => { try { const txid = - "3793d4906654f648e659f384c0f40b19c8f10c1e9fb72232a9b8edd61abaa1ec" + '3793d4906654f648e659f384c0f40b19c8f10c1e9fb72232a9b8edd61abaa1ec' await bchjs.SLP.Utils.decodeOpReturn(txid) - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { // console.log(`err: `, err) - assert.include(err.message, "scriptpubkey not op_return") + assert.include(err.message, 'scriptpubkey not op_return') } }) // Note: This TX is interpreted as valid by the original decodeOpReturn(). // Fixing this issue and related issues was the reason for creating the // decodeOpReturn2() method using the slp-parser library. - it("should throw error for invalid SLP transaction", async () => { + it('should throw error for invalid SLP transaction', async () => { try { const txid = - "a60a522cc11ad7011b74e57fbabbd99296e4b9346bcb175dcf84efb737030415" + 'a60a522cc11ad7011b74e57fbabbd99296e4b9346bcb175dcf84efb737030415' await bchjs.SLP.Utils.decodeOpReturn(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) } catch (err) { // console.log(`err: `, err) - assert.include(err.message, "amount string size not 8 bytes") + assert.include(err.message, 'amount string size not 8 bytes') } }) }) - describe("#tokenUtxoDetails", () => { + describe('#tokenUtxoDetails', () => { // // This captures an important corner-case. When an SLP token is created, the // // change UTXO will contain the same SLP txid, but it is not an SLP UTXO. - it("should return details on minting baton from genesis transaction", async () => { + it('should return details on minting baton from genesis transaction', async () => { const utxos = [ { txid: - "bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90", + 'bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90', vout: 3, amount: 0.00002015, satoshis: 2015, @@ -245,7 +245,7 @@ describe(`#SLP`, () => { }, { txid: - "bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90", + 'bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90', vout: 2, amount: 0.00000546, satoshis: 546, @@ -257,32 +257,32 @@ describe(`#SLP`, () => { const data = await bchjs.SLP.Utils.tokenUtxoDetails(utxos) // console.log(`data: ${JSON.stringify(data, null, 2)}`) - assert.equal(data[0].isValid, false, "Change UTXO marked as false.") + assert.equal(data[0].isValid, false, 'Change UTXO marked as false.') - assert.property(data[1], "txid") - assert.property(data[1], "vout") - assert.property(data[1], "amount") - assert.property(data[1], "satoshis") - assert.property(data[1], "height") - assert.property(data[1], "confirmations") - assert.property(data[1], "utxoType") - assert.property(data[1], "tokenId") - assert.property(data[1], "tokenTicker") - assert.property(data[1], "tokenName") - assert.property(data[1], "tokenDocumentUrl") - assert.property(data[1], "tokenDocumentHash") - assert.property(data[1], "decimals") - assert.property(data[1], "isValid") + assert.property(data[1], 'txid') + assert.property(data[1], 'vout') + assert.property(data[1], 'amount') + assert.property(data[1], 'satoshis') + assert.property(data[1], 'height') + assert.property(data[1], 'confirmations') + assert.property(data[1], 'utxoType') + assert.property(data[1], 'tokenId') + assert.property(data[1], 'tokenTicker') + assert.property(data[1], 'tokenName') + assert.property(data[1], 'tokenDocumentUrl') + assert.property(data[1], 'tokenDocumentHash') + assert.property(data[1], 'decimals') + assert.property(data[1], 'isValid') assert.equal(data[1].isValid, true) }) - it("should return details for a MINT token utxo", async () => { + it('should return details for a MINT token utxo', async () => { // Mock the call to REST API const utxos = [ { txid: - "cf4b922d1e1aa56b52d752d4206e1448ea76c3ebe69b3b97d8f8f65413bd5c76", + 'cf4b922d1e1aa56b52d752d4206e1448ea76c3ebe69b3b97d8f8f65413bd5c76', vout: 1, amount: 0.00000546, satoshis: 546, @@ -294,31 +294,31 @@ describe(`#SLP`, () => { const data = await bchjs.SLP.Utils.tokenUtxoDetails(utxos) // console.log(`data: ${JSON.stringify(data, null, 2)}`) - assert.property(data[0], "txid") - assert.property(data[0], "vout") - assert.property(data[0], "amount") - assert.property(data[0], "satoshis") - assert.property(data[0], "height") - assert.property(data[0], "confirmations") - assert.property(data[0], "utxoType") - assert.property(data[0], "transactionType") - assert.property(data[0], "tokenId") - assert.property(data[0], "tokenTicker") - assert.property(data[0], "tokenName") - assert.property(data[0], "tokenDocumentUrl") - assert.property(data[0], "tokenDocumentHash") - assert.property(data[0], "decimals") - assert.property(data[0], "mintBatonVout") - assert.property(data[0], "tokenQty") - assert.property(data[0], "isValid") + assert.property(data[0], 'txid') + assert.property(data[0], 'vout') + assert.property(data[0], 'amount') + assert.property(data[0], 'satoshis') + assert.property(data[0], 'height') + assert.property(data[0], 'confirmations') + assert.property(data[0], 'utxoType') + assert.property(data[0], 'transactionType') + assert.property(data[0], 'tokenId') + assert.property(data[0], 'tokenTicker') + assert.property(data[0], 'tokenName') + assert.property(data[0], 'tokenDocumentUrl') + assert.property(data[0], 'tokenDocumentHash') + assert.property(data[0], 'decimals') + assert.property(data[0], 'mintBatonVout') + assert.property(data[0], 'tokenQty') + assert.property(data[0], 'isValid') assert.equal(data[0].isValid, true) }) - it("should return details for a simple SEND SLP token utxo", async () => { + it('should return details for a simple SEND SLP token utxo', async () => { const utxos = [ { txid: - "fde117b1f176b231e2fa9a6cb022e0f7c31c288221df6bcb05f8b7d040ca87cb", + 'fde117b1f176b231e2fa9a6cb022e0f7c31c288221df6bcb05f8b7d040ca87cb', vout: 1, amount: 0.00000546, satoshis: 546, @@ -330,40 +330,40 @@ describe(`#SLP`, () => { const data = await bchjs.SLP.Utils.tokenUtxoDetails(utxos) // console.log(`data: ${JSON.stringify(data, null, 2)}`) - assert.property(data[0], "txid") - assert.property(data[0], "vout") - assert.property(data[0], "amount") - assert.property(data[0], "satoshis") - assert.property(data[0], "height") - assert.property(data[0], "confirmations") - assert.property(data[0], "utxoType") - assert.property(data[0], "tokenId") - assert.property(data[0], "tokenTicker") - assert.property(data[0], "tokenName") - assert.property(data[0], "tokenDocumentUrl") - assert.property(data[0], "tokenDocumentHash") - assert.property(data[0], "decimals") - assert.property(data[0], "tokenQty") - assert.property(data[0], "isValid") + assert.property(data[0], 'txid') + assert.property(data[0], 'vout') + assert.property(data[0], 'amount') + assert.property(data[0], 'satoshis') + assert.property(data[0], 'height') + assert.property(data[0], 'confirmations') + assert.property(data[0], 'utxoType') + assert.property(data[0], 'tokenId') + assert.property(data[0], 'tokenTicker') + assert.property(data[0], 'tokenName') + assert.property(data[0], 'tokenDocumentUrl') + assert.property(data[0], 'tokenDocumentHash') + assert.property(data[0], 'decimals') + assert.property(data[0], 'tokenQty') + assert.property(data[0], 'isValid') assert.equal(data[0].isValid, true) }) - it("should handle BCH and SLP utxos in the same TX", async () => { + it('should handle BCH and SLP utxos in the same TX', async () => { const utxos = [ { txid: - "d56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56", + 'd56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56', vout: 3, - value: "6816", + value: '6816', height: 606848, confirmations: 13, satoshis: 6816 }, { txid: - "d56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56", + 'd56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56', vout: 2, - value: "546", + value: '546', height: 606848, confirmations: 13, satoshis: 546 @@ -379,11 +379,11 @@ describe(`#SLP`, () => { assert.equal(result[1].isValid, true) }) - it("should handle problematic utxos", async () => { + it('should handle problematic utxos', async () => { const utxos = [ { txid: - "0e3a217fc22612002031d317b4cecd9b692b66b52951a67b23c43041aefa3959", + '0e3a217fc22612002031d317b4cecd9b692b66b52951a67b23c43041aefa3959', vout: 0, amount: 0.00018362, satoshis: 18362, @@ -392,7 +392,7 @@ describe(`#SLP`, () => { }, { txid: - "67fd3c7c3a6eb0fea9ab311b91039545086220f7eeeefa367fa28e6e43009f19", + '67fd3c7c3a6eb0fea9ab311b91039545086220f7eeeefa367fa28e6e43009f19', vout: 1, amount: 0.00000546, satoshis: 546, @@ -410,11 +410,11 @@ describe(`#SLP`, () => { assert.equal(result[1].isValid, true) }) - it("should return false for BCH-only UTXOs", async () => { + it('should return false for BCH-only UTXOs', async () => { const utxos = [ { txid: - "a937f792c7c9eb23b4f344ce5c233d1ac0909217d0a504d71e6b1e4efb864a3b", + 'a937f792c7c9eb23b4f344ce5c233d1ac0909217d0a504d71e6b1e4efb864a3b', vout: 0, amount: 0.00001, satoshis: 1000, @@ -423,7 +423,7 @@ describe(`#SLP`, () => { }, { txid: - "53fd141c2e999e080a5860887441a2c45e9cbe262027e2bd2ac998fc76e43c44", + '53fd141c2e999e080a5860887441a2c45e9cbe262027e2bd2ac998fc76e43c44', vout: 0, amount: 0.00001, satoshis: 1000, @@ -440,20 +440,20 @@ describe(`#SLP`, () => { assert.equal(data[1].isValid, false) }) - it("should handle a dust attack", async () => { + it('should handle a dust attack', async () => { // it("#dustattack", async () => { const utxos = [ { height: 655965, tx_hash: - "a675af87dcd8d39be782737aa52e0076b52eb2f5ce355ffcb5567a64dd96b77e", + 'a675af87dcd8d39be782737aa52e0076b52eb2f5ce355ffcb5567a64dd96b77e', tx_pos: 151, value: 547, satoshis: 547, txid: - "a675af87dcd8d39be782737aa52e0076b52eb2f5ce355ffcb5567a64dd96b77e", + 'a675af87dcd8d39be782737aa52e0076b52eb2f5ce355ffcb5567a64dd96b77e', vout: 151, - address: "bitcoincash:qq4dw3sm8qvglspy6w2qg0u2ugsy9zcfcqrpeflwww", + address: 'bitcoincash:qq4dw3sm8qvglspy6w2qg0u2ugsy9zcfcqrpeflwww', hdIndex: 11 } ] @@ -464,19 +464,19 @@ describe(`#SLP`, () => { assert.equal(data[0].isValid, false) }) - it("should handle null SLPDB validations", async () => { + it('should handle null SLPDB validations', async () => { const utxos = [ { height: 665577, tx_hash: - "4b89405c54d1c0bde8aa476a47561a42a6e7a5e927daa2ec69d428810eae3419", + '4b89405c54d1c0bde8aa476a47561a42a6e7a5e927daa2ec69d428810eae3419', tx_pos: 1, value: 546 }, { height: 665577, tx_hash: - "3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488", + '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488', tx_pos: 1, value: 546 } @@ -490,27 +490,27 @@ describe(`#SLP`, () => { }) }) - describe("#balancesForAddress", () => { - it(`should fetch all balances for address: simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9`, async () => { + describe('#balancesForAddress', () => { + it('should fetch all balances for address: simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9', async () => { const balances = await bchjs.SLP.Utils.balancesForAddress( - "simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9" + 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9' ) // console.log(`balances: ${JSON.stringify(balances, null, 2)}`) assert.isArray(balances) assert.hasAllKeys(balances[0], [ - "tokenId", - "balanceString", - "balance", - "decimalCount", - "slpAddress" + 'tokenId', + 'balanceString', + 'balance', + 'decimalCount', + 'slpAddress' ]) }) - it(`should fetch balances for multiple addresses`, async () => { + it('should fetch balances for multiple addresses', async () => { const addresses = [ - "simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9", - "simpleledger:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5ucdyl3r57" + 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9', + 'simpleledger:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5ucdyl3r57' ] const balances = await bchjs.SLP.Utils.balancesForAddress(addresses) @@ -519,34 +519,34 @@ describe(`#SLP`, () => { assert.isArray(balances) assert.isArray(balances[0]) assert.hasAllKeys(balances[0][0], [ - "tokenId", - "balanceString", - "balance", - "decimalCount", - "slpAddress" + 'tokenId', + 'balanceString', + 'balance', + 'decimalCount', + 'slpAddress' ]) }) }) - describe("#hydrateUtxos", () => { - it("should hydrate UTXOs", async () => { + describe('#hydrateUtxos', () => { + it('should hydrate UTXOs', async () => { const utxos = [ { utxos: [ { txid: - "d56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56", + 'd56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56', vout: 3, - value: "6816", + value: '6816', height: 606848, confirmations: 13, satoshis: 6816 }, { txid: - "d56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56", + 'd56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56', vout: 2, - value: "546", + value: '546', height: 606848, confirmations: 13, satoshis: 546 @@ -564,40 +564,40 @@ describe(`#SLP`, () => { assert.equal(result.slpUtxos[0].utxos.length, 2) // Test the non-slp UTXO. - assert.property(result.slpUtxos[0].utxos[0], "txid") - assert.property(result.slpUtxos[0].utxos[0], "vout") - assert.property(result.slpUtxos[0].utxos[0], "value") - assert.property(result.slpUtxos[0].utxos[0], "height") - assert.property(result.slpUtxos[0].utxos[0], "confirmations") - assert.property(result.slpUtxos[0].utxos[0], "satoshis") - assert.property(result.slpUtxos[0].utxos[0], "isValid") + assert.property(result.slpUtxos[0].utxos[0], 'txid') + assert.property(result.slpUtxos[0].utxos[0], 'vout') + assert.property(result.slpUtxos[0].utxos[0], 'value') + assert.property(result.slpUtxos[0].utxos[0], 'height') + assert.property(result.slpUtxos[0].utxos[0], 'confirmations') + assert.property(result.slpUtxos[0].utxos[0], 'satoshis') + assert.property(result.slpUtxos[0].utxos[0], 'isValid') assert.equal(result.slpUtxos[0].utxos[0].isValid, false) // Test the slp UTXO. - assert.property(result.slpUtxos[0].utxos[1], "txid") - assert.property(result.slpUtxos[0].utxos[1], "vout") - assert.property(result.slpUtxos[0].utxos[1], "value") - assert.property(result.slpUtxos[0].utxos[1], "height") - assert.property(result.slpUtxos[0].utxos[1], "confirmations") - assert.property(result.slpUtxos[0].utxos[1], "satoshis") - assert.property(result.slpUtxos[0].utxos[1], "isValid") + assert.property(result.slpUtxos[0].utxos[1], 'txid') + assert.property(result.slpUtxos[0].utxos[1], 'vout') + assert.property(result.slpUtxos[0].utxos[1], 'value') + assert.property(result.slpUtxos[0].utxos[1], 'height') + assert.property(result.slpUtxos[0].utxos[1], 'confirmations') + assert.property(result.slpUtxos[0].utxos[1], 'satoshis') + assert.property(result.slpUtxos[0].utxos[1], 'isValid') assert.equal(result.slpUtxos[0].utxos[1].isValid, true) - assert.property(result.slpUtxos[0].utxos[1], "transactionType") - assert.property(result.slpUtxos[0].utxos[1], "tokenId") - assert.property(result.slpUtxos[0].utxos[1], "tokenTicker") - assert.property(result.slpUtxos[0].utxos[1], "tokenName") - assert.property(result.slpUtxos[0].utxos[1], "tokenDocumentUrl") - assert.property(result.slpUtxos[0].utxos[1], "tokenDocumentHash") - assert.property(result.slpUtxos[0].utxos[1], "decimals") - assert.property(result.slpUtxos[0].utxos[1], "tokenType") - assert.property(result.slpUtxos[0].utxos[1], "tokenQty") + assert.property(result.slpUtxos[0].utxos[1], 'transactionType') + assert.property(result.slpUtxos[0].utxos[1], 'tokenId') + assert.property(result.slpUtxos[0].utxos[1], 'tokenTicker') + assert.property(result.slpUtxos[0].utxos[1], 'tokenName') + assert.property(result.slpUtxos[0].utxos[1], 'tokenDocumentUrl') + assert.property(result.slpUtxos[0].utxos[1], 'tokenDocumentHash') + assert.property(result.slpUtxos[0].utxos[1], 'decimals') + assert.property(result.slpUtxos[0].utxos[1], 'tokenType') + assert.property(result.slpUtxos[0].utxos[1], 'tokenQty') }) - it("should process data directly from Electrumx", async () => { + it('should process data directly from Electrumx', async () => { const addrs = [ - "bitcoincash:qqnt53cfw990u6y38xgezm0lfa8hknw0wueezcpagp", - "bitcoincash:qrh3qgtax6adegzc7zxm6m4sgrv9wq28yqnfn33ce5", - "bitcoincash:qqcaee5w4ws77n8s2gzy6fwtma6uxd7ctq8553e495" + 'bitcoincash:qqnt53cfw990u6y38xgezm0lfa8hknw0wueezcpagp', + 'bitcoincash:qrh3qgtax6adegzc7zxm6m4sgrv9wq28yqnfn33ce5', + 'bitcoincash:qqcaee5w4ws77n8s2gzy6fwtma6uxd7ctq8553e495' ] const utxos = await bchjs.Electrumx.utxo(addrs) @@ -617,31 +617,31 @@ describe(`#SLP`, () => { // Test the expected values. assert.equal(result.slpUtxos[0].utxos[0].isValid, false) assert.equal(result.slpUtxos[1].utxos[0].isValid, true) - assert.equal(result.slpUtxos[1].utxos[0].tokenTicker, "TROUT") + assert.equal(result.slpUtxos[1].utxos[0].tokenTicker, 'TROUT') assert.equal(result.slpUtxos[2].utxos[0].isValid, false) assert.equal(result.slpUtxos[2].utxos[1].isValid, true) - assert.equal(result.slpUtxos[2].utxos[1].tokenTicker, "VALENTINE") + assert.equal(result.slpUtxos[2].utxos[1].tokenTicker, 'VALENTINE') } catch (err) { console.error( 'The hydrateUtxos call may hitting rate limits, or SLPDB may be having issues if "isValid" results are "null"' ) - console.log("Error: ", err) + console.log('Error: ', err) } }) - it("should handle null SLPDB validations", async () => { + it('should handle null SLPDB validations', async () => { const utxos = [ { height: 665577, tx_hash: - "4b89405c54d1c0bde8aa476a47561a42a6e7a5e927daa2ec69d428810eae3419", + '4b89405c54d1c0bde8aa476a47561a42a6e7a5e927daa2ec69d428810eae3419', tx_pos: 1, value: 546 }, { height: 665577, tx_hash: - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a", + 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a', tx_pos: 1, value: 546 } @@ -655,11 +655,11 @@ describe(`#SLP`, () => { }) }) - describe("#validateTxid", () => { + describe('#validateTxid', () => { // This test is not necessary. - it("should handle a null response from SLPDB", async () => { + it('should handle a null response from SLPDB', async () => { const txid = - "4b89405c54d1c0bde8aa476a47561a42a6e7a5e927daa2ec69d428810eae3419" + '4b89405c54d1c0bde8aa476a47561a42a6e7a5e927daa2ec69d428810eae3419' const result = await bchjs.SLP.Utils.validateTxid(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) @@ -669,10 +669,10 @@ describe(`#SLP`, () => { // assert.equal(result[0].valid, null) }) - it("should handle a null response from SLPDB", async () => { + it('should handle a null response from SLPDB', async () => { const txid = [ - "4b89405c54d1c0bde8aa476a47561a42a6e7a5e927daa2ec69d428810eae3419", - "3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488" + '4b89405c54d1c0bde8aa476a47561a42a6e7a5e927daa2ec69d428810eae3419', + '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488' ] const result = await bchjs.SLP.Utils.validateTxid(txid) @@ -684,66 +684,66 @@ describe(`#SLP`, () => { }) }) - describe("#validateTxid2", () => { - it("should invalidate a known invalid TXID", async () => { + describe('#validateTxid2', () => { + it('should invalidate a known invalid TXID', async () => { const txid = - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a" + 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a' const result = await bchjs.SLP.Utils.validateTxid2(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "txid") + assert.property(result, 'txid') assert.equal(result.txid, txid) - assert.property(result, "isValid") + assert.property(result, 'isValid') assert.equal(result.isValid, false) }) - it("should validate a known valid TXID", async () => { + it('should validate a known valid TXID', async () => { const txid = - "3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488" + '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488' const result = await bchjs.SLP.Utils.validateTxid2(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "txid") + assert.property(result, 'txid') assert.equal(result.txid, txid) - assert.property(result, "isValid") + assert.property(result, 'isValid') assert.equal(result.isValid, true) }) }) - describe("#getWhitelist", () => { - it("should get the whitelist", async () => { + describe('#getWhitelist', () => { + it('should get the whitelist', async () => { const result = await bchjs.SLP.Utils.getWhitelist() // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) - assert.property(result[0], "name") - assert.property(result[1], "tokenId") + assert.property(result[0], 'name') + assert.property(result[1], 'tokenId') }) }) - describe("#getStatus", () => { - it("should return the current block height of the SLPDB indexer", async () => { + describe('#getStatus', () => { + it('should return the current block height of the SLPDB indexer', async () => { const result = await bchjs.SLP.Utils.getStatus() // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "bchBlockHeight") - assert.property(result, "slpProcessedBlockHeight") + assert.property(result, 'bchBlockHeight') + assert.property(result, 'slpProcessedBlockHeight') }) }) }) - describe("#tokentype1", () => { - describe("#getHexOpReturn", () => { - it("should return OP_RETURN object ", async () => { + describe('#tokentype1', () => { + describe('#getHexOpReturn', () => { + it('should return OP_RETURN object ', async () => { const tokenUtxos = [ { tokenId: - "0a321bff9761f28e06a268b14711274bb77617410a16807bd0437ef234a072b1", + '0a321bff9761f28e06a268b14711274bb77617410a16807bd0437ef234a072b1', decimals: 0, tokenQty: 2 } @@ -756,10 +756,10 @@ describe(`#SLP`, () => { ) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "script") + assert.property(result, 'script') assert.isString(result.script) - assert.property(result, "outputs") + assert.property(result, 'outputs') assert.isNumber(result.outputs) }) }) @@ -767,6 +767,6 @@ describe(`#SLP`, () => { }) // Promise-based sleep function -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/integration/util.js b/test/integration/util.js index 90dc34e..f1ce7f4 100644 --- a/test/integration/util.js +++ b/test/integration/util.js @@ -3,100 +3,100 @@ rest.bitcoin.com. */ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') const bchjs = new BCHJS() // Inspect utility used for debugging. -const util = require("util") +const util = require('util') util.inspect.defaultOptions = { showHidden: true, colors: true, depth: 3 } -describe(`#util`, () => { +describe('#util', () => { beforeEach(async () => { if (process.env.IS_USING_FREE_TIER) await sleep(1000) }) - describe(`#validateAddress`, () => { - it(`should return false for testnet addr on mainnet`, async () => { - const address = `bchtest:qqqk4y6lsl5da64sg5qc3xezmplyu5kmpyz2ysaa5y` + describe('#validateAddress', () => { + it('should return false for testnet addr on mainnet', async () => { + const address = 'bchtest:qqqk4y6lsl5da64sg5qc3xezmplyu5kmpyz2ysaa5y' const result = await bchjs.Util.validateAddress(address) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.hasAllKeys(result, ["isvalid"]) + assert.hasAllKeys(result, ['isvalid']) assert.equal(result.isvalid, false) }) - it(`should return false for bad address`, async () => { - const address = `bitcoincash:qp4k8fjtgunhdr7yq30ha4peu` + it('should return false for bad address', async () => { + const address = 'bitcoincash:qp4k8fjtgunhdr7yq30ha4peu' const result = await bchjs.Util.validateAddress(address) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.hasAllKeys(result, ["isvalid"]) + assert.hasAllKeys(result, ['isvalid']) assert.equal(result.isvalid, false) }) - it(`should validate valid address`, async () => { - const address = `bitcoincash:qp4k8fjtgunhdr7yq30ha4peuwupzan2vcnwrmpy0z` + it('should validate valid address', async () => { + const address = 'bitcoincash:qp4k8fjtgunhdr7yq30ha4peuwupzan2vcnwrmpy0z' const result = await bchjs.Util.validateAddress(address) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.hasAnyKeys(result, [ - "isvalid", - "address", - "scriptPubKey", - //"ismine", - //"iswatchonly", - "isscript" + 'isvalid', + 'address', + 'scriptPubKey', + // "ismine", + // "iswatchonly", + 'isscript' ]) assert.equal(result.isvalid, true) }) - it(`should validate an array of addresses`, async () => { + it('should validate an array of addresses', async () => { const address = [ - `bitcoincash:qp4k8fjtgunhdr7yq30ha4peuwupzan2vcnwrmpy0z`, - `bitcoincash:qp4k8fjtgunhdr7yq30ha4peuwupzan2vcnwrmpy0z` + 'bitcoincash:qp4k8fjtgunhdr7yq30ha4peuwupzan2vcnwrmpy0z', + 'bitcoincash:qp4k8fjtgunhdr7yq30ha4peuwupzan2vcnwrmpy0z' ] const result = await bchjs.Util.validateAddress(address) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) assert.hasAnyKeys(result[0], [ - "isvalid", - "address", - "scriptPubKey", - //"ismine", - //"iswatchonly", - "isscript" + 'isvalid', + 'address', + 'scriptPubKey', + // "ismine", + // "iswatchonly", + 'isscript' ]) }) - it(`should throw error on array size rate limit`, async () => { + it('should throw error on array size rate limit', async () => { try { - const dataMock = `bitcoincash:qp4k8fjtgunhdr7yq30ha4peuwupzan2vcnwrmpy0z` + const dataMock = 'bitcoincash:qp4k8fjtgunhdr7yq30ha4peuwupzan2vcnwrmpy0z' const data = [] for (let i = 0; i < 25; i++) data.push(dataMock) const result = await bchjs.Util.validateAddress(data) console.log(`result: ${util.inspect(result)}`) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, "Array too large") + assert.hasAnyKeys(err, ['error']) + assert.include(err.error, 'Array too large') } }) }) }) -function sleep(ms) { +function sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/test/unit/address.js b/test/unit/address.js index 6a41766..85a8a6c 100644 --- a/test/unit/address.js +++ b/test/unit/address.js @@ -1,15 +1,15 @@ // Public npm libraries. -const assert = require("assert") -const Bitcoin = require("@psf/bitcoincashjs-lib") +const assert = require('assert') +const Bitcoin = require('@psf/bitcoincashjs-lib') // Mocks -const fixtures = require("./fixtures/address.json") +const fixtures = require('./fixtures/address.json') // Unit under test (uut) -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') let bchjs -function flatten(arrays) { +function flatten (arrays) { return [].concat.apply([], arrays) } @@ -49,14 +49,14 @@ const CASHADDR_ADDRESSES = flatten([ ]) const CASHADDR_ADDRESSES_NO_PREFIX = CASHADDR_ADDRESSES.map(address => { - const parts = address.split(":") + const parts = address.split(':') return parts[1] }) const REGTEST_ADDRESSES = fixtures.cashaddrRegTestP2PKH const REGTEST_ADDRESSES_NO_PREFIX = REGTEST_ADDRESSES.map(address => { - const parts = address.split(":") + const parts = address.split(':') return parts[1] }) @@ -79,14 +79,14 @@ const P2SH_ADDRESSES = flatten([ fixtures.cashaddrMainnetP2SH ]) -describe("#address.js", () => { +describe('#address.js', () => { beforeEach(() => { bchjs = new BCHJS() }) - describe("#addressConversion", () => { - describe("#toLegacyAddress", () => { - it("should translate legacy address format to itself correctly", () => { + describe('#addressConversion', () => { + describe('#toLegacyAddress', () => { + it('should translate legacy address format to itself correctly', () => { assert.deepEqual( LEGACY_ADDRESSES.map(address => bchjs.Address.toLegacyAddress(address) @@ -95,7 +95,7 @@ describe("#address.js", () => { ) }) - it("should convert cashaddr address to legacy base58Check", () => { + it('should convert cashaddr address to legacy base58Check', () => { assert.deepEqual( CASHADDR_ADDRESSES.map(address => bchjs.Address.toLegacyAddress(address) @@ -104,7 +104,7 @@ describe("#address.js", () => { ) }) - it("should convert cashaddr regtest address to legacy base58Check", () => { + it('should convert cashaddr regtest address to legacy base58Check', () => { assert.deepEqual( REGTEST_ADDRESSES.map(address => bchjs.Address.toLegacyAddress(address) @@ -113,20 +113,20 @@ describe("#address.js", () => { ) }) - describe("errors", () => { - it("should fail when called with an invalid address", () => { + describe('errors', () => { + it('should fail when called with an invalid address', () => { assert.throws(() => { bchjs.Address.toLegacyAddress() }, bchjs.BitcoinCash.InvalidAddressError) assert.throws(() => { - bchjs.Address.toLegacyAddress("some invalid address") + bchjs.Address.toLegacyAddress('some invalid address') }, bchjs.BitcoinCash.InvalidAddressError) }) }) }) - describe("#toCashAddress", () => { - it("should convert legacy base58Check address to cashaddr", () => { + describe('#toCashAddress', () => { + it('should convert legacy base58Check address to cashaddr', () => { assert.deepEqual( LEGACY_ADDRESSES.map(address => bchjs.Address.toCashAddress(address, true) @@ -135,7 +135,7 @@ describe("#address.js", () => { ) }) - it("should convert legacy base58Check address to regtest cashaddr", () => { + it('should convert legacy base58Check address to regtest cashaddr', () => { assert.deepEqual( fixtures.legacyTestnetP2PKH.map(address => bchjs.Address.toCashAddress(address, true, true) @@ -144,7 +144,7 @@ describe("#address.js", () => { ) }) - it("should translate cashaddr address format to itself correctly", () => { + it('should translate cashaddr address format to itself correctly', () => { assert.deepEqual( CASHADDR_ADDRESSES.map(address => bchjs.Address.toCashAddress(address, true) @@ -153,7 +153,7 @@ describe("#address.js", () => { ) }) - it("should translate regtest cashaddr address format to itself correctly", () => { + it('should translate regtest cashaddr address format to itself correctly', () => { assert.deepEqual( REGTEST_ADDRESSES.map(address => bchjs.Address.toCashAddress(address, true, true) @@ -162,7 +162,7 @@ describe("#address.js", () => { ) }) - it("should translate no-prefix cashaddr address format to itself correctly", () => { + it('should translate no-prefix cashaddr address format to itself correctly', () => { assert.deepEqual( CASHADDR_ADDRESSES_NO_PREFIX.map(address => bchjs.Address.toCashAddress(address, true) @@ -171,7 +171,7 @@ describe("#address.js", () => { ) }) - it("should translate no-prefix regtest cashaddr address format to itself correctly", () => { + it('should translate no-prefix regtest cashaddr address format to itself correctly', () => { assert.deepEqual( REGTEST_ADDRESSES_NO_PREFIX.map(address => bchjs.Address.toCashAddress(address, true, true) @@ -180,68 +180,68 @@ describe("#address.js", () => { ) }) - it("should translate cashaddr address format to itself of no-prefix correctly", () => { + it('should translate cashaddr address format to itself of no-prefix correctly', () => { CASHADDR_ADDRESSES.forEach(address => { const noPrefix = bchjs.Address.toCashAddress(address, false) - assert.equal(address.split(":")[1], noPrefix) + assert.equal(address.split(':')[1], noPrefix) }) }) - it("should translate regtest cashaddr address format to itself of no-prefix correctly", () => { + it('should translate regtest cashaddr address format to itself of no-prefix correctly', () => { REGTEST_ADDRESSES.forEach(address => { const noPrefix = bchjs.Address.toCashAddress(address, false, true) - assert.equal(address.split(":")[1], noPrefix) + assert.equal(address.split(':')[1], noPrefix) }) }) - describe("errors", () => { - it("should fail when called with an invalid address", () => { + describe('errors', () => { + it('should fail when called with an invalid address', () => { assert.throws(() => { bchjs.BitcoinCash.Address.toCashAddress() }, bchjs.BitcoinCash.InvalidAddressError) assert.throws(() => { - bchjs.BitcoinCash.Address.toCashAddress("some invalid address") + bchjs.BitcoinCash.Address.toCashAddress('some invalid address') }, bchjs.BitcoinCash.InvalidAddressError) }) }) }) - describe("#toHash160", () => { - it("should convert legacy base58check address to hash160", () => { + describe('#toHash160', () => { + it('should convert legacy base58check address to hash160', () => { assert.deepEqual( LEGACY_ADDRESSES.map(address => bchjs.Address.toHash160(address)), HASH160_HASHES ) }) - it("should convert cashaddr address to hash160", () => { + it('should convert cashaddr address to hash160', () => { assert.deepEqual( CASHADDR_ADDRESSES.map(address => bchjs.Address.toHash160(address)), HASH160_HASHES ) }) - it("should convert regtest cashaddr address to hash160", () => { + it('should convert regtest cashaddr address to hash160', () => { assert.deepEqual( REGTEST_ADDRESSES.map(address => bchjs.Address.toHash160(address)), fixtures.hash160TestnetP2PKH ) }) - describe("errors", () => { - it("should fail when called with an invalid address", () => { + describe('errors', () => { + it('should fail when called with an invalid address', () => { assert.throws(() => { bchjs.Address.toHash160() }, bchjs.BitcoinCash.InvalidAddressError) assert.throws(() => { - bchjs.Address.toHash160("some invalid address") + bchjs.Address.toHash160('some invalid address') }, bchjs.BitcoinCash.InvalidAddressError) }) }) }) - describe("#fromHash160", () => { - it("should convert hash160 to mainnet P2PKH legacy base58check address", () => { + describe('#fromHash160', () => { + it('should convert hash160 to mainnet P2PKH legacy base58check address', () => { assert.deepEqual( fixtures.hash160MainnetP2PKH.map(hash160 => bchjs.Address.hash160ToLegacy(hash160) @@ -250,7 +250,7 @@ describe("#address.js", () => { ) }) - it("should convert hash160 to mainnet P2SH legacy base58check address", () => { + it('should convert hash160 to mainnet P2SH legacy base58check address', () => { assert.deepEqual( fixtures.hash160MainnetP2SH.map(hash160 => bchjs.Address.hash160ToLegacy( @@ -262,7 +262,7 @@ describe("#address.js", () => { ) }) - it("should convert hash160 to testnet P2PKH legacy base58check address", () => { + it('should convert hash160 to testnet P2PKH legacy base58check address', () => { assert.deepEqual( fixtures.hash160TestnetP2PKH.map(hash160 => bchjs.Address.hash160ToLegacy( @@ -274,7 +274,7 @@ describe("#address.js", () => { ) }) - it("should convert hash160 to mainnet P2PKH cash address", () => { + it('should convert hash160 to mainnet P2PKH cash address', () => { assert.deepEqual( fixtures.hash160MainnetP2PKH.map(hash160 => bchjs.Address.hash160ToCash(hash160) @@ -283,7 +283,7 @@ describe("#address.js", () => { ) }) - it("should convert hash160 to mainnet P2SH cash address", () => { + it('should convert hash160 to mainnet P2SH cash address', () => { assert.deepEqual( fixtures.hash160MainnetP2SH.map(hash160 => bchjs.Address.hash160ToCash( @@ -295,7 +295,7 @@ describe("#address.js", () => { ) }) - it("should convert hash160 to testnet P2PKH cash address", () => { + it('should convert hash160 to testnet P2PKH cash address', () => { assert.deepEqual( fixtures.hash160TestnetP2PKH.map(hash160 => bchjs.Address.hash160ToCash( @@ -307,7 +307,7 @@ describe("#address.js", () => { ) }) - it("should convert hash160 to regtest P2PKH cash address", () => { + it('should convert hash160 to regtest P2PKH cash address', () => { assert.deepEqual( fixtures.hash160TestnetP2PKH.map(hash160 => bchjs.Address.hash160ToCash( @@ -320,28 +320,28 @@ describe("#address.js", () => { ) }) - describe("errors", () => { - it("should fail when called with an invalid address", () => { + describe('errors', () => { + it('should fail when called with an invalid address', () => { assert.throws(() => { bchjs.Address.hash160ToLegacy() }, bchjs.BitcoinCash.InvalidAddressError) assert.throws(() => { - bchjs.Address.hash160ToLegacy("some invalid address") + bchjs.Address.hash160ToLegacy('some invalid address') }, bchjs.BitcoinCash.InvalidAddressError) assert.throws(() => { bchjs.Address.hash160ToCash() }, bchjs.BitcoinCash.InvalidAddressError) assert.throws(() => { - bchjs.Address.hash160ToCash("some invalid address") + bchjs.Address.hash160ToCash('some invalid address') }, bchjs.BitcoinCash.InvalidAddressError) }) }) }) }) - describe("address format detection", () => { - describe("#isLegacyAddress", () => { - describe("is legacy", () => { + describe('address format detection', () => { + describe('#isLegacyAddress', () => { + describe('is legacy', () => { LEGACY_ADDRESSES.forEach(address => { it(`should detect ${address} is a legacy base58Check address`, () => { const isBase58Check = bchjs.Address.isLegacyAddress(address) @@ -349,7 +349,7 @@ describe("#address.js", () => { }) }) }) - describe("is not legacy", () => { + describe('is not legacy', () => { CASHADDR_ADDRESSES.forEach(address => { it(`should detect ${address} is not a legacy address`, () => { const isBase58Check = bchjs.Address.isLegacyAddress(address) @@ -365,20 +365,20 @@ describe("#address.js", () => { }) }) - describe("errors", () => { - it("should fail when called with an invalid address", () => { + describe('errors', () => { + it('should fail when called with an invalid address', () => { assert.throws(() => { bchjs.Address.isLegacyAddress() }, bchjs.BitcoinCash.InvalidAddressError) assert.throws(() => { - bchjs.Address.isLegacyAddress("some invalid address") + bchjs.Address.isLegacyAddress('some invalid address') }, bchjs.BitcoinCash.InvalidAddressError) }) }) }) - describe("#isCashAddress", () => { - describe("is cashaddr", () => { + describe('#isCashAddress', () => { + describe('is cashaddr', () => { CASHADDR_ADDRESSES.forEach(address => { it(`should detect ${address} is a cashaddr address`, () => { const isCashaddr = bchjs.Address.isCashAddress(address) @@ -394,7 +394,7 @@ describe("#address.js", () => { }) }) - describe("is not cashaddr", () => { + describe('is not cashaddr', () => { LEGACY_ADDRESSES.forEach(address => { it(`should detect ${address} is not a cashaddr address`, () => { const isCashaddr = bchjs.Address.isCashAddress(address) @@ -403,19 +403,19 @@ describe("#address.js", () => { }) }) - describe("errors", () => { - it("should fail when called with an invalid address", () => { + describe('errors', () => { + it('should fail when called with an invalid address', () => { assert.throws(() => { bchjs.Address.isCashAddress() }, bchjs.BitcoinCash.InvalidAddressError) assert.throws(() => { - bchjs.Address.isCashAddress("some invalid address") + bchjs.Address.isCashAddress('some invalid address') }, bchjs.BitcoinCash.InvalidAddressError) }) }) }) - describe("#isHash160", () => { - describe("is hash160", () => { + describe('#isHash160', () => { + describe('is hash160', () => { HASH160_HASHES.forEach(address => { it(`should detect ${address} is a hash160 hash`, () => { const isHash160 = bchjs.Address.isHash160(address) @@ -423,7 +423,7 @@ describe("#address.js", () => { }) }) }) - describe("is not hash160", () => { + describe('is not hash160', () => { LEGACY_ADDRESSES.forEach(address => { it(`should detect ${address} is not a hash160 hash`, () => { const isHash160 = bchjs.Address.isHash160(address) @@ -446,22 +446,22 @@ describe("#address.js", () => { }) }) - describe("errors", () => { - it("should fail when called with an invalid address", () => { + describe('errors', () => { + it('should fail when called with an invalid address', () => { assert.throws(() => { bchjs.Address.isHash160() }, bchjs.BitcoinCash.InvalidAddressError) assert.throws(() => { - bchjs.Address.isHash160("some invalid address") + bchjs.Address.isHash160('some invalid address') }, bchjs.BitcoinCash.InvalidAddressError) }) }) }) }) - describe("network detection", () => { - describe("#isMainnetAddress", () => { - describe("is mainnet", () => { + describe('network detection', () => { + describe('#isMainnetAddress', () => { + describe('is mainnet', () => { MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a mainnet address`, () => { const isMainnet = bchjs.Address.isMainnetAddress(address) @@ -470,7 +470,7 @@ describe("#address.js", () => { }) }) - describe("is not mainnet", () => { + describe('is not mainnet', () => { TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not a mainnet address`, () => { const isMainnet = bchjs.Address.isMainnetAddress(address) @@ -486,20 +486,20 @@ describe("#address.js", () => { }) }) - describe("errors", () => { - it("should fail when called with an invalid address", () => { + describe('errors', () => { + it('should fail when called with an invalid address', () => { assert.throws(() => { bchjs.Address.isMainnetAddress() }, bchjs.BitcoinCash.InvalidAddressError) assert.throws(() => { - bchjs.Address.isMainnetAddress("some invalid address") + bchjs.Address.isMainnetAddress('some invalid address') }, bchjs.BitcoinCash.InvalidAddressError) }) }) }) - describe("#isTestnetAddress", () => { - describe("is testnet", () => { + describe('#isTestnetAddress', () => { + describe('is testnet', () => { TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a testnet address`, () => { const isTestnet = bchjs.Address.isTestnetAddress(address) @@ -508,7 +508,7 @@ describe("#address.js", () => { }) }) - describe("is not testnet", () => { + describe('is not testnet', () => { MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not a testnet address`, () => { const isTestnet = bchjs.Address.isTestnetAddress(address) @@ -524,20 +524,20 @@ describe("#address.js", () => { }) }) - describe("errors", () => { - it("should fail when called with an invalid address", () => { + describe('errors', () => { + it('should fail when called with an invalid address', () => { assert.throws(() => { bchjs.Address.isTestnetAddress() }, bchjs.BitcoinCash.InvalidAddressError) assert.throws(() => { - bchjs.Address.isTestnetAddress("some invalid address") + bchjs.Address.isTestnetAddress('some invalid address') }, bchjs.BitcoinCash.InvalidAddressError) }) }) }) - describe("#isRegTestAddress", () => { - describe("is testnet", () => { + describe('#isRegTestAddress', () => { + describe('is testnet', () => { REGTEST_ADDRESSES.forEach(address => { it(`should detect ${address} is a regtest address`, () => { const isRegTest = bchjs.Address.isRegTestAddress(address) @@ -546,7 +546,7 @@ describe("#address.js", () => { }) }) - describe("is not testnet", () => { + describe('is not testnet', () => { MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not a regtest address`, () => { const isRegTest = bchjs.Address.isRegTestAddress(address) @@ -562,22 +562,22 @@ describe("#address.js", () => { }) }) - describe("errors", () => { - it("should fail when called with an invalid address", () => { + describe('errors', () => { + it('should fail when called with an invalid address', () => { assert.throws(() => { bchjs.Address.isRegTestAddress() }, bchjs.BitcoinCash.InvalidAddressError) assert.throws(() => { - bchjs.Address.isRegTestAddress("some invalid address") + bchjs.Address.isRegTestAddress('some invalid address') }, bchjs.BitcoinCash.InvalidAddressError) }) }) }) }) - describe("address type detection", () => { - describe("#isP2PKHAddress", () => { - describe("is P2PKH", () => { + describe('address type detection', () => { + describe('#isP2PKHAddress', () => { + describe('is P2PKH', () => { P2PKH_ADDRESSES.forEach(address => { it(`should detect ${address} is a P2PKH address`, () => { const isP2PKH = bchjs.Address.isP2PKHAddress(address) @@ -586,7 +586,7 @@ describe("#address.js", () => { }) }) - describe("is not P2PKH", () => { + describe('is not P2PKH', () => { P2SH_ADDRESSES.forEach(address => { it(`should detect ${address} is not a P2PKH address`, () => { const isP2PKH = bchjs.Address.isP2PKHAddress(address) @@ -595,20 +595,20 @@ describe("#address.js", () => { }) }) - describe("errors", () => { - it("should fail when called with an invalid address", () => { + describe('errors', () => { + it('should fail when called with an invalid address', () => { assert.throws(() => { bchjs.Address.isP2PKHAddress() }, bchjs.BitcoinCash.InvalidAddressError) assert.throws(() => { - bchjs.Address.isP2PKHAddress("some invalid address") + bchjs.Address.isP2PKHAddress('some invalid address') }, bchjs.BitcoinCash.InvalidAddressError) }) }) }) - describe("#isP2SHAddress", () => { - describe("is P2SH", () => { + describe('#isP2SHAddress', () => { + describe('is P2SH', () => { P2SH_ADDRESSES.forEach(address => { it(`should detect ${address} is a P2SH address`, () => { const isP2SH = bchjs.Address.isP2SHAddress(address) @@ -617,7 +617,7 @@ describe("#address.js", () => { }) }) - describe("is not P2SH", () => { + describe('is not P2SH', () => { P2PKH_ADDRESSES.forEach(address => { it(`should detect ${address} is not a P2SH address`, () => { const isP2SH = bchjs.Address.isP2SHAddress(address) @@ -626,21 +626,21 @@ describe("#address.js", () => { }) }) - describe("errors", () => { - it("should fail when called with an invalid address", () => { + describe('errors', () => { + it('should fail when called with an invalid address', () => { assert.throws(() => { bchjs.Address.isP2SHAddress() }, bchjs.BitcoinCash.InvalidAddressError) assert.throws(() => { - bchjs.Address.isP2SHAddress("some invalid address") + bchjs.Address.isP2SHAddress('some invalid address') }, bchjs.BitcoinCash.InvalidAddressError) }) }) }) }) - describe("cashaddr prefix detection", () => { - it("should return the same result for detectAddressFormat", () => { + describe('cashaddr prefix detection', () => { + it('should return the same result for detectAddressFormat', () => { assert.deepEqual( CASHADDR_ADDRESSES_NO_PREFIX.map(address => bchjs.Address.detectAddressFormat(address) @@ -658,7 +658,7 @@ describe("#address.js", () => { ) ) }) - it("should return the same result for detectAddressNetwork", () => { + it('should return the same result for detectAddressNetwork', () => { assert.deepEqual( CASHADDR_ADDRESSES_NO_PREFIX.map(address => bchjs.Address.detectAddressNetwork(address) @@ -676,7 +676,7 @@ describe("#address.js", () => { ) ) }) - it("should return the same result for detectAddressType", () => { + it('should return the same result for detectAddressType', () => { assert.deepEqual( CASHADDR_ADDRESSES_NO_PREFIX.map(address => bchjs.Address.detectAddressType(address) @@ -694,7 +694,7 @@ describe("#address.js", () => { ) ) }) - it("should return the same result for toLegacyAddress", () => { + it('should return the same result for toLegacyAddress', () => { assert.deepEqual( CASHADDR_ADDRESSES_NO_PREFIX.map(address => bchjs.Address.toLegacyAddress(address) @@ -710,7 +710,7 @@ describe("#address.js", () => { REGTEST_ADDRESSES.map(address => bchjs.Address.toLegacyAddress(address)) ) }) - it("should return the same result for isLegacyAddress", () => { + it('should return the same result for isLegacyAddress', () => { assert.deepEqual( CASHADDR_ADDRESSES_NO_PREFIX.map(address => bchjs.Address.isLegacyAddress(address) @@ -726,7 +726,7 @@ describe("#address.js", () => { REGTEST_ADDRESSES.map(address => bchjs.Address.isLegacyAddress(address)) ) }) - it("should return the same result for isCashAddress", () => { + it('should return the same result for isCashAddress', () => { assert.deepEqual( CASHADDR_ADDRESSES_NO_PREFIX.map(address => bchjs.Address.isCashAddress(address) @@ -740,7 +740,7 @@ describe("#address.js", () => { REGTEST_ADDRESSES.map(address => bchjs.Address.isCashAddress(address)) ) }) - it("should return the same result for isMainnetAddress", () => { + it('should return the same result for isMainnetAddress', () => { assert.deepEqual( CASHADDR_ADDRESSES_NO_PREFIX.map(address => bchjs.Address.isMainnetAddress(address) @@ -758,7 +758,7 @@ describe("#address.js", () => { ) ) }) - it("should return the same result for isTestnetAddress", () => { + it('should return the same result for isTestnetAddress', () => { assert.deepEqual( CASHADDR_ADDRESSES_NO_PREFIX.map(address => bchjs.Address.isTestnetAddress(address) @@ -776,7 +776,7 @@ describe("#address.js", () => { ) ) }) - it("should return the same result for isP2PKHAddress", () => { + it('should return the same result for isP2PKHAddress', () => { assert.deepEqual( CASHADDR_ADDRESSES_NO_PREFIX.map(address => bchjs.Address.isP2PKHAddress(address) @@ -790,7 +790,7 @@ describe("#address.js", () => { REGTEST_ADDRESSES.map(address => bchjs.Address.isP2PKHAddress(address)) ) }) - it("should return the same result for isP2SHAddress", () => { + it('should return the same result for isP2SHAddress', () => { assert.deepEqual( CASHADDR_ADDRESSES_NO_PREFIX.map(address => bchjs.Address.isP2SHAddress(address) @@ -806,102 +806,102 @@ describe("#address.js", () => { }) }) - describe("#detectAddressFormat", () => { + describe('#detectAddressFormat', () => { LEGACY_ADDRESSES.forEach(address => { it(`should detect ${address} is a legacy base58Check address`, () => { const isBase58Check = bchjs.Address.detectAddressFormat(address) - assert.equal(isBase58Check, "legacy") + assert.equal(isBase58Check, 'legacy') }) }) CASHADDR_ADDRESSES.forEach(address => { it(`should detect ${address} is a legacy cashaddr address`, () => { const isCashaddr = bchjs.Address.detectAddressFormat(address) - assert.equal(isCashaddr, "cashaddr") + assert.equal(isCashaddr, 'cashaddr') }) }) REGTEST_ADDRESSES.forEach(address => { it(`should detect ${address} is a legacy cashaddr address`, () => { const isCashaddr = bchjs.Address.detectAddressFormat(address) - assert.equal(isCashaddr, "cashaddr") + assert.equal(isCashaddr, 'cashaddr') }) }) - describe("errors", () => { - it("should fail when called with an invalid address", () => { + describe('errors', () => { + it('should fail when called with an invalid address', () => { assert.throws(() => { bchjs.Address.detectAddressFormat() }, bchjs.BitcoinCash.InvalidAddressError) assert.throws(() => { - bchjs.Address.detectAddressFormat("some invalid address") + bchjs.Address.detectAddressFormat('some invalid address') }, bchjs.BitcoinCash.InvalidAddressError) }) }) }) - describe("#detectAddressNetwork", () => { + describe('#detectAddressNetwork', () => { MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a mainnet address`, () => { const isMainnet = bchjs.Address.detectAddressNetwork(address) - assert.equal(isMainnet, "mainnet") + assert.equal(isMainnet, 'mainnet') }) }) TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a testnet address`, () => { const isTestnet = bchjs.Address.detectAddressNetwork(address) - assert.equal(isTestnet, "testnet") + assert.equal(isTestnet, 'testnet') }) }) REGTEST_ADDRESSES.forEach(address => { it(`should detect ${address} is a testnet address`, () => { const isTestnet = bchjs.Address.detectAddressNetwork(address) - assert.equal(isTestnet, "regtest") + assert.equal(isTestnet, 'regtest') }) }) - describe("errors", () => { - it("should fail when called with an invalid address", () => { + describe('errors', () => { + it('should fail when called with an invalid address', () => { assert.throws(() => { bchjs.Address.detectAddressNetwork() }, bchjs.BitcoinCash.InvalidAddressError) assert.throws(() => { - bchjs.Address.detectAddressNetwork("some invalid address") + bchjs.Address.detectAddressNetwork('some invalid address') }, bchjs.BitcoinCash.InvalidAddressError) }) }) }) - describe("#detectAddressType", () => { + describe('#detectAddressType', () => { P2PKH_ADDRESSES.forEach(address => { it(`should detect ${address} is a P2PKH address`, () => { const isP2PKH = bchjs.Address.detectAddressType(address) - assert.equal(isP2PKH, "p2pkh") + assert.equal(isP2PKH, 'p2pkh') }) }) P2SH_ADDRESSES.forEach(address => { it(`should detect ${address} is a P2SH address`, () => { const isP2SH = bchjs.Address.detectAddressType(address) - assert.equal(isP2SH, "p2sh") + assert.equal(isP2SH, 'p2sh') }) }) - describe("errors", () => { - it("should fail when called with an invalid address", () => { + describe('errors', () => { + it('should fail when called with an invalid address', () => { assert.throws(() => { bchjs.Address.detectAddressType() }, bchjs.BitcoinCash.InvalidAddressError) assert.throws(() => { - bchjs.Address.detectAddressType("some invalid address") + bchjs.Address.detectAddressType('some invalid address') }, bchjs.BitcoinCash.InvalidAddressError) }) }) }) - describe("#fromXPub", () => { + describe('#fromXPub', () => { XPUBS.forEach((xpub, i) => { xpub.addresses.forEach((address, j) => { it(`generate public external change address ${j} for ${xpub.xpub}`, () => { @@ -911,12 +911,12 @@ describe("#address.js", () => { }) }) - describe("#fromOutputScript", () => { - it("generate address from output script", () => { + describe('#fromOutputScript', () => { + it('generate address from output script', () => { const script = bchjs.Script.encode([ - Buffer.from("BOX", "ascii"), + Buffer.from('BOX', 'ascii'), bchjs.Script.opcodes.OP_CAT, - Buffer.from("BITBOX", "ascii"), + Buffer.from('BITBOX', 'ascii'), bchjs.Script.opcodes.OP_EQUAL ]) diff --git a/test/unit/bitcoin-cash.js b/test/unit/bitcoin-cash.js index f8ae038..47c68d9 100644 --- a/test/unit/bitcoin-cash.js +++ b/test/unit/bitcoin-cash.js @@ -1,11 +1,11 @@ // Public npm libraries -const assert = require("assert") +const assert = require('assert') // Mocks -const fixtures = require("./fixtures/bitcoincash.json") +const fixtures = require('./fixtures/bitcoincash.json') // Unit under test (uut) -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') // const bchjs = new BCHJS() let bchjs @@ -25,13 +25,13 @@ let bchjs // * confirm xpriv generates WIF // 6. More error test cases. -describe("#BitcoinCash", () => { +describe('#BitcoinCash', () => { beforeEach(() => { bchjs = new BCHJS() }) - describe("price conversion", () => { - it("should exercise toBitcoinCash", () => { + describe('price conversion', () => { + it('should exercise toBitcoinCash', () => { fixtures.conversion.toBCH.satoshis.forEach(satoshi => { it(`should convert ${satoshi[0]} Satoshis to ${satoshi[1]} $BCH`, () => { assert.equal(bchjs.BitcoinCash.toBitcoinCash(satoshi[0]), satoshi[1]) @@ -57,7 +57,7 @@ describe("#BitcoinCash", () => { }) }) - it("should exercise toSatoshi", () => { + it('should exercise toSatoshi', () => { fixtures.conversion.toSatoshi.bch.forEach(bch => { it(`should convert ${bch[0]} $BCH to ${bch[1]} Satoshis`, () => { assert.equal(bchjs.BitcoinCash.toSatoshi(bch[0]), bch[1]) @@ -83,7 +83,7 @@ describe("#BitcoinCash", () => { }) }) - it("should exercise satsToBits", () => { + it('should exercise satsToBits', () => { fixtures.conversion.satsToBits.bch.forEach(bch => { it(`should convert ${bch[0]} BCH to ${bch[1]} bits`, () => { assert.equal( @@ -118,8 +118,8 @@ describe("#BitcoinCash", () => { // }); }) - describe("sign and verify messages", () => { - it("should exercise signMessageWithPrivKey", () => { + describe('sign and verify messages', () => { + it('should exercise signMessageWithPrivKey', () => { fixtures.signatures.sign.forEach(sign => { it(`should sign a message w/ ${sign.network} ${sign.privateKeyWIF}`, () => { const privateKeyWIF = sign.privateKeyWIF @@ -133,7 +133,7 @@ describe("#BitcoinCash", () => { }) }) - it("shoudl exercise verifyMessage", () => { + it('shoudl exercise verifyMessage', () => { fixtures.signatures.verify.forEach(sign => { it(`should verify a valid signed message from ${sign.network} cashaddr address ${sign.address}`, () => { assert.equal( @@ -147,7 +147,7 @@ describe("#BitcoinCash", () => { }) }) - it("should verify legacy addresses", () => { + it('should verify legacy addresses', () => { fixtures.signatures.verify.forEach(sign => { const legacyAddress = bchjs.Address.toLegacyAddress(sign.address) it(`should verify a valid signed message from ${sign.network} legacy address ${legacyAddress}`, () => { @@ -170,7 +170,7 @@ describe("#BitcoinCash", () => { bchjs.BitcoinCash.verifyMessage( sign.address, sign.signature, - "nope" + 'nope' ), false ) @@ -179,8 +179,8 @@ describe("#BitcoinCash", () => { }) }) - describe("encode and decode to base58Check", () => { - describe("#encodeBase58Check", () => { + describe('encode and decode to base58Check', () => { + describe('#encodeBase58Check', () => { fixtures.encodeBase58Check.forEach((base58Check, i) => { it(`encode ${base58Check.hex} as base58Check ${base58Check.base58Check}`, () => { assert.equal( @@ -191,7 +191,7 @@ describe("#BitcoinCash", () => { }) }) - describe("#decodeBase58Check", () => { + describe('#decodeBase58Check', () => { fixtures.encodeBase58Check.forEach((base58Check, i) => { it(`decode ${base58Check.base58Check} as ${base58Check.hex}`, () => { assert.equal( @@ -203,8 +203,8 @@ describe("#BitcoinCash", () => { }) }) - describe("encode and decode BIP21 urls", () => { - describe("#encodeBIP21", () => { + describe('encode and decode BIP21 urls', () => { + describe('#encodeBIP21', () => { fixtures.bip21.valid.forEach((bip21, i) => { it(`encode ${bip21.address} as url`, () => { const url = bchjs.BitcoinCash.encodeBIP21( @@ -226,7 +226,7 @@ describe("#BitcoinCash", () => { }) }) - describe("#decodeBIP21", () => { + describe('#decodeBIP21', () => { fixtures.bip21.valid.forEach((bip21, i) => { it(`decodes ${bip21.url}`, () => { const decoded = bchjs.BitcoinCash.decodeBIP21(bip21.url) @@ -252,9 +252,9 @@ describe("#BitcoinCash", () => { }) }) - describe("#getByteCount", () => { + describe('#getByteCount', () => { fixtures.getByteCount.forEach(fixture => { - it(`get byte count`, () => { + it('get byte count', () => { const byteCount = bchjs.BitcoinCash.getByteCount( fixture.inputs, fixture.outputs @@ -264,8 +264,8 @@ describe("#BitcoinCash", () => { }) }) - describe("#bip38", () => { - describe("#encryptBIP38", () => { + describe('#bip38', () => { + describe('#encryptBIP38', () => { fixtures.bip38.encrypt.mainnet.forEach(fixture => { it(`BIP 38 encrypt wif ${fixture.wif} with password ${fixture.password} on mainnet`, () => { const encryptedKey = bchjs.BitcoinCash.encryptBIP38( @@ -287,13 +287,13 @@ describe("#BitcoinCash", () => { }) }) - describe("#decryptBIP38", () => { + describe('#decryptBIP38', () => { fixtures.bip38.decrypt.mainnet.forEach(fixture => { it(`BIP 38 decrypt encrypted key ${fixture.encryptedKey} on mainnet`, () => { const wif = bchjs.BitcoinCash.decryptBIP38( fixture.encryptedKey, fixture.password, - "mainnet" + 'mainnet' ) assert.equal(wif, fixture.wif) }) @@ -304,7 +304,7 @@ describe("#BitcoinCash", () => { const wif = bchjs.BitcoinCash.decryptBIP38( fixture.encryptedKey, fixture.password, - "testnet" + 'testnet' ) assert.equal(wif, fixture.wif) }) diff --git a/test/unit/blockchain.js b/test/unit/blockchain.js index e088ffe..de3dd73 100644 --- a/test/unit/blockchain.js +++ b/test/unit/blockchain.js @@ -1,70 +1,70 @@ -const assert = require("assert") -const assert2 = require("chai").assert -const axios = require("axios") -const BCHJS = require("../../src/bch-js") +const assert = require('assert') +const assert2 = require('chai').assert +const axios = require('axios') +const BCHJS = require('../../src/bch-js') const bchjs = new BCHJS() -const sinon = require("sinon") +const sinon = require('sinon') -const mockData = require("./fixtures/blockchain-mock") +const mockData = require('./fixtures/blockchain-mock') -describe("#Blockchain", () => { - describe("#getBestBlockHash", () => { +describe('#Blockchain', () => { + describe('#getBestBlockHash', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) - it("should get best block hash", done => { - const resolved = new Promise(r => - r({ + it('should get best block hash', done => { + const resolved = new Promise(resolve => + resolve({ data: - "0000000000000000005f1f550d3d8b142b684277016ebd00fa29c668606ae52d" + '0000000000000000005f1f550d3d8b142b684277016ebd00fa29c668606ae52d' }) ) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) bchjs.Blockchain.getBestBlockHash() .then(result => { const hash = - "0000000000000000005f1f550d3d8b142b684277016ebd00fa29c668606ae52d" - assert.equal(hash, result) + '0000000000000000005f1f550d3d8b142b684277016ebd00fa29c668606ae52d' + assert.strictEqual(hash, result) }) .then(done, done) }) }) - describe("#getBlock", () => { + describe('#getBlock', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) const data = { - hash: "00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09", + hash: '00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09', confirmations: 526807, size: 216, height: 1000, version: 1, - versionHex: "00000001", + versionHex: '00000001', merkleroot: - "fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33", - tx: ["fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33"], + 'fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33', + tx: ['fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33'], time: 1232346882, mediantime: 1232344831, nonce: 2595206198, - bits: "1d00ffff", + bits: '1d00ffff', difficulty: 1, chainwork: - "000000000000000000000000000000000000000000000000000003e903e903e9", + '000000000000000000000000000000000000000000000000000003e903e903e9', previousblockhash: - "0000000008e647742775a230787d66fdf92c46a48c896bfbc85cdc8acc67e87d", + '0000000008e647742775a230787d66fdf92c46a48c896bfbc85cdc8acc67e87d', nextblockhash: - "00000000a2887344f8db859e372e7e4bc26b23b9de340f725afbf2edb265b4c6" + '00000000a2887344f8db859e372e7e4bc26b23b9de340f725afbf2edb265b4c6' } - it("should get block by hash", done => { + it('should get block by hash', done => { const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) bchjs.Blockchain.getBlock( - "00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09" + '00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09' ) .then(result => { assert.deepEqual(data, result) @@ -73,30 +73,30 @@ describe("#Blockchain", () => { }) }) - describe("#getBlockchainInfo", () => { + describe('#getBlockchainInfo', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) const data = { - chain: "main", + chain: 'main', blocks: 527810, headers: 527810, bestblockhash: - "000000000000000001d127592d091d4c45062504663c9acab27a1b16c028e3c0", + '000000000000000001d127592d091d4c45062504663c9acab27a1b16c028e3c0', difficulty: 576023394804.6666, mediantime: 1524878499, verificationprogress: 0.9999990106793685, chainwork: - "00000000000000000000000000000000000000000096da5b040913fa09249b4e", + '00000000000000000000000000000000000000000096da5b040913fa09249b4e', pruned: false, softforks: [ - { id: "bip34", version: 2, reject: [Object] }, - { id: "bip66", version: 3, reject: [Object] }, - { id: "bip65", version: 4, reject: [Object] } + { id: 'bip34', version: 2, reject: [Object] }, + { id: 'bip66', version: 3, reject: [Object] }, + { id: 'bip65', version: 4, reject: [Object] } ], bip9_softforks: { csv: { - status: "active", + status: 'active', startTime: 1462060800, timeout: 1493596800, since: 419328 @@ -104,9 +104,9 @@ describe("#Blockchain", () => { } } - it("should get blockchain info", done => { + it('should get blockchain info', done => { const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) bchjs.Blockchain.getBlockchainInfo() .then(result => { @@ -116,15 +116,15 @@ describe("#Blockchain", () => { }) }) - describe("#getBlockCount", () => { + describe('#getBlockCount', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) const data = 527810 - it("should get block count", done => { + it('should get block count', done => { const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) bchjs.Blockchain.getBlockCount() .then(result => { @@ -134,16 +134,16 @@ describe("#Blockchain", () => { }) }) - describe("#getBlockHash", () => { + describe('#getBlockHash', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) const data = - "000000000000000001d127592d091d4c45062504663c9acab27a1b16c028e3c0" + '000000000000000001d127592d091d4c45062504663c9acab27a1b16c028e3c0' - it("should get block hash by height", done => { + it('should get block hash by height', done => { const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) bchjs.Blockchain.getBlockHash(527810) .then(result => { @@ -153,35 +153,35 @@ describe("#Blockchain", () => { }) }) - describe("#getBlockHeader", () => { + describe('#getBlockHeader', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) const data = { - hash: "000000000000000001d127592d091d4c45062504663c9acab27a1b16c028e3c0", + hash: '000000000000000001d127592d091d4c45062504663c9acab27a1b16c028e3c0', confirmations: 1, height: 527810, version: 536870912, - versionHex: "20000000", + versionHex: '20000000', merkleroot: - "9298432bbebe4638456aa19cb7ef91639da87668a285d88d0ecd6080424d223b", + '9298432bbebe4638456aa19cb7ef91639da87668a285d88d0ecd6080424d223b', time: 1524881438, mediantime: 1524878499, nonce: 3326843941, - bits: "1801e8a5", + bits: '1801e8a5', difficulty: 576023394804.6666, chainwork: - "00000000000000000000000000000000000000000096da5b040913fa09249b4e", + '00000000000000000000000000000000000000000096da5b040913fa09249b4e', previousblockhash: - "000000000000000000b33251708bc7a7b4540e61880d8c376e8e2db6a19a4789" + '000000000000000000b33251708bc7a7b4540e61880d8c376e8e2db6a19a4789' } - it("should get block header by hash", done => { + it('should get block header by hash', done => { const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) bchjs.Blockchain.getBlockHeader( - "000000000000000001d127592d091d4c45062504663c9acab27a1b16c028e3c0", + '000000000000000001d127592d091d4c45062504663c9acab27a1b16c028e3c0', true ) .then(result => { @@ -191,15 +191,15 @@ describe("#Blockchain", () => { }) }) - describe("#getDifficulty", () => { + describe('#getDifficulty', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) - const data = "577528469277.1339" + const data = '577528469277.1339' - it("should get difficulty", done => { + it('should get difficulty', done => { const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) bchjs.Blockchain.getDifficulty() .then(result => { @@ -209,18 +209,18 @@ describe("#Blockchain", () => { }) }) - describe("#getMempoolAncestors", () => { + describe('#getMempoolAncestors', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) - const data = "Transaction not in mempool" + const data = 'Transaction not in mempool' - it("should get mempool ancestors", done => { + it('should get mempool ancestors', done => { const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) bchjs.Blockchain.getMempoolAncestors( - "daf58932cb91619304dd4cbd03c7202e89ad7d6cbd6e2209e5f64ce3b6ed7c88", + 'daf58932cb91619304dd4cbd03c7202e89ad7d6cbd6e2209e5f64ce3b6ed7c88', true ) .then(result => { @@ -230,20 +230,20 @@ describe("#Blockchain", () => { }) }) - describe("#getMempoolDescendants", () => { + describe('#getMempoolDescendants', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) const data = { - result: "Transaction not in mempool" + result: 'Transaction not in mempool' } - it("should get mempool descendants", done => { + it('should get mempool descendants', done => { const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) bchjs.Blockchain.getMempoolDescendants( - "daf58932cb91619304dd4cbd03c7202e89ad7d6cbd6e2209e5f64ce3b6ed7c88", + 'daf58932cb91619304dd4cbd03c7202e89ad7d6cbd6e2209e5f64ce3b6ed7c88', true ) .then(result => { @@ -253,20 +253,20 @@ describe("#Blockchain", () => { }) }) - describe("#getMempoolEntry", () => { + describe('#getMempoolEntry', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) const data = { - result: "Transaction not in mempool" + result: 'Transaction not in mempool' } - it("should get mempool entry", done => { + it('should get mempool entry', done => { const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) bchjs.Blockchain.getMempoolEntry( - "daf58932cb91619304dd4cbd03c7202e89ad7d6cbd6e2209e5f64ce3b6ed7c88" + 'daf58932cb91619304dd4cbd03c7202e89ad7d6cbd6e2209e5f64ce3b6ed7c88' ) .then(result => { assert.deepEqual(data, result) @@ -275,7 +275,7 @@ describe("#Blockchain", () => { }) }) - describe("#getMempoolInfo", () => { + describe('#getMempoolInfo', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) @@ -289,9 +289,9 @@ describe("#Blockchain", () => { } } - it("should get mempool info", done => { + it('should get mempool info', done => { const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) bchjs.Blockchain.getMempoolInfo() .then(result => { @@ -301,7 +301,7 @@ describe("#Blockchain", () => { }) }) - describe("#getRawMempool", () => { + describe('#getRawMempool', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) @@ -310,7 +310,7 @@ describe("#Blockchain", () => { transactions: [ { txid: - "ab36d68dd0a618592fe34e4a898e8beeeb4049133547dbb16f9338384084af96", + 'ab36d68dd0a618592fe34e4a898e8beeeb4049133547dbb16f9338384084af96', size: 191, fee: 0.00047703, modifiedfee: 0.00047703, @@ -330,9 +330,9 @@ describe("#Blockchain", () => { } } - it("should get mempool info", done => { + it('should get mempool info', done => { const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) bchjs.Blockchain.getRawMempool() .then(result => { @@ -342,7 +342,7 @@ describe("#Blockchain", () => { }) }) - describe("#getTxOut", () => { + describe('#getTxOut', () => { // TODO finish this test let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) @@ -351,63 +351,66 @@ describe("#Blockchain", () => { // result: {} // } - it("should throw an error for improper txid.", async () => { + it('should throw an error for improper txid.', async () => { try { - await bchjs.Blockchain.getTxOut("badtxid") + await bchjs.Blockchain.getTxOut('badtxid') } catch (err) { - assert2.include(err.message, "txid needs to be a proper transaction ID") + assert2.include( + err.message, + 'txid needs to be a proper transaction ID' + ) } }) - it("should throw an error if no vout value is provided.", async () => { + it('should throw an error if no vout value is provided.', async () => { try { await bchjs.Blockchain.getTxOut( - "daf58932cb91619304dd4cbd03c7202e89ad7d6cbd6e2209e5f64ce3b6ed7c88" + 'daf58932cb91619304dd4cbd03c7202e89ad7d6cbd6e2209e5f64ce3b6ed7c88' ) } catch (err) { - assert2.include(err.message, "n must be an integer") + assert2.include(err.message, 'n must be an integer') } }) - it("should throw an error if include_mempool is not a boolean", async () => { + it('should throw an error if include_mempool is not a boolean', async () => { try { await bchjs.Blockchain.getTxOut( - "daf58932cb91619304dd4cbd03c7202e89ad7d6cbd6e2209e5f64ce3b6ed7c88", + 'daf58932cb91619304dd4cbd03c7202e89ad7d6cbd6e2209e5f64ce3b6ed7c88', 0, - "bad value" + 'bad value' ) } catch (err) { assert2.include( err.message, - "include_mempool input must be of type boolean" + 'includeMempool input must be of type boolean' ) } }) - it("should get information on an unspent tx", async () => { - sandbox.stub(axios, "post").resolves({ data: mockData.txOutUnspent }) + it('should get information on an unspent tx', async () => { + sandbox.stub(axios, 'post').resolves({ data: mockData.txOutUnspent }) const result = await bchjs.Blockchain.getTxOut( - "62a3ea958a463a372bc0caf2c374a7f60be9c624be63a0db8db78f05809df6d8", + '62a3ea958a463a372bc0caf2c374a7f60be9c624be63a0db8db78f05809df6d8', 0, true ) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert2.hasAllKeys(result, [ - "bestblock", - "confirmations", - "value", - "scriptPubKey", - "coinbase" + 'bestblock', + 'confirmations', + 'value', + 'scriptPubKey', + 'coinbase' ]) }) - it("should get information on a spent tx", async () => { - sandbox.stub(axios, "post").resolves({ data: null }) + it('should get information on a spent tx', async () => { + sandbox.stub(axios, 'post').resolves({ data: null }) const result = await bchjs.Blockchain.getTxOut( - "87380e52d151856b23173d6d8a3db01b984c6b50f77ea045a5a1cf4f54497871", + '87380e52d151856b23173d6d8a3db01b984c6b50f77ea045a5a1cf4f54497871', 0, true ) @@ -417,7 +420,7 @@ describe("#Blockchain", () => { }) }) - describe("#preciousBlock", () => { + describe('#preciousBlock', () => { // TODO finish this test let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) @@ -426,9 +429,9 @@ describe("#Blockchain", () => { result: {} } - it("should get TODO", done => { + it('should get TODO', done => { const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) bchjs.Blockchain.preciousBlock() .then(result => { @@ -438,15 +441,15 @@ describe("#Blockchain", () => { }) }) - describe("#pruneBlockchain", () => { + describe('#pruneBlockchain', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) - const data = "Cannot prune blocks because node is not in prune mode." + const data = 'Cannot prune blocks because node is not in prune mode.' - it("should prune blockchain", done => { + it('should prune blockchain', done => { const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "post").returns(resolved) + sandbox.stub(axios, 'post').returns(resolved) bchjs.Blockchain.pruneBlockchain(507) .then(result => { @@ -456,15 +459,15 @@ describe("#Blockchain", () => { }) }) - describe("#verifyChain", () => { + describe('#verifyChain', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) const data = true - it("should verify blockchain", done => { + it('should verify blockchain', done => { const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) bchjs.Blockchain.verifyChain(3, 6) .then(result => { @@ -474,17 +477,17 @@ describe("#Blockchain", () => { }) }) - describe("#verifyTxOutProof", () => { + describe('#verifyTxOutProof', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) const data = "proof must be hexadecimal string (not '')" - it("should verify utxo proof", done => { + it('should verify utxo proof', done => { const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) - bchjs.Blockchain.verifyTxOutProof("3") + bchjs.Blockchain.verifyTxOutProof('3') .then(result => { assert.deepEqual(data, result) }) diff --git a/test/unit/control.js b/test/unit/control.js index 2ec8219..ba39935 100644 --- a/test/unit/control.js +++ b/test/unit/control.js @@ -1,31 +1,31 @@ -const assert = require("assert") -const axios = require("axios") -const BCHJS = require("../../src/bch-js") +const assert = require('assert') +const axios = require('axios') +const BCHJS = require('../../src/bch-js') const bchjs = new BCHJS() -const sinon = require("sinon") +const sinon = require('sinon') -describe("#Control", () => { - describe("#getNetworkInfo", () => { +describe('#Control', () => { + describe('#getNetworkInfo', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) - it("should get info", done => { + it('should get info', done => { const data = { version: 170000, protocolversion: 70015, blocks: 527813, timeoffset: 0, connections: 21, - proxy: "", + proxy: '', difficulty: 581086703759.5878, testnet: false, paytxfee: 0, relayfee: 0.00001, - errors: "" + errors: '' } const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) bchjs.Control.getNetworkInfo() .then(result => { @@ -35,12 +35,12 @@ describe("#Control", () => { }) }) - describe("#getMemoryInfo", () => { + describe('#getMemoryInfo', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) - it("should get memory info", done => { + it('should get memory info', done => { const data = { locked: { used: 0, @@ -52,7 +52,7 @@ describe("#Control", () => { } } const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) bchjs.Control.getMemoryInfo() .then(result => { diff --git a/test/unit/crypto.js b/test/unit/crypto.js index 73f6d23..1d08ebd 100644 --- a/test/unit/crypto.js +++ b/test/unit/crypto.js @@ -1,97 +1,97 @@ -const fixtures = require("./fixtures/crypto.json") -const assert = require("assert") -const BCHJS = require("../../src/bch-js") +const fixtures = require('./fixtures/crypto.json') +const assert = require('assert') +const BCHJS = require('../../src/bch-js') const bchjs = new BCHJS() -const Buffer = require("safe-buffer").Buffer +const Buffer = require('safe-buffer').Buffer -describe("#Crypto", () => { - describe("#sha256", () => { +describe('#Crypto', () => { + describe('#sha256', () => { fixtures.sha256.forEach(fixture => { it(`should create SHA256Hash hex encoded ${fixture.hash} from ${fixture.hex}`, () => { - const data = Buffer.from(fixture.hex, "hex") - const sha256Hash = bchjs.Crypto.sha256(data).toString("hex") + const data = Buffer.from(fixture.hex, 'hex') + const sha256Hash = bchjs.Crypto.sha256(data).toString('hex') assert.equal(sha256Hash, fixture.hash) }) - it(`should create 64 character SHA256Hash hex encoded`, () => { - const data = Buffer.from(fixture.hex, "hex") - const sha256Hash = bchjs.Crypto.sha256(data).toString("hex") + it('should create 64 character SHA256Hash hex encoded', () => { + const data = Buffer.from(fixture.hex, 'hex') + const sha256Hash = bchjs.Crypto.sha256(data).toString('hex') assert.equal(sha256Hash.length, 64) }) }) }) - describe("#ripemd160", () => { + describe('#ripemd160', () => { fixtures.ripemd160.forEach(fixture => { it(`should create RIPEMD160Hash hex encoded ${fixture.hash} from ${fixture.hex}`, () => { - const data = Buffer.from(fixture.hex, "hex") - const ripemd160 = bchjs.Crypto.ripemd160(data).toString("hex") + const data = Buffer.from(fixture.hex, 'hex') + const ripemd160 = bchjs.Crypto.ripemd160(data).toString('hex') assert.equal(ripemd160, fixture.hash) }) - it(`should create 64 character RIPEMD160Hash hex encoded`, () => { - const data = Buffer.from(fixture.hex, "hex") - const ripemd160 = bchjs.Crypto.ripemd160(data).toString("hex") + it('should create 64 character RIPEMD160Hash hex encoded', () => { + const data = Buffer.from(fixture.hex, 'hex') + const ripemd160 = bchjs.Crypto.ripemd160(data).toString('hex') assert.equal(ripemd160.length, 40) }) }) }) - describe("#hash256", () => { + describe('#hash256', () => { fixtures.hash256.forEach(fixture => { it(`should create double SHA256 Hash hex encoded ${fixture.hash} from ${fixture.hex}`, () => { - const data = Buffer.from(fixture.hex, "hex") - const hash256 = bchjs.Crypto.hash256(data).toString("hex") + const data = Buffer.from(fixture.hex, 'hex') + const hash256 = bchjs.Crypto.hash256(data).toString('hex') assert.equal(hash256, fixture.hash) }) - it(`should create 64 character SHA256 Hash hex encoded`, () => { - const data = Buffer.from(fixture.hex, "hex") - const hash256 = bchjs.Crypto.hash256(data).toString("hex") + it('should create 64 character SHA256 Hash hex encoded', () => { + const data = Buffer.from(fixture.hex, 'hex') + const hash256 = bchjs.Crypto.hash256(data).toString('hex') assert.equal(hash256.length, 64) }) }) }) - describe("#hash160", () => { + describe('#hash160', () => { fixtures.hash160.forEach(fixture => { it(`should create RIPEMD160(SHA256()) hex encoded ${fixture.hash} from ${fixture.hex}`, () => { - const data = Buffer.from(fixture.hex, "hex") - const hash160 = bchjs.Crypto.hash160(data).toString("hex") + const data = Buffer.from(fixture.hex, 'hex') + const hash160 = bchjs.Crypto.hash160(data).toString('hex') assert.equal(hash160, fixture.hash) }) - it(`should create 64 character SHA256Hash hex encoded`, () => { - const data = Buffer.from(fixture.hex, "hex") - const hash160 = bchjs.Crypto.hash160(data).toString("hex") + it('should create 64 character SHA256Hash hex encoded', () => { + const data = Buffer.from(fixture.hex, 'hex') + const hash160 = bchjs.Crypto.hash160(data).toString('hex') assert.equal(hash160.length, 40) }) }) }) - describe("#randomBytes", () => { + describe('#randomBytes', () => { for (let i = 0; i < 6; i++) { - it("should return 16 bytes of entropy hex encoded", () => { + it('should return 16 bytes of entropy hex encoded', () => { const entropy = bchjs.Crypto.randomBytes(16) assert.equal(Buffer.byteLength(entropy), 16) }) - it("should return 20 bytes of entropy hex encoded", () => { + it('should return 20 bytes of entropy hex encoded', () => { const entropy = bchjs.Crypto.randomBytes(20) assert.equal(Buffer.byteLength(entropy), 20) }) - it("should return 24 bytes of entropy hex encoded", () => { + it('should return 24 bytes of entropy hex encoded', () => { const entropy = bchjs.Crypto.randomBytes(24) assert.equal(Buffer.byteLength(entropy), 24) }) - it("should return 28 bytes of entropy hex encoded", () => { + it('should return 28 bytes of entropy hex encoded', () => { const entropy = bchjs.Crypto.randomBytes(28) assert.equal(Buffer.byteLength(entropy), 28) }) - it("should return 32 bytes of entropy hex encoded", () => { + it('should return 32 bytes of entropy hex encoded', () => { const entropy = bchjs.Crypto.randomBytes(32) assert.equal(Buffer.byteLength(entropy), 32) }) diff --git a/test/unit/ecpairs.js b/test/unit/ecpairs.js index 7cd4f8f..f543073 100644 --- a/test/unit/ecpairs.js +++ b/test/unit/ecpairs.js @@ -1,25 +1,25 @@ // Public npm libraries. -const assert = require("assert") -const Buffer = require("safe-buffer").Buffer +const assert = require('assert') +const Buffer = require('safe-buffer').Buffer // Mocks -const fixtures = require("./fixtures/ecpair.json") +const fixtures = require('./fixtures/ecpair.json') // Unit under test (uut) -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') // const bchjs = new BCHJS() let bchjs -describe("#ECPair", () => { +describe('#ECPair', () => { beforeEach(() => { bchjs = new BCHJS() }) - describe("#fromWIF", () => { + describe('#fromWIF', () => { fixtures.fromWIF.forEach(fixture => { it(`should create ECPair from WIF ${fixture.privateKeyWIF}`, () => { const ecpair = bchjs.ECPair.fromWIF(fixture.privateKeyWIF) - assert.equal(typeof ecpair, "object") + assert.equal(typeof ecpair, 'object') }) it(`should get ${fixture.legacy} legacy address`, () => { @@ -42,7 +42,7 @@ describe("#ECPair", () => { }) }) - describe("#toWIF", () => { + describe('#toWIF', () => { fixtures.toWIF.forEach(fixture => { it(`should get WIF ${fixture.privateKeyWIF} from ECPair`, () => { const ecpair = bchjs.ECPair.fromWIF(fixture.privateKeyWIF) @@ -52,32 +52,32 @@ describe("#ECPair", () => { }) }) - describe("#fromPublicKey", () => { + describe('#fromPublicKey', () => { fixtures.fromPublicKey.forEach(fixture => { - it(`should create ECPair from public key buffer`, () => { + it('should create ECPair from public key buffer', () => { const ecpair = bchjs.ECPair.fromPublicKey( - Buffer.from(fixture.pubkeyHex, "hex") + Buffer.from(fixture.pubkeyHex, 'hex') ) - assert.equal(typeof ecpair, "object") + assert.equal(typeof ecpair, 'object') }) it(`should get ${fixture.legacy} legacy address`, () => { const ecpair = bchjs.ECPair.fromPublicKey( - Buffer.from(fixture.pubkeyHex, "hex") + Buffer.from(fixture.pubkeyHex, 'hex') ) assert.equal(bchjs.HDNode.toLegacyAddress(ecpair), fixture.legacy) }) it(`should get ${fixture.cashAddr} cash address`, () => { const ecpair = bchjs.ECPair.fromPublicKey( - Buffer.from(fixture.pubkeyHex, "hex") + Buffer.from(fixture.pubkeyHex, 'hex') ) assert.equal(bchjs.HDNode.toCashAddress(ecpair), fixture.cashAddr) }) it(`should get ${fixture.regtestAddr} cash address`, () => { const ecpair = bchjs.ECPair.fromPublicKey( - Buffer.from(fixture.pubkeyHex, "hex") + Buffer.from(fixture.pubkeyHex, 'hex') ) assert.equal( bchjs.HDNode.toCashAddress(ecpair, true), @@ -87,19 +87,19 @@ describe("#ECPair", () => { }) }) - describe("#toPublicKey", () => { + describe('#toPublicKey', () => { fixtures.toPublicKey.forEach(fixture => { - it(`should create a public key buffer from an ECPair`, () => { + it('should create a public key buffer from an ECPair', () => { const ecpair = bchjs.ECPair.fromPublicKey( - Buffer.from(fixture.pubkeyHex, "hex") + Buffer.from(fixture.pubkeyHex, 'hex') ) const pubkeyBuffer = bchjs.ECPair.toPublicKey(ecpair) - assert.equal(typeof pubkeyBuffer, "object") + assert.equal(typeof pubkeyBuffer, 'object') }) }) }) - describe("#toLegacyAddress", () => { + describe('#toLegacyAddress', () => { fixtures.toLegacyAddress.forEach(fixture => { it(`should create legacy address ${fixture.legacy} from an ECPair`, () => { const ecpair = bchjs.ECPair.fromWIF(fixture.privateKeyWIF) @@ -109,7 +109,7 @@ describe("#ECPair", () => { }) }) - describe("#toCashAddress", () => { + describe('#toCashAddress', () => { fixtures.toCashAddress.forEach(fixture => { it(`should create cash address ${fixture.cashAddr} from an ECPair`, () => { const ecpair = bchjs.ECPair.fromWIF(fixture.privateKeyWIF) @@ -127,23 +127,23 @@ describe("#ECPair", () => { }) }) - describe("#sign", () => { + describe('#sign', () => { fixtures.sign.forEach(fixture => { - it(`should sign 32 byte hash buffer`, () => { + it('should sign 32 byte hash buffer', () => { const ecpair = bchjs.ECPair.fromWIF(fixture.privateKeyWIF) - const buf = Buffer.from(bchjs.Crypto.sha256(fixture.data), "hex") + const buf = Buffer.from(bchjs.Crypto.sha256(fixture.data), 'hex') const signatureBuf = bchjs.ECPair.sign(ecpair, buf) - assert.equal(typeof signatureBuf, "object") + assert.equal(typeof signatureBuf, 'object') }) }) }) - describe("#verify", () => { + describe('#verify', () => { fixtures.verify.forEach(fixture => { - it(`should verify signed 32 byte hash buffer`, () => { + it('should verify signed 32 byte hash buffer', () => { const ecpair1 = bchjs.ECPair.fromWIF(fixture.privateKeyWIF1) - //const ecpair2 = bchjs.ECPair.fromWIF(fixture.privateKeyWIF2) - const buf = Buffer.from(bchjs.Crypto.sha256(fixture.data), "hex") + // const ecpair2 = bchjs.ECPair.fromWIF(fixture.privateKeyWIF2) + const buf = Buffer.from(bchjs.Crypto.sha256(fixture.data), 'hex') const signature = bchjs.ECPair.sign(ecpair1, buf) const verify = bchjs.ECPair.verify(ecpair1, buf, signature) assert.equal(verify, true) diff --git a/test/unit/electrumx.js b/test/unit/electrumx.js index 479d77b..971483a 100644 --- a/test/unit/electrumx.js +++ b/test/unit/electrumx.js @@ -1,275 +1,275 @@ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert -const axios = require("axios") -const sinon = require("sinon") +const axios = require('axios') +const sinon = require('sinon') -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') const bchjs = new BCHJS() -const mockData = require("./fixtures/electrumx-mock") +const mockData = require('./fixtures/electrumx-mock') -describe(`#ElectrumX`, () => { +describe('#ElectrumX', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) - describe(`#utxo`, () => { - it(`should throw an error for improper input`, async () => { + describe('#utxo', () => { + it('should throw an error for improper input', async () => { try { const addr = 12345 await bchjs.Electrumx.utxo(addr) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { // console.log(`err: `, err) assert.include( err.message, - `Input address must be a string or array of strings` + 'Input address must be a string or array of strings' ) } }) - it(`should GET utxos for a single address`, async () => { + it('should GET utxos for a single address', async () => { // Stub the network call. - sandbox.stub(axios, "get").resolves({ data: mockData.utxo }) + sandbox.stub(axios, 'get').resolves({ data: mockData.utxo }) - const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9" + const addr = 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9' const result = await bchjs.Electrumx.utxo(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "utxos") + assert.property(result, 'utxos') assert.isArray(result.utxos) - assert.property(result.utxos[0], "height") - assert.property(result.utxos[0], "tx_hash") - assert.property(result.utxos[0], "tx_pos") - assert.property(result.utxos[0], "value") + assert.property(result.utxos[0], 'height') + assert.property(result.utxos[0], 'tx_hash') + assert.property(result.utxos[0], 'tx_pos') + assert.property(result.utxos[0], 'value') }) - it(`should POST utxo details for an array of addresses`, async () => { + it('should POST utxo details for an array of addresses', async () => { // Stub the network call. - sandbox.stub(axios, "post").resolves({ data: mockData.utxos }) + sandbox.stub(axios, 'post').resolves({ data: mockData.utxos }) const addr = [ - "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf", - "bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v" + 'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf', + 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v' ] const result = await bchjs.Electrumx.utxo(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "utxos") + assert.property(result, 'utxos') assert.isArray(result.utxos) - assert.property(result.utxos[0], "utxos") + assert.property(result.utxos[0], 'utxos') assert.isArray(result.utxos[0].utxos) - assert.property(result.utxos[0], "address") + assert.property(result.utxos[0], 'address') - assert.property(result.utxos[0].utxos[0], "height") - assert.property(result.utxos[0].utxos[0], "tx_hash") - assert.property(result.utxos[0].utxos[0], "tx_pos") - assert.property(result.utxos[0].utxos[0], "value") + assert.property(result.utxos[0].utxos[0], 'height') + assert.property(result.utxos[0].utxos[0], 'tx_hash') + assert.property(result.utxos[0].utxos[0], 'tx_pos') + assert.property(result.utxos[0].utxos[0], 'value') }) }) - describe(`#balance`, () => { - it(`should throw an error for improper input`, async () => { + describe('#balance', () => { + it('should throw an error for improper input', async () => { try { const addr = 12345 await bchjs.Electrumx.balance(addr) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { // console.log(`err: `, err) assert.include( err.message, - `Input address must be a string or array of strings` + 'Input address must be a string or array of strings' ) } }) - it(`should GET balance for a single address`, async () => { + it('should GET balance for a single address', async () => { // Stub the network call. - sandbox.stub(axios, "get").resolves({ data: mockData.balance }) + sandbox.stub(axios, 'get').resolves({ data: mockData.balance }) - const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9" + const addr = 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9' const result = await bchjs.Electrumx.balance(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "balance") - assert.property(result.balance, "confirmed") - assert.property(result.balance, "unconfirmed") + assert.property(result, 'balance') + assert.property(result.balance, 'confirmed') + assert.property(result.balance, 'unconfirmed') }) - it(`should POST balance for an array of addresses`, async () => { + it('should POST balance for an array of addresses', async () => { // Stub the network call. - sandbox.stub(axios, "post").resolves({ data: mockData.balances }) + sandbox.stub(axios, 'post').resolves({ data: mockData.balances }) const addr = [ - "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf", - "bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v" + 'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf', + 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v' ] const result = await bchjs.Electrumx.balance(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "balances") + assert.property(result, 'balances') assert.isArray(result.balances) - assert.property(result.balances[0], "address") - assert.property(result.balances[0], "balance") - assert.property(result.balances[0].balance, "confirmed") - assert.property(result.balances[0].balance, "unconfirmed") + assert.property(result.balances[0], 'address') + assert.property(result.balances[0], 'balance') + assert.property(result.balances[0].balance, 'confirmed') + assert.property(result.balances[0].balance, 'unconfirmed') }) }) - describe(`#transactions`, () => { - it(`should throw an error for improper input`, async () => { + describe('#transactions', () => { + it('should throw an error for improper input', async () => { try { const addr = 12345 await bchjs.Electrumx.transactions(addr) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { // console.log(`err: `, err) assert.include( err.message, - `Input address must be a string or array of strings` + 'Input address must be a string or array of strings' ) } }) - it(`should GET transactions for a single address`, async () => { + it('should GET transactions for a single address', async () => { // Stub the network call. - sandbox.stub(axios, "get").resolves({ data: mockData.transaction }) + sandbox.stub(axios, 'get').resolves({ data: mockData.transaction }) - const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9" + const addr = 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9' const result = await bchjs.Electrumx.transactions(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "transactions") + assert.property(result, 'transactions') assert.isArray(result.transactions) - assert.property(result.transactions[0], "height") - assert.property(result.transactions[0], "tx_hash") + assert.property(result.transactions[0], 'height') + assert.property(result.transactions[0], 'tx_hash') }) - it(`should POST transaction history for an array of addresses`, async () => { + it('should POST transaction history for an array of addresses', async () => { // Stub the network call. - sandbox.stub(axios, "post").resolves({ data: mockData.transactions }) + sandbox.stub(axios, 'post').resolves({ data: mockData.transactions }) const addr = [ - "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf", - "bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v" + 'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf', + 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v' ] const result = await bchjs.Electrumx.transactions(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "transactions") + assert.property(result, 'transactions') assert.isArray(result.transactions) - assert.property(result.transactions[0], "address") - assert.property(result.transactions[0], "transactions") + assert.property(result.transactions[0], 'address') + assert.property(result.transactions[0], 'transactions') assert.isArray(result.transactions[0].transactions) - assert.property(result.transactions[0].transactions[0], "height") - assert.property(result.transactions[0].transactions[0], "tx_hash") + assert.property(result.transactions[0].transactions[0], 'height') + assert.property(result.transactions[0].transactions[0], 'tx_hash') }) }) - describe(`#unconfirmed`, () => { - it(`should throw an error for improper input`, async () => { + describe('#unconfirmed', () => { + it('should throw an error for improper input', async () => { try { const addr = 12345 await bchjs.Electrumx.unconfirmed(addr) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { // console.log(`err: `, err) assert.include( err.message, - `Input address must be a string or array of strings` + 'Input address must be a string or array of strings' ) } }) - it(`should GET unconfirmed utxos for a single address`, async () => { + it('should GET unconfirmed utxos for a single address', async () => { // Stub the network call. - sandbox.stub(axios, "get").resolves({ data: mockData.unconfirmed }) + sandbox.stub(axios, 'get').resolves({ data: mockData.unconfirmed }) - const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9" + const addr = 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9' const result = await bchjs.Electrumx.unconfirmed(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "utxos") + assert.property(result, 'utxos') assert.isArray(result.utxos) - assert.property(result.utxos[0], "height") - assert.property(result.utxos[0], "tx_hash") - assert.property(result.utxos[0], "fee") + assert.property(result.utxos[0], 'height') + assert.property(result.utxos[0], 'tx_hash') + assert.property(result.utxos[0], 'fee') }) - it(`should POST unconfirmed utxo details for an array of addresses`, async () => { + it('should POST unconfirmed utxo details for an array of addresses', async () => { // Stub the network call. - sandbox.stub(axios, "post").resolves({ data: mockData.unconfirmedArray }) + sandbox.stub(axios, 'post').resolves({ data: mockData.unconfirmedArray }) const addr = [ - "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf", - "bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v" + 'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf', + 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v' ] const result = await bchjs.Electrumx.unconfirmed(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "utxos") + assert.property(result, 'utxos') assert.isArray(result.utxos) - assert.property(result.utxos[0], "utxos") + assert.property(result.utxos[0], 'utxos') assert.isArray(result.utxos[0].utxos) - assert.property(result.utxos[0], "address") + assert.property(result.utxos[0], 'address') - assert.property(result.utxos[0].utxos[0], "height") - assert.property(result.utxos[0].utxos[0], "tx_hash") - assert.property(result.utxos[0].utxos[0], "fee") + assert.property(result.utxos[0].utxos[0], 'height') + assert.property(result.utxos[0].utxos[0], 'tx_hash') + assert.property(result.utxos[0].utxos[0], 'fee') }) }) - describe(`#blockHeader`, () => { - it(`should throw an error for improper height input`, async () => { + describe('#blockHeader', () => { + it('should throw an error for improper height input', async () => { try { // Mock network calls. - sandbox.stub(axios, "get").rejects({ + sandbox.stub(axios, 'get').rejects({ response: { data: { success: false, - error: "height must be a positive number" + error: 'height must be a positive number' } } }) @@ -277,21 +277,21 @@ describe(`#ElectrumX`, () => { const height = -10 await bchjs.Electrumx.blockHeader(height) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { // console.log(`err: `, err) - assert.include(err.message, `height must be a positive number`) + assert.include(err.message, 'height must be a positive number') } }) - it(`should throw an error for improper count input`, async () => { + it('should throw an error for improper count input', async () => { try { // Mock network calls. - sandbox.stub(axios, "get").rejects({ + sandbox.stub(axios, 'get').rejects({ response: { data: { success: false, - error: "count must be a positive number" + error: 'count must be a positive number' } } }) @@ -300,16 +300,16 @@ describe(`#ElectrumX`, () => { const count = -10 await bchjs.Electrumx.blockHeader(height, count) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { // console.log(`err: `, err) - assert.include(err.message, `count must be a positive number`) + assert.include(err.message, 'count must be a positive number') } }) - it(`should GET block headers for a given height`, async () => { + it('should GET block headers for a given height', async () => { // Stub the network call. - sandbox.stub(axios, "get").resolves({ data: mockData.blockHeaders }) + sandbox.stub(axios, 'get').resolves({ data: mockData.blockHeaders }) const height = 42 @@ -320,101 +320,101 @@ describe(`#ElectrumX`, () => { }) }) - describe(`#txData`, () => { - it(`should throw an error for improper input`, async () => { + describe('#txData', () => { + it('should throw an error for improper input', async () => { try { const txid = 12345 await bchjs.Electrumx.txData(txid) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { // console.log(`err: `, err) assert.include( err.message, - `Input txId must be a string or array of strings` + 'Input txId must be a string or array of strings' ) } }) - it(`should GET details data for a single transaction`, async () => { + it('should GET details data for a single transaction', async () => { // Stub the network call. - sandbox.stub(axios, "get").resolves({ data: mockData.details }) + sandbox.stub(axios, 'get').resolves({ data: mockData.details }) const txid = - "4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251" + '4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251' const result = await bchjs.Electrumx.txData(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "details") + assert.property(result, 'details') assert.isObject(result.details) - assert.property(result.details, "blockhash") - assert.property(result.details, "hash") - assert.property(result.details, "hex") - assert.property(result.details, "vin") - assert.property(result.details, "vout") + assert.property(result.details, 'blockhash') + assert.property(result.details, 'hash') + assert.property(result.details, 'hex') + assert.property(result.details, 'vin') + assert.property(result.details, 'vout') assert.equal(result.details.hash, txid) }) - it(`should POST details for an array of transactions`, async () => { + it('should POST details for an array of transactions', async () => { // Stub the network call. - sandbox.stub(axios, "post").resolves({ data: mockData.detailsArray }) + sandbox.stub(axios, 'post').resolves({ data: mockData.detailsArray }) const txids = [ - "4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251", - "4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251" + '4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251', + '4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251' ] const result = await bchjs.Electrumx.txData(txids) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "transactions") + assert.property(result, 'transactions') assert.isArray(result.transactions) - assert.property(result.transactions[0], "txid") - assert.property(result.transactions[0], "details") + assert.property(result.transactions[0], 'txid') + assert.property(result.transactions[0], 'details') - assert.property(result.transactions[0].details, "blockhash") - assert.property(result.transactions[0].details, "hash") - assert.property(result.transactions[0].details, "hex") - assert.property(result.transactions[0].details, "vin") - assert.property(result.transactions[0].details, "vout") + assert.property(result.transactions[0].details, 'blockhash') + assert.property(result.transactions[0].details, 'hash') + assert.property(result.transactions[0].details, 'hex') + assert.property(result.transactions[0].details, 'vin') + assert.property(result.transactions[0].details, 'vout') - assert.equal(result.transactions.length, 2, "2 outputs for 2 inputs") + assert.equal(result.transactions.length, 2, '2 outputs for 2 inputs') }) }) - describe(`#broadcast`, () => { - it(`should throw an error for improper input`, async () => { + describe('#broadcast', () => { + it('should throw an error for improper input', async () => { try { const txHex = 12345 await bchjs.Electrumx.broadcast(txHex) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { // console.log(`err: `, err) - assert.include(err.message, `Input txHex must be a string.`) + assert.include(err.message, 'Input txHex must be a string.') } }) - it(`should broadcast a single transaction`, async () => { + it('should broadcast a single transaction', async () => { // Stub the network call. - sandbox.stub(axios, "post").resolves({ data: mockData.broadcast }) + sandbox.stub(axios, 'post').resolves({ data: mockData.broadcast }) const tx = mockData.details const txid = tx.details.txid const result = await bchjs.Electrumx.broadcast(tx.details.hex) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "txid") + assert.property(result, 'txid') assert.equal(result.txid, txid) }) }) diff --git a/test/unit/encryption.js b/test/unit/encryption.js index 9242348..6945ae7 100644 --- a/test/unit/encryption.js +++ b/test/unit/encryption.js @@ -1,13 +1,13 @@ -const assert = require("chai").assert -const sinon = require("sinon") +const assert = require('chai').assert +const sinon = require('sinon') -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') // const bchjs = new BCHJS() let bchjs -const mockData = require("./fixtures/encryption-mock") +const mockData = require('./fixtures/encryption-mock') -describe("#Encryption", () => { +describe('#Encryption', () => { let sandbox beforeEach(() => { @@ -17,52 +17,52 @@ describe("#Encryption", () => { afterEach(() => sandbox.restore()) - describe("#getPubKey", () => { - it("should throw error if BCH address is not provided.", async () => { + describe('#getPubKey', () => { + it('should throw error if BCH address is not provided.', async () => { try { await bchjs.encryption.getPubKey() - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { // console.log(`err: `, err) assert.include( err.message, - "Input must be a valid Bitcoin Cash address" + 'Input must be a valid Bitcoin Cash address' ) } }) - it("should report when public key can not be found", async () => { + it('should report when public key can not be found', async () => { // Stub the network call. sandbox - .stub(bchjs.encryption.axios, "get") + .stub(bchjs.encryption.axios, 'get') .resolves({ data: mockData.failureMock }) - const addr = "bitcoincash:qpxqr2pmcverj4vukgjqssvk2zju8tp9xsgz2nqagx" + const addr = 'bitcoincash:qpxqr2pmcverj4vukgjqssvk2zju8tp9xsgz2nqagx' const result = await bchjs.encryption.getPubKey(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, false) - assert.property(result, "publicKey") - assert.equal(result.publicKey, "not found") + assert.property(result, 'publicKey') + assert.equal(result.publicKey, 'not found') }) - it("should get a public key", async () => { + it('should get a public key', async () => { // Stub the network call. sandbox - .stub(bchjs.encryption.axios, "get") + .stub(bchjs.encryption.axios, 'get') .resolves({ data: mockData.successMock }) - const addr = "bitcoincash:qpf8jv9hmqcda0502gjp7nm3g24y5h5s4unutghsxq" + const addr = 'bitcoincash:qpf8jv9hmqcda0502gjp7nm3g24y5h5s4unutghsxq' const result = await bchjs.encryption.getPubKey(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "publicKey") + assert.property(result, 'publicKey') }) }) }) diff --git a/test/unit/fixtures/bitcore-mock.js b/test/unit/fixtures/bitcore-mock.js index 33d9cb8..b4e6770 100644 --- a/test/unit/fixtures/bitcore-mock.js +++ b/test/unit/fixtures/bitcore-mock.js @@ -6,34 +6,34 @@ const balance = { confirmed: 230000, unconfirmed: 0, balance: 230000 } const utxo = [ { - _id: "5cecdd39a9f1235e2a3d409a", - chain: "BCH", - network: "mainnet", + _id: '5cecdd39a9f1235e2a3d409a', + chain: 'BCH', + network: 'mainnet', coinbase: false, mintIndex: 0, - spentTxid: "", + spentTxid: '', mintTxid: - "27ec8512c1a9ee9e9ae9b98eb60375f1d2bd60e2e76a1eff5a45afdbc517cf9c", + '27ec8512c1a9ee9e9ae9b98eb60375f1d2bd60e2e76a1eff5a45afdbc517cf9c', mintHeight: 560430, spentHeight: -2, - address: "qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf", - script: "76a914db6ea94fa26b7272dc5e1487c35f258391e0f38788ac", + address: 'qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf', + script: '76a914db6ea94fa26b7272dc5e1487c35f258391e0f38788ac', value: 100000, confirmations: -1 }, { - _id: "5cecdd1ca9f1235e2a3b6349", - chain: "BCH", - network: "mainnet", + _id: '5cecdd1ca9f1235e2a3b6349', + chain: 'BCH', + network: 'mainnet', coinbase: false, mintIndex: 0, - spentTxid: "", + spentTxid: '', mintTxid: - "6e1ae1bf7db6de799ec1c05ab2816ac65549bd80141567af088e6f291385b07d", + '6e1ae1bf7db6de799ec1c05ab2816ac65549bd80141567af088e6f291385b07d', mintHeight: 560039, spentHeight: -2, - address: "qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf", - script: "76a914db6ea94fa26b7272dc5e1487c35f258391e0f38788ac", + address: 'qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf', + script: '76a914db6ea94fa26b7272dc5e1487c35f258391e0f38788ac', value: 130000, confirmations: -1 } diff --git a/test/unit/fixtures/block-mock.js b/test/unit/fixtures/block-mock.js index 844140f..4f053b3 100644 --- a/test/unit/fixtures/block-mock.js +++ b/test/unit/fixtures/block-mock.js @@ -4,24 +4,24 @@ module.exports = { details: { - hash: "000000001c6aeec19265e9cc3ded8ba5ef5e63fae7747f30bf9c02c7bc8883f0", + hash: '000000001c6aeec19265e9cc3ded8ba5ef5e63fae7747f30bf9c02c7bc8883f0', size: 216, height: 507, version: 1, merkleroot: - "a85fa3d831ab6b0305e7ff88d2d4941e25a810d4461635df51490653822071a8", - tx: ["a85fa3d831ab6b0305e7ff88d2d4941e25a810d4461635df51490653822071a8"], + 'a85fa3d831ab6b0305e7ff88d2d4941e25a810d4461635df51490653822071a8', + tx: ['a85fa3d831ab6b0305e7ff88d2d4941e25a810d4461635df51490653822071a8'], time: 1231973656, nonce: 330467862, - bits: "1d00ffff", + bits: '1d00ffff', difficulty: 1, chainwork: - "000000000000000000000000000000000000000000000000000001fc01fc01fc", + '000000000000000000000000000000000000000000000000000001fc01fc01fc', confirmations: 585104, previousblockhash: - "00000000a99525c043fd7e323414b60add43c254c44860094048f9c01e9a5fdd", + '00000000a99525c043fd7e323414b60add43c254c44860094048f9c01e9a5fdd', nextblockhash: - "000000000d550f4161f2702165fdd782ec72ff9c541f864ebb8256b662b7e51a", + '000000000d550f4161f2702165fdd782ec72ff9c541f864ebb8256b662b7e51a', reward: 50, isMainChain: true, poolInfo: {} diff --git a/test/unit/fixtures/blockchain-mock.js b/test/unit/fixtures/blockchain-mock.js index 17b7c43..9bbba2c 100644 --- a/test/unit/fixtures/blockchain-mock.js +++ b/test/unit/fixtures/blockchain-mock.js @@ -4,47 +4,47 @@ module.exports = { bestBlockHash: - "0000000000000000008e1f65f875703872544aa888c7ca6587f055f8f5fbd4bf", + '0000000000000000008e1f65f875703872544aa888c7ca6587f055f8f5fbd4bf', blockHeader: { - hash: "000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201", + hash: '000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201', confirmations: 85727, height: 500000, version: 536870912, - versionHex: "20000000", + versionHex: '20000000', merkleroot: - "4af279645e1b337e655ae3286fc2ca09f58eb01efa6ab27adedd1e9e6ec19091", + '4af279645e1b337e655ae3286fc2ca09f58eb01efa6ab27adedd1e9e6ec19091', time: 1509343584, mediantime: 1509336533, nonce: 3604508752, - bits: "1809b91a", + bits: '1809b91a', difficulty: 113081236211.4533, chainwork: - "0000000000000000000000000000000000000000007ae48aca46e3b449ad9714", + '0000000000000000000000000000000000000000007ae48aca46e3b449ad9714', previousblockhash: - "0000000000000000043831d6ebb013716f0580287ee5e5687e27d0ed72e6e523", + '0000000000000000043831d6ebb013716f0580287ee5e5687e27d0ed72e6e523', nextblockhash: - "00000000000000000568f0a96bf4348847bc84e455cbfec389f27311037a20f3" + '00000000000000000568f0a96bf4348847bc84e455cbfec389f27311037a20f3' }, txOutProof: - "0000002086a4a3161f9ba2174883ec0b93acceac3b2f37b36ed1f90000000000000000009cb02406d1094ecf3e0b4c0ca7c585125e721147c39daf6b48c90b512741e13a12333e5cb38705180f441d8c7100000008fee9b60f1edb57e5712839186277ed39e0a004a32be9096ee47472efde8eae62f789f9d7a9f59d0ea7093dea1e0c65ff0b953f1d8cf3d47f92e732ca0295f603c272d5f4a63509f7a887f2549d78af7444aa0ecbb4f66d9cbe13bc6a89f59e05a199df8325d490818ffefe6b6321d32d7496a68580459836c0183f89082fc1b491cc91b23ecdcaa4c347bf599a62904d61f1c15b400ebbd5c90149010c139d9c1e31b774b796977393a238080ab477e1d240d0c4f155d36f519668f49bae6bd8cd5b8e40522edf76faa09cca6188d83ff13af6967cc6a569d1a5e9aeb1fdb7f531ddd2d0cbb81879741d5f38166ac1932136264366a4065cc96a42e41f96294f02df01", + '0000002086a4a3161f9ba2174883ec0b93acceac3b2f37b36ed1f90000000000000000009cb02406d1094ecf3e0b4c0ca7c585125e721147c39daf6b48c90b512741e13a12333e5cb38705180f441d8c7100000008fee9b60f1edb57e5712839186277ed39e0a004a32be9096ee47472efde8eae62f789f9d7a9f59d0ea7093dea1e0c65ff0b953f1d8cf3d47f92e732ca0295f603c272d5f4a63509f7a887f2549d78af7444aa0ecbb4f66d9cbe13bc6a89f59e05a199df8325d490818ffefe6b6321d32d7496a68580459836c0183f89082fc1b491cc91b23ecdcaa4c347bf599a62904d61f1c15b400ebbd5c90149010c139d9c1e31b774b796977393a238080ab477e1d240d0c4f155d36f519668f49bae6bd8cd5b8e40522edf76faa09cca6188d83ff13af6967cc6a569d1a5e9aeb1fdb7f531ddd2d0cbb81879741d5f38166ac1932136264366a4065cc96a42e41f96294f02df01', verifiedProof: - "03f69502ca32e7927fd4f38c1d3f950bff650c1eea3d09a70e9df5a9d7f989f7", + '03f69502ca32e7927fd4f38c1d3f950bff650c1eea3d09a70e9df5a9d7f989f7', txOutUnspent: { bestblock: - "000000000000000000b441e02f5b1b9f5b3def961047afcc6f2f5636c952705e", + '000000000000000000b441e02f5b1b9f5b3def961047afcc6f2f5636c952705e', confirmations: 2, value: 0.00006, scriptPubKey: { asm: - "OP_DUP OP_HASH160 d19fae66b685f5c3633c0db0600313918347225f OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a914d19fae66b685f5c3633c0db0600313918347225f88ac", + 'OP_DUP OP_HASH160 d19fae66b685f5c3633c0db0600313918347225f OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a914d19fae66b685f5c3633c0db0600313918347225f88ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qrgeltnxk6zltsmr8sxmqcqrzwgcx3eztusrwgf0x3"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qrgeltnxk6zltsmr8sxmqcqrzwgcx3eztusrwgf0x3'] }, coinbase: false } diff --git a/test/unit/fixtures/electrumx-mock.js b/test/unit/fixtures/electrumx-mock.js index 1ca4819..b32a63d 100644 --- a/test/unit/fixtures/electrumx-mock.js +++ b/test/unit/fixtures/electrumx-mock.js @@ -8,7 +8,7 @@ const utxo = { { height: 602405, tx_hash: - "2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7", + '2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7', tx_pos: 0, value: 1000 } @@ -23,23 +23,23 @@ const utxos = { { height: 604392, tx_hash: - "7774e449c5a3065144cefbc4c0c21e6b69c987f095856778ef9f45ddd8ae1a41", + '7774e449c5a3065144cefbc4c0c21e6b69c987f095856778ef9f45ddd8ae1a41', tx_pos: 0, value: 1000 }, { height: 630834, tx_hash: - "4fe60a51e0d8f5134bfd8e5f872d6e502d7f01b28a6afebb27f4438a4f638d53", + '4fe60a51e0d8f5134bfd8e5f872d6e502d7f01b28a6afebb27f4438a4f638d53', tx_pos: 0, value: 6000 } ], - address: "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf" + address: 'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf' }, { utxos: [], - address: "bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v" + address: 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v' } ] } @@ -60,14 +60,14 @@ const balances = { confirmed: 7000, unconfirmed: 0 }, - address: "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf" + address: 'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf' }, { balance: { confirmed: 0, unconfirmed: 0 }, - address: "bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v" + address: 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v' } ] } @@ -78,12 +78,12 @@ const transaction = { { height: 560430, tx_hash: - "3e1f3e882be9c03897eeb197224bf87f312be556a89f4308fabeeeabcf9bc851" + '3e1f3e882be9c03897eeb197224bf87f312be556a89f4308fabeeeabcf9bc851' }, { height: 560534, tx_hash: - "4ebbeaac51ce141e262964e3a0ce11b96ca72c0dffe9b4127ce80135f503a280" + '4ebbeaac51ce141e262964e3a0ce11b96ca72c0dffe9b4127ce80135f503a280' } ] } @@ -96,25 +96,25 @@ const transactions = { { height: 631219, tx_hash: - "ae2daa01c8172545b5edd205ea438706bcb74e63d4084a26b9ff2a46d46dc97f" + 'ae2daa01c8172545b5edd205ea438706bcb74e63d4084a26b9ff2a46d46dc97f' } ], - address: "bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj" + address: 'bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj' }, { transactions: [ { height: 560430, tx_hash: - "3e1f3e882be9c03897eeb197224bf87f312be556a89f4308fabeeeabcf9bc851" + '3e1f3e882be9c03897eeb197224bf87f312be556a89f4308fabeeeabcf9bc851' }, { height: 560534, tx_hash: - "4ebbeaac51ce141e262964e3a0ce11b96ca72c0dffe9b4127ce80135f503a280" + '4ebbeaac51ce141e262964e3a0ce11b96ca72c0dffe9b4127ce80135f503a280' } ], - address: "bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v" + address: 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v' } ] } @@ -125,7 +125,7 @@ const unconfirmed = { { height: 602405, tx_hash: - "2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7", + '2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7', fee: 34100 } ] @@ -139,21 +139,21 @@ const unconfirmedArray = { { height: 604392, tx_hash: - "7774e449c5a3065144cefbc4c0c21e6b69c987f095856778ef9f45ddd8ae1a41", + '7774e449c5a3065144cefbc4c0c21e6b69c987f095856778ef9f45ddd8ae1a41', fee: 34210 }, { height: 630834, tx_hash: - "4fe60a51e0d8f5134bfd8e5f872d6e502d7f01b28a6afebb27f4438a4f638d53", + '4fe60a51e0d8f5134bfd8e5f872d6e502d7f01b28a6afebb27f4438a4f638d53', value: 3000 } ], - address: "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf" + address: 'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf' }, { utxos: [], - address: "bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v" + address: 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v' } ] } diff --git a/test/unit/fixtures/encryption-mock.js b/test/unit/fixtures/encryption-mock.js index d4d19da..ff888f8 100644 --- a/test/unit/fixtures/encryption-mock.js +++ b/test/unit/fixtures/encryption-mock.js @@ -5,12 +5,12 @@ const successMock = { success: true, publicKey: - "03fcc37586d93af1e146238217989924e0ab1f011c34e1a23aec529354d5b28eb4" + '03fcc37586d93af1e146238217989924e0ab1f011c34e1a23aec529354d5b28eb4' } const failureMock = { success: false, - publicKey: "not found" + publicKey: 'not found' } module.exports = { diff --git a/test/unit/fixtures/ipfs-mock.js b/test/unit/fixtures/ipfs-mock.js index 25f628a..4165319 100644 --- a/test/unit/fixtures/ipfs-mock.js +++ b/test/unit/fixtures/ipfs-mock.js @@ -5,17 +5,17 @@ const uploadData = { successful: [ { - source: "Local", - id: "uppy-ipfs/js-1e-application/octet-stream", - name: "ipfs.js", - extension: "js", + source: 'Local', + id: 'uppy-ipfs/js-1e-application/octet-stream', + name: 'ipfs.js', + extension: 'js', meta: { - test: "avatar", - name: "ipfs.js", - type: "application/octet-stream", - fileModelId: "5ec562319bfacc745e8d8a52" + test: 'avatar', + name: 'ipfs.js', + type: 'application/octet-stream', + fileModelId: '5ec562319bfacc745e8d8a52' }, - type: "application/octet-stream", + type: 'application/octet-stream', progress: { uploadStarted: 1589596706524, uploadComplete: true, @@ -25,22 +25,22 @@ const uploadData = { }, size: null, isRemote: false, - remote: "", + remote: '', tus: { uploadUrl: - "http://localhost:5001/uppy-files/6acd261f494c3375dc522e27880efe33" + 'http://localhost:5001/uppy-files/6acd261f494c3375dc522e27880efe33' }, response: { uploadURL: - "http://localhost:5001/uppy-files/6acd261f494c3375dc522e27880efe33" + 'http://localhost:5001/uppy-files/6acd261f494c3375dc522e27880efe33' }, uploadURL: - "http://localhost:5001/uppy-files/6acd261f494c3375dc522e27880efe33", + 'http://localhost:5001/uppy-files/6acd261f494c3375dc522e27880efe33', isPaused: false } ], failed: [], - uploadID: "cka90u4m300000fi0cldg6lrf" + uploadID: 'cka90u4m300000fi0cldg6lrf' } const paymentInfo = { @@ -48,18 +48,18 @@ const paymentInfo = { hostingCostBCH: 0.00004201, hostingCostUSD: 0.01, file: { - payloadLink: "", + payloadLink: '', hasBeenPaid: false, - _id: "5ebf5d04cba8b038394e0d62", + _id: '5ebf5d04cba8b038394e0d62', schemaVersion: 1, size: 2374, - fileId: "uppy-ipfs/js-1e-application/octet-stream", - fileName: "ipfs.js", - fileExtension: "js", - createdTimestamp: "1589599492.952", + fileId: 'uppy-ipfs/js-1e-application/octet-stream', + fileName: 'ipfs.js', + fileExtension: 'js', + createdTimestamp: '1589599492.952', hostingCost: 4201, walletIndex: 36, - bchAddr: "bchtest:qqymyk4zfvnw8rh6hcvl922ewudkyrn9jvk6gtuae6", + bchAddr: 'bchtest:qqymyk4zfvnw8rh6hcvl922ewudkyrn9jvk6gtuae6', __v: 0 } } @@ -69,51 +69,51 @@ mockNewFileModel = { hostingCostBCH: 0.00004197, hostingCostUSD: 0.01, file: { - payloadLink: "", + payloadLink: '', hasBeenPaid: false, - _id: "5ec562319bfacc745e8d8a52", + _id: '5ec562319bfacc745e8d8a52', schemaVersion: 1, size: 4458, - fileName: "ipfs.js", - fileExtension: "js", - createdTimestamp: "1589994033.655", + fileName: 'ipfs.js', + fileExtension: 'js', + createdTimestamp: '1589994033.655', hostingCost: 4196, walletIndex: 49, - bchAddr: "bchtest:qzrpkevu7h2ayfa4rjx08r5elvpfu72dg567x3mh3c", + bchAddr: 'bchtest:qzrpkevu7h2ayfa4rjx08r5elvpfu72dg567x3mh3c', __v: 0 } } const unpaidFileData = { file: { - payloadLink: "", + payloadLink: '', hasBeenPaid: false, - _id: "5ec7392c2acfe57aa62e945a", + _id: '5ec7392c2acfe57aa62e945a', schemaVersion: 1, size: 726, - fileName: "ipfs-e2e.js", - fileExtension: "js", - createdTimestamp: "1590114604.986", + fileName: 'ipfs-e2e.js', + fileExtension: 'js', + createdTimestamp: '1590114604.986', hostingCost: 4403, walletIndex: 56, - bchAddr: "bchtest:qz5z82u0suqh80x5tfx4ht8kdrkkw664vcy44uz0wk", + bchAddr: 'bchtest:qz5z82u0suqh80x5tfx4ht8kdrkkw664vcy44uz0wk', __v: 0 } } const paidFileData = { file: { - payloadLink: "QmRDHPhY5hCNVRMVQvS2H9uty8P1skdwgLaHpUAkEvsjcE", + payloadLink: 'QmRDHPhY5hCNVRMVQvS2H9uty8P1skdwgLaHpUAkEvsjcE', hasBeenPaid: true, - _id: "5ec7392c2acfe57aa62e945a", + _id: '5ec7392c2acfe57aa62e945a', schemaVersion: 1, size: 726, - fileName: "ipfs-e2e.js", - fileExtension: "js", - createdTimestamp: "1590114604.986", + fileName: 'ipfs-e2e.js', + fileExtension: 'js', + createdTimestamp: '1590114604.986', hostingCost: 4403, walletIndex: 56, - bchAddr: "bchtest:qz5z82u0suqh80x5tfx4ht8kdrkkw664vcy44uz0wk", + bchAddr: 'bchtest:qz5z82u0suqh80x5tfx4ht8kdrkkw664vcy44uz0wk', __v: 0 } } diff --git a/test/unit/fixtures/ninsight-mock.js b/test/unit/fixtures/ninsight-mock.js index d261f7e..f455459 100644 --- a/test/unit/fixtures/ninsight-mock.js +++ b/test/unit/fixtures/ninsight-mock.js @@ -5,7 +5,7 @@ const utxo = { utxos: [ { - txid: "2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7", + txid: '2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7', vout: 0, amount: 0.00001, satoshis: 1000, @@ -13,18 +13,18 @@ const utxo = { confirmations: 36459 } ], - legacyAddress: "15NCRBJsHaJy8As5bX1oh2YauRejnZ1MKF", - cashAddress: "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9", - slpAddress: "simpleledger:qqh793x9au6ehvh7r2zflzguanlme760wuwzunhjfm", - scriptPubKey: "76a9142fe2c4c5ef359bb2fe1a849f891cecffbcfb4f7788ac", + legacyAddress: '15NCRBJsHaJy8As5bX1oh2YauRejnZ1MKF', + cashAddress: 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9', + slpAddress: 'simpleledger:qqh793x9au6ehvh7r2zflzguanlme760wuwzunhjfm', + scriptPubKey: '76a9142fe2c4c5ef359bb2fe1a849f891cecffbcfb4f7788ac', asm: - "OP_DUP OP_HASH160 2fe2c4c5ef359bb2fe1a849f891cecffbcfb4f77 OP_EQUALVERIFY OP_CHECKSIG" + 'OP_DUP OP_HASH160 2fe2c4c5ef359bb2fe1a849f891cecffbcfb4f77 OP_EQUALVERIFY OP_CHECKSIG' } const unconfirmed = { utxos: [ { - txid: "3904ffe6f8fba4ceda5e887130f60fcb18bdc7dcee10392a57f89475c5c108f1", + txid: '3904ffe6f8fba4ceda5e887130f60fcb18bdc7dcee10392a57f89475c5c108f1', vout: 0, amount: 0.03608203, satoshis: 3608203, @@ -32,10 +32,10 @@ const unconfirmed = { ts: 1559670801 } ], - legacyAddress: "1AyWs8U4HUnTLmxxFiGoJbsXauRsvBrcKW", - cashAddress: "bitcoincash:qpkkjkhe29mqhqmu3evtq3dsnruuzl3rku6usknlh5", - slpAddress: "simpleledger:qpkkjkhe29mqhqmu3evtq3dsnruuzl3rkuk8mdxlf2", - scriptPubKey: "76a9146d695af951760b837c8e58b045b098f9c17e23b788ac" + legacyAddress: '1AyWs8U4HUnTLmxxFiGoJbsXauRsvBrcKW', + cashAddress: 'bitcoincash:qpkkjkhe29mqhqmu3evtq3dsnruuzl3rku6usknlh5', + slpAddress: 'simpleledger:qpkkjkhe29mqhqmu3evtq3dsnruuzl3rkuk8mdxlf2', + scriptPubKey: '76a9146d695af951760b837c8e58b045b098f9c17e23b788ac' } const utxoPost = [utxo, utxo] @@ -45,40 +45,40 @@ const transactions = { pagesTotal: 1, txs: [ { - txid: "ec7bc8349386e3e1939bbdc4f8092fdbdd6a380734e68486b558cd594c451d5b", + txid: 'ec7bc8349386e3e1939bbdc4f8092fdbdd6a380734e68486b558cd594c451d5b', version: 2, locktime: 0, vin: [ { txid: - "4f1fc57c33659628938db740449bf92fb75799e1d5750a4aeef80eb52d6df1e0", + '4f1fc57c33659628938db740449bf92fb75799e1d5750a4aeef80eb52d6df1e0', vout: 0, sequence: 4294967295, n: 0, scriptSig: { hex: - "483045022100a3662a19ae384a1ceddea57765e425e61b04823e976d574da3911ac6b55d7f9b02200e571d985bce987675a2d58587a346fa40c39f4df13dc88548a92c52d5b24422412103f953f7630acc15bd3f5078c698f3af777286ae955b57e4857c158f75d87adb5f", + '483045022100a3662a19ae384a1ceddea57765e425e61b04823e976d574da3911ac6b55d7f9b02200e571d985bce987675a2d58587a346fa40c39f4df13dc88548a92c52d5b24422412103f953f7630acc15bd3f5078c698f3af777286ae955b57e4857c158f75d87adb5f', asm: - "3045022100a3662a19ae384a1ceddea57765e425e61b04823e976d574da3911ac6b55d7f9b02200e571d985bce987675a2d58587a346fa40c39f4df13dc88548a92c52d5b24422[ALL|FORKID] 03f953f7630acc15bd3f5078c698f3af777286ae955b57e4857c158f75d87adb5f" + '3045022100a3662a19ae384a1ceddea57765e425e61b04823e976d574da3911ac6b55d7f9b02200e571d985bce987675a2d58587a346fa40c39f4df13dc88548a92c52d5b24422[ALL|FORKID] 03f953f7630acc15bd3f5078c698f3af777286ae955b57e4857c158f75d87adb5f' }, - addr: "17HPz8RQ4XM6mjre6aspvqyj1j648CZidM", + addr: '17HPz8RQ4XM6mjre6aspvqyj1j648CZidM', valueSat: 1111, value: 0.00001111, doubleSpentTxID: null }, { txid: - "126d62c299e7e14c66fe0b485d13082c23641f003690462046bc24ad2d1180c1", + '126d62c299e7e14c66fe0b485d13082c23641f003690462046bc24ad2d1180c1', vout: 0, sequence: 4294967295, n: 1, scriptSig: { hex: - "47304402203e3f923207111ff9bbd2fb5ab1a49a9145ad809ee0cad0e0ddaed64bfe38dc16022012ee288fb413bd500c63f8bb95e46b6b57d34762decd46b7188478a1c398eeda412103f953f7630acc15bd3f5078c698f3af777286ae955b57e4857c158f75d87adb5f", + '47304402203e3f923207111ff9bbd2fb5ab1a49a9145ad809ee0cad0e0ddaed64bfe38dc16022012ee288fb413bd500c63f8bb95e46b6b57d34762decd46b7188478a1c398eeda412103f953f7630acc15bd3f5078c698f3af777286ae955b57e4857c158f75d87adb5f', asm: - "304402203e3f923207111ff9bbd2fb5ab1a49a9145ad809ee0cad0e0ddaed64bfe38dc16022012ee288fb413bd500c63f8bb95e46b6b57d34762decd46b7188478a1c398eeda[ALL|FORKID] 03f953f7630acc15bd3f5078c698f3af777286ae955b57e4857c158f75d87adb5f" + '304402203e3f923207111ff9bbd2fb5ab1a49a9145ad809ee0cad0e0ddaed64bfe38dc16022012ee288fb413bd500c63f8bb95e46b6b57d34762decd46b7188478a1c398eeda[ALL|FORKID] 03f953f7630acc15bd3f5078c698f3af777286ae955b57e4857c158f75d87adb5f' }, - addr: "17HPz8RQ4XM6mjre6aspvqyj1j648CZidM", + addr: '17HPz8RQ4XM6mjre6aspvqyj1j648CZidM', valueSat: 1000, value: 0.00001, doubleSpentTxID: null @@ -86,14 +86,14 @@ const transactions = { ], vout: [ { - value: "0.00001736", + value: '0.00001736', n: 0, scriptPubKey: { - hex: "76a914d96ac75ca8df9729d278da50ccd7355c5785444e88ac", + hex: '76a914d96ac75ca8df9729d278da50ccd7355c5785444e88ac', asm: - "OP_DUP OP_HASH160 d96ac75ca8df9729d278da50ccd7355c5785444e OP_EQUALVERIFY OP_CHECKSIG", - addresses: ["1LpbYkEM5cryfhs58tH8c93p4SGzit7UrP"], - type: "pubkeyhash" + 'OP_DUP OP_HASH160 d96ac75ca8df9729d278da50ccd7355c5785444e OP_EQUALVERIFY OP_CHECKSIG', + addresses: ['1LpbYkEM5cryfhs58tH8c93p4SGzit7UrP'], + type: 'pubkeyhash' }, spentTxId: null, spentIndex: null, @@ -109,36 +109,36 @@ const transactions = { fees: 0.00000375 } ], - legacyAddress: "1LpbYkEM5cryfhs58tH8c93p4SGzit7UrP", - cashAddress: "bitcoincash:qrvk436u4r0ew2wj0rd9pnxhx4w90p2yfc29ta0d2n", + legacyAddress: '1LpbYkEM5cryfhs58tH8c93p4SGzit7UrP', + cashAddress: 'bitcoincash:qrvk436u4r0ew2wj0rd9pnxhx4w90p2yfc29ta0d2n', currentPage: 0 } const transactionsPost = [transactions, transactions] const details = { - txid: "fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33", + txid: 'fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33', version: 1, locktime: 0, vin: [ { - coinbase: "04ffff001d02fd04", + coinbase: '04ffff001d02fd04', sequence: 4294967295, n: 0 } ], vout: [ { - value: "50.00000000", + value: '50.00000000', n: 0, scriptPubKey: { hex: - "4104f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446aac", + '4104f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446aac', asm: - "04f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446a OP_CHECKSIG", - addresses: ["1BW18n7MfpU35q4MTBSk8pse3XzQF8XvzT"], - type: "pubkeyhash", - cashAddrs: ["bitcoincash:qpej6mkrwca4tvy2snq4crhrf88v4ljspysx0ueetk"] + '04f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446a OP_CHECKSIG', + addresses: ['1BW18n7MfpU35q4MTBSk8pse3XzQF8XvzT'], + type: 'pubkeyhash', + cashAddrs: ['bitcoincash:qpej6mkrwca4tvy2snq4crhrf88v4ljspysx0ueetk'] }, spentTxId: null, spentIndex: null, @@ -146,7 +146,7 @@ const details = { } ], blockhash: - "00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09", + '00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09', blockheight: 1000, confirmations: 585610, time: 1232346882, diff --git a/test/unit/fixtures/openbazaar-mock.js b/test/unit/fixtures/openbazaar-mock.js index fad84ce..099f8fb 100644 --- a/test/unit/fixtures/openbazaar-mock.js +++ b/test/unit/fixtures/openbazaar-mock.js @@ -6,23 +6,23 @@ const balance = { page: 1, totalPages: 1, itemsOnPage: 1000, - addrStr: "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9", - balance: "0.00001", - totalReceived: "0.00001", - totalSent: "0", - unconfirmedBalance: "0", + addrStr: 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9', + balance: '0.00001', + totalReceived: '0.00001', + totalSent: '0', + unconfirmedBalance: '0', unconfirmedTxApperances: 0, txApperances: 1, transactions: [ - "2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7" + '2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7' ] } const utxo = [ { - txid: "2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7", + txid: '2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7', vout: 0, - amount: "0.00001", + amount: '0.00001', satoshis: 1000, height: 602405, confirmations: 11 @@ -30,51 +30,51 @@ const utxo = [ ] const tx = { - txid: "2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7", + txid: '2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7', version: 2, vin: [ { - txid: "5f09d317e24c5d376f737a2711f3bd1d381abdb41743fff3819b4f76382e1eac", + txid: '5f09d317e24c5d376f737a2711f3bd1d381abdb41743fff3819b4f76382e1eac', vout: 1, sequence: 4294967295, n: 0, scriptSig: { hex: - "473044022000dd11c41a472f2e54348db996e60864d489429f12d1e044d49ff600b880c9590220715a926404bb0e2731a3795afb341ec1dad3f84ead7d27cd31fcc59abb14738c4121038476128287ac37c7a3cf7e8625fd5f024db1bc3d8e37395abe7bf42fda78d0d9" + '473044022000dd11c41a472f2e54348db996e60864d489429f12d1e044d49ff600b880c9590220715a926404bb0e2731a3795afb341ec1dad3f84ead7d27cd31fcc59abb14738c4121038476128287ac37c7a3cf7e8625fd5f024db1bc3d8e37395abe7bf42fda78d0d9' }, - addresses: ["bitcoincash:qqxy8hycqe89j7wa79gnggq6z3gaqu2uvqy26xehfe"], - value: "0.00047504" + addresses: ['bitcoincash:qqxy8hycqe89j7wa79gnggq6z3gaqu2uvqy26xehfe'], + value: '0.00047504' } ], vout: [ { - value: "0.00001", + value: '0.00001', n: 0, scriptPubKey: { - hex: "76a9142fe2c4c5ef359bb2fe1a849f891cecffbcfb4f7788ac", - addresses: ["bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9"] + hex: '76a9142fe2c4c5ef359bb2fe1a849f891cecffbcfb4f7788ac', + addresses: ['bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9'] }, spent: false }, { - value: "0.00046256", + value: '0.00046256', n: 1, scriptPubKey: { - hex: "76a9142dbf5e1804c39a497b908c876097d63210c8490288ac", - addresses: ["bitcoincash:qqkm7hscqnpe5jtmjzxgwcyh6ceppjzfqg3jdn422e"] + hex: '76a9142dbf5e1804c39a497b908c876097d63210c8490288ac', + addresses: ['bitcoincash:qqkm7hscqnpe5jtmjzxgwcyh6ceppjzfqg3jdn422e'] }, spent: false } ], - blockhash: "0000000000000000010903a1fc4274499037c9339be9ec7338ee980331c20ce5", + blockhash: '0000000000000000010903a1fc4274499037c9339be9ec7338ee980331c20ce5', blockheight: 602405, confirmations: 11, blocktime: 1569792892, - valueOut: "0.00047256", - valueIn: "0.00047504", - fees: "0.00000248", + valueOut: '0.00047256', + valueIn: '0.00047504', + fees: '0.00000248', hex: - "0200000001ac1e2e38764f9b81f3ff4317b4bd1a381dbdf311277a736f375d4ce217d3095f010000006a473044022000dd11c41a472f2e54348db996e60864d489429f12d1e044d49ff600b880c9590220715a926404bb0e2731a3795afb341ec1dad3f84ead7d27cd31fcc59abb14738c4121038476128287ac37c7a3cf7e8625fd5f024db1bc3d8e37395abe7bf42fda78d0d9ffffffff02e8030000000000001976a9142fe2c4c5ef359bb2fe1a849f891cecffbcfb4f7788acb0b40000000000001976a9142dbf5e1804c39a497b908c876097d63210c8490288ac00000000" + '0200000001ac1e2e38764f9b81f3ff4317b4bd1a381dbdf311277a736f375d4ce217d3095f010000006a473044022000dd11c41a472f2e54348db996e60864d489429f12d1e044d49ff600b880c9590220715a926404bb0e2731a3795afb341ec1dad3f84ead7d27cd31fcc59abb14738c4121038476128287ac37c7a3cf7e8625fd5f024db1bc3d8e37395abe7bf42fda78d0d9ffffffff02e8030000000000001976a9142fe2c4c5ef359bb2fe1a849f891cecffbcfb4f7788acb0b40000000000001976a9142dbf5e1804c39a497b908c876097d63210c8490288ac00000000' } module.exports = { diff --git a/test/unit/fixtures/price-mocks.js b/test/unit/fixtures/price-mocks.js index ade76b4..c8168ec 100644 --- a/test/unit/fixtures/price-mocks.js +++ b/test/unit/fixtures/price-mocks.js @@ -3,210 +3,210 @@ */ const mockRates = { - AED: "915.049218", - AFN: "19144.48874646", - ALGO: "826.6633482661356600405", - ALL: "26221.96098759", - AMD: "119977.82663822", - ANG: "446.841810455", - AOA: "162269.774275", - ARS: "19322.704621", - ATOM: "45.5920571010248851205", - AUD: "353.78913716", - AWG: "448.407", - AZN: "424.1182875", - BAL: "18.9361216125975755781", - BAM: "413.75759465", - BAND: "40.84187228461349099275", - BAT: "1169.75444148879972951", - BBD: "498.23", - BCH: "1.0", - BDT: "21107.92000745", - BGN: "413.93197515", - BHD: "93.93578597", - BIF: "481540.76228735", - BMD: "249.115", - BND: "337.84677362", - BOB: "1718.851399565", - BRL: "1396.737982", - BSD: "249.115", - BSV: "1.555324933590611026515", - BTC: "0.021265", - BTN: "18249.513962505", - BWP: "2848.17713393", - BYN: "637.963336685", - BYR: "6379633.36685000049823", - BZD: "501.752236985", - CAD: "328.80838319", - CDF: "488848.679106575", - CGLD: "121.0412516398620018305", - CHF: "226.8989243", - CLF: "7.110489445", - CLP: "196202.978234955", - CNH: "1664.25510705", - CNY: "1666.429881", - COMP: "2.4706436576415750709", - COP: "958730.858397465", - CRC: "150173.845981", - CUC: "248.997666835", - CVE: "23541.3675", - CZK: "5770.848621", - DAI: "247.0463573269230002455", - DASH: "3.327367317363110236645", - DJF: "44315.31795969", - DKK: "1575.7370741", - DOP: "14529.76988648", - DZD: "32107.28592277", - EEK: "3640.489633465", - EGP: "3911.404438", - EOS: "96.6873665825732601419", - ERN: "3736.727740265", - ETB: "9302.454572035", - ETC: "44.91795888928957612395", - ETH: "0.6574429621419051422355", - EUR: "211.595", - FJD: "533.11855575", - FKP: "192.55642863", - GBP: "192.87", - GEL: "804.64145", - GGP: "192.55642863", - GHS: "1448.776859925", - GIP: "192.55642863", - GMD: "12891.70125", - GNF: "2438630.43574976", - GTQ: "1936.689014855", - GYD: "52047.88891278", - HKD: "1930.67861725", - HNL: "6126.43736492", - HRK: "1605.40119007", - HTG: "15682.48428085", - HUF: "77261.419177275", - IDR: "3666848.2425", - ILS: "843.29662455", - IMP: "192.55642863", - INR: "18275.43761675", - IQD: "297176.65680577", - ISK: "34639.44075", - JEP: "192.55642863", - JMD: "36261.061070375", - JOD: "176.622535", - JPY: "26304.9247525", - KES: "27093.7474", - KGS: "20240.23303148", - KHR: "1021526.66327067", - KMF: "104678.164103975", - KNC: "275.5392102643512742545", - KRW: "284115.6575", - KWD: "76.196555935", - KYD: "207.44852333", - KZT: "106578.169689505", - LAK: "2300372.70137523", - LBP: "376426.60931701", - LINK: "22.8704181013371177476", - LKR: "45903.840861165", - LRC: "1428.4116972477063306", - LRD: "48689.521020355", - LSL: "4093.68786226", - LTC: "5.182877353583689269445", - LTL: "803.357262175", - LVL: "163.484459015", - LYD: "340.470203685", - MAD: "2290.86403115", - MDL: "4231.74490411", - MGA: "978918.42727237", - MKD: "13034.71219274", - MKR: "0.43727565410331105846", - MMK: "321367.16219401", - MNT: "706980.17312004", - MOP: "1987.157222705", - MRO: "88934.055", - MTL: "170.32939187", - MUR: "9942.18014823", - MVR: "3836.371", - MWK: "187533.350248305", - MXN: "5285.574344805", - MYR: "1033.2044625", - MZN: "18168.45667469", - NAD: "4120.3621", - NGN: "95465.8503", - NIO: "8675.07065117", - NMR: "8.6886689628111785348", - NOK: "2328.95371465", - NPR: "29198.52701022", - NZD: "378.934057915", - OMG: "74.27621574882972595255", - OMR: "95.913509955", - OXT: "1023.479868529169993565", - PAB: "249.115", - PEN: "892.41413087", - PGK: "870.976539545", - PHP: "12100.979598855", - PKR: "40413.26181118", - PLN: "968.71705891", - PYG: "1750259.579863715", - QAR: "907.08999375", - REN: "758.802924154736515935", - REP: "18.2168190127970744169", - REPV2: "18.225711080673967324", - RON: "1032.33256", - RSD: "24895.307525", - RUB: "19351.4774035", - RWF: "243426.179717085", - SAR: "934.309544225", - SBD: "2013.0584566", - SCR: "4561.388071665", - SEK: "2201.10291435", - SGD: "338.356712025", - SHP: "192.55642863", - SLL: "2482430.971263275", - SOS: "144000.839307095", - SRD: "3525.97371", - SSP: "32449.7199", - STD: "5232524.31108792", - SVC: "2178.147216215", - SZL: "4091.741526765", - THB: "7785.4665375", - TJS: "2568.96954016", - TMT: "871.9025", - TND: "686.00043125", - TOP: "578.0165522", - TRY: "1963.587954325", - TTD: "1689.460313635", - TWD: "7158.9423125", - TZS: "577510.41827928", - UAH: "7061.44019619", - UGX: "931508.2111739", - UMA: "30.09543944427665349095", - UNI: "79.18593747516647884725", - USD: "249.115", - USDC: "249.115", - UYU: "10688.478117885", - UZS: "2582693.606121005", - VEF: "61901998.996866715", - VES: "112695476.713406465", - VND: "5773814.12282902", - VUV: "28486.73470656", - WST: "653.35042289", - XAF: "138884.3079243", - XAG: "10.22661168355", - XAU: "0.1312935696", - XCD: "673.24574325", - XDR: "176.50246157", - XLM: "2936.20532162536435083", - XOF: "138884.3079243", - XPD: "0.1061030608", - XPF: "25265.84267069", - XPT: "0.2910211253", - XRP: "1014.931757995518373565", - XTZ: "113.8135051169590628124", - YER: "62365.930534515", - YFI: "0.0178703370267443543872", - ZAR: "4122.31765275", - ZEC: "3.87305659203980154283", - ZMK: "1308619.842149325", - ZMW: "5027.95231667", - ZRX: "644.844402797695193656", - ZWL: "80215.03" + AED: '915.049218', + AFN: '19144.48874646', + ALGO: '826.6633482661356600405', + ALL: '26221.96098759', + AMD: '119977.82663822', + ANG: '446.841810455', + AOA: '162269.774275', + ARS: '19322.704621', + ATOM: '45.5920571010248851205', + AUD: '353.78913716', + AWG: '448.407', + AZN: '424.1182875', + BAL: '18.9361216125975755781', + BAM: '413.75759465', + BAND: '40.84187228461349099275', + BAT: '1169.75444148879972951', + BBD: '498.23', + BCH: '1.0', + BDT: '21107.92000745', + BGN: '413.93197515', + BHD: '93.93578597', + BIF: '481540.76228735', + BMD: '249.115', + BND: '337.84677362', + BOB: '1718.851399565', + BRL: '1396.737982', + BSD: '249.115', + BSV: '1.555324933590611026515', + BTC: '0.021265', + BTN: '18249.513962505', + BWP: '2848.17713393', + BYN: '637.963336685', + BYR: '6379633.36685000049823', + BZD: '501.752236985', + CAD: '328.80838319', + CDF: '488848.679106575', + CGLD: '121.0412516398620018305', + CHF: '226.8989243', + CLF: '7.110489445', + CLP: '196202.978234955', + CNH: '1664.25510705', + CNY: '1666.429881', + COMP: '2.4706436576415750709', + COP: '958730.858397465', + CRC: '150173.845981', + CUC: '248.997666835', + CVE: '23541.3675', + CZK: '5770.848621', + DAI: '247.0463573269230002455', + DASH: '3.327367317363110236645', + DJF: '44315.31795969', + DKK: '1575.7370741', + DOP: '14529.76988648', + DZD: '32107.28592277', + EEK: '3640.489633465', + EGP: '3911.404438', + EOS: '96.6873665825732601419', + ERN: '3736.727740265', + ETB: '9302.454572035', + ETC: '44.91795888928957612395', + ETH: '0.6574429621419051422355', + EUR: '211.595', + FJD: '533.11855575', + FKP: '192.55642863', + GBP: '192.87', + GEL: '804.64145', + GGP: '192.55642863', + GHS: '1448.776859925', + GIP: '192.55642863', + GMD: '12891.70125', + GNF: '2438630.43574976', + GTQ: '1936.689014855', + GYD: '52047.88891278', + HKD: '1930.67861725', + HNL: '6126.43736492', + HRK: '1605.40119007', + HTG: '15682.48428085', + HUF: '77261.419177275', + IDR: '3666848.2425', + ILS: '843.29662455', + IMP: '192.55642863', + INR: '18275.43761675', + IQD: '297176.65680577', + ISK: '34639.44075', + JEP: '192.55642863', + JMD: '36261.061070375', + JOD: '176.622535', + JPY: '26304.9247525', + KES: '27093.7474', + KGS: '20240.23303148', + KHR: '1021526.66327067', + KMF: '104678.164103975', + KNC: '275.5392102643512742545', + KRW: '284115.6575', + KWD: '76.196555935', + KYD: '207.44852333', + KZT: '106578.169689505', + LAK: '2300372.70137523', + LBP: '376426.60931701', + LINK: '22.8704181013371177476', + LKR: '45903.840861165', + LRC: '1428.4116972477063306', + LRD: '48689.521020355', + LSL: '4093.68786226', + LTC: '5.182877353583689269445', + LTL: '803.357262175', + LVL: '163.484459015', + LYD: '340.470203685', + MAD: '2290.86403115', + MDL: '4231.74490411', + MGA: '978918.42727237', + MKD: '13034.71219274', + MKR: '0.43727565410331105846', + MMK: '321367.16219401', + MNT: '706980.17312004', + MOP: '1987.157222705', + MRO: '88934.055', + MTL: '170.32939187', + MUR: '9942.18014823', + MVR: '3836.371', + MWK: '187533.350248305', + MXN: '5285.574344805', + MYR: '1033.2044625', + MZN: '18168.45667469', + NAD: '4120.3621', + NGN: '95465.8503', + NIO: '8675.07065117', + NMR: '8.6886689628111785348', + NOK: '2328.95371465', + NPR: '29198.52701022', + NZD: '378.934057915', + OMG: '74.27621574882972595255', + OMR: '95.913509955', + OXT: '1023.479868529169993565', + PAB: '249.115', + PEN: '892.41413087', + PGK: '870.976539545', + PHP: '12100.979598855', + PKR: '40413.26181118', + PLN: '968.71705891', + PYG: '1750259.579863715', + QAR: '907.08999375', + REN: '758.802924154736515935', + REP: '18.2168190127970744169', + REPV2: '18.225711080673967324', + RON: '1032.33256', + RSD: '24895.307525', + RUB: '19351.4774035', + RWF: '243426.179717085', + SAR: '934.309544225', + SBD: '2013.0584566', + SCR: '4561.388071665', + SEK: '2201.10291435', + SGD: '338.356712025', + SHP: '192.55642863', + SLL: '2482430.971263275', + SOS: '144000.839307095', + SRD: '3525.97371', + SSP: '32449.7199', + STD: '5232524.31108792', + SVC: '2178.147216215', + SZL: '4091.741526765', + THB: '7785.4665375', + TJS: '2568.96954016', + TMT: '871.9025', + TND: '686.00043125', + TOP: '578.0165522', + TRY: '1963.587954325', + TTD: '1689.460313635', + TWD: '7158.9423125', + TZS: '577510.41827928', + UAH: '7061.44019619', + UGX: '931508.2111739', + UMA: '30.09543944427665349095', + UNI: '79.18593747516647884725', + USD: '249.115', + USDC: '249.115', + UYU: '10688.478117885', + UZS: '2582693.606121005', + VEF: '61901998.996866715', + VES: '112695476.713406465', + VND: '5773814.12282902', + VUV: '28486.73470656', + WST: '653.35042289', + XAF: '138884.3079243', + XAG: '10.22661168355', + XAU: '0.1312935696', + XCD: '673.24574325', + XDR: '176.50246157', + XLM: '2936.20532162536435083', + XOF: '138884.3079243', + XPD: '0.1061030608', + XPF: '25265.84267069', + XPT: '0.2910211253', + XRP: '1014.931757995518373565', + XTZ: '113.8135051169590628124', + YER: '62365.930534515', + YFI: '0.0178703370267443543872', + ZAR: '4122.31765275', + ZEC: '3.87305659203980154283', + ZMK: '1308619.842149325', + ZMW: '5027.95231667', + ZRX: '644.844402797695193656', + ZWL: '80215.03' } module.exports = { diff --git a/test/unit/fixtures/slp/mock-utils.js b/test/unit/fixtures/slp/mock-utils.js index 70cb550..928e09a 100644 --- a/test/unit/fixtures/slp/mock-utils.js +++ b/test/unit/fixtures/slp/mock-utils.js @@ -5,14 +5,14 @@ const mockList = [ { decimals: 0, - timestamp: "2019-04-29 08:59", + timestamp: '2019-04-29 08:59', timestampUnix: 1539218362, versionType: 1, - documentUri: "", - symbol: "WMW", - name: "WheresMyWallet", + documentUri: '', + symbol: 'WMW', + name: 'WheresMyWallet', containsBaton: false, - id: "8fc284dcbc922f7bb7e2a443dc3af792f52923bba403fcf67ca028c88e89da0e", + id: '8fc284dcbc922f7bb7e2a443dc3af792f52923bba403fcf67ca028c88e89da0e', documentHash: null, initialTokenQty: 1000, blockCreated: 580336, @@ -23,18 +23,18 @@ const mockList = [ totalMinted: 1000, totalBurned: 0, circulatingSupply: 1000, - mintingBatonStatus: "NEVER_CREATED" + mintingBatonStatus: 'NEVER_CREATED' }, { decimals: 0, - timestamp: "2019-04-29 08:59", + timestamp: '2019-04-29 08:59', timestampUnix: 1539218362, versionType: 1, - documentUri: "", - symbol: "WMW", + documentUri: '', + symbol: 'WMW', name: "Where'sMyWallet", containsBaton: false, - id: "471d1f33e8a69cf59ce174ce43174feeecdf1f475ccc4cc3705600a5d6d2cd06", + id: '471d1f33e8a69cf59ce174ce43174feeecdf1f475ccc4cc3705600a5d6d2cd06', documentHash: null, initialTokenQty: 1000, blockCreated: 580336, @@ -45,20 +45,20 @@ const mockList = [ totalMinted: 1000, totalBurned: 0, circulatingSupply: 1000, - mintingBatonStatus: "NEVER_CREATED" + mintingBatonStatus: 'NEVER_CREATED' } ] const mockToken = { decimals: 0, - timestamp: "2018-08-25 01:54", + timestamp: '2018-08-25 01:54', timestampUnix: 1539218362, versionType: 1, - documentUri: "", - symbol: "USDT", - name: "US Dollar Tether", + documentUri: '', + symbol: 'USDT', + name: 'US Dollar Tether', containsBaton: false, - id: "4276533bb702e7f8c9afd8aa61ebf016e95011dc3d54e55faa847ac1dd461e84", + id: '4276533bb702e7f8c9afd8aa61ebf016e95011dc3d54e55faa847ac1dd461e84', documentHash: null, initialTokenQty: 10000000000000000, blockCreated: 544903, @@ -69,20 +69,20 @@ const mockToken = { totalMinted: 10000000000000000, totalBurned: 10000000000000000, circulatingSupply: 0, - mintingBatonStatus: "NEVER_CREATED" + mintingBatonStatus: 'NEVER_CREATED' } const mockTokens = [ { decimals: 0, - timestamp: "2018-08-25 01:54", + timestamp: '2018-08-25 01:54', timestampUnix: 1539218362, versionType: 1, - documentUri: "", - symbol: "USDT", - name: "US Dollar Tether", + documentUri: '', + symbol: 'USDT', + name: 'US Dollar Tether', containsBaton: false, - id: "4276533bb702e7f8c9afd8aa61ebf016e95011dc3d54e55faa847ac1dd461e84", + id: '4276533bb702e7f8c9afd8aa61ebf016e95011dc3d54e55faa847ac1dd461e84', documentHash: null, initialTokenQty: 10000000000000000, blockCreated: 544903, @@ -93,18 +93,18 @@ const mockTokens = [ totalMinted: 10000000000000000, totalBurned: 10000000000000000, circulatingSupply: 0, - mintingBatonStatus: "NEVER_CREATED" + mintingBatonStatus: 'NEVER_CREATED' }, { decimals: 0, - timestamp: "2019-04-29 08:59", + timestamp: '2019-04-29 08:59', timestampUnix: 1539218362, versionType: 1, - documentUri: "", - symbol: "WMW", + documentUri: '', + symbol: 'WMW', name: "Where'sMyWallet", containsBaton: false, - id: "471d1f33e8a69cf59ce174ce43174feeecdf1f475ccc4cc3705600a5d6d2cd06", + id: '471d1f33e8a69cf59ce174ce43174feeecdf1f475ccc4cc3705600a5d6d2cd06', documentHash: null, initialTokenQty: 1000, blockCreated: 580336, @@ -115,21 +115,21 @@ const mockTokens = [ totalMinted: 1000, totalBurned: 0, circulatingSupply: 1000, - mintingBatonStatus: "NEVER_CREATED" + mintingBatonStatus: 'NEVER_CREATED' } ] const balancesForAddress = [ { - tokenId: "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb", - balance: "1", - balanceString: "1", - slpAddress: "simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9", + tokenId: 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb', + balance: '1', + balanceString: '1', + slpAddress: 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9', decimalCount: 8 }, { - tokenId: "a436c8e1b6bee3d701c6044d190f76f774be83c36de8d34a988af4489e86dd37", - balance: "1", + tokenId: 'a436c8e1b6bee3d701c6044d190f76f774be83c36de8d34a988af4489e86dd37', + balance: '1', decimalCount: 7 } ] @@ -138,46 +138,46 @@ const balancesForAddresses = [ [ { tokenId: - "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb", + 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb', balance: 1, - balanceString: "1", - slpAddress: "simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9", + balanceString: '1', + slpAddress: 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9', decimalCount: 8 }, { tokenId: - "a436c8e1b6bee3d701c6044d190f76f774be83c36de8d34a988af4489e86dd37", + 'a436c8e1b6bee3d701c6044d190f76f774be83c36de8d34a988af4489e86dd37', balance: 1, - balanceString: "1", - slpAddress: "simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9", + balanceString: '1', + slpAddress: 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9', decimalCount: 7 } ], [ { tokenId: - "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7", + '497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7', balance: 10, - balanceString: "10", - slpAddress: "simpleledger:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5ucdyl3r57", + balanceString: '10', + slpAddress: 'simpleledger:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5ucdyl3r57', decimalCount: 8 } ] ] const mockBalance = { - tokenId: "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb", + tokenId: 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb', balance: 1, - balanceString: "1" + balanceString: '1' } const mockRawTx = [ - "0100000002b3b54b72de3cdff8d00a5a26e2aa7897f730c2889c46b41a83294004a2c6c9c6020000006a47304402202fff3979f9cf0a5052655c8699081a77a653903de41547928db0b94601aa082502207cdb909e3a7b2b7f8a3eb80243a1bd2fd8ad9449a0ec30242ae4b187436d11a0412103b30e7096c6e3a3b45e5aba4ad8fe48a1fdd7c04de0de55a43095e7560b52e19dfeffffffd25817de09517a6af6c3dbb332041f85d844052b32ea1dbca123365b18953726000000006a473044022011a39acbbb80c4723822d434445fc4b3d72ad0212902fdb183a5408af00e158c02200eb3778b1af9f3a8fe28b6670f5fe543fb4c190f79f349273860125be05269b2412103b30e7096c6e3a3b45e5aba4ad8fe48a1fdd7c04de0de55a43095e7560b52e19dfeffffff030000000000000000336a04534c500001010747454e45534953084e414b414d4f544f084e414b414d4f544f4c004c0001084c0008000775f05a07400022020000000000001976a91433c0448680ca324225eeca7a230cf191ab88400288ac8afc0000000000001976a91433c0448680ca324225eeca7a230cf191ab88400288ac967a0800" + '0100000002b3b54b72de3cdff8d00a5a26e2aa7897f730c2889c46b41a83294004a2c6c9c6020000006a47304402202fff3979f9cf0a5052655c8699081a77a653903de41547928db0b94601aa082502207cdb909e3a7b2b7f8a3eb80243a1bd2fd8ad9449a0ec30242ae4b187436d11a0412103b30e7096c6e3a3b45e5aba4ad8fe48a1fdd7c04de0de55a43095e7560b52e19dfeffffffd25817de09517a6af6c3dbb332041f85d844052b32ea1dbca123365b18953726000000006a473044022011a39acbbb80c4723822d434445fc4b3d72ad0212902fdb183a5408af00e158c02200eb3778b1af9f3a8fe28b6670f5fe543fb4c190f79f349273860125be05269b2412103b30e7096c6e3a3b45e5aba4ad8fe48a1fdd7c04de0de55a43095e7560b52e19dfeffffff030000000000000000336a04534c500001010747454e45534953084e414b414d4f544f084e414b414d4f544f4c004c0001084c0008000775f05a07400022020000000000001976a91433c0448680ca324225eeca7a230cf191ab88400288ac8afc0000000000001976a91433c0448680ca324225eeca7a230cf191ab88400288ac967a0800' ] const mockIsValidTxid = [ { - txid: "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb", + txid: 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb', valid: true } ] @@ -185,15 +185,15 @@ const mockIsValidTxid = [ const mockBalancesForToken = [ { tokenBalance: 1000, - slpAddress: "simpleledger:qzhfd7ssy9nt4gw7j9w5e7w5mxx5w549rv7mknzqkz" + slpAddress: 'simpleledger:qzhfd7ssy9nt4gw7j9w5e7w5mxx5w549rv7mknzqkz' } ] const mockTokenStats = { - tokenId: "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb", - documentUri: "", - symbol: "NAKAMOTO", - name: "NAKAMOTO", + tokenId: 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb', + documentUri: '', + symbol: 'NAKAMOTO', + name: 'NAKAMOTO', decimals: 8, txnsSinceGenesis: 367, validUtxos: 248, @@ -206,15 +206,15 @@ const mockTokenStats = { const mockTransactions = [ { - txid: "27e27170b546f05b2af69d6eddff8834038facf5d81302e9e562df09a5c4445f", + txid: '27e27170b546f05b2af69d6eddff8834038facf5d81302e9e562df09a5c4445f', tokenDetails: { valid: true, detail: { decimals: null, tokenIdHex: - "495322b37d6b2eae81f045eda612b95870a0c2b6069c58f70cf8ef4e6a9fd43a", + '495322b37d6b2eae81f045eda612b95870a0c2b6069c58f70cf8ef4e6a9fd43a', timestamp: null, - transactionType: "SEND", + transactionType: 'SEND', versionType: 1, documentUri: null, documentSha256Hex: null, @@ -225,13 +225,13 @@ const mockTransactions = [ genesisOrMintQuantity: null, sendOutputs: [ { - $numberDecimal: "0" + $numberDecimal: '0' }, { - $numberDecimal: "25" + $numberDecimal: '25' }, { - $numberDecimal: "77" + $numberDecimal: '77' } ] }, @@ -243,60 +243,60 @@ const mockTransactions = [ const mockBurnTotal = { transactionId: - "c7078a6c7400518a513a0bde1f4158cf740d08d3b5bfb19aa7b6657e2f4160de", + 'c7078a6c7400518a513a0bde1f4158cf740d08d3b5bfb19aa7b6657e2f4160de', inputTotal: 100000000, outputTotal: 100000000, burnTotal: 0 } const nonSLPTxDetailsWithoutOpReturn = { - txid: "3793d4906654f648e659f384c0f40b19c8f10c1e9fb72232a9b8edd61abaa1ec", - hash: "3793d4906654f648e659f384c0f40b19c8f10c1e9fb72232a9b8edd61abaa1ec", + txid: '3793d4906654f648e659f384c0f40b19c8f10c1e9fb72232a9b8edd61abaa1ec', + hash: '3793d4906654f648e659f384c0f40b19c8f10c1e9fb72232a9b8edd61abaa1ec', version: 1, size: 704, locktime: 0, vin: [ { - txid: "15a34ece03e13c20ee41dd113a982964a92dafb49328a6c395c8ecec12901bd5", + txid: '15a34ece03e13c20ee41dd113a982964a92dafb49328a6c395c8ecec12901bd5', vout: 0, scriptSig: { asm: - "3045022100f020493f2c62740c89f07fba92d2916ad238c6965ef69fdf8338b4d6ee6c5a4502200251693e9883868cc5fb227bfc9bdaa5c333f14f712c0f3d8d2efb781f1a15fa[ALL|FORKID] 02a8087ad440c428aede8cf39eabe12b9807356b04d48aa0c361fa0d9d68a1aeac", + '3045022100f020493f2c62740c89f07fba92d2916ad238c6965ef69fdf8338b4d6ee6c5a4502200251693e9883868cc5fb227bfc9bdaa5c333f14f712c0f3d8d2efb781f1a15fa[ALL|FORKID] 02a8087ad440c428aede8cf39eabe12b9807356b04d48aa0c361fa0d9d68a1aeac', hex: - "483045022100f020493f2c62740c89f07fba92d2916ad238c6965ef69fdf8338b4d6ee6c5a4502200251693e9883868cc5fb227bfc9bdaa5c333f14f712c0f3d8d2efb781f1a15fa412102a8087ad440c428aede8cf39eabe12b9807356b04d48aa0c361fa0d9d68a1aeac" + '483045022100f020493f2c62740c89f07fba92d2916ad238c6965ef69fdf8338b4d6ee6c5a4502200251693e9883868cc5fb227bfc9bdaa5c333f14f712c0f3d8d2efb781f1a15fa412102a8087ad440c428aede8cf39eabe12b9807356b04d48aa0c361fa0d9d68a1aeac' }, sequence: 4294967295 }, { - txid: "52f720a5c6b5ad2765ecabc51b375d4aa741339f2a6fbd1524dcb3d45e230337", + txid: '52f720a5c6b5ad2765ecabc51b375d4aa741339f2a6fbd1524dcb3d45e230337', vout: 0, scriptSig: { asm: - "3045022100b3e65b51cd31c081070ebf5c91e43d10431a71e748c86ff6bcc7e4f5ecc7f54d02202d67edefe3a065cbda2e1782dd77bce2d891de2a428f5dd92eae15e4a843527c[ALL|FORKID] 03d0ea0c7798905c7f8dee6180321c92bf67df9dfde42da0f3cf25413d914c0e29", + '3045022100b3e65b51cd31c081070ebf5c91e43d10431a71e748c86ff6bcc7e4f5ecc7f54d02202d67edefe3a065cbda2e1782dd77bce2d891de2a428f5dd92eae15e4a843527c[ALL|FORKID] 03d0ea0c7798905c7f8dee6180321c92bf67df9dfde42da0f3cf25413d914c0e29', hex: - "483045022100b3e65b51cd31c081070ebf5c91e43d10431a71e748c86ff6bcc7e4f5ecc7f54d02202d67edefe3a065cbda2e1782dd77bce2d891de2a428f5dd92eae15e4a843527c412103d0ea0c7798905c7f8dee6180321c92bf67df9dfde42da0f3cf25413d914c0e29" + '483045022100b3e65b51cd31c081070ebf5c91e43d10431a71e748c86ff6bcc7e4f5ecc7f54d02202d67edefe3a065cbda2e1782dd77bce2d891de2a428f5dd92eae15e4a843527c412103d0ea0c7798905c7f8dee6180321c92bf67df9dfde42da0f3cf25413d914c0e29' }, sequence: 4294967295 }, { - txid: "58e607b7ae35a970a50bc3f78bb7b3f786c906cc07241bdbe7e439bbd026036a", + txid: '58e607b7ae35a970a50bc3f78bb7b3f786c906cc07241bdbe7e439bbd026036a', vout: 0, scriptSig: { asm: - "3045022100c450cdf99fa8eca980b4c6878ff02de46b22bca9b08c01152739d12003ef14c902203d93e6f3811acfac0f531eca1afbf5c5416b19ac154a6672e9f3afc53d1b56a6[ALL|FORKID] 03d0ea0c7798905c7f8dee6180321c92bf67df9dfde42da0f3cf25413d914c0e29", + '3045022100c450cdf99fa8eca980b4c6878ff02de46b22bca9b08c01152739d12003ef14c902203d93e6f3811acfac0f531eca1afbf5c5416b19ac154a6672e9f3afc53d1b56a6[ALL|FORKID] 03d0ea0c7798905c7f8dee6180321c92bf67df9dfde42da0f3cf25413d914c0e29', hex: - "483045022100c450cdf99fa8eca980b4c6878ff02de46b22bca9b08c01152739d12003ef14c902203d93e6f3811acfac0f531eca1afbf5c5416b19ac154a6672e9f3afc53d1b56a6412103d0ea0c7798905c7f8dee6180321c92bf67df9dfde42da0f3cf25413d914c0e29" + '483045022100c450cdf99fa8eca980b4c6878ff02de46b22bca9b08c01152739d12003ef14c902203d93e6f3811acfac0f531eca1afbf5c5416b19ac154a6672e9f3afc53d1b56a6412103d0ea0c7798905c7f8dee6180321c92bf67df9dfde42da0f3cf25413d914c0e29' }, sequence: 4294967295 }, { - txid: "9e2bc2f0e39cff9fd6f8cf56586bfd24389cba0367d70304914be277b2f7268b", + txid: '9e2bc2f0e39cff9fd6f8cf56586bfd24389cba0367d70304914be277b2f7268b', vout: 0, scriptSig: { asm: - "3045022100cd25d6e5de8057335d3db0e0ad05dd4802ebb45ae2e4ea52ba26670787eaa3bd02207024b366b61e6f28324fc040dad5fa589ee7f2487c8e4c54848827360c792cc3[ALL|FORKID] 03d0ea0c7798905c7f8dee6180321c92bf67df9dfde42da0f3cf25413d914c0e29", + '3045022100cd25d6e5de8057335d3db0e0ad05dd4802ebb45ae2e4ea52ba26670787eaa3bd02207024b366b61e6f28324fc040dad5fa589ee7f2487c8e4c54848827360c792cc3[ALL|FORKID] 03d0ea0c7798905c7f8dee6180321c92bf67df9dfde42da0f3cf25413d914c0e29', hex: - "483045022100cd25d6e5de8057335d3db0e0ad05dd4802ebb45ae2e4ea52ba26670787eaa3bd02207024b366b61e6f28324fc040dad5fa589ee7f2487c8e4c54848827360c792cc3412103d0ea0c7798905c7f8dee6180321c92bf67df9dfde42da0f3cf25413d914c0e29" + '483045022100cd25d6e5de8057335d3db0e0ad05dd4802ebb45ae2e4ea52ba26670787eaa3bd02207024b366b61e6f28324fc040dad5fa589ee7f2487c8e4c54848827360c792cc3412103d0ea0c7798905c7f8dee6180321c92bf67df9dfde42da0f3cf25413d914c0e29' }, sequence: 4294967295 } @@ -307,11 +307,11 @@ const nonSLPTxDetailsWithoutOpReturn = { n: 0, scriptPubKey: { asm: - "OP_DUP OP_HASH160 84c49aa95f145334b125c80c2cc9d077d08e00ce OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a91484c49aa95f145334b125c80c2cc9d077d08e00ce88ac", + 'OP_DUP OP_HASH160 84c49aa95f145334b125c80c2cc9d077d08e00ce OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a91484c49aa95f145334b125c80c2cc9d077d08e00ce88ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qzzvfx4ftu29xd93yhyqctxf6pmaprsqecm3rhd0lv"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qzzvfx4ftu29xd93yhyqctxf6pmaprsqecm3rhd0lv'] } }, { @@ -319,11 +319,11 @@ const nonSLPTxDetailsWithoutOpReturn = { n: 1, scriptPubKey: { asm: - "OP_DUP OP_HASH160 1aec955da539e59b32fa97e96fc0f53f018ae8a2 OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a9141aec955da539e59b32fa97e96fc0f53f018ae8a288ac", + 'OP_DUP OP_HASH160 1aec955da539e59b32fa97e96fc0f53f018ae8a2 OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a9141aec955da539e59b32fa97e96fc0f53f018ae8a288ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qqdwe92a55u7txejl2t7jm7q75lsrzhg5grz36dzh5"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qqdwe92a55u7txejl2t7jm7q75lsrzhg5grz36dzh5'] } }, { @@ -331,37 +331,37 @@ const nonSLPTxDetailsWithoutOpReturn = { n: 2, scriptPubKey: { asm: - "OP_DUP OP_HASH160 1af7e01ee75e22c645a5b37e401bd560168abc07 OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a9141af7e01ee75e22c645a5b37e401bd560168abc0788ac", + 'OP_DUP OP_HASH160 1af7e01ee75e22c645a5b37e401bd560168abc07 OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a9141af7e01ee75e22c645a5b37e401bd560168abc0788ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qqd00cq7ua0z93j95kehusqm64spdz4uqur3lepgqm"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qqd00cq7ua0z93j95kehusqm64spdz4uqur3lepgqm'] } } ], hex: - "0100000004d51b9012ececc895c3a62893b4af2da96429983a11dd41ee203ce103ce4ea315000000006b483045022100f020493f2c62740c89f07fba92d2916ad238c6965ef69fdf8338b4d6ee6c5a4502200251693e9883868cc5fb227bfc9bdaa5c333f14f712c0f3d8d2efb781f1a15fa412102a8087ad440c428aede8cf39eabe12b9807356b04d48aa0c361fa0d9d68a1aeacffffffff3703235ed4b3dc2415bd6f2a9f3341a74a5d371bc5abec6527adb5c6a520f752000000006b483045022100b3e65b51cd31c081070ebf5c91e43d10431a71e748c86ff6bcc7e4f5ecc7f54d02202d67edefe3a065cbda2e1782dd77bce2d891de2a428f5dd92eae15e4a843527c412103d0ea0c7798905c7f8dee6180321c92bf67df9dfde42da0f3cf25413d914c0e29ffffffff6a0326d0bb39e4e7db1b2407cc06c986f7b3b78bf7c30ba570a935aeb707e658000000006b483045022100c450cdf99fa8eca980b4c6878ff02de46b22bca9b08c01152739d12003ef14c902203d93e6f3811acfac0f531eca1afbf5c5416b19ac154a6672e9f3afc53d1b56a6412103d0ea0c7798905c7f8dee6180321c92bf67df9dfde42da0f3cf25413d914c0e29ffffffff8b26f7b277e24b910403d76703ba9c3824fd6b5856cff8d69fff9ce3f0c22b9e000000006b483045022100cd25d6e5de8057335d3db0e0ad05dd4802ebb45ae2e4ea52ba26670787eaa3bd02207024b366b61e6f28324fc040dad5fa589ee7f2487c8e4c54848827360c792cc3412103d0ea0c7798905c7f8dee6180321c92bf67df9dfde42da0f3cf25413d914c0e29ffffffff035ef6a8d6000000001976a91484c49aa95f145334b125c80c2cc9d077d08e00ce88ac22020000000000001976a9141aec955da539e59b32fa97e96fc0f53f018ae8a288ac98cb0a50000000001976a9141af7e01ee75e22c645a5b37e401bd560168abc0788ac00000000", - blockhash: "0000000000000000014bf37d1253e3c46f0e6f151bd6cca13f8093e76c31496d", + '0100000004d51b9012ececc895c3a62893b4af2da96429983a11dd41ee203ce103ce4ea315000000006b483045022100f020493f2c62740c89f07fba92d2916ad238c6965ef69fdf8338b4d6ee6c5a4502200251693e9883868cc5fb227bfc9bdaa5c333f14f712c0f3d8d2efb781f1a15fa412102a8087ad440c428aede8cf39eabe12b9807356b04d48aa0c361fa0d9d68a1aeacffffffff3703235ed4b3dc2415bd6f2a9f3341a74a5d371bc5abec6527adb5c6a520f752000000006b483045022100b3e65b51cd31c081070ebf5c91e43d10431a71e748c86ff6bcc7e4f5ecc7f54d02202d67edefe3a065cbda2e1782dd77bce2d891de2a428f5dd92eae15e4a843527c412103d0ea0c7798905c7f8dee6180321c92bf67df9dfde42da0f3cf25413d914c0e29ffffffff6a0326d0bb39e4e7db1b2407cc06c986f7b3b78bf7c30ba570a935aeb707e658000000006b483045022100c450cdf99fa8eca980b4c6878ff02de46b22bca9b08c01152739d12003ef14c902203d93e6f3811acfac0f531eca1afbf5c5416b19ac154a6672e9f3afc53d1b56a6412103d0ea0c7798905c7f8dee6180321c92bf67df9dfde42da0f3cf25413d914c0e29ffffffff8b26f7b277e24b910403d76703ba9c3824fd6b5856cff8d69fff9ce3f0c22b9e000000006b483045022100cd25d6e5de8057335d3db0e0ad05dd4802ebb45ae2e4ea52ba26670787eaa3bd02207024b366b61e6f28324fc040dad5fa589ee7f2487c8e4c54848827360c792cc3412103d0ea0c7798905c7f8dee6180321c92bf67df9dfde42da0f3cf25413d914c0e29ffffffff035ef6a8d6000000001976a91484c49aa95f145334b125c80c2cc9d077d08e00ce88ac22020000000000001976a9141aec955da539e59b32fa97e96fc0f53f018ae8a288ac98cb0a50000000001976a9141af7e01ee75e22c645a5b37e401bd560168abc0788ac00000000', + blockhash: '0000000000000000014bf37d1253e3c46f0e6f151bd6cca13f8093e76c31496d', confirmations: 1571, time: 1565380800, blocktime: 1565380800 } const nonSLPTxDetailsWithOpReturn = { - txid: "2ff74c48a5d657cf45f699601990bffbbe7a2a516d5480674cbf6c6a4497908f", - hash: "2ff74c48a5d657cf45f699601990bffbbe7a2a516d5480674cbf6c6a4497908f", + txid: '2ff74c48a5d657cf45f699601990bffbbe7a2a516d5480674cbf6c6a4497908f', + hash: '2ff74c48a5d657cf45f699601990bffbbe7a2a516d5480674cbf6c6a4497908f', version: 1, size: 271, locktime: 0, vin: [ { - txid: "6a81a401ec165eccd08c5c5a57a2185056675bbf2380d515c418b7a4c04db40a", + txid: '6a81a401ec165eccd08c5c5a57a2185056675bbf2380d515c418b7a4c04db40a', vout: 1, scriptSig: { asm: - "30440220168a04932175c6d6b10947ebef23c53ff2e905bb8dfb7d1aec961944f83bf20e0220724ad7a459bb31174b9e6cbbc73260c9a62d32dda2c47f5d7c5351b5eb9cd944[ALL|FORKID] 0467ff2df20f28bc62ad188525868f41d461f7dab3c1e500314cdb5218e5637bfd0f9c02eb5b3f383f698d28ff13547eaf05dd9216130861dd0216824e9d7337e3", + '30440220168a04932175c6d6b10947ebef23c53ff2e905bb8dfb7d1aec961944f83bf20e0220724ad7a459bb31174b9e6cbbc73260c9a62d32dda2c47f5d7c5351b5eb9cd944[ALL|FORKID] 0467ff2df20f28bc62ad188525868f41d461f7dab3c1e500314cdb5218e5637bfd0f9c02eb5b3f383f698d28ff13547eaf05dd9216130861dd0216824e9d7337e3', hex: - "4730440220168a04932175c6d6b10947ebef23c53ff2e905bb8dfb7d1aec961944f83bf20e0220724ad7a459bb31174b9e6cbbc73260c9a62d32dda2c47f5d7c5351b5eb9cd94441410467ff2df20f28bc62ad188525868f41d461f7dab3c1e500314cdb5218e5637bfd0f9c02eb5b3f383f698d28ff13547eaf05dd9216130861dd0216824e9d7337e3" + '4730440220168a04932175c6d6b10947ebef23c53ff2e905bb8dfb7d1aec961944f83bf20e0220724ad7a459bb31174b9e6cbbc73260c9a62d32dda2c47f5d7c5351b5eb9cd94441410467ff2df20f28bc62ad188525868f41d461f7dab3c1e500314cdb5218e5637bfd0f9c02eb5b3f383f698d28ff13547eaf05dd9216130861dd0216824e9d7337e3' }, sequence: 4294967295 } @@ -372,10 +372,10 @@ const nonSLPTxDetailsWithOpReturn = { n: 0, scriptPubKey: { asm: - "OP_RETURN -802180445 46386600368a3e883cd68c6939ab8c0a3c91537a3be6d9be35e42b8e37cfc92c", + 'OP_RETURN -802180445 46386600368a3e883cd68c6939ab8c0a3c91537a3be6d9be35e42b8e37cfc92c', hex: - "6a045d4dd0af2046386600368a3e883cd68c6939ab8c0a3c91537a3be6d9be35e42b8e37cfc92c", - type: "nulldata" + '6a045d4dd0af2046386600368a3e883cd68c6939ab8c0a3c91537a3be6d9be35e42b8e37cfc92c', + type: 'nulldata' } }, { @@ -383,37 +383,37 @@ const nonSLPTxDetailsWithOpReturn = { n: 1, scriptPubKey: { asm: - "OP_DUP OP_HASH160 066ebee590278f32aedc8a4865700c49e717f1d7 OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a914066ebee590278f32aedc8a4865700c49e717f1d788ac", + 'OP_DUP OP_HASH160 066ebee590278f32aedc8a4865700c49e717f1d7 OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a914066ebee590278f32aedc8a4865700c49e717f1d788ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qqrxa0h9jqnc7v4wmj9ysetsp3y7w9l36u8gnnjulq"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qqrxa0h9jqnc7v4wmj9ysetsp3y7w9l36u8gnnjulq'] } } ], hex: - "01000000010ab44dc0a4b718c415d58023bf5b67565018a2575a5c8cd0cc5e16ec01a4816a010000008a4730440220168a04932175c6d6b10947ebef23c53ff2e905bb8dfb7d1aec961944f83bf20e0220724ad7a459bb31174b9e6cbbc73260c9a62d32dda2c47f5d7c5351b5eb9cd94441410467ff2df20f28bc62ad188525868f41d461f7dab3c1e500314cdb5218e5637bfd0f9c02eb5b3f383f698d28ff13547eaf05dd9216130861dd0216824e9d7337e3ffffffff020000000000000000276a045d4dd0af2046386600368a3e883cd68c6939ab8c0a3c91537a3be6d9be35e42b8e37cfc92c420a0000000000001976a914066ebee590278f32aedc8a4865700c49e717f1d788ac00000000", - blockhash: "0000000000000000014bf37d1253e3c46f0e6f151bd6cca13f8093e76c31496d", + '01000000010ab44dc0a4b718c415d58023bf5b67565018a2575a5c8cd0cc5e16ec01a4816a010000008a4730440220168a04932175c6d6b10947ebef23c53ff2e905bb8dfb7d1aec961944f83bf20e0220724ad7a459bb31174b9e6cbbc73260c9a62d32dda2c47f5d7c5351b5eb9cd94441410467ff2df20f28bc62ad188525868f41d461f7dab3c1e500314cdb5218e5637bfd0f9c02eb5b3f383f698d28ff13547eaf05dd9216130861dd0216824e9d7337e3ffffffff020000000000000000276a045d4dd0af2046386600368a3e883cd68c6939ab8c0a3c91537a3be6d9be35e42b8e37cfc92c420a0000000000001976a914066ebee590278f32aedc8a4865700c49e717f1d788ac00000000', + blockhash: '0000000000000000014bf37d1253e3c46f0e6f151bd6cca13f8093e76c31496d', confirmations: 1571, time: 1565380800, blocktime: 1565380800 } txDetailsSLPGenesis = { - txid: "bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90", - hash: "bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90", + txid: 'bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90', + hash: 'bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90', version: 2, size: 357, locktime: 0, vin: [ { - txid: "86190b4a1ef25f09a388e2e86c299fc4bbc54c310386dcf37611b2958b964e25", + txid: '86190b4a1ef25f09a388e2e86c299fc4bbc54c310386dcf37611b2958b964e25', vout: 0, scriptSig: { asm: - "304402203cdf545000c17bce9dfa99a1515e5e3dc17b0abcfa55d1eacc01fa3f876d574102203170f0d7280dc7f4de887a141c94fb43bb3b5b0da12e4f400d3c89abf2a1c842[ALL|FORKID] 026ad033bd90dfa45766f4fdd377153468f1287e8fa0834fdad7dc11662e83dca8", + '304402203cdf545000c17bce9dfa99a1515e5e3dc17b0abcfa55d1eacc01fa3f876d574102203170f0d7280dc7f4de887a141c94fb43bb3b5b0da12e4f400d3c89abf2a1c842[ALL|FORKID] 026ad033bd90dfa45766f4fdd377153468f1287e8fa0834fdad7dc11662e83dca8', hex: - "47304402203cdf545000c17bce9dfa99a1515e5e3dc17b0abcfa55d1eacc01fa3f876d574102203170f0d7280dc7f4de887a141c94fb43bb3b5b0da12e4f400d3c89abf2a1c8424121026ad033bd90dfa45766f4fdd377153468f1287e8fa0834fdad7dc11662e83dca8" + '47304402203cdf545000c17bce9dfa99a1515e5e3dc17b0abcfa55d1eacc01fa3f876d574102203170f0d7280dc7f4de887a141c94fb43bb3b5b0da12e4f400d3c89abf2a1c8424121026ad033bd90dfa45766f4fdd377153468f1287e8fa0834fdad7dc11662e83dca8' }, sequence: 4294967295 } @@ -424,10 +424,10 @@ txDetailsSLPGenesis = { n: 0, scriptPubKey: { asm: - "OP_RETURN 5262419 1 47454e45534953 534c5053444b 534c502053444b206578616d706c65207573696e6720424954424f58 646576656c6f7065722e626974636f696e2e636f6d 0 8 2 0000000bcdf49b00", + 'OP_RETURN 5262419 1 47454e45534953 534c5053444b 534c502053444b206578616d706c65207573696e6720424954424f58 646576656c6f7065722e626974636f696e2e636f6d 0 8 2 0000000bcdf49b00', hex: - "6a04534c500001010747454e4553495306534c5053444b1c534c502053444b206578616d706c65207573696e6720424954424f5815646576656c6f7065722e626974636f696e2e636f6d4c0001080102080000000bcdf49b00", - type: "nulldata" + '6a04534c500001010747454e4553495306534c5053444b1c534c502053444b206578616d706c65207573696e6720424954424f5815646576656c6f7065722e626974636f696e2e636f6d4c0001080102080000000bcdf49b00', + type: 'nulldata' } }, { @@ -435,11 +435,11 @@ txDetailsSLPGenesis = { n: 1, scriptPubKey: { asm: - "OP_DUP OP_HASH160 70083e743742ad726a3a8f3a511d9a89f979dd63 OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a91470083e743742ad726a3a8f3a511d9a89f979dd6388ac", + 'OP_DUP OP_HASH160 70083e743742ad726a3a8f3a511d9a89f979dd63 OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a91470083e743742ad726a3a8f3a511d9a89f979dd6388ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qpcqs0n5xap26un2828n55gan2ylj7wavvzeuwdx05"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qpcqs0n5xap26un2828n55gan2ylj7wavvzeuwdx05'] } }, { @@ -447,11 +447,11 @@ txDetailsSLPGenesis = { n: 2, scriptPubKey: { asm: - "OP_DUP OP_HASH160 70083e743742ad726a3a8f3a511d9a89f979dd63 OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a91470083e743742ad726a3a8f3a511d9a89f979dd6388ac", + 'OP_DUP OP_HASH160 70083e743742ad726a3a8f3a511d9a89f979dd63 OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a91470083e743742ad726a3a8f3a511d9a89f979dd6388ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qpcqs0n5xap26un2828n55gan2ylj7wavvzeuwdx05"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qpcqs0n5xap26un2828n55gan2ylj7wavvzeuwdx05'] } }, { @@ -459,48 +459,48 @@ txDetailsSLPGenesis = { n: 3, scriptPubKey: { asm: - "OP_DUP OP_HASH160 70083e743742ad726a3a8f3a511d9a89f979dd63 OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a91470083e743742ad726a3a8f3a511d9a89f979dd6388ac", + 'OP_DUP OP_HASH160 70083e743742ad726a3a8f3a511d9a89f979dd63 OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a91470083e743742ad726a3a8f3a511d9a89f979dd6388ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qpcqs0n5xap26un2828n55gan2ylj7wavvzeuwdx05"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qpcqs0n5xap26un2828n55gan2ylj7wavvzeuwdx05'] } } ], hex: - "0200000001254e968b95b21176f3dc8603314cc5bbc49f296ce8e288a3095ff21e4a0b1986000000006a47304402203cdf545000c17bce9dfa99a1515e5e3dc17b0abcfa55d1eacc01fa3f876d574102203170f0d7280dc7f4de887a141c94fb43bb3b5b0da12e4f400d3c89abf2a1c8424121026ad033bd90dfa45766f4fdd377153468f1287e8fa0834fdad7dc11662e83dca8ffffffff040000000000000000596a04534c500001010747454e4553495306534c5053444b1c534c502053444b206578616d706c65207573696e6720424954424f5815646576656c6f7065722e626974636f696e2e636f6d4c0001080102080000000bcdf49b0022020000000000001976a91470083e743742ad726a3a8f3a511d9a89f979dd6388ac22020000000000001976a91470083e743742ad726a3a8f3a511d9a89f979dd6388acdf070000000000001976a91470083e743742ad726a3a8f3a511d9a89f979dd6388ac00000000", - blockhash: "000000000000000002f45ff275b5c073422b2bf1c3e4babae823145c2bbff55a", + '0200000001254e968b95b21176f3dc8603314cc5bbc49f296ce8e288a3095ff21e4a0b1986000000006a47304402203cdf545000c17bce9dfa99a1515e5e3dc17b0abcfa55d1eacc01fa3f876d574102203170f0d7280dc7f4de887a141c94fb43bb3b5b0da12e4f400d3c89abf2a1c8424121026ad033bd90dfa45766f4fdd377153468f1287e8fa0834fdad7dc11662e83dca8ffffffff040000000000000000596a04534c500001010747454e4553495306534c5053444b1c534c502053444b206578616d706c65207573696e6720424954424f5815646576656c6f7065722e626974636f696e2e636f6d4c0001080102080000000bcdf49b0022020000000000001976a91470083e743742ad726a3a8f3a511d9a89f979dd6388ac22020000000000001976a91470083e743742ad726a3a8f3a511d9a89f979dd6388acdf070000000000001976a91470083e743742ad726a3a8f3a511d9a89f979dd6388ac00000000', + blockhash: '000000000000000002f45ff275b5c073422b2bf1c3e4babae823145c2bbff55a', confirmations: 1744, time: 1565274914, blocktime: 1565274914 } const txDetailsSLPMint = { - txid: "65f21bbfcd545e5eb515e38e861a9dfe2378aaa2c4e458eb9e59e4d40e38f3a4", - hash: "65f21bbfcd545e5eb515e38e861a9dfe2378aaa2c4e458eb9e59e4d40e38f3a4", + txid: '65f21bbfcd545e5eb515e38e861a9dfe2378aaa2c4e458eb9e59e4d40e38f3a4', + hash: '65f21bbfcd545e5eb515e38e861a9dfe2378aaa2c4e458eb9e59e4d40e38f3a4', version: 2, size: 474, locktime: 0, vin: [ { - txid: "023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e4", + txid: '023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e4', vout: 2, scriptSig: { asm: - "3045022100f73afe1ba320dfdf191c7219e37a6dcd8d52f3e0155efee8a3e17556965e031b022021a9689e57210697236f644cc91c43d73e894020b227445776afe9a5b79c0f23[ALL|FORKID] 036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850d", + '3045022100f73afe1ba320dfdf191c7219e37a6dcd8d52f3e0155efee8a3e17556965e031b022021a9689e57210697236f644cc91c43d73e894020b227445776afe9a5b79c0f23[ALL|FORKID] 036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850d', hex: - "483045022100f73afe1ba320dfdf191c7219e37a6dcd8d52f3e0155efee8a3e17556965e031b022021a9689e57210697236f644cc91c43d73e894020b227445776afe9a5b79c0f234121036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850d" + '483045022100f73afe1ba320dfdf191c7219e37a6dcd8d52f3e0155efee8a3e17556965e031b022021a9689e57210697236f644cc91c43d73e894020b227445776afe9a5b79c0f234121036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850d' }, sequence: 4294967295 }, { - txid: "023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e4", + txid: '023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e4', vout: 3, scriptSig: { asm: - "3045022100cc549d3659875931ea5ba7bd71072ac650864fc046c8239d2f8948f67486d7b30220103641cc9566283c7706d702dc92c2f442673cbc51ce84b5d383ba68da97b157[ALL|FORKID] 036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850d", + '3045022100cc549d3659875931ea5ba7bd71072ac650864fc046c8239d2f8948f67486d7b30220103641cc9566283c7706d702dc92c2f442673cbc51ce84b5d383ba68da97b157[ALL|FORKID] 036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850d', hex: - "483045022100cc549d3659875931ea5ba7bd71072ac650864fc046c8239d2f8948f67486d7b30220103641cc9566283c7706d702dc92c2f442673cbc51ce84b5d383ba68da97b1574121036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850d" + '483045022100cc549d3659875931ea5ba7bd71072ac650864fc046c8239d2f8948f67486d7b30220103641cc9566283c7706d702dc92c2f442673cbc51ce84b5d383ba68da97b1574121036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850d' }, sequence: 4294967295 } @@ -511,10 +511,10 @@ const txDetailsSLPMint = { n: 0, scriptPubKey: { asm: - "OP_RETURN 5262419 1 1414416717 023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e4 2 00000002540be400", + 'OP_RETURN 5262419 1 1414416717 023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e4 2 00000002540be400', hex: - "6a04534c50000101044d494e5420023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e401020800000002540be400", - type: "nulldata" + '6a04534c50000101044d494e5420023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e401020800000002540be400', + type: 'nulldata' } }, { @@ -522,11 +522,11 @@ const txDetailsSLPMint = { n: 1, scriptPubKey: { asm: - "OP_DUP OP_HASH160 210a88277de7a80a1dac90a8153c0e7c8a2f08a7 OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a914210a88277de7a80a1dac90a8153c0e7c8a2f08a788ac", + 'OP_DUP OP_HASH160 210a88277de7a80a1dac90a8153c0e7c8a2f08a7 OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a914210a88277de7a80a1dac90a8153c0e7c8a2f08a788ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5u5k0yyr2q"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5u5k0yyr2q'] } }, { @@ -534,11 +534,11 @@ const txDetailsSLPMint = { n: 2, scriptPubKey: { asm: - "OP_DUP OP_HASH160 210a88277de7a80a1dac90a8153c0e7c8a2f08a7 OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a914210a88277de7a80a1dac90a8153c0e7c8a2f08a788ac", + 'OP_DUP OP_HASH160 210a88277de7a80a1dac90a8153c0e7c8a2f08a7 OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a914210a88277de7a80a1dac90a8153c0e7c8a2f08a788ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5u5k0yyr2q"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5u5k0yyr2q'] } }, { @@ -546,59 +546,59 @@ const txDetailsSLPMint = { n: 3, scriptPubKey: { asm: - "OP_DUP OP_HASH160 210a88277de7a80a1dac90a8153c0e7c8a2f08a7 OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a914210a88277de7a80a1dac90a8153c0e7c8a2f08a788ac", + 'OP_DUP OP_HASH160 210a88277de7a80a1dac90a8153c0e7c8a2f08a7 OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a914210a88277de7a80a1dac90a8153c0e7c8a2f08a788ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5u5k0yyr2q"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5u5k0yyr2q'] } } ], hex: - "0200000002e454f384ced298581b0b0c6e9b9d7a93474c9a5ad14f998b0547395ae9d33c02020000006b483045022100f73afe1ba320dfdf191c7219e37a6dcd8d52f3e0155efee8a3e17556965e031b022021a9689e57210697236f644cc91c43d73e894020b227445776afe9a5b79c0f234121036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850dffffffffe454f384ced298581b0b0c6e9b9d7a93474c9a5ad14f998b0547395ae9d33c02030000006b483045022100cc549d3659875931ea5ba7bd71072ac650864fc046c8239d2f8948f67486d7b30220103641cc9566283c7706d702dc92c2f442673cbc51ce84b5d383ba68da97b1574121036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850dffffffff040000000000000000396a04534c50000101044d494e5420023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e401020800000002540be40022020000000000001976a914210a88277de7a80a1dac90a8153c0e7c8a2f08a788ac22020000000000001976a914210a88277de7a80a1dac90a8153c0e7c8a2f08a788ac681d0000000000001976a914210a88277de7a80a1dac90a8153c0e7c8a2f08a788ac00000000", - blockhash: "000000000000000000182bc50810ab0296a6f1f7b6313bf535b6e78dffca8db6", + '0200000002e454f384ced298581b0b0c6e9b9d7a93474c9a5ad14f998b0547395ae9d33c02020000006b483045022100f73afe1ba320dfdf191c7219e37a6dcd8d52f3e0155efee8a3e17556965e031b022021a9689e57210697236f644cc91c43d73e894020b227445776afe9a5b79c0f234121036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850dffffffffe454f384ced298581b0b0c6e9b9d7a93474c9a5ad14f998b0547395ae9d33c02030000006b483045022100cc549d3659875931ea5ba7bd71072ac650864fc046c8239d2f8948f67486d7b30220103641cc9566283c7706d702dc92c2f442673cbc51ce84b5d383ba68da97b1574121036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850dffffffff040000000000000000396a04534c50000101044d494e5420023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e401020800000002540be40022020000000000001976a914210a88277de7a80a1dac90a8153c0e7c8a2f08a788ac22020000000000001976a914210a88277de7a80a1dac90a8153c0e7c8a2f08a788ac681d0000000000001976a914210a88277de7a80a1dac90a8153c0e7c8a2f08a788ac00000000', + blockhash: '000000000000000000182bc50810ab0296a6f1f7b6313bf535b6e78dffca8db6', confirmations: 154, time: 1566227300, blocktime: 1566227300 } const txDetailsSLPSend = { - txid: "4f922565af664b6fdf0a1ba3924487344be721b3d8815c62cafc8a51e04a8afa", - hash: "4f922565af664b6fdf0a1ba3924487344be721b3d8815c62cafc8a51e04a8afa", + txid: '4f922565af664b6fdf0a1ba3924487344be721b3d8815c62cafc8a51e04a8afa', + hash: '4f922565af664b6fdf0a1ba3924487344be721b3d8815c62cafc8a51e04a8afa', version: 2, size: 626, locktime: 0, vin: [ { - txid: "65f21bbfcd545e5eb515e38e861a9dfe2378aaa2c4e458eb9e59e4d40e38f3a4", + txid: '65f21bbfcd545e5eb515e38e861a9dfe2378aaa2c4e458eb9e59e4d40e38f3a4', vout: 1, scriptSig: { asm: - "30440220392bd0f72f0ff7ce983fe6320383e6f52d6921064e95fcd1599b672d1ff074b4022061922fb13f7477708dc88cb11a5448c702c4bad059526253821c7ccc5e182932[ALL|FORKID] 036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850d", + '30440220392bd0f72f0ff7ce983fe6320383e6f52d6921064e95fcd1599b672d1ff074b4022061922fb13f7477708dc88cb11a5448c702c4bad059526253821c7ccc5e182932[ALL|FORKID] 036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850d', hex: - "4730440220392bd0f72f0ff7ce983fe6320383e6f52d6921064e95fcd1599b672d1ff074b4022061922fb13f7477708dc88cb11a5448c702c4bad059526253821c7ccc5e1829324121036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850d" + '4730440220392bd0f72f0ff7ce983fe6320383e6f52d6921064e95fcd1599b672d1ff074b4022061922fb13f7477708dc88cb11a5448c702c4bad059526253821c7ccc5e1829324121036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850d' }, sequence: 4294967295 }, { - txid: "023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e4", + txid: '023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e4', vout: 1, scriptSig: { asm: - "3044022010e57d2db06c7013ef9fd6848a6e307674a25cb62cb44a666b03800b322a1e3f022013f41bbf2ef462be799a71e1392ca0a37687d3602002bb3b8d772e2afad498a7[ALL|FORKID] 036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850d", + '3044022010e57d2db06c7013ef9fd6848a6e307674a25cb62cb44a666b03800b322a1e3f022013f41bbf2ef462be799a71e1392ca0a37687d3602002bb3b8d772e2afad498a7[ALL|FORKID] 036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850d', hex: - "473044022010e57d2db06c7013ef9fd6848a6e307674a25cb62cb44a666b03800b322a1e3f022013f41bbf2ef462be799a71e1392ca0a37687d3602002bb3b8d772e2afad498a74121036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850d" + '473044022010e57d2db06c7013ef9fd6848a6e307674a25cb62cb44a666b03800b322a1e3f022013f41bbf2ef462be799a71e1392ca0a37687d3602002bb3b8d772e2afad498a74121036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850d' }, sequence: 4294967295 }, { - txid: "65f21bbfcd545e5eb515e38e861a9dfe2378aaa2c4e458eb9e59e4d40e38f3a4", + txid: '65f21bbfcd545e5eb515e38e861a9dfe2378aaa2c4e458eb9e59e4d40e38f3a4', vout: 3, scriptSig: { asm: - "3044022064a522467b966777592ddb699ce0536a9a94e7f3c9a3c428bec929f78ee3efc60220700c6e1506ab8b5253c12d7f1682aac3bb5f6c869ec257a851d19d36d8c1f10f[ALL|FORKID] 036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850d", + '3044022064a522467b966777592ddb699ce0536a9a94e7f3c9a3c428bec929f78ee3efc60220700c6e1506ab8b5253c12d7f1682aac3bb5f6c869ec257a851d19d36d8c1f10f[ALL|FORKID] 036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850d', hex: - "473044022064a522467b966777592ddb699ce0536a9a94e7f3c9a3c428bec929f78ee3efc60220700c6e1506ab8b5253c12d7f1682aac3bb5f6c869ec257a851d19d36d8c1f10f4121036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850d" + '473044022064a522467b966777592ddb699ce0536a9a94e7f3c9a3c428bec929f78ee3efc60220700c6e1506ab8b5253c12d7f1682aac3bb5f6c869ec257a851d19d36d8c1f10f4121036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850d' }, sequence: 4294967295 } @@ -609,10 +609,10 @@ const txDetailsSLPSend = { n: 0, scriptPubKey: { asm: - "OP_RETURN 5262419 1 1145980243 023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e4 0000000011e1a300 0000000e101edc00", + 'OP_RETURN 5262419 1 1145980243 023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e4 0000000011e1a300 0000000e101edc00', hex: - "6a04534c500001010453454e4420023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e4080000000011e1a300080000000e101edc00", - type: "nulldata" + '6a04534c500001010453454e4420023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e4080000000011e1a300080000000e101edc00', + type: 'nulldata' } }, { @@ -620,11 +620,11 @@ const txDetailsSLPSend = { n: 1, scriptPubKey: { asm: - "OP_DUP OP_HASH160 99e5a8229a9af0dbf3cadb25ea981df49c9d93bf OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a91499e5a8229a9af0dbf3cadb25ea981df49c9d93bf88ac", + 'OP_DUP OP_HASH160 99e5a8229a9af0dbf3cadb25ea981df49c9d93bf OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a91499e5a8229a9af0dbf3cadb25ea981df49c9d93bf88ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qzv7t2pzn2d0pklnetdjt65crh6fe8vnhuwvhsk2nn"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qzv7t2pzn2d0pklnetdjt65crh6fe8vnhuwvhsk2nn'] } }, { @@ -632,11 +632,11 @@ const txDetailsSLPSend = { n: 2, scriptPubKey: { asm: - "OP_DUP OP_HASH160 210a88277de7a80a1dac90a8153c0e7c8a2f08a7 OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a914210a88277de7a80a1dac90a8153c0e7c8a2f08a788ac", + 'OP_DUP OP_HASH160 210a88277de7a80a1dac90a8153c0e7c8a2f08a7 OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a914210a88277de7a80a1dac90a8153c0e7c8a2f08a788ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5u5k0yyr2q"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5u5k0yyr2q'] } }, { @@ -644,37 +644,37 @@ const txDetailsSLPSend = { n: 3, scriptPubKey: { asm: - "OP_DUP OP_HASH160 210a88277de7a80a1dac90a8153c0e7c8a2f08a7 OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a914210a88277de7a80a1dac90a8153c0e7c8a2f08a788ac", + 'OP_DUP OP_HASH160 210a88277de7a80a1dac90a8153c0e7c8a2f08a7 OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a914210a88277de7a80a1dac90a8153c0e7c8a2f08a788ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5u5k0yyr2q"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5u5k0yyr2q'] } } ], hex: - "0200000003a4f3380ed4e4599eeb58e4c4a2aa7823fe9d1a868ee315b55e5e54cdbf1bf265010000006a4730440220392bd0f72f0ff7ce983fe6320383e6f52d6921064e95fcd1599b672d1ff074b4022061922fb13f7477708dc88cb11a5448c702c4bad059526253821c7ccc5e1829324121036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850dffffffffe454f384ced298581b0b0c6e9b9d7a93474c9a5ad14f998b0547395ae9d33c02010000006a473044022010e57d2db06c7013ef9fd6848a6e307674a25cb62cb44a666b03800b322a1e3f022013f41bbf2ef462be799a71e1392ca0a37687d3602002bb3b8d772e2afad498a74121036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850dffffffffa4f3380ed4e4599eeb58e4c4a2aa7823fe9d1a868ee315b55e5e54cdbf1bf265030000006a473044022064a522467b966777592ddb699ce0536a9a94e7f3c9a3c428bec929f78ee3efc60220700c6e1506ab8b5253c12d7f1682aac3bb5f6c869ec257a851d19d36d8c1f10f4121036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850dffffffff040000000000000000406a04534c500001010453454e4420023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e4080000000011e1a300080000000e101edc0022020000000000001976a91499e5a8229a9af0dbf3cadb25ea981df49c9d93bf88ac22020000000000001976a914210a88277de7a80a1dac90a8153c0e7c8a2f08a788acf21a0000000000001976a914210a88277de7a80a1dac90a8153c0e7c8a2f08a788ac00000000", - blockhash: "000000000000000000182bc50810ab0296a6f1f7b6313bf535b6e78dffca8db6", + '0200000003a4f3380ed4e4599eeb58e4c4a2aa7823fe9d1a868ee315b55e5e54cdbf1bf265010000006a4730440220392bd0f72f0ff7ce983fe6320383e6f52d6921064e95fcd1599b672d1ff074b4022061922fb13f7477708dc88cb11a5448c702c4bad059526253821c7ccc5e1829324121036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850dffffffffe454f384ced298581b0b0c6e9b9d7a93474c9a5ad14f998b0547395ae9d33c02010000006a473044022010e57d2db06c7013ef9fd6848a6e307674a25cb62cb44a666b03800b322a1e3f022013f41bbf2ef462be799a71e1392ca0a37687d3602002bb3b8d772e2afad498a74121036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850dffffffffa4f3380ed4e4599eeb58e4c4a2aa7823fe9d1a868ee315b55e5e54cdbf1bf265030000006a473044022064a522467b966777592ddb699ce0536a9a94e7f3c9a3c428bec929f78ee3efc60220700c6e1506ab8b5253c12d7f1682aac3bb5f6c869ec257a851d19d36d8c1f10f4121036a0ccfe281fc5f83f0b1d33fbc0da65cffc6f7f265bb2e17b9c7d8278323850dffffffff040000000000000000406a04534c500001010453454e4420023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e4080000000011e1a300080000000e101edc0022020000000000001976a91499e5a8229a9af0dbf3cadb25ea981df49c9d93bf88ac22020000000000001976a914210a88277de7a80a1dac90a8153c0e7c8a2f08a788acf21a0000000000001976a914210a88277de7a80a1dac90a8153c0e7c8a2f08a788ac00000000', + blockhash: '000000000000000000182bc50810ab0296a6f1f7b6313bf535b6e78dffca8db6', confirmations: 154, time: 1566227300, blocktime: 1566227300 } const txDetailsSLPGenesisNoBaton = { - txid: "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7", - hash: "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7", + txid: '497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7', + hash: '497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7', version: 1, size: 285, locktime: 575672, vin: [ { - txid: "805728012bc3349d1a05dc503aaf389c7a743917d7af6adfb844baff8ff2f89f", + txid: '805728012bc3349d1a05dc503aaf389c7a743917d7af6adfb844baff8ff2f89f', vout: 2, scriptSig: { asm: - "3045022100e4c0e18d97ea6d24c15d60e4032131e985091dec0d844fe00065cb6852b2cfaa02207b6334f72e1aa70f26a88e0e0bff183966405b59bf3a9eaa89d03155cd155505[ALL|FORKID] 03adb6ee2ccaf17f407704c91aae7327bd12fa81aa1bad63bc1685a9ded76d6f2a", + '3045022100e4c0e18d97ea6d24c15d60e4032131e985091dec0d844fe00065cb6852b2cfaa02207b6334f72e1aa70f26a88e0e0bff183966405b59bf3a9eaa89d03155cd155505[ALL|FORKID] 03adb6ee2ccaf17f407704c91aae7327bd12fa81aa1bad63bc1685a9ded76d6f2a', hex: - "483045022100e4c0e18d97ea6d24c15d60e4032131e985091dec0d844fe00065cb6852b2cfaa02207b6334f72e1aa70f26a88e0e0bff183966405b59bf3a9eaa89d03155cd155505412103adb6ee2ccaf17f407704c91aae7327bd12fa81aa1bad63bc1685a9ded76d6f2a" + '483045022100e4c0e18d97ea6d24c15d60e4032131e985091dec0d844fe00065cb6852b2cfaa02207b6334f72e1aa70f26a88e0e0bff183966405b59bf3a9eaa89d03155cd155505412103adb6ee2ccaf17f407704c91aae7327bd12fa81aa1bad63bc1685a9ded76d6f2a' }, sequence: 4294967294 } @@ -685,10 +685,10 @@ const txDetailsSLPGenesisNoBaton = { n: 0, scriptPubKey: { asm: - "OP_RETURN 5262419 1 47454e45534953 544f4b2d4348 546f6b796f43617368 0 0 8 0 000775f05a074000", + 'OP_RETURN 5262419 1 47454e45534953 544f4b2d4348 546f6b796f43617368 0 0 8 0 000775f05a074000', hex: - "6a04534c500001010747454e4553495306544f4b2d434809546f6b796f436173684c004c0001084c0008000775f05a074000", - type: "nulldata" + '6a04534c500001010747454e4553495306544f4b2d434809546f6b796f436173684c004c0001084c0008000775f05a074000', + type: 'nulldata' } }, { @@ -696,11 +696,11 @@ const txDetailsSLPGenesisNoBaton = { n: 1, scriptPubKey: { asm: - "OP_DUP OP_HASH160 17c068626a1085ab782b94fe5577b67b9168a1d9 OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a91417c068626a1085ab782b94fe5577b67b9168a1d988ac", + 'OP_DUP OP_HASH160 17c068626a1085ab782b94fe5577b67b9168a1d9 OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a91417c068626a1085ab782b94fe5577b67b9168a1d988ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qqtuq6rzdgggt2mc9w20u4thkeaez69pmy6ur897sr"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qqtuq6rzdgggt2mc9w20u4thkeaez69pmy6ur897sr'] } }, { @@ -708,48 +708,48 @@ const txDetailsSLPGenesisNoBaton = { n: 2, scriptPubKey: { asm: - "OP_DUP OP_HASH160 8b3decf88562b3a8037d8e88171e14bff010ea3d OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a9148b3decf88562b3a8037d8e88171e14bff010ea3d88ac", + 'OP_DUP OP_HASH160 8b3decf88562b3a8037d8e88171e14bff010ea3d OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a9148b3decf88562b3a8037d8e88171e14bff010ea3d88ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qz9nmm8cs43t82qr0k8gs9c7zjllqy82853g26y3tc"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qz9nmm8cs43t82qr0k8gs9c7zjllqy82853g26y3tc'] } } ], hex: - "01000000019ff8f28fffba44b8df6aafd71739747a9c38af3a50dc051a9d34c32b01285780020000006b483045022100e4c0e18d97ea6d24c15d60e4032131e985091dec0d844fe00065cb6852b2cfaa02207b6334f72e1aa70f26a88e0e0bff183966405b59bf3a9eaa89d03155cd155505412103adb6ee2ccaf17f407704c91aae7327bd12fa81aa1bad63bc1685a9ded76d6f2afeffffff030000000000000000326a04534c500001010747454e4553495306544f4b2d434809546f6b796f436173684c004c0001084c0008000775f05a07400022020000000000001976a91417c068626a1085ab782b94fe5577b67b9168a1d988ac973c0700000000001976a9148b3decf88562b3a8037d8e88171e14bff010ea3d88acb8c80800", - blockhash: "0000000000000000003e44676df0c4f80b68aff24bf04823444c0069729631f8", + '01000000019ff8f28fffba44b8df6aafd71739747a9c38af3a50dc051a9d34c32b01285780020000006b483045022100e4c0e18d97ea6d24c15d60e4032131e985091dec0d844fe00065cb6852b2cfaa02207b6334f72e1aa70f26a88e0e0bff183966405b59bf3a9eaa89d03155cd155505412103adb6ee2ccaf17f407704c91aae7327bd12fa81aa1bad63bc1685a9ded76d6f2afeffffff030000000000000000326a04534c500001010747454e4553495306544f4b2d434809546f6b796f436173684c004c0001084c0008000775f05a07400022020000000000001976a91417c068626a1085ab782b94fe5577b67b9168a1d988ac973c0700000000001976a9148b3decf88562b3a8037d8e88171e14bff010ea3d88acb8c80800', + blockhash: '0000000000000000003e44676df0c4f80b68aff24bf04823444c0069729631f8', confirmations: 21249, time: 1553714591, blocktime: 1553714591 } const txDetailsSLPSendAlt = { - txid: "d94357179775425ebc59c93173bd6dc9854095f090a2eb9dcfe9797398bc8eae", - hash: "d94357179775425ebc59c93173bd6dc9854095f090a2eb9dcfe9797398bc8eae", + txid: 'd94357179775425ebc59c93173bd6dc9854095f090a2eb9dcfe9797398bc8eae', + hash: 'd94357179775425ebc59c93173bd6dc9854095f090a2eb9dcfe9797398bc8eae', version: 2, size: 438, locktime: 0, vin: [ { - txid: "984a8fc8093e1db5489a8856ab0ecbaef188662535f08de6f87da8622978146f", + txid: '984a8fc8093e1db5489a8856ab0ecbaef188662535f08de6f87da8622978146f', vout: 0, scriptSig: { asm: - "3045022100f3f84a7c0a72e6df55ad8ff4596aae2d040403b38f8054d95ee48f3d554790050220776b0833891e65c52685ce3a498e3ee0aa804a85e9b79f21bb74a367ad88a569[ALL|FORKID] 03440d292d554f524a1a16fab1c4384c82a15aa191b6a25187c03f6ec4db57d61e", + '3045022100f3f84a7c0a72e6df55ad8ff4596aae2d040403b38f8054d95ee48f3d554790050220776b0833891e65c52685ce3a498e3ee0aa804a85e9b79f21bb74a367ad88a569[ALL|FORKID] 03440d292d554f524a1a16fab1c4384c82a15aa191b6a25187c03f6ec4db57d61e', hex: - "483045022100f3f84a7c0a72e6df55ad8ff4596aae2d040403b38f8054d95ee48f3d554790050220776b0833891e65c52685ce3a498e3ee0aa804a85e9b79f21bb74a367ad88a569412103440d292d554f524a1a16fab1c4384c82a15aa191b6a25187c03f6ec4db57d61e" + '483045022100f3f84a7c0a72e6df55ad8ff4596aae2d040403b38f8054d95ee48f3d554790050220776b0833891e65c52685ce3a498e3ee0aa804a85e9b79f21bb74a367ad88a569412103440d292d554f524a1a16fab1c4384c82a15aa191b6a25187c03f6ec4db57d61e' }, sequence: 4294967295 }, { - txid: "164ff37f47a1be6550a81f3d76f3d57e121d82ed04ed8b7bc932e2273141ebbc", + txid: '164ff37f47a1be6550a81f3d76f3d57e121d82ed04ed8b7bc932e2273141ebbc', vout: 1, scriptSig: { asm: - "30440220177d3583516caf6a3d8e99ed9c0a76595a4187d04c575c0f7dab6a6dfa4630c502207fc842e03ca73a2c9d1f9d7406145bb4ea6eb90d1585ea7c4e82491707fadb74[ALL|FORKID] 0252996f42e5908cc6fe5e2df42888a7226f352f2d496e7f9bb17aaf55e41d997b", + '30440220177d3583516caf6a3d8e99ed9c0a76595a4187d04c575c0f7dab6a6dfa4630c502207fc842e03ca73a2c9d1f9d7406145bb4ea6eb90d1585ea7c4e82491707fadb74[ALL|FORKID] 0252996f42e5908cc6fe5e2df42888a7226f352f2d496e7f9bb17aaf55e41d997b', hex: - "4730440220177d3583516caf6a3d8e99ed9c0a76595a4187d04c575c0f7dab6a6dfa4630c502207fc842e03ca73a2c9d1f9d7406145bb4ea6eb90d1585ea7c4e82491707fadb7441210252996f42e5908cc6fe5e2df42888a7226f352f2d496e7f9bb17aaf55e41d997b" + '4730440220177d3583516caf6a3d8e99ed9c0a76595a4187d04c575c0f7dab6a6dfa4630c502207fc842e03ca73a2c9d1f9d7406145bb4ea6eb90d1585ea7c4e82491707fadb7441210252996f42e5908cc6fe5e2df42888a7226f352f2d496e7f9bb17aaf55e41d997b' }, sequence: 4294967295 } @@ -760,10 +760,10 @@ const txDetailsSLPSendAlt = { n: 0, scriptPubKey: { asm: - "OP_RETURN 5262419 256 1145980243 73db55368981e4878440637e448d4abe7f661be5c3efdcbcb63bd86a01a76b5a 0000000000000001", + 'OP_RETURN 5262419 256 1145980243 73db55368981e4878440637e448d4abe7f661be5c3efdcbcb63bd86a01a76b5a 0000000000000001', hex: - "6a04534c50000200010453454e442073db55368981e4878440637e448d4abe7f661be5c3efdcbcb63bd86a01a76b5a080000000000000001", - type: "nulldata" + '6a04534c50000200010453454e442073db55368981e4878440637e448d4abe7f661be5c3efdcbcb63bd86a01a76b5a080000000000000001', + type: 'nulldata' } }, { @@ -771,11 +771,11 @@ const txDetailsSLPSendAlt = { n: 1, scriptPubKey: { asm: - "OP_DUP OP_HASH160 f037d66efd7235ae4eeb03f666845a7c23ace91a OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a914f037d66efd7235ae4eeb03f666845a7c23ace91a88ac", + 'OP_DUP OP_HASH160 f037d66efd7235ae4eeb03f666845a7c23ace91a OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a914f037d66efd7235ae4eeb03f666845a7c23ace91a88ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qrcr04nwl4erttjwavplve5ytf7z8t8frg94efy6ts"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qrcr04nwl4erttjwavplve5ytf7z8t8frg94efy6ts'] } }, { @@ -783,120 +783,120 @@ const txDetailsSLPSendAlt = { n: 2, scriptPubKey: { asm: - "OP_DUP OP_HASH160 d5669ba347fd2abe6a06d0310f817d1f1304ba71 OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a914d5669ba347fd2abe6a06d0310f817d1f1304ba7188ac", + 'OP_DUP OP_HASH160 d5669ba347fd2abe6a06d0310f817d1f1304ba71 OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a914d5669ba347fd2abe6a06d0310f817d1f1304ba7188ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qr2kdxargl7j40n2qmgrzrup0503xp96wyn5ju6p5l"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qr2kdxargl7j40n2qmgrzrup0503xp96wyn5ju6p5l'] } } ], hex: - "02000000026f14782962a87df8e68df035256688f1aecb0eab56889a48b51d3e09c88f4a98000000006b483045022100f3f84a7c0a72e6df55ad8ff4596aae2d040403b38f8054d95ee48f3d554790050220776b0833891e65c52685ce3a498e3ee0aa804a85e9b79f21bb74a367ad88a569412103440d292d554f524a1a16fab1c4384c82a15aa191b6a25187c03f6ec4db57d61effffffffbceb413127e232c97b8bed04ed821d127ed5f3763d1fa85065bea1477ff34f16010000006a4730440220177d3583516caf6a3d8e99ed9c0a76595a4187d04c575c0f7dab6a6dfa4630c502207fc842e03ca73a2c9d1f9d7406145bb4ea6eb90d1585ea7c4e82491707fadb7441210252996f42e5908cc6fe5e2df42888a7226f352f2d496e7f9bb17aaf55e41d997bffffffff030000000000000000386a04534c50000200010453454e442073db55368981e4878440637e448d4abe7f661be5c3efdcbcb63bd86a01a76b5a08000000000000000122020000000000001976a914f037d66efd7235ae4eeb03f666845a7c23ace91a88ac07b90000000000001976a914d5669ba347fd2abe6a06d0310f817d1f1304ba7188ac00000000" + '02000000026f14782962a87df8e68df035256688f1aecb0eab56889a48b51d3e09c88f4a98000000006b483045022100f3f84a7c0a72e6df55ad8ff4596aae2d040403b38f8054d95ee48f3d554790050220776b0833891e65c52685ce3a498e3ee0aa804a85e9b79f21bb74a367ad88a569412103440d292d554f524a1a16fab1c4384c82a15aa191b6a25187c03f6ec4db57d61effffffffbceb413127e232c97b8bed04ed821d127ed5f3763d1fa85065bea1477ff34f16010000006a4730440220177d3583516caf6a3d8e99ed9c0a76595a4187d04c575c0f7dab6a6dfa4630c502207fc842e03ca73a2c9d1f9d7406145bb4ea6eb90d1585ea7c4e82491707fadb7441210252996f42e5908cc6fe5e2df42888a7226f352f2d496e7f9bb17aaf55e41d997bffffffff030000000000000000386a04534c50000200010453454e442073db55368981e4878440637e448d4abe7f661be5c3efdcbcb63bd86a01a76b5a08000000000000000122020000000000001976a914f037d66efd7235ae4eeb03f666845a7c23ace91a88ac07b90000000000001976a914d5669ba347fd2abe6a06d0310f817d1f1304ba7188ac00000000' } const mockTxDetails = { - txid: "9dbaaafc48c49a21beabada8de632009288a2cd52eecefd0c00edcffca9955d0", + txid: '9dbaaafc48c49a21beabada8de632009288a2cd52eecefd0c00edcffca9955d0', version: 2, locktime: 0, vin: [ { - txid: "203f21da29235b290cca3ec7cf14479533b3fd15d75ecb2e72f57bcff984bd94", + txid: '203f21da29235b290cca3ec7cf14479533b3fd15d75ecb2e72f57bcff984bd94', vout: 1, sequence: 4294967295, n: 0, scriptSig: { hex: - "4730440220068b4d98542760aeff6dd3b17958611c12cfe36ca23d1a2df42241b0c993286202202db64ad12f62fe0f13ed904d095c4ed06555e0632d9d55db50fabba7d0153aea412103021c8dd3baebdbc1b437b063ffe631cac3d6ce6aa62e3c3b8eb83a0dfceef542", + '4730440220068b4d98542760aeff6dd3b17958611c12cfe36ca23d1a2df42241b0c993286202202db64ad12f62fe0f13ed904d095c4ed06555e0632d9d55db50fabba7d0153aea412103021c8dd3baebdbc1b437b063ffe631cac3d6ce6aa62e3c3b8eb83a0dfceef542', asm: - "30440220068b4d98542760aeff6dd3b17958611c12cfe36ca23d1a2df42241b0c993286202202db64ad12f62fe0f13ed904d095c4ed06555e0632d9d55db50fabba7d0153aea[ALL|FORKID] 03021c8dd3baebdbc1b437b063ffe631cac3d6ce6aa62e3c3b8eb83a0dfceef542" + '30440220068b4d98542760aeff6dd3b17958611c12cfe36ca23d1a2df42241b0c993286202202db64ad12f62fe0f13ed904d095c4ed06555e0632d9d55db50fabba7d0153aea[ALL|FORKID] 03021c8dd3baebdbc1b437b063ffe631cac3d6ce6aa62e3c3b8eb83a0dfceef542' }, value: 546, - legacyAddress: "1Fy3KxcwycjXyjpcBMMxbiZwGxDgFmNeSw", - cashAddress: "bitcoincash:qzjz4l6fvdhgpjdfhs8gg8664en0l942p5sjf3lwh7", - slpAddress: "simpleledger:qzjz4l6fvdhgpjdfhs8gg8664en0l942p5ufz22wfq" + legacyAddress: '1Fy3KxcwycjXyjpcBMMxbiZwGxDgFmNeSw', + cashAddress: 'bitcoincash:qzjz4l6fvdhgpjdfhs8gg8664en0l942p5sjf3lwh7', + slpAddress: 'simpleledger:qzjz4l6fvdhgpjdfhs8gg8664en0l942p5ufz22wfq' }, { - txid: "50dd2b262bf60e605a4749f7187c6c6fe57af9067f07744d28df1602b7685d89", + txid: '50dd2b262bf60e605a4749f7187c6c6fe57af9067f07744d28df1602b7685d89', vout: 1, sequence: 4294967295, n: 1, scriptSig: { hex: - "483045022100f1de68dfab06aba82b10cf8d63be91a31e44087c624de01a63fc0bc209d637ed02200c5182100391a9b486b83cb3caa533451c84247594a5c2ceabfb3b0c9dc68bfd412103021c8dd3baebdbc1b437b063ffe631cac3d6ce6aa62e3c3b8eb83a0dfceef542", + '483045022100f1de68dfab06aba82b10cf8d63be91a31e44087c624de01a63fc0bc209d637ed02200c5182100391a9b486b83cb3caa533451c84247594a5c2ceabfb3b0c9dc68bfd412103021c8dd3baebdbc1b437b063ffe631cac3d6ce6aa62e3c3b8eb83a0dfceef542', asm: - "3045022100f1de68dfab06aba82b10cf8d63be91a31e44087c624de01a63fc0bc209d637ed02200c5182100391a9b486b83cb3caa533451c84247594a5c2ceabfb3b0c9dc68bfd[ALL|FORKID] 03021c8dd3baebdbc1b437b063ffe631cac3d6ce6aa62e3c3b8eb83a0dfceef542" + '3045022100f1de68dfab06aba82b10cf8d63be91a31e44087c624de01a63fc0bc209d637ed02200c5182100391a9b486b83cb3caa533451c84247594a5c2ceabfb3b0c9dc68bfd[ALL|FORKID] 03021c8dd3baebdbc1b437b063ffe631cac3d6ce6aa62e3c3b8eb83a0dfceef542' }, value: 546, - legacyAddress: "1Fy3KxcwycjXyjpcBMMxbiZwGxDgFmNeSw", - cashAddress: "bitcoincash:qzjz4l6fvdhgpjdfhs8gg8664en0l942p5sjf3lwh7", - slpAddress: "simpleledger:qzjz4l6fvdhgpjdfhs8gg8664en0l942p5ufz22wfq" + legacyAddress: '1Fy3KxcwycjXyjpcBMMxbiZwGxDgFmNeSw', + cashAddress: 'bitcoincash:qzjz4l6fvdhgpjdfhs8gg8664en0l942p5sjf3lwh7', + slpAddress: 'simpleledger:qzjz4l6fvdhgpjdfhs8gg8664en0l942p5ufz22wfq' }, { - txid: "d3ec152a06d1f9f474c22015f63deeaadf39a399b516d5e60eebe1ad3c9315ec", + txid: 'd3ec152a06d1f9f474c22015f63deeaadf39a399b516d5e60eebe1ad3c9315ec', vout: 1, sequence: 4294967295, n: 2, scriptSig: { hex: - "483045022100d8e0d89ad11bf281026463a34d4b1a7e4465cab43bc26f8cb0f6999cb359f7d1022052e74af271323259977bb55c116efbb7988b4f670119ba247f24a2a56f4ac063412103da9d0ed61cc8010a01ed9d8bc64230ba72afe0c0ffdae0195911fbe9aa3e0112", + '483045022100d8e0d89ad11bf281026463a34d4b1a7e4465cab43bc26f8cb0f6999cb359f7d1022052e74af271323259977bb55c116efbb7988b4f670119ba247f24a2a56f4ac063412103da9d0ed61cc8010a01ed9d8bc64230ba72afe0c0ffdae0195911fbe9aa3e0112', asm: - "3045022100d8e0d89ad11bf281026463a34d4b1a7e4465cab43bc26f8cb0f6999cb359f7d1022052e74af271323259977bb55c116efbb7988b4f670119ba247f24a2a56f4ac063[ALL|FORKID] 03da9d0ed61cc8010a01ed9d8bc64230ba72afe0c0ffdae0195911fbe9aa3e0112" + '3045022100d8e0d89ad11bf281026463a34d4b1a7e4465cab43bc26f8cb0f6999cb359f7d1022052e74af271323259977bb55c116efbb7988b4f670119ba247f24a2a56f4ac063[ALL|FORKID] 03da9d0ed61cc8010a01ed9d8bc64230ba72afe0c0ffdae0195911fbe9aa3e0112' }, value: 422955, - legacyAddress: "18TRupzu6qbvEJUFAwoWEsDBQXaQcmUdXk", - cashAddress: "bitcoincash:qpgusltsseyslth9azccyxel5gne2257fq0p9q2nkj", - slpAddress: "simpleledger:qpgusltsseyslth9azccyxel5gne2257fqr6wmlngv" + legacyAddress: '18TRupzu6qbvEJUFAwoWEsDBQXaQcmUdXk', + cashAddress: 'bitcoincash:qpgusltsseyslth9azccyxel5gne2257fq0p9q2nkj', + slpAddress: 'simpleledger:qpgusltsseyslth9azccyxel5gne2257fqr6wmlngv' } ], vout: [ { - value: "0.00000000", + value: '0.00000000', n: 0, scriptPubKey: { hex: - "6a04534c500001010453454e44207353603832726dc0bd67afaac2acdd0fbd9fbe562710a68fd1e88943211277fc0800000000000000ca", + '6a04534c500001010453454e44207353603832726dc0bd67afaac2acdd0fbd9fbe562710a68fd1e88943211277fc0800000000000000ca', asm: - "OP_RETURN 5262419 1 1145980243 7353603832726dc0bd67afaac2acdd0fbd9fbe562710a68fd1e88943211277fc 00000000000000ca" + 'OP_RETURN 5262419 1 1145980243 7353603832726dc0bd67afaac2acdd0fbd9fbe562710a68fd1e88943211277fc 00000000000000ca' }, spentTxId: null, spentIndex: null, spentHeight: null }, { - value: "0.00000546", + value: '0.00000546', n: 1, scriptPubKey: { - hex: "76a9140c036a1ee180c958f97afa5a8a6272ab47091fbd88ac", + hex: '76a9140c036a1ee180c958f97afa5a8a6272ab47091fbd88ac', asm: - "OP_DUP OP_HASH160 0c036a1ee180c958f97afa5a8a6272ab47091fbd OP_EQUALVERIFY OP_CHECKSIG", - addresses: ["126XCYnDwqMBXfQTvsTfpYRwX59moZUZDS"], - type: "pubkeyhash", - cashAddrs: ["bitcoincash:qqxqx6s7uxqvjk8e0ta94znzw245wzglh5h9wdssan"], - slpAddrs: ["simpleledger:qqxqx6s7uxqvjk8e0ta94znzw245wzglh5m79k9srd"] + 'OP_DUP OP_HASH160 0c036a1ee180c958f97afa5a8a6272ab47091fbd OP_EQUALVERIFY OP_CHECKSIG', + addresses: ['126XCYnDwqMBXfQTvsTfpYRwX59moZUZDS'], + type: 'pubkeyhash', + cashAddrs: ['bitcoincash:qqxqx6s7uxqvjk8e0ta94znzw245wzglh5h9wdssan'], + slpAddrs: ['simpleledger:qqxqx6s7uxqvjk8e0ta94znzw245wzglh5m79k9srd'] }, spentTxId: null, spentIndex: null, spentHeight: null }, { - value: "0.00422880", + value: '0.00422880', n: 2, scriptPubKey: { - hex: "76a91451c87d7086490faee5e8b1821b3fa227952a9e4888ac", + hex: '76a91451c87d7086490faee5e8b1821b3fa227952a9e4888ac', asm: - "OP_DUP OP_HASH160 51c87d7086490faee5e8b1821b3fa227952a9e48 OP_EQUALVERIFY OP_CHECKSIG", - addresses: ["18TRupzu6qbvEJUFAwoWEsDBQXaQcmUdXk"], - type: "pubkeyhash", - cashAddrs: ["bitcoincash:qpgusltsseyslth9azccyxel5gne2257fq0p9q2nkj"], - slpAddrs: ["simpleledger:qpgusltsseyslth9azccyxel5gne2257fqr6wmlngv"] + 'OP_DUP OP_HASH160 51c87d7086490faee5e8b1821b3fa227952a9e48 OP_EQUALVERIFY OP_CHECKSIG', + addresses: ['18TRupzu6qbvEJUFAwoWEsDBQXaQcmUdXk'], + type: 'pubkeyhash', + cashAddrs: ['bitcoincash:qpgusltsseyslth9azccyxel5gne2257fq0p9q2nkj'], + slpAddrs: ['simpleledger:qpgusltsseyslth9azccyxel5gne2257fqr6wmlngv'] }, spentTxId: null, spentIndex: null, spentHeight: null } ], - blockhash: "0000000000000000028713785942eddfd39daa60e8768b9b0513ff077d1ecd2f", + blockhash: '0000000000000000028713785942eddfd39daa60e8768b9b0513ff077d1ecd2f', blockheight: 600711, confirmations: 1668, time: 1568761257, @@ -907,69 +907,69 @@ const mockTxDetails = { fees: 0.00000621, tokenInfo: { versionType: 1, - transactionType: "SEND", + transactionType: 'SEND', tokenIdHex: - "7353603832726dc0bd67afaac2acdd0fbd9fbe562710a68fd1e88943211277fc", - sendOutputs: ["0", "202"] + '7353603832726dc0bd67afaac2acdd0fbd9fbe562710a68fd1e88943211277fc', + sendOutputs: ['0', '202'] }, tokenIsValid: true } const mockDualValidation = [ { - txid: "d56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56", + txid: 'd56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56', valid: true }, { - txid: "d56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56", + txid: 'd56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56', valid: true } ] const mockDualOpData = { tokenType: 1, - transactionType: "send", - tokenId: "dd84ca78db4d617221b58eabc6667af8fe2f7eadbfcc213d35be9f1b419beb8d", + transactionType: 'send', + tokenId: 'dd84ca78db4d617221b58eabc6667af8fe2f7eadbfcc213d35be9f1b419beb8d', spendData: [ { - quantity: "1", - sentTo: "bitcoincash:qqavn6wspzy7nsy7ex9dj9t7a8va7nv6ey05jkul6l", + quantity: '1', + sentTo: 'bitcoincash:qqavn6wspzy7nsy7ex9dj9t7a8va7nv6ey05jkul6l', vout: 1 }, { - quantity: "5", - sentTo: "bitcoincash:qpyx5hv7nhxk9cmug3vp7jnasdt8akselvteqypm9m", + quantity: '5', + sentTo: 'bitcoincash:qpyx5hv7nhxk9cmug3vp7jnasdt8akselvteqypm9m', vout: 2 } ] } const mockInvalidSlpSend = { - txid: "a60a522cc11ad7011b74e57fbabbd99296e4b9346bcb175dcf84efb737030415", - hash: "a60a522cc11ad7011b74e57fbabbd99296e4b9346bcb175dcf84efb737030415", + txid: 'a60a522cc11ad7011b74e57fbabbd99296e4b9346bcb175dcf84efb737030415', + hash: 'a60a522cc11ad7011b74e57fbabbd99296e4b9346bcb175dcf84efb737030415', version: 2, size: 473, locktime: 0, vin: [ { - txid: "3ad621d46ddb7bdccb6e5e7b6505ee639d9327a2b2bdaa2937b8e3aa55c4f2a7", + txid: '3ad621d46ddb7bdccb6e5e7b6505ee639d9327a2b2bdaa2937b8e3aa55c4f2a7', vout: 0, scriptSig: { asm: - "3045022100f962fdc585261007f114f0470828bbe9ac6197cefc4d0897fe4a7dd1d4cb2f5402202e104b617a1c14fc293c0ace9d4fd5e1cfa819a68b4ff976b4c3c199feda5227[ALL|FORKID] 0351c450ded2d7747dcad69982c9d954f3f785bab018d89fa09723bba7397e91fb", + '3045022100f962fdc585261007f114f0470828bbe9ac6197cefc4d0897fe4a7dd1d4cb2f5402202e104b617a1c14fc293c0ace9d4fd5e1cfa819a68b4ff976b4c3c199feda5227[ALL|FORKID] 0351c450ded2d7747dcad69982c9d954f3f785bab018d89fa09723bba7397e91fb', hex: - "483045022100f962fdc585261007f114f0470828bbe9ac6197cefc4d0897fe4a7dd1d4cb2f5402202e104b617a1c14fc293c0ace9d4fd5e1cfa819a68b4ff976b4c3c199feda522741210351c450ded2d7747dcad69982c9d954f3f785bab018d89fa09723bba7397e91fb" + '483045022100f962fdc585261007f114f0470828bbe9ac6197cefc4d0897fe4a7dd1d4cb2f5402202e104b617a1c14fc293c0ace9d4fd5e1cfa819a68b4ff976b4c3c199feda522741210351c450ded2d7747dcad69982c9d954f3f785bab018d89fa09723bba7397e91fb' }, sequence: 4294967295 }, { - txid: "a31c3167686f892d835727bc46b74bb11a46d74a8a6b08dc6cd82abb6e987b43", + txid: 'a31c3167686f892d835727bc46b74bb11a46d74a8a6b08dc6cd82abb6e987b43', vout: 1, scriptSig: { asm: - "3044022027dcd4ef752819ba4e61b892039ea0cb8d3ab0ffaeb78384dce9cf43dd76967e0220594fdf41e3d26cd207b6df939e3d655f6e09b01f05948edeb096aa644e1b6ec4[ALL|FORKID] 0351c450ded2d7747dcad69982c9d954f3f785bab018d89fa09723bba7397e91fb", + '3044022027dcd4ef752819ba4e61b892039ea0cb8d3ab0ffaeb78384dce9cf43dd76967e0220594fdf41e3d26cd207b6df939e3d655f6e09b01f05948edeb096aa644e1b6ec4[ALL|FORKID] 0351c450ded2d7747dcad69982c9d954f3f785bab018d89fa09723bba7397e91fb', hex: - "473044022027dcd4ef752819ba4e61b892039ea0cb8d3ab0ffaeb78384dce9cf43dd76967e0220594fdf41e3d26cd207b6df939e3d655f6e09b01f05948edeb096aa644e1b6ec441210351c450ded2d7747dcad69982c9d954f3f785bab018d89fa09723bba7397e91fb" + '473044022027dcd4ef752819ba4e61b892039ea0cb8d3ab0ffaeb78384dce9cf43dd76967e0220594fdf41e3d26cd207b6df939e3d655f6e09b01f05948edeb096aa644e1b6ec441210351c450ded2d7747dcad69982c9d954f3f785bab018d89fa09723bba7397e91fb' }, sequence: 4294967295 } @@ -980,10 +980,10 @@ const mockInvalidSlpSend = { n: 0, scriptPubKey: { asm: - "OP_RETURN 5262419 1 1145980243 091c80cee60cc3a6dd7b8c6c04cf0cf2d8103ba2d75daa105dcf1aaa53551fe8 1 fffffffffffffffe", + 'OP_RETURN 5262419 1 1145980243 091c80cee60cc3a6dd7b8c6c04cf0cf2d8103ba2d75daa105dcf1aaa53551fe8 1 fffffffffffffffe', hex: - "6a04534c500001010453454e4420091c80cee60cc3a6dd7b8c6c04cf0cf2d8103ba2d75daa105dcf1aaa53551fe8010108fffffffffffffffe", - type: "nulldata" + '6a04534c500001010453454e4420091c80cee60cc3a6dd7b8c6c04cf0cf2d8103ba2d75daa105dcf1aaa53551fe8010108fffffffffffffffe', + type: 'nulldata' } }, { @@ -991,11 +991,11 @@ const mockInvalidSlpSend = { n: 1, scriptPubKey: { asm: - "OP_DUP OP_HASH160 c0c53d84b5420c9bfe4015d1ae69017c3f1ddef8 OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a914c0c53d84b5420c9bfe4015d1ae69017c3f1ddef888ac", + 'OP_DUP OP_HASH160 c0c53d84b5420c9bfe4015d1ae69017c3f1ddef8 OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a914c0c53d84b5420c9bfe4015d1ae69017c3f1ddef888ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qrqv20vyk4pqexl7gq2artnfq97r78w7lqj5548mny"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qrqv20vyk4pqexl7gq2artnfq97r78w7lqj5548mny'] } }, { @@ -1003,11 +1003,11 @@ const mockInvalidSlpSend = { n: 2, scriptPubKey: { asm: - "OP_DUP OP_HASH160 b505afc357a7e911b207332f13e8e674a72099c3 OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a914b505afc357a7e911b207332f13e8e674a72099c388ac", + 'OP_DUP OP_HASH160 b505afc357a7e911b207332f13e8e674a72099c3 OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a914b505afc357a7e911b207332f13e8e674a72099c388ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qz6stt7r27n7jydjquej7ylgue62wgyecvs9zm4gff"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qz6stt7r27n7jydjquej7ylgue62wgyecvs9zm4gff'] } }, { @@ -1015,37 +1015,37 @@ const mockInvalidSlpSend = { n: 3, scriptPubKey: { asm: - "OP_DUP OP_HASH160 b505afc357a7e911b207332f13e8e674a72099c3 OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a914b505afc357a7e911b207332f13e8e674a72099c388ac", + 'OP_DUP OP_HASH160 b505afc357a7e911b207332f13e8e674a72099c3 OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a914b505afc357a7e911b207332f13e8e674a72099c388ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qz6stt7r27n7jydjquej7ylgue62wgyecvs9zm4gff"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qz6stt7r27n7jydjquej7ylgue62wgyecvs9zm4gff'] } } ], hex: - "0200000002a7f2c455aae3b83729aabdb2a227939d63ee05657b5e6ecbdc7bdb6dd421d63a000000006b483045022100f962fdc585261007f114f0470828bbe9ac6197cefc4d0897fe4a7dd1d4cb2f5402202e104b617a1c14fc293c0ace9d4fd5e1cfa819a68b4ff976b4c3c199feda522741210351c450ded2d7747dcad69982c9d954f3f785bab018d89fa09723bba7397e91fbffffffff437b986ebb2ad86cdc086b8a4ad7461ab14bb746bc2757832d896f6867311ca3010000006a473044022027dcd4ef752819ba4e61b892039ea0cb8d3ab0ffaeb78384dce9cf43dd76967e0220594fdf41e3d26cd207b6df939e3d655f6e09b01f05948edeb096aa644e1b6ec441210351c450ded2d7747dcad69982c9d954f3f785bab018d89fa09723bba7397e91fbffffffff040000000000000000396a04534c500001010453454e4420091c80cee60cc3a6dd7b8c6c04cf0cf2d8103ba2d75daa105dcf1aaa53551fe8010108fffffffffffffffe22020000000000001976a914c0c53d84b5420c9bfe4015d1ae69017c3f1ddef888ac22020000000000001976a914b505afc357a7e911b207332f13e8e674a72099c388ac3bac0000000000001976a914b505afc357a7e911b207332f13e8e674a72099c388ac00000000", - blockhash: "000000000000000000915bd33a7241f34800b190f7cf51f90b42b2b05d2b7ed8", + '0200000002a7f2c455aae3b83729aabdb2a227939d63ee05657b5e6ecbdc7bdb6dd421d63a000000006b483045022100f962fdc585261007f114f0470828bbe9ac6197cefc4d0897fe4a7dd1d4cb2f5402202e104b617a1c14fc293c0ace9d4fd5e1cfa819a68b4ff976b4c3c199feda522741210351c450ded2d7747dcad69982c9d954f3f785bab018d89fa09723bba7397e91fbffffffff437b986ebb2ad86cdc086b8a4ad7461ab14bb746bc2757832d896f6867311ca3010000006a473044022027dcd4ef752819ba4e61b892039ea0cb8d3ab0ffaeb78384dce9cf43dd76967e0220594fdf41e3d26cd207b6df939e3d655f6e09b01f05948edeb096aa644e1b6ec441210351c450ded2d7747dcad69982c9d954f3f785bab018d89fa09723bba7397e91fbffffffff040000000000000000396a04534c500001010453454e4420091c80cee60cc3a6dd7b8c6c04cf0cf2d8103ba2d75daa105dcf1aaa53551fe8010108fffffffffffffffe22020000000000001976a914c0c53d84b5420c9bfe4015d1ae69017c3f1ddef888ac22020000000000001976a914b505afc357a7e911b207332f13e8e674a72099c388ac3bac0000000000001976a914b505afc357a7e911b207332f13e8e674a72099c388ac00000000', + blockhash: '000000000000000000915bd33a7241f34800b190f7cf51f90b42b2b05d2b7ed8', confirmations: 90327, time: 1535577007, blocktime: 1535577007 } const txDetailsSLPNftGenesis = { - txid: "4ef6eb92950a13a69e97c2c02c7967d806aa874c0e2a6b5546a8880f2cd14bc4", - hash: "4ef6eb92950a13a69e97c2c02c7967d806aa874c0e2a6b5546a8880f2cd14bc4", + txid: '4ef6eb92950a13a69e97c2c02c7967d806aa874c0e2a6b5546a8880f2cd14bc4', + hash: '4ef6eb92950a13a69e97c2c02c7967d806aa874c0e2a6b5546a8880f2cd14bc4', version: 2, size: 344, locktime: 0, vin: [ { - txid: "4041bc842554b796de1dbb625bbb6994379bc5132a47522677bef7323f3e5051", + txid: '4041bc842554b796de1dbb625bbb6994379bc5132a47522677bef7323f3e5051', vout: 2, scriptSig: { asm: - "3045022100f8d678e7cd6a2fc317fe4c0c8b633f5941aa40bceb6d7472559955908869544b02206d82e45a6658bb9b5ad39734aa93832b1de2d3c9650e1b59c2ee2f15aa26f3bb[ALL|FORKID] 029547345d63f86ea89ea92ea4ed26386c4493ff60c78d871cc7b38f517f3fd72c", + '3045022100f8d678e7cd6a2fc317fe4c0c8b633f5941aa40bceb6d7472559955908869544b02206d82e45a6658bb9b5ad39734aa93832b1de2d3c9650e1b59c2ee2f15aa26f3bb[ALL|FORKID] 029547345d63f86ea89ea92ea4ed26386c4493ff60c78d871cc7b38f517f3fd72c', hex: - "483045022100f8d678e7cd6a2fc317fe4c0c8b633f5941aa40bceb6d7472559955908869544b02206d82e45a6658bb9b5ad39734aa93832b1de2d3c9650e1b59c2ee2f15aa26f3bb4121029547345d63f86ea89ea92ea4ed26386c4493ff60c78d871cc7b38f517f3fd72c" + '483045022100f8d678e7cd6a2fc317fe4c0c8b633f5941aa40bceb6d7472559955908869544b02206d82e45a6658bb9b5ad39734aa93832b1de2d3c9650e1b59c2ee2f15aa26f3bb4121029547345d63f86ea89ea92ea4ed26386c4493ff60c78d871cc7b38f517f3fd72c' }, sequence: 4294967295 } @@ -1056,10 +1056,10 @@ const txDetailsSLPNftGenesis = { n: 0, scriptPubKey: { asm: - "OP_RETURN 5262419 -1 47454e45534953 4e46545454 4e4654205465737420546f6b656e 68747470733a2f2f46756c6c537461636b2e63617368 0 0 2 0000000000000001", + 'OP_RETURN 5262419 -1 47454e45534953 4e46545454 4e4654205465737420546f6b656e 68747470733a2f2f46756c6c537461636b2e63617368 0 0 2 0000000000000001', hex: - "6a04534c500001810747454e45534953054e465454540e4e4654205465737420546f6b656e1668747470733a2f2f46756c6c537461636b2e636173684c0001000102080000000000000001", - type: "nulldata" + '6a04534c500001810747454e45534953054e465454540e4e4654205465737420546f6b656e1668747470733a2f2f46756c6c537461636b2e636173684c0001000102080000000000000001', + type: 'nulldata' } }, { @@ -1067,11 +1067,11 @@ const txDetailsSLPNftGenesis = { n: 1, scriptPubKey: { asm: - "OP_DUP OP_HASH160 6011206cd60db8b634f85edf46da22a6d1351e54 OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a9146011206cd60db8b634f85edf46da22a6d1351e5488ac", + 'OP_DUP OP_HASH160 6011206cd60db8b634f85edf46da22a6d1351e54 OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a9146011206cd60db8b634f85edf46da22a6d1351e5488ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qpspzgrv6cxm3d35lp0d73k6y2ndzdg72s2304ttr8"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qpspzgrv6cxm3d35lp0d73k6y2ndzdg72s2304ttr8'] } }, { @@ -1079,11 +1079,11 @@ const txDetailsSLPNftGenesis = { n: 2, scriptPubKey: { asm: - "OP_DUP OP_HASH160 6011206cd60db8b634f85edf46da22a6d1351e54 OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a9146011206cd60db8b634f85edf46da22a6d1351e5488ac", + 'OP_DUP OP_HASH160 6011206cd60db8b634f85edf46da22a6d1351e54 OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a9146011206cd60db8b634f85edf46da22a6d1351e5488ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qpspzgrv6cxm3d35lp0d73k6y2ndzdg72s2304ttr8"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qpspzgrv6cxm3d35lp0d73k6y2ndzdg72s2304ttr8'] } }, { @@ -1091,17 +1091,17 @@ const txDetailsSLPNftGenesis = { n: 3, scriptPubKey: { asm: - "OP_DUP OP_HASH160 6011206cd60db8b634f85edf46da22a6d1351e54 OP_EQUALVERIFY OP_CHECKSIG", - hex: "76a9146011206cd60db8b634f85edf46da22a6d1351e5488ac", + 'OP_DUP OP_HASH160 6011206cd60db8b634f85edf46da22a6d1351e54 OP_EQUALVERIFY OP_CHECKSIG', + hex: '76a9146011206cd60db8b634f85edf46da22a6d1351e5488ac', reqSigs: 1, - type: "pubkeyhash", - addresses: ["bitcoincash:qpspzgrv6cxm3d35lp0d73k6y2ndzdg72s2304ttr8"] + type: 'pubkeyhash', + addresses: ['bitcoincash:qpspzgrv6cxm3d35lp0d73k6y2ndzdg72s2304ttr8'] } } ], hex: - "020000000151503e3f32f7be772652472a13c59b379469bb5b62bb1dde96b7542584bc4140020000006b483045022100f8d678e7cd6a2fc317fe4c0c8b633f5941aa40bceb6d7472559955908869544b02206d82e45a6658bb9b5ad39734aa93832b1de2d3c9650e1b59c2ee2f15aa26f3bb4121029547345d63f86ea89ea92ea4ed26386c4493ff60c78d871cc7b38f517f3fd72cffffffff0400000000000000004b6a04534c500001810747454e45534953054e465454540e4e4654205465737420546f6b656e1668747470733a2f2f46756c6c537461636b2e636173684c000100010208000000000000000122020000000000001976a9146011206cd60db8b634f85edf46da22a6d1351e5488ac22020000000000001976a9146011206cd60db8b634f85edf46da22a6d1351e5488ac043d0000000000001976a9146011206cd60db8b634f85edf46da22a6d1351e5488ac00000000", - blockhash: "000000000000000002405a44302888bc29bf0e9f4d99b97303038bcc83c15e33", + '020000000151503e3f32f7be772652472a13c59b379469bb5b62bb1dde96b7542584bc4140020000006b483045022100f8d678e7cd6a2fc317fe4c0c8b633f5941aa40bceb6d7472559955908869544b02206d82e45a6658bb9b5ad39734aa93832b1de2d3c9650e1b59c2ee2f15aa26f3bb4121029547345d63f86ea89ea92ea4ed26386c4493ff60c78d871cc7b38f517f3fd72cffffffff0400000000000000004b6a04534c500001810747454e45534953054e465454540e4e4654205465737420546f6b656e1668747470733a2f2f46756c6c537461636b2e636173684c000100010208000000000000000122020000000000001976a9146011206cd60db8b634f85edf46da22a6d1351e5488ac22020000000000001976a9146011206cd60db8b634f85edf46da22a6d1351e5488ac043d0000000000001976a9146011206cd60db8b634f85edf46da22a6d1351e5488ac00000000', + blockhash: '000000000000000002405a44302888bc29bf0e9f4d99b97303038bcc83c15e33', confirmations: 2, time: 1591329189, blocktime: 1591329189 @@ -1109,123 +1109,123 @@ const txDetailsSLPNftGenesis = { const mockWhitelist = [ { - name: "USDH", - tokenId: "c4b0d62156b3fa5c8f3436079b5394f7edc1bef5dc1cd2f9d0c4d46f82cca479" + name: 'USDH', + tokenId: 'c4b0d62156b3fa5c8f3436079b5394f7edc1bef5dc1cd2f9d0c4d46f82cca479' }, { - name: "SPICE", - tokenId: "4de69e374a8ed21cbddd47f2338cc0f479dc58daa2bbe11cd604ca488eca0ddf" + name: 'SPICE', + tokenId: '4de69e374a8ed21cbddd47f2338cc0f479dc58daa2bbe11cd604ca488eca0ddf' }, { - name: "PSF", - tokenId: "38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0" + name: 'PSF', + tokenId: '38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0' }, { - name: "TROUT", - tokenId: "a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2" + name: 'TROUT', + tokenId: 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2' }, { - name: "PSFTEST", - tokenId: "d0ef4de95b78222bfee2326ab11382f4439aa0855936e2fe6ac129a8d778baa0" + name: 'PSFTEST', + tokenId: 'd0ef4de95b78222bfee2326ab11382f4439aa0855936e2fe6ac129a8d778baa0' } ] const mockValidateTxid3Valid = [ { - txid: "daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd", + txid: 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd', valid: true } ] const mockValidateTxid3Invalid = [ { - txid: "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a", + txid: 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a', valid: null } ] const mockValidateTxidArray = [ { - txid: "daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd", + txid: 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd', valid: true }, { - txid: "3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488", + txid: '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488', valid: true }, { - txid: "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a", + txid: 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a', valid: false }, { - txid: "01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0", + txid: '01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0', valid: false } ] const whitelist = [ { - name: "USDH", - tokenId: "c4b0d62156b3fa5c8f3436079b5394f7edc1bef5dc1cd2f9d0c4d46f82cca479" + name: 'USDH', + tokenId: 'c4b0d62156b3fa5c8f3436079b5394f7edc1bef5dc1cd2f9d0c4d46f82cca479' }, { - name: "SPICE", - tokenId: "4de69e374a8ed21cbddd47f2338cc0f479dc58daa2bbe11cd604ca488eca0ddf" + name: 'SPICE', + tokenId: '4de69e374a8ed21cbddd47f2338cc0f479dc58daa2bbe11cd604ca488eca0ddf' }, { - name: "PSF", - tokenId: "38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0" + name: 'PSF', + tokenId: '38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0' }, { - name: "TROUT", - tokenId: "a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2" + name: 'TROUT', + tokenId: 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2' }, { - name: "PSFTEST", - tokenId: "d0ef4de95b78222bfee2326ab11382f4439aa0855936e2fe6ac129a8d778baa0" + name: 'PSFTEST', + tokenId: 'd0ef4de95b78222bfee2326ab11382f4439aa0855936e2fe6ac129a8d778baa0' }, { - name: "TOK-CH", - tokenId: "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7" + name: 'TOK-CH', + tokenId: '497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7' } ] const slpdbStatus = { - _id: "5fe4cd90cd2bd2000f7fe46c", - version: "1.0.0-beta-rc13", - versionHash: "bb4a805610b9e4d67c1595b716df36190c75e8b1", + _id: '5fe4cd90cd2bd2000f7fe46c', + version: '1.0.0-beta-rc13', + versionHash: 'bb4a805610b9e4d67c1595b716df36190c75e8b1', deplVersionHash: null, - startCmd: "node index run", - context: "SLPDB", + startCmd: 'node index run', + context: 'SLPDB', lastStatusUpdate: { - utc: "Thu, 24 Dec 2020 17:19:12 GMT", + utc: 'Thu, 24 Dec 2020 17:19:12 GMT', unix: 1608830352 }, lastIncomingTxnZmq: { - utc: "Thu, 24 Dec 2020 17:19:12 GMT", + utc: 'Thu, 24 Dec 2020 17:19:12 GMT', unix: 1608830352 }, lastIncomingBlockZmq: { - utc: "Thu, 24 Dec 2020 16:43:38 GMT", + utc: 'Thu, 24 Dec 2020 16:43:38 GMT', unix: 1608828218 }, lastOutgoingTxnZmq: null, lastOutgoingBlockZmq: null, - state: "RUNNING", + state: 'RUNNING', stateHistory: [ { - utc: "Mon, 07 Dec 2020 15:26:23 GMT", - state: "STARTUP_BLOCK_SYNC" + utc: 'Mon, 07 Dec 2020 15:26:23 GMT', + state: 'STARTUP_BLOCK_SYNC' }, { - utc: "Tue, 08 Dec 2020 19:53:04 GMT", - state: "RUNNING" + utc: 'Tue, 08 Dec 2020 19:53:04 GMT', + state: 'RUNNING' } ], - network: "mainnet", + network: 'mainnet', bchBlockHeight: 667270, bchBlockHash: - "000000000000000003d57b35b1b6b8073c8311974e2b9a473e1bd6daa98fde53", + '000000000000000003d57b35b1b6b8073c8311974e2b9a473e1bd6daa98fde53', slpProcessedBlockHeight: 667270, mempoolInfoBch: { loaded: true, @@ -1239,20 +1239,20 @@ const slpdbStatus = { mempoolSizeSlp: 78, tokensCount: 77976, pastStackTraces: [ - "[Tue, 08 Dec 2020 19:35:36 GMT] MongoServerSelectionError: connection to 172.17.0.1:12301 timed out\n at Timeout._onTimeout (/home/safeuser/SLPDB/node_modules/mongodb/lib/core/sdam/topology.js:438:30)\n at listOnTimeout (internal/timers.js:554:17)\n at processTimers (internal/timers.js:497:7)", - "[Tue, 08 Dec 2020 19:35:36 GMT] MongoServerSelectionError: connection to 172.17.0.1:12301 timed out\n at Timeout._onTimeout (/home/safeuser/SLPDB/node_modules/mongodb/lib/core/sdam/topology.js:438:30)\n at listOnTimeout (internal/timers.js:554:17)\n at processTimers (internal/timers.js:497:7)" + '[Tue, 08 Dec 2020 19:35:36 GMT] MongoServerSelectionError: connection to 172.17.0.1:12301 timed out\n at Timeout._onTimeout (/home/safeuser/SLPDB/node_modules/mongodb/lib/core/sdam/topology.js:438:30)\n at listOnTimeout (internal/timers.js:554:17)\n at processTimers (internal/timers.js:497:7)', + '[Tue, 08 Dec 2020 19:35:36 GMT] MongoServerSelectionError: connection to 172.17.0.1:12301 timed out\n at Timeout._onTimeout (/home/safeuser/SLPDB/node_modules/mongodb/lib/core/sdam/topology.js:438:30)\n at listOnTimeout (internal/timers.js:554:17)\n at processTimers (internal/timers.js:497:7)' ], doubleSpends: [ { txo: - "3e377f67e9d065f02e47633d847cdb04b0679d51baccdc0feea5297529e330b5:820", + '3e377f67e9d065f02e47633d847cdb04b0679d51baccdc0feea5297529e330b5:820', details: { originalTxid: - "dc148149d25a546fffe0b207c62b192811c288481df5f43f1f76f67b6004f98c", + 'dc148149d25a546fffe0b207c62b192811c288481df5f43f1f76f67b6004f98c', current: - "de12db60e253c378eeebb1df85153168a998db8267ec54b38589cc31348b2b8d", + 'de12db60e253c378eeebb1df85153168a998db8267ec54b38589cc31348b2b8d', time: { - utc: "Sat, 19 Dec 2020 02:25:37 GMT", + utc: 'Sat, 19 Dec 2020 02:25:37 GMT', unix: 1608344737 } } @@ -1260,7 +1260,7 @@ const slpdbStatus = { ], reorgs: [], mongoDbStats: { - db: "slpdb", + db: 'slpdb', collections: 5, views: 0, objects: 2497140, @@ -1275,13 +1275,13 @@ const slpdbStatus = { fsTotalSize: 153676.98046875, ok: 1 }, - publicUrl: "fullstack--bchn-02", + publicUrl: 'fullstack--bchn-02', telemetryHash: null, system: { loadAvg1: 0.16, loadAvg5: 0.11, loadAvg15: 0.04, - platform: "linux", + platform: 'linux', cpuCount: 8, freeMem: 5780.51953125, totalMem: 31360.8828125, diff --git a/test/unit/generating.js b/test/unit/generating.js index 068d68f..50e869b 100644 --- a/test/unit/generating.js +++ b/test/unit/generating.js @@ -1,31 +1,31 @@ // Public npm libraries -const assert = require("assert") -const axios = require("axios") -const sinon = require("sinon") +const assert = require('assert') +const axios = require('axios') +const sinon = require('sinon') // Unit under test (uut) -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') // const bchjs = new BCHJS() let bchjs -describe("#Generating", () => { +describe('#Generating', () => { beforeEach(() => { bchjs = new BCHJS() }) - describe("#generateToAddress", () => { + describe('#generateToAddress', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) - it("should generate", done => { + it('should generate', done => { const data = [] const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "post").returns(resolved) + sandbox.stub(axios, 'post').returns(resolved) bchjs.Generating.generateToAddress( 1, - "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf" + 'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf' ) .then(result => { assert.deepEqual(data, result) diff --git a/test/unit/hdnode.js b/test/unit/hdnode.js index e5c7792..e24774d 100644 --- a/test/unit/hdnode.js +++ b/test/unit/hdnode.js @@ -1,23 +1,23 @@ // Public npm libraries -const assert = require("assert") -const Buffer = require("safe-buffer").Buffer +const assert = require('assert') +const Buffer = require('safe-buffer').Buffer // Mocks -const fixtures = require("./fixtures/hdnode.json") -const slpFixtures = require("./fixtures/slp/address.json") +const fixtures = require('./fixtures/hdnode.json') +const slpFixtures = require('./fixtures/slp/address.json') // Unit under test (uut) -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') let bchjs -describe("#HDNode", () => { +describe('#HDNode', () => { beforeEach(() => { bchjs = new BCHJS() }) - describe("#fromSeed", () => { + describe('#fromSeed', () => { fixtures.fromSeed.forEach(mnemonic => { - it(`should create an HDNode from root seed buffer`, async () => { + it('should create an HDNode from root seed buffer', async () => { const rootSeedBuffer = await bchjs.Mnemonic.toSeed(mnemonic) const hdNode = bchjs.HDNode.fromSeed(rootSeedBuffer) assert.notEqual(hdNode, null) @@ -25,9 +25,9 @@ describe("#HDNode", () => { }) }) - describe("#derive", () => { + describe('#derive', () => { fixtures.derive.forEach(derive => { - it(`should derive non hardened child HDNode`, async () => { + it('should derive non hardened child HDNode', async () => { const rootSeedBuffer = await bchjs.Mnemonic.toSeed(derive.mnemonic) const hdNode = bchjs.HDNode.fromSeed(rootSeedBuffer) const childHDNode = bchjs.HDNode.derive(hdNode, 0) @@ -37,9 +37,9 @@ describe("#HDNode", () => { }) }) - describe("#deriveHardened", () => { + describe('#deriveHardened', () => { fixtures.deriveHardened.forEach(derive => { - it(`should derive hardened child HDNode`, async () => { + it('should derive hardened child HDNode', async () => { const rootSeedBuffer = await bchjs.Mnemonic.toSeed(derive.mnemonic) const hdNode = bchjs.HDNode.fromSeed(rootSeedBuffer) const childHDNode = bchjs.HDNode.deriveHardened(hdNode, 0) @@ -48,9 +48,9 @@ describe("#HDNode", () => { }) }) - describe("derive BIP44 $BCH account", () => { + describe('derive BIP44 $BCH account', () => { fixtures.deriveBIP44.forEach(derive => { - it(`should derive BIP44 $BCH account`, async () => { + it('should derive BIP44 $BCH account', async () => { const rootSeedBuffer = await bchjs.Mnemonic.toSeed(derive.mnemonic) const hdNode = bchjs.HDNode.fromSeed(rootSeedBuffer) const purpose = bchjs.HDNode.deriveHardened(hdNode, 44) @@ -63,22 +63,22 @@ describe("#HDNode", () => { }) }) - describe("#derivePath", () => { - describe("derive non hardened Path", () => { + describe('#derivePath', () => { + describe('derive non hardened Path', () => { fixtures.derivePath.forEach(derive => { - it(`should derive non hardened child HDNode from path`, async () => { + it('should derive non hardened child HDNode from path', async () => { const rootSeedBuffer = await bchjs.Mnemonic.toSeed(derive.mnemonic) const hdNode = bchjs.HDNode.fromSeed(rootSeedBuffer) - const childHDNode = bchjs.HDNode.derivePath(hdNode, "0") + const childHDNode = bchjs.HDNode.derivePath(hdNode, '0') assert.equal(bchjs.HDNode.toXPub(childHDNode), derive.xpub) assert.equal(bchjs.HDNode.toXPriv(childHDNode), derive.xpriv) }) }) }) - describe("derive hardened Path", () => { + describe('derive hardened Path', () => { fixtures.deriveHardenedPath.forEach(derive => { - it(`should derive hardened child HDNode from path`, async () => { + it('should derive hardened child HDNode from path', async () => { const rootSeedBuffer = await bchjs.Mnemonic.toSeed(derive.mnemonic) const hdNode = bchjs.HDNode.fromSeed(rootSeedBuffer) const childHDNode = bchjs.HDNode.derivePath(hdNode, "0'") @@ -88,9 +88,9 @@ describe("#HDNode", () => { }) }) - describe("derive BIP44 $BCH account", () => { + describe('derive BIP44 $BCH account', () => { fixtures.deriveBIP44.forEach(derive => { - it(`should derive BIP44 $BCH account`, async () => { + it('should derive BIP44 $BCH account', async () => { const rootSeedBuffer = await bchjs.Mnemonic.toSeed(derive.mnemonic) const hdNode = bchjs.HDNode.fromSeed(rootSeedBuffer) const childHDNode = bchjs.HDNode.derivePath(hdNode, "44'/145'/0'") @@ -101,24 +101,24 @@ describe("#HDNode", () => { }) }) - describe("#toLegacyAddress", () => { + describe('#toLegacyAddress', () => { fixtures.toLegacyAddress.forEach(fixture => { it(`should get address ${fixture.address} from HDNode`, async () => { const rootSeedBuffer = await bchjs.Mnemonic.toSeed(fixture.mnemonic) const hdNode = bchjs.HDNode.fromSeed(rootSeedBuffer) - const childHDNode = bchjs.HDNode.derivePath(hdNode, "0") + const childHDNode = bchjs.HDNode.derivePath(hdNode, '0') const addy = bchjs.HDNode.toLegacyAddress(childHDNode) assert.equal(addy, fixture.address) }) }) }) - describe("#toCashAddress", () => { + describe('#toCashAddress', () => { fixtures.toCashAddress.forEach(fixture => { it(`should get address ${fixture.address} from HDNode`, async () => { const rootSeedBuffer = await bchjs.Mnemonic.toSeed(fixture.mnemonic) const hdNode = bchjs.HDNode.fromSeed(rootSeedBuffer) - const childHDNode = bchjs.HDNode.derivePath(hdNode, "0") + const childHDNode = bchjs.HDNode.derivePath(hdNode, '0') const addy = bchjs.HDNode.toCashAddress(childHDNode) assert.equal(addy, fixture.address) }) @@ -126,14 +126,14 @@ describe("#HDNode", () => { it(`should get address ${fixture.regtestAddress} from HDNode`, async () => { const rootSeedBuffer = await bchjs.Mnemonic.toSeed(fixture.mnemonic) const hdNode = bchjs.HDNode.fromSeed(rootSeedBuffer) - const childHDNode = bchjs.HDNode.derivePath(hdNode, "0") + const childHDNode = bchjs.HDNode.derivePath(hdNode, '0') const addr = bchjs.HDNode.toCashAddress(childHDNode, true) assert.equal(addr, fixture.regtestAddress) }) }) }) - describe("#toWIF", () => { + describe('#toWIF', () => { fixtures.toWIF.forEach(fixture => { it(`should get privateKeyWIF ${fixture.privateKeyWIF} from HDNode`, () => { const hdNode = bchjs.HDNode.fromXPriv(fixture.xpriv) @@ -142,7 +142,7 @@ describe("#HDNode", () => { }) }) - describe("#toXPub", () => { + describe('#toXPub', () => { fixtures.toXPub.forEach(fixture => { it(`should create xpub ${fixture.xpub} from an HDNode`, async () => { const rootSeedBuffer = await bchjs.Mnemonic.toSeed(fixture.mnemonic) @@ -153,7 +153,7 @@ describe("#HDNode", () => { }) }) - describe("#toXPriv", () => { + describe('#toXPriv', () => { fixtures.toXPriv.forEach(fixture => { it(`should create xpriv ${fixture.xpriv} from an HDNode`, async () => { const rootSeedBuffer = await bchjs.Mnemonic.toSeed(fixture.mnemonic) @@ -164,30 +164,30 @@ describe("#HDNode", () => { }) }) - describe("#toKeyPair", () => { + describe('#toKeyPair', () => { fixtures.toKeyPair.forEach(fixture => { - it(`should get ECPair from an HDNode`, async () => { + it('should get ECPair from an HDNode', async () => { const rootSeedBuffer = await bchjs.Mnemonic.toSeed(fixture.mnemonic) const hdNode = bchjs.HDNode.fromSeed(rootSeedBuffer) const keyPair = bchjs.HDNode.toKeyPair(hdNode) - assert.equal(typeof keyPair, "object") + assert.equal(typeof keyPair, 'object') }) }) }) - describe("#toPublicKey", () => { + describe('#toPublicKey', () => { fixtures.toPublicKey.forEach(fixture => { - it(`should create public key buffer from an HDNode`, async () => { + it('should create public key buffer from an HDNode', async () => { const rootSeedBuffer = await bchjs.Mnemonic.toSeed(fixture.mnemonic) const hdNode = bchjs.HDNode.fromSeed(rootSeedBuffer) const publicKeyBuffer = bchjs.HDNode.toPublicKey(hdNode) - assert.equal(typeof publicKeyBuffer, "object") + assert.equal(typeof publicKeyBuffer, 'object') }) }) }) - describe("#fromXPriv", () => { - it("should exercise fromXPriv", () => { + describe('#fromXPriv', () => { + it('should exercise fromXPriv', () => { fixtures.fromXPriv.forEach(fixture => { const hdNode = bchjs.HDNode.fromXPriv(fixture.xpriv) it(`should create HDNode from xpriv ${fixture.xpriv}`, () => { @@ -224,8 +224,8 @@ describe("#HDNode", () => { }) }) - describe("#fromXPub", () => { - it("should exercise fromXPub", () => { + describe('#fromXPub', () => { + it('should exercise fromXPub', () => { fixtures.fromXPub.forEach(fixture => { const hdNode = bchjs.HDNode.fromXPub(fixture.xpub) it(`should create HDNode from xpub ${fixture.xpub}`, () => { @@ -254,21 +254,21 @@ describe("#HDNode", () => { }) }) - describe("#bip32", () => { - it("should create accounts and addresses", () => { + describe('#bip32', () => { + it('should create accounts and addresses', () => { fixtures.accounts.forEach(async fixture => { const seedBuffer = await bchjs.Mnemonic.toSeed(fixture.mnemonic) console.log(`seedBuffer: ${seedBuffer.toString()}`) const hdNode = bchjs.HDNode.fromSeed(seedBuffer) const a = bchjs.HDNode.derivePath(hdNode, "0'") - const external = bchjs.HDNode.derivePath(a, "0") + const external = bchjs.HDNode.derivePath(a, '0') const account = bchjs.HDNode.createAccount([external]) - it(`#createAccount`, () => { + it('#createAccount', () => { assert.notEqual(account, null) }) - describe("#getChainAddress", () => { + describe('#getChainAddress', () => { const external1 = bchjs.Address.toCashAddress( account.getChainAddress(0) ) @@ -277,7 +277,7 @@ describe("#HDNode", () => { }) }) - describe("#nextChainAddress", () => { + describe('#nextChainAddress', () => { for (let i = 0; i < 4; i++) { const ex = bchjs.Address.toCashAddress(account.nextChainAddress(0)) it(`should create external change address ${ex}`, () => { @@ -289,22 +289,22 @@ describe("#HDNode", () => { }) }) - describe("#sign", () => { + describe('#sign', () => { fixtures.sign.forEach(fixture => { - it(`should sign 32 byte hash buffer`, () => { + it('should sign 32 byte hash buffer', () => { const hdnode = bchjs.HDNode.fromXPriv(fixture.privateKeyWIF) - const buf = Buffer.from(bchjs.Crypto.sha256(fixture.data), "hex") + const buf = Buffer.from(bchjs.Crypto.sha256(fixture.data), 'hex') const signatureBuf = bchjs.HDNode.sign(hdnode, buf) - assert.equal(typeof signatureBuf, "object") + assert.equal(typeof signatureBuf, 'object') }) }) }) - describe("#verify", () => { + describe('#verify', () => { fixtures.verify.forEach(fixture => { - it(`should verify signed 32 byte hash buffer`, () => { + it('should verify signed 32 byte hash buffer', () => { const hdnode1 = bchjs.HDNode.fromXPriv(fixture.privateKeyWIF1) - const buf = Buffer.from(bchjs.Crypto.sha256(fixture.data), "hex") + const buf = Buffer.from(bchjs.Crypto.sha256(fixture.data), 'hex') const signature = bchjs.HDNode.sign(hdnode1, buf) const verify = bchjs.HDNode.verify(hdnode1, buf, signature) assert.equal(verify, true) @@ -312,46 +312,46 @@ describe("#HDNode", () => { }) }) - describe("#isPublic", () => { + describe('#isPublic', () => { fixtures.isPublic.forEach(fixture => { - it(`should verify hdnode is public`, () => { + it('should verify hdnode is public', () => { const node = bchjs.HDNode.fromXPub(fixture.xpub) assert.equal(bchjs.HDNode.isPublic(node), true) }) }) fixtures.isPublic.forEach(fixture => { - it(`should verify hdnode is not public`, () => { + it('should verify hdnode is not public', () => { const node = bchjs.HDNode.fromXPriv(fixture.xpriv) assert.equal(bchjs.HDNode.isPublic(node), false) }) }) }) - describe("#isPrivate", () => { + describe('#isPrivate', () => { fixtures.isPrivate.forEach(fixture => { - it(`should verify hdnode is not private`, () => { + it('should verify hdnode is not private', () => { const node = bchjs.HDNode.fromXPub(fixture.xpub) assert.equal(bchjs.HDNode.isPrivate(node), false) }) }) fixtures.isPrivate.forEach(fixture => { - it(`should verify hdnode is private`, () => { + it('should verify hdnode is private', () => { const node = bchjs.HDNode.fromXPriv(fixture.xpriv) assert.equal(bchjs.HDNode.isPrivate(node), true) }) }) }) - describe("#toIdentifier", () => { + describe('#toIdentifier', () => { fixtures.toIdentifier.forEach(fixture => { - it(`should get identifier of hdnode`, () => { + it('should get identifier of hdnode', () => { const node = bchjs.HDNode.fromXPriv(fixture.xpriv) const publicKeyBuffer = bchjs.HDNode.toPublicKey(node) const hash160 = bchjs.Crypto.hash160(publicKeyBuffer) const identifier = bchjs.HDNode.toIdentifier(node) - assert.equal(identifier.toString("hex"), hash160.toString("hex")) + assert.equal(identifier.toString('hex'), hash160.toString('hex')) }) }) }) diff --git a/test/unit/ipfs.js b/test/unit/ipfs.js index 3c6ea3d..1207824 100644 --- a/test/unit/ipfs.js +++ b/test/unit/ipfs.js @@ -2,14 +2,14 @@ Unit tests for the IPFS Class. */ -const assert = require("chai").assert -const sinon = require("sinon") -const BCHJS = require("../../src/bch-js") +const assert = require('chai').assert +const sinon = require('sinon') +const BCHJS = require('../../src/bch-js') let bchjs -const mockData = require("./fixtures/ipfs-mock") +const mockData = require('./fixtures/ipfs-mock') -describe(`#IPFS`, () => { +describe('#IPFS', () => { let sandbox beforeEach(() => { @@ -20,203 +20,203 @@ describe(`#IPFS`, () => { afterEach(() => sandbox.restore()) - describe("#initUppy", () => { - it("should initialize uppy", () => { + describe('#initUppy', () => { + it('should initialize uppy', () => { bchjs.IPFS.initUppy() }) }) - describe("#createFileModelServer", () => { - it("should throw an error if file does not exist", async () => { + describe('#createFileModelServer', () => { + it('should throw an error if file does not exist', async () => { try { - const path = "/non-existant-file" + const path = '/non-existant-file' await bchjs.IPFS.createFileModelServer(path) - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { - //console.log(`err.message: ${err.message}`) - assert.include(err.message, `Could not find this file`) + // console.log(`err.message: ${err.message}`) + assert.include(err.message, 'Could not find this file') } }) - it("should create a new file model", async () => { + it('should create a new file model', async () => { const path = `${__dirname}/ipfs.js` sandbox - .stub(bchjs.IPFS.axios, "post") + .stub(bchjs.IPFS.axios, 'post') .resolves({ data: mockData.mockNewFileModel }) const result = await bchjs.IPFS.createFileModelServer(path) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "hostingCostBCH") - assert.property(result, "hostingCostUSD") - assert.property(result, "file") + assert.property(result, 'hostingCostBCH') + assert.property(result, 'hostingCostUSD') + assert.property(result, 'file') - assert.property(result.file, "payloadLink") - assert.property(result.file, "hasBeenPaid") - assert.property(result.file, "_id") - assert.property(result.file, "schemaVersion") - assert.property(result.file, "size") - assert.property(result.file, "fileName") - assert.property(result.file, "fileExtension") - assert.property(result.file, "createdTimestamp") - assert.property(result.file, "hostingCost") - assert.property(result.file, "walletIndex") - assert.property(result.file, "bchAddr") + assert.property(result.file, 'payloadLink') + assert.property(result.file, 'hasBeenPaid') + assert.property(result.file, '_id') + assert.property(result.file, 'schemaVersion') + assert.property(result.file, 'size') + assert.property(result.file, 'fileName') + assert.property(result.file, 'fileExtension') + assert.property(result.file, 'createdTimestamp') + assert.property(result.file, 'hostingCost') + assert.property(result.file, 'walletIndex') + assert.property(result.file, 'bchAddr') }) }) - describe("#uploadFileServer", () => { - it("should throw an error if file does not exist", async () => { + describe('#uploadFileServer', () => { + it('should throw an error if file does not exist', async () => { try { - const path = "/non-existant-file" + const path = '/non-existant-file' await bchjs.IPFS.uploadFileServer(path) - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { - //console.log(`err.message: ${err.message}`) - assert.include(err.message, `Could not find this file`) + // console.log(`err.message: ${err.message}`) + assert.include(err.message, 'Could not find this file') } }) - it("should throw an error if modelId is not included", async () => { + it('should throw an error if modelId is not included', async () => { try { const path = `${__dirname}/ipfs.js` await bchjs.IPFS.uploadFileServer(path) - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { - //console.log(`err.message: ${err.message}`) - assert.include(err.message, `Must include a file model ID`) + // console.log(`err.message: ${err.message}`) + assert.include(err.message, 'Must include a file model ID') } }) - it("Should throw error if the file was not uploaded", async () => { + it('Should throw error if the file was not uploaded', async () => { try { const mock = { successful: [], failed: [ { - id: "file id" + id: 'file id' } ] } - sandbox.stub(bchjs.IPFS.uppy, "upload").resolves(mock) + sandbox.stub(bchjs.IPFS.uppy, 'upload').resolves(mock) const path = `${__dirname}/ipfs.js` - await bchjs.IPFS.uploadFileServer(path, "5ec562319bfacc745e8d8a52") + await bchjs.IPFS.uploadFileServer(path, '5ec562319bfacc745e8d8a52') - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { - //console.log(err) - assert.include(err.message, `The file could not be uploaded`) + // console.log(err) + assert.include(err.message, 'The file could not be uploaded') } }) - it("should return file object if the file is uploaded", async () => { + it('should return file object if the file is uploaded', async () => { try { - sandbox.stub(bchjs.IPFS.uppy, "upload").resolves(mockData.uploadData) + sandbox.stub(bchjs.IPFS.uppy, 'upload').resolves(mockData.uploadData) const path = `${__dirname}/ipfs.js` const result = await bchjs.IPFS.uploadFileServer( path, - "5ec562319bfacc745e8d8a52" + '5ec562319bfacc745e8d8a52' ) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "schemaVersion") - assert.property(result, "size") - assert.property(result, "fileId") - assert.property(result, "fileName") - assert.property(result, "fileExtension") + assert.property(result, 'schemaVersion') + assert.property(result, 'size') + assert.property(result, 'fileId') + assert.property(result, 'fileName') + assert.property(result, 'fileExtension') } catch (err) { - //console.log(err) - assert.equal(true, false, "Unexpected result") + // console.log(err) + assert.equal(true, false, 'Unexpected result') } }) }) - describe("#getStatus", () => { - it("should throw an error if modelId is not included", async () => { + describe('#getStatus', () => { + it('should throw an error if modelId is not included', async () => { try { await bchjs.IPFS.getStatus() - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { - //console.log(`err.message: ${err.message}`) - assert.include(err.message, `Must include a file model ID`) + // console.log(`err.message: ${err.message}`) + assert.include(err.message, 'Must include a file model ID') } }) - it("should get data on an unpaid file", async () => { - const modelId = "5ec7392c2acfe57aa62e945a" + it('should get data on an unpaid file', async () => { + const modelId = '5ec7392c2acfe57aa62e945a' sandbox - .stub(bchjs.IPFS.axios, "get") + .stub(bchjs.IPFS.axios, 'get') .resolves({ data: mockData.unpaidFileData }) const result = await bchjs.IPFS.getStatus(modelId) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "hasBeenPaid") - assert.property(result, "satCost") - assert.property(result, "bchAddr") - assert.property(result, "ipfsHash") - assert.property(result, "fileId") - assert.property(result, "fileName") + assert.property(result, 'hasBeenPaid') + assert.property(result, 'satCost') + assert.property(result, 'bchAddr') + assert.property(result, 'ipfsHash') + assert.property(result, 'fileId') + assert.property(result, 'fileName') }) - it("should get data on an unpaid file", async () => { - const modelId = "5ec7392c2acfe57aa62e945a" + it('should get data on an unpaid file', async () => { + const modelId = '5ec7392c2acfe57aa62e945a' sandbox - .stub(bchjs.IPFS.axios, "get") + .stub(bchjs.IPFS.axios, 'get') .resolves({ data: mockData.paidFileData }) const result = await bchjs.IPFS.getStatus(modelId) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "hasBeenPaid") - assert.property(result, "satCost") - assert.property(result, "bchAddr") - assert.property(result, "ipfsHash") - assert.property(result, "fileId") - assert.property(result, "fileName") + assert.property(result, 'hasBeenPaid') + assert.property(result, 'satCost') + assert.property(result, 'bchAddr') + assert.property(result, 'ipfsHash') + assert.property(result, 'fileId') + assert.property(result, 'fileName') }) }) - describe("#createFileModelWeb", () => { - it("should throw an error if file is undefined", async () => { + describe('#createFileModelWeb', () => { + it('should throw an error if file is undefined', async () => { try { let file await bchjs.IPFS.createFileModelWeb(file) - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { - //console.log(`err.message: ${err.message}`) - assert.include(err.message, `File is required`) + // console.log(`err.message: ${err.message}`) + assert.include(err.message, 'File is required') } }) - it("should throw an error if file is empty", async () => { + it('should throw an error if file is empty', async () => { try { const file = {} await bchjs.IPFS.createFileModelWeb(file) - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { - //console.log(`err.message: ${err.message}`) + // console.log(`err.message: ${err.message}`) assert.include( err.message, - `File should have the property 'name' of string type` + 'File should have the property \'name\' of string type' ) } }) @@ -228,12 +228,12 @@ describe(`#IPFS`, () => { await bchjs.IPFS.createFileModelWeb(file) - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { - //console.log(`err.message: ${err.message}`) + // console.log(`err.message: ${err.message}`) assert.include( err.message, - `File should have the property 'name' of string type` + 'File should have the property \'name\' of string type' ) } }) @@ -241,80 +241,80 @@ describe(`#IPFS`, () => { it("should throw an error if 'size' property is not included", async () => { try { const file = { - name: "ipfs.js" + name: 'ipfs.js' } await bchjs.IPFS.createFileModelWeb(file) - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { - //console.log(`err.message: ${err.message}`) + // console.log(`err.message: ${err.message}`) assert.include( err.message, - `File should have the property 'size' of number type` + 'File should have the property \'size\' of number type' ) } }) - it("should create a new file model", async () => { + it('should create a new file model', async () => { const file = { - name: "ipfs.js", + name: 'ipfs.js', size: 5000, - type: "text/plain" + type: 'text/plain' } sandbox - .stub(bchjs.IPFS.axios, "post") + .stub(bchjs.IPFS.axios, 'post') .resolves({ data: mockData.mockNewFileModel }) const result = await bchjs.IPFS.createFileModelWeb(file) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "success") + assert.property(result, 'success') assert.equal(result.success, true) - assert.property(result, "hostingCostBCH") - assert.property(result, "hostingCostUSD") - assert.property(result, "file") + assert.property(result, 'hostingCostBCH') + assert.property(result, 'hostingCostUSD') + assert.property(result, 'file') - assert.property(result.file, "payloadLink") - assert.property(result.file, "hasBeenPaid") - assert.property(result.file, "_id") - assert.property(result.file, "schemaVersion") - assert.property(result.file, "size") - assert.property(result.file, "fileName") - assert.property(result.file, "fileExtension") - assert.property(result.file, "createdTimestamp") - assert.property(result.file, "hostingCost") - assert.property(result.file, "walletIndex") - assert.property(result.file, "bchAddr") + assert.property(result.file, 'payloadLink') + assert.property(result.file, 'hasBeenPaid') + assert.property(result.file, '_id') + assert.property(result.file, 'schemaVersion') + assert.property(result.file, 'size') + assert.property(result.file, 'fileName') + assert.property(result.file, 'fileExtension') + assert.property(result.file, 'createdTimestamp') + assert.property(result.file, 'hostingCost') + assert.property(result.file, 'walletIndex') + assert.property(result.file, 'bchAddr') }) }) - describe("#uploadFileWeb", () => { - it("should throw an error if file is undefined", async () => { + describe('#uploadFileWeb', () => { + it('should throw an error if file is undefined', async () => { try { let file await bchjs.IPFS.uploadFileWeb(file) - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { - //console.log(`err.message: ${err.message}`) - assert.include(err.message, `File is required`) + // console.log(`err.message: ${err.message}`) + assert.include(err.message, 'File is required') } }) - it("should throw an error if file is empty", async () => { + it('should throw an error if file is empty', async () => { try { const file = {} await bchjs.IPFS.uploadFileWeb(file) - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { - //console.log(`err.message: ${err.message}`) + // console.log(`err.message: ${err.message}`) assert.include( err.message, - `File should have the property 'name' of string type` + 'File should have the property \'name\' of string type' ) } }) @@ -322,121 +322,121 @@ describe(`#IPFS`, () => { try { const file = { size: 5000, - type: "text/plain" + type: 'text/plain' } await bchjs.IPFS.uploadFileWeb(file) - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { - //console.log(`err.message: ${err.message}`) + // console.log(`err.message: ${err.message}`) assert.include( err.message, - `File should have the property 'name' of string type` + 'File should have the property \'name\' of string type' ) } }) it("should throw an error if 'size' property is not included", async () => { try { const file = { - name: "ipfs.js", - type: "text/plain" + name: 'ipfs.js', + type: 'text/plain' } await bchjs.IPFS.uploadFileWeb(file) - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { - //console.log(`err.message: ${err.message}`) + // console.log(`err.message: ${err.message}`) assert.include( err.message, - `File should have the property 'size' of number type` + 'File should have the property \'size\' of number type' ) } }) it("should throw an error if 'type' property is not included", async () => { try { const file = { - name: "ipfs.js", + name: 'ipfs.js', size: 5000 } await bchjs.IPFS.uploadFileWeb(file) - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { - //console.log(`err.message: ${err.message}`) + // console.log(`err.message: ${err.message}`) assert.include( err.message, - `File should have the property 'type' of string type` + 'File should have the property \'type\' of string type' ) } }) - it("should throw an error if modelId is not included", async () => { + it('should throw an error if modelId is not included', async () => { try { const file = { - name: "ipfs.js", + name: 'ipfs.js', size: 5000, - type: "text/plain" + type: 'text/plain' } await bchjs.IPFS.uploadFileWeb(file) - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { - //console.log(`err.message: ${err.message}`) - assert.include(err.message, `Must include a file model ID`) + // console.log(`err.message: ${err.message}`) + assert.include(err.message, 'Must include a file model ID') } }) - it("Should throw error if the file was not uploaded", async () => { + it('Should throw error if the file was not uploaded', async () => { try { const mock = { successful: [], failed: [ { - id: "file id" + id: 'file id' } ] } - sandbox.stub(bchjs.IPFS.uppy, "upload").resolves(mock) + sandbox.stub(bchjs.IPFS.uppy, 'upload').resolves(mock) const file = { - name: "ipfs.js", + name: 'ipfs.js', size: 5000, - type: "text/plain" + type: 'text/plain' } - await bchjs.IPFS.uploadFileWeb(file, "5ec562319bfacc745e8d8a52") + await bchjs.IPFS.uploadFileWeb(file, '5ec562319bfacc745e8d8a52') - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { - //console.log(err) - assert.include(err.message, `The file could not be uploaded`) + // console.log(err) + assert.include(err.message, 'The file could not be uploaded') } }) - it("should return file object if the file is uploaded", async () => { + it('should return file object if the file is uploaded', async () => { try { - sandbox.stub(bchjs.IPFS.uppy, "upload").resolves(mockData.uploadData) + sandbox.stub(bchjs.IPFS.uppy, 'upload').resolves(mockData.uploadData) const file = { - name: "ipfs.js", + name: 'ipfs.js', size: 5000, - type: "text/plain" + type: 'text/plain' } const result = await bchjs.IPFS.uploadFileWeb( file, - "5ec562319bfacc745e8d8a52" + '5ec562319bfacc745e8d8a52' ) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "schemaVersion") - assert.property(result, "size") - assert.property(result, "fileId") - assert.property(result, "fileName") - assert.property(result, "fileExtension") + assert.property(result, 'schemaVersion') + assert.property(result, 'size') + assert.property(result, 'fileId') + assert.property(result, 'fileName') + assert.property(result, 'fileExtension') } catch (err) { - //console.log(err) - assert.equal(true, false, "Unexpected result") + // console.log(err) + assert.equal(true, false, 'Unexpected result') } }) }) diff --git a/test/unit/mining.js b/test/unit/mining.js index 2079ed0..9397f5a 100644 --- a/test/unit/mining.js +++ b/test/unit/mining.js @@ -1,39 +1,39 @@ // Public npm libraries -const assert = require("assert") -const axios = require("axios") -const sinon = require("sinon") +const assert = require('assert') +const axios = require('axios') +const sinon = require('sinon') // Unit under test (uut) -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') let bchjs -describe("#Mining", () => { +describe('#Mining', () => { beforeEach(() => { bchjs = new BCHJS() }) - describe("#getBlockTemplate", () => { + describe('#getBlockTemplate', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) - it("should get block template", done => { + it('should get block template', done => { const data = { data: - "01000000017f6305e3b0b05f5b57a82f4e6d4187e148bbe56a947208390e488bad36472368000000006a47304402203b0079ff5b896187feb02e2679c87ac2fb8d483b60e0721ed33601e2c0eecc700220590f8a0e1a51b53b368294861fd5fc99db3a6607d0f4e543f6217108e208c1834121024c93c841d7f576584ffbf513b7abd8283e6562669905f6554f788fce4cc67a34ffffffff0228100000000000001976a914af78709a76abc8a28e568c9210c8247dd10cff2c88ac22020000000000001976a914f339927678803f451b41400737e7dc83c6a8682188ac00000000", + '01000000017f6305e3b0b05f5b57a82f4e6d4187e148bbe56a947208390e488bad36472368000000006a47304402203b0079ff5b896187feb02e2679c87ac2fb8d483b60e0721ed33601e2c0eecc700220590f8a0e1a51b53b368294861fd5fc99db3a6607d0f4e543f6217108e208c1834121024c93c841d7f576584ffbf513b7abd8283e6562669905f6554f788fce4cc67a34ffffffff0228100000000000001976a914af78709a76abc8a28e568c9210c8247dd10cff2c88ac22020000000000001976a914f339927678803f451b41400737e7dc83c6a8682188ac00000000', txid: - "7f462d71c649a0d8cfbaa2d20d8ff86677966b308f0ac9906ee015bf4453f97a", + '7f462d71c649a0d8cfbaa2d20d8ff86677966b308f0ac9906ee015bf4453f97a', hash: - "7f462d71c649a0d8cfbaa2d20d8ff86677966b308f0ac9906ee015bf4453f97a", + '7f462d71c649a0d8cfbaa2d20d8ff86677966b308f0ac9906ee015bf4453f97a', depends: [], fee: 226, sigops: 2 } const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) - bchjs.Mining.getBlockTemplate("") + bchjs.Mining.getBlockTemplate('') .then(result => { assert.deepEqual(data, result) }) @@ -41,26 +41,26 @@ describe("#Mining", () => { }) }) - describe("#getMiningInfo", () => { + describe('#getMiningInfo', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) - it("should get mining info", done => { + it('should get mining info', done => { const data = { blocks: 527816, currentblocksize: 89408, currentblocktx: 156, difficulty: 568757800682.7649, blockprioritypercentage: 5, - errors: "", + errors: '', networkhashps: 4347259225696976000, pooledtx: 184, - chain: "main" + chain: 'main' } const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) bchjs.Mining.getMiningInfo() .then(result => { @@ -70,16 +70,16 @@ describe("#Mining", () => { }) }) - describe("#getNetworkHashps", () => { + describe('#getNetworkHashps', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) - it("should get network hashps", done => { + it('should get network hashps', done => { const data = 3586365937646890000 const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) bchjs.Mining.getNetworkHashps() .then(result => { @@ -89,17 +89,17 @@ describe("#Mining", () => { }) }) - describe("#submitBlock", () => { + describe('#submitBlock', () => { // TODO finish let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) - it("should TODO", done => { + it('should TODO', done => { const data = {} const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "post").returns(resolved) + sandbox.stub(axios, 'post').returns(resolved) bchjs.Mining.submitBlock() .then(result => { diff --git a/test/unit/mnemonic.js b/test/unit/mnemonic.js index 2028653..8a2f0eb 100644 --- a/test/unit/mnemonic.js +++ b/test/unit/mnemonic.js @@ -1,82 +1,82 @@ -const fixtures = require("./fixtures/mnemonic.json") -const assert = require("assert") -const BCHJS = require("../../src/bch-js") +const fixtures = require('./fixtures/mnemonic.json') +const assert = require('assert') +const BCHJS = require('../../src/bch-js') const bchjs = new BCHJS() -describe("#Mnemonic", () => { - describe("#generate", () => { - it("should generate a 12 word mnemonic", () => { +describe('#Mnemonic', () => { + describe('#generate', () => { + it('should generate a 12 word mnemonic', () => { const mnemonic = bchjs.Mnemonic.generate(128) - assert.equal(mnemonic.split(" ").length, 12) + assert.equal(mnemonic.split(' ').length, 12) }) - it("should generate a 15 word mnemonic", () => { + it('should generate a 15 word mnemonic', () => { const mnemonic = bchjs.Mnemonic.generate(160) - assert.equal(mnemonic.split(" ").length, 15) + assert.equal(mnemonic.split(' ').length, 15) }) - it("should generate a 18 word mnemonic", () => { + it('should generate a 18 word mnemonic', () => { const mnemonic = bchjs.Mnemonic.generate(192) - assert.equal(mnemonic.split(" ").length, 18) + assert.equal(mnemonic.split(' ').length, 18) }) - it("should generate an 21 word mnemonic", () => { + it('should generate an 21 word mnemonic', () => { const mnemonic = bchjs.Mnemonic.generate(224) - assert.equal(mnemonic.split(" ").length, 21) + assert.equal(mnemonic.split(' ').length, 21) }) - it("should generate an 24 word mnemonic", () => { + it('should generate an 24 word mnemonic', () => { const mnemonic = bchjs.Mnemonic.generate(256) - assert.equal(mnemonic.split(" ").length, 24) + assert.equal(mnemonic.split(' ').length, 24) }) - it("should generate an 24 word italian mnemonic", () => { + it('should generate an 24 word italian mnemonic', () => { const mnemonic = bchjs.Mnemonic.generate( 256, bchjs.Mnemonic.wordLists().italian ) - assert.equal(mnemonic.split(" ").length, 24) + assert.equal(mnemonic.split(' ').length, 24) }) }) - describe("#fromEntropy", () => { - it("should generate a 12 word mnemonic from 16 bytes of entropy", () => { + describe('#fromEntropy', () => { + it('should generate a 12 word mnemonic from 16 bytes of entropy', () => { const rand = bchjs.Crypto.randomBytes(16) - const mnemonic = bchjs.Mnemonic.fromEntropy(rand.toString("hex")) - assert.equal(mnemonic.split(" ").length, 12) + const mnemonic = bchjs.Mnemonic.fromEntropy(rand.toString('hex')) + assert.equal(mnemonic.split(' ').length, 12) }) - it("should generate a 15 word mnemonic from 20 bytes of entropy", () => { + it('should generate a 15 word mnemonic from 20 bytes of entropy', () => { const rand = bchjs.Crypto.randomBytes(20) - const mnemonic = bchjs.Mnemonic.fromEntropy(rand.toString("hex")) - assert.equal(mnemonic.split(" ").length, 15) + const mnemonic = bchjs.Mnemonic.fromEntropy(rand.toString('hex')) + assert.equal(mnemonic.split(' ').length, 15) }) - it("should generate an 18 word mnemonic from 24 bytes of entropy", () => { + it('should generate an 18 word mnemonic from 24 bytes of entropy', () => { const rand = bchjs.Crypto.randomBytes(24) - const mnemonic = bchjs.Mnemonic.fromEntropy(rand.toString("hex")) - assert.equal(mnemonic.split(" ").length, 18) + const mnemonic = bchjs.Mnemonic.fromEntropy(rand.toString('hex')) + assert.equal(mnemonic.split(' ').length, 18) }) - it("should generate an 21 word mnemonic from 28 bytes of entropy", () => { + it('should generate an 21 word mnemonic from 28 bytes of entropy', () => { const rand = bchjs.Crypto.randomBytes(28) - const mnemonic = bchjs.Mnemonic.fromEntropy(rand.toString("hex")) - assert.equal(mnemonic.split(" ").length, 21) + const mnemonic = bchjs.Mnemonic.fromEntropy(rand.toString('hex')) + assert.equal(mnemonic.split(' ').length, 21) }) - it("should generate an 24 word mnemonic from 32 bytes of entropy", () => { + it('should generate an 24 word mnemonic from 32 bytes of entropy', () => { const rand = bchjs.Crypto.randomBytes(32) - const mnemonic = bchjs.Mnemonic.fromEntropy(rand.toString("hex")) - assert.equal(mnemonic.split(" ").length, 24) + const mnemonic = bchjs.Mnemonic.fromEntropy(rand.toString('hex')) + assert.equal(mnemonic.split(' ').length, 24) }) - it("should generate an 24 french word mnemonic 32 bytes of entropy", () => { + it('should generate an 24 french word mnemonic 32 bytes of entropy', () => { const rand = bchjs.Crypto.randomBytes(32) const mnemonic = bchjs.Mnemonic.fromEntropy( - rand.toString("hex"), + rand.toString('hex'), bchjs.Mnemonic.wordLists().french ) - assert.equal(mnemonic.split(" ").length, 24) + assert.equal(mnemonic.split(' ').length, 24) }) fixtures.fromEntropy.forEach(entropy => { @@ -87,38 +87,38 @@ describe("#Mnemonic", () => { }) }) - describe("#toEntropy", () => { - it("should turn a 12 word mnemonic to entropy", () => { + describe('#toEntropy', () => { + it('should turn a 12 word mnemonic to entropy', () => { const mnemonic = bchjs.Mnemonic.generate(128) const entropy = bchjs.Mnemonic.toEntropy(mnemonic) assert.equal(entropy.length, 16) }) - it("should turn a 15 word mnemonic to entropy", () => { + it('should turn a 15 word mnemonic to entropy', () => { const mnemonic = bchjs.Mnemonic.generate(160) const entropy = bchjs.Mnemonic.toEntropy(mnemonic) assert.equal(entropy.length, 20) }) - it("should turn a 18 word mnemonic to entropy", () => { + it('should turn a 18 word mnemonic to entropy', () => { const mnemonic = bchjs.Mnemonic.generate(192) const entropy = bchjs.Mnemonic.toEntropy(mnemonic) assert.equal(entropy.length, 24) }) - it("should turn a 21 word mnemonic to entropy", () => { + it('should turn a 21 word mnemonic to entropy', () => { const mnemonic = bchjs.Mnemonic.generate(224) const entropy = bchjs.Mnemonic.toEntropy(mnemonic) assert.equal(entropy.length, 28) }) - it("should turn a 24 word mnemonic to entropy", () => { + it('should turn a 24 word mnemonic to entropy', () => { const mnemonic = bchjs.Mnemonic.generate(256) const entropy = bchjs.Mnemonic.toEntropy(mnemonic) assert.equal(entropy.length, 32) }) - it("should turn a 24 word spanish mnemonic to entropy", () => { + it('should turn a 24 word spanish mnemonic to entropy', () => { const mnemonic = bchjs.Mnemonic.generate( 256, bchjs.Mnemonic.wordLists().spanish @@ -133,83 +133,83 @@ describe("#Mnemonic", () => { fixtures.fromEntropy.forEach(fixture => { const entropy = bchjs.Mnemonic.toEntropy(fixture.mnemonic) it(`should convert ${fixture.mnemonic} to ${fixture.entropy}`, () => { - assert.equal(entropy.toString("hex"), fixture.entropy) + assert.equal(entropy.toString('hex'), fixture.entropy) }) }) }) - describe("#validate", () => { - it("fails for a mnemonic that is too short", () => { + describe('#validate', () => { + it('fails for a mnemonic that is too short', () => { assert.equal( bchjs.Mnemonic.validate( - "mixed winner", + 'mixed winner', bchjs.Mnemonic.wordLists().english ), - "Invalid mnemonic" + 'Invalid mnemonic' ) }) - it("fails for a mnemonic that is too long", () => { + it('fails for a mnemonic that is too long', () => { assert.equal( bchjs.Mnemonic.validate( - "mixed winner decide drift danger together twice planet impose asthma catch require select mask awkward spy relief front work solar pitch economy render cake mixed winner decide drift danger together twice planet impose asthma catch require select mask awkward spy relief front work solar pitch economy render cake mixed winner decide drift danger together twice planet impose asthma catch require select mask awkward spy relief front work solar pitch economy render cake mixed winner decide drift danger together twice planet impose asthma catch require select mask awkward spy relief front work solar pitch economy render cake mixed winner decide drift danger together twice planet impose asthma catch require select mask awkward spy relief front work solar pitch economy render cake mixed winner decide drift danger together twice planet impose asthma catch require select mask awkward spy relief front work solar pitch economy render cake mixed winner decide drift danger together twice planet impose asthma catch require select mask awkward spy relief front work solar pitch economy render cake mixed winner decide drift danger together twice planet impose asthma catch require select mask awkward spy relief front work solar pitch economy render cake", + 'mixed winner decide drift danger together twice planet impose asthma catch require select mask awkward spy relief front work solar pitch economy render cake mixed winner decide drift danger together twice planet impose asthma catch require select mask awkward spy relief front work solar pitch economy render cake mixed winner decide drift danger together twice planet impose asthma catch require select mask awkward spy relief front work solar pitch economy render cake mixed winner decide drift danger together twice planet impose asthma catch require select mask awkward spy relief front work solar pitch economy render cake mixed winner decide drift danger together twice planet impose asthma catch require select mask awkward spy relief front work solar pitch economy render cake mixed winner decide drift danger together twice planet impose asthma catch require select mask awkward spy relief front work solar pitch economy render cake mixed winner decide drift danger together twice planet impose asthma catch require select mask awkward spy relief front work solar pitch economy render cake mixed winner decide drift danger together twice planet impose asthma catch require select mask awkward spy relief front work solar pitch economy render cake', bchjs.Mnemonic.wordLists().english ), - "Invalid mnemonic" + 'Invalid mnemonic' ) }) - it("fails if mnemonic words are not in the word list", () => { + it('fails if mnemonic words are not in the word list', () => { assert.equal( bchjs.Mnemonic.validate( - "failsauce one two three four five six seven eight nine ten eleven", + 'failsauce one two three four five six seven eight nine ten eleven', bchjs.Mnemonic.wordLists().english ), - "failsauce is not in wordlist, did you mean balance?" + 'failsauce is not in wordlist, did you mean balance?' ) }) - it("validate a 128 bit mnemonic", () => { + it('validate a 128 bit mnemonic', () => { const mnemonic = bchjs.Mnemonic.generate(128) assert.equal( bchjs.Mnemonic.validate(mnemonic, bchjs.Mnemonic.wordLists().english), - "Valid mnemonic" + 'Valid mnemonic' ) }) - it("validate a 160 bit mnemonic", () => { + it('validate a 160 bit mnemonic', () => { const mnemonic = bchjs.Mnemonic.generate(160) assert.equal( bchjs.Mnemonic.validate(mnemonic, bchjs.Mnemonic.wordLists().english), - "Valid mnemonic" + 'Valid mnemonic' ) }) - it("validate a 192 bit mnemonic", () => { + it('validate a 192 bit mnemonic', () => { const mnemonic = bchjs.Mnemonic.generate(192) assert.equal( bchjs.Mnemonic.validate(mnemonic, bchjs.Mnemonic.wordLists().english), - "Valid mnemonic" + 'Valid mnemonic' ) }) - it("validate a 224 bit mnemonic", () => { + it('validate a 224 bit mnemonic', () => { const mnemonic = bchjs.Mnemonic.generate(224) assert.equal( bchjs.Mnemonic.validate(mnemonic, bchjs.Mnemonic.wordLists().english), - "Valid mnemonic" + 'Valid mnemonic' ) }) - it("validate a 256 bit mnemonic", () => { + it('validate a 256 bit mnemonic', () => { const mnemonic = bchjs.Mnemonic.generate(256) assert.equal( bchjs.Mnemonic.validate(mnemonic, bchjs.Mnemonic.wordLists().english), - "Valid mnemonic" + 'Valid mnemonic' ) }) - it("validate a 256 bit chinese simplified mnemonic", () => { + it('validate a 256 bit chinese simplified mnemonic', () => { const mnemonic = bchjs.Mnemonic.generate( 256, bchjs.Mnemonic.wordLists().chinese_simplified @@ -219,82 +219,82 @@ describe("#Mnemonic", () => { mnemonic, bchjs.Mnemonic.wordLists().chinese_simplified ), - "Valid mnemonic" + 'Valid mnemonic' ) }) }) - describe("#toSeed", () => { - it("should create 512 bit / 64 byte HMAC-SHA512 root seed from a 128 bit mnemonic", async () => { + describe('#toSeed', () => { + it('should create 512 bit / 64 byte HMAC-SHA512 root seed from a 128 bit mnemonic', async () => { const mnemonic = bchjs.Mnemonic.generate(128) - const rootSeedBuffer = await bchjs.Mnemonic.toSeed(mnemonic, "") + const rootSeedBuffer = await bchjs.Mnemonic.toSeed(mnemonic, '') assert.equal(rootSeedBuffer.byteLength, 64) }) - it("should create 512 bit / 64 byte HMAC-SHA512 root seed from a 160 bit mnemonic", async () => { + it('should create 512 bit / 64 byte HMAC-SHA512 root seed from a 160 bit mnemonic', async () => { const mnemonic = bchjs.Mnemonic.generate(160) - const rootSeedBuffer = await bchjs.Mnemonic.toSeed(mnemonic, "") + const rootSeedBuffer = await bchjs.Mnemonic.toSeed(mnemonic, '') assert.equal(rootSeedBuffer.byteLength, 64) }) - it("should create 512 bit / 64 byte HMAC-SHA512 root seed from a 192 bit mnemonic", async () => { + it('should create 512 bit / 64 byte HMAC-SHA512 root seed from a 192 bit mnemonic', async () => { const mnemonic = bchjs.Mnemonic.generate(192) - const rootSeedBuffer = await bchjs.Mnemonic.toSeed(mnemonic, "") + const rootSeedBuffer = await bchjs.Mnemonic.toSeed(mnemonic, '') assert.equal(rootSeedBuffer.byteLength, 64) }) - it("should create 512 bit / 64 byte HMAC-SHA512 root seed from a 224 bit mnemonic", async () => { + it('should create 512 bit / 64 byte HMAC-SHA512 root seed from a 224 bit mnemonic', async () => { const mnemonic = bchjs.Mnemonic.generate(224) - const rootSeedBuffer = await bchjs.Mnemonic.toSeed(mnemonic, "") + const rootSeedBuffer = await bchjs.Mnemonic.toSeed(mnemonic, '') assert.equal(rootSeedBuffer.byteLength, 64) }) - it("should create 512 bit / 64 byte HMAC-SHA512 root seed from a 256 bit mnemonic", async () => { + it('should create 512 bit / 64 byte HMAC-SHA512 root seed from a 256 bit mnemonic', async () => { const mnemonic = bchjs.Mnemonic.generate(256) - const rootSeedBuffer = await bchjs.Mnemonic.toSeed(mnemonic, "") + const rootSeedBuffer = await bchjs.Mnemonic.toSeed(mnemonic, '') assert.equal(rootSeedBuffer.byteLength, 64) }) }) - describe("#wordLists", () => { - it("return a list of 2048 english words", () => { + describe('#wordLists', () => { + it('return a list of 2048 english words', () => { assert.equal(bchjs.Mnemonic.wordLists().english.length, 2048) }) - it("return a list of 2048 japanese words", () => { + it('return a list of 2048 japanese words', () => { assert.equal(bchjs.Mnemonic.wordLists().japanese.length, 2048) }) - it("return a list of 2048 chinese simplified words", () => { + it('return a list of 2048 chinese simplified words', () => { assert.equal(bchjs.Mnemonic.wordLists().chinese_simplified.length, 2048) }) - it("return a list of 2048 chinese traditional words", () => { + it('return a list of 2048 chinese traditional words', () => { assert.equal(bchjs.Mnemonic.wordLists().chinese_traditional.length, 2048) }) - it("return a list of 2048 french words", () => { + it('return a list of 2048 french words', () => { assert.equal(bchjs.Mnemonic.wordLists().french.length, 2048) }) - it("return a list of 2048 italian words", () => { + it('return a list of 2048 italian words', () => { assert.equal(bchjs.Mnemonic.wordLists().italian.length, 2048) }) - it("return a list of 2048 korean words", () => { + it('return a list of 2048 korean words', () => { assert.equal(bchjs.Mnemonic.wordLists().korean.length, 2048) }) - it("return a list of 2048 spanish words", () => { + it('return a list of 2048 spanish words', () => { assert.equal(bchjs.Mnemonic.wordLists().spanish.length, 2048) }) }) - describe("#toKeypairs", async () => { + describe('#toKeypairs', async () => { fixtures.toKeypairs.forEach(async (fixture, i) => { const keypairs = await bchjs.Mnemonic.toKeypairs(fixture.mnemonic, 5) keypairs.forEach((keypair, j) => { - it(`Generate keypair from mnemonic`, () => { + it('Generate keypair from mnemonic', () => { assert.equal( keypair.privateKeyWIF, fixtures.toKeypairs[i].output[j].privateKeyWIF @@ -312,7 +312,7 @@ describe("#Mnemonic", () => { true ) regtestKeypairs.forEach((keypair, j) => { - it(`Generate keypair from mnemonic`, () => { + it('Generate keypair from mnemonic', () => { assert.equal( keypair.privateKeyWIF, fixtures.toKeypairs[i].output[j].privateKeyWIFRegTest @@ -326,7 +326,7 @@ describe("#Mnemonic", () => { }) }) - describe("#findNearestWord", () => { + describe('#findNearestWord', () => { fixtures.findNearestWord.forEach((fixture, i) => { const word = bchjs.Mnemonic.findNearestWord( fixture.word, diff --git a/test/unit/ninsight.js b/test/unit/ninsight.js index 9670586..45a898e 100644 --- a/test/unit/ninsight.js +++ b/test/unit/ninsight.js @@ -1,67 +1,67 @@ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert -const axios = require("axios") -const sinon = require("sinon") +const axios = require('axios') +const sinon = require('sinon') -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') const bchjs = new BCHJS() -const mockData = require("./fixtures/ninsight-mock") +const mockData = require('./fixtures/ninsight-mock') -describe(`#Ninsight`, () => { +describe('#Ninsight', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) - describe(`#utxo`, () => { - it(`should throw an error for improper input`, async () => { + describe('#utxo', () => { + it('should throw an error for improper input', async () => { try { const addr = 12345 await bchjs.Ninsight.utxo(addr) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - //console.log(`err: `, err) + // console.log(`err: `, err) assert.include( err.message, - `Input address must be a string or array of strings.` + 'Input address must be a string or array of strings.' ) } }) - it(`should GET utxos for a single address`, async () => { + it('should GET utxos for a single address', async () => { // Stub the network call. - sandbox.stub(axios, "post").resolves({ data: mockData.utxo }) + sandbox.stub(axios, 'post').resolves({ data: mockData.utxo }) - const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9" + const addr = 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9' const result = await bchjs.Ninsight.utxo(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "utxos") - assert.property(result, "legacyAddress") - assert.property(result, "cashAddress") - assert.property(result, "slpAddress") - assert.property(result, "scriptPubKey") - assert.property(result, "asm") + assert.property(result, 'utxos') + assert.property(result, 'legacyAddress') + assert.property(result, 'cashAddress') + assert.property(result, 'slpAddress') + assert.property(result, 'scriptPubKey') + assert.property(result, 'asm') assert.isArray(result.utxos) - assert.property(result.utxos[0], "txid") - assert.property(result.utxos[0], "vout") - assert.property(result.utxos[0], "amount") - assert.property(result.utxos[0], "satoshis") - assert.property(result.utxos[0], "height") - assert.property(result.utxos[0], "confirmations") + assert.property(result.utxos[0], 'txid') + assert.property(result.utxos[0], 'vout') + assert.property(result.utxos[0], 'amount') + assert.property(result.utxos[0], 'satoshis') + assert.property(result.utxos[0], 'height') + assert.property(result.utxos[0], 'confirmations') }) - it(`should POST utxo details for an array of addresses`, async () => { + it('should POST utxo details for an array of addresses', async () => { // Mock the network call. - sandbox.stub(axios, "post").resolves({ data: mockData.utxoPost }) + sandbox.stub(axios, 'post').resolves({ data: mockData.utxoPost }) const addr = [ - "bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7", - "bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr" + 'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7', + 'bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr' ] const result = await bchjs.Ninsight.utxo(addr) @@ -70,62 +70,62 @@ describe(`#Ninsight`, () => { assert.isArray(result) assert.isArray(result[0].utxos) - assert.property(result[0], "utxos") - assert.property(result[0], "legacyAddress") - assert.property(result[0], "cashAddress") - assert.property(result[0], "slpAddress") - assert.property(result[0], "scriptPubKey") - assert.property(result[0], "asm") + assert.property(result[0], 'utxos') + assert.property(result[0], 'legacyAddress') + assert.property(result[0], 'cashAddress') + assert.property(result[0], 'slpAddress') + assert.property(result[0], 'scriptPubKey') + assert.property(result[0], 'asm') }) }) - describe("#unconfirmed", () => { - it("should throw an error for improper input", async () => { + describe('#unconfirmed', () => { + it('should throw an error for improper input', async () => { try { const addr = 12345 await bchjs.Ninsight.unconfirmed(addr) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { assert.include( err.message, - "Input address must be a string or array of strings." + 'Input address must be a string or array of strings.' ) } }) - it(`should POST utxos for a single address`, async () => { + it('should POST utxos for a single address', async () => { // Stub the network call. - sandbox.stub(axios, "post").resolves({ data: mockData.unconfirmed }) + sandbox.stub(axios, 'post').resolves({ data: mockData.unconfirmed }) - const addr = "bitcoincash:qpkkjkhe29mqhqmu3evtq3dsnruuzl3rku6usknlh5" + const addr = 'bitcoincash:qpkkjkhe29mqhqmu3evtq3dsnruuzl3rku6usknlh5' const result = await bchjs.Ninsight.unconfirmed(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "utxos") - assert.property(result, "legacyAddress") - assert.property(result, "cashAddress") - assert.property(result, "slpAddress") - assert.property(result, "scriptPubKey") + assert.property(result, 'utxos') + assert.property(result, 'legacyAddress') + assert.property(result, 'cashAddress') + assert.property(result, 'slpAddress') + assert.property(result, 'scriptPubKey') assert.isArray(result.utxos) - assert.property(result.utxos[0], "txid") - assert.property(result.utxos[0], "vout") - assert.property(result.utxos[0], "amount") - assert.property(result.utxos[0], "satoshis") - assert.property(result.utxos[0], "confirmations") - assert.property(result.utxos[0], "ts") + assert.property(result.utxos[0], 'txid') + assert.property(result.utxos[0], 'vout') + assert.property(result.utxos[0], 'amount') + assert.property(result.utxos[0], 'satoshis') + assert.property(result.utxos[0], 'confirmations') + assert.property(result.utxos[0], 'ts') }) - it(`should POST utxo details for an array of addresses`, async () => { + it('should POST utxo details for an array of addresses', async () => { // Mock the network call. - sandbox.stub(axios, "post").resolves({ data: mockData.unconfirmedPost }) + sandbox.stub(axios, 'post').resolves({ data: mockData.unconfirmedPost }) const addr = [ - "bitcoincash:qpkkjkhe29mqhqmu3evtq3dsnruuzl3rku6usknlh5", - "bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr" + 'bitcoincash:qpkkjkhe29mqhqmu3evtq3dsnruuzl3rku6usknlh5', + 'bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr' ] const result = await bchjs.Ninsight.unconfirmed(addr) @@ -134,122 +134,122 @@ describe(`#Ninsight`, () => { assert.isArray(result) assert.isArray(result[0].utxos) - assert.property(result[0], "utxos") - assert.property(result[0], "legacyAddress") - assert.property(result[0], "cashAddress") - assert.property(result[0], "slpAddress") - assert.property(result[0], "scriptPubKey") + assert.property(result[0], 'utxos') + assert.property(result[0], 'legacyAddress') + assert.property(result[0], 'cashAddress') + assert.property(result[0], 'slpAddress') + assert.property(result[0], 'scriptPubKey') }) }) - describe(`#transactions`, () => { - it(`should throw an error for improper input`, async () => { + describe('#transactions', () => { + it('should throw an error for improper input', async () => { try { const addr = 12345 await bchjs.Ninsight.transactions(addr) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - //console.log(`err: `, err) + // console.log(`err: `, err) assert.include( err.message, - `Input address must be a string or array of strings.` + 'Input address must be a string or array of strings.' ) } }) - it(`should POST transaction history for a single address`, async () => { + it('should POST transaction history for a single address', async () => { // Stub the network call. - sandbox.stub(axios, "post").resolves({ data: mockData.transactionsPost }) + sandbox.stub(axios, 'post').resolves({ data: mockData.transactionsPost }) - const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9" + const addr = 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9' const result = await bchjs.Ninsight.transactions(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) - assert.property(result[0], "cashAddress") - assert.property(result[0], "legacyAddress") - assert.property(result[0], "txs") + assert.property(result[0], 'cashAddress') + assert.property(result[0], 'legacyAddress') + assert.property(result[0], 'txs') assert.isArray(result[0].txs) - assert.property(result[0].txs[0], "txid") - assert.property(result[0].txs[0], "vin") - assert.property(result[0].txs[0], "vout") + assert.property(result[0].txs[0], 'txid') + assert.property(result[0].txs[0], 'vin') + assert.property(result[0].txs[0], 'vout') }) - it(`should POST transaction history for an array of addresses`, async () => { + it('should POST transaction history for an array of addresses', async () => { // Mock the network call. - sandbox.stub(axios, "post").resolves({ data: mockData.transactionsPost }) + sandbox.stub(axios, 'post').resolves({ data: mockData.transactionsPost }) const addr = [ - "bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7", - "bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr" + 'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7', + 'bitcoincash:qz0us0z6ucpqt07jgpad0shgh7xmwxyr3ynlcsq0wr' ] const result = await bchjs.Ninsight.transactions(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) - assert.property(result[0], "cashAddress") - assert.property(result[0], "legacyAddress") - assert.property(result[0], "txs") + assert.property(result[0], 'cashAddress') + assert.property(result[0], 'legacyAddress') + assert.property(result[0], 'txs') assert.isArray(result[0].txs) - assert.property(result[0].txs[0], "txid") + assert.property(result[0].txs[0], 'txid') }) }) - describe(`#txDetails`, () => { - it(`should throw an error for improper input`, async () => { + describe('#txDetails', () => { + it('should throw an error for improper input', async () => { try { const txid = 12345 await bchjs.Ninsight.txDetails(txid) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - //console.log(`err: `, err) + // console.log(`err: `, err) assert.include( err.message, - `Transaction ID must be a string or array of strings.` + 'Transaction ID must be a string or array of strings.' ) } }) - it(`should POST transaction details for a single TxID`, async () => { + it('should POST transaction details for a single TxID', async () => { // Stub the network call. - sandbox.stub(axios, "post").resolves({ data: mockData.detailsPost }) + sandbox.stub(axios, 'post').resolves({ data: mockData.detailsPost }) - const txid = "fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33" + const txid = 'fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33' const result = await bchjs.Ninsight.txDetails(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) - assert.property(result[0], "txid") - assert.property(result[0], "version") - assert.property(result[0], "locktime") - assert.property(result[0], "vin") - assert.property(result[0], "vout") - assert.property(result[0], "blockhash") - assert.property(result[0], "blockheight") - assert.property(result[0], "confirmations") - assert.property(result[0], "time") - assert.property(result[0], "blocktime") - assert.property(result[0], "isCoinBase") - assert.property(result[0], "valueOut") - assert.property(result[0], "size") + assert.property(result[0], 'txid') + assert.property(result[0], 'version') + assert.property(result[0], 'locktime') + assert.property(result[0], 'vin') + assert.property(result[0], 'vout') + assert.property(result[0], 'blockhash') + assert.property(result[0], 'blockheight') + assert.property(result[0], 'confirmations') + assert.property(result[0], 'time') + assert.property(result[0], 'blocktime') + assert.property(result[0], 'isCoinBase') + assert.property(result[0], 'valueOut') + assert.property(result[0], 'size') }) - it(`should POST transaction details for an array of TxIDs`, async () => { + it('should POST transaction details for an array of TxIDs', async () => { // Stub the network call. - sandbox.stub(axios, "post").resolves({ data: mockData.detailsPost }) + sandbox.stub(axios, 'post').resolves({ data: mockData.detailsPost }) const txid = [ - "fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33", - "fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33" + 'fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33', + 'fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33' ] const result = await bchjs.Ninsight.txDetails(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) - assert.property(result[0], "txid") - assert.property(result[0], "vin") - assert.property(result[0], "vout") + assert.property(result[0], 'txid') + assert.property(result[0], 'vin') + assert.property(result[0], 'vout') }) }) }) diff --git a/test/unit/openbazaar.js b/test/unit/openbazaar.js index d663fb0..5755c08 100644 --- a/test/unit/openbazaar.js +++ b/test/unit/openbazaar.js @@ -1,126 +1,126 @@ -const chai = require("chai") +const chai = require('chai') const assert = chai.assert -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') const bchjs = new BCHJS() -const axios = require("axios") -const sinon = require("sinon") +const axios = require('axios') +const sinon = require('sinon') -const mockData = require("./fixtures/openbazaar-mock") +const mockData = require('./fixtures/openbazaar-mock') -describe(`#OpenBazaar`, () => { +describe('#OpenBazaar', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) - describe(`#Balance`, () => { - it(`should throw an error for improper input`, async () => { + describe('#Balance', () => { + it('should throw an error for improper input', async () => { try { const addr = 12345 await bchjs.OpenBazaar.balance(addr) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - //console.log(`err: `, err) - assert.include(err.message, `Input address must be a string`) + // console.log(`err: `, err) + assert.include(err.message, 'Input address must be a string') } }) - it(`should GET balance for a single address`, async () => { + it('should GET balance for a single address', async () => { // Stub the network call. - sandbox.stub(axios, "get").resolves({ data: mockData.balance }) + sandbox.stub(axios, 'get').resolves({ data: mockData.balance }) - const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9" + const addr = 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9' const result = await bchjs.OpenBazaar.balance(addr) - //console.log(`result: ${util.inspect(result)}`) + // console.log(`result: ${util.inspect(result)}`) assert.hasAllKeys(result, [ - "page", - "totalPages", - "itemsOnPage", - "addrStr", - "balance", - "totalReceived", - "totalSent", - "unconfirmedBalance", - "unconfirmedTxApperances", - "txApperances", - "transactions" + 'page', + 'totalPages', + 'itemsOnPage', + 'addrStr', + 'balance', + 'totalReceived', + 'totalSent', + 'unconfirmedBalance', + 'unconfirmedTxApperances', + 'txApperances', + 'transactions' ]) assert.isArray(result.transactions) }) }) - describe(`#utxo`, () => { - it(`should throw an error for improper input`, async () => { + describe('#utxo', () => { + it('should throw an error for improper input', async () => { try { const addr = 12345 await bchjs.OpenBazaar.utxo(addr) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - //console.log(`err: `, err) - assert.include(err.message, `Input address must be a string`) + // console.log(`err: `, err) + assert.include(err.message, 'Input address must be a string') } }) - it(`should GET utxos for a single address`, async () => { + it('should GET utxos for a single address', async () => { // Stub the network call. - sandbox.stub(axios, "get").resolves({ data: mockData.utxo }) + sandbox.stub(axios, 'get').resolves({ data: mockData.utxo }) - const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9" + const addr = 'bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9' const result = await bchjs.OpenBazaar.utxo(addr) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) assert.hasAllKeys(result[0], [ - "txid", - "vout", - "amount", - "height", - "confirmations", - "satoshis" + 'txid', + 'vout', + 'amount', + 'height', + 'confirmations', + 'satoshis' ]) }) }) - describe(`#tx`, () => { - it(`should throw an error for improper input`, async () => { + describe('#tx', () => { + it('should throw an error for improper input', async () => { try { const txid = 12345 await bchjs.OpenBazaar.tx(txid) - assert.equal(true, false, "Unexpected result!") + assert.equal(true, false, 'Unexpected result!') } catch (err) { - //console.log(`err: `, err) - assert.include(err.message, `Input txid must be a string`) + // console.log(`err: `, err) + assert.include(err.message, 'Input txid must be a string') } }) - it(`should GET tx details for a single txid`, async () => { + it('should GET tx details for a single txid', async () => { // Stub the network call. - sandbox.stub(axios, "get").resolves({ data: mockData.tx }) + sandbox.stub(axios, 'get').resolves({ data: mockData.tx }) const txid = - "2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7" + '2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7' const result = await bchjs.OpenBazaar.tx(txid) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.hasAllKeys(result, [ - "txid", - "version", - "vin", - "vout", - "blockhash", - "blockheight", - "confirmations", - "blocktime", - "valueOut", - "valueIn", - "fees", - "hex" + 'txid', + 'version', + 'vin', + 'vout', + 'blockhash', + 'blockheight', + 'confirmations', + 'blocktime', + 'valueOut', + 'valueIn', + 'fees', + 'hex' ]) assert.isArray(result.vin) assert.isArray(result.vout) diff --git a/test/unit/price.js b/test/unit/price.js index 23f1ee7..1613e1d 100644 --- a/test/unit/price.js +++ b/test/unit/price.js @@ -1,11 +1,11 @@ -const assert = require("chai").assert -const BCHJS = require("../../src/bch-js") -const sinon = require("sinon") +const assert = require('chai').assert +const BCHJS = require('../../src/bch-js') +const sinon = require('sinon') -const mockDataLib = require("./fixtures/price-mocks") +const mockDataLib = require('./fixtures/price-mocks') let mockData -describe("#price", () => { +describe('#price', () => { let sandbox let bchjs @@ -19,22 +19,22 @@ describe("#price", () => { afterEach(() => sandbox.restore()) - describe("#current", () => { - it("should get current price for single currency", async () => { + describe('#current', () => { + it('should get current price for single currency', async () => { sandbox - .stub(bchjs.Price.axios, "get") + .stub(bchjs.Price.axios, 'get') .resolves({ data: { price: 24905 } }) - const result = await bchjs.Price.current("usd") + const result = await bchjs.Price.current('usd') // console.log(result) assert.isNumber(result) }) }) - describe("#getUsd", () => { - it("should get the USD price of BCH", async () => { - sandbox.stub(bchjs.Price.axios, "get").resolves({ data: { usd: 249.87 } }) + describe('#getUsd', () => { + it('should get the USD price of BCH', async () => { + sandbox.stub(bchjs.Price.axios, 'get').resolves({ data: { usd: 249.87 } }) const result = await bchjs.Price.getUsd() // console.log(result) @@ -43,23 +43,23 @@ describe("#price", () => { }) }) - describe("#rates", () => { - it("should get the price of BCH in several currencies", async () => { + describe('#rates', () => { + it('should get the price of BCH in several currencies', async () => { sandbox - .stub(bchjs.Price.axios, "get") + .stub(bchjs.Price.axios, 'get') .resolves({ data: mockData.mockRates }) const result = await bchjs.Price.rates() // console.log(result) - assert.property(result, "USD") - assert.property(result, "CAD") + assert.property(result, 'USD') + assert.property(result, 'CAD') }) }) - describe("#getBchaUsd", () => { - it("should get the USD price of BCHA", async () => { - sandbox.stub(bchjs.Price.axios, "get").resolves({ data: { usd: 18.87 } }) + describe('#getBchaUsd', () => { + it('should get the USD price of BCHA', async () => { + sandbox.stub(bchjs.Price.axios, 'get').resolves({ data: { usd: 18.87 } }) const result = await bchjs.Price.getBchaUsd() // console.log(result) diff --git a/test/unit/raw-tranactions.js b/test/unit/raw-tranactions.js index a2f41fa..2b31c9a 100644 --- a/test/unit/raw-tranactions.js +++ b/test/unit/raw-tranactions.js @@ -4,13 +4,13 @@ */ // Public npm libraries -const assert = require("assert") -const axios = require("axios") -const sinon = require("sinon") +const assert = require('assert') +const axios = require('axios') +const sinon = require('sinon') // const nock = require("nock") // HTTP mocking // Unit under test (uut) -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') // const bchjs = new BCHJS() let bchjs @@ -18,22 +18,22 @@ let bchjs // const util = require("util") // util.inspect.defaultOptions = { depth: 1 } -describe("#RawTransactions", () => { +describe('#RawTransactions', () => { beforeEach(() => { bchjs = new BCHJS() }) - describe("#decodeRawTransaction", () => { + describe('#decodeRawTransaction', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) - it("should decode raw transaction", done => { + it('should decode raw transaction', done => { const data = { txid: - "4ebd325a4b394cff8c57e8317ccf5a8d0e2bdf1b8526f8aad6c8e43d8240621a", + '4ebd325a4b394cff8c57e8317ccf5a8d0e2bdf1b8526f8aad6c8e43d8240621a', hash: - "4ebd325a4b394cff8c57e8317ccf5a8d0e2bdf1b8526f8aad6c8e43d8240621a", + '4ebd325a4b394cff8c57e8317ccf5a8d0e2bdf1b8526f8aad6c8e43d8240621a', size: 10, version: 2, locktime: 0, @@ -42,9 +42,9 @@ describe("#RawTransactions", () => { } const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) - bchjs.RawTransactions.decodeRawTransaction("02000000000000000000") + bchjs.RawTransactions.decodeRawTransaction('02000000000000000000') .then(result => { assert.equal(data, result) }) @@ -52,44 +52,44 @@ describe("#RawTransactions", () => { }) }) - describe("#decodeScript", () => { + describe('#decodeScript', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) - it("should decode script", async () => { + it('should decode script', async () => { const data = { - asm: "OP_RETURN 5361746f736869204e616b616d6f746f", - type: "nulldata", - p2sh: "bitcoincash:prswx5965nfumux9qng5kj8hw603vcne7q08t8c6jp" + asm: 'OP_RETURN 5361746f736869204e616b616d6f746f', + type: 'nulldata', + p2sh: 'bitcoincash:prswx5965nfumux9qng5kj8hw603vcne7q08t8c6jp' } const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) const result = await bchjs.RawTransactions.decodeScript( - "6a105361746f736869204e616b616d6f746f" + '6a105361746f736869204e616b616d6f746f' ) - //console.log(`result: ${util.inspect(result)}`) + // console.log(`result: ${util.inspect(result)}`) assert.deepEqual(data, result) }) }) - describe("#getRawTransaction", () => { + describe('#getRawTransaction', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) - it("should get raw transaction", done => { + it('should get raw transaction', done => { const data = - "020000000160d663961c63c7f0a07f22ec07b8f55b3935bfdbed8b1d8454916e8932fbf109010000006b4830450221008479fab4cfdcb111833d250a43f98ac26d43272b7a29cb1b9a0491eae5c44b3502203448b17253632395c29a7d62058bbfe93efb20fc8636ba6837002d464195aec04121029123258f7cdcd45b864066bcaa9b71f24d5ed1fa1dd36eaf107d8432b5014658ffffffff016d180000000000001976a91479d3297d1823149f4ec61df31d19f2fad5390c0288ac00000000" + '020000000160d663961c63c7f0a07f22ec07b8f55b3935bfdbed8b1d8454916e8932fbf109010000006b4830450221008479fab4cfdcb111833d250a43f98ac26d43272b7a29cb1b9a0491eae5c44b3502203448b17253632395c29a7d62058bbfe93efb20fc8636ba6837002d464195aec04121029123258f7cdcd45b864066bcaa9b71f24d5ed1fa1dd36eaf107d8432b5014658ffffffff016d180000000000001976a91479d3297d1823149f4ec61df31d19f2fad5390c0288ac00000000' const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) bchjs.RawTransactions.getRawTransaction( - "808d617eccaad4f1397fe07a06ec5ed15a0821cf22a3e0931c0c92aef9e572b6" + '808d617eccaad4f1397fe07a06ec5ed15a0821cf22a3e0931c0c92aef9e572b6' ) .then(result => { assert.equal(data, result) @@ -98,19 +98,19 @@ describe("#RawTransactions", () => { }) }) - describe("#sendRawTransaction", () => { + describe('#sendRawTransaction', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) - it("should send single raw transaction", async () => { - const data = "Error: transaction already in block chain" + it('should send single raw transaction', async () => { + const data = 'Error: transaction already in block chain' const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) const result = await bchjs.RawTransactions.sendRawTransaction( - "020000000160d663961c63c7f0a07f22ec07b8f55b3935bfdbed8b1d8454916e8932fbf109010000006b4830450221008479fab4cfdcb111833d250a43f98ac26d43272b7a29cb1b9a0491eae5c44b3502203448b17253632395c29a7d62058bbfe93efb20fc8636ba6837002d464195aec04121029123258f7cdcd45b864066bcaa9b71f24d5ed1fa1dd36eaf107d8432b5014658ffffffff016d180000000000001976a91479d3297d1823149f4ec61df31d19f2fad5390c0288ac00000000" + '020000000160d663961c63c7f0a07f22ec07b8f55b3935bfdbed8b1d8454916e8932fbf109010000006b4830450221008479fab4cfdcb111833d250a43f98ac26d43272b7a29cb1b9a0491eae5c44b3502203448b17253632395c29a7d62058bbfe93efb20fc8636ba6837002d464195aec04121029123258f7cdcd45b864066bcaa9b71f24d5ed1fa1dd36eaf107d8432b5014658ffffffff016d180000000000001976a91479d3297d1823149f4ec61df31d19f2fad5390c0288ac00000000' ) assert.equal(data, result) diff --git a/test/unit/scripts.js b/test/unit/scripts.js index 7095ba7..02172ce 100644 --- a/test/unit/scripts.js +++ b/test/unit/scripts.js @@ -1,32 +1,32 @@ // Public npm libraries -const assert = require("assert") -const Buffer = require("safe-buffer").Buffer +const assert = require('assert') +const Buffer = require('safe-buffer').Buffer // Mocks -const fixtures = require("./fixtures/script.json") +const fixtures = require('./fixtures/script.json') // Unit under test (uut) -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') let bchjs -describe("#Script", () => { +describe('#Script', () => { beforeEach(() => { bchjs = new BCHJS() }) - describe("#decode", () => { - describe("P2PKH scriptSig", () => { + describe('#decode', () => { + describe('P2PKH scriptSig', () => { fixtures.decodeScriptSig.forEach(fixture => { - it(`should decode scriptSig buffer`, () => { + it('should decode scriptSig buffer', () => { const decodedScriptSig = bchjs.Script.decode( - Buffer.from(fixture.scriptSigHex, "hex") + Buffer.from(fixture.scriptSigHex, 'hex') ) - assert.equal(typeof decodedScriptSig, "object") + assert.equal(typeof decodedScriptSig, 'object') }) it(`should decode scriptSig buffer to cash address ${fixture.cashAddress}`, () => { const decodedScriptSig = bchjs.Script.decode( - Buffer.from(fixture.scriptSigHex, "hex") + Buffer.from(fixture.scriptSigHex, 'hex') ) const address = bchjs.HDNode.toCashAddress( bchjs.ECPair.fromPublicKey(decodedScriptSig[1]) @@ -36,7 +36,7 @@ describe("#Script", () => { it(`should decode scriptSig buffer to legacy address ${fixture.legacyAddress}`, () => { const decodedScriptSig = bchjs.Script.decode( - Buffer.from(fixture.scriptSigHex, "hex") + Buffer.from(fixture.scriptSigHex, 'hex') ) const address = bchjs.HDNode.toLegacyAddress( bchjs.ECPair.fromPublicKey(decodedScriptSig[1]) @@ -46,103 +46,103 @@ describe("#Script", () => { }) }) - describe("P2PKH scriptPubKey", () => { + describe('P2PKH scriptPubKey', () => { fixtures.decodeScriptPubKey.forEach(fixture => { - it(`should decode scriptSig buffer`, () => { + it('should decode scriptSig buffer', () => { const decodedScriptPubKey = bchjs.Script.decode( - Buffer.from(fixture.scriptPubKeyHex, "hex") + Buffer.from(fixture.scriptPubKeyHex, 'hex') ) assert.equal(decodedScriptPubKey.length, 5) }) it(`should match hashed pubKey ${fixture.pubKeyHex}`, () => { const decodedScriptPubKey = bchjs.Script.decode( - Buffer.from(fixture.scriptPubKeyHex, "hex") + Buffer.from(fixture.scriptPubKeyHex, 'hex') ) - const data = Buffer.from(fixture.pubKeyHex, "hex") - const hash160 = bchjs.Crypto.hash160(data).toString("hex") - assert.equal(decodedScriptPubKey[2].toString("hex"), hash160) + const data = Buffer.from(fixture.pubKeyHex, 'hex') + const hash160 = bchjs.Crypto.hash160(data).toString('hex') + assert.equal(decodedScriptPubKey[2].toString('hex'), hash160) }) }) }) }) - describe("#encode", () => { - describe("P2PKH scriptSig", () => { + describe('#encode', () => { + describe('P2PKH scriptSig', () => { fixtures.encodeScriptSig.forEach(fixture => { - it(`should encode scriptSig chunks to buffer`, () => { + it('should encode scriptSig chunks to buffer', () => { const arr = [ - Buffer.from(fixture.scriptSigChunks[0], "hex"), - Buffer.from(fixture.scriptSigChunks[1], "hex") + Buffer.from(fixture.scriptSigChunks[0], 'hex'), + Buffer.from(fixture.scriptSigChunks[1], 'hex') ] const encodedScriptSig = bchjs.Script.encode(arr) - assert.equal(typeof encodedScriptSig, "object") + assert.equal(typeof encodedScriptSig, 'object') }) }) }) - describe("P2PKH scriptPubKey", () => { + describe('P2PKH scriptPubKey', () => { fixtures.encodeScriptPubKey.forEach(fixture => { - it(`should encode scriptPubKey buffer`, () => { + it('should encode scriptPubKey buffer', () => { const decodedScriptPubKey = bchjs.Script.decode( - Buffer.from(fixture.scriptPubKeyHex, "hex") + Buffer.from(fixture.scriptPubKeyHex, 'hex') ) const compiledScriptPubKey = bchjs.Script.encode(decodedScriptPubKey) assert.equal( - compiledScriptPubKey.toString("hex"), + compiledScriptPubKey.toString('hex'), fixture.scriptPubKeyHex ) }) }) }) - describe("Encode SLP SEND OP_RETURN properly", () => { - it("should correctly compile OP_RETURN SLP SEND transaction", () => { + describe('Encode SLP SEND OP_RETURN properly', () => { + it('should correctly compile OP_RETURN SLP SEND transaction', () => { const scriptArr = [ bchjs.Script.opcodes.OP_RETURN, - Buffer.from("534c5000", "hex"), - Buffer.from("01", "hex"), - Buffer.from(`SEND`), + Buffer.from('534c5000', 'hex'), + Buffer.from('01', 'hex'), + Buffer.from('SEND'), Buffer.from( - "73db55368981e4878440637e448d4abe7f661be5c3efdcbcb63bd86a01a76b5a", - "hex" + '73db55368981e4878440637e448d4abe7f661be5c3efdcbcb63bd86a01a76b5a', + 'hex' ), - Buffer.from("00000001", "hex") + Buffer.from('00000001', 'hex') ] const data = bchjs.Script.encode2(scriptArr) // convert data to a hex string - let str = "" + let str = '' for (let i = 0; i < data.length; i++) { let hex = Number(data[i]).toString(16) // zero pad when its a single digit. hex = `0${hex}` hex = hex.slice(-2) - //console.log(`hex: ${hex}`) + // console.log(`hex: ${hex}`) str += hex } console.log(`Hex string: ${str}`) - //console.log(`scriptArr: ${JSON.stringify(data,null,2)}`) + // console.log(`scriptArr: ${JSON.stringify(data,null,2)}`) const correctStr = - "6a04534c500001010453454e442073db55368981e4878440637e448d4abe7f661be5c3efdcbcb63bd86a01a76b5a0400000001" + '6a04534c500001010453454e442073db55368981e4878440637e448d4abe7f661be5c3efdcbcb63bd86a01a76b5a0400000001' assert.equal(str, correctStr) }) }) }) - describe("#toASM", () => { - describe("P2PKH scriptSig", () => { + describe('#toASM', () => { + describe('P2PKH scriptSig', () => { fixtures.scriptSigToASM.forEach(fixture => { it(`should encode scriptSig buffer to ${fixture.asm}`, () => { const arr = [ - Buffer.from(fixture.scriptSigChunks[0], "hex"), - Buffer.from(fixture.scriptSigChunks[1], "hex") + Buffer.from(fixture.scriptSigChunks[0], 'hex'), + Buffer.from(fixture.scriptSigChunks[1], 'hex') ] const compiledScriptSig = bchjs.Script.encode(arr) const asm = bchjs.Script.toASM(compiledScriptSig) @@ -151,11 +151,11 @@ describe("#Script", () => { }) }) - describe("P2PKH scriptPubKey", () => { + describe('P2PKH scriptPubKey', () => { fixtures.scriptPubKeyToASM.forEach(fixture => { it(`should compile scriptPubKey buffer to ${fixture.asm}`, () => { const asm = bchjs.Script.toASM( - Buffer.from(fixture.scriptPubKeyHex, "hex") + Buffer.from(fixture.scriptPubKeyHex, 'hex') ) assert.equal(asm, fixture.asm) }) @@ -163,27 +163,27 @@ describe("#Script", () => { }) }) - describe("#fromASM", () => { - describe("P2PKH scriptSig", () => { + describe('#fromASM', () => { + describe('P2PKH scriptSig', () => { fixtures.scriptSigFromASM.forEach(fixture => { - it(`should decode scriptSig asm to buffer`, () => { + it('should decode scriptSig asm to buffer', () => { const buf = bchjs.Script.fromASM(fixture.asm) - assert.equal(typeof buf, "object") + assert.equal(typeof buf, 'object') }) }) }) - describe("P2PKH scriptPubKey", () => { + describe('P2PKH scriptPubKey', () => { fixtures.scriptPubKeyFromASM.forEach(fixture => { - it(`should decode scriptPubKey asm to buffer`, () => { + it('should decode scriptPubKey asm to buffer', () => { const buf = bchjs.Script.fromASM(fixture.asm) - assert.equal(typeof buf, "object") + assert.equal(typeof buf, 'object') }) }) }) }) - describe("#OPCodes", () => { + describe('#OPCodes', () => { for (const opcode in fixtures.opcodes) { it(`should have OP Code ${opcode}`, () => { assert.equal(bchjs.Script.opcodes[opcode], fixtures.opcodes[opcode]) @@ -191,7 +191,7 @@ describe("#Script", () => { } }) - describe("#classifyInput", () => { + describe('#classifyInput', () => { fixtures.classifyInput.forEach(fixture => { it(`should classify input type ${fixture.type}`, () => { const type = bchjs.Script.classifyInput( @@ -202,7 +202,7 @@ describe("#Script", () => { }) }) - describe("#classifyOutput", () => { + describe('#classifyOutput', () => { fixtures.classifyOutput.forEach(fixture => { it(`should classify ouput type ${fixture.type}`, () => { const type = bchjs.Script.classifyOutput( @@ -213,25 +213,25 @@ describe("#Script", () => { }) }) - describe("#nullDataTemplate", () => { + describe('#nullDataTemplate', () => { fixtures.nullDataTemplate.forEach(fixture => { - it(`should encode nulldata output`, () => { + it('should encode nulldata output', () => { const buf = bchjs.Script.nullData.output.encode( - Buffer.from(`${fixture.data}`, "ascii") + Buffer.from(`${fixture.data}`, 'ascii') ) - assert.equal(buf.toString("hex"), fixture.hex) + assert.equal(buf.toString('hex'), fixture.hex) }) - it(`should decode nulldata output`, () => { + it('should decode nulldata output', () => { const buf = bchjs.Script.nullData.output.decode( - Buffer.from(`${fixture.hex}`, "hex") + Buffer.from(`${fixture.hex}`, 'hex') ) - assert.equal(buf.toString("ascii"), fixture.data) + assert.equal(buf.toString('ascii'), fixture.data) }) - it(`should confirm correctly formatted nulldata output`, () => { + it('should confirm correctly formatted nulldata output', () => { const buf = bchjs.Script.nullData.output.encode( - Buffer.from(`${fixture.data}`, "ascii") + Buffer.from(`${fixture.data}`, 'ascii') ) const valid = bchjs.Script.nullData.output.check(buf) assert.equal(valid, true) @@ -239,26 +239,26 @@ describe("#Script", () => { }) }) - describe("#pubKeyTemplate", () => { - describe("#pubKeyInputTemplate", () => { + describe('#pubKeyTemplate', () => { + describe('#pubKeyInputTemplate', () => { fixtures.pubKeyInputTemplate.forEach(fixture => { - it(`should encode pubKey input`, () => { + it('should encode pubKey input', () => { const buf = bchjs.Script.pubKey.input.encode( - Buffer.from(fixture.signature, "hex") + Buffer.from(fixture.signature, 'hex') ) - assert.equal(buf.toString("hex"), fixture.hex) + assert.equal(buf.toString('hex'), fixture.hex) }) - it(`should decode pubKey input`, () => { + it('should decode pubKey input', () => { const buf = bchjs.Script.pubKey.input.decode( - Buffer.from(fixture.hex, "hex") + Buffer.from(fixture.hex, 'hex') ) - assert.equal(buf.toString("hex"), fixture.signature) + assert.equal(buf.toString('hex'), fixture.signature) }) - it(`should confirm correctly formatted pubKeyHash input`, () => { + it('should confirm correctly formatted pubKeyHash input', () => { const buf = bchjs.Script.pubKey.input.encode( - Buffer.from(fixture.signature, "hex") + Buffer.from(fixture.signature, 'hex') ) const valid = bchjs.Script.pubKey.input.check(buf) assert.equal(valid, true) @@ -266,25 +266,25 @@ describe("#Script", () => { }) }) - describe("#pubKeyOutputTemplate", () => { + describe('#pubKeyOutputTemplate', () => { fixtures.pubKeyOutputTemplate.forEach(fixture => { - it(`should encode pubKey output`, () => { + it('should encode pubKey output', () => { const buf = bchjs.Script.pubKey.output.encode( - Buffer.from(fixture.pubKey, "hex") + Buffer.from(fixture.pubKey, 'hex') ) - assert.equal(buf.toString("hex"), fixture.hex) + assert.equal(buf.toString('hex'), fixture.hex) }) - it(`should decode pubKey output`, () => { + it('should decode pubKey output', () => { const buf = bchjs.Script.pubKey.output.decode( - Buffer.from(`${fixture.hex}`, "hex") + Buffer.from(`${fixture.hex}`, 'hex') ) - assert.equal(buf.toString("hex"), fixture.pubKey) + assert.equal(buf.toString('hex'), fixture.pubKey) }) - it(`should confirm correctly formatted pubKey output`, () => { + it('should confirm correctly formatted pubKey output', () => { const buf = bchjs.Script.pubKey.output.encode( - Buffer.from(fixture.pubKey, "hex") + Buffer.from(fixture.pubKey, 'hex') ) const valid = bchjs.Script.pubKey.output.check(buf) assert.equal(valid, true) @@ -293,35 +293,35 @@ describe("#Script", () => { }) }) - describe("#pubKeyHashTemplate", () => { - describe("#pubKeyHashInputTemplate", () => { + describe('#pubKeyHashTemplate', () => { + describe('#pubKeyHashInputTemplate', () => { fixtures.pubKeyHashInputTemplate.forEach(fixture => { - it(`should encode pubKeyHash input`, () => { + it('should encode pubKeyHash input', () => { const buf = bchjs.Script.pubKeyHash.input.encode( - Buffer.from(fixture.signature, "hex"), - Buffer.from(fixture.pubKey, "hex") + Buffer.from(fixture.signature, 'hex'), + Buffer.from(fixture.pubKey, 'hex') ) - assert.equal(buf.toString("hex"), fixture.hex) + assert.equal(buf.toString('hex'), fixture.hex) }) - it(`should decode pubKeyHash input signature`, () => { + it('should decode pubKeyHash input signature', () => { const buf = bchjs.Script.pubKeyHash.input.decode( - Buffer.from(fixture.hex, "hex") + Buffer.from(fixture.hex, 'hex') ) - assert.equal(buf.signature.toString("hex"), fixture.signature) + assert.equal(buf.signature.toString('hex'), fixture.signature) }) - it(`should decode pubKeyHash input pubkey`, () => { + it('should decode pubKeyHash input pubkey', () => { const buf = bchjs.Script.pubKeyHash.input.decode( - Buffer.from(fixture.hex, "hex") + Buffer.from(fixture.hex, 'hex') ) - assert.equal(buf.pubKey.toString("hex"), fixture.pubKey) + assert.equal(buf.pubKey.toString('hex'), fixture.pubKey) }) - it(`should confirm correctly formatted pubKeyHash input`, () => { + it('should confirm correctly formatted pubKeyHash input', () => { const buf = bchjs.Script.pubKeyHash.input.encode( - Buffer.from(fixture.signature, "hex"), - Buffer.from(fixture.pubKey, "hex") + Buffer.from(fixture.signature, 'hex'), + Buffer.from(fixture.pubKey, 'hex') ) const valid = bchjs.Script.pubKeyHash.input.check(buf) assert.equal(valid, true) @@ -329,24 +329,24 @@ describe("#Script", () => { }) }) - describe("#pubKeyHashOutputTemplate", () => { - it("should exercise pubKeyHashOutputTemplate", () => { + describe('#pubKeyHashOutputTemplate', () => { + it('should exercise pubKeyHashOutputTemplate', () => { fixtures.pubKeyHashOutputTemplate.forEach(fixture => { const node = bchjs.HDNode.fromXPriv(fixture.xpriv) const identifier = bchjs.HDNode.toIdentifier(node) - it(`should encode pubKeyHash output`, () => { + it('should encode pubKeyHash output', () => { const buf = bchjs.Script.pubKeyHash.output.encode(identifier) - assert.equal(buf.toString("hex"), fixture.hex) + assert.equal(buf.toString('hex'), fixture.hex) }) - it(`should decode pubKeyHash output`, () => { + it('should decode pubKeyHash output', () => { const buf = bchjs.Script.pubKeyHash.output.decode( - Buffer.from(`${fixture.hex}`, "hex") + Buffer.from(`${fixture.hex}`, 'hex') ) - assert.equal(buf.toString("hex"), identifier.toString("hex")) + assert.equal(buf.toString('hex'), identifier.toString('hex')) }) - it(`should confirm correctly formatted pubKeyHash output`, () => { + it('should confirm correctly formatted pubKeyHash output', () => { const buf = bchjs.Script.pubKeyHash.output.encode(identifier) const valid = bchjs.Script.pubKeyHash.output.check(buf) assert.equal(valid, true) @@ -356,31 +356,31 @@ describe("#Script", () => { }) }) - describe("#multisigTemplate", () => { - describe("#multisigInputTemplate", () => { + describe('#multisigTemplate', () => { + describe('#multisigInputTemplate', () => { fixtures.multisigInputTemplate.forEach(fixture => { - it(`should encode multisig input`, () => { + it('should encode multisig input', () => { const signatures = fixture.signatures.map(signature => signature - ? Buffer.from(signature, "hex") + ? Buffer.from(signature, 'hex') : bchjs.Script.opcodes.OP_0 ) const buf = bchjs.Script.multisig.input.encode(signatures) - assert.equal(buf.toString("hex"), fixture.hex) + assert.equal(buf.toString('hex'), fixture.hex) }) - it(`should decode multisig input`, () => { + it('should decode multisig input', () => { const buf = bchjs.Script.multisig.input.decode( - Buffer.from(fixture.hex, "hex") + Buffer.from(fixture.hex, 'hex') ) - assert.equal(buf[0].toString("hex"), fixture.signatures[0]) + assert.equal(buf[0].toString('hex'), fixture.signatures[0]) }) - it(`should confirm correctly formatted multisig input`, () => { + it('should confirm correctly formatted multisig input', () => { const signatures = fixture.signatures.map(signature => signature - ? Buffer.from(signature, "hex") + ? Buffer.from(signature, 'hex') : bchjs.Script.opcodes.OP_0 ) @@ -391,25 +391,25 @@ describe("#Script", () => { }) }) - describe("#multisigOutputTemplate", () => { + describe('#multisigOutputTemplate', () => { fixtures.multisigOutputTemplate.forEach(fixture => { - it(`should encode multisig output`, () => { - const pubKeys = fixture.pubKeys.map(p => Buffer.from(p, "hex")) + it('should encode multisig output', () => { + const pubKeys = fixture.pubKeys.map(p => Buffer.from(p, 'hex')) const m = pubKeys.length const buf = bchjs.Script.multisig.output.encode(m, pubKeys) - assert.equal(buf.toString("hex"), fixture.hex) + assert.equal(buf.toString('hex'), fixture.hex) }) - it(`should decode multisig output`, () => { + it('should decode multisig output', () => { const output = bchjs.Script.multisig.output.decode( - Buffer.from(`${fixture.hex}`, "hex") + Buffer.from(`${fixture.hex}`, 'hex') ) assert.equal(output.m, fixture.pubKeys.length) }) - it(`should confirm correctly formatted multisig output`, () => { - const pubKeys = fixture.pubKeys.map(p => Buffer.from(p, "hex")) + it('should confirm correctly formatted multisig output', () => { + const pubKeys = fixture.pubKeys.map(p => Buffer.from(p, 'hex')) const m = pubKeys.length const buf = bchjs.Script.multisig.output.encode(m, pubKeys) const valid = bchjs.Script.multisig.output.check(buf) @@ -419,23 +419,23 @@ describe("#Script", () => { }) }) - describe("#scriptHashTemplate", () => { - describe("#scriptHashInputTemplate", () => { + describe('#scriptHashTemplate', () => { + describe('#scriptHashInputTemplate', () => { fixtures.scriptHashInputTemplate.forEach(fixture => { - it(`should encode scriptHash input`, () => { + it('should encode scriptHash input', () => { const buf = bchjs.Script.scriptHash.input.encode( bchjs.Script.fromASM(fixture.redeemScriptSig), bchjs.Script.fromASM(fixture.redeemScript) ) - assert.equal(buf.toString("hex"), fixture.hex) + assert.equal(buf.toString('hex'), fixture.hex) }) - it(`should decode scriptHash input`, () => { + it('should decode scriptHash input', () => { const redeemScriptSig = bchjs.Script.fromASM(fixture.redeemScriptSig) const redeemScript = bchjs.Script.fromASM(fixture.redeemScript) assert.deepEqual( bchjs.Script.scriptHash.input.decode( - Buffer.from(fixture.hex, "hex") + Buffer.from(fixture.hex, 'hex') ), { redeemScriptSig: redeemScriptSig, @@ -444,7 +444,7 @@ describe("#Script", () => { ) }) - it(`should confirm correctly formatted scriptHash input`, () => { + it('should confirm correctly formatted scriptHash input', () => { const buf = bchjs.Script.scriptHash.input.encode( bchjs.Script.fromASM(fixture.redeemScriptSig), bchjs.Script.fromASM(fixture.redeemScript) @@ -455,26 +455,26 @@ describe("#Script", () => { }) }) - describe("#scriptHashOutputTemplate", () => { + describe('#scriptHashOutputTemplate', () => { fixtures.scriptHashOutputTemplate.forEach(fixture => { - it(`should encode scriptHash output`, () => { + it('should encode scriptHash output', () => { const redeemScript = bchjs.Script.fromASM(fixture.output) const scriptHash = bchjs.Crypto.hash160(redeemScript) const buf = bchjs.Script.scriptHash.output.encode(scriptHash) - assert.equal(buf.toString("hex"), fixture.hex) + assert.equal(buf.toString('hex'), fixture.hex) }) - it(`should decode scriptHash output`, () => { + it('should decode scriptHash output', () => { const redeemScript = bchjs.Script.fromASM(fixture.output) const scriptHash = bchjs.Crypto.hash160(redeemScript) const buf = bchjs.Script.scriptHash.output.decode( - Buffer.from(`${fixture.hex}`, "hex") + Buffer.from(`${fixture.hex}`, 'hex') ) assert.deepEqual(buf, scriptHash) }) - it(`should confirm correctly formatted scriptHash output`, () => { + it('should confirm correctly formatted scriptHash output', () => { const redeemScript = bchjs.Script.fromASM(fixture.output) const scriptHash = bchjs.Crypto.hash160(redeemScript) const buf = bchjs.Script.scriptHash.output.encode(scriptHash) diff --git a/test/unit/slp-address.js b/test/unit/slp-address.js index ef0ed07..96cf6da 100644 --- a/test/unit/slp-address.js +++ b/test/unit/slp-address.js @@ -1,15 +1,15 @@ -const assert = require("assert") +const assert = require('assert') -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') // const SLP = require("../../src/slp/slp") // const SLP = new slp({ restURL: "http://fakeurl.com/" }) let slp -const fixtures = require("./fixtures/slp/address.json") -//const axios = require("axios") -//const sinon = require("sinon") +const fixtures = require('./fixtures/slp/address.json') +// const axios = require("axios") +// const sinon = require("sinon") -function flatten(arrays) { +function flatten (arrays) { return [].concat.apply([], arrays) } @@ -87,16 +87,16 @@ const SLP_TESTNET_ADDRESSES_NO_PREFIX = SLP_TESTNET_ADDRESSES.map(address => { return parts[1] }) */ -describe("#SLP Address", () => { +describe('#SLP Address', () => { beforeEach(() => { const bchjs = new BCHJS() // console.log(`bchjs.restURL: ${bchjs.restURL}`) slp = bchjs.SLP }) - describe("#mainnet", () => { - describe("#toLegacyAddress", () => { - it("should convert mainnet legacy address format to itself correctly", () => { + describe('#mainnet', () => { + describe('#toLegacyAddress', () => { + it('should convert mainnet legacy address format to itself correctly', () => { assert.deepEqual( LEGACY_MAINNET_ADDRESSES.map(address => slp.Address.toLegacyAddress(address) @@ -105,7 +105,7 @@ describe("#SLP Address", () => { ) }) - it(`should convert cashAddr to legacyAddr`, async () => { + it('should convert cashAddr to legacyAddr', async () => { assert.deepEqual( CASH_MAINNET_ADDRESSES.map(address => slp.Address.toLegacyAddress(address) @@ -114,7 +114,7 @@ describe("#SLP Address", () => { ) }) - it(`should convert slpAddr to legacyAddr`, async () => { + it('should convert slpAddr to legacyAddr', async () => { assert.deepEqual( SLP_MAINNET_ADDRESSES.map(address => slp.Address.toLegacyAddress(address) @@ -124,8 +124,8 @@ describe("#SLP Address", () => { }) }) - describe("#toCashAddress", () => { - it("should convert mainnet cash address format to itself correctly", () => { + describe('#toCashAddress', () => { + it('should convert mainnet cash address format to itself correctly', () => { assert.deepEqual( CASH_MAINNET_ADDRESSES.map(address => slp.Address.toCashAddress(address) @@ -134,7 +134,7 @@ describe("#SLP Address", () => { ) }) - it(`should convert legacyAddr to cashAddr`, async () => { + it('should convert legacyAddr to cashAddr', async () => { assert.deepEqual( LEGACY_MAINNET_ADDRESSES.map(address => slp.Address.toCashAddress(address) @@ -143,7 +143,7 @@ describe("#SLP Address", () => { ) }) - it(`should convert slpAddr to cashAddr`, async () => { + it('should convert slpAddr to cashAddr', async () => { assert.deepEqual( SLP_MAINNET_ADDRESSES.map(address => slp.Address.toCashAddress(address) @@ -153,8 +153,8 @@ describe("#SLP Address", () => { }) }) - describe("#toSLPAddress", () => { - it("should convert mainnet slp address format to itself correctly", () => { + describe('#toSLPAddress', () => { + it('should convert mainnet slp address format to itself correctly', () => { assert.deepEqual( SLP_MAINNET_ADDRESSES.map(address => slp.Address.toSLPAddress(address) @@ -163,7 +163,7 @@ describe("#SLP Address", () => { ) }) - it(`should convert legacyAddr to slpAddr`, async () => { + it('should convert legacyAddr to slpAddr', async () => { assert.deepEqual( LEGACY_MAINNET_ADDRESSES.map(address => slp.Address.toSLPAddress(address) @@ -172,7 +172,7 @@ describe("#SLP Address", () => { ) }) - it(`should convert cashAddr to slpAddr`, async () => { + it('should convert cashAddr to slpAddr', async () => { assert.deepEqual( CASH_MAINNET_ADDRESSES.map(address => slp.Address.toSLPAddress(address) @@ -182,8 +182,8 @@ describe("#SLP Address", () => { }) }) - describe("#isLegacyAddress", () => { - describe("is legacy addr", () => { + describe('#isLegacyAddress', () => { + describe('is legacy addr', () => { LEGACY_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a legacy address`, () => { const isLegacyaddr = slp.Address.isLegacyAddress(address) @@ -192,7 +192,7 @@ describe("#SLP Address", () => { }) }) - describe("cashaddr is not legacy addr", () => { + describe('cashaddr is not legacy addr', () => { CASH_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not a legacy address`, () => { const isLegacyaddr = slp.Address.isLegacyAddress(address) @@ -201,7 +201,7 @@ describe("#SLP Address", () => { }) }) - describe("slpaddr is not legacy addr", () => { + describe('slpaddr is not legacy addr', () => { SLP_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not a legacy address`, () => { const isLegacyaddr = slp.Address.isLegacyAddress(address) @@ -211,8 +211,8 @@ describe("#SLP Address", () => { }) }) - describe("#isCashAddress", () => { - describe("is cashaddr", () => { + describe('#isCashAddress', () => { + describe('is cashaddr', () => { CASH_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a cashaddr address`, () => { const isCashaddr = slp.Address.isCashAddress(address) @@ -221,7 +221,7 @@ describe("#SLP Address", () => { }) }) - describe("legacy is not cash addr", () => { + describe('legacy is not cash addr', () => { LEGACY_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not a cash address`, () => { const isCashaddr = slp.Address.isCashAddress(address) @@ -230,7 +230,7 @@ describe("#SLP Address", () => { }) }) - describe("slpaddr is not cash addr", () => { + describe('slpaddr is not cash addr', () => { SLP_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not a cash address`, () => { const isCashaddr = slp.Address.isCashAddress(address) @@ -240,8 +240,8 @@ describe("#SLP Address", () => { }) }) - describe("#isSLPAddress", () => { - describe("is slpaddr", () => { + describe('#isSLPAddress', () => { + describe('is slpaddr', () => { SLP_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is an slp address`, () => { const isSLPaddr = slp.Address.isSLPAddress(address) @@ -250,7 +250,7 @@ describe("#SLP Address", () => { }) }) - describe("legacy is not slp addr", () => { + describe('legacy is not slp addr', () => { LEGACY_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not an slp address`, () => { const isSLPaddr = slp.Address.isSLPAddress(address) @@ -259,7 +259,7 @@ describe("#SLP Address", () => { }) }) - describe("cash is not slp addr", () => { + describe('cash is not slp addr', () => { CASH_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not an slp address`, () => { const isSLPaddr = slp.Address.isSLPAddress(address) @@ -269,8 +269,8 @@ describe("#SLP Address", () => { }) }) - describe("#isMainnetAddress", () => { - describe("mainnet legacy addr", () => { + describe('#isMainnetAddress', () => { + describe('mainnet legacy addr', () => { LEGACY_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a mainnet address`, () => { const isMainnetaddr = slp.Address.isMainnetAddress(address) @@ -279,7 +279,7 @@ describe("#SLP Address", () => { }) }) - describe("mainnet cash addr", () => { + describe('mainnet cash addr', () => { CASH_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a mainnet address`, () => { const isMainnetaddr = slp.Address.isMainnetAddress(address) @@ -288,7 +288,7 @@ describe("#SLP Address", () => { }) }) - describe("mainnet slp addr", () => { + describe('mainnet slp addr', () => { SLP_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a mainnet address`, () => { const isMainnetaddr = slp.Address.isMainnetAddress(address) @@ -297,7 +297,7 @@ describe("#SLP Address", () => { }) }) - describe("testnet legacy addr", () => { + describe('testnet legacy addr', () => { LEGACY_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not a mainnet address`, () => { const isMainnetaddr = slp.Address.isMainnetAddress(address) @@ -306,7 +306,7 @@ describe("#SLP Address", () => { }) }) - describe("testnet cash addr", () => { + describe('testnet cash addr', () => { CASH_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not a mainnet address`, () => { const isMainnetaddr = slp.Address.isMainnetAddress(address) @@ -315,7 +315,7 @@ describe("#SLP Address", () => { }) }) - describe("testnet slp addr", () => { + describe('testnet slp addr', () => { SLP_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not a mainnet address`, () => { const isMainnetaddr = slp.Address.isMainnetAddress(address) @@ -325,8 +325,8 @@ describe("#SLP Address", () => { }) }) - describe("#isP2PKHAddress", () => { - describe("mainnet legacy addr", () => { + describe('#isP2PKHAddress', () => { + describe('mainnet legacy addr', () => { MAINNET_P2PKH_ADDRESSES.forEach(address => { it(`should detect ${address} is a P2PKH address`, () => { const isP2PKHaddr = slp.Address.isP2PKHAddress(address) @@ -336,8 +336,8 @@ describe("#SLP Address", () => { }) }) - describe("#isP2SHAddress", () => { - describe("mainnet legacy addr", () => { + describe('#isP2SHAddress', () => { + describe('mainnet legacy addr', () => { MAINNET_P2SH_ADDRESSES.forEach(address => { it(`should detect ${address} is a P2SH address`, () => { const isP2SHaddr = slp.Address.isP2SHAddress(address) @@ -347,72 +347,72 @@ describe("#SLP Address", () => { }) }) - describe("#detectAddressFormat", () => { + describe('#detectAddressFormat', () => { LEGACY_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a legacy address`, () => { const isLegacy = slp.Address.detectAddressFormat(address) - assert.equal(isLegacy, "legacy") + assert.equal(isLegacy, 'legacy') }) }) CASH_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a cash address`, () => { const isCashaddr = slp.Address.detectAddressFormat(address) - assert.equal(isCashaddr, "cashaddr") + assert.equal(isCashaddr, 'cashaddr') }) }) SLP_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is an slp address`, () => { const isSlpaddr = slp.Address.detectAddressFormat(address) - assert.equal(isSlpaddr, "slpaddr") + assert.equal(isSlpaddr, 'slpaddr') }) }) }) - describe("#detectAddressNetwork", () => { + describe('#detectAddressNetwork', () => { LEGACY_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a mainnet address`, () => { const isMainnet = slp.Address.detectAddressNetwork(address) - assert.equal(isMainnet, "mainnet") + assert.equal(isMainnet, 'mainnet') }) }) CASH_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a mainnet address`, () => { const isMainnet = slp.Address.detectAddressNetwork(address) - assert.equal(isMainnet, "mainnet") + assert.equal(isMainnet, 'mainnet') }) }) SLP_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a mainnet address`, () => { const isMainnet = slp.Address.detectAddressNetwork(address) - assert.equal(isMainnet, "mainnet") + assert.equal(isMainnet, 'mainnet') }) }) }) - describe("#detectAddressType", () => { + describe('#detectAddressType', () => { MAINNET_P2PKH_ADDRESSES.forEach(address => { it(`should detect ${address} is a p2pkh address`, () => { const isp2pkh = slp.Address.detectAddressType(address) - assert.equal(isp2pkh, "p2pkh") + assert.equal(isp2pkh, 'p2pkh') }) }) MAINNET_P2SH_ADDRESSES.forEach(address => { it(`should detect ${address} is a p2sh address`, () => { const isp2sh = slp.Address.detectAddressType(address) - assert.equal(isp2sh, "p2sh") + assert.equal(isp2sh, 'p2sh') }) }) }) }) - describe("#testnet", () => { - describe("#toLegacyAddress", () => { - it("should convert testnet legacy address format to itself correctly", () => { + describe('#testnet', () => { + describe('#toLegacyAddress', () => { + it('should convert testnet legacy address format to itself correctly', () => { assert.deepEqual( LEGACY_TESTNET_ADDRESSES.map(address => slp.Address.toLegacyAddress(address) @@ -421,7 +421,7 @@ describe("#SLP Address", () => { ) }) - it(`should convert cashAddr to legacyAddr`, async () => { + it('should convert cashAddr to legacyAddr', async () => { assert.deepEqual( CASH_TESTNET_ADDRESSES.map(address => slp.Address.toLegacyAddress(address) @@ -430,7 +430,7 @@ describe("#SLP Address", () => { ) }) - it(`should convert slpAddr to legacyAddr`, async () => { + it('should convert slpAddr to legacyAddr', async () => { assert.deepEqual( SLP_TESTNET_ADDRESSES.map(address => slp.Address.toLegacyAddress(address) @@ -440,8 +440,8 @@ describe("#SLP Address", () => { }) }) - describe("#toCashAddress", () => { - it("should convert testnet cash address format to itself correctly", () => { + describe('#toCashAddress', () => { + it('should convert testnet cash address format to itself correctly', () => { assert.deepEqual( CASH_TESTNET_ADDRESSES.map(address => slp.Address.toCashAddress(address) @@ -450,7 +450,7 @@ describe("#SLP Address", () => { ) }) - it(`should convert legacyAddr to cashAddr`, async () => { + it('should convert legacyAddr to cashAddr', async () => { assert.deepEqual( LEGACY_TESTNET_ADDRESSES.map(address => slp.Address.toCashAddress(address) @@ -459,7 +459,7 @@ describe("#SLP Address", () => { ) }) - it(`should convert slpAddr to cashAddr`, async () => { + it('should convert slpAddr to cashAddr', async () => { assert.deepEqual( SLP_TESTNET_ADDRESSES.map(address => slp.Address.toCashAddress(address) @@ -469,8 +469,8 @@ describe("#SLP Address", () => { }) }) - describe("#toSLPAddress", () => { - it("should convert testnet slp address format to itself correctly", () => { + describe('#toSLPAddress', () => { + it('should convert testnet slp address format to itself correctly', () => { assert.deepEqual( SLP_TESTNET_ADDRESSES.map(address => slp.Address.toSLPAddress(address) @@ -479,7 +479,7 @@ describe("#SLP Address", () => { ) }) - it(`should convert legacyAddr to slpAddr`, async () => { + it('should convert legacyAddr to slpAddr', async () => { assert.deepEqual( LEGACY_TESTNET_ADDRESSES.map(address => slp.Address.toSLPAddress(address) @@ -488,7 +488,7 @@ describe("#SLP Address", () => { ) }) - it(`should convert cashAddr to slpAddr`, async () => { + it('should convert cashAddr to slpAddr', async () => { assert.deepEqual( CASH_TESTNET_ADDRESSES.map(address => slp.Address.toSLPAddress(address) @@ -498,8 +498,8 @@ describe("#SLP Address", () => { }) }) - describe("#isLegacyAddress", () => { - describe("is legacy addr", () => { + describe('#isLegacyAddress', () => { + describe('is legacy addr', () => { LEGACY_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a legacy address`, () => { const isLegacyaddr = slp.Address.isLegacyAddress(address) @@ -508,7 +508,7 @@ describe("#SLP Address", () => { }) }) - describe("cashaddr is not legacy addr", () => { + describe('cashaddr is not legacy addr', () => { CASH_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not a legacy address`, () => { const isLegacyaddr = slp.Address.isLegacyAddress(address) @@ -517,7 +517,7 @@ describe("#SLP Address", () => { }) }) - describe("slpaddr is not legacy addr", () => { + describe('slpaddr is not legacy addr', () => { SLP_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not a legacy address`, () => { const isLegacyaddr = slp.Address.isLegacyAddress(address) @@ -527,8 +527,8 @@ describe("#SLP Address", () => { }) }) - describe("#isCashAddress", () => { - describe("is cashaddr", () => { + describe('#isCashAddress', () => { + describe('is cashaddr', () => { CASH_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a cashaddr address`, () => { const isCashaddr = slp.Address.isCashAddress(address) @@ -537,7 +537,7 @@ describe("#SLP Address", () => { }) }) - describe("legacy is not cash addr", () => { + describe('legacy is not cash addr', () => { LEGACY_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not a cash address`, () => { const isCashaddr = slp.Address.isCashAddress(address) @@ -546,7 +546,7 @@ describe("#SLP Address", () => { }) }) - describe("slpaddr is not cash addr", () => { + describe('slpaddr is not cash addr', () => { SLP_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not a cash address`, () => { const isCashaddr = slp.Address.isCashAddress(address) @@ -556,8 +556,8 @@ describe("#SLP Address", () => { }) }) - describe("#isSLPAddress", () => { - describe("is slpaddr", () => { + describe('#isSLPAddress', () => { + describe('is slpaddr', () => { SLP_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is an slp address`, () => { const isSLPaddr = slp.Address.isSLPAddress(address) @@ -566,7 +566,7 @@ describe("#SLP Address", () => { }) }) - describe("legacy is not slp addr", () => { + describe('legacy is not slp addr', () => { LEGACY_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not an slp address`, () => { const isSLPaddr = slp.Address.isSLPAddress(address) @@ -575,7 +575,7 @@ describe("#SLP Address", () => { }) }) - describe("cash is not slp addr", () => { + describe('cash is not slp addr', () => { CASH_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not an slp address`, () => { const isSLPaddr = slp.Address.isSLPAddress(address) @@ -585,8 +585,8 @@ describe("#SLP Address", () => { }) }) - describe("#isTestnetAddress", () => { - describe("testnet legacy addr", () => { + describe('#isTestnetAddress', () => { + describe('testnet legacy addr', () => { LEGACY_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a testnet address`, () => { const isTestnetaddr = slp.Address.isTestnetAddress(address) @@ -595,7 +595,7 @@ describe("#SLP Address", () => { }) }) - describe("testnet cash addr", () => { + describe('testnet cash addr', () => { CASH_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a testnet address`, () => { const isTestnetaddr = slp.Address.isTestnetAddress(address) @@ -604,7 +604,7 @@ describe("#SLP Address", () => { }) }) - describe("testnet slp addr", () => { + describe('testnet slp addr', () => { SLP_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a testnet address`, () => { const isTestnetaddr = slp.Address.isTestnetAddress(address) @@ -613,7 +613,7 @@ describe("#SLP Address", () => { }) }) - describe("mainnet legacy addr", () => { + describe('mainnet legacy addr', () => { LEGACY_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not a testnet address`, () => { const isTestnetaddr = slp.Address.isTestnetAddress(address) @@ -622,7 +622,7 @@ describe("#SLP Address", () => { }) }) - describe("mainnet cash addr", () => { + describe('mainnet cash addr', () => { CASH_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not a testnet address`, () => { const isTestnetaddr = slp.Address.isTestnetAddress(address) @@ -631,7 +631,7 @@ describe("#SLP Address", () => { }) }) - describe("mainnet slp addr", () => { + describe('mainnet slp addr', () => { SLP_MAINNET_ADDRESSES.forEach(address => { it(`should detect ${address} is not a testnet address`, () => { const isTestnetaddr = slp.Address.isTestnetAddress(address) @@ -641,8 +641,8 @@ describe("#SLP Address", () => { }) }) - describe("#isP2PKHAddress", () => { - describe("testnet legacy addr", () => { + describe('#isP2PKHAddress', () => { + describe('testnet legacy addr', () => { TESTNET_P2PKH_ADDRESSES.forEach(address => { it(`should detect ${address} is a P2PKH address`, () => { const isP2PKHaddr = slp.Address.isP2PKHAddress(address) @@ -652,8 +652,8 @@ describe("#SLP Address", () => { }) }) - describe("#isP2SHAddress", () => { - describe("testnet legacy addr", () => { + describe('#isP2SHAddress', () => { + describe('testnet legacy addr', () => { TESTNET_P2SH_ADDRESSES.forEach(address => { it(`should detect ${address} is a P2SH address`, () => { const isP2SHaddr = slp.Address.isP2SHAddress(address) @@ -663,66 +663,66 @@ describe("#SLP Address", () => { }) }) - describe("#detectAddressFormat", () => { + describe('#detectAddressFormat', () => { LEGACY_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a legacy address`, () => { const isLegacy = slp.Address.detectAddressFormat(address) - assert.equal(isLegacy, "legacy") + assert.equal(isLegacy, 'legacy') }) }) CASH_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a cash address`, () => { const isCashaddr = slp.Address.detectAddressFormat(address) - assert.equal(isCashaddr, "cashaddr") + assert.equal(isCashaddr, 'cashaddr') }) }) SLP_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is an slp address`, () => { const isSlpaddr = slp.Address.detectAddressFormat(address) - assert.equal(isSlpaddr, "slpaddr") + assert.equal(isSlpaddr, 'slpaddr') }) }) }) - describe("#detectAddressNetwork", () => { + describe('#detectAddressNetwork', () => { LEGACY_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a testnet address`, () => { const isTestnet = slp.Address.detectAddressNetwork(address) - assert.equal(isTestnet, "testnet") + assert.equal(isTestnet, 'testnet') }) }) CASH_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a testnet address`, () => { const isTestnet = slp.Address.detectAddressNetwork(address) - assert.equal(isTestnet, "testnet") + assert.equal(isTestnet, 'testnet') }) }) SLP_TESTNET_ADDRESSES.forEach(address => { it(`should detect ${address} is a testnet address`, () => { const isTestnet = slp.Address.detectAddressNetwork(address) - assert.equal(isTestnet, "testnet") + assert.equal(isTestnet, 'testnet') }) }) }) - describe("#detectAddressType", () => { + describe('#detectAddressType', () => { TESTNET_P2PKH_ADDRESSES.forEach(address => { it(`should detect ${address} is a p2pkh address`, () => { const isp2pkh = slp.Address.detectAddressType(address) - assert.equal(isp2pkh, "p2pkh") + assert.equal(isp2pkh, 'p2pkh') }) }) }) - describe("#detectAddressType", () => { + describe('#detectAddressType', () => { TESTNET_P2SH_ADDRESSES.forEach(address => { it(`should detect ${address} is a p2sh address`, () => { const isp2sh = slp.Address.detectAddressType(address) - assert.equal(isp2sh, "p2sh") + assert.equal(isp2sh, 'p2sh') }) }) }) diff --git a/test/unit/slp-ecpair.js b/test/unit/slp-ecpair.js index 5024520..2bcbafd 100644 --- a/test/unit/slp-ecpair.js +++ b/test/unit/slp-ecpair.js @@ -1,21 +1,21 @@ -const assert = require("assert") +const assert = require('assert') -const fixtures = require("./fixtures/slp/ecpair.json") +const fixtures = require('./fixtures/slp/ecpair.json') -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') let slp // const SLP = require("../../src/slp/slp") // const slp = new SLP({ restURL: "http://fakeurl.com/" }) -describe("#SLP ECPair", () => { +describe('#SLP ECPair', () => { beforeEach(() => { const bchjs = new BCHJS() slp = bchjs.SLP }) - describe("#toSLPAddress", () => { - it(`should return slp address for ecpair`, async () => { + describe('#toSLPAddress', () => { + it('should return slp address for ecpair', async () => { fixtures.wif.forEach((wif, index) => { const ecpair = slp.ECPair.fromWIF(wif) const slpAddr = slp.ECPair.toSLPAddress(ecpair) diff --git a/test/unit/slp-nft1.js b/test/unit/slp-nft1.js index 9e9640b..b22083a 100644 --- a/test/unit/slp-nft1.js +++ b/test/unit/slp-nft1.js @@ -2,25 +2,25 @@ Unit tests for the TokenType1 library. */ -const assert = require("chai").assert -const nock = require("nock") // http call mocking -const sinon = require("sinon") +const assert = require('chai').assert +const nock = require('nock') // http call mocking +const sinon = require('sinon') // const axios = require("axios") // Default to unit tests unless some other value for TEST is passed. -if (!process.env.TEST) process.env.TEST = "unit" +if (!process.env.TEST) process.env.TEST = 'unit' // const SERVER = bchjs.restURL -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') const bchjs = new BCHJS() // Mock data used for unit tests // const mockData = require("./fixtures/slp/mock-utils") // Default to unit tests unless some other value for TEST is passed. -if (!process.env.TEST) process.env.TEST = "unit" +if (!process.env.TEST) process.env.TEST = 'unit' -describe("#SLP NFT1", () => { +describe('#SLP NFT1', () => { let sandbox beforeEach(() => { @@ -38,13 +38,13 @@ describe("#SLP NFT1", () => { sandbox.restore() }) - describe("#newNFTGroupOpReturn", () => { - it("should generate new NFT Group OP_RETURN code", () => { + describe('#newNFTGroupOpReturn', () => { + it('should generate new NFT Group OP_RETURN code', () => { const configObj = { - name: "SLP Test Token", - ticker: "SLPTEST", - documentUrl: "https://bchjs.cash", - documentHash: "", + name: 'SLP Test Token', + ticker: 'SLPTEST', + documentUrl: 'https://bchjs.cash', + documentHash: '', initialQty: 5 } @@ -55,48 +55,48 @@ describe("#SLP NFT1", () => { }) }) - describe("#mintNFTGroupOpReturn", () => { - it("should generate NFT Group Mint OP_RETURN code", () => { + describe('#mintNFTGroupOpReturn', () => { + it('should generate NFT Group Mint OP_RETURN code', () => { const tokenUtxoData = [ { txid: - "3de3766b10506c9156533f1639979e49d1884521543c13e4af73647df1ed3f76", + '3de3766b10506c9156533f1639979e49d1884521543c13e4af73647df1ed3f76', vout: 2, - value: "546", + value: '546', height: 638207, confirmations: 63, satoshis: 546, - utxoType: "minting-baton", - transactionType: "mint", + utxoType: 'minting-baton', + transactionType: 'mint', tokenId: - "680967b3f6fe080dbca8dbd370665bd29742e3490db24e2f28d08b424511807e", + '680967b3f6fe080dbca8dbd370665bd29742e3490db24e2f28d08b424511807e', tokenType: 129, - tokenTicker: "NFTP", - tokenName: "NFT Parent", - tokenDocumentUrl: "FullStack.cash", - tokenDocumentHash: "", + tokenTicker: 'NFTP', + tokenName: 'NFT Parent', + tokenDocumentUrl: 'FullStack.cash', + tokenDocumentHash: '', decimals: 0, mintBatonVout: 2, isValid: true }, { txid: - "3de3766b10506c9156533f1639979e49d1884521543c13e4af73647df1ed3f76", + '3de3766b10506c9156533f1639979e49d1884521543c13e4af73647df1ed3f76', vout: 1, - value: "546", + value: '546', height: 638207, confirmations: 63, satoshis: 546, - utxoType: "token", + utxoType: 'token', tokenQty: 10, - transactionType: "mint", + transactionType: 'mint', tokenId: - "680967b3f6fe080dbca8dbd370665bd29742e3490db24e2f28d08b424511807e", + '680967b3f6fe080dbca8dbd370665bd29742e3490db24e2f28d08b424511807e', tokenType: 129, - tokenTicker: "NFTP", - tokenName: "NFT Parent", - tokenDocumentUrl: "FullStack.cash", - tokenDocumentHash: "", + tokenTicker: 'NFTP', + tokenName: 'NFT Parent', + tokenDocumentUrl: 'FullStack.cash', + tokenDocumentHash: '', decimals: 0, mintBatonVout: 2, isValid: true @@ -110,13 +110,13 @@ describe("#SLP NFT1", () => { }) }) - describe("#generateNFTChildOpReturn", () => { - it("should generate NFT Genesis OP_RETURN code", () => { + describe('#generateNFTChildOpReturn', () => { + it('should generate NFT Genesis OP_RETURN code', () => { const configObj = { - name: "SLP Test Token", - ticker: "SLPTEST", - documentUrl: "https://bchjs.cash", - documentHash: "" + name: 'SLP Test Token', + ticker: 'SLPTEST', + documentUrl: 'https://bchjs.cash', + documentHash: '' } const result = bchjs.SLP.NFT1.generateNFTChildGenesisOpReturn(configObj) @@ -126,26 +126,26 @@ describe("#SLP NFT1", () => { }) }) - describe("#generateNFTChildSendOpReturn", () => { - it("should generate send OP_RETURN code for no change", () => { + describe('#generateNFTChildSendOpReturn', () => { + it('should generate send OP_RETURN code for no change', () => { // Mock UTXO. const tokenUtxos = [ { txid: - "81955624a8eb7011769ff5faa607f78f84b0f8152b9145e7db8b1e521c895ee3", + '81955624a8eb7011769ff5faa607f78f84b0f8152b9145e7db8b1e521c895ee3', vout: 1, - value: "546", + value: '546', height: 638273, confirmations: 42, satoshis: 546, - utxoType: "token", + utxoType: 'token', tokenQty: 1, tokenId: - "81955624a8eb7011769ff5faa607f78f84b0f8152b9145e7db8b1e521c895ee3", - tokenTicker: "NFTC", - tokenName: "NFT Child", - tokenDocumentUrl: "https://FullStack.cash", - tokenDocumentHash: "", + '81955624a8eb7011769ff5faa607f78f84b0f8152b9145e7db8b1e521c895ee3', + tokenTicker: 'NFTC', + tokenName: 'NFT Child', + tokenDocumentUrl: 'https://FullStack.cash', + tokenDocumentHash: '', decimals: 0, tokenType: 129, isValid: true @@ -155,29 +155,29 @@ describe("#SLP NFT1", () => { const result = bchjs.SLP.NFT1.generateNFTChildSendOpReturn(tokenUtxos, 1) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.hasAllKeys(result, ["script", "outputs"]) + assert.hasAllKeys(result, ['script', 'outputs']) assert.isNumber(result.outputs) }) - it("should generate send OP_RETURN code with change", () => { + it('should generate send OP_RETURN code with change', () => { // Mock UTXO. const tokenUtxos = [ { txid: - "81955624a8eb7011769ff5faa607f78f84b0f8152b9145e7db8b1e521c895ee3", + '81955624a8eb7011769ff5faa607f78f84b0f8152b9145e7db8b1e521c895ee3', vout: 1, - value: "546", + value: '546', height: 638273, confirmations: 42, satoshis: 546, - utxoType: "token", + utxoType: 'token', tokenQty: 4, tokenId: - "81955624a8eb7011769ff5faa607f78f84b0f8152b9145e7db8b1e521c895ee3", - tokenTicker: "NFTC", - tokenName: "NFT Child", - tokenDocumentUrl: "https://FullStack.cash", - tokenDocumentHash: "", + '81955624a8eb7011769ff5faa607f78f84b0f8152b9145e7db8b1e521c895ee3', + tokenTicker: 'NFTC', + tokenName: 'NFT Child', + tokenDocumentUrl: 'https://FullStack.cash', + tokenDocumentHash: '', decimals: 0, tokenType: 129, isValid: true @@ -187,33 +187,33 @@ describe("#SLP NFT1", () => { const result = bchjs.SLP.NFT1.generateNFTChildSendOpReturn(tokenUtxos, 1) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.hasAllKeys(result, ["script", "outputs"]) + assert.hasAllKeys(result, ['script', 'outputs']) assert.isNumber(result.outputs) }) }) - describe("#generateNFTGroupSendOpReturn", () => { - it("should generate send OP_RETURN with change", () => { + describe('#generateNFTGroupSendOpReturn', () => { + it('should generate send OP_RETURN with change', () => { // Mock UTXO. const tokenUtxos = [ { txid: - "35846676e7514658bbd2fd60b1f0d4d86195908f6b2de5328d54c8e4a2d05919", + '35846676e7514658bbd2fd60b1f0d4d86195908f6b2de5328d54c8e4a2d05919', vout: 1, - value: "546", + value: '546', height: 638207, confirmations: 3, satoshis: 546, - utxoType: "token", + utxoType: 'token', tokenQty: 10, - transactionType: "mint", + transactionType: 'mint', tokenId: - "eee4b82e4bb7113eca433829144363fc45f110693c286494fbf5b5c8043cc981", + 'eee4b82e4bb7113eca433829144363fc45f110693c286494fbf5b5c8043cc981', tokenType: 129, - tokenTicker: "NFTTT", - tokenName: "NFT Test Token", - tokenDocumentUrl: "https://FullStack.cash", - tokenDocumentHash: "", + tokenTicker: 'NFTTT', + tokenName: 'NFT Test Token', + tokenDocumentUrl: 'https://FullStack.cash', + tokenDocumentHash: '', decimals: 0, mintBatonVout: 2, isValid: true @@ -223,31 +223,31 @@ describe("#SLP NFT1", () => { const result = bchjs.SLP.NFT1.generateNFTGroupSendOpReturn(tokenUtxos, 1) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.hasAllKeys(result, ["script", "outputs"]) + assert.hasAllKeys(result, ['script', 'outputs']) assert.isNumber(result.outputs) }) - it("should generate send OP_RETURN with no change", () => { + it('should generate send OP_RETURN with no change', () => { // Mock UTXO. const tokenUtxos = [ { txid: - "35846676e7514658bbd2fd60b1f0d4d86195908f6b2de5328d54c8e4a2d05919", + '35846676e7514658bbd2fd60b1f0d4d86195908f6b2de5328d54c8e4a2d05919', vout: 1, - value: "546", + value: '546', height: 638207, confirmations: 3, satoshis: 546, - utxoType: "token", + utxoType: 'token', tokenQty: 10, - transactionType: "mint", + transactionType: 'mint', tokenId: - "eee4b82e4bb7113eca433829144363fc45f110693c286494fbf5b5c8043cc981", + 'eee4b82e4bb7113eca433829144363fc45f110693c286494fbf5b5c8043cc981', tokenType: 129, - tokenTicker: "NFTTT", - tokenName: "NFT Test Token", - tokenDocumentUrl: "https://FullStack.cash", - tokenDocumentHash: "", + tokenTicker: 'NFTTT', + tokenName: 'NFT Test Token', + tokenDocumentUrl: 'https://FullStack.cash', + tokenDocumentHash: '', decimals: 0, mintBatonVout: 2, isValid: true @@ -257,7 +257,7 @@ describe("#SLP NFT1", () => { const result = bchjs.SLP.NFT1.generateNFTGroupSendOpReturn(tokenUtxos, 10) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.hasAllKeys(result, ["script", "outputs"]) + assert.hasAllKeys(result, ['script', 'outputs']) assert.isNumber(result.outputs) }) }) diff --git a/test/unit/slp-tokentype1.js b/test/unit/slp-tokentype1.js index 1668ca7..920dd75 100644 --- a/test/unit/slp-tokentype1.js +++ b/test/unit/slp-tokentype1.js @@ -2,25 +2,25 @@ Unit tests for the TokenType1 library. */ -const assert = require("chai").assert -const nock = require("nock") // http call mocking -const sinon = require("sinon") +const assert = require('chai').assert +const nock = require('nock') // http call mocking +const sinon = require('sinon') // const axios = require("axios") // Default to unit tests unless some other value for TEST is passed. -if (!process.env.TEST) process.env.TEST = "unit" +if (!process.env.TEST) process.env.TEST = 'unit' // const SERVER = bchjs.restURL -const BCHJS = require("../../src/bch-js") +const BCHJS = require('../../src/bch-js') const bchjs = new BCHJS() // Mock data used for unit tests // const mockData = require("./fixtures/slp/mock-utils") // Default to unit tests unless some other value for TEST is passed. -if (!process.env.TEST) process.env.TEST = "unit" +if (!process.env.TEST) process.env.TEST = 'unit' -describe("#SLP TokenType1", () => { +describe('#SLP TokenType1', () => { let sandbox beforeEach(() => { @@ -38,63 +38,63 @@ describe("#SLP TokenType1", () => { sandbox.restore() }) - describe("#generateSendOpReturn", () => { - it("should generate send OP_RETURN code", () => { + describe('#generateSendOpReturn', () => { + it('should generate send OP_RETURN code', () => { // Mock UTXO. const tokenUtxos = [ { txid: - "a8eb788b8ddda6faea00e6e2756624b8feb97655363d0400dd66839ea619d36e", + 'a8eb788b8ddda6faea00e6e2756624b8feb97655363d0400dd66839ea619d36e', vout: 2, - value: "546", + value: '546', confirmations: 0, satoshis: 546, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7", - tokenTicker: "TOK-CH", - tokenName: "TokyoCash", - tokenDocumentUrl: "", - tokenDocumentHash: "", + '497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7', + tokenTicker: 'TOK-CH', + tokenName: 'TokyoCash', + tokenDocumentUrl: '', + tokenDocumentHash: '', decimals: 8, tokenQty: 7 } ] const result = bchjs.SLP.TokenType1.generateSendOpReturn(tokenUtxos, 1) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.hasAllKeys(result, ["script", "outputs"]) + assert.hasAllKeys(result, ['script', 'outputs']) assert.isNumber(result.outputs) }) }) - describe("#generateSendOpReturn01", () => { - it("should generate send OP_RETURN code", () => { + describe('#generateSendOpReturn01', () => { + it('should generate send OP_RETURN code', () => { // Mock UTXO. const tokenUtxos = [ { - address: "bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu", + address: 'bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu', decimals: 9, height: 0, isValid: true, satoshis: 546, - tokenDocumentHash: "", - tokenDocumentUrl: "https://cashtabapp.com/", + tokenDocumentHash: '', + tokenDocumentUrl: 'https://cashtabapp.com/', tokenId: - "bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1", - tokenName: "Cash Tab Points", + 'bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1', + tokenName: 'Cash Tab Points', tokenQty: 1000000000, - tokenTicker: "CTP", + tokenTicker: 'CTP', tokenType: 1, - transactionType: "send", + transactionType: 'send', tx_hash: - "ff46ab7730194691b89301e7d5d4805c304db83522e8aa4e5fa8b592c8aecf41", + 'ff46ab7730194691b89301e7d5d4805c304db83522e8aa4e5fa8b592c8aecf41', tx_pos: 1, txid: - "ff46ab7730194691b89301e7d5d4805c304db83522e8aa4e5fa8b592c8aecf41", - utxoType: "token", + 'ff46ab7730194691b89301e7d5d4805c304db83522e8aa4e5fa8b592c8aecf41', + utxoType: 'token', value: 546, vout: 1 } @@ -104,38 +104,38 @@ describe("#SLP TokenType1", () => { tokenUtxos, 0.000000001 ) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.hasAllKeys(result, ["script", "outputs"]) + assert.hasAllKeys(result, ['script', 'outputs']) assert.isNumber(result.outputs) }) }) - describe("#generateSendOpReturn02", () => { - it("should generate send OP_RETURN code", () => { + describe('#generateSendOpReturn02', () => { + it('should generate send OP_RETURN code', () => { // Mock UTXO. const tokenUtxos = [ { - address: "bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu", + address: 'bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu', decimals: 9, height: 660974, isValid: true, satoshis: 546, - tokenDocumentHash: "", - tokenDocumentUrl: "https://cashtabapp.com/", + tokenDocumentHash: '', + tokenDocumentUrl: 'https://cashtabapp.com/', tokenId: - "bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1", - tokenName: "Cash Tab Points", + 'bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1', + tokenName: 'Cash Tab Points', tokenQty: 1000000000, - tokenTicker: "CTP", + tokenTicker: 'CTP', tokenType: 1, - transactionType: "send", + transactionType: 'send', tx_hash: - "2922728e4febc21523369902615165bc15753f79f7488d3f1a260808ff0e116d", + '2922728e4febc21523369902615165bc15753f79f7488d3f1a260808ff0e116d', tx_pos: 1, txid: - "2922728e4febc21523369902615165bc15753f79f7488d3f1a260808ff0e116d", - utxoType: "token", + '2922728e4febc21523369902615165bc15753f79f7488d3f1a260808ff0e116d', + utxoType: 'token', value: 546, vout: 1 } @@ -145,38 +145,38 @@ describe("#SLP TokenType1", () => { tokenUtxos, 1000000000 ) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.hasAllKeys(result, ["script", "outputs"]) + assert.hasAllKeys(result, ['script', 'outputs']) assert.isNumber(result.outputs) }) }) - describe("#generateSendOpReturn03", () => { - it("should generate send OP_RETURN code", () => { + describe('#generateSendOpReturn03', () => { + it('should generate send OP_RETURN code', () => { // Mock UTXO. const tokenUtxos = [ { - address: "bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu", + address: 'bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu', decimals: 9, height: 660974, isValid: true, satoshis: 546, - tokenDocumentHash: "", - tokenDocumentUrl: "https://cashtabapp.com/", + tokenDocumentHash: '', + tokenDocumentUrl: 'https://cashtabapp.com/', tokenId: - "bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1", - tokenName: "Cash Tab Points", + 'bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1', + tokenName: 'Cash Tab Points', tokenQty: 1000000000, - tokenTicker: "CTP", + tokenTicker: 'CTP', tokenType: 1, - transactionType: "send", + transactionType: 'send', tx_hash: - "2922728e4febc21523369902615165bc15753f79f7488d3f1a260808ff0e116d", + '2922728e4febc21523369902615165bc15753f79f7488d3f1a260808ff0e116d', tx_pos: 1, txid: - "2922728e4febc21523369902615165bc15753f79f7488d3f1a260808ff0e116d", - utxoType: "token", + '2922728e4febc21523369902615165bc15753f79f7488d3f1a260808ff0e116d', + utxoType: 'token', value: 546, vout: 1 } @@ -186,134 +186,134 @@ describe("#SLP TokenType1", () => { tokenUtxos, 0.000000001 ) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.hasAllKeys(result, ["script", "outputs"]) + assert.hasAllKeys(result, ['script', 'outputs']) assert.isNumber(result.outputs) }) }) - describe("#generateSendOpReturn04", () => { - it("should generate send OP_RETURN code", () => { + describe('#generateSendOpReturn04', () => { + it('should generate send OP_RETURN code', () => { // Mock UTXO. const tokenUtxos = [ { - address: "bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu", + address: 'bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu', decimals: 9, height: 660974, isValid: true, satoshis: 546, - tokenDocumentHash: "", - tokenDocumentUrl: "https://cashtabapp.com/", + tokenDocumentHash: '', + tokenDocumentUrl: 'https://cashtabapp.com/', tokenId: - "bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1", - tokenName: "Cash Tab Points", + 'bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1', + tokenName: 'Cash Tab Points', tokenQty: 1000000000, - tokenTicker: "CTP", + tokenTicker: 'CTP', tokenType: 1, - transactionType: "send", + transactionType: 'send', tx_hash: - "2922728e4febc21523369902615165bc15753f79f7488d3f1a260808ff0e116d", + '2922728e4febc21523369902615165bc15753f79f7488d3f1a260808ff0e116d', tx_pos: 1, txid: - "2922728e4febc21523369902615165bc15753f79f7488d3f1a260808ff0e116d", - utxoType: "token", + '2922728e4febc21523369902615165bc15753f79f7488d3f1a260808ff0e116d', + utxoType: 'token', value: 546, vout: 1 }, { - address: "bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu", + address: 'bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu', decimals: 9, height: 0, isValid: true, satoshis: 546, - tokenDocumentHash: "", - tokenDocumentUrl: "https://cashtabapp.com/", + tokenDocumentHash: '', + tokenDocumentUrl: 'https://cashtabapp.com/', tokenId: - "bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1", - tokenName: "Cash Tab Points", + 'bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1', + tokenName: 'Cash Tab Points', tokenQty: 1.000000001, - tokenTicker: "CTP", + tokenTicker: 'CTP', tokenType: 1, - transactionType: "send", + transactionType: 'send', tx_hash: - "2ae85b47d9dc61bd90909048d057234efe9508bcc6a599708d029122ed113515", + '2ae85b47d9dc61bd90909048d057234efe9508bcc6a599708d029122ed113515', tx_pos: 1, txid: - "2ae85b47d9dc61bd90909048d057234efe9508bcc6a599708d029122ed113515", - utxoType: "token", + '2ae85b47d9dc61bd90909048d057234efe9508bcc6a599708d029122ed113515', + utxoType: 'token', value: 546, vout: 1 }, { - address: "bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu", + address: 'bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu', decimals: 9, height: 0, isValid: true, satoshis: 546, - tokenDocumentHash: "", - tokenDocumentUrl: "https://cashtabapp.com/", + tokenDocumentHash: '', + tokenDocumentUrl: 'https://cashtabapp.com/', tokenId: - "bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1", - tokenName: "Cash Tab Points", + 'bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1', + tokenName: 'Cash Tab Points', tokenQty: 1, - tokenTicker: "CTP", + tokenTicker: 'CTP', tokenType: 1, - transactionType: "send", + transactionType: 'send', tx_hash: - "4ebd5acb0f3c4edefb9d15295cc2e14f4dada90a3ff0ee17cf77efc57e2940a1", + '4ebd5acb0f3c4edefb9d15295cc2e14f4dada90a3ff0ee17cf77efc57e2940a1', tx_pos: 1, txid: - "4ebd5acb0f3c4edefb9d15295cc2e14f4dada90a3ff0ee17cf77efc57e2940a1", - utxoType: "token", + '4ebd5acb0f3c4edefb9d15295cc2e14f4dada90a3ff0ee17cf77efc57e2940a1', + utxoType: 'token', value: 546, vout: 1 }, { - address: "bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu", + address: 'bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu', decimals: 9, height: 0, isValid: true, satoshis: 546, - tokenDocumentHash: "", - tokenDocumentUrl: "https://cashtabapp.com/", + tokenDocumentHash: '', + tokenDocumentUrl: 'https://cashtabapp.com/', tokenId: - "bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1", - tokenName: "Cash Tab Points", + 'bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1', + tokenName: 'Cash Tab Points', tokenQty: 1, - tokenTicker: "CTP", + tokenTicker: 'CTP', tokenType: 1, - transactionType: "send", + transactionType: 'send', tx_hash: - "5ed96f59ae4fec31ee8fc96304bd610c3658f9df2fde35119aad6f44547420f9", + '5ed96f59ae4fec31ee8fc96304bd610c3658f9df2fde35119aad6f44547420f9', tx_pos: 1, txid: - "5ed96f59ae4fec31ee8fc96304bd610c3658f9df2fde35119aad6f44547420f9", - utxoType: "token", + '5ed96f59ae4fec31ee8fc96304bd610c3658f9df2fde35119aad6f44547420f9', + utxoType: 'token', value: 546, vout: 1 }, { - address: "bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu", + address: 'bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu', decimals: 9, height: 0, isValid: true, satoshis: 546, - tokenDocumentHash: "", - tokenDocumentUrl: "https://cashtabapp.com/", + tokenDocumentHash: '', + tokenDocumentUrl: 'https://cashtabapp.com/', tokenId: - "bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1", - tokenName: "Cash Tab Points", + 'bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1', + tokenName: 'Cash Tab Points', tokenQty: 1, - tokenTicker: "CTP", + tokenTicker: 'CTP', tokenType: 1, - transactionType: "send", + transactionType: 'send', tx_hash: - "648465087cc8ba218ccf6b7261256924ef2dc1d20e5c10117a6d555065c01600", + '648465087cc8ba218ccf6b7261256924ef2dc1d20e5c10117a6d555065c01600', tx_pos: 1, txid: - "648465087cc8ba218ccf6b7261256924ef2dc1d20e5c10117a6d555065c01600", - utxoType: "token", + '648465087cc8ba218ccf6b7261256924ef2dc1d20e5c10117a6d555065c01600', + utxoType: 'token', value: 546, vout: 1 } @@ -323,134 +323,134 @@ describe("#SLP TokenType1", () => { tokenUtxos, 1000000004.000000001 ) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.hasAllKeys(result, ["script", "outputs"]) + assert.hasAllKeys(result, ['script', 'outputs']) assert.isNumber(result.outputs) }) }) - describe("#generateSendOpReturn05", () => { - it("should generate send OP_RETURN code", () => { + describe('#generateSendOpReturn05', () => { + it('should generate send OP_RETURN code', () => { // Mock UTXO. const tokenUtxos = [ { - address: "bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu", + address: 'bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu', decimals: 9, height: 660974, isValid: true, satoshis: 546, - tokenDocumentHash: "", - tokenDocumentUrl: "https://cashtabapp.com/", + tokenDocumentHash: '', + tokenDocumentUrl: 'https://cashtabapp.com/', tokenId: - "bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1", - tokenName: "Cash Tab Points", + 'bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1', + tokenName: 'Cash Tab Points', tokenQty: 1000000000, - tokenTicker: "CTP", + tokenTicker: 'CTP', tokenType: 1, - transactionType: "send", + transactionType: 'send', tx_hash: - "2922728e4febc21523369902615165bc15753f79f7488d3f1a260808ff0e116d", + '2922728e4febc21523369902615165bc15753f79f7488d3f1a260808ff0e116d', tx_pos: 1, txid: - "2922728e4febc21523369902615165bc15753f79f7488d3f1a260808ff0e116d", - utxoType: "token", + '2922728e4febc21523369902615165bc15753f79f7488d3f1a260808ff0e116d', + utxoType: 'token', value: 546, vout: 1 }, { - address: "bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu", + address: 'bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu', decimals: 9, height: 0, isValid: true, satoshis: 546, - tokenDocumentHash: "", - tokenDocumentUrl: "https://cashtabapp.com/", + tokenDocumentHash: '', + tokenDocumentUrl: 'https://cashtabapp.com/', tokenId: - "bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1", - tokenName: "Cash Tab Points", + 'bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1', + tokenName: 'Cash Tab Points', tokenQty: 1.000000001, - tokenTicker: "CTP", + tokenTicker: 'CTP', tokenType: 1, - transactionType: "send", + transactionType: 'send', tx_hash: - "2ae85b47d9dc61bd90909048d057234efe9508bcc6a599708d029122ed113515", + '2ae85b47d9dc61bd90909048d057234efe9508bcc6a599708d029122ed113515', tx_pos: 1, txid: - "2ae85b47d9dc61bd90909048d057234efe9508bcc6a599708d029122ed113515", - utxoType: "token", + '2ae85b47d9dc61bd90909048d057234efe9508bcc6a599708d029122ed113515', + utxoType: 'token', value: 546, vout: 1 }, { - address: "bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu", + address: 'bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu', decimals: 9, height: 0, isValid: true, satoshis: 546, - tokenDocumentHash: "", - tokenDocumentUrl: "https://cashtabapp.com/", + tokenDocumentHash: '', + tokenDocumentUrl: 'https://cashtabapp.com/', tokenId: - "bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1", - tokenName: "Cash Tab Points", + 'bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1', + tokenName: 'Cash Tab Points', tokenQty: 1, - tokenTicker: "CTP", + tokenTicker: 'CTP', tokenType: 1, - transactionType: "send", + transactionType: 'send', tx_hash: - "4ebd5acb0f3c4edefb9d15295cc2e14f4dada90a3ff0ee17cf77efc57e2940a1", + '4ebd5acb0f3c4edefb9d15295cc2e14f4dada90a3ff0ee17cf77efc57e2940a1', tx_pos: 1, txid: - "4ebd5acb0f3c4edefb9d15295cc2e14f4dada90a3ff0ee17cf77efc57e2940a1", - utxoType: "token", + '4ebd5acb0f3c4edefb9d15295cc2e14f4dada90a3ff0ee17cf77efc57e2940a1', + utxoType: 'token', value: 546, vout: 1 }, { - address: "bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu", + address: 'bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu', decimals: 9, height: 0, isValid: true, satoshis: 546, - tokenDocumentHash: "", - tokenDocumentUrl: "https://cashtabapp.com/", + tokenDocumentHash: '', + tokenDocumentUrl: 'https://cashtabapp.com/', tokenId: - "bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1", - tokenName: "Cash Tab Points", + 'bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1', + tokenName: 'Cash Tab Points', tokenQty: 1, - tokenTicker: "CTP", + tokenTicker: 'CTP', tokenType: 1, - transactionType: "send", + transactionType: 'send', tx_hash: - "5ed96f59ae4fec31ee8fc96304bd610c3658f9df2fde35119aad6f44547420f9", + '5ed96f59ae4fec31ee8fc96304bd610c3658f9df2fde35119aad6f44547420f9', tx_pos: 1, txid: - "5ed96f59ae4fec31ee8fc96304bd610c3658f9df2fde35119aad6f44547420f9", - utxoType: "token", + '5ed96f59ae4fec31ee8fc96304bd610c3658f9df2fde35119aad6f44547420f9', + utxoType: 'token', value: 546, vout: 1 }, { - address: "bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu", + address: 'bitcoincash:qpv9fx6mjdpgltygudnpw3tvmxdyzx7savhphtzswu', decimals: 9, height: 0, isValid: true, satoshis: 546, - tokenDocumentHash: "", - tokenDocumentUrl: "https://cashtabapp.com/", + tokenDocumentHash: '', + tokenDocumentUrl: 'https://cashtabapp.com/', tokenId: - "bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1", - tokenName: "Cash Tab Points", + 'bef614aac85c0c866f4d39e4d12a96851267d38d1bca5bdd6488bbd42e28b6b1', + tokenName: 'Cash Tab Points', tokenQty: 1, - tokenTicker: "CTP", + tokenTicker: 'CTP', tokenType: 1, - transactionType: "send", + transactionType: 'send', tx_hash: - "648465087cc8ba218ccf6b7261256924ef2dc1d20e5c10117a6d555065c01600", + '648465087cc8ba218ccf6b7261256924ef2dc1d20e5c10117a6d555065c01600', tx_pos: 1, txid: - "648465087cc8ba218ccf6b7261256924ef2dc1d20e5c10117a6d555065c01600", - utxoType: "token", + '648465087cc8ba218ccf6b7261256924ef2dc1d20e5c10117a6d555065c01600', + utxoType: 'token', value: 546, vout: 1 } @@ -460,718 +460,718 @@ describe("#SLP TokenType1", () => { tokenUtxos, 1000000003.500000001 ) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.hasAllKeys(result, ["script", "outputs"]) + assert.hasAllKeys(result, ['script', 'outputs']) assert.isNumber(result.outputs) }) }) - describe("#generateSendOpReturn06", () => { - it("should generate send OP_RETURN code", () => { + describe('#generateSendOpReturn06', () => { + it('should generate send OP_RETURN code', () => { // Mock UTXO. const tokenUtxos = [ { height: 660844, tx_hash: - "00dcc47dcebf3ad95140c271a70172a45a4f5de53ecc17d71471eea57a0c361f", + '00dcc47dcebf3ad95140c271a70172a45a4f5de53ecc17d71471eea57a0c361f', tx_pos: 1, value: 546, satoshis: 546, txid: - "00dcc47dcebf3ad95140c271a70172a45a4f5de53ecc17d71471eea57a0c361f", + '00dcc47dcebf3ad95140c271a70172a45a4f5de53ecc17d71471eea57a0c361f', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 3.0000011, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "04585cff8a53166afc86f3f0e06d5d2c8b08fb9d39c959ee3e3ff55f550bdabb", + '04585cff8a53166afc86f3f0e06d5d2c8b08fb9d39c959ee3e3ff55f550bdabb', tx_pos: 1, value: 546, satoshis: 546, txid: - "04585cff8a53166afc86f3f0e06d5d2c8b08fb9d39c959ee3e3ff55f550bdabb", + '04585cff8a53166afc86f3f0e06d5d2c8b08fb9d39c959ee3e3ff55f550bdabb', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 3.000001, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "25a4af01d1acb12275ced70a50c475dffe6821bc988a232cd0c5c68282673ce6", + '25a4af01d1acb12275ced70a50c475dffe6821bc988a232cd0c5c68282673ce6', tx_pos: 1, value: 546, satoshis: 546, txid: - "25a4af01d1acb12275ced70a50c475dffe6821bc988a232cd0c5c68282673ce6", + '25a4af01d1acb12275ced70a50c475dffe6821bc988a232cd0c5c68282673ce6', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 3.0000002, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "2f87a94ad524fc702d47404899badd261346a794898d69cea9dbb56dca0f2bd1", + '2f87a94ad524fc702d47404899badd261346a794898d69cea9dbb56dca0f2bd1', tx_pos: 1, value: 546, satoshis: 546, txid: - "2f87a94ad524fc702d47404899badd261346a794898d69cea9dbb56dca0f2bd1", + '2f87a94ad524fc702d47404899badd261346a794898d69cea9dbb56dca0f2bd1', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 1, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "31bb9a154181520cbd91ca98605143ad8aaa72a9a90d0649f63bea697d99f4fd", + '31bb9a154181520cbd91ca98605143ad8aaa72a9a90d0649f63bea697d99f4fd', tx_pos: 1, value: 546, satoshis: 546, txid: - "31bb9a154181520cbd91ca98605143ad8aaa72a9a90d0649f63bea697d99f4fd", + '31bb9a154181520cbd91ca98605143ad8aaa72a9a90d0649f63bea697d99f4fd', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 3.0000001, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "34c77f5f6cac57ce99574fcb09ed542371a002146e1e60135ba4ab23ea7dafeb", + '34c77f5f6cac57ce99574fcb09ed542371a002146e1e60135ba4ab23ea7dafeb', tx_pos: 1, value: 546, satoshis: 546, txid: - "34c77f5f6cac57ce99574fcb09ed542371a002146e1e60135ba4ab23ea7dafeb", + '34c77f5f6cac57ce99574fcb09ed542371a002146e1e60135ba4ab23ea7dafeb', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 3.0000008, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "42e04820e080a5499507bdfa02881c3ccf76370833f9a69705ce6bf6f9fcd509", + '42e04820e080a5499507bdfa02881c3ccf76370833f9a69705ce6bf6f9fcd509', tx_pos: 1, value: 546, satoshis: 546, txid: - "42e04820e080a5499507bdfa02881c3ccf76370833f9a69705ce6bf6f9fcd509", + '42e04820e080a5499507bdfa02881c3ccf76370833f9a69705ce6bf6f9fcd509', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 3.0000007, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "4d65bc6900b2454abfd89c782295a559ed559e909c1be81b5e76097fdc06f872", + '4d65bc6900b2454abfd89c782295a559ed559e909c1be81b5e76097fdc06f872', tx_pos: 1, value: 546, satoshis: 546, txid: - "4d65bc6900b2454abfd89c782295a559ed559e909c1be81b5e76097fdc06f872", + '4d65bc6900b2454abfd89c782295a559ed559e909c1be81b5e76097fdc06f872', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 2.05, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "53c6db88c01c11781dd1ac67eca8177a2260e9005bc49180466eadf71c01f99a", + '53c6db88c01c11781dd1ac67eca8177a2260e9005bc49180466eadf71c01f99a', tx_pos: 1, value: 546, satoshis: 546, txid: - "53c6db88c01c11781dd1ac67eca8177a2260e9005bc49180466eadf71c01f99a", + '53c6db88c01c11781dd1ac67eca8177a2260e9005bc49180466eadf71c01f99a', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 3.0000004, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "55531993ed6c5ba7350fdfbfb820bde924e365e52a0e44a33713bd9acbd84379", + '55531993ed6c5ba7350fdfbfb820bde924e365e52a0e44a33713bd9acbd84379', tx_pos: 1, value: 546, satoshis: 546, txid: - "55531993ed6c5ba7350fdfbfb820bde924e365e52a0e44a33713bd9acbd84379", + '55531993ed6c5ba7350fdfbfb820bde924e365e52a0e44a33713bd9acbd84379', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 2.0523412, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "5f109d1215de0d75ee4b4be079e6922a69d0a6f528899ef35fee0c4d64822b8c", + '5f109d1215de0d75ee4b4be079e6922a69d0a6f528899ef35fee0c4d64822b8c', tx_pos: 1, value: 546, satoshis: 546, txid: - "5f109d1215de0d75ee4b4be079e6922a69d0a6f528899ef35fee0c4d64822b8c", + '5f109d1215de0d75ee4b4be079e6922a69d0a6f528899ef35fee0c4d64822b8c', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 2, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "66efb27f0a2712554e630db1ac8f7f2ea146820fa02f6f869c9310aa8faa03e4", + '66efb27f0a2712554e630db1ac8f7f2ea146820fa02f6f869c9310aa8faa03e4', tx_pos: 1, value: 546, satoshis: 546, txid: - "66efb27f0a2712554e630db1ac8f7f2ea146820fa02f6f869c9310aa8faa03e4", + '66efb27f0a2712554e630db1ac8f7f2ea146820fa02f6f869c9310aa8faa03e4', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 3.000001, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "962fcc8ba3164f3e3ad50c9e9b635d9487a0f7c125ad32421c303332a63ef830", + '962fcc8ba3164f3e3ad50c9e9b635d9487a0f7c125ad32421c303332a63ef830', tx_pos: 1, value: 546, satoshis: 546, txid: - "962fcc8ba3164f3e3ad50c9e9b635d9487a0f7c125ad32421c303332a63ef830", + '962fcc8ba3164f3e3ad50c9e9b635d9487a0f7c125ad32421c303332a63ef830', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 3.0000005, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "974dd914cb2de49e7c167cff04ec0182e64861c0ff638223d608e6e51bc11237", + '974dd914cb2de49e7c167cff04ec0182e64861c0ff638223d608e6e51bc11237', tx_pos: 1, value: 546, satoshis: 546, txid: - "974dd914cb2de49e7c167cff04ec0182e64861c0ff638223d608e6e51bc11237", + '974dd914cb2de49e7c167cff04ec0182e64861c0ff638223d608e6e51bc11237', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 3.0000014, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "ab0fbc0e18278bb9b5ae59660fd8046b0b481a800e011659333035d7c2593128", + 'ab0fbc0e18278bb9b5ae59660fd8046b0b481a800e011659333035d7c2593128', tx_pos: 1, value: 546, satoshis: 546, txid: - "ab0fbc0e18278bb9b5ae59660fd8046b0b481a800e011659333035d7c2593128", + 'ab0fbc0e18278bb9b5ae59660fd8046b0b481a800e011659333035d7c2593128', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 2.0523413, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "ac01f0010bcb5937038d637f9d9131124daab15ffda7458a0c801f38f7f9f3f3", + 'ac01f0010bcb5937038d637f9d9131124daab15ffda7458a0c801f38f7f9f3f3', tx_pos: 1, value: 546, satoshis: 546, txid: - "ac01f0010bcb5937038d637f9d9131124daab15ffda7458a0c801f38f7f9f3f3", + 'ac01f0010bcb5937038d637f9d9131124daab15ffda7458a0c801f38f7f9f3f3', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 1, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "ba5049164f13263cdf25453bce53f6b230687bdab2393e0f40c39c313386791c", + 'ba5049164f13263cdf25453bce53f6b230687bdab2393e0f40c39c313386791c', tx_pos: 1, value: 546, satoshis: 546, txid: - "ba5049164f13263cdf25453bce53f6b230687bdab2393e0f40c39c313386791c", + 'ba5049164f13263cdf25453bce53f6b230687bdab2393e0f40c39c313386791c', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 3.0000003, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "d84daa1aa0b8fa265e83dcd506f0f410066eef880ebcd9e8dc70a55ec9fd78f5", + 'd84daa1aa0b8fa265e83dcd506f0f410066eef880ebcd9e8dc70a55ec9fd78f5', tx_pos: 1, value: 546, satoshis: 546, txid: - "d84daa1aa0b8fa265e83dcd506f0f410066eef880ebcd9e8dc70a55ec9fd78f5", + 'd84daa1aa0b8fa265e83dcd506f0f410066eef880ebcd9e8dc70a55ec9fd78f5', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 3.0000012, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "e67b76c4c411fca92efe1cc0af1bd38c53ee62ce08b4cc81d61209d53d2511c5", + 'e67b76c4c411fca92efe1cc0af1bd38c53ee62ce08b4cc81d61209d53d2511c5', tx_pos: 1, value: 546, satoshis: 546, txid: - "e67b76c4c411fca92efe1cc0af1bd38c53ee62ce08b4cc81d61209d53d2511c5", + 'e67b76c4c411fca92efe1cc0af1bd38c53ee62ce08b4cc81d61209d53d2511c5', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 3.0000014, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "f05c192813b5c1565e17b96d8d27481c317ccc25b81ff38fa700c6e91931e211", + 'f05c192813b5c1565e17b96d8d27481c317ccc25b81ff38fa700c6e91931e211', tx_pos: 1, value: 546, satoshis: 546, txid: - "f05c192813b5c1565e17b96d8d27481c317ccc25b81ff38fa700c6e91931e211", + 'f05c192813b5c1565e17b96d8d27481c317ccc25b81ff38fa700c6e91931e211', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 3.0000013, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "f3404e1c4b8fe9d73fae9d11bcd5adf1bcc55852208f0fda8fd4d234320faff9", + 'f3404e1c4b8fe9d73fae9d11bcd5adf1bcc55852208f0fda8fd4d234320faff9', tx_pos: 1, value: 546, satoshis: 546, txid: - "f3404e1c4b8fe9d73fae9d11bcd5adf1bcc55852208f0fda8fd4d234320faff9", + 'f3404e1c4b8fe9d73fae9d11bcd5adf1bcc55852208f0fda8fd4d234320faff9', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 3.0000009, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660844, tx_hash: - "fedda41bf7553358b60f0be373f02aa79dec5979c95159bc8c12afdb86b3dec2", + 'fedda41bf7553358b60f0be373f02aa79dec5979c95159bc8c12afdb86b3dec2', tx_pos: 1, value: 546, satoshis: 546, txid: - "fedda41bf7553358b60f0be373f02aa79dec5979c95159bc8c12afdb86b3dec2", + 'fedda41bf7553358b60f0be373f02aa79dec5979c95159bc8c12afdb86b3dec2', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 3.0000006, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660869, tx_hash: - "68fa5a225999c6f28e4a13cd81c9c3d45bae40dd746b9116d859219ad6060851", + '68fa5a225999c6f28e4a13cd81c9c3d45bae40dd746b9116d859219ad6060851', tx_pos: 1, value: 546, satoshis: 546, txid: - "68fa5a225999c6f28e4a13cd81c9c3d45bae40dd746b9116d859219ad6060851", + '68fa5a225999c6f28e4a13cd81c9c3d45bae40dd746b9116d859219ad6060851', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 1e-7, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660869, tx_hash: - "8856a0b51ded579c8b880c3b4f7aa2cad491f073439d2cf05d8ea1a64bb0f7b6", + '8856a0b51ded579c8b880c3b4f7aa2cad491f073439d2cf05d8ea1a64bb0f7b6', tx_pos: 1, value: 546, satoshis: 546, txid: - "8856a0b51ded579c8b880c3b4f7aa2cad491f073439d2cf05d8ea1a64bb0f7b6", + '8856a0b51ded579c8b880c3b4f7aa2cad491f073439d2cf05d8ea1a64bb0f7b6', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 3e-7, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660869, tx_hash: - "d4bf048e67cdec88c7affd67ca0843ecb8eac53cefce1c4580bed5a699920267", + 'd4bf048e67cdec88c7affd67ca0843ecb8eac53cefce1c4580bed5a699920267', tx_pos: 1, value: 546, satoshis: 546, txid: - "d4bf048e67cdec88c7affd67ca0843ecb8eac53cefce1c4580bed5a699920267", + 'd4bf048e67cdec88c7affd67ca0843ecb8eac53cefce1c4580bed5a699920267', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 4e-7, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660869, tx_hash: - "e2ce53b60e290246dd5e4758c707ffd8a526d651caff49f7f06c841fd9f5870a", + 'e2ce53b60e290246dd5e4758c707ffd8a526d651caff49f7f06c841fd9f5870a', tx_pos: 1, value: 546, satoshis: 546, txid: - "e2ce53b60e290246dd5e4758c707ffd8a526d651caff49f7f06c841fd9f5870a", + 'e2ce53b60e290246dd5e4758c707ffd8a526d651caff49f7f06c841fd9f5870a', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 2e-7, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' }, { height: 660959, tx_hash: - "7b6ed9a3c13e69d893f217debb3d7313db8d48cf11fc7cdf2256afdafe83f2c2", + '7b6ed9a3c13e69d893f217debb3d7313db8d48cf11fc7cdf2256afdafe83f2c2', tx_pos: 1, value: 546, satoshis: 546, txid: - "7b6ed9a3c13e69d893f217debb3d7313db8d48cf11fc7cdf2256afdafe83f2c2", + '7b6ed9a3c13e69d893f217debb3d7313db8d48cf11fc7cdf2256afdafe83f2c2', vout: 1, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d", - tokenTicker: "WDT", + '7443f7c831cdf2b2b04d5f0465ed0bcf348582675b0e4f17906438c232c22f3d', + tokenTicker: 'WDT', tokenName: - "Test Token With Exceptionally Long Name For CSS And Style Revisions", + 'Test Token With Exceptionally Long Name For CSS And Style Revisions', tokenDocumentUrl: - "https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org", - tokenDocumentHash: "����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��", + 'https://www.ImpossiblyLongWebsiteDidYouThinkWebDevWouldBeFun.org', + tokenDocumentHash: '����\\�IS\u001e9�����k+���\u0018���\u001b]�߷2��', decimals: 7, tokenType: 1, tokenQty: 1e-7, isValid: true, - address: "bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed" + address: 'bitcoincash:qqvcsnz9x9nu7vq35vmrkjc7hkfxhhs9nuv44zm0ed' } ] @@ -1179,32 +1179,32 @@ describe("#SLP TokenType1", () => { tokenUtxos, 58.1546965 ) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.hasAllKeys(result, ["script", "outputs"]) + assert.hasAllKeys(result, ['script', 'outputs']) assert.isNumber(result.outputs) }) }) - describe("#generateBurnOpReturn", () => { - it("should generate burn OP_RETURN code", () => { + describe('#generateBurnOpReturn', () => { + it('should generate burn OP_RETURN code', () => { // Mock UTXO. const tokenUtxos = [ { txid: - "a8eb788b8ddda6faea00e6e2756624b8feb97655363d0400dd66839ea619d36e", + 'a8eb788b8ddda6faea00e6e2756624b8feb97655363d0400dd66839ea619d36e', vout: 2, - value: "546", + value: '546', confirmations: 0, satoshis: 546, - utxoType: "token", - transactionType: "send", + utxoType: 'token', + transactionType: 'send', tokenId: - "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7", - tokenTicker: "TOK-CH", - tokenName: "TokyoCash", - tokenDocumentUrl: "", - tokenDocumentHash: "", + '497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7', + tokenTicker: 'TOK-CH', + tokenName: 'TokyoCash', + tokenDocumentUrl: '', + tokenDocumentHash: '', decimals: 8, tokenQty: 7 } @@ -1218,13 +1218,13 @@ describe("#SLP TokenType1", () => { }) }) - describe("#generateGenesisOpReturn", () => { - it("should generate genesis OP_RETURN code", () => { + describe('#generateGenesisOpReturn', () => { + it('should generate genesis OP_RETURN code', () => { const configObj = { - name: "SLP Test Token", - ticker: "SLPTEST", - documentUrl: "https://bchjs.cash", - documentHash: "", + name: 'SLP Test Token', + ticker: 'SLPTEST', + documentUrl: 'https://bchjs.cash', + documentHash: '', decimals: 8, initialQty: 10 } @@ -1235,11 +1235,11 @@ describe("#SLP TokenType1", () => { assert.equal(Buffer.isBuffer(result), true) }) - it("should work if user does not specify doc hash", () => { + it('should work if user does not specify doc hash', () => { const configObj = { - name: "SLP Test Token", - ticker: "SLPTEST", - documentUrl: "https://bchjs.cash", + name: 'SLP Test Token', + ticker: 'SLPTEST', + documentUrl: 'https://bchjs.cash', decimals: 8, initialQty: 10 } @@ -1251,40 +1251,40 @@ describe("#SLP TokenType1", () => { }) }) - describe("#generateMintOpReturn", () => { - it("should throw error if tokenUtxos is not an array.", () => { + describe('#generateMintOpReturn', () => { + it('should throw error if tokenUtxos is not an array.', () => { try { bchjs.SLP.TokenType1.generateMintOpReturn({}, 100) - assert.equal(true, false, "Unexpected result.") + assert.equal(true, false, 'Unexpected result.') } catch (err) { assert.include( err.message, - `tokenUtxos must be an array`, - "Expected error message." + 'tokenUtxos must be an array', + 'Expected error message.' ) } }) - it("should throw error if minting baton is not in UTXOs.", () => { + it('should throw error if minting baton is not in UTXOs.', () => { try { const utxos = [ { txid: - "ccc6d336399e26d98afcd3821b41fb1535cd50f57063ed7593eaed5108659606", + 'ccc6d336399e26d98afcd3821b41fb1535cd50f57063ed7593eaed5108659606', vout: 1, - value: "546", + value: '546', height: 637618, confirmations: 239, satoshis: 546, - utxoType: "token", + utxoType: 'token', tokenQty: 100, tokenId: - "ccc6d336399e26d98afcd3821b41fb1535cd50f57063ed7593eaed5108659606", - tokenTicker: "SLPTEST", - tokenName: "SLP Test Token", - tokenDocumentUrl: "https://FullStack.cash", - tokenDocumentHash: "", + 'ccc6d336399e26d98afcd3821b41fb1535cd50f57063ed7593eaed5108659606', + tokenTicker: 'SLPTEST', + tokenName: 'SLP Test Token', + tokenDocumentUrl: 'https://FullStack.cash', + tokenDocumentHash: '', decimals: 8, isValid: true } @@ -1292,32 +1292,32 @@ describe("#SLP TokenType1", () => { bchjs.SLP.TokenType1.generateMintOpReturn(utxos, 100) - assert.equal(true, false, "Unexpected result.") + assert.equal(true, false, 'Unexpected result.') } catch (err) { assert.include( err.message, - `Minting baton could not be found in tokenUtxos array`, - "Expected error message." + 'Minting baton could not be found in tokenUtxos array', + 'Expected error message.' ) } }) - it("should throw error if tokenId is not included in minting-baton UTXO.", () => { + it('should throw error if tokenId is not included in minting-baton UTXO.', () => { try { const utxos = [ { txid: - "9d35c1803ed3ab8bd23c198b027f7b3b530586494dc265de6391b74a6b090136", + '9d35c1803ed3ab8bd23c198b027f7b3b530586494dc265de6391b74a6b090136', vout: 2, - value: "546", + value: '546', height: 637625, confirmations: 207, satoshis: 546, - utxoType: "minting-baton", - tokenTicker: "SLPTEST", - tokenName: "SLP Test Token", - tokenDocumentUrl: "https://FullStack.cash", - tokenDocumentHash: "", + utxoType: 'minting-baton', + tokenTicker: 'SLPTEST', + tokenName: 'SLP Test Token', + tokenDocumentUrl: 'https://FullStack.cash', + tokenDocumentHash: '', decimals: 8, isValid: true } @@ -1325,67 +1325,67 @@ describe("#SLP TokenType1", () => { bchjs.SLP.TokenType1.generateMintOpReturn(utxos, 100) - assert.equal(true, false, "Unexpected result.") + assert.equal(true, false, 'Unexpected result.') } catch (err) { assert.include( err.message, - `tokenId property not found in mint-baton UTXO`, - "Expected error message." + 'tokenId property not found in mint-baton UTXO', + 'Expected error message.' ) } }) - it("should throw error if decimals is not included in minting-baton UTXO.", () => { + it('should throw error if decimals is not included in minting-baton UTXO.', () => { try { const utxos = [ { txid: - "9d35c1803ed3ab8bd23c198b027f7b3b530586494dc265de6391b74a6b090136", + '9d35c1803ed3ab8bd23c198b027f7b3b530586494dc265de6391b74a6b090136', vout: 2, - value: "546", + value: '546', height: 637625, confirmations: 207, satoshis: 546, - utxoType: "minting-baton", + utxoType: 'minting-baton', tokenId: - "9d35c1803ed3ab8bd23c198b027f7b3b530586494dc265de6391b74a6b090136", - tokenTicker: "SLPTEST", - tokenName: "SLP Test Token", - tokenDocumentUrl: "https://FullStack.cash", - tokenDocumentHash: "", + '9d35c1803ed3ab8bd23c198b027f7b3b530586494dc265de6391b74a6b090136', + tokenTicker: 'SLPTEST', + tokenName: 'SLP Test Token', + tokenDocumentUrl: 'https://FullStack.cash', + tokenDocumentHash: '', isValid: true } ] bchjs.SLP.TokenType1.generateMintOpReturn(utxos, 100) - assert.equal(true, false, "Unexpected result.") + assert.equal(true, false, 'Unexpected result.') } catch (err) { assert.include( err.message, - `decimals property not found in mint-baton UTXO`, - "Expected error message." + 'decimals property not found in mint-baton UTXO', + 'Expected error message.' ) } }) - it("should generate genesis OP_RETURN code", () => { + it('should generate genesis OP_RETURN code', () => { tokenUtxo = [ { txid: - "9d35c1803ed3ab8bd23c198b027f7b3b530586494dc265de6391b74a6b090136", + '9d35c1803ed3ab8bd23c198b027f7b3b530586494dc265de6391b74a6b090136', vout: 2, - value: "546", + value: '546', height: 637625, confirmations: 207, satoshis: 546, - utxoType: "minting-baton", + utxoType: 'minting-baton', tokenId: - "9d35c1803ed3ab8bd23c198b027f7b3b530586494dc265de6391b74a6b090136", - tokenTicker: "SLPTEST", - tokenName: "SLP Test Token", - tokenDocumentUrl: "https://FullStack.cash", - tokenDocumentHash: "", + '9d35c1803ed3ab8bd23c198b027f7b3b530586494dc265de6391b74a6b090136', + tokenTicker: 'SLPTEST', + tokenName: 'SLP Test Token', + tokenDocumentUrl: 'https://FullStack.cash', + tokenDocumentHash: '', decimals: 8, isValid: true } @@ -1398,12 +1398,12 @@ describe("#SLP TokenType1", () => { }) }) - describe("#getHexOpReturn", () => { - it("should return OP_RETURN object ", async () => { + describe('#getHexOpReturn', () => { + it('should return OP_RETURN object ', async () => { const tokenUtxos = [ { tokenId: - "0a321bff9761f28e06a268b14711274bb77617410a16807bd0437ef234a072b1", + '0a321bff9761f28e06a268b14711274bb77617410a16807bd0437ef234a072b1', decimals: 0, tokenQty: 2 } @@ -1411,10 +1411,10 @@ describe("#SLP TokenType1", () => { const sendQty = 1.5 - sandbox.stub(bchjs.SLP.TokenType1.axios, "post").resolves({ + sandbox.stub(bchjs.SLP.TokenType1.axios, 'post').resolves({ data: { script: - "6a04534c500001010453454e44200a321bff9761f28e06a268b14711274bb77617410a16807bd0437ef234a072b1080000000000000001080000000000000000", + '6a04534c500001010453454e44200a321bff9761f28e06a268b14711274bb77617410a16807bd0437ef234a072b1080000000000000001080000000000000000', outputs: 2 } }) @@ -1425,10 +1425,10 @@ describe("#SLP TokenType1", () => { ) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "script") + assert.property(result, 'script') assert.isString(result.script) - assert.property(result, "outputs") + assert.property(result, 'outputs') assert.isNumber(result.outputs) }) }) diff --git a/test/unit/slp-utils.js b/test/unit/slp-utils.js index 33ae2f9..180d600 100644 --- a/test/unit/slp-utils.js +++ b/test/unit/slp-utils.js @@ -1,25 +1,25 @@ // Public npm libraries -const assert = require("chai").assert -const sinon = require("sinon") -const cloneDeep = require("lodash.clonedeep") +const assert = require('chai').assert +const sinon = require('sinon') +const cloneDeep = require('lodash.clonedeep') // Unit under test -const SLP = require("../../src/slp/slp") +const SLP = require('../../src/slp/slp') let uut let SERVER const REST_URL = process.env.RESTURL ? process.env.RESTURL - : "https://bchn.fullstack.cash/v4/" + : 'https://bchn.fullstack.cash/v4/' // Mock data used for unit tests -const mockDataLib = require("./fixtures/slp/mock-utils") +const mockDataLib = require('./fixtures/slp/mock-utils') let mockData // Default to unit tests unless some other value for TEST is passed. -if (!process.env.TEST) process.env.TEST = "unit" +if (!process.env.TEST) process.env.TEST = 'unit' -describe("#SLP Utils", () => { +describe('#SLP Utils', () => { let sandbox beforeEach(() => { @@ -45,338 +45,338 @@ describe("#SLP Utils", () => { sandbox.restore() }) - describe("#list", () => { - it(`should list single SLP token by id`, async () => { + describe('#list', () => { + it('should list single SLP token by id', async () => { sandbox - .stub(uut.Utils.axios, "get") + .stub(uut.Utils.axios, 'get') .resolves({ data: mockData.mockToken }) const tokenId = - "4276533bb702e7f8c9afd8aa61ebf016e95011dc3d54e55faa847ac1dd461e84" + '4276533bb702e7f8c9afd8aa61ebf016e95011dc3d54e55faa847ac1dd461e84' const list = await uut.Utils.list(tokenId) // console.log(`list: ${JSON.stringify(list, null, 2)}`) assert.equal(list.id, tokenId) - assert.property(list, "decimals") - assert.property(list, "symbol") - assert.property(list, "documentUri") - assert.property(list, "name") + assert.property(list, 'decimals') + assert.property(list, 'symbol') + assert.property(list, 'documentUri') + assert.property(list, 'name') }) - it(`should list multiple SLP tokens by array of ids`, async () => { + it('should list multiple SLP tokens by array of ids', async () => { // Mock the call to the REST API sandbox - .stub(uut.Utils.axios, "post") + .stub(uut.Utils.axios, 'post') .resolves({ data: mockData.mockList }) const tokenIds = [ - "4276533bb702e7f8c9afd8aa61ebf016e95011dc3d54e55faa847ac1dd461e84", - "8fc284dcbc922f7bb7e2a443dc3af792f52923bba403fcf67ca028c88e89da0e" + '4276533bb702e7f8c9afd8aa61ebf016e95011dc3d54e55faa847ac1dd461e84', + '8fc284dcbc922f7bb7e2a443dc3af792f52923bba403fcf67ca028c88e89da0e' ] const list = await uut.Utils.list(tokenIds) // console.log(`list: ${JSON.stringify(list, null, 2)}`) assert.isArray(list) - assert.property(list[0], "symbol") - assert.property(list[1], "symbol") + assert.property(list[0], 'symbol') + assert.property(list[1], 'symbol') }) }) - describe("#balancesForAddress", () => { - it(`should throw an error if input is not a string or array of strings`, async () => { + describe('#balancesForAddress', () => { + it('should throw an error if input is not a string or array of strings', async () => { try { const address = 1234 await uut.Utils.balancesForAddress(address) - assert.equal(true, false, "Uh oh. Code path should not end here.") + assert.equal(true, false, 'Uh oh. Code path should not end here.') } catch (err) { - //console.log(`Error: `, err) + // console.log(`Error: `, err) assert.include( err.message, - `Input address must be a string or array of strings` + 'Input address must be a string or array of strings' ) } }) - it(`should fetch all balances for address: simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9`, async () => { + it('should fetch all balances for address: simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9', async () => { // Mock the call to the REST API - if (process.env.TEST === "unit") { + if (process.env.TEST === 'unit') { sandbox - .stub(uut.Utils.axios, "get") + .stub(uut.Utils.axios, 'get') .resolves({ data: mockData.balancesForAddress }) } - //sandbox + // sandbox // .stub(uut.Utils, "balancesForAddress") // .resolves(mockData.balancesForAddress) const balances = await uut.Utils.balancesForAddress( - "simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9" + 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9' ) // console.log(`balances: ${JSON.stringify(balances, null, 2)}`) assert.isArray(balances) assert.hasAllKeys(balances[0], [ - "tokenId", - "balanceString", - "balance", - "decimalCount", - "slpAddress" + 'tokenId', + 'balanceString', + 'balance', + 'decimalCount', + 'slpAddress' ]) }) - it(`should fetch balances for multiple addresses.`, async () => { + it('should fetch balances for multiple addresses.', async () => { const addresses = [ - "simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9", - "simpleledger:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5ucdyl3r57" + 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9', + 'simpleledger:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5ucdyl3r57' ] // Mock the call to the REST API - if (process.env.TEST === "unit") { + if (process.env.TEST === 'unit') { sandbox - .stub(uut.Utils.axios, "post") + .stub(uut.Utils.axios, 'post') .resolves({ data: mockData.balancesForAddresses }) } const balances = await uut.Utils.balancesForAddress(addresses) - //console.log(`balances: ${JSON.stringify(balances, null, 2)}`) + // console.log(`balances: ${JSON.stringify(balances, null, 2)}`) assert.isArray(balances) assert.isArray(balances[0]) assert.hasAllKeys(balances[0][0], [ - "tokenId", - "balanceString", - "balance", - "decimalCount", - "slpAddress" + 'tokenId', + 'balanceString', + 'balance', + 'decimalCount', + 'slpAddress' ]) }) }) - describe("#validateTxid", () => { - it(`should validate slp txid`, async () => { + describe('#validateTxid', () => { + it('should validate slp txid', async () => { // Mock the call to the REST API sandbox - .stub(uut.Utils.axios, "post") + .stub(uut.Utils.axios, 'post') .resolves({ data: mockData.mockIsValidTxid }) const isValid = await uut.Utils.validateTxid( - "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb" + 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb' ) assert.deepEqual(isValid, [ { txid: - "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb", + 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb', valid: true } ]) }) }) - describe("#balancesForToken", () => { - it(`should retrieve token balances for a given tokenId`, async () => { + describe('#balancesForToken', () => { + it('should retrieve token balances for a given tokenId', async () => { // Mock the call to the REST API sandbox - .stub(uut.Utils.axios, "get") + .stub(uut.Utils.axios, 'get') .resolves({ data: mockData.mockBalancesForToken }) const balances = await uut.Utils.balancesForToken( - "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb" + 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb' ) - assert.hasAnyKeys(balances[0], ["tokenBalance", "slpAddress"]) + assert.hasAnyKeys(balances[0], ['tokenBalance', 'slpAddress']) }) }) - describe("#tokenStats", () => { - it(`should retrieve stats for a given tokenId`, async () => { + describe('#tokenStats', () => { + it('should retrieve stats for a given tokenId', async () => { // Mock the call to the REST API sandbox - .stub(uut.Utils.axios, "get") + .stub(uut.Utils.axios, 'get') .resolves({ data: mockData.mockTokenStats }) const tokenStats = await uut.Utils.tokenStats( - "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb" + 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb' ) assert.hasAnyKeys(tokenStats, [ - "circulatingSupply", - "decimals", - "documentUri", - "name", - "satoshisLockedUp", - "symbol", - "tokenId", - "totalBurned", - "totalMinted", - "txnsSinceGenesis", - "validAddresses", - "validUtxos" + 'circulatingSupply', + 'decimals', + 'documentUri', + 'name', + 'satoshisLockedUp', + 'symbol', + 'tokenId', + 'totalBurned', + 'totalMinted', + 'txnsSinceGenesis', + 'validAddresses', + 'validUtxos' ]) }) }) - describe("#transactions", () => { - it(`should retrieve transactions for a given tokenId and address`, async () => { + describe('#transactions', () => { + it('should retrieve transactions for a given tokenId and address', async () => { // Mock the call to the REST API sandbox - .stub(uut.Utils.axios, "get") + .stub(uut.Utils.axios, 'get') .resolves({ data: mockData.mockTransactions }) const transactions = await uut.Utils.transactions( - "495322b37d6b2eae81f045eda612b95870a0c2b6069c58f70cf8ef4e6a9fd43a", - "simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu" + '495322b37d6b2eae81f045eda612b95870a0c2b6069c58f70cf8ef4e6a9fd43a', + 'simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu' ) - assert.hasAnyKeys(transactions[0], ["txid", "tokenDetails"]) + assert.hasAnyKeys(transactions[0], ['txid', 'tokenDetails']) }) }) - describe("#burnTotal", () => { - it(`should retrieve input, output and burn totals`, async () => { + describe('#burnTotal', () => { + it('should retrieve input, output and burn totals', async () => { // Mock the call to the REST API sandbox - .stub(uut.Utils.axios, "get") + .stub(uut.Utils.axios, 'get') .resolves({ data: mockData.mockBurnTotal }) const burnTotal = await uut.Utils.burnTotal( - "c7078a6c7400518a513a0bde1f4158cf740d08d3b5bfb19aa7b6657e2f4160de" + 'c7078a6c7400518a513a0bde1f4158cf740d08d3b5bfb19aa7b6657e2f4160de' ) - //console.log(`burnTotal: ${JSON.stringify(burnTotal, null, 2)}`) + // console.log(`burnTotal: ${JSON.stringify(burnTotal, null, 2)}`) assert.hasAnyKeys(burnTotal, [ - "transactionId", - "inputTotal", - "outputTotal", - "burnTotal" + 'transactionId', + 'inputTotal', + 'outputTotal', + 'burnTotal' ]) }) }) - describe("#decodeOpReturn", () => { - it("should throw an error for a non-string input", async () => { + describe('#decodeOpReturn', () => { + it('should throw an error for a non-string input', async () => { try { const txid = 53423 // Not a string. await uut.Utils.decodeOpReturn(txid) - assert.equal(true, false, "Unexpected result.") + assert.equal(true, false, 'Unexpected result.') } catch (err) { - //console.log(`err: ${util.inspect(err)}`) - assert.include(err.message, `txid string must be included`) + // console.log(`err: ${util.inspect(err)}`) + assert.include(err.message, 'txid string must be included') } }) - it("should throw an error for non-SLP transaction", async () => { + it('should throw an error for non-SLP transaction', async () => { try { // Mock the call to the REST API sandbox - .stub(uut.Utils.axios, "get") + .stub(uut.Utils.axios, 'get') .resolves({ data: mockData.nonSLPTxDetailsWithoutOpReturn }) const txid = - "3793d4906654f648e659f384c0f40b19c8f10c1e9fb72232a9b8edd61abaa1ec" + '3793d4906654f648e659f384c0f40b19c8f10c1e9fb72232a9b8edd61abaa1ec' await uut.Utils.decodeOpReturn(txid) - assert.equal(true, false, "Unexpected result.") + assert.equal(true, false, 'Unexpected result.') } catch (err) { // console.log(`err: ${util.inspect(err)}`) - assert.include(err.message, `scriptpubkey not op_return`) + assert.include(err.message, 'scriptpubkey not op_return') } }) - it("should throw an error for non-SLP transaction with OP_RETURN", async () => { + it('should throw an error for non-SLP transaction with OP_RETURN', async () => { try { // Mock the call to the REST API sandbox - .stub(uut.Utils.axios, "get") + .stub(uut.Utils.axios, 'get') .resolves({ data: mockData.nonSLPTxDetailsWithOpReturn }) const txid = - "2ff74c48a5d657cf45f699601990bffbbe7a2a516d5480674cbf6c6a4497908f" + '2ff74c48a5d657cf45f699601990bffbbe7a2a516d5480674cbf6c6a4497908f' await uut.Utils.decodeOpReturn(txid) - assert.equal(true, false, "Unexpected result.") + assert.equal(true, false, 'Unexpected result.') } catch (err) { // console.log(`err: ${util.inspect(err)}`) - assert.include(err.message, `SLP not in first chunk`) + assert.include(err.message, 'SLP not in first chunk') } }) - it("should decode a genesis transaction", async () => { + it('should decode a genesis transaction', async () => { // Mock the call to the REST API sandbox - .stub(uut.Utils.axios, "get") + .stub(uut.Utils.axios, 'get') .resolves({ data: mockData.txDetailsSLPGenesis }) const txid = - "bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90" + 'bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90' const result = await uut.Utils.decodeOpReturn(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.hasAllKeys(result, [ - "tokenType", - "txType", - "tokenId", - "ticker", - "name", - "documentUri", - "documentHash", - "decimals", - "mintBatonVout", - "qty" + 'tokenType', + 'txType', + 'tokenId', + 'ticker', + 'name', + 'documentUri', + 'documentHash', + 'decimals', + 'mintBatonVout', + 'qty' ]) }) - it("should decode a mint transaction", async () => { + it('should decode a mint transaction', async () => { // Mock the call to the REST API sandbox - .stub(uut.Utils.axios, "get") + .stub(uut.Utils.axios, 'get') .resolves({ data: mockData.txDetailsSLPMint }) const txid = - "65f21bbfcd545e5eb515e38e861a9dfe2378aaa2c4e458eb9e59e4d40e38f3a4" + '65f21bbfcd545e5eb515e38e861a9dfe2378aaa2c4e458eb9e59e4d40e38f3a4' const result = await uut.Utils.decodeOpReturn(txid) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.hasAllKeys(result, [ - "tokenType", - "txType", - "tokenId", - "mintBatonVout", - "qty" + 'tokenType', + 'txType', + 'tokenId', + 'mintBatonVout', + 'qty' ]) }) - it("should decode a send transaction", async () => { + it('should decode a send transaction', async () => { // Mock the call to the REST API sandbox - .stub(uut.Utils.axios, "get") + .stub(uut.Utils.axios, 'get') .resolves({ data: mockData.txDetailsSLPSend }) const txid = - "4f922565af664b6fdf0a1ba3924487344be721b3d8815c62cafc8a51e04a8afa" + '4f922565af664b6fdf0a1ba3924487344be721b3d8815c62cafc8a51e04a8afa' const result = await uut.Utils.decodeOpReturn(txid) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.hasAllKeys(result, ["tokenType", "txType", "tokenId", "amounts"]) + assert.hasAllKeys(result, ['tokenType', 'txType', 'tokenId', 'amounts']) }) - it("should properly decode a Genesis transaction with no minting baton", async () => { + it('should properly decode a Genesis transaction with no minting baton', async () => { // Mock the call to the REST API. sandbox - .stub(uut.Utils.axios, "get") + .stub(uut.Utils.axios, 'get') .resolves({ data: mockData.txDetailsSLPGenesisNoBaton }) const txid = - "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7" + '497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7' const data = await uut.Utils.decodeOpReturn(txid) // console.log(`data: ${JSON.stringify(data, null, 2)}`) @@ -384,69 +384,69 @@ describe("#SLP Utils", () => { assert.equal(data.mintBatonVout, 0) }) - it("should decode a send transaction with alternate encoding", async () => { + it('should decode a send transaction with alternate encoding', async () => { // Mock the call to the REST API sandbox - .stub(uut.Utils.axios, "get") + .stub(uut.Utils.axios, 'get') .resolves({ data: mockData.txDetailsSLPSendAlt }) const txid = - "d94357179775425ebc59c93173bd6dc9854095f090a2eb9dcfe9797398bc8eae" + 'd94357179775425ebc59c93173bd6dc9854095f090a2eb9dcfe9797398bc8eae' const data = await uut.Utils.decodeOpReturn(txid) // console.log(`data: ${JSON.stringify(data, null, 2)}`) assert.hasAnyKeys(data, [ - "transactionType", - "txType", - "tokenId", - "amounts" + 'transactionType', + 'txType', + 'tokenId', + 'amounts' ]) }) // Note: This TX is interpreted as valid by the original decodeOpReturn(). // Fixing this issue and related issues was the reason for creating the // decodeOpReturn2() method using the slp-parser library. - it("should throw error for invalid SLP transaction", async () => { + it('should throw error for invalid SLP transaction', async () => { try { // Mock the call to the REST API sandbox - .stub(uut.Utils.axios, "get") + .stub(uut.Utils.axios, 'get') .resolves({ data: mockData.mockInvalidSlpSend }) const txid = - "a60a522cc11ad7011b74e57fbabbd99296e4b9346bcb175dcf84efb737030415" + 'a60a522cc11ad7011b74e57fbabbd99296e4b9346bcb175dcf84efb737030415' await uut.Utils.decodeOpReturn(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) } catch (err) { // console.log(`err: `, err) - assert.include(err.message, "amount string size not 8 bytes") + assert.include(err.message, 'amount string size not 8 bytes') } }) - it("should decode a NFT Parent transaction", async () => { + it('should decode a NFT Parent transaction', async () => { // Mock the call to the REST API. sandbox - .stub(uut.Utils.axios, "get") + .stub(uut.Utils.axios, 'get') .resolves({ data: mockData.txDetailsSLPNftGenesis }) const txid = - "4ef6eb92950a13a69e97c2c02c7967d806aa874c0e2a6b5546a8880f2cd14bc4" + '4ef6eb92950a13a69e97c2c02c7967d806aa874c0e2a6b5546a8880f2cd14bc4' const data = await uut.Utils.decodeOpReturn(txid) // console.log(`data: ${JSON.stringify(data, null, 2)}`) - assert.property(data, "tokenType") - assert.property(data, "txType") - assert.property(data, "ticker") - assert.property(data, "name") - assert.property(data, "tokenId") - assert.property(data, "documentUri") - assert.property(data, "documentHash") - assert.property(data, "decimals") - assert.property(data, "mintBatonVout") - assert.property(data, "qty") + assert.property(data, 'tokenType') + assert.property(data, 'txType') + assert.property(data, 'ticker') + assert.property(data, 'name') + assert.property(data, 'tokenId') + assert.property(data, 'documentUri') + assert.property(data, 'documentHash') + assert.property(data, 'decimals') + assert.property(data, 'mintBatonVout') + assert.property(data, 'qty') assert.equal(data.tokenType, 129) assert.equal(data.mintBatonVout, 2) @@ -482,27 +482,27 @@ describe("#SLP Utils", () => { // }) }) - describe("#tokenUtxoDetails", () => { - it("should throw error if input is not an array.", async () => { + describe('#tokenUtxoDetails', () => { + it('should throw error if input is not an array.', async () => { try { - await uut.Utils.tokenUtxoDetails("test") + await uut.Utils.tokenUtxoDetails('test') - assert.equal(true, false, "Unexpected result.") + assert.equal(true, false, 'Unexpected result.') } catch (err) { assert.include( err.message, - `Input must be an array`, - "Expected error message." + 'Input must be an array', + 'Expected error message.' ) } }) - it("should throw error if utxo does not have satoshis or value property.", async () => { + it('should throw error if utxo does not have satoshis or value property.', async () => { try { const utxos = [ { txid: - "bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90", + 'bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90', vout: 3, amount: 0.00002015, satoshis: 2015, @@ -511,7 +511,7 @@ describe("#SLP Utils", () => { }, { txid: - "bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90", + 'bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90', vout: 2, amount: 0.00000546, height: 594892, @@ -521,22 +521,22 @@ describe("#SLP Utils", () => { await uut.Utils.tokenUtxoDetails(utxos) - assert.equal(true, false, "Unexpected result.") + assert.equal(true, false, 'Unexpected result.') } catch (err) { assert.include( err.message, - `utxo 1 does not have a satoshis or value property`, - "Expected error message." + 'utxo 1 does not have a satoshis or value property', + 'Expected error message.' ) } }) - it("should throw error if utxo does not have txid or tx_hash property.", async () => { + it('should throw error if utxo does not have txid or tx_hash property.', async () => { try { const utxos = [ { txid: - "bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90", + 'bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90', vout: 3, amount: 0.00002015, satoshis: 2015, @@ -554,48 +554,48 @@ describe("#SLP Utils", () => { await uut.Utils.tokenUtxoDetails(utxos) - assert.equal(true, false, "Unexpected result.") + assert.equal(true, false, 'Unexpected result.') } catch (err) { assert.include( err.message, - `utxo 1 does not have a txid or tx_hash property`, - "Expected error message." + 'utxo 1 does not have a txid or tx_hash property', + 'Expected error message.' ) } }) // // This captures an important corner-case. When an SLP token is created, the // // change UTXO will contain the same SLP txid, but it is not an SLP UTXO. - it("should return details on minting baton from genesis transaction", async () => { + it('should return details on minting baton from genesis transaction', async () => { // Mock the call to REST API // Stub the call to validateTxid - sandbox.stub(uut.Utils, "validateTxid").resolves([ + sandbox.stub(uut.Utils, 'validateTxid').resolves([ { txid: - "bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90", + 'bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90', valid: true } ]) // Stub the calls to decodeOpReturn. - sandbox.stub(uut.Utils, "decodeOpReturn").resolves({ + sandbox.stub(uut.Utils, 'decodeOpReturn').resolves({ tokenType: 1, - txType: "GENESIS", - ticker: "SLPSDK", - name: "SLP SDK example using BITBOX", + txType: 'GENESIS', + ticker: 'SLPSDK', + name: 'SLP SDK example using BITBOX', tokenId: - "bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90", - documentUri: "developer.bitcoin.com", - documentHash: "", + 'bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90', + documentUri: 'developer.bitcoin.com', + documentHash: '', decimals: 8, mintBatonVout: 2, - qty: "50700000000" + qty: '50700000000' }) const utxos = [ { txid: - "bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90", + 'bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90', vout: 3, amount: 0.00002015, satoshis: 2015, @@ -604,7 +604,7 @@ describe("#SLP Utils", () => { }, { txid: - "bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90", + 'bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90', vout: 2, amount: 0.00000546, satoshis: 546, @@ -617,67 +617,67 @@ describe("#SLP Utils", () => { // console.log(`data: ${JSON.stringify(data, null, 2)}`) // assert.equal(data[0], false, "Change UTXO marked as false.") - assert.property(data[0], "txid") - assert.property(data[0], "vout") - assert.property(data[0], "amount") - assert.property(data[0], "satoshis") - assert.property(data[0], "height") - assert.property(data[0], "confirmations") - assert.property(data[0], "isValid") + assert.property(data[0], 'txid') + assert.property(data[0], 'vout') + assert.property(data[0], 'amount') + assert.property(data[0], 'satoshis') + assert.property(data[0], 'height') + assert.property(data[0], 'confirmations') + assert.property(data[0], 'isValid') assert.equal(data[0].isValid, false) - assert.property(data[1], "txid") - assert.property(data[1], "vout") - assert.property(data[1], "amount") - assert.property(data[1], "satoshis") - assert.property(data[1], "height") - assert.property(data[1], "confirmations") - assert.property(data[1], "utxoType") - assert.property(data[1], "tokenId") - assert.property(data[1], "tokenTicker") - assert.property(data[1], "tokenName") - assert.property(data[1], "tokenDocumentUrl") - assert.property(data[1], "tokenDocumentHash") - assert.property(data[1], "decimals") - assert.property(data[1], "isValid") + assert.property(data[1], 'txid') + assert.property(data[1], 'vout') + assert.property(data[1], 'amount') + assert.property(data[1], 'satoshis') + assert.property(data[1], 'height') + assert.property(data[1], 'confirmations') + assert.property(data[1], 'utxoType') + assert.property(data[1], 'tokenId') + assert.property(data[1], 'tokenTicker') + assert.property(data[1], 'tokenName') + assert.property(data[1], 'tokenDocumentUrl') + assert.property(data[1], 'tokenDocumentHash') + assert.property(data[1], 'decimals') + assert.property(data[1], 'isValid') assert.equal(data[1].isValid, true) }) - it("should return details for a MINT token utxo", async () => { + it('should return details for a MINT token utxo', async () => { // Mock the call to REST API // Stub the calls to decodeOpReturn. sandbox - .stub(uut.Utils, "decodeOpReturn") + .stub(uut.Utils, 'decodeOpReturn') .onCall(0) .resolves({ tokenType: 1, - txType: "MINT", + txType: 'MINT', tokenId: - "38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0", + '38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0', mintBatonVout: 2, - qty: "1000000000000" + qty: '1000000000000' }) .onCall(1) .resolves({ tokenType: 1, - txType: "GENESIS", - ticker: "PSF", - name: "Permissionless Software Foundation", + txType: 'GENESIS', + ticker: 'PSF', + name: 'Permissionless Software Foundation', tokenId: - "38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0", - documentUri: "psfoundation.cash", - documentHash: "", + '38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0', + documentUri: 'psfoundation.cash', + documentHash: '', decimals: 8, mintBatonVout: 2, - qty: "1988209163133" + qty: '1988209163133' }) // Stub the call to validateTxid - sandbox.stub(uut.Utils, "validateTxid").resolves([ + sandbox.stub(uut.Utils, 'validateTxid').resolves([ { txid: - "cf4b922d1e1aa56b52d752d4206e1448ea76c3ebe69b3b97d8f8f65413bd5c76", + 'cf4b922d1e1aa56b52d752d4206e1448ea76c3ebe69b3b97d8f8f65413bd5c76', valid: true } ]) @@ -685,7 +685,7 @@ describe("#SLP Utils", () => { const utxos = [ { txid: - "cf4b922d1e1aa56b52d752d4206e1448ea76c3ebe69b3b97d8f8f65413bd5c76", + 'cf4b922d1e1aa56b52d752d4206e1448ea76c3ebe69b3b97d8f8f65413bd5c76', vout: 1, amount: 0.00000546, satoshis: 546, @@ -697,59 +697,59 @@ describe("#SLP Utils", () => { const data = await uut.Utils.tokenUtxoDetails(utxos) // console.log(`data: ${JSON.stringify(data, null, 2)}`) - assert.property(data[0], "txid") - assert.property(data[0], "vout") - assert.property(data[0], "amount") - assert.property(data[0], "satoshis") - assert.property(data[0], "height") - assert.property(data[0], "confirmations") - assert.property(data[0], "utxoType") - assert.property(data[0], "transactionType") - assert.property(data[0], "tokenId") - assert.property(data[0], "tokenTicker") - assert.property(data[0], "tokenName") - assert.property(data[0], "tokenDocumentUrl") - assert.property(data[0], "tokenDocumentHash") - assert.property(data[0], "decimals") - assert.property(data[0], "mintBatonVout") - assert.property(data[0], "tokenQty") - assert.property(data[0], "isValid") + assert.property(data[0], 'txid') + assert.property(data[0], 'vout') + assert.property(data[0], 'amount') + assert.property(data[0], 'satoshis') + assert.property(data[0], 'height') + assert.property(data[0], 'confirmations') + assert.property(data[0], 'utxoType') + assert.property(data[0], 'transactionType') + assert.property(data[0], 'tokenId') + assert.property(data[0], 'tokenTicker') + assert.property(data[0], 'tokenName') + assert.property(data[0], 'tokenDocumentUrl') + assert.property(data[0], 'tokenDocumentHash') + assert.property(data[0], 'decimals') + assert.property(data[0], 'mintBatonVout') + assert.property(data[0], 'tokenQty') + assert.property(data[0], 'isValid') assert.equal(data[0].isValid, true) }) - it("should return details for a simple SEND SLP token utxo", async () => { + it('should return details for a simple SEND SLP token utxo', async () => { // Mock the call to REST API // Stub the calls to decodeOpReturn. sandbox - .stub(uut.Utils, "decodeOpReturn") + .stub(uut.Utils, 'decodeOpReturn') .onCall(0) .resolves({ tokenType: 1, - txType: "SEND", + txType: 'SEND', tokenId: - "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7", - amounts: ["200000000", "99887500000000"] + '497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7', + amounts: ['200000000', '99887500000000'] }) .onCall(1) .resolves({ tokenType: 1, - txType: "GENESIS", - ticker: "TOK-CH", - name: "TokyoCash", + txType: 'GENESIS', + ticker: 'TOK-CH', + name: 'TokyoCash', tokenId: - "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7", - documentUri: "", - documentHash: "", + '497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7', + documentUri: '', + documentHash: '', decimals: 8, mintBatonVout: 0, - qty: "2100000000000000" + qty: '2100000000000000' }) // Stub the call to validateTxid - sandbox.stub(uut.Utils, "validateTxid").resolves([ + sandbox.stub(uut.Utils, 'validateTxid').resolves([ { txid: - "fde117b1f176b231e2fa9a6cb022e0f7c31c288221df6bcb05f8b7d040ca87cb", + 'fde117b1f176b231e2fa9a6cb022e0f7c31c288221df6bcb05f8b7d040ca87cb', valid: true } ]) @@ -757,7 +757,7 @@ describe("#SLP Utils", () => { const utxos = [ { txid: - "fde117b1f176b231e2fa9a6cb022e0f7c31c288221df6bcb05f8b7d040ca87cb", + 'fde117b1f176b231e2fa9a6cb022e0f7c31c288221df6bcb05f8b7d040ca87cb', vout: 1, amount: 0.00000546, satoshis: 546, @@ -769,78 +769,78 @@ describe("#SLP Utils", () => { const data = await uut.Utils.tokenUtxoDetails(utxos) // console.log(`data: ${JSON.stringify(data, null, 2)}`) - assert.property(data[0], "txid") - assert.property(data[0], "vout") - assert.property(data[0], "amount") - assert.property(data[0], "satoshis") - assert.property(data[0], "height") - assert.property(data[0], "confirmations") - assert.property(data[0], "utxoType") - assert.property(data[0], "tokenId") - assert.property(data[0], "tokenTicker") - assert.property(data[0], "tokenName") - assert.property(data[0], "tokenDocumentUrl") - assert.property(data[0], "tokenDocumentHash") - assert.property(data[0], "decimals") - assert.property(data[0], "tokenQty") - assert.property(data[0], "isValid") + assert.property(data[0], 'txid') + assert.property(data[0], 'vout') + assert.property(data[0], 'amount') + assert.property(data[0], 'satoshis') + assert.property(data[0], 'height') + assert.property(data[0], 'confirmations') + assert.property(data[0], 'utxoType') + assert.property(data[0], 'tokenId') + assert.property(data[0], 'tokenTicker') + assert.property(data[0], 'tokenName') + assert.property(data[0], 'tokenDocumentUrl') + assert.property(data[0], 'tokenDocumentHash') + assert.property(data[0], 'decimals') + assert.property(data[0], 'tokenQty') + assert.property(data[0], 'isValid') assert.equal(data[0].isValid, true) }) - it("should handle BCH and SLP utxos in the same TX", async () => { + it('should handle BCH and SLP utxos in the same TX', async () => { // Mock external dependencies. sandbox - .stub(uut.Utils, "validateTxid") + .stub(uut.Utils, 'validateTxid') .resolves(mockData.mockDualValidation) sandbox - .stub(uut.Utils, "decodeOpReturn") + .stub(uut.Utils, 'decodeOpReturn') .onCall(0) .resolves({ tokenType: 1, - txType: "SEND", + txType: 'SEND', tokenId: - "dd84ca78db4d617221b58eabc6667af8fe2f7eadbfcc213d35be9f1b419beb8d", - amounts: ["1", "5"] + 'dd84ca78db4d617221b58eabc6667af8fe2f7eadbfcc213d35be9f1b419beb8d', + amounts: ['1', '5'] }) .onCall(1) .resolves({ tokenType: 1, - txType: "SEND", + txType: 'SEND', tokenId: - "dd84ca78db4d617221b58eabc6667af8fe2f7eadbfcc213d35be9f1b419beb8d", - amounts: ["1", "5"] + 'dd84ca78db4d617221b58eabc6667af8fe2f7eadbfcc213d35be9f1b419beb8d', + amounts: ['1', '5'] }) .onCall(2) .resolves({ tokenType: 1, - txType: "GENESIS", - ticker: "TAP", - name: "Thoughts and Prayers", + txType: 'GENESIS', + ticker: 'TAP', + name: 'Thoughts and Prayers', tokenId: - "dd84ca78db4d617221b58eabc6667af8fe2f7eadbfcc213d35be9f1b419beb8d", - documentUri: "", - documentHash: "", + 'dd84ca78db4d617221b58eabc6667af8fe2f7eadbfcc213d35be9f1b419beb8d', + documentUri: '', + documentHash: '', decimals: 0, mintBatonVout: 2, - qty: "1000000" + qty: '1000000' }) const utxos = [ { txid: - "d56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56", + 'd56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56', vout: 3, - value: "6816", + value: '6816', height: 606848, confirmations: 13, satoshis: 6816 }, { txid: - "d56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56", + 'd56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56', vout: 2, - value: "546", + value: '546', height: 606848, confirmations: 13, satoshis: 546 @@ -853,55 +853,55 @@ describe("#SLP Utils", () => { assert.isArray(result) assert.equal(result.length, 2) - assert.property(result[0], "txid") - assert.property(result[0], "vout") - assert.property(result[0], "value") - assert.property(result[0], "satoshis") - assert.property(result[0], "height") - assert.property(result[0], "confirmations") - assert.property(result[0], "isValid") + assert.property(result[0], 'txid') + assert.property(result[0], 'vout') + assert.property(result[0], 'value') + assert.property(result[0], 'satoshis') + assert.property(result[0], 'height') + assert.property(result[0], 'confirmations') + assert.property(result[0], 'isValid') assert.equal(result[0].isValid, false) assert.equal(result[1].isValid, true) - assert.equal(result[1].utxoType, "token") - assert.equal(result[1].transactionType, "send") + assert.equal(result[1].utxoType, 'token') + assert.equal(result[1].transactionType, 'send') }) - it("should handle problematic utxos", async () => { + it('should handle problematic utxos', async () => { // Mock external dependencies. // Stub the calls to decodeOpReturn. sandbox - .stub(uut.Utils, "decodeOpReturn") + .stub(uut.Utils, 'decodeOpReturn') .onCall(0) - .throws({ message: "scriptpubkey not op_return" }) + .throws({ message: 'scriptpubkey not op_return' }) .onCall(1) .resolves({ tokenType: 1, - txType: "SEND", + txType: 'SEND', tokenId: - "f05faf13a29c7f5e54ab921750aafb6afaa953db863bd2cf432e918661d4132f", - amounts: ["5000000", "395010942"] + 'f05faf13a29c7f5e54ab921750aafb6afaa953db863bd2cf432e918661d4132f', + amounts: ['5000000', '395010942'] }) .onCall(2) .resolves({ tokenType: 1, - txType: "GENESIS", - ticker: "AUDC", - name: "AUD Coin", + txType: 'GENESIS', + ticker: 'AUDC', + name: 'AUD Coin', tokenId: - "f05faf13a29c7f5e54ab921750aafb6afaa953db863bd2cf432e918661d4132f", - documentUri: "audcoino@gmail.com", - documentHash: "", + 'f05faf13a29c7f5e54ab921750aafb6afaa953db863bd2cf432e918661d4132f', + documentUri: 'audcoino@gmail.com', + documentHash: '', decimals: 6, mintBatonVout: 0, - qty: "2000000000000000000" + qty: '2000000000000000000' }) // Stub the call to validateTxid - sandbox.stub(uut.Utils, "validateTxid").resolves([ + sandbox.stub(uut.Utils, 'validateTxid').resolves([ { txid: - "67fd3c7c3a6eb0fea9ab311b91039545086220f7eeeefa367fa28e6e43009f19", + '67fd3c7c3a6eb0fea9ab311b91039545086220f7eeeefa367fa28e6e43009f19', valid: true } ]) @@ -909,7 +909,7 @@ describe("#SLP Utils", () => { const utxos = [ { txid: - "0e3a217fc22612002031d317b4cecd9b692b66b52951a67b23c43041aefa3959", + '0e3a217fc22612002031d317b4cecd9b692b66b52951a67b23c43041aefa3959', vout: 0, amount: 0.00018362, satoshis: 18362, @@ -918,7 +918,7 @@ describe("#SLP Utils", () => { }, { txid: - "67fd3c7c3a6eb0fea9ab311b91039545086220f7eeeefa367fa28e6e43009f19", + '67fd3c7c3a6eb0fea9ab311b91039545086220f7eeeefa367fa28e6e43009f19', vout: 1, amount: 0.00000546, satoshis: 546, @@ -933,31 +933,31 @@ describe("#SLP Utils", () => { assert.isArray(result) assert.equal(result.length, 2) - assert.property(result[0], "txid") - assert.property(result[0], "vout") - assert.property(result[0], "amount") - assert.property(result[0], "satoshis") - assert.property(result[0], "height") - assert.property(result[0], "confirmations") - assert.property(result[0], "isValid") + assert.property(result[0], 'txid') + assert.property(result[0], 'vout') + assert.property(result[0], 'amount') + assert.property(result[0], 'satoshis') + assert.property(result[0], 'height') + assert.property(result[0], 'confirmations') + assert.property(result[0], 'isValid') assert.equal(result[0].isValid, false) assert.equal(result[1].isValid, true) - assert.equal(result[1].utxoType, "token") - assert.equal(result[1].transactionType, "send") + assert.equal(result[1].utxoType, 'token') + assert.equal(result[1].transactionType, 'send') }) - it("should return isValid=false for BCH-only UTXOs", async () => { + it('should return isValid=false for BCH-only UTXOs', async () => { // Mock live network calls sandbox - .stub(uut.Utils, "decodeOpReturn") - .throws(new Error("scriptpubkey not op_return")) + .stub(uut.Utils, 'decodeOpReturn') + .throws(new Error('scriptpubkey not op_return')) const utxos = [ { txid: - "a937f792c7c9eb23b4f344ce5c233d1ac0909217d0a504d71e6b1e4efb864a3b", + 'a937f792c7c9eb23b4f344ce5c233d1ac0909217d0a504d71e6b1e4efb864a3b', vout: 0, amount: 0.00001, satoshis: 1000, @@ -966,7 +966,7 @@ describe("#SLP Utils", () => { }, { txid: - "53fd141c2e999e080a5860887441a2c45e9cbe262027e2bd2ac998fc76e43c44", + '53fd141c2e999e080a5860887441a2c45e9cbe262027e2bd2ac998fc76e43c44', vout: 0, amount: 0.00001, satoshis: 1000, @@ -980,47 +980,47 @@ describe("#SLP Utils", () => { assert.isArray(result) - assert.property(result[0], "txid") - assert.property(result[0], "vout") - assert.property(result[0], "amount") - assert.property(result[0], "satoshis") - assert.property(result[0], "confirmations") - assert.property(result[0], "isValid") + assert.property(result[0], 'txid') + assert.property(result[0], 'vout') + assert.property(result[0], 'amount') + assert.property(result[0], 'satoshis') + assert.property(result[0], 'confirmations') + assert.property(result[0], 'isValid') assert.equal(result[0].isValid, false) - assert.property(result[1], "txid") - assert.property(result[1], "vout") - assert.property(result[1], "amount") - assert.property(result[1], "satoshis") - assert.property(result[1], "confirmations") - assert.property(result[1], "isValid") + assert.property(result[1], 'txid') + assert.property(result[1], 'vout') + assert.property(result[1], 'amount') + assert.property(result[1], 'satoshis') + assert.property(result[1], 'confirmations') + assert.property(result[1], 'isValid') assert.equal(result[1].isValid, false) }) - it("should decode a Genesis transaction", async () => { + it('should decode a Genesis transaction', async () => { const slpData = { tokenType: 1, - txType: "GENESIS", - ticker: "SLPTEST", - name: "SLP Test Token", + txType: 'GENESIS', + ticker: 'SLPTEST', + name: 'SLP Test Token', tokenId: - "d2ec6abff5d1c8ed9ab5db6d140dcaebb813463e42933a4a4db171e7222a0954", - documentUri: "https://FullStack.cash", - documentHash: "", + 'd2ec6abff5d1c8ed9ab5db6d140dcaebb813463e42933a4a4db171e7222a0954', + documentUri: 'https://FullStack.cash', + documentHash: '', decimals: 8, mintBatonVout: 2, - qty: "10000000000" + qty: '10000000000' } // Mock external dependencies. // Stub the calls to decodeOpReturn. - sandbox.stub(uut.Utils, "decodeOpReturn").resolves(slpData) + sandbox.stub(uut.Utils, 'decodeOpReturn').resolves(slpData) // Stub the call to validateTxid - sandbox.stub(uut.Utils, "validateTxid").resolves([ + sandbox.stub(uut.Utils, 'validateTxid').resolves([ { txid: - "d2ec6abff5d1c8ed9ab5db6d140dcaebb813463e42933a4a4db171e7222a0954", + 'd2ec6abff5d1c8ed9ab5db6d140dcaebb813463e42933a4a4db171e7222a0954', valid: true } ]) @@ -1028,25 +1028,25 @@ describe("#SLP Utils", () => { const utxos = [ { txid: - "d2ec6abff5d1c8ed9ab5db6d140dcaebb813463e42933a4a4db171e7222a0954", + 'd2ec6abff5d1c8ed9ab5db6d140dcaebb813463e42933a4a4db171e7222a0954', vout: 1, - value: "546", + value: '546', confirmations: 0, satoshis: 546 }, { txid: - "d2ec6abff5d1c8ed9ab5db6d140dcaebb813463e42933a4a4db171e7222a0954", + 'd2ec6abff5d1c8ed9ab5db6d140dcaebb813463e42933a4a4db171e7222a0954', vout: 2, - value: "546", + value: '546', confirmations: 0, satoshis: 546 }, { txid: - "d2ec6abff5d1c8ed9ab5db6d140dcaebb813463e42933a4a4db171e7222a0954", + 'd2ec6abff5d1c8ed9ab5db6d140dcaebb813463e42933a4a4db171e7222a0954', vout: 3, - value: "12178", + value: '12178', confirmations: 0, satoshis: 12178 } @@ -1057,47 +1057,47 @@ describe("#SLP Utils", () => { assert.isArray(data) - assert.equal(data[0].utxoType, "token") + assert.equal(data[0].utxoType, 'token') assert.equal(data[0].tokenQty, 100) assert.equal(data[0].isValid, true) assert.equal(data[0].tokenType, 1) - assert.equal(data[1].utxoType, "minting-baton") + assert.equal(data[1].utxoType, 'minting-baton') assert.equal(data[1].isValid, true) assert.equal(data[1].tokenType, 1) assert.equal(data[2].isValid, false) }) - it("should decode a Mint transaction", async () => { + it('should decode a Mint transaction', async () => { // Define stubbed data. const slpData = { tokenType: 1, - txType: "MINT", + txType: 'MINT', tokenId: - "9d35c1803ed3ab8bd23c198b027f7b3b530586494dc265de6391b74a6b090136", + '9d35c1803ed3ab8bd23c198b027f7b3b530586494dc265de6391b74a6b090136', mintBatonVout: 2, - qty: "10000000000" + qty: '10000000000' } const genesisData = { tokenType: 1, - txType: "GENESIS", - ticker: "SLPTEST", - name: "SLP Test Token", + txType: 'GENESIS', + ticker: 'SLPTEST', + name: 'SLP Test Token', tokenId: - "9d35c1803ed3ab8bd23c198b027f7b3b530586494dc265de6391b74a6b090136", - documentUri: "https://FullStack.cash", - documentHash: "", + '9d35c1803ed3ab8bd23c198b027f7b3b530586494dc265de6391b74a6b090136', + documentUri: 'https://FullStack.cash', + documentHash: '', decimals: 8, mintBatonVout: 2, - qty: "10000000000" + qty: '10000000000' } const stubValid = [ { txid: - "880587f01e3112e779c0fdf1b9b859c242a28e56ead85483eeedcaa52f051a04", + '880587f01e3112e779c0fdf1b9b859c242a28e56ead85483eeedcaa52f051a04', valid: true } ] @@ -1105,7 +1105,7 @@ describe("#SLP Utils", () => { // Mock external dependencies. // Stub the calls to decodeOpReturn. sandbox - .stub(uut.Utils, "decodeOpReturn") + .stub(uut.Utils, 'decodeOpReturn') .resolves(slpData) .onCall(1) .resolves(genesisData) @@ -1118,7 +1118,7 @@ describe("#SLP Utils", () => { // Stub the call to validateTxid sandbox - .stub(uut.Utils, "validateTxid") + .stub(uut.Utils, 'validateTxid') .resolves(stubValid) .onCall(1) .resolves(stubValid) @@ -1126,25 +1126,25 @@ describe("#SLP Utils", () => { const utxos = [ { txid: - "880587f01e3112e779c0fdf1b9b859c242a28e56ead85483eeedcaa52f051a04", + '880587f01e3112e779c0fdf1b9b859c242a28e56ead85483eeedcaa52f051a04', vout: 1, - value: "546", + value: '546', confirmations: 0, satoshis: 546 }, { txid: - "880587f01e3112e779c0fdf1b9b859c242a28e56ead85483eeedcaa52f051a04", + '880587f01e3112e779c0fdf1b9b859c242a28e56ead85483eeedcaa52f051a04', vout: 2, - value: "546", + value: '546', confirmations: 0, satoshis: 546 }, { txid: - "880587f01e3112e779c0fdf1b9b859c242a28e56ead85483eeedcaa52f051a04", + '880587f01e3112e779c0fdf1b9b859c242a28e56ead85483eeedcaa52f051a04', vout: 3, - value: "10552", + value: '10552', confirmations: 0, satoshis: 10552 } @@ -1155,38 +1155,38 @@ describe("#SLP Utils", () => { assert.isArray(data) - assert.equal(data[0].utxoType, "token") + assert.equal(data[0].utxoType, 'token') assert.equal(data[0].tokenQty, 100) assert.equal(data[0].isValid, true) assert.equal(data[0].tokenType, 1) - assert.equal(data[1].utxoType, "minting-baton") + assert.equal(data[1].utxoType, 'minting-baton') assert.equal(data[1].isValid, true) assert.equal(data[1].tokenType, 1) assert.equal(data[2].isValid, false) }) - it("should decode a NFT Group Genesis transaction", async () => { + it('should decode a NFT Group Genesis transaction', async () => { // Define stubbed data. const slpData = { tokenType: 129, - txType: "GENESIS", - ticker: "NFTTT", - name: "NFT Test Token", + txType: 'GENESIS', + ticker: 'NFTTT', + name: 'NFT Test Token', tokenId: - "4ef6eb92950a13a69e97c2c02c7967d806aa874c0e2a6b5546a8880f2cd14bc4", - documentUri: "https://FullStack.cash", - documentHash: "", + '4ef6eb92950a13a69e97c2c02c7967d806aa874c0e2a6b5546a8880f2cd14bc4', + documentUri: 'https://FullStack.cash', + documentHash: '', decimals: 0, mintBatonVout: 2, - qty: "1" + qty: '1' } const stubValid = [ { txid: - "4ef6eb92950a13a69e97c2c02c7967d806aa874c0e2a6b5546a8880f2cd14bc4", + '4ef6eb92950a13a69e97c2c02c7967d806aa874c0e2a6b5546a8880f2cd14bc4', valid: true } ] @@ -1194,7 +1194,7 @@ describe("#SLP Utils", () => { // Mock external dependencies. // Stub the calls to decodeOpReturn. sandbox - .stub(uut.Utils, "decodeOpReturn") + .stub(uut.Utils, 'decodeOpReturn') .resolves(slpData) .onCall(1) .resolves(slpData) @@ -1207,7 +1207,7 @@ describe("#SLP Utils", () => { // Stub the call to validateTxid sandbox - .stub(uut.Utils, "validateTxid") + .stub(uut.Utils, 'validateTxid') .resolves(stubValid) .onCall(1) .resolves(stubValid) @@ -1217,27 +1217,27 @@ describe("#SLP Utils", () => { const utxos = [ { txid: - "4ef6eb92950a13a69e97c2c02c7967d806aa874c0e2a6b5546a8880f2cd14bc4", + '4ef6eb92950a13a69e97c2c02c7967d806aa874c0e2a6b5546a8880f2cd14bc4', vout: 3, - value: "15620", + value: '15620', height: 638207, confirmations: 3, satoshis: 15620 }, { txid: - "4ef6eb92950a13a69e97c2c02c7967d806aa874c0e2a6b5546a8880f2cd14bc4", + '4ef6eb92950a13a69e97c2c02c7967d806aa874c0e2a6b5546a8880f2cd14bc4', vout: 2, - value: "546", + value: '546', height: 638207, confirmations: 3, satoshis: 546 }, { txid: - "4ef6eb92950a13a69e97c2c02c7967d806aa874c0e2a6b5546a8880f2cd14bc4", + '4ef6eb92950a13a69e97c2c02c7967d806aa874c0e2a6b5546a8880f2cd14bc4', vout: 1, - value: "546", + value: '546', height: 638207, confirmations: 3, satoshis: 546 @@ -1251,44 +1251,44 @@ describe("#SLP Utils", () => { assert.equal(data[0].isValid, false) - assert.equal(data[1].utxoType, "minting-baton") + assert.equal(data[1].utxoType, 'minting-baton') assert.equal(data[1].isValid, true) assert.equal(data[1].tokenType, 129) - assert.equal(data[2].utxoType, "token") + assert.equal(data[2].utxoType, 'token') assert.equal(data[2].tokenType, 129) assert.equal(data[1].isValid, true) }) - it("should decode a NFT Group Mint transaction", async () => { + it('should decode a NFT Group Mint transaction', async () => { // Define stubbed data. const slpData = { tokenType: 129, - txType: "MINT", + txType: 'MINT', tokenId: - "eee4b82e4bb7113eca433829144363fc45f110693c286494fbf5b5c8043cc981", + 'eee4b82e4bb7113eca433829144363fc45f110693c286494fbf5b5c8043cc981', mintBatonVout: 2, - qty: "10" + qty: '10' } const genesisData = { tokenType: 129, - txType: "GENESIS", - ticker: "NFTTT", - name: "NFT Test Token", + txType: 'GENESIS', + ticker: 'NFTTT', + name: 'NFT Test Token', tokenId: - "eee4b82e4bb7113eca433829144363fc45f110693c286494fbf5b5c8043cc981", - documentUri: "https://FullStack.cash", - documentHash: "", + 'eee4b82e4bb7113eca433829144363fc45f110693c286494fbf5b5c8043cc981', + documentUri: 'https://FullStack.cash', + documentHash: '', decimals: 0, mintBatonVout: 2, - qty: "1" + qty: '1' } const stubValid = [ { txid: - "35846676e7514658bbd2fd60b1f0d4d86195908f6b2de5328d54c8e4a2d05919", + '35846676e7514658bbd2fd60b1f0d4d86195908f6b2de5328d54c8e4a2d05919', valid: true } ] @@ -1296,7 +1296,7 @@ describe("#SLP Utils", () => { // Mock external dependencies. // Stub the calls to decodeOpReturn. sandbox - .stub(uut.Utils, "decodeOpReturn") + .stub(uut.Utils, 'decodeOpReturn') .resolves(slpData) .onCall(1) .resolves(slpData) @@ -1309,7 +1309,7 @@ describe("#SLP Utils", () => { // Stub the call to validateTxid sandbox - .stub(uut.Utils, "validateTxid") + .stub(uut.Utils, 'validateTxid') .resolves(stubValid) .onCall(1) .resolves(stubValid) @@ -1319,27 +1319,27 @@ describe("#SLP Utils", () => { const utxos = [ { txid: - "35846676e7514658bbd2fd60b1f0d4d86195908f6b2de5328d54c8e4a2d05919", + '35846676e7514658bbd2fd60b1f0d4d86195908f6b2de5328d54c8e4a2d05919', vout: 3, - value: "15620", + value: '15620', height: 638207, confirmations: 3, satoshis: 15620 }, { txid: - "35846676e7514658bbd2fd60b1f0d4d86195908f6b2de5328d54c8e4a2d05919", + '35846676e7514658bbd2fd60b1f0d4d86195908f6b2de5328d54c8e4a2d05919', vout: 2, - value: "546", + value: '546', height: 638207, confirmations: 3, satoshis: 546 }, { txid: - "35846676e7514658bbd2fd60b1f0d4d86195908f6b2de5328d54c8e4a2d05919", + '35846676e7514658bbd2fd60b1f0d4d86195908f6b2de5328d54c8e4a2d05919', vout: 1, - value: "546", + value: '546', height: 638207, confirmations: 3, satoshis: 546 @@ -1353,35 +1353,35 @@ describe("#SLP Utils", () => { assert.equal(data[0].isValid, false) - assert.equal(data[1].utxoType, "minting-baton") + assert.equal(data[1].utxoType, 'minting-baton') assert.equal(data[1].tokenType, 129) assert.equal(data[1].isValid, true) - assert.equal(data[2].utxoType, "token") + assert.equal(data[2].utxoType, 'token') assert.equal(data[2].tokenType, 129) assert.equal(data[2].isValid, true) }) - it("should decode a NFT Child Genesis transaction", async () => { + it('should decode a NFT Child Genesis transaction', async () => { // Define stubbed data. const slpData = { tokenType: 65, - txType: "GENESIS", - ticker: "NFTC", - name: "NFT Child", + txType: 'GENESIS', + ticker: 'NFTC', + name: 'NFT Child', tokenId: - "9b6db26b64aedcedc0bd9a3037b29b3598573ec5cea99eec03faa838616cd683", - documentUri: "https://FullStack.cash", - documentHash: "", + '9b6db26b64aedcedc0bd9a3037b29b3598573ec5cea99eec03faa838616cd683', + documentUri: 'https://FullStack.cash', + documentHash: '', decimals: 0, mintBatonVout: 0, - qty: "1" + qty: '1' } const stubValid = [ { txid: - "9b6db26b64aedcedc0bd9a3037b29b3598573ec5cea99eec03faa838616cd683", + '9b6db26b64aedcedc0bd9a3037b29b3598573ec5cea99eec03faa838616cd683', valid: true } ] @@ -1389,28 +1389,28 @@ describe("#SLP Utils", () => { // Mock external dependencies. // Stub the calls to decodeOpReturn. sandbox - .stub(uut.Utils, "decodeOpReturn") + .stub(uut.Utils, 'decodeOpReturn') .resolves(slpData) .onCall(1) .resolves(slpData) // Stub the call to validateTxid - sandbox.stub(uut.Utils, "validateTxid").resolves(stubValid) + sandbox.stub(uut.Utils, 'validateTxid').resolves(stubValid) const utxos = [ { txid: - "9b6db26b64aedcedc0bd9a3037b29b3598573ec5cea99eec03faa838616cd683", + '9b6db26b64aedcedc0bd9a3037b29b3598573ec5cea99eec03faa838616cd683', vout: 1, - value: "546", + value: '546', confirmations: 0, satoshis: 546 }, { txid: - "9b6db26b64aedcedc0bd9a3037b29b3598573ec5cea99eec03faa838616cd683", + '9b6db26b64aedcedc0bd9a3037b29b3598573ec5cea99eec03faa838616cd683', vout: 2, - value: "13478", + value: '13478', confirmations: 0, satoshis: 13478 } @@ -1421,41 +1421,41 @@ describe("#SLP Utils", () => { assert.isArray(data) - assert.equal(data[0].utxoType, "token") + assert.equal(data[0].utxoType, 'token') assert.equal(data[0].tokenType, 65) assert.equal(data[0].isValid, true) assert.equal(data[1].isValid, false) }) - it("should decode an NFT Child Send transaction", async () => { + it('should decode an NFT Child Send transaction', async () => { // Define stubbed data. const slpData = { tokenType: 65, - txType: "SEND", + txType: 'SEND', tokenId: - "9b6db26b64aedcedc0bd9a3037b29b3598573ec5cea99eec03faa838616cd683", - amounts: ["1"] + '9b6db26b64aedcedc0bd9a3037b29b3598573ec5cea99eec03faa838616cd683', + amounts: ['1'] } const genesisData = { tokenType: 65, - txType: "GENESIS", - ticker: "NFTC", - name: "NFT Child", + txType: 'GENESIS', + ticker: 'NFTC', + name: 'NFT Child', tokenId: - "9b6db26b64aedcedc0bd9a3037b29b3598573ec5cea99eec03faa838616cd683", - documentUri: "https://FullStack.cash", - documentHash: "", + '9b6db26b64aedcedc0bd9a3037b29b3598573ec5cea99eec03faa838616cd683', + documentUri: 'https://FullStack.cash', + documentHash: '', decimals: 0, mintBatonVout: 0, - qty: "1" + qty: '1' } const stubValid = [ { txid: - "6d68a7ffbb63ef851c43025f801a1d365cddda50b00741bca022c743d74cd61a", + '6d68a7ffbb63ef851c43025f801a1d365cddda50b00741bca022c743d74cd61a', valid: true } ] @@ -1463,7 +1463,7 @@ describe("#SLP Utils", () => { // Mock external dependencies. // Stub the calls to decodeOpReturn. sandbox - .stub(uut.Utils, "decodeOpReturn") + .stub(uut.Utils, 'decodeOpReturn') .resolves(slpData) .onCall(1) .resolves(genesisData) @@ -1471,22 +1471,22 @@ describe("#SLP Utils", () => { .resolves(slpData) // Stub the call to validateTxid - sandbox.stub(uut.Utils, "validateTxid").resolves(stubValid) + sandbox.stub(uut.Utils, 'validateTxid').resolves(stubValid) const utxos = [ { txid: - "6d68a7ffbb63ef851c43025f801a1d365cddda50b00741bca022c743d74cd61a", + '6d68a7ffbb63ef851c43025f801a1d365cddda50b00741bca022c743d74cd61a', vout: 1, - value: "546", + value: '546', confirmations: 0, satoshis: 546 }, { txid: - "6d68a7ffbb63ef851c43025f801a1d365cddda50b00741bca022c743d74cd61a", + '6d68a7ffbb63ef851c43025f801a1d365cddda50b00741bca022c743d74cd61a', vout: 2, - value: "12136", + value: '12136', confirmations: 0, satoshis: 12136 } @@ -1497,42 +1497,42 @@ describe("#SLP Utils", () => { assert.isArray(data) - assert.equal(data[0].utxoType, "token") - assert.equal(data[0].transactionType, "send") + assert.equal(data[0].utxoType, 'token') + assert.equal(data[0].transactionType, 'send') assert.equal(data[0].tokenType, 65) assert.equal(data[0].isValid, true) assert.equal(data[1].isValid, false) }) - it("should decode an NFT Group Send transaction", async () => { + it('should decode an NFT Group Send transaction', async () => { // Define stubbed data. const slpData = { tokenType: 129, - txType: "SEND", + txType: 'SEND', tokenId: - "eee4b82e4bb7113eca433829144363fc45f110693c286494fbf5b5c8043cc981", - amounts: ["1", "8"] + 'eee4b82e4bb7113eca433829144363fc45f110693c286494fbf5b5c8043cc981', + amounts: ['1', '8'] } const genesisData = { tokenType: 129, - txType: "GENESIS", - ticker: "NFTTT", - name: "NFT Test Token", + txType: 'GENESIS', + ticker: 'NFTTT', + name: 'NFT Test Token', tokenId: - "eee4b82e4bb7113eca433829144363fc45f110693c286494fbf5b5c8043cc981", - documentUri: "https://FullStack.cash", - documentHash: "", + 'eee4b82e4bb7113eca433829144363fc45f110693c286494fbf5b5c8043cc981', + documentUri: 'https://FullStack.cash', + documentHash: '', decimals: 0, mintBatonVout: 2, - qty: "1" + qty: '1' } const stubValid = [ { txid: - "57cc47c265ce878679e95e2cec510d8a1a9840f5c62feb4743cc5947d57d9766", + '57cc47c265ce878679e95e2cec510d8a1a9840f5c62feb4743cc5947d57d9766', valid: true } ] @@ -1540,7 +1540,7 @@ describe("#SLP Utils", () => { // Mock external dependencies. // Stub the calls to decodeOpReturn. sandbox - .stub(uut.Utils, "decodeOpReturn") + .stub(uut.Utils, 'decodeOpReturn') .resolves(slpData) .onCall(1) .resolves(genesisData) @@ -1553,7 +1553,7 @@ describe("#SLP Utils", () => { // Stub the call to validateTxid sandbox - .stub(uut.Utils, "validateTxid") + .stub(uut.Utils, 'validateTxid') .resolves(stubValid) .onCall(1) .resolves(stubValid) @@ -1561,25 +1561,25 @@ describe("#SLP Utils", () => { const utxos = [ { txid: - "57cc47c265ce878679e95e2cec510d8a1a9840f5c62feb4743cc5947d57d9766", + '57cc47c265ce878679e95e2cec510d8a1a9840f5c62feb4743cc5947d57d9766', vout: 1, - value: "546", + value: '546', confirmations: 0, satoshis: 546 }, { txid: - "57cc47c265ce878679e95e2cec510d8a1a9840f5c62feb4743cc5947d57d9766", + '57cc47c265ce878679e95e2cec510d8a1a9840f5c62feb4743cc5947d57d9766', vout: 2, - value: "546", + value: '546', confirmations: 0, satoshis: 546 }, { txid: - "57cc47c265ce878679e95e2cec510d8a1a9840f5c62feb4743cc5947d57d9766", + '57cc47c265ce878679e95e2cec510d8a1a9840f5c62feb4743cc5947d57d9766', vout: 3, - value: "10794", + value: '10794', confirmations: 0, satoshis: 10794 } @@ -1590,48 +1590,48 @@ describe("#SLP Utils", () => { assert.isArray(data) - assert.equal(data[0].utxoType, "token") - assert.equal(data[0].transactionType, "send") + assert.equal(data[0].utxoType, 'token') + assert.equal(data[0].transactionType, 'send') assert.equal(data[0].tokenType, 129) assert.equal(data[0].isValid, true) - assert.equal(data[1].utxoType, "token") - assert.equal(data[1].transactionType, "send") + assert.equal(data[1].utxoType, 'token') + assert.equal(data[1].transactionType, 'send') assert.equal(data[1].tokenType, 129) assert.equal(data[1].isValid, true) assert.equal(data[2].isValid, false) }) - it("should return null value when 429 recieved", async () => { + it('should return null value when 429 recieved', async () => { const utxos = [ { height: 654522, tx_hash: - "072a1e2c2d5f1309bf4eef7f88684e4ecd544a903b386b07f3e04b91b13d8af1", + '072a1e2c2d5f1309bf4eef7f88684e4ecd544a903b386b07f3e04b91b13d8af1', tx_pos: 0, value: 6999, satoshis: 6999, txid: - "072a1e2c2d5f1309bf4eef7f88684e4ecd544a903b386b07f3e04b91b13d8af1", + '072a1e2c2d5f1309bf4eef7f88684e4ecd544a903b386b07f3e04b91b13d8af1', vout: 0 }, { height: 654522, tx_hash: - "a72db6a0883ecb8e379f317231b2571e41e041b7b1107e3e54c2e0b3386ac6ca", + 'a72db6a0883ecb8e379f317231b2571e41e041b7b1107e3e54c2e0b3386ac6ca', tx_pos: 1, value: 546, satoshis: 546, txid: - "a72db6a0883ecb8e379f317231b2571e41e041b7b1107e3e54c2e0b3386ac6ca", + 'a72db6a0883ecb8e379f317231b2571e41e041b7b1107e3e54c2e0b3386ac6ca', vout: 1 } ] - sandbox.stub(uut.Utils, "decodeOpReturn").rejects({ + sandbox.stub(uut.Utils, 'decodeOpReturn').rejects({ error: - "Too many requests. Your limits are currently 3 requests per minute. Increase rate limits at https://fullstack.cash" + 'Too many requests. Your limits are currently 3 requests per minute. Increase rate limits at https://fullstack.cash' }) const data = await uut.Utils.tokenUtxoDetails(utxos) @@ -1644,25 +1644,25 @@ describe("#SLP Utils", () => { }) // it("should handle a dust attack", async () => { - it("should handle dust attack UTXOs", async () => { + it('should handle dust attack UTXOs', async () => { // Mock external dependencies. // Stub the calls to decodeOpReturn. sandbox - .stub(uut.Utils, "decodeOpReturn") - .rejects(new Error("lokad id wrong size")) + .stub(uut.Utils, 'decodeOpReturn') + .rejects(new Error('lokad id wrong size')) const utxos = [ { height: 655965, tx_hash: - "a675af87dcd8d39be782737aa52e0076b52eb2f5ce355ffcb5567a64dd96b77e", + 'a675af87dcd8d39be782737aa52e0076b52eb2f5ce355ffcb5567a64dd96b77e', tx_pos: 151, value: 547, satoshis: 547, txid: - "a675af87dcd8d39be782737aa52e0076b52eb2f5ce355ffcb5567a64dd96b77e", + 'a675af87dcd8d39be782737aa52e0076b52eb2f5ce355ffcb5567a64dd96b77e', vout: 151, - address: "bitcoincash:qq4dw3sm8qvglspy6w2qg0u2ugsy9zcfcqrpeflwww", + address: 'bitcoincash:qq4dw3sm8qvglspy6w2qg0u2ugsy9zcfcqrpeflwww', hdIndex: 11 } ] @@ -1673,17 +1673,17 @@ describe("#SLP Utils", () => { assert.equal(data[0].isValid, false) }) - it("should invalidate a malformed SLP OP_RETURN", async () => { + it('should invalidate a malformed SLP OP_RETURN', async () => { sandbox - .stub(uut.Utils, "decodeOpReturn") - .rejects(new Error("trailing data")) + .stub(uut.Utils, 'decodeOpReturn') + .rejects(new Error('trailing data')) const utxos = [ // Malformed SLP tx { - note: "Malformed SLP tx", + note: 'Malformed SLP tx', tx_hash: - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a", + 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a', tx_pos: 1, value: 546 } @@ -1695,40 +1695,40 @@ describe("#SLP Utils", () => { assert.equal(data[0].isValid, false) }) - it("should use backup validators when regular SLPDB returns null", async () => { + it('should use backup validators when regular SLPDB returns null', async () => { // Mock the call to REST API // Stub the calls to decodeOpReturn. sandbox - .stub(uut.Utils, "decodeOpReturn") + .stub(uut.Utils, 'decodeOpReturn') .onCall(0) .resolves({ tokenType: 1, - txType: "SEND", + txType: 'SEND', tokenId: - "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7", - amounts: ["200000000", "99887500000000"] + '497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7', + amounts: ['200000000', '99887500000000'] }) .onCall(1) .resolves({ tokenType: 1, - txType: "GENESIS", - ticker: "TOK-CH", - name: "TokyoCash", + txType: 'GENESIS', + ticker: 'TOK-CH', + name: 'TokyoCash', tokenId: - "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7", - documentUri: "", - documentHash: "", + '497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7', + documentUri: '', + documentHash: '', decimals: 8, mintBatonVout: 0, - qty: "2100000000000000" + qty: '2100000000000000' }) // Force default SLPDB to return 'null', which should trigger usage of the // backup whitelist-SLPDB. - sandbox.stub(uut.Utils, "validateTxid").resolves([ + sandbox.stub(uut.Utils, 'validateTxid').resolves([ { txid: - "fde117b1f176b231e2fa9a6cb022e0f7c31c288221df6bcb05f8b7d040ca87cb", + 'fde117b1f176b231e2fa9a6cb022e0f7c31c288221df6bcb05f8b7d040ca87cb', valid: null } ]) @@ -1737,26 +1737,26 @@ describe("#SLP Utils", () => { uut.Utils.whitelist = mockData.whitelist // Mock the response from the whitelist-SLPDB. - sandbox.stub(uut.Utils, "validateTxid3").resolves([ + sandbox.stub(uut.Utils, 'validateTxid3').resolves([ { txid: - "fde117b1f176b231e2fa9a6cb022e0f7c31c288221df6bcb05f8b7d040ca87cb", + 'fde117b1f176b231e2fa9a6cb022e0f7c31c288221df6bcb05f8b7d040ca87cb', valid: null } ]) // Mock the response from slp-api - sandbox.stub(uut.Utils, "validateTxid2").resolves({ + sandbox.stub(uut.Utils, 'validateTxid2').resolves({ txid: - "fde117b1f176b231e2fa9a6cb022e0f7c31c288221df6bcb05f8b7d040ca87cb", + 'fde117b1f176b231e2fa9a6cb022e0f7c31c288221df6bcb05f8b7d040ca87cb', isValid: true, - msg: "" + msg: '' }) const utxos = [ { txid: - "fde117b1f176b231e2fa9a6cb022e0f7c31c288221df6bcb05f8b7d040ca87cb", + 'fde117b1f176b231e2fa9a6cb022e0f7c31c288221df6bcb05f8b7d040ca87cb', vout: 1, amount: 0.00000546, satoshis: 546, @@ -1772,49 +1772,49 @@ describe("#SLP Utils", () => { assert.equal(data[0].isValid, true) }) - it("should handle SLPDB returning null corner case", async () => { + it('should handle SLPDB returning null corner case', async () => { // Mock the call to REST API // Stub the calls to decodeOpReturn. sandbox - .stub(uut.Utils, "decodeOpReturn") + .stub(uut.Utils, 'decodeOpReturn') .onCall(0) .resolves({ tokenType: 1, - txType: "SEND", + txType: 'SEND', tokenId: - "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7", - amounts: ["200000000", "99887500000000"] + '497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7', + amounts: ['200000000', '99887500000000'] }) .onCall(1) .resolves({ tokenType: 1, - txType: "GENESIS", - ticker: "TOK-CH", - name: "TokyoCash", + txType: 'GENESIS', + ticker: 'TOK-CH', + name: 'TokyoCash', tokenId: - "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7", - documentUri: "", - documentHash: "", + '497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7', + documentUri: '', + documentHash: '', decimals: 8, mintBatonVout: 0, - qty: "2100000000000000" + qty: '2100000000000000' }) // Force default SLPDB to return 'null' corner case. - sandbox.stub(uut.Utils, "validateTxid").resolves([null]) + sandbox.stub(uut.Utils, 'validateTxid').resolves([null]) // Mock the response from slp-api - sandbox.stub(uut.Utils, "validateTxid2").resolves({ + sandbox.stub(uut.Utils, 'validateTxid2').resolves({ txid: - "fde117b1f176b231e2fa9a6cb022e0f7c31c288221df6bcb05f8b7d040ca87cb", + 'fde117b1f176b231e2fa9a6cb022e0f7c31c288221df6bcb05f8b7d040ca87cb', isValid: true, - msg: "" + msg: '' }) const utxos = [ { txid: - "fde117b1f176b231e2fa9a6cb022e0f7c31c288221df6bcb05f8b7d040ca87cb", + 'fde117b1f176b231e2fa9a6cb022e0f7c31c288221df6bcb05f8b7d040ca87cb', vout: 1, amount: 0.00000546, satoshis: 546, @@ -1831,196 +1831,196 @@ describe("#SLP Utils", () => { }) }) - describe("#txDetails", () => { - it("should throw an error if txid is not included", async () => { + describe('#txDetails', () => { + it('should throw an error if txid is not included', async () => { try { await uut.Utils.txDetails() } catch (err) { assert.include( err.message, - `txid string must be included`, - "Expected error message." + 'txid string must be included', + 'Expected error message.' ) } }) - it("should throw error for non-existent txid", async () => { + it('should throw error for non-existent txid', async () => { try { // Mock the call to the REST API - if (process.env.TEST === "unit") { + if (process.env.TEST === 'unit') { sandbox - .stub(uut.Utils.axios, "get") - //.resolves({ data: mockData.nonSLPTxDetailsWithoutOpReturn }) - .throws({ error: `TXID not found` }) + .stub(uut.Utils.axios, 'get') + // .resolves({ data: mockData.nonSLPTxDetailsWithoutOpReturn }) + .throws({ error: 'TXID not found' }) } - const txid = `d284e71227ec89f714b964d8eda595be6392bebd2fac46082bc5a9ce6fb7b33e` + const txid = 'd284e71227ec89f714b964d8eda595be6392bebd2fac46082bc5a9ce6fb7b33e' await uut.Utils.txDetails(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.fail("Unexpected result") + assert.fail('Unexpected result') } catch (err) { // console.log(`err: `, err) - assert.include(err.error, `TXID not found`, "Expected error message.") + assert.include(err.error, 'TXID not found', 'Expected error message.') } }) - it("should return details for an SLP txid", async () => { + it('should return details for an SLP txid', async () => { // Mock the call to the REST API - if (process.env.TEST === "unit") { + if (process.env.TEST === 'unit') { sandbox - .stub(uut.Utils.axios, "get") + .stub(uut.Utils.axios, 'get') .resolves({ data: mockData.mockTxDetails }) } - const txid = `9dbaaafc48c49a21beabada8de632009288a2cd52eecefd0c00edcffca9955d0` + const txid = '9dbaaafc48c49a21beabada8de632009288a2cd52eecefd0c00edcffca9955d0' const result = await uut.Utils.txDetails(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.hasAnyKeys(result, [ - "txid", - "version", - "locktime", - "vin", - "vout", - "blockhash", - "blockheight", - "confirmations", - "time", - "blocktime", - "valueOut", - "size", - "valueIn", - "fees", - "tokenInfo", - "tokenIsValid" + 'txid', + 'version', + 'locktime', + 'vin', + 'vout', + 'blockhash', + 'blockheight', + 'confirmations', + 'time', + 'blocktime', + 'valueOut', + 'size', + 'valueIn', + 'fees', + 'tokenInfo', + 'tokenIsValid' ]) }) }) - describe("#hydrateUtxos", () => { - it("should throw an error if input is not an array", async () => { + describe('#hydrateUtxos', () => { + it('should throw an error if input is not an array', async () => { try { const utxos = 1234 await uut.Utils.hydrateUtxos(utxos) - assert.equal(true, false, "Uh oh. Code path should not end here.") + assert.equal(true, false, 'Uh oh. Code path should not end here.') } catch (err) { // console.log(`Error: `, err) - assert.include(err.message, `Input must be an array.`) + assert.include(err.message, 'Input must be an array.') } }) }) - describe("#validateTxid2", () => { - it("should throw an error if the input is an array", async () => { + describe('#validateTxid2', () => { + it('should throw an error if the input is an array', async () => { try { const txid = [ - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a" + 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a' ] await uut.Utils.validateTxid2(txid) - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { // console.log("err: ", err) - assert.include(err.message, "txid must be 64 character string") + assert.include(err.message, 'txid must be 64 character string') } }) - it("should throw an error for a malformed txid", async () => { + it('should throw an error for a malformed txid', async () => { try { const txid = - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783" + 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783' await uut.Utils.validateTxid2(txid) - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { // console.log("err: ", err) - assert.include(err.message, "txid must be 64 character string") + assert.include(err.message, 'txid must be 64 character string') } }) - it("should invalidate a known invalid TXID", async () => { + it('should invalidate a known invalid TXID', async () => { const txid = - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a" + 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a' // Mock live network calls. - sandbox.stub(uut.Utils.axios, "get").resolves({ + sandbox.stub(uut.Utils.axios, 'get').resolves({ data: { txid: txid, isValid: false, - msg: "" + msg: '' } }) const result = await uut.Utils.validateTxid2(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "txid") + assert.property(result, 'txid') assert.equal(result.txid, txid) - assert.property(result, "isValid") + assert.property(result, 'isValid') assert.equal(result.isValid, false) }) - it("should validate a known valid TXID", async () => { + it('should validate a known valid TXID', async () => { const txid = - "3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488" + '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488' // Mock live network calls. - sandbox.stub(uut.Utils.axios, "get").resolves({ + sandbox.stub(uut.Utils.axios, 'get').resolves({ data: { txid: txid, isValid: true, - msg: "" + msg: '' } }) const result = await uut.Utils.validateTxid2(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`) - assert.property(result, "txid") + assert.property(result, 'txid') assert.equal(result.txid, txid) - assert.property(result, "isValid") + assert.property(result, 'isValid') assert.equal(result.isValid, true) }) // slp-validate can take a long time. bch-api cuts it off if it fails to // return is less than 10 seconds. This test case handle this situation. - it("should handle timeout errors", async () => { + it('should handle timeout errors', async () => { try { const txid = - "eacb1085dfa296fef6d4ae2c0f4529a1bef096dd2325bdcc6dcb5241b3bdb579" + 'eacb1085dfa296fef6d4ae2c0f4529a1bef096dd2325bdcc6dcb5241b3bdb579' // Mock live network calls. - sandbox.stub(uut.Utils.axios, "get").rejects({ + sandbox.stub(uut.Utils.axios, 'get').rejects({ error: - "Network error: Could not communicate with full node or other external service." + 'Network error: Could not communicate with full node or other external service.' }) await uut.Utils.validateTxid2(txid) - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { // console.log("err: ", err) - assert.include(err.message, "slp-validate timed out") + assert.include(err.message, 'slp-validate timed out') } }) }) - describe("#validateTxid", () => { - it("should invalidate a known invalid TXID", async () => { + describe('#validateTxid', () => { + it('should invalidate a known invalid TXID', async () => { const txid = - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a" + 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a' // Mock live network calls. - sandbox.stub(uut.Utils.axios, "post").resolves({ + sandbox.stub(uut.Utils.axios, 'post').resolves({ data: mockData.mockValidateTxid3Invalid }) @@ -2029,10 +2029,10 @@ describe("#SLP Utils", () => { assert.isArray(result) - assert.property(result[0], "txid") + assert.property(result[0], 'txid') assert.equal(result[0].txid, txid) - assert.property(result[0], "valid") + assert.property(result[0], 'valid') assert.equal(result[0].valid, null) }) /* @@ -2054,43 +2054,43 @@ describe("#SLP Utils", () => { */ }) - describe("#getWhitelist", () => { - it("should return the list", async () => { + describe('#getWhitelist', () => { + it('should return the list', async () => { sandbox - .stub(uut.Utils.axios, "get") + .stub(uut.Utils.axios, 'get') .resolves({ data: mockData.mockWhitelist }) const result = await uut.Utils.getWhitelist() assert.isArray(result) - assert.property(result[0], "name") - assert.property(result[1], "tokenId") + assert.property(result[0], 'name') + assert.property(result[1], 'tokenId') }) - it("catches and throws an error", async () => { + it('catches and throws an error', async () => { try { - sandbox.stub(uut.Utils.axios, "get").rejects({ + sandbox.stub(uut.Utils.axios, 'get').rejects({ error: - "Network error: Could not communicate with full node or other external service." + 'Network error: Could not communicate with full node or other external service.' }) await uut.Utils.getWhitelist() - assert.fail("Unexpected result") + assert.fail('Unexpected result') } catch (err) { - console.log("err: ", err) - assert.include(err.error, "Network error") + console.log('err: ', err) + assert.include(err.error, 'Network error') } }) }) - describe("#validateTxid3", () => { - it("should invalidate a known invalid TXID", async () => { + describe('#validateTxid3', () => { + it('should invalidate a known invalid TXID', async () => { const txid = - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a" + 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a' // Mock live network calls. - sandbox.stub(uut.Utils.axios, "post").resolves({ + sandbox.stub(uut.Utils.axios, 'post').resolves({ data: mockData.mockValidateTxid3Invalid }) @@ -2099,81 +2099,81 @@ describe("#SLP Utils", () => { assert.isArray(result) - assert.property(result[0], "txid") + assert.property(result[0], 'txid') assert.equal(result[0].txid, txid) - assert.property(result[0], "valid") + assert.property(result[0], 'valid') assert.equal(result[0].valid, null) }) - it("should handle an array with a single element", async () => { + it('should handle an array with a single element', async () => { sandbox - .stub(uut.Utils.axios, "post") + .stub(uut.Utils.axios, 'post') .resolves({ data: mockData.mockValidateTxid3Valid }) const txid = [ - "daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd" + 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd' ] const result = await uut.Utils.validateTxid3(txid) assert.isArray(result) - assert.property(result[0], "txid") + assert.property(result[0], 'txid') assert.equal(result[0].txid, txid) - assert.property(result[0], "valid") + assert.property(result[0], 'valid') assert.equal(result[0].valid, true) }) - it("should handle an single string input", async () => { + it('should handle an single string input', async () => { sandbox - .stub(uut.Utils.axios, "post") + .stub(uut.Utils.axios, 'post') .resolves({ data: mockData.mockValidateTxid3Valid }) const txid = - "daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd" + 'daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd' const result = await uut.Utils.validateTxid3(txid) assert.isArray(result) - assert.property(result[0], "txid") + assert.property(result[0], 'txid') assert.equal(result[0].txid, txid) - assert.property(result[0], "valid") + assert.property(result[0], 'valid') assert.equal(result[0].valid, true) }) - it("catches and throws an error", async () => { + it('catches and throws an error', async () => { try { - sandbox.stub(uut.Utils.axios, "post").rejects({ + sandbox.stub(uut.Utils.axios, 'post').rejects({ error: - "Network error: Could not communicate with full node or other external service." + 'Network error: Could not communicate with full node or other external service.' }) await uut.Utils.validateTxid3() - assert.equal(true, false, "Unexpected result") + assert.equal(true, false, 'Unexpected result') } catch (err) { // console.log("err: ", err) - assert.include(err.error, "Network error") + assert.include(err.error, 'Network error') } }) }) - describe("#getStatus", () => { - it("should return the current block height of the SLPDB indexer", async () => { + describe('#getStatus', () => { + it('should return the current block height of the SLPDB indexer', async () => { sandbox - .stub(uut.Utils.axios, "get") + .stub(uut.Utils.axios, 'get') .resolves({ data: mockData.slpdbStatus }) const result = await uut.Utils.getStatus() // console.log(`result: `, result) - assert.property(result, "bchBlockHeight") - assert.property(result, "slpProcessedBlockHeight") + assert.property(result, 'bchBlockHeight') + assert.property(result, 'slpProcessedBlockHeight') }) }) }) diff --git a/test/unit/transaction-builder.js b/test/unit/transaction-builder.js index aa5f29f..9b1899c 100644 --- a/test/unit/transaction-builder.js +++ b/test/unit/transaction-builder.js @@ -1,14 +1,14 @@ -const fixtures = require("./fixtures/transaction-builder.json") -const assert = require("assert") -const BCHJS = require("../../src/bch-js") +const fixtures = require('./fixtures/transaction-builder.json') +const assert = require('assert') +const BCHJS = require('../../src/bch-js') const bchjs = new BCHJS() -const Buffer = require("safe-buffer").Buffer +const Buffer = require('safe-buffer').Buffer -describe("#TransactionBuilder", () => { - describe("#hashTypes", () => { - const transactionBuilder = new bchjs.TransactionBuilder("mainnet") +describe('#TransactionBuilder', () => { + describe('#hashTypes', () => { + const transactionBuilder = new bchjs.TransactionBuilder('mainnet') fixtures.hashTypes.forEach(fixture => { - it(`should match hash type`, () => { + it('should match hash type', () => { assert.equal( fixture[Object.keys(fixture)[0]], transactionBuilder.hashTypes[Object.keys(fixture)[0]] @@ -17,11 +17,11 @@ describe("#TransactionBuilder", () => { }) }) - describe("#P2PK", () => { - describe("#toOne", () => { - describe("#Mainnet", () => { + describe('#P2PK', () => { + describe('#toOne', () => { + describe('#Mainnet', () => { fixtures.scripts.p2pk.toOne.mainnet.forEach(fixture => { - it(`should create 1-to-1 P2PK transaction on mainnet`, () => { + it('should create 1-to-1 P2PK transaction on mainnet', () => { const node = bchjs.HDNode.fromXPriv(fixture.xpriv) const transactionBuilder = new bchjs.TransactionBuilder() const originalAmount = fixture.amount @@ -56,11 +56,11 @@ describe("#TransactionBuilder", () => { }) }) - describe("#Testnet", () => { + describe('#Testnet', () => { fixtures.scripts.p2pk.toOne.testnet.forEach(fixture => { - it(`should create 1-to-1 P2PK transaction on testnet`, () => { + it('should create 1-to-1 P2PK transaction on testnet', () => { const node = bchjs.HDNode.fromXPriv(fixture.xpriv) - const transactionBuilder = new bchjs.TransactionBuilder("testnet") + const transactionBuilder = new bchjs.TransactionBuilder('testnet') const originalAmount = fixture.amount const txid = fixture.txHash const pubKey = bchjs.HDNode.toPublicKey(node) @@ -94,10 +94,10 @@ describe("#TransactionBuilder", () => { }) }) - describe("#toMany", () => { - describe("#Mainnet", () => { + describe('#toMany', () => { + describe('#Mainnet', () => { fixtures.scripts.p2pk.toMany.mainnet.forEach(fixture => { - it(`should create 1-to-many P2PK transaction on mainnet`, () => { + it('should create 1-to-many P2PK transaction on mainnet', () => { const node1 = bchjs.HDNode.fromXPriv(fixture.xprivs[0]) const node2 = bchjs.HDNode.fromXPriv(fixture.xprivs[1]) const node3 = bchjs.HDNode.fromXPriv(fixture.xprivs[2]) @@ -139,13 +139,13 @@ describe("#TransactionBuilder", () => { }) }) - describe("#Testnet", () => { + describe('#Testnet', () => { fixtures.scripts.p2pk.toMany.testnet.forEach(fixture => { - it(`should create 1-to-many P2PK transaction on testnet`, () => { + it('should create 1-to-many P2PK transaction on testnet', () => { const node1 = bchjs.HDNode.fromXPriv(fixture.xprivs[0]) const node2 = bchjs.HDNode.fromXPriv(fixture.xprivs[1]) const node3 = bchjs.HDNode.fromXPriv(fixture.xprivs[2]) - const transactionBuilder = new bchjs.TransactionBuilder("testnet") + const transactionBuilder = new bchjs.TransactionBuilder('testnet') const originalAmount = fixture.amount const txid = fixture.txHash const pubKey1 = bchjs.HDNode.toPublicKey(node1) @@ -184,10 +184,10 @@ describe("#TransactionBuilder", () => { }) }) - describe("#manyToMany", () => { - describe("#Mainnet", () => { + describe('#manyToMany', () => { + describe('#Mainnet', () => { fixtures.scripts.p2pk.manyToMany.mainnet.forEach(fixture => { - it(`should create many-to-many P2PK transaction on mainnet`, () => { + it('should create many-to-many P2PK transaction on mainnet', () => { const node1 = bchjs.HDNode.fromXPriv(fixture.xprivs[0]) const node2 = bchjs.HDNode.fromXPriv(fixture.xprivs[1]) const node3 = bchjs.HDNode.fromXPriv(fixture.xprivs[2]) @@ -246,14 +246,14 @@ describe("#TransactionBuilder", () => { }) }) - describe("#Testnet", () => { + describe('#Testnet', () => { fixtures.scripts.p2pk.manyToMany.testnet.forEach(fixture => { - it(`should create many-to-many P2PK transaction on testnet`, () => { + it('should create many-to-many P2PK transaction on testnet', () => { const node1 = bchjs.HDNode.fromXPriv(fixture.xprivs[0]) const node2 = bchjs.HDNode.fromXPriv(fixture.xprivs[1]) const node3 = bchjs.HDNode.fromXPriv(fixture.xprivs[2]) const node4 = bchjs.HDNode.fromXPriv(fixture.xprivs[3]) - const transactionBuilder = new bchjs.TransactionBuilder("testnet") + const transactionBuilder = new bchjs.TransactionBuilder('testnet') const originalAmount = fixture.amount const txid = fixture.txHash const pubKey1 = bchjs.HDNode.toPublicKey(node1) @@ -308,10 +308,10 @@ describe("#TransactionBuilder", () => { }) }) - describe("#fromMany", () => { - describe("#Mainnet", () => { + describe('#fromMany', () => { + describe('#Mainnet', () => { fixtures.scripts.p2pk.fromMany.mainnet.forEach(fixture => { - it(`should create many-to-1 P2PK transaction on mainnet`, () => { + it('should create many-to-1 P2PK transaction on mainnet', () => { const node1 = bchjs.HDNode.fromXPriv(fixture.xprivs[0]) const node2 = bchjs.HDNode.fromXPriv(fixture.xprivs[1]) const node3 = bchjs.HDNode.fromXPriv(fixture.xprivs[2]) @@ -366,13 +366,13 @@ describe("#TransactionBuilder", () => { }) }) - describe("#Testnet", () => { + describe('#Testnet', () => { fixtures.scripts.p2pk.fromMany.testnet.forEach(fixture => { - it(`should create many-to-1 P2PK transaction on testnet`, () => { + it('should create many-to-1 P2PK transaction on testnet', () => { const node1 = bchjs.HDNode.fromXPriv(fixture.xprivs[0]) const node2 = bchjs.HDNode.fromXPriv(fixture.xprivs[1]) const node3 = bchjs.HDNode.fromXPriv(fixture.xprivs[2]) - const transactionBuilder = new bchjs.TransactionBuilder("testnet") + const transactionBuilder = new bchjs.TransactionBuilder('testnet') const originalAmount = fixture.amount const txid = fixture.txHash const pubKey1 = bchjs.HDNode.toPublicKey(node1) @@ -425,11 +425,11 @@ describe("#TransactionBuilder", () => { }) }) - describe("#P2PKH", () => { - describe("#toOne", () => { - describe("#Mainnet", () => { + describe('#P2PKH', () => { + describe('#toOne', () => { + describe('#Mainnet', () => { fixtures.scripts.p2pkh.toOne.mainnet.forEach(fixture => { - it(`should create 1-to-1 P2PKH transaction on mainnet`, () => { + it('should create 1-to-1 P2PKH transaction on mainnet', () => { const hdnode = bchjs.HDNode.fromXPriv(fixture.xpriv) const transactionBuilder = new bchjs.TransactionBuilder() const keyPair = bchjs.HDNode.toKeyPair(hdnode) @@ -464,11 +464,11 @@ describe("#TransactionBuilder", () => { }) }) - describe("#Testnet", () => { + describe('#Testnet', () => { fixtures.scripts.p2pkh.toOne.testnet.forEach(fixture => { - it(`should create 1-to-1 P2PKH transaction on testnet`, () => { - const hdnode = bchjs.HDNode.fromXPriv(fixture.xpriv, "testnet") - const transactionBuilder = new bchjs.TransactionBuilder("testnet") + it('should create 1-to-1 P2PKH transaction on testnet', () => { + const hdnode = bchjs.HDNode.fromXPriv(fixture.xpriv, 'testnet') + const transactionBuilder = new bchjs.TransactionBuilder('testnet') const keyPair = bchjs.HDNode.toKeyPair(hdnode) const txHash = fixture.txHash // original amount of satoshis in vin @@ -540,10 +540,10 @@ describe("#TransactionBuilder", () => { */ }) - describe("#toMany", () => { - describe("#Mainnet", () => { + describe('#toMany', () => { + describe('#Mainnet', () => { fixtures.scripts.p2pkh.toMany.mainnet.forEach(fixture => { - it(`should create 1-to-2 P2PKH transaction on mainnet`, () => { + it('should create 1-to-2 P2PKH transaction on mainnet', () => { const hdnode = bchjs.HDNode.fromXPriv(fixture.xpriv) const transactionBuilder = new bchjs.TransactionBuilder() const keyPair = bchjs.HDNode.toKeyPair(hdnode) @@ -584,12 +584,12 @@ describe("#TransactionBuilder", () => { }) }) - describe("#Testnet", () => { + describe('#Testnet', () => { fixtures.scripts.p2pkh.toMany.testnet.forEach(fixture => { // TODO pass in tesnet network config - it(`should create 1-to-2 P2PKH transaction on testnet`, () => { + it('should create 1-to-2 P2PKH transaction on testnet', () => { const hdnode = bchjs.HDNode.fromXPriv(fixture.xpriv) - const transactionBuilder = new bchjs.TransactionBuilder("testnet") + const transactionBuilder = new bchjs.TransactionBuilder('testnet') const keyPair = bchjs.HDNode.toKeyPair(hdnode) const txHash = fixture.txHash // original amount of satoshis in vin @@ -670,13 +670,13 @@ describe("#TransactionBuilder", () => { assert.equal(hex, fixture.hex) }) }) - })*/ + }) */ }) - describe("#manyToMany", () => { - describe("#Mainnet", () => { + describe('#manyToMany', () => { + describe('#Mainnet', () => { fixtures.scripts.p2pkh.manyToMany.mainnet.forEach(fixture => { - it(`should create 2-to-2 P2PKH transaction on mainnet`, () => { + it('should create 2-to-2 P2PKH transaction on mainnet', () => { const node1 = bchjs.HDNode.fromXPriv(fixture.xprivs[0]) const node2 = bchjs.HDNode.fromXPriv(fixture.xprivs[1]) const transactionBuilder = new bchjs.TransactionBuilder() @@ -721,12 +721,12 @@ describe("#TransactionBuilder", () => { }) }) - describe("#Testnet", () => { + describe('#Testnet', () => { fixtures.scripts.p2pkh.manyToMany.testnet.forEach(fixture => { - it(`should create 2-to-2 P2PKH transaction on testnet`, () => { + it('should create 2-to-2 P2PKH transaction on testnet', () => { const node1 = bchjs.HDNode.fromXPriv(fixture.xprivs[0]) const node2 = bchjs.HDNode.fromXPriv(fixture.xprivs[1]) - const transactionBuilder = new bchjs.TransactionBuilder("testnet") + const transactionBuilder = new bchjs.TransactionBuilder('testnet') const txHash = fixture.txHash const originalAmount = fixture.amounts[0] + fixture.amounts[1] transactionBuilder.addInput(txHash, 0) @@ -817,10 +817,10 @@ describe("#TransactionBuilder", () => { */ }) - describe("#fromMany", () => { - describe("#Mainnet", () => { + describe('#fromMany', () => { + describe('#Mainnet', () => { fixtures.scripts.p2pkh.fromMany.mainnet.forEach(fixture => { - it(`should create 2-to-1 P2PKH transaction on mainnet`, () => { + it('should create 2-to-1 P2PKH transaction on mainnet', () => { const node1 = bchjs.HDNode.fromXPriv(fixture.xprivs[0]) const node2 = bchjs.HDNode.fromXPriv(fixture.xprivs[1]) const transactionBuilder = new bchjs.TransactionBuilder() @@ -858,12 +858,12 @@ describe("#TransactionBuilder", () => { }) }) - describe("#Testnet", () => { + describe('#Testnet', () => { fixtures.scripts.p2pkh.fromMany.testnet.forEach(fixture => { - it(`should create 2-to-1 P2PKH transaction on testnet`, () => { + it('should create 2-to-1 P2PKH transaction on testnet', () => { const node1 = bchjs.HDNode.fromXPriv(fixture.xprivs[0]) const node2 = bchjs.HDNode.fromXPriv(fixture.xprivs[1]) - const transactionBuilder = new bchjs.TransactionBuilder("testnet") + const transactionBuilder = new bchjs.TransactionBuilder('testnet') const txHash = fixture.txHash const originalAmount = fixture.amounts[0] + fixture.amounts[1] transactionBuilder.addInput(txHash, 0) @@ -941,10 +941,10 @@ describe("#TransactionBuilder", () => { }) }) - describe("#op_return", () => { - describe("#Mainnet", () => { + describe('#op_return', () => { + describe('#Mainnet', () => { fixtures.nulldata.mainnet.forEach(fixture => { - it(`should create transaction w/ OP_RETURN output on mainnet`, () => { + it('should create transaction w/ OP_RETURN output on mainnet', () => { const node = bchjs.HDNode.fromXPriv(fixture.xpriv) const transactionBuilder = new bchjs.TransactionBuilder() const txHash = fixture.txHash @@ -958,7 +958,7 @@ describe("#TransactionBuilder", () => { transactionBuilder.addOutput(fixture.output, sendAmount) const data = fixture.data const buf = bchjs.Script.nullData.output.encode( - Buffer.from(data, "ascii") + Buffer.from(data, 'ascii') ) transactionBuilder.addOutput(buf, 0) const keyPair = bchjs.HDNode.toKeyPair(node) @@ -977,11 +977,11 @@ describe("#TransactionBuilder", () => { }) }) - describe("#Testnet", () => { + describe('#Testnet', () => { fixtures.nulldata.testnet.forEach(fixture => { - it(`should create transaction w/ OP_RETURN output on testnet`, () => { + it('should create transaction w/ OP_RETURN output on testnet', () => { const node = bchjs.HDNode.fromXPriv(fixture.xpriv) - const transactionBuilder = new bchjs.TransactionBuilder("testnet") + const transactionBuilder = new bchjs.TransactionBuilder('testnet') const txHash = fixture.txHash const originalAmount = fixture.amount transactionBuilder.addInput(txHash, 0) @@ -993,7 +993,7 @@ describe("#TransactionBuilder", () => { transactionBuilder.addOutput(fixture.output, sendAmount) const data = fixture.data const buf = bchjs.Script.nullData.output.encode( - Buffer.from(data, "ascii") + Buffer.from(data, 'ascii') ) transactionBuilder.addOutput(buf, 0) const keyPair = bchjs.HDNode.toKeyPair(node) @@ -1049,11 +1049,11 @@ describe("#TransactionBuilder", () => { */ }) - describe("#P2MS", () => { - describe("#toOne", () => { - describe("#Mainnet", () => { + describe('#P2MS', () => { + describe('#toOne', () => { + describe('#Mainnet', () => { fixtures.scripts.p2ms.toOne.mainnet.forEach(fixture => { - it(`should create 1-to-1 1-of-2 P2MS transaction on mainnet`, () => { + it('should create 1-to-1 1-of-2 P2MS transaction on mainnet', () => { const node1 = bchjs.HDNode.fromXPriv(fixture.xprivs[0]) const node2 = bchjs.HDNode.fromXPriv(fixture.xprivs[1]) const node3 = bchjs.HDNode.fromXPriv(fixture.xprivs[2]) @@ -1130,10 +1130,10 @@ describe("#TransactionBuilder", () => { // }); }) - describe("#toMany", () => { - describe("#Mainnet", () => { + describe('#toMany', () => { + describe('#Mainnet', () => { fixtures.scripts.p2ms.toMany.mainnet.forEach(fixture => { - it(`should create 1-to-2 P2MS transaction on mainnet`, () => { + it('should create 1-to-2 P2MS transaction on mainnet', () => { const node1 = bchjs.HDNode.fromXPriv(fixture.xprivs[0]) const node2 = bchjs.HDNode.fromXPriv(fixture.xprivs[1]) const node3 = bchjs.HDNode.fromXPriv(fixture.xprivs[2]) @@ -1220,10 +1220,10 @@ describe("#TransactionBuilder", () => { // }); }) - describe("#manyToMany", () => { - describe("#Mainnet", () => { + describe('#manyToMany', () => { + describe('#Mainnet', () => { fixtures.scripts.p2ms.manyToMany.mainnet.forEach(fixture => { - it(`should create 2-to-2 P2MS transaction on mainnet`, () => { + it('should create 2-to-2 P2MS transaction on mainnet', () => { const node1 = bchjs.HDNode.fromXPriv(fixture.xprivs[0]) const node2 = bchjs.HDNode.fromXPriv(fixture.xprivs[1]) const node3 = bchjs.HDNode.fromXPriv(fixture.xprivs[2]) @@ -1329,10 +1329,10 @@ describe("#TransactionBuilder", () => { // }); }) - describe("#fromMany", () => { - describe("#Mainnet", () => { + describe('#fromMany', () => { + describe('#Mainnet', () => { fixtures.scripts.p2ms.fromMany.mainnet.forEach(fixture => { - it(`should create 2-to-1 P2MS transaction on mainnet`, () => { + it('should create 2-to-1 P2MS transaction on mainnet', () => { const node1 = bchjs.HDNode.fromXPriv(fixture.xprivs[0]) const node2 = bchjs.HDNode.fromXPriv(fixture.xprivs[1]) const node3 = bchjs.HDNode.fromXPriv(fixture.xprivs[2]) @@ -1429,11 +1429,11 @@ describe("#TransactionBuilder", () => { }) }) - describe("#P2SH", () => { - describe("#toOne", () => { - describe("#Mainnet", () => { + describe('#P2SH', () => { + describe('#toOne', () => { + describe('#Mainnet', () => { fixtures.scripts.p2sh.toOne.mainnet.forEach(fixture => { - it(`should create 1-to-1 P2SH transaction on mainnet`, () => { + it('should create 1-to-1 P2SH transaction on mainnet', () => { const node1 = bchjs.HDNode.fromXPriv(fixture.xprivs[0]) const node2 = bchjs.HDNode.fromXPriv(fixture.xprivs[1]) const transactionBuilder = new bchjs.TransactionBuilder() @@ -1516,10 +1516,10 @@ describe("#TransactionBuilder", () => { // }); }) - describe("#toMany", () => { - describe("#Mainnet", () => { + describe('#toMany', () => { + describe('#Mainnet', () => { fixtures.scripts.p2sh.toMany.mainnet.forEach(fixture => { - it(`should create 1-to-2 P2SH transaction on mainnet`, () => { + it('should create 1-to-2 P2SH transaction on mainnet', () => { const node1 = bchjs.HDNode.fromXPriv(fixture.xprivs[0]) const node2 = bchjs.HDNode.fromXPriv(fixture.xprivs[1]) const node3 = bchjs.HDNode.fromXPriv(fixture.xprivs[2]) @@ -1614,10 +1614,10 @@ describe("#TransactionBuilder", () => { // }); }) - describe("#manyToMany", () => { - describe("#Mainnet", () => { + describe('#manyToMany', () => { + describe('#Mainnet', () => { fixtures.scripts.p2sh.manyToMany.mainnet.forEach(fixture => { - it(`should create 2-to-2 P2SH transaction on mainnet`, () => { + it('should create 2-to-2 P2SH transaction on mainnet', () => { const node1 = bchjs.HDNode.fromXPriv(fixture.xprivs[0]) const node2 = bchjs.HDNode.fromXPriv(fixture.xprivs[1]) const node3 = bchjs.HDNode.fromXPriv(fixture.xprivs[2]) @@ -1734,10 +1734,10 @@ describe("#TransactionBuilder", () => { // }); }) - describe("#fromMany", () => { - describe("#Mainnet", () => { + describe('#fromMany', () => { + describe('#Mainnet', () => { fixtures.scripts.p2sh.fromMany.mainnet.forEach(fixture => { - it(`should create 2-to-1 P2SH transaction on mainnet`, () => { + it('should create 2-to-1 P2SH transaction on mainnet', () => { const node1 = bchjs.HDNode.fromXPriv(fixture.xprivs[0]) const node2 = bchjs.HDNode.fromXPriv(fixture.xprivs[1]) const node3 = bchjs.HDNode.fromXPriv(fixture.xprivs[2]) @@ -1842,10 +1842,10 @@ describe("#TransactionBuilder", () => { }) }) - describe("#op_return", () => { - describe("#Mainnet", () => { + describe('#op_return', () => { + describe('#Mainnet', () => { fixtures.nulldata.mainnet.forEach(fixture => { - it(`should create transaction w/ OP_RETURN output on mainnet`, () => { + it('should create transaction w/ OP_RETURN output on mainnet', () => { const node = bchjs.HDNode.fromXPriv(fixture.xpriv) const transactionBuilder = new bchjs.TransactionBuilder() const txHash = fixture.txHash @@ -1859,7 +1859,7 @@ describe("#TransactionBuilder", () => { transactionBuilder.addOutput(fixture.output, sendAmount) const data = fixture.data const buf = bchjs.Script.nullData.output.encode( - Buffer.from(data, "ascii") + Buffer.from(data, 'ascii') ) transactionBuilder.addOutput(buf, 0) const keyPair = bchjs.HDNode.toKeyPair(node) @@ -1878,11 +1878,11 @@ describe("#TransactionBuilder", () => { }) }) - describe("#Testnet", () => { + describe('#Testnet', () => { fixtures.nulldata.testnet.forEach(fixture => { - it(`should create transaction w/ OP_RETURN output on testnet`, () => { + it('should create transaction w/ OP_RETURN output on testnet', () => { const node = bchjs.HDNode.fromXPriv(fixture.xpriv) - const transactionBuilder = new bchjs.TransactionBuilder("testnet") + const transactionBuilder = new bchjs.TransactionBuilder('testnet') const txHash = fixture.txHash const originalAmount = fixture.amount transactionBuilder.addInput(txHash, 0) @@ -1894,7 +1894,7 @@ describe("#TransactionBuilder", () => { transactionBuilder.addOutput(fixture.output, sendAmount) const data = fixture.data const buf = bchjs.Script.nullData.output.encode( - Buffer.from(data, "ascii") + Buffer.from(data, 'ascii') ) transactionBuilder.addOutput(buf, 0) const keyPair = bchjs.HDNode.toKeyPair(node) @@ -1950,37 +1950,37 @@ describe("#TransactionBuilder", () => { */ }) - describe("#bip66", () => { + describe('#bip66', () => { fixtures.bip66.forEach(fixture => { it(`should bip66 encode as ${fixture.DER}`, () => { const transactionBuilder = new bchjs.TransactionBuilder() - const r = Buffer.from(fixture.r, "hex") - const s = Buffer.from(fixture.s, "hex") + const r = Buffer.from(fixture.r, 'hex') + const s = Buffer.from(fixture.s, 'hex') const DER = transactionBuilder.bip66.encode(r, s) - assert.equal(DER.toString("hex"), fixture.DER) + assert.equal(DER.toString('hex'), fixture.DER) }) }) fixtures.bip66.forEach(fixture => { it(`should bip66 decode ${fixture.DER}`, () => { const transactionBuilder = new bchjs.TransactionBuilder() - const buffer = Buffer.from(fixture.DER, "hex") + const buffer = Buffer.from(fixture.DER, 'hex') const signature = transactionBuilder.bip66.decode(buffer) - assert.equal(signature.r.toString("hex"), fixture.r) - assert.equal(signature.s.toString("hex"), fixture.s) + assert.equal(signature.r.toString('hex'), fixture.r) + assert.equal(signature.s.toString('hex'), fixture.s) }) }) fixtures.bip66.forEach(fixture => { it(`should bip66 check ${fixture.DER}`, () => { const transactionBuilder = new bchjs.TransactionBuilder() - const buffer = Buffer.from(fixture.DER, "hex") + const buffer = Buffer.from(fixture.DER, 'hex') assert.equal(transactionBuilder.bip66.check(buffer), true) }) }) }) - describe("#bip68", () => { + describe('#bip68', () => { fixtures.bip68.encode.forEach(fixture => { it(`should bip68 encode as ${fixture.result}`, () => { const transactionBuilder = new bchjs.TransactionBuilder() @@ -2002,10 +2002,10 @@ describe("#TransactionBuilder", () => { }) }) - describe("#LockTime", () => { - describe("#Mainnet", () => { + describe('#LockTime', () => { + describe('#Mainnet', () => { fixtures.locktime.mainnet.forEach(fixture => { - it(`should create transaction with nLockTime on mainnet`, () => { + it('should create transaction with nLockTime on mainnet', () => { const node = bchjs.HDNode.fromXPriv(fixture.xpriv) const transactionBuilder = new bchjs.TransactionBuilder() diff --git a/test/unit/util.js b/test/unit/util.js index 7a17955..0034874 100644 --- a/test/unit/util.js +++ b/test/unit/util.js @@ -1,30 +1,30 @@ -const assert = require("assert") -const axios = require("axios") -const BCHJS = require("../../src/bch-js") +const assert = require('assert') +const axios = require('axios') +const BCHJS = require('../../src/bch-js') const bchjs = new BCHJS() -const sinon = require("sinon") +const sinon = require('sinon') -describe("#Util", () => { - describe("#validateAddress", () => { +describe('#Util', () => { + describe('#validateAddress', () => { let sandbox beforeEach(() => (sandbox = sinon.createSandbox())) afterEach(() => sandbox.restore()) - it("should validate address", done => { + it('should validate address', done => { const data = { isvalid: true, - address: "bitcoincash:qpz7qtkuyhrsz4qmnnrvf8gz9zd0u9v7eqsewyk4w5", - scriptPubKey: "76a91445e02edc25c701541b9cc6c49d02289afe159ec888ac", + address: 'bitcoincash:qpz7qtkuyhrsz4qmnnrvf8gz9zd0u9v7eqsewyk4w5', + scriptPubKey: '76a91445e02edc25c701541b9cc6c49d02289afe159ec888ac', ismine: false, iswatchonly: false, isscript: false } const resolved = new Promise(r => r({ data: data })) - sandbox.stub(axios, "get").returns(resolved) + sandbox.stub(axios, 'get').returns(resolved) bchjs.Util.validateAddress( - "bitcoincash:qpz7qtkuyhrsz4qmnnrvf8gz9zd0u9v7eqsewyk4w5" + 'bitcoincash:qpz7qtkuyhrsz4qmnnrvf8gz9zd0u9v7eqsewyk4w5' ) .then(result => { assert.deepEqual(data, result)