Compare commits

...
5 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
6 changed files with 75 additions and 54 deletions
+3 -3
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",
+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
}
]
+19
View File
@@ -1178,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 {