SimpleSavingsWallet.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict'
  2. import expectThrow from './helpers/expectThrow';
  3. const SimpleSavingsWallet = artifacts.require('../contracts/examples/SimpleSavingsWallet.sol')
  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 web3.eth.sendTransaction({from: owner, to: savingsWallet.address, value: paymentAmount})
  14. assert.isTrue(
  15. (new web3.BigNumber(paymentAmount)).equals(web3.eth.getBalance(savingsWallet.address))
  16. )
  17. })
  18. it('owner can send funds', async function() {
  19. // Receive payment so we have some money to spend.
  20. await web3.eth.sendTransaction({from: accounts[9], to: savingsWallet.address, value: 1000000})
  21. await expectThrow(savingsWallet.sendTo(0, paymentAmount, {from: owner}))
  22. await expectThrow(savingsWallet.sendTo(savingsWallet.address, paymentAmount, {from: owner}))
  23. await expectThrow(savingsWallet.sendTo(accounts[1], 0, {from: owner}))
  24. const balance = web3.eth.getBalance(accounts[1])
  25. await savingsWallet.sendTo(accounts[1], paymentAmount, {from: owner})
  26. assert.isTrue(balance.plus(paymentAmount).equals(web3.eth.getBalance(accounts[1])))
  27. })
  28. })