transform Ownable to initializers
This commit is contained in:
11
contracts/mocks/OwnableMock.sol
Normal file
11
contracts/mocks/OwnableMock.sol
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
pragma solidity ^0.4.24;
|
||||||
|
|
||||||
|
import { Ownable } from '../ownership/Ownable.sol';
|
||||||
|
|
||||||
|
contract OwnableMock is Ownable {
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,12 +1,13 @@
|
|||||||
pragma solidity ^0.4.24;
|
pragma solidity ^0.4.24;
|
||||||
|
|
||||||
|
import "../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 private _owner;
|
address private _owner;
|
||||||
|
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ contract Ownable {
|
|||||||
* @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.
|
||||||
*/
|
*/
|
||||||
constructor() public {
|
function initialize() public initializer {
|
||||||
_owner = msg.sender;
|
_owner = msg.sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,18 @@
|
|||||||
|
const { EVMRevert } = require('../helpers/EVMRevert');
|
||||||
|
const { expectThrow } = require('../helpers/expectThrow');
|
||||||
|
|
||||||
const { shouldBehaveLikeOwnable } = require('./Ownable.behavior');
|
const { shouldBehaveLikeOwnable } = require('./Ownable.behavior');
|
||||||
|
|
||||||
const Ownable = artifacts.require('Ownable');
|
const Ownable = artifacts.require('OwnableMock');
|
||||||
|
|
||||||
contract('Ownable', function ([_, owner, ...otherAccounts]) {
|
contract('Ownable', function ([_, owner, ...otherAccounts]) {
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
this.ownable = await Ownable.new({ from: owner });
|
this.ownable = await Ownable.new({ from: owner });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('cannot be reinitialized', async function () {
|
||||||
|
await expectThrow(this.ownable.initialize(), EVMRevert);
|
||||||
|
});
|
||||||
|
|
||||||
shouldBehaveLikeOwnable(owner, otherAccounts);
|
shouldBehaveLikeOwnable(owner, otherAccounts);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user