-
Notifications
You must be signed in to change notification settings - Fork 607
feat: Milestone 2.1 l1 -> l2 messaging #703
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
Changes from all commits
5987879
8243fcf
3c2effa
0d704b2
422045c
009c17b
c9afe61
39e9dfe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ const logger = createDebugLogger('aztec:e2e_l1_to_l2_msg'); | |
| const config = getConfigEnvVars(); | ||
|
|
||
| // NOTE: this tests is just a scaffold, it is awaiting functionality to come from the aztec-node around indexing messages in the contract | ||
| describe.skip('e2e_l1_to_l2_msg', () => { | ||
| describe('e2e_l1_to_l2_msg', () => { | ||
| let node: AztecNodeService; | ||
| let aztecRpcServer: AztecRPCServer; | ||
| let accounts: AztecAddress[]; | ||
|
|
@@ -62,6 +62,7 @@ describe.skip('e2e_l1_to_l2_msg', () => { | |
| config.publisherPrivateKey = Buffer.from(privKey!); | ||
| config.rollupContract = rollupAddress; | ||
| config.inboxContract = inboxAddress; | ||
| config.archiverPollingInterval = 1000; | ||
| config.unverifiedDataEmitterContract = unverifiedDataEmitterAddress; | ||
|
|
||
| // Deploy portal contracts | ||
|
|
@@ -109,11 +110,9 @@ describe.skip('e2e_l1_to_l2_msg', () => { | |
| const deployContract = async (initialBalance = 0n, owner = { x: 0n, y: 0n }) => { | ||
| logger(`Deploying L2 Token contract...`); | ||
| const deployer = new ContractDeployer(NonNativeTokenContractAbi, aztecRpcServer); | ||
| const tx = deployer | ||
| .deploy(initialBalance, owner, { | ||
| portalContract: tokenPortalAddress, | ||
| }) | ||
| .send(); | ||
| const tx = deployer.deploy(initialBalance, owner).send({ | ||
| portalContract: tokenPortalAddress, | ||
| }); | ||
| const receipt = await tx.getReceipt(); | ||
| contract = new Contract(receipt.contractAddress!, NonNativeTokenContractAbi, aztecRpcServer); | ||
| await contract.attach(tokenPortalAddress); | ||
|
|
@@ -124,14 +123,14 @@ describe.skip('e2e_l1_to_l2_msg', () => { | |
| return contract; | ||
| }; | ||
|
|
||
| it('Should be able to consume an L1 Message and mint a non native token on L2', async () => { | ||
| const initialBalance = 1n; | ||
| const ownerAddress = accounts[0]; | ||
| const owner = await aztecRpcServer.getAccountPublicKey(ownerAddress); | ||
| const deployedContract = await deployContract(initialBalance, pointToPublicKey(owner)); | ||
| it('Milestone 2.2: L1->L2 Calls', async () => { | ||
| const initialBalance = 10n; | ||
| const [ownerAddress, receiver] = accounts; | ||
| const ownerPub = await aztecRpcServer.getAccountPublicKey(ownerAddress); | ||
| const deployedL2Contract = await deployContract(initialBalance, pointToPublicKey(ownerPub)); | ||
| await expectBalance(accounts[0], initialBalance); | ||
|
|
||
| const l2TokenAddress = deployedContract.address.toString() as `0x${string}`; | ||
| const l2TokenAddress = deployedL2Contract.address.toString() as `0x${string}`; | ||
|
|
||
| logger('Initializing the TokenPortal contract'); | ||
| await tokenPortal.write.initialize( | ||
|
|
@@ -148,8 +147,7 @@ describe.skip('e2e_l1_to_l2_msg', () => { | |
| const claimSecretHash = computeSecretMessageHash(wasm, secret); | ||
| logger('Generated claim secret: ', claimSecretHash); | ||
|
|
||
| // Mint some PortalERCjh20 token on l1 | ||
| logger('Minting tokens on L2'); | ||
| logger('Minting tokens on L1'); | ||
| await underlyingERC20.write.mint([ethAccount.toString(), 1000000n], {} as any); | ||
| await underlyingERC20.write.approve([tokenPortalAddress.toString(), 1000n], {} as any); | ||
|
|
||
|
|
@@ -158,31 +156,44 @@ describe.skip('e2e_l1_to_l2_msg', () => { | |
| const deadline = 2 ** 32 - 1; // max uint32 - 1 | ||
|
|
||
| logger('Sending messages to L1 portal'); | ||
| const returnedMessageKey = await tokenPortal.write.depositToAztec( | ||
| [l2TokenAddress, 100n, deadline, secretString], | ||
| {} as any, | ||
| ); | ||
|
|
||
| const messageKeyFr = Fr.fromBuffer(Buffer.from(returnedMessageKey, 'hex')); | ||
|
|
||
| // Wait for the rollup to process the message | ||
| // TODO: not implemented | ||
|
|
||
| // Force the node to consume the message | ||
| // TODO: not implemented | ||
| const args = [ownerAddress.toString(), 100n, deadline, secretString] as const; | ||
| const { result: messageKeyHex } = await tokenPortal.simulate.depositToAztec(args, { | ||
| account: ethAccount.toString(), | ||
| } as any); | ||
| await tokenPortal.write.depositToAztec(args, {} as any); | ||
| const messageKey = Fr.fromString(messageKeyHex); | ||
|
|
||
| // Wait for the archiver to process the message | ||
| const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); | ||
| await delay(5000); /// waiting 5 seconds. | ||
|
|
||
| // send a transfer tx to force through rollup with the message included | ||
| const transferAmount = 1n; | ||
| const transferTx = contract.methods | ||
| .transfer( | ||
| transferAmount, | ||
| pointToPublicKey(await aztecRpcServer.getAccountPublicKey(ownerAddress)), | ||
| pointToPublicKey(await aztecRpcServer.getAccountPublicKey(receiver)), | ||
| ) | ||
| .send({ from: accounts[0] }); | ||
|
|
||
| await transferTx.isMined(0, 0.1); | ||
| const transferReceipt = await transferTx.getReceipt(); | ||
|
|
||
| expect(transferReceipt.status).toBe(TxStatus.MINED); | ||
|
|
||
| logger('Consuming messages on L2'); | ||
| // Call the mint tokens function on the noir contract | ||
| const mintAmount = 100n; | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question - should we add
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds like a good to have, ill add this. edit: this seems more of a unit test thing rather than integration test thing, ill not do it here |
||
| logger('Consuming messages on L2'); | ||
| const tx = deployedContract.methods | ||
| .mint(mintAmount, pointToPublicKey(owner), messageKeyFr, secret) | ||
| const consumptionTx = deployedL2Contract.methods | ||
| .mint(mintAmount, pointToPublicKey(ownerPub), messageKey, secret) | ||
| .send({ from: ownerAddress }); | ||
|
|
||
| await tx.isMined(0, 0.1); | ||
| const receipt = await tx.getReceipt(); | ||
| await consumptionTx.isMined(0, 0.1); | ||
| const consumptionReceipt = await consumptionTx.getReceipt(); | ||
|
|
||
| expect(receipt.status).toBe(TxStatus.MINED); | ||
| await expectBalance(ownerAddress, mintAmount); | ||
| }); | ||
| expect(consumptionReceipt.status).toBe(TxStatus.MINED); | ||
| await expectBalance(ownerAddress, mintAmount + initialBalance - transferAmount); | ||
| }, 80_000); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,7 +151,7 @@ export function appFactory(node: AztecNode, prefix: string) { | |
| ctx.status = 200; | ||
| }); | ||
|
|
||
| router.get('/l1-l2-message-and-index', async (ctx: Koa.Context) => { | ||
| router.get('/l1-l2-message', async (ctx: Koa.Context) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you have to change the URL in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great catch |
||
| const key = ctx.query.messageKey!; | ||
| const messageAndindex = await node.getL1ToL2MessageAndIndex(Fr.fromString(key as string)); | ||
| ctx.set('content-type', 'application/json'); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah good catch!