-
Notifications
You must be signed in to change notification settings - Fork 54
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
25 changed files
with
1,911 additions
and
4 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
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
26 changes: 26 additions & 0 deletions
26
...racts/src/v0.8/ccip/test/tokenAdminRegistry/FactoryBurnMintERC20/BurnMintERC20Setup.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import {FactoryBurnMintERC20} from "../../../tokenAdminRegistry/TokenPoolFactory/FactoryBurnMintERC20.sol"; | ||
import {BaseTest} from "../../BaseTest.t.sol"; | ||
|
||
contract BurnMintERC20Setup is BaseTest { | ||
FactoryBurnMintERC20 internal s_burnMintERC20; | ||
|
||
address internal s_mockPool = makeAddr("s_mockPool"); | ||
uint256 internal s_amount = 1e18; | ||
|
||
address internal s_alice; | ||
|
||
function setUp() public virtual override { | ||
BaseTest.setUp(); | ||
|
||
s_alice = makeAddr("alice"); | ||
|
||
s_burnMintERC20 = new FactoryBurnMintERC20("Chainlink Token", "LINK", 18, 1e27, 0, s_alice); | ||
|
||
// Set s_mockPool to be a burner and minter | ||
s_burnMintERC20.grantMintAndBurnRoles(s_mockPool); | ||
deal(address(s_burnMintERC20), OWNER, s_amount); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...v0.8/ccip/test/tokenAdminRegistry/FactoryBurnMintERC20/FactoryBurnMintERC20.approve.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import {BurnMintERC20Setup} from "./BurnMintERC20Setup.t.sol"; | ||
|
||
contract FactoryBurnMintERC20_approve is BurnMintERC20Setup { | ||
function test_Approve_Success() public { | ||
uint256 balancePre = s_burnMintERC20.balanceOf(STRANGER); | ||
uint256 sendingAmount = s_amount / 2; | ||
|
||
s_burnMintERC20.approve(STRANGER, sendingAmount); | ||
|
||
changePrank(STRANGER); | ||
|
||
s_burnMintERC20.transferFrom(OWNER, STRANGER, sendingAmount); | ||
|
||
assertEq(sendingAmount + balancePre, s_burnMintERC20.balanceOf(STRANGER)); | ||
} | ||
|
||
// Reverts | ||
|
||
function test_InvalidAddress_Reverts() public { | ||
vm.expectRevert(); | ||
|
||
s_burnMintERC20.approve(address(s_burnMintERC20), s_amount); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...rc/v0.8/ccip/test/tokenAdminRegistry/FactoryBurnMintERC20/FactoryBurnMintERC20.burn.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import {IERC20} from "../../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol"; | ||
import {FactoryBurnMintERC20} from "../../../tokenAdminRegistry/TokenPoolFactory/FactoryBurnMintERC20.sol"; | ||
import {BurnMintERC20Setup} from "./BurnMintERC20Setup.t.sol"; | ||
|
||
contract FactoryBurnMintERC20_burn is BurnMintERC20Setup { | ||
function test_BasicBurn_Success() public { | ||
s_burnMintERC20.grantBurnRole(OWNER); | ||
deal(address(s_burnMintERC20), OWNER, s_amount); | ||
|
||
vm.expectEmit(); | ||
emit IERC20.Transfer(OWNER, address(0), s_amount); | ||
|
||
s_burnMintERC20.burn(s_amount); | ||
|
||
assertEq(0, s_burnMintERC20.balanceOf(OWNER)); | ||
} | ||
|
||
// Revert | ||
|
||
function test_SenderNotBurner_Reverts() public { | ||
vm.expectRevert(abi.encodeWithSelector(FactoryBurnMintERC20.SenderNotBurner.selector, OWNER)); | ||
|
||
s_burnMintERC20.burnFrom(STRANGER, s_amount); | ||
} | ||
|
||
function test_ExceedsBalance_Reverts() public { | ||
changePrank(s_mockPool); | ||
|
||
vm.expectRevert("ERC20: burn amount exceeds balance"); | ||
|
||
s_burnMintERC20.burn(s_amount * 2); | ||
} | ||
|
||
function test_BurnFromZeroAddress_Reverts() public { | ||
s_burnMintERC20.grantBurnRole(address(0)); | ||
changePrank(address(0)); | ||
|
||
vm.expectRevert("ERC20: burn from the zero address"); | ||
|
||
s_burnMintERC20.burn(0); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...0.8/ccip/test/tokenAdminRegistry/FactoryBurnMintERC20/FactoryBurnMintERC20.burnFrom.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import {FactoryBurnMintERC20} from "../../../tokenAdminRegistry/TokenPoolFactory/FactoryBurnMintERC20.sol"; | ||
import {BurnMintERC20Setup} from "./BurnMintERC20Setup.t.sol"; | ||
|
||
contract FactoryBurnMintERC20_burnFrom is BurnMintERC20Setup { | ||
function setUp() public virtual override { | ||
BurnMintERC20Setup.setUp(); | ||
} | ||
|
||
function test_BurnFrom_Success() public { | ||
s_burnMintERC20.approve(s_mockPool, s_amount); | ||
|
||
changePrank(s_mockPool); | ||
|
||
s_burnMintERC20.burnFrom(OWNER, s_amount); | ||
|
||
assertEq(0, s_burnMintERC20.balanceOf(OWNER)); | ||
} | ||
|
||
// Reverts | ||
|
||
function test_SenderNotBurner_Reverts() public { | ||
vm.expectRevert(abi.encodeWithSelector(FactoryBurnMintERC20.SenderNotBurner.selector, OWNER)); | ||
|
||
s_burnMintERC20.burnFrom(OWNER, s_amount); | ||
} | ||
|
||
function test_InsufficientAllowance_Reverts() public { | ||
changePrank(s_mockPool); | ||
|
||
vm.expectRevert("ERC20: insufficient allowance"); | ||
|
||
s_burnMintERC20.burnFrom(OWNER, s_amount); | ||
} | ||
|
||
function test_ExceedsBalance_Reverts() public { | ||
s_burnMintERC20.approve(s_mockPool, s_amount * 2); | ||
|
||
changePrank(s_mockPool); | ||
|
||
vm.expectRevert("ERC20: burn amount exceeds balance"); | ||
|
||
s_burnMintERC20.burnFrom(OWNER, s_amount * 2); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...cip/test/tokenAdminRegistry/FactoryBurnMintERC20/FactoryBurnMintERC20.burnFromAlias.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import {FactoryBurnMintERC20} from "../../../tokenAdminRegistry/TokenPoolFactory/FactoryBurnMintERC20.sol"; | ||
import {BurnMintERC20Setup} from "./BurnMintERC20Setup.t.sol"; | ||
|
||
contract FactoryBurnMintERC20_burnFromAlias is BurnMintERC20Setup { | ||
function setUp() public virtual override { | ||
BurnMintERC20Setup.setUp(); | ||
} | ||
|
||
function test_BurnFrom_Success() public { | ||
s_burnMintERC20.approve(s_mockPool, s_amount); | ||
|
||
changePrank(s_mockPool); | ||
|
||
s_burnMintERC20.burn(OWNER, s_amount); | ||
|
||
assertEq(0, s_burnMintERC20.balanceOf(OWNER)); | ||
} | ||
|
||
// Reverts | ||
|
||
function test_SenderNotBurner_Reverts() public { | ||
vm.expectRevert(abi.encodeWithSelector(FactoryBurnMintERC20.SenderNotBurner.selector, OWNER)); | ||
|
||
s_burnMintERC20.burn(OWNER, s_amount); | ||
} | ||
|
||
function test_InsufficientAllowance_Reverts() public { | ||
changePrank(s_mockPool); | ||
|
||
vm.expectRevert("ERC20: insufficient allowance"); | ||
|
||
s_burnMintERC20.burn(OWNER, s_amount); | ||
} | ||
|
||
function test_ExceedsBalance_Reverts() public { | ||
s_burnMintERC20.approve(s_mockPool, s_amount * 2); | ||
|
||
changePrank(s_mockPool); | ||
|
||
vm.expectRevert("ERC20: burn amount exceeds balance"); | ||
|
||
s_burnMintERC20.burn(OWNER, s_amount * 2); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
.../ccip/test/tokenAdminRegistry/FactoryBurnMintERC20/FactoryBurnMintERC20.constructor.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import {FactoryBurnMintERC20} from "../../../tokenAdminRegistry/TokenPoolFactory/FactoryBurnMintERC20.sol"; | ||
import {BurnMintERC20Setup} from "./BurnMintERC20Setup.t.sol"; | ||
|
||
contract FactoryBurnMintERC20_constructor is BurnMintERC20Setup { | ||
function test_Constructor_Success() public { | ||
string memory name = "Chainlink token v2"; | ||
string memory symbol = "LINK2"; | ||
uint8 decimals = 19; | ||
uint256 maxSupply = 1e33; | ||
|
||
s_burnMintERC20 = new FactoryBurnMintERC20(name, symbol, decimals, maxSupply, 1e18, s_alice); | ||
|
||
assertEq(name, s_burnMintERC20.name()); | ||
assertEq(symbol, s_burnMintERC20.symbol()); | ||
assertEq(decimals, s_burnMintERC20.decimals()); | ||
assertEq(maxSupply, s_burnMintERC20.maxSupply()); | ||
|
||
assertTrue(s_burnMintERC20.isMinter(s_alice)); | ||
assertTrue(s_burnMintERC20.isBurner(s_alice)); | ||
assertEq(s_burnMintERC20.balanceOf(s_alice), 1e18); | ||
assertEq(s_burnMintERC20.totalSupply(), 1e18); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
.../test/tokenAdminRegistry/FactoryBurnMintERC20/FactoryBurnMintERC20.decreaseApproval.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import {BurnMintERC20Setup} from "./BurnMintERC20Setup.t.sol"; | ||
|
||
contract FactoryBurnMintERC20_decreaseApproval is BurnMintERC20Setup { | ||
function test_DecreaseApproval_Success() public { | ||
s_burnMintERC20.approve(s_mockPool, s_amount); | ||
uint256 allowance = s_burnMintERC20.allowance(OWNER, s_mockPool); | ||
assertEq(allowance, s_amount); | ||
s_burnMintERC20.decreaseApproval(s_mockPool, s_amount); | ||
assertEq(s_burnMintERC20.allowance(OWNER, s_mockPool), allowance - s_amount); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...ccip/test/tokenAdminRegistry/FactoryBurnMintERC20/FactoryBurnMintERC20.getCCIPAdmin.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import {FactoryBurnMintERC20} from "../../../tokenAdminRegistry/TokenPoolFactory/FactoryBurnMintERC20.sol"; | ||
import {BurnMintERC20Setup} from "./BurnMintERC20Setup.t.sol"; | ||
|
||
contract FactoryBurnMintERC20_getCCIPAdmin is BurnMintERC20Setup { | ||
function test_getCCIPAdmin_Success() public view { | ||
assertEq(s_alice, s_burnMintERC20.getCCIPAdmin()); | ||
} | ||
|
||
function test_setCCIPAdmin_Success() public { | ||
address newAdmin = makeAddr("newAdmin"); | ||
|
||
vm.expectEmit(); | ||
emit FactoryBurnMintERC20.CCIPAdminTransferred(s_alice, newAdmin); | ||
|
||
s_burnMintERC20.setCCIPAdmin(newAdmin); | ||
|
||
assertEq(newAdmin, s_burnMintERC20.getCCIPAdmin()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
.../tokenAdminRegistry/FactoryBurnMintERC20/FactoryBurnMintERC20.grantMintAndBurnRoles.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import {FactoryBurnMintERC20} from "../../../tokenAdminRegistry/TokenPoolFactory/FactoryBurnMintERC20.sol"; | ||
import {BurnMintERC20Setup} from "./BurnMintERC20Setup.t.sol"; | ||
|
||
contract FactoryBurnMintERC20_grantMintAndBurnRoles is BurnMintERC20Setup { | ||
function test_GrantMintAndBurnRoles_Success() public { | ||
assertFalse(s_burnMintERC20.isMinter(STRANGER)); | ||
assertFalse(s_burnMintERC20.isBurner(STRANGER)); | ||
|
||
vm.expectEmit(); | ||
emit FactoryBurnMintERC20.MintAccessGranted(STRANGER); | ||
vm.expectEmit(); | ||
emit FactoryBurnMintERC20.BurnAccessGranted(STRANGER); | ||
|
||
s_burnMintERC20.grantMintAndBurnRoles(STRANGER); | ||
|
||
assertTrue(s_burnMintERC20.isMinter(STRANGER)); | ||
assertTrue(s_burnMintERC20.isBurner(STRANGER)); | ||
} | ||
} |
Oops, something went wrong.