SimpleSavingsWallet.test.js 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. import expectThrow from './helpers/expectThrow';
  2. const SimpleSavingsWallet = artifacts.require('SimpleSavingsWallet');
  3. contract('SimpleSavingsWallet', function (accounts) {
  4. let savingsWallet;
  5. let owner;
  6. const paymentAmount = 4242;
  7. beforeEach(async function () {
  8. savingsWallet = await SimpleSavingsWallet.new(4141);
  9. owner = await savingsWallet.owner();
  10. });
  11. it('should receive funds', async function () {
  12. await web3.eth.sendTransaction({ from: owner, to: savingsWallet.address, value: paymentAmount });
  13. assert.isTrue((new web3.BigNumber(paymentAmount)).equals(web3.eth.getBalance(savingsWallet.address)));
  14. });
  15. it('owner can send funds', async function () {
  16. // Receive payment so we have some money to spend.
  17. await web3.eth.sendTransaction({ from: accounts[9], to: savingsWallet.address, value: 1000000 });
  18. await expectThrow(savingsWallet.sendTo(0, paymentAmount, { from: owner }));
  19. await expectThrow(savingsWallet.sendTo(savingsWallet.address, paymentAmount, { from: owner }));
  20. await expectThrow(savingsWallet.sendTo(accounts[1], 0, { from: owner }));
  21. const balance = web3.eth.getBalance(accounts[1]);
  22. await savingsWallet.sendTo(accounts[1], paymentAmount, { from: owner });
  23. assert.isTrue(balance.plus(paymentAmount).equals(web3.eth.getBalance(accounts[1])));
  24. });
  25. });