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
40b5594f
Commit
40b5594f
authored
Jul 10, 2018
by
Arun Kumar
Committed by
Matt Condon
Jul 10, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Promisify web3 sync requests in tests (#1009)
parent
4575a240
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
137 additions
and
104 deletions
+137
-104
Bounty.test.js
test/Bounty.test.js
+22
-21
LimitBalance.test.js
test/LimitBalance.test.js
+10
-4
SimpleSavingsWallet.test.js
test/SimpleSavingsWallet.test.js
+8
-5
AllowanceCrowdsale.test.js
test/crowdsale/AllowanceCrowdsale.test.js
+4
-2
Crowdsale.test.js
test/crowdsale/Crowdsale.test.js
+5
-4
FinalizableCrowdsale.test.js
test/crowdsale/FinalizableCrowdsale.test.js
+1
-1
IncreasingPriceCrowdsale.test.js
test/crowdsale/IncreasingPriceCrowdsale.test.js
+1
-1
MintedCrowdsale.behaviour.js
test/crowdsale/MintedCrowdsale.behaviour.js
+4
-2
PostDeliveryCrowdsale.test.js
test/crowdsale/PostDeliveryCrowdsale.test.js
+1
-1
RefundableCrowdsale.test.js
test/crowdsale/RefundableCrowdsale.test.js
+6
-5
TimedCrowdsale.test.js
test/crowdsale/TimedCrowdsale.test.js
+1
-1
SampleCrowdsale.test.js
test/examples/SampleCrowdsale.test.js
+6
-5
SimpleToken.test.js
test/examples/SimpleToken.test.js
+1
-1
increaseTime.js
test/helpers/increaseTime.js
+2
-2
latestTime.js
test/helpers/latestTime.js
+5
-2
toPromise.js
test/helpers/toPromise.js
+0
-4
web3.js
test/helpers/web3.js
+7
-0
Destructible.test.js
test/lifecycle/Destructible.test.js
+6
-5
TokenDestructible.test.js
test/lifecycle/TokenDestructible.test.js
+3
-2
HasNoEther.test.js
test/ownership/HasNoEther.test.js
+9
-9
Escrow.behaviour.js
test/payment/Escrow.behaviour.js
+7
-6
PullPayment.test.js
test/payment/PullPayment.test.js
+4
-2
RefundEscrow.test.js
test/payment/RefundEscrow.test.js
+5
-4
SplitPayment.test.js
test/payment/SplitPayment.test.js
+14
-12
TokenTimelock.test.js
test/token/ERC20/TokenTimelock.test.js
+1
-1
TokenVesting.test.js
test/token/ERC20/TokenVesting.test.js
+4
-2
No files found.
test/Bounty.test.js
View file @
40b5594f
import
{
ethGetBalance
,
ethSendTransaction
}
from
'./helpers/web3'
;
let
sendReward
=
function
(
sender
,
receiver
,
value
)
{
web3
.
eth
.
sendTransaction
({
from
:
sender
,
to
:
receiver
,
value
:
value
,
});
};
const
sendReward
=
async
(
from
,
to
,
value
)
=>
ethSendTransaction
({
from
,
to
,
value
,
});
var
SecureTargetBounty
=
artifacts
.
require
(
'SecureTargetBounty'
);
var
InsecureTargetBounty
=
artifacts
.
require
(
'InsecureTargetBounty'
);
...
...
@@ -24,21 +21,24 @@ contract('Bounty', function (accounts) {
let
owner
=
accounts
[
0
];
let
reward
=
web3
.
toWei
(
1
,
'ether'
);
let
bounty
=
await
SecureTargetBounty
.
new
();
sendReward
(
owner
,
bounty
.
address
,
reward
);
await
sendReward
(
owner
,
bounty
.
address
,
reward
);
assert
.
equal
(
reward
,
web3
.
eth
.
getBalance
(
bounty
.
address
).
toNumber
());
const
balance
=
await
ethGetBalance
(
bounty
.
address
);
assert
.
equal
(
reward
,
balance
.
toNumber
());
});
it
(
'empties itself when destroyed'
,
async
function
()
{
let
owner
=
accounts
[
0
];
let
reward
=
web3
.
toWei
(
1
,
'ether'
);
let
bounty
=
await
SecureTargetBounty
.
new
();
sendReward
(
owner
,
bounty
.
address
,
reward
);
await
sendReward
(
owner
,
bounty
.
address
,
reward
);
assert
.
equal
(
reward
,
web3
.
eth
.
getBalance
(
bounty
.
address
).
toNumber
());
const
balance
=
await
ethGetBalance
(
bounty
.
address
);
assert
.
equal
(
reward
,
balance
.
toNumber
());
await
bounty
.
destroy
();
assert
.
equal
(
0
,
web3
.
eth
.
getBalance
(
bounty
.
address
).
toNumber
());
const
updatedBalance
=
await
ethGetBalance
(
bounty
.
address
);
assert
.
equal
(
0
,
updatedBalance
.
toNumber
());
});
describe
(
'Against secure contract'
,
function
()
{
...
...
@@ -54,10 +54,10 @@ contract('Bounty', function (accounts) {
if
(
err
)
{
throw
err
;
}
var
targetAddress
=
result
.
args
.
createdAddress
;
sendReward
(
owner
,
bounty
.
address
,
reward
);
await
sendReward
(
owner
,
bounty
.
address
,
reward
);
assert
.
equal
(
reward
,
web3
.
eth
.
getBalance
(
bounty
.
address
)
.
toNumber
());
const
balance
=
await
ethGetBalance
(
bounty
.
address
);
assert
.
equal
(
reward
,
balance
.
toNumber
());
try
{
await
bounty
.
claim
(
targetAddress
,
{
from
:
researcher
});
...
...
@@ -70,8 +70,8 @@ contract('Bounty', function (accounts) {
await
bounty
.
withdrawPayments
({
from
:
researcher
});
assert
.
isTrue
(
false
);
// should never reach here
}
catch
(
err
)
{
assert
.
equal
(
reward
,
web3
.
eth
.
getBalance
(
bounty
.
address
)
.
toNumber
());
const
updatedBalance
=
await
ethGetBalance
(
bounty
.
address
);
assert
.
equal
(
reward
,
updatedBalance
.
toNumber
());
}
};
await
bounty
.
createTarget
({
from
:
researcher
});
...
...
@@ -91,9 +91,10 @@ contract('Bounty', function (accounts) {
event
.
stopWatching
();
if
(
err
)
{
throw
err
;
}
let
targetAddress
=
result
.
args
.
createdAddress
;
sendReward
(
owner
,
bounty
.
address
,
reward
);
await
sendReward
(
owner
,
bounty
.
address
,
reward
);
assert
.
equal
(
reward
,
web3
.
eth
.
getBalance
(
bounty
.
address
).
toNumber
());
const
balance
=
await
ethGetBalance
(
bounty
.
address
);
assert
.
equal
(
reward
,
balance
.
toNumber
());
await
bounty
.
claim
(
targetAddress
,
{
from
:
researcher
});
let
claim
=
await
bounty
.
claimed
.
call
();
...
...
@@ -101,8 +102,8 @@ contract('Bounty', function (accounts) {
assert
.
isTrue
(
claim
);
await
bounty
.
withdrawPayments
({
from
:
researcher
});
assert
.
equal
(
0
,
web3
.
eth
.
getBalance
(
bounty
.
address
)
.
toNumber
());
const
updatedBalance
=
await
ethGetBalance
(
bounty
.
address
);
assert
.
equal
(
0
,
updatedBalance
.
toNumber
());
};
await
bounty
.
createTarget
({
from
:
researcher
});
await
awaitEvent
(
event
,
watcher
);
...
...
test/LimitBalance.test.js
View file @
40b5594f
import
assertRevert
from
'./helpers/assertRevert'
;
import
{
ethGetBalance
}
from
'./helpers/web3'
;
var
LimitBalanceMock
=
artifacts
.
require
(
'LimitBalanceMock'
);
contract
(
'LimitBalance'
,
function
(
accounts
)
{
...
...
@@ -19,7 +21,8 @@ contract('LimitBalance', function (accounts) {
let
amount
=
1
;
await
lb
.
limitedDeposit
({
value
:
amount
});
assert
.
equal
(
web3
.
eth
.
getBalance
(
lb
.
address
),
amount
);
const
balance
=
await
ethGetBalance
(
lb
.
address
);
assert
.
equal
(
balance
,
amount
);
});
it
(
'shouldnt allow sending above limit'
,
async
function
()
{
...
...
@@ -31,17 +34,20 @@ contract('LimitBalance', function (accounts) {
let
amount
=
500
;
await
lb
.
limitedDeposit
({
value
:
amount
});
assert
.
equal
(
web3
.
eth
.
getBalance
(
lb
.
address
),
amount
);
const
balance
=
await
ethGetBalance
(
lb
.
address
);
assert
.
equal
(
balance
,
amount
);
await
lb
.
limitedDeposit
({
value
:
amount
});
assert
.
equal
(
web3
.
eth
.
getBalance
(
lb
.
address
),
amount
*
2
);
const
updatedBalance
=
await
ethGetBalance
(
lb
.
address
);
assert
.
equal
(
updatedBalance
,
amount
*
2
);
});
it
(
'shouldnt allow multiple sends above limit'
,
async
function
()
{
let
amount
=
500
;
await
lb
.
limitedDeposit
({
value
:
amount
});
assert
.
equal
(
web3
.
eth
.
getBalance
(
lb
.
address
),
amount
);
const
balance
=
await
ethGetBalance
(
lb
.
address
);
assert
.
equal
(
balance
,
amount
);
await
assertRevert
(
lb
.
limitedDeposit
({
value
:
amount
+
1
}));
});
});
test/SimpleSavingsWallet.test.js
View file @
40b5594f
import
expectThrow
from
'./helpers/expectThrow'
;
import
{
ethGetBalance
,
ethSendTransaction
}
from
'./helpers/web3'
;
const
SimpleSavingsWallet
=
artifacts
.
require
(
'SimpleSavingsWallet'
);
...
...
@@ -15,19 +16,21 @@ contract('SimpleSavingsWallet', function (accounts) {
});
it
(
'should receive funds'
,
async
function
()
{
await
web3
.
eth
.
sendTransaction
({
from
:
owner
,
to
:
savingsWallet
.
address
,
value
:
paymentAmount
});
assert
.
isTrue
((
new
web3
.
BigNumber
(
paymentAmount
)).
equals
(
web3
.
eth
.
getBalance
(
savingsWallet
.
address
)));
await
ethSendTransaction
({
from
:
owner
,
to
:
savingsWallet
.
address
,
value
:
paymentAmount
});
const
balance
=
await
ethGetBalance
(
savingsWallet
.
address
);
assert
.
isTrue
((
new
web3
.
BigNumber
(
paymentAmount
)).
equals
(
balance
));
});
it
(
'owner can send funds'
,
async
function
()
{
// Receive payment so we have some money to spend.
await
web3
.
eth
.
s
endTransaction
({
from
:
accounts
[
9
],
to
:
savingsWallet
.
address
,
value
:
1000000
});
await
ethS
endTransaction
({
from
:
accounts
[
9
],
to
:
savingsWallet
.
address
,
value
:
1000000
});
await
expectThrow
(
savingsWallet
.
sendTo
(
0
,
paymentAmount
,
{
from
:
owner
}));
await
expectThrow
(
savingsWallet
.
sendTo
(
savingsWallet
.
address
,
paymentAmount
,
{
from
:
owner
}));
await
expectThrow
(
savingsWallet
.
sendTo
(
accounts
[
1
],
0
,
{
from
:
owner
}));
const
balance
=
web3
.
eth
.
g
etBalance
(
accounts
[
1
]);
const
balance
=
await
ethG
etBalance
(
accounts
[
1
]);
await
savingsWallet
.
sendTo
(
accounts
[
1
],
paymentAmount
,
{
from
:
owner
});
assert
.
isTrue
(
balance
.
plus
(
paymentAmount
).
equals
(
web3
.
eth
.
getBalance
(
accounts
[
1
])));
const
updatedBalance
=
await
ethGetBalance
(
accounts
[
1
]);
assert
.
isTrue
(
balance
.
plus
(
paymentAmount
).
equals
(
updatedBalance
));
});
});
test/crowdsale/AllowanceCrowdsale.test.js
View file @
40b5594f
import
ether
from
'../helpers/ether'
;
import
assertRevert
from
'../helpers/assertRevert'
;
import
{
ethGetBalance
}
from
'../helpers/web3'
;
const
BigNumber
=
web3
.
BigNumber
;
...
...
@@ -52,9 +54,9 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
});
it
(
'should forward funds to wallet'
,
async
function
()
{
const
pre
=
web3
.
eth
.
g
etBalance
(
wallet
);
const
pre
=
await
ethG
etBalance
(
wallet
);
await
this
.
crowdsale
.
sendTransaction
({
value
,
from
:
investor
});
const
post
=
web3
.
eth
.
g
etBalance
(
wallet
);
const
post
=
await
ethG
etBalance
(
wallet
);
post
.
minus
(
pre
).
should
.
be
.
bignumber
.
equal
(
value
);
});
});
...
...
test/crowdsale/Crowdsale.test.js
View file @
40b5594f
import
ether
from
'../helpers/ether'
;
import
{
ethGetBalance
}
from
'../helpers/web3'
;
const
BigNumber
=
web3
.
BigNumber
;
...
...
@@ -47,9 +48,9 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
});
it
(
'should forward funds to wallet'
,
async
function
()
{
const
pre
=
web3
.
eth
.
g
etBalance
(
wallet
);
const
pre
=
await
ethG
etBalance
(
wallet
);
await
this
.
crowdsale
.
sendTransaction
({
value
,
from
:
investor
});
const
post
=
web3
.
eth
.
g
etBalance
(
wallet
);
const
post
=
await
ethG
etBalance
(
wallet
);
post
.
minus
(
pre
).
should
.
be
.
bignumber
.
equal
(
value
);
});
});
...
...
@@ -72,9 +73,9 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
});
it
(
'should forward funds to wallet'
,
async
function
()
{
const
pre
=
web3
.
eth
.
g
etBalance
(
wallet
);
const
pre
=
await
ethG
etBalance
(
wallet
);
await
this
.
crowdsale
.
buyTokens
(
investor
,
{
value
,
from
:
purchaser
});
const
post
=
web3
.
eth
.
g
etBalance
(
wallet
);
const
post
=
await
ethG
etBalance
(
wallet
);
post
.
minus
(
pre
).
should
.
be
.
bignumber
.
equal
(
value
);
});
});
...
...
test/crowdsale/FinalizableCrowdsale.test.js
View file @
40b5594f
...
...
@@ -22,7 +22,7 @@ contract('FinalizableCrowdsale', function ([_, owner, wallet, thirdparty]) {
});
beforeEach
(
async
function
()
{
this
.
openingTime
=
latestTime
(
)
+
duration
.
weeks
(
1
);
this
.
openingTime
=
(
await
latestTime
()
)
+
duration
.
weeks
(
1
);
this
.
closingTime
=
this
.
openingTime
+
duration
.
weeks
(
1
);
this
.
afterClosingTime
=
this
.
closingTime
+
duration
.
seconds
(
1
);
...
...
test/crowdsale/IncreasingPriceCrowdsale.test.js
View file @
40b5594f
...
...
@@ -30,7 +30,7 @@ contract('IncreasingPriceCrowdsale', function ([_, investor, wallet, purchaser])
beforeEach
(
async
function
()
{
await
advanceBlock
();
this
.
startTime
=
latestTime
(
)
+
duration
.
weeks
(
1
);
this
.
startTime
=
(
await
latestTime
()
)
+
duration
.
weeks
(
1
);
this
.
closingTime
=
this
.
startTime
+
duration
.
weeks
(
1
);
this
.
afterClosingTime
=
this
.
closingTime
+
duration
.
seconds
(
1
);
this
.
token
=
await
SimpleToken
.
new
();
...
...
test/crowdsale/MintedCrowdsale.behaviour.js
View file @
40b5594f
import
{
ethGetBalance
}
from
'../helpers/web3'
;
const
BigNumber
=
web3
.
BigNumber
;
const
should
=
require
(
'chai'
)
...
...
@@ -34,9 +36,9 @@ export default function ([_, investor, wallet, purchaser], rate, value) {
});
it
(
'should forward funds to wallet'
,
async
function
()
{
const
pre
=
web3
.
eth
.
g
etBalance
(
wallet
);
const
pre
=
await
ethG
etBalance
(
wallet
);
await
this
.
crowdsale
.
sendTransaction
({
value
,
from
:
investor
});
const
post
=
web3
.
eth
.
g
etBalance
(
wallet
);
const
post
=
await
ethG
etBalance
(
wallet
);
post
.
minus
(
pre
).
should
.
be
.
bignumber
.
equal
(
value
);
});
});
...
...
test/crowdsale/PostDeliveryCrowdsale.test.js
View file @
40b5594f
...
...
@@ -25,7 +25,7 @@ contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) {
});
beforeEach
(
async
function
()
{
this
.
openingTime
=
latestTime
(
)
+
duration
.
weeks
(
1
);
this
.
openingTime
=
(
await
latestTime
()
)
+
duration
.
weeks
(
1
);
this
.
closingTime
=
this
.
openingTime
+
duration
.
weeks
(
1
);
this
.
beforeEndTime
=
this
.
closingTime
-
duration
.
hours
(
1
);
this
.
afterClosingTime
=
this
.
closingTime
+
duration
.
seconds
(
1
);
...
...
test/crowdsale/RefundableCrowdsale.test.js
View file @
40b5594f
...
...
@@ -3,6 +3,7 @@ import { advanceBlock } from '../helpers/advanceToBlock';
import
{
increaseTimeTo
,
duration
}
from
'../helpers/increaseTime'
;
import
latestTime
from
'../helpers/latestTime'
;
import
EVMRevert
from
'../helpers/EVMRevert'
;
import
{
ethGetBalance
}
from
'../helpers/web3'
;
const
BigNumber
=
web3
.
BigNumber
;
...
...
@@ -26,7 +27,7 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor, purchaser
});
beforeEach
(
async
function
()
{
this
.
openingTime
=
latestTime
(
)
+
duration
.
weeks
(
1
);
this
.
openingTime
=
(
await
latestTime
()
)
+
duration
.
weeks
(
1
);
this
.
closingTime
=
this
.
openingTime
+
duration
.
weeks
(
1
);
this
.
afterClosingTime
=
this
.
closingTime
+
duration
.
seconds
(
1
);
...
...
@@ -63,10 +64,10 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor, purchaser
await
this
.
crowdsale
.
sendTransaction
({
value
:
lessThanGoal
,
from
:
investor
});
await
increaseTimeTo
(
this
.
afterClosingTime
);
await
this
.
crowdsale
.
finalize
({
from
:
owner
});
const
pre
=
web3
.
eth
.
g
etBalance
(
investor
);
const
pre
=
await
ethG
etBalance
(
investor
);
await
this
.
crowdsale
.
claimRefund
({
from
:
investor
,
gasPrice
:
0
})
.
should
.
be
.
fulfilled
;
const
post
=
web3
.
eth
.
g
etBalance
(
investor
);
const
post
=
await
ethG
etBalance
(
investor
);
post
.
minus
(
pre
).
should
.
be
.
bignumber
.
equal
(
lessThanGoal
);
});
...
...
@@ -74,9 +75,9 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor, purchaser
await
increaseTimeTo
(
this
.
openingTime
);
await
this
.
crowdsale
.
sendTransaction
({
value
:
goal
,
from
:
investor
});
await
increaseTimeTo
(
this
.
afterClosingTime
);
const
pre
=
web3
.
eth
.
g
etBalance
(
wallet
);
const
pre
=
await
ethG
etBalance
(
wallet
);
await
this
.
crowdsale
.
finalize
({
from
:
owner
});
const
post
=
web3
.
eth
.
g
etBalance
(
wallet
);
const
post
=
await
ethG
etBalance
(
wallet
);
post
.
minus
(
pre
).
should
.
be
.
bignumber
.
equal
(
goal
);
});
});
test/crowdsale/TimedCrowdsale.test.js
View file @
40b5594f
...
...
@@ -25,7 +25,7 @@ contract('TimedCrowdsale', function ([_, investor, wallet, purchaser]) {
});
beforeEach
(
async
function
()
{
this
.
openingTime
=
latestTime
(
)
+
duration
.
weeks
(
1
);
this
.
openingTime
=
(
await
latestTime
()
)
+
duration
.
weeks
(
1
);
this
.
closingTime
=
this
.
openingTime
+
duration
.
weeks
(
1
);
this
.
afterClosingTime
=
this
.
closingTime
+
duration
.
seconds
(
1
);
this
.
token
=
await
SimpleToken
.
new
();
...
...
test/examples/SampleCrowdsale.test.js
View file @
40b5594f
...
...
@@ -4,6 +4,7 @@ import { increaseTimeTo, duration } from '../helpers/increaseTime';
import
latestTime
from
'../helpers/latestTime'
;
import
EVMRevert
from
'../helpers/EVMRevert'
;
import
assertRevert
from
'../helpers/assertRevert'
;
import
{
ethGetBalance
}
from
'../helpers/web3'
;
const
BigNumber
=
web3
.
BigNumber
;
...
...
@@ -26,7 +27,7 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) {
});
beforeEach
(
async
function
()
{
this
.
openingTime
=
latestTime
(
)
+
duration
.
weeks
(
1
);
this
.
openingTime
=
(
await
latestTime
()
)
+
duration
.
weeks
(
1
);
this
.
closingTime
=
this
.
openingTime
+
duration
.
weeks
(
1
);
this
.
afterClosingTime
=
this
.
closingTime
+
duration
.
seconds
(
1
);
...
...
@@ -88,16 +89,16 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) {
await
increaseTimeTo
(
this
.
openingTime
);
await
this
.
crowdsale
.
send
(
GOAL
);
const
beforeFinalization
=
web3
.
eth
.
g
etBalance
(
wallet
);
const
beforeFinalization
=
await
ethG
etBalance
(
wallet
);
await
increaseTimeTo
(
this
.
afterClosingTime
);
await
this
.
crowdsale
.
finalize
({
from
:
owner
});
const
afterFinalization
=
web3
.
eth
.
g
etBalance
(
wallet
);
const
afterFinalization
=
await
ethG
etBalance
(
wallet
);
afterFinalization
.
minus
(
beforeFinalization
).
should
.
be
.
bignumber
.
equal
(
GOAL
);
});
it
(
'should allow refunds if the goal is not reached'
,
async
function
()
{
const
balanceBeforeInvestment
=
web3
.
eth
.
g
etBalance
(
investor
);
const
balanceBeforeInvestment
=
await
ethG
etBalance
(
investor
);
await
increaseTimeTo
(
this
.
openingTime
);
await
this
.
crowdsale
.
sendTransaction
({
value
:
ether
(
1
),
from
:
investor
,
gasPrice
:
0
});
...
...
@@ -106,7 +107,7 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) {
await
this
.
crowdsale
.
finalize
({
from
:
owner
});
await
this
.
crowdsale
.
claimRefund
({
from
:
investor
,
gasPrice
:
0
}).
should
.
be
.
fulfilled
;
const
balanceAfterRefund
=
web3
.
eth
.
g
etBalance
(
investor
);
const
balanceAfterRefund
=
await
ethG
etBalance
(
investor
);
balanceBeforeInvestment
.
should
.
be
.
bignumber
.
equal
(
balanceAfterRefund
);
});
...
...
test/examples/SimpleToken.test.js
View file @
40b5594f
...
...
@@ -30,7 +30,7 @@ contract('SimpleToken', accounts => {
assert
(
creatorBalance
.
eq
(
totalSupply
));
const
receipt
=
web3
.
eth
.
getTransactionReceipt
(
token
.
transactionHash
);
const
receipt
=
await
web3
.
eth
.
getTransactionReceipt
(
token
.
transactionHash
);
const
logs
=
decodeLogs
(
receipt
.
logs
,
SimpleToken
,
token
.
address
);
assert
.
equal
(
logs
.
length
,
1
);
assert
.
equal
(
logs
[
0
].
event
,
'Transfer'
);
...
...
test/helpers/increaseTime.js
View file @
40b5594f
...
...
@@ -31,8 +31,8 @@ export default function increaseTime (duration) {
*
* @param target time in seconds
*/
export
function
increaseTimeTo
(
target
)
{
let
now
=
latestTime
(
);
export
async
function
increaseTimeTo
(
target
)
{
let
now
=
(
await
latestTime
()
);
if
(
target
<
now
)
throw
Error
(
`Cannot increase current time(
${
now
}
) to a moment in the past(
${
target
}
)`
);
let
diff
=
target
-
now
;
return
increaseTime
(
diff
);
...
...
test/helpers/latestTime.js
View file @
40b5594f
import
{
ethGetBlock
}
from
'./web3'
;
// Returns the time of the last mined block in seconds
export
default
function
latestTime
()
{
return
web3
.
eth
.
getBlock
(
'latest'
).
timestamp
;
export
default
async
function
latestTime
()
{
const
block
=
await
ethGetBlock
(
'latest'
);
return
block
.
timestamp
;
}
test/helpers/toPromise.js
deleted
100644 → 0
View file @
4575a240
export
default
func
=>
(...
args
)
=>
new
Promise
((
resolve
,
reject
)
=>
func
(...
args
,
(
error
,
data
)
=>
error
?
reject
(
error
)
:
resolve
(
data
)));
test/helpers/web3.js
0 → 100644
View file @
40b5594f
const
pify
=
require
(
'pify'
);
const
ethAsync
=
pify
(
web3
.
eth
);
export
const
ethGetBalance
=
ethAsync
.
getBalance
;
export
const
ethSendTransaction
=
ethAsync
.
sendTransaction
;
export
const
ethGetBlock
=
ethAsync
.
getBlock
;
test/lifecycle/Destructible.test.js
View file @
40b5594f
import
{
ethGetBalance
}
from
'../helpers/web3'
;
var
Destructible
=
artifacts
.
require
(
'Destructible'
);
const
Destructible
=
artifacts
.
require
(
'Destructible'
);
require
(
'../helpers/transactionMined.js'
);
contract
(
'Destructible'
,
function
(
accounts
)
{
it
(
'should send balance to owner after destruction'
,
async
function
()
{
let
destructible
=
await
Destructible
.
new
({
from
:
accounts
[
0
],
value
:
web3
.
toWei
(
'10'
,
'ether'
)
});
let
owner
=
await
destructible
.
owner
();
let
initBalance
=
web3
.
eth
.
g
etBalance
(
owner
);
let
initBalance
=
await
ethG
etBalance
(
owner
);
await
destructible
.
destroy
({
from
:
owner
});
let
newBalance
=
web3
.
eth
.
g
etBalance
(
owner
);
let
newBalance
=
await
ethG
etBalance
(
owner
);
assert
.
isTrue
(
newBalance
>
initBalance
);
});
it
(
'should send balance to recepient after destruction'
,
async
function
()
{
let
destructible
=
await
Destructible
.
new
({
from
:
accounts
[
0
],
value
:
web3
.
toWei
(
'10'
,
'ether'
)
});
let
owner
=
await
destructible
.
owner
();
let
initBalance
=
web3
.
eth
.
g
etBalance
(
accounts
[
1
]);
let
initBalance
=
await
ethG
etBalance
(
accounts
[
1
]);
await
destructible
.
destroyAndSend
(
accounts
[
1
],
{
from
:
owner
});
let
newBalance
=
web3
.
eth
.
g
etBalance
(
accounts
[
1
]);
let
newBalance
=
await
ethG
etBalance
(
accounts
[
1
]);
assert
.
isTrue
(
newBalance
.
greaterThan
(
initBalance
));
});
});
test/lifecycle/TokenDestructible.test.js
View file @
40b5594f
import
{
ethGetBalance
}
from
'../helpers/web3'
;
var
TokenDestructible
=
artifacts
.
require
(
'TokenDestructible'
);
var
StandardTokenMock
=
artifacts
.
require
(
'StandardTokenMock'
);
...
...
@@ -15,9 +16,9 @@ contract('TokenDestructible', function (accounts) {
it
(
'should send balance to owner after destruction'
,
async
function
()
{
let
owner
=
await
destructible
.
owner
();
let
initBalance
=
web3
.
eth
.
g
etBalance
(
owner
);
let
initBalance
=
await
ethG
etBalance
(
owner
);
await
destructible
.
destroy
([],
{
from
:
owner
});
let
newBalance
=
web3
.
eth
.
g
etBalance
(
owner
);
let
newBalance
=
await
ethG
etBalance
(
owner
);
assert
.
isTrue
(
newBalance
>
initBalance
);
});
...
...
test/ownership/HasNoEther.test.js
View file @
40b5594f
import
{
ethSendTransaction
,
ethGetBalance
}
from
'../helpers/web3'
;
import
expectThrow
from
'../helpers/expectThrow'
;
import
toPromise
from
'../helpers/toPromise'
;
const
HasNoEtherTest
=
artifacts
.
require
(
'HasNoEtherTest'
);
const
ForceEther
=
artifacts
.
require
(
'ForceEther'
);
...
...
@@ -19,7 +19,7 @@ contract('HasNoEther', function (accounts) {
let
hasNoEther
=
await
HasNoEtherTest
.
new
();
await
expectThrow
(
toPromise
(
web3
.
eth
.
sendTransaction
)
({
ethSendTransaction
({
from
:
accounts
[
1
],
to
:
hasNoEther
.
address
,
value
:
amount
,
...
...
@@ -30,20 +30,20 @@ contract('HasNoEther', function (accounts) {
it
(
'should allow owner to reclaim ether'
,
async
function
()
{
// Create contract
let
hasNoEther
=
await
HasNoEtherTest
.
new
();
const
startBalance
=
await
web3
.
eth
.
g
etBalance
(
hasNoEther
.
address
);
const
startBalance
=
await
ethG
etBalance
(
hasNoEther
.
address
);
assert
.
equal
(
startBalance
,
0
);
// Force ether into it
let
forceEther
=
await
ForceEther
.
new
({
value
:
amount
});
await
forceEther
.
destroyAndSend
(
hasNoEther
.
address
);
const
forcedBalance
=
await
web3
.
eth
.
g
etBalance
(
hasNoEther
.
address
);
const
forcedBalance
=
await
ethG
etBalance
(
hasNoEther
.
address
);
assert
.
equal
(
forcedBalance
,
amount
);
// Reclaim
const
ownerStartBalance
=
await
web3
.
eth
.
g
etBalance
(
accounts
[
0
]);
const
ownerStartBalance
=
await
ethG
etBalance
(
accounts
[
0
]);
await
hasNoEther
.
reclaimEther
();
const
ownerFinalBalance
=
await
web3
.
eth
.
g
etBalance
(
accounts
[
0
]);
const
finalBalance
=
await
web3
.
eth
.
g
etBalance
(
hasNoEther
.
address
);
const
ownerFinalBalance
=
await
ethG
etBalance
(
accounts
[
0
]);
const
finalBalance
=
await
ethG
etBalance
(
hasNoEther
.
address
);
assert
.
equal
(
finalBalance
,
0
);
assert
.
isAbove
(
ownerFinalBalance
,
ownerStartBalance
);
});
...
...
@@ -55,7 +55,7 @@ contract('HasNoEther', function (accounts) {
// Force ether into it
let
forceEther
=
await
ForceEther
.
new
({
value
:
amount
});
await
forceEther
.
destroyAndSend
(
hasNoEther
.
address
);
const
forcedBalance
=
await
web3
.
eth
.
g
etBalance
(
hasNoEther
.
address
);
const
forcedBalance
=
await
ethG
etBalance
(
hasNoEther
.
address
);
assert
.
equal
(
forcedBalance
,
amount
);
// Reclaim
...
...
test/payment/Escrow.behaviour.js
View file @
40b5594f
import
expectEvent
from
'../helpers/expectEvent'
;
import
EVMRevert
from
'../helpers/EVMRevert'
;
import
{
ethGetBalance
}
from
'../helpers/web3'
;
const
BigNumber
=
web3
.
BigNumber
;
...
...
@@ -15,7 +16,7 @@ export default function (owner, [payee1, payee2]) {
it
(
'can accept a single deposit'
,
async
function
()
{
await
this
.
escrow
.
deposit
(
payee1
,
{
from
:
owner
,
value
:
amount
});
const
balance
=
await
web3
.
eth
.
g
etBalance
(
this
.
escrow
.
address
);
const
balance
=
await
ethG
etBalance
(
this
.
escrow
.
address
);
const
deposit
=
await
this
.
escrow
.
depositsOf
(
payee1
);
balance
.
should
.
be
.
bignumber
.
equal
(
amount
);
...
...
@@ -41,7 +42,7 @@ export default function (owner, [payee1, payee2]) {
await
this
.
escrow
.
deposit
(
payee1
,
{
from
:
owner
,
value
:
amount
});
await
this
.
escrow
.
deposit
(
payee1
,
{
from
:
owner
,
value
:
amount
*
2
});
const
balance
=
await
web3
.
eth
.
g
etBalance
(
this
.
escrow
.
address
);
const
balance
=
await
ethG
etBalance
(
this
.
escrow
.
address
);
const
deposit
=
await
this
.
escrow
.
depositsOf
(
payee1
);
balance
.
should
.
be
.
bignumber
.
equal
(
amount
*
3
);
...
...
@@ -52,7 +53,7 @@ export default function (owner, [payee1, payee2]) {
await
this
.
escrow
.
deposit
(
payee1
,
{
from
:
owner
,
value
:
amount
});
await
this
.
escrow
.
deposit
(
payee2
,
{
from
:
owner
,
value
:
amount
*
2
});
const
balance
=
await
web3
.
eth
.
g
etBalance
(
this
.
escrow
.
address
);
const
balance
=
await
ethG
etBalance
(
this
.
escrow
.
address
);
const
depositPayee1
=
await
this
.
escrow
.
depositsOf
(
payee1
);
const
depositPayee2
=
await
this
.
escrow
.
depositsOf
(
payee2
);
...
...
@@ -64,14 +65,14 @@ export default function (owner, [payee1, payee2]) {
describe
(
'withdrawals'
,
async
function
()
{
it
(
'can withdraw payments'
,
async
function
()
{
const
payeeInitialBalance
=
await
web3
.
eth
.
g
etBalance
(
payee1
);
const
payeeInitialBalance
=
await
ethG
etBalance
(
payee1
);
await
this
.
escrow
.
deposit
(
payee1
,
{
from
:
owner
,
value
:
amount
});
await
this
.
escrow
.
withdraw
(
payee1
,
{
from
:
owner
});
const
escrowBalance
=
await
web3
.
eth
.
g
etBalance
(
this
.
escrow
.
address
);
const
escrowBalance
=
await
ethG
etBalance
(
this
.
escrow
.
address
);
const
finalDeposit
=
await
this
.
escrow
.
depositsOf
(
payee1
);
const
payeeFinalBalance
=
await
web3
.
eth
.
g
etBalance
(
payee1
);
const
payeeFinalBalance
=
await
ethG
etBalance
(
payee1
);
escrowBalance
.
should
.
be
.
bignumber
.
equal
(
0
);
finalDeposit
.
should
.
be
.
bignumber
.
equal
(
0
);
...
...
test/payment/PullPayment.test.js
View file @
40b5594f
import
{
ethGetBalance
}
from
'../helpers/web3'
;
const
BigNumber
=
web3
.
BigNumber
;
require
(
'chai'
)
...
...
@@ -45,7 +47,7 @@ contract('PullPayment', function (accounts) {
it
(
'can withdraw payment'
,
async
function
()
{
const
payee
=
accounts
[
1
];
const
initialBalance
=
web3
.
eth
.
g
etBalance
(
payee
);
const
initialBalance
=
await
ethG
etBalance
(
payee
);
await
this
.
contract
.
callTransfer
(
payee
,
amount
);
...
...
@@ -56,7 +58,7 @@ contract('PullPayment', function (accounts) {
const
payment2
=
await
this
.
contract
.
payments
(
payee
);
payment2
.
should
.
be
.
bignumber
.
equal
(
0
);
const
balance
=
web3
.
eth
.
g
etBalance
(
payee
);
const
balance
=
await
ethG
etBalance
(
payee
);
Math
.
abs
(
balance
-
initialBalance
-
amount
).
should
.
be
.
lt
(
1
e16
);
});
});
test/payment/RefundEscrow.test.js
View file @
40b5594f
import
EVMRevert
from
'../helpers/EVMRevert'
;
import
expectEvent
from
'../helpers/expectEvent'
;
import
{
ethGetBalance
}
from
'../helpers/web3'
;
const
BigNumber
=
web3
.
BigNumber
;
...
...
@@ -60,9 +61,9 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) {
});
it
(
'allows beneficiary withdrawal'
,
async
function
()
{
const
beneficiaryInitialBalance
=
await
web3
.
eth
.
g
etBalance
(
beneficiary
);
const
beneficiaryInitialBalance
=
await
ethG
etBalance
(
beneficiary
);
await
this
.
escrow
.
beneficiaryWithdraw
();
const
beneficiaryFinalBalance
=
await
web3
.
eth
.
g
etBalance
(
beneficiary
);
const
beneficiaryFinalBalance
=
await
ethG
etBalance
(
beneficiary
);
beneficiaryFinalBalance
.
sub
(
beneficiaryInitialBalance
).
should
.
be
.
bignumber
.
equal
(
amount
*
refundees
.
length
);
});
...
...
@@ -89,9 +90,9 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) {
it
(
'refunds refundees'
,
async
function
()
{
for
(
let
refundee
of
[
refundee1
,
refundee2
])
{
const
refundeeInitialBalance
=
await
web3
.
eth
.
g
etBalance
(
refundee
);
const
refundeeInitialBalance
=
await
ethG
etBalance
(
refundee
);
await
this
.
escrow
.
withdraw
(
refundee
);
const
refundeeFinalBalance
=
await
web3
.
eth
.
g
etBalance
(
refundee
);
const
refundeeFinalBalance
=
await
ethG
etBalance
(
refundee
);
refundeeFinalBalance
.
sub
(
refundeeInitialBalance
).
should
.
be
.
bignumber
.
equal
(
amount
);
}
...
...
test/payment/SplitPayment.test.js
View file @
40b5594f
import
{
ethGetBalance
,
ethSendTransaction
}
from
'../helpers/web3'
;
const
BigNumber
=
web3
.
BigNumber
;
require
(
'chai'
)
...
...
@@ -19,9 +21,9 @@ contract('SplitPayment', function ([owner, payee1, payee2, payee3, nonpayee1, pa
});
it
(
'should accept payments'
,
async
function
()
{
await
web3
.
eth
.
s
endTransaction
({
from
:
owner
,
to
:
this
.
contract
.
address
,
value
:
amount
});
await
ethS
endTransaction
({
from
:
owner
,
to
:
this
.
contract
.
address
,
value
:
amount
});
const
balance
=
web3
.
eth
.
g
etBalance
(
this
.
contract
.
address
);
const
balance
=
await
ethG
etBalance
(
this
.
contract
.
address
);
balance
.
should
.
be
.
bignumber
.
equal
(
amount
);
});
...
...
@@ -40,35 +42,35 @@ contract('SplitPayment', function ([owner, payee1, payee2, payee3, nonpayee1, pa
});
it
(
'should throw if non-payee want to claim'
,
async
function
()
{
await
web3
.
eth
.
s
endTransaction
({
from
:
payer1
,
to
:
this
.
contract
.
address
,
value
:
amount
});
await
ethS
endTransaction
({
from
:
payer1
,
to
:
this
.
contract
.
address
,
value
:
amount
});
await
this
.
contract
.
claim
({
from
:
nonpayee1
}).
should
.
be
.
rejectedWith
(
EVMThrow
);
});
it
(
'should distribute funds to payees'
,
async
function
()
{
await
web3
.
eth
.
s
endTransaction
({
from
:
payer1
,
to
:
this
.
contract
.
address
,
value
:
amount
});
await
ethS
endTransaction
({
from
:
payer1
,
to
:
this
.
contract
.
address
,
value
:
amount
});
// receive funds
const
initBalance
=
web3
.
eth
.
g
etBalance
(
this
.
contract
.
address
);
const
initBalance
=
await
ethG
etBalance
(
this
.
contract
.
address
);
initBalance
.
should
.
be
.
bignumber
.
equal
(
amount
);
// distribute to payees
const
initAmount1
=
web3
.
eth
.
g
etBalance
(
payee1
);
const
initAmount1
=
await
ethG
etBalance
(
payee1
);
await
this
.
contract
.
claim
({
from
:
payee1
});
const
profit1
=
web3
.
eth
.
g
etBalance
(
payee1
)
-
initAmount1
;
const
profit1
=
await
ethG
etBalance
(
payee1
)
-
initAmount1
;
assert
(
Math
.
abs
(
profit1
-
web3
.
toWei
(
0.20
,
'ether'
))
<
1
e16
);
const
initAmount2
=
web3
.
eth
.
g
etBalance
(
payee2
);
const
initAmount2
=
await
ethG
etBalance
(
payee2
);
await
this
.
contract
.
claim
({
from
:
payee2
});
const
profit2
=
web3
.
eth
.
g
etBalance
(
payee2
)
-
initAmount2
;
const
profit2
=
await
ethG
etBalance
(
payee2
)
-
initAmount2
;
assert
(
Math
.
abs
(
profit2
-
web3
.
toWei
(
0.10
,
'ether'
))
<
1
e16
);
const
initAmount3
=
web3
.
eth
.
g
etBalance
(
payee3
);
const
initAmount3
=
await
ethG
etBalance
(
payee3
);
await
this
.
contract
.
claim
({
from
:
payee3
});
const
profit3
=
web3
.
eth
.
g
etBalance
(
payee3
)
-
initAmount3
;
const
profit3
=
await
ethG
etBalance
(
payee3
)
-
initAmount3
;
assert
(
Math
.
abs
(
profit3
-
web3
.
toWei
(
0.70
,
'ether'
))
<
1
e16
);
// end balance should be zero
const
endBalance
=
web3
.
eth
.
g
etBalance
(
this
.
contract
.
address
);
const
endBalance
=
await
ethG
etBalance
(
this
.
contract
.
address
);
endBalance
.
should
.
be
.
bignumber
.
equal
(
0
);
// check correct funds released accounting
...
...
test/token/ERC20/TokenTimelock.test.js
View file @
40b5594f
...
...
@@ -16,7 +16,7 @@ contract('TokenTimelock', function ([_, owner, beneficiary]) {
beforeEach
(
async
function
()
{
this
.
token
=
await
MintableToken
.
new
({
from
:
owner
});
this
.
releaseTime
=
latestTime
(
)
+
duration
.
years
(
1
);
this
.
releaseTime
=
(
await
latestTime
()
)
+
duration
.
years
(
1
);
this
.
timelock
=
await
TokenTimelock
.
new
(
this
.
token
.
address
,
beneficiary
,
this
.
releaseTime
);
await
this
.
token
.
mint
(
this
.
timelock
.
address
,
amount
,
{
from
:
owner
});
});
...
...
test/token/ERC20/TokenVesting.test.js
View file @
40b5594f
import
EVMRevert
from
'../../helpers/EVMRevert'
;
import
latestTime
from
'../../helpers/latestTime'
;
import
{
increaseTimeTo
,
duration
}
from
'../../helpers/increaseTime'
;
import
{
ethGetBlock
}
from
'../../helpers/web3'
;
const
BigNumber
=
web3
.
BigNumber
;
...
...
@@ -18,7 +19,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
beforeEach
(
async
function
()
{
this
.
token
=
await
MintableToken
.
new
({
from
:
owner
});
this
.
start
=
latestTime
(
)
+
duration
.
minutes
(
1
);
// +1 minute so it starts after contract instantiation
this
.
start
=
(
await
latestTime
()
)
+
duration
.
minutes
(
1
);
// +1 minute so it starts after contract instantiation
this
.
cliff
=
duration
.
years
(
1
);
this
.
duration
=
duration
.
years
(
2
);
...
...
@@ -40,7 +41,8 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
await
increaseTimeTo
(
this
.
start
+
this
.
cliff
);
const
{
receipt
}
=
await
this
.
vesting
.
release
(
this
.
token
.
address
);
const
releaseTime
=
web3
.
eth
.
getBlock
(
receipt
.
blockNumber
).
timestamp
;
const
block
=
await
ethGetBlock
(
receipt
.
blockNumber
);
const
releaseTime
=
block
.
timestamp
;
const
balance
=
await
this
.
token
.
balanceOf
(
beneficiary
);
balance
.
should
.
bignumber
.
equal
(
amount
.
mul
(
releaseTime
-
this
.
start
).
div
(
this
.
duration
).
floor
());
...
...
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