Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph Horizon: tests and internal review fixes #983

Merged
merged 9 commits into from
Jun 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: upgradeable contracts
Signed-off-by: Tomás Migone <tomas@edgeandnode.com>
tmigone committed Jun 12, 2024
commit 17d3b792c6541546db163c0121c72a63de0c89dc
15 changes: 11 additions & 4 deletions packages/horizon/test/data-service/DataServiceUpgradeable.t.sol
Original file line number Diff line number Diff line change
@@ -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);

@@ -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)));

@@ -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
@@ -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());
}
}