Skip to content

Commit 20584c6

Browse files
committed
fix: reverting unneeded hacks to test code
1 parent ea09d5f commit 20584c6

10 files changed

Lines changed: 75 additions & 105 deletions

File tree

packages/contracts/.solcover.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,16 @@ module.exports = {
88
skipFiles,
99
istanbulFolder: './reports/coverage',
1010
configureYulOptimizer: true,
11+
mocha: {
12+
grep: '@skip-on-coverage',
13+
invert: true,
14+
},
15+
onCompileComplete: async function (/* config */) {
16+
// Set environment variable to indicate we're running under coverage
17+
process.env.SOLIDITY_COVERAGE = 'true'
18+
},
19+
onIstanbulComplete: async function (/* config */) {
20+
// Clean up environment variable
21+
delete process.env.SOLIDITY_COVERAGE
22+
},
1123
}

packages/contracts/addresses.json

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -566,22 +566,6 @@
566566
"txHash": "0x20a0c0f2a26258e1c63f33f3a5651580bb74ea4bf0e66076ebbdda4fa41d5955"
567567
}
568568
},
569-
"1337": {
570-
"Controller": {
571-
"address": "0xC0dcc73ab4084494bfFAf8a427Fd3f645217BB1C",
572-
"constructorArgs": [],
573-
"creationCodeHash": "0x1a9b639b11e33783876f36ee77419a9a2a6a2041e51f78fd993ab012ea151c21",
574-
"runtimeCodeHash": "0xec5980ddda2719b394f85b230fb95154a4944ac29d64ca66b9ccb04ee7e175e3",
575-
"txHash": "0xd90746512994568e5c431c91ac502d28f17a47d827fb584bb0bf1b85b7e73d33"
576-
},
577-
"GraphProxyAdmin": {
578-
"address": "0x25ec220C451593C9af36131Aa886397a21516533",
579-
"constructorArgs": [],
580-
"creationCodeHash": "0x4536e01a111e4f1b45c44cb2e38bfac56aca4577accf5bbee5f09c111a099ff4",
581-
"runtimeCodeHash": "0x370843a171393282a9b7d05ba36f934831867f136e398505e9c38a9d0c3ecf46",
582-
"txHash": "0xcf73cf1c75058d59876cb777959cb71757448265fbe3c415a3f6920fb15cb34e"
583-
}
584-
},
585569
"42161": {
586570
"GraphProxyAdmin": {
587571
"address": "0x2983936aC20202a6555993448E0d5654AC8Ca5fd",

packages/contracts/test/unit/gns.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ describe('L1GNS', () => {
854854
const seqID = toBN('2')
855855
await legacyGNSMock.connect(me).createLegacySubgraph(seqID, newSubgraph0.subgraphDeploymentID)
856856
const tx = legacyGNSMock.connect(me).migrateLegacySubgraph(me.address, seqID, newSubgraph0.subgraphMetadata)
857-
await expect(tx).emit(legacyGNSMock, 'LegacySubgraphClaimed').withArgs(me.address, seqID)
857+
await expect(tx).emit(legacyGNSMock, ' LegacySubgraphClaimed').withArgs(me.address, seqID)
858858
const expectedSubgraphID = buildLegacySubgraphId(me.address, seqID)
859859
const migratedSubgraphDeploymentID = await legacyGNSMock.getSubgraphDeploymentID(expectedSubgraphID)
860860
const migratedNSignal = await legacyGNSMock.getSubgraphNSignal(expectedSubgraphID)
@@ -872,7 +872,7 @@ describe('L1GNS', () => {
872872
const seqID = toBN('2')
873873
await legacyGNSMock.connect(me).createLegacySubgraph(seqID, newSubgraph0.subgraphDeploymentID)
874874
let tx = legacyGNSMock.connect(me).migrateLegacySubgraph(me.address, seqID, newSubgraph0.subgraphMetadata)
875-
await expect(tx).emit(legacyGNSMock, 'LegacySubgraphClaimed').withArgs(me.address, seqID)
875+
await expect(tx).emit(legacyGNSMock, ' LegacySubgraphClaimed').withArgs(me.address, seqID)
876876
tx = legacyGNSMock.connect(me).migrateLegacySubgraph(me.address, seqID, newSubgraph0.subgraphMetadata)
877877
await expect(tx).revertedWith('GNS: Subgraph was already claimed')
878878
})
@@ -917,12 +917,12 @@ describe('L1GNS', () => {
917917
}
918918

919919
const publishCurateAndSendSubgraph = async function (
920-
beforeTransferCallback?: (_subgraphID: string) => Promise<void>,
920+
beforeTransferCallback?: (/* subgraphID: string */) => Promise<void>,
921921
): Promise<Subgraph> {
922922
const subgraph0 = await publishAndCurateOnSubgraph()
923923

924924
if (beforeTransferCallback != null) {
925-
await beforeTransferCallback(subgraph0.id)
925+
await beforeTransferCallback()
926926
}
927927

928928
const maxSubmissionCost = toBN('100')
@@ -947,7 +947,7 @@ describe('L1GNS', () => {
947947
const migrateTx = legacyGNSMock
948948
.connect(me)
949949
.migrateLegacySubgraph(me.address, seqID, newSubgraph0.subgraphMetadata)
950-
await expect(migrateTx).emit(legacyGNSMock, 'LegacySubgraphClaimed').withArgs(me.address, seqID)
950+
await expect(migrateTx).emit(legacyGNSMock, ' LegacySubgraphClaimed').withArgs(me.address, seqID)
951951
const subgraphID = buildLegacySubgraphId(me.address, seqID)
952952

953953
// Curate on the subgraph

packages/contracts/test/unit/l2/l2GraphTokenGateway.test.ts

Lines changed: 39 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,33 @@
1-
import { smock } from '@defi-wonderland/smock'
2-
import { deploy, DeployType, GraphNetworkContracts, helpers, toBN, toGRT } from '@graphprotocol/sdk'
3-
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
1+
import { FakeContract, smock } from '@defi-wonderland/smock'
42
import { expect, use } from 'chai'
53
import { constants, ContractTransaction, Signer, utils, Wallet } from 'ethers'
64
import hre from 'hardhat'
75

8-
// Define types for the contracts we'll use in the tests
9-
type L2GraphToken = any
10-
type L2GraphTokenGateway = any
11-
type CallhookReceiverMock = any
12-
type GraphToken = any
13-
type L1GraphTokenGateway = any
14-
type RewardsManager = any
15-
6+
import { CallhookReceiverMock } from '../../../build/types/CallhookReceiverMock'
7+
import { L2GraphToken } from '../../../build/types/L2GraphToken'
8+
import { L2GraphTokenGateway } from '../../../build/types/L2GraphTokenGateway'
169
import { NetworkFixture } from '../lib/fixtures'
17-
import { L2ArbitrumMessengerMock } from './l2ArbitrumMessengerMock'
1810

19-
// Initialize smock before using it
20-
smock.fake // This ensures smock is initialized
2111
use(smock.matchers)
2212

23-
// Mock the L2ArbitrumMessenger.sendTxToL1 function
24-
// This is done by monkey-patching the L2ArbitrumMessenger contract
25-
// We'll use this to verify that the function was called with the correct parameters
26-
L2ArbitrumMessengerMock.reset()
13+
import { deploy, DeployType, GraphNetworkContracts, helpers, toBN, toGRT } from '@graphprotocol/sdk'
14+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
15+
16+
import { GraphToken, L1GraphTokenGateway } from '../../../build/types'
17+
import { RewardsManager } from '../../../build/types/RewardsManager'
2718

2819
const { AddressZero } = constants
2920

3021
describe('L2GraphTokenGateway', () => {
31-
// Remove the graph function call as it's not available in this environment
22+
const graph = hre.graph()
3223
let me: SignerWithAddress
3324
let governor: SignerWithAddress
3425
let tokenSender: SignerWithAddress
3526
let l1Receiver: SignerWithAddress
3627
let l2Receiver: SignerWithAddress
3728
let pauseGuardian: SignerWithAddress
3829
let fixture: NetworkFixture
30+
let arbSysMock: FakeContract
3931

4032
let fixtureContracts: GraphNetworkContracts
4133
let l1MockContracts: GraphNetworkContracts
@@ -56,10 +48,9 @@ describe('L2GraphTokenGateway', () => {
5648
)
5749

5850
before(async function () {
59-
// Get test accounts directly from ethers
60-
;[me, governor, tokenSender, l1Receiver, l2Receiver, pauseGuardian] = await hre.ethers.getSigners()
51+
;[me, governor, tokenSender, l1Receiver, l2Receiver, pauseGuardian] = await graph.getTestAccounts()
6152

62-
fixture = new NetworkFixture(hre.ethers.provider)
53+
fixture = new NetworkFixture(graph.provider)
6354

6455
// Deploy L2
6556
fixtureContracts = await fixture.load(governor, true)
@@ -84,24 +75,23 @@ describe('L2GraphTokenGateway', () => {
8475
// Give some funds to the token sender and router mock
8576
await grt.connect(governor).mint(tokenSender.address, senderTokens)
8677
await helpers.setBalance(routerMock.address, utils.parseEther('1'))
87-
88-
// Deploy the ArbSys mock at the correct address
89-
const ArbSysMockFactory = await hre.ethers.getContractFactory('ArbSysMock')
90-
const arbSysMock = await ArbSysMockFactory.deploy()
91-
await arbSysMock.deployed()
92-
93-
// Get the bytecode of the deployed contract
94-
const code = await hre.ethers.provider.getCode(arbSysMock.address)
95-
96-
// Set the code at the ArbSys precompile address
97-
const ARB_SYS_ADDRESS = '0x0000000000000000000000000000000000000064'
98-
await hre.ethers.provider.send('hardhat_setCode', [ARB_SYS_ADDRESS, code])
9978
})
10079

10180
beforeEach(async function () {
10281
await fixture.setUp()
103-
// Reset the L2ArbitrumMessengerMock for each test
104-
L2ArbitrumMessengerMock.reset()
82+
// Thanks to Livepeer: https://github.com/livepeer/arbitrum-lpt-bridge/blob/main/test/unit/L2/l2LPTGateway.test.ts#L86
83+
// Skip smock setup when running under coverage due to provider compatibility issues
84+
const isRunningUnderCoverage =
85+
hre.network.name === 'coverage' ||
86+
process.env.SOLIDITY_COVERAGE === 'true' ||
87+
process.env.npm_lifecycle_event === 'test:coverage'
88+
89+
if (!isRunningUnderCoverage) {
90+
arbSysMock = await smock.fake('ArbSys', {
91+
address: '0x0000000000000000000000000000000000000064',
92+
})
93+
arbSysMock.sendTxToL1.returns(1)
94+
}
10595
})
10696

10797
afterEach(async function () {
@@ -242,10 +232,20 @@ describe('L2GraphTokenGateway', () => {
242232
.emit(l2GraphTokenGateway, 'TxToL1')
243233
.withArgs(tokenSender.address, l1GRTGatewayMock.address, 1, calldata)
244234

245-
// We verify the TxToL1 event was emitted with the correct parameters
246-
// This is sufficient to verify that sendTxToL1 was called correctly
247-
// The event is emitted in the sendTxToL1 function of L2ArbitrumMessenger
235+
// For some reason the call count doesn't work properly,
236+
// and each function call is counted 12 times.
237+
// Possibly related to https://github.com/defi-wonderland/smock/issues/85 ?
238+
// expect(arbSysMock.sendTxToL1).to.have.been.calledOnce
239+
240+
// Only check smock expectations when not running under coverage
241+
const isRunningUnderCoverage =
242+
hre.network.name === 'coverage' ||
243+
process.env.SOLIDITY_COVERAGE === 'true' ||
244+
process.env.npm_lifecycle_event === 'test:coverage'
248245

246+
if (!isRunningUnderCoverage && arbSysMock) {
247+
expect(arbSysMock.sendTxToL1).to.have.been.calledWith(l1GRTGatewayMock.address, calldata)
248+
}
249249
const senderBalance = await grt.balanceOf(tokenSender.address)
250250
expect(senderBalance).eq(toGRT('990'))
251251
}
@@ -273,26 +273,12 @@ describe('L2GraphTokenGateway', () => {
273273
})
274274
it('burns tokens and triggers an L1 call', async function () {
275275
await grt.connect(tokenSender).approve(l2GraphTokenGateway.address, toGRT('10'))
276-
277-
// Execute the transfer
278276
await testValidOutboundTransfer(tokenSender, defaultData)
279-
280-
// The event checks are already done in testValidOutboundTransfer
281-
// We just need to verify the balance change
282-
const senderBalance = await grt.balanceOf(tokenSender.address)
283-
expect(senderBalance).eq(toGRT('990'))
284277
})
285278
it('decodes the sender address from messages sent by the router', async function () {
286279
await grt.connect(tokenSender).approve(l2GraphTokenGateway.address, toGRT('10'))
287280
const routerEncodedData = utils.defaultAbiCoder.encode(['address', 'bytes'], [tokenSender.address, defaultData])
288-
289-
// Execute the transfer
290281
await testValidOutboundTransfer(routerMock, routerEncodedData)
291-
292-
// The event checks are already done in testValidOutboundTransfer
293-
// We just need to verify the balance change
294-
const senderBalance = await grt.balanceOf(tokenSender.address)
295-
expect(senderBalance).eq(toGRT('990'))
296282
})
297283
it('reverts when called with nonempty calldata', async function () {
298284
await grt.connect(tokenSender).approve(l2GraphTokenGateway.address, toGRT('10'))

packages/data-edge/test/dataedge.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@ import '@nomiclabs/hardhat-ethers'
22

33
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
44
import { expect } from 'chai'
5-
import { Contract } from 'ethers'
65
import { ethers } from 'hardhat'
76

7+
import { DataEdge, DataEdge__factory } from '../build/types'
8+
89
const { getContractFactory, getSigners } = ethers
910
const { id, hexConcat, randomBytes, hexlify, defaultAbiCoder } = ethers.utils
1011

1112
describe('DataEdge', () => {
12-
let edge: Contract
13+
let edge: DataEdge
1314
let me: SignerWithAddress
1415

1516
beforeEach(async () => {
1617
;[me] = await getSigners()
1718

18-
const factory = await getContractFactory('DataEdge', me)
19+
const factory = (await getContractFactory('DataEdge', me)) as DataEdge__factory
1920
edge = await factory.deploy()
2021
await edge.deployed()
2122
})

packages/data-edge/test/eventful-dataedge.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@ import '@nomiclabs/hardhat-ethers'
22

33
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
44
import { expect } from 'chai'
5-
import { Contract } from 'ethers'
65
import { ethers } from 'hardhat'
76

7+
import { EventfulDataEdge, EventfulDataEdge__factory } from '../build/types'
8+
89
const { getContractFactory, getSigners } = ethers
910
const { id, hexConcat, randomBytes, hexlify, defaultAbiCoder } = ethers.utils
1011

1112
describe('EventfulDataEdge', () => {
12-
let edge: Contract
13+
let edge: EventfulDataEdge
1314
let me: SignerWithAddress
1415

1516
beforeEach(async () => {
1617
;[me] = await getSigners()
1718

18-
const factory = await getContractFactory('EventfulDataEdge', me)
19+
const factory = (await getContractFactory('EventfulDataEdge', me)) as EventfulDataEdge__factory
1920
edge = await factory.deploy()
2021
await edge.deployed()
2122
})

packages/sdk/src/deployments/network/actions/governed.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@ export const acceptOwnership: GraphNetworkAction<
2727
throw new Error(`Contract ${contractName} not found`)
2828
}
2929

30-
let pendingGovernor: string
31-
try {
32-
pendingGovernor = await (contract as GovernedContract).connect(signer).pendingGovernor()
33-
} catch (error) {
34-
console.log(`Contract ${contract.address} does not have pendingGovernor() method or call failed: ${error}`)
35-
return
36-
}
30+
const pendingGovernor = await (contract as GovernedContract).connect(signer).pendingGovernor()
3731

3832
if (pendingGovernor === ethers.constants.AddressZero) {
3933
console.log(`No pending governor for ${contract.address}`)
@@ -42,14 +36,9 @@ export const acceptOwnership: GraphNetworkAction<
4236

4337
if (pendingGovernor === signer.address) {
4438
console.log(`Accepting ownership of ${contract.address}`)
45-
try {
46-
const tx = await (contract as GovernedContract).connect(signer).acceptOwnership()
47-
await tx.wait()
48-
return tx
49-
} catch (error) {
50-
console.log(`Failed to accept ownership of ${contract.address}: ${error}`)
51-
return
52-
}
39+
const tx = await (contract as GovernedContract).connect(signer).acceptOwnership()
40+
await tx.wait()
41+
return tx
5342
} else {
5443
console.log(`Signer ${signer.address} is not the pending governor of ${contract.address}, it is ${pendingGovernor}`)
5544
}

packages/sdk/src/deployments/network/deployment/contracts/deploy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export async function deployGraphNetwork(
194194
for (const contract of GraphNetworkGovernedContractNameList) {
195195
const tx = await acceptOwnership(loadedContracts, governor, { contractName: contract })
196196
if (tx) {
197-
txs.push(tx)
197+
txs.push()
198198
}
199199
}
200200
await Promise.all(txs.map((tx) => tx.wait()))
@@ -226,14 +226,14 @@ export async function deployMockGraphNetwork(l2Deploy: boolean) {
226226
contractList.push(...(l2Deploy ? GraphNetworkL2ContractNameList : GraphNetworkL1ContractNameList))
227227
contractList.push('AllocationExchange')
228228

229-
const contracts: any = {}
229+
const contracts: Partial<Record<GraphNetworkContractName, Contract>> = {}
230230
for (const name of contractList) {
231231
const fake = Wallet.createRandom()
232232
await setCode(fake.address, '0x1234')
233233
contracts[name] = new Contract(fake.address, [], fake)
234234
}
235235

236-
return contracts as GraphNetworkContracts // :eyes:
236+
return contracts as GraphNetworkContracts
237237
}
238238

239239
export const deploy = async (

packages/sdk/src/deployments/network/deployment/contracts/load.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export interface GraphNetworkContracts extends ContractList<GraphNetworkContract
9292

9393
// This ensures that local artifacts are preferred over the ones that ship with the sdk in node_modules
9494
export function getArtifactsPath() {
95-
return [path.resolve('artifacts'), path.resolve('node_modules', '@graphprotocol/contracts/artifacts')]
95+
return [path.resolve('build/contracts'), path.resolve('node_modules', '@graphprotocol/contracts/build/contracts')]
9696
}
9797
export function loadGraphNetworkContracts(
9898
addressBookPath: string,

packages/token-distribution/test/config.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,13 @@ export interface DateRange {
3838

3939
const dateRange = (months: number): DateRange => {
4040
const date = new Date(+new Date() - 120) // set start time for a few seconds before
41-
const newDate = new Date(date.getTime())
42-
newDate.setMonth(date.getMonth() + months)
43-
return { startTime: Math.round(+date / 1000), endTime: Math.round(+newDate.getTime() / 1000) }
41+
const newDate = new Date().setMonth(date.getMonth() + months)
42+
return { startTime: Math.round(+date / 1000), endTime: Math.round(+newDate / 1000) }
4443
}
4544

4645
const moveTime = (time: number, months: number) => {
4746
const date = new Date(time * 1000)
48-
const newDate = new Date(date.getTime())
49-
newDate.setMonth(date.getMonth() + months)
50-
return Math.round(newDate.getTime() / 1000)
47+
return Math.round(+date.setMonth(date.getMonth() + months) / 1000)
5148
}
5249

5350
const moveDateRange = (dateRange: DateRange, months: number) => {

0 commit comments

Comments
 (0)