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

feat: combine contracts for l1 -> l2 and l2 -> l1 #726

Merged
merged 7 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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: 4 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ jobs:
name: "Test"
command: cond_spot_run_tests end-to-end e2e_nested_contract.test.ts

e2e-l1-to-l2-messaging:
e2e-cross-chain-messaging:
docker:
- image: aztecprotocol/alpine-build-image
resource_class: small
Expand All @@ -438,18 +438,7 @@ jobs:
- *setup_env
- run:
name: "Test"
command: cond_spot_run_tests end-to-end e2e_l1_to_l2_msg.test.ts

e2e-l2-to-l1-messaging:
docker:
- image: aztecprotocol/alpine-build-image
resource_class: small
steps:
- *checkout
- *setup_env
- run:
name: "Test"
command: cond_spot_run_tests end-to-end e2e_rollup_native_asset_contract.test.ts
command: cond_spot_run_tests end-to-end e2e_cross_chain_messaging.test.ts

integration-l1-publisher:
docker:
Expand Down Expand Up @@ -611,8 +600,7 @@ workflows:
- e2e-block-building: *e2e_test
- e2e-nested-contract: *e2e_test
- e2e-public-token-contract: *e2e_test
- e2e-l2-to-l1-messaging: *e2e_test
- e2e-l1-to-l2-messaging: *e2e_test
- e2e-cross-chain-messaging: *e2e_test
- integration-l1-publisher: *e2e_test
- e2e-p2p: *e2e_test

Expand All @@ -623,8 +611,7 @@ workflows:
- e2e-block-building
- e2e-nested-contract
- e2e-public-token-contract
- e2e-l2-to-l1-messaging
- e2e-l1-to-l2-messaging
- e2e-cross-chain-messaging
- integration-l1-publisher
- e2e-p2p
<<: *defaults
77 changes: 0 additions & 77 deletions l1-contracts/test/portals/RNA.t.sol

This file was deleted.

37 changes: 0 additions & 37 deletions l1-contracts/test/portals/RollupNativeAsset.sol

This file was deleted.

17 changes: 17 additions & 0 deletions l1-contracts/test/portals/TokenPortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,21 @@ contract TokenPortal {
// Send message to rollup
return inbox.sendL2Message{value: msg.value}(actor, _deadline, contentHash, _secretHash);
}

function withdraw(uint256 _amount, address _recipient) external returns (bytes32) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we doing natspec stuff for this too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would probably be useful, but have not as strict when it was just a test contract and not a core

DataStructures.L2ToL1Msg memory message = DataStructures.L2ToL1Msg({
sender: DataStructures.L2Actor(l2TokenAddress, 1),
recipient: DataStructures.L1Actor(address(this), block.chainid),
content: Hash.sha256ToField(
abi.encodeWithSignature("withdraw(uint256,address)", _amount, _recipient)
)
});

// @todo: (issue #624) handle different versions
bytes32 entryKey = registry.getOutbox().consume(message);

underlying.transfer(_recipient, _amount);

return entryKey;
}
}
34 changes: 34 additions & 0 deletions l1-contracts/test/portals/TokenPortal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {Registry} from "@aztec/core/messagebridge/Registry.sol";
import {Outbox} from "@aztec/core/messagebridge/Outbox.sol";
import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
import {Hash} from "@aztec/core/libraries/Hash.sol";
import {Errors} from "@aztec/core/libraries/Errors.sol";

// Interfaces
import {IRegistry} from "@aztec/core/interfaces/messagebridge/IRegistry.sol";
Expand All @@ -30,6 +31,7 @@ contract TokenPortalTest is Test {
bytes32 content,
bytes32 secretHash
);
event MessageConsumed(bytes32 indexed entryKey, address indexed recipient);

Registry internal registry;
Inbox internal inbox;
Expand Down Expand Up @@ -103,4 +105,36 @@ contract TokenPortalTest is Test {
DataStructures.Entry memory entry = inbox.get(entryKey);
assertEq(entry.count, 1);
}

function testWithdraw() public {
uint256 withdrawAmount = 654;
portalERC20.mint(address(tokenPortal), withdrawAmount);
address _recipient = address(0xdead);
bytes32[] memory entryKeys = new bytes32[](1);
entryKeys[0] = outbox.computeEntryKey(
DataStructures.L2ToL1Msg({
sender: DataStructures.L2Actor({actor: l2TokenAddress, version: 1}),
recipient: DataStructures.L1Actor({actor: address(tokenPortal), chainId: block.chainid}),
content: Hash.sha256ToField(
abi.encodeWithSignature("withdraw(uint256,address)", withdrawAmount, _recipient)
)
})
);

// Insert messages into the outbox (impersonating the rollup contract)
vm.prank(address(rollup));
outbox.sendL1Messages(entryKeys);

assertEq(portalERC20.balanceOf(_recipient), 0);

vm.expectEmit(true, true, true, true);
emit MessageConsumed(entryKeys[0], address(tokenPortal));
bytes32 entryKey = tokenPortal.withdraw(withdrawAmount, _recipient);
// Should have received 654 RNA tokens
assertEq(portalERC20.balanceOf(_recipient), withdrawAmount);

// Should not be able to withdraw again
vm.expectRevert(abi.encodeWithSelector(Errors.Outbox__NothingToConsume.selector, entryKey));
tokenPortal.withdraw(withdrawAmount, _recipient);
}
}
Loading