-
Notifications
You must be signed in to change notification settings - Fork 12.4k
True Ownership #1247
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
Merged
nventuro
merged 5 commits into
OpenZeppelin:rbac-migration
from
nventuro:true-ownership
Aug 30, 2018
Merged
True Ownership #1247
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6452350
Added barebones Secondary.
nventuro 56045b4
Added transferPrimary
nventuro 70db29f
Escrow is now Secondary instead of Ownable.
nventuro 622df07
Now reverting on transfers to 0.
nventuro 84b3159
The Secondary's primary is now private.
nventuro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| pragma solidity ^0.4.24; | ||
|
|
||
| import "../ownership/Secondary.sol"; | ||
|
|
||
|
|
||
| contract SecondaryMock is Secondary { | ||
| function onlyPrimaryMock() public view onlyPrimary { | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| pragma solidity ^0.4.24; | ||
|
|
||
|
|
||
| /** | ||
| * @title Secondary | ||
| * @dev A Secondary contract can only be used by its primary account (the one that created it) | ||
| */ | ||
| contract Secondary { | ||
| address private primary_; | ||
|
|
||
| /** | ||
| * @dev Sets the primary account to the one that is creating the Secondary contract. | ||
| */ | ||
| constructor() public { | ||
| primary_ = msg.sender; | ||
| } | ||
|
|
||
| /** | ||
| * @dev Reverts if called from any account other than the primary. | ||
| */ | ||
| modifier onlyPrimary() { | ||
| require(msg.sender == primary_); | ||
| _; | ||
| } | ||
|
|
||
| function primary() public view returns (address) { | ||
| return primary_; | ||
| } | ||
|
|
||
| function transferPrimary(address _recipient) public onlyPrimary { | ||
| require(_recipient != address(0)); | ||
|
|
||
| primary_ = _recipient; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| const { assertRevert } = require('../helpers/assertRevert'); | ||
|
|
||
| const SecondaryMock = artifacts.require('SecondaryMock'); | ||
|
|
||
| require('chai') | ||
| .should(); | ||
|
|
||
| contract('Secondary', function ([_, primary, newPrimary, anyone]) { | ||
| const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; | ||
|
|
||
| beforeEach(async function () { | ||
| this.secondary = await SecondaryMock.new({ from: primary }); | ||
| }); | ||
|
|
||
| it('stores the primary\'s address', async function () { | ||
| (await this.secondary.primary()).should.equal(primary); | ||
| }); | ||
|
|
||
| describe('onlyPrimary', function () { | ||
| it('allows the primary account to call onlyPrimary functions', async function () { | ||
| await this.secondary.onlyPrimaryMock({ from: primary }); | ||
| }); | ||
|
|
||
| it('reverts when anyone calls onlyPrimary functions', async function () { | ||
| await assertRevert(this.secondary.onlyPrimaryMock({ from: anyone })); | ||
| }); | ||
| }); | ||
|
|
||
| describe('transferPrimary', function () { | ||
| it('makes the recipient the new primary', async function () { | ||
| await this.secondary.transferPrimary(newPrimary, { from: primary }); | ||
| (await this.secondary.primary()).should.equal(newPrimary); | ||
| }); | ||
|
|
||
| it('reverts when transfering to the null address', async function () { | ||
| await assertRevert(this.secondary.transferPrimary(ZERO_ADDRESS, { from: primary })); | ||
| }); | ||
|
|
||
| it('reverts when called by anyone', async function () { | ||
| await assertRevert(this.secondary.transferPrimary(newPrimary, { from: anyone })); | ||
| }); | ||
|
|
||
| context('with new primary', function () { | ||
| beforeEach(async function () { | ||
frangio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| await this.secondary.transferPrimary(newPrimary, { from: primary }); | ||
| }); | ||
|
|
||
| it('allows the new primary account to call onlyPrimary functions', async function () { | ||
| await this.secondary.onlyPrimaryMock({ from: newPrimary }); | ||
| }); | ||
|
|
||
| it('reverts when the old primary account calls onlyPrimary functions', async function () { | ||
| await assertRevert(this.secondary.onlyPrimaryMock({ from: primary })); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.