|
| 1 | +import { Fr, type Logger, generateClaimSecret, retryUntil } from '@aztec/aztec.js'; |
| 2 | +import { EthAddress } from '@aztec/foundation/eth-address'; |
| 3 | +import { TestContract } from '@aztec/noir-test-contracts.js/Test'; |
| 4 | + |
| 5 | +import { jest } from '@jest/globals'; |
| 6 | + |
| 7 | +import { sendL1ToL2Message } from '../fixtures/l1_to_l2_messaging.js'; |
| 8 | +import type { EndToEndContext } from '../fixtures/utils.js'; |
| 9 | +import { EpochsTestContext } from './epochs_test.js'; |
| 10 | + |
| 11 | +jest.setTimeout(1000 * 60 * 10); |
| 12 | + |
| 13 | +// Proves an epoch that contains txs with public function calls that consume L1 to L2 messages |
| 14 | +// Regression for this issue https://aztecprotocol.slack.com/archives/C085C1942HG/p1754400213976059 |
| 15 | +describe('e2e_epochs/epochs_proof_public_cross_chain', () => { |
| 16 | + let context: EndToEndContext; |
| 17 | + let logger: Logger; |
| 18 | + |
| 19 | + let test: EpochsTestContext; |
| 20 | + |
| 21 | + beforeEach(async () => { |
| 22 | + test = await EpochsTestContext.setup({ numberOfAccounts: 1, minTxsPerBlock: 1, disableAnvilTestWatcher: true }); |
| 23 | + ({ context, logger } = test); |
| 24 | + }); |
| 25 | + |
| 26 | + afterEach(async () => { |
| 27 | + jest.restoreAllMocks(); |
| 28 | + await test.teardown(); |
| 29 | + }); |
| 30 | + |
| 31 | + it('submits proof with a tx with public l1-to-l2 message claim', async () => { |
| 32 | + // Deploy a contract that consumes L1 to L2 messages |
| 33 | + await context.aztecNodeAdmin!.setConfig({ minTxsPerBlock: 0 }); |
| 34 | + logger.warn(`Deploying test contract`); |
| 35 | + const testContract = await TestContract.deploy(context.wallet).send({ from: context.accounts[0] }).deployed(); |
| 36 | + logger.warn(`Test contract deployed at ${testContract.address}`); |
| 37 | + |
| 38 | + // Send an l1 to l2 message to be consumed from the contract |
| 39 | + const [secret, secretHash] = await generateClaimSecret(); |
| 40 | + const message = { recipient: testContract.address, content: Fr.random(), secretHash }; |
| 41 | + logger.warn(`Sending L1 to L2 message ${message.content.toString()} to be consumed by ${testContract.address}`); |
| 42 | + const { msgHash, globalLeafIndex } = await sendL1ToL2Message(message, context.deployL1ContractsValues); |
| 43 | + |
| 44 | + logger.warn(`Waiting for message ${msgHash} with index ${globalLeafIndex} to be synced`); |
| 45 | + await retryUntil( |
| 46 | + () => context.aztecNode.isL1ToL2MessageSynced(msgHash), |
| 47 | + 'message sync', |
| 48 | + test.L2_SLOT_DURATION_IN_S * 4, |
| 49 | + ); |
| 50 | + |
| 51 | + // And we consume the message using the test contract. It's important that we don't wait for the membership witness |
| 52 | + // to be available, since we want to test the scenario where the message becomes available on the same block the tx lands. |
| 53 | + logger.warn(`Consuming message ${message.content.toString()} from the contract at ${testContract.address}`); |
| 54 | + const txReceipt = await testContract.methods |
| 55 | + .consume_message_from_arbitrary_sender_public( |
| 56 | + message.content, |
| 57 | + secret, |
| 58 | + EthAddress.fromString(context.deployL1ContractsValues.l1Client.account.address), |
| 59 | + globalLeafIndex.toBigInt(), |
| 60 | + ) |
| 61 | + .send({ from: context.accounts[0] }) |
| 62 | + .wait(); |
| 63 | + expect(txReceipt.blockNumber).toBeGreaterThan(0); |
| 64 | + |
| 65 | + // Wait until a proof lands for the transaction |
| 66 | + logger.warn(`Waiting for proof for tx ${txReceipt.txHash} mined at ${txReceipt.blockNumber!}`); |
| 67 | + await retryUntil( |
| 68 | + async () => { |
| 69 | + const provenBlockNumber = await context.aztecNode.getProvenBlockNumber(); |
| 70 | + logger.info(`Proven block number is ${provenBlockNumber}`); |
| 71 | + return provenBlockNumber >= txReceipt.blockNumber!; |
| 72 | + }, |
| 73 | + 'Proof has been submitted', |
| 74 | + test.L2_SLOT_DURATION_IN_S * test.epochDuration * 3, |
| 75 | + ); |
| 76 | + |
| 77 | + const provenBlockNumber = await context.aztecNode.getProvenBlockNumber(); |
| 78 | + expect(provenBlockNumber).toBeGreaterThanOrEqual(txReceipt.blockNumber!); |
| 79 | + |
| 80 | + logger.info(`Test succeeded`); |
| 81 | + }); |
| 82 | +}); |
0 commit comments