mirror of
https://github.com/Permissionless-Software-Foundation/bch-js.git
synced 2026-09-22 00:52:01 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cee348cb3e | ||
|
|
75e56e7aa7 | ||
|
|
d6ae6ffb6b | ||
|
|
12f6547167 | ||
|
|
d1847d2eca | ||
|
|
1f01e6ae47 | ||
|
|
1375601a81 | ||
|
|
e97a8e7cf5 | ||
|
|
3df211301c | ||
|
|
a81dec068c | ||
|
|
4af6716631 | ||
|
|
98f7cb8f3a | ||
|
|
348a67a79b | ||
|
|
a9c128f96b | ||
|
|
bdf1c50c9d | ||
|
|
ccc545b1be | ||
|
|
c6301055fa | ||
|
|
13d9f89a82 | ||
|
|
f5de593f89 | ||
|
|
3b0ec95fba | ||
|
|
0a328090ea | ||
|
|
315cb4f254 | ||
|
|
28f08f02ac | ||
|
|
5949e0f6f8 | ||
|
|
617bb16ddb | ||
|
|
83f14f5522 | ||
|
|
b8e22e1c99 | ||
|
|
72d560e407 | ||
|
|
248b2fa2a6 | ||
|
|
563cb297fe | ||
|
|
4c020240e1 | ||
|
|
e070409a95 | ||
|
|
fbbd855145 | ||
|
|
731987b35b | ||
|
|
1e8e7b79f2 |
Generated
+67
-51
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@psf/bch-js",
|
||||
"version": "3.4.0",
|
||||
"version": "4.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@@ -4445,6 +4445,12 @@
|
||||
"integrity": "sha1-+CbJtOKoUR2E46yinbBeGk87cqk=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.clonedeep": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
|
||||
"integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.escaperegexp": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz",
|
||||
@@ -5253,9 +5259,9 @@
|
||||
}
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "2.6.0",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
|
||||
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==",
|
||||
"version": "2.6.1",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
|
||||
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==",
|
||||
"dev": true
|
||||
},
|
||||
"node-mocks-http": {
|
||||
@@ -5301,9 +5307,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"npm": {
|
||||
"version": "6.14.7",
|
||||
"resolved": "https://registry.npmjs.org/npm/-/npm-6.14.7.tgz",
|
||||
"integrity": "sha512-swhsdpNpyXg4GbM6LpOQ6qaloQuIKizZ+Zh6JPXJQc59ka49100Js0WvZx594iaKSoFgkFq2s8uXFHS3/Xy2WQ==",
|
||||
"version": "6.14.9",
|
||||
"resolved": "https://registry.npmjs.org/npm/-/npm-6.14.9.tgz",
|
||||
"integrity": "sha512-yHi1+i9LyAZF1gAmgyYtVk+HdABlLy94PMIDoK1TRKWvmFQAt5z3bodqVwKvzY0s6dLqQPVsRLiwhJfNtiHeCg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"JSONStream": "^1.3.5",
|
||||
@@ -5370,7 +5376,7 @@
|
||||
"lodash.uniq": "~4.5.0",
|
||||
"lodash.without": "~4.4.0",
|
||||
"lru-cache": "^5.1.1",
|
||||
"meant": "~1.0.1",
|
||||
"meant": "^1.0.2",
|
||||
"mississippi": "^3.0.0",
|
||||
"mkdirp": "^0.5.5",
|
||||
"move-concurrently": "^1.0.1",
|
||||
@@ -5385,8 +5391,8 @@
|
||||
"npm-packlist": "^1.4.8",
|
||||
"npm-pick-manifest": "^3.0.2",
|
||||
"npm-profile": "^4.0.4",
|
||||
"npm-registry-fetch": "^4.0.5",
|
||||
"npm-user-validate": "~1.0.0",
|
||||
"npm-registry-fetch": "^4.0.7",
|
||||
"npm-user-validate": "^1.0.1",
|
||||
"npmlog": "~4.1.2",
|
||||
"once": "~1.4.0",
|
||||
"opener": "^1.5.1",
|
||||
@@ -5461,17 +5467,6 @@
|
||||
"humanize-ms": "^1.2.1"
|
||||
}
|
||||
},
|
||||
"ajv": {
|
||||
"version": "5.5.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"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-align": {
|
||||
"version": "2.0.0",
|
||||
"bundled": true,
|
||||
@@ -5802,11 +5797,6 @@
|
||||
"mkdirp": "~0.5.0"
|
||||
}
|
||||
},
|
||||
"co": {
|
||||
"version": "4.6.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"code-point-at": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
@@ -5898,11 +5888,11 @@
|
||||
}
|
||||
},
|
||||
"configstore": {
|
||||
"version": "3.1.2",
|
||||
"version": "3.1.5",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"dot-prop": "^4.1.0",
|
||||
"dot-prop": "^4.2.1",
|
||||
"graceful-fs": "^4.1.2",
|
||||
"make-dir": "^1.0.0",
|
||||
"unique-string": "^1.0.0",
|
||||
@@ -6078,7 +6068,7 @@
|
||||
}
|
||||
},
|
||||
"dot-prop": {
|
||||
"version": "4.2.0",
|
||||
"version": "4.2.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
@@ -6255,11 +6245,6 @@
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"fast-deep-equal": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"fast-json-stable-stringify": {
|
||||
"version": "2.0.0",
|
||||
"bundled": true,
|
||||
@@ -6580,12 +6565,35 @@
|
||||
"dev": true
|
||||
},
|
||||
"har-validator": {
|
||||
"version": "5.1.0",
|
||||
"version": "5.1.5",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ajv": "^5.3.0",
|
||||
"ajv": "^6.12.3",
|
||||
"har-schema": "^2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"ajv": {
|
||||
"version": "6.12.6",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"fast-deep-equal": "^3.1.1",
|
||||
"fast-json-stable-stringify": "^2.0.0",
|
||||
"json-schema-traverse": "^0.4.1",
|
||||
"uri-js": "^4.2.2"
|
||||
}
|
||||
},
|
||||
"fast-deep-equal": {
|
||||
"version": "3.1.3",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"json-schema-traverse": {
|
||||
"version": "0.4.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"has": {
|
||||
@@ -6872,11 +6880,6 @@
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"json-schema-traverse": {
|
||||
"version": "0.3.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"json-stringify-safe": {
|
||||
"version": "5.0.1",
|
||||
"bundled": true,
|
||||
@@ -7224,7 +7227,7 @@
|
||||
}
|
||||
},
|
||||
"meant": {
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
@@ -7249,6 +7252,11 @@
|
||||
"brace-expansion": "^1.1.7"
|
||||
}
|
||||
},
|
||||
"minimist": {
|
||||
"version": "1.2.5",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
"minizlib": {
|
||||
"version": "1.3.3",
|
||||
"bundled": true,
|
||||
@@ -7485,7 +7493,7 @@
|
||||
}
|
||||
},
|
||||
"npm-registry-fetch": {
|
||||
"version": "4.0.5",
|
||||
"version": "4.0.7",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
@@ -7514,7 +7522,7 @@
|
||||
}
|
||||
},
|
||||
"npm-user-validate": {
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
},
|
||||
@@ -7859,13 +7867,6 @@
|
||||
"ini": "~1.3.0",
|
||||
"minimist": "^1.2.0",
|
||||
"strip-json-comments": "~2.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"minimist": {
|
||||
"version": "1.2.5",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"read": {
|
||||
@@ -8525,6 +8526,21 @@
|
||||
"xdg-basedir": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"uri-js": {
|
||||
"version": "4.4.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"punycode": "^2.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"punycode": {
|
||||
"version": "2.1.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"url-parse-lax": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
|
||||
+12
-8
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@psf/bch-js",
|
||||
"version": "3.4.0",
|
||||
"version": "4.0.0",
|
||||
"description": "The FullStack.cash JavaScript library for Bitcoin Cash and SLP Tokens",
|
||||
"author": "Chris Troutner <chris.troutner@gmail.com>",
|
||||
"contributors": [
|
||||
@@ -8,16 +8,19 @@
|
||||
],
|
||||
"main": "src/bch-js",
|
||||
"scripts": {
|
||||
"test": "nyc mocha --timeout 30000 test/unit/",
|
||||
"test": "nyc mocha --trace-warnings --unhandled-rejections=strict --timeout 30000 test/unit/",
|
||||
"test:integration": "bash test/integration/test-bchn-integration.sh",
|
||||
"test:integration:bchn": "bash test/integration/test-bchn-integration.sh",
|
||||
"test:integration:abc": "RESTURL=https://abc.fullstack.cash/v3/ IS_USING_FREE_TIER=true mocha --timeout 30000 test/integration/",
|
||||
"test:integration:abc": "RESTURL=https://abc.fullstack.cash/v4/ IS_USING_FREE_TIER=true mocha --timeout 30000 test/integration/",
|
||||
"test:integration:testnet": "IS_USING_FREE_TIER=true mocha --timeout 30000 test/integration/testnet/",
|
||||
"test:integration:local": "RESTURL=http://localhost:3000/v3/ mocha --timeout 30000 test/integration",
|
||||
"test:integration:local:bchn": "RESTURL=http://localhost:3000/v3/ bash test/integration/test-free-tier-bchn.sh",
|
||||
"test:integration:local:testnet": "RESTURL=http://localhost:4000/v3/ mocha --timeout 30000 test/integration/testnet",
|
||||
"test:temp": "mocha --timeout 30000 -g '#Encryption' test/integration/",
|
||||
"test:integration:api": "RESTURL=https://api.fullstack.cash/v3/ mocha --timeout 30000 test/integration",
|
||||
"test:integration:local": "RESTURL=http://localhost:3000/v4/ mocha --timeout 30000 test/integration",
|
||||
"test:integration:local:bchn": "RESTURL=http://localhost:3000/v4/ bash test/integration/test-bchn-integration.sh",
|
||||
"test:integration:local:testnet": "RESTURL=http://localhost:4000/v4/ mocha --timeout 30000 test/integration/testnet",
|
||||
"test:integration:api": "RESTURL=https://api.fullstack.cash/v4/ mocha --timeout 30000 test/integration",
|
||||
"test:temp": "RESTURL=https://bchn.fullstack.cash/v4/ mocha --timeout 30000 -g '#validateTxid' test/integration/bchn/",
|
||||
"test:temp2": "RESTURL=https://abc.fullstack.cash/v4/ mocha --timeout 30000 -g '#validateTxid' test/integration/",
|
||||
"test:temp3": "ISBCHN=true RESTURL=http://localhost:3000/v4/ mocha --timeout 30000 -g '#validateTxid' test/integration/bchn/",
|
||||
"test:temp4": "mocha --timeout=30000 -g '#tokenUtxoDetails' 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"
|
||||
@@ -82,6 +85,7 @@
|
||||
"eslint-config-prettier": "^6.0.0",
|
||||
"eslint-plugin-node": "^9.1.0",
|
||||
"eslint-plugin-prettier": "^3.1.0",
|
||||
"lodash.clonedeep": "^4.5.0",
|
||||
"mocha": "^6.1.4",
|
||||
"nock": "^10.0.6",
|
||||
"node-mocks-http": "^1.7.0",
|
||||
|
||||
+18
-1
@@ -6,11 +6,28 @@ const coininfo = require("coininfo")
|
||||
class Address {
|
||||
constructor(config) {
|
||||
const tmp = {}
|
||||
if (!config || !config.restURL) tmp.restURL = `https://api.bchjs.cash/v3/`
|
||||
if (!config || !config.restURL) tmp.restURL = `https://api.bchjs.cash/v4/`
|
||||
else tmp.restURL = config.restURL
|
||||
|
||||
this.restURL = tmp.restURL
|
||||
this.apiToken = tmp.apiToken
|
||||
this.authToken = config.authToken
|
||||
|
||||
if (this.authToken) {
|
||||
// Add Basic Authentication token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: this.authToken
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+21
-3
@@ -7,8 +7,8 @@
|
||||
*/
|
||||
|
||||
// bch-api mainnet.
|
||||
// const DEFAULT_REST_API = "https://api.bchjs.cash/v3/"
|
||||
const DEFAULT_REST_API = "https://api.fullstack.cash/v3/"
|
||||
const DEFAULT_REST_API = "https://api.fullstack.cash/v4/"
|
||||
// const DEFAULT_REST_API = "http://localhost:3000/v4/"
|
||||
|
||||
// local deps
|
||||
const BitcoinCash = require("./bitcoincash")
|
||||
@@ -55,9 +55,27 @@ class BCHJS {
|
||||
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
|
||||
|
||||
// Generate a Basic Authentication token from an auth password
|
||||
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")
|
||||
this.authToken = `Basic ${base64Credential}`
|
||||
}
|
||||
|
||||
const libConfig = {
|
||||
restURL: this.restURL,
|
||||
apiToken: this.apiToken
|
||||
apiToken: this.apiToken,
|
||||
authToken: this.authToken
|
||||
}
|
||||
|
||||
// console.log(`apiToken: ${this.apiToken}`)
|
||||
|
||||
+14
-4
@@ -15,12 +15,22 @@ class Blockbook {
|
||||
constructor(config) {
|
||||
this.restURL = config.restURL
|
||||
this.apiToken = config.apiToken
|
||||
this.authToken = config.authToken
|
||||
// console.log(`Blockbook apiToken: ${this.apiToken}`)
|
||||
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
if (this.authToken) {
|
||||
// Add Basic Authentication token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: this.authToken
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-4
@@ -11,11 +11,21 @@ class Blockchain {
|
||||
constructor(config) {
|
||||
this.restURL = config.restURL
|
||||
this.apiToken = config.apiToken
|
||||
this.authToken = config.authToken
|
||||
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
if (this.authToken) {
|
||||
// Add Basic Authentication token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: this.authToken
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-4
@@ -10,11 +10,21 @@ class Control {
|
||||
constructor(config) {
|
||||
this.restURL = config.restURL
|
||||
this.apiToken = config.apiToken
|
||||
this.authToken = config.authToken
|
||||
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
if (this.authToken) {
|
||||
// Add Basic Authentication token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: this.authToken
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-5
@@ -11,12 +11,21 @@ class ElectrumX {
|
||||
constructor(config) {
|
||||
this.restURL = config.restURL
|
||||
this.apiToken = config.apiToken
|
||||
this.authToken = config.authToken
|
||||
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`,
|
||||
timeout: 15000
|
||||
if (this.authToken) {
|
||||
// Add Basic Authentication token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: this.authToken
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-5
@@ -11,12 +11,21 @@ class Encryption {
|
||||
this.restURL = config.restURL
|
||||
this.apiToken = config.apiToken
|
||||
this.axios = axios
|
||||
// console.log(`Blockbook apiToken: ${this.apiToken}`)
|
||||
this.authToken = config.authToken
|
||||
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
if (this.authToken) {
|
||||
// Add Basic Authentication token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: this.authToken
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-4
@@ -6,11 +6,21 @@ class Generating {
|
||||
constructor(config) {
|
||||
this.restURL = config.restURL
|
||||
this.apiToken = config.apiToken
|
||||
this.authToken = config.authToken
|
||||
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
if (this.authToken) {
|
||||
// Add Basic Authentication token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: this.authToken
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-4
@@ -6,11 +6,21 @@ class Mining {
|
||||
constructor(config) {
|
||||
this.restURL = config.restURL
|
||||
this.apiToken = config.apiToken
|
||||
this.authToken = config.authToken
|
||||
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
if (this.authToken) {
|
||||
// Add Basic Authentication token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: this.authToken
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+52
-28
@@ -6,41 +6,30 @@ class Price {
|
||||
constructor(config) {
|
||||
_this = this
|
||||
|
||||
if (config) {
|
||||
this.restURL = config.restURL
|
||||
this.apiToken = config.apiToken
|
||||
}
|
||||
this.restURL = config.restURL
|
||||
this.apiToken = config.apiToken
|
||||
this.authToken = config.authToken
|
||||
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
if (this.authToken) {
|
||||
// Add Basic Authentication token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: this.authToken
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.axios = axios
|
||||
}
|
||||
|
||||
/**
|
||||
* @api price.current() current()
|
||||
* @apiName Price.
|
||||
* @apiGroup Price
|
||||
* @apiDescription Return current price of BCH in multiple currencies.
|
||||
* This endpoint will be deprecated in favor of getUSD. It uses the Bitcoin.com
|
||||
* price feed.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
*(async () => {
|
||||
* try {
|
||||
* let current = await bchjs.Price.current('usd');
|
||||
* console.log(current);
|
||||
* } catch(err) {
|
||||
* console.err(err)
|
||||
* }
|
||||
*})()
|
||||
*
|
||||
* // 26681
|
||||
*/
|
||||
// This endpoint is deprecated. Documentation removed.
|
||||
async current(currency = "usd") {
|
||||
try {
|
||||
const response = await this.axios.get(
|
||||
@@ -132,6 +121,41 @@ class Price {
|
||||
else throw err
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api price.getBchaUsd() getBchaUsd()
|
||||
* @apiName Price getBchaUsd()
|
||||
* @apiGroup Price
|
||||
* @apiDescription Return current price of BCHA in USD.
|
||||
* This endpoint gets the USD price of BCHA from the Coinex API. The price
|
||||
* comes from bch-api, so it has a better chance of working in Tor.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
*(async () => {
|
||||
* try {
|
||||
* let current = await bchjs.Price.getBchaUsd();
|
||||
* console.log(current);
|
||||
* } catch(err) {
|
||||
* console.err(err)
|
||||
* }
|
||||
*})()
|
||||
*
|
||||
* // 18.81
|
||||
*/
|
||||
async getBchaUsd() {
|
||||
try {
|
||||
const response = await this.axios.get(
|
||||
`${this.restURL}price/bchausd`,
|
||||
_this.axiosOptions
|
||||
)
|
||||
// console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`)
|
||||
|
||||
return response.data.usd
|
||||
} catch (err) {
|
||||
if (err.response && err.response.data) throw err.response.data
|
||||
else throw err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Price
|
||||
|
||||
+21
-12
@@ -6,14 +6,27 @@ class RawTransactions {
|
||||
constructor(config) {
|
||||
this.restURL = config.restURL
|
||||
this.apiToken = config.apiToken
|
||||
this.authToken = config.authToken
|
||||
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
if (this.authToken) {
|
||||
// Add Basic Authentication token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: this.authToken
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Encapsulate dependencies
|
||||
this.axios = axios
|
||||
|
||||
_this = this
|
||||
}
|
||||
|
||||
@@ -262,9 +275,7 @@ class RawTransactions {
|
||||
txids: txid,
|
||||
verbose: verbose
|
||||
},
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
}
|
||||
headers: _this.axiosOptions.headers
|
||||
}
|
||||
const response = await axios(options)
|
||||
|
||||
@@ -314,7 +325,7 @@ class RawTransactions {
|
||||
try {
|
||||
// Single tx hex.
|
||||
if (typeof hex === "string") {
|
||||
const response = await axios.get(
|
||||
const response = await this.axios.get(
|
||||
`${this.restURL}rawtransactions/sendRawTransaction/${hex}`,
|
||||
_this.axiosOptions
|
||||
)
|
||||
@@ -337,11 +348,9 @@ class RawTransactions {
|
||||
data: {
|
||||
hexes: hex
|
||||
},
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
}
|
||||
headers: _this.axiosOptions.headers
|
||||
}
|
||||
const response = await axios(options)
|
||||
const response = await _this.axios(options)
|
||||
|
||||
return response.data
|
||||
}
|
||||
|
||||
+14
-4
@@ -4,11 +4,21 @@ class Schnorr {
|
||||
constructor(config) {
|
||||
this.restURL = config.restURL
|
||||
this.apiToken = config.apiToken
|
||||
this.authToken = config.authToken
|
||||
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
if (this.authToken) {
|
||||
// Add Basic Authentication token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: this.authToken
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+20
-11
@@ -18,22 +18,31 @@ const Utils = require("./utils")
|
||||
// SLP is a superset of BITBOX
|
||||
class SLP {
|
||||
constructor(config) {
|
||||
const tmp = {}
|
||||
if (!config || !config.restURL) {
|
||||
tmp.restURL = `https://api.fullstack.cash/v3/`
|
||||
this.restURL = config.restURL
|
||||
this.apiToken = config.apiToken
|
||||
this.authToken = config.authToken
|
||||
|
||||
if (this.authToken) {
|
||||
// Add Basic Authentication token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: this.authToken
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tmp.restURL = config.restURL
|
||||
tmp.apiToken = config.apiToken
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.restURL = tmp.restURL
|
||||
this.apiToken = tmp.apiToken
|
||||
|
||||
this.Address = new Address(tmp)
|
||||
this.Address = new Address(config)
|
||||
this.ECPair = ECPair
|
||||
this.TokenType1 = new TokenType1(tmp)
|
||||
this.TokenType1 = new TokenType1(config)
|
||||
this.NFT1 = new NFT1(this.restURL)
|
||||
this.Utils = new Utils(tmp)
|
||||
this.Utils = new Utils(config)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
-6
@@ -18,17 +18,28 @@ class TokenType1 {
|
||||
constructor(config) {
|
||||
this.restURL = config.restURL
|
||||
this.apiToken = config.apiToken
|
||||
this.authToken = config.authToken
|
||||
|
||||
if (this.authToken) {
|
||||
// Add Basic Authentication token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: this.authToken
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addy = new Address(config)
|
||||
this.Script = new Script()
|
||||
|
||||
this.axios = axios
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
}
|
||||
}
|
||||
|
||||
// Instantiate the transaction builder.
|
||||
TransactionBuilder.setAddress(addy)
|
||||
|
||||
+268
-41
@@ -1,3 +1,4 @@
|
||||
// Public npm libraries
|
||||
const axios = require("axios")
|
||||
const slpParser = require("slp-parser")
|
||||
|
||||
@@ -13,15 +14,28 @@ class Utils {
|
||||
this.restURL = config.restURL
|
||||
this.apiToken = config.apiToken
|
||||
this.slpParser = slpParser
|
||||
this.authToken = config.authToken
|
||||
this.axios = axios
|
||||
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
if (this.authToken) {
|
||||
// Add Basic Authentication token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: this.authToken
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_this = this
|
||||
|
||||
this.whitelist = []
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,6 +197,7 @@ class Utils {
|
||||
async list(id) {
|
||||
let path
|
||||
let method
|
||||
|
||||
if (!id) {
|
||||
method = "get"
|
||||
path = `${this.restURL}slp/list`
|
||||
@@ -199,9 +214,9 @@ class Utils {
|
||||
try {
|
||||
let response
|
||||
if (method === "get") {
|
||||
response = await axios.get(path, _this.axiosOptions)
|
||||
response = await _this.axios.get(path, _this.axiosOptions)
|
||||
} else {
|
||||
response = await axios.post(
|
||||
response = await _this.axios.post(
|
||||
path,
|
||||
{
|
||||
tokenIds: id
|
||||
@@ -297,7 +312,7 @@ class Utils {
|
||||
if (typeof address === "string") {
|
||||
const path = `${this.restURL}slp/balancesForAddress/${address}`
|
||||
|
||||
const response = await axios.get(path, _this.axiosOptions)
|
||||
const response = await _this.axios.get(path, _this.axiosOptions)
|
||||
return response.data
|
||||
|
||||
// Array of addresses.
|
||||
@@ -305,7 +320,7 @@ class Utils {
|
||||
const path = `${this.restURL}slp/balancesForAddress`
|
||||
|
||||
// Dev note: must use axios.post for unit test stubbing.
|
||||
const response = await axios.post(
|
||||
const response = await _this.axios.post(
|
||||
path,
|
||||
{
|
||||
addresses: address
|
||||
@@ -359,10 +374,10 @@ class Utils {
|
||||
*/
|
||||
// Retrieve token balances for a given tokenId.
|
||||
async balancesForToken(tokenId) {
|
||||
const path = `${this.restURL}slp/balancesForToken/${tokenId}`
|
||||
|
||||
try {
|
||||
const response = await axios.get(path, _this.axiosOptions)
|
||||
const path = `${this.restURL}slp/balancesForToken/${tokenId}`
|
||||
|
||||
const response = await _this.axios.get(path, _this.axiosOptions)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
@@ -427,7 +442,7 @@ class Utils {
|
||||
else txids = txid
|
||||
|
||||
try {
|
||||
const response = await axios.post(
|
||||
const response = await _this.axios.post(
|
||||
path,
|
||||
{
|
||||
txids: txids
|
||||
@@ -438,16 +453,6 @@ class Utils {
|
||||
|
||||
const validatedTxids = response.data
|
||||
|
||||
// Handle any null values
|
||||
for (let i = 0; i < validatedTxids.length; i++) {
|
||||
if (validatedTxids[i] === null) {
|
||||
validatedTxids[i] = {
|
||||
txid: txids[i],
|
||||
valid: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return validatedTxids
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
@@ -475,7 +480,7 @@ class Utils {
|
||||
* // validate single SLP txid
|
||||
* (async () => {
|
||||
* try {
|
||||
* let validated = await bchjs.SLP.Utils.validateTxid(
|
||||
* let validated = await bchjs.SLP.Utils.validateTxid2(
|
||||
* "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb"
|
||||
* );
|
||||
* console.log(validated);
|
||||
@@ -503,7 +508,7 @@ class Utils {
|
||||
|
||||
const path = `${this.restURL}slp/validateTxid2/${txid}`
|
||||
|
||||
const response = await axios.get(path, _this.axiosOptions)
|
||||
const response = await _this.axios.get(path, _this.axiosOptions)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
@@ -515,6 +520,154 @@ class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api SLP.Utils.whitelist() whitelist()
|
||||
* @apiName whitelist
|
||||
* @apiGroup SLP Utils
|
||||
* @apiDescription Get SLP tokens in whitelist
|
||||
* Retrieves a list of the SLP tokens that in the whitelist. Tokens in the
|
||||
* whitelist can be validated with the validateTxid3() function. validateTxid3()
|
||||
* will still work when the SLP network is under stress.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
*
|
||||
* // validate single SLP txid
|
||||
* (async () => {
|
||||
* try {
|
||||
* let list = await bchjs.SLP.Utils.whitelit();
|
||||
* console.log(list);
|
||||
* } catch (error) {
|
||||
* console.error(error);
|
||||
* }
|
||||
* })();
|
||||
*
|
||||
* // returns
|
||||
* [
|
||||
* {
|
||||
* name: 'USDH',
|
||||
* tokenId:
|
||||
* 'c4b0d62156b3fa5c8f3436079b5394f7edc1bef5dc1cd2f9d0c4d46f82cca479'
|
||||
* },
|
||||
* {
|
||||
* name: 'SPICE',
|
||||
* tokenId:
|
||||
* '4de69e374a8ed21cbddd47f2338cc0f479dc58daa2bbe11cd604ca488eca0ddf'
|
||||
* },
|
||||
* {
|
||||
* name: 'PSF',
|
||||
* tokenId:
|
||||
* '38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0'
|
||||
* },
|
||||
* {
|
||||
* name: 'TROUT',
|
||||
* tokenId:
|
||||
* 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||
* },
|
||||
* {
|
||||
* name: 'PSFTEST',
|
||||
* tokenId:
|
||||
* 'd0ef4de95b78222bfee2326ab11382f4439aa0855936e2fe6ac129a8d778baa0'
|
||||
* }
|
||||
* ]
|
||||
*/
|
||||
async getWhitelist() {
|
||||
try {
|
||||
const path = `${this.restURL}slp/whitelist`
|
||||
|
||||
// Retrieve the whitelist from the REST API if we haven't gotten it yet.
|
||||
if (this.whitelist.length === 0) {
|
||||
const response = await _this.axios.get(path, _this.axiosOptions)
|
||||
// console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`)
|
||||
|
||||
this.whitelist = response.data
|
||||
}
|
||||
|
||||
return this.whitelist
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api SLP.Utils.validateTxid3() validateTxid3()
|
||||
* @apiName validateTxid3
|
||||
* @apiGroup SLP Utils
|
||||
* @apiDescription Validate that txid is an SLP transaction using the SLPDB whitelist server.
|
||||
* Same exact functionality as the validateTxid() function, but this function
|
||||
* calls the whitelist SLPDB. It will only validate SLP tokens that are in the
|
||||
* whitelist. You can retrieve the whitelist with the SLP.Utils.whitelist()
|
||||
* function.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
*
|
||||
* // validate single SLP txid
|
||||
* (async () => {
|
||||
* try {
|
||||
* let validated = await bchjs.SLP.Utils.validateTxid3(
|
||||
* "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb"
|
||||
* );
|
||||
* console.log(validated);
|
||||
* } catch (error) {
|
||||
* console.error(error);
|
||||
* }
|
||||
* })();
|
||||
*
|
||||
* // returns
|
||||
* [ { txid:
|
||||
* 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb',
|
||||
* valid: true } ]
|
||||
*
|
||||
* // validate multiple SLP txids
|
||||
* (async () => {
|
||||
* try {
|
||||
* let validated = await bchjs.SLP.Utils.validateTxid3([
|
||||
* "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb",
|
||||
* "00ea27261196a411776f81029c0ebe34362936b4a9847deb1f7a40a02b3a1476"
|
||||
* ]);
|
||||
* console.log(validated);
|
||||
* } catch (error) {
|
||||
* console.error(error);
|
||||
* }
|
||||
* })();
|
||||
*
|
||||
* // returns
|
||||
* [ { txid:
|
||||
* 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb',
|
||||
* valid: true },
|
||||
* { txid:
|
||||
* '00ea27261196a411776f81029c0ebe34362936b4a9847deb1f7a40a02b3a1476',
|
||||
* valid: true } ]
|
||||
*/
|
||||
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]
|
||||
else txids = txid
|
||||
|
||||
try {
|
||||
const response = await _this.axios.post(
|
||||
path,
|
||||
{
|
||||
txids: txids
|
||||
},
|
||||
_this.axiosOptions
|
||||
)
|
||||
// console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`)
|
||||
|
||||
const validatedTxids = response.data
|
||||
|
||||
return validatedTxids
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api SLP.Utils.tokenStats() tokenStats()
|
||||
* @apiName tokenStats
|
||||
@@ -551,10 +704,11 @@ class Utils {
|
||||
* }
|
||||
*/
|
||||
async tokenStats(tokenId) {
|
||||
const path = `${this.restURL}slp/tokenStats/${tokenId}`
|
||||
|
||||
try {
|
||||
const response = await axios.get(path, _this.axiosOptions)
|
||||
const path = `${this.restURL}slp/tokenStats/${tokenId}`
|
||||
|
||||
const response = await _this.axios.get(path, _this.axiosOptions)
|
||||
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
@@ -621,10 +775,11 @@ class Utils {
|
||||
*/
|
||||
// Retrieve token transactions for a given tokenId and address.
|
||||
async transactions(tokenId, address) {
|
||||
const path = `${this.restURL}slp/transactions/${tokenId}/${address}`
|
||||
|
||||
try {
|
||||
const response = await axios.get(path, _this.axiosOptions)
|
||||
const path = `${this.restURL}slp/transactions/${tokenId}/${address}`
|
||||
|
||||
const response = await _this.axios.get(path, _this.axiosOptions)
|
||||
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
@@ -660,10 +815,11 @@ class Utils {
|
||||
* }
|
||||
*/
|
||||
async burnTotal(transactionId) {
|
||||
const path = `${this.restURL}slp/burnTotal/${transactionId}`
|
||||
|
||||
try {
|
||||
const response = await axios.get(path, _this.axiosOptions)
|
||||
const path = `${this.restURL}slp/burnTotal/${transactionId}`
|
||||
|
||||
const response = await _this.axios.get(path, _this.axiosOptions)
|
||||
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
@@ -705,7 +861,7 @@ class Utils {
|
||||
// console.log(`this.restURL: ${this.restURL}`)
|
||||
const path = `${this.restURL}slp/txDetails/${txid}`
|
||||
|
||||
const response = await axios.get(path, _this.axiosOptions)
|
||||
const response = await _this.axios.get(path, _this.axiosOptions)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
@@ -780,7 +936,7 @@ class Utils {
|
||||
|
||||
// Retrieve the transaction object from the full node.
|
||||
const path = `${this.restURL}rawtransactions/getRawTransaction/${txid}?verbose=true`
|
||||
const response = await axios.get(path, _this.axiosOptions)
|
||||
const response = await _this.axios.get(path, _this.axiosOptions)
|
||||
const txDetails = response.data
|
||||
// console.log(`txDetails: ${JSON.stringify(txDetails, null, 2)}`)
|
||||
|
||||
@@ -931,6 +1087,7 @@ class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the UTXO has a vout or tx_pos property.
|
||||
if (!Number.isInteger(utxo.vout)) {
|
||||
if (Number.isInteger(utxo.tx_pos)) {
|
||||
utxo.vout = utxo.tx_pos
|
||||
@@ -965,9 +1122,13 @@ class Utils {
|
||||
if (
|
||||
!err.message ||
|
||||
(err.message.indexOf("scriptpubkey not op_return") === -1 &&
|
||||
err.message.indexOf("lokad id") === -1)
|
||||
err.message.indexOf("lokad id") === -1 &&
|
||||
err.message.indexOf("trailing data") === -1)
|
||||
) {
|
||||
// console.log(`error from decodeOpReturn(${utxo.txid}): `, err)
|
||||
// console.log(
|
||||
// `unknown error from decodeOpReturn(). Marking as 'null'`,
|
||||
// err
|
||||
// )
|
||||
|
||||
utxo.isValid = null
|
||||
outAry.push(utxo)
|
||||
@@ -976,6 +1137,7 @@ class Utils {
|
||||
// an SLP UTXO.
|
||||
// Mark as false and continue the loop.
|
||||
} else {
|
||||
// console.log("marking as invalid")
|
||||
utxo.isValid = false
|
||||
outAry.push(utxo)
|
||||
}
|
||||
@@ -1119,16 +1281,81 @@ class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, validate the SLP txid with SLPDB.
|
||||
// *After* the UTXO has been hydrated with SLP data,
|
||||
// validate the TXID with SLPDB.
|
||||
if (outAry[i].tokenType) {
|
||||
var isValid = cachedTxValidation[utxo.txid]
|
||||
// Only execute this block if the current UTXO has a 'tokenType'
|
||||
// property. i.e. it has been successfully hydrated with SLP
|
||||
// information.
|
||||
|
||||
// If the value has been cached, use the cached version first.
|
||||
let isValid = cachedTxValidation[utxo.txid]
|
||||
|
||||
// If not in the cache, try the general SLPDB.
|
||||
if (isValid == null) {
|
||||
isValid = await this.validateTxid(utxo.txid)
|
||||
isValid = isValid[0].valid
|
||||
|
||||
// Save the result to the local cache.
|
||||
cachedTxValidation[utxo.txid] = isValid
|
||||
}
|
||||
// console.log(`isValid: ${JSON.stringify(isValid, null, 2)}`)
|
||||
|
||||
outAry[i].isValid = isValid[0].valid
|
||||
// If still null, check the whitelist SLPDB
|
||||
if (isValid === null) {
|
||||
// console.log(
|
||||
// `checking against whitelist SLPDB. outAry[${i}]: ${JSON.stringify(
|
||||
// outAry[i],
|
||||
// null,
|
||||
// 2
|
||||
// )}`
|
||||
// )
|
||||
|
||||
// Figure out if the token UTXO is in the whitelist.
|
||||
let utxoInWhitelist = false
|
||||
for (let j = 0; j < this.whitelist.length; j++) {
|
||||
if (outAry[i].tokenId === this.whitelist[j].tokenId) {
|
||||
utxoInWhitelist = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// If the utxo.tokenId is in the whitelist, check the validity with
|
||||
// the whitelist SLPDB. This should still be functioning properly
|
||||
// if the general SLPDB is not.
|
||||
if (utxoInWhitelist) {
|
||||
isValid = await this.validateTxid3(utxo.txid)
|
||||
|
||||
// console.log(
|
||||
// `whitelist-SLPDB for ${utxo.txid}: ${JSON.stringify(
|
||||
// isValid,
|
||||
// null,
|
||||
// 2
|
||||
// )}`
|
||||
// )
|
||||
|
||||
isValid = isValid[0].valid
|
||||
|
||||
// Save the result to the local cache.
|
||||
cachedTxValidation[utxo.txid] = isValid
|
||||
}
|
||||
}
|
||||
|
||||
// If still null, as a last resort, check it against slp-validate
|
||||
if (isValid === null) {
|
||||
isValid = await this.validateTxid2(utxo.txid)
|
||||
// console.log(
|
||||
// `slp-validate isValid: ${JSON.stringify(isValid, null, 2)}`
|
||||
// )
|
||||
|
||||
isValid = isValid.isValid
|
||||
|
||||
// Save the result to the local cache.
|
||||
cachedTxValidation[utxo.txid] = isValid
|
||||
}
|
||||
|
||||
// console.log(`isValid: ${JSON.stringify(isValid, null, 2)}`)
|
||||
outAry[i].isValid = isValid
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1309,7 +1536,7 @@ class Utils {
|
||||
// Throw error if input is not an array.
|
||||
if (!Array.isArray(utxos)) throw new Error("Input must be an array.")
|
||||
|
||||
const response = await axios.post(
|
||||
const response = await _this.axios.post(
|
||||
`${this.restURL}slp/hydrateUtxos`,
|
||||
{
|
||||
utxos: utxos
|
||||
|
||||
+14
-4
@@ -6,11 +6,21 @@ class Util {
|
||||
constructor(config) {
|
||||
this.restURL = config.restURL
|
||||
this.apiToken = config.apiToken
|
||||
this.authToken = config.authToken
|
||||
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
if (this.authToken) {
|
||||
// Add Basic Authentication token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: this.authToken
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Add JWT token to the authorization header.
|
||||
this.axiosOptions = {
|
||||
headers: {
|
||||
authorization: `Token ${this.apiToken}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,12 +5,18 @@
|
||||
To Run Test:
|
||||
- Update the RESTURL for bch-api you want to test against.
|
||||
- Ensure the BCHJSTOKEN environment variable is set to an empty string.
|
||||
- If working with bch-api locally, eliminate the local IP address from the
|
||||
whitelist in bch-api/src/middleware/route-ratelimit.js
|
||||
|
||||
Run this test with this command:
|
||||
mocha --timeout=30000 anonymous-rate-limits.js
|
||||
*/
|
||||
|
||||
const assert = require("chai").assert
|
||||
|
||||
const RESTURL = `https://api.fullstack.cash/v3/`
|
||||
// const RESTURL = `http://localhost:3000/v3/`
|
||||
// const RESTURL = `https://abc.fullstack.cash/v4/`
|
||||
const RESTURL = `https://bchn.fullstack.cash/v4/`
|
||||
// const RESTURL = `http://localhost:3000/v4/`
|
||||
|
||||
const BCHJS = require("../../../src/bch-js")
|
||||
const bchjs = new BCHJS({ restURL: RESTURL })
|
||||
@@ -24,7 +30,7 @@ describe("#anonymous rate limits", () => {
|
||||
|
||||
it("should allow an anonymous call to an indexer", async () => {
|
||||
const addr = "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf"
|
||||
const result = await bchjs.Blockbook.balance(addr)
|
||||
const result = await bchjs.Electrumx.balance(addr)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.property(result, "balance")
|
||||
@@ -32,7 +38,7 @@ describe("#anonymous rate limits", () => {
|
||||
|
||||
it("should throw error when rate limit exceeded", async () => {
|
||||
try {
|
||||
for (let i = 0; i < 22; i++) await bchjs.Control.getNetworkInfo()
|
||||
for (let i = 0; i < 35; i++) await bchjs.Control.getNetworkInfo()
|
||||
|
||||
assert.fail("Unexpected result")
|
||||
} catch (err) {
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Mocha test that verifies that the bch-api server is enforcing its
|
||||
access rules for Basic Authentication.
|
||||
|
||||
To Run Test:
|
||||
- Update the restURL for bch-api you want to test against.
|
||||
- Update the PRO_PASS value with a current PRO_PASSES string used by bch-api.
|
||||
*/
|
||||
|
||||
const assert = require("chai").assert
|
||||
|
||||
const PRO_PASS = "testpassword"
|
||||
|
||||
const BCHJS = require("../../../src/bch-js")
|
||||
const bchjs = new BCHJS({
|
||||
// restURL: `https://bchn.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 () => {
|
||||
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")
|
||||
}
|
||||
|
||||
if (i === 15) {
|
||||
// console.log(`validating 5th call: ${i}`)
|
||||
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"
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
if (i === 15) {
|
||||
// console.log(`validating 5th call: ${i}`)
|
||||
assert.property(result, "balance", "more than 10 calls allowed")
|
||||
}
|
||||
}
|
||||
}).timeout(45000)
|
||||
})
|
||||
@@ -1,4 +1,8 @@
|
||||
/*
|
||||
CT 11/11/2020:
|
||||
There is no longer a free tier. These tests have been deprecated.
|
||||
|
||||
--------
|
||||
Mocha test that verifies that the bch-api server is enforcing its
|
||||
FREE access rules
|
||||
|
||||
@@ -14,8 +18,8 @@ const JWT_TOKEN =
|
||||
|
||||
const BCHJS = require("../../../src/bch-js")
|
||||
const bchjs = new BCHJS({
|
||||
restURL: `https://api.fullstack.cash/v3/`,
|
||||
// restURL: `http://localhost:3000/v3/`,
|
||||
restURL: `https://api.fullstack.cash/v4/`,
|
||||
// restURL: `http://localhost:3000/v4/`,
|
||||
apiToken: JWT_TOKEN
|
||||
})
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
/*
|
||||
CT 11/11/2020:
|
||||
There is no longer a free tier. These tests have been deprecated.
|
||||
|
||||
----
|
||||
Mocha test that verifies that the bch-api server is enforcing its
|
||||
full-node access rules
|
||||
|
||||
@@ -14,15 +18,16 @@ const JWT_TOKEN =
|
||||
|
||||
const BCHJS = require("../../../src/bch-js")
|
||||
const bchjs = new BCHJS({
|
||||
restURL: `https://api.fullstack.cash/v3/`,
|
||||
// restURL: `http://localhost:3000/v3/`,
|
||||
// restURL: `https://bchn.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"
|
||||
const result = await bchjs.Blockbook.balance(addr)
|
||||
const result = await bchjs.Electrumx.balance(addr)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.property(result, "balance")
|
||||
|
||||
@@ -14,12 +14,13 @@ const JWT_TOKEN =
|
||||
|
||||
const BCHJS = require("../../../src/bch-js")
|
||||
const bchjs = new BCHJS({
|
||||
restURL: `https://api.fullstack.cash/v3/`,
|
||||
// restURL: `http://localhost:3000/v3/`,
|
||||
// restURL: `https://bchn.fullstack.cash/v4/`,
|
||||
restURL: `https://abc.fullstack.cash/v4/`,
|
||||
// restURL: `http://localhost:3000/v4/`,
|
||||
apiToken: JWT_TOKEN
|
||||
})
|
||||
|
||||
describe("#full node rate limits", () => {
|
||||
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()
|
||||
@@ -40,7 +41,7 @@ describe("#full node rate limits", () => {
|
||||
const addr = "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf"
|
||||
|
||||
for (let i = 0; i < 22; i++) {
|
||||
const result = await bchjs.Blockbook.balance(addr)
|
||||
const result = await bchjs.Electrumx.balance(addr)
|
||||
|
||||
if (i === 5) {
|
||||
// console.log(`validating 5th call: ${i}`)
|
||||
|
||||
@@ -21,6 +21,15 @@ describe("#price", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("#getBchaUsd", () => {
|
||||
it("should get the USD price of BCHA", async () => {
|
||||
const result = await bchjs.Price.getBchaUsd()
|
||||
console.log(result)
|
||||
|
||||
assert.isNumber(result)
|
||||
})
|
||||
})
|
||||
|
||||
describe("#rates", () => {
|
||||
it("should get the price of BCH in several currencies", async () => {
|
||||
const result = await bchjs.Price.rates()
|
||||
|
||||
@@ -35,7 +35,7 @@ describe(`#SLP`, () => {
|
||||
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",
|
||||
@@ -60,6 +60,34 @@ describe(`#SLP`, () => {
|
||||
"mintingBatonStatus"
|
||||
])
|
||||
})
|
||||
|
||||
it("should NOT get a list of all tokens in existence", async () => {
|
||||
try {
|
||||
await bchjs.SLP.Utils.list()
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.fail("Unexpected result!")
|
||||
} catch (err) {
|
||||
// console.log(err)
|
||||
assert.include(err.message, "Not Found")
|
||||
}
|
||||
})
|
||||
|
||||
it("should get information on multiple tokens", async () => {
|
||||
const tokenIds = [
|
||||
// Spice
|
||||
`4de69e374a8ed21cbddd47f2338cc0f479dc58daa2bbe11cd604ca488eca0ddf`,
|
||||
// PSF
|
||||
"38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0"
|
||||
]
|
||||
|
||||
const result = await bchjs.SLP.Utils.list(tokenIds)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.isArray(result)
|
||||
assert.equal(result[0].symbol, "SPICE")
|
||||
assert.equal(result[1].symbol, "PSF")
|
||||
})
|
||||
})
|
||||
|
||||
// describe("#decodeOpReturn", () => {
|
||||
@@ -463,6 +491,98 @@ describe(`#SLP`, () => {
|
||||
|
||||
assert.equal(data[0].isValid, false)
|
||||
})
|
||||
|
||||
it("should handle a range of UTXO types", async () => {
|
||||
const utxos = [
|
||||
// Malformed SLP tx
|
||||
{
|
||||
note: "Malformed SLP tx",
|
||||
tx_hash:
|
||||
"f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a",
|
||||
tx_pos: 1,
|
||||
value: 546
|
||||
},
|
||||
// Normal TX (non-SLP)
|
||||
{
|
||||
note: "Normal TX (non-SLP)",
|
||||
tx_hash:
|
||||
"01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0",
|
||||
tx_pos: 0,
|
||||
value: 400000
|
||||
},
|
||||
// Valid PSF SLP tx
|
||||
{
|
||||
note: "Valid PSF SLP tx",
|
||||
tx_hash:
|
||||
"daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd",
|
||||
tx_pos: 1,
|
||||
value: 546
|
||||
},
|
||||
// Valid SLP token not in whitelist
|
||||
{
|
||||
note: "Valid SLP token not in whitelist",
|
||||
tx_hash:
|
||||
"3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488",
|
||||
tx_pos: 1,
|
||||
value: 546
|
||||
},
|
||||
// Token send on BCHN network.
|
||||
{
|
||||
note: "Token send on BCHN network",
|
||||
tx_hash:
|
||||
"402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019",
|
||||
tx_pos: 1,
|
||||
value: 546
|
||||
},
|
||||
// Token send on ABC network.
|
||||
{
|
||||
note: "Token send on ABC network",
|
||||
tx_hash:
|
||||
"336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d",
|
||||
tx_pos: 1,
|
||||
value: 546
|
||||
},
|
||||
// Known invalid SLP token send of PSF tokens.
|
||||
{
|
||||
note: "Known invalid SLP token send of PSF tokens",
|
||||
tx_hash:
|
||||
"2bf691ad3679d928fef880b8a45b93b233f8fa0d0a92cf792313dbe77b1deb74",
|
||||
tx_pos: 1,
|
||||
value: 546
|
||||
}
|
||||
]
|
||||
|
||||
const data = await bchjs.SLP.Utils.tokenUtxoDetails(utxos)
|
||||
// console.log(`data: ${JSON.stringify(data, null, 2)}`)
|
||||
|
||||
// Malformed SLP tx
|
||||
assert.equal(data[0].tx_hash, utxos[0].tx_hash)
|
||||
assert.equal(data[0].isValid, false)
|
||||
|
||||
// Normal TX (non-SLP)
|
||||
assert.equal(data[1].tx_hash, utxos[1].tx_hash)
|
||||
assert.equal(data[1].isValid, false)
|
||||
|
||||
// Valid PSF SLP tx
|
||||
assert.equal(data[2].tx_hash, utxos[2].tx_hash)
|
||||
assert.equal(data[2].isValid, true)
|
||||
|
||||
// Valid SLP token not in whitelist
|
||||
assert.equal(data[3].tx_hash, utxos[3].tx_hash)
|
||||
assert.equal(data[3].isValid, true)
|
||||
|
||||
// Token send on BCHN network
|
||||
assert.equal(data[4].tx_hash, utxos[4].tx_hash)
|
||||
assert.equal(data[4].isValid, true)
|
||||
|
||||
// Token send on ABC network
|
||||
assert.equal(data[5].tx_hash, utxos[5].tx_hash)
|
||||
assert.equal(data[5].isValid, null)
|
||||
|
||||
// Known invalid SLP token send of PSF tokens
|
||||
assert.equal(data[6].tx_hash, utxos[6].tx_hash)
|
||||
assert.equal(data[6].isValid, false)
|
||||
})
|
||||
})
|
||||
|
||||
describe("#balancesForAddress", () => {
|
||||
@@ -663,6 +783,150 @@ describe(`#SLP`, () => {
|
||||
assert.equal(result.isValid, true)
|
||||
})
|
||||
})
|
||||
|
||||
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")
|
||||
})
|
||||
})
|
||||
|
||||
describe("#validateTxid3", () => {
|
||||
it("should invalidate a known invalid TXID", async () => {
|
||||
const txid =
|
||||
"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.equal(result[0].txid, txid)
|
||||
|
||||
assert.property(result[0], "valid")
|
||||
assert.equal(result[0].valid, null)
|
||||
})
|
||||
|
||||
it("should validate a known valid TXID", async () => {
|
||||
const txid =
|
||||
"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.equal(result[0].txid, txid)
|
||||
|
||||
assert.property(result[0], "valid")
|
||||
assert.equal(result[0].valid, true)
|
||||
})
|
||||
|
||||
it("should handle a mix of valid, invalid, and non-SLP txs", async () => {
|
||||
const txids = [
|
||||
// Malformed SLP tx
|
||||
"f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a",
|
||||
// Normal TX (non-SLP)
|
||||
"01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0",
|
||||
// Valid PSF SLP tx
|
||||
"daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd",
|
||||
// Valid SLP token not in whitelist
|
||||
"3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488",
|
||||
// Token send on BCHN network.
|
||||
"402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019",
|
||||
// Token send on ABC network.
|
||||
"336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d",
|
||||
// Known invalid SLP token send of PSF tokens.
|
||||
"2bf691ad3679d928fef880b8a45b93b233f8fa0d0a92cf792313dbe77b1deb74"
|
||||
]
|
||||
|
||||
const result = await bchjs.SLP.Utils.validateTxid3(txids)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.equal(result[0].txid, txids[0])
|
||||
assert.equal(result[0].valid, null)
|
||||
|
||||
assert.equal(result[1].txid, txids[1])
|
||||
assert.equal(result[1].valid, null)
|
||||
|
||||
assert.equal(result[2].txid, txids[2])
|
||||
assert.equal(result[2].valid, true)
|
||||
|
||||
// True in validateTxid() but null in validateTxid3()
|
||||
assert.equal(result[3].txid, txids[3])
|
||||
assert.equal(result[3].valid, null)
|
||||
|
||||
// Note: This should change from null to true once SLPDB finishes indexing.
|
||||
assert.equal(result[4].txid, txids[4])
|
||||
assert.equal(result[4].valid, null)
|
||||
|
||||
assert.equal(result[5].txid, txids[5])
|
||||
assert.equal(result[5].valid, null)
|
||||
|
||||
assert.equal(result[6].txid, txids[6])
|
||||
assert.equal(result[6].valid, false)
|
||||
assert.include(
|
||||
result[6].invalidReason,
|
||||
"Token outputs are greater than valid token inputs"
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("#validateTxid", () => {
|
||||
it("should handle a mix of valid, invalid, and non-SLP txs", async () => {
|
||||
const txids = [
|
||||
// Malformed SLP tx
|
||||
"f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a",
|
||||
// Normal TX (non-SLP)
|
||||
"01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0",
|
||||
// Valid PSF SLP tx
|
||||
"daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd",
|
||||
// Valid SLP token not in whitelist
|
||||
"3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488",
|
||||
// Token send on BCHN network.
|
||||
"402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019",
|
||||
// Token send on ABC network.
|
||||
"336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d",
|
||||
// Known invalid SLP token send of PSF tokens.
|
||||
"2bf691ad3679d928fef880b8a45b93b233f8fa0d0a92cf792313dbe77b1deb74"
|
||||
]
|
||||
|
||||
const result = await bchjs.SLP.Utils.validateTxid(txids)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.equal(result[0].txid, txids[0])
|
||||
assert.equal(result[0].valid, null)
|
||||
|
||||
assert.equal(result[1].txid, txids[1])
|
||||
assert.equal(result[1].valid, null)
|
||||
|
||||
assert.equal(result[2].txid, txids[2])
|
||||
assert.equal(result[2].valid, true)
|
||||
|
||||
// True in validateTxid() but null in validateTxid3()
|
||||
assert.equal(result[3].txid, txids[3])
|
||||
assert.equal(result[3].valid, true)
|
||||
|
||||
assert.equal(result[4].txid, txids[4])
|
||||
assert.equal(result[4].valid, true)
|
||||
|
||||
assert.equal(result[5].txid, txids[5])
|
||||
assert.equal(result[5].valid, null)
|
||||
|
||||
assert.equal(result[6].txid, txids[6])
|
||||
assert.equal(result[6].valid, false)
|
||||
assert.include(
|
||||
result[6].invalidReason,
|
||||
"Token outputs are greater than valid token inputs"
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("#tokentype1", () => {
|
||||
|
||||
@@ -25,6 +25,15 @@ describe("#price", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("#getBchaUsd", () => {
|
||||
it("should get the USD price of BCHA", async () => {
|
||||
const result = await bchjs.Price.getBchaUsd()
|
||||
console.log(result)
|
||||
|
||||
assert.isNumber(result)
|
||||
})
|
||||
})
|
||||
|
||||
describe("#rates", () => {
|
||||
it("should get the price of BCH in several currencies", async () => {
|
||||
const result = await bchjs.Price.rates()
|
||||
|
||||
@@ -244,7 +244,7 @@ describe("#rawtransaction", () => {
|
||||
//console.log(`err: ${util.inspect(err)}`)
|
||||
|
||||
assert.hasAllKeys(err, ["error"])
|
||||
assert.include(err.error, "bad-txns-inputs-missingorspent (code 16)")
|
||||
assert.include(err.error, "bad-txns-inputs-missingorspent")
|
||||
}
|
||||
})
|
||||
|
||||
@@ -261,7 +261,7 @@ describe("#rawtransaction", () => {
|
||||
// console.log(`err: ${util.inspect(err)}`)
|
||||
|
||||
assert.hasAllKeys(err, ["error"])
|
||||
assert.include(err.error, "bad-txns-inputs-missingorspent (code 16)")
|
||||
assert.include(err.error, "bad-txns-inputs-missingorspent")
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -463,6 +463,98 @@ describe(`#SLP`, () => {
|
||||
|
||||
assert.equal(data[0].isValid, false)
|
||||
})
|
||||
|
||||
it("should handle a range of UTXO types", async () => {
|
||||
const utxos = [
|
||||
// Malformed SLP tx
|
||||
{
|
||||
note: "Malformed SLP tx",
|
||||
tx_hash:
|
||||
"f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a",
|
||||
tx_pos: 1,
|
||||
value: 546
|
||||
},
|
||||
// Normal TX (non-SLP)
|
||||
{
|
||||
note: "Normal TX (non-SLP)",
|
||||
tx_hash:
|
||||
"01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0",
|
||||
tx_pos: 0,
|
||||
value: 400000
|
||||
},
|
||||
// Valid PSF SLP tx
|
||||
{
|
||||
note: "Valid PSF SLP tx",
|
||||
tx_hash:
|
||||
"daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd",
|
||||
tx_pos: 1,
|
||||
value: 546
|
||||
},
|
||||
// Valid SLP token not in whitelist
|
||||
{
|
||||
note: "Valid SLP token not in whitelist",
|
||||
tx_hash:
|
||||
"3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488",
|
||||
tx_pos: 1,
|
||||
value: 546
|
||||
},
|
||||
// Token send on BCHN network.
|
||||
{
|
||||
note: "Token send on BCHN network",
|
||||
tx_hash:
|
||||
"402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019",
|
||||
tx_pos: 1,
|
||||
value: 546
|
||||
},
|
||||
// Token send on ABC network.
|
||||
{
|
||||
note: "Token send on ABC network",
|
||||
tx_hash:
|
||||
"336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d",
|
||||
tx_pos: 1,
|
||||
value: 546
|
||||
},
|
||||
// Known invalid SLP token send of PSF tokens.
|
||||
{
|
||||
note: "Known invalid SLP token send of PSF tokens",
|
||||
tx_hash:
|
||||
"2bf691ad3679d928fef880b8a45b93b233f8fa0d0a92cf792313dbe77b1deb74",
|
||||
tx_pos: 1,
|
||||
value: 546
|
||||
}
|
||||
]
|
||||
|
||||
const data = await bchjs.SLP.Utils.tokenUtxoDetails(utxos)
|
||||
// console.log(`data: ${JSON.stringify(data, null, 2)}`)
|
||||
|
||||
// Malformed SLP tx
|
||||
assert.equal(data[0].tx_hash, utxos[0].tx_hash)
|
||||
assert.equal(data[0].isValid, false)
|
||||
|
||||
// Normal TX (non-SLP)
|
||||
assert.equal(data[1].tx_hash, utxos[1].tx_hash)
|
||||
assert.equal(data[1].isValid, false)
|
||||
|
||||
// Valid PSF SLP tx
|
||||
assert.equal(data[2].tx_hash, utxos[2].tx_hash)
|
||||
assert.equal(data[2].isValid, true)
|
||||
|
||||
// Valid SLP token not in whitelist
|
||||
assert.equal(data[3].tx_hash, utxos[3].tx_hash)
|
||||
assert.equal(data[3].isValid, true)
|
||||
|
||||
// Token send on BCHN network
|
||||
assert.equal(data[4].tx_hash, utxos[4].tx_hash)
|
||||
assert.equal(data[4].isValid, null)
|
||||
|
||||
// Token send on ABC network
|
||||
assert.equal(data[5].tx_hash, utxos[5].tx_hash)
|
||||
assert.equal(data[5].isValid, true)
|
||||
|
||||
// Known invalid SLP token send of PSF tokens
|
||||
assert.equal(data[6].tx_hash, utxos[6].tx_hash)
|
||||
assert.equal(data[6].isValid, false)
|
||||
})
|
||||
})
|
||||
|
||||
describe("#balancesForAddress", () => {
|
||||
@@ -634,6 +726,94 @@ describe(`#SLP`, () => {
|
||||
assert.equal(result.isValid, true)
|
||||
})
|
||||
})
|
||||
|
||||
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")
|
||||
})
|
||||
})
|
||||
|
||||
describe("#validateTxid3", () => {
|
||||
it("should invalidate a known invalid TXID", async () => {
|
||||
const txid =
|
||||
"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.equal(result[0].txid, txid)
|
||||
|
||||
assert.property(result[0], "valid")
|
||||
assert.equal(result[0].valid, null)
|
||||
})
|
||||
|
||||
it("should validate a known valid TXID", async () => {
|
||||
const txid =
|
||||
"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.equal(result[0].txid, txid)
|
||||
|
||||
assert.property(result[0], "valid")
|
||||
assert.equal(result[0].valid, true)
|
||||
})
|
||||
|
||||
it("should handle a mix of valid, invalid, and non-SLP txs", async () => {
|
||||
const txids = [
|
||||
// Malformed SLP tx
|
||||
"f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a",
|
||||
// Normal TX (non-SLP)
|
||||
"01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0",
|
||||
// Valid PSF SLP tx
|
||||
"daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd",
|
||||
// Valid SLP token not in whitelist
|
||||
"3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488",
|
||||
// Unprocessed SLP TX
|
||||
// "a0d6406eecfd8634158efa9314ff15b4cbf451938e9dc7b5678c46b41eabc6ed" // Mint baton
|
||||
"402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019"
|
||||
]
|
||||
|
||||
const result = await bchjs.SLP.Utils.validateTxid3(txids)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
})
|
||||
|
||||
describe("#validateTxid", () => {
|
||||
it("should handle a mix of valid, invalid, and non-SLP txs", async () => {
|
||||
const txids = [
|
||||
// Malformed SLP tx
|
||||
"f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a",
|
||||
// Normal TX (non-SLP)
|
||||
"01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0",
|
||||
// Valid PSF SLP tx
|
||||
"daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd",
|
||||
// Valid SLP token not in whitelist
|
||||
"3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488",
|
||||
// Unprocessed SLP TX
|
||||
// "a0d6406eecfd8634158efa9314ff15b4cbf451938e9dc7b5678c46b41eabc6ed"
|
||||
// Token send on BCHN network.
|
||||
"402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019",
|
||||
// Token send on ABC network.
|
||||
"336bfe2168aac4c3303508a9e8548a0d33797a83b85b76a12d845c8d6674f79d"
|
||||
]
|
||||
|
||||
const result = await bchjs.SLP.Utils.validateTxid(txids)
|
||||
console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("#tokentype1", () => {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
export RESTURL=https://bchn.fullstack.cash/v3/
|
||||
#export RESTURL=http://localhost:3000/v3/
|
||||
# export RESTURL=https://bchn.fullstack.cash/v4/
|
||||
#export RESTURL=http://localhost:3000/v4/
|
||||
#export IS_USING_FREE_TIER=true
|
||||
|
||||
cd test/integration/bchn/
|
||||
mocha --timeout 30000 blockchain.js control.js encryption.js electrumx.js ninsight.js openbazaar.js price.js rawtransaction.js slp.js util.js
|
||||
#mocha --timeout 30000 slp.js
|
||||
|
||||
@@ -8,11 +8,11 @@ const assert = chai.assert
|
||||
|
||||
const RESTURL = process.env.RESTURL
|
||||
? process.env.RESTURL
|
||||
: `https://testnet3.fullstack.cash/v3/`
|
||||
: `https://testnet3.fullstack.cash/v4/`
|
||||
// if (process.env.RESTURL) RESTURL = process.env.RESTURL
|
||||
|
||||
const BCHJS = require("../../../src/bch-js")
|
||||
// const bchjs = new BCHJS({ restURL: `https://testnet.bchjs.cash/v3/` })
|
||||
// const bchjs = new BCHJS({ restURL: `https://testnet.bchjs.cash/v4/` })
|
||||
const bchjs = new BCHJS({ restURL: RESTURL, apiToken: process.env.BCHJSTOKEN })
|
||||
// const bchjs = new BCHJS({ restURL: RESTURL })
|
||||
//const axios = require("axios")
|
||||
|
||||
@@ -12,11 +12,11 @@ const assert = chai.assert
|
||||
|
||||
const RESTURL = process.env.RESTURL
|
||||
? process.env.RESTURL
|
||||
: "https://testnet3.fullstack.cash/v3/"
|
||||
: "https://testnet3.fullstack.cash/v4/"
|
||||
// if (process.env.RESTURL) RESTURL = process.env.RESTURL
|
||||
|
||||
const BCHJS = require("../../../src/bch-js")
|
||||
// const bchjs = new BCHJS({ restURL: `https://testnet.bchjs.cash/v3/` })
|
||||
// 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.
|
||||
|
||||
@@ -7,7 +7,7 @@ const assert = chai.assert
|
||||
|
||||
const RESTURL = process.env.RESTURL
|
||||
? process.env.RESTURL
|
||||
: `https://testnet3.fullstack.cash/v3/`
|
||||
: `https://testnet3.fullstack.cash/v4/`
|
||||
|
||||
const BCHJS = require("../../../src/bch-js")
|
||||
const bchjs = new BCHJS({ restURL: RESTURL, apiToken: process.env.BCHJSTOKEN })
|
||||
|
||||
@@ -4,7 +4,7 @@ const sinon = require("sinon")
|
||||
|
||||
const RESTURL = process.env.RESTURL
|
||||
? process.env.RESTURL
|
||||
: `https://testnet3.fullstack.cash/v3/`
|
||||
: `https://testnet3.fullstack.cash/v4/`
|
||||
|
||||
const BCHJS = require("../../../src/bch-js")
|
||||
const bchjs = new BCHJS({ restURL: RESTURL, apiToken: process.env.BCHJSTOKEN })
|
||||
|
||||
@@ -10,11 +10,11 @@ const assert = chai.assert
|
||||
|
||||
const RESTURL = process.env.RESTURL
|
||||
? process.env.RESTURL
|
||||
: `https://testnet3.fullstack.cash/v3/`
|
||||
: `https://testnet3.fullstack.cash/v4/`
|
||||
// if (process.env.RESTURL) RESTURL = process.env.RESTURL
|
||||
|
||||
const BCHJS = require("../../../src/bch-js")
|
||||
// const bchjs = new BCHJS({ restURL: `https://testnet.bchjs.cash/v3/` })
|
||||
// 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.
|
||||
|
||||
@@ -7,11 +7,11 @@ const assert = chai.assert
|
||||
|
||||
const RESTURL = process.env.RESTURL
|
||||
? process.env.RESTURL
|
||||
: `https://testnet3.fullstack.cash/v3/`
|
||||
: `https://testnet3.fullstack.cash/v4/`
|
||||
// if (process.env.RESTURL) RESTURL = process.env.RESTURL
|
||||
|
||||
const BCHJS = require("../../../src/bch-js")
|
||||
// const bchjs = new BCHJS({ restURL: `https://testnet.bchjs.cash/v3/` })
|
||||
// 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.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
export RESTURL=https://free-test.fullstack.cash/v3/
|
||||
export RESTURL=https://free-test.fullstack.cash/v4/
|
||||
export NETWORK=testnet
|
||||
export IS_USING_FREE_TIER=true
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@ const assert = chai.assert
|
||||
|
||||
const RESTURL = process.env.RESTURL
|
||||
? process.env.RESTURL
|
||||
: `https://testnet3.fullstack.cash/v3/`
|
||||
: `https://testnet3.fullstack.cash/v4/`
|
||||
// if (process.env.RESTURL) RESTURL = process.env.RESTURL
|
||||
|
||||
const BCHJS = require("../../../src/bch-js")
|
||||
// const bchjs = new BCHJS({ restURL: `https://testnet.bchjs.cash/v3/` })
|
||||
// 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.
|
||||
|
||||
+781
-751
File diff suppressed because it is too large
Load Diff
@@ -1,25 +0,0 @@
|
||||
const chai = require("chai")
|
||||
const assert = chai.assert
|
||||
const BCHJS = require("../../src/bch-js")
|
||||
|
||||
// Used for debugging and iterrogating JS objects.
|
||||
const util = require("util")
|
||||
util.inspect.defaultOptions = { depth: 1 }
|
||||
|
||||
describe(`#BitboxShim`, () => {
|
||||
it("should create the shim library", () => {
|
||||
const BitboxShim = BCHJS.BitboxShim()
|
||||
const bitbox = new BitboxShim()
|
||||
|
||||
//console.log(`bitbox.Address: ${util.inspect(bitbox.Address)}`)
|
||||
|
||||
assert.hasAnyKeys(bitbox.Address, [
|
||||
// "details",
|
||||
// "utxo",
|
||||
// "unconfirmed",
|
||||
// "transactions",
|
||||
// "toLegacyAddress"
|
||||
"restURL"
|
||||
])
|
||||
})
|
||||
})
|
||||
+37
-37
@@ -1,7 +1,13 @@
|
||||
const fixtures = require("./fixtures/bitcoincash.json")
|
||||
// Public npm libraries
|
||||
const assert = require("assert")
|
||||
|
||||
// Mocks
|
||||
const fixtures = require("./fixtures/bitcoincash.json")
|
||||
|
||||
// Unit under test (uut)
|
||||
const BCHJS = require("../../src/bch-js")
|
||||
const bchjs = new BCHJS()
|
||||
// const bchjs = new BCHJS()
|
||||
let bchjs
|
||||
|
||||
// TODO
|
||||
// 1. generate testnet p2sh
|
||||
@@ -20,28 +26,26 @@ const bchjs = new BCHJS()
|
||||
// 6. More error test cases.
|
||||
|
||||
describe("#BitcoinCash", () => {
|
||||
beforeEach(() => {
|
||||
bchjs = new BCHJS()
|
||||
})
|
||||
|
||||
describe("price conversion", () => {
|
||||
describe("#toBitcoinCash", () => {
|
||||
it("should exercise toBitcoinCash", () => {
|
||||
fixtures.conversion.toBCH.satoshis.forEach(satoshi => {
|
||||
it(`should convert ${satoshi[0]} Satoshis to ${
|
||||
satoshi[1]
|
||||
} $BCH`, () => {
|
||||
it(`should convert ${satoshi[0]} Satoshis to ${satoshi[1]} $BCH`, () => {
|
||||
assert.equal(bchjs.BitcoinCash.toBitcoinCash(satoshi[0]), satoshi[1])
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.conversion.toBCH.strings.forEach(satoshi => {
|
||||
it(`should convert "${satoshi[0]}" Satoshis as a string to ${
|
||||
satoshi[1]
|
||||
} $BCH`, () => {
|
||||
it(`should convert "${satoshi[0]}" Satoshis as a string to ${satoshi[1]} $BCH`, () => {
|
||||
assert.equal(bchjs.BitcoinCash.toBitcoinCash(satoshi[0]), satoshi[1])
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.conversion.toBCH.not.forEach(bch => {
|
||||
it(`converts ${bch[0]} to Bitcoin Cash, not to ${
|
||||
bch[1]
|
||||
} Satoshi`, () => {
|
||||
it(`converts ${bch[0]} to Bitcoin Cash, not to ${bch[1]} Satoshi`, () => {
|
||||
assert.notEqual(bchjs.BitcoinCash.toBitcoinCash(bch[0]), bch[1])
|
||||
})
|
||||
})
|
||||
@@ -53,7 +57,7 @@ describe("#BitcoinCash", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("#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])
|
||||
@@ -61,17 +65,13 @@ describe("#BitcoinCash", () => {
|
||||
})
|
||||
|
||||
fixtures.conversion.toSatoshi.strings.forEach(bch => {
|
||||
it(`should convert "${bch[0]}" $BCH as a string to ${
|
||||
bch[1]
|
||||
} Satoshis`, () => {
|
||||
it(`should convert "${bch[0]}" $BCH as a string to ${bch[1]} Satoshis`, () => {
|
||||
assert.equal(bchjs.BitcoinCash.toSatoshi(bch[0]), bch[1])
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.conversion.toSatoshi.not.forEach(satoshi => {
|
||||
it(`converts ${satoshi[0]} to Satoshi, not to ${
|
||||
satoshi[1]
|
||||
} Bitcoin Cash`, () => {
|
||||
it(`converts ${satoshi[0]} to Satoshi, not to ${satoshi[1]} Bitcoin Cash`, () => {
|
||||
assert.notEqual(bchjs.BitcoinCash.toSatoshi(satoshi[0]), satoshi[1])
|
||||
})
|
||||
})
|
||||
@@ -83,7 +83,7 @@ describe("#BitcoinCash", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("#satsToBits", () => {
|
||||
it("should exercise satsToBits", () => {
|
||||
fixtures.conversion.satsToBits.bch.forEach(bch => {
|
||||
it(`should convert ${bch[0]} BCH to ${bch[1]} bits`, () => {
|
||||
assert.equal(
|
||||
@@ -94,9 +94,7 @@ describe("#BitcoinCash", () => {
|
||||
})
|
||||
|
||||
fixtures.conversion.satsToBits.strings.forEach(bch => {
|
||||
it(`should convert "${bch[0]}" BCH as a string to ${
|
||||
bch[1]
|
||||
} bits`, () => {
|
||||
it(`should convert "${bch[0]}" BCH as a string to ${bch[1]} bits`, () => {
|
||||
assert.equal(
|
||||
bchjs.BitcoinCash.satsToBits(bchjs.BitcoinCash.toSatoshi(bch[0])),
|
||||
bch[1]
|
||||
@@ -121,7 +119,7 @@ describe("#BitcoinCash", () => {
|
||||
})
|
||||
|
||||
describe("sign and verify messages", () => {
|
||||
describe("#signMessageWithPrivKey", () => {
|
||||
it("should exercise signMessageWithPrivKey", () => {
|
||||
fixtures.signatures.sign.forEach(sign => {
|
||||
it(`should sign a message w/ ${sign.network} ${sign.privateKeyWIF}`, () => {
|
||||
const privateKeyWIF = sign.privateKeyWIF
|
||||
@@ -135,7 +133,7 @@ describe("#BitcoinCash", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("#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(
|
||||
@@ -149,22 +147,24 @@ describe("#BitcoinCash", () => {
|
||||
})
|
||||
})
|
||||
|
||||
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}`, () => {
|
||||
assert.equal(
|
||||
bchjs.BitcoinCash.verifyMessage(
|
||||
legacyAddress,
|
||||
sign.signature,
|
||||
sign.message
|
||||
),
|
||||
true
|
||||
)
|
||||
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}`, () => {
|
||||
assert.equal(
|
||||
bchjs.BitcoinCash.verifyMessage(
|
||||
legacyAddress,
|
||||
sign.signature,
|
||||
sign.message
|
||||
),
|
||||
true
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.signatures.verify.forEach(sign => {
|
||||
const legacyAddress = bchjs.Address.toLegacyAddress(sign.address)
|
||||
// const legacyAddress = bchjs.Address.toLegacyAddress(sign.address)
|
||||
it(`should not verify an invalid signed message from ${sign.network} cashaddr address ${sign.address}`, () => {
|
||||
assert.equal(
|
||||
bchjs.BitcoinCash.verifyMessage(
|
||||
|
||||
+11
-4
@@ -1,13 +1,20 @@
|
||||
// Public npm libraries.
|
||||
const assert = require("assert")
|
||||
|
||||
const BCHJS = require("../../src/bch-js")
|
||||
const bchjs = new BCHJS()
|
||||
|
||||
const Buffer = require("safe-buffer").Buffer
|
||||
|
||||
// Mocks
|
||||
const fixtures = require("./fixtures/ecpair.json")
|
||||
|
||||
// Unit under test (uut)
|
||||
const BCHJS = require("../../src/bch-js")
|
||||
// const bchjs = new BCHJS()
|
||||
let bchjs
|
||||
|
||||
describe("#ECPair", () => {
|
||||
beforeEach(() => {
|
||||
bchjs = new BCHJS()
|
||||
})
|
||||
|
||||
describe("#fromWIF", () => {
|
||||
fixtures.fromWIF.forEach(fixture => {
|
||||
it(`should create ECPair from WIF ${fixture.privateKeyWIF}`, () => {
|
||||
|
||||
@@ -1107,6 +1107,89 @@ const txDetailsSLPNftGenesis = {
|
||||
blocktime: 1591329189
|
||||
}
|
||||
|
||||
const mockWhitelist = [
|
||||
{
|
||||
name: "USDH",
|
||||
tokenId: "c4b0d62156b3fa5c8f3436079b5394f7edc1bef5dc1cd2f9d0c4d46f82cca479"
|
||||
},
|
||||
{
|
||||
name: "SPICE",
|
||||
tokenId: "4de69e374a8ed21cbddd47f2338cc0f479dc58daa2bbe11cd604ca488eca0ddf"
|
||||
},
|
||||
{
|
||||
name: "PSF",
|
||||
tokenId: "38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0"
|
||||
},
|
||||
{
|
||||
name: "TROUT",
|
||||
tokenId: "a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2"
|
||||
},
|
||||
{
|
||||
name: "PSFTEST",
|
||||
tokenId: "d0ef4de95b78222bfee2326ab11382f4439aa0855936e2fe6ac129a8d778baa0"
|
||||
}
|
||||
]
|
||||
|
||||
const mockValidateTxid3Valid = [
|
||||
{
|
||||
txid: "daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd",
|
||||
valid: true
|
||||
}
|
||||
]
|
||||
|
||||
const mockValidateTxid3Invalid = [
|
||||
{
|
||||
txid: "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a",
|
||||
valid: null
|
||||
}
|
||||
]
|
||||
|
||||
const mockValidateTxidArray = [
|
||||
{
|
||||
txid: "daf4d8b8045e7a90b7af81bfe2370178f687da0e545511bce1c9ae539eba5ffd",
|
||||
valid: true
|
||||
},
|
||||
{
|
||||
txid: "3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488",
|
||||
valid: true
|
||||
},
|
||||
{
|
||||
txid: "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a",
|
||||
valid: false
|
||||
},
|
||||
{
|
||||
txid: "01cdaec2f8b311fc2d6ecc930247bd45fa696dc204ab684596e281fe1b06c1f0",
|
||||
valid: false
|
||||
}
|
||||
]
|
||||
|
||||
const whitelist = [
|
||||
{
|
||||
name: "USDH",
|
||||
tokenId: "c4b0d62156b3fa5c8f3436079b5394f7edc1bef5dc1cd2f9d0c4d46f82cca479"
|
||||
},
|
||||
{
|
||||
name: "SPICE",
|
||||
tokenId: "4de69e374a8ed21cbddd47f2338cc0f479dc58daa2bbe11cd604ca488eca0ddf"
|
||||
},
|
||||
{
|
||||
name: "PSF",
|
||||
tokenId: "38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0"
|
||||
},
|
||||
{
|
||||
name: "TROUT",
|
||||
tokenId: "a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2"
|
||||
},
|
||||
{
|
||||
name: "PSFTEST",
|
||||
tokenId: "d0ef4de95b78222bfee2326ab11382f4439aa0855936e2fe6ac129a8d778baa0"
|
||||
},
|
||||
{
|
||||
name: "TOK-CH",
|
||||
tokenId: "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7"
|
||||
}
|
||||
]
|
||||
|
||||
module.exports = {
|
||||
mockList,
|
||||
mockToken,
|
||||
@@ -1131,5 +1214,9 @@ module.exports = {
|
||||
mockTxDetails,
|
||||
mockDualValidation,
|
||||
mockDualOpData,
|
||||
mockInvalidSlpSend
|
||||
mockInvalidSlpSend,
|
||||
mockWhitelist,
|
||||
mockValidateTxid3Valid,
|
||||
mockValidateTxid3Invalid,
|
||||
whitelist
|
||||
}
|
||||
|
||||
+10
-2
@@ -1,10 +1,18 @@
|
||||
// Public npm libraries
|
||||
const assert = require("assert")
|
||||
const axios = require("axios")
|
||||
const BCHJS = require("../../src/bch-js")
|
||||
const bchjs = new BCHJS()
|
||||
const sinon = require("sinon")
|
||||
|
||||
// Unit under test (uut)
|
||||
const BCHJS = require("../../src/bch-js")
|
||||
// const bchjs = new BCHJS()
|
||||
let bchjs
|
||||
|
||||
describe("#Generating", () => {
|
||||
beforeEach(() => {
|
||||
bchjs = new BCHJS()
|
||||
})
|
||||
|
||||
describe("#generateToAddress", () => {
|
||||
let sandbox
|
||||
beforeEach(() => (sandbox = sinon.createSandbox()))
|
||||
|
||||
+62
-49
@@ -1,11 +1,20 @@
|
||||
const fixtures = require("./fixtures/hdnode.json")
|
||||
const slpFixtures = require("./fixtures/slp/address.json")
|
||||
// Public npm libraries
|
||||
const assert = require("assert")
|
||||
const BCHJS = require("../../src/bch-js")
|
||||
const bchjs = new BCHJS()
|
||||
const Buffer = require("safe-buffer").Buffer
|
||||
|
||||
// Mocks
|
||||
const fixtures = require("./fixtures/hdnode.json")
|
||||
const slpFixtures = require("./fixtures/slp/address.json")
|
||||
|
||||
// Unit under test (uut)
|
||||
const BCHJS = require("../../src/bch-js")
|
||||
let bchjs
|
||||
|
||||
describe("#HDNode", () => {
|
||||
beforeEach(() => {
|
||||
bchjs = new BCHJS()
|
||||
})
|
||||
|
||||
describe("#fromSeed", () => {
|
||||
fixtures.fromSeed.forEach(mnemonic => {
|
||||
it(`should create an HDNode from root seed buffer`, async () => {
|
||||
@@ -178,71 +187,75 @@ describe("#HDNode", () => {
|
||||
})
|
||||
|
||||
describe("#fromXPriv", () => {
|
||||
fixtures.fromXPriv.forEach(fixture => {
|
||||
const hdNode = bchjs.HDNode.fromXPriv(fixture.xpriv)
|
||||
it(`should create HDNode from xpriv ${fixture.xpriv}`, () => {
|
||||
assert.notEqual(hdNode, null)
|
||||
})
|
||||
it("should exercise fromXPriv", () => {
|
||||
fixtures.fromXPriv.forEach(fixture => {
|
||||
const hdNode = bchjs.HDNode.fromXPriv(fixture.xpriv)
|
||||
it(`should create HDNode from xpriv ${fixture.xpriv}`, () => {
|
||||
assert.notEqual(hdNode, null)
|
||||
})
|
||||
|
||||
it(`should export xpriv ${fixture.xpriv}`, () => {
|
||||
assert.equal(bchjs.HDNode.toXPriv(hdNode), fixture.xpriv)
|
||||
})
|
||||
it(`should export xpriv ${fixture.xpriv}`, () => {
|
||||
assert.equal(bchjs.HDNode.toXPriv(hdNode), fixture.xpriv)
|
||||
})
|
||||
|
||||
it(`should export xpub ${fixture.xpub}`, () => {
|
||||
assert.equal(bchjs.HDNode.toXPub(hdNode), fixture.xpub)
|
||||
})
|
||||
it(`should export xpub ${fixture.xpub}`, () => {
|
||||
assert.equal(bchjs.HDNode.toXPub(hdNode), fixture.xpub)
|
||||
})
|
||||
|
||||
it(`should export legacy address ${fixture.legacy}`, () => {
|
||||
assert.equal(bchjs.HDNode.toLegacyAddress(hdNode), fixture.legacy)
|
||||
})
|
||||
it(`should export legacy address ${fixture.legacy}`, () => {
|
||||
assert.equal(bchjs.HDNode.toLegacyAddress(hdNode), fixture.legacy)
|
||||
})
|
||||
|
||||
it(`should export cashaddress ${fixture.cashaddress}`, () => {
|
||||
assert.equal(bchjs.HDNode.toCashAddress(hdNode), fixture.cashaddress)
|
||||
})
|
||||
it(`should export cashaddress ${fixture.cashaddress}`, () => {
|
||||
assert.equal(bchjs.HDNode.toCashAddress(hdNode), fixture.cashaddress)
|
||||
})
|
||||
|
||||
it(`should export regtest cashaddress ${fixture.regtestaddress}`, () => {
|
||||
assert.equal(
|
||||
bchjs.HDNode.toCashAddress(hdNode, true),
|
||||
fixture.regtestaddress
|
||||
)
|
||||
})
|
||||
it(`should export regtest cashaddress ${fixture.regtestaddress}`, () => {
|
||||
assert.equal(
|
||||
bchjs.HDNode.toCashAddress(hdNode, true),
|
||||
fixture.regtestaddress
|
||||
)
|
||||
})
|
||||
|
||||
it(`should export privateKeyWIF ${fixture.privateKeyWIF}`, () => {
|
||||
assert.equal(bchjs.HDNode.toWIF(hdNode), fixture.privateKeyWIF)
|
||||
it(`should export privateKeyWIF ${fixture.privateKeyWIF}`, () => {
|
||||
assert.equal(bchjs.HDNode.toWIF(hdNode), fixture.privateKeyWIF)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("#fromXPub", () => {
|
||||
fixtures.fromXPub.forEach(fixture => {
|
||||
const hdNode = bchjs.HDNode.fromXPub(fixture.xpub)
|
||||
it(`should create HDNode from xpub ${fixture.xpub}`, () => {
|
||||
assert.notEqual(hdNode, null)
|
||||
})
|
||||
it("should exercise fromXPub", () => {
|
||||
fixtures.fromXPub.forEach(fixture => {
|
||||
const hdNode = bchjs.HDNode.fromXPub(fixture.xpub)
|
||||
it(`should create HDNode from xpub ${fixture.xpub}`, () => {
|
||||
assert.notEqual(hdNode, null)
|
||||
})
|
||||
|
||||
it(`should export xpub ${fixture.xpub}`, () => {
|
||||
assert.equal(bchjs.HDNode.toXPub(hdNode), fixture.xpub)
|
||||
})
|
||||
it(`should export xpub ${fixture.xpub}`, () => {
|
||||
assert.equal(bchjs.HDNode.toXPub(hdNode), fixture.xpub)
|
||||
})
|
||||
|
||||
it(`should export legacy address ${fixture.legacy}`, () => {
|
||||
assert.equal(bchjs.HDNode.toLegacyAddress(hdNode), fixture.legacy)
|
||||
})
|
||||
it(`should export legacy address ${fixture.legacy}`, () => {
|
||||
assert.equal(bchjs.HDNode.toLegacyAddress(hdNode), fixture.legacy)
|
||||
})
|
||||
|
||||
it(`should export cashaddress ${fixture.cashaddress}`, () => {
|
||||
assert.equal(bchjs.HDNode.toCashAddress(hdNode), fixture.cashaddress)
|
||||
})
|
||||
it(`should export cashaddress ${fixture.cashaddress}`, () => {
|
||||
assert.equal(bchjs.HDNode.toCashAddress(hdNode), fixture.cashaddress)
|
||||
})
|
||||
|
||||
it(`should export regtest cashaddress ${fixture.regtestaddress}`, () => {
|
||||
assert.equal(
|
||||
bchjs.HDNode.toCashAddress(hdNode, true),
|
||||
fixture.regtestaddress
|
||||
)
|
||||
it(`should export regtest cashaddress ${fixture.regtestaddress}`, () => {
|
||||
assert.equal(
|
||||
bchjs.HDNode.toCashAddress(hdNode, true),
|
||||
fixture.regtestaddress
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("#bip32", () => {
|
||||
describe("create accounts and addresses", () => {
|
||||
it("should create accounts and addresses", () => {
|
||||
fixtures.accounts.forEach(async fixture => {
|
||||
const seedBuffer = await bchjs.Mnemonic.toSeed(fixture.mnemonic)
|
||||
console.log(`seedBuffer: ${seedBuffer.toString()}`)
|
||||
|
||||
+9
-2
@@ -1,10 +1,17 @@
|
||||
// Public npm libraries
|
||||
const assert = require("assert")
|
||||
const axios = require("axios")
|
||||
const BCHJS = require("../../src/bch-js")
|
||||
const bchjs = new BCHJS()
|
||||
const sinon = require("sinon")
|
||||
|
||||
// Unit under test (uut)
|
||||
const BCHJS = require("../../src/bch-js")
|
||||
let bchjs
|
||||
|
||||
describe("#Mining", () => {
|
||||
beforeEach(() => {
|
||||
bchjs = new BCHJS()
|
||||
})
|
||||
|
||||
describe("#getBlockTemplate", () => {
|
||||
let sandbox
|
||||
beforeEach(() => (sandbox = sinon.createSandbox()))
|
||||
|
||||
+12
-1
@@ -5,7 +5,7 @@ const sinon = require("sinon")
|
||||
const mockDataLib = require("./fixtures/price-mocks")
|
||||
let mockData
|
||||
|
||||
describe("#Price", () => {
|
||||
describe("#price", () => {
|
||||
let sandbox
|
||||
let bchjs
|
||||
|
||||
@@ -56,4 +56,15 @@ describe("#Price", () => {
|
||||
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 } })
|
||||
|
||||
const result = await bchjs.Price.getBchaUsd()
|
||||
// console.log(result)
|
||||
|
||||
assert.isNumber(result)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,23 +1,28 @@
|
||||
/*
|
||||
TODO:
|
||||
-Replace old unit tests mocking axios with the more generalized nock library.
|
||||
See the sendRawTransaction test for an example.
|
||||
-Create a mocking library of data to compare unit and integration tests.
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const assert = require("assert")
|
||||
const axios = require("axios")
|
||||
const BCHJS = require("../../src/bch-js")
|
||||
const bchjs = new BCHJS()
|
||||
|
||||
const sinon = require("sinon")
|
||||
const nock = require("nock") // HTTP mocking
|
||||
// const nock = require("nock") // HTTP mocking
|
||||
|
||||
// Unit under test (uut)
|
||||
const BCHJS = require("../../src/bch-js")
|
||||
// const bchjs = new BCHJS()
|
||||
let bchjs
|
||||
|
||||
// Used for debugging
|
||||
const util = require("util")
|
||||
util.inspect.defaultOptions = { depth: 1 }
|
||||
// const util = require("util")
|
||||
// util.inspect.defaultOptions = { depth: 1 }
|
||||
|
||||
describe("#RawTransactions", () => {
|
||||
beforeEach(() => {
|
||||
bchjs = new BCHJS()
|
||||
})
|
||||
|
||||
describe("#decodeRawTransaction", () => {
|
||||
let sandbox
|
||||
beforeEach(() => (sandbox = sinon.createSandbox()))
|
||||
@@ -111,19 +116,20 @@ describe("#RawTransactions", () => {
|
||||
assert.equal(data, result)
|
||||
})
|
||||
|
||||
it("should send an array of raw transactions", async () => {
|
||||
const data = "Error: transaction already in block chain"
|
||||
|
||||
// Mock the http call to rest.bitcoin.com
|
||||
nock(`${bchjs.RawTransactions.restURL}`)
|
||||
.post(uri => uri.includes(`/`))
|
||||
.reply(200, { data: data })
|
||||
|
||||
const result = await bchjs.RawTransactions.sendRawTransaction([
|
||||
"020000000160d663961c63c7f0a07f22ec07b8f55b3935bfdbed8b1d8454916e8932fbf109010000006b4830450221008479fab4cfdcb111833d250a43f98ac26d43272b7a29cb1b9a0491eae5c44b3502203448b17253632395c29a7d62058bbfe93efb20fc8636ba6837002d464195aec04121029123258f7cdcd45b864066bcaa9b71f24d5ed1fa1dd36eaf107d8432b5014658ffffffff016d180000000000001976a91479d3297d1823149f4ec61df31d19f2fad5390c0288ac00000000"
|
||||
])
|
||||
|
||||
assert.equal(data, result.data)
|
||||
})
|
||||
// it("should send an array of raw transactions", async () => {
|
||||
// const data = "Error: transaction already in block chain"
|
||||
//
|
||||
// // Mock the http call to rest.bitcoin.com
|
||||
// // nock(`${bchjs.RawTransactions.restURL}`)
|
||||
// // .post(uri => uri.includes(`/`))
|
||||
// // .reply(200, { data: data })
|
||||
// sandbox.stub(bchjs, "axios").resolves({ data: data })
|
||||
//
|
||||
// const result = await bchjs.RawTransactions.sendRawTransaction([
|
||||
// "020000000160d663961c63c7f0a07f22ec07b8f55b3935bfdbed8b1d8454916e8932fbf109010000006b4830450221008479fab4cfdcb111833d250a43f98ac26d43272b7a29cb1b9a0491eae5c44b3502203448b17253632395c29a7d62058bbfe93efb20fc8636ba6837002d464195aec04121029123258f7cdcd45b864066bcaa9b71f24d5ed1fa1dd36eaf107d8432b5014658ffffffff016d180000000000001976a91479d3297d1823149f4ec61df31d19f2fad5390c0288ac00000000"
|
||||
// ])
|
||||
//
|
||||
// assert.equal(data, result.data)
|
||||
// })
|
||||
})
|
||||
})
|
||||
|
||||
+31
-20
@@ -1,10 +1,19 @@
|
||||
const fixtures = require("./fixtures/script.json")
|
||||
// Public npm libraries
|
||||
const assert = require("assert")
|
||||
const BCHJS = require("../../src/bch-js")
|
||||
const bchjs = new BCHJS()
|
||||
const Buffer = require("safe-buffer").Buffer
|
||||
|
||||
// Mocks
|
||||
const fixtures = require("./fixtures/script.json")
|
||||
|
||||
// Unit under test (uut)
|
||||
const BCHJS = require("../../src/bch-js")
|
||||
let bchjs
|
||||
|
||||
describe("#Script", () => {
|
||||
beforeEach(() => {
|
||||
bchjs = new BCHJS()
|
||||
})
|
||||
|
||||
describe("#decode", () => {
|
||||
describe("P2PKH scriptSig", () => {
|
||||
fixtures.decodeScriptSig.forEach(fixture => {
|
||||
@@ -321,25 +330,27 @@ describe("#Script", () => {
|
||||
})
|
||||
|
||||
describe("#pubKeyHashOutputTemplate", () => {
|
||||
fixtures.pubKeyHashOutputTemplate.forEach(fixture => {
|
||||
const node = bchjs.HDNode.fromXPriv(fixture.xpriv)
|
||||
const identifier = bchjs.HDNode.toIdentifier(node)
|
||||
it(`should encode pubKeyHash output`, () => {
|
||||
const buf = bchjs.Script.pubKeyHash.output.encode(identifier)
|
||||
assert.equal(buf.toString("hex"), fixture.hex)
|
||||
})
|
||||
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`, () => {
|
||||
const buf = bchjs.Script.pubKeyHash.output.encode(identifier)
|
||||
assert.equal(buf.toString("hex"), fixture.hex)
|
||||
})
|
||||
|
||||
it(`should decode pubKeyHash output`, () => {
|
||||
const buf = bchjs.Script.pubKeyHash.output.decode(
|
||||
Buffer.from(`${fixture.hex}`, "hex")
|
||||
)
|
||||
assert.equal(buf.toString("hex"), identifier.toString("hex"))
|
||||
})
|
||||
it(`should decode pubKeyHash output`, () => {
|
||||
const buf = bchjs.Script.pubKeyHash.output.decode(
|
||||
Buffer.from(`${fixture.hex}`, "hex")
|
||||
)
|
||||
assert.equal(buf.toString("hex"), identifier.toString("hex"))
|
||||
})
|
||||
|
||||
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)
|
||||
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)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
+82
-74
@@ -1,7 +1,9 @@
|
||||
const assert = require("assert")
|
||||
|
||||
const slp = require("../../src/slp/slp")
|
||||
const SLP = new slp({ restURL: "http://fakeurl.com/" })
|
||||
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")
|
||||
@@ -86,12 +88,18 @@ const SLP_TESTNET_ADDRESSES_NO_PREFIX = SLP_TESTNET_ADDRESSES.map(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", () => {
|
||||
assert.deepEqual(
|
||||
LEGACY_MAINNET_ADDRESSES.map(address =>
|
||||
SLP.Address.toLegacyAddress(address)
|
||||
slp.Address.toLegacyAddress(address)
|
||||
),
|
||||
LEGACY_MAINNET_ADDRESSES
|
||||
)
|
||||
@@ -100,7 +108,7 @@ describe("#SLP Address", () => {
|
||||
it(`should convert cashAddr to legacyAddr`, async () => {
|
||||
assert.deepEqual(
|
||||
CASH_MAINNET_ADDRESSES.map(address =>
|
||||
SLP.Address.toLegacyAddress(address)
|
||||
slp.Address.toLegacyAddress(address)
|
||||
),
|
||||
LEGACY_MAINNET_ADDRESSES
|
||||
)
|
||||
@@ -109,7 +117,7 @@ describe("#SLP Address", () => {
|
||||
it(`should convert slpAddr to legacyAddr`, async () => {
|
||||
assert.deepEqual(
|
||||
SLP_MAINNET_ADDRESSES.map(address =>
|
||||
SLP.Address.toLegacyAddress(address)
|
||||
slp.Address.toLegacyAddress(address)
|
||||
),
|
||||
LEGACY_MAINNET_ADDRESSES
|
||||
)
|
||||
@@ -120,7 +128,7 @@ describe("#SLP Address", () => {
|
||||
it("should convert mainnet cash address format to itself correctly", () => {
|
||||
assert.deepEqual(
|
||||
CASH_MAINNET_ADDRESSES.map(address =>
|
||||
SLP.Address.toCashAddress(address)
|
||||
slp.Address.toCashAddress(address)
|
||||
),
|
||||
CASH_MAINNET_ADDRESSES
|
||||
)
|
||||
@@ -129,7 +137,7 @@ describe("#SLP Address", () => {
|
||||
it(`should convert legacyAddr to cashAddr`, async () => {
|
||||
assert.deepEqual(
|
||||
LEGACY_MAINNET_ADDRESSES.map(address =>
|
||||
SLP.Address.toCashAddress(address)
|
||||
slp.Address.toCashAddress(address)
|
||||
),
|
||||
CASH_MAINNET_ADDRESSES
|
||||
)
|
||||
@@ -138,7 +146,7 @@ describe("#SLP Address", () => {
|
||||
it(`should convert slpAddr to cashAddr`, async () => {
|
||||
assert.deepEqual(
|
||||
SLP_MAINNET_ADDRESSES.map(address =>
|
||||
SLP.Address.toCashAddress(address)
|
||||
slp.Address.toCashAddress(address)
|
||||
),
|
||||
CASH_MAINNET_ADDRESSES
|
||||
)
|
||||
@@ -149,7 +157,7 @@ describe("#SLP Address", () => {
|
||||
it("should convert mainnet slp address format to itself correctly", () => {
|
||||
assert.deepEqual(
|
||||
SLP_MAINNET_ADDRESSES.map(address =>
|
||||
SLP.Address.toSLPAddress(address)
|
||||
slp.Address.toSLPAddress(address)
|
||||
),
|
||||
SLP_MAINNET_ADDRESSES
|
||||
)
|
||||
@@ -158,7 +166,7 @@ describe("#SLP Address", () => {
|
||||
it(`should convert legacyAddr to slpAddr`, async () => {
|
||||
assert.deepEqual(
|
||||
LEGACY_MAINNET_ADDRESSES.map(address =>
|
||||
SLP.Address.toSLPAddress(address)
|
||||
slp.Address.toSLPAddress(address)
|
||||
),
|
||||
SLP_MAINNET_ADDRESSES
|
||||
)
|
||||
@@ -167,7 +175,7 @@ describe("#SLP Address", () => {
|
||||
it(`should convert cashAddr to slpAddr`, async () => {
|
||||
assert.deepEqual(
|
||||
CASH_MAINNET_ADDRESSES.map(address =>
|
||||
SLP.Address.toSLPAddress(address)
|
||||
slp.Address.toSLPAddress(address)
|
||||
),
|
||||
SLP_MAINNET_ADDRESSES
|
||||
)
|
||||
@@ -178,7 +186,7 @@ describe("#SLP Address", () => {
|
||||
describe("is legacy addr", () => {
|
||||
LEGACY_MAINNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a legacy address`, () => {
|
||||
const isLegacyaddr = SLP.Address.isLegacyAddress(address)
|
||||
const isLegacyaddr = slp.Address.isLegacyAddress(address)
|
||||
assert.equal(isLegacyaddr, true)
|
||||
})
|
||||
})
|
||||
@@ -187,7 +195,7 @@ describe("#SLP Address", () => {
|
||||
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)
|
||||
const isLegacyaddr = slp.Address.isLegacyAddress(address)
|
||||
assert.equal(isLegacyaddr, false)
|
||||
})
|
||||
})
|
||||
@@ -196,7 +204,7 @@ describe("#SLP Address", () => {
|
||||
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)
|
||||
const isLegacyaddr = slp.Address.isLegacyAddress(address)
|
||||
assert.equal(isLegacyaddr, false)
|
||||
})
|
||||
})
|
||||
@@ -207,7 +215,7 @@ describe("#SLP Address", () => {
|
||||
describe("is cashaddr", () => {
|
||||
CASH_MAINNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a cashaddr address`, () => {
|
||||
const isCashaddr = SLP.Address.isCashAddress(address)
|
||||
const isCashaddr = slp.Address.isCashAddress(address)
|
||||
assert.equal(isCashaddr, true)
|
||||
})
|
||||
})
|
||||
@@ -216,7 +224,7 @@ describe("#SLP Address", () => {
|
||||
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)
|
||||
const isCashaddr = slp.Address.isCashAddress(address)
|
||||
assert.equal(isCashaddr, false)
|
||||
})
|
||||
})
|
||||
@@ -225,7 +233,7 @@ describe("#SLP Address", () => {
|
||||
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)
|
||||
const isCashaddr = slp.Address.isCashAddress(address)
|
||||
assert.equal(isCashaddr, false)
|
||||
})
|
||||
})
|
||||
@@ -236,7 +244,7 @@ describe("#SLP Address", () => {
|
||||
describe("is slpaddr", () => {
|
||||
SLP_MAINNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is an slp address`, () => {
|
||||
const isSLPaddr = SLP.Address.isSLPAddress(address)
|
||||
const isSLPaddr = slp.Address.isSLPAddress(address)
|
||||
assert.equal(isSLPaddr, true)
|
||||
})
|
||||
})
|
||||
@@ -245,7 +253,7 @@ describe("#SLP Address", () => {
|
||||
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)
|
||||
const isSLPaddr = slp.Address.isSLPAddress(address)
|
||||
assert.equal(isSLPaddr, false)
|
||||
})
|
||||
})
|
||||
@@ -254,7 +262,7 @@ describe("#SLP Address", () => {
|
||||
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)
|
||||
const isSLPaddr = slp.Address.isSLPAddress(address)
|
||||
assert.equal(isSLPaddr, false)
|
||||
})
|
||||
})
|
||||
@@ -265,7 +273,7 @@ describe("#SLP Address", () => {
|
||||
describe("mainnet legacy addr", () => {
|
||||
LEGACY_MAINNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a mainnet address`, () => {
|
||||
const isMainnetaddr = SLP.Address.isMainnetAddress(address)
|
||||
const isMainnetaddr = slp.Address.isMainnetAddress(address)
|
||||
assert.equal(isMainnetaddr, true)
|
||||
})
|
||||
})
|
||||
@@ -274,7 +282,7 @@ describe("#SLP Address", () => {
|
||||
describe("mainnet cash addr", () => {
|
||||
CASH_MAINNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a mainnet address`, () => {
|
||||
const isMainnetaddr = SLP.Address.isMainnetAddress(address)
|
||||
const isMainnetaddr = slp.Address.isMainnetAddress(address)
|
||||
assert.equal(isMainnetaddr, true)
|
||||
})
|
||||
})
|
||||
@@ -283,7 +291,7 @@ describe("#SLP Address", () => {
|
||||
describe("mainnet slp addr", () => {
|
||||
SLP_MAINNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a mainnet address`, () => {
|
||||
const isMainnetaddr = SLP.Address.isMainnetAddress(address)
|
||||
const isMainnetaddr = slp.Address.isMainnetAddress(address)
|
||||
assert.equal(isMainnetaddr, true)
|
||||
})
|
||||
})
|
||||
@@ -292,7 +300,7 @@ describe("#SLP Address", () => {
|
||||
describe("testnet legacy addr", () => {
|
||||
LEGACY_TESTNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is not a mainnet address`, () => {
|
||||
const isMainnetaddr = SLP.Address.isMainnetAddress(address)
|
||||
const isMainnetaddr = slp.Address.isMainnetAddress(address)
|
||||
assert.equal(isMainnetaddr, false)
|
||||
})
|
||||
})
|
||||
@@ -301,7 +309,7 @@ describe("#SLP Address", () => {
|
||||
describe("testnet cash addr", () => {
|
||||
CASH_TESTNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is not a mainnet address`, () => {
|
||||
const isMainnetaddr = SLP.Address.isMainnetAddress(address)
|
||||
const isMainnetaddr = slp.Address.isMainnetAddress(address)
|
||||
assert.equal(isMainnetaddr, false)
|
||||
})
|
||||
})
|
||||
@@ -310,7 +318,7 @@ describe("#SLP Address", () => {
|
||||
describe("testnet slp addr", () => {
|
||||
SLP_TESTNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is not a mainnet address`, () => {
|
||||
const isMainnetaddr = SLP.Address.isMainnetAddress(address)
|
||||
const isMainnetaddr = slp.Address.isMainnetAddress(address)
|
||||
assert.equal(isMainnetaddr, false)
|
||||
})
|
||||
})
|
||||
@@ -321,7 +329,7 @@ describe("#SLP Address", () => {
|
||||
describe("mainnet legacy addr", () => {
|
||||
MAINNET_P2PKH_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a P2PKH address`, () => {
|
||||
const isP2PKHaddr = SLP.Address.isP2PKHAddress(address)
|
||||
const isP2PKHaddr = slp.Address.isP2PKHAddress(address)
|
||||
assert.equal(isP2PKHaddr, true)
|
||||
})
|
||||
})
|
||||
@@ -332,7 +340,7 @@ describe("#SLP Address", () => {
|
||||
describe("mainnet legacy addr", () => {
|
||||
MAINNET_P2SH_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a P2SH address`, () => {
|
||||
const isP2SHaddr = SLP.Address.isP2SHAddress(address)
|
||||
const isP2SHaddr = slp.Address.isP2SHAddress(address)
|
||||
assert.equal(isP2SHaddr, true)
|
||||
})
|
||||
})
|
||||
@@ -342,21 +350,21 @@ describe("#SLP Address", () => {
|
||||
describe("#detectAddressFormat", () => {
|
||||
LEGACY_MAINNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a legacy address`, () => {
|
||||
const isLegacy = SLP.Address.detectAddressFormat(address)
|
||||
const isLegacy = slp.Address.detectAddressFormat(address)
|
||||
assert.equal(isLegacy, "legacy")
|
||||
})
|
||||
})
|
||||
|
||||
CASH_MAINNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a cash address`, () => {
|
||||
const isCashaddr = SLP.Address.detectAddressFormat(address)
|
||||
const isCashaddr = slp.Address.detectAddressFormat(address)
|
||||
assert.equal(isCashaddr, "cashaddr")
|
||||
})
|
||||
})
|
||||
|
||||
SLP_MAINNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is an slp address`, () => {
|
||||
const isSlpaddr = SLP.Address.detectAddressFormat(address)
|
||||
const isSlpaddr = slp.Address.detectAddressFormat(address)
|
||||
assert.equal(isSlpaddr, "slpaddr")
|
||||
})
|
||||
})
|
||||
@@ -365,21 +373,21 @@ describe("#SLP Address", () => {
|
||||
describe("#detectAddressNetwork", () => {
|
||||
LEGACY_MAINNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a mainnet address`, () => {
|
||||
const isMainnet = SLP.Address.detectAddressNetwork(address)
|
||||
const isMainnet = slp.Address.detectAddressNetwork(address)
|
||||
assert.equal(isMainnet, "mainnet")
|
||||
})
|
||||
})
|
||||
|
||||
CASH_MAINNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a mainnet address`, () => {
|
||||
const isMainnet = SLP.Address.detectAddressNetwork(address)
|
||||
const isMainnet = slp.Address.detectAddressNetwork(address)
|
||||
assert.equal(isMainnet, "mainnet")
|
||||
})
|
||||
})
|
||||
|
||||
SLP_MAINNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a mainnet address`, () => {
|
||||
const isMainnet = SLP.Address.detectAddressNetwork(address)
|
||||
const isMainnet = slp.Address.detectAddressNetwork(address)
|
||||
assert.equal(isMainnet, "mainnet")
|
||||
})
|
||||
})
|
||||
@@ -388,14 +396,14 @@ describe("#SLP Address", () => {
|
||||
describe("#detectAddressType", () => {
|
||||
MAINNET_P2PKH_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a p2pkh address`, () => {
|
||||
const isp2pkh = SLP.Address.detectAddressType(address)
|
||||
const isp2pkh = slp.Address.detectAddressType(address)
|
||||
assert.equal(isp2pkh, "p2pkh")
|
||||
})
|
||||
})
|
||||
|
||||
MAINNET_P2SH_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a p2sh address`, () => {
|
||||
const isp2sh = SLP.Address.detectAddressType(address)
|
||||
const isp2sh = slp.Address.detectAddressType(address)
|
||||
assert.equal(isp2sh, "p2sh")
|
||||
})
|
||||
})
|
||||
@@ -407,7 +415,7 @@ describe("#SLP Address", () => {
|
||||
it("should convert testnet legacy address format to itself correctly", () => {
|
||||
assert.deepEqual(
|
||||
LEGACY_TESTNET_ADDRESSES.map(address =>
|
||||
SLP.Address.toLegacyAddress(address)
|
||||
slp.Address.toLegacyAddress(address)
|
||||
),
|
||||
LEGACY_TESTNET_ADDRESSES
|
||||
)
|
||||
@@ -416,7 +424,7 @@ describe("#SLP Address", () => {
|
||||
it(`should convert cashAddr to legacyAddr`, async () => {
|
||||
assert.deepEqual(
|
||||
CASH_TESTNET_ADDRESSES.map(address =>
|
||||
SLP.Address.toLegacyAddress(address)
|
||||
slp.Address.toLegacyAddress(address)
|
||||
),
|
||||
LEGACY_TESTNET_ADDRESSES
|
||||
)
|
||||
@@ -425,7 +433,7 @@ describe("#SLP Address", () => {
|
||||
it(`should convert slpAddr to legacyAddr`, async () => {
|
||||
assert.deepEqual(
|
||||
SLP_TESTNET_ADDRESSES.map(address =>
|
||||
SLP.Address.toLegacyAddress(address)
|
||||
slp.Address.toLegacyAddress(address)
|
||||
),
|
||||
LEGACY_TESTNET_ADDRESSES
|
||||
)
|
||||
@@ -436,7 +444,7 @@ describe("#SLP Address", () => {
|
||||
it("should convert testnet cash address format to itself correctly", () => {
|
||||
assert.deepEqual(
|
||||
CASH_TESTNET_ADDRESSES.map(address =>
|
||||
SLP.Address.toCashAddress(address)
|
||||
slp.Address.toCashAddress(address)
|
||||
),
|
||||
CASH_TESTNET_ADDRESSES
|
||||
)
|
||||
@@ -445,7 +453,7 @@ describe("#SLP Address", () => {
|
||||
it(`should convert legacyAddr to cashAddr`, async () => {
|
||||
assert.deepEqual(
|
||||
LEGACY_TESTNET_ADDRESSES.map(address =>
|
||||
SLP.Address.toCashAddress(address)
|
||||
slp.Address.toCashAddress(address)
|
||||
),
|
||||
CASH_TESTNET_ADDRESSES
|
||||
)
|
||||
@@ -454,7 +462,7 @@ describe("#SLP Address", () => {
|
||||
it(`should convert slpAddr to cashAddr`, async () => {
|
||||
assert.deepEqual(
|
||||
SLP_TESTNET_ADDRESSES.map(address =>
|
||||
SLP.Address.toCashAddress(address)
|
||||
slp.Address.toCashAddress(address)
|
||||
),
|
||||
CASH_TESTNET_ADDRESSES
|
||||
)
|
||||
@@ -465,7 +473,7 @@ describe("#SLP Address", () => {
|
||||
it("should convert testnet slp address format to itself correctly", () => {
|
||||
assert.deepEqual(
|
||||
SLP_TESTNET_ADDRESSES.map(address =>
|
||||
SLP.Address.toSLPAddress(address)
|
||||
slp.Address.toSLPAddress(address)
|
||||
),
|
||||
SLP_TESTNET_ADDRESSES
|
||||
)
|
||||
@@ -474,7 +482,7 @@ describe("#SLP Address", () => {
|
||||
it(`should convert legacyAddr to slpAddr`, async () => {
|
||||
assert.deepEqual(
|
||||
LEGACY_TESTNET_ADDRESSES.map(address =>
|
||||
SLP.Address.toSLPAddress(address)
|
||||
slp.Address.toSLPAddress(address)
|
||||
),
|
||||
SLP_TESTNET_ADDRESSES
|
||||
)
|
||||
@@ -483,7 +491,7 @@ describe("#SLP Address", () => {
|
||||
it(`should convert cashAddr to slpAddr`, async () => {
|
||||
assert.deepEqual(
|
||||
CASH_TESTNET_ADDRESSES.map(address =>
|
||||
SLP.Address.toSLPAddress(address)
|
||||
slp.Address.toSLPAddress(address)
|
||||
),
|
||||
SLP_TESTNET_ADDRESSES
|
||||
)
|
||||
@@ -494,7 +502,7 @@ describe("#SLP Address", () => {
|
||||
describe("is legacy addr", () => {
|
||||
LEGACY_TESTNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a legacy address`, () => {
|
||||
const isLegacyaddr = SLP.Address.isLegacyAddress(address)
|
||||
const isLegacyaddr = slp.Address.isLegacyAddress(address)
|
||||
assert.equal(isLegacyaddr, true)
|
||||
})
|
||||
})
|
||||
@@ -503,7 +511,7 @@ describe("#SLP Address", () => {
|
||||
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)
|
||||
const isLegacyaddr = slp.Address.isLegacyAddress(address)
|
||||
assert.equal(isLegacyaddr, false)
|
||||
})
|
||||
})
|
||||
@@ -512,7 +520,7 @@ describe("#SLP Address", () => {
|
||||
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)
|
||||
const isLegacyaddr = slp.Address.isLegacyAddress(address)
|
||||
assert.equal(isLegacyaddr, false)
|
||||
})
|
||||
})
|
||||
@@ -523,7 +531,7 @@ describe("#SLP Address", () => {
|
||||
describe("is cashaddr", () => {
|
||||
CASH_TESTNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a cashaddr address`, () => {
|
||||
const isCashaddr = SLP.Address.isCashAddress(address)
|
||||
const isCashaddr = slp.Address.isCashAddress(address)
|
||||
assert.equal(isCashaddr, true)
|
||||
})
|
||||
})
|
||||
@@ -532,7 +540,7 @@ describe("#SLP Address", () => {
|
||||
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)
|
||||
const isCashaddr = slp.Address.isCashAddress(address)
|
||||
assert.equal(isCashaddr, false)
|
||||
})
|
||||
})
|
||||
@@ -541,7 +549,7 @@ describe("#SLP Address", () => {
|
||||
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)
|
||||
const isCashaddr = slp.Address.isCashAddress(address)
|
||||
assert.equal(isCashaddr, false)
|
||||
})
|
||||
})
|
||||
@@ -552,7 +560,7 @@ describe("#SLP Address", () => {
|
||||
describe("is slpaddr", () => {
|
||||
SLP_TESTNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is an slp address`, () => {
|
||||
const isSLPaddr = SLP.Address.isSLPAddress(address)
|
||||
const isSLPaddr = slp.Address.isSLPAddress(address)
|
||||
assert.equal(isSLPaddr, true)
|
||||
})
|
||||
})
|
||||
@@ -561,7 +569,7 @@ describe("#SLP Address", () => {
|
||||
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)
|
||||
const isSLPaddr = slp.Address.isSLPAddress(address)
|
||||
assert.equal(isSLPaddr, false)
|
||||
})
|
||||
})
|
||||
@@ -570,7 +578,7 @@ describe("#SLP Address", () => {
|
||||
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)
|
||||
const isSLPaddr = slp.Address.isSLPAddress(address)
|
||||
assert.equal(isSLPaddr, false)
|
||||
})
|
||||
})
|
||||
@@ -581,7 +589,7 @@ describe("#SLP Address", () => {
|
||||
describe("testnet legacy addr", () => {
|
||||
LEGACY_TESTNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a testnet address`, () => {
|
||||
const isTestnetaddr = SLP.Address.isTestnetAddress(address)
|
||||
const isTestnetaddr = slp.Address.isTestnetAddress(address)
|
||||
assert.equal(isTestnetaddr, true)
|
||||
})
|
||||
})
|
||||
@@ -590,7 +598,7 @@ describe("#SLP Address", () => {
|
||||
describe("testnet cash addr", () => {
|
||||
CASH_TESTNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a testnet address`, () => {
|
||||
const isTestnetaddr = SLP.Address.isTestnetAddress(address)
|
||||
const isTestnetaddr = slp.Address.isTestnetAddress(address)
|
||||
assert.equal(isTestnetaddr, true)
|
||||
})
|
||||
})
|
||||
@@ -599,7 +607,7 @@ describe("#SLP Address", () => {
|
||||
describe("testnet slp addr", () => {
|
||||
SLP_TESTNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a testnet address`, () => {
|
||||
const isTestnetaddr = SLP.Address.isTestnetAddress(address)
|
||||
const isTestnetaddr = slp.Address.isTestnetAddress(address)
|
||||
assert.equal(isTestnetaddr, true)
|
||||
})
|
||||
})
|
||||
@@ -608,7 +616,7 @@ describe("#SLP Address", () => {
|
||||
describe("mainnet legacy addr", () => {
|
||||
LEGACY_MAINNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is not a testnet address`, () => {
|
||||
const isTestnetaddr = SLP.Address.isTestnetAddress(address)
|
||||
const isTestnetaddr = slp.Address.isTestnetAddress(address)
|
||||
assert.equal(isTestnetaddr, false)
|
||||
})
|
||||
})
|
||||
@@ -617,7 +625,7 @@ describe("#SLP Address", () => {
|
||||
describe("mainnet cash addr", () => {
|
||||
CASH_MAINNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is not a testnet address`, () => {
|
||||
const isTestnetaddr = SLP.Address.isTestnetAddress(address)
|
||||
const isTestnetaddr = slp.Address.isTestnetAddress(address)
|
||||
assert.equal(isTestnetaddr, false)
|
||||
})
|
||||
})
|
||||
@@ -626,7 +634,7 @@ describe("#SLP Address", () => {
|
||||
describe("mainnet slp addr", () => {
|
||||
SLP_MAINNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is not a testnet address`, () => {
|
||||
const isTestnetaddr = SLP.Address.isTestnetAddress(address)
|
||||
const isTestnetaddr = slp.Address.isTestnetAddress(address)
|
||||
assert.equal(isTestnetaddr, false)
|
||||
})
|
||||
})
|
||||
@@ -637,7 +645,7 @@ describe("#SLP Address", () => {
|
||||
describe("testnet legacy addr", () => {
|
||||
TESTNET_P2PKH_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a P2PKH address`, () => {
|
||||
const isP2PKHaddr = SLP.Address.isP2PKHAddress(address)
|
||||
const isP2PKHaddr = slp.Address.isP2PKHAddress(address)
|
||||
assert.equal(isP2PKHaddr, true)
|
||||
})
|
||||
})
|
||||
@@ -648,7 +656,7 @@ describe("#SLP Address", () => {
|
||||
describe("testnet legacy addr", () => {
|
||||
TESTNET_P2SH_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a P2SH address`, () => {
|
||||
const isP2SHaddr = SLP.Address.isP2SHAddress(address)
|
||||
const isP2SHaddr = slp.Address.isP2SHAddress(address)
|
||||
assert.equal(isP2SHaddr, true)
|
||||
})
|
||||
})
|
||||
@@ -658,21 +666,21 @@ describe("#SLP Address", () => {
|
||||
describe("#detectAddressFormat", () => {
|
||||
LEGACY_TESTNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a legacy address`, () => {
|
||||
const isLegacy = SLP.Address.detectAddressFormat(address)
|
||||
const isLegacy = slp.Address.detectAddressFormat(address)
|
||||
assert.equal(isLegacy, "legacy")
|
||||
})
|
||||
})
|
||||
|
||||
CASH_TESTNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a cash address`, () => {
|
||||
const isCashaddr = SLP.Address.detectAddressFormat(address)
|
||||
const isCashaddr = slp.Address.detectAddressFormat(address)
|
||||
assert.equal(isCashaddr, "cashaddr")
|
||||
})
|
||||
})
|
||||
|
||||
SLP_TESTNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is an slp address`, () => {
|
||||
const isSlpaddr = SLP.Address.detectAddressFormat(address)
|
||||
const isSlpaddr = slp.Address.detectAddressFormat(address)
|
||||
assert.equal(isSlpaddr, "slpaddr")
|
||||
})
|
||||
})
|
||||
@@ -681,21 +689,21 @@ describe("#SLP Address", () => {
|
||||
describe("#detectAddressNetwork", () => {
|
||||
LEGACY_TESTNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a testnet address`, () => {
|
||||
const isTestnet = SLP.Address.detectAddressNetwork(address)
|
||||
const isTestnet = slp.Address.detectAddressNetwork(address)
|
||||
assert.equal(isTestnet, "testnet")
|
||||
})
|
||||
})
|
||||
|
||||
CASH_TESTNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a testnet address`, () => {
|
||||
const isTestnet = SLP.Address.detectAddressNetwork(address)
|
||||
const isTestnet = slp.Address.detectAddressNetwork(address)
|
||||
assert.equal(isTestnet, "testnet")
|
||||
})
|
||||
})
|
||||
|
||||
SLP_TESTNET_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a testnet address`, () => {
|
||||
const isTestnet = SLP.Address.detectAddressNetwork(address)
|
||||
const isTestnet = slp.Address.detectAddressNetwork(address)
|
||||
assert.equal(isTestnet, "testnet")
|
||||
})
|
||||
})
|
||||
@@ -704,7 +712,7 @@ describe("#SLP Address", () => {
|
||||
describe("#detectAddressType", () => {
|
||||
TESTNET_P2PKH_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a p2pkh address`, () => {
|
||||
const isp2pkh = SLP.Address.detectAddressType(address)
|
||||
const isp2pkh = slp.Address.detectAddressType(address)
|
||||
assert.equal(isp2pkh, "p2pkh")
|
||||
})
|
||||
})
|
||||
@@ -713,7 +721,7 @@ describe("#SLP Address", () => {
|
||||
describe("#detectAddressType", () => {
|
||||
TESTNET_P2SH_ADDRESSES.forEach(address => {
|
||||
it(`should detect ${address} is a p2sh address`, () => {
|
||||
const isp2sh = SLP.Address.detectAddressType(address)
|
||||
const isp2sh = slp.Address.detectAddressType(address)
|
||||
assert.equal(isp2sh, "p2sh")
|
||||
})
|
||||
})
|
||||
@@ -753,7 +761,7 @@ describe("#details", () => {
|
||||
const resolved = new Promise(r => r({ data: data }))
|
||||
sandbox.stub(axios, "get").returns(resolved)
|
||||
|
||||
SLP.Address.details(
|
||||
slp.Address.details(
|
||||
"simpleledger:qr4zg7xth86yzq94gl8jvnf5z4wuupzt3gev5wtnm6"
|
||||
)
|
||||
.then(result => {
|
||||
@@ -788,7 +796,7 @@ describe("#utxo", () => {
|
||||
const resolved = new Promise(r => r({ data: data }))
|
||||
sandbox.stub(axios, "get").returns(resolved)
|
||||
|
||||
SLP.Address.utxo("simpleledger:qr4zg7xth86yzq94gl8jvnf5z4wuupzt3gev5wtnm6")
|
||||
slp.Address.utxo("simpleledger:qr4zg7xth86yzq94gl8jvnf5z4wuupzt3gev5wtnm6")
|
||||
.then(result => {
|
||||
assert.deepEqual(
|
||||
"467969e067f5612863d0bf2daaa70dede2c6be03abb6fd401c5ef6e1e1f1f5c5",
|
||||
@@ -815,7 +823,7 @@ describe("#unconfirmed", () => {
|
||||
const resolved = new Promise(r => r({ data: data }))
|
||||
sandbox.stub(axios, "get").returns(resolved)
|
||||
|
||||
SLP.Address.unconfirmed(
|
||||
slp.Address.unconfirmed(
|
||||
"simpleledger:qr4zg7xth86yzq94gl8jvnf5z4wuupzt3gev5wtnm6"
|
||||
)
|
||||
.then(result => {
|
||||
@@ -828,7 +836,7 @@ describe("#unconfirmed", () => {
|
||||
|
||||
// (async () => {
|
||||
// try {
|
||||
// const details = await SLP.Address.unconfirmed(
|
||||
// const details = await slp.Address.unconfirmed(
|
||||
// "simpleledger:qr4zg7xth86yzq94gl8jvnf5z4wuupzt3gev5wtnm6"
|
||||
// )
|
||||
// console.log(details)
|
||||
|
||||
+12
-3
@@ -1,10 +1,19 @@
|
||||
const fixtures = require("./fixtures/slp/ecpair.json")
|
||||
const assert = require("assert")
|
||||
|
||||
const SLP = require("../../src/slp/slp")
|
||||
const slp = new SLP({ restURL: "http://fakeurl.com/" })
|
||||
const fixtures = require("./fixtures/slp/ecpair.json")
|
||||
|
||||
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", () => {
|
||||
beforeEach(() => {
|
||||
const bchjs = new BCHJS()
|
||||
slp = bchjs.SLP
|
||||
})
|
||||
|
||||
describe("#toSLPAddress", () => {
|
||||
it(`should return slp address for ecpair`, async () => {
|
||||
fixtures.wif.forEach((wif, index) => {
|
||||
|
||||
+645
-486
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user