Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lint): lint & github action updates #37

Merged
merged 6 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**
Expand Down
1 change: 0 additions & 1 deletion lib/dashtx.js

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -18,11 +18,11 @@
"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 [email protected] -- reexport",
"test": "node ./tests/",
"--------------": "-----------------------------------------------",
"jshint": "npx -p [email protected] -- jshint -c ./.jshintrc ./*.js ./lib",
"jshint": "npx -p [email protected] -- jshint -c ./.jshintrc ./*.js",
"prettier": "npx -p [email protected] -- prettier -w '**/*.{js,md}'",
"reexport-types": "npx -p [email protected] -- reexport",
"tsc": "npx -p [email protected] -- tsc -p ./jsconfig.json"
Expand Down
104 changes: 104 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
@@ -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);
});
32 changes: 17 additions & 15 deletions tx.test.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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");
Expand All @@ -61,9 +64,8 @@ async function main() {
],
outputs: [
{
// TODO pubkeyhash or pubKeyHash, but NOT BOTH
pubkeyhash: "f93af105187d21ed6adfa5d71bfada7d7324e53c",
units: 190968096,
pubKeyHash: "f93af105187d21ed6adfa5d71bfada7d7324e53c",
satoshis: 190968096,
},
],
};
Expand Down Expand Up @@ -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,
},
],
};
Expand Down Expand Up @@ -267,8 +269,8 @@ async function main() {
],
outputs: [
{
pubkeyhash: "f93af105187d21ed6adfa5d71bfada7d7324e53c",
units: 190968096,
pubKeyHash: "f93af105187d21ed6adfa5d71bfada7d7324e53c",
satoshis: 190968096,
},
],
});
Expand Down
25 changes: 0 additions & 25 deletions utils.js

This file was deleted.

Loading