From 3ceebc1f12414b5d34f5364244b1ad70ee977a07 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 7 Jan 2021 17:44:04 -0800 Subject: [PATCH] fix(tests): Updated unit and integration tests --- package.json | 6 +++--- src/slp/tokentype1.js | 4 ++-- src/slp/utils.js | 6 +++--- test/integration/slp.js | 4 ++-- test/unit/slp-tokentype1.js | 19 +++++++++++++++++++ 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 20cee03..7b4482f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/slp/tokentype1.js b/src/slp/tokentype1.js index 63baccc..c71d0f2 100644 --- a/src/slp/tokentype1.js +++ b/src/slp/tokentype1.js @@ -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( diff --git a/src/slp/utils.js b/src/slp/utils.js index d6a6512..ad151ec 100644 --- a/src/slp/utils.js +++ b/src/slp/utils.js @@ -1136,7 +1136,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 +1147,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 +1254,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 diff --git a/test/integration/slp.js b/test/integration/slp.js index e535988..405fcd7 100644 --- a/test/integration/slp.js +++ b/test/integration/slp.js @@ -743,8 +743,8 @@ describe('#SLP', () => { const tokenUtxos = [ { tokenId: - '0a321bff9761f28e06a268b14711274bb77617410a16807bd0437ef234a072b1', - decimals: 0, + '38e97c5d7d3585a2cbf3f9580c82ca33985f9cb0845d4dcce220cb709f9538b0', + decimals: 8, tokenQty: 2 } ] diff --git a/test/unit/slp-tokentype1.js b/test/unit/slp-tokentype1.js index 198fcee..d3bda31 100644 --- a/test/unit/slp-tokentype1.js +++ b/test/unit/slp-tokentype1.js @@ -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.