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

Fix/ownable error - Silent transferOwnership Failure #323

Merged
merged 4 commits into from
Jul 22, 2017

Conversation

pooleja
Copy link
Contributor

@pooleja pooleja commented Jul 20, 2017

Fixes #319

The transfer ownership call in the Ownable contract had a silent failure if the "to" address was not set in the transferOwnership() call. This fix adds a specific require() call so that any callers of the function will be notified that they passed an incorrect error.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.09%) to 83.421% when pulling 6d565ef on pooleja:fix/ownable_error into c3a30e9 on OpenZeppelin:master.

@maraoz
Copy link
Contributor

maraoz commented Jul 20, 2017

@pooleja test coverage decreased, can you check that please? You can get the test coverage locally by running npm run coverage

@pooleja
Copy link
Contributor Author

pooleja commented Jul 20, 2017

Ownable.sol says it is at 100% still:
https://coveralls.io/builds/12483052/source?filename=contracts%2Fownership%2FOwnable.sol

That is the only contract code touched.

I am wondering if the code coverage counts lines without actual code, like { or } lines? If so, this was reduced by 2 lines of brackets for code fomatting.

@maraoz
Copy link
Contributor

maraoz commented Jul 20, 2017

Ah, sorry. ACK!

@maraoz maraoz requested a review from frangio July 20, 2017 20:33
@frangio
Copy link
Contributor

frangio commented Jul 20, 2017

@cgewecke Do you have any hint as to what caused the coverage decrease?

Let's merge this anyway.

@cgewecke
Copy link
Contributor

@frangio Interesting - it looks like it's because the old tests hit both branches of an if statement raising the overall value of branch coverage for the whole project, and coveralls is averaging everything together.

From Istanbul's report in the CI (the second number is the branch totals):

A previous build had these values:
istanbul_previous

This build looks like this:
istanbul

Also . . . I'm seeing coverage crash occasionally in the CI here on a weird database error, so if you see really bad numbers that could also be a cause. Re-running on Travis could clear it.

We're upgrading to testrpc 4.x over the weekend which might help smooth things out.

@jakub-wojciechowski
Copy link
Contributor

Guys @pooleja @frangio ,
I think there is a slightly bigger problem with this new test. If we comment the line:

function transferOwnership(address newOwner) onlyOwner {
    //require(newOwner != address(0));
    owner = newOwner;
  }

All test will pass successfully.

We need to check both paths of execution by failing when there is no error thrown at all:

it('should guard ownership against stuck state', async function() {
    let originalOwner = await ownable.owner();
    try {
      await ownable.transferOwnership(null, {from: originalOwner});
    } catch(error) {
      return assertJump(error);
    }
    assert.fail()
  });

@frangio
Copy link
Contributor

frangio commented Jul 21, 2017

Good catch @jakub-wojciechowski.

@pooleja Can you fix the test?

@pooleja
Copy link
Contributor Author

pooleja commented Jul 21, 2017

Yep, I will take care of that. Good catch.

@pooleja
Copy link
Contributor Author

pooleja commented Jul 22, 2017

Added the assert.fail() call to ensure there is no regression so it will be caught if the check for invalid address is removed.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.09%) to 83.421% when pulling 64787b1 on pooleja:fix/ownable_error into c3a30e9 on OpenZeppelin:master.

@OpenZeppelin OpenZeppelin deleted a comment from coveralls Jul 22, 2017
@frangio frangio merged commit e9cf6df into OpenZeppelin:master Jul 22, 2017
ProphetDaniel pushed a commit to classicdelta/Smart-Contracts that referenced this pull request Mar 9, 2018
Fix/ownable error - Silent transferOwnership Failure
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.

Ownable transferOwnership() silently fails
6 participants