Merge pull request #15 from christroutner/unstable

Unstable
This commit is contained in:
Chris Troutner
2020-03-20 21:06:22 -07:00
committed by GitHub
6 changed files with 163 additions and 6 deletions
+4 -2
View File
@@ -52,7 +52,8 @@ describe(`#blockchain`, () => {
"difficulty",
"chainwork",
"previousblockhash",
"nextblockhash"
"nextblockhash",
"nTx"
])
})
@@ -79,7 +80,8 @@ describe(`#blockchain`, () => {
"difficulty",
"chainwork",
"previousblockhash",
"nextblockhash"
"nextblockhash",
"nTx"
])
})
+1 -1
View File
@@ -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")
})
+68
View File
@@ -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"
])
})
})
})
})
+4 -2
View File
@@ -59,7 +59,8 @@ describe(`#blockchain`, () => {
"difficulty",
"chainwork",
"previousblockhash",
"nextblockhash"
"nextblockhash",
"nTx"
])
})
@@ -86,7 +87,8 @@ describe(`#blockchain`, () => {
"difficulty",
"chainwork",
"previousblockhash",
"nextblockhash"
"nextblockhash",
"nTx"
])
})
+1 -1
View File
@@ -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")
})
+85
View File
@@ -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"
])
})
})
})