From 9539119c57223f99cfb0e54996b895517be94e50 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Fri, 16 Oct 2020 22:22:18 -0700 Subject: [PATCH] fix(testnet): Added additional integration tests for testnet SLP --- package.json | 2 +- test/integration/slp.js | 4 ++- test/integration/testnet/slp.js | 56 ++++++++++++++++++++++++++++++++- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e2b3f71..25b0241 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "test:integration:free": "bash test/integration/test-free-tier.sh", "test:integration:free:bchn": "bash test/integration/test-free-tier-bchn.sh", "test:integration:free:testnet": "bash test/integration/testnet/test-free-tier.sh", - "test:temp": "mocha --timeout 30000 -g '#dustattack' test/unit/slp-utils.js", + "test:temp": "mocha --timeout 30000 -g '#hydrateUtxos' test/integration/", "test:integration:api": "RESTURL=https://api.fullstack.cash/v3/ mocha --timeout 30000 test/integration", "coverage": "nyc report --reporter=text-lcov | coveralls", "coverage:report": "nyc --reporter=html mocha --timeout 25000 test/unit/", diff --git a/test/integration/slp.js b/test/integration/slp.js index 99d3b29..64e03fd 100644 --- a/test/integration/slp.js +++ b/test/integration/slp.js @@ -6,7 +6,7 @@ const chai = require("chai") const assert = chai.assert const BCHJS = require("../../src/bch-js") -const bchjs = new BCHJS() +let bchjs // Inspect utility used for debugging. const util = require("util") @@ -25,6 +25,8 @@ describe(`#SLP`, () => { beforeEach(async () => { // Introduce a delay so that the BVT doesn't trip the rate limits. await sleep(1000) + + bchjs = new BCHJS() }) describe("#util", () => { diff --git a/test/integration/testnet/slp.js b/test/integration/testnet/slp.js index 088e178..15e1c86 100644 --- a/test/integration/testnet/slp.js +++ b/test/integration/testnet/slp.js @@ -89,7 +89,7 @@ describe(`#SLP`, () => { } }) - it(`should fetch all balances for address: simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9`, async () => { + it(`should fetch all balances for address: slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9`, async () => { // Mock the call to rest.bitcoin.com if (process.env.TEST === "unit") { sandbox @@ -139,6 +139,60 @@ describe(`#SLP`, () => { ]) }) }) + + describe("#tokenUtxoDetails", () => { + it("should hydrate UTXOs", async () => { + const bchAddr = bchjs.SLP.Address.toCashAddress( + "slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9" + ) + + const utxos = await bchjs.Electrumx.utxo([bchAddr]) + // console.log(`utxos: ${JSON.stringify(utxos, null, 2)}`) + + const utxoInfo = await bchjs.SLP.Utils.tokenUtxoDetails( + utxos.utxos[0].utxos + ) + // console.log(`utxoInfo: ${JSON.stringify(utxoInfo, null, 2)}`) + + assert.isArray(utxoInfo) + + // first UTXO should be a PSF test token. + assert.equal(utxoInfo[0].isValid, true) + }) + }) + + describe("#hydrateUtxos", () => { + // This test will error out if the LOCAL_RESTURL settings is not set properly + // in bch-api. + it("should hydrate UTXOs", async () => { + const bchAddr = bchjs.SLP.Address.toCashAddress( + "slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9" + ) + + const utxos = await bchjs.Electrumx.utxo([bchAddr]) + // console.log(`utxos: ${JSON.stringify(utxos, null, 2)}`) + + const utxoInfo = await bchjs.SLP.Utils.hydrateUtxos(utxos.utxos) + // console.log(`utxoInfo: ${JSON.stringify(utxoInfo, null, 2)}`) + + assert.isArray(utxoInfo.slpUtxos[0].utxos) + + // first UTXO should be a PSF test token. + assert.equal(utxoInfo.slpUtxos[0].utxos[0].isValid, true) + }) + }) + + describe("#validateTxid2", () => { + it("should validate a token txid", async () => { + const txid = + "ad28116e0818339342dddfc5f58ca8a5379ceb9679b4e4cbd72f4de905415ec1" + + const validated = await bchjs.SLP.Utils.validateTxid(txid) + // console.log(validated) + + assert.equal(validated[0].valid, true) + }) + }) }) // Promise-based sleep function