-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add handling to
noir_wasm
for projects without dependencies (#…
…4344) # Description ## Problem\* Resolves #4338 ## Summary\* This PR returns an empty dependencies map rather than undefined if the package being compiled doesn't have any dependencies. I've also updated the test suite so it also compiles more than just a contract ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[Exceptional Case]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --------- Co-authored-by: kevaundray <kevtheappdev@gmail.com>
- Loading branch information
1 parent
292a972
commit 4982251
Showing
9 changed files
with
197 additions
and
77 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
import { getPaths } from '../../shared'; | ||
import { expect } from '@esm-bundle/chai'; | ||
import { compile, createFileManager } from '@noir-lang/noir_wasm'; | ||
import { ContractArtifact, ProgramArtifact } from '../../../src/types/noir_artifact'; | ||
import { shouldCompileContractIdentically, shouldCompileProgramIdentically } from '../shared/compile.test'; | ||
|
||
const paths = getPaths('.'); | ||
|
||
async function getFile(path: string) { | ||
// @ts-ignore | ||
const basePath = new URL('./../../', import.meta.url).toString().replace(/\/$/g, ''); | ||
const url = `${basePath}${path.replace('.', '')}`; | ||
const response = await fetch(url); | ||
return response; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
async function getPrecompiledSource(path: string): Promise<any> { | ||
const response = await getFile(path); | ||
const compiledData = await response.text(); | ||
return JSON.parse(compiledData); | ||
} | ||
|
||
describe('noir-compiler/browser', () => { | ||
shouldCompileProgramIdentically( | ||
async () => { | ||
const { simpleScriptExpectedArtifact } = paths; | ||
const fm = createFileManager('/'); | ||
const files = Object.values(paths).filter((fileOrDir) => /^\.?\/.*\..*$/.test(fileOrDir)); | ||
for (const path of files) { | ||
console.log(path); | ||
await fm.writeFile(path, (await getFile(path)).body as ReadableStream<Uint8Array>); | ||
} | ||
const nargoArtifact = (await getPrecompiledSource(simpleScriptExpectedArtifact)) as ProgramArtifact; | ||
const noirWasmArtifact = await compile(fm, '/fixtures/simple'); | ||
|
||
return { nargoArtifact, noirWasmArtifact }; | ||
}, | ||
expect, | ||
60 * 20e3, | ||
); | ||
|
||
shouldCompileProgramIdentically( | ||
async () => { | ||
const { depsScriptExpectedArtifact } = paths; | ||
const fm = createFileManager('/'); | ||
const files = Object.values(paths).filter((fileOrDir) => /^\.?\/.*\..*$/.test(fileOrDir)); | ||
for (const path of files) { | ||
console.log(path); | ||
await fm.writeFile(path, (await getFile(path)).body as ReadableStream<Uint8Array>); | ||
} | ||
const nargoArtifact = (await getPrecompiledSource(depsScriptExpectedArtifact)) as ProgramArtifact; | ||
const noirWasmArtifact = await compile(fm, '/fixtures/with-deps'); | ||
|
||
return { nargoArtifact, noirWasmArtifact }; | ||
}, | ||
expect, | ||
60 * 20e3, | ||
); | ||
|
||
shouldCompileContractIdentically( | ||
async () => { | ||
const { contractExpectedArtifact } = paths; | ||
const fm = createFileManager('/'); | ||
const files = Object.values(paths).filter((fileOrDir) => /^\.?\/.*\..*$/.test(fileOrDir)); | ||
for (const path of files) { | ||
console.log(path); | ||
await fm.writeFile(path, (await getFile(path)).body as ReadableStream<Uint8Array>); | ||
} | ||
const nargoArtifact = (await getPrecompiledSource(contractExpectedArtifact)) as ContractArtifact; | ||
const noirWasmArtifact = await compile(fm, '/fixtures/noir-contract'); | ||
|
||
return { nargoArtifact, noirWasmArtifact }; | ||
}, | ||
expect, | ||
60 * 20e3, | ||
); | ||
}); |
43 changes: 0 additions & 43 deletions
43
compiler/wasm/test/compiler/browser/compile_with_deps.test.ts
This file was deleted.
Oops, something went wrong.
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,39 @@ | ||
import { join, resolve } from 'path'; | ||
import { getPaths } from '../../shared'; | ||
|
||
import { expect } from 'chai'; | ||
import { compile, createFileManager } from '@noir-lang/noir_wasm'; | ||
import { readFile } from 'fs/promises'; | ||
import { ContractArtifact, ProgramArtifact } from '../../../src/types/noir_artifact'; | ||
import { shouldCompileContractIdentically, shouldCompileProgramIdentically } from '../shared/compile.test'; | ||
|
||
const basePath = resolve(join(__dirname, '../../')); | ||
|
||
describe('noir-compiler/node', () => { | ||
shouldCompileProgramIdentically(async () => { | ||
const { simpleScriptProjectPath, simpleScriptExpectedArtifact } = getPaths(basePath); | ||
|
||
const fm = createFileManager(simpleScriptProjectPath); | ||
const nargoArtifact = JSON.parse((await readFile(simpleScriptExpectedArtifact)).toString()) as ProgramArtifact; | ||
const noirWasmArtifact = await compile(fm); | ||
return { nargoArtifact, noirWasmArtifact }; | ||
}, expect); | ||
|
||
shouldCompileProgramIdentically(async () => { | ||
const { depsScriptProjectPath, depsScriptExpectedArtifact } = getPaths(basePath); | ||
|
||
const fm = createFileManager(depsScriptProjectPath); | ||
const nargoArtifact = JSON.parse((await readFile(depsScriptExpectedArtifact)).toString()) as ProgramArtifact; | ||
const noirWasmArtifact = await compile(fm); | ||
return { nargoArtifact, noirWasmArtifact }; | ||
}, expect); | ||
|
||
shouldCompileContractIdentically(async () => { | ||
const { contractProjectPath, contractExpectedArtifact } = getPaths(basePath); | ||
|
||
const fm = createFileManager(contractProjectPath); | ||
const nargoArtifact = JSON.parse((await readFile(contractExpectedArtifact)).toString()) as ContractArtifact; | ||
const noirWasmArtifact = await compile(fm); | ||
return { nargoArtifact, noirWasmArtifact }; | ||
}, expect); | ||
}); |
20 changes: 0 additions & 20 deletions
20
compiler/wasm/test/compiler/node/compile_with_deps.test.ts
This file was deleted.
Oops, something went wrong.
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