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: lack of cjs package version #2848

Merged
merged 5 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions tooling/noir_js/.mocharc.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extensions": ["cjs"],
"spec": [
"test/node/**/*.test.cjs"
]
}
2 changes: 1 addition & 1 deletion tooling/noir_js/.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"require": "ts-node/register",
"loader": "ts-node/esm",
"extensions": ["ts"],
"extensions": ["ts", "cjs"],
"spec": [
"test/node/**/*.test.ts*"
]
Expand Down
17 changes: 13 additions & 4 deletions tooling/noir_js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@
"lib",
"package.json"
],
"main": "lib/index.js",
"source": "src/index.ts",
"main": "lib/index.cjs",
"module": "lib/index.js",
"exports": {
"require": "./lib/index.cjs",
"default": "./lib/index.js",
"types": "./lib/index.d.ts"
},
"types": "lib/index.d.ts",
"scripts": {
"dev": "tsc --watch",
"build": "tsc",
"dev": "tsc-multi --watch",
"build": "tsc-multi",
"test": "yarn test:node",
"test:node": "mocha --timeout 25000",
"test:node:esm": "mocha --timeout 25000 --config ./.mocharc.json",
"test:node:cjs": "mocha --timeout 25000 --config ./.mocharc.cjs.json",
"prettier": "prettier 'src/**/*.ts'",
"prettier:fix": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
"lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0"
Expand All @@ -39,6 +47,7 @@
"mocha": "^10.2.0",
"prettier": "3.0.3",
"ts-node": "^10.9.1",
"tsc-multi": "^1.1.0",
"typescript": "^5.2.2"
}
}
76 changes: 76 additions & 0 deletions tooling/noir_js/test/node/cjs.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* eslint-disable no-undef */
kobyhallx marked this conversation as resolved.
Show resolved Hide resolved
/* eslint-disable @typescript-eslint/no-var-requires */
const chai = require('chai');
const assert_lt_json = require('../noir_compiled_examples/assert_lt/target/assert_lt.json');
const noirjs = require('@noir-lang/noir_js');

it('001 generates witnesses successfully', async () => {
kobyhallx marked this conversation as resolved.
Show resolved Hide resolved
const inputs = {
x: '2',
y: '3',
};
const _solvedWitness = await noirjs.generateWitness(assert_lt_json, inputs);
});

it('string input and number input are the same', async () => {
const inputsString = {
x: '2',
y: '3',
};
const inputsNumber = {
x: 2,
y: 3,
};
const solvedWitnessString = await noirjs.generateWitness(assert_lt_json, inputsString);
const solvedWitnessNumber = await noirjs.generateWitness(assert_lt_json, inputsNumber);
chai.expect(solvedWitnessString).to.deep.equal(solvedWitnessNumber);
});

it('string input and number input are the same', async () => {
const inputsString = {
x: '2',
y: '3',
};
const inputsNumber = {
x: 2,
y: 3,
};

const solvedWitnessString = await noirjs.generateWitness(assert_lt_json, inputsString);
const solvedWitnessNumber = await noirjs.generateWitness(assert_lt_json, inputsNumber);
chai.expect(solvedWitnessString).to.deep.equal(solvedWitnessNumber);
});

it('0x prefixed string input for inputs will throw', async () => {
const inputsHexPrefix = {
x: '0x2',
y: '0x3',
};

try {
await noirjs.generateWitness(assert_lt_json, inputsHexPrefix);
chai.expect.fail(
'Expected generatedWitness to throw, due to inputs being prefixed with 0x. Currently not supported',
);
} catch (error) {
// Successfully errored due to 0x not being supported. Update this test once/if we choose
// to support 0x prefixed inputs.
}
});

describe('input validation', () => {
it('x should be a uint64 not a string', async () => {
const inputs = {
x: 'foo',
y: '3',
};

try {
await noirjs.generateWitness(assert_lt_json, inputs);
chai.expect.fail('Expected generatedWitness to throw, due to x not being convertible to a uint64');
} catch (error) {
const knownError = error;
chai.expect(knownError.message).to.equal('Input for x is the wrong type, expected uint64, got "foo"');
}
});
});
7 changes: 7 additions & 0 deletions tooling/noir_js/tsc-multi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"targets": [
{ "extname": ".cjs", "module": "commonjs" },
{ "extname": ".mjs", "module": "esnext" }
],
"projects": ["packages/*/tsconfig.json"]
}
59 changes: 57 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ __metadata:
mocha: ^10.2.0
prettier: 3.0.3
ts-node: ^10.9.1
tsc-multi: ^1.1.0
typescript: ^5.2.2
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -3544,7 +3545,7 @@ __metadata:
languageName: node
linkType: hard

"fast-glob@npm:^3.2.9, fast-glob@npm:^3.3.0":
"fast-glob@npm:^3.2.12, fast-glob@npm:^3.2.9, fast-glob@npm:^3.3.0":
version: 3.3.1
resolution: "fast-glob@npm:3.3.1"
dependencies:
Expand Down Expand Up @@ -3908,6 +3909,13 @@ __metadata:
languageName: node
linkType: hard

"get-stdin@npm:^8.0.0":
version: 8.0.0
resolution: "get-stdin@npm:8.0.0"
checksum: 40128b6cd25781ddbd233344f1a1e4006d4284906191ed0a7d55ec2c1a3e44d650f280b2c9eeab79c03ac3037da80257476c0e4e5af38ddfb902d6ff06282d77
languageName: node
linkType: hard

"get-stream@npm:^5.1.0":
version: 5.2.0
resolution: "get-stream@npm:5.2.0"
Expand Down Expand Up @@ -5817,6 +5825,15 @@ __metadata:
languageName: node
linkType: hard

"p-all@npm:^3.0.0":
version: 3.0.0
resolution: "p-all@npm:3.0.0"
dependencies:
p-map: ^4.0.0
checksum: 267a620c2330b14246b92008f4be8758debe74e1454c8fb5808544f51fd038ac4597dbeeaa1542f237794e613cd42e4f1a58c01e5a0a6a6b21340fef616257df
languageName: node
linkType: hard

"p-cancelable@npm:^3.0.0":
version: 3.0.0
resolution: "p-cancelable@npm:3.0.0"
Expand Down Expand Up @@ -6953,6 +6970,15 @@ __metadata:
languageName: node
linkType: hard

"string-to-stream@npm:^3.0.1":
version: 3.0.1
resolution: "string-to-stream@npm:3.0.1"
dependencies:
readable-stream: ^3.4.0
checksum: e8ac7f7497f8f101196e39dd529e98bb97165c532cc4cae5003083a420db62f46ffd67ddff7112b45f9f8d0f9ff1cc6cda9b06362236d43fa6b1685e8b0d446e
languageName: node
linkType: hard

"string-width-cjs@npm:string-width@^4.2.0, string-width@npm:^1.0.2 || 2 || 3 || 4, string-width@npm:^4.1.0, string-width@npm:^4.2.0, string-width@npm:^4.2.3":
version: 4.2.3
resolution: "string-width@npm:4.2.3"
Expand Down Expand Up @@ -7032,6 +7058,13 @@ __metadata:
languageName: node
linkType: hard

"superstruct@npm:^1.0.3":
version: 1.0.3
resolution: "superstruct@npm:1.0.3"
checksum: 761790bb111e6e21ddd608299c252f3be35df543263a7ebbc004e840d01fcf8046794c274bcb351bdf3eae4600f79d317d085cdbb19ca05803a4361840cc9bb1
languageName: node
linkType: hard

"supertap@npm:^3.0.1":
version: 3.0.1
resolution: "supertap@npm:3.0.1"
Expand Down Expand Up @@ -7278,6 +7311,28 @@ __metadata:
languageName: node
linkType: hard

"tsc-multi@npm:^1.1.0":
version: 1.1.0
resolution: "tsc-multi@npm:1.1.0"
dependencies:
debug: ^4.3.4
fast-glob: ^3.2.12
get-stdin: ^8.0.0
p-all: ^3.0.0
picocolors: ^1.0.0
signal-exit: ^3.0.7
string-to-stream: ^3.0.1
superstruct: ^1.0.3
tslib: ^2.5.0
yargs: ^17.7.1
peerDependencies:
typescript: ">=4.3.0"
bin:
tsc-multi: bin/tsc-multi.js
checksum: a82c0358611ac15667aa148ade33b6ad64cc0a94299fb9afc01e3e6224a994dff8812960a43643f25e4c0dac8419707027c3096d0e60bff3522591c06d5f4eeb
languageName: node
linkType: hard

"tslib@npm:^1.8.1":
version: 1.14.1
resolution: "tslib@npm:1.14.1"
Expand Down Expand Up @@ -7940,7 +7995,7 @@ __metadata:
languageName: node
linkType: hard

"yargs@npm:^17.7.2":
"yargs@npm:^17.7.1, yargs@npm:^17.7.2":
version: 17.7.2
resolution: "yargs@npm:17.7.2"
dependencies:
Expand Down
Loading