-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The test directory has been restructured for easier discovery of different tests based on types. Minor gas optimisations have been made in the `L2Comptroller` contract.
- Loading branch information
1 parent
3658c27
commit 5112711
Showing
26 changed files
with
951 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule foundry-upgrades
deleted from
e736e4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
ds-test/=lib/forge-std/lib/ds-test/src/ | ||
forge-std/=lib/forge-std/src/ | ||
foundry-upgrades/=lib/foundry-upgrades/src/ | ||
openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/ | ||
openzeppelin-contracts/=lib/openzeppelin-contracts/ | ||
openzeppelin/=lib/foundry-upgrades/lib/openzeppelin-contracts/contracts/ | ||
solmate/=lib/foundry-upgrades/lib/solmate/src/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.18; | ||
|
||
import {Setup} from "../../helpers/Setup.sol"; | ||
import {SafeERC20Upgradeable} from "openzeppelin-contracts-upgradeable/contracts/token/ERC20/utils/SafeERC20Upgradeable.sol"; | ||
import {IERC20Upgradeable} from "openzeppelin-contracts-upgradeable/contracts/interfaces/IERC20Upgradeable.sol"; | ||
import {L1Comptroller} from "../../../src/L1Comptroller.sol"; | ||
import "forge-std/Test.sol"; | ||
import "forge-std/console.sol"; | ||
|
||
contract BuyBackFuzz is Setup { | ||
using SafeERC20Upgradeable for IERC20Upgradeable; | ||
using stdStorage for StdStorage; | ||
|
||
function setUp() public override { | ||
super.setUp(); | ||
vm.selectFork(l1ForkId); | ||
} | ||
|
||
function testFuzz_ShouldBurnCorrectAmountOfTokens_WhenReceiverIsSender(uint256 tokenToBurnAmount) public { | ||
uint256 tokenSupplyBefore = tokenToBurnL1.totalSupply(); | ||
|
||
// Make sure the fuzzer gives amount less than the token supply. | ||
tokenToBurnAmount = bound(tokenToBurnAmount, 1, tokenSupplyBefore); | ||
|
||
deal(address(tokenToBurnL1), alice, tokenToBurnAmount); | ||
|
||
uint256 aliceBalanceBefore = tokenToBurnL1.balanceOf(alice); | ||
|
||
vm.startPrank(alice); | ||
|
||
// Approve the MTA tokens to the L1Comptroller for burn. | ||
IERC20Upgradeable(tokenToBurnL1).safeIncreaseAllowance( | ||
address(L1ComptrollerProxy), | ||
tokenToBurnAmount | ||
); | ||
|
||
// Expecting a call to be made to the Optimism's cross domain messenger contract on L1 | ||
// with the relevant data. | ||
vm.expectCall( | ||
address(L1DomainMessenger), | ||
abi.encodeCall( | ||
L1DomainMessenger.sendMessage, | ||
( | ||
address(L2ComptrollerProxy), | ||
abi.encodeWithSignature( | ||
"buyBackFromL1(address,address,uint256)", | ||
alice, | ||
alice, | ||
tokenToBurnAmount | ||
), | ||
1_920_000 | ||
) | ||
) | ||
); | ||
|
||
L1ComptrollerProxy.buyBack(alice, tokenToBurnAmount); | ||
|
||
assertEq( | ||
tokenToBurnL1.balanceOf(alice), | ||
aliceBalanceBefore - tokenToBurnAmount, | ||
"Wrong Alice's balance after burn" | ||
); | ||
assertEq( | ||
tokenToBurnL1.totalSupply(), | ||
tokenSupplyBefore - tokenToBurnAmount, | ||
"Wrong total supply" | ||
); | ||
assertEq( | ||
L1ComptrollerProxy.burntAmountOf(alice), | ||
tokenToBurnAmount, | ||
"Burnt amount not updated" | ||
); | ||
} | ||
|
||
function testFuzz_ShouldBurnCorrectAmountOfTokens_WhenReceiverIsNotSender(uint256 tokenToBurnAmount) public { | ||
uint256 tokenSupplyBefore = tokenToBurnL1.totalSupply(); | ||
|
||
// Make sure the fuzzer gives amount less than the token supply. | ||
tokenToBurnAmount = bound(tokenToBurnAmount, 1, tokenSupplyBefore); | ||
|
||
deal(address(tokenToBurnL1), alice, tokenToBurnAmount); | ||
|
||
uint256 aliceBalanceBefore = tokenToBurnL1.balanceOf(alice); | ||
address dummyReceiver = makeAddr("dummyReceiver"); | ||
|
||
vm.startPrank(alice); | ||
|
||
// Approve the MTA tokens to the L1Comptroller for burn. | ||
IERC20Upgradeable(tokenToBurnL1).safeIncreaseAllowance( | ||
address(L1ComptrollerProxy), | ||
tokenToBurnAmount | ||
); | ||
|
||
// Expecting a call to be made to the Optimism's cross domain messenger contract on L1 | ||
// with the relevant data. | ||
vm.expectCall( | ||
address(L1DomainMessenger), | ||
abi.encodeCall( | ||
L1DomainMessenger.sendMessage, | ||
( | ||
address(L2ComptrollerProxy), | ||
abi.encodeWithSignature( | ||
"buyBackFromL1(address,address,uint256)", | ||
alice, | ||
dummyReceiver, | ||
tokenToBurnAmount | ||
), | ||
1_920_000 | ||
) | ||
) | ||
); | ||
|
||
L1ComptrollerProxy.buyBack(dummyReceiver, tokenToBurnAmount); | ||
|
||
assertEq( | ||
tokenToBurnL1.balanceOf(alice), | ||
aliceBalanceBefore - tokenToBurnAmount, | ||
"Wrong Alice's balance after burn" | ||
); | ||
assertEq( | ||
tokenToBurnL1.totalSupply(), | ||
tokenSupplyBefore - tokenToBurnAmount, | ||
"Wrong total supply" | ||
); | ||
assertEq( | ||
L1ComptrollerProxy.burntAmountOf(alice), | ||
tokenToBurnAmount, | ||
"Burnt amount not updated" | ||
); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
test/L1Comptroller/BuyBack.t.sol → ...mptroller/integration-tests/BuyBack.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/L1Comptroller/EmergencyWithdraw.t.sol → ...integration-tests/EmergencyWithdraw.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/L1Comptroller/Pausable.t.sol → ...ptroller/integration-tests/Pausable.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...L1Comptroller/SetCrossChainGasLimit.t.sol → ...gration-tests/SetCrossChainGasLimit.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/L1Comptroller/SetL2Comptroller.t.sol → .../integration-tests/SetL2Comptroller.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.