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/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/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") }) diff --git a/test/integration/testnet/slp.js b/test/integration/testnet/slp.js index 46bea98..014e1e7 100644 --- a/test/integration/testnet/slp.js +++ b/test/integration/testnet/slp.js @@ -54,4 +54,89 @@ 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" + ]) + }) + }) + + 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" + ]) + }) + }) })