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
ab9591ba
Commit
ab9591ba
authored
Apr 18, 2017
by
Manuel Aráoz
Committed by
GitHub
Apr 18, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #193 from AugustoL/master
Added totalPayments uint on PullPayments contract
parents
b4203167
a8bcb0fc
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 @
ab9591ba
...
@@ -11,17 +11,19 @@ import '../SafeMath.sol';
...
@@ -11,17 +11,19 @@ import '../SafeMath.sol';
*/
*/
contract PullPayment is SafeMath {
contract PullPayment is SafeMath {
mapping(address => uint) public payments;
mapping(address => uint) public payments;
uint public totalPayments;
// store sent amount as credit to be pulled, called by payer
// store sent amount as credit to be pulled, called by payer
function asyncSend(address dest, uint amount) internal {
function asyncSend(address dest, uint amount) internal {
payments[dest] = safeAdd(payments[dest], amount);
payments[dest] = safeAdd(payments[dest], amount);
totalPayments = safeAdd(totalPayments, amount);
}
}
// withdraw accumulated balance, called by payee
// withdraw accumulated balance, called by payee
function withdrawPayments() {
function withdrawPayments() {
address payee = msg.sender;
address payee = msg.sender;
uint payment = payments[payee];
uint payment = payments[payee];
if (payment == 0) {
if (payment == 0) {
throw;
throw;
}
}
...
@@ -30,6 +32,7 @@ contract PullPayment is SafeMath {
...
@@ -30,6 +32,7 @@ contract PullPayment is SafeMath {
throw;
throw;
}
}
totalPayments = safeSub(totalPayments, payment);
payments[payee] = 0;
payments[payee] = 0;
if (!payee.send(payment)) {
if (!payee.send(payment)) {
...
...
test/PullPayment.js
View file @
ab9591ba
...
@@ -12,7 +12,9 @@ contract('PullPayment', function(accounts) {
...
@@ -12,7 +12,9 @@ contract('PullPayment', function(accounts) {
let
ppce
=
await
PullPaymentMock
.
new
();
let
ppce
=
await
PullPaymentMock
.
new
();
let
callSend
=
await
ppce
.
callSend
(
accounts
[
0
],
AMOUNT
);
let
callSend
=
await
ppce
.
callSend
(
accounts
[
0
],
AMOUNT
);
let
paymentsToAccount0
=
await
ppce
.
payments
(
accounts
[
0
]);
let
paymentsToAccount0
=
await
ppce
.
payments
(
accounts
[
0
]);
let
totalPayments
=
await
ppce
.
totalPayments
();
assert
.
equal
(
totalPayments
,
AMOUNT
);
assert
.
equal
(
paymentsToAccount0
,
AMOUNT
);
assert
.
equal
(
paymentsToAccount0
,
AMOUNT
);
});
});
...
@@ -21,7 +23,9 @@ contract('PullPayment', function(accounts) {
...
@@ -21,7 +23,9 @@ contract('PullPayment', function(accounts) {
let
call1
=
await
ppce
.
callSend
(
accounts
[
0
],
200
);
let
call1
=
await
ppce
.
callSend
(
accounts
[
0
],
200
);
let
call2
=
await
ppce
.
callSend
(
accounts
[
0
],
300
);
let
call2
=
await
ppce
.
callSend
(
accounts
[
0
],
300
);
let
paymentsToAccount0
=
await
ppce
.
payments
(
accounts
[
0
]);
let
paymentsToAccount0
=
await
ppce
.
payments
(
accounts
[
0
]);
let
totalPayments
=
await
ppce
.
totalPayments
();
assert
.
equal
(
totalPayments
,
500
);
assert
.
equal
(
paymentsToAccount0
,
500
);
assert
.
equal
(
paymentsToAccount0
,
500
);
});
});
...
@@ -35,6 +39,9 @@ contract('PullPayment', function(accounts) {
...
@@ -35,6 +39,9 @@ contract('PullPayment', function(accounts) {
let
paymentsToAccount1
=
await
ppce
.
payments
(
accounts
[
1
]);
let
paymentsToAccount1
=
await
ppce
.
payments
(
accounts
[
1
]);
assert
.
equal
(
paymentsToAccount1
,
300
);
assert
.
equal
(
paymentsToAccount1
,
300
);
let
totalPayments
=
await
ppce
.
totalPayments
();
assert
.
equal
(
totalPayments
,
500
);
});
});
it
(
"can withdraw payment"
,
async
function
()
{
it
(
"can withdraw payment"
,
async
function
()
{
...
@@ -48,10 +55,16 @@ contract('PullPayment', function(accounts) {
...
@@ -48,10 +55,16 @@ contract('PullPayment', function(accounts) {
let
payment1
=
await
ppce
.
payments
(
payee
);
let
payment1
=
await
ppce
.
payments
(
payee
);
assert
.
equal
(
payment1
,
AMOUNT
);
assert
.
equal
(
payment1
,
AMOUNT
);
let
totalPayments
=
await
ppce
.
totalPayments
();
assert
.
equal
(
totalPayments
,
AMOUNT
);
let
withdraw
=
await
ppce
.
withdrawPayments
({
from
:
payee
});
let
withdraw
=
await
ppce
.
withdrawPayments
({
from
:
payee
});
let
payment2
=
await
ppce
.
payments
(
payee
);
let
payment2
=
await
ppce
.
payments
(
payee
);
assert
.
equal
(
payment2
,
0
);
assert
.
equal
(
payment2
,
0
);
totalPayments
=
await
ppce
.
totalPayments
();
assert
.
equal
(
totalPayments
,
0
);
let
balance
=
web3
.
eth
.
getBalance
(
payee
);
let
balance
=
web3
.
eth
.
getBalance
(
payee
);
assert
(
Math
.
abs
(
balance
-
initialBalance
-
AMOUNT
)
<
1
e16
);
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