This repository has been archived by the owner on Apr 17, 2024. It is now read-only.
-
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.
- Loading branch information
Showing
3 changed files
with
139 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: forge-test | ||
|
||
on: [push] | ||
|
||
env: | ||
FOUNDRY_PROFILE: ci | ||
|
||
jobs: | ||
check: | ||
name: Foundry project | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
|
||
- name: Run Forge tests | ||
env: | ||
FOUNDRY_PROFILE: default | ||
RPC_URL: ${{ secrets.BASE_RPC_URL }} | ||
run: | | ||
forge test -vvv --fuzz-runs 1000 --rpc-url "$RPC_URL" | ||
id: test |
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,30 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol"; | ||
|
||
contract BRRMigrator { | ||
using SafeTransferLib for address; | ||
|
||
// The old BRR token which can be converted 1:1 into the new BRR token. | ||
address private constant _OLD_TOKEN = | ||
0x6d80d90ce251985bF41A98c6FDd6b7b975Fff884; | ||
|
||
/// @notice The new and final BRR token. | ||
address public immutable newToken; | ||
|
||
constructor(address _newToken) { | ||
newToken = _newToken; | ||
} | ||
|
||
/** | ||
* @notice Migrate the old BRR token to the new BRR token. | ||
* @param amount uint256 Token amount. | ||
*/ | ||
function migrate(uint256 amount) external { | ||
// Burn the old token, and transfer the new token to `msg.sender`. | ||
_OLD_TOKEN.safeTransferFrom(msg.sender, address(0xdead), amount); | ||
|
||
newToken.safeTransfer(msg.sender, amount); | ||
} | ||
} |
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,81 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "forge-std/Test.sol"; | ||
import {ERC20} from "solady/tokens/ERC20.sol"; | ||
import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol"; | ||
import {BRR} from "src/BRR.sol"; | ||
import {BRRMigrator} from "src/BRRMigrator.sol"; | ||
|
||
contract BRRMigratorTest is Test { | ||
using SafeTransferLib for address; | ||
|
||
address public constant OLD_TOKEN = | ||
0x6d80d90ce251985bF41A98c6FDd6b7b975Fff884; | ||
uint256 public constant TEST_SUPPLY = 1_000_000e18; | ||
BRR public immutable token = new BRR(address(this)); | ||
BRRMigrator public immutable migrator = new BRRMigrator(address(token)); | ||
|
||
constructor() { | ||
token.mint(address(migrator), TEST_SUPPLY); | ||
|
||
vm.prank(BRR(OLD_TOKEN).owner()); | ||
|
||
BRR(OLD_TOKEN).mint(address(this), TEST_SUPPLY); | ||
address(OLD_TOKEN).safeApprove(address(migrator), type(uint256).max); | ||
} | ||
|
||
function testCannotMigrateTransferFromFailed() external { | ||
uint256 amount = TEST_SUPPLY + 1; | ||
|
||
vm.expectRevert(SafeTransferLib.TransferFromFailed.selector); | ||
|
||
migrator.migrate(amount); | ||
} | ||
|
||
function testMigrateZero() external { | ||
uint256 amount = 0; | ||
uint256 oldTokenBalanceBefore = OLD_TOKEN.balanceOf(address(this)); | ||
uint256 newTokenBalanceBefore = token.balanceOf(address(this)); | ||
|
||
migrator.migrate(amount); | ||
|
||
// Should be unchanged if `amount` is zero. | ||
assertEq(oldTokenBalanceBefore, OLD_TOKEN.balanceOf(address(this))); | ||
assertEq(newTokenBalanceBefore, token.balanceOf(address(this))); | ||
} | ||
|
||
function testMigrate() external { | ||
uint256 amount = 1; | ||
uint256 oldTokenBalanceBefore = OLD_TOKEN.balanceOf(address(this)); | ||
uint256 newTokenBalanceBefore = token.balanceOf(address(this)); | ||
|
||
migrator.migrate(amount); | ||
|
||
assertEq( | ||
oldTokenBalanceBefore - amount, | ||
OLD_TOKEN.balanceOf(address(this)) | ||
); | ||
assertEq( | ||
newTokenBalanceBefore + amount, | ||
token.balanceOf(address(this)) | ||
); | ||
} | ||
|
||
function testMigrateFuzz(uint256 amount) external { | ||
amount = bound(amount, 0, TEST_SUPPLY); | ||
uint256 oldTokenBalanceBefore = OLD_TOKEN.balanceOf(address(this)); | ||
uint256 newTokenBalanceBefore = token.balanceOf(address(this)); | ||
|
||
migrator.migrate(amount); | ||
|
||
assertEq( | ||
oldTokenBalanceBefore - amount, | ||
OLD_TOKEN.balanceOf(address(this)) | ||
); | ||
assertEq( | ||
newTokenBalanceBefore + amount, | ||
token.balanceOf(address(this)) | ||
); | ||
} | ||
} |