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
e35ba313
Commit
e35ba313
authored
Oct 27, 2016
by
Makoto Inoue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs to test success and fail case of claiming
parent
e8262f7c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
19 deletions
+84
-19
SimpleTokenBounty.sol
contracts/bounties/SimpleTokenBounty.sol
+4
-1
Bounty.js
test/Bounty.js
+80
-18
No files found.
contracts/bounties/SimpleTokenBounty.sol
View file @
e35ba313
...
...
@@ -22,6 +22,8 @@ contract SimpleTokenBounty is PullPayment {
address public factoryAddress;
mapping(address => address) public researchers;
event TargetCreated(address createdAddress);
function() payable {
if (claimed) throw;
}
...
...
@@ -33,6 +35,7 @@ contract SimpleTokenBounty is PullPayment {
function createTarget() returns(Target) {
target = Target(Factory(factoryAddress).deployContract());
researchers[target] = msg.sender;
TargetCreated(target);
return target;
}
...
...
@@ -44,7 +47,7 @@ contract SimpleTokenBounty is PullPayment {
address researcher = researchers[target];
if (researcher == 0) throw;
// Check Target contract invariants
if (
!
target.checkInvariant()) {
if (target.checkInvariant()) {
throw;
}
asyncSend(researcher, this.balance);
...
...
test/Bounty.js
View file @
e35ba313
contract
(
'Bounty'
,
function
(
accounts
)
{
before
(
function
(){
owner
=
accounts
[
0
];
researcher
=
accounts
[
1
];
var
sendReward
=
function
(
sender
,
receiver
,
value
){
web3
.
eth
.
sendTransaction
({
from
:
sender
,
to
:
receiver
,
value
:
value
})
}
contract
(
'Bounty'
,
function
(
accounts
)
{
it
(
"can create bounty contract with factory address"
,
function
(
done
){
var
target
=
SecureTargetMock
.
deployed
();
SimpleTokenBounty
.
new
(
target
.
address
).
then
(
function
(
bounty
){
return
bounty
.
factoryAddress
.
call
()
...
...
@@ -18,26 +22,21 @@ contract('Bounty', function(accounts) {
it
(
"sets reward"
,
function
(
done
){
var
target
=
SecureTargetMock
.
deployed
();
var
owner
=
accounts
[
0
];
var
reward
=
web3
.
toWei
(
1
,
"ether"
);
var
bounty
;
SimpleTokenBounty
.
new
(
target
.
address
).
then
(
function
(
bounty
){
web3
.
eth
.
sendTransaction
({
from
:
owner
,
to
:
bounty
.
address
,
value
:
reward
})
sendReward
(
owner
,
bounty
.
address
,
reward
);
assert
.
equal
(
reward
,
web3
.
eth
.
getBalance
(
bounty
.
address
).
toNumber
())
}).
then
(
done
);
})
describe
(
"SecureTargetMock"
,
function
(){
before
(
function
(){
targetFactory
=
SecureTargetFactory
.
deployed
();
})
it
(
"checkInvariant returns true"
,
function
(
done
){
var
targetFactory
=
SecureTargetFactory
.
deployed
();
var
bounty
;
SimpleTokenBounty
.
new
(
targetFactory
.
address
).
then
(
function
(
_bounty
)
{
bounty
=
_bounty
;
...
...
@@ -51,14 +50,46 @@ contract('Bounty', function(accounts) {
}).
then
(
done
);
})
})
describe
(
"InsecureTargetMock"
,
function
(){
before
(
function
(){
targetFactory
=
InsecureTargetFactory
.
deployed
();
it
(
"cannot calim reward"
,
function
(
done
){
var
targetFactory
=
SecureTargetFactory
.
deployed
();
var
owner
=
accounts
[
0
];
var
researcher
=
accounts
[
1
];
var
reward
=
web3
.
toWei
(
1
,
"ether"
);
SimpleTokenBounty
.
new
(
targetFactory
.
address
).
then
(
function
(
bounty
)
{
var
event
=
bounty
.
TargetCreated
({});
event
.
watch
(
function
(
err
,
result
)
{
event
.
stopWatching
();
if
(
err
)
{
throw
err
}
var
targetAddress
=
result
.
args
.
createdAddress
;
sendReward
(
owner
,
bounty
.
address
,
reward
);
assert
.
equal
(
reward
,
web3
.
eth
.
getBalance
(
bounty
.
address
).
toNumber
())
bounty
.
claim
(
targetAddress
,
{
from
:
researcher
}).
then
(
function
(){
throw
(
"should not come here"
)}).
catch
(
function
()
{
return
bounty
.
claimed
.
call
();
}).
then
(
function
(
result
)
{
assert
.
isFalse
(
result
);
bounty
.
withdrawPayments
({
from
:
researcher
}).
then
(
function
(){
throw
(
"should not come here"
)}).
catch
(
function
()
{
assert
.
equal
(
reward
,
web3
.
eth
.
getBalance
(
bounty
.
address
).
toNumber
())
done
();
})
})
})
bounty
.
createTarget
({
from
:
researcher
});
})
})
})
describe
(
"InsecureTargetMock"
,
function
(){
it
(
"checkInvariant returns false"
,
function
(
done
){
var
targetFactory
=
InsecureTargetFactory
.
deployed
();
var
bounty
;
SimpleTokenBounty
.
new
(
targetFactory
.
address
).
then
(
function
(
_bounty
)
{
bounty
=
_bounty
;
...
...
@@ -72,5 +103,36 @@ contract('Bounty', function(accounts) {
}).
then
(
done
);
})
it
(
"calims reward"
,
function
(
done
){
var
targetFactory
=
InsecureTargetFactory
.
deployed
();
var
owner
=
accounts
[
0
];
var
researcher
=
accounts
[
1
];
var
reward
=
web3
.
toWei
(
1
,
"ether"
);
SimpleTokenBounty
.
new
(
targetFactory
.
address
).
then
(
function
(
bounty
)
{
var
event
=
bounty
.
TargetCreated
({});
event
.
watch
(
function
(
err
,
result
)
{
event
.
stopWatching
();
if
(
err
)
{
throw
err
}
var
targetAddress
=
result
.
args
.
createdAddress
;
sendReward
(
owner
,
bounty
.
address
,
reward
);
assert
.
equal
(
reward
,
web3
.
eth
.
getBalance
(
bounty
.
address
).
toNumber
())
bounty
.
claim
(
targetAddress
,
{
from
:
researcher
}).
then
(
function
()
{
return
bounty
.
claimed
.
call
();
}).
then
(
function
(
result
)
{
assert
.
isTrue
(
result
);
return
bounty
.
withdrawPayments
({
from
:
researcher
})
}).
then
(
function
()
{
assert
.
equal
(
0
,
web3
.
eth
.
getBalance
(
bounty
.
address
).
toNumber
())
}).
then
(
done
);
})
bounty
.
createTarget
({
from
:
researcher
});
})
})
})
});
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