SimpleSavingsWallet.test.js 1.4 KB

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