added test for SimpleSavingsWallet

pull/680/head
zava 7 years ago committed by Alejandro Santander
parent 82c85121bb
commit 46736da489
  1. 40
      test/SimpleSavingsWallet.js

@ -1,4 +1,5 @@
'use strict'
import assertJump from './helpers/assertJump'
const SimpleSavingsWallet = artifacts.require('../contracts/examples/SimpleSavingsWallet.sol')
@ -6,11 +7,46 @@ contract('SimpleSavingsWallet', function(accounts) {
let savingsWallet
let owner
const paymentAmount = 4242
beforeEach(async function() {
savingsWallet = await SimpleSavingsWallet.new(4141)
owner = await inheritable.owner()
owner = await savingsWallet.owner()
})
it('should receive funds', async function() {
await web3.eth.sendTransaction({from: owner, to: this.contract.address, value: amount})
await web3.eth.sendTransaction({from: owner, to: savingsWallet.address, value: paymentAmount})
assert.isTrue(
(new web3.BigNumber(paymentAmount)).equals(web3.eth.getBalance(savingsWallet.address))
)
})
it('owner can send funds', async function() {
// Receive payment so we have some money to spend.
await web3.eth.sendTransaction({from: accounts[9], to: savingsWallet.address, value: 1000000})
try {
await savingsWallet.sendTo(0, paymentAmount, {from: owner})
assert.fail('should have thrown before')
} catch(error) {
assertJump(error)
}
try {
await savingsWallet.sendTo(savingsWallet.address, paymentAmount, {from: owner})
assert.fail('should have thrown before')
} catch(error) {
assertJump(error)
}
try {
await savingsWallet.sendTo(accounts[1], 0, {from: owner})
assert.fail('should have thrown before')
} catch(error) {
assertJump(error)
}
const balance = web3.eth.getBalance(accounts[1])
await savingsWallet.sendTo(accounts[1], paymentAmount, {from: owner})
assert.isTrue(
balance.plus(paymentAmount).equals(web3.eth.getBalance(accounts[1]))
)
})
})

Loading…
Cancel
Save