Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate initialization call from the constructor #63

Merged
merged 1 commit into from Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 3 additions & 9 deletions contracts/CMTAT.sol
Expand Up @@ -34,14 +34,8 @@ contract CMTAT is
string constant TEXT_TRANSFER_OK = "No restriction";

constructor(
address owner,
address forwarder,
string memory name,
string memory symbol,
string memory tokenId,
string memory terms
address forwarder
) MetaTxModule(forwarder) {
__CMTAT_init(owner, name, symbol, tokenId, terms);
}

function initialize(
Expand All @@ -66,7 +60,7 @@ contract CMTAT is
string memory symbol,
string memory tokenId,
string memory terms
) internal initializer {
) internal onlyInitializing {
__Context_init_unchained();
__Base_init_unchained(0, tokenId, terms);
__AccessControl_init_unchained();
Expand All @@ -77,7 +71,7 @@ contract CMTAT is
__CMTAT_init_unchained(owner);
}

function __CMTAT_init_unchained(address owner) internal initializer {
function __CMTAT_init_unchained(address owner) internal onlyInitializing {
_setupRole(DEFAULT_ADMIN_ROLE, owner);
_setupRole(ENFORCER_ROLE, owner);
_setupRole(MINTER_ROLE, owner);
Expand Down
4 changes: 2 additions & 2 deletions contracts/modules/BaseModule.sol
Expand Up @@ -28,7 +28,7 @@ abstract contract BaseModule is Initializable, ERC20Upgradeable {
uint8 decimals_,
string memory tokenId_,
string memory terms_
) internal initializer {
) internal onlyInitializing {
__ERC20_init(name_, symbol_);
_decimals = decimals_;
tokenId = tokenId_;
Expand All @@ -39,7 +39,7 @@ abstract contract BaseModule is Initializable, ERC20Upgradeable {
uint8 decimals_,
string memory tokenId_,
string memory terms_
) internal initializer {
) internal onlyInitializing {
_decimals = decimals_;
tokenId = tokenId_;
terms = terms_;
Expand Down
4 changes: 2 additions & 2 deletions contracts/modules/EnforcementModule.sol
Expand Up @@ -36,12 +36,12 @@ abstract contract EnforcementModule is
/**
* @dev Initializes the contract in unpaused state.
*/
function __Enforcement_init() internal initializer {
function __Enforcement_init() internal onlyInitializing {
__Context_init_unchained();
__Enforcement_init_unchained();
}

function __Enforcement_init_unchained() internal initializer {}
function __Enforcement_init_unchained() internal onlyInitializing {}

/**
* @dev Returns true if the contract is paused, and false otherwise.
Expand Down
4 changes: 2 additions & 2 deletions contracts/modules/SnapshotModule.sol
Expand Up @@ -36,12 +36,12 @@ abstract contract SnapshotModule is

uint256[] private _scheduledSnapshots;

function __Snapshot_init() internal initializer {
function __Snapshot_init() internal onlyInitializing {
__Context_init_unchained();
__Snapshot_init_unchained();
}

function __Snapshot_init_unchained() internal initializer {}
function __Snapshot_init_unchained() internal onlyInitializing{}

function _scheduleSnapshot(uint256 time) internal returns (uint256) {
require(block.timestamp < time, "Snapshot scheduled in the past");
Expand Down
4 changes: 2 additions & 2 deletions contracts/modules/ValidationModule.sol
Expand Up @@ -22,14 +22,14 @@ abstract contract ValidationModule is Initializable, ContextUpgradeable {
/**
* @dev Initializes the contract with rule engine.
*/
function __Validation_init(IRuleEngine ruleEngine_) internal initializer {
function __Validation_init(IRuleEngine ruleEngine_) internal onlyInitializing {
__Context_init_unchained();
__Validation_init_unchained(ruleEngine_);
}

function __Validation_init_unchained(IRuleEngine ruleEngine_)
internal
initializer
onlyInitializing
{
if (address(ruleEngine_) != address(0)) {
ruleEngine = ruleEngine_;
Expand Down
30 changes: 23 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion test/modules/AuthorizationModule.test.js
Expand Up @@ -9,7 +9,8 @@ contract(
'AuthorizationModule',
function ([_, owner, address1, address2, address3, fakeRuleEngine]) {
beforeEach(async function () {
this.cmtat = await CMTAT.new(owner, _, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner })
this.cmtat = await CMTAT.new(_, { from: owner })
await this.cmtat.initialize(owner, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner })
})

context('Authorization', function () {
Expand Down
3 changes: 2 additions & 1 deletion test/modules/BaseModule.test.js
Expand Up @@ -8,7 +8,8 @@ contract(
'BaseModule',
function ([_, owner, address1, address2, address3, fakeRuleEngine]) {
beforeEach(async function () {
this.cmtat = await CMTAT.new(owner, _, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner })
this.cmtat = await CMTAT.new(_, { from: owner })
await this.cmtat.initialize(owner, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner })
})

context('Token structure', function () {
Expand Down
3 changes: 2 additions & 1 deletion test/modules/BurnModule.test.js
Expand Up @@ -8,7 +8,8 @@ contract(
'BurnModule',
function ([_, owner, address1, address2, address3, fakeRuleEngine]) {
beforeEach(async function () {
this.cmtat = await CMTAT.new(owner, _, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner })
this.cmtat = await CMTAT.new(_, { from: owner })
await this.cmtat.initialize(owner, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner })
})

context('Burn', function () {
Expand Down
3 changes: 2 additions & 1 deletion test/modules/EnforcementModule.test.js
Expand Up @@ -8,7 +8,8 @@ contract(
'EnforcementModule',
function ([_, owner, address1, address2, address3, fakeRuleEngine]) {
beforeEach(async function () {
this.cmtat = await CMTAT.new(owner, _, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner })
this.cmtat = await CMTAT.new(_, { from: owner })
await this.cmtat.initialize(owner, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner })
})

context('Freeze', function () {
Expand Down
3 changes: 2 additions & 1 deletion test/modules/MetaTxModule.test.js
Expand Up @@ -28,8 +28,9 @@ contract(
]) {
beforeEach(async function () {
this.trustedForwarder = await MinimalForwarderMock.new()
this.cmtat = await CMTAT.new(this.trustedForwarder.address, { from: owner })
this.trustedForwarder.initialize()
this.cmtat = await CMTAT.new(owner, this.trustedForwarder.address, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner })
await this.cmtat.initialize(owner, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner })
})

context('Transferring without paying gas', function () {
Expand Down
3 changes: 2 additions & 1 deletion test/modules/MintModule.test.js
Expand Up @@ -8,7 +8,8 @@ contract(
'MintModule',
function ([_, owner, address1, address2, address3, fakeRuleEngine]) {
beforeEach(async function () {
this.cmtat = await CMTAT.new(owner, _, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner })
this.cmtat = await CMTAT.new(_, { from: owner })
await this.cmtat.initialize(owner, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner })
})

context('Minting', function () {
Expand Down
3 changes: 2 additions & 1 deletion test/modules/PauseModule.test.js
Expand Up @@ -6,7 +6,8 @@ const CMTAT = artifacts.require('CMTAT')

contract('PauseModule', function ([_, owner, address1, address2, address3]) {
beforeEach(async function () {
this.cmtat = await CMTAT.new(owner, _, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner })
this.cmtat = await CMTAT.new(_, { from: owner })
await this.cmtat.initialize(owner, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner })
})

context('Pause', function () {
Expand Down
3 changes: 2 additions & 1 deletion test/modules/SnapshotModule.test.js
Expand Up @@ -15,7 +15,8 @@ contract(
'SnapshotModule',
function ([_, owner, address1, address2, address3, fakeRuleEngine]) {
beforeEach(async function () {
this.cmtat = await CMTAT.new(owner, _, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner })
this.cmtat = await CMTAT.new(_, { from: owner })
await this.cmtat.initialize(owner, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner })
})

context('Snapshot scheduling', function () {
Expand Down
3 changes: 2 additions & 1 deletion test/modules/ValidationModule.test.js
Expand Up @@ -9,7 +9,8 @@ contract(
'ValidationModule',
function ([_, owner, address1, address2, address3, fakeRuleEngine]) {
beforeEach(async function () {
this.cmtat = await CMTAT.new(owner, _, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner })
this.cmtat = await CMTAT.new(_, { from: owner })
await this.cmtat.initialize(owner, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner })
})

context('Rule Engine', function () {
Expand Down