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
94797978
Unverified
Commit
94797978
authored
Aug 06, 2018
by
Nicolás Venturo
Committed by
GitHub
Aug 06, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SplitPayment now requires payees. (#1131)
* SplitPayment now requires payees. * Improved test phrasing.
parent
31ac59b2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
57 deletions
+72
-57
SplitPayment.sol
contracts/payment/SplitPayment.sol
+1
-0
SplitPayment.test.js
test/payment/SplitPayment.test.js
+71
-57
No files found.
contracts/payment/SplitPayment.sol
View file @
94797978
...
@@ -23,6 +23,7 @@ contract SplitPayment {
...
@@ -23,6 +23,7 @@ contract SplitPayment {
*/
*/
constructor(address[] _payees, uint256[] _shares) public payable {
constructor(address[] _payees, uint256[] _shares) public payable {
require(_payees.length == _shares.length);
require(_payees.length == _shares.length);
require(_payees.length > 0);
for (uint256 i = 0; i < _payees.length; i++) {
for (uint256 i = 0; i < _payees.length; i++) {
addPayee(_payees[i], _shares[i]);
addPayee(_payees[i], _shares[i]);
...
...
test/payment/SplitPayment.test.js
View file @
94797978
...
@@ -13,68 +13,82 @@ const SplitPayment = artifacts.require('SplitPayment');
...
@@ -13,68 +13,82 @@ const SplitPayment = artifacts.require('SplitPayment');
contract
(
'SplitPayment'
,
function
([
_
,
owner
,
payee1
,
payee2
,
payee3
,
nonpayee1
,
payer1
])
{
contract
(
'SplitPayment'
,
function
([
_
,
owner
,
payee1
,
payee2
,
payee3
,
nonpayee1
,
payer1
])
{
const
amount
=
web3
.
toWei
(
1.0
,
'ether'
);
const
amount
=
web3
.
toWei
(
1.0
,
'ether'
);
beforeEach
(
async
function
()
{
it
(
'cannot be created with no payees'
,
async
function
()
{
this
.
payees
=
[
payee1
,
payee2
,
payee3
];
await
expectThrow
(
SplitPayment
.
new
([],
[]),
EVMThrow
);
this
.
shares
=
[
20
,
10
,
70
];
this
.
contract
=
await
SplitPayment
.
new
(
this
.
payees
,
this
.
shares
);
});
it
(
'should accept payments'
,
async
function
()
{
await
ethSendTransaction
({
from
:
owner
,
to
:
this
.
contract
.
address
,
value
:
amount
});
const
balance
=
await
ethGetBalance
(
this
.
contract
.
address
);
balance
.
should
.
be
.
bignumber
.
equal
(
amount
);
});
it
(
'should store shares if address is payee'
,
async
function
()
{
const
shares
=
await
this
.
contract
.
shares
.
call
(
payee1
);
shares
.
should
.
be
.
bignumber
.
not
.
equal
(
0
);
});
it
(
'should not store shares if address is not payee'
,
async
function
()
{
const
shares
=
await
this
.
contract
.
shares
.
call
(
nonpayee1
);
shares
.
should
.
be
.
bignumber
.
equal
(
0
);
});
});
it
(
'
should throw if no funds to claim
'
,
async
function
()
{
it
(
'
requires shares for each payee
'
,
async
function
()
{
await
expectThrow
(
this
.
contract
.
claim
({
from
:
payee1
}
),
EVMThrow
);
await
expectThrow
(
SplitPayment
.
new
([
payee1
,
payee2
,
payee3
],
[
20
,
30
]
),
EVMThrow
);
});
});
it
(
'should throw if non-payee want to claim'
,
async
function
()
{
it
(
'requires a payee for each share'
,
async
function
()
{
await
ethSendTransaction
({
from
:
payer1
,
to
:
this
.
contract
.
address
,
value
:
amount
});
await
expectThrow
(
SplitPayment
.
new
([
payee1
,
payee2
],
[
20
,
30
,
40
]),
EVMThrow
);
await
expectThrow
(
this
.
contract
.
claim
({
from
:
nonpayee1
}),
EVMThrow
);
});
});
it
(
'should distribute funds to payees'
,
async
function
()
{
context
(
'once deployed'
,
function
()
{
await
ethSendTransaction
({
from
:
payer1
,
to
:
this
.
contract
.
address
,
value
:
amount
});
beforeEach
(
async
function
()
{
this
.
payees
=
[
payee1
,
payee2
,
payee3
];
// receive funds
this
.
shares
=
[
20
,
10
,
70
];
const
initBalance
=
await
ethGetBalance
(
this
.
contract
.
address
);
initBalance
.
should
.
be
.
bignumber
.
equal
(
amount
);
this
.
contract
=
await
SplitPayment
.
new
(
this
.
payees
,
this
.
shares
);
});
// distribute to payees
const
initAmount1
=
await
ethGetBalance
(
payee1
);
it
(
'should accept payments'
,
async
function
()
{
await
this
.
contract
.
claim
({
from
:
payee1
});
await
ethSendTransaction
({
from
:
owner
,
to
:
this
.
contract
.
address
,
value
:
amount
});
const
profit1
=
await
ethGetBalance
(
payee1
)
-
initAmount1
;
assert
(
Math
.
abs
(
profit1
-
web3
.
toWei
(
0.20
,
'ether'
))
<
1
e16
);
const
balance
=
await
ethGetBalance
(
this
.
contract
.
address
);
balance
.
should
.
be
.
bignumber
.
equal
(
amount
);
const
initAmount2
=
await
ethGetBalance
(
payee2
);
});
await
this
.
contract
.
claim
({
from
:
payee2
});
const
profit2
=
await
ethGetBalance
(
payee2
)
-
initAmount2
;
it
(
'should store shares if address is payee'
,
async
function
()
{
assert
(
Math
.
abs
(
profit2
-
web3
.
toWei
(
0.10
,
'ether'
))
<
1
e16
);
const
shares
=
await
this
.
contract
.
shares
.
call
(
payee1
);
shares
.
should
.
be
.
bignumber
.
not
.
equal
(
0
);
const
initAmount3
=
await
ethGetBalance
(
payee3
);
});
await
this
.
contract
.
claim
({
from
:
payee3
});
const
profit3
=
await
ethGetBalance
(
payee3
)
-
initAmount3
;
it
(
'should not store shares if address is not payee'
,
async
function
()
{
assert
(
Math
.
abs
(
profit3
-
web3
.
toWei
(
0.70
,
'ether'
))
<
1
e16
);
const
shares
=
await
this
.
contract
.
shares
.
call
(
nonpayee1
);
shares
.
should
.
be
.
bignumber
.
equal
(
0
);
// end balance should be zero
});
const
endBalance
=
await
ethGetBalance
(
this
.
contract
.
address
);
endBalance
.
should
.
be
.
bignumber
.
equal
(
0
);
it
(
'should throw if no funds to claim'
,
async
function
()
{
await
expectThrow
(
this
.
contract
.
claim
({
from
:
payee1
}),
EVMThrow
);
// check correct funds released accounting
});
const
totalReleased
=
await
this
.
contract
.
totalReleased
.
call
();
totalReleased
.
should
.
be
.
bignumber
.
equal
(
initBalance
);
it
(
'should throw if non-payee want to claim'
,
async
function
()
{
await
ethSendTransaction
({
from
:
payer1
,
to
:
this
.
contract
.
address
,
value
:
amount
});
await
expectThrow
(
this
.
contract
.
claim
({
from
:
nonpayee1
}),
EVMThrow
);
});
it
(
'should distribute funds to payees'
,
async
function
()
{
await
ethSendTransaction
({
from
:
payer1
,
to
:
this
.
contract
.
address
,
value
:
amount
});
// receive funds
const
initBalance
=
await
ethGetBalance
(
this
.
contract
.
address
);
initBalance
.
should
.
be
.
bignumber
.
equal
(
amount
);
// distribute to payees
const
initAmount1
=
await
ethGetBalance
(
payee1
);
await
this
.
contract
.
claim
({
from
:
payee1
});
const
profit1
=
await
ethGetBalance
(
payee1
)
-
initAmount1
;
assert
(
Math
.
abs
(
profit1
-
web3
.
toWei
(
0.20
,
'ether'
))
<
1
e16
);
const
initAmount2
=
await
ethGetBalance
(
payee2
);
await
this
.
contract
.
claim
({
from
:
payee2
});
const
profit2
=
await
ethGetBalance
(
payee2
)
-
initAmount2
;
assert
(
Math
.
abs
(
profit2
-
web3
.
toWei
(
0.10
,
'ether'
))
<
1
e16
);
const
initAmount3
=
await
ethGetBalance
(
payee3
);
await
this
.
contract
.
claim
({
from
:
payee3
});
const
profit3
=
await
ethGetBalance
(
payee3
)
-
initAmount3
;
assert
(
Math
.
abs
(
profit3
-
web3
.
toWei
(
0.70
,
'ether'
))
<
1
e16
);
// end balance should be zero
const
endBalance
=
await
ethGetBalance
(
this
.
contract
.
address
);
endBalance
.
should
.
be
.
bignumber
.
equal
(
0
);
// check correct funds released accounting
const
totalReleased
=
await
this
.
contract
.
totalReleased
.
call
();
totalReleased
.
should
.
be
.
bignumber
.
equal
(
initBalance
);
});
});
});
});
});
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