-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1911 from o1-labs/test/recursive-zkprogram-web
Add recursive ZkProgram to e2e testing
- Loading branch information
Showing
6 changed files
with
96 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,31 @@ | ||
import replace from 'replace-in-file'; | ||
|
||
const options = { | ||
files: './dist/web/examples/zkapps/**/*.js', | ||
from: /from 'o1js'/g, | ||
to: "from '../../../index.js'", | ||
}; | ||
|
||
try { | ||
const results = await replace(options); | ||
console.log('Replacement results:', results); | ||
} catch (error) { | ||
console.error('Error occurred:', error); | ||
const replaceOptions = [ | ||
{ | ||
files: './dist/web/examples/zkapps/**/*.js', | ||
from: /from 'o1js'/g, | ||
to: "from '../../../index.js'", | ||
}, | ||
{ | ||
files: './dist/web/examples/zkprogram/*.js', | ||
from: /from 'o1js'/g, | ||
to: "from '../../index.js'", | ||
}, | ||
]; | ||
|
||
async function performReplacement(options) { | ||
try { | ||
const results = await replace(options); | ||
console.log(`Replacement results for ${options.files}:`, results); | ||
} catch (error) { | ||
console.error(`Error occurred while replacing in ${options.files}:`, error); | ||
} | ||
} | ||
|
||
async function main() { | ||
for (const options of replaceOptions) { | ||
await performReplacement(options); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { SelfProof, Field, ZkProgram } from 'o1js'; | ||
|
||
export const RecursiveProgram = ZkProgram({ | ||
name: 'recursive-program', | ||
publicInput: Field, | ||
|
||
methods: { | ||
baseCase: { | ||
privateInputs: [], | ||
async method(input: Field) { | ||
input.assertEquals(Field(0)); | ||
}, | ||
}, | ||
|
||
inductiveCase: { | ||
privateInputs: [SelfProof], | ||
async method(input: Field, earlierProof: SelfProof<Field, void>) { | ||
earlierProof.verify(); | ||
earlierProof.publicInput.add(1).assertEquals(input); | ||
}, | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters