Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved test coverage #2

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/DefaultInflationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ contract DefaultInflationManager is Initializable, Ownable2StepUpgradeable, IMin
uint256 public treasuryMintPerSecond;
uint256 public lastMint;

constructor() initializer {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes sense to increase deployment costs for the purposes of coverage. Also, won't this mean that we cannot call initialize() after this?

Copy link
Contributor Author

@dev1644 dev1644 Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added constructor here so that we don't need to send another transaction to initialize the implementation contract.

won't this mean that we cannot call initialize() after this?

Aren't we using Proxy to interact with DefualtInflationManager? In that case using constructor here is better because proxy's can be initialized when we will deploy it (Proxy).


function initialize(IPolygon token_, address hub_, address treasury_, address owner_) external initializer {
token = token_;
hub = hub_;
Expand Down
5 changes: 1 addition & 4 deletions src/Polygon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import {IPolygon} from "./interfaces/IPolygon.sol";
contract Polygon is ERC20Permit, IPolygon {
address public immutable inflationManager;

constructor(address migration_, address inflationManager_)
ERC20("Polygon", "POL")
ERC20Permit("Polygon")
{
constructor(address migration_, address inflationManager_) ERC20("Polygon", "POL") ERC20Permit("Polygon") {
inflationManager = inflationManager_;
_mint(migration_, 10_000_000_000e18);
}
Expand Down
11 changes: 11 additions & 0 deletions test/DefaultInflationManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ contract DefaultInflationManagerTest is Test {
inflationManager.initialize(IPolygon(address(polygon)), hub, treasury, governance);
}

function test_Initialize_InflationManagerImpl() external {
DefaultInflationManager inflationManagerImpl = new DefaultInflationManager();

// setting DefaultInflationManager._initialized to 0
vm.store(address(inflationManagerImpl), bytes32(uint256(0)), bytes32(uint256(0)));
inflationManagerImpl.initialize(IPolygon(address(polygon)), hub, treasury, governance);

vm.expectRevert("Initializable: contract is already initialized");
inflationManagerImpl.initialize(IPolygon(address(0)), address(0), address(0), address(0));
}

function testRevert_Initialize() external {
vm.expectRevert("Initializable: contract is already initialized");
inflationManager.initialize(IPolygon(address(0)), address(0), address(0), address(0));
Expand Down
18 changes: 18 additions & 0 deletions test/PolygonMigration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ contract PolygonMigrationTest is Test {
assertEq(matic.balanceOf(user), amount2);
}

function testRevert_Unmigrate(address user, uint256 amount, uint256 unmigrationLock) external {
vm.assume(amount <= 10000000000 * 10 ** 18 && user != address(0) && unmigrationLock != 0);
matic.mint(user, amount);
vm.startPrank(user);
matic.approve(address(migration), amount);
migration.migrate(amount);

assertEq(matic.balanceOf(user), 0);
assertEq(matic.balanceOf(address(migration)), amount);
assertEq(polygon.balanceOf(user), amount);
vm.startPrank(governance);
migration.updateUnmigrationLock(unmigrationLock);

vm.startPrank(user);
vm.expectRevert("PolygonMigration: unmigration is locked");
migration.unmigrate(amount);
}

function testRevert_UpdateReleaseTimestampOnlyGovernance(address user, uint256 timestamp) external {
vm.assume(timestamp >= block.timestamp && user != governance);
vm.expectRevert("Ownable: caller is not the owner");
Expand Down