From 93177d34f928ee8ba9a4b1ae00cdbc674f71e8ab Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Wed, 11 Mar 2020 18:20:06 -0700 Subject: [PATCH 1/3] Added additional SLP testnet integration test --- test/integration/testnet/slp.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/integration/testnet/slp.js b/test/integration/testnet/slp.js index 46bea98..97b68fb 100644 --- a/test/integration/testnet/slp.js +++ b/test/integration/testnet/slp.js @@ -54,4 +54,21 @@ describe(`#SLP`, () => { ]) }) }) + + describe("#decodeOpReturn", () => { + it("should decode the OP_RETURN for a SEND txid", async () => { + const txid = + "ad28116e0818339342dddfc5f58ca8a5379ceb9679b4e4cbd72f4de905415ec1" + + const result = await bchjs.SLP.Utils.decodeOpReturn(txid) + // console.log(`result: ${JSON.stringify(result, null, 2)}`) + + assert.hasAllKeys(result, [ + "tokenType", + "transactionType", + "tokenId", + "spendData" + ]) + }) + }) }) From 6ca93d2823c0272663fbb11a06a5b9239117d1f7 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Wed, 11 Mar 2020 19:46:47 -0700 Subject: [PATCH 2/3] Adding additional SLP integration tests for mainnet and testnet --- test/integration/slp.js | 68 +++++++++++++++++++++++++++++++++ test/integration/testnet/slp.js | 68 +++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+) diff --git a/test/integration/slp.js b/test/integration/slp.js index 2218c28..1741d96 100644 --- a/test/integration/slp.js +++ b/test/integration/slp.js @@ -384,5 +384,73 @@ describe(`#SLP`, () => { assert.equal(false, data[1]) }) }) + + 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: simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9`, async () => { + // Mock the call to rest.bitcoin.com + if (process.env.TEST === "unit") { + sandbox + .stub(axios, "get") + .resolves({ data: mockData.balancesForAddress }) + } + + const balances = await bchjs.SLP.Utils.balancesForAddress( + "simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9" + ) + // console.log(`balances: ${JSON.stringify(balances, null, 2)}`) + + assert.isArray(balances) + assert.hasAllKeys(balances[0], [ + "tokenId", + "balanceString", + "balance", + "decimalCount", + "slpAddress" + ]) + }) + + it(`should fetch balances for multiple addresses`, async () => { + const addresses = [ + "simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9", + "simpleledger:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5ucdyl3r57" + ] + + // Mock the call to rest.bitcoin.com + if (process.env.TEST === "unit") { + sandbox + .stub(axios, "post") + .resolves({ data: mockData.balancesForAddresses }) + } + + const balances = await bchjs.SLP.Utils.balancesForAddress(addresses) + // console.log(`balances: ${JSON.stringify(balances, null, 2)}`) + + assert.isArray(balances) + assert.isArray(balances[0]) + assert.hasAllKeys(balances[0][0], [ + "tokenId", + "balanceString", + "balance", + "decimalCount", + "slpAddress" + ]) + }) + }) }) }) diff --git a/test/integration/testnet/slp.js b/test/integration/testnet/slp.js index 97b68fb..014e1e7 100644 --- a/test/integration/testnet/slp.js +++ b/test/integration/testnet/slp.js @@ -71,4 +71,72 @@ 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: simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9`, async () => { + // Mock the call to rest.bitcoin.com + if (process.env.TEST === "unit") { + sandbox + .stub(axios, "get") + .resolves({ data: mockData.balancesForAddress }) + } + + const balances = await bchjs.SLP.Utils.balancesForAddress( + "slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9" + ) + // console.log(`balances: ${JSON.stringify(balances, null, 2)}`) + + assert.isArray(balances) + assert.hasAllKeys(balances[0], [ + "tokenId", + "balanceString", + "balance", + "decimalCount", + "slpAddress" + ]) + }) + + it(`should fetch balances for multiple addresses`, async () => { + const addresses = [ + "slptest:qz0kc67pm4emjyr3gaaa2wstdaykg9m4yqwlzpj3w9", + "slptest:qr5uy4h8ysyhwkp9s245scckdnc7teyjqc5ft2z43h" + ] + + // Mock the call to rest.bitcoin.com + if (process.env.TEST === "unit") { + sandbox + .stub(axios, "post") + .resolves({ data: mockData.balancesForAddresses }) + } + + const balances = await bchjs.SLP.Utils.balancesForAddress(addresses) + // console.log(`balances: ${JSON.stringify(balances, null, 2)}`) + + assert.isArray(balances) + assert.isArray(balances[0]) + assert.hasAllKeys(balances[0][0], [ + "tokenId", + "balanceString", + "balance", + "decimalCount", + "slpAddress" + ]) + }) + }) }) From f324bae49340c95639849fd42a7a3730aa22e57e Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Fri, 20 Mar 2020 21:00:20 -0700 Subject: [PATCH 3/3] fix(bch-api): Updating to work with bch-api v1.14.8 and ABC v0.21.2 --- test/integration/blockchain.js | 6 ++++-- test/integration/control.js | 2 +- test/integration/testnet/blockchain.js | 6 ++++-- test/integration/testnet/control.js | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/test/integration/blockchain.js b/test/integration/blockchain.js index 2c3f9b2..4ea3761 100644 --- a/test/integration/blockchain.js +++ b/test/integration/blockchain.js @@ -52,7 +52,8 @@ describe(`#blockchain`, () => { "difficulty", "chainwork", "previousblockhash", - "nextblockhash" + "nextblockhash", + "nTx" ]) }) @@ -79,7 +80,8 @@ describe(`#blockchain`, () => { "difficulty", "chainwork", "previousblockhash", - "nextblockhash" + "nextblockhash", + "nTx" ]) }) diff --git a/test/integration/control.js b/test/integration/control.js index 447f85c..5e4fd98 100644 --- a/test/integration/control.js +++ b/test/integration/control.js @@ -11,7 +11,7 @@ describe(`#control`, () => { describe(`#getNetworkInfo`, () => { it("should get info on the full node", async () => { const result = await bchjs.Control.getNetworkInfo() - // console.log(`result: ${JSON.stringify(result, null, 2)}`) + console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.property(result, "version") }) diff --git a/test/integration/testnet/blockchain.js b/test/integration/testnet/blockchain.js index c7e13a3..961f252 100644 --- a/test/integration/testnet/blockchain.js +++ b/test/integration/testnet/blockchain.js @@ -59,7 +59,8 @@ describe(`#blockchain`, () => { "difficulty", "chainwork", "previousblockhash", - "nextblockhash" + "nextblockhash", + "nTx" ]) }) @@ -86,7 +87,8 @@ describe(`#blockchain`, () => { "difficulty", "chainwork", "previousblockhash", - "nextblockhash" + "nextblockhash", + "nTx" ]) }) diff --git a/test/integration/testnet/control.js b/test/integration/testnet/control.js index be04826..e1e36e9 100644 --- a/test/integration/testnet/control.js +++ b/test/integration/testnet/control.js @@ -16,7 +16,7 @@ describe(`#control`, () => { describe(`#getNetworkInfo`, () => { it("should get info on the full node", async () => { const result = await bchjs.Control.getNetworkInfo() - // console.log(`result: ${JSON.stringify(result, null, 2)}`) + console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.property(result, "version") })