From 744438cebad1c0c7276bc2874cb49f512f993b19 Mon Sep 17 00:00:00 2001 From: Smart Date: Fri, 25 Feb 2022 16:36:19 +1000 Subject: [PATCH] add simpleHash function & tests, add coverage --- .run/ts-mocha.run.xml | 14 ++++++++++++++ package.json | 6 +++++- test/simpleHash.spec.ts | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 .run/ts-mocha.run.xml create mode 100644 test/simpleHash.spec.ts diff --git a/.run/ts-mocha.run.xml b/.run/ts-mocha.run.xml new file mode 100644 index 0000000..b8c1d06 --- /dev/null +++ b/.run/ts-mocha.run.xml @@ -0,0 +1,14 @@ + + + project + + $PROJECT_DIR$/node_modules/ts-mocha + $PROJECT_DIR$ + true + bdd + + PATTERN + $PROJECT_DIR$/test/*.spec.ts + + + diff --git a/package.json b/package.json index f8cf2be..43b8459 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,10 @@ "repository": "https://github.com/tornadocash/fixed-merkle-tree.git", "main": "lib/index.js", "types": "lib/index.d.ts", + "engines": { + "node": "14.17", + "npm": "6" + }, "scripts": { "test": "ts-mocha 'test/*.spec.ts'", "build": "tsc", @@ -22,7 +26,6 @@ "files": [ "src/*" ], - "dependencies": {}, "devDependencies": { "@types/expect": "^24.3.0", "@types/mocha": "^9.1.0", @@ -31,6 +34,7 @@ "chai": "^4.2.0", "eslint": "^8.9.0", "eslint-config-prettier": "^8.3.0", + "nyc": "^15.1.0", "mocha": "^9.2.1", "ts-mocha": "^9.0.2", "typescript": "^4.5.5" diff --git a/test/simpleHash.spec.ts b/test/simpleHash.spec.ts new file mode 100644 index 0000000..39fbb2a --- /dev/null +++ b/test/simpleHash.spec.ts @@ -0,0 +1,18 @@ +import simpleHash from '../src/simpleHash' +import { it } from 'mocha' +import { should } from 'chai' + +describe('SimpleHash', () => { + it('should return correct hash string with default params', () => { + const hash = simpleHash([1, 2, 3]) + return should().equal(hash, '3530513397947785053296897142557895557120') + }) + it('should return correct hash string with length param', () => { + const hash = simpleHash([1, 2, 3], null, 77) + return should().equal(hash, '1259729275322113643079999203492506359813191573070980317691663537897682854338069790720') + }) + it('should return correct hash string with seed param', () => { + const hash = simpleHash(['1', '2', '3'], 123) + return should().equal(hash, '1371592418687375416654554138100746944512') + }) +})