diff --git a/tooling/noir_codegen/.gitignore b/tooling/noir_codegen/.gitignore index ec86c860b3..29b0e40ffa 100644 --- a/tooling/noir_codegen/.gitignore +++ b/tooling/noir_codegen/.gitignore @@ -2,3 +2,4 @@ crs lib test/codegen +test/test_lib/export diff --git a/tooling/noir_codegen/src/index.ts b/tooling/noir_codegen/src/index.ts index 19829cd06f..fbbab07bcf 100644 --- a/tooling/noir_codegen/src/index.ts +++ b/tooling/noir_codegen/src/index.ts @@ -46,14 +46,14 @@ export const codegen = (programs: [string, CompiledCircuit][]): string => { functions.push(codegenFunction(name, stripUnwantedFields(program), function_sig)); } + const structTypeDefinitions: string = codegenStructDefinitions(structTypeMap, primitiveTypeMap); + // Add the primitive Noir types that do not have a 1-1 mapping to TypeScript. const primitiveTypeAliases: string[] = []; for (const value of primitiveTypeMap.values()) { primitiveTypeAliases.push(`export type ${value.aliasName} = ${value.tsType};`); } - const structTypeDefinitions: string = codegenStructDefinitions(structTypeMap, primitiveTypeMap); - results = results.concat(...primitiveTypeAliases, '', structTypeDefinitions, ...functions); return results.join('\n'); diff --git a/tooling/noir_codegen/test/index.test.ts b/tooling/noir_codegen/test/index.test.ts index bce031ceec..03fb680a53 100644 --- a/tooling/noir_codegen/test/index.test.ts +++ b/tooling/noir_codegen/test/index.test.ts @@ -4,7 +4,7 @@ import { expect } from 'chai'; import { exported_function_foo, MyStruct, u64, ForeignCallHandler } from './codegen/index.js'; it('codegens a callable function', async () => { - const my_struct = { foo: true, bar: ['12345', '12345', '12345'] }; + const my_struct = { foo: true, bar: ['12345', '12345', '12345'], baz: '0x00' }; const [sum, constant, struct]: [u64, u64, MyStruct] = await exported_function_foo( '2', @@ -20,7 +20,7 @@ it('codegens a callable function', async () => { expect(sum).to.be.eq('0x05'); expect(constant).to.be.eq('0x03'); - expect(struct).to.be.deep.eq({ foo: true, bar: ['12345', '12345', '12345'] }); + expect(struct).to.be.deep.eq(my_struct); }); it('allows passing a custom foreign call handler', async () => { @@ -35,7 +35,7 @@ it('allows passing a custom foreign call handler', async () => { return []; }; - const my_struct = { foo: true, bar: ['12345', '12345', '12345'] }; + const my_struct = { foo: true, bar: ['12345', '12345', '12345'], baz: '0x00' }; const [sum, constant, struct]: [u64, u64, MyStruct] = await exported_function_foo( '2', @@ -102,5 +102,5 @@ it('allows passing a custom foreign call handler', async () => { expect(sum).to.be.eq('0x05'); expect(constant).to.be.eq('0x03'); - expect(struct).to.be.deep.eq({ foo: true, bar: ['12345', '12345', '12345'] }); + expect(struct).to.be.deep.eq(my_struct); }); diff --git a/tooling/noir_codegen/test/test_lib/src/lib.nr b/tooling/noir_codegen/test/test_lib/src/lib.nr index 64f93cdf40..23607c6f65 100644 --- a/tooling/noir_codegen/test/test_lib/src/lib.nr +++ b/tooling/noir_codegen/test/test_lib/src/lib.nr @@ -1,6 +1,7 @@ struct MyStruct { foo: bool, bar: [str<5>; 3], + baz: Field } struct NestedStruct {