From d21a69dcb4b1f1855e383e3f3ef5a9112b566f74 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 26 Mar 2024 23:21:40 -0600 Subject: [PATCH 1/6] chore: consolidate package.json.main --- index.js | 2 +- lib/dashtx.js | 1 - package.json | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) delete mode 100644 lib/dashtx.js diff --git a/index.js b/index.js index 1722173..b482a73 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ // auto-generated by `jswt reexport` // DO NOT EDIT -module.exports = require("./lib/dashtx.js"); +module.exports = require("./dashtx.js"); // these typedef reexports will be available to dependent packages /** diff --git a/lib/dashtx.js b/lib/dashtx.js deleted file mode 100644 index 2818fd5..0000000 --- a/lib/dashtx.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require("../dashtx.js"); diff --git a/package.json b/package.json index 98afd5f..437a7a0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "dashtx", "version": "0.13.3", "description": "Create DASH Transactions with Vanilla JS (0 deps, cross-platform)", - "main": "dashtx.js", + "main": "index.js", "files": [ "index.js", "dashtx.js", @@ -22,7 +22,7 @@ "prepublish": "npx -p jswt@1.x -- reexport", "test": "node ./tests/", "--------------": "-----------------------------------------------", - "jshint": "npx -p jshint@2.x -- jshint -c ./.jshintrc ./*.js ./lib", + "jshint": "npx -p jshint@2.x -- jshint -c ./.jshintrc ./*.js", "prettier": "npx -p prettier@2.x -- prettier -w '**/*.{js,md}'", "reexport-types": "npx -p jswt@1.x -- reexport", "tsc": "npx -p typescript@4.x -- tsc -p ./jsconfig.json" From 11db0f0e194983b29d5facd6cdc1918825e8f37e Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 26 Mar 2024 23:00:01 -0600 Subject: [PATCH 2/6] fix(test): quote 'name' field of .github/workflows/node.js.yml --- .github/workflows/node.js.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index e871743..950d569 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -5,7 +5,7 @@ on: pull_request: jobs: build: - name: Node.js build: fmt, ci, lint, test + name: 'Node.js build: fmt, ci, lint, test' runs-on: ubuntu-latest strategy: matrix: From 5a09c03c10ce4c1a8914fb98de8043f1f3069f68 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 26 Mar 2024 23:15:24 -0600 Subject: [PATCH 3/6] chore: remove tsc from lint for now --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 437a7a0..2dc384a 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "scripts": { "bump": "npm version -m \"chore(release): bump to v%s\"", "fmt": "npm run prettier", - "lint": "npm run jshint && npm run tsc", + "lint": "npm run jshint", "prepublish": "npx -p jswt@1.x -- reexport", "test": "node ./tests/", "--------------": "-----------------------------------------------", From 7a323431de00f012a4ef13211db2482383f5d72b Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 26 Mar 2024 23:02:43 -0600 Subject: [PATCH 4/6] chore: remove old Tx.utils.hexToU8Reversed --- utils.js | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 utils.js diff --git a/utils.js b/utils.js deleted file mode 100644 index fb90204..0000000 --- a/utils.js +++ /dev/null @@ -1,25 +0,0 @@ -// we probably don't need this... - -/** - * @param {String} hex - */ -Tx.utils.hexToU8Reversed = function (hex) { - let u8 = new Uint8Array(hex.length / 2); - - let i = 0; - let index = u8.length - 1; - for (;;) { - if (i >= hex.length - 2) { - break; - } - - let h = hex.slice(i, i + 2); - let b = parseInt(h, 16); - u8[index] = b; - - i += 2; - index -= 1; - } - - return u8; -}; From 2bf16a542c231e07ce6f54b8ca0eda96aa34b6fb Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 26 Mar 2024 23:11:51 -0600 Subject: [PATCH 5/6] chore: partially update tx.test.js to latest API to pass lint --- tx.test.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/tx.test.js b/tx.test.js index 7474a91..affd84f 100644 --- a/tx.test.js +++ b/tx.test.js @@ -1,6 +1,8 @@ "use strict"; -let Tx = require("./tx.js"); +let Tx = require("./"); +let toVarInt = Tx.utils.toVarInt; +let toVarIntSize = Tx.utils.toVarIntSize; /** @type {import('node:crypto')} */ //@ts-ignore @@ -38,6 +40,7 @@ Secp256k1.utils.hmacSha256 = async function (key, message) { return new Uint8Array(buffer); }; +/* jshint maxstatements: 200 */ async function main() { //let expectedBytes = "00ff0ff0fff00f00"; //let u8 = Tx.utils.hexToU8("00ff0ff0fff00f00"); @@ -61,9 +64,8 @@ async function main() { ], outputs: [ { - // TODO pubkeyhash or pubKeyHash, but NOT BOTH - pubkeyhash: "f93af105187d21ed6adfa5d71bfada7d7324e53c", - units: 190968096, + pubKeyHash: "f93af105187d21ed6adfa5d71bfada7d7324e53c", + satoshis: 190968096, }, ], }; @@ -169,21 +171,21 @@ async function main() { ], outputs: [ { - pubkeyhash: "5bcd0d776a7252310b9f1a7eee1a749d42126944", - //pubkeyhash: "1e0a6ef6085bb8af443a9e7f8941e61deb09fb54", - units: quarterValue, + pubKeyHash: "5bcd0d776a7252310b9f1a7eee1a749d42126944", + //pubKeyHash: "1e0a6ef6085bb8af443a9e7f8941e61deb09fb54", + satoshis: quarterValue, }, { - pubkeyhash: "5bcd0d776a7252310b9f1a7eee1a749d42126944", - units: quarterValue, + pubKeyHash: "5bcd0d776a7252310b9f1a7eee1a749d42126944", + satoshis: quarterValue, }, { - pubkeyhash: "5bcd0d776a7252310b9f1a7eee1a749d42126944", - units: quarterValue, + pubKeyHash: "5bcd0d776a7252310b9f1a7eee1a749d42126944", + satoshis: quarterValue, }, { - pubkeyhash: "5bcd0d776a7252310b9f1a7eee1a749d42126944", - units: quarterValue, + pubKeyHash: "5bcd0d776a7252310b9f1a7eee1a749d42126944", + satoshis: quarterValue, }, ], }; @@ -267,8 +269,8 @@ async function main() { ], outputs: [ { - pubkeyhash: "f93af105187d21ed6adfa5d71bfada7d7324e53c", - units: 190968096, + pubKeyHash: "f93af105187d21ed6adfa5d71bfada7d7324e53c", + satoshis: 190968096, }, ], }); From cbd2c7318d6755bd76f4ad6f714ca3bd0288a5fc Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 26 Mar 2024 23:50:50 -0600 Subject: [PATCH 6/6] chore: add new test runner --- tests/index.js | 104 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 tests/index.js diff --git a/tests/index.js b/tests/index.js new file mode 100644 index 0000000..371f68b --- /dev/null +++ b/tests/index.js @@ -0,0 +1,104 @@ +"use strict"; + +let ChildProcess = require("child_process"); +let Fs = require("node:fs/promises"); +let Path = require("node:path"); + +async function main() { + console.info("TAP version 13"); + + let dirents = await Fs.readdir(__dirname, { withFileTypes: true }); + + let failures = 0; + let count = 0; + for (let dirent of dirents) { + if (dirent.name === "index.js") { + continue; + } + + count += 1; + let direntPath = Path.join(__dirname, dirent.name); + let relPath = Path.relative(".", direntPath); + + let success = await handleEach(count, relPath); + if (!success) { + failures += 1; + } + } + + let passes = count - failures; + console.info(``); + console.info(`1..${count}`); + console.info(`# tests ${count}`); + console.info(`# pass ${passes}`); + console.info(`# fail ${failures}`); + console.info(`# skip 0`); + + if (failures !== 0) { + process.exit(1); + } +} + +async function handleEach(count, relPath) { + let success = await exec("node", [relPath]) + .then(function (result) { + console.info(`ok ${count} - ${relPath}`); + return true; + }) + .catch(function (err) { + console.info(`not ok ${count} - ${relPath}`); + if (err.code) { + console.info(` # Error: ${err.code}`); + } + if (err.stderr) { + console.info(` # Stderr: ${err.stderr}`); + } + return false; + }); + + return success; +} + +async function exec(exe, args) { + return new Promise(function (resolve, reject) { + let cmd = ChildProcess.spawn(exe, args); + + let stdout = []; + let stderr = []; + + cmd.stdout.on("data", function (data) { + stdout.push(data.toString("utf8")); + }); + + cmd.stderr.on("data", function (data) { + stderr.push(data.toString("utf8")); + }); + + cmd.on("close", function (code) { + let result = { + code: code, + stdout: stdout.join(""), + stderr: stderr.join(""), + }; + + if (!code) { + resolve(result); + return; + } + + let err = new Error(result.stderr); + Object.assign(err, result); + reject(err); + }); + }); +} + +main() + .then(function () { + process.exit(0); + }) + .catch(function (err) { + console.error("Fail:"); + console.error(err.stack || err); + process.exit(1); + });