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
+67 -51
View File
@@ -1,6 +1,6 @@
{
"name": "@psf/bch-js",
"version": "3.4.0",
"version": "4.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -4445,6 +4445,12 @@
"integrity": "sha1-+CbJtOKoUR2E46yinbBeGk87cqk=",
"dev": true
},
"lodash.clonedeep": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
"integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=",
"dev": true
},
"lodash.escaperegexp": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz",
@@ -5253,9 +5259,9 @@
}
},
"node-fetch": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==",
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==",
"dev": true
},
"node-mocks-http": {
@@ -5301,9 +5307,9 @@
"dev": true
},
"npm": {
"version": "6.14.7",
"resolved": "https://registry.npmjs.org/npm/-/npm-6.14.7.tgz",
"integrity": "sha512-swhsdpNpyXg4GbM6LpOQ6qaloQuIKizZ+Zh6JPXJQc59ka49100Js0WvZx594iaKSoFgkFq2s8uXFHS3/Xy2WQ==",
"version": "6.14.9",
"resolved": "https://registry.npmjs.org/npm/-/npm-6.14.9.tgz",
"integrity": "sha512-yHi1+i9LyAZF1gAmgyYtVk+HdABlLy94PMIDoK1TRKWvmFQAt5z3bodqVwKvzY0s6dLqQPVsRLiwhJfNtiHeCg==",
"dev": true,
"requires": {
"JSONStream": "^1.3.5",
@@ -5370,7 +5376,7 @@
"lodash.uniq": "~4.5.0",
"lodash.without": "~4.4.0",
"lru-cache": "^5.1.1",
"meant": "~1.0.1",
"meant": "^1.0.2",
"mississippi": "^3.0.0",
"mkdirp": "^0.5.5",
"move-concurrently": "^1.0.1",
@@ -5385,8 +5391,8 @@
"npm-packlist": "^1.4.8",
"npm-pick-manifest": "^3.0.2",
"npm-profile": "^4.0.4",
"npm-registry-fetch": "^4.0.5",
"npm-user-validate": "~1.0.0",
"npm-registry-fetch": "^4.0.7",
"npm-user-validate": "^1.0.1",
"npmlog": "~4.1.2",
"once": "~1.4.0",
"opener": "^1.5.1",
@@ -5461,17 +5467,6 @@
"humanize-ms": "^1.2.1"
}
},
"ajv": {
"version": "5.5.2",
"bundled": true,
"dev": true,
"requires": {
"co": "^4.6.0",
"fast-deep-equal": "^1.0.0",
"fast-json-stable-stringify": "^2.0.0",
"json-schema-traverse": "^0.3.0"
}
},
"ansi-align": {
"version": "2.0.0",
"bundled": true,
@@ -5802,11 +5797,6 @@
"mkdirp": "~0.5.0"
}
},
"co": {
"version": "4.6.0",
"bundled": true,
"dev": true
},
"code-point-at": {
"version": "1.1.0",
"bundled": true,
@@ -5898,11 +5888,11 @@
}
},
"configstore": {
"version": "3.1.2",
"version": "3.1.5",
"bundled": true,
"dev": true,
"requires": {
"dot-prop": "^4.1.0",
"dot-prop": "^4.2.1",
"graceful-fs": "^4.1.2",
"make-dir": "^1.0.0",
"unique-string": "^1.0.0",
@@ -6078,7 +6068,7 @@
}
},
"dot-prop": {
"version": "4.2.0",
"version": "4.2.1",
"bundled": true,
"dev": true,
"requires": {
@@ -6255,11 +6245,6 @@
"bundled": true,
"dev": true
},
"fast-deep-equal": {
"version": "1.1.0",
"bundled": true,
"dev": true
},
"fast-json-stable-stringify": {
"version": "2.0.0",
"bundled": true,
@@ -6580,12 +6565,35 @@
"dev": true
},
"har-validator": {
"version": "5.1.0",
"version": "5.1.5",
"bundled": true,
"dev": true,
"requires": {
"ajv": "^5.3.0",
"ajv": "^6.12.3",
"har-schema": "^2.0.0"
},
"dependencies": {
"ajv": {
"version": "6.12.6",
"bundled": true,
"dev": true,
"requires": {
"fast-deep-equal": "^3.1.1",
"fast-json-stable-stringify": "^2.0.0",
"json-schema-traverse": "^0.4.1",
"uri-js": "^4.2.2"
}
},
"fast-deep-equal": {
"version": "3.1.3",
"bundled": true,
"dev": true
},
"json-schema-traverse": {
"version": "0.4.1",
"bundled": true,
"dev": true
}
}
},
"has": {
@@ -6872,11 +6880,6 @@
"bundled": true,
"dev": true
},
"json-schema-traverse": {
"version": "0.3.1",
"bundled": true,
"dev": true
},
"json-stringify-safe": {
"version": "5.0.1",
"bundled": true,
@@ -7224,7 +7227,7 @@
}
},
"meant": {
"version": "1.0.1",
"version": "1.0.2",
"bundled": true,
"dev": true
},
@@ -7249,6 +7252,11 @@
"brace-expansion": "^1.1.7"
}
},
"minimist": {
"version": "1.2.5",
"bundled": true,
"dev": true
},
"minizlib": {
"version": "1.3.3",
"bundled": true,
@@ -7485,7 +7493,7 @@
}
},
"npm-registry-fetch": {
"version": "4.0.5",
"version": "4.0.7",
"bundled": true,
"dev": true,
"requires": {
@@ -7514,7 +7522,7 @@
}
},
"npm-user-validate": {
"version": "1.0.0",
"version": "1.0.1",
"bundled": true,
"dev": true
},
@@ -7859,13 +7867,6 @@
"ini": "~1.3.0",
"minimist": "^1.2.0",
"strip-json-comments": "~2.0.1"
},
"dependencies": {
"minimist": {
"version": "1.2.5",
"bundled": true,
"dev": true
}
}
},
"read": {
@@ -8525,6 +8526,21 @@
"xdg-basedir": "^3.0.0"
}
},
"uri-js": {
"version": "4.4.0",
"bundled": true,
"dev": true,
"requires": {
"punycode": "^2.1.0"
},
"dependencies": {
"punycode": {
"version": "2.1.1",
"bundled": true,
"dev": true
}
}
},
"url-parse-lax": {
"version": "1.0.0",
"bundled": true,
+1
View File
@@ -85,6 +85,7 @@
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-node": "^9.1.0",
"eslint-plugin-prettier": "^3.1.0",
"lodash.clonedeep": "^4.5.0",
"mocha": "^6.1.4",
"nock": "^10.0.6",
"node-mocks-http": "^1.7.0",
+1
View File
@@ -196,6 +196,7 @@ class Utils {
async list(id) {
let path
let method
if (!id) {
method = "get"
path = `${this.restURL}slp/list`
+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", () => {