Skip to content
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

Sync staging changes #269

Merged
merged 6 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/tests-l2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Tests (L2)

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

# Install commands
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
registry-url: https://registry.npmjs.org
- name: yarn add ts-node
run: yarn add ts-node
- name: yarn install
run: yarn install

# Run scripts
- name: Prep addressess
run: ./node_modules/.bin/ts-node config/testAddressesL2.ts && ./node_modules/.bin/mustache ./config/generatedAddresses.json ./config/addresses.template.ts > ./config/addresses.ts
- name: Prep test L2
run: ./node_modules/.bin/mustache ./config/generatedAddresses.json subgraph.template.yaml > subgraph.yaml && ./node_modules/@graphprotocol/graph-cli/bin/run codegen --output-dir src/types/
- name: Test
run: ./node_modules/@graphprotocol/graph-cli/bin/run test -v 0.6.0-rc.2
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"devDependencies": {
"@graphprotocol/contracts": "6.2.0",
"@graphprotocol/graph-cli": "0.68.0",
"@graphprotocol/graph-cli": "0.68.5",
"@graphprotocol/graph-ts": "0.32.0",
"@types/node": "^14.0.13",
"@typescript-eslint/eslint-plugin": "^3.3.0",
Expand Down
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ type SubgraphDeploymentManifest @entity(immutable:true) {
network: String
"Whether the subgraph is a SpS/SbS. Null if we can't parse it"
poweredBySubstreams: Boolean
"Start block for the deployment. It's the lowest startBlock found (0 if some data source doesn't contain a start block)"
startBlock: BigInt
}

# TODO - add when we have the ability to parse data sources
Expand Down
23 changes: 21 additions & 2 deletions src/mappings/ipfs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json, Bytes, dataSource, JSONValueKind, log, DataSourceContext } from '@graphprotocol/graph-ts'
import { json, Bytes, dataSource, JSONValueKind, log, DataSourceContext, BigInt } from '@graphprotocol/graph-ts'
import {
SubgraphMeta,
SubgraphVersionMeta,
Expand Down Expand Up @@ -133,6 +133,25 @@ export function handleSubgraphDeploymentManifest(content: Bytes): void {
}
let substreamsSplitTry = manifest.split('- kind: substreams', 2)
subgraphDeploymentManifest.poweredBySubstreams = substreamsSplitTry.length > 1

// startBlock calculation
let templatesSplit = manifest.split("templates:")
let nonTemplateManifestSplit = templatesSplit[0] // we take the left as we want to remove the templates for the source checks.
let sourcesSplit = nonTemplateManifestSplit.split("source:") // We want to know how many source definitions we have
let startBlockSplit = nonTemplateManifestSplit.split("startBlock: ") // And how many startBlock definitions we have to know if we should set startBlock to 0

if (sourcesSplit.length > startBlockSplit.length) {
subgraphDeploymentManifest.startBlock = BigInt.fromI32(0)
} else {
// need to figure the minimum startBlock defined, we skip i = 0 as we know it's not gonna contain a start block num, since it's before the first appearance of "startBlock:"
let min = BigInt.fromI32(0)
for(let i = 1; i < startBlockSplit.length; i++) {
let numString = startBlockSplit[i].split("\n", 1)[0].toString()
let num = BigInt.fromString(numString)
min = min == BigInt.fromI32(0) ? num : min <= num ? min : num
}
subgraphDeploymentManifest.startBlock = min
}
}
subgraphDeploymentManifest.save()
}
}
1 change: 0 additions & 1 deletion src/mappings/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,6 @@ export function handleRebateCollected(event: RebateCollected): void {
allocation.queryFeeRebates = event.params.queryRebates
allocation.distributedRebates = allocation.distributedRebates.plus(event.params.queryRebates)
allocation.delegationFees = event.params.delegationRewards
allocation.status = 'Closed'
allocation.save()

// Update epoch
Expand Down
5 changes: 4 additions & 1 deletion tests/curation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ createMockedFunction(controllerAddress, 'getGovernor', 'getGovernor():(address)'
// L2 graph network init EpochManager call
createMockedFunction(graphAddress, 'blockNum', 'blockNum():(uint256)')
.withArgs([])
.returns([ethereum.Value.fromI32(0)])
.returns([ethereum.Value.fromI32(5)])

describe('Signalled', () => {
beforeAll(() => {
// We need epoch length and delegation ratio to be nonzero for these tests
let graphNetwork = createOrLoadGraphNetwork(blockNumber, controllerAddress)
graphNetwork.delegationRatio = delegationRatio
graphNetwork.epochLength = epochLength
graphNetwork.lastLengthUpdateBlock = 1
graphNetwork.save()

// When _stake is successfully run, before any event we are considering here can be emitted
Expand Down Expand Up @@ -202,6 +203,7 @@ describe('Burned', () => {
let graphNetwork = createOrLoadGraphNetwork(blockNumber, controllerAddress)
graphNetwork.delegationRatio = delegationRatio
graphNetwork.epochLength = epochLength
graphNetwork.lastLengthUpdateBlock = 1
graphNetwork.save()

// When _stake is successfully run, before any event we are considering here can be emitted
Expand Down Expand Up @@ -313,6 +315,7 @@ describe('ParameterUpdated', () => {
let graphNetwork = createOrLoadGraphNetwork(blockNumber, controllerAddress)
graphNetwork.delegationRatio = delegationRatio
graphNetwork.epochLength = epochLength
graphNetwork.lastLengthUpdateBlock = 1
graphNetwork.save()

// When _stake is successfully run, before any event we are considering here can be emitted
Expand Down
2 changes: 1 addition & 1 deletion tests/gns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ createMockedFunction(controllerAddress, 'getGovernor', 'getGovernor():(address)'
// L2 graph network init EpochManager call
createMockedFunction(graphAddress, 'blockNum', 'blockNum():(uint256)')
.withArgs([])
.returns([ethereum.Value.fromI32(0)])
.returns([ethereum.Value.fromI32(5)])

// CONSTANTS
const blockNumber = BigInt.fromI32(1)
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ createMockedFunction(controllerAddress, 'getGovernor', 'getGovernor():(address)'
// L2 graph network init EpochManager call
createMockedFunction(graphAddress, 'blockNum', 'blockNum():(uint256)')
.withArgs([])
.returns([ethereum.Value.fromI32(0)])
.returns([ethereum.Value.fromI32(1)])

afterAll(() => {
// Clear the store in order to start the next test off on a clean slate
Expand Down
11 changes: 10 additions & 1 deletion tests/staking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ createMockedFunction(controllerAddress, 'getGovernor', 'getGovernor():(address)'
// L2 graph network init EpochManager call
createMockedFunction(graphAddress, 'blockNum', 'blockNum():(uint256)')
.withArgs([])
.returns([ethereum.Value.fromI32(0)])
.returns([ethereum.Value.fromI32(5)])

// INDEXER STAKE RELATED TESTS
describe('INDEXER STAKE', () => {
Expand Down Expand Up @@ -180,6 +180,7 @@ describe('INDEXER STAKE', () => {
let graphNetwork = createOrLoadGraphNetwork(blockNumber, controllerAddress)
graphNetwork.delegationRatio = delegationRatio
graphNetwork.epochLength = epochLength
graphNetwork.lastLengthUpdateBlock = 1
graphNetwork.save()

// When _stake is successfully run, before any event we are considering here can be emitted
Expand Down Expand Up @@ -233,6 +234,7 @@ describe('INDEXER STAKE', () => {
let graphNetwork = createOrLoadGraphNetwork(blockNumber, controllerAddress)
graphNetwork.delegationRatio = delegationRatio
graphNetwork.epochLength = epochLength
graphNetwork.lastLengthUpdateBlock = 1
graphNetwork.save()

// When _stake is successfully run, before any event we are considering here can be emitted
Expand Down Expand Up @@ -282,6 +284,7 @@ describe('INDEXER STAKE', () => {
let graphNetwork = createOrLoadGraphNetwork(blockNumber, controllerAddress)
graphNetwork.delegationRatio = delegationRatio
graphNetwork.epochLength = epochLength
graphNetwork.lastLengthUpdateBlock = 1
graphNetwork.save()

// When _stake is successfully run, before any event we are considering here can be emitted
Expand Down Expand Up @@ -342,6 +345,7 @@ describe('INDEXER STAKE', () => {
let graphNetwork = createOrLoadGraphNetwork(blockNumber, controllerAddress)
graphNetwork.delegationRatio = delegationRatio
graphNetwork.epochLength = epochLength
graphNetwork.lastLengthUpdateBlock = 1
graphNetwork.save()

// When _stake is successfully run, before any event we are considering here can be emitted
Expand Down Expand Up @@ -382,6 +386,7 @@ describe('DELEGATOR STAKE', () => {
let graphNetwork = createOrLoadGraphNetwork(blockNumber, controllerAddress)
graphNetwork.delegationRatio = delegationRatio
graphNetwork.epochLength = epochLength
graphNetwork.lastLengthUpdateBlock = 1
graphNetwork.save()

// When _stake is successfully run, before any event we are considering here can be emitted
Expand Down Expand Up @@ -453,6 +458,7 @@ describe('DELEGATOR STAKE', () => {
let graphNetwork = createOrLoadGraphNetwork(blockNumber, controllerAddress)
graphNetwork.delegationRatio = delegationRatio
graphNetwork.epochLength = epochLength
graphNetwork.lastLengthUpdateBlock = 1
graphNetwork.save()

// When _stake is successfully run, before any event we are considering here can be emitted
Expand Down Expand Up @@ -543,6 +549,7 @@ describe('DELEGATOR STAKE', () => {
let graphNetwork = createOrLoadGraphNetwork(blockNumber, controllerAddress)
graphNetwork.delegationRatio = delegationRatio
graphNetwork.epochLength = epochLength
graphNetwork.lastLengthUpdateBlock = 1
graphNetwork.save()

// When _stake is successfully run, before any event we are considering here can be emitted
Expand Down Expand Up @@ -600,6 +607,7 @@ describe('ALLOCATION LIFE CYCLE', () => {
let graphNetwork = createOrLoadGraphNetwork(blockNumber, controllerAddress)
graphNetwork.delegationRatio = delegationRatio
graphNetwork.epochLength = epochLength
graphNetwork.lastLengthUpdateBlock = 1
graphNetwork.save()

// When _stake is successfully run, before any event we are considering here can be emitted
Expand Down Expand Up @@ -670,6 +678,7 @@ describe('ALLOCATION LIFE CYCLE', () => {
let graphNetwork = createOrLoadGraphNetwork(blockNumber, controllerAddress)
graphNetwork.delegationRatio = delegationRatio
graphNetwork.epochLength = epochLength
graphNetwork.lastLengthUpdateBlock = 1
graphNetwork.save()

// When _stake is successfully run, before any event we are considering here can be emitted
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,10 @@
"@graphprotocol/sdk" "^0.5.0"
console-table-printer "^2.11.1"

"@graphprotocol/[email protected].0":
version "0.68.0"
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-cli/-/graph-cli-0.68.0.tgz#30464a75b7341d6c468f7ff3dba01259efff6b78"
integrity sha512-F3l1t+0qfGAGbD3i/3/qDnwZp8z37OE2PmdQdQkbImq1h34Cy8mjRKvc3ZJ4E2G16JkIevqK2rWwTRHcIGMTNA==
"@graphprotocol/[email protected].5":
version "0.68.5"
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-cli/-/graph-cli-0.68.5.tgz#58cf65d15f41f1a30defe1cd50474d7c1205dd6a"
integrity sha512-3GY2pYr5LksO6JY6s5nvePnSKVdtzDEn1CUGezyjCMR1uq9YIXMPXKqcnrzCX/DLugioEabiEi2+yOg9+rnFDQ==
dependencies:
"@float-capital/float-subgraph-uncrashable" "^0.0.0-alpha.4"
"@oclif/core" "2.8.6"
Expand Down
Loading