Skip to content

Commit

Permalink
fix: e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Maikol committed Mar 13, 2024
1 parent 87bb02d commit b24377e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import { expect } from 'chai'
import hre from 'hardhat'
import { isGraphL2ChainId } from '@graphprotocol/sdk'
import { NamedAccounts } from '@graphprotocol/sdk/gre'

describe('[L1] RewardsManager configuration', () => {
const graph = hre.graph()
const { RewardsManager } = graph.contracts

before(function () {
let namedAccounts: NamedAccounts

before(async function () {
if (isGraphL2ChainId(graph.chainId)) this.skip()
namedAccounts = await graph.getNamedAccounts()
})

it('issuancePerBlock should match "issuancePerBlock" in the config file', async function () {
const value = await RewardsManager.issuancePerBlock()
expect(value).eq('114693500000000000000') // hardcoded as it's set with a function call rather than init parameter
})

it('should allow subgraph availability oracle to deny rewards', async function () {
const availabilityOracle = await RewardsManager.subgraphAvailabilityOracle()
expect(availabilityOracle).eq(namedAccounts.availabilityOracle.address)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import hre from 'hardhat'

describe('[L2] RewardsManager configuration', () => {
const graph = hre.graph()
const { RewardsManager } = graph.contracts
const { RewardsManager, SubgraphAvailabilityManager } = graph.contracts

before(function () {
if (isGraphL1ChainId(graph.chainId)) this.skip()
Expand All @@ -14,4 +14,9 @@ describe('[L2] RewardsManager configuration', () => {
const value = await RewardsManager.issuancePerBlock()
expect(value).eq('6036500000000000000') // hardcoded as it's set with a function call rather than init parameter
})

it('should allow subgraph availability manager to deny rewards', async function () {
const availabilityOracle = await RewardsManager.subgraphAvailabilityOracle()
expect(availabilityOracle).eq(SubgraphAvailabilityManager.address)
})
})
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { expect } from 'chai'
import hre from 'hardhat'
import { NamedAccounts } from '@graphprotocol/sdk/gre'

describe('RewardsManager configuration', () => {
const {
contracts: { RewardsManager, Controller, SubgraphAvailabilityManager },
contracts: { RewardsManager, Controller },
} = hre.graph()

it('should be controlled by Controller', async function () {
const controller = await RewardsManager.controller()
expect(controller).eq(Controller.address)
})

it('should allow subgraph availability oracle to deny rewards', async function () {
const availabilityOracle = await RewardsManager.subgraphAvailabilityOracle()
expect(availabilityOracle).eq(SubgraphAvailabilityManager.address)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { ethers } from 'hardhat'

import type { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'

import { SubgraphAvailabilityManager } from '../../build/types/SubgraphAvailabilityManager'
import { IRewardsManager } from '../../build/types/IRewardsManager'
import { SubgraphAvailabilityManager } from '../../../build/types/SubgraphAvailabilityManager'
import { IRewardsManager } from '../../../build/types/IRewardsManager'

import { NetworkFixture } from '../lib/fixtures'

Expand Down
23 changes: 17 additions & 6 deletions packages/sdk/src/gre/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const namedAccountList: AccountNames[] = [
'arbitrator',
'governor',
'authority',
'availabilityOracle',
'pauseGuardian',
'allocationExchangeOwner',
]
Expand All @@ -24,8 +25,15 @@ export async function getNamedAccounts(
const namedAccounts = namedAccountList.reduce(
async (accountsPromise, name) => {
const accounts = await accountsPromise
const address = getItemValue(readConfig(graphConfigPath, true), `general/${name}`)
accounts[name] = await SignerWithAddress.create(provider.getSigner(address))
let address
try {
address = getItemValue(readConfig(graphConfigPath, true), `general/${name}`)
} catch (e) {
// Skip if not found
}
if (address) {
accounts[name] = await SignerWithAddress.create(provider.getSigner(address))
}
return accounts
},
Promise.resolve({} as NamedAccounts),
Expand All @@ -45,10 +53,13 @@ export async function getTestAccounts(
): Promise<SignerWithAddress[]> {
// Get list of privileged accounts we don't want as test accounts
const namedAccounts = await getNamedAccounts(provider, graphConfigPath)
const blacklist = namedAccountList.map((a) => {
const account = namedAccounts[a]
return account.address
})
const blacklist = namedAccountList.reduce((accounts, name) => {
const account = namedAccounts[name]
if (account) {
accounts.push(account.address)
}
return accounts
}, [])
blacklist.push((await getDeployer(provider)).address)

// Get signers and filter out blacklisted accounts
Expand Down

0 comments on commit b24377e

Please sign in to comment.