Skip to content

Commit

Permalink
test: upgradeable contracts
Browse files Browse the repository at this point in the history
Signed-off-by: Tomás Migone <[email protected]>
  • Loading branch information
tmigone committed Jun 12, 2024
1 parent da34d9b commit 17d3b79
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 7 deletions.
15 changes: 11 additions & 4 deletions packages/horizon/test/data-service/DataServiceUpgradeable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import { DataServiceBaseUpgradeable } from "./implementations/DataServiceBaseUpg
import { UnsafeUpgrades } from "openzeppelin-foundry-upgrades/Upgrades.sol";

contract DataServiceUpgradeableTest is GraphBaseTest {
function test_WhenTheContractIsDeployedWithAValidController() external {
DataServiceBaseUpgradeable dataService = _deployDataService();
function test_WhenTheContractIsDeployed() external {
(DataServiceBaseUpgradeable dataService, DataServiceBaseUpgradeable implementation) = _deployDataService();

// via proxy - ensure that the proxy was initialized correctly
// these calls validate proxy storage was correctly initialized
uint32 delegationRatio = dataService.getDelegationRatio();
assertEq(delegationRatio, type(uint32).min);

Expand All @@ -23,9 +25,14 @@ contract DataServiceUpgradeableTest is GraphBaseTest {
(uint64 minThawingPeriod, uint64 maxThawingPeriod) = dataService.getThawingPeriodRange();
assertEq(minThawingPeriod, type(uint64).min);
assertEq(maxThawingPeriod, type(uint64).max);

// this ensures that implementation immutables were correctly initialized
// and they can be read via the proxy
assertEq(implementation.controller(), address(controller));
assertEq(dataService.controller(), address(controller));
}

function _deployDataService() internal returns (DataServiceBaseUpgradeable) {
function _deployDataService() internal returns (DataServiceBaseUpgradeable, DataServiceBaseUpgradeable) {
// Deploy implementation
address implementation = address(new DataServiceBaseUpgradeable(address(controller)));

Expand All @@ -36,6 +43,6 @@ contract DataServiceUpgradeableTest is GraphBaseTest {
abi.encodeCall(DataServiceBaseUpgradeable.initialize, ())
);

return DataServiceBaseUpgradeable(proxy);
return (DataServiceBaseUpgradeable(proxy), DataServiceBaseUpgradeable(implementation));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

import { GraphBaseTest } from "../../GraphBase.t.sol";
import { DataServiceImpPausableUpgradeable } from "../implementations/DataServiceImpPausableUpgradeable.sol";
import { UnsafeUpgrades } from "openzeppelin-foundry-upgrades/Upgrades.sol";

contract DataServicePausableUpgradeableTest is GraphBaseTest {
function test_WhenTheContractIsDeployed() external {
(
DataServiceImpPausableUpgradeable dataService,
DataServiceImpPausableUpgradeable implementation
) = _deployDataService();

// via proxy - ensure that the proxy was initialized correctly
// these calls validate proxy storage was correctly initialized
uint32 delegationRatio = dataService.getDelegationRatio();
assertEq(delegationRatio, type(uint32).min);

(uint256 minTokens, uint256 maxTokens) = dataService.getProvisionTokensRange();
assertEq(minTokens, type(uint256).min);
assertEq(maxTokens, type(uint256).max);

(uint32 minVerifierCut, uint32 maxVerifierCut) = dataService.getVerifierCutRange();
assertEq(minVerifierCut, type(uint32).min);
assertEq(maxVerifierCut, type(uint32).max);

(uint64 minThawingPeriod, uint64 maxThawingPeriod) = dataService.getThawingPeriodRange();
assertEq(minThawingPeriod, type(uint64).min);
assertEq(maxThawingPeriod, type(uint64).max);

// this ensures that implementation immutables were correctly initialized
// and they can be read via the proxy
assertEq(implementation.controller(), address(controller));
assertEq(dataService.controller(), address(controller));
}

function _deployDataService()
internal
returns (DataServiceImpPausableUpgradeable, DataServiceImpPausableUpgradeable)
{
// Deploy implementation
address implementation = address(new DataServiceImpPausableUpgradeable(address(controller)));

// Deploy proxy
address proxy = UnsafeUpgrades.deployTransparentProxy(
implementation,
users.governor,
abi.encodeCall(DataServiceImpPausableUpgradeable.initialize, ())
);

return (DataServiceImpPausableUpgradeable(proxy), DataServiceImpPausableUpgradeable(implementation));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ contract DataServiceBaseUpgradeable is DataService {
function collect(address serviceProvider, IGraphPayments.PaymentTypes feeType, bytes calldata data) external {}

function slash(address serviceProvider, bytes calldata data) external {}

function controller() external view returns (address) {
return address(_graphController());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.26;

import { DataService } from "../../../contracts/data-service/DataService.sol";
import { DataServicePausableUpgradeable } from "../../../contracts/data-service/extensions/DataServicePausableUpgradeable.sol";
import { IGraphPayments } from "./../../../contracts/interfaces/IGraphPayments.sol";

contract DataServiceImpPausableUpgradeable is DataServicePausableUpgradeable {
constructor(address controller) DataService(controller) {
_disableInitializers();
}

function initialize() external initializer {
__DataService_init();
__DataServicePausable_init();
}

function register(address serviceProvider, bytes calldata data) external {}

function acceptProvision(address serviceProvider, bytes calldata data) external {}

function startService(address serviceProvider, bytes calldata data) external {}

function stopService(address serviceProvider, bytes calldata data) external {}

function collect(address serviceProvider, IGraphPayments.PaymentTypes feeType, bytes calldata data) external {}

function slash(address serviceProvider, bytes calldata data) external {}

function controller() external view returns (address) {
return address(_graphController());
}
}

0 comments on commit 17d3b79

Please sign in to comment.