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
52120a8c
Commit
52120a8c
authored
Mar 20, 2017
by
Manuel Araoz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
5.3 always throw on error
parent
a1aa74f9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
34 deletions
+32
-34
Pausable.sol
contracts/lifecycle/Pausable.sol
+6
-4
Shareable.sol
contracts/ownership/Shareable.sol
+3
-1
ERC20.sol
contracts/token/ERC20.sol
+6
-7
StandardToken.sol
contracts/token/StandardToken.sol
+4
-18
Pausable.js
test/Pausable.js
+13
-4
No files found.
contracts/lifecycle/Pausable.sol
View file @
52120a8c
...
...
@@ -13,15 +13,17 @@ contract Pausable is Ownable {
bool public stopped;
modifier stopInEmergency {
if (
!
stopped) {
_
;
if (stopped) {
throw
;
}
_;
}
modifier onlyInEmergency {
if (stopped) {
_
;
if (
!
stopped) {
throw
;
}
_;
}
// called by the owner on emergency, triggers stopped state
...
...
contracts/ownership/Shareable.sol
View file @
52120a8c
...
...
@@ -105,12 +105,13 @@ contract Shareable {
return !(pending.ownersDone & ownerIndexBit == 0);
}
// returns true when operation can be executed
function confirmAndCheck(bytes32 _operation) internal returns (bool) {
// determine what index the present sender is:
uint index = ownerIndex[msg.sender];
// make sure they're an owner
if (index == 0) {
return
;
throw
;
}
var pending = pendings[_operation];
...
...
@@ -140,6 +141,7 @@ contract Shareable {
pending.ownersDone |= ownerIndexBit;
}
}
return false;
}
function clearPending() internal {
...
...
contracts/token/ERC20.sol
View file @
52120a8c
pragma solidity ^0.4.8;
import './ERC20Basic.sol';
/*
* ERC20 interface
* see https://github.com/ethereum/EIPs/issues/20
*/
contract ERC20 {
uint public totalSupply;
function balanceOf(address who) constant returns (uint);
contract ERC20 is ERC20Basic {
function allowance(address owner, address spender) constant returns (uint);
function transfer(address to, uint value) returns (bool ok);
function transferFrom(address from, address to, uint value) returns (bool ok);
function approve(address spender, uint value) returns (bool ok);
event Transfer(address indexed from, address indexed to, uint value);
function transferFrom(address from, address to, uint value);
function approve(address spender, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
}
contracts/token/StandardToken.sol
View file @
52120a8c
pragma solidity ^0.4.8;
import './BasicToken.sol';
import './ERC20.sol';
import '../SafeMath.sol';
/**
...
...
@@ -12,19 +12,11 @@ import '../SafeMath.sol';
* Based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/
contract StandardToken is
ERC20, SafeMath
{
contract StandardToken is
BasicToken, ERC20
{
mapping(address => uint) balances;
mapping (address => mapping (address => uint)) allowed;
function transfer(address _to, uint _value) returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], _value);
balances[_to] = safeAdd(balances[_to], _value);
Transfer(msg.sender, _to, _value);
return true;
}
function transferFrom(address _from, address _to, uint _value) returns (bool success) {
function transferFrom(address _from, address _to, uint _value) {
var _allowance = allowed[_from][msg.sender];
// Check is not needed because safeSub(_allowance, _value) will already throw if this condition is not met
...
...
@@ -34,17 +26,11 @@ contract StandardToken is ERC20, SafeMath {
balances[_from] = safeSub(balances[_from], _value);
allowed[_from][msg.sender] = safeSub(_allowance, _value);
Transfer(_from, _to, _value);
return true;
}
function balanceOf(address _owner) constant returns (uint balance) {
return balances[_owner];
}
function approve(address _spender, uint _value)
returns (bool success)
{
function approve(address _spender, uint _value) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint remaining) {
...
...
test/Pausable.js
View file @
52120a8c
'use strict'
;
var
PausableMock
=
artifacts
.
require
(
'helpers/PausableMock.sol'
);
const
assertJump
=
require
(
'./helpers/assertJump'
);
const
PausableMock
=
artifacts
.
require
(
'helpers/PausableMock.sol'
);
contract
(
'Pausable'
,
function
(
accounts
)
{
...
...
@@ -20,7 +21,11 @@ contract('Pausable', function(accounts) {
let
count0
=
await
Pausable
.
count
();
assert
.
equal
(
count0
,
0
);
await
Pausable
.
normalProcess
();
try
{
await
Pausable
.
normalProcess
();
}
catch
(
error
)
{
assertJump
(
error
);
}
let
count1
=
await
Pausable
.
count
();
assert
.
equal
(
count1
,
0
);
});
...
...
@@ -28,9 +33,13 @@ contract('Pausable', function(accounts) {
it
(
'can not take drastic measure in non-emergency'
,
async
function
()
{
let
Pausable
=
await
PausableMock
.
new
();
await
Pausable
.
drasticMeasure
();
let
drasticMeasureTaken
=
await
Pausable
.
drasticMeasureTaken
();
try
{
await
Pausable
.
drasticMeasure
();
}
catch
(
error
)
{
assertJump
(
error
);
}
const
drasticMeasureTaken
=
await
Pausable
.
drasticMeasureTaken
();
assert
.
isFalse
(
drasticMeasureTaken
);
});
...
...
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