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
0ec09f41
Commit
0ec09f41
authored
Dec 05, 2016
by
Arseniy Klempner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create tests for Shareable
parent
ab93a8e3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
122 additions
and
0 deletions
+122
-0
ShareableMock.sol
contracts/test-helpers/ShareableMock.sol
+19
-0
Shareable.js
test/Shareable.js
+103
-0
No files found.
contracts/test-helpers/ShareableMock.sol
0 → 100644
View file @
0ec09f41
pragma solidity ^0.4.4;
import "../Shareable.sol";
contract ShareableMock is Shareable {
uint public count = 0;
function ShareableMock(address[] _owners, uint _required) Shareable(_owners, _required) {
}
function increaseCount(bytes32 action) onlymanyowners(action) {
count = count + 1;
}
function isOwnerConst(address _addr) constant returns (bool) {
return isOwner(_addr);
}
}
test/Shareable.js
0 → 100644
View file @
0ec09f41
contract
(
'Shareable'
,
function
(
accounts
)
{
it
(
'should construct with correct owners and number of sigs required'
,
async
function
()
{
let
requiredSigs
=
2
;
let
owners
=
accounts
.
slice
(
1
,
4
);
let
shareable
=
await
ShareableMock
.
new
(
owners
,
requiredSigs
);
let
required
=
await
shareable
.
required
();
assert
.
equal
(
required
,
requiredSigs
);
let
owner
=
await
shareable
.
getOwner
(
0
);
assert
.
equal
(
owner
,
accounts
[
0
]);
for
(
let
i
=
0
;
i
<
accounts
.
length
;
i
++
)
{
let
owner
=
await
shareable
.
getOwner
(
i
);
let
isowner
=
await
shareable
.
isOwnerConst
(
accounts
[
i
]);
if
(
i
<=
owners
.
length
)
{
assert
.
equal
(
accounts
[
i
],
owner
);
assert
.
isTrue
(
isowner
);
}
else
{
assert
.
notEqual
(
accounts
[
i
],
owner
);
assert
.
isFalse
(
isowner
);
}
}
});
it
(
'should only perform multisig function with enough sigs'
,
async
function
()
{
let
requiredSigs
=
3
;
let
owners
=
accounts
.
slice
(
1
,
4
);
let
shareable
=
await
ShareableMock
.
new
(
owners
,
requiredSigs
);
let
hash
=
1234
;
let
initCount
=
await
shareable
.
count
();
initCount
=
initCount
.
toString
();
for
(
let
i
=
0
;
i
<
requiredSigs
;
i
++
)
{
await
shareable
.
increaseCount
(
hash
,
{
from
:
accounts
[
i
]});
let
count
=
await
shareable
.
count
();
if
(
i
==
requiredSigs
-
1
)
{
assert
.
equal
(
Number
(
initCount
)
+
1
,
count
.
toString
());
}
else
{
assert
.
equal
(
initCount
,
count
.
toString
());
}
}
});
it
(
'should require approval from different owners'
,
async
function
()
{
let
requiredSigs
=
2
;
let
owners
=
accounts
.
slice
(
1
,
4
);
let
shareable
=
await
ShareableMock
.
new
(
owners
,
requiredSigs
);
let
hash
=
1234
;
let
initCount
=
await
shareable
.
count
();
initCount
=
initCount
.
toString
();
//Count shouldn't increase when the same owner calls repeatedly
for
(
let
i
=
0
;
i
<
2
;
i
++
)
{
await
shareable
.
increaseCount
(
hash
);
let
count
=
await
shareable
.
count
();
assert
.
equal
(
initCount
,
count
.
toString
());
}
});
it
(
'should reset sig count after operation is approved'
,
async
function
()
{
let
requiredSigs
=
3
;
let
owners
=
accounts
.
slice
(
1
,
4
);
let
shareable
=
await
ShareableMock
.
new
(
owners
,
requiredSigs
);
let
hash
=
1234
;
let
initCount
=
await
shareable
.
count
();
initCount
=
initCount
.
toString
();
for
(
let
i
=
0
;
i
<
requiredSigs
*
3
;
i
++
)
{
await
shareable
.
increaseCount
(
hash
,
{
from
:
accounts
[
i
%
4
]});
let
count
=
await
shareable
.
count
();
if
((
i
%
(
requiredSigs
))
==
requiredSigs
-
1
)
{
initCount
=
Number
(
initCount
)
+
1
;
assert
.
equal
(
initCount
,
count
.
toString
());
}
else
{
assert
.
equal
(
initCount
,
count
.
toString
());
}
}
});
it
(
'should not perform multisig function after an owner revokes'
,
async
function
()
{
let
requiredSigs
=
3
;
let
owners
=
accounts
.
slice
(
1
,
4
);
let
shareable
=
await
ShareableMock
.
new
(
owners
,
requiredSigs
);
let
hash
=
1234
;
let
initCount
=
await
shareable
.
count
();
initCount
=
initCount
.
toString
();
for
(
let
i
=
0
;
i
<
requiredSigs
;
i
++
)
{
if
(
i
==
1
)
{
await
shareable
.
revoke
(
hash
,
{
from
:
accounts
[
i
-
1
]});
}
await
shareable
.
increaseCount
(
hash
,
{
from
:
accounts
[
i
]});
let
count
=
await
shareable
.
count
();
assert
.
equal
(
initCount
,
count
.
toString
());
}
});
});
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