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

Circomdesktoptest #5399

Open
wants to merge 11 commits into
base: circom-desktop
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion apps/circuit-compiler/src/app/components/generateProof.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function GenerateProof () {
className="btn btn-secondary btn-block d-block w-100 text-break mb-1 mt-1"
onClick={() => generateProof(circuitApp.plugin, circuitApp.appState, circuitApp.dispatch)}
disabled={(status === "compiling") || (status === "computing") || (status === "proving") || (status === "exporting")}
data-id="compute_witness_btn"
data-id="generateProofBtn"
>
<RenderIf condition={status === 'proving'}>
<i className="fas fa-sync fa-spin mr-2" aria-hidden="true"></i>
Expand Down
Binary file not shown.
2 changes: 2 additions & 0 deletions apps/remixdesktop/src/plugins/circomElectronBasePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class CircomElectronPluginClient extends ElectronBasePluginClient {
}

async install(version = 'latest') {
this.call('terminal' as any, 'logHtml', `Checking if circom compiler (${version}) is installed in ${getInstallationPath(version)}`)

this.isCircomInstalled = await circomCli.isCircomInstalled(version)
if (!this.isCircomInstalled) {
this.call('terminal' as any, 'logHtml', 'Downloading circom compiler from ' + getInstallationUrl(version))
Expand Down
42 changes: 12 additions & 30 deletions apps/remixdesktop/src/tools/circom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { app } from 'electron'
import os from 'os'
import { exec } from 'child_process'
import path from 'path'
import fs, { existsSync } from 'fs'
Expand Down Expand Up @@ -33,16 +34,13 @@ async function downloadFile(url: string, dest: string) {
}

export function getInstallationPath(version) {
switch (process.platform) {
case 'win32':
return process.env.NODE_ENV === 'production' ? path.join(app.getPath('temp'), 'circom-download', version, 'circom-windows-amd64.exe') : path.join(app.getAppPath(), 'circom-download', version, 'circom-windows-amd64.exe')

case 'darwin':
return process.env.NODE_ENV === 'production' ? path.join(app.getPath('temp'), 'circom-download', version, 'circom-macos-amd64') : path.join(app.getAppPath(), 'circom-download', version, 'circom-macos-amd64')

case 'linux':
return process.env.NODE_ENV === 'production' ? path.join(app.getPath('temp'), 'circom-download', version, 'circom-linux-amd64') : path.join(app.getAppPath(), 'circom-download', version, 'circom-linux-amd64')
}
const fileNames = {
win32: 'circom-windows-amd64.exe',
darwin: 'circom-macos-amd64',
linux: 'circom-linux-amd64'
};

return path.join(os.tmpdir(), 'circom-download', version, fileNames[process.platform]);
}

export function getInstallationUrl(version) {
Expand All @@ -59,25 +57,9 @@ export function getInstallationUrl(version) {
}

export function getLogInputSignalsPath() {
console.log('home: ', app.getPath('home'))
console.log('appData: ', app.getPath('appData'))
console.log('userData: ', app.getPath('userData'))
console.log('temp: ', app.getPath('temp'))
console.log('exe: ', app.getPath('exe'))
console.log('getAppPath: ', app.getAppPath())
switch (process.platform) {
case 'win32':
// eslint-disable-next-line no-case-declarations
const programDir = app.getPath('exe').split('\\').slice(0, -1).join('\\')

return process.env.NODE_ENV === 'production' ? path.join(programDir, 'log_input_signals.txt') : path.join(app.getAppPath(), 'log_input_signals.txt')

case 'darwin':
return path.join(app.getAppPath(), 'log_input_signals.txt')

case 'linux':
return process.env.NODE_ENV === 'production' ? path.join(app.getPath('temp'), 'log_input_signals.txt') : path.join(app.getAppPath(), 'log_input_signals.txt')
}
const tempFilePath = path.join(os.tmpdir(), 'log_input_signals.txt');
return tempFilePath;
}

export const circomCli = {
Expand Down Expand Up @@ -106,9 +88,9 @@ export const circomCli = {
async run (filePath: string, version: string, options?: Record<string, string>) {
const installationPath = getInstallationPath(version)
const cmd = `${installationPath} ${filePath} ${Object.keys(options || {}).map((key) => options[key] ? `--${key} ${options[key]}` : `--${key}`).join(' ')}`

console.log(cmd)
return new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => {
exec(cmd, { cwd: os.tmpdir() }, (error, stdout, stderr) => {
if (error) {
reject(`${error.message} with error code ${error.code}`)
} else {
Expand Down
86 changes: 86 additions & 0 deletions apps/remixdesktop/test/tests/app/circom-compiler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { NightwatchBrowser } from "nightwatch"


const tests = {
before: function (browser: NightwatchBrowser, done: VoidFunction) {
browser.hideToolTips()
done()
},
'Should create semaphore workspace': function (browser: NightwatchBrowser) {
browser
.waitForElementVisible('*[data-id="homeTabGetStartedsemaphore"]', 20000)
.click('*[data-id="homeTabGetStartedsemaphore"]')
.pause(3000)
.windowHandles(function (result) {
console.log(result.value)
browser.switchWindow(result.value[1])
.waitForElementVisible('*[data-id="treeViewLitreeViewItemcircuits"]')
.click('*[data-id="treeViewLitreeViewItemcircuits"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemcircuits/semaphore.circom"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts"]')
.click('*[data-id="treeViewLitreeViewItemscripts"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/groth16"]')
.click('*[data-id="treeViewLitreeViewItemscripts/groth16"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/groth16/groth16_trusted_setup.ts"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/groth16/groth16_zkproof.ts"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/plonk"]')
.click('*[data-id="treeViewLitreeViewItemscripts/plonk"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/plonk/plonk_trusted_setup.ts"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/plonk/plonk_zkproof.ts"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemtemplates"]')
.click('*[data-id="treeViewLitreeViewItemtemplates"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemtemplates/groth16_verifier.sol.ejs"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemtemplates/plonk_verifier.sol.ejs"]')
})
},
'Should compile a simple circuit using editor play button': function (browser: NightwatchBrowser) {
browser
.click('[data-id="treeViewLitreeViewItemcircuits/simple.circom"]')
.waitForElementVisible('[data-id="play-editor"]')
.click('[data-id="play-editor"]')
.pause(3000)
.click('[data-id="play-editor"]')
.waitForElementVisible('[data-id="verticalIconsKindcircuit-compiler"]')
.waitForElementVisible('[data-id="treeViewLitreeViewItemcircuits/.bin"]')
.click('[data-id="treeViewLitreeViewItemcircuits/.bin"]')
.waitForElementVisible('[data-id="treeViewLitreeViewItemcircuits/.bin/simple_js"]')
.click('[data-id="treeViewLitreeViewItemcircuits/.bin/simple_js"]')
.waitForElementVisible('[data-id="treeViewLitreeViewItemcircuits/.bin/simple_js/simple.wasm"]')
},
'Should run setup script for simple circuit': function (browser: NightwatchBrowser) {
browser
.clickLaunchIcon('circuit-compiler')
.frame(0)
.waitForElementVisible('[data-id="runSetupBtn"]')
.click('[data-id="runSetupBtn"]')
},
'Should compute a witness for a simple circuit': function (browser: NightwatchBrowser) {
browser
.waitForElementVisible('[data-id="compute_witness_btn"]', 60000)
.waitForElementVisible('[data-id="circuit_input_a"]')
.waitForElementVisible('[data-id="circuit_input_b"]')
.setValue('[data-id="circuit_input_a"]', '1')
.setValue('[data-id="circuit_input_b"]', '2')
.click('[data-id="compute_witness_btn"]')
.frameParent()
.clickLaunchIcon('filePanel')
.waitForElementPresent('[data-id="treeViewLitreeViewItemcircuits/.bin/simple_js/simple.wtn"]')
.waitForElementVisible('[data-id="treeViewLitreeViewItemcircuits/.bin/simple_js/simple.wtn"]')
},
'Should generate proof for a simple circuit': function (browser: NightwatchBrowser) {
browser
.clickLaunchIcon('circuit-compiler')
.frame(0)
.waitForElementVisible('[data-id="generateProofBtn"]')
.click('[data-id="generateProofBtn"]')
.frameParent()
.waitForElementVisible({
locateStrategy: 'xpath',
selector: "//span[@class='text-log' and contains(., 'zk proof validity true')]",
timeout: 60000
})

}
}

module.exports = tests
67 changes: 67 additions & 0 deletions apps/remixdesktop/test/tests/app/circom-script.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { NightwatchBrowser } from "nightwatch"


const tests = {
before: function (browser: NightwatchBrowser, done: VoidFunction) {
browser.hideToolTips()
done()
},
'Should create semaphore workspace': function (browser: NightwatchBrowser) {
browser
.waitForElementVisible('*[data-id="homeTabGetStartedsemaphore"]', 20000)
.click('*[data-id="homeTabGetStartedsemaphore"]')
.pause(3000)
.windowHandles(function (result) {
console.log(result.value)
browser.switchWindow(result.value[1])
.waitForElementVisible('*[data-id="treeViewLitreeViewItemcircuits"]')
.click('*[data-id="treeViewLitreeViewItemcircuits"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemcircuits/semaphore.circom"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts"]')
.click('*[data-id="treeViewLitreeViewItemscripts"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/groth16"]')
.click('*[data-id="treeViewLitreeViewItemscripts/groth16"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/groth16/groth16_trusted_setup.ts"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/groth16/groth16_zkproof.ts"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/plonk"]')
.click('*[data-id="treeViewLitreeViewItemscripts/plonk"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/plonk/plonk_trusted_setup.ts"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/plonk/plonk_zkproof.ts"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemtemplates"]')
.click('*[data-id="treeViewLitreeViewItemtemplates"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemtemplates/groth16_verifier.sol.ejs"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemtemplates/plonk_verifier.sol.ejs"]')
})
},
'Should run plonk trusted setup script for hash checker #group6': function (browser: NightwatchBrowser) {
browser
.click('[data-id="treeViewLitreeViewItemscripts/plonk/plonk_trusted_setup.ts"]')
.pause(2000)
.click('[data-id="play-editor"]')
.waitForElementVisible('[data-id="verticalIconsKindcircuit-compiler"]')
.waitForElementVisible({
locateStrategy: 'xpath',
selector: "//span[@class='text-log' and contains(., 'setup done.')]",
timeout: 60000
})
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/plonk/zk"]')
.click('*[data-id="treeViewLitreeViewItemscripts/plonk/zk"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/plonk/zk/keys"]')
.click('*[data-id="treeViewLitreeViewItemscripts/plonk/zk/keys"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/plonk/zk/keys/verification_key.json"]')
},
'Should run plonk zkproof script for hash checker #group6': function (browser: NightwatchBrowser) {
browser
.click('[data-id="treeViewLitreeViewItemscripts/plonk/plonk_zkproof.ts"]')
.pause(2000)
.click('[data-id="play-editor"]')
.waitForElementVisible({
locateStrategy: 'xpath',
selector: "//span[@class='text-log' and contains(., 'proof done')]",
timeout: 60000
})
}

}

module.exports = {}
Loading