From 3fd0c5bbf89c56e84f66fed355e2e407c984ba44 Mon Sep 17 00:00:00 2001 From: Gregor Date: Tue, 22 Nov 2022 09:28:06 +0100 Subject: [PATCH] more cleanup in test --- examples/sudoku/ts/src/sudoku.test.ts | 35 ++++++++++++--------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/examples/sudoku/ts/src/sudoku.test.ts b/examples/sudoku/ts/src/sudoku.test.ts index fe27b64a..1fa3b9b8 100644 --- a/examples/sudoku/ts/src/sudoku.test.ts +++ b/examples/sudoku/ts/src/sudoku.test.ts @@ -39,7 +39,12 @@ describe('sudoku', () => { let solution = solveSudoku(sudoku); if (solution === undefined) throw Error('cannot happen'); - await submitSolution(sudoku, solution, account, zkAppAddress); + let tx = await Mina.transaction(account, () => { + let zkApp = new SudokuZkApp(zkAppAddress); + zkApp.submitSolution(Sudoku.from(sudoku), Sudoku.from(solution!)); + }); + await tx.prove(); + await tx.send(); isSolved = zkApp.isSolved.get().toBoolean(); expect(isSolved).toBe(true); @@ -54,9 +59,14 @@ describe('sudoku', () => { let noSolution = cloneSudoku(solution); noSolution[0][0] = (noSolution[0][0] % 9) + 1; - await expect(() => - submitSolution(sudoku, noSolution, account, zkAppAddress) - ).rejects.toThrow(/array contains the numbers 1...9/); + await expect(async () => { + let tx = await Mina.transaction(account, () => { + let zkApp = new SudokuZkApp(zkAppAddress); + zkApp.submitSolution(Sudoku.from(sudoku), Sudoku.from(noSolution)); + }); + await tx.prove(); + await tx.send(); + }).rejects.toThrow(/array contains the numbers 1...9/); let isSolved = zkApp.isSolved.get().toBoolean(); expect(isSolved).toBe(false); @@ -71,25 +81,10 @@ async function deploy( ) { let tx = await Mina.transaction(account, () => { AccountUpdate.fundNewAccount(account); - let sudokuInstance = Sudoku.from(sudoku); zkApp.deploy(); - zkApp.update(sudokuInstance); + zkApp.update(Sudoku.from(sudoku)); }); await tx.prove(); // this tx needs .sign(), because `deploy()` adds an account update that requires signature authorization await tx.sign([zkAppPrivateKey]).send(); } - -async function submitSolution( - sudoku: number[][], - solution: number[][], - account: PrivateKey, - zkAppAddress: PublicKey -) { - let tx = await Mina.transaction(account, () => { - let zkApp = new SudokuZkApp(zkAppAddress); - zkApp.submitSolution(Sudoku.from(sudoku), Sudoku.from(solution)); - }); - await tx.prove(); - await tx.send(); -}