Commit d0ec491b by Francisco Giordano

adapt contracts for upgradeability

parent 38536f42
...@@ -10,6 +10,10 @@ import "../ownership/Ownable.sol"; ...@@ -10,6 +10,10 @@ import "../ownership/Ownable.sol";
contract Migrations is Ownable { contract Migrations is Ownable {
uint256 public lastCompletedMigration; uint256 public lastCompletedMigration;
function Migrations() public {
Ownable.initialize(msg.sender);
}
function setCompleted(uint256 completed) onlyOwner public { function setCompleted(uint256 completed) onlyOwner public {
lastCompletedMigration = completed; lastCompletedMigration = completed;
} }
......
...@@ -5,5 +5,7 @@ import "../token/ERC20/DetailedERC20.sol"; ...@@ -5,5 +5,7 @@ import "../token/ERC20/DetailedERC20.sol";
contract DetailedERC20Mock is StandardToken, DetailedERC20 { contract DetailedERC20Mock is StandardToken, DetailedERC20 {
function DetailedERC20Mock(string _name, string _symbol, uint8 _decimals) DetailedERC20(_name, _symbol, _decimals) public {} function DetailedERC20Mock(string _name, string _symbol, uint8 _decimals) public {
DetailedERC20.initialize(_name, _symbol, _decimals);
}
} }
...@@ -9,9 +9,9 @@ import "../token/ERC721/ERC721Token.sol"; ...@@ -9,9 +9,9 @@ import "../token/ERC721/ERC721Token.sol";
* and a public setter for metadata URI * and a public setter for metadata URI
*/ */
contract ERC721TokenMock is ERC721Token { contract ERC721TokenMock is ERC721Token {
function ERC721TokenMock(string name, string symbol) public function ERC721TokenMock(string name, string symbol) public {
ERC721Token(name, symbol) ERC721Token.initialize(name, symbol);
{ } }
function mint(address _to, uint256 _tokenId) public { function mint(address _to, uint256 _tokenId) public {
super._mint(_to, _tokenId); super._mint(_to, _tokenId);
......
...@@ -10,6 +10,8 @@ contract PausableMock is Pausable { ...@@ -10,6 +10,8 @@ contract PausableMock is Pausable {
uint256 public count; uint256 public count;
function PausableMock() public { function PausableMock() public {
Ownable.initialize(msg.sender);
drasticMeasureTaken = false; drasticMeasureTaken = false;
count = 0; count = 0;
} }
......
...@@ -7,6 +7,8 @@ import "../token/ERC20/PausableToken.sol"; ...@@ -7,6 +7,8 @@ import "../token/ERC20/PausableToken.sol";
contract PausableTokenMock is PausableToken { contract PausableTokenMock is PausableToken {
function PausableTokenMock(address initialAccount, uint initialBalance) public { function PausableTokenMock(address initialAccount, uint initialBalance) public {
Ownable.initialize(msg.sender);
balances[initialAccount] = initialBalance; balances[initialAccount] = initialBalance;
} }
......
pragma solidity ^0.4.21; pragma solidity ^0.4.21;
import 'zos-upgradeability/contracts/migrations/Initializable.sol';
/** /**
* @title Ownable * @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control * @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions". * functions, this simplifies the implementation of "user permissions".
*/ */
contract Ownable { contract Ownable is Initializable {
address public owner; address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/** /**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender * @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account. * account.
*/ */
function Ownable() public { function initialize(address sender) public isInitializer {
owner = msg.sender; owner = sender;
} }
/** /**
......
pragma solidity ^0.4.21; pragma solidity ^0.4.21;
import "./ERC20.sol"; import "./ERC20.sol";
import 'zos-upgradeability/contracts/migrations/Initializable.sol';
contract DetailedERC20 is Initializable, ERC20 {
contract DetailedERC20 is ERC20 {
string public name; string public name;
string public symbol; string public symbol;
uint8 public decimals; uint8 public decimals;
function DetailedERC20(string _name, string _symbol, uint8 _decimals) public { function initialize(string _name, string _symbol, uint8 _decimals) public isInitializer {
name = _name; name = _name;
symbol = _symbol; symbol = _symbol;
decimals = _decimals; decimals = _decimals;
......
pragma solidity ^0.4.21; pragma solidity ^0.4.21;
import "./SafeERC20.sol"; import "./SafeERC20.sol";
import "zos-upgradeability/contracts/migrations/Initializable.sol";
/** /**
* @title TokenTimelock * @title TokenTimelock
* @dev TokenTimelock is a token holder contract that will allow a * @dev TokenTimelock is a token holder contract that will allow a
* beneficiary to extract the tokens after a given release time * beneficiary to extract the tokens after a given release time
*/ */
contract TokenTimelock { contract TokenTimelock is Initializable {
using SafeERC20 for ERC20Basic; using SafeERC20 for ERC20Basic;
// ERC20 basic token contract being held // ERC20 basic token contract being held
...@@ -20,7 +20,7 @@ contract TokenTimelock { ...@@ -20,7 +20,7 @@ contract TokenTimelock {
// timestamp when token release is enabled // timestamp when token release is enabled
uint256 public releaseTime; uint256 public releaseTime;
function TokenTimelock(ERC20Basic _token, address _beneficiary, uint256 _releaseTime) public { function initialize(ERC20Basic _token, address _beneficiary, uint256 _releaseTime) public isInitializer {
// solium-disable-next-line security/no-block-members // solium-disable-next-line security/no-block-members
require(_releaseTime > block.timestamp); require(_releaseTime > block.timestamp);
token = _token; token = _token;
......
...@@ -6,6 +6,7 @@ import "./ERC20Basic.sol"; ...@@ -6,6 +6,7 @@ import "./ERC20Basic.sol";
import "./SafeERC20.sol"; import "./SafeERC20.sol";
import "../../ownership/Ownable.sol"; import "../../ownership/Ownable.sol";
import "../../math/SafeMath.sol"; import "../../math/SafeMath.sol";
import 'zos-upgradeability/contracts/migrations/Initializable.sol';
/** /**
...@@ -14,7 +15,7 @@ import "../../math/SafeMath.sol"; ...@@ -14,7 +15,7 @@ import "../../math/SafeMath.sol";
* typical vesting scheme, with a cliff and vesting period. Optionally revocable by the * typical vesting scheme, with a cliff and vesting period. Optionally revocable by the
* owner. * owner.
*/ */
contract TokenVesting is Ownable { contract TokenVesting is Initializable, Ownable {
using SafeMath for uint256; using SafeMath for uint256;
using SafeERC20 for ERC20Basic; using SafeERC20 for ERC20Basic;
...@@ -42,7 +43,8 @@ contract TokenVesting is Ownable { ...@@ -42,7 +43,8 @@ contract TokenVesting is Ownable {
* @param _duration duration in seconds of the period in which the tokens will vest * @param _duration duration in seconds of the period in which the tokens will vest
* @param _revocable whether the vesting is revocable or not * @param _revocable whether the vesting is revocable or not
*/ */
function TokenVesting( function initialize(
address _sender,
address _beneficiary, address _beneficiary,
uint256 _start, uint256 _start,
uint256 _cliff, uint256 _cliff,
...@@ -50,7 +52,10 @@ contract TokenVesting is Ownable { ...@@ -50,7 +52,10 @@ contract TokenVesting is Ownable {
bool _revocable bool _revocable
) )
public public
isInitializer
{ {
Ownable.initialize(_sender);
require(_beneficiary != address(0)); require(_beneficiary != address(0));
require(_cliff <= _duration); require(_cliff <= _duration);
......
...@@ -2,6 +2,7 @@ pragma solidity ^0.4.21; ...@@ -2,6 +2,7 @@ pragma solidity ^0.4.21;
import "./ERC721.sol"; import "./ERC721.sol";
import "./ERC721BasicToken.sol"; import "./ERC721BasicToken.sol";
import "zos-upgradeability/contracts/migrations/Initializable.sol";
/** /**
...@@ -10,7 +11,7 @@ import "./ERC721BasicToken.sol"; ...@@ -10,7 +11,7 @@ import "./ERC721BasicToken.sol";
* Moreover, it includes approve all functionality using operator terminology * Moreover, it includes approve all functionality using operator terminology
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
*/ */
contract ERC721Token is ERC721, ERC721BasicToken { contract ERC721Token is Initializable, ERC721, ERC721BasicToken {
// Token name // Token name
string internal name_; string internal name_;
...@@ -35,7 +36,7 @@ contract ERC721Token is ERC721, ERC721BasicToken { ...@@ -35,7 +36,7 @@ contract ERC721Token is ERC721, ERC721BasicToken {
/** /**
* @dev Constructor function * @dev Constructor function
*/ */
function ERC721Token(string _name, string _symbol) public { function initialize(string _name, string _symbol) public isInitializer {
name_ = _name; name_ = _name;
symbol_ = _symbol; symbol_ = _symbol;
} }
......
...@@ -2755,7 +2755,6 @@ ...@@ -2755,7 +2755,6 @@
"version": "0.2.1", "version": "0.2.1",
"resolved": "https://registry.npmjs.org/ethjs-abi/-/ethjs-abi-0.2.1.tgz", "resolved": "https://registry.npmjs.org/ethjs-abi/-/ethjs-abi-0.2.1.tgz",
"integrity": "sha1-4KepOn6BFjqUR3utVu3lJKtt5TM=", "integrity": "sha1-4KepOn6BFjqUR3utVu3lJKtt5TM=",
"dev": true,
"requires": { "requires": {
"bn.js": "4.11.6", "bn.js": "4.11.6",
"js-sha3": "0.5.5", "js-sha3": "0.5.5",
...@@ -2765,14 +2764,12 @@ ...@@ -2765,14 +2764,12 @@
"bn.js": { "bn.js": {
"version": "4.11.6", "version": "4.11.6",
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz",
"integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=", "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU="
"dev": true
}, },
"js-sha3": { "js-sha3": {
"version": "0.5.5", "version": "0.5.5",
"resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.5.5.tgz", "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.5.5.tgz",
"integrity": "sha1-uvDA6MVK1ZA0R9+Wreekobynmko=", "integrity": "sha1-uvDA6MVK1ZA0R9+Wreekobynmko="
"dev": true
} }
} }
}, },
...@@ -4824,8 +4821,7 @@ ...@@ -4824,8 +4821,7 @@
"is-hex-prefixed": { "is-hex-prefixed": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-hex-prefixed/-/is-hex-prefixed-1.0.0.tgz", "resolved": "https://registry.npmjs.org/is-hex-prefixed/-/is-hex-prefixed-1.0.0.tgz",
"integrity": "sha1-fY035q135dEnFIkTxXPggtd39VQ=", "integrity": "sha1-fY035q135dEnFIkTxXPggtd39VQ="
"dev": true
}, },
"is-my-json-valid": { "is-my-json-valid": {
"version": "2.16.0", "version": "2.16.0",
...@@ -6394,7 +6390,6 @@ ...@@ -6394,7 +6390,6 @@
"version": "1.7.0", "version": "1.7.0",
"resolved": "https://registry.npmjs.org/number-to-bn/-/number-to-bn-1.7.0.tgz", "resolved": "https://registry.npmjs.org/number-to-bn/-/number-to-bn-1.7.0.tgz",
"integrity": "sha1-uzYjWS9+X54AMLGXe9QaDFP+HqA=", "integrity": "sha1-uzYjWS9+X54AMLGXe9QaDFP+HqA=",
"dev": true,
"requires": { "requires": {
"bn.js": "4.11.6", "bn.js": "4.11.6",
"strip-hex-prefix": "1.0.0" "strip-hex-prefix": "1.0.0"
...@@ -6403,8 +6398,7 @@ ...@@ -6403,8 +6398,7 @@
"bn.js": { "bn.js": {
"version": "4.11.6", "version": "4.11.6",
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz",
"integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=", "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU="
"dev": true
} }
} }
}, },
...@@ -8025,7 +8019,6 @@ ...@@ -8025,7 +8019,6 @@
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/strip-hex-prefix/-/strip-hex-prefix-1.0.0.tgz", "resolved": "https://registry.npmjs.org/strip-hex-prefix/-/strip-hex-prefix-1.0.0.tgz",
"integrity": "sha1-DF8VX+8RUTczd96du1iNoFUA428=", "integrity": "sha1-DF8VX+8RUTczd96du1iNoFUA428=",
"dev": true,
"requires": { "requires": {
"is-hex-prefixed": "1.0.0" "is-hex-prefixed": "1.0.0"
} }
...@@ -9452,6 +9445,21 @@ ...@@ -9452,6 +9445,21 @@
} }
} }
} }
},
"zeppelin-solidity": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/zeppelin-solidity/-/zeppelin-solidity-1.8.0.tgz",
"integrity": "sha512-7Mxq6Y7EES0PSLrRF6v0EVYqBVRRo8hFrr7m3jEs69VbbQ5kpANzizeEdbP1/PWKSOmBOg208qP2vSA0FlzFLA==",
"requires": {
"dotenv": "4.0.0",
"ethjs-abi": "0.2.1"
}
},
"zos-upgradeability": {
"version": "git://github.com/zeppelinos/upgradeability-lib.git#68cd61fb48d0e4eec7142241448efa40c395bf33",
"requires": {
"zeppelin-solidity": "1.8.0"
}
} }
} }
} }
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
"truffle-hdwallet-provider": "0.0.3" "truffle-hdwallet-provider": "0.0.3"
}, },
"dependencies": { "dependencies": {
"dotenv": "^4.0.0" "dotenv": "^4.0.0",
"zos-upgradeability": "git://github.com/zeppelinos/upgradeability-lib.git"
} }
} }
...@@ -8,6 +8,7 @@ contract('Ownable', function (accounts) { ...@@ -8,6 +8,7 @@ contract('Ownable', function (accounts) {
beforeEach(async function () { beforeEach(async function () {
ownable = await Ownable.new(); ownable = await Ownable.new();
await ownable.initialize(accounts[0]);
}); });
it('should have an owner', async function () { it('should have an owner', async function () {
......
...@@ -3,7 +3,8 @@ const MintableToken = artifacts.require('MintableToken'); ...@@ -3,7 +3,8 @@ const MintableToken = artifacts.require('MintableToken');
contract('Mintable', function ([owner, anotherAccount]) { contract('Mintable', function ([owner, anotherAccount]) {
beforeEach(async function () { beforeEach(async function () {
this.token = await MintableToken.new({ from: owner }); this.token = await MintableToken.new();
await this.token.initialize(owner);
}); });
describe('minting finished', function () { describe('minting finished', function () {
......
...@@ -15,9 +15,11 @@ contract('TokenTimelock', function ([_, owner, beneficiary]) { ...@@ -15,9 +15,11 @@ contract('TokenTimelock', function ([_, owner, beneficiary]) {
const amount = new BigNumber(100); const amount = new BigNumber(100);
beforeEach(async function () { beforeEach(async function () {
this.token = await MintableToken.new({ from: owner }); this.token = await MintableToken.new();
await this.token.initialize(owner);
this.releaseTime = latestTime() + duration.years(1); this.releaseTime = latestTime() + duration.years(1);
this.timelock = await TokenTimelock.new(this.token.address, beneficiary, this.releaseTime); this.timelock = await TokenTimelock.new();
await this.timelock.initialize(this.token.address, beneficiary, this.releaseTime);
await this.token.mint(this.timelock.address, amount, { from: owner }); await this.token.mint(this.timelock.address, amount, { from: owner });
}); });
......
...@@ -16,13 +16,15 @@ contract('TokenVesting', function ([_, owner, beneficiary]) { ...@@ -16,13 +16,15 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
const amount = new BigNumber(1000); const amount = new BigNumber(1000);
beforeEach(async function () { beforeEach(async function () {
this.token = await MintableToken.new({ from: owner }); this.token = await MintableToken.new();
await this.token.initialize(owner);
this.start = latestTime() + duration.minutes(1); // +1 minute so it starts after contract instantiation this.start = latestTime() + duration.minutes(1); // +1 minute so it starts after contract instantiation
this.cliff = duration.years(1); this.cliff = duration.years(1);
this.duration = duration.years(2); this.duration = duration.years(2);
this.vesting = await TokenVesting.new(beneficiary, this.start, this.cliff, this.duration, true, { from: owner }); this.vesting = await TokenVesting.new();
await this.vesting.initialize(owner, beneficiary, this.start, this.cliff, this.duration, true);
await this.token.mint(this.vesting.address, amount, { from: owner }); await this.token.mint(this.vesting.address, amount, { from: owner });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment