Skip to content

Commit 13f0ae0

Browse files
committed
refactor: consolidate test fixtures and fix documentation
• Consolidated duplicate test fixture files into single fixtures.ts • Removed circular dependency between fixtures.ts and sharedFixtures.ts • Fixed incorrect function calls (grantOperatorRole → grantRole, setValidityPeriod → setEligibilityPeriod) • Updated default eligibility period from 7 days to 14 days (matches contract default) • Updated all test imports to use consolidated fixtures • Fixed RewardsManagerV6Storage class documentation comment
1 parent fed7913 commit 13f0ae0

File tree

5 files changed

+101
-117
lines changed

5 files changed

+101
-117
lines changed

packages/contracts/contracts/rewards/RewardsManagerStorage.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ contract RewardsManagerV5Storage is RewardsManagerV4Storage {
7878
}
7979

8080
/**
81-
* @title RewardsManagerV5Storage
81+
* @title RewardsManagerV6Storage
8282
* @author Edge & Node
8383
* @notice Storage layout for RewardsManager V6
8484
*/

packages/issuance/test/tests/RewardsEligibilityOracle.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {
1010
deployRewardsEligibilityOracle,
1111
deployTestGraphToken,
1212
getTestAccounts,
13+
SHARED_CONSTANTS,
1314
type TestAccounts,
1415
} from './helpers/fixtures'
15-
import { SHARED_CONSTANTS } from './helpers/sharedFixtures'
1616

1717
// Role constants
1818
const GOVERNOR_ROLE = SHARED_CONSTANTS.GOVERNOR_ROLE

packages/issuance/test/tests/consolidated/AccessControl.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
const { expect } = require('chai')
8-
const { deploySharedContracts, resetContractState, SHARED_CONSTANTS } = require('../helpers/sharedFixtures')
8+
const { deploySharedContracts, resetContractState, SHARED_CONSTANTS } = require('../helpers/fixtures')
99

1010
describe('Consolidated Access Control Tests', () => {
1111
let accounts: any

packages/issuance/test/tests/helpers/fixtures.ts

Lines changed: 98 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
1+
/**
2+
* Test fixtures and setup utilities
3+
* Contains deployment functions, shared constants, and test utilities
4+
*/
5+
16
import type { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers'
27
import * as fs from 'fs'
38

49
const { ethers, upgrades } = require('hardhat')
5-
const { SHARED_CONSTANTS } = require('./sharedFixtures')
6-
const { OPERATOR_ROLE } = SHARED_CONSTANTS
10+
11+
// Shared test constants
12+
export const SHARED_CONSTANTS = {
13+
PPM: 1_000_000,
14+
15+
// Pre-calculated role constants to avoid repeated async calls
16+
GOVERNOR_ROLE: ethers.keccak256(ethers.toUtf8Bytes('GOVERNOR_ROLE')),
17+
OPERATOR_ROLE: ethers.keccak256(ethers.toUtf8Bytes('OPERATOR_ROLE')),
18+
PAUSE_ROLE: ethers.keccak256(ethers.toUtf8Bytes('PAUSE_ROLE')),
19+
ORACLE_ROLE: ethers.keccak256(ethers.toUtf8Bytes('ORACLE_ROLE')),
20+
} as const
21+
22+
// Interface IDs
23+
export const INTERFACE_IDS = {
24+
IERC165: '0x01ffc9a7',
25+
} as const
726

827
// Types
928
export interface TestAccounts {
@@ -15,6 +34,24 @@ export interface TestAccounts {
1534
indexer2: HardhatEthersSigner
1635
}
1736

37+
export interface SharedContracts {
38+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
39+
graphToken: any
40+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
41+
rewardsEligibilityOracle: any
42+
}
43+
44+
export interface SharedAddresses {
45+
graphToken: string
46+
rewardsEligibilityOracle: string
47+
}
48+
49+
export interface SharedFixtures {
50+
accounts: TestAccounts
51+
contracts: SharedContracts
52+
addresses: SharedAddresses
53+
}
54+
1855
/**
1956
* Get standard test accounts
2057
*/
@@ -60,12 +97,12 @@ export async function deployTestGraphToken(): Promise<any> {
6097
* Deploy the RewardsEligibilityOracle contract with proxy using OpenZeppelin's upgrades library
6198
* @param graphToken The Graph Token contract address
6299
* @param governor The governor signer
63-
* @param validityPeriod The validity period in seconds (default: 7 days)
100+
* @param validityPeriod The validity period in seconds (default: 14 days)
64101
*/
65102
export async function deployRewardsEligibilityOracle(
66103
graphToken: string,
67104
governor: HardhatEthersSigner,
68-
validityPeriod: number = 7 * 24 * 60 * 60, // 7 days in seconds
105+
validityPeriod: number = 14 * 24 * 60 * 60, // 14 days in seconds (contract default)
69106
// eslint-disable-next-line @typescript-eslint/no-explicit-any
70107
): Promise<any> {
71108
// Deploy implementation and proxy using OpenZeppelin's upgrades library
@@ -84,14 +121,65 @@ export async function deployRewardsEligibilityOracle(
84121
// Get the contract instance
85122
const rewardsEligibilityOracle = rewardsEligibilityOracleContract
86123

87-
// Set the validity period if it's different from the default
88-
if (validityPeriod !== 7 * 24 * 60 * 60) {
89-
// First grant operator role to governor so they can set the validity period
90-
await rewardsEligibilityOracle.connect(governor).grantOperatorRole(governor.address)
91-
await rewardsEligibilityOracle.connect(governor).setValidityPeriod(validityPeriod)
124+
// Set the eligibility period if it's different from the default (14 days)
125+
if (validityPeriod !== 14 * 24 * 60 * 60) {
126+
// First grant operator role to governor so they can set the eligibility period
127+
await rewardsEligibilityOracle.connect(governor).grantRole(SHARED_CONSTANTS.OPERATOR_ROLE, governor.address)
128+
await rewardsEligibilityOracle.connect(governor).setEligibilityPeriod(validityPeriod)
92129
// Now revoke the operator role from governor to ensure tests start with clean state
93-
await rewardsEligibilityOracle.connect(governor).revokeRole(OPERATOR_ROLE, governor.address)
130+
await rewardsEligibilityOracle.connect(governor).revokeRole(SHARED_CONSTANTS.OPERATOR_ROLE, governor.address)
94131
}
95132

96133
return rewardsEligibilityOracle
97134
}
135+
136+
/**
137+
* Shared contract deployment and setup
138+
*/
139+
export async function deploySharedContracts(): Promise<SharedFixtures> {
140+
const accounts = await getTestAccounts()
141+
142+
// Deploy base contracts
143+
const graphToken = await deployTestGraphToken()
144+
const graphTokenAddress = await graphToken.getAddress()
145+
146+
const rewardsEligibilityOracle = await deployRewardsEligibilityOracle(graphTokenAddress, accounts.governor)
147+
148+
// Cache addresses
149+
const addresses: SharedAddresses = {
150+
graphToken: graphTokenAddress,
151+
rewardsEligibilityOracle: await rewardsEligibilityOracle.getAddress(),
152+
}
153+
154+
// Create helper
155+
return {
156+
accounts,
157+
contracts: {
158+
graphToken,
159+
rewardsEligibilityOracle,
160+
},
161+
addresses,
162+
}
163+
}
164+
165+
/**
166+
* Reset contract state to initial conditions
167+
* Optimized to avoid redeployment while ensuring clean state
168+
*/
169+
export async function resetContractState(contracts: SharedContracts, accounts: TestAccounts): Promise<void> {
170+
const { rewardsEligibilityOracle } = contracts
171+
172+
// Reset RewardsEligibilityOracle state
173+
try {
174+
if (await rewardsEligibilityOracle.paused()) {
175+
await rewardsEligibilityOracle.connect(accounts.governor).unpause()
176+
}
177+
178+
// Reset eligibility validation to default (disabled)
179+
if (await rewardsEligibilityOracle.getEligibilityValidation()) {
180+
await rewardsEligibilityOracle.connect(accounts.governor).setEligibilityValidation(false)
181+
}
182+
} catch (error) {
183+
console.warn('RewardsEligibilityOracle state reset failed:', error instanceof Error ? error.message : String(error))
184+
}
185+
}

packages/issuance/test/tests/helpers/sharedFixtures.ts

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)