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

Added error msgs to require statements in minting/* contracts #242

Merged
merged 19 commits into from
Jan 10, 2019

Conversation

mirathewhite
Copy link
Contributor

Added error messages to all require statements in the new minting/* contracts. Left original contracts in USDC unchanged.

@mirathewhite
Copy link
Contributor Author

Created expectError(promise, errorMsg) that checks that a transaction returns an error with a specific message.

  • Test MINT contracts using the expectError function when appropriate
  • Upgrade to truffle 5, but still use compiler 4.24.0 for backwards compatibility

Copy link
Contributor

@eztierney eztierney left a 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:
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@o-a-hudson o-a-hudson left a 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?

@@ -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.");
Copy link
Contributor

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

Copy link
Contributor Author

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."

Copy link
Contributor

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.

Copy link
Contributor

@o-a-hudson o-a-hudson Jan 4, 2019

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.

@@ -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.");
Copy link
Contributor

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?

Copy link
Contributor Author

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."

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));
Copy link
Contributor

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?

Copy link
Contributor Author

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.

'tokenOwner': tokenOwner,
'proxiedTokenAddress': proxiedTokenAddress,
'proxyOwner': proxyOwner,
'masterMinter': upperCaseAddress(masterMinter),
Copy link
Contributor

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?

Copy link
Contributor Author

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");
Copy link
Contributor

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 ?

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@@ -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));
Copy link
Contributor

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?

Copy link
Contributor Author

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) {
Copy link
Contributor

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)?

Copy link
Contributor Author

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");
Copy link
Contributor

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.

@o-a-hudson
Copy link
Contributor

Tests seem to be failing after expectRevert update: https://travis-ci.com/centrehq/centre-tokens/jobs/169567434

@o-a-hudson
Copy link
Contributor

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.

@o-a-hudson o-a-hudson merged commit f7f8124 into circlefin:multi-issuer Jan 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants