Merge pull request #108 from sc-forks/transfer-test
Add transfer / send unit test. Use Node7pull/114/head
commit
904003638d
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,23 @@ |
|||||||
|
/* eslint-env node, mocha */ |
||||||
|
/* global artifacts, contract, assert, web3 */ |
||||||
|
|
||||||
|
const Wallet = artifacts.require('./Wallet.sol'); |
||||||
|
|
||||||
|
contract('Wallet', accounts => { |
||||||
|
it('should should allow transfers and sends', async () => { |
||||||
|
const walletA = await Wallet.new(); |
||||||
|
const walletB = await Wallet.new(); |
||||||
|
|
||||||
|
await walletA.sendTransaction({ |
||||||
|
value: web3.toBigNumber(100), from: accounts[0], |
||||||
|
}); |
||||||
|
await walletA.sendPayment(50, walletB.address, { |
||||||
|
from: accounts[0], |
||||||
|
}); |
||||||
|
await walletA.transferPayment(50, walletB.address, { |
||||||
|
from: accounts[0], |
||||||
|
}); |
||||||
|
const balance = await walletB.getBalance(); |
||||||
|
assert.equal(balance.toNumber(), 100); |
||||||
|
}); |
||||||
|
}); |
@ -0,0 +1,25 @@ |
|||||||
|
pragma solidity ^0.4.4; |
||||||
|
|
||||||
|
contract Wallet { |
||||||
|
|
||||||
|
event Deposit(address indexed _sender, uint _value); |
||||||
|
|
||||||
|
function transferPayment(uint payment, address recipient){ |
||||||
|
recipient.transfer(payment); |
||||||
|
} |
||||||
|
|
||||||
|
function sendPayment(uint payment, address recipient){ |
||||||
|
if (!recipient.send(payment)) |
||||||
|
revert(); |
||||||
|
} |
||||||
|
|
||||||
|
function getBalance() constant returns(uint){ |
||||||
|
return address(this).balance; |
||||||
|
} |
||||||
|
|
||||||
|
function() payable |
||||||
|
{ |
||||||
|
if (msg.value > 0) |
||||||
|
Deposit(msg.sender, msg.value); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue