Make Stoppable a subclass of Ownable. Fixes #47

pull/49/head
Federico Bond 8 years ago
parent c70a0cfd5d
commit 4599fbf248
  1. 1
      contracts/Ownable.sol
  2. 16
      contracts/Stoppable.sol
  3. 6
      contracts/examples/StoppableBid.sol
  4. 4
      contracts/test-helpers/StoppableMock.sol
  5. 10
      test/Stoppable.js

@ -1,4 +1,5 @@
pragma solidity ^0.4.0;
/*
* Ownable
* Base contract with an owner

@ -1,28 +1,22 @@
pragma solidity ^0.4.0;
import "./Ownable.sol";
/*
* Stoppable
* Abstract contract that allows children to implement an
* emergency stop mechanism.
*/
contract Stoppable {
address public curator;
contract Stoppable is Ownable {
bool public stopped;
modifier stopInEmergency { if (!stopped) _; }
modifier onlyInEmergency { if (stopped) _; }
function Stoppable(address _curator) {
if (_curator == 0) throw;
curator = _curator;
}
function emergencyStop() external {
if (msg.sender != curator) throw;
function emergencyStop() external onlyOwner {
stopped = true;
}
function release() external onlyInEmergency {
if (msg.sender != curator) throw;
function release() external onlyOwner onlyInEmergency {
stopped = false;
}

@ -7,10 +7,6 @@ contract StoppableBid is Stoppable, PullPayment {
address public highestBidder;
uint public highestBid;
function StoppableBid(address _curator)
Stoppable(_curator)
PullPayment() {}
function bid() external stopInEmergency {
if (msg.value <= highestBid) throw;
@ -22,7 +18,7 @@ contract StoppableBid is Stoppable, PullPayment {
}
function withdraw() onlyInEmergency {
suicide(curator);
suicide(owner);
}
}

@ -2,11 +2,11 @@ pragma solidity ^0.4.0;
import '../Stoppable.sol';
// mock class using Stoppable
contract StoppableMock is Stoppable(msg.sender) {
contract StoppableMock is Stoppable {
bool public drasticMeasureTaken;
uint public count;
function StoppableMock() Stoppable(msg.sender){
function StoppableMock() {
drasticMeasureTaken = false;
count = 0;
}

@ -2,7 +2,7 @@ contract('Stoppable', function(accounts) {
it("can perform normal process in non-emergency", function(done) {
var stoppable;
return StoppableMock.new(accounts[0])
return StoppableMock.new()
.then(function(_stoppable) {
stoppable = _stoppable;
return stoppable.count();
@ -24,7 +24,7 @@ contract('Stoppable', function(accounts) {
it("can not perform normal process in emergency", function(done) {
var stoppable;
return StoppableMock.new(accounts[0])
return StoppableMock.new()
.then(function(_stoppable) {
stoppable = _stoppable;
return stoppable.emergencyStop();
@ -50,7 +50,7 @@ contract('Stoppable', function(accounts) {
it("can not take drastic measure in non-emergency", function(done) {
var stoppable;
return StoppableMock.new(accounts[0])
return StoppableMock.new()
.then(function(_stoppable) {
stoppable = _stoppable;
return stoppable.drasticMeasure();
@ -66,7 +66,7 @@ contract('Stoppable', function(accounts) {
it("can take a drastic measure in an emergency", function(done) {
var stoppable;
return StoppableMock.new(accounts[0])
return StoppableMock.new()
.then(function(_stoppable) {
stoppable = _stoppable;
return stoppable.emergencyStop();
@ -85,7 +85,7 @@ contract('Stoppable', function(accounts) {
it("should resume allowing normal process after emergency is over", function(done) {
var stoppable;
return StoppableMock.new(accounts[0])
return StoppableMock.new()
.then(function(_stoppable) {
stoppable = _stoppable;
return stoppable.emergencyStop();

Loading…
Cancel
Save