diff --git a/yarn-project/acir-simulator/src/client/private_execution.test.ts b/yarn-project/acir-simulator/src/client/private_execution.test.ts index 09487891814..43a69221d78 100644 --- a/yarn-project/acir-simulator/src/client/private_execution.test.ts +++ b/yarn-project/acir-simulator/src/client/private_execution.test.ts @@ -999,5 +999,29 @@ describe('Private Execution test suite', () => { const result = await runSimulator({ origin: AztecAddress.random(), abi, args }); expect(result.returnValues).toEqual([portalContractAddress.toField().value]); }); + + it('this_address should return the current context address', async () => { + const contractAddress = AztecAddress.random(); + + // Tweak the contract ABI so we can extract return values + const abi = TestContractAbi.functions.find(f => f.name === 'getThisAddress')!; + abi.returnTypes = [{ kind: 'field' }]; + + // Overwrite the oracle return value + const result = await runSimulator({ origin: AztecAddress.random(), abi, args: [], contractAddress }); + expect(result.returnValues).toEqual([contractAddress.toField().value]); + }); + + it("this_portal_address should return the current context's portal address", async () => { + const portalContractAddress = EthAddress.random(); + + // Tweak the contract ABI so we can extract return values + const abi = TestContractAbi.functions.find(f => f.name === 'getThisPortalAddress')!; + abi.returnTypes = [{ kind: 'field' }]; + + // Overwrite the oracle return value + const result = await runSimulator({ origin: AztecAddress.random(), abi, args: [], portalContractAddress }); + expect(result.returnValues).toEqual([portalContractAddress.toField().value]); + }); }); }); diff --git a/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr index e2b66107ffe..db44cc275b5 100644 --- a/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr @@ -44,6 +44,26 @@ contract Test { context.finish() } + // Get the address of the l1 portal for this contract (taken from the input context) + fn getThisPortalAddress( + inputs: PrivateContextInputs, + ) -> distinct pub abi::PrivateCircuitPublicInputs { + let mut context = Context::new(inputs, abi::hash_args([])); + let this_portal_address = context.this_portal_address(); + context.return_values.push_array([this_portal_address]); + context.finish() + } + + // Get the address of this contract (taken from the input context) + fn getThisAddress( + inputs: PrivateContextInputs, + ) -> distinct pub abi::PrivateCircuitPublicInputs { + let mut context = Context::new(inputs, abi::hash_args([])); + let this_address = context.this_address(); + context.return_values.push_array([this_address]); + context.finish() + } + // Purely exists for testing open fn createL2ToL1MessagePublic( _inputs: PublicContextInputs,