fix: enable error catching for wasm module (#10)

* wip: testing error catching

* chore: version update

* chore: add mocha test boilerplate

* chore: fix linter
This commit is contained in:
tsukino
2024-01-30 09:38:18 -05:00
committed by GitHub
parent 015dd1b358
commit 4f9c6f3ee6
7 changed files with 2469 additions and 38 deletions

View File

@@ -28,6 +28,7 @@
"node_modules",
"build",
"test-build",
"dev-build",
"wasm",
"utils",
"webpack.config.js",

11
.mocharc.json Normal file
View File

@@ -0,0 +1,11 @@
{
"extension": [
"ts"
],
"spec": "tests/**/*.ts",
"require": [
"ts-node/register",
"source-map-support/register"
],
"recursive": true
}

2412
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "tlsn-js",
"version": "v0.1.0-alpha.3-rc1",
"version": "v0.1.0-alpha.3-rc2",
"description": "",
"repository": "https://github.com/tlsnotary/tlsn-js",
"main": "build/index.js",
@@ -23,12 +23,15 @@
"dev": "concurrently npm:watch:dev npm:serve:dev",
"lint:eslint": "eslint . --fix",
"lint:tsc": "tsc --noEmit",
"lint": "concurrently npm:lint:tsc npm:lint:eslint"
"lint": "concurrently npm:lint:tsc npm:lint:eslint",
"test": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register 'test/test.ts'"
},
"dependencies": {
"comlink": "^4.4.1"
},
"devDependencies": {
"@types/expect": "^24.3.0",
"@types/mocha": "^10.0.6",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"browserify": "^17.0.0",
"concurrently": "^5.1.0",
@@ -42,12 +45,15 @@
"html-webpack-plugin": "~5.3.2",
"https-browserify": "^1.0.0",
"image-webpack-loader": "^6.0.0",
"mocha": "^10.2.0",
"node-loader": "^0.6.0",
"prettier": "^3.0.2",
"process": "^0.11.10",
"serve": "14.2.1",
"stream-browserify": "^3.0.0",
"ts-loader": "^6.2.1",
"ts-mocha": "^10.0.0",
"ts-node": "^10.9.2",
"typescript": "^4.9.3",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.0",

View File

@@ -5,7 +5,6 @@ export default class TLSN {
private resolveStart: any;
constructor() {
console.log('worker module initiated.');
this.startPromise = new Promise((resolve) => {
this.resolveStart = resolve;
});
@@ -13,13 +12,14 @@ export default class TLSN {
}
async start() {
console.log('start');
// console.log('start');
const numConcurrency = navigator.hardwareConcurrency;
console.log('!@# navigator.hardwareConcurrency=', numConcurrency);
const res = await init();
console.log('!@# res.memory=', res.memory);
// console.log('!@# navigator.hardwareConcurrency=', numConcurrency);
await init();
// const res = await init();
// console.log('!@# res.memory=', res.memory);
// 6422528 ~= 6.12 mb
console.log('!@# res.memory.buffer.length=', res.memory.buffer.byteLength);
// console.log('!@# res.memory.buffer.length=', res.memory.buffer.byteLength);
await initThreadPool(numConcurrency);
this.resolveStart();
}
@@ -41,37 +41,32 @@ export default class TLSN {
secretResps?: string[];
},
) {
try {
await this.waitForStart();
console.log('worker', url, {
await this.waitForStart();
// console.log('worker', url, {
// ...options,
// notaryUrl: options?.notaryUrl,
// websocketProxyUrl: options?.websocketProxyUrl,
// });
const resProver = await prover(
url,
{
...options,
notaryUrl: options?.notaryUrl,
websocketProxyUrl: options?.websocketProxyUrl,
});
const resProver = await prover(
url,
{
...options,
notaryUrl: options?.notaryUrl,
websocketProxyUrl: options?.websocketProxyUrl,
},
options?.secretHeaders || [],
options?.secretResps || [],
);
const resJSON = JSON.parse(resProver);
console.log('!@# resProver,resJSON=', { resProver, resJSON });
console.log('!@# resAfter.memory=', resJSON.memory);
// 1105920000 ~= 1.03 gb
console.log(
'!@# resAfter.memory.buffer.length=',
resJSON.memory?.buffer?.byteLength,
);
},
options?.secretHeaders || [],
options?.secretResps || [],
);
const resJSON = JSON.parse(resProver);
// console.log('!@# resProver,resJSON=', { resProver, resJSON });
// console.log('!@# resAfter.memory=', resJSON.memory);
// 1105920000 ~= 1.03 gb
// console.log(
// '!@# resAfter.memory.buffer.length=',
// resJSON.memory?.buffer?.byteLength,
// );
return resJSON;
} catch (e: any) {
console.log(e);
return e;
}
return resJSON;
}
async verify(proof: any, pubkey: string) {

10
test/test.ts Normal file
View File

@@ -0,0 +1,10 @@
import * as assert from 'assert';
import { describe, it } from 'mocha';
describe('Array', function () {
describe('#indexOf()', function () {
it('should return -1 when the value is not present', function () {
assert.equal([1, 2, 3].indexOf(4), -1);
});
});
});

View File

@@ -1,6 +1,7 @@
{
"compilerOptions": {
"baseUrl": ".",
"module": "esnext",
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
@@ -9,7 +10,6 @@
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,