-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added barebones Secondary. * Added transferPrimary * Escrow is now Secondary instead of Ownable. * Now reverting on transfers to 0. * The Secondary's primary is now private.
- Loading branch information
Showing
6 changed files
with
124 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 () { | ||
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 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 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