Skip to content

Commit 82ec319

Browse files
committed
fix: address PR comments and improve import consistency
- Convert require() statements to ES6 imports where possible - Improve type safety in test utility functions - Export previously unused functions in issuanceCalculations.ts - Standardize import organization across test files - Fix mixed import styles in test files - Organize imports properly in commonTestUtils.ts All tests pass (161/161) and linting is clean.
1 parent 8ffbbdd commit 82ec319

File tree

8 files changed

+29
-34
lines changed

8 files changed

+29
-34
lines changed

packages/issuance/test/tests/DirectAllocation.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { expect } from 'chai'
22
import hre from 'hardhat'
3+
34
const { ethers } = hre
5+
46
const { upgrades } = require('hardhat')
57

68
import { deployDirectAllocation, deployTestGraphToken, getTestAccounts, SHARED_CONSTANTS } from './helpers/fixtures'

packages/issuance/test/tests/IssuanceSystem.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
* Reduced from 149 lines to ~80 lines using shared utilities
44
*/
55

6-
const { expect } = require('chai')
6+
import { expect } from 'chai'
77

8-
const { setupOptimizedIssuanceSystem } = require('../utils/optimizedFixtures')
9-
const { TestConstants, mineBlocks, expectRatioToEqual } = require('../utils/testPatterns')
8+
import { setupOptimizedIssuanceSystem } from '../utils/optimizedFixtures'
9+
import { expectRatioToEqual, mineBlocks, TestConstants } from '../utils/testPatterns'
1010

1111
describe('Issuance System', () => {
1212
let system: any

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import '@nomicfoundation/hardhat-chai-matchers'
33
import { time } from '@nomicfoundation/hardhat-network-helpers'
44
import { expect } from 'chai'
55
import hre from 'hardhat'
6+
67
const { ethers } = hre
78
const { upgrades } = require('hardhat')
89

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { expect } from 'chai'
2-
const { ethers } = require('hardhat')
3-
4-
const { shouldSupportERC165Interface } = require('../../utils/testPatterns')
51
// Import generated interface IDs from the interfaces package
62
import { IIssuanceAllocator, IIssuanceTarget, IRewardsEligibilityOracle } from '@graphprotocol/interfaces'
3+
import { expect } from 'chai'
4+
import { ethers } from 'hardhat'
75

6+
import { shouldSupportERC165Interface } from '../../utils/testPatterns'
87
import {
98
deployDirectAllocation,
109
deployIssuanceAllocator,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
import type { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'
66
import { expect } from 'chai'
7+
import type { Contract } from 'ethers'
8+
79
/**
810
* Test multiple access control methods on a contract
911
* @param contract - The contract to test
1012
* @param methods - Array of methods to test with their arguments
1113
* @param authorizedAccount - Account that should have access
1214
* @param unauthorizedAccount - Account that should not have access
1315
*/
14-
import type { Contract } from 'ethers'
1516

1617
export async function testMultipleAccessControl(
1718
contract: Contract,

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import '@nomicfoundation/hardhat-chai-matchers'
2+
13
import fs from 'fs'
24
import hre from 'hardhat'
5+
36
const { ethers } = hre
47
const { upgrades } = require('hardhat')
5-
import '@nomicfoundation/hardhat-chai-matchers'
68

79
import type { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'
810

packages/issuance/test/utils/issuanceCalculations.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { ethers } = require('hardhat')
1+
import { ethers } from 'hardhat'
22

33
/**
44
* Shared calculation utilities for issuance tests.
@@ -156,7 +156,7 @@ export function parseEther(value: string): bigint {
156156
/**
157157
* Helper to format wei bigint to ETH string for debugging.
158158
*/
159-
function formatEther(value: bigint): string {
159+
export function formatEther(value: bigint): string {
160160
return ethers.formatEther(value)
161161
}
162162

@@ -168,17 +168,6 @@ function formatEther(value: bigint): string {
168168
* @param endBlock - Ending block number
169169
* @returns Number of blocks for accumulation calculation
170170
*/
171-
function calculateBlockDifference(startBlock: number, endBlock: number): bigint {
171+
export function calculateBlockDifference(startBlock: number, endBlock: number): bigint {
172172
return BigInt(Math.max(0, endBlock - startBlock))
173173
}
174-
175-
module.exports = {
176-
calculateExpectedAccumulation,
177-
calculateProportionalDistribution,
178-
calculateExpectedTargetIssuance,
179-
calculateMultiTargetIssuance,
180-
verifyTotalDistribution,
181-
parseEther,
182-
formatEther,
183-
calculateBlockDifference,
184-
}

packages/issuance/test/utils/testPatterns.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* Shared test patterns and utilities to reduce duplication across test files
33
*/
44

5-
const { expect } = require('chai')
6-
const { ethers } = require('hardhat')
5+
import { expect } from 'chai'
6+
import { ethers } from 'hardhat'
77

88
// Type definitions for test utilities
99
export interface TestAccounts {
@@ -71,7 +71,7 @@ export function shouldEnforceGovernorRole<T>(
7171

7272
await expect(
7373
(contract as any).connect(testAccounts.nonGovernor)[methodName](...methodArgs),
74-
).to.be.revertedWithCustomError(contract, 'AccessControlUnauthorizedAccount')
74+
).to.be.revertedWithCustomError(contract as any, 'AccessControlUnauthorizedAccount')
7575
})
7676

7777
it(`should allow governor to call ${methodName}`, async function () {
@@ -100,7 +100,7 @@ export function shouldEnforceRoleAccess<T>(
100100

101101
await expect(
102102
(contract as any).connect(testAccounts.nonGovernor)[methodName](...methodArgs),
103-
).to.be.revertedWithCustomError(contract, 'AccessControlUnauthorizedAccount')
103+
).to.be.revertedWithCustomError(contract as any, 'AccessControlUnauthorizedAccount')
104104
})
105105
}
106106
}
@@ -161,6 +161,7 @@ export function shouldInitializeCorrectly<T>(contractGetter: () => T, expectedVa
161161
Object.entries(expectedValues).forEach(([property, expectedValue]) => {
162162
it(`should set ${property} correctly during initialization`, async function () {
163163
const contract = contractGetter()
164+
// Type assertion is necessary here since we're accessing dynamic properties
164165
const actualValue = await (contract as any)[property]()
165166
expect(actualValue).to.equal(expectedValue)
166167
})
@@ -171,7 +172,7 @@ export function shouldInitializeCorrectly<T>(contractGetter: () => T, expectedVa
171172
const accounts = this.parent.ctx.accounts
172173

173174
await expect((contract as any).initialize(accounts.governor.address)).to.be.revertedWithCustomError(
174-
contract,
175+
contract as any,
175176
'InvalidInitialization',
176177
)
177178
})
@@ -278,7 +279,7 @@ export function shouldEnforceAccessControl<T>(
278279
const contract = contractGetter()
279280
await expect(
280281
(contract as any).connect(accounts.nonGovernor)[method.name](...method.args),
281-
).to.be.revertedWithCustomError(contract, 'AccessControlUnauthorizedAccount')
282+
).to.be.revertedWithCustomError(contract as any, 'AccessControlUnauthorizedAccount')
282283
})
283284

284285
allowedRoles.forEach((role) => {
@@ -335,7 +336,7 @@ export function shouldInitializeProperly<T>(
335336
const contract = contractGetter()
336337
await expect(
337338
(contract as any)[reinitializationTest.method](...reinitializationTest.args),
338-
).to.be.revertedWithCustomError(contract, reinitializationTest.expectedError)
339+
).to.be.revertedWithCustomError(contract as any, reinitializationTest.expectedError)
339340
})
340341
}
341342
})
@@ -377,7 +378,7 @@ export function shouldHandlePausability<T>(
377378
it('should revert when non-PAUSE_ROLE tries to pause', async function () {
378379
const contract = contractGetter()
379380
await expect((contract as any).connect(accounts.nonGovernor).pause()).to.be.revertedWithCustomError(
380-
contract,
381+
contract as any,
381382
'AccessControlUnauthorizedAccount',
382383
)
383384
})
@@ -400,7 +401,7 @@ export function shouldHandlePausability<T>(
400401

401402
await expect(
402403
(contract as any).connect(caller)[operation.name](...operation.args),
403-
).to.be.revertedWithCustomError(contract, 'EnforcedPause')
404+
).to.be.revertedWithCustomError(contract as any, 'EnforcedPause')
404405
})
405406
})
406407
})
@@ -455,7 +456,7 @@ export function shouldManageRoles<T>(
455456
const contract = contractGetter()
456457
await expect(
457458
(contract as any).connect(accounts.nonGovernor).grantRole(roleConfig.role, accounts.user.address),
458-
).to.be.revertedWithCustomError(contract, 'AccessControlUnauthorizedAccount')
459+
).to.be.revertedWithCustomError(contract as any, 'AccessControlUnauthorizedAccount')
459460
})
460461
})
461462
})
@@ -520,7 +521,7 @@ export function shouldValidateInputs<T>(
520521
test.caller === 'operator' ? accounts.operator : test.caller === 'user' ? accounts.user : accounts.governor
521522

522523
await expect((contract as any).connect(caller)[test.method](...test.args)).to.be.revertedWithCustomError(
523-
contract,
524+
contract as any,
524525
test.expectedError,
525526
)
526527
})

0 commit comments

Comments
 (0)