-
Notifications
You must be signed in to change notification settings - Fork 3
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
ZK-559: (part 2) unit tests for shielder-sdk #90
Merged
Merged
Changes from all commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
22d941a
ZK-559: Add shielder-sdk-crypto package
kroist fee1b6a
add other packages to workspace
kroist e9ef3f1
ZK-559: Add WASM implementation of shielder-sdk-crypto
kroist 1d8b114
separate cryptoClient interface
kroist 1cf65dc
upd
kroist 473b8cf
upd to new interface
kroist c2cf81f
Merge remote-tracking branch 'origin/main' into crypto-wasm
kroist 29177ca
move lint config to workspace
kroist 5e81347
comply with linter
kroist 936d806
return single-threaded
kroist 471a420
ZK-559: fix vite workers (wasm generation part)
kroist 0abb655
Merge remote-tracking branch 'origin/ZK-559-workers-vite-fix' into cr…
kroist 3973738
create patched version for vite
kroist b13140b
return to normal
kroist 78ae484
add vite patch
kroist 3e7f04e
add readme
kroist e04a43a
rm all about wasm
kroist 7926432
rm /__internal
kroist b33159e
integrate into client
kroist 0b011d0
finish
kroist 9a37573
rm tests from CI
kroist 2fd71b8
upd README
kroist 298f56f
module loader
kroist 9335dc7
worker docs
kroist 170ea2e
rm comments
kroist 44f396b
license and authors
kroist 71b060b
Merge branch 'crypto-wasm' into shielder-sdk-rm-impl
kroist 2b16902
add workspace build scripts
kroist d3b7bbe
upd CI
kroist bd3eaf3
Merge remote-tracking branch 'origin/main' into shielder-sdk-rm-impl
kroist 77cc8fb
unused args in abstract method
kroist 9a4016b
ZK-559: (part 1) unit tests for shielder-sdk
kroist d535f08
rm integration test
kroist f05e0cd
sha256 hash
kroist 63887b8
upd CI
kroist caad635
disable some lints for tests
kroist 9d72837
Update _ts-checks.yml
kroist 2221d15
Merge remote-tracking branch 'origin/main' into sdk-unit-tests
kroist 3bb925e
deposit action unit tests
kroist 54adf68
more tests and coverage
kroist 0ef5ad7
upd
kroist 1f6c5bc
Merge remote-tracking branch 'origin/main' into sdk-unit-tests
kroist 0bdc174
upd dep name
kroist 0a6803a
upd
kroist ec024ef
upd
kroist add2cc5
Merge branch 'sdk-unit-tests' into unit-tests-part-2
kroist b6bc398
upd
kroist d5cffba
upd
kroist e8048b8
upd
kroist 2307140
Merge branch 'sdk-unit-tests' into unit-tests-part-2
kroist 9fbb68c
withdraw tests
kroist d1762e9
add scalar test values
kroist f47f862
small changes
kroist e6eb8b9
utils small change
kroist 505461f
Merge branch 'sdk-unit-tests' into unit-tests-part-2
kroist bdf1d0e
add simulation throwing tests
kroist 7478ff0
upd
kroist 8e9ba06
rm coverage from lints
kroist 825ba2a
Merge remote-tracking branch 'origin/main' into unit-tests-part-2
kroist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { | ||
Converter, | ||
CryptoClient, | ||
DepositAdvice, | ||
DepositCircuit, | ||
DepositPubInputs, | ||
Hasher, | ||
NewAccountAdvice, | ||
NewAccountCircuit, | ||
|
@@ -19,7 +21,7 @@ import { | |
import { hexToBigInt } from "viem"; | ||
|
||
const SCALAR_MODULO = r; | ||
export const ARITY = 7; | ||
export const HASH_RATE = 7; | ||
export const NOTE_VERSION = 0n; | ||
|
||
const mockedHash = async (inputs: Scalar[]): Promise<Scalar> => { | ||
|
@@ -36,7 +38,7 @@ const mockedHash = async (inputs: Scalar[]): Promise<Scalar> => { | |
}; | ||
|
||
const fullArityHash = async (inputs: Scalar[]): Promise<Scalar> => { | ||
const scalarArray: Scalar[] = new Array<Scalar>(ARITY).fill( | ||
const scalarArray: Scalar[] = new Array<Scalar>(HASH_RATE).fill( | ||
Scalar.fromBigint(0n) | ||
); | ||
inputs.forEach((input, index) => { | ||
|
@@ -86,7 +88,7 @@ class MockedHasher implements Hasher { | |
} | ||
|
||
poseidonRate(): Promise<number> { | ||
return Promise.resolve(7); | ||
return Promise.resolve(HASH_RATE); | ||
} | ||
} | ||
|
||
|
@@ -107,48 +109,30 @@ class MockedConverter implements Converter { | |
|
||
class MockedNoteTreeConfig implements NoteTreeConfig { | ||
treeHeight(): Promise<number> { | ||
return Promise.resolve(13); | ||
return Promise.resolve(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice that we have control over this and get short test values |
||
} | ||
|
||
arity(): Promise<number> { | ||
return Promise.resolve(7); | ||
return Promise.resolve(2); | ||
} | ||
} | ||
|
||
class MockedNewAccountCircuit implements NewAccountCircuit { | ||
prove(values: NewAccountAdvice): Promise<Proof> { | ||
const string = JSON.stringify(values); | ||
const encoder = new TextEncoder(); | ||
const data = encoder.encode(string); | ||
return Promise.resolve(data); | ||
return Promise.resolve(new Uint8Array()); | ||
} | ||
|
||
async verify(proof: Proof, pubInputs: NewAccountPubInputs): Promise<boolean> { | ||
const proofString = new TextDecoder().decode(proof); | ||
const advice: NewAccountAdvice = JSON.parse(proofString); | ||
|
||
return ( | ||
scalarsEqual(pubInputs.hId, await mockedHash([advice.id])) && | ||
scalarsEqual( | ||
pubInputs.hNote, | ||
await hashedNote( | ||
advice.id, | ||
advice.nullifier, | ||
advice.trapdoor, | ||
advice.initialDeposit | ||
) | ||
) && | ||
scalarsEqual(pubInputs.initialDeposit, advice.initialDeposit) | ||
); | ||
return Promise.resolve(true); | ||
} | ||
} | ||
|
||
class MockedDepositCircuit implements DepositCircuit { | ||
prove(): Promise<Proof> { | ||
prove(values: DepositAdvice): Promise<Proof> { | ||
return Promise.resolve(new Uint8Array()); | ||
} | ||
|
||
verify(): Promise<boolean> { | ||
async verify(proof: Proof, pubInputs: DepositPubInputs): Promise<boolean> { | ||
guspiel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return Promise.resolve(true); | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be really cool to see not only coverage percentage but also which lines are covered. Do you know if it's easy to do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you run
pnpm coverage
locally, you can see which lines are uncovered, however it's tricky to add that to report.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, it works for me. We probably can also use some vs code extension to overlay this on editor view, but it seems to take some time to configure.