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
9bd51db2
Commit
9bd51db2
authored
Feb 17, 2017
by
Manuel Araoz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor tests for truffle 3
parent
7e7193ae
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
244 additions
and
284 deletions
+244
-284
DelayedClaimable.sol
contracts/ownership/DelayedClaimable.sol
+8
-8
2_deploy_contracts.js
migrations/2_deploy_contracts.js
+2
-12
test.sh
scripts/test.sh
+10
-4
Bounty.js
test/Bounty.js
+47
-48
Claimable.js
test/Claimable.js
+16
-12
DayLimit.js
test/DayLimit.js
+4
-0
DelayedClaimble.js
test/DelayedClaimble.js
+52
-66
Killable.js
test/Killable.js
+10
-45
LimitBalance.js
test/LimitBalance.js
+14
-11
MultisigWallet.js
test/MultisigWallet.js
+11
-55
Ownable.js
test/Ownable.js
+12
-9
Pausable.js
test/Pausable.js
+18
-14
PullPayment.js
test/PullPayment.js
+2
-0
SafeMath.js
test/SafeMath.js
+1
-0
Shareable.js
test/Shareable.js
+2
-0
StandardToken.js
test/StandardToken.js
+1
-0
transactionMined.js
test/helpers/transactionMined.js
+34
-0
No files found.
contracts/ownership/DelayedClaimable.sol
View file @
9bd51db2
...
...
@@ -9,22 +9,22 @@ import './Claimable.sol';
contract DelayedClaimable is Ownable, Claimable {
uint public
claimBeforeBlock
;
uint public
claimAfterBlock
;
uint public
end
;
uint public
start
;
function set
ClaimBlocks(uint _claimBeforeBlock, uint _claimAfterBlock
) onlyOwner {
if (_
claimAfterBlock > claimBeforeBlock
)
function set
Limits(uint _start, uint _end
) onlyOwner {
if (_
start > _end
)
throw;
claimBeforeBlock = _claimBeforeBlock
;
claimAfterBlock = _claimAfterBlock
;
end = _end
;
start = _start
;
}
function claimOwnership() onlyPendingOwner {
if ((block.number >
claimBeforeBlock) || (block.number < claimAfterBlock
))
if ((block.number >
end) || (block.number < start
))
throw;
owner = pendingOwner;
pendingOwner = 0x0;
claimBeforeBlock
= 0;
end
= 0;
}
}
migrations/2_deploy_contracts.js
View file @
9bd51db2
var
Ownable
=
artifacts
.
require
(
"ownership/Ownable.sol"
);
var
Claimable
=
artifacts
.
require
(
"ownership/Claimable.sol"
);
var
LimitBalance
=
artifacts
.
require
(
"LimitBalance.sol"
);
var
SecureTargetBounty
=
artifacts
.
require
(
"test-helpers/SecureTargetBounty.sol"
);
var
InsecureTargetBounty
=
artifacts
.
require
(
"test-helpers/InsecureTargetBounty.sol"
);
//var Ownable = artifacts.require("ownership/Ownable.sol");
module
.
exports
=
function
(
deployer
)
{
deployer
.
deploy
(
Ownable
);
deployer
.
deploy
(
Claimable
);
deployer
.
deploy
(
LimitBalance
);
if
(
deployer
.
network
==
'test'
){
deployer
.
deploy
(
SecureTargetBounty
);
deployer
.
deploy
(
InsecureTargetBounty
);
}
//deployer.deploy(Ownable);
};
scripts/test.sh
View file @
9bd51db2
#! /bin/bash
testrpc &
trpc_pid
=
$!
output
=
$(
nc
-z
localhost 8545
;
echo
$?
)
[
$output
-eq
"0"
]
&&
trpc_running
=
true
if
[
!
$trpc_running
]
;
then
echo
"Starting our own testrpc node instance"
testrpc
>
/dev/null &
trpc_pid
=
$!
fi
truffle
test
kill
-9
$trpc_pid
if
[
!
$trpc_running
]
;
then
kill
-9
$trpc_pid
fi
test/Bounty.js
View file @
9bd51db2
'use strict'
;
let
sendReward
=
function
(
sender
,
receiver
,
value
){
web3
.
eth
.
sendTransaction
({
from
:
sender
,
to
:
receiver
,
value
:
value
})
});
};
var
SecureTargetBounty
=
artifacts
.
require
(
'helpers/SecureTargetBounty.sol'
);
var
InsecureTargetBounty
=
artifacts
.
require
(
'helpers/InsecureTargetBounty.sol'
);
function
awaitEvent
(
event
,
handler
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
function
wrappedHandler
(...
args
)
{
Promise
.
resolve
(
handler
(...
args
)).
then
(
resolve
).
catch
(
reject
);
}
event
.
watch
(
wrappedHandler
);
});
}
contract
(
'Bounty'
,
function
(
accounts
)
{
it
(
"sets reward"
,
async
function
()
{
it
(
'sets reward'
,
async
function
()
{
let
owner
=
accounts
[
0
];
let
reward
=
web3
.
toWei
(
1
,
"ether"
);
let
reward
=
web3
.
toWei
(
1
,
'ether'
);
let
bounty
=
await
SecureTargetBounty
.
new
();
sendReward
(
owner
,
bounty
.
address
,
reward
);
assert
.
equal
(
reward
,
web3
.
eth
.
getBalance
(
bounty
.
address
).
toNumber
());
})
})
;
it
(
"empties itself when killed"
,
async
function
(){
it
(
'empties itself when killed'
,
async
function
(){
let
owner
=
accounts
[
0
];
let
reward
=
web3
.
toWei
(
1
,
"ether"
);
let
reward
=
web3
.
toWei
(
1
,
'ether'
);
let
bounty
=
await
SecureTargetBounty
.
new
();
sendReward
(
owner
,
bounty
.
address
,
reward
);
...
...
@@ -27,89 +41,74 @@ contract('Bounty', function(accounts) {
await
bounty
.
kill
();
assert
.
equal
(
0
,
web3
.
eth
.
getBalance
(
bounty
.
address
).
toNumber
());
})
describe
(
"Against secure contract"
,
function
(){
it
(
"checkInvariant returns true"
,
async
function
(){
let
bounty
=
await
SecureTargetBounty
.
new
();
let
target
=
await
bounty
.
createTarget
();
let
check
=
await
bounty
.
checkInvariant
.
call
();
});
assert
.
isTrue
(
check
);
})
describe
(
'Against secure contract'
,
function
(){
it
(
"cannot claim reward"
,
async
function
(
done
){
it
(
'cannot claim reward'
,
async
function
(
){
let
owner
=
accounts
[
0
];
let
researcher
=
accounts
[
1
];
let
reward
=
web3
.
toWei
(
1
,
"ether"
);
let
reward
=
web3
.
toWei
(
1
,
'ether'
);
let
bounty
=
await
SecureTargetBounty
.
new
();
let
event
=
bounty
.
TargetCreated
({});
event
.
watch
(
async
function
(
err
,
result
)
{
event
.
stopWatching
();
if
(
err
)
{
throw
err
}
if
(
err
)
{
throw
err
;
}
var
targetAddress
=
result
.
args
.
createdAddress
;
sendReward
(
owner
,
bounty
.
address
,
reward
);
assert
.
equal
(
reward
,
web3
.
eth
.
getBalance
(
bounty
.
address
).
toNumber
())
assert
.
equal
(
reward
,
web3
.
eth
.
getBalance
(
bounty
.
address
).
toNumber
());
try
{
let
tmpClain
=
await
bounty
.
claim
(
targetAddress
,
{
from
:
researcher
});
done
(
"should not come here"
);
await
bounty
.
claim
(
targetAddress
,
{
from
:
researcher
});
assert
.
isTrue
(
false
);
// should never reach here
}
catch
(
error
)
{
let
reClaimedBounty
=
await
bounty
.
claimed
.
call
();
assert
.
isFalse
(
reClaimedBounty
);
}
try
{
let
withdraw
=
await
bounty
.
withdrawPayments
({
from
:
researcher
});
done
(
"should not come here"
)
await
bounty
.
withdrawPayments
({
from
:
researcher
});
assert
.
isTrue
(
false
);
// should never reach here
}
catch
(
err
)
{
assert
.
equal
(
reward
,
web3
.
eth
.
getBalance
(
bounty
.
address
).
toNumber
());
done
(
);
assert
.
equal
(
reward
,
web3
.
eth
.
getBalance
(
bounty
.
address
).
toNumber
()
);
}
}
//end of first try catch
});
bounty
.
createTarget
({
from
:
researcher
});
})
})
describe
(
"Against broken contract"
,
function
(){
it
(
"checkInvariant returns false"
,
async
function
(){
let
bounty
=
await
InsecureTargetBounty
.
new
();
let
target
=
await
bounty
.
createTarget
();
let
invariantCall
=
await
bounty
.
checkInvariant
.
call
();
assert
.
isFalse
(
invariantCall
);
})
});
});
it
(
"claims reward"
,
async
function
(
done
){
describe
(
'Against broken contract'
,
function
(){
it
(
'claims reward'
,
async
function
()
{
let
owner
=
accounts
[
0
];
let
researcher
=
accounts
[
1
];
let
reward
=
web3
.
toWei
(
1
,
"ether"
);
let
reward
=
web3
.
toWei
(
1
,
'ether'
);
let
bounty
=
await
InsecureTargetBounty
.
new
();
let
event
=
bounty
.
TargetCreated
({});
event
.
watch
(
async
function
(
err
,
result
)
{
let
watcher
=
async
function
(
err
,
result
)
{
event
.
stopWatching
();
if
(
err
)
{
throw
err
}
if
(
err
)
{
throw
err
;
}
let
targetAddress
=
result
.
args
.
createdAddress
;
sendReward
(
owner
,
bounty
.
address
,
reward
);
assert
.
equal
(
reward
,
web3
.
eth
.
getBalance
(
bounty
.
address
).
toNumber
());
let
bountyClaim
=
await
bounty
.
claim
(
targetAddress
,
{
from
:
researcher
});
await
bounty
.
claim
(
targetAddress
,
{
from
:
researcher
});
let
claim
=
await
bounty
.
claimed
.
call
();
assert
.
isTrue
(
claim
);
let
payment
=
await
bounty
.
withdrawPayments
({
from
:
researcher
});
await
bounty
.
withdrawPayments
({
from
:
researcher
});
assert
.
equal
(
0
,
web3
.
eth
.
getBalance
(
bounty
.
address
).
toNumber
());
done
();
})
};
bounty
.
createTarget
({
from
:
researcher
});
})
})
await
awaitEvent
(
event
,
watcher
);
});
});
});
test/Claimable.js
View file @
9bd51db2
'use strict'
;
var
Claimable
=
artifacts
.
require
(
'../contracts/ownership/Claimable.sol'
);
contract
(
'Claimable'
,
function
(
accounts
)
{
let
claimable
;
...
...
@@ -5,34 +9,34 @@ contract('Claimable', function(accounts) {
claimable
=
await
Claimable
.
new
();
});
it
(
"should have an owner"
,
async
function
()
{
it
(
'should have an owner'
,
async
function
()
{
let
owner
=
await
claimable
.
owner
();
assert
.
isTrue
(
owner
!=
0
);
assert
.
isTrue
(
owner
!=
=
0
);
});
it
(
"changes pendingOwner after transfer"
,
async
function
()
{
it
(
'changes pendingOwner after transfer'
,
async
function
()
{
let
newOwner
=
accounts
[
1
];
let
transfer
=
await
claimable
.
transferOwnership
(
newOwner
);
await
claimable
.
transferOwnership
(
newOwner
);
let
pendingOwner
=
await
claimable
.
pendingOwner
();
assert
.
isTrue
(
pendingOwner
===
newOwner
);
});
it
(
"should prevent to claimOwnership from no pendingOwner"
,
async
function
()
{
let
claimedOwner
=
await
claimable
.
claimOwnership
({
from
:
accounts
[
2
]});
it
(
'should prevent to claimOwnership from no pendingOwner'
,
async
function
()
{
claimable
.
claimOwnership
({
from
:
accounts
[
2
]});
let
owner
=
await
claimable
.
owner
();
assert
.
isTrue
(
owner
!=
accounts
[
2
]);
assert
.
isTrue
(
owner
!=
=
accounts
[
2
]);
});
it
(
"should prevent non-owners from transfering"
,
async
function
()
{
let
transfer
=
await
claimable
.
transferOwnership
(
accounts
[
2
],
{
from
:
accounts
[
2
]});
it
(
'should prevent non-owners from transfering'
,
async
function
()
{
await
claimable
.
transferOwnership
(
accounts
[
2
],
{
from
:
accounts
[
2
]});
let
pendingOwner
=
await
claimable
.
pendingOwner
();
assert
.
isFalse
(
pendingOwner
===
accounts
[
2
]);
});
describe
(
"after initiating a transfer"
,
function
()
{
describe
(
'after initiating a transfer'
,
function
()
{
let
newOwner
;
beforeEach
(
async
function
()
{
...
...
@@ -40,8 +44,8 @@ contract('Claimable', function(accounts) {
await
claimable
.
transferOwnership
(
newOwner
);
});
it
(
"changes allow pending owner to claim ownership"
,
async
function
()
{
let
claimedOwner
=
await
claimable
.
claimOwnership
({
from
:
newOwner
})
it
(
'changes allow pending owner to claim ownership'
,
async
function
()
{
await
claimable
.
claimOwnership
({
from
:
newOwner
});
let
owner
=
await
claimable
.
owner
();
assert
.
isTrue
(
owner
===
newOwner
);
...
...
test/DayLimit.js
View file @
9bd51db2
'use strict'
;
var
DayLimitMock
=
artifacts
.
require
(
'helpers/DayLimitMock.sol'
);
contract
(
'DayLimit'
,
function
(
accounts
)
{
it
(
'should construct with the passed daily limit'
,
async
function
()
{
...
...
test/DelayedClaimble.js
View file @
9bd51db2
'use strict'
;
var
DelayedClaimable
=
artifacts
.
require
(
'../contracts/ownership/DelayedClaimable.sol'
);
contract
(
'DelayedClaimable'
,
function
(
accounts
)
{
var
delayedClaimable
;
...
...
@@ -7,76 +11,58 @@ contract('DelayedClaimable', function(accounts) {
});
});
it
(
"Changes pendingOwner after transfer succesfull"
,
function
(
done
)
{
return
delayedClaimable
.
transferOwnership
(
accounts
[
2
])
.
then
(
function
(){
return
delayedClaimable
.
setClaimBlocks
(
1000
,
0
);
})
.
then
(
function
(){
return
delayedClaimable
.
claimBeforeBlock
();
})
.
then
(
function
(
claimBeforeBlock
)
{
assert
.
isTrue
(
claimBeforeBlock
==
1000
);
return
delayedClaimable
.
claimAfterBlock
();
})
.
then
(
function
(
claimAfterBlock
)
{
assert
.
isTrue
(
claimAfterBlock
==
0
);
return
delayedClaimable
.
pendingOwner
();
})
.
then
(
function
(
pendingOwner
)
{
assert
.
isTrue
(
pendingOwner
===
accounts
[
2
]);
return
delayedClaimable
.
claimOwnership
({
from
:
accounts
[
2
]});
})
.
then
(
function
()
{
return
delayedClaimable
.
owner
();
})
.
then
(
function
(
owner
)
{
assert
.
isTrue
(
owner
===
accounts
[
2
]);
})
.
then
(
done
);
it
(
'can set claim blocks'
,
async
function
()
{
await
delayedClaimable
.
transferOwnership
(
accounts
[
2
]);
await
delayedClaimable
.
setLimits
(
0
,
1000
);
let
end
=
await
delayedClaimable
.
end
();
assert
.
equal
(
end
,
1000
);
let
start
=
await
delayedClaimable
.
start
();
assert
.
equal
(
start
,
0
);
});
it
(
'changes pendingOwner after transfer successful'
,
async
function
()
{
await
delayedClaimable
.
transferOwnership
(
accounts
[
2
]);
await
delayedClaimable
.
setLimits
(
0
,
1000
);
let
end
=
await
delayedClaimable
.
end
();
assert
.
equal
(
end
,
1000
);
let
start
=
await
delayedClaimable
.
start
();
assert
.
equal
(
start
,
0
);
let
pendingOwner
=
await
delayedClaimable
.
pendingOwner
();
assert
.
equal
(
pendingOwner
,
accounts
[
2
]);
await
delayedClaimable
.
claimOwnership
({
from
:
accounts
[
2
]});
let
owner
=
await
delayedClaimable
.
owner
();
assert
.
equal
(
owner
,
accounts
[
2
]);
});
it
(
"Changes pendingOwner after transfer fails"
,
function
(
done
)
{
return
delayedClaimable
.
transferOwnership
(
accounts
[
1
])
.
then
(
function
(){
return
delayedClaimable
.
setClaimBlocks
(
11000
,
10000
);
})
.
then
(
function
(){
return
delayedClaimable
.
claimBeforeBlock
();
})
.
then
(
function
(
claimBeforeBlock
)
{
assert
.
isTrue
(
claimBeforeBlock
==
11000
);
return
delayedClaimable
.
claimAfterBlock
();
})
.
then
(
function
(
claimAfterBlock
)
{
assert
.
isTrue
(
claimAfterBlock
==
10000
);
return
delayedClaimable
.
pendingOwner
();
})
.
then
(
function
(
pendingOwner
)
{
assert
.
isTrue
(
pendingOwner
===
accounts
[
1
]);
return
delayedClaimable
.
claimOwnership
({
from
:
accounts
[
1
]});
})
.
catch
(
function
(
error
)
{
if
(
error
.
message
.
search
(
'invalid JUMP'
)
==
-
1
)
throw
error
;
})
.
then
(
function
()
{
return
delayedClaimable
.
owner
();
})
.
then
(
function
(
owner
)
{
assert
.
isTrue
(
owner
!=
accounts
[
1
]);
})
.
then
(
done
);
it
(
'changes pendingOwner after transfer fails'
,
async
function
()
{
await
delayedClaimable
.
transferOwnership
(
accounts
[
1
]);
await
delayedClaimable
.
setLimits
(
100
,
110
);
let
end
=
await
delayedClaimable
.
end
();
assert
.
equal
(
end
,
110
);
let
start
=
await
delayedClaimable
.
start
();
assert
.
equal
(
start
,
100
);
let
pendingOwner
=
await
delayedClaimable
.
pendingOwner
();
assert
.
equal
(
pendingOwner
,
accounts
[
1
]);
var
err
=
null
;
try
{
await
delayedClaimable
.
claimOwnership
({
from
:
accounts
[
1
]});
}
catch
(
error
)
{
err
=
error
;
}
assert
.
isFalse
(
err
.
message
.
search
(
'invalid JUMP'
)
===
-
1
);
let
owner
=
await
delayedClaimable
.
owner
();
assert
.
isTrue
(
owner
!==
accounts
[
1
]);
});
it
(
"Set claimBeforeBlock and claimAfterBlock invalid values fail"
,
function
(
done
)
{
return
delayedClaimable
.
transferOwnership
(
accounts
[
1
])
.
then
(
function
(){
return
delayedClaimable
.
setClaimBlocks
(
1000
,
10000
);
})
.
catch
(
function
(
error
)
{
if
(
error
.
message
.
search
(
'invalid JUMP'
)
==
-
1
)
throw
error
;
})
.
then
(
done
);
it
(
'set end and start invalid values fail'
,
async
function
(
)
{
await
delayedClaimable
.
transferOwnership
(
accounts
[
1
]);
var
err
=
null
;
try
{
await
delayedClaimable
.
setLimits
(
1001
,
1000
);
}
catch
(
error
)
{
err
=
error
;
}
assert
.
isFalse
(
err
.
message
.
search
(
'invalid JUMP'
)
===
-
1
);
});
});
test/Killable.js
View file @
9bd51db2
'use strict'
;
contract
(
'Killable'
,
function
(
accounts
)
{
//from https://gist.github.com/xavierlepretre/88682e871f4ad07be4534ae560692ee6
web3
.
eth
.
getTransactionReceiptMined
=
function
(
txnHash
,
interval
)
{
var
transactionReceiptAsync
;
interval
=
interval
?
interval
:
500
;
transactionReceiptAsync
=
function
(
txnHash
,
resolve
,
reject
)
{
try
{
var
receipt
=
web3
.
eth
.
getTransactionReceipt
(
txnHash
);
if
(
receipt
===
null
)
{
setTimeout
(
function
()
{
transactionReceiptAsync
(
txnHash
,
resolve
,
reject
);
},
interval
);
}
else
{
resolve
(
receipt
);
}
}
catch
(
e
)
{
reject
(
e
);
}
};
if
(
Array
.
isArray
(
txnHash
))
{
var
promises
=
[];
txnHash
.
forEach
(
function
(
oneTxHash
)
{
promises
.
push
(
web3
.
eth
.
getTransactionReceiptMined
(
oneTxHash
,
interval
));
});
return
Promise
.
all
(
promises
);
}
else
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
transactionReceiptAsync
(
txnHash
,
resolve
,
reject
);
});
}
};
var
Killable
=
artifacts
.
require
(
'../contracts/lifecycle/Killable.sol'
);
require
(
'./helpers/transactionMined.js'
);
it
(
"should send balance to owner after death"
,
async
function
()
{
let
initBalance
,
newBalance
,
owner
,
address
,
killable
,
kBalance
,
txnHash
,
receiptMined
;
web3
.
eth
.
sendTransaction
({
from
:
web3
.
eth
.
coinbase
,
to
:
accounts
[
0
],
value
:
web3
.
toWei
(
'50'
,
'ether'
)},
function
(
err
,
result
)
{
if
(
err
)
console
.
log
(
"ERROR:"
+
err
);
});
contract
(
'Killable'
,
function
(
accounts
)
{
killable
=
await
Killable
.
new
({
from
:
accounts
[
0
],
value
:
web3
.
toWei
(
'10'
,
'ether'
)});
owner
=
await
killable
.
owner
();
initBalance
=
web3
.
eth
.
getBalance
(
owner
);
kBalance
=
web3
.
eth
.
getBalance
(
killable
.
address
);
txnHash
=
await
killable
.
kill
({
from
:
owner
});
receiptMined
=
await
web3
.
eth
.
getTransactionReceiptMined
(
txnHash
);
newBalance
=
web3
.
eth
.
getBalance
(
owner
);
it
(
'should send balance to owner after death'
,
async
function
()
{
let
killable
=
await
Killable
.
new
({
from
:
accounts
[
0
],
value
:
web3
.
toWei
(
'10'
,
'ether'
)});
let
owner
=
await
killable
.
owner
();
let
initBalance
=
web3
.
eth
.
getBalance
(
owner
);
await
killable
.
kill
({
from
:
owner
});
let
newBalance
=
web3
.
eth
.
getBalance
(
owner
);
assert
.
isTrue
(
newBalance
>
initBalance
);
});
...
...
test/LimitBalance.js
View file @
9bd51db2
'use strict'
;
var
LimitBalanceMock
=
artifacts
.
require
(
'helpers/LimitBalanceMock.sol'
);
const
assertJump
=
require
(
'./helpers/assertJump'
);
contract
(
'LimitBalance'
,
function
(
accounts
)
{
...
...
@@ -9,46 +12,46 @@ contract('LimitBalance', function(accounts) {
let
LIMIT
=
1000
;
it
(
"should expose limit"
,
async
function
()
{
it
(
'should expose limit'
,
async
function
()
{
let
limit
=
await
lb
.
limit
();
assert
.
equal
(
limit
,
LIMIT
);
});
it
(
"should allow sending below limit"
,
async
function
()
{
it
(
'should allow sending below limit'
,
async
function
()
{
let
amount
=
1
;
let
limDeposit
=
await
lb
.
limitedDeposit
({
value
:
amount
});
await
lb
.
limitedDeposit
({
value
:
amount
});
assert
.
equal
(
web3
.
eth
.
getBalance
(
lb
.
address
),
amount
);
});
it
(
"shouldnt allow sending above limit"
,
async
function
()
{
it
(
'shouldnt allow sending above limit'
,
async
function
()
{
let
amount
=
1110
;
try
{
let
limDeposit
=
await
lb
.
limitedDeposit
({
value
:
amount
});
await
lb
.
limitedDeposit
({
value
:
amount
});
}
catch
(
error
)
{
return
assertJump
(
error
);
}
assert
.
fail
(
'should have thrown before'
);
});
it
(
"should allow multiple sends below limit"
,
async
function
()
{
it
(
'should allow multiple sends below limit'
,
async
function
()
{
let
amount
=
500
;
let
limDeposit
=
await
lb
.
limitedDeposit
({
value
:
amount
});
await
lb
.
limitedDeposit
({
value
:
amount
});
assert
.
equal
(
web3
.
eth
.
getBalance
(
lb
.
address
),
amount
);
let
limDeposit2
=
await
lb
.
limitedDeposit
({
value
:
amount
});
await
lb
.
limitedDeposit
({
value
:
amount
});
assert
.
equal
(
web3
.
eth
.
getBalance
(
lb
.
address
),
amount
*
2
);
});
it
(
"shouldnt allow multiple sends above limit"
,
async
function
()
{
it
(
'shouldnt allow multiple sends above limit'
,
async
function
()
{
let
amount
=
500
;
let
limDeposit
=
await
lb
.
limitedDeposit
({
value
:
amount
});
await
lb
.
limitedDeposit
({
value
:
amount
});
assert
.
equal
(
web3
.
eth
.
getBalance
(
lb
.
address
),
amount
);
try
{
await
lb
.
limitedDeposit
({
value
:
amount
+
1
})
await
lb
.
limitedDeposit
({
value
:
amount
+
1
})
;
}
catch
(
error
)
{
return
assertJump
(
error
);
}
...
...
test/MultisigWallet.js
View file @
9bd51db2
contract
(
'MultisigWallet'
,
function
(
accounts
)
{
//from https://gist.github.com/xavierlepretre/88682e871f4ad07be4534ae560692ee6
web3
.
eth
.
getTransactionReceiptMined
=
function
(
txnHash
,
interval
)
{
var
transactionReceiptAsync
;
interval
=
interval
?
interval
:
500
;
transactionReceiptAsync
=
function
(
txnHash
,
resolve
,
reject
)
{
try
{
var
receipt
=
web3
.
eth
.
getTransactionReceipt
(
txnHash
);
if
(
receipt
==
null
)
{
setTimeout
(
function
()
{
transactionReceiptAsync
(
txnHash
,
resolve
,
reject
);
},
interval
);
}
else
{
resolve
(
receipt
);
}
}
catch
(
e
)
{
reject
(
e
);
}
};
if
(
Array
.
isArray
(
txnHash
))
{
var
promises
=
[];
txnHash
.
forEach
(
function
(
oneTxHash
)
{
promises
.
push
(
web3
.
eth
.
getTransactionReceiptMined
(
oneTxHash
,
interval
));
});
return
Promise
.
all
(
promises
);
}
else
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
transactionReceiptAsync
(
txnHash
,
resolve
,
reject
);
});
}
};
'use strict'
;
var
MultisigWalletMock
=
artifacts
.
require
(
'./helpers/MultisigWalletMock.sol'
);
require
(
'./helpers/transactionMined.js'
);
contract
(
'MultisigWallet'
,
function
(
accounts
)
{
let
shouldntFail
=
function
(
err
)
{
assert
.
isFalse
(
!!
err
);
};
it
(
'should send balance to passed address upon death'
,
async
function
()
{
//Give account[0] 20 ether
web3
.
eth
.
sendTransaction
({
from
:
web3
.
eth
.
coinbase
,
to
:
accounts
[
0
],
value
:
web3
.
toWei
(
'20'
,
'ether'
)},
function
(
err
,
result
)
{
if
(
err
)
console
.
log
(
"ERROR:"
+
err
);
});
web3
.
eth
.
sendTransaction
({
from
:
web3
.
eth
.
coinbase
,
to
:
accounts
[
0
],
value
:
web3
.
toWei
(
'20'
,
'ether'
)},
shouldntFail
);
let
dailyLimit
=
10
;
let
ownersRequired
=
2
;
...
...
@@ -54,8 +26,6 @@ contract('MultisigWallet', function(accounts) {
await
wallet
.
kill
(
accounts
[
0
],
{
data
:
hash
});
let
txnHash
=
await
wallet
.
kill
(
accounts
[
0
],
{
from
:
accounts
[
1
],
data
:
hash
});
let
receiptMined
=
await
web3
.
eth
.
getTransactionReceiptMined
(
txnHash
);
//Get balances of owner and wallet after kill function is complete, compare with previous values
let
newOwnerBalance
=
web3
.
eth
.
getBalance
(
accounts
[
0
]);
let
newWalletBalance
=
web3
.
eth
.
getBalance
(
wallet
.
address
);
...
...
@@ -66,10 +36,7 @@ contract('MultisigWallet', function(accounts) {
it
(
'should execute transaction if below daily limit'
,
async
function
()
{
//Give account[0] 20 ether
web3
.
eth
.
sendTransaction
({
from
:
web3
.
eth
.
coinbase
,
to
:
accounts
[
0
],
value
:
web3
.
toWei
(
'20'
,
'ether'
)},
function
(
err
,
result
)
{
if
(
err
)
console
.
log
(
"ERROR:"
+
err
);
});
web3
.
eth
.
sendTransaction
({
from
:
web3
.
eth
.
coinbase
,
to
:
accounts
[
0
],
value
:
web3
.
toWei
(
'20'
,
'ether'
)},
shouldntFail
);
let
dailyLimit
=
10
;
let
ownersRequired
=
2
;
...
...
@@ -82,7 +49,6 @@ contract('MultisigWallet', function(accounts) {
//Owner account0 commands wallet to send 9 wei to account2
let
txnHash
=
await
wallet
.
execute
(
accounts
[
2
],
9
,
hash
);
let
receiptMined
=
await
web3
.
eth
.
getTransactionReceiptMined
(
txnHash
);
//Balance of account2 should have increased
let
newAccountBalance
=
web3
.
eth
.
getBalance
(
accounts
[
2
]);
...
...
@@ -91,10 +57,7 @@ contract('MultisigWallet', function(accounts) {
it
(
'should prevent execution of transaction if above daily limit'
,
async
function
()
{
//Give account[0] 20 ether
web3
.
eth
.
sendTransaction
({
from
:
web3
.
eth
.
coinbase
,
to
:
accounts
[
0
],
value
:
web3
.
toWei
(
'20'
,
'ether'
)},
function
(
err
,
result
)
{
if
(
err
)
console
.
log
(
"ERROR:"
+
err
);
});
web3
.
eth
.
sendTransaction
({
from
:
web3
.
eth
.
coinbase
,
to
:
accounts
[
0
],
value
:
web3
.
toWei
(
'20'
,
'ether'
)},
shouldntFail
);
let
dailyLimit
=
10
;
let
ownersRequired
=
2
;
...
...
@@ -107,7 +70,6 @@ contract('MultisigWallet', function(accounts) {
//Owner account0 commands wallet to send 9 wei to account2
let
txnHash
=
await
wallet
.
execute
(
accounts
[
2
],
9
,
hash
);
let
receiptMined
=
await
web3
.
eth
.
getTransactionReceiptMined
(
txnHash
);
//Balance of account2 should have increased
let
newAccountBalance
=
web3
.
eth
.
getBalance
(
accounts
[
2
]);
...
...
@@ -118,7 +80,6 @@ contract('MultisigWallet', function(accounts) {
//Owner account0 commands wallet to send 2 more wei to account2, going over the daily limit of 10
txnHash
=
await
wallet
.
execute
(
accounts
[
2
],
2
,
hash
);
receiptMined
=
await
web3
.
eth
.
getTransactionReceiptMined
(
txnHash
);
//Balance of account2 should not change
newAccountBalance
=
web3
.
eth
.
getBalance
(
accounts
[
2
]);
...
...
@@ -127,10 +88,7 @@ contract('MultisigWallet', function(accounts) {
it
(
'should execute transaction if above daily limit and enough owners approve'
,
async
function
()
{
//Give account[0] 20 ether
web3
.
eth
.
sendTransaction
({
from
:
web3
.
eth
.
coinbase
,
to
:
accounts
[
0
],
value
:
web3
.
toWei
(
'20'
,
'ether'
)},
function
(
err
,
result
)
{
if
(
err
)
console
.
log
(
"ERROR:"
+
err
);
});
web3
.
eth
.
sendTransaction
({
from
:
web3
.
eth
.
coinbase
,
to
:
accounts
[
0
],
value
:
web3
.
toWei
(
'20'
,
'ether'
)},
shouldntFail
);
let
dailyLimit
=
10
;
let
ownersRequired
=
2
;
...
...
@@ -143,7 +101,6 @@ contract('MultisigWallet', function(accounts) {
//Owner account0 commands wallet to send 11 wei to account2
let
txnHash
=
await
wallet
.
execute
(
accounts
[
2
],
11
,
hash
);
let
receiptMined
=
await
web3
.
eth
.
getTransactionReceiptMined
(
txnHash
);
//Balance of account2 should not change
let
newAccountBalance
=
web3
.
eth
.
getBalance
(
accounts
[
2
]);
...
...
@@ -153,7 +110,6 @@ contract('MultisigWallet', function(accounts) {
//Owner account1 commands wallet to send 11 wei to account2
txnHash
=
await
wallet
.
execute
(
accounts
[
2
],
2
,
hash
);
receiptMined
=
await
web3
.
eth
.
getTransactionReceiptMined
(
txnHash
);
//Balance of account2 should change
newAccountBalance
=
web3
.
eth
.
getBalance
(
accounts
[
2
]);
...
...
test/Ownable.js
View file @
9bd51db2
'use strict'
;
var
Ownable
=
artifacts
.
require
(
'../contracts/ownership/Ownable.sol'
);
contract
(
'Ownable'
,
function
(
accounts
)
{
let
ownable
;
...
...
@@ -5,31 +9,30 @@ contract('Ownable', function(accounts) {
ownable
=
await
Ownable
.
new
();
});
it
(
"should have an owner"
,
async
function
()
{
it
(
'should have an owner'
,
async
function
()
{
let
owner
=
await
ownable
.
owner
();
assert
.
isTrue
(
owner
!=
0
);
assert
.
isTrue
(
owner
!=
=
0
);
});
it
(
"changes owner after transfer"
,
async
function
()
{
it
(
'changes owner after transfer'
,
async
function
()
{
let
other
=
accounts
[
1
];
let
transfer
=
await
ownable
.
transferOwnership
(
other
);
await
ownable
.
transferOwnership
(
other
);
let
owner
=
await
ownable
.
owner
();
assert
.
isTrue
(
owner
===
other
);
});
it
(
"should prevent non-owners from transfering"
,
async
function
()
{
it
(
'should prevent non-owners from transfering'
,
async
function
()
{
let
other
=
accounts
[
2
];
let
transfer
=
await
ownable
.
transferOwnership
(
other
,
{
from
:
accounts
[
2
]});
await
ownable
.
transferOwnership
(
other
,
{
from
:
accounts
[
2
]});
let
owner
=
await
ownable
.
owner
();
assert
.
isFalse
(
owner
===
other
);
});
it
(
"should guard ownership against stuck state"
,
async
function
()
{
let
ownable
=
Ownable
.
deployed
();
it
(
'should guard ownership against stuck state'
,
async
function
()
{
let
originalOwner
=
await
ownable
.
owner
();
let
transfer
=
await
ownable
.
transferOwnership
(
null
,
{
from
:
originalOwner
});
await
ownable
.
transferOwnership
(
null
,
{
from
:
originalOwner
});
let
newOwner
=
await
ownable
.
owner
();
assert
.
equal
(
originalOwner
,
newOwner
);
...
...
test/Pausable.js
View file @
9bd51db2
'use strict'
;
var
PausableMock
=
artifacts
.
require
(
'helpers/PausableMock.sol'
);
contract
(
'Pausable'
,
function
(
accounts
)
{
it
(
"can perform normal process in non-emergency"
,
async
function
()
{
it
(
'can perform normal process in non-emergency'
,
async
function
()
{
let
Pausable
=
await
PausableMock
.
new
();
let
count0
=
await
Pausable
.
count
();
assert
.
equal
(
count0
,
0
);
let
normalProcess
=
await
Pausable
.
normalProcess
();
await
Pausable
.
normalProcess
();
let
count1
=
await
Pausable
.
count
();
assert
.
equal
(
count1
,
1
);
});
it
(
"can not perform normal process in emergency"
,
async
function
()
{
it
(
'can not perform normal process in emergency'
,
async
function
()
{
let
Pausable
=
await
PausableMock
.
new
();
let
emergencyStop
=
await
Pausable
.
emergencyStop
();
await
Pausable
.
emergencyStop
();
let
count0
=
await
Pausable
.
count
();
assert
.
equal
(
count0
,
0
);
let
normalProcess
=
await
Pausable
.
normalProcess
();
await
Pausable
.
normalProcess
();
let
count1
=
await
Pausable
.
count
();
assert
.
equal
(
count1
,
0
);
});
it
(
"can not take drastic measure in non-emergency"
,
async
function
()
{
it
(
'can not take drastic measure in non-emergency'
,
async
function
()
{
let
Pausable
=
await
PausableMock
.
new
();
let
drasticMeasure
=
await
Pausable
.
drasticMeasure
();
await
Pausable
.
drasticMeasure
();
let
drasticMeasureTaken
=
await
Pausable
.
drasticMeasureTaken
();
assert
.
isFalse
(
drasticMeasureTaken
);
});
it
(
"can take a drastic measure in an emergency"
,
async
function
()
{
it
(
'can take a drastic measure in an emergency'
,
async
function
()
{
let
Pausable
=
await
PausableMock
.
new
();
let
emergencyStop
=
await
Pausable
.
emergencyStop
();
let
drasticMeasure
=
await
Pausable
.
drasticMeasure
();
await
Pausable
.
emergencyStop
();
await
Pausable
.
drasticMeasure
();
let
drasticMeasureTaken
=
await
Pausable
.
drasticMeasureTaken
();
assert
.
isTrue
(
drasticMeasureTaken
);
});
it
(
"should resume allowing normal process after emergency is over"
,
async
function
()
{
it
(
'should resume allowing normal process after emergency is over'
,
async
function
()
{
let
Pausable
=
await
PausableMock
.
new
();
let
emergencyStop
=
await
Pausable
.
emergencyStop
();
let
release
=
await
Pausable
.
release
();
let
normalProcess
=
await
Pausable
.
normalProcess
();
await
Pausable
.
emergencyStop
();
await
Pausable
.
release
();
await
Pausable
.
normalProcess
();
let
count0
=
await
Pausable
.
count
();
assert
.
equal
(
count0
,
1
);
...
...
test/PullPayment.js
View file @
9bd51db2
var
PullPaymentMock
=
artifacts
.
require
(
"./helpers/PullPaymentMock.sol"
);
contract
(
'PullPayment'
,
function
(
accounts
)
{
it
(
"can't call asyncSend externally"
,
async
function
()
{
...
...
test/SafeMath.js
View file @
9bd51db2
const
assertJump
=
require
(
'./helpers/assertJump'
);
var
SafeMathMock
=
artifacts
.
require
(
"./helpers/SafeMathMock.sol"
);
contract
(
'SafeMath'
,
function
(
accounts
)
{
...
...
test/Shareable.js
View file @
9bd51db2
var
ShareableMock
=
artifacts
.
require
(
"./helpers/ShareableMock.sol"
);
contract
(
'Shareable'
,
function
(
accounts
)
{
it
(
'should construct with correct owners and number of sigs required'
,
async
function
()
{
...
...
test/StandardToken.js
View file @
9bd51db2
const
assertJump
=
require
(
'./helpers/assertJump'
);
var
StandardTokenMock
=
artifacts
.
require
(
"./helpers/StandardTokenMock.sol"
);
contract
(
'StandardToken'
,
function
(
accounts
)
{
...
...
test/helpers/transactionMined.js
0 → 100644
View file @
9bd51db2
'use strict'
;
//from https://gist.github.com/xavierlepretre/88682e871f4ad07be4534ae560692ee6
module
.
export
=
web3
.
eth
.
transactionMined
=
function
(
txnHash
,
interval
)
{
var
transactionReceiptAsync
;
interval
=
interval
?
interval
:
500
;
transactionReceiptAsync
=
function
(
txnHash
,
resolve
,
reject
)
{
try
{
var
receipt
=
web3
.
eth
.
getTransactionReceipt
(
txnHash
);
if
(
receipt
===
null
)
{
setTimeout
(
function
()
{
transactionReceiptAsync
(
txnHash
,
resolve
,
reject
);
},
interval
);
}
else
{
resolve
(
receipt
);
}
}
catch
(
e
)
{
reject
(
e
);
}
};
if
(
Array
.
isArray
(
txnHash
))
{
var
promises
=
[];
txnHash
.
forEach
(
function
(
oneTxHash
)
{
promises
.
push
(
web3
.
eth
.
getTransactionReceiptMined
(
oneTxHash
,
interval
));
});
return
Promise
.
all
(
promises
);
}
else
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
transactionReceiptAsync
(
txnHash
,
resolve
,
reject
);
});
}
};
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