SimpleSavingsWallet.test.js 1.5 KB

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