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
838509c0
Commit
838509c0
authored
Sep 26, 2018
by
Francisco Giordano
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'release-v2.0.0' of github.com:OpenZeppelin/openzeppelin-solidity into release-v2.0.0
parents
e6252d51
fa5ecd03
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
166 additions
and
318 deletions
+166
-318
CapperRole.sol
contracts/access/roles/CapperRole.sol
+8
-4
MinterRole.sol
contracts/access/roles/MinterRole.sol
+8
-4
PauserRole.sol
contracts/access/roles/PauserRole.sol
+8
-4
SignerRole.sol
contracts/access/roles/SignerRole.sol
+8
-4
BreakInvariantBountyMock.sol
contracts/mocks/BreakInvariantBountyMock.sol
+15
-6
SecureInvariantTargetBounty.sol
contracts/mocks/SecureInvariantTargetBounty.sol
+0
-20
Escrow.sol
contracts/payment/Escrow.sol
+0
-1
SplitPayment.sol
contracts/payment/SplitPayment.sol
+0
-1
ERC20Mintable.sol
contracts/token/ERC20/ERC20Mintable.sol
+0
-32
ERC721Mintable.sol
contracts/token/ERC721/ERC721Mintable.sol
+0
-33
PublicRole.behavior.js
test/access/roles/PublicRole.behavior.js
+5
-0
BreakInvariantBounty.test.js
test/drafts/BreakInvariantBounty.test.js
+77
-70
ERC20Mintable.behavior.js
test/token/ERC20/behaviors/ERC20Mintable.behavior.js
+18
-110
ERC721Holder.test.js
test/token/ERC721/ERC721Holder.test.js
+19
-0
ERC721MintBurn.behavior.js
test/token/ERC721/ERC721MintBurn.behavior.js
+0
-29
No files found.
contracts/access/roles/CapperRole.sol
View file @
838509c0
...
@@ -13,7 +13,7 @@ contract CapperRole is Initializable {
...
@@ -13,7 +13,7 @@ contract CapperRole is Initializable {
Roles.Role private cappers;
Roles.Role private cappers;
function initialize() public initializer {
function initialize() public initializer {
cappers.add
(msg.sender);
_addCapper
(msg.sender);
}
}
modifier onlyCapper() {
modifier onlyCapper() {
...
@@ -26,12 +26,16 @@ contract CapperRole is Initializable {
...
@@ -26,12 +26,16 @@ contract CapperRole is Initializable {
}
}
function addCapper(address account) public onlyCapper {
function addCapper(address account) public onlyCapper {
cappers.add(account);
_addCapper(account);
emit CapperAdded(account);
}
}
function renounceCapper() public {
function renounceCapper() public {
cappers.remove(msg.sender);
_removeCapper(msg.sender);
}
function _addCapper(address account) internal {
cappers.add(account);
emit CapperAdded(account);
}
}
function _removeCapper(address account) internal {
function _removeCapper(address account) internal {
...
...
contracts/access/roles/MinterRole.sol
View file @
838509c0
...
@@ -13,7 +13,7 @@ contract MinterRole is Initializable {
...
@@ -13,7 +13,7 @@ contract MinterRole is Initializable {
Roles.Role private minters;
Roles.Role private minters;
function initialize() public initializer {
function initialize() public initializer {
minters.add
(msg.sender);
_addMinter
(msg.sender);
}
}
modifier onlyMinter() {
modifier onlyMinter() {
...
@@ -26,12 +26,16 @@ contract MinterRole is Initializable {
...
@@ -26,12 +26,16 @@ contract MinterRole is Initializable {
}
}
function addMinter(address account) public onlyMinter {
function addMinter(address account) public onlyMinter {
minters.add(account);
_addMinter(account);
emit MinterAdded(account);
}
}
function renounceMinter() public {
function renounceMinter() public {
minters.remove(msg.sender);
_removeMinter(msg.sender);
}
function _addMinter(address account) internal {
minters.add(account);
emit MinterAdded(account);
}
}
function _removeMinter(address account) internal {
function _removeMinter(address account) internal {
...
...
contracts/access/roles/PauserRole.sol
View file @
838509c0
...
@@ -13,7 +13,7 @@ contract PauserRole is Initializable {
...
@@ -13,7 +13,7 @@ contract PauserRole is Initializable {
Roles.Role private pausers;
Roles.Role private pausers;
function initialize() public initializer {
function initialize() public initializer {
pausers.add
(msg.sender);
_addPauser
(msg.sender);
}
}
modifier onlyPauser() {
modifier onlyPauser() {
...
@@ -26,12 +26,16 @@ contract PauserRole is Initializable {
...
@@ -26,12 +26,16 @@ contract PauserRole is Initializable {
}
}
function addPauser(address account) public onlyPauser {
function addPauser(address account) public onlyPauser {
pausers.add(account);
_addPauser(account);
emit PauserAdded(account);
}
}
function renouncePauser() public {
function renouncePauser() public {
pausers.remove(msg.sender);
_removePauser(msg.sender);
}
function _addPauser(address account) internal {
pausers.add(account);
emit PauserAdded(account);
}
}
function _removePauser(address account) internal {
function _removePauser(address account) internal {
...
...
contracts/access/roles/SignerRole.sol
View file @
838509c0
...
@@ -13,7 +13,7 @@ contract SignerRole is Initializable {
...
@@ -13,7 +13,7 @@ contract SignerRole is Initializable {
Roles.Role private signers;
Roles.Role private signers;
function initialize() public initializer {
function initialize() public initializer {
signers.add
(msg.sender);
_addSigner
(msg.sender);
}
}
modifier onlySigner() {
modifier onlySigner() {
...
@@ -26,12 +26,16 @@ contract SignerRole is Initializable {
...
@@ -26,12 +26,16 @@ contract SignerRole is Initializable {
}
}
function addSigner(address account) public onlySigner {
function addSigner(address account) public onlySigner {
signers.add(account);
_addSigner(account);
emit SignerAdded(account);
}
}
function renounceSigner() public {
function renounceSigner() public {
signers.remove(msg.sender);
_removeSigner(msg.sender);
}
function _addSigner(address account) internal {
signers.add(account);
emit SignerAdded(account);
}
}
function _removeSigner(address account) internal {
function _removeSigner(address account) internal {
...
...
contracts/mocks/
InsecureInvariantTargetBounty
.sol
→
contracts/mocks/
BreakInvariantBountyMock
.sol
View file @
838509c0
...
@@ -6,15 +6,24 @@ pragma solidity ^0.4.24;
...
@@ -6,15 +6,24 @@ pragma solidity ^0.4.24;
import {BreakInvariantBounty, Target} from "../drafts/BreakInvariantBounty.sol";
import {BreakInvariantBounty, Target} from "../drafts/BreakInvariantBounty.sol";
contract InsecureInvariantTargetMock is Target {
contract TargetMock is Target {
function checkInvariant() public returns(bool) {
bool private exploited;
return false;
function exploitVulnerability() public {
exploited = true;
}
}
}
function checkInvariant() public returns (bool) {
if (exploited) {
return false;
}
return true;
}
}
contract
InsecureInvariantTargetBounty
is BreakInvariantBounty {
contract
BreakInvariantBountyMock
is BreakInvariantBounty {
function _deployContract() internal returns (address) {
function _deployContract() internal returns (address) {
return new
InsecureInvariant
TargetMock();
return new TargetMock();
}
}
}
}
contracts/mocks/SecureInvariantTargetBounty.sol
deleted
100644 → 0
View file @
e6252d51
pragma solidity ^0.4.24;
// When this line is split, truffle parsing fails.
// See: https://github.com/ethereum/solidity/issues/4871
// solium-disable-next-line max-len
import {BreakInvariantBounty, Target} from "../drafts/BreakInvariantBounty.sol";
contract SecureInvariantTargetMock is Target {
function checkInvariant() public returns(bool) {
return true;
}
}
contract SecureInvariantTargetBounty is BreakInvariantBounty {
function _deployContract() internal returns (address) {
return new SecureInvariantTargetMock();
}
}
contracts/payment/Escrow.sol
View file @
838509c0
...
@@ -45,7 +45,6 @@ contract Escrow is Initializable, Secondary {
...
@@ -45,7 +45,6 @@ contract Escrow is Initializable, Secondary {
*/
*/
function withdraw(address payee) public onlyPrimary {
function withdraw(address payee) public onlyPrimary {
uint256 payment = _deposits[payee];
uint256 payment = _deposits[payee];
assert(address(this).balance >= payment);
_deposits[payee] = 0;
_deposits[payee] = 0;
...
...
contracts/payment/SplitPayment.sol
View file @
838509c0
...
@@ -86,7 +86,6 @@ contract SplitPayment is Initializable {
...
@@ -86,7 +86,6 @@ contract SplitPayment is Initializable {
);
);
require(payment != 0);
require(payment != 0);
assert(address(this).balance >= payment);
_released[account] = _released[account].add(payment);
_released[account] = _released[account].add(payment);
_totalReleased = _totalReleased.add(payment);
_totalReleased = _totalReleased.add(payment);
...
...
contracts/token/ERC20/ERC20Mintable.sol
View file @
838509c0
...
@@ -10,27 +10,11 @@ import "../../access/roles/MinterRole.sol";
...
@@ -10,27 +10,11 @@ import "../../access/roles/MinterRole.sol";
* @dev ERC20 minting logic
* @dev ERC20 minting logic
*/
*/
contract ERC20Mintable is Initializable, ERC20, MinterRole {
contract ERC20Mintable is Initializable, ERC20, MinterRole {
event MintingFinished();
bool private _mintingFinished = false;
modifier onlyBeforeMintingFinished() {
require(!_mintingFinished);
_;
}
function initialize() public initializer {
function initialize() public initializer {
MinterRole.initialize();
MinterRole.initialize();
}
}
/**
/**
* @return true if the minting is finished.
*/
function mintingFinished() public view returns(bool) {
return _mintingFinished;
}
/**
* @dev Function to mint tokens
* @dev Function to mint tokens
* @param to The address that will receive the minted tokens.
* @param to The address that will receive the minted tokens.
* @param amount The amount of tokens to mint.
* @param amount The amount of tokens to mint.
...
@@ -42,25 +26,9 @@ contract ERC20Mintable is Initializable, ERC20, MinterRole {
...
@@ -42,25 +26,9 @@ contract ERC20Mintable is Initializable, ERC20, MinterRole {
)
)
public
public
onlyMinter
onlyMinter
onlyBeforeMintingFinished
returns (bool)
returns (bool)
{
{
_mint(to, amount);
_mint(to, amount);
return true;
return true;
}
}
/**
* @dev Function to stop minting new tokens.
* @return True if the operation was successful.
*/
function finishMinting()
public
onlyMinter
onlyBeforeMintingFinished
returns (bool)
{
_mintingFinished = true;
emit MintingFinished();
return true;
}
}
}
contracts/token/ERC721/ERC721Mintable.sol
View file @
838509c0
...
@@ -10,27 +10,11 @@ import "../../access/roles/MinterRole.sol";
...
@@ -10,27 +10,11 @@ import "../../access/roles/MinterRole.sol";
* @dev ERC721 minting logic
* @dev ERC721 minting logic
*/
*/
contract ERC721Mintable is Initializable, ERC721Full, MinterRole {
contract ERC721Mintable is Initializable, ERC721Full, MinterRole {
event MintingFinished();
bool private _mintingFinished = false;
modifier onlyBeforeMintingFinished() {
require(!_mintingFinished);
_;
}
function initialize() public initializer {
function initialize() public initializer {
MinterRole.initialize();
MinterRole.initialize();
}
}
/**
/**
* @return true if the minting is finished.
*/
function mintingFinished() public view returns(bool) {
return _mintingFinished;
}
/**
* @dev Function to mint tokens
* @dev Function to mint tokens
* @param to The address that will receive the minted tokens.
* @param to The address that will receive the minted tokens.
* @param tokenId The token id to mint.
* @param tokenId The token id to mint.
...
@@ -42,7 +26,6 @@ contract ERC721Mintable is Initializable, ERC721Full, MinterRole {
...
@@ -42,7 +26,6 @@ contract ERC721Mintable is Initializable, ERC721Full, MinterRole {
)
)
public
public
onlyMinter
onlyMinter
onlyBeforeMintingFinished
returns (bool)
returns (bool)
{
{
_mint(to, tokenId);
_mint(to, tokenId);
...
@@ -56,26 +39,10 @@ contract ERC721Mintable is Initializable, ERC721Full, MinterRole {
...
@@ -56,26 +39,10 @@ contract ERC721Mintable is Initializable, ERC721Full, MinterRole {
)
)
public
public
onlyMinter
onlyMinter
onlyBeforeMintingFinished
returns (bool)
returns (bool)
{
{
mint(to, tokenId);
mint(to, tokenId);
_setTokenURI(tokenId, tokenURI);
_setTokenURI(tokenId, tokenURI);
return true;
return true;
}
}
/**
* @dev Function to stop minting new tokens.
* @return True if the operation was successful.
*/
function finishMinting()
public
onlyMinter
onlyBeforeMintingFinished
returns (bool)
{
_mintingFinished = true;
emit MintingFinished();
return true;
}
}
}
test/access/roles/PublicRole.behavior.js
View file @
838509c0
...
@@ -89,6 +89,11 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], role
...
@@ -89,6 +89,11 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], role
(
await
this
.
contract
[
`is
${
rolename
}
`
](
authorized
)).
should
.
equal
(
false
);
(
await
this
.
contract
[
`is
${
rolename
}
`
](
authorized
)).
should
.
equal
(
false
);
});
});
it
(
`emits a
${
rolename
}
Removed event`
,
async
function
()
{
const
{
logs
}
=
await
this
.
contract
[
`renounce
${
rolename
}
`
]({
from
:
authorized
});
expectEvent
.
inLogs
(
logs
,
`
${
rolename
}
Removed`
,
{
account
:
authorized
});
});
it
(
'doesn
\'
t revert when renouncing unassigned role'
,
async
function
()
{
it
(
'doesn
\'
t revert when renouncing unassigned role'
,
async
function
()
{
await
this
.
contract
[
`renounce
${
rolename
}
`
]({
from
:
anyone
});
await
this
.
contract
[
`renounce
${
rolename
}
`
]({
from
:
anyone
});
});
});
...
...
test/drafts/BreakInvariantBounty.test.js
View file @
838509c0
...
@@ -2,97 +2,104 @@ const { ethGetBalance, ethSendTransaction } = require('../helpers/web3');
...
@@ -2,97 +2,104 @@ const { ethGetBalance, ethSendTransaction } = require('../helpers/web3');
const
expectEvent
=
require
(
'../helpers/expectEvent'
);
const
expectEvent
=
require
(
'../helpers/expectEvent'
);
const
{
assertRevert
}
=
require
(
'../helpers/assertRevert'
);
const
{
assertRevert
}
=
require
(
'../helpers/assertRevert'
);
const
SecureInvariantTargetBounty
=
artifacts
.
require
(
'SecureInvariantTargetBounty
'
);
const
BreakInvariantBountyMock
=
artifacts
.
require
(
'BreakInvariantBountyMock
'
);
const
InsecureInvariantTargetBounty
=
artifacts
.
require
(
'InsecureInvariantTargetBounty
'
);
const
TargetMock
=
artifacts
.
require
(
'TargetMock
'
);
require
(
'chai'
)
require
(
'chai'
)
.
use
(
require
(
'chai-bignumber'
)(
web3
.
BigNumber
))
.
use
(
require
(
'chai-bignumber'
)(
web3
.
BigNumber
))
.
should
();
.
should
();
const
sendReward
=
async
(
from
,
to
,
value
)
=>
ethSendTransaction
({
from
,
to
,
value
,
});
const
reward
=
new
web3
.
BigNumber
(
web3
.
toWei
(
1
,
'ether'
));
const
reward
=
new
web3
.
BigNumber
(
web3
.
toWei
(
1
,
'ether'
));
contract
(
'BreakInvariantBounty'
,
function
([
_
,
owner
,
researcher
,
nonTarget
])
{
contract
(
'BreakInvariantBounty'
,
function
([
_
,
owner
,
researcher
,
anyone
,
nonTarget
])
{
context
(
'against secure contract'
,
function
()
{
beforeEach
(
async
function
()
{
beforeEach
(
async
function
()
{
this
.
bounty
=
await
BreakInvariantBountyMock
.
new
({
from
:
owner
});
this
.
bounty
=
await
SecureInvariantTargetBounty
.
new
({
from
:
owner
});
});
});
it
(
'can set reward'
,
async
function
()
{
it
(
'can set reward'
,
async
function
()
{
await
sendReward
(
owner
,
this
.
bounty
.
address
,
reward
);
await
ethSendTransaction
({
from
:
owner
,
to
:
this
.
bounty
.
address
,
value
:
reward
});
(
await
ethGetBalance
(
this
.
bounty
.
address
)).
should
.
be
.
bignumber
.
equal
(
reward
);
});
const
balance
=
await
ethGetBalance
(
this
.
bounty
.
address
);
context
(
'with reward'
,
function
()
{
balance
.
should
.
be
.
bignumber
.
equal
(
reward
);
beforeEach
(
async
function
()
{
await
ethSendTransaction
({
from
:
owner
,
to
:
this
.
bounty
.
address
,
value
:
reward
});
});
});
context
(
'with reward'
,
function
()
{
describe
(
'destroy'
,
function
()
{
beforeEach
(
async
function
()
{
it
(
'returns all balance to the owner'
,
async
function
()
{
const
result
=
await
this
.
bounty
.
createTarget
({
from
:
researcher
});
const
ownerPreBalance
=
await
ethGetBalance
(
owner
);
const
event
=
expectEvent
.
inLogs
(
result
.
logs
,
'TargetCreated'
);
await
this
.
bounty
.
destroy
({
from
:
owner
,
gasPrice
:
0
});
const
ownerPostBalance
=
await
ethGetBalance
(
owner
);
this
.
targetAddress
=
event
.
args
.
createdAddress
;
await
sendReward
(
owner
,
this
.
bounty
.
address
,
reward
);
const
balance
=
await
ethGetBalance
(
this
.
bounty
.
address
);
(
await
ethGetBalance
(
this
.
bounty
.
address
)).
should
.
be
.
bignumber
.
equal
(
0
);
balance
.
should
.
be
.
bignumber
.
equal
(
reward
);
ownerPostBalance
.
sub
(
ownerPreBalance
)
.
should
.
be
.
bignumber
.
equal
(
reward
);
});
});
it
(
'cannot claim reward'
,
async
function
()
{
it
(
'reverts when called by anyone'
,
async
function
()
{
await
assertRevert
(
await
assertRevert
(
this
.
bounty
.
destroy
({
from
:
anyone
}));
this
.
bounty
.
claim
(
this
.
targetAddress
,
{
from
:
researcher
}),
);
});
});
});
});
});
context
(
'against broken contract'
,
function
()
{
beforeEach
(
async
function
()
{
this
.
bounty
=
await
InsecureInvariantTargetBounty
.
new
();
const
result
=
await
this
.
bounty
.
createTarget
({
from
:
researcher
});
describe
(
'claim'
,
function
()
{
const
event
=
expectEvent
.
inLogs
(
result
.
logs
,
'TargetCreated'
);
it
(
'is initially unclaimed'
,
async
function
()
{
(
await
this
.
bounty
.
claimed
()).
should
.
equal
(
false
);
this
.
targetAddress
=
event
.
args
.
createdAddress
;
});
await
sendReward
(
owner
,
this
.
bounty
.
address
,
reward
);
});
it
(
'can claim reward'
,
async
function
()
{
await
this
.
bounty
.
claim
(
this
.
targetAddress
,
{
from
:
researcher
});
const
claim
=
await
this
.
bounty
.
claimed
();
claim
.
should
.
equal
(
true
);
const
researcherPrevBalance
=
await
ethGetBalance
(
researcher
);
await
this
.
bounty
.
withdrawPayments
(
researcher
,
{
gasPrice
:
0
});
const
updatedBalance
=
await
ethGetBalance
(
this
.
bounty
.
address
);
updatedBalance
.
should
.
be
.
bignumber
.
equal
(
0
);
const
researcherCurrBalance
=
await
ethGetBalance
(
researcher
);
researcherCurrBalance
.
sub
(
researcherPrevBalance
).
should
.
be
.
bignumber
.
equal
(
reward
);
});
it
(
'cannot claim reward from non-target'
,
async
function
()
{
it
(
'can create claimable target'
,
async
function
()
{
await
assertRevert
(
const
{
logs
}
=
await
this
.
bounty
.
createTarget
({
from
:
researcher
});
this
.
bounty
.
claim
(
nonTarget
,
{
from
:
researcher
})
expectEvent
.
inLogs
(
logs
,
'TargetCreated'
);
);
});
});
context
(
'reward claimed'
,
function
()
{
context
(
'with target'
,
async
function
()
{
beforeEach
(
async
function
()
{
beforeEach
(
async
function
()
{
await
this
.
bounty
.
claim
(
this
.
targetAddress
,
{
from
:
researcher
});
const
{
logs
}
=
await
this
.
bounty
.
createTarget
({
from
:
researcher
});
const
event
=
expectEvent
.
inLogs
(
logs
,
'TargetCreated'
);
this
.
target
=
TargetMock
.
at
(
event
.
args
.
createdAddress
);
});
context
(
'before exploiting vulnerability'
,
async
function
()
{
it
(
'reverts when claiming reward'
,
async
function
()
{
await
assertRevert
(
this
.
bounty
.
claim
(
this
.
target
.
address
,
{
from
:
researcher
}));
});
});
context
(
'after exploiting vulnerability'
,
async
function
()
{
beforeEach
(
async
function
()
{
await
this
.
target
.
exploitVulnerability
({
from
:
researcher
});
});
it
(
'sends the reward to the researcher'
,
async
function
()
{
await
this
.
bounty
.
claim
(
this
.
target
.
address
,
{
from
:
anyone
});
const
researcherPreBalance
=
await
ethGetBalance
(
researcher
);
await
this
.
bounty
.
withdrawPayments
(
researcher
);
const
researcherPostBalance
=
await
ethGetBalance
(
researcher
);
researcherPostBalance
.
sub
(
researcherPreBalance
).
should
.
be
.
bignumber
.
equal
(
reward
);
(
await
ethGetBalance
(
this
.
bounty
.
address
)).
should
.
be
.
bignumber
.
equal
(
0
);
});
context
(
'after claiming'
,
async
function
()
{
beforeEach
(
async
function
()
{
await
this
.
bounty
.
claim
(
this
.
target
.
address
,
{
from
:
researcher
});
});
it
(
'is claimed'
,
async
function
()
{
(
await
this
.
bounty
.
claimed
()).
should
.
equal
(
true
);
});
it
(
'no longer accepts rewards'
,
async
function
()
{
await
assertRevert
(
ethSendTransaction
({
from
:
owner
,
to
:
this
.
bounty
.
address
,
value
:
reward
}));
});
});
});
});
});
it
(
'should no longer be payable'
,
async
function
()
{
context
(
'with non-target'
,
function
()
{
await
assertRevert
(
it
(
'reverts when claiming reward'
,
async
function
()
{
sendReward
(
owner
,
this
.
bounty
.
address
,
reward
)
await
assertRevert
(
this
.
bounty
.
claim
(
nonTarget
,
{
from
:
researcher
}));
);
}
);
});
});
});
});
});
});
...
...
test/token/ERC20/behaviors/ERC20Mintable.behavior.js
View file @
838509c0
...
@@ -11,136 +11,44 @@ function shouldBehaveLikeERC20Mintable (minter, [anyone]) {
...
@@ -11,136 +11,44 @@ function shouldBehaveLikeERC20Mintable (minter, [anyone]) {
const
ZERO_ADDRESS
=
'0x0000000000000000000000000000000000000000'
;
const
ZERO_ADDRESS
=
'0x0000000000000000000000000000000000000000'
;
describe
(
'as a mintable token'
,
function
()
{
describe
(
'as a mintable token'
,
function
()
{
describe
(
'mintingFinished'
,
function
()
{
describe
(
'mint'
,
function
()
{
context
(
'when token minting is not finished'
,
function
()
{
const
amount
=
100
;
it
(
'returns false'
,
async
function
()
{
(
await
this
.
token
.
mintingFinished
()).
should
.
equal
(
false
);
});
});
context
(
'when token minting is finished'
,
function
()
{
beforeEach
(
async
function
()
{
await
this
.
token
.
finishMinting
({
from
:
minter
});
});
it
(
'returns true'
,
async
function
()
{
(
await
this
.
token
.
mintingFinished
()).
should
.
equal
(
true
);
});
});
});
describe
(
'finishMinting'
,
function
()
{
context
(
'when the sender has minting permission'
,
function
()
{
context
(
'when the sender has minting permission'
,
function
()
{
const
from
=
minter
;
const
from
=
minter
;
context
(
'when token minting was not finished'
,
function
()
{
context
(
'for a zero amount'
,
function
()
{
it
(
'finishes token minting'
,
async
function
()
{
shouldMint
(
0
);
await
this
.
token
.
finishMinting
({
from
});
(
await
this
.
token
.
mintingFinished
()).
should
.
equal
(
true
);
});
it
(
'emits a mint finished event'
,
async
function
()
{
const
{
logs
}
=
await
this
.
token
.
finishMinting
({
from
});
await
expectEvent
.
inLogs
(
logs
,
'MintingFinished'
);
});
});
context
(
'when token minting was already finished'
,
function
()
{
beforeEach
(
async
function
()
{
await
this
.
token
.
finishMinting
({
from
});
});
it
(
'reverts'
,
async
function
()
{
await
assertRevert
(
this
.
token
.
finishMinting
({
from
}));
});
});
});
});
context
(
'when the sender doesn
\'
t have minting permission'
,
function
()
{
const
from
=
anyone
;
context
(
'when token minting was not finished'
,
function
()
{
context
(
'for a non-zero amount'
,
function
()
{
it
(
'reverts'
,
async
function
()
{
shouldMint
(
amount
);
await
assertRevert
(
this
.
token
.
finishMinting
({
from
}));
});
});
});
context
(
'when token minting was already finished'
,
function
(
)
{
function
shouldMint
(
amount
)
{
beforeEach
(
async
function
()
{
beforeEach
(
async
function
()
{
await
this
.
token
.
finishMinting
({
from
:
minter
});
({
logs
:
this
.
logs
}
=
await
this
.
token
.
mint
(
anyone
,
amount
,
{
from
}));
});
it
(
'reverts'
,
async
function
()
{
await
assertRevert
(
this
.
token
.
finishMinting
({
from
}));
});
});
});
});
describe
(
'mint'
,
function
()
{
const
amount
=
100
;
context
(
'when the sender has minting permission'
,
function
()
{
const
from
=
minter
;
context
(
'when token minting is not finished'
,
function
()
{
context
(
'for a zero amount'
,
function
()
{
shouldMint
(
0
);
});
});
context
(
'for a non-zero amount'
,
function
()
{
it
(
'mints the requested amount'
,
async
function
()
{
shouldMint
(
amount
);
(
await
this
.
token
.
balanceOf
(
anyone
)).
should
.
be
.
bignumber
.
equal
(
amount
);
});
});
function
shouldMint
(
amount
)
{
it
(
'emits a mint and a transfer event'
,
async
function
()
{
beforeEach
(
async
function
()
{
const
transferEvent
=
expectEvent
.
inLogs
(
this
.
logs
,
'Transfer'
,
{
({
logs
:
this
.
logs
}
=
await
this
.
token
.
mint
(
anyone
,
amount
,
{
from
}));
from
:
ZERO_ADDRESS
,
});
to
:
anyone
,
it
(
'mints the requested amount'
,
async
function
()
{
(
await
this
.
token
.
balanceOf
(
anyone
)).
should
.
be
.
bignumber
.
equal
(
amount
);
});
it
(
'emits a mint and a transfer event'
,
async
function
()
{
const
transferEvent
=
expectEvent
.
inLogs
(
this
.
logs
,
'Transfer'
,
{
from
:
ZERO_ADDRESS
,
to
:
anyone
,
});
transferEvent
.
args
.
value
.
should
.
be
.
bignumber
.
equal
(
amount
);
});
});
}
transferEvent
.
args
.
value
.
should
.
be
.
bignumber
.
equal
(
amount
);
});
context
(
'when token minting is finished'
,
function
()
{
beforeEach
(
async
function
()
{
await
this
.
token
.
finishMinting
({
from
:
minter
});
});
});
}
it
(
'reverts'
,
async
function
()
{
await
assertRevert
(
this
.
token
.
mint
(
anyone
,
amount
,
{
from
}));
});
});
});
});
context
(
'when the sender doesn
\'
t have minting permission'
,
function
()
{
context
(
'when the sender doesn
\'
t have minting permission'
,
function
()
{
const
from
=
anyone
;
const
from
=
anyone
;
context
(
'when token minting is not finished'
,
function
()
{
it
(
'reverts'
,
async
function
()
{
it
(
'reverts'
,
async
function
()
{
await
assertRevert
(
this
.
token
.
mint
(
anyone
,
amount
,
{
from
}));
await
assertRevert
(
this
.
token
.
mint
(
anyone
,
amount
,
{
from
}));
});
});
context
(
'when token minting is already finished'
,
function
()
{
beforeEach
(
async
function
()
{
await
this
.
token
.
finishMinting
({
from
:
minter
});
});
it
(
'reverts'
,
async
function
()
{
await
assertRevert
(
this
.
token
.
mint
(
anyone
,
amount
,
{
from
}));
});
});
});
});
});
});
});
...
...
test/token/ERC721/ERC721Holder.test.js
0 → 100644
View file @
838509c0
const
ERC721Holder
=
artifacts
.
require
(
'ERC721Holder.sol'
);
const
ERC721Mintable
=
artifacts
.
require
(
'ERC721MintableBurnableImpl.sol'
);
require
(
'chai'
)
.
should
();
contract
(
'ERC721Holder'
,
function
([
creator
])
{
it
(
'receives an ERC721 token'
,
async
function
()
{
const
token
=
await
ERC721Mintable
.
new
({
from
:
creator
});
const
tokenId
=
1
;
await
token
.
mint
(
creator
,
tokenId
,
{
from
:
creator
});
const
receiver
=
await
ERC721Holder
.
new
();
await
token
.
approve
(
receiver
.
address
,
tokenId
,
{
from
:
creator
});
await
token
.
safeTransferFrom
(
creator
,
receiver
.
address
,
tokenId
);
(
await
token
.
ownerOf
(
tokenId
)).
should
.
be
.
equal
(
receiver
.
address
);
});
});
test/token/ERC721/ERC721MintBurn.behavior.js
View file @
838509c0
...
@@ -117,35 +117,6 @@ function shouldBehaveLikeMintAndBurnERC721 (
...
@@ -117,35 +117,6 @@ function shouldBehaveLikeMintAndBurnERC721 (
});
});
});
});
});
});
describe
(
'finishMinting'
,
function
()
{
it
(
'allows the minter to finish minting'
,
async
function
()
{
const
{
logs
}
=
await
this
.
token
.
finishMinting
({
from
:
minter
});
expectEvent
.
inLogs
(
logs
,
'MintingFinished'
);
});
});
context
(
'mintingFinished'
,
function
()
{
beforeEach
(
async
function
()
{
await
this
.
token
.
finishMinting
({
from
:
minter
});
});
describe
(
'mint'
,
function
()
{
it
(
'reverts'
,
async
function
()
{
await
assertRevert
(
this
.
token
.
mint
(
owner
,
thirdTokenId
,
{
from
:
minter
})
);
});
});
describe
(
'mintWithTokenURI'
,
function
()
{
it
(
'reverts'
,
async
function
()
{
await
assertRevert
(
this
.
token
.
mintWithTokenURI
(
owner
,
thirdTokenId
,
MOCK_URI
,
{
from
:
minter
})
);
});
});
});
});
});
}
}
...
...
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