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

[WIP] Horizon: fix unit tests and refactor #972

Merged
merged 7 commits into from
May 23, 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
fix: rebase and fixes
Maikol committed May 22, 2024
commit 5247ebf93ecf04fc276e091f6c0f7175cce0d04f
5 changes: 1 addition & 4 deletions packages/contracts/contracts/upgrades/GraphProxy.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.7.6;

import { Address } from "@openzeppelin/contracts/utils/Address.sol";
pragma solidity >=0.6.12 <0.9.0;

import { GraphProxyStorage } from "./GraphProxyStorage.sol";

@@ -160,7 +158,6 @@ contract GraphProxy is GraphProxyStorage, IGraphProxy {
*/
function _acceptUpgrade() internal {
address _pendingImplementation = _getPendingImplementation();
require(Address.isContract(_pendingImplementation), "Impl must be a contract");
require(_pendingImplementation != address(0), "Impl cannot be zero address");
require(msg.sender == _pendingImplementation, "Only pending implementation");

2 changes: 1 addition & 1 deletion packages/contracts/contracts/upgrades/GraphProxyAdmin.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.7.6;
pragma solidity >=0.6.12 <0.9.0;

import { Governed } from "../governance/Governed.sol";

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.7.6;
pragma solidity >=0.6.12 <0.9.0;

/**
* @title Graph Proxy Storage
4 changes: 2 additions & 2 deletions packages/horizon/contracts/payments/PaymentsEscrow.sol
Original file line number Diff line number Diff line change
@@ -78,8 +78,8 @@ contract PaymentsEscrow is Multicall, GraphDirectory, IPaymentsEscrow {
revert GraphEscrowThawingPeriodTooLong(withdrawEscrowThawingPeriod, MAX_THAWING_PERIOD);
}

revokeCollectorThawingPeriod = revokeCollectorThawingPeriod;
withdrawEscrowThawingPeriod = withdrawEscrowThawingPeriod;
REVOKE_COLLECTOR_THAWING_PERIOD = revokeCollectorThawingPeriod;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL very nice catch

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha I was so confused for a moment

WITHDRAW_ESCROW_THAWING_PERIOD = withdrawEscrowThawingPeriod;
}

// approve a data service to collect funds
57 changes: 23 additions & 34 deletions packages/horizon/test/GraphBase.t.sol
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@ pragma solidity ^0.8.24;

import "forge-std/Test.sol";

import { GraphProxyAdmin } from "@graphprotocol/contracts/contracts/upgrades/GraphProxyAdmin.sol";
import { GraphProxy } from "@graphprotocol/contracts/contracts/upgrades/GraphProxy.sol";
import { Controller } from "@graphprotocol/contracts/contracts/governance/Controller.sol";

import { PaymentsEscrow } from "contracts/payments/PaymentsEscrow.sol";
@@ -18,6 +20,7 @@ abstract contract GraphBaseTest is Test, Constants {

/* Contracts */

GraphProxyAdmin public proxyAdmin;
Controller public controller;
MockGRTToken public token;
GraphPayments public payments;
@@ -41,6 +44,7 @@ abstract contract GraphBaseTest is Test, Constants {

function setUp() public virtual {
// Deploy ERC20 token
vm.prank(users.deployer);
token = new MockGRTToken();

// Setup Users
@@ -68,10 +72,13 @@ abstract contract GraphBaseTest is Test, Constants {

function deployProtocolContracts() private {
vm.startPrank(users.governor);
proxyAdmin = new GraphProxyAdmin();
controller = new Controller();
controller.setContractProxy(keccak256("GraphToken"), address(token));
vm.stopPrank();

// Staking Proxy
vm.prank(users.deployer);
GraphProxy stakingProxy = new GraphProxy(address(0), address(proxyAdmin));

// GraphPayments predict address
bytes32 saltPayments = keccak256("GraphPaymentsSalt");
@@ -101,39 +108,16 @@ abstract contract GraphBaseTest is Test, Constants {
users.deployer
);

// HorizonStakingExtension predict address
bytes32 saltHorizonStakingExtension = keccak256("HorizonStakingExtensionSalt");
bytes32 horizonStakingExtensionHash = keccak256(bytes.concat(
vm.getCode("HorizonStakingExtension.sol:HorizonStakingExtension"),
abi.encode(address(controller), subgraphDataServiceAddress)
));
address predictedAddressHorizonStakingExtension = vm.computeCreate2Address(
saltHorizonStakingExtension,
horizonStakingExtensionHash,
users.deployer
);

// HorizonStaking predict address
bytes32 saltHorizonStaking = keccak256("saltHorizonStaking");
bytes32 horizonStakingHash = keccak256(bytes.concat(
vm.getCode("HorizonStaking.sol:HorizonStaking"),
abi.encode(
address(controller),
predictedAddressHorizonStakingExtension,
subgraphDataServiceAddress
)
));
address predictedAddressHorizonStaking = vm.computeCreate2Address(
saltHorizonStaking,
horizonStakingHash,
users.deployer
);

// Setup controller
vm.startPrank(users.governor);
controller.setContractProxy(keccak256("GraphEscrow"), predictedAddressEscrow);
controller.setContractProxy(keccak256("GraphToken"), address(token));
controller.setContractProxy(keccak256("PaymentsEscrow"), predictedAddressEscrow);
controller.setContractProxy(keccak256("GraphPayments"), predictedPaymentsAddress);
controller.setContractProxy(keccak256("Staking"), address(predictedAddressHorizonStaking));
controller.setContractProxy(keccak256("Staking"), address(stakingProxy));
controller.setContractProxy(keccak256("EpochManager"), makeAddr("EpochManager"));
controller.setContractProxy(keccak256("RewardsManager"), makeAddr("RewardsManager"));
controller.setContractProxy(keccak256("Curation"), makeAddr("Curation"));
controller.setContractProxy(keccak256("GraphTokenGateway"), makeAddr("GraphTokenGateway"));
vm.stopPrank();

vm.startPrank(users.deployer);
@@ -146,16 +130,21 @@ abstract contract GraphBaseTest is Test, Constants {
revokeCollectorThawingPeriod,
withdrawEscrowThawingPeriod
);
stakingExtension = new HorizonStakingExtension{salt: saltHorizonStakingExtension}(
stakingExtension = new HorizonStakingExtension(
address(controller),
subgraphDataServiceAddress
);
stakingBase = new HorizonStaking{salt: saltHorizonStaking}(
stakingBase = new HorizonStaking(
address(controller),
address(stakingExtension),
subgraphDataServiceAddress
);
staking = IHorizonStaking(address(stakingBase));
vm.stopPrank();

vm.startPrank(users.governor);
proxyAdmin.upgrade(stakingProxy, address(stakingBase));
proxyAdmin.acceptProxy(stakingBase, stakingProxy);
staking = IHorizonStaking(address(stakingProxy));
vm.stopPrank();
}

33 changes: 0 additions & 33 deletions packages/horizon/test/HorizonStaking.t.sol

This file was deleted.

38 changes: 0 additions & 38 deletions packages/horizon/test/HorizonStaking.ts

This file was deleted.