MultisigWallet.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. 'use strict';
  2. var MultisigWalletMock = artifacts.require('./helpers/MultisigWalletMock.sol');
  3. require('./helpers/transactionMined.js');
  4. contract('MultisigWallet', function(accounts) {
  5. let shouldntFail = function(err) {
  6. assert.isFalse(!!err);
  7. };
  8. it('should send balance to passed address upon death', async function() {
  9. //Give account[0] 20 ether
  10. web3.eth.sendTransaction({from: web3.eth.coinbase, to: accounts[0], value: web3.toWei('20','ether')}, shouldntFail);
  11. let dailyLimit = 10;
  12. let ownersRequired = 2;
  13. //Create MultisigWallet contract with 10 ether
  14. let wallet = await MultisigWalletMock.new(accounts, ownersRequired, dailyLimit, {value: web3.toWei('10', 'ether')});
  15. //Get balances of owner and wallet after wallet creation.
  16. let ownerBalance = web3.eth.getBalance(accounts[0]);
  17. let walletBalance = web3.eth.getBalance(wallet.address);
  18. let hash = 1234;
  19. //Call destroy function from two different owner accounts, satisfying owners required
  20. await wallet.destroy(accounts[0], {data: hash});
  21. let txnHash = await wallet.destroy(accounts[0], {from: accounts[1], data: hash});
  22. //Get balances of owner and wallet after destroy function is complete, compare with previous values
  23. let newOwnerBalance = web3.eth.getBalance(accounts[0]);
  24. let newWalletBalance = web3.eth.getBalance(wallet.address);
  25. assert.isTrue(newOwnerBalance > ownerBalance);
  26. assert.isTrue(newWalletBalance < walletBalance);
  27. });
  28. it('should execute transaction if below daily limit', async function() {
  29. //Give account[0] 20 ether
  30. web3.eth.sendTransaction({from: web3.eth.coinbase, to: accounts[0], value: web3.toWei('20','ether')}, shouldntFail);
  31. let dailyLimit = 10;
  32. let ownersRequired = 2;
  33. //Create MultisigWallet contract with 10 ether
  34. let wallet = await MultisigWalletMock.new(accounts, ownersRequired, dailyLimit, {value: web3.toWei('10', 'ether')});
  35. let accountBalance = web3.eth.getBalance(accounts[2]);
  36. let hash = 1234;
  37. //Owner account0 commands wallet to send 9 wei to account2
  38. let txnHash = await wallet.execute(accounts[2], 9, hash);
  39. //Balance of account2 should have increased
  40. let newAccountBalance = web3.eth.getBalance(accounts[2]);
  41. assert.isTrue(newAccountBalance > accountBalance);
  42. });
  43. it('should prevent execution of transaction if above daily limit', async function() {
  44. //Give account[0] 20 ether
  45. web3.eth.sendTransaction({from: web3.eth.coinbase, to: accounts[0], value: web3.toWei('20','ether')}, shouldntFail);
  46. let dailyLimit = 10;
  47. let ownersRequired = 2;
  48. //Create MultisigWallet contract with 10 ether
  49. let wallet = await MultisigWalletMock.new(accounts, ownersRequired, dailyLimit, {value: web3.toWei('10', 'ether')});
  50. let accountBalance = web3.eth.getBalance(accounts[2]);
  51. let hash = 1234;
  52. //Owner account0 commands wallet to send 9 wei to account2
  53. let txnHash = await wallet.execute(accounts[2], 9, hash);
  54. //Balance of account2 should have increased
  55. let newAccountBalance = web3.eth.getBalance(accounts[2]);
  56. assert.isTrue(newAccountBalance > accountBalance);
  57. accountBalance = newAccountBalance;
  58. hash = 4567;
  59. //Owner account0 commands wallet to send 2 more wei to account2, going over the daily limit of 10
  60. txnHash = await wallet.execute(accounts[2], 2, hash);
  61. //Balance of account2 should not change
  62. newAccountBalance = web3.eth.getBalance(accounts[2]);
  63. assert.equal(newAccountBalance.toString(), accountBalance.toString());
  64. });
  65. it('should execute transaction if above daily limit and enough owners approve', async function() {
  66. //Give account[0] 20 ether
  67. web3.eth.sendTransaction({from: web3.eth.coinbase, to: accounts[0], value: web3.toWei('20','ether')}, shouldntFail);
  68. let dailyLimit = 10;
  69. let ownersRequired = 2;
  70. //Create MultisigWallet contract with 10 ether
  71. let wallet = await MultisigWalletMock.new(accounts, ownersRequired, dailyLimit, {value: web3.toWei('10', 'ether')});
  72. let accountBalance = web3.eth.getBalance(accounts[2]);
  73. let hash = 1234;
  74. //Owner account0 commands wallet to send 11 wei to account2
  75. let txnHash = await wallet.execute(accounts[2], 11, hash);
  76. //Balance of account2 should not change
  77. let newAccountBalance = web3.eth.getBalance(accounts[2]);
  78. assert.equal(newAccountBalance.toString(), accountBalance.toString());
  79. accountBalance = newAccountBalance;
  80. //Owner account1 commands wallet to send 11 wei to account2
  81. txnHash = await wallet.execute(accounts[2], 2, hash);
  82. //Balance of account2 should change
  83. newAccountBalance = web3.eth.getBalance(accounts[2]);
  84. assert.isTrue(newAccountBalance > accountBalance);
  85. });
  86. });