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
+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", () => {
}
})
})
*/
})