Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,16 @@ jobs:
echo "No Solidity files to lint with Forge"
fi

- name: Check OpenZeppelin v3 alias scope
run: |
# The @openzeppelin/contracts-v3 alias (SafeMath for 0.7.6 code) is only for graph-core
MATCHES=$(git grep -l '@openzeppelin/contracts-v3' -- '*.sol' ':!packages/graph-core/**') || [ $? -eq 1 ]
if [ -n "$MATCHES" ]; then
echo "@openzeppelin/contracts-v3 may only be imported from packages/graph-core:"
echo "$MATCHES"
exit 1
fi

- name: Check lint results
if: always()
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ pragma solidity ^0.7.6;
// TODO: Re-enable and fix issues when publishing a new version
// solhint-disable gas-indexed-events, gas-small-strings, gas-strict-inequalities

import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";
import { SafeMath } from "@openzeppelin/contracts-v3/math/SafeMath.sol";

import { GraphUpgradeable } from "@graphprotocol/graph-core/contracts/upgrades/GraphUpgradeable.sol";
import { Managed } from "@graphprotocol/graph-core/contracts/governance/Managed.sol";
import { GraphUpgradeable } from "../upgrades/GraphUpgradeable.sol";
import { Managed } from "../governance/Managed.sol";

import { EpochManagerV1Storage } from "./EpochManagerStorage.sol";
import { IEpochManager } from "@graphprotocol/interfaces/contracts/contracts/epochs/IEpochManager.sol";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity ^0.7.6;

import { Managed } from "@graphprotocol/graph-core/contracts/governance/Managed.sol";
import { Managed } from "../governance/Managed.sol";

/**
* @title Epoch Manager Storage V1
Expand Down
3 changes: 3 additions & 0 deletions packages/graph-core/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ const config: HardhatUserConfig = {
'@openzeppelin/contracts/**/*': {
default: 'off',
},
'@openzeppelin/contracts-v3/**/*': {
default: 'off',
},
},
}

Expand Down
3 changes: 2 additions & 1 deletion packages/graph-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
},
"dependencies": {
"@graphprotocol/interfaces": "workspace:^",
"@openzeppelin/contracts": "^5.4.0"
"@openzeppelin/contracts": "^5.4.0",
"@openzeppelin/contracts-v3": "npm:@openzeppelin/contracts@3.4.2"
},
"devDependencies": {
"@ethersproject/abi": "^5.8.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.27;

import { IEpochManagerLike } from "./IEpochManagerLike.sol";
import { VmSafe } from "forge-std/Vm.sol";
import { ProtocolFixture } from "../shared/ProtocolFixture.t.sol";

contract EpochManagerTest is ProtocolFixture {
Expand All @@ -17,7 +18,7 @@ contract EpochManagerTest is ProtocolFixture {
function setUp() public {
vm.warp(1_700_000_000);
_deployProtocolBase();
address impl = _deployArtifact(string.concat(PKG_ARTIFACTS, "epochs/EpochManager.sol/EpochManager.json"), "");
address impl = _deployPkg("EpochManager.sol:EpochManager", "");
epochManager = IEpochManagerLike(
_deployBehindProxy(
impl,
Expand All @@ -26,6 +27,15 @@ contract EpochManagerTest is ProtocolFixture {
);
}

function test_Bytecode_FoundryMatchesHardhat() public {
vm.skip(vm.isContext(VmSafe.ForgeContext.Coverage));
string memory json = vm.readFile("artifacts/contracts/epochs/EpochManager.sol/EpochManager.json");
bytes memory hardhat = _stripMetadata(vm.parseJsonBytes(json, ".bytecode"));
bytes memory foundry = _stripMetadata(vm.getCode("EpochManager.sol:EpochManager"));
assertGt(hardhat.length, 0);
assertEq(foundry, hardhat);
}

modifier withLifecycleLength() {
vm.prank(governor);
epochManager.setEpochLength(EPOCH_LENGTH);
Expand Down
7 changes: 0 additions & 7 deletions packages/graph-core/test/unit/shared/Fixture.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ contract FixtureTest is GraphCoreTest {
assertEq(foundry, hardhat);
}

function _stripMetadata(bytes memory code) internal pure returns (bytes memory out) {
uint256 metadataLength = (uint256(uint8(code[code.length - 2])) << 8) | uint256(uint8(code[code.length - 1]));
uint256 newLength = code.length - metadataLength - 2;
out = new bytes(newLength);
for (uint256 i = 0; i < newLength; i++) out[i] = code[i];
}

function test_Fixture_ProxyWiredToImplementation() public view {
IGraphProxy proxy = IGraphProxy(address(managed));
assertEq(proxyAdmin.getProxyAdmin(proxy), address(proxyAdmin));
Expand Down
7 changes: 7 additions & 0 deletions packages/graph-core/test/unit/shared/ProtocolFixture.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ abstract contract ProtocolFixture is Test {
vm.prank(governor);
controller.setContractProxy(keccak256(bytes(name)), addr);
}

function _stripMetadata(bytes memory code) internal pure returns (bytes memory out) {
uint256 metadataLength = (uint256(uint8(code[code.length - 2])) << 8) | uint256(uint8(code[code.length - 1]));
uint256 newLength = code.length - metadataLength - 2;
out = new bytes(newLength);
for (uint256 i = 0; i < newLength; i++) out[i] = code[i];
}
}
2 changes: 1 addition & 1 deletion packages/horizon/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ libs = ["node_modules"]
auto_detect_remappings = false
test = 'test'
cache_path = 'cache_forge'
fs_permissions = [{ access = "read", path = "./" }, { access = "read", path = "node_modules/@graphprotocol/contracts/artifacts" }, { access = "read", path = "node_modules/@graphprotocol/graph-core/artifacts" }]
fs_permissions = [{ access = "read", path = "./" }, { access = "read", path = "node_modules/@graphprotocol/graph-core/artifacts" }]
solc_version = '0.8.35'
evm_version = 'cancun'
# Suppress solc warnings emitted from third-party code we don't control
Expand Down
1 change: 0 additions & 1 deletion packages/horizon/test/unit/shared/ProtocolFixture.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { IGraphProxyAdmin } from "@graphprotocol/interfaces/contracts/contracts/

abstract contract ProtocolFixture is Test {
string internal constant CORE_ARTIFACTS = "node_modules/@graphprotocol/graph-core/artifacts/contracts/";
string internal constant PKG_ARTIFACTS = "node_modules/@graphprotocol/contracts/artifacts/contracts/";

address internal governor; // makeAddr("governor"), set in _deployProtocolBase
IController internal controller;
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/contracts-migration/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"GraphCurationToken": "packages/graph-token/artifacts/contracts/curation/GraphCurationToken.sol/GraphCurationToken.json",
"SubgraphNFT": "packages/graph-token/artifacts/contracts/discovery/SubgraphNFT.sol/SubgraphNFT.json",
"SubgraphNFTDescriptor": "packages/graph-token/artifacts/contracts/discovery/SubgraphNFTDescriptor.sol/SubgraphNFTDescriptor.json",
"EpochManager": "packages/contracts/artifacts/contracts/epochs/EpochManager.sol/EpochManager.json",
"EpochManager": "packages/graph-core/artifacts/contracts/epochs/EpochManager.sol/EpochManager.json",
"RewardsManager": "packages/contracts/artifacts/contracts/rewards/RewardsManager.sol/RewardsManager.json",
"HorizonStaking": "packages/horizon/build/contracts/contracts/staking/HorizonStaking.sol/HorizonStaking.json",
"GraphPayments": "packages/horizon/build/contracts/contracts/payments/GraphPayments.sol/GraphPayments.json",
Expand Down
Loading