Shareable.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. contract('Shareable', function(accounts) {
  2. it('should construct with correct owners and number of sigs required', async function() {
  3. let requiredSigs = 2;
  4. let owners = accounts.slice(1,4);
  5. let shareable = await ShareableMock.new(owners, requiredSigs);
  6. let required = await shareable.required();
  7. assert.equal(required, requiredSigs);
  8. let owner = await shareable.getOwner(0);
  9. assert.equal(owner, accounts[0]);
  10. for(let i = 0; i < accounts.length; i++) {
  11. let owner = await shareable.getOwner(i);
  12. let isowner = await shareable.isOwnerConst(accounts[i]);
  13. if(i <= owners.length) {
  14. assert.equal(accounts[i], owner);
  15. assert.isTrue(isowner);
  16. } else {
  17. assert.notEqual(accounts[i], owner);
  18. assert.isFalse(isowner);
  19. }
  20. }
  21. });
  22. it('should only perform multisig function with enough sigs', async function() {
  23. let requiredSigs = 3;
  24. let owners = accounts.slice(1,4);
  25. let shareable = await ShareableMock.new(owners, requiredSigs);
  26. let hash = 1234;
  27. let initCount = await shareable.count();
  28. initCount = initCount.toString();
  29. for(let i = 0; i < requiredSigs; i++) {
  30. await shareable.increaseCount(hash, {from: accounts[i]});
  31. let count = await shareable.count();
  32. if(i == requiredSigs - 1) {
  33. assert.equal(Number(initCount)+1, count.toString());
  34. } else {
  35. assert.equal(initCount, count.toString());
  36. }
  37. }
  38. });
  39. it('should require approval from different owners', async function() {
  40. let requiredSigs = 2;
  41. let owners = accounts.slice(1,4);
  42. let shareable = await ShareableMock.new(owners, requiredSigs);
  43. let hash = 1234;
  44. let initCount = await shareable.count();
  45. initCount = initCount.toString();
  46. //Count shouldn't increase when the same owner calls repeatedly
  47. for(let i = 0; i < 2; i++) {
  48. await shareable.increaseCount(hash);
  49. let count = await shareable.count();
  50. assert.equal(initCount, count.toString());
  51. }
  52. });
  53. it('should reset sig count after operation is approved', async function() {
  54. let requiredSigs = 3;
  55. let owners = accounts.slice(1,4);
  56. let shareable = await ShareableMock.new(owners, requiredSigs);
  57. let hash = 1234;
  58. let initCount = await shareable.count();
  59. //initCount = initCount.toString();
  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, 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, count);
  84. }
  85. });
  86. });