mirror of
https://github.com/oceanprotocol/ocean-subgraph.git
synced 2024-12-02 05:57:29 +01:00
add integration tests (#74)
* add integration tests * try actions * workflows check * workflows testing * workflow test * workflow test * workflow test * increase timeout * small fix Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * workflow test * workflow test * workflow test * fix workflows * add readme * fix readme * one more test * end test Co-authored-by: mihaisc <mihai.scarlat@smartcontrol.ro>
This commit is contained in:
parent
59800e7992
commit
2a711626ed
57
.github/workflows/tests.yml
vendored
Normal file
57
.github/workflows/tests.yml
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
name: 'Integration tests'
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '**'
|
||||
pull_request:
|
||||
branches:
|
||||
- '**'
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: '14'
|
||||
|
||||
- name: Cache node modules
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/.npm
|
||||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: ${{ runner.os }}-node-
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
name: Checkout Barge
|
||||
with:
|
||||
repository: "oceanprotocol/barge"
|
||||
path: 'barge'
|
||||
ref: feature/subgraph
|
||||
- run: npm ci
|
||||
- name: Run Barge
|
||||
working-directory: ${{ github.workspace }}/barge
|
||||
env:
|
||||
ADDRESS_FILE: ${HOME}/.ocean/ocean-contracts/artifacts/address.json
|
||||
run: |
|
||||
bash -x start_ocean.sh --with-thegraph --no-dashboard 2>&1 > start_ocean.log &
|
||||
for i in $(seq 1 500); do
|
||||
sleep 5
|
||||
[ -f "$HOME/.ocean/ocean-contracts/artifacts/ready" ] && break
|
||||
done
|
||||
- run: npm run bargesetup
|
||||
env:
|
||||
ADDRESS_FILE: /home/runner/.ocean/ocean-contracts/artifacts/address.json
|
||||
- run: npm run codegen
|
||||
- run: npm run build
|
||||
- run: npm run create:local-barge
|
||||
- run: npm run deploy:local-barge
|
||||
- run: npm run test-integration
|
||||
env:
|
||||
ADDRESS_FILE: /home/runner/.ocean/ocean-contracts/artifacts/address.json
|
||||
|
32
README.md
32
README.md
@ -10,6 +10,7 @@
|
||||
- [🏄 Get Started](#-get-started)
|
||||
- [🧶 Example Queries](#-example-queries)
|
||||
- [🦑 Development](#-development)
|
||||
- [🦑 Development on barge](#-development-on-barge)
|
||||
- [✨ Code Style](#-code-style)
|
||||
- [🛳 Releases](#️-releases)
|
||||
- [⬆️ Deployment](#️-deployment)
|
||||
@ -102,6 +103,37 @@ The default network for development is set to Rinkeby. If you want to switch to
|
||||
|
||||
You now have a local graph-node running and can start deploying your changes to it. To do so, follow the [Deployment instructions](#️-deployment).
|
||||
|
||||
|
||||
## 🦑 Development on Barge
|
||||
|
||||
Run barge in another terminal
|
||||
```bash
|
||||
./start_ocean.sh --with-thegraph
|
||||
```
|
||||
|
||||
Clone the repo and install dependencies:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/oceanprotocol/ocean-subgraph/
|
||||
cd ocean-subgraph
|
||||
npm i
|
||||
```
|
||||
|
||||
Generate the subgraph
|
||||
```bash
|
||||
npm run bargesetup
|
||||
```
|
||||
|
||||
To deploy a subgraph connected to Barge, use:
|
||||
|
||||
```bash
|
||||
npm run create:local-barge
|
||||
npm run deploy:local-barge
|
||||
```
|
||||
|
||||
You now have a local graph-node running on http://localhost:9000
|
||||
|
||||
|
||||
## ✨ Code Style
|
||||
|
||||
For linting and auto-formatting you can use from the root of the project:
|
||||
|
3172
package-lock.json
generated
3172
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
17
package.json
17
package.json
@ -3,8 +3,10 @@
|
||||
"version": "1.1.0",
|
||||
"scripts": {
|
||||
"start": "",
|
||||
"bargesetup": "node ./scripts/generatebargesubgraph.js",
|
||||
"create": "graph create oceanprotocol/ocean-subgraph --node https://api.thegraph.com/deploy/",
|
||||
"create:local": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
|
||||
"create:local-barge": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:9020",
|
||||
"create:local-rinkeby": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
|
||||
"create:local-ropsten": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
|
||||
"create:local-polygon": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
|
||||
@ -13,10 +15,12 @@
|
||||
"deploy": "graph deploy oceanprotocol/ocean-subgraph --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
|
||||
"deploy:beta": "graph deploy oceanprotocol/ocean-subgraph-beta --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
|
||||
"deploy:local": "graph deploy oceanprotocol/ocean-subgraph subgraph.yaml --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020",
|
||||
"deploy:local-barge": "graph deploy oceanprotocol/ocean-subgraph subgraph.barge.yaml --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:9020",
|
||||
"deploy:local-rinkeby": "graph deploy oceanprotocol/ocean-subgraph subgraph.rinkeby.yaml --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020",
|
||||
"deploy:local-ropsten": "graph deploy oceanprotocol/ocean-subgraph subgraph.ropsten.yaml --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020",
|
||||
"deploy:local-polygon": "graph deploy oceanprotocol/ocean-subgraph subgraph.polygon.yaml --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020",
|
||||
"test": "npm run codegen && npm run lint && npm run type-check",
|
||||
"test-integration": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/**/*.test.ts'",
|
||||
"lint": "eslint --ignore-path .gitignore --ext .js --ext .ts --ext .tsx .",
|
||||
"format": "prettier --ignore-path .gitignore './**/*.{css,yml,js,ts,tsx,json,yaml}' --write",
|
||||
"type-check": "tsc --noEmit",
|
||||
@ -27,18 +31,29 @@
|
||||
"@graphprotocol/graph-cli": "^0.20.0",
|
||||
"@graphprotocol/graph-ts": "^0.20.0",
|
||||
"@release-it/bumper": "^2.0.0",
|
||||
"@types/chai": "^4.2.16",
|
||||
"@types/chai-spies": "^1.0.3",
|
||||
"@types/mocha": "^8.2.2",
|
||||
"@typescript-eslint/eslint-plugin": "^4.19.0",
|
||||
"@typescript-eslint/parser": "^4.18.0",
|
||||
"auto-changelog": "^2.2.1",
|
||||
"chai": "^4.3.4",
|
||||
"chai-spies": "^1.0.0",
|
||||
"eslint": "^7.22.0",
|
||||
"eslint-config-oceanprotocol": "^1.5.0",
|
||||
"eslint-config-prettier": "^8.1.0",
|
||||
"eslint-plugin-prettier": "^3.3.1",
|
||||
"mocha": "^8.3.2",
|
||||
"mock-local-storage": "^1.1.17",
|
||||
"prettier": "^2.2.1",
|
||||
"release-it": "^14.5.0",
|
||||
"ts-node-register": "^1.0.0",
|
||||
"typescript": "^4.2.3"
|
||||
},
|
||||
"dependencies": {},
|
||||
"dependencies": {
|
||||
"@oceanprotocol/lib": "^0.12.2",
|
||||
"cross-fetch": "^3.1.4"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/oceanprotocol/ocean-subgraph.git"
|
||||
|
55
scripts/generatebargesubgraph.js
Normal file
55
scripts/generatebargesubgraph.js
Normal file
@ -0,0 +1,55 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
var fs = require('fs')
|
||||
|
||||
async function replaceContractAddresses() {
|
||||
// load barge addresses first
|
||||
try {
|
||||
const data = JSON.parse(fs.readFileSync(process.env.ADDRESS_FILE, 'utf8'))
|
||||
const {
|
||||
DTFactory,
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
BFactory,
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
FixedRateExchange,
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
Metadata
|
||||
} = data.development
|
||||
let subgraph = fs.readFileSync('subgraph.yaml', 'utf8')
|
||||
if (!data) {
|
||||
return false
|
||||
}
|
||||
// BFactory
|
||||
subgraph = subgraph.replace(
|
||||
/0xbe0083053744ECb871510C88dC0f6b77Da162706/g,
|
||||
BFactory
|
||||
)
|
||||
// dt factory
|
||||
subgraph = subgraph.replace(
|
||||
/0x57317f97E9EA49eBd19f7c9bB7c180b8cDcbDeB9/g,
|
||||
DTFactory
|
||||
)
|
||||
// metadata
|
||||
subgraph = subgraph.replace(
|
||||
/0x1a4b70d8c9DcA47cD6D0Fb3c52BB8634CA1C0Fdf/g,
|
||||
Metadata
|
||||
)
|
||||
// fixed rate exchgage
|
||||
subgraph = subgraph.replace(
|
||||
/0x608d05214E42722B94a54cF6114d4840FCfF84e1/g,
|
||||
FixedRateExchange
|
||||
)
|
||||
// network
|
||||
subgraph = subgraph.replace(/network: mainnet/g, 'network: barge')
|
||||
|
||||
// startBlocks
|
||||
subgraph = subgraph.replace(/startBlock:[ 0-9].*/g, 'startBlock: 0')
|
||||
|
||||
fs.writeFileSync('subgraph.barge.yaml', subgraph, 'utf8')
|
||||
} catch (e) {
|
||||
console.error('Failed to load address.json')
|
||||
console.error(e)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
replaceContractAddresses()
|
10
test/integration/.mocharc.json
Normal file
10
test/integration/.mocharc.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"require": [
|
||||
"ts-node/register",
|
||||
"source-map-support/register",
|
||||
"mock-local-storage"
|
||||
],
|
||||
"full-trace": true,
|
||||
"exit": true,
|
||||
"timeout": "300000"
|
||||
}
|
43
test/integration/Datatokens.test.ts
Normal file
43
test/integration/Datatokens.test.ts
Normal file
@ -0,0 +1,43 @@
|
||||
/* eslint-disable prefer-destructuring */
|
||||
import { assert, use } from 'chai'
|
||||
import spies from 'chai-spies'
|
||||
import Web3 from 'web3'
|
||||
import { Ocean, ConfigHelper, Account } from '@oceanprotocol/lib'
|
||||
const fetch = require('cross-fetch')
|
||||
const web3 = new Web3('http://127.0.0.1:8545')
|
||||
const subgraphUrl =
|
||||
'http://localhost:9000/subgraphs/name/oceanprotocol/ocean-subgraph'
|
||||
function sleep(ms: number) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms)
|
||||
})
|
||||
}
|
||||
use(spies)
|
||||
|
||||
describe('Datatokens test flow', () => {
|
||||
let alice: Account
|
||||
let ocean: Ocean
|
||||
|
||||
it('Initialize Ocean Library', async () => {
|
||||
const config = new ConfigHelper().getConfig('development')
|
||||
config.web3Provider = web3
|
||||
ocean = await Ocean.getInstance(config)
|
||||
alice = (await ocean.accounts.list())[0]
|
||||
})
|
||||
|
||||
it('Alice publishes a datatoken and querys the graph', async () => {
|
||||
const datatoken = await ocean.datatokens.create('', alice.getId())
|
||||
const graphToken = datatoken.toLowerCase()
|
||||
await sleep(1000) // let graph ingest our transaction
|
||||
const query = {
|
||||
query: `query {
|
||||
datatoken(id:"${graphToken}"){symbol,id}}`
|
||||
}
|
||||
const response = await fetch(subgraphUrl, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(query)
|
||||
})
|
||||
const result = await response.json()
|
||||
assert(result.data.datatoken.id === graphToken)
|
||||
})
|
||||
})
|
37
test/integration/ZEnding.test.ts
Normal file
37
test/integration/ZEnding.test.ts
Normal file
@ -0,0 +1,37 @@
|
||||
/* eslint-disable prefer-destructuring */
|
||||
import { assert, use } from 'chai'
|
||||
import spies from 'chai-spies'
|
||||
import Web3 from 'web3'
|
||||
const fetch = require('cross-fetch')
|
||||
const web3 = new Web3('http://127.0.0.1:8545')
|
||||
const subgraphUrl =
|
||||
'http://localhost:9000/subgraphs/name/oceanprotocol/ocean-subgraph'
|
||||
|
||||
use(spies)
|
||||
|
||||
describe('Ending tests', () => {
|
||||
let result: any
|
||||
it('Get Graph status', async () => {
|
||||
const query = {
|
||||
query: `query {
|
||||
_meta{hasIndexingErrors,
|
||||
deployment,
|
||||
block{number}
|
||||
}
|
||||
}`
|
||||
}
|
||||
const response = await fetch(subgraphUrl, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(query)
|
||||
})
|
||||
result = await response.json()
|
||||
})
|
||||
|
||||
it('Make sure that graph has no sync errors', async () => {
|
||||
assert(result.data._meta.hasIndexingErrors == false)
|
||||
})
|
||||
it('Make sure that graph has synced to last block', async () => {
|
||||
const lastblock = await web3.eth.getBlockNumber()
|
||||
assert(result.data._meta.block.number === lastblock)
|
||||
})
|
||||
})
|
18
test/integration/tsconfig.json
Normal file
18
test/integration/tsconfig.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"resolveJsonModule": true,
|
||||
"moduleResolution": "node",
|
||||
"lib": ["es2017", "es6", "es7", "dom"],
|
||||
"noUnusedLocals": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"declaration": true,
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"removeComments": true,
|
||||
"experimentalDecorators": true,
|
||||
"preserveConstEnums": true,
|
||||
"typeRoots": ["../node_modules/@types"],
|
||||
"types": ["...", "@types/mocha"],
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user