From e2e05294b00569e515a653889f72eb545aeaa063 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Wed, 26 Sep 2018 18:01:02 -0300 Subject: [PATCH] convert RefundEscrow to initializers --- .../crowdsale/distribution/RefundableCrowdsale.sol | 8 +++++++- contracts/mocks/RefundEscrowMock.sol | 10 ++++++++++ contracts/payment/RefundEscrow.sol | 8 ++++++-- test/payment/RefundEscrow.test.js | 2 +- 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 contracts/mocks/RefundEscrowMock.sol diff --git a/contracts/crowdsale/distribution/RefundableCrowdsale.sol b/contracts/crowdsale/distribution/RefundableCrowdsale.sol index 80db88d41..2554cbc8e 100644 --- a/contracts/crowdsale/distribution/RefundableCrowdsale.sol +++ b/contracts/crowdsale/distribution/RefundableCrowdsale.sol @@ -26,7 +26,13 @@ contract RefundableCrowdsale is FinalizableCrowdsale { */ constructor(uint256 goal) public { require(goal > 0); - _escrow = new RefundEscrow(wallet()); + + // conditional added to make initializer idempotent in case of diamond inheritance + if (address(_escrow) == address(0)) { + _escrow = new RefundEscrow(); + _escrow.initialize(wallet()); + } + _goal = goal; } diff --git a/contracts/mocks/RefundEscrowMock.sol b/contracts/mocks/RefundEscrowMock.sol new file mode 100644 index 000000000..8316ff66c --- /dev/null +++ b/contracts/mocks/RefundEscrowMock.sol @@ -0,0 +1,10 @@ +pragma solidity ^0.4.24; + +import "../Initializable.sol"; +import "../payment/RefundEscrow.sol"; + +contract RefundEscrowMock is Initializable, RefundEscrow { + constructor(address beneficiary) public { + RefundEscrow.initialize(beneficiary); + } +} diff --git a/contracts/payment/RefundEscrow.sol b/contracts/payment/RefundEscrow.sol index ae7f9c463..5bcc66526 100644 --- a/contracts/payment/RefundEscrow.sol +++ b/contracts/payment/RefundEscrow.sol @@ -1,5 +1,6 @@ pragma solidity ^0.4.24; +import "../Initializable.sol"; import "./ConditionalEscrow.sol"; import "../ownership/Secondary.sol"; @@ -10,7 +11,7 @@ import "../ownership/Secondary.sol"; * The primary account may close the deposit period, and allow for either withdrawal * by the beneficiary, or refunds to the depositors. */ -contract RefundEscrow is Secondary, ConditionalEscrow { +contract RefundEscrow is Initializable, Secondary, ConditionalEscrow { enum State { Active, Refunding, Closed } event Closed(); @@ -23,7 +24,10 @@ contract RefundEscrow is Secondary, ConditionalEscrow { * @dev Constructor. * @param beneficiary The beneficiary of the deposits. */ - constructor(address beneficiary) public { + function initialize(address beneficiary) public initializer { + Secondary.initialize(); + ConditionalEscrow.initialize(); + require(beneficiary != address(0)); _beneficiary = beneficiary; _state = State.Active; diff --git a/test/payment/RefundEscrow.test.js b/test/payment/RefundEscrow.test.js index e412816c4..007e9e8bd 100644 --- a/test/payment/RefundEscrow.test.js +++ b/test/payment/RefundEscrow.test.js @@ -9,7 +9,7 @@ require('chai') .use(require('chai-bignumber')(BigNumber)) .should(); -const RefundEscrow = artifacts.require('RefundEscrow'); +const RefundEscrow = artifacts.require('RefundEscrowMock'); contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee2]) { const amount = web3.toWei(54.0, 'ether');