Compare commits

...
7 Commits
Author SHA1 Message Date
Chris Troutner 2df36124b4 Merge pull request #84 from Permissionless-Software-Foundation/ct-unstable
fix(tokenUtxoDetails): Removing requirement to provide satoshis or va…
2021-01-09 15:45:43 -08:00
Chris Troutner c422d8db34 fix(tokenUtxoDetails): Removing requirement to provide satoshis or value in input 2021-01-09 15:43:29 -08:00
Chris Troutner ec2d8ea80a Merge pull request #83 from Permissionless-Software-Foundation/ct-unstable
fix(tests): Updated unit and integration tests
2021-01-07 17:52:02 -08:00
Chris Troutner fc527834ea Merge branch 'master' into ct-unstable 2021-01-07 17:44:56 -08:00
Chris Troutner 3ceebc1f12 fix(tests): Updated unit and integration tests 2021-01-07 17:44:04 -08:00
Chris Troutner 2ff46c1f76 Merge pull request #82 from Permissionless-Software-Foundation/ct-unstable
fix(axios): Updating axios
2021-01-04 14:49:11 -08:00
Chris Troutner 6926bbe113 fix(axios): Updating axios 2021-01-04 14:44:48 -08:00
8 changed files with 849 additions and 316 deletions
+772 -243
View File
File diff suppressed because it is too large Load Diff
+5 -6
View File
@@ -14,10 +14,10 @@
"test:integration:bchn": "export RESTURL=https://bchn.fullstack.cash/v4/ && export IS_USING_FREE_TIER=true && mocha --timeout 30000 test/integration/ && mocha --timeout 30000 test/integration/chains/bchn/",
"test:integration:testnet": "IS_USING_FREE_TIER=true mocha --timeout 30000 test/integration/chains/testnet/",
"test:integration:local": "RESTURL=http://localhost:3000/v4/ mocha --timeout 30000 test/integration",
"test:integration:local:bchn": "RESTURL=http://localhost:3000/v4/ bash test/integration/test-bchn-integration.sh",
"test:integration:local:bchn": "RESTURL=http://localhost:3000/v4/ mocha --timeout 30000 test/integration/ && mocha --timeout 30000 test/integration/chains/bchn/",
"test:integration:local:testnet": "RESTURL=http://localhost:4000/v4/ mocha --timeout 30000 test/integration/testnet",
"test:temp": "export RESTURL=https://bchn.fullstack.cash/v4/ && mocha --timeout 30000 -g '#getStatus' test/integration/",
"test:temp2": "mocha --timeout 30000 -g '#getStatus' test/unit/",
"test:temp": "export RESTURL=https://bchn.fullstack.cash/v4/ && mocha --timeout 30000 -g '#tokenUtxoDetails' test/integration/",
"test:temp2": "mocha --timeout 30000 -g '#generateSendOpReturn' 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",
@@ -32,9 +32,9 @@
"dependencies": {
"@uppy/core": "^1.10.4",
"@uppy/tus": "^1.5.12",
"apidoc": "^0.17.7",
"apidoc": "^0.25.0",
"assert": "^2.0.0",
"axios": "^0.19.0",
"axios": "^0.21.1",
"bc-bip68": "^1.0.5",
"bchaddrjs-slp": "^0.2.5",
"bigi": "^1.4.2",
@@ -87,7 +87,6 @@
"husky": "^4.3.6",
"lodash.clonedeep": "^4.5.0",
"mocha": "^6.1.4",
"nock": "^10.0.6",
"node-mocks-http": "^1.7.0",
"nyc": "^14.1.0",
"prettier": "^1.18.2",
+2 -2
View File
@@ -118,11 +118,11 @@ class TokenType1 {
// Convert the send quantity to the format expected by slp-mdm.
const baseQty = sendQtyBig.toString()
// console.log(`baseQty: `, baseQty)
console.log('baseQty: ', baseQty)
// Convert the change quantity to the format expected by slp-mdm.
const baseChange = change.toString()
// console.log(`baseChange: `, baseChange)
console.log('baseChange: ', baseChange)
// Check for potential burns
const outputQty = new BigNumber(baseChange).plus(
+15 -14
View File
@@ -1073,17 +1073,18 @@ class Utils {
for (let i = 0; i < utxos.length; i++) {
const utxo = utxos[i]
if (!utxo.satoshis) {
// If Electrumx, convert the value to satoshis.
if (utxo.value) {
utxo.satoshis = utxo.value
} else {
// If there is neither a satoshis or value property, throw an error.
throw new Error(
`utxo ${i} does not have a satoshis or value property.`
)
}
}
// CT 1/9/21: This code can be removed after 2/1/21
// if (!utxo.satoshis) {
// // If Electrumx, convert the value to satoshis.
// if (utxo.value) {
// utxo.satoshis = utxo.value
// } else {
// // If there is neither a satoshis or value property, throw an error.
// throw new Error(
// `utxo ${i} does not have a satoshis or value property.`
// )
// }
// }
if (!utxo.txid) {
// If Electrumx, convert the tx_hash property to txid.
@@ -1136,7 +1137,7 @@ class Utils {
err.message.indexOf('trailing data') === -1)
) {
// console.log(
// `unknown error from decodeOpReturn(). Marking as 'null'`,
// 'unknown error from decodeOpReturn(). Marking as \'null\'',
// err
// )
@@ -1147,7 +1148,7 @@ class Utils {
// an SLP UTXO.
// Mark as false and continue the loop.
} else {
// console.log("marking as invalid")
// console.log('marking as invalid')
utxo.isValid = false
outAry.push(utxo)
}
@@ -1254,7 +1255,7 @@ class Utils {
// Figure out what token quantity is represented by this utxo.
const tokenQty = slpData.amounts[utxo.vout - 1]
// console.log(`tokenQty: `, tokenQty)
// console.log('tokenQty: ', tokenQty)
if (!tokenQty) {
// outAry[i] = false
+2 -2
View File
@@ -743,8 +743,8 @@ describe('#SLP', () => {
const tokenUtxos = [
{
tokenId:
'0a321bff9761f28e06a268b14711274bb77617410a16807bd0437ef234a072b1',
decimals: 0,
'38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0',
decimals: 8,
tokenQty: 2
}
]
-8
View File
@@ -3,7 +3,6 @@
*/
const assert = require('chai').assert
const nock = require('nock') // http call mocking
const sinon = require('sinon')
// const axios = require("axios")
@@ -24,17 +23,10 @@ describe('#SLP NFT1', () => {
let sandbox
beforeEach(() => {
// Activate nock if it's inactive.
if (!nock.isActive()) nock.activate()
sandbox = sinon.createSandbox()
})
afterEach(() => {
// Clean up HTTP mocks.
nock.cleanAll() // clear interceptor list.
nock.restore()
sandbox.restore()
})
+19 -8
View File
@@ -3,7 +3,6 @@
*/
const assert = require('chai').assert
const nock = require('nock') // http call mocking
const sinon = require('sinon')
// const axios = require("axios")
@@ -24,17 +23,10 @@ describe('#SLP TokenType1', () => {
let sandbox
beforeEach(() => {
// Activate nock if it's inactive.
if (!nock.isActive()) nock.activate()
sandbox = sinon.createSandbox()
})
afterEach(() => {
// Clean up HTTP mocks.
nock.cleanAll() // clear interceptor list.
nock.restore()
sandbox.restore()
})
@@ -1186,6 +1178,25 @@ describe('#SLP TokenType1', () => {
})
})
describe('#generateSendOpReturn07', () => {
it('should generate send OP_RETURN code', () => {
// Mock UTXO.
const tokenUtxos = [
{
tokenId: '38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0',
decimals: 8,
tokenQty: 2
}
]
const result = bchjs.SLP.TokenType1.generateSendOpReturn(tokenUtxos, 1.5)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.hasAllKeys(result, ['script', 'outputs'])
assert.isNumber(result.outputs)
})
})
describe('#generateBurnOpReturn', () => {
it('should generate burn OP_RETURN code', () => {
// Mock UTXO.
+34 -33
View File
@@ -497,39 +497,40 @@ describe('#SLP Utils', () => {
}
})
it('should throw error if utxo does not have satoshis or value property.', async () => {
try {
const utxos = [
{
txid:
'bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90',
vout: 3,
amount: 0.00002015,
satoshis: 2015,
height: 594892,
confirmations: 5
},
{
txid:
'bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90',
vout: 2,
amount: 0.00000546,
height: 594892,
confirmations: 5
}
]
await uut.Utils.tokenUtxoDetails(utxos)
assert.equal(true, false, 'Unexpected result.')
} catch (err) {
assert.include(
err.message,
'utxo 1 does not have a satoshis or value property',
'Expected error message.'
)
}
})
// CT 1/9/21: This test can be removed after 2/1/21
// it('should throw error if utxo does not have satoshis or value property.', async () => {
// try {
// const utxos = [
// {
// txid:
// 'bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90',
// vout: 3,
// amount: 0.00002015,
// satoshis: 2015,
// height: 594892,
// confirmations: 5
// },
// {
// txid:
// 'bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90',
// vout: 2,
// amount: 0.00000546,
// height: 594892,
// confirmations: 5
// }
// ]
//
// await uut.Utils.tokenUtxoDetails(utxos)
//
// assert.equal(true, false, 'Unexpected result.')
// } catch (err) {
// assert.include(
// err.message,
// 'utxo 1 does not have a satoshis or value property',
// 'Expected error message.'
// )
// }
// })
it('should throw error if utxo does not have txid or tx_hash property.', async () => {
try {