-
Notifications
You must be signed in to change notification settings - Fork 147
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
@o1js/testing #2093
base: main
Are you sure you want to change the base?
@o1js/testing #2093
Conversation
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.
Overall this looks reasonable! Can I try using it locally with npm link
? I tried from the src/lib/testing
folder and it didn't work.
I used yalc to test the package so far. It should work with |
For example, the react testing library doesn’t have a code block to install react. It just mentions that it’s a peer dependency. https://github.com/testing-library/react-testing-library
I don’t think it’s a big deal either way. But it just seems like anyone installing this package will know how to install o1js too.
On Thu, Apr 3, 2025 at 4:50 PM, Boray Saygılıer ***@***.***> wrote: Overall this looks reasonable! Can I try using it locally with npm link? I tried from the src/lib/testing folder and it didn't work. I used yalc to test the package so far. It should work with npm link too. Can you explain how it failed?—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
boray left a comment (o1-labs/o1js#2093)
Overall this looks reasonable! Can I try using it locally with npm link? I tried from the src/lib/testing folder and it didn't work. I used yalc to test the package so far. It should work with npm link too. Can you explain how it failed? —
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
oops, I missed it's for o1js not @o1js/testing. Indeed, it's an overkill. I changed this while ago but not commited. It just has a note about peer dependency. The current version of the readme is incomplete. I'll be pushing updates tomorrow. |
src/testing/package.json
Outdated
"version": "0.0.1", | ||
"type": "module", | ||
"scripts": { | ||
"build": "tsc -p ../../tsconfig.testing.json && node copyBindings.js", |
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.
right now this builds everything in the project, incl. mina-signer, and copies all artefacts into **/testing/dist/**
- I think we should be a bit more selective here and only copy what we need
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.
Only mina-signer is not used, but I didn't try to prevent it from building since npm run build
in o1js also builds mina-signer.
src/testing/src/testing.ts
Outdated
export const { | ||
constraintSystem, | ||
not, | ||
and, | ||
or, | ||
fulfills, | ||
equals, | ||
contains, | ||
allConstant, | ||
ifNotAllConstant, | ||
isEmpty, | ||
withoutGenerics, | ||
print, | ||
repeat, | ||
} = ConstraintSystem_; |
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.
I would put the constraint system stuff in a separate name space.
most people won't need it, and it's confusing to pollute the name space with many simple functions like and
, equals
etc
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.
similar how Random
is exported as its own namespace!
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.
Agreed but then existing tests would be incompatible* (directly) with the package. What do you think about a new PR that creates such namespace and updates all tests?
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.
wdym they "would be incompatible"? I'm asking for a change in this file, testing.ts
, not in the existing tests
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.
export const { | |
constraintSystem, | |
not, | |
and, | |
or, | |
fulfills, | |
equals, | |
contains, | |
allConstant, | |
ifNotAllConstant, | |
isEmpty, | |
withoutGenerics, | |
print, | |
repeat, | |
} = ConstraintSystem_; | |
export { ConstraintSystem_ as ConstraintSystem } |
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 was a deliberate choice to not create a namespace to not change the usage from constraintSystem.fromZkProgram()
to ConstraintSystem.constraintSystem.fromZkProgram()
to make the package "plug and play" compatible with the existing tests.
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.
Wrong choice IMO. People won't use this, it pollutes the namespace, and it's still plug and play compatible if you just unpack the CobstraintSystem object at the beginning
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 pollutes the namespace" I agree with this but I don't think the latter is a good solution. Why not we fix the pollution in its roots at constraint-system.ts
? Similar fix would be needed for equivalent.ts
too.
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.
Sure, fix it where you think it fits best!
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.
I think this is one of those things where it's better to get it merged and change the namespace as a follow-up PR. I like to follow the "minimally invasive migration" => "improve" flow.
But I do agree that namespaceing would make sense.
A nice stopgap would be to do both (redundantly), have all the docs point to the namespace, and then migrate the old stuff. We can do this before releasing the npm package so that people don't use it/changing the API won't be a breaking change.
Okay, but this means the person releasing it will need access to our npm details. If we add a CI workflow we could trigger it manually, given we already have access to the credentials in CI |
I assumed you have the credentials for npm for o1js and you can release on my behalf. No worries, there won't be releases often :) |
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.
My only real change requests are in
- src/testing/src/testing.ts
- src/testing/package.json
I do think that everything else I've said is worth considering but should not block this PR
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.
So... this might be a hot-take, but I would love to see us be a little more organized with our directory structure. It would be really nice to have a top-level packages
directory where this stuff would fit into packages/testing
and the actual source-code files would be the only thing in the src
directory.
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.
I am onboard with this idea!
@@ -0,0 +1,22 @@ | |||
# Changelog |
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.
Goes alogn with my other comment, but if got a little more organized with our directory structure, we can check the diff for changes in packages/<package-name>
and check packages/<package-name>/CHANGELOG.md
for every package that has a diff.
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.
The level of detail here is fantastic 🏆
I do think it would be beneficial to have a bunch of this directly alongside the code in tsdoc, but I think that could happen in a follow up and should not hold up landing this PR
src/testing/src/testing.ts
Outdated
export const { | ||
constraintSystem, | ||
not, | ||
and, | ||
or, | ||
fulfills, | ||
equals, | ||
contains, | ||
allConstant, | ||
ifNotAllConstant, | ||
isEmpty, | ||
withoutGenerics, | ||
print, | ||
repeat, | ||
} = ConstraintSystem_; |
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.
I think this is one of those things where it's better to get it merged and change the namespace as a follow-up PR. I like to follow the "minimally invasive migration" => "improve" flow.
But I do agree that namespaceing would make sense.
A nice stopgap would be to do both (redundantly), have all the docs point to the namespace, and then migrate the old stuff. We can do this before releasing the npm package so that people don't use it/changing the API won't be a breaking change.
|
||
Check out [`src/lib/provable/test`](https://github.com/o1-labs/o1js/tree/main/src/lib/provable/test) directory for more examples. | ||
|
||
## API Reference |
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.
I don't think you should have an API-reference in the README as it's impossible to keep this up to date. This section should just be an instruction on how to build the tsdocs and the API reference should be in there.
(I think you can do this as a follow up though)
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.
I think that also a good path. But, the tsdocs should be at relevant files in src/lib/testing
, not in this package. I think it's acceptable to have this reference in the README. I don't think it would be hard to keep this up to date as the testing files wouldn't change much. And, if we decide to do a refactor, updating the docs must be part of the refactor.
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.
We can do a follow up PR once we figure out how we will present this package's docs in the new o1js documentation.
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.
I don't think it would be hard to keep this up to date as the testing files wouldn't change much
Even if this is true, all it takes is one change and it could lead to confusion. It's much better to have reference docs alongside code as reviewers can easily spot whether or not changes include doc changes. It's not that keeping a README up to date requires significant effort, but it's so easy to forget. It's also true of doc-comments and any inline comment in general, but it's easier to remember when the edit to the docs takes place in the same file.
But yeah... agree with this:
We can do a follow up PR once we figure out how we will present this package's docs in the new o1js documentation.
Co-authored-by: Richard Pringle <rpringle@circle-free.com>
Co-authored-by: Richard Pringle <rpringle@circle-free.com>
Co-authored-by: Richard Pringle <rpringle@circle-free.com>
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.
I'm going to give this a ✅, but I would prefer (if we all agree) that we move this package to /packages/testing
before landing this PR.
We shouldn’t depend on a single person who may or may not have the credentials to release a package. For our other releases, we already have access to the credentials via CI, and we should follow the same approach here. Since we're introducing this new package to developers, we can expect feedback and requests for improvements - which means we'll likely need to release more frequently. Relying on one individual creates an unnecessary bottleneck and adds avoidable overhead to what could be a much simpler process. |
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 seems good to merge for now, and the folder structure can be improved in follow-up PRs.
Yeah, releasing the package automatically if the version is incremented seems best to me. How do we handle mina signer? |
I think a separate PR is ok because the scope should also include migrating |
Same way. We can simply copy the workflow from here o1js/.github/workflows/build-action.yml Lines 286 to 371 in d6ae829
|
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.
please update the npm-deps-hash
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
I committed bot's suggestion.
@@ -0,0 +1,22 @@ | |||
# Changelog |
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.
In a follow up PR we should also organize our github actions better. Right now everything is a bit chaotic
"node": "./dist/node/testing/index.js", | ||
"default": "./dist/node/testing/index.js" | ||
}, | ||
"files": [ |
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.
We are including mina-signer and other internal dependencies in the package when we publish it to npm. While this might not be a big size increase in the overall package (given that the compile artefacts alone are about 45mb), it's still suboptiomal to include files that have nothing to do with the actual library in the released package
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 or when we end up splitting everything into seperate package
folders, we should definitely clean this up. So let's make sure we keep this in mind, I approve in hopes that we will follow up on this soon
This pull request introduces a new package
@o1js/testing
and includes several changes to support this addition. The changes involve setting up the package structure, configuration files, and exporting necessary utilities.New Package Setup:
src/testing/package.json
: Created a newpackage.json
file to define the@o1js/testing
package, including scripts for building and testing, and specifying dependencies.src/testing/CHANGELOG.md
: Added a changelog file to document notable changes in the project, adhering to the Keep a Changelog format and Semantic Versioning.Configuration and Build Tools:
src/testing/jest.config.js
: Added a Jest configuration file to set up the testing environment for the package, including presets and transform ignore patterns.tsconfig.testing.json
: Created a TypeScript configuration file specifically for the testing package to manage compilation settings and include/exclude patterns.src/testing/copy-bindings.js
: Added a script to copy bindings from the build directory to the distribution directory.Exporting Utilities:
src/testing/index.ts
: Created an index file to export all testing utilities from thesrc/testing.js
file.src/testing/src/testing.ts
: Imported and re-exported various utilities fromequivalent.js
,property.js
, andconstraint-system.js
to make them available as part of the testing package.src/lib/testing/equivalent.ts
: Updated the export statement to includeAnyTupleFunction
.TODO
This PR will have couple of follow-up tasks and PR's for:
src/lib/testing
for better organization of toolssrc/lib/testing
packages
directory foro1js
,mina-signer
and@o1js/testing
internally.