From e9200bb599c2351080806edbf4c2a3859fdfca67 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Wed, 31 Dec 2025 08:55:00 -0800 Subject: [PATCH] Add test for non-piped direct CLI input. Fix CLI parsing of input hashes from arguments. --- src/bin/cli.ts | 2 +- test/script.sh | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/bin/cli.ts b/src/bin/cli.ts index d1e8cd9..ccd35cb 100755 --- a/src/bin/cli.ts +++ b/src/bin/cli.ts @@ -65,7 +65,7 @@ Full documentation: const inArgs: string[] = [] let isParsingHash: boolean = true while (isParsingHash) { - if (!isHex8(args[args.length - 1])) break + if (!isHex32(args[args.length - 1])) break try { inArgs.unshift(args.pop() as string) } catch { diff --git a/test/script.sh b/test/script.sh index 04121a9..c825107 100755 --- a/test/script.sh +++ b/test/script.sh @@ -2,6 +2,8 @@ # SPDX-FileCopyrightText: 2025 Chris Duncan # SPDX-License-Identifier: GPL-3.0-or-later +set -euo pipefail + SCRIPT_LINK=$(readlink -f "$0"); SCRIPT_DIR=$(dirname "$SCRIPT_LINK"); NANO_POW_HOME="$HOME"/.nano-pow; @@ -11,39 +13,43 @@ export NANO_POW_DEBUG=true export NANO_POW_EFFORT=4 export NANO_POW_PORT=5041 -printf '\nTest CLI benchmark\n' +printf '\n\n\e[1mTest CLI benchmark\e[0m\n\n' "$SCRIPT_DIR"/../dist/bin/nano-pow.sh --debug --effort 4 --benchmark 10 --score 10 -printf '\nTest CLI piped input\n' +printf '\n\n\e[1mTest CLI execution\e[0m\n\n' +"$SCRIPT_DIR"/../dist/bin/nano-pow.sh --debug --effort 4 92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D +"$SCRIPT_DIR"/../dist/bin/nano-pow.sh 92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D --debug && exit + +printf '\n\n\e[1mTest CLI piped input\e[0m\n\n' cat "$SCRIPT_DIR"/blockhashes.txt | "$SCRIPT_DIR"/../dist/bin/nano-pow.sh --debug --effort 4 -printf '\nLaunching test server\n' +printf '\n\n\e[1mLaunching test server\e[0m\n\n' "$SCRIPT_DIR"/../dist/bin/nano-pow.sh --server sleep 3s -printf '\nGet documentation\n' +printf '\n\n\e[1mGet documentation\e[0m\n\n' curl localhost:5041 -printf '\nExpect errors. Server should not crash when bad data is received like missing end quote or requests exceeding max size\n' +printf '\n\n\e[1mExpect errors. Server should not crash when bad data is received like missing end quote or requests exceeding max size\e[0m\n\n' curl -d '{ "action": "work_validate", "work": "47c83266398728cf", "hash: "92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D" }' localhost:5041 curl -d '{ "action": "work_validate", "work": "47c83266398728cf", "hash": "92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D }' localhost:5041 curl -d '{ "action": "work_validate", "work": "47c83266398728cf", "hash": "92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D", "difficulty": "-1", "foo": "bar" }' localhost:5041 -printf '\nValidate good hashes\n' +printf '\n\n\e[1mValidate good hashes\e[0m\n\n' curl -d '{ "action": "work_validate", "work": "47c83266398728cf", "hash": "92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D" }' localhost:5041 curl -d '{ "action": "work_validate", "work": "4a8fb104eebbd336", "hash": "8797585D56B8AEA3A62899C31FC088F9BE849BA8298A88E94F6E3112D4E55D01" }' localhost:5041 curl -d '{ "action": "work_validate", "work": "c5d5d6f7c5d6ccd1", "hash": "281E89AC73B1082B464B9C3C1168384F846D39F6DF25105F8B4A22915E999117" }' localhost:5041 curl -d '{ "action": "work_validate", "work": "326f310d629a8a98", "hash": "204076E3364D16A018754FF67D418AB2FBEB38799FF9A29A1D5F9E34F16BEEEA", "difficulty": "fffffff700000000" }' localhost:5041 curl -d '{ "action": "work_validate", "work": "6866c1ac3831a891", "hash": "7069D9CD1E85D6204301D254B0927F06ACC794C9EA5DF70EA5578458FB597090", "difficulty": "fffffe0000000000" }' localhost:5041 -printf '\nValidate bad hashes\n' +printf '\n\n\e[1mValidate bad hashes\e[0m\n\n' curl -d '{ "action": "work_validate", "work": "0000000000000000", "hash": "0000000000000000000000000000000000000000000000000000000000000000" }' localhost:5041 curl -d '{ "action": "work_validate", "work": "c5d5d6f7c5d6ccd1", "hash": "BA1E946BA3D778C2F30A83D44D2132CC6EEF010D8D06FF10A8ABD0100D8FB47E" }' localhost:5041 curl -d '{ "action": "work_validate", "work": "29a9ae0236990e2e", "hash": "32721F4BD2AFB6F6A08D41CD0DF3C0D9C0B5294F68D0D12422F52B28F0800B5F" }' localhost:5041 curl -d '{ "action": "work_validate", "work": "ae238556213c3624", "hash": "BF41D87DA3057FDC6050D2B00C06531F89F4AA6195D7C6C2EAAF15B6E703F8F6", "difficulty": "fffffff700000000" }' localhost:5041 curl -d '{ "action": "work_validate", "work": "7d903b18d03f9820", "hash": "39C57C28F904DFE4012288FFF64CE80C0F42601023A9C82108E8F7B2D186C150", "difficulty": "fffffe0000000000" }' localhost:5041 -printf '\nTest generate\n' +printf '\n\n\e[1mTest generate\e[0m\n\n' curl -d '{ "action": "work_generate", "hash": "0D653EBFE692CA655449B301DBCEEF4E4A47454E3DFDF8C87B87C50DB6530A25" }' localhost:5041 curl -d '{ "action": "work_generate", "hash": "E93104CFC1CE40B2A29F0E85807E7E51E521C30E2B79A8EDDDB2D771DCF5C06B" }' localhost:5041 curl -d '{ "action": "work_generate", "hash": "472F8F5D908AF51E9583950D50BAE6A8C5FD66D6984FA62D4D31ADDEA5AA3AC7" }' localhost:5041 -- 2.47.3