diff --git a/test/integration/control.js b/test/integration/control.js index 5e4fd98..e6ce678 100644 --- a/test/integration/control.js +++ b/test/integration/control.js @@ -8,6 +8,10 @@ const BCHJS = require("../../src/bch-js") const bchjs = new BCHJS() describe(`#control`, () => { + beforeEach(async () => { + if (process.env.IS_USING_FREE_TIER) await sleep(1000) + }) + describe(`#getNetworkInfo`, () => { it("should get info on the full node", async () => { const result = await bchjs.Control.getNetworkInfo() @@ -17,3 +21,7 @@ describe(`#control`, () => { }) }) }) + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +} diff --git a/test/integration/electrumx.js b/test/integration/electrumx.js index 1c706c5..38dc38d 100644 --- a/test/integration/electrumx.js +++ b/test/integration/electrumx.js @@ -7,7 +7,13 @@ const bchjs = new BCHJS() describe(`#ElectrumX`, () => { let sandbox - beforeEach(() => (sandbox = sinon.createSandbox())) + + beforeEach(async () => { + sandbox = sinon.createSandbox() + + if (process.env.IS_USING_FREE_TIER) await sleep(1000) + }) + afterEach(() => sandbox.restore()) describe(`#utxo`, () => { @@ -354,3 +360,7 @@ describe(`#ElectrumX`, () => { }) }) }) + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +} diff --git a/test/integration/encryption.js b/test/integration/encryption.js index edf1747..8ab9d64 100644 --- a/test/integration/encryption.js +++ b/test/integration/encryption.js @@ -4,6 +4,10 @@ const BCHJS = require("../../src/bch-js") const bchjs = new BCHJS() describe("#Encryption", () => { + beforeEach(async () => { + if (process.env.IS_USING_FREE_TIER) await sleep(1000) + }) + describe("#getPubKey", () => { it("should get a public key", async () => { const addr = "bitcoincash:qpf8jv9hmqcda0502gjp7nm3g24y5h5s4unutghsxq" @@ -29,3 +33,7 @@ describe("#Encryption", () => { }) }) }) + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +} diff --git a/test/integration/ninsight.js b/test/integration/ninsight.js index b90213b..ce3842a 100644 --- a/test/integration/ninsight.js +++ b/test/integration/ninsight.js @@ -7,7 +7,13 @@ const bchjs = new BCHJS({ ninsightURL: "https://rest.bitcoin.com/v2" }) describe(`#Ninsight`, () => { let sandbox - beforeEach(() => (sandbox = sinon.createSandbox())) + + beforeEach(async () => { + sandbox = sinon.createSandbox() + + if (process.env.IS_USING_FREE_TIER) await sleep(1000) + }) + afterEach(() => sandbox.restore()) describe(`#utxo`, () => { @@ -55,3 +61,7 @@ describe(`#Ninsight`, () => { }) }) }) + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +} diff --git a/test/integration/openbazaar.js b/test/integration/openbazaar.js index 1bd149d..f888b0b 100644 --- a/test/integration/openbazaar.js +++ b/test/integration/openbazaar.js @@ -8,6 +8,10 @@ const BCHJS = require("../../src/bch-js") const bchjs = new BCHJS() describe(`#OpenBazaar`, () => { + beforeEach(async () => { + if (process.env.IS_USING_FREE_TIER) await sleep(1000) + }) + describe(`#Balance`, () => { it(`should GET balance for a single address`, async () => { const addr = "bitcoincash:qqh793x9au6ehvh7r2zflzguanlme760wuzehgzjh9" @@ -79,3 +83,7 @@ describe(`#OpenBazaar`, () => { }) }) }) + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +} diff --git a/test/integration/price.js b/test/integration/price.js index 579d65f..1648405 100644 --- a/test/integration/price.js +++ b/test/integration/price.js @@ -3,6 +3,10 @@ const BCHJS = require("../../src/bch-js") const bchjs = new BCHJS() describe("#price", () => { + beforeEach(async () => { + if (process.env.IS_USING_FREE_TIER) await sleep(1000) + }) + describe("#current", () => { describe("#single currency", () => { it("should get current price for single currency", async () => { @@ -31,3 +35,7 @@ describe("#price", () => { }) }) }) + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +} diff --git a/test/integration/rawtransaction.js b/test/integration/rawtransaction.js index b6b4038..4be5bcf 100644 --- a/test/integration/rawtransaction.js +++ b/test/integration/rawtransaction.js @@ -19,6 +19,10 @@ util.inspect.defaultOptions = { } describe("#rawtransaction", () => { + beforeEach(async () => { + if (process.env.IS_USING_FREE_TIER) await sleep(1000) + }) + describe("#decodeRawTransaction", () => { it("should decode tx for a single hex", async () => { const hex = @@ -279,3 +283,7 @@ describe("#rawtransaction", () => { }) }) }) + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +} diff --git a/test/integration/slp.js b/test/integration/slp.js index cab94d3..9d39392 100644 --- a/test/integration/slp.js +++ b/test/integration/slp.js @@ -24,7 +24,7 @@ describe(`#SLP`, () => { beforeEach(async () => { // Introduce a delay so that the BVT doesn't trip the rate limits. - await sleep(1000) + if (process.env.IS_USING_FREE_TIER) await sleep(1000) bchjs = new BCHJS() }) diff --git a/test/integration/test-free-tier-bchn.sh b/test/integration/test-free-tier-bchn.sh index 2a5faea..f0a1cb9 100755 --- a/test/integration/test-free-tier-bchn.sh +++ b/test/integration/test-free-tier-bchn.sh @@ -2,6 +2,7 @@ export RESTURL=https://bchn-free-main.fullstack.cash/v3/ #export RESTURL=http://localhost:3000/v3/ +export IS_USING_FREE_TIER=true cd test/integration/bchn/ mocha --timeout 30000 blockchain.js control.js electrumx.js ninsight.js openbazaar.js price.js rawtransaction.js slp.js util.js diff --git a/test/integration/testnet/blockbook.js b/test/integration/testnet/blockbook.js index d286f6e..18d7c31 100644 --- a/test/integration/testnet/blockbook.js +++ b/test/integration/testnet/blockbook.js @@ -26,6 +26,10 @@ util.inspect.defaultOptions = { } describe(`#Blockbook`, () => { + beforeEach(async () => { + if (process.env.IS_USING_FREE_TIER) await sleep(1000) + }) + describe(`#Balance`, () => { it(`should GET balance for a single address`, async () => { const addr = "bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2" @@ -165,7 +169,7 @@ describe(`#Blockbook`, () => { for (let i = 0; i < 25; i++) addr.push("bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2") - const result = await bchjs.Blockbook.utxo(addr) + await bchjs.Blockbook.utxo(addr) //console.log(`result: ${util.inspect(result)}`) assert.equal(true, false, "Unexpected result!") @@ -176,3 +180,7 @@ describe(`#Blockbook`, () => { }) }) }) + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +} diff --git a/test/integration/testnet/blockchain.js b/test/integration/testnet/blockchain.js index 961f252..3d777f8 100644 --- a/test/integration/testnet/blockchain.js +++ b/test/integration/testnet/blockchain.js @@ -12,7 +12,7 @@ const assert = chai.assert const RESTURL = process.env.RESTURL ? process.env.RESTURL - : `https://tapi.fullstack.cash/v3/` + : "https://tapi.fullstack.cash/v3/" // if (process.env.RESTURL) RESTURL = process.env.RESTURL const BCHJS = require("../../../src/bch-js") @@ -27,11 +27,15 @@ util.inspect.defaultOptions = { depth: 3 } -describe(`#blockchain`, () => { - describe(`#getBestBlockHash`, () => { - it(`should GET best block hash`, async () => { +describe("#blockchain", () => { + beforeEach(async () => { + if (process.env.IS_USING_FREE_TIER) await sleep(1000) + }) + + describe("#getBestBlockHash", () => { + it("should GET best block hash", async () => { const result = await bchjs.Blockchain.getBestBlockHash() - //console.log(`result: ${util.inspect(result)}`) + // console.log(`result: ${util.inspect(result)}`) assert.isString(result) assert.equal(result.length, 64, "Specific hash length") @@ -39,7 +43,7 @@ describe(`#blockchain`, () => { }) describe("#getBlockHeader", () => { - it(`should GET block header for a single hash`, async () => { + it("should GET block header for a single hash", async () => { const hash = "000000000000c57178ace90210289e6b5383134c5b5306e1cdd8395176e10aaf" @@ -64,7 +68,7 @@ describe(`#blockchain`, () => { ]) }) - it(`should GET block headers for an array of hashes`, async () => { + it("should GET block headers for an array of hashes", async () => { const hash = [ "000000000000c57178ace90210289e6b5383134c5b5306e1cdd8395176e10aaf", "00000000000b7db4cbae48d852fcbef32f728014582094ad613fe12af6600ff2" @@ -92,21 +96,7 @@ describe(`#blockchain`, () => { ]) }) - it(`should throw an error for improper input`, async () => { - try { - const hash = 12345 - - await bchjs.Blockchain.getBlockHeader(hash) - assert.equal(true, false, "Unexpected result!") - } catch (err) { - assert.include( - err.message, - `Input hash must be a string or array of strings` - ) - } - }) - - it(`should throw error on array size rate limit`, async () => { + it("should throw error on array size rate limit", async () => { try { const data = [] for (let i = 0; i < 25; i++) { @@ -115,7 +105,7 @@ describe(`#blockchain`, () => { ) } - const result = await bchjs.Blockchain.getBlockHeader(data) + await bchjs.Blockchain.getBlockHeader(data) // console.log(`result: ${util.inspect(result)}`) assert.equal(true, false, "Unexpected result!") @@ -178,7 +168,7 @@ describe(`#blockchain`, () => { }) */ - it(`should throw an error if txid is not in mempool`, async () => { + it("should throw an error if txid is not in mempool", async () => { try { const txid = "1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04" @@ -187,39 +177,25 @@ describe(`#blockchain`, () => { assert.equal(true, false, "Unexpected result!") } catch (err) { - //console.log(`err: ${util.inspect(err)}`) + // console.log(`err: ${util.inspect(err)}`) assert.hasAnyKeys(err, ["error"]) - assert.include(err.error, `Transaction not in mempool`) - } - }) - - it(`should throw an error for improper single input`, async () => { - try { - const txid = 12345 - - await bchjs.Blockchain.getMempoolEntry(txid) - assert.equal(true, false, "Unexpected result!") - } catch (err) { - assert.include( - err.message, - `Input must be a string or array of strings` - ) + assert.include(err.error, "Transaction not in mempool") } }) }) - describe(`#getTxOutProof`, () => { - it(`should get single tx out proof`, async () => { + describe("#getTxOutProof", () => { + it("should get single tx out proof", async () => { const txid = "1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04" const result = await bchjs.Blockchain.getTxOutProof(txid) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isString(result) }) - it(`should get an array of tx out proofs`, async () => { + it("should get an array of tx out proofs", async () => { const txid = [ "1f121fb6a33f48cd426dde06aa20ce589dd97becabb835a8d33071cbf40c7d04", "fc4f696c0ebb3d0994b3975f57d85be75ef752b9fd52c17e361ec3be2fa3e752" @@ -231,27 +207,13 @@ describe(`#blockchain`, () => { assert.isArray(result) assert.isString(result[0]) }) - - it(`should throw an error for improper single input`, async () => { - try { - const txid = 12345 - - await bchjs.Blockchain.getTxOutProof(txid) - assert.equal(true, false, "Unexpected result!") - } catch (err) { - assert.include( - err.message, - `Input must be a string or array of strings` - ) - } - }) }) - describe(`#verifyTxOutProof`, () => { + describe("#verifyTxOutProof", () => { const mockTxOutProof = "00000020ac86ce8f2bda235c0dc135d18f6a777c44b121e8f41db8a51ca65000000000000cd4de3c49337712f3a1092c47c3bf73ec2f9b1cfd289ee991ede0b6eab4df229d5b8c5dffff001d82ce005b0700000003ec55d9142eac2c1d2229e5af24898b2590c111b62e2787fa1998d3d713fd432fd557124ed758fa156a6cdc6d317d5575aec2b86dfb159c62ecb4743f28bef1cb52e7a32fbec31e367ec152fdb952f75ee75bd8575f97b394093dbb0e6c694ffc0135" - it(`should verify a single proof`, async () => { + it("should verify a single proof", async () => { const result = await bchjs.Blockchain.verifyTxOutProof(mockTxOutProof) // console.log(`result: ${JSON.stringify(result, null, 2)}`) @@ -263,10 +225,10 @@ describe(`#blockchain`, () => { ) }) - it(`should verify an array of proofs`, async () => { + it("should verify an array of proofs", async () => { const proofs = [mockTxOutProof, mockTxOutProof] const result = await bchjs.Blockchain.verifyTxOutProof(proofs) - //console.log(`result: ${JSON.stringify(result, null, 2)}`) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.isArray(result) assert.isString(result[0]) @@ -276,21 +238,7 @@ describe(`#blockchain`, () => { ) }) - it(`should throw an error for improper single input`, async () => { - try { - const txid = 12345 - - await bchjs.Blockchain.verifyTxOutProof(txid) - assert.equal(true, false, "Unexpected result!") - } catch (err) { - assert.include( - err.message, - `Input must be a string or array of strings` - ) - } - }) - - it(`should throw error on array size rate limit`, async () => { + it("should throw error on array size rate limit", async () => { try { const data = [] for (let i = 0; i < 25; i++) data.push(mockTxOutProof) @@ -306,3 +254,7 @@ describe(`#blockchain`, () => { }) }) }) + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +} diff --git a/test/integration/testnet/control.js b/test/integration/testnet/control.js index e1e36e9..863cafd 100644 --- a/test/integration/testnet/control.js +++ b/test/integration/testnet/control.js @@ -13,6 +13,10 @@ const BCHJS = require("../../../src/bch-js") const bchjs = new BCHJS({ restURL: RESTURL, apiToken: process.env.BCHJSTOKEN }) describe(`#control`, () => { + beforeEach(async () => { + if (process.env.IS_USING_FREE_TIER) await sleep(1000) + }) + describe(`#getNetworkInfo`, () => { it("should get info on the full node", async () => { const result = await bchjs.Control.getNetworkInfo() @@ -22,3 +26,7 @@ describe(`#control`, () => { }) }) }) + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +} diff --git a/test/integration/testnet/electrumx.js b/test/integration/testnet/electrumx.js index 7886803..c880ab4 100644 --- a/test/integration/testnet/electrumx.js +++ b/test/integration/testnet/electrumx.js @@ -11,7 +11,13 @@ const bchjs = new BCHJS({ restURL: RESTURL, apiToken: process.env.BCHJSTOKEN }) describe(`#ElectrumX`, () => { let sandbox - beforeEach(() => (sandbox = sinon.createSandbox())) + + beforeEach(async () => { + sandbox = sinon.createSandbox() + + if (process.env.IS_USING_FREE_TIER) await sleep(1000) + }) + afterEach(() => sandbox.restore()) describe(`#utxo`, () => { @@ -358,3 +364,7 @@ describe(`#ElectrumX`, () => { }) }) }) + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +} diff --git a/test/integration/testnet/ninsight.js b/test/integration/testnet/ninsight.js index 7f913fc..fe1351e 100644 --- a/test/integration/testnet/ninsight.js +++ b/test/integration/testnet/ninsight.js @@ -7,7 +7,13 @@ const bchjs = new BCHJS({ ninsightURL: "https://trest.bitcoin.com/v2" }) describe(`#Ninsight`, () => { let sandbox - beforeEach(() => (sandbox = sinon.createSandbox())) + + beforeEach(async () => { + if (process.env.IS_USING_FREE_TIER) await sleep(1000) + + sandbox = sinon.createSandbox() + }) + afterEach(() => sandbox.restore()) describe(`#utxo`, () => { @@ -63,3 +69,7 @@ describe(`#Ninsight`, () => { }) }) }) + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +} diff --git a/test/integration/testnet/openbazaar.js b/test/integration/testnet/openbazaar.js deleted file mode 100644 index 9d02775..0000000 --- a/test/integration/testnet/openbazaar.js +++ /dev/null @@ -1,124 +0,0 @@ -/* - tests for OpenBazaar library. -*/ - -// Force testnet call to OB1 servers. -process.env.NETWORK = "testnet" - -const chai = require("chai") -const assert = chai.assert - -const RESTURL = process.env.RESTURL - ? process.env.RESTURL - : `https://tapi.fullstack.cash/v3/` - -const BCHJS = require("../../../src/bch-js") -const bchjs = new BCHJS({ restURL: RESTURL, apiToken: process.env.BCHJSTOKEN }) - -describe(`#OpenBazaar`, () => { - describe(`#Balance`, () => { - // it(`should GET balance for a single address`, async () => { - // const addr = "bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2" - // - // const result = await bchjs.OpenBazaar.balance(addr) - // // console.log(`result: ${JSON.stringify(result, null, 2)}`) - // - // assert.hasAllKeys(result, [ - // "page", - // "totalPages", - // "itemsOnPage", - // "addrStr", - // "balance", - // "totalReceived", - // "totalSent", - // "unconfirmedBalance", - // "unconfirmedTxApperances", - // "txApperances", - // "transactions" - // ]) - // assert.isArray(result.transactions) - // }) - - it(`should throw an error for improper input`, async () => { - try { - const addr = 12345 - - await bchjs.OpenBazaar.balance(addr) - // assert.equal(true, false, "Unexpected result!") - } catch (err) { - //console.log(`err: `, err) - assert.include(err.message, `Input address must be a string`) - } - }) - }) - - describe(`#utxo`, () => { - // it(`should GET utxos for a single address`, async () => { - // const addr = "bchtest:qrvn2n228aa39xupcw9jw0d3fj8axxky656e4j62z2" - // - // const result = await bchjs.OpenBazaar.utxo(addr) - // // console.log(`result: ${JSON.stringify(result, null, 2)}`) - // - // assert.isArray(result) - // assert.hasAllKeys(result[0], [ - // "txid", - // "vout", - // "amount", - // "height", - // "confirmations", - // "satoshis" - // ]) - // }) - - it(`should throw an error for improper input`, async () => { - try { - const addr = 12345 - - await bchjs.OpenBazaar.utxo(addr) - assert.equal(true, false, "Unexpected result!") - } catch (err) { - //console.log(`err: `, err) - assert.include(err.message, `Input address must be a string`) - } - }) - }) - - describe(`#tx`, () => { - it(`should throw an error for improper input`, async () => { - try { - const addr = 12345 - - await bchjs.OpenBazaar.tx(addr) - assert.equal(true, false, "Unexpected result!") - } catch (err) { - //console.log(`err: `, err) - assert.include(err.message, `Input txid must be a string`) - } - }) - - // it(`should GET transactions for a single address`, async () => { - // const addr = - // "ed4692f50a4553527dd26cd8674ca06a0ab2d366f3135ca3668310467ead3cbf" - // - // const result = await bchjs.OpenBazaar.tx(addr) - // // console.log(`result: ${JSON.stringify(result, null, 2)}`) - // - // assert.hasAnyKeys(result, [ - // "txid", - // "version", - // "vin", - // "vout", - // "blockhash", - // "blockheight", - // "confirmations", - // "blocktime", - // "valueOut", - // "valueIn", - // "fees", - // "hex" - // ]) - // assert.isArray(result.vin) - // assert.isArray(result.vout) - // }) - }) -}) diff --git a/test/integration/testnet/rawtransaction.js b/test/integration/testnet/rawtransaction.js index 4207d72..d2fa1fb 100644 --- a/test/integration/testnet/rawtransaction.js +++ b/test/integration/testnet/rawtransaction.js @@ -26,6 +26,10 @@ util.inspect.defaultOptions = { } describe("#rawtransaction", () => { + beforeEach(async () => { + if (process.env.IS_USING_FREE_TIER) await sleep(1000) + }) + describe("#decodeRawTransaction", () => { it("should decode tx for a single hex", async () => { const hex = @@ -70,21 +74,6 @@ describe("#rawtransaction", () => { assert.isArray(result[0].vout) }) - it(`should throw an error for improper single input`, async () => { - try { - const addr = 12345 - - await bchjs.RawTransactions.decodeRawTransaction(addr) - assert.equal(true, false, "Unexpected result!") - } catch (err) { - //console.log(`err: `, err) - assert.include( - err.message, - `Input must be a string or array of strings.` - ) - } - }) - it(`should throw error on array size rate limit`, async () => { try { const data = [] @@ -239,22 +228,6 @@ describe("#rawtransaction", () => { const result = await bchjs.RawTransactions.decodeScript(hexes) console.log(`result ${JSON.stringify(result, null, 2)}`) }) -*/ - /* - it(`should throw an error for improper single input`, async () => { - try { - const addr = 12345 - - await bchjs.RawTransactions.decodeRawTransaction(addr) - assert.equal(true, false, "Unexpected result!") - } catch (err) { - //console.log(`err: `, err) - assert.include( - err.message, - `Input must be a string or array of strings.` - ) - } - }) */ }) @@ -299,21 +272,6 @@ describe("#rawtransaction", () => { } }) - it(`should throw an error for improper single input`, async () => { - try { - const addr = 12345 - - await bchjs.RawTransactions.sendRawTransaction(addr) - assert.equal(true, false, "Unexpected result!") - } catch (err) { - //console.log(`err: `, err) - assert.include( - err.message, - `Input hex must be a string or array of strings` - ) - } - }) - it(`should throw error on array size rate limit`, async () => { try { const dataMock = @@ -332,3 +290,7 @@ describe("#rawtransaction", () => { }) }) }) + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +} diff --git a/test/integration/testnet/slp.js b/test/integration/testnet/slp.js index 15e1c86..5ceb546 100644 --- a/test/integration/testnet/slp.js +++ b/test/integration/testnet/slp.js @@ -25,7 +25,7 @@ util.inspect.defaultOptions = { describe(`#SLP`, () => { beforeEach(async () => { // Introduce a delay so that the BVT doesn't trip the rate limits. - await sleep(1000) + if (process.env.IS_USING_FREE_TIER) await sleep(1000) }) describe("#util", () => { @@ -73,22 +73,6 @@ describe(`#SLP`, () => { }) describe("#balancesForAddress", () => { - it(`should throw an error if input is not a string or array of strings`, async () => { - try { - const address = 1234 - - await bchjs.SLP.Utils.balancesForAddress(address) - - assert.equal(true, false, "Uh oh. Code path should not end here.") - } catch (err) { - //console.log(`Error: `, err) - assert.include( - err.message, - `Input address must be a string or array of strings` - ) - } - }) - it(`should fetch all balances for address: slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9`, async () => { // Mock the call to rest.bitcoin.com if (process.env.TEST === "unit") { diff --git a/test/integration/testnet/test-free-tier.sh b/test/integration/testnet/test-free-tier.sh index 623f10f..dd12f28 100755 --- a/test/integration/testnet/test-free-tier.sh +++ b/test/integration/testnet/test-free-tier.sh @@ -2,8 +2,8 @@ export RESTURL=https://free-test.fullstack.cash/v3/ export NETWORK=testnet -#export RESTURL=http://localhost:3000/v3/ +export IS_USING_FREE_TIER=true cd test/integration/testnet/ -mocha --timeout 30000 blockchain.js control.js electrumx.js openbazaar.js rawtransaction.js slp.js util.js +mocha --timeout 30000 blockchain.js control.js electrumx.js rawtransaction.js slp.js util.js #mocha --timeout 30000 blockchain.js diff --git a/test/integration/testnet/util.js b/test/integration/testnet/util.js index e3096e9..f30f076 100644 --- a/test/integration/testnet/util.js +++ b/test/integration/testnet/util.js @@ -24,6 +24,10 @@ util.inspect.defaultOptions = { } describe(`#util`, () => { + beforeEach(async () => { + if (process.env.IS_USING_FREE_TIER) await sleep(1000) + }) + describe(`#validateAddress`, () => { it(`should return false for testnet addr on mainnet`, async () => { const address = `bitcoincash:qp4k8fjtgunhdr7yq30ha4peu` @@ -82,21 +86,6 @@ describe(`#util`, () => { ]) }) - it(`should throw an error for improper single input`, async () => { - try { - const address = 15432 - - await bchjs.Util.validateAddress(address) - assert.equal(true, false, "Unexpected result!") - } catch (err) { - //console.log(`err: `, err) - assert.include( - err.message, - `Input must be a string or array of strings.` - ) - } - }) - it(`should throw error on array size rate limit`, async () => { try { const dataMock = `bchtest:pq6k9969f6v6sg7a75jkru4n7wn9sknv5cztcp0dnh` @@ -114,3 +103,7 @@ describe(`#util`, () => { }) }) }) + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +} diff --git a/test/integration/util.js b/test/integration/util.js index 35831a8..90dc34e 100644 --- a/test/integration/util.js +++ b/test/integration/util.js @@ -17,6 +17,10 @@ util.inspect.defaultOptions = { } describe(`#util`, () => { + beforeEach(async () => { + if (process.env.IS_USING_FREE_TIER) await sleep(1000) + }) + describe(`#validateAddress`, () => { it(`should return false for testnet addr on mainnet`, async () => { const address = `bchtest:qqqk4y6lsl5da64sg5qc3xezmplyu5kmpyz2ysaa5y` @@ -92,3 +96,7 @@ describe(`#util`, () => { }) }) }) + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +}