Skip to content

Commit

Permalink
chore: updated build/test process to use rollup and separate tsconfigs
Browse files Browse the repository at this point in the history
  • Loading branch information
AtHeartEngineer committed Feb 7, 2023
1 parent 45f4ddb commit d2ae14a
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 25 deletions.
4 changes: 0 additions & 4 deletions babel.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion dist/stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -6891,7 +6891,7 @@
</script>
<script>
/*<!--*/
const data = {"version":2,"tree":{"name":"root","children":[{"name":"rln.js","children":[{"uid":"fe40-1","name":"\u0000tslib.js"},{"name":"src","children":[{"uid":"fe40-3","name":"utils.ts"},{"uid":"fe40-5","name":"rln.ts"},{"uid":"fe40-7","name":"registry.ts"},{"uid":"fe40-9","name":"cache.ts"},{"uid":"fe40-11","name":"index.ts"}]}]}],"isRoot":true},"nodeParts":{"fe40-1":{"renderedLength":1474,"gzipLength":0,"brotliLength":0,"metaUid":"fe40-0"},"fe40-3":{"renderedLength":770,"gzipLength":0,"brotliLength":0,"metaUid":"fe40-2"},"fe40-5":{"renderedLength":10883,"gzipLength":0,"brotliLength":0,"metaUid":"fe40-4"},"fe40-7":{"renderedLength":6537,"gzipLength":0,"brotliLength":0,"metaUid":"fe40-6"},"fe40-9":{"renderedLength":3528,"gzipLength":0,"brotliLength":0,"metaUid":"fe40-8"},"fe40-11":{"renderedLength":0,"gzipLength":0,"brotliLength":0,"metaUid":"fe40-10"}},"nodeMetas":{"fe40-0":{"id":"\u0000tslib.js","moduleParts":{"rln.js":"fe40-1"},"imported":[],"importedBy":[{"uid":"fe40-4"},{"uid":"fe40-6"},{"uid":"fe40-8"}]},"fe40-2":{"id":"/src/utils.ts","moduleParts":{"rln.js":"fe40-3"},"imported":[{"uid":"fe40-13"},{"uid":"fe40-18"}],"importedBy":[{"uid":"fe40-10"},{"uid":"fe40-4"}]},"fe40-4":{"id":"/src/rln.ts","moduleParts":{"rln.js":"fe40-5"},"imported":[{"uid":"fe40-0"},{"uid":"fe40-12"},{"uid":"fe40-13"},{"uid":"fe40-14"},{"uid":"fe40-2"},{"uid":"fe40-15"},{"uid":"fe40-16"}],"importedBy":[{"uid":"fe40-10"},{"uid":"fe40-8"}]},"fe40-6":{"id":"/src/registry.ts","moduleParts":{"rln.js":"fe40-7"},"imported":[{"uid":"fe40-0"},{"uid":"fe40-17"},{"uid":"fe40-15"}],"importedBy":[{"uid":"fe40-10"}]},"fe40-8":{"id":"/src/cache.ts","moduleParts":{"rln.js":"fe40-9"},"imported":[{"uid":"fe40-0"},{"uid":"fe40-4"}],"importedBy":[{"uid":"fe40-10"}]},"fe40-10":{"id":"/src/index.ts","moduleParts":{"rln.js":"fe40-11"},"imported":[{"uid":"fe40-4"},{"uid":"fe40-6"},{"uid":"fe40-8"},{"uid":"fe40-2"}],"importedBy":[],"isEntry":true},"fe40-12":{"id":"@ethersproject/bytes","moduleParts":{},"imported":[],"importedBy":[{"uid":"fe40-4"}],"isExternal":true},"fe40-13":{"id":"@ethersproject/solidity","moduleParts":{},"imported":[],"importedBy":[{"uid":"fe40-4"},{"uid":"fe40-2"}],"isExternal":true},"fe40-14":{"id":"@ethersproject/strings","moduleParts":{},"imported":[],"importedBy":[{"uid":"fe40-4"}],"isExternal":true},"fe40-15":{"id":"poseidon-lite","moduleParts":{},"imported":[],"importedBy":[{"uid":"fe40-4"},{"uid":"fe40-6"}],"isExternal":true},"fe40-16":{"id":"@semaphore-protocol/identity","moduleParts":{},"imported":[],"importedBy":[{"uid":"fe40-4"}],"isExternal":true},"fe40-17":{"id":"@zk-kit/incremental-merkle-tree","moduleParts":{},"imported":[],"importedBy":[{"uid":"fe40-6"}],"isExternal":true},"fe40-18":{"id":"ffjavascript","moduleParts":{},"imported":[],"importedBy":[{"uid":"fe40-2"}],"isExternal":true}},"env":{"rollup":"3.14.0"},"options":{"gzip":false,"brotli":false,"sourcemap":false}};
const data = {"version":2,"tree":{"name":"root","children":[{"name":"rln.js","children":[{"uid":"bf78-1","name":"\u0000tslib.js"},{"name":"src","children":[{"uid":"bf78-3","name":"utils.ts"},{"uid":"bf78-5","name":"rln.ts"},{"uid":"bf78-7","name":"registry.ts"},{"uid":"bf78-9","name":"cache.ts"},{"uid":"bf78-11","name":"index.ts"}]}]}],"isRoot":true},"nodeParts":{"bf78-1":{"renderedLength":1474,"gzipLength":0,"brotliLength":0,"metaUid":"bf78-0"},"bf78-3":{"renderedLength":770,"gzipLength":0,"brotliLength":0,"metaUid":"bf78-2"},"bf78-5":{"renderedLength":10883,"gzipLength":0,"brotliLength":0,"metaUid":"bf78-4"},"bf78-7":{"renderedLength":6537,"gzipLength":0,"brotliLength":0,"metaUid":"bf78-6"},"bf78-9":{"renderedLength":3528,"gzipLength":0,"brotliLength":0,"metaUid":"bf78-8"},"bf78-11":{"renderedLength":0,"gzipLength":0,"brotliLength":0,"metaUid":"bf78-10"}},"nodeMetas":{"bf78-0":{"id":"\u0000tslib.js","moduleParts":{"rln.js":"bf78-1"},"imported":[],"importedBy":[{"uid":"bf78-4"},{"uid":"bf78-6"},{"uid":"bf78-8"}]},"bf78-2":{"id":"/src/utils.ts","moduleParts":{"rln.js":"bf78-3"},"imported":[{"uid":"bf78-13"},{"uid":"bf78-18"}],"importedBy":[{"uid":"bf78-10"},{"uid":"bf78-4"}]},"bf78-4":{"id":"/src/rln.ts","moduleParts":{"rln.js":"bf78-5"},"imported":[{"uid":"bf78-0"},{"uid":"bf78-12"},{"uid":"bf78-13"},{"uid":"bf78-14"},{"uid":"bf78-2"},{"uid":"bf78-15"},{"uid":"bf78-16"}],"importedBy":[{"uid":"bf78-10"},{"uid":"bf78-8"}]},"bf78-6":{"id":"/src/registry.ts","moduleParts":{"rln.js":"bf78-7"},"imported":[{"uid":"bf78-0"},{"uid":"bf78-17"},{"uid":"bf78-15"}],"importedBy":[{"uid":"bf78-10"}]},"bf78-8":{"id":"/src/cache.ts","moduleParts":{"rln.js":"bf78-9"},"imported":[{"uid":"bf78-0"},{"uid":"bf78-4"}],"importedBy":[{"uid":"bf78-10"}]},"bf78-10":{"id":"/src/index.ts","moduleParts":{"rln.js":"bf78-11"},"imported":[{"uid":"bf78-4"},{"uid":"bf78-6"},{"uid":"bf78-8"},{"uid":"bf78-2"}],"importedBy":[],"isEntry":true},"bf78-12":{"id":"@ethersproject/bytes","moduleParts":{},"imported":[],"importedBy":[{"uid":"bf78-4"}],"isExternal":true},"bf78-13":{"id":"@ethersproject/solidity","moduleParts":{},"imported":[],"importedBy":[{"uid":"bf78-4"},{"uid":"bf78-2"}],"isExternal":true},"bf78-14":{"id":"@ethersproject/strings","moduleParts":{},"imported":[],"importedBy":[{"uid":"bf78-4"}],"isExternal":true},"bf78-15":{"id":"poseidon-lite","moduleParts":{},"imported":[],"importedBy":[{"uid":"bf78-4"},{"uid":"bf78-6"}],"isExternal":true},"bf78-16":{"id":"@semaphore-protocol/identity","moduleParts":{},"imported":[],"importedBy":[{"uid":"bf78-4"}],"isExternal":true},"bf78-17":{"id":"@zk-kit/incremental-merkle-tree","moduleParts":{},"imported":[],"importedBy":[{"uid":"bf78-6"}],"isExternal":true},"bf78-18":{"id":"ffjavascript","moduleParts":{},"imported":[],"importedBy":[{"uid":"bf78-2"}],"isExternal":true}},"env":{"rollup":"3.14.0"},"options":{"gzip":false,"brotli":false,"sourcemap":false}};

const run = () => {
const width = window.innerWidth;
Expand Down
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const config: Config.InitialOptions = {

"transform": {
"^.+\\.jsx?$": "babel-jest",
"^.+\\.tsx?$": "ts-jest"
"^.+\\.tsx?$": ["ts-jest", { tsconfig: "tsconfig.test.json" }]
},
"silent": true,
"detectOpenHandles": true,
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
},
"scripts": {
"build": "rollup --config rollup.config.mjs",
"tests": "jest"
"test": "jest",
"test:debug": "jest --silent=false"
},
"keywords": [
"rln",
Expand All @@ -26,10 +27,10 @@
"publishConfig": {
"access": "public"
},
"main": "./dist/rln.js",
"types": "dist/rln.d.ts",
"main": "./dist/index.js",
"types": "dist/index.d.ts",
"exports": {
"import": "./dist/rln.js"
"import": "./dist/index.js"
},
"directories": {
"dist": "./dist",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default {
'./dist/'
]
}),
typescript(/*{ plugin options }*/),
typescript({tsconfig: 'tsconfig.build.json'}),
visualizer({
emitFile: true,
filename: "stats.html",
Expand Down
13 changes: 9 additions & 4 deletions src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,23 @@ export default class Registry {
}

public async export(): Promise<string> {
return JSON.stringify({
console.debug("Exporting: ")
const out = JSON.stringify({
"treeDepth": this._treeDepth,
"zeroValue": String(this._zeroValue),
"registry": this._registry.leaves.map((x) => String(x)),
"slashed": this._slashed.leaves.map((x) => String(x)),
})
console.debug(out)
return out
}

public static async import(registry: string): Promise<Registry> {
const _temp_registry = new Registry(registry["treeDepth"], BigInt(registry["zeroValue"]))
_temp_registry.addMembers(registry["registry"].map((x) => BigInt(x)))
_temp_registry.addSlashedMembers(registry["slashed"].map((x) => BigInt(x)))
const _registryObject = JSON.parse(registry)
console.debug(_registryObject)
const _temp_registry = new Registry(_registryObject['treeDepth'], BigInt(_registryObject['zeroValue']))
_temp_registry.addMembers(_registryObject["registry"].map((x) => BigInt(x)))
_temp_registry.addSlashedMembers(_registryObject["slashed"].map((x) => BigInt(x)))
return _temp_registry
}
}
3 changes: 2 additions & 1 deletion tests/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ describe("Registry", () => {
})
})

test.skip("Should export/import to json", async () => {
test("Should export/import to json", async () => {
const registry_json_test = new Registry()
registry_json_test.addMembers([BigInt(1), BigInt(2)])
const json = await registry_json_test.export()
console.debug(json)
const registry_from_json = await Registry.import(json)
expect(registry_from_json.members).toHaveLength(2)
expect(registry_from_json.root).toEqual(registry_json_test.root)
Expand Down
4 changes: 2 additions & 2 deletions tests/rln.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe("RLN", () => {
expect(retrievedSecret).toEqual(rln_instance.secretIdentity)
})

test.skip("Should generate and verify RLN proof", async () => {
test("Should generate and verify RLN proof", async () => {
const leaves = Object.assign([], identityCommitments)
leaves.push(rln_instance.commitment)

Expand All @@ -91,7 +91,7 @@ describe("RLN", () => {
expect(response).toBe(true)
}, 30000)

test.skip("Should retrieve user secret using full proofs", async () => {
test("Should retrieve user secret using full proofs", async () => {
const leaves = Object.assign([], identityCommitments)
leaves.push(rln_instance.commitment)

Expand Down
8 changes: 8 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"rootDir": "./src",
"outDir": "./dist",
"files": [
"src/index.ts",
]
}
8 changes: 1 addition & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"compilerOptions": {
"baseUrl": ".",
"rootDir": "./src",
"outDir": "./dist/",
"target": "ES6",
"module": "esnext",
"moduleResolution": "nodenext",
Expand Down Expand Up @@ -32,8 +29,5 @@
"./src/types/snarkjs"
],
}
},
"files": [
"src/index.ts",
]
}
}
12 changes: 12 additions & 0 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig.json",
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitAny": false,
"noImplicitReturns": false,
"noEmitOnError": false,
"include": [
"tests"
],
"exclude": []
}

0 comments on commit d2ae14a

Please sign in to comment.