Skip to content

Commit

Permalink
[NO-JIRA] fix erc20 burn (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonzwli authored Apr 12, 2024
1 parent 27d6570 commit 2c1c4a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 2 additions & 3 deletions contracts/token/erc20/preset/ImmutableERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ contract ImmutableERC20 is Ownable, ERC20Permit, MintingAccessControl {

/**
* @dev Burns `amount` number of tokens from the `from` address.
* @param from the address to burn the tokens from.
* @param amount the amount of tokens to burn.
*/
function burn(address from, uint256 amount) external {
_burn(from, amount);
function burn(uint256 amount) external {
_burn(msg.sender, amount);
}

/**
Expand Down
12 changes: 7 additions & 5 deletions test/token/erc20/preset/ImmutableERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ contract ImmutableERC20Test is Test {

address public minter;
address public hubOwner;
address public tokenReceiver;
string name;
string symbol;
uint256 maxSupply;

function setUp() public virtual {
hubOwner = makeAddr("hubOwner");
minter = makeAddr("minterRole");
tokenReceiver = makeAddr("tokenReceiver");
name = "HappyToken";
symbol = "HPY";
maxSupply = 1000;
Expand Down Expand Up @@ -68,13 +70,13 @@ contract ImmutableERC20Test is Test {
}

function testBurn() public {
address from = makeAddr("from");
uint256 amount = 100;
vm.prank(minter);
erc20.mint(from, amount);
assertEq(erc20.balanceOf(from), 100);
erc20.burn(from, amount);
assertEq(erc20.balanceOf(from), 0);
erc20.mint(tokenReceiver, amount);
assertEq(erc20.balanceOf(tokenReceiver), 100);
vm.prank(tokenReceiver);
erc20.burn(amount);
assertEq(erc20.balanceOf(tokenReceiver), 0);
}

function testCanOnlyMintUpToMaxSupply() public {
Expand Down

0 comments on commit 2c1c4a9

Please sign in to comment.