fix(slp utils): refactoring unit tests

This commit is contained in:
Chris Troutner
2020-12-06 15:41:39 -08:00
parent 3df211301c
commit e97a8e7cf5
5 changed files with 111 additions and 120 deletions
+1 -2
View File
@@ -338,7 +338,7 @@ describe("#address.js", () => {
})
})
})
/*
describe("address format detection", () => {
describe("#isLegacyAddress", () => {
describe("is legacy", () => {
@@ -932,5 +932,4 @@ describe("#address.js", () => {
})
})
})
*/
})
+41 -67
View File
@@ -1,9 +1,7 @@
// Public npm libraries
const assert = require("assert")
const assert2 = require("chai").assert
// const nock = require("nock") // http call mocking
const assert = require("chai").assert
const sinon = require("sinon")
// const axios = require("axios")
const cloneDeep = require("lodash.clonedeep")
// Unit under test
const SLP = require("../../src/slp/slp")
@@ -15,7 +13,8 @@ const REST_URL = process.env.RESTURL
: "https://bchn.fullstack.cash/v4/"
// Mock data used for unit tests
const mockData = require("./fixtures/slp/mock-utils")
const mockDataLib = require("./fixtures/slp/mock-utils")
let mockData
// Default to unit tests unless some other value for TEST is passed.
if (!process.env.TEST) process.env.TEST = "unit"
@@ -27,6 +26,8 @@ describe("#SLP Utils", () => {
// Activate nock if it's inactive.
// if (!nock.isActive()) nock.activate()
mockData = cloneDeep(mockDataLib)
sandbox = sinon.createSandbox()
uut = new SLP({
@@ -45,69 +46,42 @@ describe("#SLP Utils", () => {
})
describe("#list", () => {
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`, async () => {
sandbox
.stub(uut.Utils.axios, "get")
.resolves({ data: mockData.mockToken })
// 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])
// })
const tokenId =
"4276533bb702e7f8c9afd8aa61ebf016e95011dc3d54e55faa847ac1dd461e84"
const list = await uut.Utils.list(tokenId)
// console.log(`list: ${JSON.stringify(list, null, 2)}`)
assert.equal(list.id, tokenId)
assert.property(list, "decimals")
assert.property(list, "symbol")
assert.property(list, "documentUri")
assert.property(list, "name")
})
it(`should list multiple SLP tokens by array of ids`, async () => {
// Mock the call to the REST API
sandbox
.stub(uut.Utils.axios, "post")
.resolves({ data: mockData.mockList })
const tokenIds = [
"4276533bb702e7f8c9afd8aa61ebf016e95011dc3d54e55faa847ac1dd461e84",
"8fc284dcbc922f7bb7e2a443dc3af792f52923bba403fcf67ca028c88e89da0e"
]
const list = await uut.Utils.list(tokenIds)
// console.log(`list: ${JSON.stringify(list, null, 2)}`)
assert.isArray(list)
assert.property(list[0], "symbol")
assert.property(list[1], "symbol")
})
})
/*
describe("#balancesForAddress", () => {