Skip to content

Commit

Permalink
scripts to init / rollback the database for e2e tests (#136)
Browse files Browse the repository at this point in the history
scripts to init / rollback the database for e2e tests
loads fixtures by default
executes codegen
log ps & give the graph node some seconds to spin up
upgrades ipfs kubo node
adds ipfs configuration to node so it can be used by local websites
removes formatting from docker commands
container node naming (maybe just mac)
consolidated fixture rolling scripts
roll zero tty fix
renames dump file
uses node 18 for gh actions
uses an earlier nightly version of foundry
stores current snapshot locally

Signed-off-by: stadolf <[email protected]>

---------

Signed-off-by: Stefan Adolf <[email protected]>
Signed-off-by: stadolf <[email protected]>
  • Loading branch information
elmariachi111 authored Jul 21, 2023
1 parent c4edb42 commit 81f9157
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 35 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ jobs:
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Use Node.js 16
version: nightly-d369d2486f85576eec4ca41d277391dfdae21ba7

- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: "16.x"
node-version: '18'

- name: Install node dependencies
run: yarn --frozen-lockfile
Expand All @@ -45,4 +46,4 @@ jobs:
# with:
# ignore-compile: true
# node-version: 16
# fail-on: none
# fail-on: none
1 change: 1 addition & 0 deletions deploy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SNAPSHOT
25 changes: 25 additions & 0 deletions deploy/001-ipfs-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

# https://docs.ipfs.tech/install/run-ipfs-inside-docker/#customizing-your-node

set -ex

ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["GET", "POST"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Headers '["Authorization"]'
ipfs config --json API.HTTPHeaders.Access-Control-Expose-Headers '["Location"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Credentials '["true"]'

ipfs config --json Gateway.HTTPHeaders.Access-Control-Allow-Origin '["*"]'
ipfs config --json Gateway.HTTPHeaders.Access-Control-Allow-Methods '["GET", "POST"]'
ipfs config --json Gateway.HTTPHeaders.Access-Control-Allow-Headers '["Authorization"]'
ipfs config --json Gateway.HTTPHeaders.Access-Control-Expose-Headers '["Location"]'
ipfs config --json Gateway.HTTPHeaders.Access-Control-Allow-Credentials '["true"]'

# https://web3.storage/docs/reference/peering/
# allows us to also pull w3s content from our local machine
ipfs config --json Peering.Peers '[{"ID": "bafzbeibhqavlasjc7dvbiopygwncnrtvjd2xmryk5laib7zyjor6kf3avm","Addrs": ["/dnsaddr/elastic.dag.house"]}]'

#https://github.com/ipfs/kubo/blob/master/docs/config.md#implicit-defaults-of-gatewaypublicgateways
#axios is confused with local ipfs subdomains
ipfs config --json Gateway.PublicGateways '{"localhost":{"Paths": ["/ipfs", "/ipns"],"UseSubdomains":false}}'
28 changes: 0 additions & 28 deletions deploy/deploy_ipnft3525.js

This file was deleted.

27 changes: 27 additions & 0 deletions deploy/inittest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

if command -v docker-compose &> /dev/null
then
DC="docker-compose"
else
DC="docker compose"
fi

$DC down --remove-orphans
sleep 5
$DC up -d
$DC ps
./setupLocal.sh -f

cd subgraph
yarn prepare:local
yarn codegen
yarn create:local
yarn deploy:local -l v0.0.1
cd ..

$DC exec -T postgres pg_dump -Fc -U graph-node -w graph-node -f after_setup.dump
cast rpc evm_snapshot
echo "0x0" > ./deploy/SNAPSHOT


46 changes: 46 additions & 0 deletions deploy/rollzero.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

if command -v docker-compose &> /dev/null
then
DC="docker-compose --ansi=never"
else
DC="docker compose --progress=plain --ansi=never"
fi

CURRENT_SNAPSHOT=$(<./deploy/SNAPSHOT)

#todo check whether docker is operational & cast is available here.

# if [[ "$OSTYPE" == "darwin"* ]]; then
# GRAPH_CONTAINER=ipnft-graph-node-1
# else
# GRAPH_CONTAINER=ipnft_graph-node_1
# fi

#GRAPH_CONTAINER="ipnft_graph-node_1"

# we can only *wait* for a *container name* but must address the container by its compose service name...
# earn a beer by making this work:
scname=`docker inspect -f '{{.Name}}' $(docker compose ps -q graph-node)`
GRAPH_CONTAINER=${scname:1}

$DC stop graph-node
docker container wait $GRAPH_CONTAINER
cast rpc evm_revert $CURRENT_SNAPSHOT

$DC exec -T postgres dropdb -U graph-node -w graph-node
$DC exec -T postgres createdb -U graph-node -w graph-node
$DC exec -T postgres pg_restore -U graph-node -w -d graph-node after_setup.dump

# alternatively
# $DC exec postgres psql -U graph-node -d postgres -c 'ALTER DATABASE "graph-node" WITH ALLOW_CONNECTIONS false;'
# $DC exec postgres psql -U graph-node -d postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname='graph-node'";
# $DC exec postgres psql -U graph-node -d postgres -c 'ALTER DATABASE "graph-node" WITH ALLOW_CONNECTIONS true;'
# $DC restart graph-node

$DC start graph-node
#wait for graph-node to be alive again
curl --retry-connrefused --retry-all-errors --max-time 30 --retry 10 --retry-delay 3 --retry-max-time 60 http://127.0.0.1:8030

cast rpc evm_snapshot > ./deploy/SNAPSHOT

6 changes: 4 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ services:
GRAPH_LOG: info
GRAPH_ALLOW_NON_DETERMINISTIC_IPFS: 1
ipfs:
image: ipfs/kubo:v0.15.0
image: ipfs/kubo:v0.21.0
ports:
- '5001:5001'
#volumes:
- '8080:8080'
volumes:
- ./deploy/001-ipfs-config.sh:/container-init.d/001-ipfs-config.sh
# - ./data/ipfs:/data/ipfs
postgres:
image: postgres
Expand Down
1 change: 0 additions & 1 deletion setupLocal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,5 @@ if [ "$fixture" -eq "1" ]; then
forge script script/dev/Synthesizer.s.sol:FixtureSynthesizer -f $RPC_URL --broadcast
forge script script/dev/CrowdSale.s.sol:FixtureCrowdSale -f $RPC_URL --broadcast

sleep 5
echo "SALE_ID= forge script script/dev/CrowdSale.s.sol:ClaimSale -f $RPC_URL --broadcast"
fi

0 comments on commit 81f9157

Please sign in to comment.