From ded2504c18d2ccb01e430f0cb9300f7d85b731bd Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Fri, 4 Apr 2025 16:27:58 -0300 Subject: [PATCH] chore: Test that a contract without initializer can still be called In #12215 the `TestContract` had an `initializer` added, meaning that the e2e test that checked that we could call a private function in a contract without an initializer no longer tested that. This PR adds another test that covers that scenario. --- .../private_initialization.test.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_deploy_contract/private_initialization.test.ts b/yarn-project/end-to-end/src/e2e_deploy_contract/private_initialization.test.ts index f0a9b5b8ab39..0ed9548fdd9d 100644 --- a/yarn-project/end-to-end/src/e2e_deploy_contract/private_initialization.test.ts +++ b/yarn-project/end-to-end/src/e2e_deploy_contract/private_initialization.test.ts @@ -1,4 +1,5 @@ import { type AztecNode, BatchCall, Fr, type Logger, type Wallet } from '@aztec/aztec.js'; +import { DocsExampleContract } from '@aztec/noir-contracts.js/DocsExample'; import { StatefulTestContract } from '@aztec/noir-contracts.js/StatefulTest'; import { TestContract } from '@aztec/noir-contracts.js/Test'; import { siloNullifier } from '@aztec/stdlib/hash'; @@ -18,9 +19,10 @@ describe('e2e_deploy_contract private initialization', () => { afterAll(() => t.teardown()); - // Tests calling a private function in an uninitialized and undeployed contract. Note that - // it still requires registering the contract artifact and instance locally in the pxe. - it('executes a function in an undeployed contract from an account contract', async () => { + // Tests calling a private function in an uninitialized and undeployed contract. + // Requires registering the contract artifact and instance locally in the pxe. + // The function has a noinitcheck flag so it can be called without initialization. + it('executes a noinitcheck function in an uninitialized contract', async () => { const contract = await t.registerContract(wallet, TestContract); const receipt = await contract.methods.emit_nullifier(10).send().wait(); const txEffects = await aztecNode.getTxEffect(receipt.txHash); @@ -29,6 +31,16 @@ describe('e2e_deploy_contract private initialization', () => { expect(txEffects!.data.nullifiers).toContainEqual(expected); }); + // Tests calling a private function in an uninitialized and undeployed contract. + // Requires registering the contract artifact and instance locally in the pxe. + // This contract does not have a constructor, so the fn does not need the noinitcheck flag. + it('executes a function in a contract without initializer', async () => { + const contract = await t.registerContract(wallet, DocsExampleContract); + await expect(contract.methods.is_legendary_initialized().simulate()).resolves.toEqual(false); + await contract.methods.initialize_private(0, 1).send().wait(); + await expect(contract.methods.is_legendary_initialized().simulate()).resolves.toEqual(true); + }); + // Tests privately initializing an undeployed contract. Also requires pxe registration in advance. it('privately initializes an undeployed contract from an account contract', async () => { const owner = await t.registerRandomAccount();