Editing slp-util unit tests

This commit is contained in:
Chris Troutner
2020-12-06 13:07:35 -08:00
parent 98f7cb8f3a
commit 4af6716631
5 changed files with 105 additions and 124 deletions
+1 -1
View File
@@ -20,7 +20,7 @@
"test:temp": "RESTURL=https://bchn.fullstack.cash/v4/ mocha --timeout 30000 -g '#validateTxid' test/integration/bchn/",
"test:temp2": "RESTURL=https://abc.fullstack.cash/v4/ mocha --timeout 30000 -g '#validateTxid' test/integration/",
"test:temp3": "ISBCHN=true RESTURL=http://localhost:3000/v4/ mocha --timeout 30000 -g '#validateTxid' test/integration/bchn/",
"test:temp4": "mocha -g '#SLP Utils' test/unit/",
"test:temp4": "mocha --trace-warnings --unhandled-rejections=strict -g '#SLP Utils' test/unit/",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"coverage:report": "nyc --reporter=html mocha --timeout 25000 test/unit/",
"docs": "./node_modules/.bin/apidoc -i src/ -o docs"
+1 -1
View File
@@ -579,7 +579,7 @@ class Utils {
// Retrieve the whitelist from the REST API if we haven't gotten it yet.
if (this.whitelist.length === 0) {
const response = await _this.axios.get(path, _this.axiosOptions)
console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`)
// console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`)
this.whitelist = response.data
}
+29 -1
View File
@@ -35,7 +35,7 @@ describe(`#SLP`, () => {
const tokenId = `4de69e374a8ed21cbddd47f2338cc0f479dc58daa2bbe11cd604ca488eca0ddf`
const result = await bchjs.SLP.Utils.list(tokenId)
//console.log(`result: ${JSON.stringify(result, null, 2)}`)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.hasAnyKeys(result, [
"decimals",
@@ -60,6 +60,34 @@ describe(`#SLP`, () => {
"mintingBatonStatus"
])
})
it("should NOT get a list of all tokens in existence", async () => {
try {
await bchjs.SLP.Utils.list()
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.fail("Unexpected result!")
} catch (err) {
// console.log(err)
assert.include(err.message, "Not Found")
}
})
it("should get information on multiple tokens", async () => {
const tokenIds = [
// Spice
`4de69e374a8ed21cbddd47f2338cc0f479dc58daa2bbe11cd604ca488eca0ddf`,
// PSF
"38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0"
]
const result = await bchjs.SLP.Utils.list(tokenIds)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.isArray(result)
assert.equal(result[0].symbol, "SPICE")
assert.equal(result[1].symbol, "PSF")
})
})
// describe("#decodeOpReturn", () => {
+2 -1
View File
@@ -5,4 +5,5 @@
#export IS_USING_FREE_TIER=true
cd test/integration/bchn/
mocha --timeout 30000 blockchain.js control.js encryption.js electrumx.js ninsight.js openbazaar.js price.js rawtransaction.js slp.js util.js
#mocha --timeout 30000 blockchain.js control.js encryption.js electrumx.js ninsight.js openbazaar.js price.js rawtransaction.js slp.js util.js
mocha --timeout 30000 slp.js
+72 -120
View File
@@ -1,7 +1,7 @@
// Public npm libraries
const assert = require("assert")
const assert2 = require("chai").assert
const nock = require("nock") // http call mocking
// const nock = require("nock") // http call mocking
const sinon = require("sinon")
// const axios = require("axios")
@@ -12,7 +12,7 @@ let SERVER
const REST_URL = process.env.RESTURL
? process.env.RESTURL
: "https://api.fullstack.cash/v4/"
: "https://bchn.fullstack.cash/v4/"
// Mock data used for unit tests
const mockData = require("./fixtures/slp/mock-utils")
@@ -25,7 +25,7 @@ describe("#SLP Utils", () => {
beforeEach(() => {
// Activate nock if it's inactive.
if (!nock.isActive()) nock.activate()
// if (!nock.isActive()) nock.activate()
sandbox = sinon.createSandbox()
@@ -38,130 +38,78 @@ describe("#SLP Utils", () => {
afterEach(() => {
// Clean up HTTP mocks.
nock.cleanAll() // clear interceptor list.
nock.restore()
// nock.cleanAll() // clear interceptor list.
// nock.restore()
sandbox.restore()
})
describe("#list", () => {
it(`should list all SLP tokens`, async () => {
// Mock the call to the REST API
if (process.env.TEST === "unit") {
nock(SERVER)
.get(uri => uri.includes("/"))
.reply(200, mockData.mockList)
}
const list = await uut.Utils.list()
//console.log(`list: ${JSON.stringify(list, null, 2)}`)
assert2.isArray(list)
assert2.hasAllKeys(list[0], [
"blockCreated",
"blockLastActiveMint",
"blockLastActiveSend",
"circulatingSupply",
"containsBaton",
"decimals",
"documentHash",
"documentUri",
"id",
"initialTokenQty",
"mintingBatonStatus",
"name",
"symbol",
"timestamp",
"timestampUnix",
"totalBurned",
"totalMinted",
"txnsSinceGenesis",
"validAddresses",
"versionType"
])
it("should do something", () => {
console.log("hello world")
})
//
// it(`should list single SLP token by id`, async () => {
// // Mock the call to the REST API
// // if (process.env.TEST === "unit") {
// // nock(SERVER)
// // .get(uri => uri.includes("/"))
// // .reply(200, mockData.mockToken)
// // }
//
// const tokenId =
// "4276533bb702e7f8c9afd8aa61ebf016e95011dc3d54e55faa847ac1dd461e84"
//
// console.log(`uut.restURL: ${uut.restURL}`)
//
// const list = await uut.Utils.list(tokenId)
// console.log(`list: ${JSON.stringify(list, null, 2)}`)
//
// // assert.equal(list.id, tokenId)
// })
it(`should list single SLP token by id: 4276533bb702e7f8c9afd8aa61ebf016e95011dc3d54e55faa847ac1dd461e84`, async () => {
// Mock the call to the REST API
if (process.env.TEST === "unit") {
nock(SERVER)
.get(uri => uri.includes("/"))
.reply(200, mockData.mockToken)
}
const tokenId =
"4276533bb702e7f8c9afd8aa61ebf016e95011dc3d54e55faa847ac1dd461e84"
const list = await uut.Utils.list(tokenId)
//console.log(`list: ${JSON.stringify(list, null, 2)}`)
assert2.hasAllKeys(list, [
"blockCreated",
"blockLastActiveMint",
"blockLastActiveSend",
"circulatingSupply",
"containsBaton",
"decimals",
"documentHash",
"documentUri",
"id",
"initialTokenQty",
"mintingBatonStatus",
"name",
"symbol",
"timestamp",
"timestampUnix",
"totalBurned",
"totalMinted",
"txnsSinceGenesis",
"validAddresses",
"versionType"
])
assert.equal(list.id, tokenId)
})
it(`should list multiple SLP tokens by array of ids`, async () => {
// Mock the call to the REST API
if (process.env.TEST === "unit") {
nock(SERVER)
.post(uri => uri.includes("/"))
.reply(200, mockData.mockTokens)
}
const tokenIds = [
"4276533bb702e7f8c9afd8aa61ebf016e95011dc3d54e55faa847ac1dd461e84",
"b3f4f132dc3b9c8c96316346993a8d54d729715147b7b11aa6c8cd909e955313"
]
const list = await uut.Utils.list(tokenIds)
// console.log(`list: ${JSON.stringify(list, null, 2)}`)
assert2.hasAllKeys(list[0], [
"blockCreated",
"blockLastActiveMint",
"blockLastActiveSend",
"circulatingSupply",
"containsBaton",
"decimals",
"documentHash",
"documentUri",
"id",
"initialTokenQty",
"mintingBatonStatus",
"name",
"symbol",
"timestamp",
"timestampUnix",
"totalBurned",
"totalMinted",
"txnsSinceGenesis",
"validAddresses",
"versionType"
])
assert.equal(list[0].id, tokenIds[0])
})
// it(`should list multiple SLP tokens by array of ids`, async () => {
// // Mock the call to the REST API
// if (process.env.TEST === "unit") {
// nock(SERVER)
// .post(uri => uri.includes("/"))
// .reply(200, mockData.mockTokens)
// }
//
// const tokenIds = [
// "4276533bb702e7f8c9afd8aa61ebf016e95011dc3d54e55faa847ac1dd461e84",
// "b3f4f132dc3b9c8c96316346993a8d54d729715147b7b11aa6c8cd909e955313"
// ]
//
// const list = await uut.Utils.list(tokenIds)
// // console.log(`list: ${JSON.stringify(list, null, 2)}`)
//
// assert2.hasAllKeys(list[0], [
// "blockCreated",
// "blockLastActiveMint",
// "blockLastActiveSend",
// "circulatingSupply",
// "containsBaton",
// "decimals",
// "documentHash",
// "documentUri",
// "id",
// "initialTokenQty",
// "mintingBatonStatus",
// "name",
// "symbol",
// "timestamp",
// "timestampUnix",
// "totalBurned",
// "totalMinted",
// "txnsSinceGenesis",
// "validAddresses",
// "versionType"
// ])
// assert.equal(list[0].id, tokenIds[0])
// })
})
/*
describe("#balancesForAddress", () => {
it(`should throw an error if input is not a string or array of strings`, async () => {
try {
@@ -1802,8 +1750,10 @@ describe("#SLP Utils", () => {
const txid = `d284e71227ec89f714b964d8eda595be6392bebd2fac46082bc5a9ce6fb7b33e`
const result = await uut.Utils.txDetails(txid)
await uut.Utils.txDetails(txid)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.fail("Unexpected result")
} catch (err) {
// console.log(`err: `, err)
assert2.include(err.error, `TXID not found`, "Expected error message.")
@@ -1996,6 +1946,7 @@ describe("#SLP Utils", () => {
console.log(`result: ${JSON.stringify(result, null, 2)}`)
})
*/
/*
})
describe("#getWhitelist", () => {
@@ -2105,4 +2056,5 @@ describe("#SLP Utils", () => {
}
})
})
*/
})