Skip to content

Fix/ownable error - Silent transferOwnership Failure#323

Merged
frangio merged 4 commits into
OpenZeppelin:masterfrom
pooleja:fix/ownable_error
Jul 22, 2017
Merged

Fix/ownable error - Silent transferOwnership Failure#323
frangio merged 4 commits into
OpenZeppelin:masterfrom
pooleja:fix/ownable_error

Conversation

@pooleja

@pooleja pooleja commented Jul 20, 2017

Copy link
Copy Markdown
Contributor

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
Copy Markdown

Coverage Status

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

@maraoz

maraoz commented Jul 20, 2017

Copy link
Copy Markdown
Contributor

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

@pooleja

pooleja commented Jul 20, 2017

Copy link
Copy Markdown
Contributor Author

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

maraoz commented Jul 20, 2017

Copy link
Copy Markdown
Contributor

Ah, sorry. ACK!

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

frangio commented Jul 20, 2017

Copy link
Copy Markdown
Contributor

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

Let's merge this anyway.

@cgewecke

Copy link
Copy Markdown
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
Copy Markdown
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

frangio commented Jul 21, 2017

Copy link
Copy Markdown
Contributor

Good catch @jakub-wojciechowski.

@pooleja Can you fix the test?

@pooleja

pooleja commented Jul 21, 2017

Copy link
Copy Markdown
Contributor Author

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

@pooleja

pooleja commented Jul 22, 2017

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown

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