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

Readme and repo grooming, release 0.14 #1209

Merged
merged 7 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
22 changes: 14 additions & 8 deletions README-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ npm run build
./run src/examples/api_exploration.ts
```

## Build and run the web version
## Run examples in the browser

```sh
npm install
npm run build:web
npm run serve:web

./run-in-browser.js src/examples/api_exploration.ts
```

To see the test running in a web browser, go to `http://localhost:8000/`.

Note: Some of our examples don't work on the web because they use Node.js APIs.

## Run tests

- Unit tests
Expand Down Expand Up @@ -50,25 +53,28 @@ To see the test running in a web browser, go to `http://localhost:8000/`.

## Branch Compatibility

o1js is mostly used to write Mina Smart Contracts and must be compatible with the latest Berkeley Testnet, or soon Mainnet.
o1js is mostly used to write Mina Smart Contracts and must be compatible with the latest Berkeley Testnet, or soon Mainnet.

The OCaml code is in the o1js-bindings repository, not directly in o1js.

To maintain compatibility between the repositories and build o1js from the [Mina repository](https://github.com/MinaProtocol/mina), make changes to its core, such as the OCaml-bindings in the [o1js-bindings repository](https://github.com/o1-labs/o1js-bindings), you must follow a certain branch compatibility pattern:

The following branches are compatible:

| repository | mina -> o1js -> o1js-bindings |
| ---------- | ------------------------------------- |
| branches | rampup -> main -> main |
| | berkeley -> berkeley -> berkeley |
| | develop -> develop -> develop |
| repository | mina -> o1js -> o1js-bindings |
| ---------- | -------------------------------- |
| branches | o1js-main -> main -> main |
| | berkeley -> berkeley -> berkeley |
| | develop -> develop -> develop |

## Run the GitHub actions locally

<!-- The test example should stay in sync with a real value set in .github/workflows/build-actions.yml -->

You can execute the CI locally by using [act](https://github.com/nektos/act). First generate a GitHub token and use:

```
act -j Build-And-Test-Server --matrix test_type:"Simple integration tests" -s $GITHUB_TOKEN
```

to execute the job "Build-And-Test-Server for the test type `Simple integration tests`.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"node": ">=16.4.0"
},
"scripts": {
"type-check": "tsc --noEmit",
"dev": "npx tsc -p tsconfig.node.json && node src/build/copy-to-dist.js",
"make": "make -C ../../.. snarkyjs",
"make:no-types": "npm run clean && make -C ../../.. snarkyjs_no_types",
Expand All @@ -53,19 +52,18 @@
"build:web": "rimraf ./dist/web && node src/build/buildWeb.js",
"build:examples": "rimraf ./dist/examples && npx tsc -p tsconfig.examples.json || exit 0",
"build:docs": "npx typedoc",
"serve:web": "cp src/bindings/compiled/web_bindings/server.js src/bindings/compiled/web_bindings/index.html src/examples/simple_zkapp.js dist/web && node dist/web/server.js",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed a couple scripts here that, to my knowledge, aren't used

"prepublish:web": "NODE_ENV=production node src/build/buildWeb.js",
"prepublish:node": "npm run build && NODE_ENV=production node src/build/buildNode.js",
"prepublishOnly": "npm run prepublish:web && npm run prepublish:node",
"dump-vks": "./run src/examples/vk_regression.ts --bundle --dump ./src/examples/regression_test.json",
"format": "prettier --write --ignore-unknown **/*",
"test": "./run-jest-tests.sh",
"clean": "rimraf ./dist && rimraf ./src/bindings/compiled/_node_bindings",
"clean-all": "npm run clean && rimraf ./tests/report && rimraf ./tests/test-artifacts",
"test": "./run-jest-tests.sh",
"test:integration": "./run-integration-tests.sh",
"test:unit": "./run-unit-tests.sh",
"test:e2e": "rimraf ./tests/report && rimraf ./tests/test-artifacts && npx playwright test",
"e2e:prepare-server": "npm run build:examples && (cp -rf dist/examples dist/web || :) && node src/build/e2eTestsBuildHelper.js && cp -rf src/bindings/compiled/web_bindings/index.html src/bindings/compiled/web_bindings/server.js tests/artifacts/html/*.html tests/artifacts/javascript/*.js dist/web",
"e2e:prepare-server": "npm run build:examples && (cp -rf dist/examples dist/web || :) && node src/build/e2eTestsBuildHelper.js && cp -rf src/examples/plain-html/index.html src/examples/plain-html/server.js tests/artifacts/html/*.html tests/artifacts/javascript/*.js dist/web",
"e2e:run-server": "node dist/web/server.js",
"e2e:install": "npx playwright install --with-deps",
"e2e:show-report": "npx playwright show-report tests/report"
Expand Down
2 changes: 1 addition & 1 deletion src/bindings
15 changes: 15 additions & 0 deletions src/examples/plain-html/index.html
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these files are moved here from the bindings repo. they used to be in src/bindings/compiled/web_bindings which is completely the wrong place for test/example files

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>hello-snarkyjs</title>
<script type="importmap">
{ "imports": { "snarkyjs": "./index.js" } }
</script>
<script type="module" src="./simple_zkapp.js">
</script>
</head>
<body>
<div>Check out the console (F12)</div>
</body>
</html>
42 changes: 42 additions & 0 deletions src/examples/plain-html/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import fs from 'node:fs/promises';
import path from 'node:path';
import http from 'node:http';

const port = 8000;
const defaultHeaders = {
'content-type': 'text/html',
'Cross-Origin-Embedder-Policy': 'require-corp',
'Cross-Origin-Opener-Policy': 'same-origin',
};

const server = http.createServer(async (req, res) => {
let file = '.' + req.url;
console.log(file);

if (file === './') file = './index.html';
let content;
try {
content = await fs.readFile(path.resolve('./dist/web', file), 'utf8');
} catch (err) {
res.writeHead(404, defaultHeaders);
res.write('<html><body>404</body><html>');
res.end();
return;
}

const extension = path.basename(file).split('.').pop();
const contentType = {
html: 'text/html',
js: 'application/javascript',
map: 'application/json',
}[extension];
const headers = { ...defaultHeaders, 'content-type': contentType };

res.writeHead(200, headers);
res.write(content);
res.end();
});

server.listen(port, () => {
console.log(`Server is running on: http://localhost:${port}`);
});