From 25b49f784bab8c3677e37f1f1648ca4e3d23a1e2 Mon Sep 17 00:00:00 2001 From: Arijit Das Date: Sat, 9 Oct 2021 17:30:33 +0530 Subject: [PATCH 1/3] Use ipld-eth-db docker image. --- .github/workflows/on-pr.yaml | 4 ++-- Makefile | 4 ---- docker-compose.yml | 26 +++++++------------------- pkg/eth/api_test.go | 2 +- pkg/graphql/graphql_test.go | 2 +- scripts/run_intregration_test.sh | 2 +- 6 files changed, 12 insertions(+), 28 deletions(-) diff --git a/.github/workflows/on-pr.yaml b/.github/workflows/on-pr.yaml index 581ca99b..fd1d8001 100644 --- a/.github/workflows/on-pr.yaml +++ b/.github/workflows/on-pr.yaml @@ -28,7 +28,7 @@ jobs: go-version: ${{ matrix.go-version }} - uses: actions/checkout@v2 - name: Run database - run: docker-compose up -d db + run: docker-compose up -d ipld-eth-db - name: Test run: | sleep 10 @@ -52,7 +52,7 @@ jobs: go-version: ${{ matrix.go-version }} - uses: actions/checkout@v2 - name: Run database - run: docker-compose -f docker-compose.test.yml -f docker-compose.yml up -d db dapptools contract eth-server + run: docker-compose -f docker-compose.test.yml -f docker-compose.yml up -d ipld-eth-db dapptools contract eth-server - name: Test run: | while [ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8081)" != "200" ]; do echo "waiting for ipld-eth-server..." && sleep 5; done && \ diff --git a/Makefile b/Makefile index 49636c89..3da04bf9 100644 --- a/Makefile +++ b/Makefile @@ -57,10 +57,6 @@ TEST_CONNECT_STRING_LOCAL = postgresql://$(USER)@$(HOST_NAME):$(PORT)/$(TEST_DB) test: | $(GINKGO) $(GOOSE) go vet ./... go fmt ./... - export PGPASSWORD=$(DATABASE_PASSWORD) - dropdb -h $(DATABASE_HOSTNAME) -p $(DATABASE_PORT) -U $(DATABASE_USER) --if-exists $(TEST_DB) - createdb -h $(DATABASE_HOSTNAME) -p $(DATABASE_PORT) -U $(DATABASE_USER) $(TEST_DB) - $(GOOSE) -dir db/migrations postgres "$(TEST_CONNECT_STRING)" up $(GINKGO) -r --skipPackage=test .PHONY: integrationtest diff --git a/docker-compose.yml b/docker-compose.yml index 5ed1cfca..139b0562 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,33 +4,21 @@ services: dapptools: restart: unless-stopped depends_on: - - statediff-migrations + - ipld-eth-db image: vulcanize/dapptools:v0.30.0-v1.10.9-statediff-0.0.27 environment: DB_USER: vdbm DB_NAME: vulcanize_public - DB_HOST: db + DB_HOST: ipld-eth-db DB_PORT: 5432 DB_PASSWORD: password ports: - "127.0.0.1:8545:8545" - "127.0.0.1:8546:8546" - statediff-migrations: - restart: on-failure - depends_on: - - db - image: vulcanize/statediff-migrations:v0.8.0 - environment: - DATABASE_USER: vdbm - DATABASE_NAME: vulcanize_public - DATABASE_HOSTNAME: db - DATABASE_PORT: 5432 - DATABASE_PASSWORD: password - - db: + ipld-eth-db: restart: always - image: postgres:10.12-alpine + image: vulcanize/ipld-eth-db:v0.2.0 environment: POSTGRES_USER: "vdbm" POSTGRES_DB: "vulcanize_public" @@ -44,7 +32,7 @@ services: eth-server: restart: unless-stopped depends_on: - - db + - ipld-eth-db build: context: ./ cache_from: @@ -57,7 +45,7 @@ services: VDB_COMMAND: "serve" ETH_CHAIN_CONFIG: "/tmp/chain.json" DATABASE_NAME: "vulcanize_public" - DATABASE_HOSTNAME: "db" + DATABASE_HOSTNAME: "ipld-eth-db" DATABASE_PORT: 5432 DATABASE_USER: "vdbm" DATABASE_PASSWORD: "password" @@ -73,7 +61,7 @@ services: graphql: restart: unless-stopped depends_on: - - db + - ipld-eth-db image: vulcanize/postgraphile:v1.0.1 environment: - PG_HOST=db diff --git a/pkg/eth/api_test.go b/pkg/eth/api_test.go index fa5025c2..ceb5b22a 100644 --- a/pkg/eth/api_test.go +++ b/pkg/eth/api_test.go @@ -188,7 +188,7 @@ func SetupDB() (*postgres.DB, error) { User: "vdbm", Password: "password", Hostname: "localhost", - Name: "vulcanize_testing", + Name: "vulcanize_public", Port: 8077, }) return postgres.NewDB(uri, postgres.ConnectionConfig{}, node.Info{}) diff --git a/pkg/graphql/graphql_test.go b/pkg/graphql/graphql_test.go index 68e394db..eda87382 100644 --- a/pkg/graphql/graphql_test.go +++ b/pkg/graphql/graphql_test.go @@ -49,7 +49,7 @@ func SetupDB() (*postgres.DB, error) { User: "vdbm", Password: "password", Hostname: "localhost", - Name: "vulcanize_testing", + Name: "vulcanize_public", Port: 8077, }) return postgres.NewDB(uri, postgres.ConnectionConfig{}, node.Info{}) diff --git a/scripts/run_intregration_test.sh b/scripts/run_intregration_test.sh index 929e6297..211df86e 100755 --- a/scripts/run_intregration_test.sh +++ b/scripts/run_intregration_test.sh @@ -7,7 +7,7 @@ docker-compose down --remove-orphans --volumes # Build and start the containers. # Note: Build only if `ipld-eth-server` or other container code is modified. Otherwise comment this line. docker-compose -f docker-compose.test.yml -f docker-compose.yml build eth-server -docker-compose -f docker-compose.test.yml -f docker-compose.yml up -d db dapptools contract eth-server +docker-compose -f docker-compose.test.yml -f docker-compose.yml up -d ipld-eth-db dapptools contract eth-server export PGPASSWORD=password export DATABASE_USER=vdbm From 20c04a98bcfd536341916c1d2dee1463cc5b6abc Mon Sep 17 00:00:00 2001 From: Arijit Das Date: Mon, 11 Oct 2021 22:12:05 +0530 Subject: [PATCH 2/3] Update DB name. --- docker-compose.yml | 6 +++--- pkg/eth/api_test.go | 2 +- pkg/graphql/graphql_test.go | 2 +- scripts/run_unit_test.sh | 5 ++++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 139b0562..889a207f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: image: vulcanize/dapptools:v0.30.0-v1.10.9-statediff-0.0.27 environment: DB_USER: vdbm - DB_NAME: vulcanize_public + DB_NAME: vulcanize_testing DB_HOST: ipld-eth-db DB_PORT: 5432 DB_PASSWORD: password @@ -21,7 +21,7 @@ services: image: vulcanize/ipld-eth-db:v0.2.0 environment: POSTGRES_USER: "vdbm" - POSTGRES_DB: "vulcanize_public" + POSTGRES_DB: "vulcanize_testing" POSTGRES_PASSWORD: "password" volumes: - vdb_db_eth_server:/var/lib/postgresql/data @@ -44,7 +44,7 @@ services: ETH_SERVER_HTTPPATH: 0.0.0.0:8081 VDB_COMMAND: "serve" ETH_CHAIN_CONFIG: "/tmp/chain.json" - DATABASE_NAME: "vulcanize_public" + DATABASE_NAME: "vulcanize_testing" DATABASE_HOSTNAME: "ipld-eth-db" DATABASE_PORT: 5432 DATABASE_USER: "vdbm" diff --git a/pkg/eth/api_test.go b/pkg/eth/api_test.go index ceb5b22a..fa5025c2 100644 --- a/pkg/eth/api_test.go +++ b/pkg/eth/api_test.go @@ -188,7 +188,7 @@ func SetupDB() (*postgres.DB, error) { User: "vdbm", Password: "password", Hostname: "localhost", - Name: "vulcanize_public", + Name: "vulcanize_testing", Port: 8077, }) return postgres.NewDB(uri, postgres.ConnectionConfig{}, node.Info{}) diff --git a/pkg/graphql/graphql_test.go b/pkg/graphql/graphql_test.go index eda87382..68e394db 100644 --- a/pkg/graphql/graphql_test.go +++ b/pkg/graphql/graphql_test.go @@ -49,7 +49,7 @@ func SetupDB() (*postgres.DB, error) { User: "vdbm", Password: "password", Hostname: "localhost", - Name: "vulcanize_public", + Name: "vulcanize_testing", Port: 8077, }) return postgres.NewDB(uri, postgres.ConnectionConfig{}, node.Info{}) diff --git a/scripts/run_unit_test.sh b/scripts/run_unit_test.sh index 1e15f03b..703fcef8 100755 --- a/scripts/run_unit_test.sh +++ b/scripts/run_unit_test.sh @@ -1,2 +1,5 @@ -docker-compose -f docker-compose.test.yml -f docker-compose.yml up -d db +# Clear up existing docker images and volume. +docker-compose down --remove-orphans --volumes + +docker-compose -f docker-compose.test.yml -f docker-compose.yml up -d ipld-eth-db PGPASSWORD=password DATABASE_USER=vdbm DATABASE_PORT=8077 DATABASE_PASSWORD=password DATABASE_HOSTNAME=127.0.0.1 make test \ No newline at end of file From fcd2b963b013f7eade35e5d09fdf9fd732ff87e5 Mon Sep 17 00:00:00 2001 From: Arijit Das Date: Mon, 11 Oct 2021 22:26:24 +0530 Subject: [PATCH 3/3] Get DB config from env. --- .github/workflows/on-pr.yaml | 2 +- pkg/eth/api_test.go | 12 +++++++----- pkg/graphql/graphql_test.go | 13 ++++++++----- scripts/run_unit_test.sh | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.github/workflows/on-pr.yaml b/.github/workflows/on-pr.yaml index fd1d8001..d33adc7a 100644 --- a/.github/workflows/on-pr.yaml +++ b/.github/workflows/on-pr.yaml @@ -32,7 +32,7 @@ jobs: - name: Test run: | sleep 10 - PGPASSWORD=password DATABASE_USER=vdbm DATABASE_PORT=8077 DATABASE_PASSWORD=password DATABASE_HOSTNAME=127.0.0.1 make test + PGPASSWORD=password DATABASE_USER=vdbm DATABASE_PORT=8077 DATABASE_PASSWORD=password DATABASE_HOSTNAME=127.0.0.1 DATABASE_NAME=vulcanize_testing make test integrationtest: name: Run integration tests diff --git a/pkg/eth/api_test.go b/pkg/eth/api_test.go index fa5025c2..13a6336b 100644 --- a/pkg/eth/api_test.go +++ b/pkg/eth/api_test.go @@ -19,6 +19,7 @@ package eth_test import ( "context" "math/big" + "os" "strconv" "github.com/ethereum/go-ethereum/common" @@ -184,12 +185,13 @@ var ( // SetupDB is use to setup a db for watcher tests func SetupDB() (*postgres.DB, error) { + port, _ := strconv.Atoi(os.Getenv("DATABASE_PORT")) uri := postgres.DbConnectionString(postgres.ConnectionParams{ - User: "vdbm", - Password: "password", - Hostname: "localhost", - Name: "vulcanize_testing", - Port: 8077, + User: os.Getenv("DATABASE_USER"), + Password: os.Getenv("DATABASE_PASSWORD"), + Hostname: os.Getenv("DATABASE_HOSTNAME"), + Name: os.Getenv("DATABASE_NAME"), + Port: port, }) return postgres.NewDB(uri, postgres.ConnectionConfig{}, node.Info{}) } diff --git a/pkg/graphql/graphql_test.go b/pkg/graphql/graphql_test.go index 68e394db..ceb87c9d 100644 --- a/pkg/graphql/graphql_test.go +++ b/pkg/graphql/graphql_test.go @@ -20,6 +20,8 @@ import ( "context" "fmt" "math/big" + "os" + "strconv" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -45,12 +47,13 @@ import ( // SetupDB is use to setup a db for watcher tests func SetupDB() (*postgres.DB, error) { + port, _ := strconv.Atoi(os.Getenv("DATABASE_PORT")) uri := postgres.DbConnectionString(postgres.ConnectionParams{ - User: "vdbm", - Password: "password", - Hostname: "localhost", - Name: "vulcanize_testing", - Port: 8077, + User: os.Getenv("DATABASE_USER"), + Password: os.Getenv("DATABASE_PASSWORD"), + Hostname: os.Getenv("DATABASE_HOSTNAME"), + Name: os.Getenv("DATABASE_NAME"), + Port: port, }) return postgres.NewDB(uri, postgres.ConnectionConfig{}, node.Info{}) } diff --git a/scripts/run_unit_test.sh b/scripts/run_unit_test.sh index 703fcef8..bcbeced7 100755 --- a/scripts/run_unit_test.sh +++ b/scripts/run_unit_test.sh @@ -2,4 +2,4 @@ docker-compose down --remove-orphans --volumes docker-compose -f docker-compose.test.yml -f docker-compose.yml up -d ipld-eth-db -PGPASSWORD=password DATABASE_USER=vdbm DATABASE_PORT=8077 DATABASE_PASSWORD=password DATABASE_HOSTNAME=127.0.0.1 make test \ No newline at end of file +PGPASSWORD=password DATABASE_USER=vdbm DATABASE_PORT=8077 DATABASE_PASSWORD=password DATABASE_HOSTNAME=127.0.0.1 DATABASE_NAME=vulcanize_testing make test \ No newline at end of file