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

Allow overriding the slot time for lightnet. #718

Merged
merged 5 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

26 changes: 0 additions & 26 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/test-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
run: |
npm ci
npm run build --if-present
npm run clean
npm run coverage
cd templates/project-ts
npm install || true
Expand Down
Empty file removed .husky/_/husky.sh
Empty file.
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## Unreleased

## [0.22.2](https://github.com/o1-labs/zkapp-cli/compare/v0.22.1...v0.22.2) - 2024-12-1
## [0.22.4](https://github.com/o1-labs/zkapp-cli/compare/v0.22.3...v0.22.4) - 2025-01-29

### Added

- Allow overriding the slot time for lightnet. [#718](https://github.com/o1-labs/zkapp-cli/pull/718)

## [0.22.2](https://github.com/o1-labs/zkapp-cli/compare/v0.22.1...v0.22.2) - 2024-12-01

### Changed

Expand Down
44 changes: 44 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import js from '@eslint/js';
import prettier from 'eslint-config-prettier';
import globals from 'globals';
import ts from 'typescript-eslint';

export default [
{
ignores: [
'node_modules/',
'build/',
'reports/',
'coverage',
'package-lock.json',
'**/GradientBG.js',
'**/.eslintrc.cjs',
'**/babel.config.cjs',
'**/jest-resolver.cjs',
],
},
js.configs.recommended,
...ts.configs.recommended,
prettier,
{
files: ['**/*.js', '**/*.ts'],
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...globals.jest,
},
},
},
{
rules: {
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{ argsIgnorePattern: '^_' },
],
'@typescript-eslint/no-empty-object-type': 'off',
},
},
];
6 changes: 3 additions & 3 deletions examples/sudoku/ts/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ await tx.sign([zkAppPrivateKey, senderKey]).send();

console.log('Is the sudoku solved?', zkApp.isSolved.get().toBoolean());

let solution = solveSudoku(sudoku);
const solution = solveSudoku(sudoku);
if (solution === undefined) throw Error('cannot happen');

// submit a wrong solution
let noSolution = cloneSudoku(solution);
const noSolution = cloneSudoku(solution);
noSolution[0][0] = (noSolution[0][0] % 9) + 1;

console.log('Submitting wrong solution...');
try {
let tx = await Mina.transaction(sender, async () => {
const tx = await Mina.transaction(sender, async () => {
await zkApp.submitSolution(Sudoku.from(sudoku), Sudoku.from(noSolution));
});
await tx.prove();
Expand Down
20 changes: 10 additions & 10 deletions examples/sudoku/ts/src/sudoku.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('sudoku', () => {
senderKey: PrivateKey;

beforeEach(async () => {
let Local = await Mina.LocalBlockchain({ proofsEnabled: false });
const Local = await Mina.LocalBlockchain({ proofsEnabled: false });
Mina.setActiveInstance(Local);
sender = Local.testAccounts[0];
senderKey = sender.key;
Expand All @@ -27,10 +27,10 @@ describe('sudoku', () => {
let isSolved = zkApp.isSolved.get().toBoolean();
expect(isSolved).toBe(false);

let solution = solveSudoku(sudoku);
const solution = solveSudoku(sudoku);
if (solution === undefined) throw Error('cannot happen');
let tx = await Mina.transaction(sender, async () => {
let zkApp = new SudokuZkApp(zkAppAddress);
const tx = await Mina.transaction(sender, async () => {
const zkApp = new SudokuZkApp(zkAppAddress);
await zkApp.submitSolution(Sudoku.from(sudoku), Sudoku.from(solution!));
});
await tx.prove();
Expand All @@ -43,15 +43,15 @@ describe('sudoku', () => {
it('rejects an incorrect solution', async () => {
await deploy(zkApp, zkAppPrivateKey, sudoku, sender, senderKey);

let solution = solveSudoku(sudoku);
const solution = solveSudoku(sudoku);
if (solution === undefined) throw Error('cannot happen');

let noSolution = cloneSudoku(solution);
const noSolution = cloneSudoku(solution);
noSolution[0][0] = (noSolution[0][0] % 9) + 1;

await expect(async () => {
let tx = await Mina.transaction(sender, async () => {
let zkApp = new SudokuZkApp(zkAppAddress);
const tx = await Mina.transaction(sender, async () => {
const zkApp = new SudokuZkApp(zkAppAddress);
await zkApp.submitSolution(
Sudoku.from(sudoku),
Sudoku.from(noSolution)
Expand All @@ -61,7 +61,7 @@ describe('sudoku', () => {
await tx.sign([senderKey]).send();
}).rejects.toThrow(/array contains the numbers 1...9/);

let isSolved = zkApp.isSolved.get().toBoolean();
const isSolved = zkApp.isSolved.get().toBoolean();
expect(isSolved).toBe(false);
});
});
Expand All @@ -73,7 +73,7 @@ async function deploy(
sender: PublicKey,
senderKey: PrivateKey
) {
let tx = await Mina.transaction(sender, async () => {
const tx = await Mina.transaction(sender, async () => {
AccountUpdate.fundNewAccount(sender);
await zkApp.deploy();
await zkApp.update(Sudoku.from(sudoku));
Expand Down
26 changes: 13 additions & 13 deletions examples/sudoku/ts/src/sudoku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ class SudokuZkApp extends SmartContract {
sudokuInstance: Sudoku,
solutionInstance: Sudoku
) {
let sudoku = sudokuInstance.value;
let solution = solutionInstance.value;
const sudoku = sudokuInstance.value;
const solution = solutionInstance.value;

// first, we check that the passed solution is a valid sudoku

// define helpers
let range9 = Array.from({ length: 9 }, (_, i) => i);
let oneTo9 = range9.map((i) => Field(i + 1));
const range9 = Array.from({ length: 9 }, (_, i) => i);
const oneTo9 = range9.map((i) => Field(i + 1));

function assertHas1To9(array: Field[]) {
oneTo9
Expand All @@ -65,19 +65,19 @@ class SudokuZkApp extends SmartContract {

// check all rows
for (let i = 0; i < 9; i++) {
let row = solution[i];
const row = solution[i];
assertHas1To9(row);
}
// check all columns
for (let j = 0; j < 9; j++) {
let column = solution.map((row) => row[j]);
const column = solution.map((row) => row[j]);
assertHas1To9(column);
}
// check 3x3 squares
for (let k = 0; k < 9; k++) {
let [i0, j0] = divmod(k, 3);
let square = range9.map((m) => {
let [i1, j1] = divmod(m, 3);
const [i0, j0] = divmod(k, 3);
const square = range9.map((m) => {
const [i1, j1] = divmod(m, 3);
return solution[3 * i0 + i1][3 * j0 + j1];
});
assertHas1To9(square);
Expand All @@ -86,8 +86,8 @@ class SudokuZkApp extends SmartContract {
// next, we check that the solution extends the initial sudoku
for (let i = 0; i < 9; i++) {
for (let j = 0; j < 9; j++) {
let cell = sudoku[i][j];
let solutionCell = solution[i][j];
const cell = sudoku[i][j];
const solutionCell = solution[i][j];
// either the sudoku has nothing in it (indicated by a cell value of 0),
// or it is equal to the solution
Bool.or(cell.equals(0), cell.equals(solutionCell)).assertTrue(
Expand All @@ -97,7 +97,7 @@ class SudokuZkApp extends SmartContract {
}

// finally, we check that the sudoku is the one that was originally deployed
let sudokuHash = this.sudokuHash.getAndRequireEquals();
const sudokuHash = this.sudokuHash.getAndRequireEquals();

sudokuInstance
.hash()
Expand All @@ -109,6 +109,6 @@ class SudokuZkApp extends SmartContract {
}

function divmod(k: number, n: number) {
let q = Math.floor(k / n);
const q = Math.floor(k / n);
return [q, k - q * n];
}
6 changes: 3 additions & 3 deletions examples/tictactoe/ts/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from 'o1js';
import { TicTacToe, Board } from './tictactoe.js';

let Local = await Mina.LocalBlockchain({ proofsEnabled: false });
const Local = await Mina.LocalBlockchain({ proofsEnabled: false });
Mina.setActiveInstance(Local);
const [player1, player2] = Local.testAccounts;
const player1Key = player1.key;
Expand Down Expand Up @@ -52,7 +52,7 @@ console.log('after transaction');
let b = zkApp.board.get();

console.log('initial state of the zkApp');
let zkAppState = Mina.getAccount(zkAppPublicKey);
const zkAppState = Mina.getAccount(zkAppPublicKey);

for (const i in [0, 1, 2, 3, 4, 5, 6, 7]) {
console.log('state', i, ':', zkAppState?.zkapp?.appState?.[i].toString());
Expand Down Expand Up @@ -99,7 +99,7 @@ await makeMove(player1, player1Key, 2, 2);
b = zkApp.board.get();
new Board(b).printState();

let isNextPlayer2 = zkApp.nextIsPlayer2.get();
const isNextPlayer2 = zkApp.nextIsPlayer2.get();

console.log('did someone win?', isNextPlayer2 ? 'Player 1!' : 'Player 2!');
// cleanup
Expand Down
4 changes: 2 additions & 2 deletions examples/tictactoe/ts/src/tictactoe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('tictactoe', () => {
zkAppPrivateKey: PrivateKey;

beforeEach(async () => {
let Local = await Mina.LocalBlockchain({ proofsEnabled: false });
const Local = await Mina.LocalBlockchain({ proofsEnabled: false });
Mina.setActiveInstance(Local);

[player1, player2] = Local.testAccounts;
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('tictactoe', () => {
await txn.sign([player1Key]).send();

// check next player
let isNextPlayer2 = zkApp.nextIsPlayer2.get();
const isNextPlayer2 = zkApp.nextIsPlayer2.get();
expect(isNextPlayer2).toEqual(Bool(true));
});
});
10 changes: 5 additions & 5 deletions examples/tictactoe/ts/src/tictactoe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class Board {

constructor(serializedBoard: Field) {
const bits = serializedBoard.toBits(18);
let board = [];
const board = [];
for (let i = 0; i < 3; i++) {
let row = [];
const row = [];
for (let j = 0; j < 3; j++) {
const isPlayed = bits[i * 3 + j];
const player = bits[i * 3 + j + 9];
Expand All @@ -50,8 +50,8 @@ class Board {
}

serialize(): Field {
let isPlayed = [];
let player = [];
const isPlayed = [];
const player = [];
for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
isPlayed.push(this.board[i][j].isSome);
Expand Down Expand Up @@ -211,7 +211,7 @@ class TicTacToe extends SmartContract {

// 4. get and deserialize the board
this.board.requireEquals(this.board.get()); // precondition that links this.board.get() to the actual on-chain state
let board = new Board(this.board.get());
const board = new Board(this.board.get());

// 5. update the board (and the state) with our move
x.equals(Field(0))
Expand Down
Loading