Claimable.test.js 1.7 KB

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