Skip to content
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
27 changes: 27 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: build-and-test

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
build_test:

runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22.x
registry-url: https://registry.npmjs.org
- name: Install Yarn
run: npm install -g yarn
- run: yarn install
- run: yarn ci
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ node_modules
build
generated
.env
.DS_Store
.DS_Store
tests/.*
matchstick

# Matchstick test runner generated files
**/tests/.*
**/matchstick/*
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,40 @@

`yarn`

## Running Tests

This repository uses [Matchstick](https://github.com/LimeChain/matchstick) for subgraph testing.

### Prerequisites

- **PostgreSQL 14** must be installed and running on your machine. Matchstick requires this for its testing environment.

### Running the tests

Tests are available for select packages and can be run using the following commands:

```bash
# Run tests for all packages with test suites
yarn test

# Run tests in parallel (faster)
yarn test:parallel

# Run full CI pipeline (prepare and test)
yarn ci
```

The `yarn test` command runs tests for the following packages (when available):

- `managed-optimistic-oracle-v2-subgraph`
- `optimistic-oracle-subgraph`
- `optimistic-oracle-v2-subgraph`
- `optimistic-oracle-v3-subgraph`
- `skinny-optimistic-oracle-subgraph`
- `votingV2-subgraph`

To run tests for a specific package, navigate to the package directory and run `yarn test` or `graph test` directly.

## Voting V1 Events

This subgraph indexes events emitted by the core Oracle contracts. The code can be found in `packages/voting`
Expand Down
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
},
"scripts": {
"lint": "prettier ./**",
"lint-fix": "prettier ./** --write"
"lint-fix": "prettier ./** --write",
"codegen": "lerna run codegen ",
"build": "lerna run build --scope='managed-optimistic-oracle-v2-subgraph' --scope='optimistic-oracle-subgraph' --scope='optimistic-oracle-v2-subgraph' --scope='optimistic-oracle-v3-subgraph' --scope='skinny-optimistic-oracle-subgraph' --scope='votingV2-subgraph'",
"test": "lerna run test --scope='managed-optimistic-oracle-v2-subgraph' --scope='optimistic-oracle-subgraph' --scope='optimistic-oracle-v2-subgraph' --scope='optimistic-oracle-v3-subgraph' --scope='skinny-optimistic-oracle-subgraph' --scope='votingV2-subgraph'",
"test:parallel": "lerna run test --parallel --scope='managed-optimistic-oracle-v2-subgraph' --scope='optimistic-oracle-subgraph' --scope='optimistic-oracle-v2-subgraph' --scope='optimistic-oracle-v3-subgraph' --scope='skinny-optimistic-oracle-subgraph' --scope='votingV2-subgraph'",
"prepare-ci": "lerna run --parallel prepare-ci --scope='managed-optimistic-oracle-v2-subgraph' --scope='optimistic-oracle-subgraph' --scope='optimistic-oracle-v2-subgraph' --scope='optimistic-oracle-v3-subgraph' --scope='skinny-optimistic-oracle-subgraph' --scope='votingV2-subgraph'",
"ci": "yarn prepare-ci && yarn test"
},
"bugs": {
"url": "https://github.com/UMAprotocol/subgraphs/issues"
Expand All @@ -24,7 +30,8 @@
"packages/votingV2/**",
"packages/optimistic-oracle/**",
"packages/optimistic-oracle-v3/**",
"packages/optimistic-governor/**"
"packages/optimistic-governor/**",
"packages/managed-oracle-v2/**"
]
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/financial-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"codegen": "graph codegen",
"build": "graph build",
"prepare:mainnet": "mustache config/mainnet.json subgraph.template.yaml > subgraph.yaml && yarn codegen && yarn build",
"prepare-ci": "mustache config/mainnet.json subgraph.template.yaml > subgraph.yaml && yarn codegen && yarn build",
"prepare:kovan": "mustache config/kovan.json subgraph.template.yaml > subgraph.yaml && yarn codegen && yarn build",
"deploy:kovan": "env STAGING=true scripts/deploy.sh kovan",
"deploy:mainnet": "env STAGING=true scripts/deploy.sh mainnet",
Expand Down
1 change: 1 addition & 0 deletions packages/long-short-pair/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"codegen": "graph codegen",
"build": "graph build",
"prepare:mainnet": "scripts/build-manifest.sh mainnet && yarn codegen && yarn build",
"prepare-ci": "scripts/build-manifest.sh mainnet && yarn codegen && yarn build",
"prepare:kovan": "scripts/build-manifest.sh kovan && yarn codegen && yarn build",
"prepare:polygon": "scripts/build-manifest.sh polygon && yarn codegen && yarn build",
"deploy:kovan": "env STAGING=true scripts/deploy.sh kovan",
Expand Down
2 changes: 2 additions & 0 deletions packages/managed-oracle-v2/matchstick.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
testsFolder: tests
libsFolder: ../../node_modules # binaries istalled in root of monorepo
7 changes: 6 additions & 1 deletion packages/managed-oracle-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
"build": "graph build",
"remove-call-handlers": "node ./scripts/remove-call-handlers.js",
"prepare:polygon": "scripts/build-manifest.sh polygon && yarn remove-call-handlers && yarn codegen && yarn build",
"prepare-ci": "scripts/build-manifest.sh polygon && yarn remove-call-handlers && yarn codegen && yarn build",
"prepare:amoy": "scripts/build-manifest.sh amoy && yarn remove-call-handlers && yarn codegen && yarn build",
"deploy:polygon": "env STAGING=true scripts/deploy.sh polygon",
"deploy-prod:polygon": "env STUDIO=true scripts/deploy.sh polygon",
"deploy:amoy": "env STAGING=true scripts/deploy.sh amoy",
"deploy-prod:amoy": "env STUDIO=true scripts/deploy.sh amoy",
"deploy:goldsky:amoy": "env GOLDSKY=true scripts/deploy.sh amoy",
"deploy-prod:goldsky:polygon": "env GOLDSKY=true scripts/deploy.sh polygon"
"deploy-prod:goldsky:polygon": "env GOLDSKY=true scripts/deploy.sh polygon",
"test": "graph test"
},
"repository": {
"type": "git",
Expand All @@ -32,5 +34,8 @@
"@graphprotocol/graph-ts": "^0.32.0",
"mustache": "^4.2.0",
"yaml": "^2.2.1"
},
"devDependencies": {
"matchstick-as": "0.6.0"
}
}
2 changes: 2 additions & 0 deletions packages/managed-oracle-v2/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ type CustomBond @entity {
"ID is managedRequestId, ie. the hash of requester, identifier, ancillaryData"
id: ID!

currency: Bytes!

requester: Bytes!

identifier: String!
Expand Down
1 change: 1 addition & 0 deletions packages/managed-oracle-v2/src/mappings/managedOracleV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function handleCustomBondSet(event: CustomBondSet): void {
entity.requester = event.params.requester;
entity.identifier = event.params.identifier.toString();
entity.ancillaryData = event.params.ancillaryData.toHex();
entity.currency = event.params.currency;
}

entity.customBond = event.params.bond;
Expand Down
40 changes: 39 additions & 1 deletion packages/managed-oracle-v2/src/mappings/optimisticOracleV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
SetEventBasedCall,
Settle,
} from "../../generated/ManagedOracleV2/ManagedOracleV2";
import { getOrCreateOptimisticPriceRequest } from "../utils/helpers";
import { getManagedRequestId, getOrCreateOptimisticPriceRequest } from "../utils/helpers";
import { CustomBond, CustomLiveness } from "../../generated/schema";

import { Address, BigInt, Bytes, dataSource, log } from "@graphprotocol/graph-ts";

Expand All @@ -17,6 +18,18 @@ let network = dataSource.network();
let isMainnet = network == "mainnet";
let isGoerli = network == "goerli";

function getCustomBond(requester: Address, identifier: Bytes, ancillaryData: Bytes): CustomBond | null {
const managedRequestId = getManagedRequestId(requester, identifier, ancillaryData).toHexString();
let customBondEntity = CustomBond.load(managedRequestId);
return customBondEntity ? customBondEntity : null;
}

function getCustomLiveness(requester: Address, identifier: Bytes, ancillaryData: Bytes): CustomLiveness | null {
const managedRequestId = getManagedRequestId(requester, identifier, ancillaryData).toHexString();
let customLivenessEntity = CustomLiveness.load(managedRequestId);
return customLivenessEntity ? customLivenessEntity : null;
}

function getState(
ooAddress: Address,
requester: Address,
Expand All @@ -35,6 +48,10 @@ function getState(
];
let oov2 = ManagedOracleV2.bind(ooAddress);
let state = oov2.try_getState(requester, identifier, timestamp, ancillaryData);
if (state.reverted) {
log.warning("getState call reverted, returning Invalid state", []);
return states[0]; // Return "Invalid" if the call fails
}
return states[state.value];
}

Expand Down Expand Up @@ -100,6 +117,27 @@ export function handleOptimisticRequestPrice(event: RequestPrice): void {
request.customLiveness = requestSettings.customLiveness;
}

// Look up custom bond and liveness values that may have been set before the request
let customBond = getCustomBond(event.params.requester, event.params.identifier, event.params.ancillaryData);
if (customBond !== null) {
const bond = customBond.customBond;
const currency = customBond.currency;
log.debug("custom bond of {} of currency {} was set for request Id: {}", [
bond.toString(),
currency.toHexString(),
requestId,
]);
request.bond = bond;
request.currency = currency;
}

let customLiveness = getCustomLiveness(event.params.requester, event.params.identifier, event.params.ancillaryData);
if (customLiveness !== null) {
const liveness = customLiveness.customLiveness;
log.debug("custom liveness of {} was set for request Id: {}", [liveness.toString(), requestId]);
request.customLiveness = customLiveness.customLiveness;
}

request.save();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address, Bytes, crypto } from "@graphprotocol/graph-ts";
import { Address, ByteArray, Bytes, crypto } from "@graphprotocol/graph-ts";

export function getManagedRequestId(requester: Address, identifier: Bytes, ancillaryData: Bytes): Bytes {
export function getManagedRequestId(requester: Address, identifier: Bytes, ancillaryData: Bytes): ByteArray {
let packed = requester.concat(identifier).concat(ancillaryData);
return crypto.keccak256(packed);
}
Loading