Skip to content

Commit

Permalink
Merge pull request #63 from CMTA/fb-initialize-patch-only
Browse files Browse the repository at this point in the history
Separate initialization call from the constructor
  • Loading branch information
veorq authored Nov 2, 2022
2 parents 863c7b0 + df938f8 commit 1987be5
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 33 deletions.
12 changes: 3 additions & 9 deletions contracts/CMTAT.sol
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 1987be5

Please sign in to comment.