-
Notifications
You must be signed in to change notification settings - Fork 368
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
Added error msgs to require statements in minting/* contracts #242
Added error msgs to require statements in minting/* contracts #242
Conversation
Created
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The build failed - I think you may need to update .travis.yml?
yarn.lock
Outdated
@@ -6802,6 +6817,18 @@ sol-explore@^1.6.2: | |||
version "1.6.2" | |||
resolved "https://registry.yarnpkg.com/sol-explore/-/sol-explore-1.6.2.tgz#43ae8c419fd3ac056a05f8a9d1fb1022cd41ecc2" | |||
|
|||
solc@0.5.0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume we need this because truffle 5.0 depends on it? Even though we aren't using it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Migrating requires adding bn.js for big numbers. I'm updating the yarn.lock file.
…tation of BN for comparison, convert all addresses to uppercase prior to comparison, change some function calls to comply with web3js 1.0.0 api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if for the for the inline tests in test functions that use upperCaseAddress https://github.com/centrehq/centre-tokens/pull/242/files#diff-e70111a4751894a1ea34a2b82306a2a1R69 in a assert.equals statement, it might be cleaner to do something like: assert.isTrue(addressEquals(address1, address2)) where addressEquals could be a function that compared both addresses after applying the upperCaseAddress function you wrote? Just because it is starting to get hard to remember what has to be uppercased and a function would hide that detail from the user. What do you think?
contracts/minting/Controller.sol
Outdated
@@ -40,7 +40,7 @@ contract Controller is Ownable { | |||
* @dev ensure that the caller is the controller of a non-zero worker address | |||
*/ | |||
modifier onlyController() { | |||
require(controllers[msg.sender] != address(0)); | |||
require(controllers[msg.sender] != address(0), "Sender must be a controller."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this error should be "Sender address cannot be the null" since it check checking that it is not address(0)? Thinking it should be consistent with the same condition here: https://github.com/centrehq/centre-tokens/pull/242/files#diff-668c7639279550e7f3cd2913080190f6R57
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified to "The value of controller[msg.sender] must be non-zero."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should never convert to all upper-case. All addresses coming back from Web3 will be checksummed (mixed-case), so we need to make sure the addresses we have hardcoded are also checksummed, and then if we ever get an address from a source other than Web3, use web3.utils.toChecksum
(https://web3js.readthedocs.io/en/1.0/web3-utils.html#tochecksumaddress) on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should never convert to all upper-case. All addresses coming back from Web3 will be checksummed (mixed-case), so we need to make sure the addresses we have hardcoded are also checksummed, and then if we ever get an address from a source other than Web3, use
web3.utils.toChecksum
(https://web3js.readthedocs.io/en/1.0/web3-utils.html#tochecksumaddress) on it.
If things are coming back as checksummed and not uppercase, I agree this would be a great approach and we can disregard the suggestions around an address comparison function.
contracts/minting/MintController.sol
Outdated
@@ -91,7 +91,7 @@ contract MintController is Controller { | |||
*/ | |||
function incrementMinterAllowance(uint256 allowanceIncrement) onlyController public returns (bool) { | |||
address minter = controllers[msg.sender]; | |||
require(minterManager.isMinter(minter)); | |||
require(minterManager.isMinter(minter), "Can only increment allowance for enabled minter."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor: should we drop the word "enabled" and just say for minter as I don't think we have a notion of an "enabled" minter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to "Can only increment allowance for minters in minterManager."
test/TokenTestUtils.js
Outdated
function calculateFeeAmount(amount) { | ||
return Math.floor((fee / feeBase) * amount); | ||
} | ||
|
||
function checkMinterConfiguredEvent(configureMinterEvent, minter, minterAllowedAmount) { | ||
assert.equal(configureMinterEvent.logs[0].event, 'MinterConfigured') | ||
assert.equal(configureMinterEvent.logs[0].args.minter, minter) | ||
assert.equal(upperCaseAddress(configureMinterEvent.logs[0].args.minter), upperCaseAddress(minter)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we able to uppercase only the first argument to assert.equal in these cases since the addresses have been changed to uppercase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the solution you recommended to write addressEquals(address1, address2)
is cleaner. I don't want to keep track of which argument is already uppercased.
test/TokenTestUtils.js
Outdated
'tokenOwner': tokenOwner, | ||
'proxiedTokenAddress': proxiedTokenAddress, | ||
'proxyOwner': proxyOwner, | ||
'masterMinter': upperCaseAddress(masterMinter), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't these already uppercased when you changed the hardcoded address to be in uppercase? (Also, from what I can tell it looks like the BN conversion function will make them uppercase anyway) Do you think we need these upperCaseAddress calls here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressEquals() will make this unnecessary.
var totalSupply = new BigNumber(await token.totalSupply()) | ||
assert(balanceSum.isEqualTo(totalSupply), "sum of balances is not equal to totalSupply"); | ||
var totalSupply = newBigNumber(await token.totalSupply()) | ||
assert(balanceSum.cmp(totalSupply)==0, "sum of balances is not equal to totalSupply"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, but maybe we want to check for equals here instead of comparison, so we don't have to check == 0 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The BN library does not work with assert.equals - it returns false even if the numbers are equal because the internal representation might be different. This is one of the reasons I had to to use the hex representation for the deepEquals function.
@@ -404,17 +429,17 @@ async function setLongDecimalFeesTransferWithFees(token, ownerAccount, arbitrary | |||
let balance3 = await token.balanceOf(arbitraryAccount); | |||
assert.equal(balance3, 1000); | |||
let balanceFeeAccount = await token.balanceOf(feeAccount); | |||
assert.isTrue(new BigNumber(balanceFeeAccount).minus(new BigNumber(initialBalanceFeeAccount)).isEqualTo(new BigNumber(feeAmount))); | |||
assert.isTrue(balanceFeeAccount.sub(initialBalanceFeeAccount).cmp(newBigNumber(feeAmount))==0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest using equals here instead of cmp as well just to avoid having to write ==0 in each test that uses it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see note about regarding BN library and assert.equals.
test/TokenTestUtils.js
Outdated
@@ -483,8 +508,8 @@ async function redeem(token, account, amount) { | |||
function validateTransferEvent(transferEvent, from, to, value) { | |||
let eventResult = transferEvent.logs[0]; | |||
assert.equal(eventResult.event, 'Transfer'); | |||
assert.equal(eventResult.args.from, from); | |||
assert.equal(eventResult.args.to, to); | |||
assert.equal(upperCaseAddress(eventResult.args.from), upperCaseAddress(from)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering in this case as well if we need to call upperCaseAddress on from and to arguments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will use addressEquals()
@@ -216,6 +222,23 @@ function buildExpectedState(token, customVars) { | |||
return expectedState; | |||
} | |||
|
|||
// Replaces all BN objects with 32 character hex strings | |||
function mapBNToHex(state) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps here it might be easier to use the web3 tohex function that can take BN to hex (https://web3js.readthedocs.io/en/1.0/web3-utils.html#tohex)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do this for all BN to hex conversions.
@@ -136,7 +137,7 @@ async function run_tests(newToken, accounts) { | |||
await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); | |||
|
|||
// increment minter allowance | |||
await expectRevert(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account})); | |||
await expectError(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only increment allowance for enabled minter"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there might be a bug with our expectError method because in this line we are expecting to find a revert string "Can only increment allowance for enabled minter" but that is no longer in the contract. Yet the tests are still passing, so this looks like the expectError function is not checking the expected revert string properly.
Tests seem to be failing after expectRevert update: https://travis-ci.com/centrehq/centre-tokens/jobs/169567434 |
We'll fix this in a separate PR. |
Added error messages to all require statements in the new minting/* contracts. Left original contracts in USDC unchanged.