Shareable.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. var ShareableMock = artifacts.require("./helpers/ShareableMock.sol");
  2. contract('Shareable', function(accounts) {
  3. it('should construct with correct owners and number of sigs required', async function() {
  4. let requiredSigs = 2;
  5. let owners = accounts.slice(1,4);
  6. let shareable = await ShareableMock.new(owners, requiredSigs);
  7. let required = await shareable.required();
  8. assert.equal(required, requiredSigs);
  9. let owner = await shareable.getOwner(0);
  10. assert.equal(owner, accounts[0]);
  11. for(let i = 0; i < accounts.length; i++) {
  12. let owner = await shareable.getOwner(i);
  13. let isowner = await shareable.isOwner(accounts[i]);
  14. if(i <= owners.length) {
  15. assert.equal(accounts[i], owner);
  16. assert.isTrue(isowner);
  17. } else {
  18. assert.notEqual(accounts[i], owner);
  19. assert.isFalse(isowner);
  20. }
  21. }
  22. });
  23. it('should only perform multisig function with enough sigs', async function() {
  24. let requiredSigs = 3;
  25. let owners = accounts.slice(1,4);
  26. let shareable = await ShareableMock.new(owners, requiredSigs);
  27. let hash = 1234;
  28. let initCount = await shareable.count();
  29. initCount = initCount.toString();
  30. for(let i = 0; i < requiredSigs; i++) {
  31. await shareable.increaseCount(hash, {from: accounts[i]});
  32. let count = await shareable.count();
  33. if(i == requiredSigs - 1) {
  34. assert.equal(Number(initCount)+1, count.toString());
  35. } else {
  36. assert.equal(initCount, count.toString());
  37. }
  38. }
  39. });
  40. it('should require approval from different owners', async function() {
  41. let requiredSigs = 2;
  42. let owners = accounts.slice(1,4);
  43. let shareable = await ShareableMock.new(owners, requiredSigs);
  44. let hash = 1234;
  45. let initCount = await shareable.count();
  46. initCount = initCount.toString();
  47. //Count shouldn't increase when the same owner calls repeatedly
  48. for(let i = 0; i < 2; i++) {
  49. await shareable.increaseCount(hash);
  50. let count = await shareable.count();
  51. assert.equal(initCount, count.toString());
  52. }
  53. });
  54. it('should reset sig count after operation is approved', async function() {
  55. let requiredSigs = 3;
  56. let owners = accounts.slice(1,4);
  57. let shareable = await ShareableMock.new(owners, requiredSigs);
  58. let hash = 1234;
  59. let initCount = await shareable.count();
  60. for(let i = 0; i < requiredSigs * 3; i++) {
  61. await shareable.increaseCount(hash, {from: accounts[i % 4]});
  62. let count = await shareable.count();
  63. if((i%(requiredSigs)) == requiredSigs - 1) {
  64. initCount = Number(initCount)+1;
  65. assert.equal(initCount, count);
  66. } else {
  67. assert.equal(initCount.toString(), count);
  68. }
  69. }
  70. });
  71. it('should not perform multisig function after an owner revokes', async function() {
  72. let requiredSigs = 3;
  73. let owners = accounts.slice(1,4);
  74. let shareable = await ShareableMock.new(owners, requiredSigs);
  75. let hash = 1234;
  76. let initCount = await shareable.count();
  77. for(let i = 0; i < requiredSigs; i++) {
  78. if(i == 1) {
  79. await shareable.revoke(hash, {from: accounts[i-1]});
  80. }
  81. await shareable.increaseCount(hash, {from: accounts[i]});
  82. let count = await shareable.count();
  83. assert.equal(initCount.toString(), count);
  84. }
  85. });
  86. });