-
Notifications
You must be signed in to change notification settings - Fork 157
Sync: l2-testnet / scenario1 > dev #703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0797e5b
chore: update project to use latest GRE
tmigone df31b2e
chore: sync tooling changes from l2-testnet
tmigone 0ec59a6
feat: scenario1
tmigone ca2b268
fix: fix e2e script
tmigone 6e12213
fix: prevent scenario1 to be re-run upon fixture import
tmigone bd9e435
fix: readme typo
tmigone dd34737
fix: scenario1 ensure deployer has enough funds
tmigone 9788d5a
fix: run scenario1 scripts with increased gasLimit to avoid OOG revert
tmigone 1e73591
fix: use custom gasLimit to close allocations
tmigone 3ec15a9
chore: split scenario1 into several tasks, clean up fixtures
tmigone 64ea981
fix: fix e2e tests after syncing changes from l2-testnet
tmigone f7a5a7a
feat: add parameter to migrate function so we can set automine on/off
tmigone bfd2014
chore: update mainnet graph config file
tmigone edd5808
fix: fix scenario env setup, allow e2e config override
tmigone 397bcac
fix(e2e): use strict eq instead of gte when testing balances
tmigone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { expect } from 'chai' | ||
import hre from 'hardhat' | ||
import { AllocationFixture, getIndexerFixtures, IndexerFixture } from './fixtures/indexers' | ||
|
||
enum AllocationState { | ||
Null, | ||
Active, | ||
Closed, | ||
Finalized, | ||
Claimed, | ||
} | ||
|
||
let indexerFixtures: IndexerFixture[] | ||
|
||
describe('Close allocations', () => { | ||
const { contracts, getTestAccounts } = hre.graph() | ||
const { Staking } = contracts | ||
|
||
before(async () => { | ||
indexerFixtures = getIndexerFixtures(await getTestAccounts()) | ||
}) | ||
|
||
describe('Allocations', () => { | ||
let allocations: AllocationFixture[] = [] | ||
let openAllocations: AllocationFixture[] = [] | ||
let closedAllocations: AllocationFixture[] = [] | ||
|
||
before(async () => { | ||
allocations = indexerFixtures.map((i) => i.allocations).flat() | ||
openAllocations = allocations.filter((a) => !a.close) | ||
closedAllocations = allocations.filter((a) => a.close) | ||
}) | ||
|
||
it(`some allocatons should be open`, async function () { | ||
for (const allocation of openAllocations) { | ||
const state = await Staking.getAllocationState(allocation.signer.address) | ||
expect(state).eq(AllocationState.Active) | ||
} | ||
}) | ||
|
||
it(`some allocatons should be closed`, async function () { | ||
for (const allocation of closedAllocations) { | ||
const state = await Staking.getAllocationState(allocation.signer.address) | ||
expect(state).eq(AllocationState.Closed) | ||
} | ||
}) | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// ### Scenario description ### | ||
// Common protocol actions > Close some allocations | ||
// This scenario will close several open allocations. See fixtures for details. | ||
// Need to wait at least 1 epoch after the allocations have been created before running it. | ||
// On localhost, the epoch is automatically advanced to guarantee this. | ||
// Run with: | ||
// npx hardhat e2e:scenario close-allocations --network <network> --graph-config config/graph.<network>.yml | ||
|
||
import hre from 'hardhat' | ||
import { closeAllocation } from './lib/staking' | ||
import { advanceToNextEpoch } from '../../test/lib/testHelpers' | ||
import { fundAccountsETH } from './lib/accounts' | ||
import { getIndexerFixtures } from './fixtures/indexers' | ||
import { getGraphOptsFromArgv } from './lib/helpers' | ||
|
||
async function main() { | ||
const graphOpts = getGraphOptsFromArgv() | ||
const graph = hre.graph(graphOpts) | ||
const indexerFixtures = getIndexerFixtures(await graph.getTestAccounts()) | ||
|
||
const deployer = await graph.getDeployer() | ||
const indexers = indexerFixtures.map((i) => i.signer.address) | ||
const indexerETHBalances = indexerFixtures.map((i) => i.ethBalance) | ||
|
||
// == Fund participants | ||
console.log('\n== Fund indexers') | ||
await fundAccountsETH(deployer, indexers, indexerETHBalances) | ||
|
||
// == Time travel on local networks, ensure allocations can be closed | ||
if (['hardhat', 'localhost'].includes(hre.network.name)) { | ||
console.log('\n== Advancing to next epoch') | ||
await advanceToNextEpoch(graph.contracts.EpochManager) | ||
} | ||
|
||
// == Close allocations | ||
console.log('\n== Close allocations') | ||
|
||
for (const indexer of indexerFixtures) { | ||
for (const allocation of indexer.allocations.filter((a) => a.close)) { | ||
await closeAllocation(graph.contracts, indexer.signer, allocation.signer.address) | ||
} | ||
} | ||
} | ||
|
||
// We recommend this pattern to be able to use async/await everywhere | ||
// and properly handle errors. | ||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error) | ||
process.exitCode = 1 | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { expect } from 'chai' | ||
import hre from 'hardhat' | ||
import { recreatePreviousSubgraphId } from './lib/subgraph' | ||
import { BigNumber } from 'ethers' | ||
import { CuratorFixture, getCuratorFixtures } from './fixtures/curators' | ||
import { SubgraphFixture, getSubgraphFixtures, getSubgraphOwner } from './fixtures/subgraphs' | ||
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' | ||
|
||
let curatorFixtures: CuratorFixture[] | ||
let subgraphFixtures: SubgraphFixture[] | ||
let subgraphOwnerFixture: SignerWithAddress | ||
|
||
describe('Publish subgraphs', () => { | ||
const { contracts, getTestAccounts } = hre.graph() | ||
const { GNS, GraphToken, Curation } = contracts | ||
|
||
before(async () => { | ||
const testAccounts = await getTestAccounts() | ||
curatorFixtures = getCuratorFixtures(testAccounts) | ||
subgraphFixtures = getSubgraphFixtures() | ||
subgraphOwnerFixture = getSubgraphOwner(testAccounts).signer | ||
}) | ||
|
||
describe('GRT balances', () => { | ||
it(`curator balances should match airdropped amount minus signalled`, async function () { | ||
for (const curator of curatorFixtures) { | ||
const address = curator.signer.address | ||
const balance = await GraphToken.balanceOf(address) | ||
expect(balance).eq(curator.grtBalance.sub(curator.signalled)) | ||
} | ||
}) | ||
}) | ||
|
||
describe('Subgraphs', () => { | ||
it(`should be published`, async function () { | ||
for (let i = 0; i < subgraphFixtures.length; i++) { | ||
const subgraphId = await recreatePreviousSubgraphId( | ||
contracts, | ||
subgraphOwnerFixture.address, | ||
subgraphFixtures.length - i, | ||
) | ||
const isPublished = await GNS.isPublished(subgraphId) | ||
expect(isPublished).eq(true) | ||
} | ||
}) | ||
|
||
it(`should have signal`, async function () { | ||
for (let i = 0; i < subgraphFixtures.length; i++) { | ||
const subgraph = subgraphFixtures[i] | ||
const subgraphId = await recreatePreviousSubgraphId( | ||
contracts, | ||
subgraphOwnerFixture.address, | ||
subgraphFixtures.length - i, | ||
) | ||
|
||
let totalSignal: BigNumber = BigNumber.from(0) | ||
for (const curator of curatorFixtures) { | ||
const _subgraph = curator.subgraphs.find((s) => s.deploymentId === subgraph.deploymentId) | ||
if (_subgraph) { | ||
totalSignal = totalSignal.add(_subgraph.signal) | ||
} | ||
} | ||
|
||
const tokens = await GNS.subgraphTokens(subgraphId) | ||
const MAX_PPM = 1000000 | ||
const curationTax = await Curation.curationTaxPercentage() | ||
const tax = totalSignal.mul(curationTax).div(MAX_PPM) | ||
expect(tokens).eq(totalSignal.sub(tax)) | ||
} | ||
}) | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// ### Scenario description ### | ||
// Common protocol actions > Set up subgraphs: publish and signal | ||
// This scenario will create a set of subgraphs and add signal to them. See fixtures for details. | ||
// Run with: | ||
// npx hardhat e2e:scenario create-subgraphs --network <network> --graph-config config/graph.<network>.yml | ||
|
||
import hre from 'hardhat' | ||
import { publishNewSubgraph } from './lib/subgraph' | ||
import { fundAccountsETH, fundAccountsGRT } from './lib/accounts' | ||
import { signal } from './lib/curation' | ||
import { getSubgraphFixtures, getSubgraphOwner } from './fixtures/subgraphs' | ||
import { getCuratorFixtures } from './fixtures/curators' | ||
import { getGraphOptsFromArgv } from './lib/helpers' | ||
|
||
async function main() { | ||
const graphOpts = getGraphOptsFromArgv() | ||
const graph = hre.graph(graphOpts) | ||
const testAccounts = await graph.getTestAccounts() | ||
|
||
const subgraphFixtures = getSubgraphFixtures() | ||
const subgraphOwnerFixture = getSubgraphOwner(testAccounts) | ||
const curatorFixtures = getCuratorFixtures(testAccounts) | ||
|
||
const deployer = await graph.getDeployer() | ||
const subgraphOwners = [subgraphOwnerFixture.signer.address] | ||
const subgraphOwnerETHBalance = [subgraphOwnerFixture.ethBalance] | ||
const curators = curatorFixtures.map((c) => c.signer.address) | ||
const curatorETHBalances = curatorFixtures.map((i) => i.ethBalance) | ||
const curatorGRTBalances = curatorFixtures.map((i) => i.grtBalance) | ||
|
||
// == Fund participants | ||
console.log('\n== Fund subgraph owners and curators') | ||
await fundAccountsETH( | ||
deployer, | ||
[...subgraphOwners, ...curators], | ||
[...subgraphOwnerETHBalance, ...curatorETHBalances], | ||
) | ||
await fundAccountsGRT(deployer, curators, curatorGRTBalances, graph.contracts.GraphToken) | ||
|
||
// == Publish subgraphs | ||
console.log('\n== Publishing subgraphs') | ||
|
||
for (const subgraph of subgraphFixtures) { | ||
const id = await publishNewSubgraph( | ||
graph.contracts, | ||
subgraphOwnerFixture.signer, | ||
subgraph.deploymentId, | ||
) | ||
const subgraphData = subgraphFixtures.find((s) => s.deploymentId === subgraph.deploymentId) | ||
if (subgraphData) subgraphData.subgraphId = id | ||
} | ||
|
||
// == Signal subgraphs | ||
console.log('\n== Signaling subgraphs') | ||
for (const curator of curatorFixtures) { | ||
for (const subgraph of curator.subgraphs) { | ||
const subgraphData = subgraphFixtures.find((s) => s.deploymentId === subgraph.deploymentId) | ||
if (subgraphData) | ||
await signal(graph.contracts, curator.signer, subgraphData.subgraphId, subgraph.signal) | ||
} | ||
} | ||
} | ||
|
||
// We recommend this pattern to be able to use async/await everywhere | ||
// and properly handle errors. | ||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error) | ||
process.exitCode = 1 | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.