Skip to content

Commit d5bc134

Browse files
committed
test: migrate issuance Hardhat tests to Forge with 100% coverage
Port all allocator, eligibility, and direct-allocation tests from Hardhat/TypeScript to Forge/Solidity. Tests cover access control, distribution accounting, target management, defensive checks, interface compliance, interface ID stability, and operator functions. Mock contracts placed in test/unit/mocks/ for shared use across test suites. All 188 tests pass.
1 parent 3554569 commit d5bc134

16 files changed

Lines changed: 2463 additions & 0 deletions
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.33;
3+
4+
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
5+
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
6+
7+
import { BaseUpgradeable } from "../../../contracts/common/BaseUpgradeable.sol";
8+
import { IssuanceAllocator } from "../../../contracts/allocate/IssuanceAllocator.sol";
9+
import { IssuanceAllocatorSharedTest } from "./shared.t.sol";
10+
11+
/// @notice Construction and initialization tests for IssuanceAllocator.
12+
contract IssuanceAllocatorConstructionTest is IssuanceAllocatorSharedTest {
13+
/* solhint-disable graph/func-name-mixedcase */
14+
15+
function test_Revert_ZeroGraphTokenAddress() public {
16+
vm.expectRevert(BaseUpgradeable.GraphTokenCannotBeZeroAddress.selector);
17+
new IssuanceAllocator(address(0));
18+
}
19+
20+
function test_Revert_ZeroGovernorAddress() public {
21+
IssuanceAllocator impl = new IssuanceAllocator(address(token));
22+
bytes memory initData = abi.encodeCall(IssuanceAllocator.initialize, (address(0)));
23+
vm.expectRevert(BaseUpgradeable.GovernorCannotBeZeroAddress.selector);
24+
new TransparentUpgradeableProxy(address(impl), address(this), initData);
25+
}
26+
27+
function test_Init_GovernorRoleSet() public view {
28+
assertTrue(allocator.hasRole(GOVERNOR_ROLE, governor));
29+
}
30+
31+
function test_Init_DefaultTargetCount() public view {
32+
// Should have 1 target (the default at index 0)
33+
assertEq(allocator.getTargetCount(), 1);
34+
}
35+
36+
function test_Init_DefaultTargetIsZeroAddress() public view {
37+
assertEq(allocator.getTargetAt(0), address(0));
38+
}
39+
40+
function test_Init_IssuancePerBlockIsZero() public view {
41+
assertEq(allocator.getIssuancePerBlock(), 0);
42+
}
43+
44+
function test_Init_LastDistributionBlockIsCurrentBlock() public view {
45+
assertEq(allocator.getDistributionState().lastDistributionBlock, block.number);
46+
}
47+
48+
function test_Revert_DoubleInitialization() public {
49+
vm.expectRevert(Initializable.InvalidInitialization.selector);
50+
allocator.initialize(governor);
51+
}
52+
53+
/* solhint-enable graph/func-name-mixedcase */
54+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.33;
3+
4+
import { Test } from "forge-std/Test.sol";
5+
6+
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
7+
8+
import { IssuanceAllocator } from "../../../contracts/allocate/IssuanceAllocator.sol";
9+
import { IssuanceAllocatorTestHarness } from "../../../contracts/test/allocate/IssuanceAllocatorTestHarness.sol";
10+
import { MockGraphToken } from "../mocks/MockGraphToken.sol";
11+
12+
/// @notice Tests for defensive checks in IssuanceAllocator internal functions.
13+
contract IssuanceAllocatorDefensiveChecksTest is Test {
14+
/* solhint-disable graph/func-name-mixedcase */
15+
16+
IssuanceAllocatorTestHarness internal harness;
17+
18+
function setUp() public {
19+
MockGraphToken token = new MockGraphToken();
20+
IssuanceAllocatorTestHarness impl = new IssuanceAllocatorTestHarness(address(token));
21+
bytes memory initData = abi.encodeCall(IssuanceAllocator.initialize, (address(this)));
22+
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(address(impl), address(this), initData);
23+
harness = IssuanceAllocatorTestHarness(address(proxy));
24+
}
25+
26+
function test_DistributePendingProportionally_AllocatedRateZero() public {
27+
// Defensive: allocatedRate == 0 should return early without reverting
28+
harness.exposedDistributePendingProportionally(100, 0, 1000);
29+
}
30+
31+
function test_DistributePendingProportionally_AvailableZero() public {
32+
// Defensive: available == 0 should return early without reverting
33+
harness.exposedDistributePendingProportionally(0, 100, 1000);
34+
}
35+
36+
function test_DistributePendingProportionally_BothZero() public {
37+
// Defensive: both == 0 should return early without reverting
38+
harness.exposedDistributePendingProportionally(0, 0, 1000);
39+
}
40+
41+
/* solhint-enable graph/func-name-mixedcase */
42+
}

0 commit comments

Comments
 (0)