convert RefundEscrow to initializers
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
|
||||
10
contracts/mocks/RefundEscrowMock.sol
Normal file
10
contracts/mocks/RefundEscrowMock.sol
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
@ -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');
|
||||
|
||||
Reference in New Issue
Block a user