Claimable.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. } catch(error) {
  23. assertJump(error);
  24. }
  25. });
  26. it('should prevent non-owners from transfering', async function() {
  27. const other = accounts[2];
  28. const owner = await claimable.owner.call();
  29. assert.isTrue(owner !== other);
  30. try {
  31. await claimable.transferOwnership(other, {from: other});
  32. } catch(error) {
  33. assertJump(error);
  34. }
  35. });
  36. describe('after initiating a transfer', function () {
  37. let newOwner;
  38. beforeEach(async function () {
  39. newOwner = accounts[1];
  40. await claimable.transferOwnership(newOwner);
  41. });
  42. it('changes allow pending owner to claim ownership', async function() {
  43. await claimable.claimOwnership({from: newOwner});
  44. let owner = await claimable.owner();
  45. assert.isTrue(owner === newOwner);
  46. });
  47. });
  48. });