SimpleSavingsWallet.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict'
  2. import assertJump from './helpers/assertJump'
  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. try {
  22. await savingsWallet.sendTo(0, paymentAmount, {from: owner})
  23. assert.fail('should have thrown before')
  24. } catch(error) {
  25. assertJump(error)
  26. }
  27. try {
  28. await savingsWallet.sendTo(savingsWallet.address, paymentAmount, {from: owner})
  29. assert.fail('should have thrown before')
  30. } catch(error) {
  31. assertJump(error)
  32. }
  33. try {
  34. await savingsWallet.sendTo(accounts[1], 0, {from: owner})
  35. assert.fail('should have thrown before')
  36. } catch(error) {
  37. assertJump(error)
  38. }
  39. const balance = web3.eth.getBalance(accounts[1])
  40. await savingsWallet.sendTo(accounts[1], paymentAmount, {from: owner})
  41. assert.isTrue(
  42. balance.plus(paymentAmount).equals(web3.eth.getBalance(accounts[1]))
  43. )
  44. })
  45. })