Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
soloseng committed May 14, 2024
1 parent 72b1f6e commit 6935a35
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 46 deletions.
22 changes: 6 additions & 16 deletions packages/protocol/contracts/common/GoldToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";

import "./UsingRegistry.sol";
import "./CalledByVm.sol";
import "./Initializable.sol";
import "./interfaces/ICeloToken.sol";
import "./interfaces/ICeloVersionedContract.sol";
import "./interfaces/IMintGoldSchedule.sol";
import "../common/interfaces/ICeloVersionedContract.sol";
import "../../contracts-0.8/common/IsL2Check.sol";

contract GoldToken is
Initializable,
CalledByVm,
UsingRegistry,
IERC20,
ICeloToken,
Expand Down Expand Up @@ -43,18 +45,7 @@ contract GoldToken is

event Approval(address indexed owner, address indexed spender, uint256 value);

event IncreasedTotalSupply(uint256 amount);

event setCeloMintingScheduleAddress(address indexed newAddress);

modifier onlyGovernanceOrVm() {
if (isL1()) {
require(msg.sender == address(0), "Only VM can call");
} else {
require(msg.sender == owner(), "Only owner can call");
}
_;
}
event SetGoldTokenMintingScheduleAddress(address indexed newScheduleAddress);

modifier isRestricted() {
if (isL1()) {
Expand Down Expand Up @@ -96,7 +87,7 @@ contract GoldToken is
);
goldTokenMintingSchedule = IMintGoldSchedule(goldTokenMintingScheduleAddress);

emit setCeloMintingScheduleAddress(goldTokenMintingScheduleAddress);
emit SetGoldTokenMintingScheduleAddress(goldTokenMintingScheduleAddress);
}

/**
Expand Down Expand Up @@ -231,9 +222,8 @@ contract GoldToken is
* @notice Increases the variable for total amount of CELO in existence.
* @param amount The amount to increase counter by
*/
function increaseSupply(uint256 amount) external onlyGovernanceOrVm {
function increaseSupply(uint256 amount) external onlyL1 onlyVm {
totalSupply_ = totalSupply_.add(amount);
emit IncreasedTotalSupply(amount);
}

/**
Expand Down
62 changes: 32 additions & 30 deletions packages/protocol/test-sol/common/GoldToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ contract GoldTokenTest is Test, IsL2Check {
MintGoldSchedule goldTokenMintingSchedule;

uint256 constant ONE_GOLDTOKEN = 1000000000000000000;
uint256 constant TWO_GOLDTOKEN = 2000000000000000000;
uint256 constant THREE_GOLDTOKEN = 3000000000000000000;

address receiver;
address sender;
address goldTokenOwner;

event Transfer(address indexed from, address indexed to, uint256 value);
event TransferComment(string comment);
event SetGoldTokenMintingScheduleAddress(address indexed newScheduleAddress);

modifier _whenL2() {
deployCodeTo("Registry.sol", abi.encode(false), proxyAdminAddress);
Expand All @@ -31,24 +29,14 @@ contract GoldTokenTest is Test, IsL2Check {
vm.prank(goldTokenOwner);
goldToken = new GoldToken(true);
goldTokenMintingSchedule = new MintGoldSchedule(true);

receiver = actor("receiver");
sender = actor("sender");

vm.deal(receiver, ONE_GOLDTOKEN);
vm.deal(sender, ONE_GOLDTOKEN);

if (isL1()) {
vm.prank(address(0));
goldToken.increaseSupply(TWO_GOLDTOKEN);
} else {
vm.prank(goldTokenOwner);
goldToken.increaseSupply(TWO_GOLDTOKEN);
}
}
}

contract GoldTokenTest_General is GoldTokenTest {
contract GoldTokenTest_general is GoldTokenTest {
function setUp() public {
super.setUp();
}
Expand Down Expand Up @@ -205,9 +193,11 @@ contract GoldTokenTest_mint is GoldTokenTest {
}

function test_Should_increaseGoldTokenTotalSupplyWhencalledByVm() public {
uint256 goldTokenSupplyBefore = goldToken.totalSupply();
vm.prank(address(0));
goldToken.mint(receiver, ONE_GOLDTOKEN);
assertEq(goldToken.totalSupply(), THREE_GOLDTOKEN);
uint256 goldTokenSupplyAfter = goldToken.totalSupply();
assertGt(goldTokenSupplyAfter, goldTokenSupplyBefore);
}

function test_Emits_TransferEvent() public {
Expand All @@ -225,30 +215,34 @@ contract GoldTokenTest_mint_l2 is GoldTokenTest {
goldToken.setGoldTokenMintingScheduleAddress(address(goldTokenMintingSchedule));
}

function test_Reverts_whenCalledByOtherThanL2Governance() public {
function test_Reverts_whenCalledByOtherThanOwnerOrMintingSchedule() public {
vm.prank(address(0));

vm.expectRevert("Only owner or goldTokenMintingSchedule can call");
goldToken.mint(receiver, ONE_GOLDTOKEN);
}

function test_Should_increaseGoldTokenTotalSupply() public {
uint256 goldTokenSupplyBefore = goldToken.totalSupply();
vm.prank(goldTokenOwner);
goldToken.mint(receiver, ONE_GOLDTOKEN);
assertEq(goldToken.totalSupply(), THREE_GOLDTOKEN);
uint256 goldTokenSupplyAfter = goldToken.totalSupply();
assertGt(goldTokenSupplyAfter, goldTokenSupplyBefore);
}

function test_Should_increaseGoldTokenBalanceWhenMintedByL2GovernanceOrGoldTokenMintingSchedule()
public
{
assertEq(goldToken.balanceOf(receiver), ONE_GOLDTOKEN);
uint256 originalBalance = goldToken.balanceOf(receiver);
vm.prank(goldTokenOwner);
goldToken.mint(receiver, ONE_GOLDTOKEN);
assertEq(goldToken.balanceOf(receiver), TWO_GOLDTOKEN);
uint256 balanceAfterFirstMint = goldToken.balanceOf(receiver);
assertGt(balanceAfterFirstMint, originalBalance);

vm.prank(address(goldTokenMintingSchedule));
goldToken.mint(receiver, ONE_GOLDTOKEN);
assertEq(goldToken.balanceOf(receiver), THREE_GOLDTOKEN);
uint256 balanceAfterSecondMint = goldToken.balanceOf(receiver);
assertGt(balanceAfterSecondMint, balanceAfterFirstMint);
}

function test_Emits_TransferEvent() public {
Expand Down Expand Up @@ -278,18 +272,24 @@ contract GoldTokenTest_setGoldTokenMintingScheduleAddress is GoldTokenTest {

assertEq(address(goldToken.goldTokenMintingSchedule()), address(goldTokenMintingSchedule));
}
function test_Emits_SetGoldTokenMintingScheduleAddressEvent() public {
vm.expectEmit(true, true, true, true);
emit SetGoldTokenMintingScheduleAddress(address(goldTokenMintingSchedule));
vm.prank(goldTokenOwner);
goldToken.setGoldTokenMintingScheduleAddress(address(goldTokenMintingSchedule));
}
}

contract GoldTokenTest_increaseSupply is GoldTokenTest {
function test_ShouldIncreaseTotalSupply() public {
assertEq(goldToken.totalSupply(), TWO_GOLDTOKEN);
uint256 goldTokenSupplyBefore = goldToken.totalSupply();
vm.prank(address(0));
goldToken.increaseSupply(ONE_GOLDTOKEN);
assertEq(goldToken.totalSupply(), THREE_GOLDTOKEN);
uint256 goldTokenSupplyAfter = goldToken.totalSupply();
assertGt(goldTokenSupplyAfter, goldTokenSupplyBefore);
}

function test_Reverts_WhenCalledByOtherThanVm() public {
assertEq(goldToken.totalSupply(), TWO_GOLDTOKEN);
vm.prank(goldTokenOwner);
vm.expectRevert("Only VM can call");
goldToken.increaseSupply(ONE_GOLDTOKEN);
Expand All @@ -306,21 +306,23 @@ contract GoldTokenTest_increaseSupply_l2 is GoldTokenTest {
goldToken.setGoldTokenMintingScheduleAddress(address(goldTokenMintingSchedule));
}

function test_Reverts_WhenCalledByOtherThanL2Governance() public {
assertEq(goldToken.totalSupply(), TWO_GOLDTOKEN);
function test_Reverts_WhenCalledByAnyone() public {
vm.prank(address(0));
vm.expectRevert("Only owner can call");
vm.expectRevert("This method is no longer supported in L2.");
goldToken.increaseSupply(ONE_GOLDTOKEN);
vm.prank(address(goldTokenMintingSchedule));
vm.expectRevert("Only owner can call");
vm.expectRevert("This method is no longer supported in L2.");
goldToken.increaseSupply(ONE_GOLDTOKEN);
}

function test_ShouldIncreaseTotalSupply() public {
assertEq(goldToken.totalSupply(), TWO_GOLDTOKEN);
function test_ShouldNotIncreaseTotalSupply() public {
uint256 goldTokenSupplyBefore = goldToken.totalSupply();
vm.expectRevert("This method is no longer supported in L2.");
vm.prank(goldTokenOwner);
goldToken.increaseSupply(ONE_GOLDTOKEN);
assertEq(goldToken.totalSupply(), THREE_GOLDTOKEN);

uint256 goldTokenSupplyAfter = goldToken.totalSupply();
assertEq(goldTokenSupplyAfter, goldTokenSupplyBefore);
}
}

Expand Down

0 comments on commit 6935a35

Please sign in to comment.