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

chore(wip): try jest changes for jean's PR #8602

Merged
merged 2 commits into from
Sep 17, 2024
Merged
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
21 changes: 15 additions & 6 deletions yarn-project/bb-prover/src/avm_proving.test.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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,
);
Expand Down Expand Up @@ -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
);
Expand All @@ -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,
);
Expand All @@ -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',
Expand All @@ -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,
);
Expand Down Expand Up @@ -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,
);
});
});
});
29 changes: 22 additions & 7 deletions yarn-project/bb-prover/src/test/test_avm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -126,7 +129,7 @@ export async function proveAvmTestContract(
const globals = globalVariables == undefined ? GlobalVariables.empty() : globalVariables;
const environment = initExecutionEnvironment({ functionSelector, calldata, globals });

const contractsDb = mock<PublicContractsDB>();
const contractsDb = jestMock() as PublicContractsDB;
const contractInstance = new SerializableContractInstance({
version: 1,
salt: new Fr(0x123),
Expand All @@ -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<PublicStateDB>();
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);
Expand Down Expand Up @@ -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!);
Expand Down
1 change: 1 addition & 0 deletions yarn-project/ivc-integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions yarn-project/ivc-integration/src/avm_integration.test.ts
Original file line number Diff line number Diff line change
@@ -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 */

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -102,4 +102,4 @@ describe('AVM Integration', () => {

expect(verifyResult.status).toBe(BB_RESULT.SUCCESS);
});
});
});
1 change: 1 addition & 0 deletions yarn-project/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading