o1-labs / zkapp-cli

CLI to create a zkApp (zero-knowledge app) for Mina Protocol
https://docs.minaprotocol.com/zkapps/how-to-write-a-zkapp
Apache License 2.0
115 stars 44 forks source link

Examples are broken #311

Closed rjdellecese closed 1 year ago

rjdellecese commented 1 year ago

Describe the bug

After running zk example sudoku or zk example tictactoe and cding into the respective project directory, running any of npm run test, npm run build, or npm run start produces errors.

Here's what the errors look like for the sudoku app:

`npm run test` ``` > sudoku@0.1.0 test > node --experimental-vm-modules --experimental-wasm-modules --experimental-wasm-threads node_modules/jest/bin/jest.js (node:86278) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time (Use `node --trace-warnings ...` to show where the warning was created) Browserslist: caniuse-lite is outdated. Please run: npx browserslist@latest --update-db Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating FAIL src/sudoku.test.ts ● Test suite failed to run src/sudoku.ts:37:4 - error TS2345: Argument of type 'SudokuZkApp' is not assignable to parameter of type 'SmartContract & { constructor: any; }'. Type 'SudokuZkApp' is not assignable to type 'SmartContract'. Types of property 'init' are incompatible. Type '(sudokuInstance: Sudoku) => void' is not assignable to type '(zkappKey?: PrivateKey | undefined) => void'. Types of parameters 'sudokuInstance' and 'zkappKey' are incompatible. Type 'PrivateKey | undefined' is not assignable to type 'Sudoku'. Type 'undefined' is not assignable to type 'Sudoku'. 37 @state(Field) sudokuHash = State(); ~~~~~~~~~~~~ src/sudoku.ts:38:4 - error TS2345: Argument of type 'SudokuZkApp' is not assignable to parameter of type 'SmartContract & { constructor: any; }'. 38 @state(Bool) isSolved = State(); ~~~~~~~~~~~ src/sudoku.ts:40:4 - error TS2345: Argument of type 'SudokuZkApp' is not assignable to parameter of type 'SmartContract & { constructor: any; }'. Type 'SudokuZkApp' is not assignable to type 'SmartContract'. 40 @method init(sudokuInstance: Sudoku) { ~~~~~~ src/sudoku.ts:40:11 - error TS2416: Property 'init' in type 'SudokuZkApp' is not assignable to the same property in base type 'SmartContract'. Type '(sudokuInstance: Sudoku) => void' is not assignable to type '(zkappKey?: PrivateKey | undefined) => void'. Types of parameters 'sudokuInstance' and 'zkappKey' are incompatible. Type 'PrivateKey | undefined' is not assignable to type 'Sudoku'. Type 'undefined' is not assignable to type 'Sudoku'. 40 @method init(sudokuInstance: Sudoku) { ~~~~ src/sudoku.ts:45:4 - error TS2345: Argument of type 'SudokuZkApp' is not assignable to parameter of type 'SmartContract & { constructor: any; }'. 45 @method submitSolution(sudokuInstance: Sudoku, solutionInstance: Sudoku) { ~~~~~~ Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: 6.827 s Ran all test suites. Jest did not exit one second after the test run has completed. This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue. ``` (it then seems to hang indefinitely)
`npm run build` ``` > sudoku@0.1.0 build > tsc -p tsconfig.json src/sudoku.ts:37:4 - error TS2345: Argument of type 'SudokuZkApp' is not assignable to parameter of type 'SmartContract & { constructor: any; }'. Type 'SudokuZkApp' is not assignable to type 'SmartContract'. Types of property 'init' are incompatible. Type '(sudokuInstance: Sudoku) => void' is not assignable to type '(zkappKey?: PrivateKey | undefined) => void'. Types of parameters 'sudokuInstance' and 'zkappKey' are incompatible. Type 'PrivateKey | undefined' is not assignable to type 'Sudoku'. Type 'undefined' is not assignable to type 'Sudoku'. 37 @state(Field) sudokuHash = State(); ~~~~~~~~~~~~ src/sudoku.ts:38:4 - error TS2345: Argument of type 'SudokuZkApp' is not assignable to parameter of type 'SmartContract & { constructor: any; }'. 38 @state(Bool) isSolved = State(); ~~~~~~~~~~~ src/sudoku.ts:40:4 - error TS2345: Argument of type 'SudokuZkApp' is not assignable to parameter of type 'SmartContract & { constructor: any; }'. Type 'SudokuZkApp' is not assignable to type 'SmartContract'. 40 @method init(sudokuInstance: Sudoku) { ~~~~~~ src/sudoku.ts:40:11 - error TS2416: Property 'init' in type 'SudokuZkApp' is not assignable to the same property in base type 'SmartContract'. Type '(sudokuInstance: Sudoku) => void' is not assignable to type '(zkappKey?: PrivateKey | undefined) => void'. Types of parameters 'sudokuInstance' and 'zkappKey' are incompatible. Type 'PrivateKey | undefined' is not assignable to type 'Sudoku'. Type 'undefined' is not assignable to type 'Sudoku'. 40 @method init(sudokuInstance: Sudoku) { ~~~~ src/sudoku.ts:45:4 - error TS2345: Argument of type 'SudokuZkApp' is not assignable to parameter of type 'SmartContract & { constructor: any; }'. 45 @method submitSolution(sudokuInstance: Sudoku, solutionInstance: Sudoku) { ~~~~~~ Found 5 errors in the same file, starting at: src/sudoku.ts:37 ```
`npm run start` ``` > sudoku@0.1.0 start > node build/src/run.js Deploying Sudoku... /Users/rjdellecese/code/sudoku/node_modules/snarkyjs/dist/node/_node_bindings/snarky_js_node.bc.cjs:7565 throw err; ^ TypeError: sudokuInstance.hash is not a function at SudokuZkApp.init (file:///Users/rjdellecese/code/sudoku/build/src/sudoku.js:33:44) at file:///Users/rjdellecese/code/sudoku/node_modules/snarkyjs/dist/node/lib/zkapp.js:174:37 at runWith (file:///Users/rjdellecese/code/sudoku/node_modules/snarkyjs/dist/node/lib/global-context.js:55:18) at Function.runWith (file:///Users/rjdellecese/code/sudoku/node_modules/snarkyjs/dist/node/lib/global-context.js:14:37) at file:///Users/rjdellecese/code/sudoku/node_modules/snarkyjs/dist/node/lib/zkapp.js:170:69 at runWith (file:///Users/rjdellecese/code/sudoku/node_modules/snarkyjs/dist/node/lib/global-context.js:55:18) at Function.runWith (file:///Users/rjdellecese/code/sudoku/node_modules/snarkyjs/dist/node/lib/global-context.js:14:37) at SudokuZkApp.wrappedMethod (file:///Users/rjdellecese/code/sudoku/node_modules/snarkyjs/dist/node/lib/zkapp.js:63:41) at SudokuZkApp.deploy (file:///Users/rjdellecese/code/sudoku/node_modules/snarkyjs/dist/node/lib/zkapp.js:458:18) at file:///Users/rjdellecese/code/sudoku/build/src/sudoku.js:117:23 ```

Steps to Reproduce

npm install -g zkapp-cli
zk example sudoku
cd sudoku
npm run test

System Info

System:
    OS: macOS 13.0.1
    CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
  Binaries:
    Node: 16.17.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 8.15.0 - /usr/local/bin/npm
  npmPackages:
    snarkyjs: Not Found (not in a project)
  npmGlobalPackages:
    zkapp-cli: 0.5.1

Severity

annoyance

Additional Information

I've generated and run these example apps successfully in the past (albeit on a different machine) with zkapp-cli version 0.4.19, which makes me think this might be a new issue in 0.5.x.

I'm also noticing that zk system is failing to pick up the snarkyjs version in these generated example projects (when running it from inside an example project directory).

ymekuria commented 1 year ago

Thanks for raising this issue. We need to update the examples to be compatible with SnarkyJS v 0.7.1

jasongitmail commented 1 year ago

Both Sudoku and tictactoe are now updated. Thanks for the issue!