Skip to content

Commit 5814575

Browse files
fix(pulse): disable impl contract initializer (#2646)
* fix(pulse): disable impl contract initializer * fix: ctor and tests * fix: remove unnecessary initializable inherit
1 parent 1924af3 commit 5814575

File tree

5 files changed

+40
-22
lines changed

5 files changed

+40
-22
lines changed

target_chains/ethereum/contracts/contracts/pulse/Scheduler.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// SPDX-License-Identifier: Apache 2
22

33
pragma solidity ^0.8.0;
4-
54
import "@openzeppelin/contracts/utils/math/SafeCast.sol";
65
import "@openzeppelin/contracts/utils/math/SignedMath.sol";
76
import "@openzeppelin/contracts/utils/math/Math.sol";

target_chains/ethereum/contracts/contracts/pulse/SchedulerUpgradeable.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ contract SchedulerUpgradeable is
4545
}
4646

4747
/// @custom:oz-upgrades-unsafe-allow constructor
48-
constructor() initializer {}
48+
constructor() {
49+
_disableInitializers();
50+
}
4951

5052
/// Only the owner can upgrade the contract
5153
function _authorizeUpgrade(address) internal override onlyOwner {}

target_chains/ethereum/contracts/forge-test/PulseScheduler.t.sol

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,19 @@ contract SchedulerTest is Test, SchedulerEvents, PulseSchedulerTestUtils {
8181
uint128 keeperFee = 10 ** 14; // 0.0001 ether
8282

8383
SchedulerUpgradeable _scheduler = new SchedulerUpgradeable();
84-
proxy = new ERC1967Proxy(address(_scheduler), "");
84+
proxy = new ERC1967Proxy(
85+
address(_scheduler),
86+
abi.encodeWithSelector(
87+
SchedulerUpgradeable.initialize.selector,
88+
owner,
89+
admin,
90+
pyth,
91+
minBalancePerFeed,
92+
keeperFee
93+
)
94+
);
8595
scheduler = SchedulerUpgradeable(address(proxy));
8696

87-
scheduler.initialize(owner, admin, pyth, minBalancePerFeed, keeperFee);
88-
8997
reader = new MockReader(address(proxy));
9098

9199
// Start tests at a high timestamp to avoid underflow when we set

target_chains/ethereum/contracts/forge-test/PulseSchedulerGasBenchmark.t.sol

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,22 @@ contract PulseSchedulerGasBenchmark is Test, PulseSchedulerTestUtils {
2424
manager = address(1);
2525
admin = address(2);
2626
pyth = address(3);
27-
28-
SchedulerUpgradeable _scheduler = new SchedulerUpgradeable();
29-
proxy = new ERC1967Proxy(address(_scheduler), "");
30-
scheduler = SchedulerUpgradeable(address(proxy));
31-
3227
uint128 minBalancePerFeed = 10 ** 16; // 0.01 ether
3328
uint128 keeperFee = 10 ** 15; // 0.001 ether
3429

35-
scheduler.initialize(
36-
manager,
37-
admin,
38-
pyth,
39-
minBalancePerFeed,
40-
keeperFee
30+
SchedulerUpgradeable _scheduler = new SchedulerUpgradeable();
31+
proxy = new ERC1967Proxy(
32+
address(_scheduler),
33+
abi.encodeWithSelector(
34+
SchedulerUpgradeable.initialize.selector,
35+
manager,
36+
admin,
37+
pyth,
38+
minBalancePerFeed,
39+
keeperFee
40+
)
4141
);
42+
scheduler = SchedulerUpgradeable(address(proxy));
4243

4344
// Start tests at a high timestamp to avoid underflow when we set
4445
// `minPublishTime = timestamp - 1 hour` in updatePriceFeeds

target_chains/ethereum/contracts/forge-test/PulseSchedulerGovernance.t.sol

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,27 @@ contract PulseSchedulerGovernanceTest is Test {
2626

2727
function setUp() public {
2828
SchedulerUpgradeable _scheduler = new SchedulerUpgradeable();
29+
uint128 minBalancePerFeed = 10 ** 16; // 0.01 ether
30+
uint128 keeperFee = 10 ** 15; // 0.001 ether
31+
2932
// Deploy proxy contract and point it to implementation
30-
proxy = new ERC1967Proxy(address(_scheduler), "");
33+
proxy = new ERC1967Proxy(
34+
address(_scheduler),
35+
abi.encodeWithSelector(
36+
SchedulerUpgradeable.initialize.selector,
37+
owner,
38+
admin,
39+
pyth,
40+
minBalancePerFeed,
41+
keeperFee
42+
)
43+
);
3144
// Wrap in ABI to support easier calls
3245
scheduler = SchedulerUpgradeable(address(proxy));
3346

3447
// For testing upgrades
3548
scheduler2 = new SchedulerUpgradeable();
3649
schedulerInvalidMagic = new SchedulerInvalidMagic();
37-
38-
uint128 minBalancePerFeed = 10 ** 16; // 0.01 ether
39-
uint128 keeperFee = 10 ** 15; // 0.001 ether
40-
41-
scheduler.initialize(owner, admin, pyth, minBalancePerFeed, keeperFee);
4250
}
4351

4452
function testGetAdmin() public {

0 commit comments

Comments
 (0)