소스 검색

Merge pull request #65 from se3000/ownable_guard

add check prevening ownables from getting stuck
Manuel Aráoz 9 년 전
부모
커밋
3207996777
2개의 변경된 파일17개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      contracts/Ownable.sol
  2. 16 0
      test/Ownable.js

+ 1 - 1
contracts/Ownable.sol

@@ -17,7 +17,7 @@ contract Ownable {
   }
 
   function transfer(address newOwner) onlyOwner {
-    owner = newOwner;
+    if (newOwner != address(0)) owner = newOwner;
   }
 
 }

+ 16 - 0
test/Ownable.js

@@ -39,4 +39,20 @@ contract('Ownable', function(accounts) {
       .then(done)
   });
 
+  it("should guard ownership against stuck state" ,function(done) {
+    var ownable = Ownable.deployed();
+
+    return ownable.owner()
+      .then(function (originalOwner) {
+        return ownable.transfer(null, {from: originalOwner})
+          .then(function() {
+            return ownable.owner();
+          })
+          .then(function(newOwner) {
+            assert.equal(originalOwner, newOwner);
+          })
+          .then(done);
+      });
+  });
+
 });