add simpleHash function & tests, add coverage

This commit is contained in:
Smart 2022-02-25 16:36:19 +10:00
parent e6a1ce979c
commit 744438ceba
3 changed files with 37 additions and 1 deletions

14
.run/ts-mocha.run.xml Normal file
View File

@ -0,0 +1,14 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="ts-mocha" type="mocha-javascript-test-runner">
<node-interpreter>project</node-interpreter>
<node-options />
<mocha-package>$PROJECT_DIR$/node_modules/ts-mocha</mocha-package>
<working-directory>$PROJECT_DIR$</working-directory>
<pass-parent-env>true</pass-parent-env>
<ui>bdd</ui>
<extra-mocha-options />
<test-kind>PATTERN</test-kind>
<test-pattern>$PROJECT_DIR$/test/*.spec.ts</test-pattern>
<method v="2" />
</configuration>
</component>

View File

@ -5,6 +5,10 @@
"repository": "https://github.com/tornadocash/fixed-merkle-tree.git", "repository": "https://github.com/tornadocash/fixed-merkle-tree.git",
"main": "lib/index.js", "main": "lib/index.js",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",
"engines": {
"node": "14.17",
"npm": "6"
},
"scripts": { "scripts": {
"test": "ts-mocha 'test/*.spec.ts'", "test": "ts-mocha 'test/*.spec.ts'",
"build": "tsc", "build": "tsc",
@ -22,7 +26,6 @@
"files": [ "files": [
"src/*" "src/*"
], ],
"dependencies": {},
"devDependencies": { "devDependencies": {
"@types/expect": "^24.3.0", "@types/expect": "^24.3.0",
"@types/mocha": "^9.1.0", "@types/mocha": "^9.1.0",
@ -31,6 +34,7 @@
"chai": "^4.2.0", "chai": "^4.2.0",
"eslint": "^8.9.0", "eslint": "^8.9.0",
"eslint-config-prettier": "^8.3.0", "eslint-config-prettier": "^8.3.0",
"nyc": "^15.1.0",
"mocha": "^9.2.1", "mocha": "^9.2.1",
"ts-mocha": "^9.0.2", "ts-mocha": "^9.0.2",
"typescript": "^4.5.5" "typescript": "^4.5.5"

18
test/simpleHash.spec.ts Normal file
View File

@ -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')
})
})