diff --git a/yarn-project/bb-prover/src/avm_proving.test.ts b/yarn-project/bb-prover/src/avm_proving.test.ts index 7ff6ff83ce59..6444b8b01ebc 100644 --- a/yarn-project/bb-prover/src/avm_proving.test.ts +++ b/yarn-project/bb-prover/src/avm_proving.test.ts @@ -1,8 +1,15 @@ import { GlobalVariables } from '@aztec/circuits.js'; import { Fr } from '@aztec/foundation/fields'; + + +import { mock } from 'jest-mock-extended'; + + + import { proveAndVerifyAvmTestContract } from '../src/test/test_avm.js'; + const TIMEOUT = 60_000; const TIMESTAMP = new Fr(99833); const GLOBAL_VARIABLES = GlobalVariables.empty(); @@ -30,7 +37,7 @@ describe('AVM WitGen, proof generation and verification', () => { it.each(avmFunctionsAndCalldata)( 'Should prove %s', async (name, calldata) => { - await proveAndVerifyAvmTestContract(name, calldata); + await proveAndVerifyAvmTestContract(jest, mock, name, calldata); }, TIMEOUT, ); @@ -76,7 +83,7 @@ describe('AVM WitGen, proof generation and verification', () => { it.each(avmHashFunctions)( 'Should prove %s', async (name, calldata) => { - await proveAndVerifyAvmTestContract(name, calldata); + await proveAndVerifyAvmTestContract(jest, mock, name, calldata); }, TIMEOUT * 2, // We need more for keccak for now ); @@ -85,7 +92,7 @@ describe('AVM WitGen, proof generation and verification', () => { it( 'Should prove that timestamp matches', async () => { - await proveAndVerifyAvmTestContract('assert_timestamp', [TIMESTAMP], undefined, GLOBAL_VARIABLES); + await proveAndVerifyAvmTestContract(jest, mock, 'assert_timestamp', [TIMESTAMP], undefined, GLOBAL_VARIABLES); }, TIMEOUT, ); @@ -95,6 +102,8 @@ describe('AVM WitGen, proof generation and verification', () => { async () => { // The error assertion string must match with that of assert_timestamp noir function. await proveAndVerifyAvmTestContract( + jest, + mock, 'assert_timestamp', [TIMESTAMP.add(new Fr(1))], 'timestamp does not match', @@ -116,7 +125,7 @@ describe('AVM WitGen, proof generation and verification', () => { it.each(avmEmbeddedCurveFunctions)( 'Should prove %s', async (name, calldata) => { - await proveAndVerifyAvmTestContract(name, calldata); + await proveAndVerifyAvmTestContract(jest, mock, name, calldata); }, TIMEOUT, ); @@ -145,9 +154,9 @@ describe('AVM WitGen, proof generation and verification', () => { it.each(avmContextFunctions)( 'Should prove %s', async contextFunction => { - await proveAndVerifyAvmTestContract(contextFunction); + await proveAndVerifyAvmTestContract(jest, mock, contextFunction); }, TIMEOUT, ); }); -}); +}); \ No newline at end of file diff --git a/yarn-project/bb-prover/src/test/test_avm.ts b/yarn-project/bb-prover/src/test/test_avm.ts index 4903d96210a6..d9f522bf7114 100644 --- a/yarn-project/bb-prover/src/test/test_avm.ts +++ b/yarn-project/bb-prover/src/test/test_avm.ts @@ -45,8 +45,6 @@ import { } from '@aztec/simulator/avm/fixtures'; import { SerializableContractInstance } from '@aztec/types/contracts'; -import { jest } from '@jest/globals'; -import { mock } from 'jest-mock-extended'; import fs from 'node:fs/promises'; import { tmpdir } from 'node:os'; import path from 'path'; @@ -116,6 +114,11 @@ const getPublicInputs = (result: PublicExecutionResult): PublicCircuitPublicInpu }; export async function proveAvmTestContract( + // NOTE(AD): these are hackishly passed instead of + // importing them as this module gets exported in our index.ts and jest is only a dev dependency/ + // In the future, a testing helper package that depends on jest might be a better solution + jest: any, + jestMock: any, functionName: string, calldata: Fr[] = [], assertionErrString?: string, @@ -126,7 +129,7 @@ export async function proveAvmTestContract( const globals = globalVariables == undefined ? GlobalVariables.empty() : globalVariables; const environment = initExecutionEnvironment({ functionSelector, calldata, globals }); - const contractsDb = mock(); + const contractsDb = jestMock() as PublicContractsDB; const contractInstance = new SerializableContractInstance({ version: 1, salt: new Fr(0x123), @@ -135,11 +138,11 @@ export async function proveAvmTestContract( initializationHash: new Fr(0x101112), publicKeysHash: new Fr(0x161718), }).withAddress(environment.address); - contractsDb.getContractInstance.mockResolvedValue(Promise.resolve(contractInstance)); + (contractsDb.getContractInstance as any).mockResolvedValue(Promise.resolve(contractInstance)); - const storageDb = mock(); + const storageDb = jestMock() as PublicStateDB; const storageValue = new Fr(5); - storageDb.storageRead.mockResolvedValue(Promise.resolve(storageValue)); + (storageDb.storageRead as any).mockResolvedValue(Promise.resolve(storageValue)); const hostStorage = initHostStorage({ contractsDb }); const trace = new PublicSideEffectTrace(startSideEffectCounter); @@ -196,12 +199,24 @@ export async function proveAvmTestContract( * execution. */ export async function proveAndVerifyAvmTestContract( + // NOTE(AD): these are hackishly passed instead of + // importing them as this module gets exported in our index.ts and jest is only a dev dependency/ + // In the future, a testing helper package that depends on jest might be a better solution + jest: any, + jestMock: any, functionName: string, calldata: Fr[] = [], assertionErrString?: string, globalVariables?: GlobalVariables, ) { - const succeededRes = await proveAvmTestContract(functionName, calldata, assertionErrString, globalVariables); + const succeededRes = await proveAvmTestContract( + jest, + jestMock, + functionName, + calldata, + assertionErrString, + globalVariables, + ); // Then we test VK extraction and serialization. const vkData = await extractAvmVkData(succeededRes.vkPath!); diff --git a/yarn-project/ivc-integration/package.json b/yarn-project/ivc-integration/package.json index 2976b6de2d8d..5036e1f55463 100644 --- a/yarn-project/ivc-integration/package.json +++ b/yarn-project/ivc-integration/package.json @@ -71,6 +71,7 @@ "@types/jest": "^29.5.0", "@types/node": "^18.7.23", "jest": "^29.5.0", + "jest-mock-extended": "^3.0.3", "levelup": "^5.1.1", "memdown": "^6.1.1", "ts-node": "^10.9.1", diff --git a/yarn-project/ivc-integration/src/avm_integration.test.ts b/yarn-project/ivc-integration/src/avm_integration.test.ts index 4f64f94fab50..7c92e32b186e 100644 --- a/yarn-project/ivc-integration/src/avm_integration.test.ts +++ b/yarn-project/ivc-integration/src/avm_integration.test.ts @@ -1,23 +1,23 @@ import { type BBSuccess, BB_RESULT, generateProof, verifyProof } from '@aztec/bb-prover'; import { proveAvmTestContract } from '@aztec/bb-prover'; -import { - AVM_PROOF_LENGTH_IN_FIELDS, - AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS, - PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH, -} from '@aztec/circuits.js/constants'; +import { AVM_PROOF_LENGTH_IN_FIELDS, AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS, PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH } from '@aztec/circuits.js/constants'; import { Fr } from '@aztec/foundation/fields'; import { createDebugLogger } from '@aztec/foundation/log'; import { BufferReader } from '@aztec/foundation/serialize'; import { type FixedLengthArray } from '@aztec/noir-protocol-circuits-types/types'; + + import { jest } from '@jest/globals'; import fs from 'fs/promises'; +import { mock } from 'jest-mock-extended'; import os from 'os'; import path from 'path'; import { fileURLToPath } from 'url'; import { MockPublicKernelCircuit, witnessGenMockPublicKernelCircuit } from './index.js'; + // Auto-generated types from noir are not in camel case. /* eslint-disable camelcase */ @@ -54,7 +54,7 @@ describe('AVM Integration', () => { } it('Should generate and verify an ultra honk proof from an AVM verification', async () => { - const bbSuccess = await proveAvmTestContract('new_note_hash', [new Fr(1)]); + const bbSuccess = await proveAvmTestContract(jest, mock, 'new_note_hash', [new Fr(1)]); const avmProofPath = bbSuccess.proofPath; const avmVkPath = bbSuccess.vkPath; @@ -102,4 +102,4 @@ describe('AVM Integration', () => { expect(verifyResult.status).toBe(BB_RESULT.SUCCESS); }); -}); +}); \ No newline at end of file diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index f9c30a026f8e..faafc60d2554 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -700,6 +700,7 @@ __metadata: "@types/node": ^18.7.23 change-case: ^5.4.4 jest: ^29.5.0 + jest-mock-extended: ^3.0.3 levelup: ^5.1.1 memdown: ^6.1.1 ts-node: ^10.9.1