Skip to content

Commit

Permalink
Make withdraw method behaviour compatible with Starkgate
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejka committed May 24, 2023
1 parent 0ea654a commit e288c1c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 44 deletions.
3 changes: 2 additions & 1 deletion contracts/l1/L1DAIBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,14 @@ contract L1DAIBridge {
return (low, high);
}


// slither-disable-next-line similar-names
function withdraw(uint256 amount, address l1Recipient) external {
emit LogWithdrawal(l1Recipient, amount);

uint256[] memory payload = new uint256[](4);
payload[0] = HANDLE_WITHDRAW;
payload[1] = uint256(uint160(msg.sender));
payload[1] = uint256(uint160(l1Recipient));
(payload[2], payload[3]) = toSplitUint(amount);

StarkNetLike(starkNet).consumeMessageFromL2(l2DaiBridge, payload);
Expand Down
47 changes: 4 additions & 43 deletions test/l1/l1DAIBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ describe("l1:L1DAIBridge", function () {
expect(await dai.balanceOf(escrow.address)).to.be.eq(0);
});
});
describe("withdraw", function () {
describe.only("withdraw", function () {
it("sends funds from the escrow", async () => {
const {
admin,
Expand Down Expand Up @@ -351,10 +351,10 @@ describe("l1:L1DAIBridge", function () {
expect(await dai.balanceOf(l1Bridge.address)).to.be.eq(0);
expect(await dai.balanceOf(escrow.address)).to.be.eq(withdrawalAmount);

await l1Bridge.connect(l1Alice).withdraw(withdrawalAmount, l1Bob.address);
await l1Bridge.connect(l1Bob).withdraw(withdrawalAmount, l1Alice.address);

expect(await dai.balanceOf(l1Alice.address)).to.be.eq(0);
expect(await dai.balanceOf(l1Bob.address)).to.be.eq(withdrawalAmount);
expect(await dai.balanceOf(l1Alice.address)).to.be.eq(withdrawalAmount);
expect(await dai.balanceOf(l1Bob.address)).to.be.eq(0);
expect(await dai.balanceOf(l1Bridge.address)).to.be.eq(0);
expect(await dai.balanceOf(escrow.address)).to.be.eq(0);

Expand Down Expand Up @@ -400,45 +400,6 @@ describe("l1:L1DAIBridge", function () {
[WITHDRAW, l1Alice.address, ...split(withdrawalAmount)]
);
});
it("reverts when called by not a withdrawal recipient", async () => {
const {
admin,
l1Alice,
l1Bob,
dai,
starkNetFake,
escrow,
l1Bridge,
l2BridgeAddress,
} = await setupTest();

const withdrawalAmount = eth("333");

await escrow.approve(dai.address, l1Bridge.address, MAX_UINT256);

await dai.connect(admin).transfer(escrow.address, withdrawalAmount);

expect(await dai.balanceOf(l1Alice.address)).to.be.eq(0);
expect(await dai.balanceOf(l1Bridge.address)).to.be.eq(0);
expect(await dai.balanceOf(escrow.address)).to.be.eq(withdrawalAmount);

starkNetFake.consumeMessageFromL2
.whenCalledWith(l2BridgeAddress, [
WITHDRAW,
l1Bob.address,
...split(withdrawalAmount),
])
.reverts();

await expect(
l1Bridge.connect(l1Bob).withdraw(withdrawalAmount, l1Alice.address)
).to.be.reverted;

expect(starkNetFake.consumeMessageFromL2).to.have.been.calledWith(
l2BridgeAddress,
[WITHDRAW, l1Bob.address, ...split(withdrawalAmount)]
);
});
it("reverts when called with wrong amount", async () => {
const {
admin,
Expand Down

0 comments on commit e288c1c

Please sign in to comment.