Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
a8bcb0fc
Commit
a8bcb0fc
authored
Apr 14, 2017
by
AugustoL
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added totalPayments uint on PullPayments contract
parent
b4203167
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
1 deletions
+17
-1
PullPayment.sol
contracts/payment/PullPayment.sol
+4
-1
PullPayment.js
test/PullPayment.js
+13
-0
No files found.
contracts/payment/PullPayment.sol
View file @
a8bcb0fc
...
...
@@ -11,17 +11,19 @@ import '../SafeMath.sol';
*/
contract PullPayment is SafeMath {
mapping(address => uint) public payments;
uint public totalPayments;
// store sent amount as credit to be pulled, called by payer
function asyncSend(address dest, uint amount) internal {
payments[dest] = safeAdd(payments[dest], amount);
totalPayments = safeAdd(totalPayments, amount);
}
// withdraw accumulated balance, called by payee
function withdrawPayments() {
address payee = msg.sender;
uint payment = payments[payee];
if (payment == 0) {
throw;
}
...
...
@@ -30,6 +32,7 @@ contract PullPayment is SafeMath {
throw;
}
totalPayments = safeSub(totalPayments, payment);
payments[payee] = 0;
if (!payee.send(payment)) {
...
...
test/PullPayment.js
View file @
a8bcb0fc
...
...
@@ -12,7 +12,9 @@ contract('PullPayment', function(accounts) {
let
ppce
=
await
PullPaymentMock
.
new
();
let
callSend
=
await
ppce
.
callSend
(
accounts
[
0
],
AMOUNT
);
let
paymentsToAccount0
=
await
ppce
.
payments
(
accounts
[
0
]);
let
totalPayments
=
await
ppce
.
totalPayments
();
assert
.
equal
(
totalPayments
,
AMOUNT
);
assert
.
equal
(
paymentsToAccount0
,
AMOUNT
);
});
...
...
@@ -21,7 +23,9 @@ contract('PullPayment', function(accounts) {
let
call1
=
await
ppce
.
callSend
(
accounts
[
0
],
200
);
let
call2
=
await
ppce
.
callSend
(
accounts
[
0
],
300
);
let
paymentsToAccount0
=
await
ppce
.
payments
(
accounts
[
0
]);
let
totalPayments
=
await
ppce
.
totalPayments
();
assert
.
equal
(
totalPayments
,
500
);
assert
.
equal
(
paymentsToAccount0
,
500
);
});
...
...
@@ -35,6 +39,9 @@ contract('PullPayment', function(accounts) {
let
paymentsToAccount1
=
await
ppce
.
payments
(
accounts
[
1
]);
assert
.
equal
(
paymentsToAccount1
,
300
);
let
totalPayments
=
await
ppce
.
totalPayments
();
assert
.
equal
(
totalPayments
,
500
);
});
it
(
"can withdraw payment"
,
async
function
()
{
...
...
@@ -48,10 +55,16 @@ contract('PullPayment', function(accounts) {
let
payment1
=
await
ppce
.
payments
(
payee
);
assert
.
equal
(
payment1
,
AMOUNT
);
let
totalPayments
=
await
ppce
.
totalPayments
();
assert
.
equal
(
totalPayments
,
AMOUNT
);
let
withdraw
=
await
ppce
.
withdrawPayments
({
from
:
payee
});
let
payment2
=
await
ppce
.
payments
(
payee
);
assert
.
equal
(
payment2
,
0
);
totalPayments
=
await
ppce
.
totalPayments
();
assert
.
equal
(
totalPayments
,
0
);
let
balance
=
web3
.
eth
.
getBalance
(
payee
);
assert
(
Math
.
abs
(
balance
-
initialBalance
-
AMOUNT
)
<
1
e16
);
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment