Ownable.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. contract('Ownable', function(accounts) {
  2. it("should have an owner", function(done) {
  3. var ownable = Ownable.deployed();
  4. return ownable.owner()
  5. .then(function(owner) {
  6. assert.isTrue(owner != 0);
  7. })
  8. .then(done)
  9. });
  10. it("changes owner after transfer", function(done) {
  11. var ownable = Ownable.deployed();
  12. var other = accounts[1];
  13. return ownable.transfer(other)
  14. .then(function() {
  15. return ownable.owner();
  16. })
  17. .then(function(owner) {
  18. assert.isTrue(owner === other);
  19. })
  20. .then(done)
  21. });
  22. it("should prevent non-owners from transfering" ,function(done) {
  23. var ownable = Ownable.deployed();
  24. var other = accounts[2];
  25. return ownable.transfer(other, {from: accounts[2]})
  26. .then(function() {
  27. return ownable.owner();
  28. })
  29. .then(function(owner) {
  30. assert.isFalse(owner === other);
  31. })
  32. .then(done)
  33. });
  34. it("should guard ownership against stuck state" ,function(done) {
  35. var ownable = Ownable.deployed();
  36. return ownable.owner()
  37. .then(function (originalOwner) {
  38. return ownable.transfer(null, {from: originalOwner})
  39. .then(function() {
  40. return ownable.owner();
  41. })
  42. .then(function(newOwner) {
  43. assert.equal(originalOwner, newOwner);
  44. })
  45. .then(done);
  46. });
  47. });
  48. });