SimpleSavingsWallet.test.js 1.4 KB

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