Ownable.js 1.4 KB

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