Skip to content

Commit

Permalink
feat: Add decimal check tests (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Manuel authored Mar 10, 2022
1 parent faf36fe commit 1f058ec
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions contracts/Migrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ pragma solidity 0.8.7;

import { ERC20Helper } from "../modules/erc20-helper/src/ERC20Helper.sol";

import { IERC20Like } from "./interfaces/Interfaces.sol";

contract Migrator {

address public immutable oldToken;
address public immutable newToken;

constructor(address oldToken_, address newToken_) {
require(IERC20Like(newToken_).decimals() == IERC20Like(oldToken_).decimals(), "M:C:DECIMAL_MISMATCH");

oldToken = oldToken_;
newToken = newToken_;
}
Expand Down
8 changes: 8 additions & 0 deletions contracts/interfaces/Interfaces.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.8.7;

interface IERC20Like {

function decimals() external view returns (uint8 decimals_);

}
22 changes: 22 additions & 0 deletions contracts/test/Migrator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@ contract SomeAccount {

}

contract MigratorConstructorTest is TestUtils {

function test_constructor_mismatch_decimals() external {
MockERC20 oldToken = new MockERC20("Old Token", "OT", 18);
MockERC20 newToken = new MockERC20("New Token", "NT", 17);

vm.expectRevert("M:C:DECIMAL_MISMATCH");
new Migrator(address(oldToken), address(newToken));
}

function test_constructor() external {
MockERC20 oldToken = new MockERC20("Old Token", "OT", 18);
MockERC20 newToken = new MockERC20("New Token", "NT", 18);

Migrator migrator = new Migrator(address(oldToken), address(newToken));

assertEq(migrator.oldToken(), address(oldToken));
assertEq(migrator.newToken(), address(newToken));
}

}

contract MigratorTest is TestUtils {

uint256 public constant OLD_SUPPLY = 10_000_000 ether;
Expand Down

0 comments on commit 1f058ec

Please sign in to comment.