Skip to content

Commit 905b45e

Browse files
committed
cr fixes
1 parent 5f67014 commit 905b45e

File tree

5 files changed

+33
-12
lines changed

5 files changed

+33
-12
lines changed

script/Deploy.s.sol

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ contract Deploy is Script, DeployUtils {
3030
error InvalidEnv();
3131

3232
function run() external {
33-
_ensureEnvsExist();
34-
3533
admin = vm.addr(vm.envUint("PRIVATE_KEY_TEST"));
3634
allocator = vm.envAddress("ALLOCATOR");
3735
terminationOracle = vm.envAddress("TERMINATION_ORACLE");
@@ -57,16 +55,6 @@ contract Deploy is Script, DeployUtils {
5755
_serializeAndSaveArtifact();
5856
}
5957

60-
function _ensureEnvsExist() internal view {
61-
if (
62-
!vm.envExists("RPC_TEST") || !vm.envExists("PRIVATE_KEY_TEST") || !vm.envExists("FILECOIN_PAY")
63-
|| !vm.envExists("SP_REGISTRY") || !vm.envExists("ALLOCATOR") || !vm.envExists("TERMINATION_ORACLE")
64-
|| !vm.envExists("ORACLE")
65-
) {
66-
revert InvalidEnv();
67-
}
68-
}
69-
7058
function _deployValidatorFactory(address _admin) internal returns (address proxy) {
7159
Validator validatorImpl = new Validator();
7260
ValidatorFactory impl = new ValidatorFactory();

src/PoRepMarket.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ contract PoRepMarket is Initializable, AccessControlUpgradeable, UUPSUpgradeable
134134
error ValidatorAlreadySet(uint256 dealId);
135135
error InvalidRetrievabilityPct(uint8 value);
136136
error InvalidIndexingPct(uint8 value);
137+
error InvalidClientSmartContractAddress();
137138

138139
/**
139140
* @notice Constructor
@@ -166,6 +167,7 @@ contract PoRepMarket is Initializable, AccessControlUpgradeable, UUPSUpgradeable
166167
* @param _clientSmartContract The address of the client smart contract
167168
*/
168169
function setClientSmartContract(address _clientSmartContract) public onlyRole(DEFAULT_ADMIN_ROLE) {
170+
if (_clientSmartContract == address(0)) revert InvalidClientSmartContractAddress();
169171
DealProposalsStorage storage $ = _getDealProposalsStorage();
170172
$._clientSmartContract = _clientSmartContract;
171173
emit ClientSmartContractUpdated(_clientSmartContract);

src/ValidatorFactory.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ contract ValidatorFactory is UUPSUpgradeable, AccessControlUpgradeable {
5858
error InvalidAdminAddress();
5959
error InvalidClientAddress();
6060
error InvalidSlcAddress();
61+
error InvalidPoRepMarketAddress();
62+
error InvalidClientSmartContractAddress();
63+
error InvalidFilecoinPayAddress();
6164

6265
/**
6366
* @notice Emitted when a new proxy is successfully created
@@ -92,6 +95,10 @@ contract ValidatorFactory is UUPSUpgradeable, AccessControlUpgradeable {
9295
external
9396
reinitializer(2)
9497
{
98+
if (_poRepMarket == address(0)) revert InvalidPoRepMarketAddress();
99+
if (_clientSmartContract == address(0)) revert InvalidClientSmartContractAddress();
100+
if (_filecoinPay == address(0)) revert InvalidFilecoinPayAddress();
101+
95102
ValidatorFactoryStorage storage $ = s();
96103
$._poRepMarket = _poRepMarket;
97104
$._clientSmartContract = _clientSmartContract;

test/PoRepMarket.t.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,4 +347,10 @@ contract PoRepMarketTest is Test {
347347
vm.expectRevert(abi.encodeWithSelector(PoRepMarket.InvalidIndexingPct.selector, uint8(101)));
348348
poRepMarket.proposeDeal(badRequirements, defaultTerms);
349349
}
350+
351+
function testSetClientSmartContractRevertsWhenAddressIsZero() public {
352+
vm.prank(adminAddress);
353+
vm.expectRevert(abi.encodeWithSelector(PoRepMarket.InvalidClientSmartContractAddress.selector));
354+
poRepMarket.setClientSmartContract(address(0));
355+
}
350356
}

test/ValidatorFactory.t.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,22 @@ contract ValidatorFactoryTest is Test {
161161
vm.prank(incorrectClient);
162162
factory.create(admin, slcAddress, provider, params);
163163
}
164+
165+
function testInitialize2RevertsWhenPoRepMarketIsZero() public {
166+
ValidatorFactory f = ValidatorFactory(address(new ERC1967Proxy(address(factoryImpl), initData)));
167+
vm.expectRevert(abi.encodeWithSelector(ValidatorFactory.InvalidPoRepMarketAddress.selector));
168+
f.initialize2(address(0), clientSmartContract, filecoinPay);
169+
}
170+
171+
function testInitialize2RevertsWhenClientSmartContractIsZero() public {
172+
ValidatorFactory f = ValidatorFactory(address(new ERC1967Proxy(address(factoryImpl), initData)));
173+
vm.expectRevert(abi.encodeWithSelector(ValidatorFactory.InvalidClientSmartContractAddress.selector));
174+
f.initialize2(poRepMarket, address(0), filecoinPay);
175+
}
176+
177+
function testInitialize2RevertsWhenFilecoinPayIsZero() public {
178+
ValidatorFactory f = ValidatorFactory(address(new ERC1967Proxy(address(factoryImpl), initData)));
179+
vm.expectRevert(abi.encodeWithSelector(ValidatorFactory.InvalidFilecoinPayAddress.selector));
180+
f.initialize2(poRepMarket, clientSmartContract, address(0));
181+
}
164182
}

0 commit comments

Comments
 (0)