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

Testing factory #2

Open
wants to merge 18 commits into
base: 2023-01-29-vaultinfo
Choose a base branch
from
Open
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
43 changes: 43 additions & 0 deletions .github/workflows/subgraph-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: flow-subgraph-test
on: [push, pull_request]

env:
GRAPH_TOKEN: ${{ secrets.GRAPH_ACCESS_TOKEN }}

jobs:
build:
runs-on: ubuntu-latest

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

- name: Use Node.js version
uses: actions/setup-node@v2
with:
node-version: 16

- name: Install dependencies
run: |
npm ci

- name: Build Docker Compose images
run: |
docker-compose down
docker-compose up --build -d

- name: Run Subgraph tests
run: |
npm run ci-test

- name: Stop containers
run: docker-compose down

- name: Graph Authentication
run: npx graph auth --product hosted-service $GRAPH_TOKEN

- name: Prepare subgraph manifest
run: npx mustache config/mumbai.json subgraph.template.yaml subgraph.yaml

- name: Graph Deployments
run: npx graph deploy --product hosted-service gildlab/offchainassetvault-mumbai
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ docker
generated
typechain
build
.env
.env
data
5 changes: 5 additions & 0 deletions config/hardhat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"network": "hardhat",
"offchainAssetReceiptVaultFactory": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
"offchainAssetReceiptVaultFactoryBlock": 3
}
4 changes: 2 additions & 2 deletions config/localhost.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"network": "localhost",
"offchainAssetReceiptVaultFactory": "0x2625760C4A8e8101801D3a48eE64B2bEA42f1E96",
"offchainAssetReceiptVaultFactoryBlock": 214
"offchainAssetReceiptVaultFactory": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
"offchainAssetReceiptVaultFactoryBlock": 3
}
4 changes: 2 additions & 2 deletions config/mumbai.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"network": "mumbai",
"offchainAssetReceiptVaultFactoryBlock": 31787036,
"offchainAssetReceiptVaultFactory": "0x8707993CEE55bdeB8064D3883CFB17ebd81c7B1A"
"offchainAssetReceiptVaultFactoryBlock": 32253649,
"offchainAssetReceiptVaultFactory": "0x94927792b88d518f9a429572dd3d40400b8be906"
}
4 changes: 2 additions & 2 deletions config/polygon.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"network": "matic",
"offchainAssetReceiptVaultFactoryBlock": 38971381,
"offchainAssetReceiptVaultFactory": "0x9329bf1b69a3CE69eC7694453eDC433800643B73"
"offchainAssetReceiptVaultFactoryBlock": 39549051,
"offchainAssetReceiptVaultFactory": "0xFE259001e141A41f3bcCDBc315A8F0D23Ef84b0b"
}
54 changes: 54 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
version: '3'
services:
hardhat:
image: vishalkale151071/hardhat-node
ports:
- '8545:8545'
graph-node:
image: graphprotocol/graph-node
ports:
- '8000:8000'
- '8001:8001'
- '8020:8020'
- '8030:8030'
- '8040:8040'
depends_on:
- ipfs
- postgres
- hardhat
extra_hosts:
- host.docker.internal:host-gateway
environment:
postgres_host: postgres
postgres_user: graph-node
postgres_pass: let-me-in
postgres_db: graph-node
ipfs: 'ipfs:5001'
ethereum: 'localhost:http://hardhat:8545'
GRAPH_LOG: info
ipfs:
image: ipfs/go-ipfs:v0.10.0
ports:
- '5001:5001'
volumes:
- ./data/ipfs:/data/ipfs
postgres:
image: postgres
ports:
- '5432:5432'
command:
[
"postgres",
"-cshared_preload_libraries=pg_stat_statements"
]
environment:
POSTGRES_USER: graph-node
POSTGRES_PASSWORD: let-me-in
POSTGRES_DB: graph-node
# FIXME: remove this env. var. which we shouldn't need. Introduced by
# <https://github.com/graphprotocol/graph-node/pull/3511>, maybe as a
# workaround for https://github.com/docker/for-mac/issues/6270?
PGDATA: "/var/lib/postgresql/data"
POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C"
volumes:
- ./data/postgres:/var/lib/postgresql/data
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "@nomiclabs/hardhat-etherscan";
require("dotenv").config();

function createLocalHostConfig() {
const url = "http://192.168.0.215:8545";
const url = "http://localhost:8545";
const mnemonic =
"test test test test test test test test test test test junk";
return {
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
"main": "index.js",
"scripts": {
"test": "npx hardhat test",
"ci-test": "npx hardhat test --network localhost",
"codegen": "graph codegen",
"build": "graph build",
"deploy-subgraph": "ts-node scripts/index.ts",
"deploy-mumbai": "ts-node scripts/index.ts --config config/mumbai.json --subgraphTemplate subgraph.template.yaml --subgraphName gildlab/offchainassetvault-mumbai",
"deploy-polygon": "ts-node scripts/index.ts --config config/polygon.json --subgraphTemplate subgraph.template.yaml --subgraphName gildlab/offchainassetvault-polygon",
"deploy-goerli": "ts-node scripts/index.ts --config config/goerli.json --subgraphTemplate subgraph.template.yaml --subgraphName gildlab/offchainassetvault-goerli",
"deploy-mainnet": "ts-node scripts/index.ts --config config/ethereum.json --subgraphTemplate subgraph.template.yaml --subgraphName gildlab/offchainassetvault-ethereum",
"create-local": "graph create --node http://192.168.0.215:8020/ gildlab/offchainassetvault",
"remove-local": "graph remove --node http://192.168.0.215:8020/ gildlab/offchainassetvault",
"deploy-local": "npx mustache config/localhost.json subgraph.template.yaml subgraph.yaml && graph deploy --node http://192.168.0.215:8020/ --ipfs http://192.168.0.215:5001 gildlab/offchainassetvault --version-label 1"
"create-local": "graph create --node http://localhost:8020/ gildlab/offchainassetvault",
"remove-local": "graph remove --node http://localhost:8020/ gildlab/offchainassetvault",
"deploy-local": "npx mustache config/localhost.json subgraph.template.yaml subgraph.yaml && npm run codegen && graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 gildlab/offchainassetvault --version-label 1"
},
"repository": {
"type": "git",
Expand Down
21 changes: 19 additions & 2 deletions src/OffchainAssetReceiptVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,12 @@ export function handleOffchainAssetVaultInitialized(
export function handleReceiptVaultInformation(
event: ReceiptVaultInformationEvent
): void {
let receiptVaultInformation = new ReceiptVaultInformation(
`ReceiptInformation-${event.address}`
let receiptVaultInformation = new ReceiptVaultInformation(event.transaction.hash.toHex());

let offchainAssetReceiptVault = OffchainAssetReceiptVault.load(
event.address.toHex()
);

receiptVaultInformation.transaction = getTransaction(
event.block,
event.transaction.hash.toHex()
Expand All @@ -273,6 +276,20 @@ export function handleReceiptVaultInformation(
event.address.toHex()
).id;
receiptVaultInformation.save();

if (offchainAssetReceiptVault) {
let hash = new Hash(event.transaction.hash.toHex());
hash.owner = receiptVaultInformation.caller;
hash.offchainAssetReceiptVault = offchainAssetReceiptVault.id;
hash.offchainAssetReceiptVaultDeployer = offchainAssetReceiptVault.deployer.toHex();
hash.hash = event.params.vaultInformation.toString();
hash.timestamp = event.block.timestamp;
hash.save();

offchainAssetReceiptVault.hashCount =
offchainAssetReceiptVault.hashCount.plus(ONE);
offchainAssetReceiptVault.save();
}
}

export function handleRoleAdminChanged(event: RoleAdminChanged): void {
Expand Down
4 changes: 2 additions & 2 deletions subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ dataSources:
name: OffchainAssetReceiptVaultFactory
network: localhost
source:
address: "0x2625760C4A8e8101801D3a48eE64B2bEA42f1E96"
address: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0"
abi: OffchainAssetReceiptVaultFactory
startBlock: 214
startBlock: 3
mapping:
kind: ethereum/events
apiVersion: 0.0.7
Expand Down
4 changes: 2 additions & 2 deletions test/1_factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ describe("Deploy Factory Test", () => {

const configPath = path.resolve(
__dirname,
`../config/${hre.network.name}.json`
`../config/localhost.json`
);
const config = JSON.parse(fetchFile(configPath));

config.network = hre.network.name;
config.network = "localhost";
config.offchainAssetReceiptVaultFactory = factory.address;
config.offchainAssetReceiptVaultFactoryBlock =
factory.deployTransaction.blockNumber;
Expand Down
Loading