Claimable.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. 'use strict';
  2. const assertJump = require('./helpers/assertJump');
  3. var Claimable = artifacts.require('../contracts/ownership/Claimable.sol');
  4. contract('Claimable', function(accounts) {
  5. let claimable;
  6. beforeEach(async function() {
  7. claimable = await Claimable.new();
  8. });
  9. it('should have an owner', async function() {
  10. let owner = await claimable.owner();
  11. assert.isTrue(owner !== 0);
  12. });
  13. it('changes pendingOwner after transfer', async function() {
  14. let newOwner = accounts[1];
  15. await claimable.transferOwnership(newOwner);
  16. let pendingOwner = await claimable.pendingOwner();
  17. assert.isTrue(pendingOwner === newOwner);
  18. });
  19. it('should prevent to claimOwnership from no pendingOwner', async function() {
  20. try {
  21. await claimable.claimOwnership({from: accounts[2]});
  22. assert.fail('should have thrown before');
  23. } catch(error) {
  24. assertJump(error);
  25. }
  26. });
  27. it('should prevent non-owners from transfering', async function() {
  28. const other = accounts[2];
  29. const owner = await claimable.owner.call();
  30. assert.isTrue(owner !== other);
  31. try {
  32. await claimable.transferOwnership(other, {from: other});
  33. assert.fail('should have thrown before');
  34. } catch(error) {
  35. assertJump(error);
  36. }
  37. });
  38. describe('after initiating a transfer', function () {
  39. let newOwner;
  40. beforeEach(async function () {
  41. newOwner = accounts[1];
  42. await claimable.transferOwnership(newOwner);
  43. });
  44. it('changes allow pending owner to claim ownership', async function() {
  45. await claimable.claimOwnership({from: newOwner});
  46. let owner = await claimable.owner();
  47. assert.isTrue(owner === newOwner);
  48. });
  49. });
  50. });