Ownable.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict'
  2. const assertJump = require('./helpers/assertJump')
  3. var Ownable = artifacts.require('../contracts/ownership/Ownable.sol')
  4. contract('Ownable', function (accounts) {
  5. let ownable
  6. beforeEach(async function () {
  7. ownable = await Ownable.new()
  8. })
  9. it('should have an owner', async function () {
  10. let owner = await ownable.owner()
  11. assert.isTrue(owner !== 0)
  12. })
  13. it('changes owner after transfer', async function () {
  14. let other = accounts[1]
  15. await ownable.transferOwnership(other)
  16. let owner = await ownable.owner()
  17. assert.isTrue(owner === other)
  18. })
  19. it('should prevent non-owners from transfering', async function () {
  20. const other = accounts[2]
  21. const owner = await ownable.owner.call()
  22. assert.isTrue(owner !== other)
  23. try {
  24. await ownable.transferOwnership(other, {from: other})
  25. } catch (error) {
  26. assertJump(error)
  27. }
  28. })
  29. it('should guard ownership against stuck state setting owner as 0x0 address', async function () {
  30. let originalOwner = await ownable.owner()
  31. try {
  32. await ownable.transferOwnership(null, {from: originalOwner})
  33. } catch (error) {
  34. assertJump(error)
  35. }
  36. })
  37. })