From 7a635731432de776f5c38085e2b2eccdd251cd89 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 8 Dec 2020 17:23:41 -0800 Subject: [PATCH] fix(integration): Refactored abc and bchn integration tests --- package.json | 8 +- test/integration/chains/abc/rawtransaction.js | 71 ++++ test/integration/chains/abc/slp.js | 223 ++++++++++++ .../integration/chains/bchn/rawtransaction.js | 71 ++++ test/integration/chains/bchn/slp.js | 247 +++++++++++++ .../{ => chains}/testnet/blockbook.js | 0 .../{ => chains}/testnet/blockchain.js | 0 .../{ => chains}/testnet/control.js | 0 .../{ => chains}/testnet/electrumx.js | 0 .../{ => chains}/testnet/ninsight.js | 0 .../{ => chains}/testnet/rawtransaction.js | 0 test/integration/{ => chains}/testnet/slp.js | 0 .../{ => chains}/testnet/test-free-tier.sh | 0 test/integration/{ => chains}/testnet/util.js | 0 test/integration/rawtransaction.js | 34 -- test/integration/slp.js | 332 +++++++++--------- 16 files changed, 782 insertions(+), 204 deletions(-) create mode 100644 test/integration/chains/abc/rawtransaction.js create mode 100644 test/integration/chains/abc/slp.js create mode 100644 test/integration/chains/bchn/rawtransaction.js create mode 100644 test/integration/chains/bchn/slp.js rename test/integration/{ => chains}/testnet/blockbook.js (100%) rename test/integration/{ => chains}/testnet/blockchain.js (100%) rename test/integration/{ => chains}/testnet/control.js (100%) rename test/integration/{ => chains}/testnet/electrumx.js (100%) rename test/integration/{ => chains}/testnet/ninsight.js (100%) rename test/integration/{ => chains}/testnet/rawtransaction.js (100%) rename test/integration/{ => chains}/testnet/slp.js (100%) rename test/integration/{ => chains}/testnet/test-free-tier.sh (100%) rename test/integration/{ => chains}/testnet/util.js (100%) diff --git a/package.json b/package.json index fd23780..7fad43a 100644 --- a/package.json +++ b/package.json @@ -10,15 +10,15 @@ "scripts": { "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/v4/ IS_USING_FREE_TIER=true mocha --timeout 30000 test/integration/", + "test:integration:abc": "export RESTURL=https://abc.fullstack.cash/v4/ && export IS_USING_FREE_TIER=true && mocha --timeout 30000 test/integration/ && mocha --timeout 30000 test/integration/chains/abc/", + "test:integration:bchn": "export RESTURL=https://bchn.fullstack.cash/v4/ && export IS_USING_FREE_TIER=true && mocha --timeout 30000 test/integration/ && mocha --timeout 30000 test/integration/chains/bchn/", "test:integration:testnet": "IS_USING_FREE_TIER=true mocha --timeout 30000 test/integration/testnet/", "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:temp": "export RESTURL=http://localhost:3000/v4/ && export IS_USING_FREE_TIER=true && mocha --timeout 30000 test/integration/chains/bchn/", + "test:temp2": "RESTURL=https://abc.fullstack.cash/v4/ mocha --timeout 30000 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", diff --git a/test/integration/chains/abc/rawtransaction.js b/test/integration/chains/abc/rawtransaction.js new file mode 100644 index 0000000..66a2322 --- /dev/null +++ b/test/integration/chains/abc/rawtransaction.js @@ -0,0 +1,71 @@ +/* + Integration tests for the bchjs. Only covers calls made to + rest.bitcoin.com. + + TODO +*/ + +const chai = require("chai") +const assert = chai.assert +const BCHJS = require("../../../../src/bch-js") +const bchjs = new BCHJS() + +// Inspect utility used for debugging. +const util = require("util") +util.inspect.defaultOptions = { + showHidden: true, + colors: true, + depth: 3 +} + +describe("#rawtransaction", () => { + beforeEach(async () => { + if (process.env.IS_USING_FREE_TIER) await sleep(1000) + }) + + /* + Testing sentRawTransaction isn't really possible with an integration test, + as the endpoint really needs an e2e test to be properly tested. The tests + below expect error messages returned from the server, but at least test + that the server is responding on those endpoints, and responds consistently. + */ + describe("sendRawTransaction", () => { + it("should send a single transaction hex", async () => { + try { + const hex = + "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000" + + await bchjs.RawTransactions.sendRawTransaction(hex) + //console.log(`result ${JSON.stringify(result, null, 2)}`) + + assert.equal(true, false, "Unexpected result!") + } catch (err) { + //console.log(`err: ${util.inspect(err)}`) + + assert.hasAllKeys(err, ["error"]) + assert.include(err.error, "bad-txns-inputs-missingorspent") + } + }) + + it("should send an array of tx hexes", async () => { + try { + const hexes = [ + "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000", + "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000" + ] + + const result = await bchjs.RawTransactions.sendRawTransaction(hexes) + console.log(`result ${JSON.stringify(result, null, 2)}`) + } catch (err) { + // console.log(`err: ${util.inspect(err)}`) + + assert.hasAllKeys(err, ["error"]) + assert.include(err.error, "bad-txns-inputs-missingorspent") + } + }) + }) +}) + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +} diff --git a/test/integration/chains/abc/slp.js b/test/integration/chains/abc/slp.js new file mode 100644 index 0000000..ef3b87f --- /dev/null +++ b/test/integration/chains/abc/slp.js @@ -0,0 +1,223 @@ +/* + Integration tests for the bchjs covering SLP tokens. + These tests are specific to the ABC chain. +*/ + +const chai = require("chai") +const assert = chai.assert + +const BCHJS = require("../../../../src/bch-js") +let bchjs + +// Inspect utility used for debugging. +const util = require("util") +util.inspect.defaultOptions = { + showHidden: true, + colors: true, + depth: 1 +} + +describe(`#SLP`, () => { + // before(() => { + // console.log(`bchjs.SLP.restURL: ${bchjs.SLP.restURL}`) + // console.log(`bchjs.SLP.apiToken: ${bchjs.SLP.apiToken}`) + // }) + + beforeEach(async () => { + // Introduce a delay so that the BVT doesn't trip the rate limits. + if (process.env.IS_USING_FREE_TIER) await sleep(1000) + + bchjs = new BCHJS() + }) + + describe("#util", () => { + describe("#tokenUtxoDetails", () => { + 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("#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)}`) + + assert.isArray(result) + assert.equal(result[0].valid, null) + assert.equal(result[1].valid, null) + assert.equal(result[2].valid, true) + assert.equal(result[3].valid, true) + assert.equal(result[4].valid, null) + }) + }) + + 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" + ] + + const result = await bchjs.SLP.Utils.validateTxid(txids) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) + + assert.isArray(result) + assert.equal(result[0].valid, null) + assert.equal(result[1].valid, null) + assert.equal(result[2].valid, true) + assert.equal(result[3].valid, true) + assert.equal(result[4].valid, null) + assert.equal(result[5].valid, true) + }) + }) + }) +}) + +// Promise-based sleep function +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +} diff --git a/test/integration/chains/bchn/rawtransaction.js b/test/integration/chains/bchn/rawtransaction.js new file mode 100644 index 0000000..d512dc1 --- /dev/null +++ b/test/integration/chains/bchn/rawtransaction.js @@ -0,0 +1,71 @@ +/* + Integration tests for the bchjs. Only covers calls made to + rest.bitcoin.com. + + TODO +*/ + +const chai = require("chai") +const assert = chai.assert +const BCHJS = require("../../../../src/bch-js") +const bchjs = new BCHJS() + +// Inspect utility used for debugging. +const util = require("util") +util.inspect.defaultOptions = { + showHidden: true, + colors: true, + depth: 3 +} + +describe("#rawtransaction", () => { + beforeEach(async () => { + if (process.env.IS_USING_FREE_TIER) await sleep(1000) + }) + + /* + Testing sentRawTransaction isn't really possible with an integration test, + as the endpoint really needs an e2e test to be properly tested. The tests + below expect error messages returned from the server, but at least test + that the server is responding on those endpoints, and responds consistently. + */ + describe("sendRawTransaction", () => { + it("should send a single transaction hex", async () => { + try { + const hex = + "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000" + + await bchjs.RawTransactions.sendRawTransaction(hex) + //console.log(`result ${JSON.stringify(result, null, 2)}`) + + assert.equal(true, false, "Unexpected result!") + } catch (err) { + //console.log(`err: ${util.inspect(err)}`) + + assert.hasAllKeys(err, ["error"]) + assert.include(err.error, "Missing inputs") + } + }) + + it("should send an array of tx hexes", async () => { + try { + const hexes = [ + "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000", + "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000" + ] + + const result = await bchjs.RawTransactions.sendRawTransaction(hexes) + console.log(`result ${JSON.stringify(result, null, 2)}`) + } catch (err) { + // console.log(`err: ${util.inspect(err)}`) + + assert.hasAllKeys(err, ["error"]) + assert.include(err.error, "Missing inputs") + } + }) + }) +}) + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +} diff --git a/test/integration/chains/bchn/slp.js b/test/integration/chains/bchn/slp.js new file mode 100644 index 0000000..8e356ff --- /dev/null +++ b/test/integration/chains/bchn/slp.js @@ -0,0 +1,247 @@ +/* + Integration tests for the bchjs covering SLP tokens. + These tests are specific to the ABC chain. +*/ + +const chai = require("chai") +const assert = chai.assert + +const BCHJS = require("../../../../src/bch-js") +let bchjs + +// Inspect utility used for debugging. +const util = require("util") +util.inspect.defaultOptions = { + showHidden: true, + colors: true, + depth: 1 +} + +describe(`#SLP`, () => { + // before(() => { + // console.log(`bchjs.SLP.restURL: ${bchjs.SLP.restURL}`) + // console.log(`bchjs.SLP.apiToken: ${bchjs.SLP.apiToken}`) + // }) + + beforeEach(async () => { + // Introduce a delay so that the BVT doesn't trip the rate limits. + if (process.env.IS_USING_FREE_TIER) await sleep(1000) + + bchjs = new BCHJS() + }) + + describe("#util", () => { + describe("#tokenUtxoDetails", () => { + 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("#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 + "402c663379d9699b6e2dd38737061e5888c5a49fca77c97ab98e79e08959e019" + ] + + const result = await bchjs.SLP.Utils.validateTxid3(txids) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) + + assert.isArray(result) + + 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) + }) + }) + + 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" + ] + + const result = await bchjs.SLP.Utils.validateTxid(txids) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) + + assert.isArray(result) + + 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) + }) + }) + }) +}) + +// Promise-based sleep function +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +} diff --git a/test/integration/testnet/blockbook.js b/test/integration/chains/testnet/blockbook.js similarity index 100% rename from test/integration/testnet/blockbook.js rename to test/integration/chains/testnet/blockbook.js diff --git a/test/integration/testnet/blockchain.js b/test/integration/chains/testnet/blockchain.js similarity index 100% rename from test/integration/testnet/blockchain.js rename to test/integration/chains/testnet/blockchain.js diff --git a/test/integration/testnet/control.js b/test/integration/chains/testnet/control.js similarity index 100% rename from test/integration/testnet/control.js rename to test/integration/chains/testnet/control.js diff --git a/test/integration/testnet/electrumx.js b/test/integration/chains/testnet/electrumx.js similarity index 100% rename from test/integration/testnet/electrumx.js rename to test/integration/chains/testnet/electrumx.js diff --git a/test/integration/testnet/ninsight.js b/test/integration/chains/testnet/ninsight.js similarity index 100% rename from test/integration/testnet/ninsight.js rename to test/integration/chains/testnet/ninsight.js diff --git a/test/integration/testnet/rawtransaction.js b/test/integration/chains/testnet/rawtransaction.js similarity index 100% rename from test/integration/testnet/rawtransaction.js rename to test/integration/chains/testnet/rawtransaction.js diff --git a/test/integration/testnet/slp.js b/test/integration/chains/testnet/slp.js similarity index 100% rename from test/integration/testnet/slp.js rename to test/integration/chains/testnet/slp.js diff --git a/test/integration/testnet/test-free-tier.sh b/test/integration/chains/testnet/test-free-tier.sh similarity index 100% rename from test/integration/testnet/test-free-tier.sh rename to test/integration/chains/testnet/test-free-tier.sh diff --git a/test/integration/testnet/util.js b/test/integration/chains/testnet/util.js similarity index 100% rename from test/integration/testnet/util.js rename to test/integration/chains/testnet/util.js diff --git a/test/integration/rawtransaction.js b/test/integration/rawtransaction.js index 51a14fe..ede2a4c 100644 --- a/test/integration/rawtransaction.js +++ b/test/integration/rawtransaction.js @@ -231,40 +231,6 @@ describe("#rawtransaction", () => { that the server is responding on those endpoints, and responds consistently. */ describe("sendRawTransaction", () => { - it("should send a single transaction hex", async () => { - try { - const hex = - "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000" - - await bchjs.RawTransactions.sendRawTransaction(hex) - //console.log(`result ${JSON.stringify(result, null, 2)}`) - - assert.equal(true, false, "Unexpected result!") - } catch (err) { - //console.log(`err: ${util.inspect(err)}`) - - assert.hasAllKeys(err, ["error"]) - assert.include(err.error, "bad-txns-inputs-missingorspent") - } - }) - - it("should send an array of tx hexes", async () => { - try { - const hexes = [ - "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000", - "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000" - ] - - const result = await bchjs.RawTransactions.sendRawTransaction(hexes) - console.log(`result ${JSON.stringify(result, null, 2)}`) - } catch (err) { - // console.log(`err: ${util.inspect(err)}`) - - assert.hasAllKeys(err, ["error"]) - assert.include(err.error, "bad-txns-inputs-missingorspent") - } - }) - it(`should throw error on array size rate limit`, async () => { try { const dataMock = diff --git a/test/integration/slp.js b/test/integration/slp.js index d327858..50d08f7 100644 --- a/test/integration/slp.js +++ b/test/integration/slp.js @@ -464,97 +464,97 @@ 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) - }) + // 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", () => { @@ -738,82 +738,82 @@ describe(`#SLP`, () => { }) }) - describe("#validateTxid3", () => { - it("should invalidate a known invalid TXID", async () => { - const txid = - "f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a" + // 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)}`) + // }) + // }) - 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("#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", () => {