Skip to content

Commit

Permalink
Validate token decimals in initializer.
Browse files Browse the repository at this point in the history
  • Loading branch information
MickdeGraaf committed Sep 14, 2020
1 parent c2fbe8f commit f2400b5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions contracts/Crust.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ contract Crust is IMiniMeToken {
require(_crumbs.length > 0, "Crust.constructor: Crust must at least have one crumb");
for(uint256 i = 0; i < _crumbs.length; i ++) {
crumbs.push(IMiniMeToken(_crumbs[i]));
require(crumbs[i].decimals() == _decimals, "Crumbs must have same number of decimals as crust");
}
name = _name;
symbol = _symbol;
Expand Down Expand Up @@ -64,4 +65,12 @@ contract Crust is IMiniMeToken {
}
return result;
}

/**
* @notice Gets the amount of decimals.
* @dev Necesary because otherwise typechain does not generate working artifacts
*/
function decimals() external view returns(uint8) {
return decimals;
}
}
1 change: 1 addition & 0 deletions contracts/interfaces/IMiniMeToken.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pragma solidity 0.4.24;

interface IMiniMeToken {
function decimals() external view returns(uint8);
function balanceOf(address _account) external view returns(uint256);
function balanceOfAt(address _account, uint256 _block) external view returns(uint256);
function totalSupply() external view returns(uint256);
Expand Down
15 changes: 15 additions & 0 deletions test/crust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ describe("Pie Crust", function () {
// TODO make this test show up in the coverage report. (Low priority)
});

it("Test token decimals", async() => {
const token2 = await (new MiniMeTokenFactory(signers[0])).deploy(
constants.AddressZero,
constants.AddressZero,
0,
"TKN2",
8,
"TKN2",
true
);
// Using chai-as-promised because waffle chai matchers seem not to be working with constructors
// @ts-ignore
await expect((new CrustFactory(signers[0])).deploy([token0.address, token1.address, token2.address], "TEST", "TEST", 18)).to.be.rejectedWith("VM Exception while processing transaction: revert Crumbs must have same number of decimals as crust")
});

it("Test balance of", async() => {
await token0.generateTokens(account, parseEther("1337"));
expect(await crust.balanceOf(account)).to.eq(parseEther("1337"));
Expand Down

0 comments on commit f2400b5

Please sign in to comment.