Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da30a957a7 | ||
|
|
705835512e | ||
|
|
2a0e9f8dfd | ||
|
|
c8bdaefe97 | ||
|
|
a141d154b7 | ||
|
|
76986d9497 | ||
|
|
233fa29740 | ||
|
|
4883590d85 | ||
|
|
181e3745f1 | ||
|
|
4b697b2a98 | ||
|
|
77812f2673 | ||
|
|
849b17f4bd | ||
|
|
56c85709c1 | ||
|
|
2be2a06575 | ||
|
|
39fb9207b2 | ||
|
|
3914889d53 | ||
|
|
1a6ff273ba | ||
|
|
f57b816530 | ||
|
|
76aaa93c50 | ||
|
|
778bf82dfd | ||
|
|
e8c1db69b4 | ||
|
|
86eee94f9b | ||
|
|
d785fda414 | ||
|
|
41e04a1c30 | ||
|
|
3aa5cb36ef | ||
|
|
43ddbc7eea | ||
|
|
8df8b50cb1 | ||
|
|
072ba1edcc | ||
|
|
f61691a26e | ||
|
|
6ab34eb878 | ||
|
|
3e211d5978 | ||
|
|
f600ea46bc | ||
|
|
6fa38fd198 | ||
|
|
2fa941f084 | ||
|
|
14332c2cd9 | ||
|
|
a780782bb6 | ||
|
|
627f2c7f81 | ||
|
|
925b22869a | ||
|
|
e6fb859967 | ||
|
|
850b305bf6 | ||
|
|
2f6f939982 | ||
|
|
409521416b | ||
|
|
72d3174f63 | ||
|
|
e288a2933d | ||
|
|
1020ec18a4 | ||
|
|
3118bf4964 | ||
|
|
61e6585f1c | ||
|
|
e924974ece | ||
|
|
20b75ff18f | ||
|
|
ef65993412 | ||
|
|
520be6bc86 | ||
|
|
01074ab55c | ||
|
|
88e20dfc6e | ||
|
|
4446219c36 | ||
|
|
88a89c0cc2 | ||
|
|
63e77c9bc0 | ||
|
|
19570f733f | ||
|
|
3058dc48a8 | ||
|
|
5d86b6e029 | ||
|
|
3b863dc76b | ||
|
|
e92b66638e | ||
|
|
cb39a94792 | ||
|
|
ef4d1f958d | ||
|
|
de12fab935 | ||
|
|
34a6d3af4b | ||
|
|
c28ebcc4f2 | ||
|
|
93a995627c | ||
|
|
316bf0990a | ||
|
|
143d79fdfc | ||
|
|
c07ee1d78a |
+193
-25
@@ -1,7 +1,6 @@
|
||||
name: Docker Build
|
||||
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Run docker build
|
||||
@@ -14,34 +13,62 @@ jobs:
|
||||
name: Run unit tests
|
||||
env:
|
||||
GOPATH: /tmp/go
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.16.x, 1.17.x]
|
||||
os: [ubuntu-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
# To run the unit tests you need to add secrets to your repository.
|
||||
BUILD_HOSTNAME: ${{ secrets.BUILD_HOSTNAME }}
|
||||
BUILD_USERNAME: ${{ secrets.BUILD_USERNAME }}
|
||||
BUILD_KEY: ${{ secrets.BUILD_KEY }}
|
||||
#strategy:
|
||||
# matrix:
|
||||
# go-version: [1.16.x, 1.17.x]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Create GOPATH
|
||||
run: mkdir -p /tmp/go
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
- uses: actions/checkout@v2
|
||||
- name: Run database
|
||||
run: docker-compose up -d ipld-eth-db
|
||||
- name: Test
|
||||
|
||||
# Passed experience with GHA has taught me to store variables in files instead of passing them as variables.
|
||||
- name: Output variables to files
|
||||
run: |
|
||||
sleep 10
|
||||
PGPASSWORD=password DATABASE_USER=vdbm DATABASE_PORT=8077 DATABASE_PASSWORD=password DATABASE_HOSTNAME=127.0.0.1 DATABASE_NAME=vulcanize_testing make test
|
||||
echo $GITHUB_REPOSITORY > /tmp/git_repository
|
||||
echo $GITHUB_HEAD_REF > /tmp/git_head_ref
|
||||
echo "-----BEGIN OPENSSH PRIVATE KEY-----" >> /tmp/key
|
||||
echo ${{ env.BUILD_KEY }} >> /tmp/key
|
||||
echo "-----END OPENSSH PRIVATE KEY-----" >> /tmp/key
|
||||
chmod 400 /tmp/key
|
||||
cat /tmp/git_repository
|
||||
cat /tmp/git_head_ref
|
||||
|
||||
- name: Raw SCP
|
||||
run: |
|
||||
scp -o 'StrictHostKeyChecking no' -o UserKnownHostsFile=/dev/null -q -i /tmp/key /tmp/git_repository ${{ env.BUILD_USERNAME }}@${{ env.BUILD_HOSTNAME }}:/tmp/git_repository
|
||||
scp -o 'StrictHostKeyChecking no' -o UserKnownHostsFile=/dev/null -q -i /tmp/key /tmp/git_head_ref ${{ env.BUILD_USERNAME }}@${{ env.BUILD_HOSTNAME }}:/tmp/git_head_ref
|
||||
scp -o 'StrictHostKeyChecking no' -o UserKnownHostsFile=/dev/null -q -i /tmp/key .github/workflows/run_unit_test.sh ${{ env.BUILD_USERNAME }}@${{ env.BUILD_HOSTNAME }}:/tmp/run_unit_test.sh
|
||||
|
||||
- name: Trigger Unit Test
|
||||
run: |
|
||||
ssh -o 'StrictHostKeyChecking no' -o UserKnownHostsFile=/dev/null -q -i /tmp/key ${{ env.BUILD_USERNAME }}@${{ env.BUILD_HOSTNAME }} chmod +x /tmp/run_unit_test.sh /tmp/run_unit_test.sh
|
||||
ssh -o 'StrictHostKeyChecking no' -o UserKnownHostsFile=/dev/null -q -i /tmp/key ${{ env.BUILD_USERNAME }}@${{ env.BUILD_HOSTNAME }} /tmp/run_unit_test.sh
|
||||
|
||||
- name: Get the logs and cat them
|
||||
run: |
|
||||
scp -o 'StrictHostKeyChecking no' -o UserKnownHostsFile=/dev/null -q -i /tmp/key ${{ env.BUILD_USERNAME }}@${{ env.BUILD_HOSTNAME }}:/tmp/test.log .
|
||||
cat ./test.log
|
||||
|
||||
- name: Check Error Code
|
||||
run: |
|
||||
scp -o 'StrictHostKeyChecking no' -o UserKnownHostsFile=/dev/null -q -i /tmp/key ${{ env.BUILD_USERNAME }}@${{ env.BUILD_HOSTNAME }}:/tmp/return_test.txt .
|
||||
[ $(cat ./return_test.txt) -eq 0 ]
|
||||
|
||||
integrationtest:
|
||||
name: Run integration tests
|
||||
env:
|
||||
STACK_ORCHESTRATOR_REF: fcbc74451c5494664fe21f765e89c9c6565c07cb
|
||||
GO_ETHEREUM_REF: 498101102c891c4f8c3cab5649158c642ee1fd6b
|
||||
GOPATH: /tmp/go
|
||||
DB_WRITE: true
|
||||
ETH_FORWARD_ETH_CALLS: false
|
||||
ETH_PROXY_ON_ERROR: false
|
||||
ETH_HTTP_PATH: ""
|
||||
ETH_HTTP_PATH: "go-ethereum:8545"
|
||||
WATCHED_ADDRESS_GAP_FILLER_ENABLED: false
|
||||
WATCHED_ADDRESS_GAP_FILLER_INTERVAL: 2
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.16.x]
|
||||
@@ -55,10 +82,44 @@ jobs:
|
||||
with:
|
||||
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 ipld-eth-db dapptools contract eth-server
|
||||
with:
|
||||
path: "./ipld-eth-server"
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{ env.STACK_ORCHESTRATOR_REF }}
|
||||
path: "./stack-orchestrator/"
|
||||
repository: vulcanize/stack-orchestrator
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{ env.GO_ETHEREUM_REF }}
|
||||
repository: vulcanize/go-ethereum
|
||||
path: "./go-ethereum/"
|
||||
- name: Create config file
|
||||
run: |
|
||||
echo vulcanize_go_ethereum=$GITHUB_WORKSPACE/go-ethereum/ > ./config.sh
|
||||
echo vulcanize_ipld_eth_server=$GITHUB_WORKSPACE/ipld-eth-server/ >> ./config.sh
|
||||
echo db_write=$DB_WRITE >> ./config.sh
|
||||
echo eth_forward_eth_calls=$ETH_FORWARD_ETH_CALLS >> ./config.sh
|
||||
echo eth_proxy_on_error=$ETH_PROXY_ON_ERROR >> ./config.sh
|
||||
echo eth_http_path=$ETH_HTTP_PATH >> ./config.sh
|
||||
cat ./config.sh
|
||||
- name: Build geth
|
||||
run: |
|
||||
cd $GITHUB_WORKSPACE/stack-orchestrator/helper-scripts
|
||||
./compile-geth.sh \
|
||||
-p "$GITHUB_WORKSPACE/config.sh" \
|
||||
-e docker
|
||||
- name: Run docker compose
|
||||
run: |
|
||||
docker-compose \
|
||||
-f "$GITHUB_WORKSPACE/stack-orchestrator/docker/latest/docker-compose-db.yml" \
|
||||
-f "$GITHUB_WORKSPACE/stack-orchestrator/docker/local/docker-compose-go-ethereum.yml" \
|
||||
-f "$GITHUB_WORKSPACE/stack-orchestrator/docker/local/docker-compose-ipld-eth-server.yml" \
|
||||
--env-file "$GITHUB_WORKSPACE/config.sh" \
|
||||
up -d --build
|
||||
- name: Test
|
||||
run: |
|
||||
cd $GITHUB_WORKSPACE/ipld-eth-server
|
||||
while [ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8081)" != "200" ]; do echo "waiting for ipld-eth-server..." && sleep 5; done && \
|
||||
while [ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8545)" != "200" ]; do echo "waiting for geth-statediff..." && sleep 5; done && \
|
||||
make integrationtest
|
||||
@@ -66,15 +127,19 @@ jobs:
|
||||
integrationtest_forwardethcalls:
|
||||
name: Run integration tests for direct proxy fall-through of eth_calls
|
||||
env:
|
||||
STACK_ORCHESTRATOR_REF: fcbc74451c5494664fe21f765e89c9c6565c07cb
|
||||
GO_ETHEREUM_REF: 498101102c891c4f8c3cab5649158c642ee1fd6b
|
||||
GOPATH: /tmp/go
|
||||
DB_WRITE: false
|
||||
ETH_FORWARD_ETH_CALLS: true
|
||||
ETH_PROXY_ON_ERROR: false
|
||||
ETH_HTTP_PATH: "dapptools:8545"
|
||||
ETH_HTTP_PATH: "go-ethereum:8545"
|
||||
WATCHED_ADDRESS_GAP_FILLER_ENABLED: false
|
||||
WATCHED_ADDRESS_GAP_FILLER_INTERVAL: 2
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [ 1.16.x ]
|
||||
os: [ ubuntu-latest ]
|
||||
go-version: [1.16.x]
|
||||
os: [ubuntu-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Create GOPATH
|
||||
@@ -84,10 +149,113 @@ jobs:
|
||||
with:
|
||||
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 ipld-eth-db dapptools contract eth-server
|
||||
with:
|
||||
path: "./ipld-eth-server"
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{ env.STACK_ORCHESTRATOR_REF }}
|
||||
path: "./stack-orchestrator/"
|
||||
repository: vulcanize/stack-orchestrator
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{ env.GO_ETHEREUM_REF }}
|
||||
repository: vulcanize/go-ethereum
|
||||
path: "./go-ethereum/"
|
||||
- name: Create config file
|
||||
run: |
|
||||
echo vulcanize_go_ethereum=$GITHUB_WORKSPACE/go-ethereum/ > ./config.sh
|
||||
echo vulcanize_ipld_eth_server=$GITHUB_WORKSPACE/ipld-eth-server/ >> ./config.sh
|
||||
echo db_write=$DB_WRITE >> ./config.sh
|
||||
echo eth_forward_eth_calls=$ETH_FORWARD_ETH_CALLS >> ./config.sh
|
||||
echo eth_proxy_on_error=$ETH_PROXY_ON_ERROR >> ./config.sh
|
||||
echo eth_http_path=$ETH_HTTP_PATH >> ./config.sh
|
||||
cat ./config.sh
|
||||
- name: Build geth
|
||||
run: |
|
||||
cd $GITHUB_WORKSPACE/stack-orchestrator/helper-scripts
|
||||
./compile-geth.sh \
|
||||
-p "$GITHUB_WORKSPACE/config.sh" \
|
||||
-e docker
|
||||
- name: Run docker compose
|
||||
run: |
|
||||
docker-compose \
|
||||
-f "$GITHUB_WORKSPACE/stack-orchestrator/docker/latest/docker-compose-db.yml" \
|
||||
-f "$GITHUB_WORKSPACE/stack-orchestrator/docker/local/docker-compose-go-ethereum.yml" \
|
||||
-f "$GITHUB_WORKSPACE/stack-orchestrator/docker/local/docker-compose-ipld-eth-server.yml" \
|
||||
--env-file "$GITHUB_WORKSPACE/config.sh" \
|
||||
up -d --build
|
||||
- name: Test
|
||||
run: |
|
||||
cd $GITHUB_WORKSPACE/ipld-eth-server
|
||||
while [ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8081)" != "200" ]; do echo "waiting for ipld-eth-server..." && sleep 5; done && \
|
||||
while [ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8545)" != "200" ]; do echo "waiting for geth-statediff..." && sleep 5; done && \
|
||||
make integrationtest
|
||||
|
||||
integrationtest_watchedaddress_gapfillingservice:
|
||||
name: Run integration tests for watched addresses with gap filling service enabled
|
||||
env:
|
||||
STACK_ORCHESTRATOR_REF: fcbc74451c5494664fe21f765e89c9c6565c07cb
|
||||
GO_ETHEREUM_REF: 498101102c891c4f8c3cab5649158c642ee1fd6b
|
||||
GOPATH: /tmp/go
|
||||
DB_WRITE: true
|
||||
ETH_FORWARD_ETH_CALLS: false
|
||||
ETH_PROXY_ON_ERROR: false
|
||||
ETH_HTTP_PATH: "go-ethereum:8545"
|
||||
WATCHED_ADDRESS_GAP_FILLER_ENABLED: true
|
||||
WATCHED_ADDRESS_GAP_FILLER_INTERVAL: 2
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.16.x]
|
||||
os: [ubuntu-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Create GOPATH
|
||||
run: mkdir -p /tmp/go
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
path: "./ipld-eth-server"
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{ env.STACK_ORCHESTRATOR_REF }}
|
||||
path: "./stack-orchestrator/"
|
||||
repository: vulcanize/stack-orchestrator
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{ env.GO_ETHEREUM_REF }}
|
||||
repository: vulcanize/go-ethereum
|
||||
path: "./go-ethereum/"
|
||||
- name: Create config file
|
||||
run: |
|
||||
echo vulcanize_go_ethereum=$GITHUB_WORKSPACE/go-ethereum/ > ./config.sh
|
||||
echo vulcanize_ipld_eth_server=$GITHUB_WORKSPACE/ipld-eth-server/ >> ./config.sh
|
||||
echo db_write=$DB_WRITE >> ./config.sh
|
||||
echo eth_forward_eth_calls=$ETH_FORWARD_ETH_CALLS >> ./config.sh
|
||||
echo eth_proxy_on_error=$ETH_PROXY_ON_ERROR >> ./config.sh
|
||||
echo eth_http_path=$ETH_HTTP_PATH >> ./config.sh
|
||||
echo watched_addres_gap_filler_enabled=$WATCHED_ADDRESS_GAP_FILLER_ENABLED >> ./config.sh
|
||||
echo watched_addres_gap_filler_interval=$WATCHED_ADDRESS_GAP_FILLER_INTERVAL >> ./config.sh
|
||||
cat ./config.sh
|
||||
- name: Build geth
|
||||
run: |
|
||||
cd $GITHUB_WORKSPACE/stack-orchestrator/helper-scripts
|
||||
./compile-geth.sh \
|
||||
-p "$GITHUB_WORKSPACE/config.sh" \
|
||||
-e docker
|
||||
- name: Run docker compose
|
||||
run: |
|
||||
docker-compose \
|
||||
-f "$GITHUB_WORKSPACE/stack-orchestrator/docker/latest/docker-compose-db.yml" \
|
||||
-f "$GITHUB_WORKSPACE/stack-orchestrator/docker/local/docker-compose-go-ethereum.yml" \
|
||||
-f "$GITHUB_WORKSPACE/stack-orchestrator/docker/local/docker-compose-ipld-eth-server.yml" \
|
||||
--env-file "$GITHUB_WORKSPACE/config.sh" \
|
||||
up -d --build
|
||||
- name: Test
|
||||
run: |
|
||||
cd $GITHUB_WORKSPACE/ipld-eth-server
|
||||
while [ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8081)" != "200" ]; do echo "waiting for ipld-eth-server..." && sleep 5; done && \
|
||||
while [ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8545)" != "200" ]; do echo "waiting for geth-statediff..." && sleep 5; done && \
|
||||
make integrationtest
|
||||
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Set up repo
|
||||
start_dir=$(pwd)
|
||||
temp_dir=$(mktemp -d)
|
||||
cd $temp_dir
|
||||
git clone -b $(cat /tmp/git_head_ref) "https://github.com/$(cat /tmp/git_repository).git"
|
||||
cd ipld-eth-server
|
||||
|
||||
## Remove the branch and github related info. This way future runs wont be confused.
|
||||
rm -f /tmp/git_head_ref /tmp/git_repository
|
||||
|
||||
# Spin up DB
|
||||
docker-compose up -d ipld-eth-db
|
||||
trap "docker-compose down --remove-orphans; cd $start_dir ; rm -r $temp_dir" SIGINT SIGTERM ERR
|
||||
sleep 10
|
||||
|
||||
# Remove old logs so there's no confusion, then run test
|
||||
rm -f /tmp/test.log /tmp/return_test.txt
|
||||
PGPASSWORD=password DATABASE_USER=vdbm DATABASE_PORT=8077 DATABASE_PASSWORD=password DATABASE_HOSTNAME=127.0.0.1 DATABASE_NAME=vulcanize_testing make test > /tmp/test.log
|
||||
echo $? > /tmp/return_test.txt
|
||||
|
||||
# Clean up
|
||||
docker-compose down -v --remove-orphans
|
||||
cd $start_dir
|
||||
rm -fr $temp_dir
|
||||
|
||||
@@ -71,13 +71,6 @@ test_local: | $(GINKGO) $(GOOSE)
|
||||
go fmt ./...
|
||||
./scripts/run_unit_test.sh
|
||||
|
||||
.PHONY: integrationtest_local
|
||||
integrationtest_local: | $(GINKGO) $(GOOSE)
|
||||
go vet ./...
|
||||
go fmt ./...
|
||||
./scripts/run_integration_test.sh
|
||||
./scripts/run_integration_test_forward_eth_calls.sh
|
||||
|
||||
build:
|
||||
go fmt ./...
|
||||
GO111MODULE=on go build
|
||||
|
||||
@@ -33,9 +33,9 @@ External dependency
|
||||
## Install
|
||||
Start by downloading ipld-eth-server and moving into the repo:
|
||||
|
||||
`GO111MODULE=off go get -d github.com/vulcanize/ipld-eth-server`
|
||||
`GO111MODULE=off go get -d github.com/vulcanize/ipld-eth-server/v3`
|
||||
|
||||
`cd $GOPATH/src/github.com/vulcanize/ipld-eth-server`
|
||||
`cd $GOPATH/src/github.com/vulcanize/ipld-eth-server/v3@v3.x.x`
|
||||
|
||||
Then, build the binary:
|
||||
|
||||
@@ -148,8 +148,8 @@ TODO: Add the rest of the standard endpoints and unique endpoints (e.g. getSlice
|
||||
|
||||
|
||||
### Testing
|
||||
`make test` will run the unit tests
|
||||
`make test` setups a clean `vulcanize_testing` db
|
||||
|
||||
Follow steps in [test/README.md](./test/README.md)
|
||||
|
||||
## Monitoring
|
||||
|
||||
|
||||
+31
-8
@@ -19,16 +19,20 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/prom"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/prom"
|
||||
)
|
||||
|
||||
var (
|
||||
cfgFile string
|
||||
envFile string
|
||||
subCommand string
|
||||
logWithCommand log.Entry
|
||||
)
|
||||
@@ -99,6 +103,7 @@ func init() {
|
||||
viper.AutomaticEnv()
|
||||
|
||||
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file location")
|
||||
rootCmd.PersistentFlags().StringVar(&envFile, "env", "", "environment file location")
|
||||
|
||||
rootCmd.PersistentFlags().String("client-ipcPath", "", "location of geth.ipc file")
|
||||
rootCmd.PersistentFlags().String("log-level", log.InfoLevel.String(), "log level (trace, debug, info, warn, error, fatal, panic)")
|
||||
@@ -121,14 +126,32 @@ func init() {
|
||||
}
|
||||
|
||||
func initConfig() {
|
||||
if cfgFile == "" && envFile == "" {
|
||||
log.Fatal("No configuration file specified, use --config , --env flag to provide configuration")
|
||||
}
|
||||
|
||||
if cfgFile != "" {
|
||||
viper.SetConfigFile(cfgFile)
|
||||
if err := viper.ReadInConfig(); err == nil {
|
||||
log.Printf("Using config file: %s", viper.ConfigFileUsed())
|
||||
} else {
|
||||
log.Fatal(fmt.Sprintf("Couldn't read config file: %s", err.Error()))
|
||||
if filepath.Ext(cfgFile) != ".toml" {
|
||||
log.Fatal("Provide .toml file for --config flag")
|
||||
}
|
||||
} else {
|
||||
log.Warn("No config file passed with --config flag")
|
||||
|
||||
viper.SetConfigFile(cfgFile)
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
log.Fatalf("Couldn't read config file: %s", err.Error())
|
||||
}
|
||||
|
||||
log.Infof("Using config file: %s", viper.ConfigFileUsed())
|
||||
}
|
||||
|
||||
if envFile != "" {
|
||||
if filepath.Ext(envFile) != ".env" {
|
||||
log.Fatal("Provide .env file for --env flag")
|
||||
}
|
||||
|
||||
if err := godotenv.Load(envFile); err != nil {
|
||||
log.Fatalf("Failed to set environment variable from env file: %s", err.Error())
|
||||
}
|
||||
|
||||
log.Infof("Using env file: %s", envFile)
|
||||
}
|
||||
}
|
||||
|
||||
+28
-6
@@ -32,11 +32,12 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
"github.com/vulcanize/gap-filler/pkg/mux"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/graphql"
|
||||
srpc "github.com/vulcanize/ipld-eth-server/pkg/rpc"
|
||||
s "github.com/vulcanize/ipld-eth-server/pkg/serve"
|
||||
v "github.com/vulcanize/ipld-eth-server/version"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth"
|
||||
fill "github.com/vulcanize/ipld-eth-server/v3/pkg/fill"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/graphql"
|
||||
srpc "github.com/vulcanize/ipld-eth-server/v3/pkg/rpc"
|
||||
s "github.com/vulcanize/ipld-eth-server/v3/pkg/serve"
|
||||
v "github.com/vulcanize/ipld-eth-server/v3/version"
|
||||
)
|
||||
|
||||
var ErrNoRpcEndpoints = errors.New("no rpc endpoints is available")
|
||||
@@ -100,12 +101,25 @@ func serve() {
|
||||
logWithCommand.Info("state validator disabled")
|
||||
}
|
||||
|
||||
var watchedAddressFillService *fill.Service
|
||||
if serverConfig.WatchedAddressGapFillerEnabled {
|
||||
watchedAddressFillService = fill.New(serverConfig)
|
||||
wg.Add(1)
|
||||
go watchedAddressFillService.Start(wg)
|
||||
logWithCommand.Info("watched address gap filler enabled")
|
||||
} else {
|
||||
logWithCommand.Info("watched address gap filler disabled")
|
||||
}
|
||||
|
||||
shutdown := make(chan os.Signal, 1)
|
||||
signal.Notify(shutdown, os.Interrupt)
|
||||
<-shutdown
|
||||
if graphQL != nil {
|
||||
graphQL.Stop()
|
||||
}
|
||||
if watchedAddressFillService != nil {
|
||||
watchedAddressFillService.Stop()
|
||||
}
|
||||
server.Stop()
|
||||
wg.Wait()
|
||||
}
|
||||
@@ -133,7 +147,7 @@ func startServers(server s.Server, settings *s.Config) error {
|
||||
|
||||
if settings.HTTPEnabled {
|
||||
logWithCommand.Info("starting up HTTP server")
|
||||
_, err := srpc.StartHTTPEndpoint(settings.HTTPEndpoint, server.APIs(), []string{"eth", "net"}, nil, []string{"*"}, rpc.HTTPTimeouts{})
|
||||
_, err := srpc.StartHTTPEndpoint(settings.HTTPEndpoint, server.APIs(), []string{"vdb", "eth", "net"}, nil, []string{"*"}, rpc.HTTPTimeouts{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -360,6 +374,10 @@ func init() {
|
||||
serveCmd.PersistentFlags().Bool("validator-enabled", false, "turn on the state validator")
|
||||
serveCmd.PersistentFlags().Uint("validator-every-nth-block", 1500, "only validate every Nth block")
|
||||
|
||||
// watched address gap filler flags
|
||||
serveCmd.PersistentFlags().Bool("watched-address-gap-filler-enabled", false, "turn on the watched address gap filler")
|
||||
serveCmd.PersistentFlags().Int("watched-address-gap-filler-interval", 60, "watched address gap fill interval in secs")
|
||||
|
||||
// and their bindings
|
||||
// eth graphql server
|
||||
viper.BindPFlag("eth.server.graphql", serveCmd.PersistentFlags().Lookup("eth-server-graphql"))
|
||||
@@ -408,4 +426,8 @@ func init() {
|
||||
// state validator flags
|
||||
viper.BindPFlag("validator.enabled", serveCmd.PersistentFlags().Lookup("validator-enabled"))
|
||||
viper.BindPFlag("validator.everyNthBlock", serveCmd.PersistentFlags().Lookup("validator-every-nth-block"))
|
||||
|
||||
// watched address gap filler flags
|
||||
viper.BindPFlag("watch.fill.enabled", serveCmd.PersistentFlags().Lookup("watched-address-gap-filler-enabled"))
|
||||
viper.BindPFlag("watch.fill.interval", serveCmd.PersistentFlags().Lookup("watched-address-gap-filler-interval"))
|
||||
}
|
||||
|
||||
+3
-3
@@ -27,9 +27,9 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/client"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
w "github.com/vulcanize/ipld-eth-server/pkg/serve"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/client"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth"
|
||||
w "github.com/vulcanize/ipld-eth-server/v3/pkg/serve"
|
||||
)
|
||||
|
||||
// subscribeCmd represents the subscribe command
|
||||
|
||||
+4
-4
@@ -22,10 +22,10 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
validator "github.com/vulcanize/eth-ipfs-state-validator/pkg"
|
||||
ipfsethdb "github.com/vulcanize/ipfs-ethdb/postgres"
|
||||
validator "github.com/vulcanize/eth-ipfs-state-validator/v3/pkg"
|
||||
ipfsethdb "github.com/vulcanize/ipfs-ethdb/v3/postgres"
|
||||
|
||||
s "github.com/vulcanize/ipld-eth-server/pkg/serve"
|
||||
s "github.com/vulcanize/ipld-eth-server/v3/pkg/serve"
|
||||
)
|
||||
|
||||
const GroupName = "statedb-validate"
|
||||
@@ -57,7 +57,7 @@ func validate() {
|
||||
stateRoot := common.HexToHash(stateRootStr)
|
||||
cacheSize := viper.GetInt("cacheSize")
|
||||
|
||||
ethDB := ipfsethdb.NewDatabase(config.DB.DB, ipfsethdb.CacheConfig{
|
||||
ethDB := ipfsethdb.NewDatabase(config.DB, ipfsethdb.CacheConfig{
|
||||
Name: GroupName,
|
||||
Size: cacheSize * 1024 * 1024,
|
||||
ExpiryDuration: time.Minute * time.Duration(CacheExpiryInMins),
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
v "github.com/vulcanize/ipld-eth-server/version"
|
||||
v "github.com/vulcanize/ipld-eth-server/v3/version"
|
||||
)
|
||||
|
||||
// versionCmd represents the version command
|
||||
|
||||
@@ -2,13 +2,11 @@ version: '3.2'
|
||||
|
||||
services:
|
||||
contract:
|
||||
depends_on:
|
||||
- dapptools
|
||||
build:
|
||||
context: ./test/contract
|
||||
args:
|
||||
ETH_ADDR: "http://dapptools:8545"
|
||||
ETH_ADDR: "http://go-ethereum:8545"
|
||||
environment:
|
||||
ETH_ADDR: "http://dapptools:8545"
|
||||
ETH_ADDR: "http://go-ethereum:8545"
|
||||
ports:
|
||||
- "127.0.0.1:3000:3000"
|
||||
|
||||
+3
-17
@@ -1,25 +1,9 @@
|
||||
version: '3.2'
|
||||
|
||||
services:
|
||||
dapptools:
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
- ipld-eth-db
|
||||
image: vulcanize/dapptools:v0.30.0-v1.10.14-statediff-0.0.29
|
||||
environment:
|
||||
DB_USER: vdbm
|
||||
DB_NAME: vulcanize_testing
|
||||
DB_HOST: ipld-eth-db
|
||||
DB_PORT: 5432
|
||||
DB_PASSWORD: password
|
||||
DB_WRITE: $DB_WRITE
|
||||
ports:
|
||||
- "127.0.0.1:8545:8545"
|
||||
- "127.0.0.1:8546:8546"
|
||||
|
||||
ipld-eth-db:
|
||||
restart: always
|
||||
image: vulcanize/ipld-eth-db:v0.2.0
|
||||
image: vulcanize/ipld-eth-db:v3.2.0
|
||||
environment:
|
||||
POSTGRES_USER: "vdbm"
|
||||
POSTGRES_DB: "vulcanize_testing"
|
||||
@@ -54,6 +38,8 @@ services:
|
||||
ETH_FORWARD_ETH_CALLS: $ETH_FORWARD_ETH_CALLS
|
||||
ETH_PROXY_ON_ERROR: $ETH_PROXY_ON_ERROR
|
||||
ETH_HTTP_PATH: $ETH_HTTP_PATH
|
||||
WATCHED_ADDRESS_GAP_FILLER_ENABLED: $WATCHED_ADDRESS_GAP_FILLER_ENABLED
|
||||
WATCHED_ADDRESS_GAP_FILLER_INTERVAL: $WATCHED_ADDRESS_GAP_FILLER_INTERVAL
|
||||
volumes:
|
||||
- type: bind
|
||||
source: ./chain.json
|
||||
|
||||
+11
-11
@@ -12,7 +12,7 @@ We can expose a number of different APIs for remote access to ipld-eth-server da
|
||||
ipld-eth-server stores all processed data in Postgres using PG-IPFS, this includes all of the IPLD objects.
|
||||
[Postgraphile](https://www.graphile.org/postgraphile/) can be used to expose GraphQL endpoints for the Postgres tables.
|
||||
|
||||
e.g.
|
||||
e.g.
|
||||
|
||||
`postgraphile --plugins @graphile/pg-pubsub --subscriptions --simple-subscriptions -c postgres://localhost:5432/vulcanize_public?sslmode=disable -s public,btc,eth -a -j`
|
||||
|
||||
@@ -33,16 +33,16 @@ by ipld-eth-server to filter and return a requested subset of chain data to the
|
||||
An example of how to subscribe to a real-time Ethereum data feed from ipld-eth-server using the `Stream` RPC method is provided below
|
||||
|
||||
```go
|
||||
package main
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/client"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/watch"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/client"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/watch"
|
||||
)
|
||||
|
||||
config, _ := eth.NewEthSubscriptionConfig()
|
||||
@@ -153,16 +153,16 @@ the addresses in the `addresses` fields are pre-hashed ETH addresses.
|
||||
An example of how to subscribe to a real-time Bitcoin data feed from ipld-eth-server using the `Stream` RPC method is provided below
|
||||
|
||||
```go
|
||||
package main
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/btc"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/client"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/watch"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/btc"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/client"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/watch"
|
||||
)
|
||||
|
||||
config, _ := btc.NewBtcSubscriptionConfig()
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
graphqlEndpoint = "127.0.0.1:8083" # $SERVER_GRAPHQL_ENDPOINT
|
||||
|
||||
[ethereum]
|
||||
chainConfig = "./chain.json" # ETH_CHAIN_CONFIG
|
||||
chainID = "1" # $ETH_CHAIN_ID
|
||||
defaultSender = "" # $ETH_DEFAULT_SENDER_ADDR
|
||||
rpcGasCap = "1000000000000" # $ETH_RPC_GAS_CAP
|
||||
@@ -27,3 +28,8 @@
|
||||
clientName = "Geth" # $ETH_CLIENT_NAME
|
||||
genesisBlock = "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3" # $ETH_GENESIS_BLOCK
|
||||
networkID = "1" # $ETH_NETWORK_ID
|
||||
|
||||
[watch]
|
||||
[watch.fill]
|
||||
enabled = false
|
||||
interval = 30
|
||||
|
||||
@@ -1,38 +1,31 @@
|
||||
module github.com/vulcanize/ipld-eth-server
|
||||
module github.com/vulcanize/ipld-eth-server/v3
|
||||
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/ethereum/go-ethereum v1.10.14
|
||||
github.com/fsnotify/fsnotify v1.5.1 // indirect
|
||||
github.com/graph-gophers/graphql-go v0.0.0-20201113091052-beb923fada29
|
||||
github.com/ethereum/go-ethereum v1.10.17
|
||||
github.com/graph-gophers/graphql-go v1.3.0
|
||||
github.com/ipfs/go-block-format v0.0.3
|
||||
github.com/ipfs/go-blockservice v0.1.7
|
||||
github.com/ipfs/go-cid v0.0.7
|
||||
github.com/ipfs/go-ipfs v0.10.0
|
||||
github.com/ipfs/go-ipfs-blockstore v1.0.1
|
||||
github.com/ipfs/go-ipfs-ds-help v1.0.0
|
||||
github.com/ipfs/go-ipld-format v0.2.0
|
||||
github.com/jmoiron/sqlx v1.2.0
|
||||
github.com/lib/pq v1.10.4
|
||||
github.com/jmoiron/sqlx v1.3.5
|
||||
github.com/joho/godotenv v1.4.0
|
||||
github.com/lib/pq v1.10.5
|
||||
github.com/machinebox/graphql v0.2.2
|
||||
github.com/mailgun/groupcache/v2 v2.2.1
|
||||
github.com/mailgun/groupcache/v2 v2.3.0
|
||||
github.com/matryer/is v1.4.0 // indirect
|
||||
github.com/multiformats/go-multihash v0.0.15
|
||||
github.com/multiformats/go-multihash v0.1.0
|
||||
github.com/onsi/ginkgo v1.16.5
|
||||
github.com/onsi/gomega v1.13.0
|
||||
github.com/onsi/gomega v1.19.0
|
||||
github.com/prometheus/client_golang v1.11.0
|
||||
github.com/shirou/gopsutil v3.21.5+incompatible // indirect
|
||||
github.com/sirupsen/logrus v1.7.0
|
||||
github.com/spf13/cobra v1.1.1
|
||||
github.com/spf13/viper v1.7.0
|
||||
github.com/tklauser/go-sysconf v0.3.6 // indirect
|
||||
github.com/vulcanize/eth-ipfs-state-validator v0.1.0
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/spf13/cobra v1.4.0
|
||||
github.com/spf13/viper v1.11.0
|
||||
github.com/vulcanize/eth-ipfs-state-validator/v3 v3.0.0
|
||||
github.com/vulcanize/gap-filler v0.3.1
|
||||
github.com/vulcanize/ipfs-ethdb v0.0.6
|
||||
golang.org/x/crypto v0.0.0-20211202192323-5770296d904e // indirect
|
||||
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect
|
||||
golang.org/x/tools v0.1.8 // indirect
|
||||
github.com/vulcanize/ipfs-ethdb/v3 v3.0.1
|
||||
)
|
||||
|
||||
replace github.com/ethereum/go-ethereum v1.10.14 => github.com/vulcanize/go-ethereum v1.10.14-statediff-0.0.29
|
||||
replace github.com/ethereum/go-ethereum v1.10.17 => github.com/vulcanize/go-ethereum v1.10.17-statediff-3.2.1
|
||||
|
||||
@@ -18,7 +18,7 @@ package main
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/cmd"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/cmd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -20,11 +20,10 @@ package client
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/serve"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/serve"
|
||||
)
|
||||
|
||||
// Client is used to subscribe to the ipld-eth-server ipld data stream
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/statediff"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/shared"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/shared"
|
||||
)
|
||||
|
||||
// APIName is the namespace for the watcher's eth api
|
||||
|
||||
+19
-38
@@ -19,7 +19,6 @@ package eth_test
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
@@ -31,16 +30,16 @@ import (
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/node"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/postgres"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
|
||||
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
|
||||
"github.com/jmoiron/sqlx"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth/test_helpers"
|
||||
ethServerShared "github.com/vulcanize/ipld-eth-server/pkg/shared"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth/test_helpers"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/shared"
|
||||
ethServerShared "github.com/vulcanize/ipld-eth-server/v3/pkg/shared"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -183,22 +182,9 @@ 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: 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{})
|
||||
}
|
||||
|
||||
var _ = Describe("API", func() {
|
||||
var (
|
||||
db *postgres.DB
|
||||
db *sqlx.DB
|
||||
api *eth.PublicEthAPI
|
||||
chainConfig = params.TestChainConfig
|
||||
)
|
||||
@@ -207,14 +193,12 @@ var _ = Describe("API", func() {
|
||||
It("test init", func() {
|
||||
var (
|
||||
err error
|
||||
tx *indexer.BlockTx
|
||||
tx interfaces.Batch
|
||||
)
|
||||
|
||||
db, err = SetupDB()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
db = shared.SetupDB()
|
||||
indexAndPublisher := shared.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash())
|
||||
|
||||
indexAndPublisher, err := indexer.NewStateDiffIndexer(chainConfig, db)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
backend, err := eth.NewEthBackend(db, ð.Config{
|
||||
ChainConfig: chainConfig,
|
||||
VMConfig: vm.Config{},
|
||||
@@ -233,11 +217,6 @@ var _ = Describe("API", func() {
|
||||
tx, err = indexAndPublisher.PushBlock(test_helpers.MockBlock, test_helpers.MockReceipts, test_helpers.MockBlock.Difficulty())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
for _, node := range test_helpers.MockStateNodes {
|
||||
err = indexAndPublisher.PushStateNode(tx, node)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
||||
ccHash := sdtypes.CodeAndCodeHash{
|
||||
Hash: test_helpers.ContractCodeHash,
|
||||
Code: test_helpers.ContractCode,
|
||||
@@ -246,7 +225,12 @@ var _ = Describe("API", func() {
|
||||
err = indexAndPublisher.PushCodeAndCodeHash(tx, ccHash)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
err = tx.Close(err)
|
||||
for _, node := range test_helpers.MockStateNodes {
|
||||
err = indexAndPublisher.PushStateNode(tx, node, test_helpers.MockBlock.Hash().String())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
||||
err = tx.Submit(err)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
uncles := test_helpers.MockBlock.Uncles()
|
||||
@@ -258,18 +242,17 @@ var _ = Describe("API", func() {
|
||||
|
||||
// setting chain config to for london block
|
||||
chainConfig.LondonBlock = big.NewInt(2)
|
||||
indexAndPublisher, err = indexer.NewStateDiffIndexer(chainConfig, db)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
indexAndPublisher = shared.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash())
|
||||
|
||||
tx, err = indexAndPublisher.PushBlock(test_helpers.MockLondonBlock, test_helpers.MockLondonReceipts, test_helpers.MockLondonBlock.Difficulty())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
err = tx.Close(err)
|
||||
err = tx.Submit(err)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
// Single test db tear down at end of all tests
|
||||
defer It("test teardown", func() { eth.TearDownDB(db) })
|
||||
defer It("test teardown", func() { shared.TearDownDB(db) })
|
||||
/*
|
||||
|
||||
Headers and blocks
|
||||
@@ -287,8 +270,6 @@ var _ = Describe("API", func() {
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("sql: no rows in result set"))
|
||||
Expect(header).To(BeNil())
|
||||
_, err = api.B.DB.Beginx()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
+31
-30
@@ -39,15 +39,16 @@ import (
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/ipfs"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/postgres"
|
||||
ethServerShared "github.com/ethereum/go-ethereum/statediff/indexer/shared"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/models"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
"github.com/jmoiron/sqlx"
|
||||
log "github.com/sirupsen/logrus"
|
||||
validator "github.com/vulcanize/eth-ipfs-state-validator/pkg"
|
||||
ipfsethdb "github.com/vulcanize/ipfs-ethdb/postgres"
|
||||
validator "github.com/vulcanize/eth-ipfs-state-validator/v3/pkg"
|
||||
ipfsethdb "github.com/vulcanize/ipfs-ethdb/v3/postgres"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/shared"
|
||||
ethServerShared "github.com/ethereum/go-ethereum/statediff/indexer/shared"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/shared"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -64,24 +65,24 @@ var (
|
||||
const (
|
||||
RetrieveCanonicalBlockHashByNumber = `SELECT block_hash FROM eth.header_cids
|
||||
INNER JOIN public.blocks ON (header_cids.mh_key = blocks.key)
|
||||
WHERE id = (SELECT canonical_header_id($1))`
|
||||
WHERE block_hash = (SELECT canonical_header_hash($1))`
|
||||
RetrieveCanonicalHeaderByNumber = `SELECT cid, data FROM eth.header_cids
|
||||
INNER JOIN public.blocks ON (header_cids.mh_key = blocks.key)
|
||||
WHERE id = (SELECT canonical_header_id($1))`
|
||||
RetrieveTD = `SELECT td FROM eth.header_cids
|
||||
WHERE block_hash = (SELECT canonical_header_hash($1))`
|
||||
RetrieveTD = `SELECT CAST(td as Text) FROM eth.header_cids
|
||||
WHERE header_cids.block_hash = $1`
|
||||
RetrieveRPCTransaction = `SELECT blocks.data, block_hash, block_number, index FROM public.blocks, eth.transaction_cids, eth.header_cids
|
||||
WHERE blocks.key = transaction_cids.mh_key
|
||||
AND transaction_cids.header_id = header_cids.id
|
||||
AND transaction_cids.header_id = header_cids.block_hash
|
||||
AND transaction_cids.tx_hash = $1`
|
||||
RetrieveCodeHashByLeafKeyAndBlockHash = `SELECT code_hash FROM eth.state_accounts, eth.state_cids, eth.header_cids
|
||||
WHERE state_accounts.state_id = state_cids.id
|
||||
AND state_cids.header_id = header_cids.id
|
||||
WHERE state_accounts.header_id = state_cids.header_id AND state_accounts.state_path = state_cids.state_path
|
||||
AND state_cids.header_id = header_cids.block_hash
|
||||
AND state_leaf_key = $1
|
||||
AND block_number <= (SELECT block_number
|
||||
FROM eth.header_cids
|
||||
WHERE block_hash = $2)
|
||||
AND header_cids.id = (SELECT canonical_header_id(block_number))
|
||||
AND header_cids.block_hash = (SELECT canonical_header_hash(block_number))
|
||||
ORDER BY block_number DESC
|
||||
LIMIT 1`
|
||||
RetrieveCodeByMhKey = `SELECT data FROM public.blocks WHERE key = $1`
|
||||
@@ -93,7 +94,7 @@ const (
|
||||
|
||||
type Backend struct {
|
||||
// underlying postgres db
|
||||
DB *postgres.DB
|
||||
DB *sqlx.DB
|
||||
|
||||
// postgres db interfaces
|
||||
Retriever *CIDRetriever
|
||||
@@ -115,7 +116,7 @@ type Config struct {
|
||||
GroupCacheConfig *shared.GroupCacheConfig
|
||||
}
|
||||
|
||||
func NewEthBackend(db *postgres.DB, c *Config) (*Backend, error) {
|
||||
func NewEthBackend(db *sqlx.DB, c *Config) (*Backend, error) {
|
||||
gcc := c.GroupCacheConfig
|
||||
|
||||
groupName := gcc.StateDB.Name
|
||||
@@ -124,7 +125,7 @@ func NewEthBackend(db *postgres.DB, c *Config) (*Backend, error) {
|
||||
}
|
||||
|
||||
r := NewCIDRetriever(db)
|
||||
ethDB := ipfsethdb.NewDatabase(db.DB, ipfsethdb.CacheConfig{
|
||||
ethDB := ipfsethdb.NewDatabase(db, ipfsethdb.CacheConfig{
|
||||
Name: groupName,
|
||||
Size: gcc.StateDB.CacheSizeInMB * 1024 * 1024,
|
||||
ExpiryDuration: time.Minute * time.Duration(gcc.StateDB.CacheExpiryInMins),
|
||||
@@ -313,17 +314,17 @@ func (b *Backend) BlockByNumber(ctx context.Context, blockNumber rpc.BlockNumber
|
||||
}
|
||||
defer func() {
|
||||
if p := recover(); p != nil {
|
||||
ethServerShared.Rollback(tx)
|
||||
shared.Rollback(tx)
|
||||
panic(p)
|
||||
} else if err != nil {
|
||||
ethServerShared.Rollback(tx)
|
||||
shared.Rollback(tx)
|
||||
} else {
|
||||
err = tx.Commit()
|
||||
}
|
||||
}()
|
||||
|
||||
// Fetch and decode the header IPLD
|
||||
var headerIPLD ipfs.BlockModel
|
||||
var headerIPLD models.IPLDModel
|
||||
headerIPLD, err = b.Fetcher.FetchHeader(tx, headerCID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
@@ -337,7 +338,7 @@ func (b *Backend) BlockByNumber(ctx context.Context, blockNumber rpc.BlockNumber
|
||||
return nil, err
|
||||
}
|
||||
// Fetch and decode the uncle IPLDs
|
||||
var uncleIPLDs []ipfs.BlockModel
|
||||
var uncleIPLDs []models.IPLDModel
|
||||
uncleIPLDs, err = b.Fetcher.FetchUncles(tx, uncleCIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -352,7 +353,7 @@ func (b *Backend) BlockByNumber(ctx context.Context, blockNumber rpc.BlockNumber
|
||||
uncles = append(uncles, &uncle)
|
||||
}
|
||||
// Fetch and decode the transaction IPLDs
|
||||
var txIPLDs []ipfs.BlockModel
|
||||
var txIPLDs []models.IPLDModel
|
||||
txIPLDs, err = b.Fetcher.FetchTrxs(tx, txCIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -367,7 +368,7 @@ func (b *Backend) BlockByNumber(ctx context.Context, blockNumber rpc.BlockNumber
|
||||
transactions = append(transactions, &transaction)
|
||||
}
|
||||
// Fetch and decode the receipt IPLDs
|
||||
var rctIPLDs []ipfs.BlockModel
|
||||
var rctIPLDs []models.IPLDModel
|
||||
rctIPLDs, err = b.Fetcher.FetchRcts(tx, rctCIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -409,17 +410,17 @@ func (b *Backend) BlockByHash(ctx context.Context, hash common.Hash) (*types.Blo
|
||||
}
|
||||
defer func() {
|
||||
if p := recover(); p != nil {
|
||||
ethServerShared.Rollback(tx)
|
||||
shared.Rollback(tx)
|
||||
panic(p)
|
||||
} else if err != nil {
|
||||
ethServerShared.Rollback(tx)
|
||||
shared.Rollback(tx)
|
||||
} else {
|
||||
err = tx.Commit()
|
||||
}
|
||||
}()
|
||||
|
||||
// Fetch and decode the header IPLD
|
||||
var headerIPLD ipfs.BlockModel
|
||||
var headerIPLD models.IPLDModel
|
||||
headerIPLD, err = b.Fetcher.FetchHeader(tx, headerCID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
@@ -433,7 +434,7 @@ func (b *Backend) BlockByHash(ctx context.Context, hash common.Hash) (*types.Blo
|
||||
return nil, err
|
||||
}
|
||||
// Fetch and decode the uncle IPLDs
|
||||
var uncleIPLDs []ipfs.BlockModel
|
||||
var uncleIPLDs []models.IPLDModel
|
||||
uncleIPLDs, err = b.Fetcher.FetchUncles(tx, uncleCIDs)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
@@ -451,7 +452,7 @@ func (b *Backend) BlockByHash(ctx context.Context, hash common.Hash) (*types.Blo
|
||||
uncles = append(uncles, &uncle)
|
||||
}
|
||||
// Fetch and decode the transaction IPLDs
|
||||
var txIPLDs []ipfs.BlockModel
|
||||
var txIPLDs []models.IPLDModel
|
||||
txIPLDs, err = b.Fetcher.FetchTrxs(tx, txCIDs)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
@@ -469,7 +470,7 @@ func (b *Backend) BlockByHash(ctx context.Context, hash common.Hash) (*types.Blo
|
||||
transactions = append(transactions, &transaction)
|
||||
}
|
||||
// Fetch and decode the receipt IPLDs
|
||||
var rctIPLDs []ipfs.BlockModel
|
||||
var rctIPLDs []models.IPLDModel
|
||||
rctIPLDs, err = b.Fetcher.FetchRcts(tx, rctCIDs)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
@@ -735,10 +736,10 @@ func (b *Backend) GetCodeByHash(ctx context.Context, address common.Address, has
|
||||
}
|
||||
defer func() {
|
||||
if p := recover(); p != nil {
|
||||
ethServerShared.Rollback(tx)
|
||||
shared.Rollback(tx)
|
||||
panic(p)
|
||||
} else if err != nil {
|
||||
ethServerShared.Rollback(tx)
|
||||
shared.Rollback(tx)
|
||||
} else {
|
||||
err = tx.Commit()
|
||||
}
|
||||
|
||||
+88
-88
@@ -23,12 +23,11 @@ import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/models"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/postgres"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/lib/pq"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/shared"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/shared"
|
||||
)
|
||||
|
||||
// Retriever interface for substituting mocks in tests
|
||||
@@ -40,11 +39,11 @@ type Retriever interface {
|
||||
|
||||
// CIDRetriever satisfies the CIDRetriever interface for ethereum
|
||||
type CIDRetriever struct {
|
||||
db *postgres.DB
|
||||
db *sqlx.DB
|
||||
}
|
||||
|
||||
// NewCIDRetriever returns a pointer to a new CIDRetriever which supports the CIDRetriever interface
|
||||
func NewCIDRetriever(db *postgres.DB) *CIDRetriever {
|
||||
func NewCIDRetriever(db *sqlx.DB) *CIDRetriever {
|
||||
return &CIDRetriever{
|
||||
db: db,
|
||||
}
|
||||
@@ -102,7 +101,7 @@ func (ecr *CIDRetriever) Retrieve(filter SubscriptionSettings, blockNumber int64
|
||||
if filter.HeaderFilter.Uncles {
|
||||
// Retrieve uncle cids for this header id
|
||||
var uncleCIDs []models.UncleModel
|
||||
uncleCIDs, err = ecr.RetrieveUncleCIDsByHeaderID(tx, header.ID)
|
||||
uncleCIDs, err = ecr.RetrieveUncleCIDsByHeaderID(tx, header.BlockHash)
|
||||
if err != nil {
|
||||
log.Error("uncle cid retrieval error")
|
||||
return nil, true, err
|
||||
@@ -112,7 +111,7 @@ func (ecr *CIDRetriever) Retrieve(filter SubscriptionSettings, blockNumber int64
|
||||
}
|
||||
// Retrieve cached trx CIDs
|
||||
if !filter.TxFilter.Off {
|
||||
cw.Transactions, err = ecr.RetrieveTxCIDs(tx, filter.TxFilter, header.ID)
|
||||
cw.Transactions, err = ecr.RetrieveTxCIDs(tx, filter.TxFilter, header.BlockHash)
|
||||
if err != nil {
|
||||
log.Error("transaction cid retrieval error")
|
||||
return nil, true, err
|
||||
@@ -121,13 +120,13 @@ func (ecr *CIDRetriever) Retrieve(filter SubscriptionSettings, blockNumber int64
|
||||
empty = false
|
||||
}
|
||||
}
|
||||
trxIds := make([]int64, len(cw.Transactions))
|
||||
for j, tx := range cw.Transactions {
|
||||
trxIds[j] = tx.ID
|
||||
trxHashes := make([]string, len(cw.Transactions))
|
||||
for j, t := range cw.Transactions {
|
||||
trxHashes[j] = t.TxHash
|
||||
}
|
||||
// Retrieve cached receipt CIDs
|
||||
if !filter.ReceiptFilter.Off {
|
||||
cw.Receipts, err = ecr.RetrieveRctCIDsByHeaderID(tx, filter.ReceiptFilter, header.ID, trxIds)
|
||||
cw.Receipts, err = ecr.RetrieveRctCIDsByHeaderID(tx, filter.ReceiptFilter, header.BlockHash, trxHashes)
|
||||
if err != nil {
|
||||
log.Error("receipt cid retrieval error")
|
||||
return nil, true, err
|
||||
@@ -138,7 +137,7 @@ func (ecr *CIDRetriever) Retrieve(filter SubscriptionSettings, blockNumber int64
|
||||
}
|
||||
// Retrieve cached state CIDs
|
||||
if !filter.StateFilter.Off {
|
||||
cw.StateNodes, err = ecr.RetrieveStateCIDs(tx, filter.StateFilter, header.ID)
|
||||
cw.StateNodes, err = ecr.RetrieveStateCIDs(tx, filter.StateFilter, header.BlockHash)
|
||||
if err != nil {
|
||||
log.Error("state cid retrieval error")
|
||||
return nil, true, err
|
||||
@@ -149,7 +148,7 @@ func (ecr *CIDRetriever) Retrieve(filter SubscriptionSettings, blockNumber int64
|
||||
}
|
||||
// Retrieve cached storage CIDs
|
||||
if !filter.StorageFilter.Off {
|
||||
cw.StorageNodes, err = ecr.RetrieveStorageCIDs(tx, filter.StorageFilter, header.ID)
|
||||
cw.StorageNodes, err = ecr.RetrieveStorageCIDs(tx, filter.StorageFilter, header.BlockHash)
|
||||
if err != nil {
|
||||
log.Error("storage cid retrieval error")
|
||||
return nil, true, err
|
||||
@@ -168,32 +167,33 @@ func (ecr *CIDRetriever) Retrieve(filter SubscriptionSettings, blockNumber int64
|
||||
func (ecr *CIDRetriever) RetrieveHeaderCIDs(tx *sqlx.Tx, blockNumber int64) ([]models.HeaderModel, error) {
|
||||
log.Debug("retrieving header cids for block ", blockNumber)
|
||||
headers := make([]models.HeaderModel, 0)
|
||||
pgStr := `SELECT * FROM eth.header_cids
|
||||
pgStr := `SELECT CAST(block_number as Text), block_hash,parent_hash,cid,mh_key,CAST(td as Text),node_id,
|
||||
CAST(reward as Text), state_root,uncle_root,tx_root,receipt_root,bloom,timestamp,times_validated,
|
||||
coinbase FROM eth.header_cids
|
||||
WHERE block_number = $1`
|
||||
return headers, tx.Select(&headers, pgStr, blockNumber)
|
||||
}
|
||||
|
||||
// RetrieveUncleCIDsByHeaderID retrieves and returns all of the uncle cids for the provided header
|
||||
func (ecr *CIDRetriever) RetrieveUncleCIDsByHeaderID(tx *sqlx.Tx, headerID int64) ([]models.UncleModel, error) {
|
||||
func (ecr *CIDRetriever) RetrieveUncleCIDsByHeaderID(tx *sqlx.Tx, headerID string) ([]models.UncleModel, error) {
|
||||
log.Debug("retrieving uncle cids for block id ", headerID)
|
||||
headers := make([]models.UncleModel, 0)
|
||||
pgStr := `SELECT * FROM eth.uncle_cids
|
||||
pgStr := `SELECT header_id,block_hash,parent_hash,cid,mh_key, CAST(reward as text) FROM eth.uncle_cids
|
||||
WHERE header_id = $1`
|
||||
return headers, tx.Select(&headers, pgStr, headerID)
|
||||
}
|
||||
|
||||
// RetrieveTxCIDs retrieves and returns all of the trx cids at the provided blockheight that conform to the provided filter parameters
|
||||
// also returns the ids for the returned transaction cids
|
||||
func (ecr *CIDRetriever) RetrieveTxCIDs(tx *sqlx.Tx, txFilter TxFilter, headerID int64) ([]models.TxModel, error) {
|
||||
func (ecr *CIDRetriever) RetrieveTxCIDs(tx *sqlx.Tx, txFilter TxFilter, headerID string) ([]models.TxModel, error) {
|
||||
log.Debug("retrieving transaction cids for header id ", headerID)
|
||||
args := make([]interface{}, 0, 3)
|
||||
results := make([]models.TxModel, 0)
|
||||
id := 1
|
||||
pgStr := fmt.Sprintf(`SELECT transaction_cids.id, transaction_cids.header_id,
|
||||
transaction_cids.tx_hash, transaction_cids.cid, transaction_cids.mh_key,
|
||||
transaction_cids.dst, transaction_cids.src, transaction_cids.index, transaction_cids.tx_data
|
||||
FROM eth.transaction_cids INNER JOIN eth.header_cids ON (transaction_cids.header_id = header_cids.id)
|
||||
WHERE header_cids.id = $%d`, id)
|
||||
pgStr := fmt.Sprintf(`SELECT transaction_cids.tx_hash, transaction_cids.header_id,transaction_cids.cid, transaction_cids.mh_key,
|
||||
transaction_cids.dst, transaction_cids.src, transaction_cids.index, transaction_cids.tx_data
|
||||
FROM eth.transaction_cids INNER JOIN eth.header_cids ON (transaction_cids.header_id = header_cids.block_hash)
|
||||
WHERE header_cids.block_hash = $%d`, id)
|
||||
args = append(args, headerID)
|
||||
id++
|
||||
if len(txFilter.Dst) > 0 {
|
||||
@@ -242,9 +242,9 @@ func logFilterCondition(id *int, pgStr string, args []interface{}, rctFilter Rec
|
||||
return pgStr, args
|
||||
}
|
||||
|
||||
func receiptFilterConditions(id *int, pgStr string, args []interface{}, rctFilter ReceiptFilter, trxIds []int64) (string, []interface{}) {
|
||||
rctCond := " AND (receipt_cids.id = ANY ( "
|
||||
logQuery := "SELECT receipt_id FROM eth.log_cids WHERE"
|
||||
func receiptFilterConditions(id *int, pgStr string, args []interface{}, rctFilter ReceiptFilter, txHashes []string) (string, []interface{}) {
|
||||
rctCond := " AND (receipt_cids.tx_id = ANY ( "
|
||||
logQuery := "SELECT rct_id FROM eth.log_cids WHERE"
|
||||
if len(rctFilter.LogAddresses) > 0 {
|
||||
// Filter on log contract addresses if there are any
|
||||
pgStr += fmt.Sprintf(`%s %s eth.log_cids.address = ANY ($%d)`, rctCond, logQuery, *id)
|
||||
@@ -258,10 +258,10 @@ func receiptFilterConditions(id *int, pgStr string, args []interface{}, rctFilte
|
||||
|
||||
pgStr += ")"
|
||||
|
||||
// Filter on txIDs if there are any and we are matching txs
|
||||
if rctFilter.MatchTxs && len(trxIds) > 0 {
|
||||
pgStr += fmt.Sprintf(` OR receipt_cids.tx_id = ANY($%d::INTEGER[])`, *id)
|
||||
args = append(args, pq.Array(trxIds))
|
||||
// Filter on txHashes if there are any, and we are matching txs
|
||||
if rctFilter.MatchTxs && len(txHashes) > 0 {
|
||||
pgStr += fmt.Sprintf(` OR receipt_cids.tx_id = ANY($%d)`, *id)
|
||||
args = append(args, pq.Array(txHashes))
|
||||
}
|
||||
pgStr += ")"
|
||||
} else { // If there are no contract addresses to filter on
|
||||
@@ -270,17 +270,17 @@ func receiptFilterConditions(id *int, pgStr string, args []interface{}, rctFilte
|
||||
pgStr += rctCond + logQuery
|
||||
pgStr, args = topicFilterCondition(id, rctFilter.Topics, args, pgStr, true)
|
||||
pgStr += ")"
|
||||
// Filter on txIDs if there are any and we are matching txs
|
||||
if rctFilter.MatchTxs && len(trxIds) > 0 {
|
||||
pgStr += fmt.Sprintf(` OR receipt_cids.tx_id = ANY($%d::INTEGER[])`, *id)
|
||||
args = append(args, pq.Array(trxIds))
|
||||
// Filter on txHashes if there are any, and we are matching txs
|
||||
if rctFilter.MatchTxs && len(txHashes) > 0 {
|
||||
pgStr += fmt.Sprintf(` OR receipt_cids.tx_id = ANY($%d)`, *id)
|
||||
args = append(args, pq.Array(txHashes))
|
||||
}
|
||||
pgStr += ")"
|
||||
} else if rctFilter.MatchTxs && len(trxIds) > 0 {
|
||||
} else if rctFilter.MatchTxs && len(txHashes) > 0 {
|
||||
// If there are no contract addresses or topics to filter on,
|
||||
// Filter on txIDs if there are any and we are matching txs
|
||||
pgStr += fmt.Sprintf(` AND receipt_cids.tx_id = ANY($%d::INTEGER[])`, *id)
|
||||
args = append(args, pq.Array(trxIds))
|
||||
// Filter on txHashes if there are any, and we are matching txs
|
||||
pgStr += fmt.Sprintf(` AND receipt_cids.tx_id = ANY($%d)`, *id)
|
||||
args = append(args, pq.Array(txHashes))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,19 +289,19 @@ func receiptFilterConditions(id *int, pgStr string, args []interface{}, rctFilte
|
||||
|
||||
// RetrieveRctCIDsByHeaderID retrieves and returns all of the rct cids at the provided header ID that conform to the provided
|
||||
// filter parameters and correspond to the provided tx ids
|
||||
func (ecr *CIDRetriever) RetrieveRctCIDsByHeaderID(tx *sqlx.Tx, rctFilter ReceiptFilter, headerID int64, trxIds []int64) ([]models.ReceiptModel, error) {
|
||||
func (ecr *CIDRetriever) RetrieveRctCIDsByHeaderID(tx *sqlx.Tx, rctFilter ReceiptFilter, headerID string, trxHashes []string) ([]models.ReceiptModel, error) {
|
||||
log.Debug("retrieving receipt cids for header id ", headerID)
|
||||
args := make([]interface{}, 0, 4)
|
||||
pgStr := `SELECT receipt_cids.id, receipt_cids.tx_id, receipt_cids.leaf_cid, receipt_cids.leaf_mh_key,
|
||||
pgStr := `SELECT receipt_cids.tx_id, receipt_cids.leaf_cid, receipt_cids.leaf_mh_key,
|
||||
receipt_cids.contract, receipt_cids.contract_hash
|
||||
FROM eth.receipt_cids, eth.transaction_cids, eth.header_cids
|
||||
WHERE receipt_cids.tx_id = transaction_cids.id
|
||||
AND transaction_cids.header_id = header_cids.id
|
||||
AND header_cids.id = $1`
|
||||
WHERE receipt_cids.tx_id = transaction_cids.tx_hash
|
||||
AND transaction_cids.header_id = header_cids.block_hash
|
||||
AND header_cids.block_hash = $1`
|
||||
id := 2
|
||||
args = append(args, headerID)
|
||||
|
||||
pgStr, args = receiptFilterConditions(&id, pgStr, args, rctFilter, trxIds)
|
||||
pgStr, args = receiptFilterConditions(&id, pgStr, args, rctFilter, trxHashes)
|
||||
|
||||
pgStr += ` ORDER BY transaction_cids.index`
|
||||
receiptCids := make([]models.ReceiptModel, 0)
|
||||
@@ -314,13 +314,13 @@ func (ecr *CIDRetriever) RetrieveFilteredGQLLogs(tx *sqlx.Tx, rctFilter ReceiptF
|
||||
log.Debug("retrieving log cids for receipt ids")
|
||||
args := make([]interface{}, 0, 4)
|
||||
id := 1
|
||||
pgStr := `SELECT eth.log_cids.leaf_cid, eth.log_cids.index, eth.log_cids.receipt_id,
|
||||
eth.log_cids.address, eth.log_cids.topic0, eth.log_cids.topic1, eth.log_cids.topic2, eth.log_cids.topic3,
|
||||
pgStr := `SELECT eth.log_cids.leaf_cid, eth.log_cids.index, eth.log_cids.rct_id,
|
||||
eth.log_cids.address, eth.log_cids.topic0, eth.log_cids.topic1, eth.log_cids.topic2, eth.log_cids.topic3,
|
||||
eth.log_cids.log_data, eth.transaction_cids.tx_hash, data, eth.receipt_cids.leaf_cid as cid, eth.receipt_cids.post_status
|
||||
FROM eth.log_cids, eth.receipt_cids, eth.transaction_cids, eth.header_cids, public.blocks
|
||||
WHERE eth.log_cids.receipt_id = receipt_cids.id
|
||||
AND receipt_cids.tx_id = transaction_cids.id
|
||||
AND transaction_cids.header_id = header_cids.id
|
||||
WHERE eth.log_cids.rct_id = receipt_cids.tx_id
|
||||
AND receipt_cids.tx_id = transaction_cids.tx_hash
|
||||
AND transaction_cids.header_id = header_cids.block_hash
|
||||
AND log_cids.leaf_mh_key = blocks.key AND header_cids.block_hash = $1`
|
||||
|
||||
args = append(args, blockHash.String())
|
||||
@@ -343,14 +343,14 @@ func (ecr *CIDRetriever) RetrieveFilteredGQLLogs(tx *sqlx.Tx, rctFilter ReceiptF
|
||||
func (ecr *CIDRetriever) RetrieveFilteredLog(tx *sqlx.Tx, rctFilter ReceiptFilter, blockNumber int64, blockHash *common.Hash) ([]LogResult, error) {
|
||||
log.Debug("retrieving log cids for receipt ids")
|
||||
args := make([]interface{}, 0, 4)
|
||||
pgStr := `SELECT eth.log_cids.leaf_cid, eth.log_cids.index, eth.log_cids.receipt_id,
|
||||
eth.log_cids.address, eth.log_cids.topic0, eth.log_cids.topic1, eth.log_cids.topic2, eth.log_cids.topic3,
|
||||
eth.log_cids.log_data, eth.transaction_cids.tx_hash, eth.transaction_cids.index as txn_index,
|
||||
header_cids.block_hash, header_cids.block_number
|
||||
FROM eth.log_cids, eth.receipt_cids, eth.transaction_cids, eth.header_cids
|
||||
WHERE eth.log_cids.receipt_id = receipt_cids.id
|
||||
AND receipt_cids.tx_id = transaction_cids.id
|
||||
AND transaction_cids.header_id = header_cids.id`
|
||||
pgStr := `SELECT eth.log_cids.leaf_cid, eth.log_cids.index, eth.log_cids.rct_id,
|
||||
eth.log_cids.address, eth.log_cids.topic0, eth.log_cids.topic1, eth.log_cids.topic2, eth.log_cids.topic3,
|
||||
eth.log_cids.log_data, eth.transaction_cids.tx_hash, eth.transaction_cids.index as txn_index,
|
||||
header_cids.block_hash, CAST(header_cids.block_number as Text)
|
||||
FROM eth.log_cids, eth.receipt_cids, eth.transaction_cids, eth.header_cids
|
||||
WHERE eth.log_cids.rct_id = receipt_cids.tx_id
|
||||
AND receipt_cids.tx_id = transaction_cids.tx_hash
|
||||
AND transaction_cids.header_id = header_cids.block_hash`
|
||||
id := 1
|
||||
if blockNumber > 0 {
|
||||
pgStr += fmt.Sprintf(` AND header_cids.block_number = $%d`, id)
|
||||
@@ -377,13 +377,13 @@ func (ecr *CIDRetriever) RetrieveFilteredLog(tx *sqlx.Tx, rctFilter ReceiptFilte
|
||||
|
||||
// RetrieveRctCIDs retrieves and returns all of the rct cids at the provided blockheight or block hash that conform to the provided
|
||||
// filter parameters and correspond to the provided tx ids
|
||||
func (ecr *CIDRetriever) RetrieveRctCIDs(tx *sqlx.Tx, rctFilter ReceiptFilter, blockNumber int64, blockHash *common.Hash, trxIds []int64) ([]models.ReceiptModel, error) {
|
||||
func (ecr *CIDRetriever) RetrieveRctCIDs(tx *sqlx.Tx, rctFilter ReceiptFilter, blockNumber int64, blockHash *common.Hash, txHashes []string) ([]models.ReceiptModel, error) {
|
||||
log.Debug("retrieving receipt cids for block ", blockNumber)
|
||||
args := make([]interface{}, 0, 5)
|
||||
pgStr := `SELECT receipt_cids.id, receipt_cids.leaf_cid, receipt_cids.leaf_mh_key, receipt_cids.tx_id
|
||||
pgStr := `SELECT receipt_cids.tx_id, receipt_cids.leaf_cid, receipt_cids.leaf_mh_key, receipt_cids.tx_id
|
||||
FROM eth.receipt_cids, eth.transaction_cids, eth.header_cids
|
||||
WHERE receipt_cids.tx_id = transaction_cids.id
|
||||
AND transaction_cids.header_id = header_cids.id`
|
||||
WHERE receipt_cids.tx_id = transaction_cids.tx_hash
|
||||
AND transaction_cids.header_id = header_cids.block_hash`
|
||||
id := 1
|
||||
if blockNumber > 0 {
|
||||
pgStr += fmt.Sprintf(` AND header_cids.block_number = $%d`, id)
|
||||
@@ -396,7 +396,7 @@ func (ecr *CIDRetriever) RetrieveRctCIDs(tx *sqlx.Tx, rctFilter ReceiptFilter, b
|
||||
id++
|
||||
}
|
||||
|
||||
pgStr, args = receiptFilterConditions(&id, pgStr, args, rctFilter, trxIds)
|
||||
pgStr, args = receiptFilterConditions(&id, pgStr, args, rctFilter, txHashes)
|
||||
|
||||
pgStr += ` ORDER BY transaction_cids.index`
|
||||
receiptCids := make([]models.ReceiptModel, 0)
|
||||
@@ -413,13 +413,13 @@ func hasTopics(topics [][]string) bool {
|
||||
}
|
||||
|
||||
// RetrieveStateCIDs retrieves and returns all of the state node cids at the provided header ID that conform to the provided filter parameters
|
||||
func (ecr *CIDRetriever) RetrieveStateCIDs(tx *sqlx.Tx, stateFilter StateFilter, headerID int64) ([]models.StateNodeModel, error) {
|
||||
func (ecr *CIDRetriever) RetrieveStateCIDs(tx *sqlx.Tx, stateFilter StateFilter, headerID string) ([]models.StateNodeModel, error) {
|
||||
log.Debug("retrieving state cids for header id ", headerID)
|
||||
args := make([]interface{}, 0, 2)
|
||||
pgStr := `SELECT state_cids.id, state_cids.header_id,
|
||||
pgStr := `SELECT state_cids.header_id,
|
||||
state_cids.state_leaf_key, state_cids.node_type, state_cids.cid, state_cids.mh_key, state_cids.state_path
|
||||
FROM eth.state_cids INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.id)
|
||||
WHERE header_cids.id = $1`
|
||||
FROM eth.state_cids INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.block_hash)
|
||||
WHERE header_cids.block_hash = $1`
|
||||
args = append(args, headerID)
|
||||
addrLen := len(stateFilter.Addresses)
|
||||
if addrLen > 0 {
|
||||
@@ -438,15 +438,15 @@ func (ecr *CIDRetriever) RetrieveStateCIDs(tx *sqlx.Tx, stateFilter StateFilter,
|
||||
}
|
||||
|
||||
// RetrieveStorageCIDs retrieves and returns all of the storage node cids at the provided header id that conform to the provided filter parameters
|
||||
func (ecr *CIDRetriever) RetrieveStorageCIDs(tx *sqlx.Tx, storageFilter StorageFilter, headerID int64) ([]models.StorageNodeWithStateKeyModel, error) {
|
||||
func (ecr *CIDRetriever) RetrieveStorageCIDs(tx *sqlx.Tx, storageFilter StorageFilter, headerID string) ([]models.StorageNodeWithStateKeyModel, error) {
|
||||
log.Debug("retrieving storage cids for header id ", headerID)
|
||||
args := make([]interface{}, 0, 3)
|
||||
pgStr := `SELECT storage_cids.id, storage_cids.state_id, storage_cids.storage_leaf_key, storage_cids.node_type,
|
||||
storage_cids.cid, storage_cids.mh_key, storage_cids.storage_path, state_cids.state_leaf_key
|
||||
pgStr := `SELECT storage_cids.header_id, storage_cids.storage_leaf_key, storage_cids.node_type,
|
||||
storage_cids.cid, storage_cids.mh_key, storage_cids.storage_path, storage_cids.state_path, state_cids.state_leaf_key
|
||||
FROM eth.storage_cids, eth.state_cids, eth.header_cids
|
||||
WHERE storage_cids.state_id = state_cids.id
|
||||
AND state_cids.header_id = header_cids.id
|
||||
AND header_cids.id = $1`
|
||||
WHERE storage_cids.header_id = state_cids.header_id AND storage_cids.state_path = state_cids.state_path
|
||||
AND state_cids.header_id = header_cids.block_hash
|
||||
AND header_cids.block_hash = $1`
|
||||
args = append(args, headerID)
|
||||
id := 2
|
||||
addrLen := len(storageFilter.Addresses)
|
||||
@@ -497,23 +497,23 @@ func (ecr *CIDRetriever) RetrieveBlockByHash(blockHash common.Hash) (models.Head
|
||||
return models.HeaderModel{}, nil, nil, nil, err
|
||||
}
|
||||
var uncleCIDs []models.UncleModel
|
||||
uncleCIDs, err = ecr.RetrieveUncleCIDsByHeaderID(tx, headerCID.ID)
|
||||
uncleCIDs, err = ecr.RetrieveUncleCIDsByHeaderID(tx, headerCID.BlockHash)
|
||||
if err != nil {
|
||||
log.Error("uncle cid retrieval error")
|
||||
return models.HeaderModel{}, nil, nil, nil, err
|
||||
}
|
||||
var txCIDs []models.TxModel
|
||||
txCIDs, err = ecr.RetrieveTxCIDsByHeaderID(tx, headerCID.ID)
|
||||
txCIDs, err = ecr.RetrieveTxCIDsByHeaderID(tx, headerCID.BlockHash)
|
||||
if err != nil {
|
||||
log.Error("tx cid retrieval error")
|
||||
return models.HeaderModel{}, nil, nil, nil, err
|
||||
}
|
||||
txIDs := make([]int64, len(txCIDs))
|
||||
txHashes := make([]string, len(txCIDs))
|
||||
for i, txCID := range txCIDs {
|
||||
txIDs[i] = txCID.ID
|
||||
txHashes[i] = txCID.TxHash
|
||||
}
|
||||
var rctCIDs []models.ReceiptModel
|
||||
rctCIDs, err = ecr.RetrieveReceiptCIDsByTxIDs(tx, txIDs)
|
||||
rctCIDs, err = ecr.RetrieveReceiptCIDsByTxIDs(tx, txHashes)
|
||||
if err != nil {
|
||||
log.Error("rct cid retrieval error")
|
||||
}
|
||||
@@ -550,23 +550,23 @@ func (ecr *CIDRetriever) RetrieveBlockByNumber(blockNumber int64) (models.Header
|
||||
return models.HeaderModel{}, nil, nil, nil, fmt.Errorf("header cid retrieval error, no header CIDs found at block %d", blockNumber)
|
||||
}
|
||||
var uncleCIDs []models.UncleModel
|
||||
uncleCIDs, err = ecr.RetrieveUncleCIDsByHeaderID(tx, headerCID[0].ID)
|
||||
uncleCIDs, err = ecr.RetrieveUncleCIDsByHeaderID(tx, headerCID[0].BlockHash)
|
||||
if err != nil {
|
||||
log.Error("uncle cid retrieval error")
|
||||
return models.HeaderModel{}, nil, nil, nil, err
|
||||
}
|
||||
var txCIDs []models.TxModel
|
||||
txCIDs, err = ecr.RetrieveTxCIDsByHeaderID(tx, headerCID[0].ID)
|
||||
txCIDs, err = ecr.RetrieveTxCIDsByHeaderID(tx, headerCID[0].BlockHash)
|
||||
if err != nil {
|
||||
log.Error("tx cid retrieval error")
|
||||
return models.HeaderModel{}, nil, nil, nil, err
|
||||
}
|
||||
txIDs := make([]int64, len(txCIDs))
|
||||
txHashes := make([]string, len(txCIDs))
|
||||
for i, txCID := range txCIDs {
|
||||
txIDs[i] = txCID.ID
|
||||
txHashes[i] = txCID.TxHash
|
||||
}
|
||||
var rctCIDs []models.ReceiptModel
|
||||
rctCIDs, err = ecr.RetrieveReceiptCIDsByTxIDs(tx, txIDs)
|
||||
rctCIDs, err = ecr.RetrieveReceiptCIDsByTxIDs(tx, txHashes)
|
||||
if err != nil {
|
||||
log.Error("rct cid retrieval error")
|
||||
}
|
||||
@@ -576,14 +576,14 @@ func (ecr *CIDRetriever) RetrieveBlockByNumber(blockNumber int64) (models.Header
|
||||
// RetrieveHeaderCIDByHash returns the header for the given block hash
|
||||
func (ecr *CIDRetriever) RetrieveHeaderCIDByHash(tx *sqlx.Tx, blockHash common.Hash) (models.HeaderModel, error) {
|
||||
log.Debug("retrieving header cids for block hash ", blockHash.String())
|
||||
pgStr := `SELECT * FROM eth.header_cids
|
||||
pgStr := `SELECT block_hash,cid,mh_key FROM eth.header_cids
|
||||
WHERE block_hash = $1`
|
||||
var headerCID models.HeaderModel
|
||||
return headerCID, tx.Get(&headerCID, pgStr, blockHash.String())
|
||||
}
|
||||
|
||||
// RetrieveTxCIDsByHeaderID retrieves all tx CIDs for the given header id
|
||||
func (ecr *CIDRetriever) RetrieveTxCIDsByHeaderID(tx *sqlx.Tx, headerID int64) ([]models.TxModel, error) {
|
||||
func (ecr *CIDRetriever) RetrieveTxCIDsByHeaderID(tx *sqlx.Tx, headerID string) ([]models.TxModel, error) {
|
||||
log.Debug("retrieving tx cids for block id ", headerID)
|
||||
pgStr := `SELECT * FROM eth.transaction_cids
|
||||
WHERE header_id = $1
|
||||
@@ -593,14 +593,14 @@ func (ecr *CIDRetriever) RetrieveTxCIDsByHeaderID(tx *sqlx.Tx, headerID int64) (
|
||||
}
|
||||
|
||||
// RetrieveReceiptCIDsByTxIDs retrieves receipt CIDs by their associated tx IDs
|
||||
func (ecr *CIDRetriever) RetrieveReceiptCIDsByTxIDs(tx *sqlx.Tx, txIDs []int64) ([]models.ReceiptModel, error) {
|
||||
log.Debugf("retrieving receipt cids for tx ids %v", txIDs)
|
||||
pgStr := `SELECT receipt_cids.id, receipt_cids.tx_id, receipt_cids.leaf_cid, receipt_cids.leaf_mh_key,
|
||||
func (ecr *CIDRetriever) RetrieveReceiptCIDsByTxIDs(tx *sqlx.Tx, txHashes []string) ([]models.ReceiptModel, error) {
|
||||
log.Debugf("retrieving receipt cids for tx hashes %v", txHashes)
|
||||
pgStr := `SELECT receipt_cids.tx_id, receipt_cids.leaf_cid, receipt_cids.leaf_mh_key,
|
||||
receipt_cids.contract, receipt_cids.contract_hash
|
||||
FROM eth.receipt_cids, eth.transaction_cids
|
||||
WHERE tx_id = ANY($1::INTEGER[])
|
||||
AND receipt_cids.tx_id = transaction_cids.id
|
||||
WHERE tx_id = ANY($1)
|
||||
AND receipt_cids.tx_id = transaction_cids.tx_hash
|
||||
ORDER BY transaction_cids.index`
|
||||
var rctCIDs []models.ReceiptModel
|
||||
return rctCIDs, tx.Select(&rctCIDs, pgStr, pq.Array(txIDs))
|
||||
return rctCIDs, tx.Select(&rctCIDs, pgStr, pq.Array(txHashes))
|
||||
}
|
||||
|
||||
@@ -19,19 +19,19 @@ package eth_test
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/models"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/postgres"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/models"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
"github.com/jmoiron/sqlx"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth/test_helpers"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth/test_helpers"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/shared"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -211,21 +211,18 @@ var (
|
||||
|
||||
var _ = Describe("Retriever", func() {
|
||||
var (
|
||||
db *postgres.DB
|
||||
diffIndexer *indexer.StateDiffIndexer
|
||||
db *sqlx.DB
|
||||
diffIndexer interfaces.StateDiffIndexer
|
||||
retriever *eth.CIDRetriever
|
||||
)
|
||||
BeforeEach(func() {
|
||||
var err error
|
||||
db, err = SetupDB()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
diffIndexer, err = indexer.NewStateDiffIndexer(params.TestChainConfig, db)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
db = shared.SetupDB()
|
||||
diffIndexer = shared.SetupTestStateDiffIndexer(ctx, params.TestChainConfig, test_helpers.Genesis.Hash())
|
||||
|
||||
retriever = eth.NewCIDRetriever(db)
|
||||
})
|
||||
AfterEach(func() {
|
||||
eth.TearDownDB(db)
|
||||
shared.TearDownDB(db)
|
||||
})
|
||||
|
||||
Describe("Retrieve", func() {
|
||||
@@ -233,11 +230,11 @@ var _ = Describe("Retriever", func() {
|
||||
tx, err := diffIndexer.PushBlock(test_helpers.MockBlock, test_helpers.MockReceipts, test_helpers.MockBlock.Difficulty())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
for _, node := range test_helpers.MockStateNodes {
|
||||
err = diffIndexer.PushStateNode(tx, node)
|
||||
err = diffIndexer.PushStateNode(tx, node, test_helpers.MockBlock.Hash().String())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
||||
err = tx.Close(err)
|
||||
err = tx.Submit(err)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
It("Retrieves all CIDs for the given blocknumber when provided an open filter", func() {
|
||||
@@ -247,8 +244,8 @@ var _ = Describe("Retriever", func() {
|
||||
}
|
||||
expectedRctCIDsAndLeafNodes := make([]rctCIDAndMHKeyResult, 0)
|
||||
pgStr := `SELECT receipt_cids.leaf_cid, receipt_cids.leaf_mh_key FROM eth.receipt_cids, eth.transaction_cids, eth.header_cids
|
||||
WHERE receipt_cids.tx_id = transaction_cids.id
|
||||
AND transaction_cids.header_id = header_cids.id
|
||||
WHERE receipt_cids.tx_id = transaction_cids.tx_hash
|
||||
AND transaction_cids.header_id = header_cids.block_hash
|
||||
AND header_cids.block_number = $1
|
||||
ORDER BY transaction_cids.index`
|
||||
err := db.Select(&expectedRctCIDsAndLeafNodes, pgStr, test_helpers.BlockNumber.Uint64())
|
||||
@@ -259,7 +256,7 @@ var _ = Describe("Retriever", func() {
|
||||
Expect(cids[0].BlockNumber).To(Equal(test_helpers.MockCIDWrapper.BlockNumber))
|
||||
|
||||
expectedHeaderCID := test_helpers.MockCIDWrapper.Header
|
||||
expectedHeaderCID.ID = cids[0].Header.ID
|
||||
expectedHeaderCID.BlockHash = cids[0].Header.BlockHash
|
||||
expectedHeaderCID.NodeID = cids[0].Header.NodeID
|
||||
Expect(cids[0].Header).To(Equal(expectedHeaderCID))
|
||||
Expect(len(cids[0].Transactions)).To(Equal(4))
|
||||
@@ -286,8 +283,8 @@ var _ = Describe("Retriever", func() {
|
||||
}
|
||||
Expect(len(cids[0].StorageNodes)).To(Equal(1))
|
||||
expectedStorageNodeCIDs := test_helpers.MockCIDWrapper.StorageNodes
|
||||
expectedStorageNodeCIDs[0].ID = cids[0].StorageNodes[0].ID
|
||||
expectedStorageNodeCIDs[0].StateID = cids[0].StorageNodes[0].StateID
|
||||
expectedStorageNodeCIDs[0].HeaderID = cids[0].StorageNodes[0].HeaderID
|
||||
expectedStorageNodeCIDs[0].StatePath = cids[0].StorageNodes[0].StatePath
|
||||
Expect(cids[0].StorageNodes).To(Equal(expectedStorageNodeCIDs))
|
||||
})
|
||||
|
||||
@@ -298,8 +295,8 @@ var _ = Describe("Retriever", func() {
|
||||
}
|
||||
expectedRctCIDsAndLeafNodes := make([]rctCIDAndMHKeyResult, 0)
|
||||
pgStr := `SELECT receipt_cids.leaf_cid, receipt_cids.leaf_mh_key FROM eth.receipt_cids, eth.transaction_cids, eth.header_cids
|
||||
WHERE receipt_cids.tx_id = transaction_cids.id
|
||||
AND transaction_cids.header_id = header_cids.id
|
||||
WHERE receipt_cids.tx_id = transaction_cids.tx_hash
|
||||
AND transaction_cids.header_id = header_cids.block_hash
|
||||
AND header_cids.block_number = $1
|
||||
ORDER BY transaction_cids.index`
|
||||
err := db.Select(&expectedRctCIDsAndLeafNodes, pgStr, test_helpers.BlockNumber.Uint64())
|
||||
@@ -314,7 +311,6 @@ var _ = Describe("Retriever", func() {
|
||||
Expect(len(cids1[0].StorageNodes)).To(Equal(0))
|
||||
Expect(len(cids1[0].Receipts)).To(Equal(1))
|
||||
expectedReceiptCID := test_helpers.MockCIDWrapper.Receipts[0]
|
||||
expectedReceiptCID.ID = cids1[0].Receipts[0].ID
|
||||
expectedReceiptCID.TxID = cids1[0].Receipts[0].TxID
|
||||
expectedReceiptCID.LeafCID = expectedRctCIDsAndLeafNodes[0].LeafCID
|
||||
expectedReceiptCID.LeafMhKey = expectedRctCIDsAndLeafNodes[0].LeafMhKey
|
||||
@@ -331,7 +327,6 @@ var _ = Describe("Retriever", func() {
|
||||
Expect(len(cids2[0].StorageNodes)).To(Equal(0))
|
||||
Expect(len(cids2[0].Receipts)).To(Equal(1))
|
||||
expectedReceiptCID = test_helpers.MockCIDWrapper.Receipts[0]
|
||||
expectedReceiptCID.ID = cids2[0].Receipts[0].ID
|
||||
expectedReceiptCID.TxID = cids2[0].Receipts[0].TxID
|
||||
expectedReceiptCID.LeafCID = expectedRctCIDsAndLeafNodes[0].LeafCID
|
||||
expectedReceiptCID.LeafMhKey = expectedRctCIDsAndLeafNodes[0].LeafMhKey
|
||||
@@ -348,7 +343,6 @@ var _ = Describe("Retriever", func() {
|
||||
Expect(len(cids3[0].StorageNodes)).To(Equal(0))
|
||||
Expect(len(cids3[0].Receipts)).To(Equal(1))
|
||||
expectedReceiptCID = test_helpers.MockCIDWrapper.Receipts[0]
|
||||
expectedReceiptCID.ID = cids3[0].Receipts[0].ID
|
||||
expectedReceiptCID.TxID = cids3[0].Receipts[0].TxID
|
||||
expectedReceiptCID.LeafCID = expectedRctCIDsAndLeafNodes[0].LeafCID
|
||||
expectedReceiptCID.LeafMhKey = expectedRctCIDsAndLeafNodes[0].LeafMhKey
|
||||
@@ -365,7 +359,6 @@ var _ = Describe("Retriever", func() {
|
||||
Expect(len(cids4[0].StorageNodes)).To(Equal(0))
|
||||
Expect(len(cids4[0].Receipts)).To(Equal(1))
|
||||
expectedReceiptCID = test_helpers.MockCIDWrapper.Receipts[1]
|
||||
expectedReceiptCID.ID = cids4[0].Receipts[0].ID
|
||||
expectedReceiptCID.TxID = cids4[0].Receipts[0].TxID
|
||||
expectedReceiptCID.LeafCID = expectedRctCIDsAndLeafNodes[1].LeafCID
|
||||
expectedReceiptCID.LeafMhKey = expectedRctCIDsAndLeafNodes[1].LeafMhKey
|
||||
@@ -396,14 +389,13 @@ var _ = Describe("Retriever", func() {
|
||||
Expect(cids6[0].Header).To(Equal(models.HeaderModel{}))
|
||||
Expect(len(cids6[0].Transactions)).To(Equal(1))
|
||||
expectedTxCID := test_helpers.MockCIDWrapper.Transactions[1]
|
||||
expectedTxCID.ID = cids6[0].Transactions[0].ID
|
||||
expectedTxCID.TxHash = cids6[0].Transactions[0].TxHash
|
||||
expectedTxCID.HeaderID = cids6[0].Transactions[0].HeaderID
|
||||
Expect(cids6[0].Transactions[0]).To(Equal(expectedTxCID))
|
||||
Expect(len(cids6[0].StateNodes)).To(Equal(0))
|
||||
Expect(len(cids6[0].StorageNodes)).To(Equal(0))
|
||||
Expect(len(cids6[0].Receipts)).To(Equal(1))
|
||||
expectedReceiptCID = test_helpers.MockCIDWrapper.Receipts[1]
|
||||
expectedReceiptCID.ID = cids6[0].Receipts[0].ID
|
||||
expectedReceiptCID.TxID = cids6[0].Receipts[0].TxID
|
||||
expectedReceiptCID.LeafCID = expectedRctCIDsAndLeafNodes[1].LeafCID
|
||||
expectedReceiptCID.LeafMhKey = expectedRctCIDsAndLeafNodes[1].LeafMhKey
|
||||
@@ -420,7 +412,6 @@ var _ = Describe("Retriever", func() {
|
||||
Expect(len(cids7[0].StorageNodes)).To(Equal(0))
|
||||
Expect(len(cids7[0].StateNodes)).To(Equal(1))
|
||||
Expect(cids7[0].StateNodes[0]).To(Equal(models.StateNodeModel{
|
||||
ID: cids7[0].StateNodes[0].ID,
|
||||
HeaderID: cids7[0].StateNodes[0].HeaderID,
|
||||
NodeType: 2,
|
||||
StateKey: common.BytesToHash(test_helpers.AccountLeafKey).Hex(),
|
||||
@@ -444,7 +435,7 @@ var _ = Describe("Retriever", func() {
|
||||
tx, err := diffIndexer.PushBlock(test_helpers.MockBlock, test_helpers.MockReceipts, test_helpers.MockBlock.Difficulty())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
err = tx.Close(err)
|
||||
err = tx.Submit(err)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
num, err := retriever.RetrieveFirstBlockNumber()
|
||||
@@ -458,7 +449,7 @@ var _ = Describe("Retriever", func() {
|
||||
tx, err := diffIndexer.PushBlock(payload.Block, payload.Receipts, payload.Block.Difficulty())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
err = tx.Close(err)
|
||||
err = tx.Submit(err)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
num, err := retriever.RetrieveFirstBlockNumber()
|
||||
@@ -473,12 +464,12 @@ var _ = Describe("Retriever", func() {
|
||||
payload2.Block = newMockBlock(5)
|
||||
tx, err := diffIndexer.PushBlock(payload1.Block, payload1.Receipts, payload1.Block.Difficulty())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = tx.Close(err)
|
||||
err = tx.Submit(err)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
tx, err = diffIndexer.PushBlock(payload2.Block, payload2.Receipts, payload2.Block.Difficulty())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = tx.Close(err)
|
||||
err = tx.Submit(err)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
num, err := retriever.RetrieveFirstBlockNumber()
|
||||
@@ -495,7 +486,7 @@ var _ = Describe("Retriever", func() {
|
||||
It("Gets the number of the latest block that has data in the database", func() {
|
||||
tx, err := diffIndexer.PushBlock(test_helpers.MockBlock, test_helpers.MockReceipts, test_helpers.MockBlock.Difficulty())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = tx.Close(err)
|
||||
err = tx.Submit(err)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
num, err := retriever.RetrieveLastBlockNumber()
|
||||
@@ -509,7 +500,7 @@ var _ = Describe("Retriever", func() {
|
||||
tx, err := diffIndexer.PushBlock(payload.Block, payload.Receipts, payload.Block.Difficulty())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
err = tx.Close(err)
|
||||
err = tx.Submit(err)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
num, err := retriever.RetrieveLastBlockNumber()
|
||||
@@ -524,12 +515,12 @@ var _ = Describe("Retriever", func() {
|
||||
payload2.Block = newMockBlock(5)
|
||||
tx, err := diffIndexer.PushBlock(payload1.Block, payload1.Receipts, payload1.Block.Difficulty())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = tx.Close(err)
|
||||
err = tx.Submit(err)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
tx, err = diffIndexer.PushBlock(payload2.Block, payload2.Receipts, payload2.Block.Difficulty())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = tx.Close(err)
|
||||
err = tx.Submit(err)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
num, err := retriever.RetrieveLastBlockNumber()
|
||||
|
||||
+17
-18
@@ -21,6 +21,7 @@ import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
@@ -31,15 +32,15 @@ import (
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/statediff"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/postgres"
|
||||
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
|
||||
"github.com/jmoiron/sqlx"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth/test_helpers"
|
||||
ethServerShared "github.com/vulcanize/ipld-eth-server/pkg/shared"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth/test_helpers"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/shared"
|
||||
ethServerShared "github.com/vulcanize/ipld-eth-server/v3/pkg/shared"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -64,7 +65,7 @@ var _ = Describe("eth state reading tests", func() {
|
||||
blocks []*types.Block
|
||||
receipts []types.Receipts
|
||||
chain *core.BlockChain
|
||||
db *postgres.DB
|
||||
db *sqlx.DB
|
||||
api *eth.PublicEthAPI
|
||||
backend *eth.Backend
|
||||
chainConfig = params.TestChainConfig
|
||||
@@ -74,11 +75,8 @@ var _ = Describe("eth state reading tests", func() {
|
||||
It("test init", func() {
|
||||
// db and type initializations
|
||||
var err error
|
||||
db, err = SetupDB()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
transformer, err := indexer.NewStateDiffIndexer(chainConfig, db)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
db = shared.SetupDB()
|
||||
transformer := shared.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash())
|
||||
|
||||
backend, err = eth.NewEthBackend(db, ð.Config{
|
||||
ChainConfig: chainConfig,
|
||||
@@ -150,21 +148,20 @@ var _ = Describe("eth state reading tests", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
for _, node := range diff.Nodes {
|
||||
err = transformer.PushStateNode(tx, node)
|
||||
err = transformer.PushStateNode(tx, node, block.Hash().String())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
err = tx.Close(err)
|
||||
err = tx.Submit(err)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
||||
// Insert some non-canonical data into the database so that we test our ability to discern canonicity
|
||||
indexAndPublisher, err := indexer.NewStateDiffIndexer(chainConfig, db)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
indexAndPublisher := shared.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash())
|
||||
|
||||
tx, err := indexAndPublisher.PushBlock(test_helpers.MockBlock, test_helpers.MockReceipts, test_helpers.MockBlock.Difficulty())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
err = tx.Close(err)
|
||||
err = tx.Submit(err)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// The non-canonical header has a child
|
||||
@@ -179,11 +176,13 @@ var _ = Describe("eth state reading tests", func() {
|
||||
err = indexAndPublisher.PushCodeAndCodeHash(tx, hash)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
err = tx.Close(err)
|
||||
// wait for tx batch process to complete.
|
||||
time.Sleep(10000 * time.Millisecond)
|
||||
err = tx.Submit(err)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
defer It("test teardown", func() {
|
||||
eth.TearDownDB(db)
|
||||
shared.TearDownDB(db)
|
||||
chain.Stop()
|
||||
})
|
||||
|
||||
|
||||
+17
-18
@@ -23,12 +23,11 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/ipfs/ipld"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/ipld"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/models"
|
||||
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/multiformats/go-multihash"
|
||||
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/ipfs"
|
||||
)
|
||||
|
||||
// Filterer interface for substituing mocks in tests
|
||||
@@ -82,12 +81,12 @@ func (s *ResponseFilterer) filterHeaders(headerFilter HeaderFilter, response *IP
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
response.Header = ipfs.BlockModel{
|
||||
response.Header = models.IPLDModel{
|
||||
Data: headerRLP,
|
||||
CID: cid.String(),
|
||||
Key: cid.String(),
|
||||
}
|
||||
if headerFilter.Uncles {
|
||||
response.Uncles = make([]ipfs.BlockModel, len(payload.Block.Body().Uncles))
|
||||
response.Uncles = make([]models.IPLDModel, len(payload.Block.Body().Uncles))
|
||||
for i, uncle := range payload.Block.Body().Uncles {
|
||||
uncleRlp, err := rlp.EncodeToBytes(uncle)
|
||||
if err != nil {
|
||||
@@ -97,9 +96,9 @@ func (s *ResponseFilterer) filterHeaders(headerFilter HeaderFilter, response *IP
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
response.Uncles[i] = ipfs.BlockModel{
|
||||
response.Uncles[i] = models.IPLDModel{
|
||||
Data: uncleRlp,
|
||||
CID: cid.String(),
|
||||
Key: cid.String(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,7 +118,7 @@ func (s *ResponseFilterer) filterTransactions(trxFilter TxFilter, response *IPLD
|
||||
if !trxFilter.Off {
|
||||
trxLen := len(payload.Block.Body().Transactions)
|
||||
trxHashes = make([]common.Hash, 0, trxLen)
|
||||
response.Transactions = make([]ipfs.BlockModel, 0, trxLen)
|
||||
response.Transactions = make([]models.IPLDModel, 0, trxLen)
|
||||
for i, trx := range payload.Block.Body().Transactions {
|
||||
// TODO: check if want corresponding receipt and if we do we must include this transaction
|
||||
if checkTransactionAddrs(trxFilter.Src, trxFilter.Dst, payload.TxMetaData[i].Src, payload.TxMetaData[i].Dst) {
|
||||
@@ -132,9 +131,9 @@ func (s *ResponseFilterer) filterTransactions(trxFilter TxFilter, response *IPLD
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.Transactions = append(response.Transactions, ipfs.BlockModel{
|
||||
response.Transactions = append(response.Transactions, models.IPLDModel{
|
||||
Data: data,
|
||||
CID: cid.String(),
|
||||
Key: cid.String(),
|
||||
})
|
||||
trxHashes = append(trxHashes, trx.Hash())
|
||||
}
|
||||
@@ -164,7 +163,7 @@ func checkTransactionAddrs(wantedSrc, wantedDst []string, actualSrc, actualDst s
|
||||
|
||||
func (s *ResponseFilterer) filerReceipts(receiptFilter ReceiptFilter, response *IPLDs, payload ConvertedPayload, trxHashes []common.Hash) error {
|
||||
if !receiptFilter.Off {
|
||||
response.Receipts = make([]ipfs.BlockModel, 0, len(payload.Receipts))
|
||||
response.Receipts = make([]models.IPLDModel, 0, len(payload.Receipts))
|
||||
rctLeafCID, rctIPLDData, err := GetRctLeafNodeData(payload.Receipts)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -183,9 +182,9 @@ func (s *ResponseFilterer) filerReceipts(receiptFilter ReceiptFilter, response *
|
||||
|
||||
// TODO: Verify this filter logic.
|
||||
if checkReceipts(receipt, receiptFilter.Topics, topics, receiptFilter.LogAddresses, contracts, trxHashes) {
|
||||
response.Receipts = append(response.Receipts, ipfs.BlockModel{
|
||||
response.Receipts = append(response.Receipts, models.IPLDModel{
|
||||
Data: rctIPLDData[idx],
|
||||
CID: rctLeafCID[idx].String(),
|
||||
Key: rctLeafCID[idx].String(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -282,9 +281,9 @@ func (s *ResponseFilterer) filterStateAndStorage(stateFilter StateFilter, storag
|
||||
response.StateNodes = append(response.StateNodes, StateNode{
|
||||
StateLeafKey: common.BytesToHash(stateNode.LeafKey),
|
||||
Path: stateNode.Path,
|
||||
IPLD: ipfs.BlockModel{
|
||||
IPLD: models.IPLDModel{
|
||||
Data: stateNode.NodeValue,
|
||||
CID: cid.String(),
|
||||
Key: cid.String(),
|
||||
},
|
||||
Type: stateNode.NodeType,
|
||||
})
|
||||
@@ -300,9 +299,9 @@ func (s *ResponseFilterer) filterStateAndStorage(stateFilter StateFilter, storag
|
||||
response.StorageNodes = append(response.StorageNodes, StorageNode{
|
||||
StateLeafKey: common.BytesToHash(stateNode.LeafKey),
|
||||
StorageLeafKey: common.BytesToHash(storageNode.LeafKey),
|
||||
IPLD: ipfs.BlockModel{
|
||||
IPLD: models.IPLDModel{
|
||||
Data: storageNode.NodeValue,
|
||||
CID: cid.String(),
|
||||
Key: cid.String(),
|
||||
},
|
||||
Type: storageNode.NodeType,
|
||||
Path: storageNode.Path,
|
||||
|
||||
+29
-29
@@ -19,15 +19,15 @@ package eth_test
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/ipfs"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/models"
|
||||
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth/test_helpers"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/shared"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth/test_helpers"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/shared"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -46,7 +46,7 @@ var _ = Describe("Filterer", func() {
|
||||
Expect(iplds).ToNot(BeNil())
|
||||
Expect(iplds.BlockNumber.Int64()).To(Equal(test_helpers.MockIPLDs.BlockNumber.Int64()))
|
||||
Expect(iplds.Header).To(Equal(test_helpers.MockIPLDs.Header))
|
||||
var expectedEmptyUncles []ipfs.BlockModel
|
||||
var expectedEmptyUncles []models.IPLDModel
|
||||
Expect(iplds.Uncles).To(Equal(expectedEmptyUncles))
|
||||
Expect(len(iplds.Transactions)).To(Equal(4))
|
||||
Expect(shared.IPLDsContainBytes(iplds.Transactions, test_helpers.Tx1)).To(BeTrue())
|
||||
@@ -60,15 +60,15 @@ var _ = Describe("Filterer", func() {
|
||||
for _, stateNode := range iplds.StateNodes {
|
||||
Expect(stateNode.Type).To(Equal(sdtypes.Leaf))
|
||||
if bytes.Equal(stateNode.StateLeafKey.Bytes(), test_helpers.AccountLeafKey) {
|
||||
Expect(stateNode.IPLD).To(Equal(ipfs.BlockModel{
|
||||
Expect(stateNode.IPLD).To(Equal(models.IPLDModel{
|
||||
Data: test_helpers.State2IPLD.RawData(),
|
||||
CID: test_helpers.State2IPLD.Cid().String(),
|
||||
Key: test_helpers.State2IPLD.Cid().String(),
|
||||
}))
|
||||
}
|
||||
if bytes.Equal(stateNode.StateLeafKey.Bytes(), test_helpers.ContractLeafKey) {
|
||||
Expect(stateNode.IPLD).To(Equal(ipfs.BlockModel{
|
||||
Expect(stateNode.IPLD).To(Equal(models.IPLDModel{
|
||||
Data: test_helpers.State1IPLD.RawData(),
|
||||
CID: test_helpers.State1IPLD.Cid().String(),
|
||||
Key: test_helpers.State1IPLD.Cid().String(),
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -80,67 +80,67 @@ var _ = Describe("Filterer", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(iplds1).ToNot(BeNil())
|
||||
Expect(iplds1.BlockNumber.Int64()).To(Equal(test_helpers.MockIPLDs.BlockNumber.Int64()))
|
||||
Expect(iplds1.Header).To(Equal(ipfs.BlockModel{}))
|
||||
Expect(iplds1.Header).To(Equal(models.IPLDModel{}))
|
||||
Expect(len(iplds1.Uncles)).To(Equal(0))
|
||||
Expect(len(iplds1.Transactions)).To(Equal(0))
|
||||
Expect(len(iplds1.StorageNodes)).To(Equal(0))
|
||||
Expect(len(iplds1.StateNodes)).To(Equal(0))
|
||||
Expect(len(iplds1.Receipts)).To(Equal(1))
|
||||
Expect(iplds1.Receipts[0]).To(Equal(ipfs.BlockModel{
|
||||
Expect(iplds1.Receipts[0]).To(Equal(models.IPLDModel{
|
||||
Data: test_helpers.Rct1IPLD,
|
||||
CID: test_helpers.Rct1CID.String(),
|
||||
Key: test_helpers.Rct1CID.String(),
|
||||
}))
|
||||
|
||||
iplds2, err := filterer.Filter(rctTopicsFilter, test_helpers.MockConvertedPayload)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(iplds2).ToNot(BeNil())
|
||||
Expect(iplds2.BlockNumber.Int64()).To(Equal(test_helpers.MockIPLDs.BlockNumber.Int64()))
|
||||
Expect(iplds2.Header).To(Equal(ipfs.BlockModel{}))
|
||||
Expect(iplds2.Header).To(Equal(models.IPLDModel{}))
|
||||
Expect(len(iplds2.Uncles)).To(Equal(0))
|
||||
Expect(len(iplds2.Transactions)).To(Equal(0))
|
||||
Expect(len(iplds2.StorageNodes)).To(Equal(0))
|
||||
Expect(len(iplds2.StateNodes)).To(Equal(0))
|
||||
Expect(len(iplds2.Receipts)).To(Equal(1))
|
||||
Expect(iplds2.Receipts[0]).To(Equal(ipfs.BlockModel{
|
||||
Expect(iplds2.Receipts[0]).To(Equal(models.IPLDModel{
|
||||
Data: test_helpers.Rct1IPLD,
|
||||
CID: test_helpers.Rct1CID.String(),
|
||||
Key: test_helpers.Rct1CID.String(),
|
||||
}))
|
||||
|
||||
iplds3, err := filterer.Filter(rctTopicsAndAddressFilter, test_helpers.MockConvertedPayload)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(iplds3).ToNot(BeNil())
|
||||
Expect(iplds3.BlockNumber.Int64()).To(Equal(test_helpers.MockIPLDs.BlockNumber.Int64()))
|
||||
Expect(iplds3.Header).To(Equal(ipfs.BlockModel{}))
|
||||
Expect(iplds3.Header).To(Equal(models.IPLDModel{}))
|
||||
Expect(len(iplds3.Uncles)).To(Equal(0))
|
||||
Expect(len(iplds3.Transactions)).To(Equal(0))
|
||||
Expect(len(iplds3.StorageNodes)).To(Equal(0))
|
||||
Expect(len(iplds3.StateNodes)).To(Equal(0))
|
||||
Expect(len(iplds3.Receipts)).To(Equal(1))
|
||||
Expect(iplds3.Receipts[0]).To(Equal(ipfs.BlockModel{
|
||||
Expect(iplds3.Receipts[0]).To(Equal(models.IPLDModel{
|
||||
Data: test_helpers.Rct1IPLD,
|
||||
CID: test_helpers.Rct1CID.String(),
|
||||
Key: test_helpers.Rct1CID.String(),
|
||||
}))
|
||||
|
||||
iplds4, err := filterer.Filter(rctAddressesAndTopicFilter, test_helpers.MockConvertedPayload)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(iplds4).ToNot(BeNil())
|
||||
Expect(iplds4.BlockNumber.Int64()).To(Equal(test_helpers.MockIPLDs.BlockNumber.Int64()))
|
||||
Expect(iplds4.Header).To(Equal(ipfs.BlockModel{}))
|
||||
Expect(iplds4.Header).To(Equal(models.IPLDModel{}))
|
||||
Expect(len(iplds4.Uncles)).To(Equal(0))
|
||||
Expect(len(iplds4.Transactions)).To(Equal(0))
|
||||
Expect(len(iplds4.StorageNodes)).To(Equal(0))
|
||||
Expect(len(iplds4.StateNodes)).To(Equal(0))
|
||||
Expect(len(iplds4.Receipts)).To(Equal(1))
|
||||
Expect(iplds4.Receipts[0]).To(Equal(ipfs.BlockModel{
|
||||
Expect(iplds4.Receipts[0]).To(Equal(models.IPLDModel{
|
||||
Data: test_helpers.Rct2IPLD,
|
||||
CID: test_helpers.Rct2CID.String(),
|
||||
Key: test_helpers.Rct2CID.String(),
|
||||
}))
|
||||
|
||||
iplds5, err := filterer.Filter(rctsForAllCollectedTrxs, test_helpers.MockConvertedPayload)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(iplds5).ToNot(BeNil())
|
||||
Expect(iplds5.BlockNumber.Int64()).To(Equal(test_helpers.MockIPLDs.BlockNumber.Int64()))
|
||||
Expect(iplds5.Header).To(Equal(ipfs.BlockModel{}))
|
||||
Expect(iplds5.Header).To(Equal(models.IPLDModel{}))
|
||||
Expect(len(iplds5.Uncles)).To(Equal(0))
|
||||
Expect(len(iplds5.Transactions)).To(Equal(4))
|
||||
Expect(shared.IPLDsContainBytes(iplds5.Transactions, test_helpers.Tx1)).To(BeTrue())
|
||||
@@ -157,39 +157,39 @@ var _ = Describe("Filterer", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(iplds6).ToNot(BeNil())
|
||||
Expect(iplds6.BlockNumber.Int64()).To(Equal(test_helpers.MockIPLDs.BlockNumber.Int64()))
|
||||
Expect(iplds6.Header).To(Equal(ipfs.BlockModel{}))
|
||||
Expect(iplds6.Header).To(Equal(models.IPLDModel{}))
|
||||
Expect(len(iplds6.Uncles)).To(Equal(0))
|
||||
Expect(len(iplds6.Transactions)).To(Equal(1))
|
||||
Expect(shared.IPLDsContainBytes(iplds5.Transactions, test_helpers.Tx2)).To(BeTrue())
|
||||
Expect(len(iplds6.StorageNodes)).To(Equal(0))
|
||||
Expect(len(iplds6.StateNodes)).To(Equal(0))
|
||||
Expect(len(iplds6.Receipts)).To(Equal(1))
|
||||
Expect(iplds4.Receipts[0]).To(Equal(ipfs.BlockModel{
|
||||
Expect(iplds4.Receipts[0]).To(Equal(models.IPLDModel{
|
||||
Data: test_helpers.Rct2IPLD,
|
||||
CID: test_helpers.Rct2CID.String(),
|
||||
Key: test_helpers.Rct2CID.String(),
|
||||
}))
|
||||
|
||||
iplds7, err := filterer.Filter(stateFilter, test_helpers.MockConvertedPayload)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(iplds7).ToNot(BeNil())
|
||||
Expect(iplds7.BlockNumber.Int64()).To(Equal(test_helpers.MockIPLDs.BlockNumber.Int64()))
|
||||
Expect(iplds7.Header).To(Equal(ipfs.BlockModel{}))
|
||||
Expect(iplds7.Header).To(Equal(models.IPLDModel{}))
|
||||
Expect(len(iplds7.Uncles)).To(Equal(0))
|
||||
Expect(len(iplds7.Transactions)).To(Equal(0))
|
||||
Expect(len(iplds7.StorageNodes)).To(Equal(0))
|
||||
Expect(len(iplds7.Receipts)).To(Equal(0))
|
||||
Expect(len(iplds7.StateNodes)).To(Equal(1))
|
||||
Expect(iplds7.StateNodes[0].StateLeafKey.Bytes()).To(Equal(test_helpers.AccountLeafKey))
|
||||
Expect(iplds7.StateNodes[0].IPLD).To(Equal(ipfs.BlockModel{
|
||||
Expect(iplds7.StateNodes[0].IPLD).To(Equal(models.IPLDModel{
|
||||
Data: test_helpers.State2IPLD.RawData(),
|
||||
CID: test_helpers.State2IPLD.Cid().String(),
|
||||
Key: test_helpers.State2IPLD.Cid().String(),
|
||||
}))
|
||||
|
||||
iplds8, err := filterer.Filter(rctTopicsAndAddressFilterFail, test_helpers.MockConvertedPayload)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(iplds8).ToNot(BeNil())
|
||||
Expect(iplds8.BlockNumber.Int64()).To(Equal(test_helpers.MockIPLDs.BlockNumber.Int64()))
|
||||
Expect(iplds8.Header).To(Equal(ipfs.BlockModel{}))
|
||||
Expect(iplds8.Header).To(Equal(models.IPLDModel{}))
|
||||
Expect(len(iplds8.Uncles)).To(Equal(0))
|
||||
Expect(len(iplds8.Transactions)).To(Equal(0))
|
||||
Expect(len(iplds8.StorageNodes)).To(Equal(0))
|
||||
|
||||
@@ -17,16 +17,7 @@
|
||||
package eth
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
|
||||
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
)
|
||||
|
||||
func ResolveToNodeType(nodeType int) sdtypes.NodeType {
|
||||
@@ -43,41 +34,3 @@ func ResolveToNodeType(nodeType int) sdtypes.NodeType {
|
||||
return sdtypes.Unknown
|
||||
}
|
||||
}
|
||||
|
||||
// LoadConfig loads chain config from json file
|
||||
func LoadConfig(chainConfigPath string) (*params.ChainConfig, error) {
|
||||
file, err := os.Open(chainConfigPath)
|
||||
if err != nil {
|
||||
utils.Fatalf("Failed to read chain config file: %v", err)
|
||||
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
chainConfig := new(params.ChainConfig)
|
||||
if err := json.NewDecoder(file).Decode(chainConfig); err != nil {
|
||||
utils.Fatalf("invalid chain config file: %v", err)
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Infof("Using chain config from %s file. Content %+v", chainConfigPath, chainConfig)
|
||||
|
||||
return chainConfig, nil
|
||||
}
|
||||
|
||||
// ChainConfig returns the appropriate ethereum chain config for the provided chain id
|
||||
func ChainConfig(chainID uint64) (*params.ChainConfig, error) {
|
||||
switch chainID {
|
||||
case 1:
|
||||
return params.MainnetChainConfig, nil
|
||||
case 3:
|
||||
return params.RopstenChainConfig, nil
|
||||
case 4:
|
||||
return params.RinkebyChainConfig, nil
|
||||
case 5:
|
||||
return params.GoerliChainConfig, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("chain config for chainid %d not available", chainID)
|
||||
}
|
||||
}
|
||||
|
||||
+23
-25
@@ -22,12 +22,10 @@ import (
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/ipfs"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/models"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/postgres"
|
||||
"github.com/jmoiron/sqlx"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/shared"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/shared"
|
||||
)
|
||||
|
||||
// Fetcher interface for substituting mocks in tests
|
||||
@@ -38,11 +36,11 @@ type Fetcher interface {
|
||||
// IPLDFetcher satisfies the IPLDFetcher interface for ethereum
|
||||
// It interfaces directly with PG-IPFS
|
||||
type IPLDFetcher struct {
|
||||
db *postgres.DB
|
||||
db *sqlx.DB
|
||||
}
|
||||
|
||||
// NewIPLDFetcher creates a pointer to a new IPLDFetcher
|
||||
func NewIPLDFetcher(db *postgres.DB) *IPLDFetcher {
|
||||
func NewIPLDFetcher(db *sqlx.DB) *IPLDFetcher {
|
||||
return &IPLDFetcher{
|
||||
db: db,
|
||||
}
|
||||
@@ -102,65 +100,65 @@ func (f *IPLDFetcher) Fetch(cids CIDWrapper) (*IPLDs, error) {
|
||||
}
|
||||
|
||||
// FetchHeaders fetches headers
|
||||
func (f *IPLDFetcher) FetchHeader(tx *sqlx.Tx, c models.HeaderModel) (ipfs.BlockModel, error) {
|
||||
func (f *IPLDFetcher) FetchHeader(tx *sqlx.Tx, c models.HeaderModel) (models.IPLDModel, error) {
|
||||
log.Debug("fetching header ipld")
|
||||
headerBytes, err := shared.FetchIPLDByMhKey(tx, c.MhKey)
|
||||
if err != nil {
|
||||
return ipfs.BlockModel{}, err
|
||||
return models.IPLDModel{}, err
|
||||
}
|
||||
return ipfs.BlockModel{
|
||||
return models.IPLDModel{
|
||||
Data: headerBytes,
|
||||
CID: c.CID,
|
||||
Key: c.CID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// FetchUncles fetches uncles
|
||||
func (f *IPLDFetcher) FetchUncles(tx *sqlx.Tx, cids []models.UncleModel) ([]ipfs.BlockModel, error) {
|
||||
func (f *IPLDFetcher) FetchUncles(tx *sqlx.Tx, cids []models.UncleModel) ([]models.IPLDModel, error) {
|
||||
log.Debug("fetching uncle iplds")
|
||||
uncleIPLDs := make([]ipfs.BlockModel, len(cids))
|
||||
uncleIPLDs := make([]models.IPLDModel, len(cids))
|
||||
for i, c := range cids {
|
||||
uncleBytes, err := shared.FetchIPLDByMhKey(tx, c.MhKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
uncleIPLDs[i] = ipfs.BlockModel{
|
||||
uncleIPLDs[i] = models.IPLDModel{
|
||||
Data: uncleBytes,
|
||||
CID: c.CID,
|
||||
Key: c.CID,
|
||||
}
|
||||
}
|
||||
return uncleIPLDs, nil
|
||||
}
|
||||
|
||||
// FetchTrxs fetches transactions
|
||||
func (f *IPLDFetcher) FetchTrxs(tx *sqlx.Tx, cids []models.TxModel) ([]ipfs.BlockModel, error) {
|
||||
func (f *IPLDFetcher) FetchTrxs(tx *sqlx.Tx, cids []models.TxModel) ([]models.IPLDModel, error) {
|
||||
log.Debug("fetching transaction iplds")
|
||||
trxIPLDs := make([]ipfs.BlockModel, len(cids))
|
||||
trxIPLDs := make([]models.IPLDModel, len(cids))
|
||||
for i, c := range cids {
|
||||
txBytes, err := shared.FetchIPLDByMhKey(tx, c.MhKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
trxIPLDs[i] = ipfs.BlockModel{
|
||||
trxIPLDs[i] = models.IPLDModel{
|
||||
Data: txBytes,
|
||||
CID: c.CID,
|
||||
Key: c.CID,
|
||||
}
|
||||
}
|
||||
return trxIPLDs, nil
|
||||
}
|
||||
|
||||
// FetchRcts fetches receipts
|
||||
func (f *IPLDFetcher) FetchRcts(tx *sqlx.Tx, cids []models.ReceiptModel) ([]ipfs.BlockModel, error) {
|
||||
func (f *IPLDFetcher) FetchRcts(tx *sqlx.Tx, cids []models.ReceiptModel) ([]models.IPLDModel, error) {
|
||||
log.Debug("fetching receipt iplds")
|
||||
rctIPLDs := make([]ipfs.BlockModel, len(cids))
|
||||
rctIPLDs := make([]models.IPLDModel, len(cids))
|
||||
for i, c := range cids {
|
||||
rctBytes, err := shared.FetchIPLDByMhKey(tx, c.LeafMhKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//nodeVal, err := DecodeLeafNode(rctBytes)
|
||||
rctIPLDs[i] = ipfs.BlockModel{
|
||||
rctIPLDs[i] = models.IPLDModel{
|
||||
Data: rctBytes,
|
||||
CID: c.LeafCID,
|
||||
Key: c.LeafCID,
|
||||
}
|
||||
}
|
||||
return rctIPLDs, nil
|
||||
@@ -179,9 +177,9 @@ func (f *IPLDFetcher) FetchState(tx *sqlx.Tx, cids []models.StateNodeModel) ([]S
|
||||
return nil, err
|
||||
}
|
||||
stateNodes = append(stateNodes, StateNode{
|
||||
IPLD: ipfs.BlockModel{
|
||||
IPLD: models.IPLDModel{
|
||||
Data: stateBytes,
|
||||
CID: stateNode.CID,
|
||||
Key: stateNode.CID,
|
||||
},
|
||||
StateLeafKey: common.HexToHash(stateNode.StateKey),
|
||||
Type: ResolveToNodeType(stateNode.NodeType),
|
||||
@@ -204,9 +202,9 @@ func (f *IPLDFetcher) FetchStorage(tx *sqlx.Tx, cids []models.StorageNodeWithSta
|
||||
return nil, err
|
||||
}
|
||||
storageNodes = append(storageNodes, StorageNode{
|
||||
IPLD: ipfs.BlockModel{
|
||||
IPLD: models.IPLDModel{
|
||||
Data: storageBytes,
|
||||
CID: storageNode.CID,
|
||||
Key: storageNode.CID,
|
||||
},
|
||||
StateLeafKey: common.HexToHash(storageNode.StateKey),
|
||||
StorageLeafKey: common.HexToHash(storageNode.StorageKey),
|
||||
|
||||
@@ -18,45 +18,44 @@ package eth_test
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/postgres"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
|
||||
"github.com/jmoiron/sqlx"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth/test_helpers"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth/test_helpers"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/shared"
|
||||
)
|
||||
|
||||
var _ = Describe("IPLDFetcher", func() {
|
||||
var (
|
||||
db *postgres.DB
|
||||
pubAndIndexer *indexer.StateDiffIndexer
|
||||
db *sqlx.DB
|
||||
pubAndIndexer interfaces.StateDiffIndexer
|
||||
fetcher *eth.IPLDFetcher
|
||||
)
|
||||
Describe("Fetch", func() {
|
||||
BeforeEach(func() {
|
||||
var (
|
||||
err error
|
||||
tx *indexer.BlockTx
|
||||
tx interfaces.Batch
|
||||
)
|
||||
db, err = SetupDB()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
pubAndIndexer, err = indexer.NewStateDiffIndexer(params.TestChainConfig, db)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
db = shared.SetupDB()
|
||||
pubAndIndexer = shared.SetupTestStateDiffIndexer(ctx, params.TestChainConfig, test_helpers.Genesis.Hash())
|
||||
|
||||
tx, err = pubAndIndexer.PushBlock(test_helpers.MockBlock, test_helpers.MockReceipts, test_helpers.MockBlock.Difficulty())
|
||||
for _, node := range test_helpers.MockStateNodes {
|
||||
err = pubAndIndexer.PushStateNode(tx, node)
|
||||
err = pubAndIndexer.PushStateNode(tx, node, test_helpers.MockBlock.Hash().String())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
||||
err = tx.Close(err)
|
||||
err = tx.Submit(err)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
fetcher = eth.NewIPLDFetcher(db)
|
||||
|
||||
})
|
||||
AfterEach(func() {
|
||||
eth.TearDownDB(db)
|
||||
shared.TearDownDB(db)
|
||||
})
|
||||
|
||||
It("Fetches and returns IPLDs for the CIDs provided in the CIDWrapper", func() {
|
||||
|
||||
+29
-23
@@ -19,13 +19,13 @@ package eth
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ethereum/go-ethereum/statediff/trie"
|
||||
"github.com/ethereum/go-ethereum/statediff/trie_helpers"
|
||||
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
|
||||
"github.com/jmoiron/sqlx"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/postgres"
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
@@ -52,12 +52,12 @@ const (
|
||||
WHERE block_hash = ANY($1::VARCHAR(66)[])`
|
||||
RetrieveUnclesByBlockHashPgStr = `SELECT uncle_cids.cid, data
|
||||
FROM eth.uncle_cids
|
||||
INNER JOIN eth.header_cids ON (uncle_cids.header_id = header_cids.id)
|
||||
INNER JOIN eth.header_cids ON (uncle_cids.header_id = header_cids.block_hash)
|
||||
INNER JOIN public.blocks ON (uncle_cids.mh_key = blocks.key)
|
||||
WHERE block_hash = $1`
|
||||
RetrieveUnclesByBlockNumberPgStr = `SELECT uncle_cids.cid, data
|
||||
FROM eth.uncle_cids
|
||||
INNER JOIN eth.header_cids ON (uncle_cids.header_id = header_cids.id)
|
||||
INNER JOIN eth.header_cids ON (uncle_cids.header_id = header_cids.block_hash)
|
||||
INNER JOIN public.blocks ON (uncle_cids.mh_key = blocks.key)
|
||||
WHERE block_number = $1`
|
||||
RetrieveUncleByHashPgStr = `SELECT cid, data
|
||||
@@ -70,13 +70,13 @@ const (
|
||||
WHERE tx_hash = ANY($1::VARCHAR(66)[])`
|
||||
RetrieveTransactionsByBlockHashPgStr = `SELECT transaction_cids.cid, data
|
||||
FROM eth.transaction_cids
|
||||
INNER JOIN eth.header_cids ON (transaction_cids.header_id = header_cids.id)
|
||||
INNER JOIN eth.header_cids ON (transaction_cids.header_id = header_cids.block_hash)
|
||||
INNER JOIN public.blocks ON (transaction_cids.mh_key = blocks.key)
|
||||
WHERE block_hash = $1
|
||||
ORDER BY eth.transaction_cids.index ASC`
|
||||
RetrieveTransactionsByBlockNumberPgStr = `SELECT transaction_cids.cid, data
|
||||
FROM eth.transaction_cids
|
||||
INNER JOIN eth.header_cids ON (transaction_cids.header_id = header_cids.id)
|
||||
INNER JOIN eth.header_cids ON (transaction_cids.header_id = header_cids.block_hash)
|
||||
INNER JOIN public.blocks ON (transaction_cids.mh_key = blocks.key)
|
||||
WHERE block_number = $1
|
||||
ORDER BY eth.transaction_cids.index ASC`
|
||||
@@ -86,42 +86,42 @@ const (
|
||||
WHERE tx_hash = $1`
|
||||
RetrieveReceiptsByTxHashesPgStr = `SELECT receipt_cids.leaf_cid, data
|
||||
FROM eth.receipt_cids
|
||||
INNER JOIN eth.transaction_cids ON (receipt_cids.tx_id = transaction_cids.id)
|
||||
INNER JOIN eth.transaction_cids ON (receipt_cids.tx_id = transaction_cids.tx_hash)
|
||||
INNER JOIN public.blocks ON (receipt_cids.leaf_mh_key = blocks.key)
|
||||
WHERE tx_hash = ANY($1::VARCHAR(66)[])`
|
||||
RetrieveReceiptsByBlockHashPgStr = `SELECT receipt_cids.leaf_cid, data, eth.transaction_cids.tx_hash
|
||||
FROM eth.receipt_cids
|
||||
INNER JOIN eth.transaction_cids ON (receipt_cids.tx_id = transaction_cids.id)
|
||||
INNER JOIN eth.header_cids ON (transaction_cids.header_id = header_cids.id)
|
||||
INNER JOIN eth.transaction_cids ON (receipt_cids.tx_id = transaction_cids.tx_hash)
|
||||
INNER JOIN eth.header_cids ON (transaction_cids.header_id = header_cids.block_hash)
|
||||
INNER JOIN public.blocks ON (receipt_cids.leaf_mh_key = blocks.key)
|
||||
WHERE block_hash = $1
|
||||
ORDER BY eth.transaction_cids.index ASC`
|
||||
RetrieveReceiptsByBlockNumberPgStr = `SELECT receipt_cids.leaf_cid, data
|
||||
FROM eth.receipt_cids
|
||||
INNER JOIN eth.transaction_cids ON (receipt_cids.tx_id = transaction_cids.id)
|
||||
INNER JOIN eth.header_cids ON (transaction_cids.header_id = header_cids.id)
|
||||
INNER JOIN eth.transaction_cids ON (receipt_cids.tx_id = transaction_cids.tx_hash)
|
||||
INNER JOIN eth.header_cids ON (transaction_cids.header_id = header_cids.block_hash)
|
||||
INNER JOIN public.blocks ON (receipt_cids.leaf_mh_key = blocks.key)
|
||||
WHERE block_number = $1
|
||||
ORDER BY eth.transaction_cids.index ASC`
|
||||
RetrieveReceiptByTxHashPgStr = `SELECT receipt_cids.leaf_cid, data
|
||||
FROM eth.receipt_cids
|
||||
INNER JOIN eth.transaction_cids ON (receipt_cids.tx_id = transaction_cids.id)
|
||||
INNER JOIN eth.transaction_cids ON (receipt_cids.tx_id = transaction_cids.tx_hash)
|
||||
INNER JOIN public.blocks ON (receipt_cids.leaf_mh_key = blocks.key)
|
||||
WHERE tx_hash = $1`
|
||||
RetrieveAccountByLeafKeyAndBlockHashPgStr = `SELECT state_cids.cid, data, state_cids.node_type
|
||||
FROM eth.state_cids
|
||||
INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.id)
|
||||
INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.block_hash)
|
||||
INNER JOIN public.blocks ON (state_cids.mh_key = blocks.key)
|
||||
WHERE state_leaf_key = $1
|
||||
AND block_number <= (SELECT block_number
|
||||
FROM eth.header_cids
|
||||
WHERE block_hash = $2)
|
||||
AND header_cids.id = (SELECT canonical_header_id(block_number))
|
||||
AND header_cids.block_hash = (SELECT canonical_header_hash(block_number))
|
||||
ORDER BY block_number DESC
|
||||
LIMIT 1`
|
||||
RetrieveAccountByLeafKeyAndBlockNumberPgStr = `SELECT state_cids.cid, data, state_cids.node_type
|
||||
FROM eth.state_cids
|
||||
INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.id)
|
||||
INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.block_hash)
|
||||
INNER JOIN public.blocks ON (state_cids.mh_key = blocks.key)
|
||||
WHERE state_leaf_key = $1
|
||||
AND block_number <= $2
|
||||
@@ -129,8 +129,11 @@ const (
|
||||
LIMIT 1`
|
||||
RetrieveStorageLeafByAddressHashAndLeafKeyAndBlockNumberPgStr = `SELECT storage_cids.cid, data, storage_cids.node_type, was_state_leaf_removed($1, $3) AS state_leaf_removed
|
||||
FROM eth.storage_cids
|
||||
INNER JOIN eth.state_cids ON (storage_cids.state_id = state_cids.id)
|
||||
INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.id)
|
||||
INNER JOIN eth.state_cids ON (
|
||||
storage_cids.header_id = state_cids.header_id
|
||||
AND storage_cids.state_path = state_cids.state_path
|
||||
)
|
||||
INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.block_hash)
|
||||
INNER JOIN public.blocks ON (storage_cids.mh_key = blocks.key)
|
||||
WHERE state_leaf_key = $1
|
||||
AND storage_leaf_key = $2
|
||||
@@ -139,15 +142,18 @@ const (
|
||||
LIMIT 1`
|
||||
RetrieveStorageLeafByAddressHashAndLeafKeyAndBlockHashPgStr = `SELECT storage_cids.cid, data, storage_cids.node_type, was_state_leaf_removed($1, $3) AS state_leaf_removed
|
||||
FROM eth.storage_cids
|
||||
INNER JOIN eth.state_cids ON (storage_cids.state_id = state_cids.id)
|
||||
INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.id)
|
||||
INNER JOIN eth.state_cids ON (
|
||||
storage_cids.header_id = state_cids.header_id
|
||||
AND storage_cids.state_path = state_cids.state_path
|
||||
)
|
||||
INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.block_hash)
|
||||
INNER JOIN public.blocks ON (storage_cids.mh_key = blocks.key)
|
||||
WHERE state_leaf_key = $1
|
||||
AND storage_leaf_key = $2
|
||||
AND block_number <= (SELECT block_number
|
||||
FROM eth.header_cids
|
||||
WHERE block_hash = $3)
|
||||
AND header_cids.id = (SELECT canonical_header_id(block_number))
|
||||
AND header_cids.block_hash = (SELECT canonical_header_hash(block_number))
|
||||
ORDER BY block_number DESC
|
||||
LIMIT 1`
|
||||
)
|
||||
@@ -167,10 +173,10 @@ type ipldResult struct {
|
||||
}
|
||||
|
||||
type IPLDRetriever struct {
|
||||
db *postgres.DB
|
||||
db *sqlx.DB
|
||||
}
|
||||
|
||||
func NewIPLDRetriever(db *postgres.DB) *IPLDRetriever {
|
||||
func NewIPLDRetriever(db *sqlx.DB) *IPLDRetriever {
|
||||
return &IPLDRetriever{
|
||||
db: db,
|
||||
}
|
||||
@@ -333,7 +339,7 @@ func DecodeLeafNode(node []byte) ([]byte, error) {
|
||||
if err := rlp.DecodeBytes(node, &nodeElements); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ty, err := trie.CheckKeyType(nodeElements)
|
||||
ty, err := trie_helpers.CheckKeyType(nodeElements)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -18,34 +18,8 @@ package eth
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/models"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/postgres"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
// TearDownDB is used to tear down the watcher dbs after tests
|
||||
func TearDownDB(db *postgres.DB) {
|
||||
tx, err := db.Beginx()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
_, err = tx.Exec(`DELETE FROM eth.header_cids`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = tx.Exec(`DELETE FROM eth.transaction_cids`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = tx.Exec(`DELETE FROM eth.receipt_cids`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = tx.Exec(`DELETE FROM eth.state_cids`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = tx.Exec(`DELETE FROM eth.storage_cids`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = tx.Exec(`DELETE FROM blocks`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = tx.Exec(`DELETE FROM eth.log_cids`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = tx.Commit()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
// TxModelsContainsCID used to check if a list of TxModels contains a specific cid string
|
||||
func TxModelsContainsCID(txs []models.TxModel, cid string) bool {
|
||||
for _, tx := range txs {
|
||||
|
||||
@@ -28,26 +28,22 @@ import (
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/ipfs"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/ipfs/ipld"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/ipld"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/models"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/postgres"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/shared"
|
||||
"github.com/ethereum/go-ethereum/statediff/testhelpers"
|
||||
testhelpers "github.com/ethereum/go-ethereum/statediff/test_helpers"
|
||||
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
blocks "github.com/ipfs/go-block-format"
|
||||
"github.com/multiformats/go-multihash"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth"
|
||||
)
|
||||
|
||||
// Test variables
|
||||
var (
|
||||
// block data
|
||||
db *postgres.DB
|
||||
BlockNumber = big.NewInt(1)
|
||||
MockHeader = types.Header{
|
||||
Time: 0,
|
||||
@@ -330,7 +326,7 @@ var (
|
||||
StorageLeafKey = crypto.Keccak256Hash(storageLocation[:]).Bytes()
|
||||
StorageValue = crypto.Keccak256([]byte{1, 2, 3, 4, 5})
|
||||
StoragePartialPath = common.Hex2Bytes("20290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563")
|
||||
StorageLeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
StorageLeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
StoragePartialPath,
|
||||
StorageValue,
|
||||
})
|
||||
@@ -340,14 +336,14 @@ var (
|
||||
ContractCodeHash = crypto.Keccak256Hash(MockContractByteCode)
|
||||
contractPath = common.Bytes2Hex([]byte{'\x06'})
|
||||
ContractLeafKey = testhelpers.AddressToLeafKey(ContractAddress)
|
||||
ContractAccount, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
ContractAccount, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: nonce1,
|
||||
Balance: big.NewInt(0),
|
||||
CodeHash: ContractCodeHash.Bytes(),
|
||||
Root: common.HexToHash(ContractRoot),
|
||||
})
|
||||
ContractPartialPath = common.Hex2Bytes("3114658a74d9cc9f7acf2c5cd696c3494d7c344d78bfec3add0d91ec4e8d1c45")
|
||||
ContractLeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
ContractLeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
ContractPartialPath,
|
||||
ContractAccount,
|
||||
})
|
||||
@@ -358,14 +354,14 @@ var (
|
||||
AccountCodeHash = common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")
|
||||
AccountAddresss = common.HexToAddress("0x0D3ab14BBaD3D99F4203bd7a11aCB94882050E7e")
|
||||
AccountLeafKey = testhelpers.Account2LeafKey
|
||||
Account, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
Account, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: nonce0,
|
||||
Balance: AccountBalance,
|
||||
CodeHash: AccountCodeHash.Bytes(),
|
||||
Root: common.HexToHash(AccountRoot),
|
||||
})
|
||||
AccountPartialPath = common.Hex2Bytes("3957f3e2f04a0764c3a0491b175f69926da61efbcc8f61fa1455fd2d2b4cdd45")
|
||||
AccountLeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
AccountLeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
AccountPartialPath,
|
||||
Account,
|
||||
})
|
||||
@@ -439,8 +435,7 @@ var (
|
||||
StateNodes: MockStateNodes,
|
||||
}
|
||||
|
||||
Reward = indexer.CalcEthBlockReward(MockBlock.Header(), MockBlock.Uncles(), MockBlock.Transactions(), MockReceipts)
|
||||
|
||||
Reward = shared.CalcEthBlockReward(MockBlock.Header(), MockBlock.Uncles(), MockBlock.Transactions(), MockReceipts)
|
||||
MockCIDWrapper = ð.CIDWrapper{
|
||||
BlockNumber: new(big.Int).Set(BlockNumber),
|
||||
Header: models.HeaderModel{
|
||||
@@ -458,6 +453,7 @@ var (
|
||||
Bloom: MockBlock.Bloom().Bytes(),
|
||||
Timestamp: MockBlock.Time(),
|
||||
TimesValidated: 1,
|
||||
Coinbase: "0x0000000000000000000000000000000000000000",
|
||||
},
|
||||
Transactions: MockTrxMetaPostPublsh,
|
||||
Receipts: MockRctMetaPostPublish,
|
||||
@@ -486,62 +482,62 @@ var (
|
||||
|
||||
MockIPLDs = eth.IPLDs{
|
||||
BlockNumber: new(big.Int).Set(BlockNumber),
|
||||
Header: ipfs.BlockModel{
|
||||
Header: models.IPLDModel{
|
||||
Data: HeaderIPLD.RawData(),
|
||||
CID: HeaderIPLD.Cid().String(),
|
||||
Key: HeaderIPLD.Cid().String(),
|
||||
},
|
||||
Transactions: []ipfs.BlockModel{
|
||||
Transactions: []models.IPLDModel{
|
||||
{
|
||||
Data: Trx1IPLD.RawData(),
|
||||
CID: Trx1IPLD.Cid().String(),
|
||||
Key: Trx1IPLD.Cid().String(),
|
||||
},
|
||||
{
|
||||
Data: Trx2IPLD.RawData(),
|
||||
CID: Trx2IPLD.Cid().String(),
|
||||
Key: Trx2IPLD.Cid().String(),
|
||||
},
|
||||
{
|
||||
Data: Trx3IPLD.RawData(),
|
||||
CID: Trx3IPLD.Cid().String(),
|
||||
Key: Trx3IPLD.Cid().String(),
|
||||
},
|
||||
{
|
||||
Data: Trx4IPLD.RawData(),
|
||||
CID: Trx4IPLD.Cid().String(),
|
||||
Key: Trx4IPLD.Cid().String(),
|
||||
},
|
||||
},
|
||||
Receipts: []ipfs.BlockModel{
|
||||
Receipts: []models.IPLDModel{
|
||||
{
|
||||
Data: Rct1IPLD,
|
||||
CID: Rct1CID.String(),
|
||||
Key: Rct1CID.String(),
|
||||
},
|
||||
{
|
||||
Data: Rct2IPLD,
|
||||
CID: Rct2CID.String(),
|
||||
Key: Rct2CID.String(),
|
||||
},
|
||||
{
|
||||
Data: Rct3IPLD,
|
||||
CID: Rct3CID.String(),
|
||||
Key: Rct3CID.String(),
|
||||
},
|
||||
{
|
||||
Data: Rct4IPLD,
|
||||
CID: Rct4CID.String(),
|
||||
Key: Rct4CID.String(),
|
||||
},
|
||||
},
|
||||
StateNodes: []eth.StateNode{
|
||||
{
|
||||
StateLeafKey: common.BytesToHash(ContractLeafKey),
|
||||
Type: sdtypes.Leaf,
|
||||
IPLD: ipfs.BlockModel{
|
||||
IPLD: models.IPLDModel{
|
||||
Data: State1IPLD.RawData(),
|
||||
CID: State1IPLD.Cid().String(),
|
||||
Key: State1IPLD.Cid().String(),
|
||||
},
|
||||
Path: []byte{'\x06'},
|
||||
},
|
||||
{
|
||||
StateLeafKey: common.BytesToHash(AccountLeafKey),
|
||||
Type: sdtypes.Leaf,
|
||||
IPLD: ipfs.BlockModel{
|
||||
IPLD: models.IPLDModel{
|
||||
Data: State2IPLD.RawData(),
|
||||
CID: State2IPLD.Cid().String(),
|
||||
Key: State2IPLD.Cid().String(),
|
||||
},
|
||||
Path: []byte{'\x0c'},
|
||||
},
|
||||
@@ -551,9 +547,9 @@ var (
|
||||
StateLeafKey: common.BytesToHash(ContractLeafKey),
|
||||
StorageLeafKey: common.BytesToHash(StorageLeafKey),
|
||||
Type: sdtypes.Leaf,
|
||||
IPLD: ipfs.BlockModel{
|
||||
IPLD: models.IPLDModel{
|
||||
Data: StorageIPLD.RawData(),
|
||||
CID: StorageIPLD.Cid().String(),
|
||||
Key: StorageIPLD.Cid().String(),
|
||||
},
|
||||
Path: []byte{},
|
||||
},
|
||||
|
||||
+7
-8
@@ -24,7 +24,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/common/math"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/ipfs"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/models"
|
||||
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -197,10 +196,10 @@ func (arg *CallArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (types.Mes
|
||||
type IPLDs struct {
|
||||
BlockNumber *big.Int
|
||||
TotalDifficulty *big.Int
|
||||
Header ipfs.BlockModel
|
||||
Uncles []ipfs.BlockModel
|
||||
Transactions []ipfs.BlockModel
|
||||
Receipts []ipfs.BlockModel
|
||||
Header models.IPLDModel
|
||||
Uncles []models.IPLDModel
|
||||
Transactions []models.IPLDModel
|
||||
Receipts []models.IPLDModel
|
||||
StateNodes []StateNode
|
||||
StorageNodes []StorageNode
|
||||
}
|
||||
@@ -209,7 +208,7 @@ type StateNode struct {
|
||||
Type sdtypes.NodeType
|
||||
StateLeafKey common.Hash
|
||||
Path []byte
|
||||
IPLD ipfs.BlockModel
|
||||
IPLD models.IPLDModel
|
||||
}
|
||||
|
||||
type StorageNode struct {
|
||||
@@ -217,7 +216,7 @@ type StorageNode struct {
|
||||
StateLeafKey common.Hash
|
||||
StorageLeafKey common.Hash
|
||||
Path []byte
|
||||
IPLD ipfs.BlockModel
|
||||
IPLD models.IPLDModel
|
||||
}
|
||||
|
||||
// CIDWrapper is used to direct fetching of IPLDs from IPFS
|
||||
@@ -249,7 +248,7 @@ type ConvertedPayload struct {
|
||||
// LogResult represent a log.
|
||||
type LogResult struct {
|
||||
LeafCID string `db:"leaf_cid"`
|
||||
ReceiptID int64 `db:"receipt_id"`
|
||||
ReceiptID string `db:"rct_id"`
|
||||
Address string `db:"address"`
|
||||
Index int64 `db:"index"`
|
||||
Data []byte `db:"log_data"`
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// VulcanizeDB
|
||||
// Copyright © 2022 Vulcanize
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package fill_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestFill(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "ipld eth server fill test suite")
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
// VulcanizeDB
|
||||
// Copyright © 2022 Vulcanize
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package fill
|
||||
|
||||
import (
|
||||
"math"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/statediff"
|
||||
"github.com/jmoiron/sqlx"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/serve"
|
||||
)
|
||||
|
||||
// WatchedAddress type is used to process currently watched addresses
|
||||
type WatchedAddress struct {
|
||||
Address string `db:"address"`
|
||||
CreatedAt uint64 `db:"created_at"`
|
||||
WatchedAt uint64 `db:"watched_at"`
|
||||
LastFilledAt uint64 `db:"last_filled_at"`
|
||||
|
||||
StartBlock uint64
|
||||
EndBlock uint64
|
||||
}
|
||||
|
||||
// Service is the underlying struct for the watched address gap filling service
|
||||
type Service struct {
|
||||
db *sqlx.DB
|
||||
client *rpc.Client
|
||||
interval int
|
||||
quitChan chan bool
|
||||
}
|
||||
|
||||
// NewServer creates a new Service
|
||||
func New(config *serve.Config) *Service {
|
||||
return &Service{
|
||||
db: config.DB,
|
||||
client: config.Client,
|
||||
interval: config.WatchedAddressGapFillInterval,
|
||||
quitChan: make(chan bool),
|
||||
}
|
||||
}
|
||||
|
||||
// Start is used to begin the service
|
||||
func (s *Service) Start(wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
for {
|
||||
select {
|
||||
case <-s.quitChan:
|
||||
log.Info("quiting eth ipld server process")
|
||||
return
|
||||
default:
|
||||
s.fill()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Stop is used to gracefully stop the service
|
||||
func (s *Service) Stop() {
|
||||
log.Info("stopping watched address gap filler")
|
||||
close(s.quitChan)
|
||||
}
|
||||
|
||||
// fill performs the filling of indexing gap for watched addresses
|
||||
func (s *Service) fill() {
|
||||
// Wait for specified interval duration
|
||||
time.Sleep(time.Duration(s.interval) * time.Second)
|
||||
|
||||
// Get watched addresses from the db
|
||||
rows := s.fetchWatchedAddresses()
|
||||
|
||||
// Get the block number to start fill at
|
||||
// Get the block number to end fill at
|
||||
fillWatchedAddresses, minStartBlock, maxEndBlock := s.GetFillAddresses(rows)
|
||||
|
||||
if len(fillWatchedAddresses) > 0 {
|
||||
log.Infof("running watched address gap filler for block range: (%d, %d)", minStartBlock, maxEndBlock)
|
||||
}
|
||||
|
||||
// Fill the missing diffs
|
||||
for blockNumber := minStartBlock; blockNumber <= maxEndBlock; blockNumber++ {
|
||||
params := statediff.Params{
|
||||
IntermediateStateNodes: true,
|
||||
IntermediateStorageNodes: true,
|
||||
IncludeBlock: true,
|
||||
IncludeReceipts: true,
|
||||
IncludeTD: true,
|
||||
IncludeCode: true,
|
||||
}
|
||||
|
||||
fillAddresses := []interface{}{}
|
||||
for _, fillWatchedAddress := range fillWatchedAddresses {
|
||||
if blockNumber >= fillWatchedAddress.StartBlock && blockNumber <= fillWatchedAddress.EndBlock {
|
||||
params.WatchedAddresses = append(params.WatchedAddresses, common.HexToAddress(fillWatchedAddress.Address))
|
||||
fillAddresses = append(fillAddresses, fillWatchedAddress.Address)
|
||||
}
|
||||
}
|
||||
|
||||
if len(fillAddresses) > 0 {
|
||||
s.writeStateDiffAt(blockNumber, params)
|
||||
s.UpdateLastFilledAt(blockNumber, fillAddresses)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetFillAddresses finds the encompassing range to perform fill for the given watched addresses
|
||||
// it also sets the address specific fill range
|
||||
func (s *Service) GetFillAddresses(rows []WatchedAddress) ([]WatchedAddress, uint64, uint64) {
|
||||
fillWatchedAddresses := []WatchedAddress{}
|
||||
minStartBlock := uint64(math.MaxUint64)
|
||||
maxEndBlock := uint64(0)
|
||||
|
||||
for _, row := range rows {
|
||||
// Check for a gap between created_at and watched_at
|
||||
// CreatedAt and WatchedAt being equal is considered a gap of one block
|
||||
if row.CreatedAt > row.WatchedAt {
|
||||
continue
|
||||
}
|
||||
|
||||
startBlock := uint64(0)
|
||||
endBlock := uint64(0)
|
||||
|
||||
// Check if some of the gap was filled earlier
|
||||
if row.LastFilledAt > 0 {
|
||||
if row.LastFilledAt < row.WatchedAt {
|
||||
startBlock = row.LastFilledAt + 1
|
||||
}
|
||||
} else {
|
||||
startBlock = row.CreatedAt
|
||||
}
|
||||
|
||||
// Add the address for filling
|
||||
if startBlock > 0 {
|
||||
row.StartBlock = startBlock
|
||||
if startBlock < minStartBlock {
|
||||
minStartBlock = startBlock
|
||||
}
|
||||
|
||||
endBlock = row.WatchedAt
|
||||
row.EndBlock = endBlock
|
||||
if endBlock > maxEndBlock {
|
||||
maxEndBlock = endBlock
|
||||
}
|
||||
|
||||
fillWatchedAddresses = append(fillWatchedAddresses, row)
|
||||
}
|
||||
}
|
||||
|
||||
return fillWatchedAddresses, minStartBlock, maxEndBlock
|
||||
}
|
||||
|
||||
// UpdateLastFilledAt updates the fill status for the provided addresses in the db
|
||||
func (s *Service) UpdateLastFilledAt(blockNumber uint64, fillAddresses []interface{}) {
|
||||
// Prepare the query
|
||||
query := "UPDATE eth_meta.watched_addresses SET last_filled_at=? WHERE address IN (?" + strings.Repeat(",?", len(fillAddresses)-1) + ")"
|
||||
query = s.db.Rebind(query)
|
||||
|
||||
args := []interface{}{blockNumber}
|
||||
args = append(args, fillAddresses...)
|
||||
|
||||
// Execute the update query
|
||||
_, err := s.db.Exec(query, args...)
|
||||
if err != nil {
|
||||
log.Fatalf(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// fetchWatchedAddresses fetches watched addresses from the db
|
||||
func (s *Service) fetchWatchedAddresses() []WatchedAddress {
|
||||
rows := []WatchedAddress{}
|
||||
pgStr := "SELECT * FROM eth_meta.watched_addresses"
|
||||
|
||||
err := s.db.Select(&rows, pgStr)
|
||||
if err != nil {
|
||||
log.Fatalf("Error fetching watched addreesses: %s", err.Error())
|
||||
}
|
||||
|
||||
return rows
|
||||
}
|
||||
|
||||
// writeStateDiffAt makes a RPC call to writeout statediffs at a blocknumber with the given params
|
||||
func (s *Service) writeStateDiffAt(blockNumber uint64, params statediff.Params) {
|
||||
err := s.client.Call(nil, "statediff_writeStateDiffAt", blockNumber, params)
|
||||
if err != nil {
|
||||
log.Fatalf("Error making a RPC call to write statediff at block number %d: %s", blockNumber, err.Error())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,411 @@
|
||||
// VulcanizeDB
|
||||
// Copyright © 2022 Vulcanize
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package fill_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
|
||||
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
|
||||
"github.com/jmoiron/sqlx"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth/test_helpers"
|
||||
fill "github.com/vulcanize/ipld-eth-server/v3/pkg/fill"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/serve"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/shared"
|
||||
)
|
||||
|
||||
var _ = Describe("Service", func() {
|
||||
|
||||
var (
|
||||
db *sqlx.DB
|
||||
watchedAddressGapFiller *fill.Service
|
||||
statediffIndexer interfaces.StateDiffIndexer
|
||||
err error
|
||||
|
||||
contract1Address = "0x5d663F5269090bD2A7DC2390c911dF6083D7b28F"
|
||||
contract2Address = "0x6Eb7e5C66DB8af2E96159AC440cbc8CDB7fbD26B"
|
||||
contract3Address = "0xcfeB164C328CA13EFd3C77E1980d94975aDfedfc"
|
||||
|
||||
chainConfig = params.TestChainConfig
|
||||
ctx = context.Background()
|
||||
)
|
||||
|
||||
It("test init", func() {
|
||||
// db initialization
|
||||
db = shared.SetupDB()
|
||||
|
||||
// indexer initialization
|
||||
// statediffIndexer, err = indexer.NewStateDiffIndexer(nil, db)
|
||||
statediffIndexer = shared.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// fill service intialization
|
||||
watchedAddressGapFiller = fill.New(&serve.Config{
|
||||
DB: db,
|
||||
})
|
||||
})
|
||||
|
||||
defer It("test teardown", func() {
|
||||
shared.TearDownDB(db)
|
||||
})
|
||||
|
||||
Describe("GetFillAddresses", func() {
|
||||
Context("overlapping fill ranges", func() {
|
||||
It("gives the range to run fill for each address", func() {
|
||||
// input data
|
||||
rows := []fill.WatchedAddress{
|
||||
{
|
||||
Address: contract1Address,
|
||||
CreatedAt: 10,
|
||||
WatchedAt: 50,
|
||||
LastFilledAt: 0,
|
||||
},
|
||||
{
|
||||
Address: contract2Address,
|
||||
CreatedAt: 40,
|
||||
WatchedAt: 70,
|
||||
LastFilledAt: 0,
|
||||
},
|
||||
{
|
||||
Address: contract3Address,
|
||||
CreatedAt: 20,
|
||||
WatchedAt: 30,
|
||||
LastFilledAt: 0,
|
||||
},
|
||||
}
|
||||
|
||||
// expected output data
|
||||
expectedOutputAddresses := []fill.WatchedAddress{
|
||||
{
|
||||
Address: contract1Address,
|
||||
CreatedAt: 10,
|
||||
WatchedAt: 50,
|
||||
LastFilledAt: 0,
|
||||
StartBlock: 10,
|
||||
EndBlock: 50,
|
||||
},
|
||||
{
|
||||
Address: contract2Address,
|
||||
CreatedAt: 40,
|
||||
WatchedAt: 70,
|
||||
LastFilledAt: 0,
|
||||
StartBlock: 40,
|
||||
EndBlock: 70,
|
||||
},
|
||||
{
|
||||
Address: contract3Address,
|
||||
CreatedAt: 20,
|
||||
WatchedAt: 30,
|
||||
LastFilledAt: 0,
|
||||
StartBlock: 20,
|
||||
EndBlock: 30,
|
||||
},
|
||||
}
|
||||
expectedOutputStartBlock := uint64(10)
|
||||
expectedOutputEndBlock := uint64(70)
|
||||
|
||||
fillWatchedAddresses, minStartBlock, maxEndBlock := watchedAddressGapFiller.GetFillAddresses(rows)
|
||||
|
||||
Expect(fillWatchedAddresses).To(Equal(expectedOutputAddresses))
|
||||
Expect(minStartBlock).To(Equal(expectedOutputStartBlock))
|
||||
Expect(maxEndBlock).To(Equal(expectedOutputEndBlock))
|
||||
})
|
||||
})
|
||||
|
||||
Context("non-overlapping fill ranges", func() {
|
||||
It("gives the range to run fill for each address", func() {
|
||||
// input data
|
||||
rows := []fill.WatchedAddress{
|
||||
{
|
||||
Address: contract1Address,
|
||||
CreatedAt: 10,
|
||||
WatchedAt: 50,
|
||||
LastFilledAt: 0,
|
||||
},
|
||||
{
|
||||
Address: contract2Address,
|
||||
CreatedAt: 70,
|
||||
WatchedAt: 90,
|
||||
LastFilledAt: 0,
|
||||
},
|
||||
}
|
||||
|
||||
// expected output data
|
||||
expectedOutputAddresses := []fill.WatchedAddress{
|
||||
{
|
||||
Address: contract1Address,
|
||||
CreatedAt: 10,
|
||||
WatchedAt: 50,
|
||||
LastFilledAt: 0,
|
||||
StartBlock: 10,
|
||||
EndBlock: 50,
|
||||
},
|
||||
{
|
||||
Address: contract2Address,
|
||||
CreatedAt: 70,
|
||||
WatchedAt: 90,
|
||||
LastFilledAt: 0,
|
||||
StartBlock: 70,
|
||||
EndBlock: 90,
|
||||
},
|
||||
}
|
||||
expectedOutputStartBlock := uint64(10)
|
||||
expectedOutputEndBlock := uint64(90)
|
||||
|
||||
fillWatchedAddresses, minStartBlock, maxEndBlock := watchedAddressGapFiller.GetFillAddresses(rows)
|
||||
|
||||
Expect(fillWatchedAddresses).To(Equal(expectedOutputAddresses))
|
||||
Expect(minStartBlock).To(Equal(expectedOutputStartBlock))
|
||||
Expect(maxEndBlock).To(Equal(expectedOutputEndBlock))
|
||||
})
|
||||
})
|
||||
|
||||
Context("a contract watched before it was created", func() {
|
||||
It("gives no range for an address when it is watched before it's created", func() {
|
||||
// input data
|
||||
rows := []fill.WatchedAddress{
|
||||
{
|
||||
Address: contract1Address,
|
||||
CreatedAt: 10,
|
||||
WatchedAt: 50,
|
||||
LastFilledAt: 0,
|
||||
},
|
||||
{
|
||||
Address: contract2Address,
|
||||
CreatedAt: 90,
|
||||
WatchedAt: 70,
|
||||
LastFilledAt: 0,
|
||||
},
|
||||
}
|
||||
|
||||
// expected output data
|
||||
expectedOutputAddresses := []fill.WatchedAddress{
|
||||
{
|
||||
Address: contract1Address,
|
||||
CreatedAt: 10,
|
||||
WatchedAt: 50,
|
||||
LastFilledAt: 0,
|
||||
StartBlock: 10,
|
||||
EndBlock: 50,
|
||||
},
|
||||
}
|
||||
expectedOutputStartBlock := uint64(10)
|
||||
expectedOutputEndBlock := uint64(50)
|
||||
|
||||
fillWatchedAddresses, minStartBlock, maxEndBlock := watchedAddressGapFiller.GetFillAddresses(rows)
|
||||
|
||||
Expect(fillWatchedAddresses).To(Equal(expectedOutputAddresses))
|
||||
Expect(minStartBlock).To(Equal(expectedOutputStartBlock))
|
||||
Expect(maxEndBlock).To(Equal(expectedOutputEndBlock))
|
||||
})
|
||||
})
|
||||
|
||||
Context("a contract having some of the gap filled earlier", func() {
|
||||
It("gives the remaining range for an address to run fill for", func() {
|
||||
// input data
|
||||
rows := []fill.WatchedAddress{
|
||||
{
|
||||
Address: contract1Address,
|
||||
CreatedAt: 10,
|
||||
WatchedAt: 50,
|
||||
LastFilledAt: 0,
|
||||
},
|
||||
{
|
||||
Address: contract2Address,
|
||||
CreatedAt: 40,
|
||||
WatchedAt: 70,
|
||||
LastFilledAt: 50,
|
||||
},
|
||||
}
|
||||
|
||||
// expected output data
|
||||
expectedOutputAddresses := []fill.WatchedAddress{
|
||||
{
|
||||
Address: contract1Address,
|
||||
CreatedAt: 10,
|
||||
WatchedAt: 50,
|
||||
LastFilledAt: 0,
|
||||
StartBlock: 10,
|
||||
EndBlock: 50,
|
||||
},
|
||||
{
|
||||
Address: contract2Address,
|
||||
CreatedAt: 40,
|
||||
WatchedAt: 70,
|
||||
LastFilledAt: 50,
|
||||
StartBlock: 51,
|
||||
EndBlock: 70,
|
||||
},
|
||||
}
|
||||
expectedOutputStartBlock := uint64(10)
|
||||
expectedOutputEndBlock := uint64(70)
|
||||
|
||||
fillWatchedAddresses, minStartBlock, maxEndBlock := watchedAddressGapFiller.GetFillAddresses(rows)
|
||||
|
||||
Expect(fillWatchedAddresses).To(Equal(expectedOutputAddresses))
|
||||
Expect(minStartBlock).To(Equal(expectedOutputStartBlock))
|
||||
Expect(maxEndBlock).To(Equal(expectedOutputEndBlock))
|
||||
})
|
||||
|
||||
It("gives no range for an address when the gap is already filled", func() {
|
||||
// input data
|
||||
rows := []fill.WatchedAddress{
|
||||
{
|
||||
Address: contract1Address,
|
||||
CreatedAt: 10,
|
||||
WatchedAt: 50,
|
||||
LastFilledAt: 0,
|
||||
},
|
||||
{
|
||||
Address: contract2Address,
|
||||
CreatedAt: 40,
|
||||
WatchedAt: 70,
|
||||
LastFilledAt: 70,
|
||||
},
|
||||
}
|
||||
|
||||
// expected output data
|
||||
expectedOutputAddresses := []fill.WatchedAddress{
|
||||
{
|
||||
Address: contract1Address,
|
||||
CreatedAt: 10,
|
||||
WatchedAt: 50,
|
||||
LastFilledAt: 0,
|
||||
StartBlock: 10,
|
||||
EndBlock: 50,
|
||||
},
|
||||
}
|
||||
expectedOutputStartBlock := uint64(10)
|
||||
expectedOutputEndBlock := uint64(50)
|
||||
|
||||
fillWatchedAddresses, minStartBlock, maxEndBlock := watchedAddressGapFiller.GetFillAddresses(rows)
|
||||
|
||||
Expect(fillWatchedAddresses).To(Equal(expectedOutputAddresses))
|
||||
Expect(minStartBlock).To(Equal(expectedOutputStartBlock))
|
||||
Expect(maxEndBlock).To(Equal(expectedOutputEndBlock))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Describe("UpdateLastFilledAt", func() {
|
||||
pgStr := "SELECT * FROM eth_meta.watched_addresses"
|
||||
|
||||
BeforeEach(func() {
|
||||
shared.TearDownDB(db)
|
||||
})
|
||||
|
||||
It("updates last filled at for a single address", func() {
|
||||
// fill db with watched addresses
|
||||
watchedAddresses := []sdtypes.WatchAddressArg{
|
||||
{
|
||||
Address: contract1Address,
|
||||
CreatedAt: 10,
|
||||
},
|
||||
}
|
||||
watchedAt := uint64(50)
|
||||
err = statediffIndexer.InsertWatchedAddresses(watchedAddresses, big.NewInt(int64(watchedAt)))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// update last filled at block in the db
|
||||
fillAddresses := []interface{}{
|
||||
contract1Address,
|
||||
}
|
||||
fillAt := uint64(12)
|
||||
watchedAddressGapFiller.UpdateLastFilledAt(fillAt, fillAddresses)
|
||||
|
||||
// expected data
|
||||
expectedData := []fill.WatchedAddress{
|
||||
{
|
||||
Address: contract1Address,
|
||||
CreatedAt: 10,
|
||||
WatchedAt: watchedAt,
|
||||
LastFilledAt: fillAt,
|
||||
},
|
||||
}
|
||||
|
||||
rows := []fill.WatchedAddress{}
|
||||
err = db.Select(&rows, pgStr)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
Expect(rows).To(Equal(expectedData))
|
||||
})
|
||||
|
||||
It("updates last filled at for multiple address", func() {
|
||||
// fill db with watched addresses
|
||||
watchedAddresses := []sdtypes.WatchAddressArg{
|
||||
{
|
||||
Address: contract1Address,
|
||||
CreatedAt: 10,
|
||||
},
|
||||
{
|
||||
Address: contract2Address,
|
||||
CreatedAt: 20,
|
||||
},
|
||||
{
|
||||
Address: contract3Address,
|
||||
CreatedAt: 30,
|
||||
},
|
||||
}
|
||||
watchedAt := uint64(50)
|
||||
err = statediffIndexer.InsertWatchedAddresses(watchedAddresses, big.NewInt(int64(watchedAt)))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// update last filled at block in the db
|
||||
fillAddresses := []interface{}{
|
||||
contract1Address,
|
||||
contract2Address,
|
||||
contract3Address,
|
||||
}
|
||||
fillAt := uint64(50)
|
||||
watchedAddressGapFiller.UpdateLastFilledAt(fillAt, fillAddresses)
|
||||
|
||||
// expected data
|
||||
expectedData := []fill.WatchedAddress{
|
||||
{
|
||||
Address: contract1Address,
|
||||
CreatedAt: 10,
|
||||
WatchedAt: watchedAt,
|
||||
LastFilledAt: fillAt,
|
||||
},
|
||||
{
|
||||
Address: contract2Address,
|
||||
CreatedAt: 20,
|
||||
WatchedAt: watchedAt,
|
||||
LastFilledAt: fillAt,
|
||||
},
|
||||
{
|
||||
Address: contract3Address,
|
||||
CreatedAt: 30,
|
||||
WatchedAt: watchedAt,
|
||||
LastFilledAt: fillAt,
|
||||
},
|
||||
}
|
||||
|
||||
rows := []fill.WatchedAddress{}
|
||||
err = db.Select(&rows, pgStr)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
Expect(rows).To(Equal(expectedData))
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -33,7 +33,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
+16
-35
@@ -20,8 +20,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
@@ -32,32 +30,18 @@ import (
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/statediff"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/node"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/postgres"
|
||||
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
|
||||
"github.com/jmoiron/sqlx"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth/test_helpers"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/graphql"
|
||||
ethServerShared "github.com/vulcanize/ipld-eth-server/pkg/shared"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth/test_helpers"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/graphql"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/shared"
|
||||
ethServerShared "github.com/vulcanize/ipld-eth-server/v3/pkg/shared"
|
||||
)
|
||||
|
||||
// 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: 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{})
|
||||
}
|
||||
|
||||
var _ = Describe("GraphQL", func() {
|
||||
const (
|
||||
gqlEndPoint = "127.0.0.1:8083"
|
||||
@@ -68,7 +52,7 @@ var _ = Describe("GraphQL", func() {
|
||||
blocks []*types.Block
|
||||
receipts []types.Receipts
|
||||
chain *core.BlockChain
|
||||
db *postgres.DB
|
||||
db *sqlx.DB
|
||||
blockHashes []common.Hash
|
||||
backend *eth.Backend
|
||||
graphQLServer *graphql.Service
|
||||
@@ -82,11 +66,9 @@ var _ = Describe("GraphQL", func() {
|
||||
|
||||
It("test init", func() {
|
||||
var err error
|
||||
db, err = SetupDB()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
db = shared.SetupDB()
|
||||
transformer := shared.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash())
|
||||
|
||||
transformer, err := indexer.NewStateDiffIndexer(chainConfig, db)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
backend, err = eth.NewEthBackend(db, ð.Config{
|
||||
ChainConfig: chainConfig,
|
||||
VMConfig: vm.Config{},
|
||||
@@ -132,7 +114,7 @@ var _ = Describe("GraphQL", func() {
|
||||
rcts = receipts[i-1]
|
||||
}
|
||||
|
||||
var diff statediff.StateObject
|
||||
var diff sdtypes.StateObject
|
||||
diff, err = builder.BuildStateDiffObject(args, params)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
@@ -140,17 +122,16 @@ var _ = Describe("GraphQL", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
for _, node := range diff.Nodes {
|
||||
err = transformer.PushStateNode(tx, node)
|
||||
err = transformer.PushStateNode(tx, node, block.Hash().String())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
||||
err = tx.Close(err)
|
||||
err = tx.Submit(err)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
||||
// Insert some non-canonical data into the database so that we test our ability to discern canonicity
|
||||
indexAndPublisher, err := indexer.NewStateDiffIndexer(chainConfig, db)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
indexAndPublisher := shared.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash())
|
||||
|
||||
blockHash = test_helpers.MockBlock.Hash()
|
||||
contractAddress = test_helpers.ContractAddr
|
||||
@@ -158,7 +139,7 @@ var _ = Describe("GraphQL", func() {
|
||||
tx, err := indexAndPublisher.PushBlock(test_helpers.MockBlock, test_helpers.MockReceipts, test_helpers.MockBlock.Difficulty())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
err = tx.Close(err)
|
||||
err = tx.Submit(err)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// The non-canonical header has a child
|
||||
@@ -173,7 +154,7 @@ var _ = Describe("GraphQL", func() {
|
||||
err = indexAndPublisher.PushCodeAndCodeHash(tx, ccHash)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
err = tx.Close(err)
|
||||
err = tx.Submit(err)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
graphQLServer, err = graphql.New(backend, gqlEndPoint, nil, []string{"*"}, rpc.HTTPTimeouts{})
|
||||
@@ -186,7 +167,7 @@ var _ = Describe("GraphQL", func() {
|
||||
defer It("test teardown", func() {
|
||||
err := graphQLServer.Stop()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
eth.TearDownDB(db)
|
||||
shared.TearDownDB(db)
|
||||
chain.Stop()
|
||||
})
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import (
|
||||
"github.com/graph-gophers/graphql-go/relay"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth"
|
||||
)
|
||||
|
||||
// Service encapsulates a GraphQL service.
|
||||
@@ -69,7 +69,7 @@ func (s *Service) Start(server *p2p.Server) error {
|
||||
return err
|
||||
}
|
||||
|
||||
handler := node.NewHTTPHandlerStack(s.handler, s.cors, s.vhosts)
|
||||
handler := node.NewHTTPHandlerStack(s.handler, s.cors, s.vhosts, nil)
|
||||
|
||||
// start http server
|
||||
_, addr, err := node.StartHTTPEndpoint(s.endpoint, rpc.DefaultHTTPTimeouts, handler)
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ import (
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/net"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/net"
|
||||
)
|
||||
|
||||
var _ = Describe("API", func() {
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ func StartHTTPEndpoint(endpoint string, apis []rpc.API, modules []string, cors [
|
||||
if err != nil {
|
||||
utils.Fatalf("Could not register HTTP API: %w", err)
|
||||
}
|
||||
handler := node.NewHTTPHandlerStack(srv, cors, vhosts)
|
||||
handler := node.NewHTTPHandlerStack(srv, cors, vhosts, nil)
|
||||
|
||||
// start http server
|
||||
_, addr, err := node.StartHTTPEndpoint(endpoint, rpc.DefaultHTTPTimeouts, handler)
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/p2p/netutil"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/prom"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/prom"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/node"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/prom"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/prom"
|
||||
)
|
||||
|
||||
// StartWSEndpoint starts a websocket endpoint.
|
||||
|
||||
+15
-8
@@ -20,10 +20,10 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/shared"
|
||||
"github.com/ethereum/go-ethereum/statediff/types"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth"
|
||||
)
|
||||
|
||||
// APIName is the namespace used for the state diffing service API
|
||||
@@ -34,13 +34,15 @@ const APIVersion = "0.0.1"
|
||||
|
||||
// PublicServerAPI is the public api for the watcher
|
||||
type PublicServerAPI struct {
|
||||
w Server
|
||||
w Server
|
||||
rpc *rpc.Client
|
||||
}
|
||||
|
||||
// NewPublicServerAPI creates a new PublicServerAPI with the provided underlying Server process
|
||||
func NewPublicServerAPI(w Server) *PublicServerAPI {
|
||||
func NewPublicServerAPI(w Server, client *rpc.Client) *PublicServerAPI {
|
||||
return &PublicServerAPI{
|
||||
w: w,
|
||||
w: w,
|
||||
rpc: client,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +85,12 @@ func (api *PublicServerAPI) Stream(ctx context.Context, params eth.SubscriptionS
|
||||
return rpcSub, nil
|
||||
}
|
||||
|
||||
// Chain returns the chain type that this watcher instance supports
|
||||
func (api *PublicServerAPI) Chain() shared.ChainType {
|
||||
return shared.Ethereum
|
||||
// WatchAddress makes a geth WatchAddress API call with the given operation and args
|
||||
func (api *PublicServerAPI) WatchAddress(operation types.OperationType, args []types.WatchAddressArg) error {
|
||||
err := api.rpc.Call(nil, "statediff_watchAddress", operation, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
+40
-21
@@ -22,16 +22,18 @@ import (
|
||||
"math/big"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/postgres"
|
||||
"github.com/ethereum/go-ethereum/statediff"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/prom"
|
||||
ethServerShared "github.com/vulcanize/ipld-eth-server/pkg/shared"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/prom"
|
||||
ethServerShared "github.com/vulcanize/ipld-eth-server/v3/pkg/shared"
|
||||
)
|
||||
|
||||
// Env variables
|
||||
@@ -53,13 +55,15 @@ const (
|
||||
|
||||
VALIDATOR_ENABLED = "VALIDATOR_ENABLED"
|
||||
VALIDATOR_EVERY_NTH_BLOCK = "VALIDATOR_EVERY_NTH_BLOCK"
|
||||
|
||||
WATCHED_ADDRESS_GAP_FILLER_ENABLED = "WATCHED_ADDRESS_GAP_FILLER_ENABLED"
|
||||
WATCHED_ADDRESS_GAP_FILLER_INTERVAL = "WATCHED_ADDRESS_GAP_FILLER_INTERVAL"
|
||||
)
|
||||
|
||||
// Config struct
|
||||
type Config struct {
|
||||
DB *postgres.DB
|
||||
DBConfig postgres.ConnectionConfig
|
||||
DBParams postgres.ConnectionParams
|
||||
DB *sqlx.DB
|
||||
DBConfig postgres.Config
|
||||
|
||||
WSEnabled bool
|
||||
WSEndpoint string
|
||||
@@ -87,12 +91,16 @@ type Config struct {
|
||||
SupportStateDiff bool
|
||||
ForwardEthCalls bool
|
||||
ProxyOnError bool
|
||||
NodeNetworkID string
|
||||
|
||||
// Cache configuration.
|
||||
GroupCache *ethServerShared.GroupCacheConfig
|
||||
|
||||
StateValidationEnabled bool
|
||||
StateValidationEveryNthBlock uint64
|
||||
|
||||
WatchedAddressGapFillerEnabled bool
|
||||
WatchedAddressGapFillInterval int
|
||||
}
|
||||
|
||||
// NewConfig is used to initialize a watcher config from a .toml file
|
||||
@@ -112,6 +120,7 @@ func NewConfig() (*Config, error) {
|
||||
ethHTTP := viper.GetString("ethereum.httpPath")
|
||||
ethHTTPEndpoint := fmt.Sprintf("http://%s", ethHTTP)
|
||||
nodeInfo, cli, err := getEthNodeAndClient(ethHTTPEndpoint)
|
||||
c.NodeNetworkID = nodeInfo.NetworkID
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -198,12 +207,12 @@ func NewConfig() (*Config, error) {
|
||||
c.IpldGraphqlEnabled = ipldGraphqlEnabled
|
||||
|
||||
overrideDBConnConfig(&c.DBConfig)
|
||||
serveDB, err := postgres.NewDB(postgres.DbConnectionString(c.DBParams), c.DBConfig, nodeInfo)
|
||||
serveDB, err := ethServerShared.NewDB(c.DBConfig.DbConnectionString(), c.DBConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prom.RegisterDBCollector(c.DBParams.Name, serveDB.DB)
|
||||
prom.RegisterDBCollector(c.DBConfig.DatabaseName, serveDB)
|
||||
c.DB = serveDB
|
||||
|
||||
defaultSenderStr := viper.GetString("ethereum.defaultSender")
|
||||
@@ -219,25 +228,27 @@ func NewConfig() (*Config, error) {
|
||||
}
|
||||
chainConfigPath := viper.GetString("ethereum.chainConfig")
|
||||
if chainConfigPath != "" {
|
||||
c.ChainConfig, err = eth.LoadConfig(chainConfigPath)
|
||||
c.ChainConfig, err = statediff.LoadConfig(chainConfigPath)
|
||||
} else {
|
||||
c.ChainConfig, err = eth.ChainConfig(nodeInfo.ChainID)
|
||||
c.ChainConfig, err = statediff.ChainConfig(nodeInfo.ChainID)
|
||||
}
|
||||
|
||||
c.loadGroupCacheConfig()
|
||||
|
||||
c.loadValidatorConfig()
|
||||
|
||||
c.loadWatchedAddressGapFillerConfig()
|
||||
|
||||
return c, err
|
||||
}
|
||||
|
||||
func overrideDBConnConfig(con *postgres.ConnectionConfig) {
|
||||
func overrideDBConnConfig(con *postgres.Config) {
|
||||
viper.BindEnv("database.server.maxIdle", SERVER_MAX_IDLE_CONNECTIONS)
|
||||
viper.BindEnv("database.server.maxOpen", SERVER_MAX_OPEN_CONNECTIONS)
|
||||
viper.BindEnv("database.server.maxLifetime", SERVER_MAX_CONN_LIFETIME)
|
||||
con.MaxIdle = viper.GetInt("database.server.maxIdle")
|
||||
con.MaxOpen = viper.GetInt("database.server.maxOpen")
|
||||
con.MaxLifetime = viper.GetInt("database.server.maxLifetime")
|
||||
con.MaxConns = viper.GetInt("database.server.maxOpen")
|
||||
con.MaxConnLifetime = time.Duration(viper.GetInt("database.server.maxLifetime"))
|
||||
}
|
||||
|
||||
func (c *Config) dbInit() {
|
||||
@@ -250,14 +261,14 @@ func (c *Config) dbInit() {
|
||||
viper.BindEnv("database.maxOpen", DATABASE_MAX_OPEN_CONNECTIONS)
|
||||
viper.BindEnv("database.maxLifetime", DATABASE_MAX_CONN_LIFETIME)
|
||||
|
||||
c.DBParams.Name = viper.GetString("database.name")
|
||||
c.DBParams.Hostname = viper.GetString("database.hostname")
|
||||
c.DBParams.Port = viper.GetInt("database.port")
|
||||
c.DBParams.User = viper.GetString("database.user")
|
||||
c.DBParams.Password = viper.GetString("database.password")
|
||||
c.DBConfig.DatabaseName = viper.GetString("database.name")
|
||||
c.DBConfig.Hostname = viper.GetString("database.hostname")
|
||||
c.DBConfig.Port = viper.GetInt("database.port")
|
||||
c.DBConfig.Username = viper.GetString("database.user")
|
||||
c.DBConfig.Password = viper.GetString("database.password")
|
||||
c.DBConfig.MaxIdle = viper.GetInt("database.maxIdle")
|
||||
c.DBConfig.MaxOpen = viper.GetInt("database.maxOpen")
|
||||
c.DBConfig.MaxLifetime = viper.GetInt("database.maxLifetime")
|
||||
c.DBConfig.MaxConns = viper.GetInt("database.maxOpen")
|
||||
c.DBConfig.MaxConnLifetime = time.Duration(viper.GetInt("database.maxLifetime"))
|
||||
}
|
||||
|
||||
func (c *Config) loadGroupCacheConfig() {
|
||||
@@ -290,3 +301,11 @@ func (c *Config) loadValidatorConfig() {
|
||||
c.StateValidationEnabled = viper.GetBool("validator.enabled")
|
||||
c.StateValidationEveryNthBlock = viper.GetUint64("validator.everyNthBlock")
|
||||
}
|
||||
|
||||
func (c *Config) loadWatchedAddressGapFillerConfig() {
|
||||
viper.BindEnv("watch.fill.enabled", WATCHED_ADDRESS_GAP_FILLER_ENABLED)
|
||||
viper.BindEnv("watch.fill.interval", WATCHED_ADDRESS_GAP_FILLER_INTERVAL)
|
||||
|
||||
c.WatchedAddressGapFillerEnabled = viper.GetBool("watch.fill.enabled")
|
||||
c.WatchedAddressGapFillInterval = viper.GetInt("watch.fill.interval")
|
||||
}
|
||||
|
||||
@@ -28,11 +28,11 @@ import (
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/postgres"
|
||||
"github.com/jmoiron/sqlx"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/net"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/net"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -74,7 +74,7 @@ type Service struct {
|
||||
// A mapping of subscription params hash to the corresponding subscription params
|
||||
SubscriptionTypes map[common.Hash]eth.SubscriptionSettings
|
||||
// Underlying db
|
||||
db *postgres.DB
|
||||
db *sqlx.DB
|
||||
// wg for syncing serve processes
|
||||
serveWg *sync.WaitGroup
|
||||
// rpc client for forwarding cache misses
|
||||
@@ -87,6 +87,8 @@ type Service struct {
|
||||
forwardEthCalls bool
|
||||
// whether to forward all calls to proxy node if they throw an error locally
|
||||
proxyOnError bool
|
||||
// eth node network id
|
||||
nodeNetworkId string
|
||||
}
|
||||
|
||||
// NewServer creates a new Server using an underlying Service struct
|
||||
@@ -103,6 +105,7 @@ func NewServer(settings *Config) (Server, error) {
|
||||
sap.supportsStateDiffing = settings.SupportStateDiff
|
||||
sap.forwardEthCalls = settings.ForwardEthCalls
|
||||
sap.proxyOnError = settings.ProxyOnError
|
||||
sap.nodeNetworkId = settings.NodeNetworkID
|
||||
var err error
|
||||
sap.backend, err = eth.NewEthBackend(sap.db, ð.Config{
|
||||
ChainConfig: settings.ChainConfig,
|
||||
@@ -121,12 +124,12 @@ func (sap *Service) Protocols() []p2p.Protocol {
|
||||
|
||||
// APIs returns the RPC descriptors the watcher service offers
|
||||
func (sap *Service) APIs() []rpc.API {
|
||||
networkID, _ := strconv.ParseUint(sap.db.Node.NetworkID, 10, 64)
|
||||
networkID, _ := strconv.ParseUint(sap.nodeNetworkId, 10, 64)
|
||||
apis := []rpc.API{
|
||||
{
|
||||
Namespace: APIName,
|
||||
Version: APIVersion,
|
||||
Service: NewPublicServerAPI(sap),
|
||||
Service: NewPublicServerAPI(sap, sap.client),
|
||||
Public: true,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// VulcanizeDB
|
||||
// Copyright © 2022 Vulcanize
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package shared
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
// NewDB creates a new db connection and initializes the connection pool
|
||||
func NewDB(connectString string, config postgres.Config) (*sqlx.DB, error) {
|
||||
db, connectErr := sqlx.Connect("postgres", connectString)
|
||||
if connectErr != nil {
|
||||
return nil, postgres.ErrDBConnectionFailed(connectErr)
|
||||
}
|
||||
if config.MaxConns > 0 {
|
||||
db.SetMaxOpenConns(config.MaxConns)
|
||||
}
|
||||
if config.MaxIdle > 0 {
|
||||
db.SetMaxIdleConns(config.MaxIdle)
|
||||
}
|
||||
if config.MaxConnLifetime > 0 {
|
||||
db.SetConnMaxLifetime(config.MaxConnLifetime)
|
||||
}
|
||||
|
||||
return db, nil
|
||||
}
|
||||
@@ -18,7 +18,7 @@ package shared
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/ipfs/ipld"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/ipld"
|
||||
"github.com/ipfs/go-cid"
|
||||
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
||||
dshelp "github.com/ipfs/go-ipfs-ds-help"
|
||||
|
||||
@@ -18,12 +18,24 @@ package shared
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/ipfs"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/models"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/node"
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
// IPLDsContainBytes used to check if a list of strings contains a particular string
|
||||
func IPLDsContainBytes(iplds []ipfs.BlockModel, b []byte) bool {
|
||||
func IPLDsContainBytes(iplds []models.IPLDModel, b []byte) bool {
|
||||
for _, ipld := range iplds {
|
||||
if bytes.Equal(ipld.Data, b) {
|
||||
return true
|
||||
@@ -31,3 +43,65 @@ func IPLDsContainBytes(iplds []ipfs.BlockModel, b []byte) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// SetupDB is use to setup a db for watcher tests
|
||||
func SetupDB() *sqlx.DB {
|
||||
config := getTestDBConfig()
|
||||
|
||||
db, err := NewDB(config.DbConnectionString(), config)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
return db
|
||||
}
|
||||
|
||||
// TearDownDB is used to tear down the watcher dbs after tests
|
||||
func TearDownDB(db *sqlx.DB) {
|
||||
tx, err := db.Beginx()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = tx.Exec(`DELETE FROM eth.header_cids`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = tx.Exec(`DELETE FROM eth.transaction_cids`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = tx.Exec(`DELETE FROM eth.receipt_cids`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = tx.Exec(`DELETE FROM eth.state_cids`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = tx.Exec(`DELETE FROM eth.storage_cids`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = tx.Exec(`DELETE FROM blocks`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = tx.Exec(`DELETE FROM eth.log_cids`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = tx.Exec(`DELETE FROM eth_meta.watched_addresses`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = tx.Commit()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
func SetupTestStateDiffIndexer(ctx context.Context, chainConfig *params.ChainConfig, genHash common.Hash) interfaces.StateDiffIndexer {
|
||||
testInfo := node.Info{
|
||||
GenesisBlock: genHash.String(),
|
||||
NetworkID: "1",
|
||||
ID: "1",
|
||||
ClientName: "geth",
|
||||
ChainID: params.TestChainConfig.ChainID.Uint64(),
|
||||
}
|
||||
|
||||
_, stateDiffIndexer, err := indexer.NewStateDiffIndexer(ctx, chainConfig, testInfo, getTestDBConfig())
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
return stateDiffIndexer
|
||||
}
|
||||
|
||||
func getTestDBConfig() postgres.Config {
|
||||
port, _ := strconv.Atoi(os.Getenv("DATABASE_PORT"))
|
||||
return postgres.Config{
|
||||
Hostname: os.Getenv("DATABASE_HOSTNAME"),
|
||||
DatabaseName: os.Getenv("DATABASE_NAME"),
|
||||
Username: os.Getenv("DATABASE_USER"),
|
||||
Password: os.Getenv("DATABASE_PASSWORD"),
|
||||
Port: port,
|
||||
Driver: postgres.SQLX,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,16 +3,9 @@ set -o xtrace
|
||||
|
||||
export ETH_FORWARD_ETH_CALLS=false
|
||||
export DB_WRITE=true
|
||||
export ETH_HTTP_PATH=""
|
||||
export ETH_PROXY_ON_ERROR=false
|
||||
|
||||
# Clear up existing docker images and volume.
|
||||
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 ipld-eth-db dapptools contract eth-server
|
||||
export WATCHED_ADDRESS_GAP_FILLER_ENABLED=false
|
||||
export WATCHED_ADDRESS_GAP_FILLER_INTERVAL=5
|
||||
|
||||
export PGPASSWORD=password
|
||||
export DATABASE_USER=vdbm
|
||||
|
||||
Regular → Executable
+2
-9
@@ -3,16 +3,9 @@ set -o xtrace
|
||||
|
||||
export ETH_FORWARD_ETH_CALLS=true
|
||||
export DB_WRITE=false
|
||||
export ETH_HTTP_PATH="dapptools:8545"
|
||||
export ETH_PROXY_ON_ERROR=false
|
||||
|
||||
# Clear up existing docker images and volume.
|
||||
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 ipld-eth-db dapptools contract eth-server
|
||||
export WATCHED_ADDRESS_GAP_FILLER_ENABLED=false
|
||||
export WATCHED_ADDRESS_GAP_FILLER_INTERVAL=5
|
||||
|
||||
export PGPASSWORD=password
|
||||
export DATABASE_USER=vdbm
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
set -e
|
||||
set -o xtrace
|
||||
|
||||
export ETH_FORWARD_ETH_CALLS=false
|
||||
export DB_WRITE=true
|
||||
export ETH_PROXY_ON_ERROR=false
|
||||
export WATCHED_ADDRESS_GAP_FILLER_ENABLED=true
|
||||
export WATCHED_ADDRESS_GAP_FILLER_INTERVAL=5
|
||||
|
||||
export PGPASSWORD=password
|
||||
export DATABASE_USER=vdbm
|
||||
export DATABASE_PORT=8077
|
||||
export DATABASE_PASSWORD=password
|
||||
export DATABASE_HOSTNAME=127.0.0.1
|
||||
|
||||
# Wait for containers to be up and execute the integration test.
|
||||
while [ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8081)" != "200" ]; do echo "waiting for ipld-eth-server..." && sleep 5; done && \
|
||||
while [ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8545)" != "200" ]; do echo "waiting for geth-statediff..." && sleep 5; done && \
|
||||
make integrationtest
|
||||
@@ -1,5 +1,8 @@
|
||||
# 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 DATABASE_NAME=vulcanize_testing make test
|
||||
docker-compose -f docker-compose.yml up -d ipld-eth-db
|
||||
sleep 10
|
||||
PGPASSWORD=password DATABASE_USER=vdbm DATABASE_PORT=8077 DATABASE_PASSWORD=password DATABASE_HOSTNAME=127.0.0.1 DATABASE_NAME=vulcanize_testing make test
|
||||
|
||||
docker-compose down --remove-orphans --volumes
|
||||
|
||||
+109
-12
@@ -1,15 +1,112 @@
|
||||
# Test Insructions
|
||||
|
||||
Spin up services:
|
||||
```
|
||||
docker-compose -f docker-compose.test.yml -f docker-compose.yml up -d db dapptools contract eth-server
|
||||
```
|
||||
## Setup
|
||||
|
||||
Running unit tests:
|
||||
```bash
|
||||
make test_local
|
||||
```
|
||||
- Clone [stack-orchestrator](https://github.com/vulcanize/stack-orchestrator) and [go-ethereum](https://github.com/vulcanize/go-ethereum) repositories.
|
||||
|
||||
Running integration test:
|
||||
```bash
|
||||
make integrationtest_local
|
||||
```
|
||||
- Checkout [v3 release](https://github.com/vulcanize/go-ethereum/releases/tag/v1.10.17-statediff-3.2.0) in go-ethereum repo.
|
||||
```bash
|
||||
# In go-ethereum repo.
|
||||
git checkout v1.10.17-statediff-3.2.0
|
||||
```
|
||||
|
||||
- Checkout working commit in stack-orchestrator repo.
|
||||
```bash
|
||||
# In stack-orchestrator repo.
|
||||
git checkout fcbc74451c5494664fe21f765e89c9c6565c07cb
|
||||
```
|
||||
|
||||
## Run
|
||||
|
||||
- Run unit tests:
|
||||
|
||||
```bash
|
||||
# In ipld-eth-server root directory.
|
||||
./scripts/run_unit_test.sh
|
||||
```
|
||||
|
||||
- Run integration tests:
|
||||
|
||||
- Update (Replace existing content) config file [config.sh](https://github.com/vulcanize/stack-orchestrator/blob/main/config.sh) in stack-orchestrator repo:
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
# Path to go-ethereum repo.
|
||||
vulcanize_go_ethereum=~/go-ethereum/
|
||||
|
||||
# Path to ipld-eth-server repo.
|
||||
vulcanize_ipld_eth_server=~/ipld-eth-server/
|
||||
|
||||
db_write=true
|
||||
eth_forward_eth_calls=false
|
||||
eth_proxy_on_error=false
|
||||
eth_http_path="go-ethereum:8545"
|
||||
```
|
||||
|
||||
- Run stack-orchestrator:
|
||||
```bash
|
||||
# In stack-orchestrator root directory.
|
||||
cd helper-scripts
|
||||
|
||||
./wrapper.sh \
|
||||
-e docker \
|
||||
-d ../docker/latest/docker-compose-db.yml \
|
||||
-d ../docker/local/docker-compose-go-ethereum.yml \
|
||||
-d ../docker/local/docker-compose-ipld-eth-server.yml \
|
||||
-v remove \
|
||||
-p ../config.sh
|
||||
```
|
||||
|
||||
- Run test:
|
||||
```bash
|
||||
# In ipld-eth-server root directory.
|
||||
./scripts/run_integration_test.sh
|
||||
```
|
||||
|
||||
- Update `config.sh` file:
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
# Path to go-ethereum repo.
|
||||
vulcanize_go_ethereum=~/go-ethereum/
|
||||
|
||||
# Path to ipld-eth-server repo.
|
||||
vulcanize_ipld_eth_server=~/ipld-eth-server/
|
||||
|
||||
db_write=false
|
||||
eth_forward_eth_calls=true
|
||||
eth_proxy_on_error=false
|
||||
eth_http_path="go-ethereum:8545"
|
||||
```
|
||||
|
||||
- Stop the stack-orchestrator and start again using the same command
|
||||
|
||||
- Run integration tests for direct proxy fall-through of eth_calls:
|
||||
```bash
|
||||
./scripts/run_integration_test_forward_eth_calls.sh
|
||||
```
|
||||
|
||||
- Update `config.sh` file:
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
# Path to go-ethereum repo.
|
||||
vulcanize_go_ethereum=~/go-ethereum/
|
||||
|
||||
# Path to ipld-eth-server repo.
|
||||
vulcanize_ipld_eth_server=~/ipld-eth-server/
|
||||
|
||||
db_write=true
|
||||
eth_forward_eth_calls=false
|
||||
eth_proxy_on_error=false
|
||||
eth_http_path="go-ethereum:8545"
|
||||
watched_addres_gap_filler_enabled=true
|
||||
watched_addres_gap_filler_interval=5
|
||||
```
|
||||
|
||||
- Stop the stack-orchestrator and start again using the same command
|
||||
|
||||
- Run integration tests for watched addresses with gap filling service enabled:
|
||||
```bash
|
||||
./scripts/run_integration_test_watched_address_gap_filler.sh
|
||||
```
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
contract SLVToken is ERC20 {
|
||||
uint256 private countA;
|
||||
uint256 private countB;
|
||||
|
||||
constructor() ERC20("Silver", "SLV") {}
|
||||
|
||||
function incrementCountA() public {
|
||||
countA = countA + 1;
|
||||
}
|
||||
|
||||
function incrementCountB() public {
|
||||
countB = countB + 1;
|
||||
}
|
||||
|
||||
receive() external payable {}
|
||||
|
||||
function destroy() public {
|
||||
selfdestruct(payable(msg.sender));
|
||||
}
|
||||
}
|
||||
@@ -17,15 +17,26 @@ task("accounts", "Prints the list of accounts", async () => {
|
||||
* @type import('hardhat/config').HardhatUserConfig
|
||||
*/
|
||||
module.exports = {
|
||||
solidity: "0.8.0",
|
||||
solidity: {
|
||||
version: "0.8.0",
|
||||
settings: {
|
||||
outputSelection: {
|
||||
'*': {
|
||||
'*': [
|
||||
'abi', 'storageLayout',
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
networks: {
|
||||
local: {
|
||||
url: 'http://127.0.0.1:8545',
|
||||
chainId: 4
|
||||
chainId: 99
|
||||
},
|
||||
docker: {
|
||||
url: process.env.ETH_ADDR,
|
||||
chainId: 4
|
||||
chainId: 99
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Generated
+46
-95
@@ -5,12 +5,14 @@
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "contract",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@openzeppelin/contracts": "^4.0.0",
|
||||
"fastify": "^3.14.2",
|
||||
"hardhat": "^2.2.0"
|
||||
"hardhat": "^2.2.0",
|
||||
"solidity-create2-deployer": "^0.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
||||
@@ -254,10 +256,10 @@
|
||||
"@resolver-engine/imports-fs": "^0.3.3",
|
||||
"@typechain/ethers-v5": "^2.0.0",
|
||||
"@types/mkdirp": "^0.5.2",
|
||||
"@types/node-fetch": "^2.5.5",
|
||||
"@types/node-fetch": "^2.6.7",
|
||||
"ethers": "^5.0.1",
|
||||
"mkdirp": "^0.5.1",
|
||||
"node-fetch": "^2.6.0",
|
||||
"node-fetch": "^2.6.7",
|
||||
"solc": "^0.6.3",
|
||||
"ts-generator": "^0.1.1",
|
||||
"typechain": "^3.0.0"
|
||||
@@ -468,7 +470,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/abi/-/abi-5.1.0.tgz",
|
||||
"integrity": "sha512-N/W9Sbn1/C6Kh2kuHRjf/hX6euMK4+9zdJRBB8sDWmihVntjUAfxbusGZKzDQD8i3szAHhTz8K7XADV5iFNfJw==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -495,7 +496,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/abstract-provider/-/abstract-provider-5.1.0.tgz",
|
||||
"integrity": "sha512-8dJUnT8VNvPwWhYIau4dwp7qe1g+KgdRm4XTWvjkI9gAT2zZa90WF5ApdZ3vl1r6NDmnn6vUVvyphClRZRteTQ==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -520,7 +520,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/abstract-signer/-/abstract-signer-5.1.0.tgz",
|
||||
"integrity": "sha512-qQDMkjGZSSJSKl6AnfTgmz9FSnzq3iEoEbHTYwjDlEAv+LNP7zd4ixCcVWlWyk+2siud856M5CRhAmPdupeN9w==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -543,7 +542,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/address/-/address-5.1.0.tgz",
|
||||
"integrity": "sha512-rfWQR12eHn2cpstCFS4RF7oGjfbkZb0oqep+BfrT+gWEGWG2IowJvIsacPOvzyS1jhNF4MQ4BS59B04Mbovteg==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -566,7 +564,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/base64/-/base64-5.1.0.tgz",
|
||||
"integrity": "sha512-npD1bLvK4Bcxz+m4EMkx+F8Rd7CnqS9DYnhNu0/GlQBXhWjvfoAZzk5HJ0f1qeyp8d+A86PTuzLOGOXf4/CN8g==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -585,7 +582,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/basex/-/basex-5.1.0.tgz",
|
||||
"integrity": "sha512-vBKr39bum7DDbOvkr1Sj19bRMEPA4FnST6Utt6xhDzI7o7L6QNkDn2yrCfP+hnvJGhZFKtLygWwqlTBZoBXYLg==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -605,7 +601,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/bignumber/-/bignumber-5.1.0.tgz",
|
||||
"integrity": "sha512-wUvQlhTjPjFXIdLPOuTrFeQmSa6Wvls1bGXQNQWvB/SEn1NsTCE8PmumIEZxmOPjSHl1eV2uyHP5jBm5Cgj92Q==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -626,7 +621,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/bytes/-/bytes-5.1.0.tgz",
|
||||
"integrity": "sha512-sGTxb+LVjFxJcJeUswAIK6ncgOrh3D8c192iEJd7mLr95V6du119rRfYT/b87WPkZ5I3gRBUYIYXtdgCWACe8g==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -645,7 +639,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/constants/-/constants-5.1.0.tgz",
|
||||
"integrity": "sha512-0/SuHrxc8R8k+JiLmJymxHJbojUDWBQqO+b+XFdwaP0jGzqC09YDy/CAlSZB6qHsBifY8X3I89HcK/oMqxRdBw==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -664,7 +657,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/contracts/-/contracts-5.1.0.tgz",
|
||||
"integrity": "sha512-dvTMs/4XGSc57cYOW0KjgX1NdTujUu7mNb6PQdJWg08m9ULzPyGZuBkFJnijBcp6vTOCQ59RwjboWgNWw393og==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -692,7 +684,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/hash/-/hash-5.1.0.tgz",
|
||||
"integrity": "sha512-fNwry20yLLPpnRRwm3fBL+2ksgO+KMadxM44WJmRIoTKzy4269+rbq9KFoe2LTqq2CXJM2CE70beGaNrpuqflQ==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -718,7 +709,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/hdnode/-/hdnode-5.1.0.tgz",
|
||||
"integrity": "sha512-obIWdlujloExPHWJGmhJO/sETOOo7SEb6qemV4f8kyFoXg+cJK+Ta9SvBrj7hsUK85n3LZeZJZRjjM7oez3Clg==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -748,7 +738,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/json-wallets/-/json-wallets-5.1.0.tgz",
|
||||
"integrity": "sha512-00n2iBy27w8zrGZSiU762UOVuzCQZxUZxopsZC47++js6xUFuI74DHcJ5K/2pddlF1YBskvmMuboEu1geK8mnA==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -779,7 +768,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/keccak256/-/keccak256-5.1.0.tgz",
|
||||
"integrity": "sha512-vrTB1W6AEYoadww5c9UyVJ2YcSiyIUTNDRccZIgwTmFFoSHwBtcvG1hqy9RzJ1T0bMdATbM9Hfx2mJ6H0i7Hig==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -798,14 +786,12 @@
|
||||
"node_modules/@ethersproject/keccak256/node_modules/js-sha3": {
|
||||
"version": "0.5.7",
|
||||
"resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.5.7.tgz",
|
||||
"integrity": "sha1-DU/9gALVMzqrr0oj7tL2N0yfKOc=",
|
||||
"dev": true
|
||||
"integrity": "sha1-DU/9gALVMzqrr0oj7tL2N0yfKOc="
|
||||
},
|
||||
"node_modules/@ethersproject/logger": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/logger/-/logger-5.1.0.tgz",
|
||||
"integrity": "sha512-wtUaD1lBX10HBXjjKV9VHCBnTdUaKQnQ2XSET1ezglqLdPdllNOIlLfhyCRqXm5xwcjExVI5ETokOYfjPtaAlw==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -821,7 +807,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/networks/-/networks-5.1.0.tgz",
|
||||
"integrity": "sha512-A/NIrIED/G/IgU1XUukOA3WcFRxn2I4O5GxsYGA5nFlIi+UZWdGojs85I1VXkR1gX9eFnDXzjE6OtbgZHjFhIA==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -840,7 +825,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/pbkdf2/-/pbkdf2-5.1.0.tgz",
|
||||
"integrity": "sha512-B8cUbHHTgs8OtgJIafrRcz/YPDobVd5Ru8gTnShOiM9EBuFpYHQpq3+8iQJ6pyczDu6HP/oc/njAsIBhwFZYew==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -860,7 +844,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/properties/-/properties-5.1.0.tgz",
|
||||
"integrity": "sha512-519KKTwgmH42AQL3+GFV3SX6khYEfHsvI6v8HYejlkigSDuqttdgVygFTDsGlofNFchhDwuclrxQnD5B0YLNMg==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -879,7 +862,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/providers/-/providers-5.1.0.tgz",
|
||||
"integrity": "sha512-FjpZL2lSXrYpQDg2fMjugZ0HjQD9a+2fOOoRhhihh+Z+qi/xZ8vIlPoumrEP1DzIG4DBV6liUqLNqnX2C6FIAA==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -916,7 +898,6 @@
|
||||
"version": "7.2.3",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.2.3.tgz",
|
||||
"integrity": "sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=8.3.0"
|
||||
},
|
||||
@@ -937,7 +918,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/random/-/random-5.1.0.tgz",
|
||||
"integrity": "sha512-+uuczLQZ4+no9cP6TCoCktXx0u2YbNaRT7lRkSt12d8263e702f0u+4JnnRO8Qmv5nylWJebnqCHzyxP+6mLqw==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -957,7 +937,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/rlp/-/rlp-5.1.0.tgz",
|
||||
"integrity": "sha512-vDTyHIwNPrecy55gKGZ47eJZhBm8LLBxihzi5ou+zrSvYTpkSTWRcKUlXFDFQVwfWB+P5PGyERAdiDEI76clxw==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -977,7 +956,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/sha2/-/sha2-5.1.0.tgz",
|
||||
"integrity": "sha512-+fNSeZRstOpdRJpdGUkRONFCaiAqWkc91zXgg76Nlp5ndBQE25Kk5yK8gCPG1aGnCrbariiPr5j9DmrYH78JCA==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -998,7 +976,6 @@
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.3.tgz",
|
||||
"integrity": "sha512-/UETyP0W22QILqS+6HowevwhEFJ3MBJnwTf75Qob9Wz9t0DPuisL8kW8YZMK62dHAKE1c1p+gY1TtOLY+USEHA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"inherits": "^2.0.3",
|
||||
"minimalistic-assert": "^1.0.0"
|
||||
@@ -1008,7 +985,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/signing-key/-/signing-key-5.1.0.tgz",
|
||||
"integrity": "sha512-tE5LFlbmdObG8bY04NpuwPWSRPgEswfxweAI1sH7TbP0ml1elNfqcq7ii/3AvIN05i5U0Pkm3Tf8bramt8MmLw==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -1031,7 +1007,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/solidity/-/solidity-5.1.0.tgz",
|
||||
"integrity": "sha512-kPodsGyo9zg1g9XSXp1lGhFaezBAUUsAUB1Vf6OkppE5Wksg4Et+x3kG4m7J/uShDMP2upkJtHNsIBK2XkVpKQ==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -1054,7 +1029,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/strings/-/strings-5.1.0.tgz",
|
||||
"integrity": "sha512-perBZy0RrmmL0ejiFGUOlBVjMsUceqLut3OBP3zP96LhiJWWbS8u1NqQVgN4/Gyrbziuda66DxiQocXhsvx+Sw==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -1075,7 +1049,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/transactions/-/transactions-5.1.0.tgz",
|
||||
"integrity": "sha512-s10crRLZEA0Bgv6FGEl/AKkTw9f+RVUrlWDX1rHnD4ZncPFeiV2AJr4nT7QSUhxJdFPvjyKRDb3nEH27dIqcPQ==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -1102,7 +1075,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/units/-/units-5.1.0.tgz",
|
||||
"integrity": "sha512-isvJrx6qG0nKWfxsGORNjmOq/nh175fStfvRTA2xEKrGqx8JNJY83fswu4GkILowfriEM/eYpretfJnfzi7YhA==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -1123,7 +1095,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/wallet/-/wallet-5.1.0.tgz",
|
||||
"integrity": "sha512-ULmUtiYQLTUS+y3DgkLzRhFEK10zMwmjOthnjiZxee3Q/MVwr3rnmuAnXIUZrPjna6hvUPnyRIdW5XuF0Ld0YQ==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -1156,7 +1127,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/web/-/web-5.1.0.tgz",
|
||||
"integrity": "sha512-LTeluWgTq04+RNqAkVhpydPcRZK/kKxD2Vy7PYGrAD27ABO9kTqTBKwiOuzTyAHKUQHfnvZbXmxBXJAGViSDcA==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -1179,7 +1149,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/wordlists/-/wordlists-5.1.0.tgz",
|
||||
"integrity": "sha512-NsUCi/TpBb+oTFvMSccUkJGtp5o/84eOyqp5q5aBeiNBSLkYyw21znRn9mAmxZgySpxgruVgKbaapnYPgvctPQ==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -1506,7 +1475,7 @@
|
||||
"integrity": "sha512-dueRKfaJL4RTtSa7bWeTK1M+VH+Gns73oCgzvYfHZywRCoPSd8EkXBL0mZ9unPTveBn+D9phZBaxuzpwjWkW0g=="
|
||||
},
|
||||
"node_modules/@types/node-fetch": {
|
||||
"version": "2.5.10",
|
||||
"version": "2.6.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.10.tgz",
|
||||
"integrity": "sha512-IpkX0AasN44hgEad0gEF/V6EgR5n69VEqPEgnmoM8GsIGro3PowbWs4tR6IhxUTyPLpOn+fiGG6nrQhcmoCuIQ==",
|
||||
"dev": true,
|
||||
@@ -1629,8 +1598,7 @@
|
||||
"node_modules/aes-js": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.0.0.tgz",
|
||||
"integrity": "sha1-4h3xCtbCBTKVvLuNq0Cwnb6ofk0=",
|
||||
"dev": true
|
||||
"integrity": "sha1-4h3xCtbCBTKVvLuNq0Cwnb6ofk0="
|
||||
},
|
||||
"node_modules/agent-base": {
|
||||
"version": "6.0.2",
|
||||
@@ -1869,8 +1837,7 @@
|
||||
"node_modules/bech32": {
|
||||
"version": "1.1.4",
|
||||
"resolved": "https://registry.npmjs.org/bech32/-/bech32-1.1.4.tgz",
|
||||
"integrity": "sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ==",
|
||||
"dev": true
|
||||
"integrity": "sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ=="
|
||||
},
|
||||
"node_modules/binary-extensions": {
|
||||
"version": "2.2.0",
|
||||
@@ -2773,7 +2740,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/ethers/-/ethers-5.1.0.tgz",
|
||||
"integrity": "sha512-2L6Ge6wMBw02FlRoCLg4E0Elt3khMNlW6ULawa10mMeeZToYJ5+uCfiuTuB+XZ6om1Y7wuO9ZzezP8FsU2M/+g==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -3093,7 +3059,7 @@
|
||||
"integrity": "sha512-4zPxDyhCyiN2wIAtSLI6gc82/EjqZc1onI4Mz/l0pWrAlsSfYH/2ZIcU+e3oA2wDwbzIWNKwa23F8rh6+DRWkw=="
|
||||
},
|
||||
"node_modules/follow-redirects": {
|
||||
"version": "1.13.3",
|
||||
"version": "1.14.7",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.3.tgz",
|
||||
"integrity": "sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA==",
|
||||
"funding": [
|
||||
@@ -12519,7 +12485,7 @@
|
||||
"merkle-patricia-tree": "^4.1.0",
|
||||
"mnemonist": "^0.38.0",
|
||||
"mocha": "^7.1.2",
|
||||
"node-fetch": "^2.6.0",
|
||||
"node-fetch": "^2.6.7",
|
||||
"qs": "^6.7.0",
|
||||
"raw-body": "^2.4.1",
|
||||
"resolve": "1.17.0",
|
||||
@@ -13722,7 +13688,7 @@
|
||||
}
|
||||
},
|
||||
"node_modules/node-fetch": {
|
||||
"version": "2.6.1",
|
||||
"version": "2.6.7",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
|
||||
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==",
|
||||
"engines": {
|
||||
@@ -14696,7 +14662,7 @@
|
||||
"dependencies": {
|
||||
"command-exists": "^1.2.8",
|
||||
"commander": "3.0.2",
|
||||
"follow-redirects": "^1.12.1",
|
||||
"follow-redirects": "^1.14.7",
|
||||
"fs-extra": "^0.30.0",
|
||||
"js-sha3": "0.8.0",
|
||||
"memorystream": "^0.3.1",
|
||||
@@ -14739,6 +14705,17 @@
|
||||
"semver": "bin/semver"
|
||||
}
|
||||
},
|
||||
"node_modules/solidity-create2-deployer": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/solidity-create2-deployer/-/solidity-create2-deployer-0.4.0.tgz",
|
||||
"integrity": "sha512-bB5d8fPt4dWsOoRodrsyfWKcjiv77IFl84+e6EckMMGYlfL2ZFqUoMz6tnqqiUFrM9abF1p6dWFOgJ/3zVc8yQ==",
|
||||
"dependencies": {
|
||||
"ethers": "^5.0.14"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/sonic-boom": {
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-1.4.1.tgz",
|
||||
@@ -15856,10 +15833,10 @@
|
||||
"@resolver-engine/imports-fs": "^0.3.3",
|
||||
"@typechain/ethers-v5": "^2.0.0",
|
||||
"@types/mkdirp": "^0.5.2",
|
||||
"@types/node-fetch": "^2.5.5",
|
||||
"@types/node-fetch": "^2.6.7",
|
||||
"ethers": "^5.0.1",
|
||||
"mkdirp": "^0.5.1",
|
||||
"node-fetch": "^2.6.0",
|
||||
"node-fetch": "^2.6.7",
|
||||
"solc": "^0.6.3",
|
||||
"ts-generator": "^0.1.1",
|
||||
"typechain": "^3.0.0"
|
||||
@@ -16055,7 +16032,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/abi/-/abi-5.1.0.tgz",
|
||||
"integrity": "sha512-N/W9Sbn1/C6Kh2kuHRjf/hX6euMK4+9zdJRBB8sDWmihVntjUAfxbusGZKzDQD8i3szAHhTz8K7XADV5iFNfJw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/address": "^5.1.0",
|
||||
"@ethersproject/bignumber": "^5.1.0",
|
||||
@@ -16072,7 +16048,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/abstract-provider/-/abstract-provider-5.1.0.tgz",
|
||||
"integrity": "sha512-8dJUnT8VNvPwWhYIau4dwp7qe1g+KgdRm4XTWvjkI9gAT2zZa90WF5ApdZ3vl1r6NDmnn6vUVvyphClRZRteTQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/bignumber": "^5.1.0",
|
||||
"@ethersproject/bytes": "^5.1.0",
|
||||
@@ -16087,7 +16062,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/abstract-signer/-/abstract-signer-5.1.0.tgz",
|
||||
"integrity": "sha512-qQDMkjGZSSJSKl6AnfTgmz9FSnzq3iEoEbHTYwjDlEAv+LNP7zd4ixCcVWlWyk+2siud856M5CRhAmPdupeN9w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/abstract-provider": "^5.1.0",
|
||||
"@ethersproject/bignumber": "^5.1.0",
|
||||
@@ -16100,7 +16074,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/address/-/address-5.1.0.tgz",
|
||||
"integrity": "sha512-rfWQR12eHn2cpstCFS4RF7oGjfbkZb0oqep+BfrT+gWEGWG2IowJvIsacPOvzyS1jhNF4MQ4BS59B04Mbovteg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/bignumber": "^5.1.0",
|
||||
"@ethersproject/bytes": "^5.1.0",
|
||||
@@ -16113,7 +16086,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/base64/-/base64-5.1.0.tgz",
|
||||
"integrity": "sha512-npD1bLvK4Bcxz+m4EMkx+F8Rd7CnqS9DYnhNu0/GlQBXhWjvfoAZzk5HJ0f1qeyp8d+A86PTuzLOGOXf4/CN8g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/bytes": "^5.1.0"
|
||||
}
|
||||
@@ -16122,7 +16094,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/basex/-/basex-5.1.0.tgz",
|
||||
"integrity": "sha512-vBKr39bum7DDbOvkr1Sj19bRMEPA4FnST6Utt6xhDzI7o7L6QNkDn2yrCfP+hnvJGhZFKtLygWwqlTBZoBXYLg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/bytes": "^5.1.0",
|
||||
"@ethersproject/properties": "^5.1.0"
|
||||
@@ -16132,7 +16103,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/bignumber/-/bignumber-5.1.0.tgz",
|
||||
"integrity": "sha512-wUvQlhTjPjFXIdLPOuTrFeQmSa6Wvls1bGXQNQWvB/SEn1NsTCE8PmumIEZxmOPjSHl1eV2uyHP5jBm5Cgj92Q==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/bytes": "^5.1.0",
|
||||
"@ethersproject/logger": "^5.1.0",
|
||||
@@ -16143,7 +16113,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/bytes/-/bytes-5.1.0.tgz",
|
||||
"integrity": "sha512-sGTxb+LVjFxJcJeUswAIK6ncgOrh3D8c192iEJd7mLr95V6du119rRfYT/b87WPkZ5I3gRBUYIYXtdgCWACe8g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/logger": "^5.1.0"
|
||||
}
|
||||
@@ -16152,7 +16121,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/constants/-/constants-5.1.0.tgz",
|
||||
"integrity": "sha512-0/SuHrxc8R8k+JiLmJymxHJbojUDWBQqO+b+XFdwaP0jGzqC09YDy/CAlSZB6qHsBifY8X3I89HcK/oMqxRdBw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/bignumber": "^5.1.0"
|
||||
}
|
||||
@@ -16161,7 +16129,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/contracts/-/contracts-5.1.0.tgz",
|
||||
"integrity": "sha512-dvTMs/4XGSc57cYOW0KjgX1NdTujUu7mNb6PQdJWg08m9ULzPyGZuBkFJnijBcp6vTOCQ59RwjboWgNWw393og==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/abi": "^5.1.0",
|
||||
"@ethersproject/abstract-provider": "^5.1.0",
|
||||
@@ -16179,7 +16146,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/hash/-/hash-5.1.0.tgz",
|
||||
"integrity": "sha512-fNwry20yLLPpnRRwm3fBL+2ksgO+KMadxM44WJmRIoTKzy4269+rbq9KFoe2LTqq2CXJM2CE70beGaNrpuqflQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/abstract-signer": "^5.1.0",
|
||||
"@ethersproject/address": "^5.1.0",
|
||||
@@ -16195,7 +16161,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/hdnode/-/hdnode-5.1.0.tgz",
|
||||
"integrity": "sha512-obIWdlujloExPHWJGmhJO/sETOOo7SEb6qemV4f8kyFoXg+cJK+Ta9SvBrj7hsUK85n3LZeZJZRjjM7oez3Clg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/abstract-signer": "^5.1.0",
|
||||
"@ethersproject/basex": "^5.1.0",
|
||||
@@ -16215,7 +16180,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/json-wallets/-/json-wallets-5.1.0.tgz",
|
||||
"integrity": "sha512-00n2iBy27w8zrGZSiU762UOVuzCQZxUZxopsZC47++js6xUFuI74DHcJ5K/2pddlF1YBskvmMuboEu1geK8mnA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/abstract-signer": "^5.1.0",
|
||||
"@ethersproject/address": "^5.1.0",
|
||||
@@ -16236,7 +16200,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/keccak256/-/keccak256-5.1.0.tgz",
|
||||
"integrity": "sha512-vrTB1W6AEYoadww5c9UyVJ2YcSiyIUTNDRccZIgwTmFFoSHwBtcvG1hqy9RzJ1T0bMdATbM9Hfx2mJ6H0i7Hig==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/bytes": "^5.1.0",
|
||||
"js-sha3": "0.5.7"
|
||||
@@ -16245,22 +16208,19 @@
|
||||
"js-sha3": {
|
||||
"version": "0.5.7",
|
||||
"resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.5.7.tgz",
|
||||
"integrity": "sha1-DU/9gALVMzqrr0oj7tL2N0yfKOc=",
|
||||
"dev": true
|
||||
"integrity": "sha1-DU/9gALVMzqrr0oj7tL2N0yfKOc="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@ethersproject/logger": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/logger/-/logger-5.1.0.tgz",
|
||||
"integrity": "sha512-wtUaD1lBX10HBXjjKV9VHCBnTdUaKQnQ2XSET1ezglqLdPdllNOIlLfhyCRqXm5xwcjExVI5ETokOYfjPtaAlw==",
|
||||
"dev": true
|
||||
"integrity": "sha512-wtUaD1lBX10HBXjjKV9VHCBnTdUaKQnQ2XSET1ezglqLdPdllNOIlLfhyCRqXm5xwcjExVI5ETokOYfjPtaAlw=="
|
||||
},
|
||||
"@ethersproject/networks": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/networks/-/networks-5.1.0.tgz",
|
||||
"integrity": "sha512-A/NIrIED/G/IgU1XUukOA3WcFRxn2I4O5GxsYGA5nFlIi+UZWdGojs85I1VXkR1gX9eFnDXzjE6OtbgZHjFhIA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/logger": "^5.1.0"
|
||||
}
|
||||
@@ -16269,7 +16229,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/pbkdf2/-/pbkdf2-5.1.0.tgz",
|
||||
"integrity": "sha512-B8cUbHHTgs8OtgJIafrRcz/YPDobVd5Ru8gTnShOiM9EBuFpYHQpq3+8iQJ6pyczDu6HP/oc/njAsIBhwFZYew==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/bytes": "^5.1.0",
|
||||
"@ethersproject/sha2": "^5.1.0"
|
||||
@@ -16279,7 +16238,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/properties/-/properties-5.1.0.tgz",
|
||||
"integrity": "sha512-519KKTwgmH42AQL3+GFV3SX6khYEfHsvI6v8HYejlkigSDuqttdgVygFTDsGlofNFchhDwuclrxQnD5B0YLNMg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/logger": "^5.1.0"
|
||||
}
|
||||
@@ -16288,7 +16246,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/providers/-/providers-5.1.0.tgz",
|
||||
"integrity": "sha512-FjpZL2lSXrYpQDg2fMjugZ0HjQD9a+2fOOoRhhihh+Z+qi/xZ8vIlPoumrEP1DzIG4DBV6liUqLNqnX2C6FIAA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/abstract-provider": "^5.1.0",
|
||||
"@ethersproject/abstract-signer": "^5.1.0",
|
||||
@@ -16315,7 +16272,6 @@
|
||||
"version": "7.2.3",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.2.3.tgz",
|
||||
"integrity": "sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ==",
|
||||
"dev": true,
|
||||
"requires": {}
|
||||
}
|
||||
}
|
||||
@@ -16324,7 +16280,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/random/-/random-5.1.0.tgz",
|
||||
"integrity": "sha512-+uuczLQZ4+no9cP6TCoCktXx0u2YbNaRT7lRkSt12d8263e702f0u+4JnnRO8Qmv5nylWJebnqCHzyxP+6mLqw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/bytes": "^5.1.0",
|
||||
"@ethersproject/logger": "^5.1.0"
|
||||
@@ -16334,7 +16289,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/rlp/-/rlp-5.1.0.tgz",
|
||||
"integrity": "sha512-vDTyHIwNPrecy55gKGZ47eJZhBm8LLBxihzi5ou+zrSvYTpkSTWRcKUlXFDFQVwfWB+P5PGyERAdiDEI76clxw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/bytes": "^5.1.0",
|
||||
"@ethersproject/logger": "^5.1.0"
|
||||
@@ -16344,7 +16298,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/sha2/-/sha2-5.1.0.tgz",
|
||||
"integrity": "sha512-+fNSeZRstOpdRJpdGUkRONFCaiAqWkc91zXgg76Nlp5ndBQE25Kk5yK8gCPG1aGnCrbariiPr5j9DmrYH78JCA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/bytes": "^5.1.0",
|
||||
"@ethersproject/logger": "^5.1.0",
|
||||
@@ -16355,7 +16308,6 @@
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.3.tgz",
|
||||
"integrity": "sha512-/UETyP0W22QILqS+6HowevwhEFJ3MBJnwTf75Qob9Wz9t0DPuisL8kW8YZMK62dHAKE1c1p+gY1TtOLY+USEHA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"inherits": "^2.0.3",
|
||||
"minimalistic-assert": "^1.0.0"
|
||||
@@ -16367,7 +16319,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/signing-key/-/signing-key-5.1.0.tgz",
|
||||
"integrity": "sha512-tE5LFlbmdObG8bY04NpuwPWSRPgEswfxweAI1sH7TbP0ml1elNfqcq7ii/3AvIN05i5U0Pkm3Tf8bramt8MmLw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/bytes": "^5.1.0",
|
||||
"@ethersproject/logger": "^5.1.0",
|
||||
@@ -16380,7 +16331,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/solidity/-/solidity-5.1.0.tgz",
|
||||
"integrity": "sha512-kPodsGyo9zg1g9XSXp1lGhFaezBAUUsAUB1Vf6OkppE5Wksg4Et+x3kG4m7J/uShDMP2upkJtHNsIBK2XkVpKQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/bignumber": "^5.1.0",
|
||||
"@ethersproject/bytes": "^5.1.0",
|
||||
@@ -16393,7 +16343,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/strings/-/strings-5.1.0.tgz",
|
||||
"integrity": "sha512-perBZy0RrmmL0ejiFGUOlBVjMsUceqLut3OBP3zP96LhiJWWbS8u1NqQVgN4/Gyrbziuda66DxiQocXhsvx+Sw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/bytes": "^5.1.0",
|
||||
"@ethersproject/constants": "^5.1.0",
|
||||
@@ -16404,7 +16353,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/transactions/-/transactions-5.1.0.tgz",
|
||||
"integrity": "sha512-s10crRLZEA0Bgv6FGEl/AKkTw9f+RVUrlWDX1rHnD4ZncPFeiV2AJr4nT7QSUhxJdFPvjyKRDb3nEH27dIqcPQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/address": "^5.1.0",
|
||||
"@ethersproject/bignumber": "^5.1.0",
|
||||
@@ -16421,7 +16369,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/units/-/units-5.1.0.tgz",
|
||||
"integrity": "sha512-isvJrx6qG0nKWfxsGORNjmOq/nh175fStfvRTA2xEKrGqx8JNJY83fswu4GkILowfriEM/eYpretfJnfzi7YhA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/bignumber": "^5.1.0",
|
||||
"@ethersproject/constants": "^5.1.0",
|
||||
@@ -16432,7 +16379,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/wallet/-/wallet-5.1.0.tgz",
|
||||
"integrity": "sha512-ULmUtiYQLTUS+y3DgkLzRhFEK10zMwmjOthnjiZxee3Q/MVwr3rnmuAnXIUZrPjna6hvUPnyRIdW5XuF0Ld0YQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/abstract-provider": "^5.1.0",
|
||||
"@ethersproject/abstract-signer": "^5.1.0",
|
||||
@@ -16455,7 +16401,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/web/-/web-5.1.0.tgz",
|
||||
"integrity": "sha512-LTeluWgTq04+RNqAkVhpydPcRZK/kKxD2Vy7PYGrAD27ABO9kTqTBKwiOuzTyAHKUQHfnvZbXmxBXJAGViSDcA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/base64": "^5.1.0",
|
||||
"@ethersproject/bytes": "^5.1.0",
|
||||
@@ -16468,7 +16413,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/wordlists/-/wordlists-5.1.0.tgz",
|
||||
"integrity": "sha512-NsUCi/TpBb+oTFvMSccUkJGtp5o/84eOyqp5q5aBeiNBSLkYyw21znRn9mAmxZgySpxgruVgKbaapnYPgvctPQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/bytes": "^5.1.0",
|
||||
"@ethersproject/hash": "^5.1.0",
|
||||
@@ -16704,7 +16648,9 @@
|
||||
"resolved": "https://registry.npmjs.org/@typechain/ethers-v5/-/ethers-v5-2.0.0.tgz",
|
||||
"integrity": "sha512-0xdCkyGOzdqh4h5JSf+zoWx85IusEjDcPIwNEHP8mrWSnCae4rvrqB+/gtpdNfX7zjlFlZiMeePn2r63EI3Lrw==",
|
||||
"dev": true,
|
||||
"requires": {}
|
||||
"requires": {
|
||||
"ethers": "^5.0.2"
|
||||
}
|
||||
},
|
||||
"@types/abstract-leveldown": {
|
||||
"version": "5.0.1",
|
||||
@@ -16754,7 +16700,7 @@
|
||||
"integrity": "sha512-dueRKfaJL4RTtSa7bWeTK1M+VH+Gns73oCgzvYfHZywRCoPSd8EkXBL0mZ9unPTveBn+D9phZBaxuzpwjWkW0g=="
|
||||
},
|
||||
"@types/node-fetch": {
|
||||
"version": "2.5.10",
|
||||
"version": "2.6.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.10.tgz",
|
||||
"integrity": "sha512-IpkX0AasN44hgEad0gEF/V6EgR5n69VEqPEgnmoM8GsIGro3PowbWs4tR6IhxUTyPLpOn+fiGG6nrQhcmoCuIQ==",
|
||||
"dev": true,
|
||||
@@ -16868,8 +16814,7 @@
|
||||
"aes-js": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.0.0.tgz",
|
||||
"integrity": "sha1-4h3xCtbCBTKVvLuNq0Cwnb6ofk0=",
|
||||
"dev": true
|
||||
"integrity": "sha1-4h3xCtbCBTKVvLuNq0Cwnb6ofk0="
|
||||
},
|
||||
"agent-base": {
|
||||
"version": "6.0.2",
|
||||
@@ -17056,8 +17001,7 @@
|
||||
"bech32": {
|
||||
"version": "1.1.4",
|
||||
"resolved": "https://registry.npmjs.org/bech32/-/bech32-1.1.4.tgz",
|
||||
"integrity": "sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ==",
|
||||
"dev": true
|
||||
"integrity": "sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ=="
|
||||
},
|
||||
"binary-extensions": {
|
||||
"version": "2.2.0",
|
||||
@@ -17804,7 +17748,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/ethers/-/ethers-5.1.0.tgz",
|
||||
"integrity": "sha512-2L6Ge6wMBw02FlRoCLg4E0Elt3khMNlW6ULawa10mMeeZToYJ5+uCfiuTuB+XZ6om1Y7wuO9ZzezP8FsU2M/+g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ethersproject/abi": "5.1.0",
|
||||
"@ethersproject/abstract-provider": "5.1.0",
|
||||
@@ -18067,7 +18010,7 @@
|
||||
"integrity": "sha512-4zPxDyhCyiN2wIAtSLI6gc82/EjqZc1onI4Mz/l0pWrAlsSfYH/2ZIcU+e3oA2wDwbzIWNKwa23F8rh6+DRWkw=="
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.13.3",
|
||||
"version": "1.14.7",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.3.tgz",
|
||||
"integrity": "sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA=="
|
||||
},
|
||||
@@ -25307,7 +25250,7 @@
|
||||
"merkle-patricia-tree": "^4.1.0",
|
||||
"mnemonist": "^0.38.0",
|
||||
"mocha": "^7.1.2",
|
||||
"node-fetch": "^2.6.0",
|
||||
"node-fetch": "^2.6.7",
|
||||
"qs": "^6.7.0",
|
||||
"raw-body": "^2.4.1",
|
||||
"resolve": "1.17.0",
|
||||
@@ -26211,7 +26154,7 @@
|
||||
}
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "2.6.1",
|
||||
"version": "2.6.7",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
|
||||
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
|
||||
},
|
||||
@@ -26930,7 +26873,7 @@
|
||||
"requires": {
|
||||
"command-exists": "^1.2.8",
|
||||
"commander": "3.0.2",
|
||||
"follow-redirects": "^1.12.1",
|
||||
"follow-redirects": "^1.14.7",
|
||||
"fs-extra": "^0.30.0",
|
||||
"js-sha3": "0.8.0",
|
||||
"memorystream": "^0.3.1",
|
||||
@@ -26966,6 +26909,14 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"solidity-create2-deployer": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/solidity-create2-deployer/-/solidity-create2-deployer-0.4.0.tgz",
|
||||
"integrity": "sha512-bB5d8fPt4dWsOoRodrsyfWKcjiv77IFl84+e6EckMMGYlfL2ZFqUoMz6tnqqiUFrM9abF1p6dWFOgJ/3zVc8yQ==",
|
||||
"requires": {
|
||||
"ethers": "^5.0.14"
|
||||
}
|
||||
},
|
||||
"sonic-boom": {
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-1.4.1.tgz",
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
"dependencies": {
|
||||
"@openzeppelin/contracts": "^4.0.0",
|
||||
"fastify": "^3.14.2",
|
||||
"hardhat": "^2.2.0"
|
||||
"hardhat": "^2.2.0",
|
||||
"solidity-create2-deployer": "^0.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
||||
|
||||
+112
-1
@@ -1,6 +1,14 @@
|
||||
const fastify = require('fastify')({ logger: true });
|
||||
const hre = require("hardhat");
|
||||
|
||||
const {
|
||||
deployContract,
|
||||
isDeployed
|
||||
} = require("solidity-create2-deployer");
|
||||
|
||||
const { getStorageSlotKey, deployCreate2Factory } = require('./utils');
|
||||
|
||||
const CREATE2_FACTORY_ADDRESS = '0x4a27c059FD7E383854Ea7DE6Be9c390a795f6eE3'
|
||||
|
||||
// readiness check
|
||||
fastify.get('/v1/healthz', async (req, reply) => {
|
||||
@@ -63,6 +71,109 @@ fastify.get('/v1/sendEth', async (req, reply) => {
|
||||
}
|
||||
});
|
||||
|
||||
fastify.get('/v1/deploySLVContract', async (req, reply) => {
|
||||
const SLVToken = await hre.ethers.getContractFactory("SLVToken");
|
||||
const token = await SLVToken.deploy();
|
||||
const receipt = await token.deployTransaction.wait();
|
||||
|
||||
return {
|
||||
address: token.address,
|
||||
txHash: token.deployTransaction.hash,
|
||||
blockNumber: receipt.blockNumber,
|
||||
blockHash: receipt.blockHash,
|
||||
}
|
||||
});
|
||||
|
||||
fastify.get('/v1/destroySLVContract', async (req, reply) => {
|
||||
const addr = req.query.addr;
|
||||
|
||||
const SLVToken = await hre.ethers.getContractFactory("SLVToken");
|
||||
const token = SLVToken.attach(addr);
|
||||
|
||||
const tx = await token.destroy();
|
||||
const receipt = await tx.wait();
|
||||
|
||||
return {
|
||||
blockNumber: receipt.blockNumber,
|
||||
}
|
||||
})
|
||||
|
||||
fastify.get('/v1/incrementCountA', async (req, reply) => {
|
||||
const addr = req.query.addr;
|
||||
|
||||
const SLVToken = await hre.ethers.getContractFactory("SLVToken");
|
||||
const token = await SLVToken.attach(addr);
|
||||
|
||||
const tx = await token.incrementCountA();
|
||||
const receipt = await tx.wait();
|
||||
|
||||
return {
|
||||
blockNumber: receipt.blockNumber,
|
||||
}
|
||||
});
|
||||
|
||||
fastify.get('/v1/incrementCountB', async (req, reply) => {
|
||||
const addr = req.query.addr;
|
||||
|
||||
const SLVToken = await hre.ethers.getContractFactory("SLVToken");
|
||||
const token = await SLVToken.attach(addr);
|
||||
|
||||
const tx = await token.incrementCountB();
|
||||
const receipt = await tx.wait();
|
||||
|
||||
return {
|
||||
blockNumber: receipt.blockNumber,
|
||||
}
|
||||
});
|
||||
|
||||
fastify.get('/v1/getStorageKey', async (req, reply) => {
|
||||
const contract = req.query.contract;
|
||||
const label = req.query.label;
|
||||
|
||||
const key = await getStorageSlotKey(contract, label)
|
||||
|
||||
return {
|
||||
key
|
||||
}
|
||||
});
|
||||
|
||||
fastify.get('/v1/create2Contract', async (req, reply) => {
|
||||
const contract = req.query.contract;
|
||||
const salt = req.query.salt;
|
||||
|
||||
const provider = hre.ethers.provider;
|
||||
const signer = await hre.ethers.getSigner();
|
||||
const isFactoryDeployed = await isDeployed(CREATE2_FACTORY_ADDRESS, provider);
|
||||
|
||||
if (!isFactoryDeployed) {
|
||||
await deployCreate2Factory(provider, signer)
|
||||
}
|
||||
|
||||
const contractFactory = await hre.ethers.getContractFactory(contract);
|
||||
const bytecode = contractFactory.bytecode;
|
||||
const constructorTypes = [];
|
||||
const constructorArgs = [];
|
||||
|
||||
const { txHash, address, receipt } = await deployContract({
|
||||
salt,
|
||||
contractBytecode: bytecode,
|
||||
constructorTypes: constructorTypes,
|
||||
constructorArgs: constructorArgs,
|
||||
signer
|
||||
});
|
||||
|
||||
const success = await isDeployed(address, provider);
|
||||
|
||||
if (success) {
|
||||
return {
|
||||
address,
|
||||
txHash,
|
||||
blockNumber: receipt.blockNumber,
|
||||
blockHash: receipt.blockHash,
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
await fastify.listen(3000, '0.0.0.0');
|
||||
@@ -72,4 +183,4 @@ async function main() {
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
main();
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
const { artifacts } = require("hardhat")
|
||||
const { utils, BigNumber } = require("ethers")
|
||||
const { deployFactory } = require("solidity-create2-deployer");
|
||||
|
||||
const CREATE2_FACTORY_ACCOUNT = '0x2287Fa6efdEc6d8c3E0f4612ce551dEcf89A357A';
|
||||
|
||||
async function getStorageLayout(contractName) {
|
||||
const artifact = await artifacts.readArtifact(contractName);
|
||||
const buildInfo = await artifacts.getBuildInfo(`${artifact.sourceName}:${artifact.contractName}`);
|
||||
|
||||
if (!buildInfo) {
|
||||
throw new Error('storageLayout not present in compiler output.');
|
||||
}
|
||||
|
||||
const output = buildInfo.output;
|
||||
const { storageLayout } = output.contracts[artifact.sourceName][artifact.contractName];
|
||||
|
||||
if (!storageLayout) {
|
||||
throw new Error('Contract hasn\'t been compiled.');
|
||||
}
|
||||
|
||||
return storageLayout;
|
||||
};
|
||||
|
||||
async function getStorageSlotKey(contractName, variableName) {
|
||||
storageLayout = await getStorageLayout(contractName)
|
||||
|
||||
const { storage } = storageLayout;
|
||||
const targetState = storage.find((state) => state.label === variableName);
|
||||
|
||||
// Throw if state variable could not be found in storage layout.
|
||||
if (!targetState) {
|
||||
throw new Error('Variable not present in storage layout.');
|
||||
}
|
||||
|
||||
key = utils.hexlify(BigNumber.from(targetState.slot));
|
||||
return key
|
||||
};
|
||||
|
||||
async function deployCreate2Factory(provider, signer) {
|
||||
// Send eth to account as required to deploy create2 factory contract.
|
||||
let tx = {
|
||||
to: CREATE2_FACTORY_ACCOUNT,
|
||||
value: utils.parseEther('0.01')
|
||||
}
|
||||
|
||||
const txResponse = await signer.sendTransaction(tx);
|
||||
await txResponse.wait()
|
||||
|
||||
// Deploy create2 factory contract.
|
||||
await deployFactory(provider)
|
||||
}
|
||||
|
||||
module.exports = { getStorageSlotKey, deployCreate2Factory }
|
||||
@@ -13,13 +13,15 @@ import (
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
integration "github.com/vulcanize/ipld-eth-server/test"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth"
|
||||
integration "github.com/vulcanize/ipld-eth-server/v3/test"
|
||||
)
|
||||
|
||||
var _ = Describe("Integration test", func() {
|
||||
directProxyEthCalls, err := strconv.ParseBool(os.Getenv("ETH_FORWARD_ETH_CALLS"))
|
||||
Expect(err).To(BeNil())
|
||||
watchedAddressServiceEnabled, err := strconv.ParseBool(os.Getenv("WATCHED_ADDRESS_GAP_FILLER_ENABLED"))
|
||||
Expect(err).To(BeNil())
|
||||
gethHttpPath := "http://127.0.0.1:8545"
|
||||
gethClient, err := ethclient.Dial(gethHttpPath)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@@ -38,11 +40,14 @@ var _ = Describe("Integration test", func() {
|
||||
var txErr error
|
||||
sleepInterval := 2 * time.Second
|
||||
|
||||
BeforeEach(func() {
|
||||
if !directProxyEthCalls || watchedAddressServiceEnabled {
|
||||
Skip("skipping direct-proxy-forwarding integration tests")
|
||||
}
|
||||
})
|
||||
|
||||
Describe("get Block", func() {
|
||||
BeforeEach(func() {
|
||||
if !directProxyEthCalls {
|
||||
Skip("skipping direct-proxy-forwarding integration tests")
|
||||
}
|
||||
contract, contractErr = integration.DeployContract()
|
||||
time.Sleep(sleepInterval)
|
||||
})
|
||||
@@ -94,9 +99,6 @@ var _ = Describe("Integration test", func() {
|
||||
|
||||
Describe("Transaction", func() {
|
||||
BeforeEach(func() {
|
||||
if !directProxyEthCalls {
|
||||
Skip("skipping direct-proxy-forwarding integration tests")
|
||||
}
|
||||
contract, contractErr = integration.DeployContract()
|
||||
time.Sleep(sleepInterval)
|
||||
})
|
||||
@@ -122,9 +124,6 @@ var _ = Describe("Integration test", func() {
|
||||
|
||||
Describe("Receipt", func() {
|
||||
BeforeEach(func() {
|
||||
if !directProxyEthCalls {
|
||||
Skip("skipping direct-proxy-forwarding integration tests")
|
||||
}
|
||||
contract, contractErr = integration.DeployContract()
|
||||
time.Sleep(sleepInterval)
|
||||
})
|
||||
@@ -142,9 +141,6 @@ var _ = Describe("Integration test", func() {
|
||||
|
||||
Describe("FilterLogs", func() {
|
||||
BeforeEach(func() {
|
||||
if !directProxyEthCalls {
|
||||
Skip("skipping direct-proxy-forwarding integration tests")
|
||||
}
|
||||
contract, contractErr = integration.DeployContract()
|
||||
time.Sleep(sleepInterval)
|
||||
})
|
||||
@@ -174,9 +170,6 @@ var _ = Describe("Integration test", func() {
|
||||
|
||||
Describe("CodeAt", func() {
|
||||
BeforeEach(func() {
|
||||
if !directProxyEthCalls {
|
||||
Skip("skipping direct-proxy-forwarding integration tests")
|
||||
}
|
||||
contract, contractErr = integration.DeployContract()
|
||||
time.Sleep(sleepInterval)
|
||||
})
|
||||
@@ -224,9 +217,6 @@ var _ = Describe("Integration test", func() {
|
||||
Describe("Get balance", func() {
|
||||
address := "0x1111111111111111111111111111111111111112"
|
||||
BeforeEach(func() {
|
||||
if !directProxyEthCalls {
|
||||
Skip("skipping direct-proxy-forwarding integration tests")
|
||||
}
|
||||
tx, txErr = integration.SendEth(address, "0.01")
|
||||
time.Sleep(sleepInterval)
|
||||
})
|
||||
@@ -286,9 +276,6 @@ var _ = Describe("Integration test", func() {
|
||||
|
||||
Describe("Get Storage", func() {
|
||||
BeforeEach(func() {
|
||||
if !directProxyEthCalls {
|
||||
Skip("skipping direct-proxy-forwarding integration tests")
|
||||
}
|
||||
contract, contractErr = integration.DeployContract()
|
||||
erc20TotalSupply, bigIntResult = new(big.Int).SetString("1000000000000000000000", 10)
|
||||
|
||||
@@ -392,9 +379,6 @@ var _ = Describe("Integration test", func() {
|
||||
|
||||
Describe("eth call", func() {
|
||||
BeforeEach(func() {
|
||||
if !directProxyEthCalls {
|
||||
Skip("skipping direct-proxy-forwarding integration tests")
|
||||
}
|
||||
contract, contractErr = integration.DeployContract()
|
||||
erc20TotalSupply, bigIntResult = new(big.Int).SetString("1000000000000000000000", 10)
|
||||
|
||||
@@ -445,9 +429,6 @@ var _ = Describe("Integration test", func() {
|
||||
|
||||
Describe("Chain ID", func() {
|
||||
It("Check chain id", func() {
|
||||
if !directProxyEthCalls {
|
||||
Skip("skipping direct-proxy-forwarding integration tests")
|
||||
}
|
||||
_, err := gethClient.ChainID(ctx)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
|
||||
+108
@@ -5,6 +5,9 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"net/http"
|
||||
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/statediff/types"
|
||||
)
|
||||
|
||||
type ContractDeployed struct {
|
||||
@@ -27,6 +30,14 @@ type Tx struct {
|
||||
BlockHash string `json:"blockHash"`
|
||||
}
|
||||
|
||||
type StorageKey struct {
|
||||
Key string `json:"key"`
|
||||
}
|
||||
|
||||
type CountIncremented struct {
|
||||
BlockNumber int64 `json:"blockNumber"`
|
||||
}
|
||||
|
||||
const srvUrl = "http://localhost:3000"
|
||||
|
||||
func DeployContract() (*ContractDeployed, error) {
|
||||
@@ -77,3 +88,100 @@ func SendEth(to string, value string) (*Tx, error) {
|
||||
|
||||
return &tx, nil
|
||||
}
|
||||
|
||||
func DeploySLVContract() (*ContractDeployed, error) {
|
||||
res, err := http.Get(fmt.Sprintf("%s/v1/deploySLVContract", srvUrl))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
var contract ContractDeployed
|
||||
|
||||
decoder := json.NewDecoder(res.Body)
|
||||
err = decoder.Decode(&contract)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &contract, nil
|
||||
}
|
||||
|
||||
func DestroySLVContract(addr string) (*ContractDestroyed, error) {
|
||||
res, err := http.Get(fmt.Sprintf("%s/v1/destroySLVContract?addr=%s", srvUrl, addr))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
var data ContractDestroyed
|
||||
decoder := json.NewDecoder(res.Body)
|
||||
|
||||
return &data, decoder.Decode(&data)
|
||||
}
|
||||
|
||||
func IncrementCount(addr string, count string) (*CountIncremented, error) {
|
||||
res, err := http.Get(fmt.Sprintf("%s/v1/incrementCount%s?addr=%s", srvUrl, count, addr))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var blockNumber CountIncremented
|
||||
|
||||
decoder := json.NewDecoder(res.Body)
|
||||
err = decoder.Decode(&blockNumber)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &blockNumber, nil
|
||||
}
|
||||
|
||||
func GetStorageSlotKey(contract string, label string) (*StorageKey, error) {
|
||||
res, err := http.Get(fmt.Sprintf("%s/v1/getStorageKey?contract=%s&label=%s", srvUrl, contract, label))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
var key StorageKey
|
||||
|
||||
decoder := json.NewDecoder(res.Body)
|
||||
err = decoder.Decode(&key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &key, nil
|
||||
}
|
||||
|
||||
func ClearWatchedAddresses(gethRPCClient *rpc.Client) error {
|
||||
gethMethod := "statediff_watchAddress"
|
||||
args := []types.WatchAddressArg{}
|
||||
|
||||
// Clear watched addresses
|
||||
gethErr := gethRPCClient.Call(nil, gethMethod, types.Clear, args)
|
||||
if gethErr != nil {
|
||||
return gethErr
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Create2Contract(contractName string, salt string) (*ContractDeployed, error) {
|
||||
res, err := http.Get(fmt.Sprintf("%s/v1/create2Contract?contract=%s&salt=%s", srvUrl, contractName, salt))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
var contract ContractDeployed
|
||||
|
||||
decoder := json.NewDecoder(res.Body)
|
||||
err = decoder.Decode(&contract)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &contract, nil
|
||||
}
|
||||
|
||||
+85
-30
@@ -16,8 +16,8 @@ import (
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
integration "github.com/vulcanize/ipld-eth-server/test"
|
||||
"github.com/vulcanize/ipld-eth-server/v3/pkg/eth"
|
||||
integration "github.com/vulcanize/ipld-eth-server/v3/test"
|
||||
)
|
||||
|
||||
const nonExistingBlockHash = "0x111111111111111111111111111111111111111111111111111111111111111"
|
||||
@@ -31,6 +31,8 @@ var (
|
||||
var _ = Describe("Integration test", func() {
|
||||
directProxyEthCalls, err := strconv.ParseBool(os.Getenv("ETH_FORWARD_ETH_CALLS"))
|
||||
Expect(err).To(BeNil())
|
||||
watchedAddressServiceEnabled, err := strconv.ParseBool(os.Getenv("WATCHED_ADDRESS_GAP_FILLER_ENABLED"))
|
||||
Expect(err).To(BeNil())
|
||||
gethHttpPath := "http://127.0.0.1:8545"
|
||||
gethClient, err := ethclient.Dial(gethHttpPath)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@@ -49,11 +51,14 @@ var _ = Describe("Integration test", func() {
|
||||
var txErr error
|
||||
sleepInterval := 2 * time.Second
|
||||
|
||||
BeforeEach(func() {
|
||||
if directProxyEthCalls || watchedAddressServiceEnabled {
|
||||
Skip("skipping no-direct-proxy-forwarding integration tests")
|
||||
}
|
||||
})
|
||||
|
||||
Describe("get Block", func() {
|
||||
BeforeEach(func() {
|
||||
if directProxyEthCalls {
|
||||
Skip("skipping no-direct-proxy-forwarding integration tests")
|
||||
}
|
||||
contract, contractErr = integration.DeployContract()
|
||||
time.Sleep(sleepInterval)
|
||||
})
|
||||
@@ -123,9 +128,6 @@ var _ = Describe("Integration test", func() {
|
||||
|
||||
Describe("Transaction", func() {
|
||||
BeforeEach(func() {
|
||||
if directProxyEthCalls {
|
||||
Skip("skipping no-direct-proxy-forwarding integration tests")
|
||||
}
|
||||
contract, contractErr = integration.DeployContract()
|
||||
time.Sleep(sleepInterval)
|
||||
})
|
||||
@@ -157,9 +159,6 @@ var _ = Describe("Integration test", func() {
|
||||
|
||||
Describe("Receipt", func() {
|
||||
BeforeEach(func() {
|
||||
if directProxyEthCalls {
|
||||
Skip("skipping no-direct-proxy-forwarding integration tests")
|
||||
}
|
||||
contract, contractErr = integration.DeployContract()
|
||||
time.Sleep(sleepInterval)
|
||||
})
|
||||
@@ -187,9 +186,6 @@ var _ = Describe("Integration test", func() {
|
||||
|
||||
Describe("FilterLogs", func() {
|
||||
BeforeEach(func() {
|
||||
if directProxyEthCalls {
|
||||
Skip("skipping no-direct-proxy-forwarding integration tests")
|
||||
}
|
||||
contract, contractErr = integration.DeployContract()
|
||||
time.Sleep(sleepInterval)
|
||||
})
|
||||
@@ -220,9 +216,6 @@ var _ = Describe("Integration test", func() {
|
||||
|
||||
Describe("CodeAt", func() {
|
||||
BeforeEach(func() {
|
||||
if directProxyEthCalls {
|
||||
Skip("skipping no-direct-proxy-forwarding integration tests")
|
||||
}
|
||||
contract, contractErr = integration.DeployContract()
|
||||
time.Sleep(sleepInterval)
|
||||
})
|
||||
@@ -270,9 +263,6 @@ var _ = Describe("Integration test", func() {
|
||||
Describe("Get balance", func() {
|
||||
address := "0x1111111111111111111111111111111111111112"
|
||||
BeforeEach(func() {
|
||||
if directProxyEthCalls {
|
||||
Skip("skipping no-direct-proxy-forwarding integration tests")
|
||||
}
|
||||
tx, txErr = integration.SendEth(address, "0.01")
|
||||
time.Sleep(sleepInterval)
|
||||
})
|
||||
@@ -335,10 +325,12 @@ var _ = Describe("Integration test", func() {
|
||||
})
|
||||
|
||||
Describe("Get Storage", func() {
|
||||
var slvContract *integration.ContractDeployed
|
||||
var slvCountA *big.Int
|
||||
|
||||
contractSalt := "SLVContractSalt"
|
||||
|
||||
BeforeEach(func() {
|
||||
if directProxyEthCalls {
|
||||
Skip("skipping no-direct-proxy-forwarding integration tests")
|
||||
}
|
||||
contract, contractErr = integration.DeployContract()
|
||||
erc20TotalSupply, bigIntResult = new(big.Int).SetString("1000000000000000000000", 10)
|
||||
|
||||
@@ -418,12 +410,48 @@ var _ = Describe("Integration test", func() {
|
||||
Expect(gethStorage).To(Equal(ipldStorage))
|
||||
})
|
||||
|
||||
It("get storage for SLV countA after tx", func() {
|
||||
slvContract, contractErr = integration.Create2Contract("SLVToken", contractSalt)
|
||||
Expect(contractErr).ToNot(HaveOccurred())
|
||||
countAIndex := "0x5"
|
||||
|
||||
time.Sleep(sleepInterval)
|
||||
|
||||
gethStorage, err := gethClient.StorageAt(ctx, common.HexToAddress(slvContract.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
gethCountA := new(big.Int).SetBytes(gethStorage)
|
||||
slvCountA = gethCountA
|
||||
|
||||
ipldStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(slvContract.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
ipldCountA := new(big.Int).SetBytes(ipldStorage)
|
||||
Expect(ipldCountA.String()).To(Equal(slvCountA.String()))
|
||||
|
||||
_, txErr = integration.IncrementCount(slvContract.Address, "A")
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
slvCountA.Add(slvCountA, big.NewInt(1))
|
||||
|
||||
time.Sleep(sleepInterval)
|
||||
|
||||
ipldStorage, err = ipldClient.StorageAt(ctx, common.HexToAddress(slvContract.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
ipldCountA = new(big.Int).SetBytes(ipldStorage)
|
||||
Expect(ipldCountA.String()).To(Equal(slvCountA.String()))
|
||||
})
|
||||
|
||||
It("get storage after self destruct", func() {
|
||||
totalSupplyIndex := "0x2"
|
||||
countAIndex := "0x5"
|
||||
|
||||
tx, err := integration.DestroyContract(contract.Address)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
slvTx, err := integration.DestroyContract(slvContract.Address)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
time.Sleep(sleepInterval)
|
||||
|
||||
gethStorage1, err := gethClient.StorageAt(ctx, common.HexToAddress(contract.Address), common.HexToHash(totalSupplyIndex), big.NewInt(tx.BlockNumber-1))
|
||||
@@ -447,14 +475,44 @@ var _ = Describe("Integration test", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
Expect(ipldStorage2).To(Equal(ipldStorage3))
|
||||
|
||||
// Check for SLV contract
|
||||
gethStorage, err := gethClient.StorageAt(ctx, common.HexToAddress(slvContract.Address), common.HexToHash(countAIndex), big.NewInt(slvTx.BlockNumber))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(gethStorage).To(Equal(eth.EmptyNodeValue))
|
||||
|
||||
ipldStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(slvContract.Address), common.HexToHash(countAIndex), big.NewInt(slvTx.BlockNumber))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(ipldStorage).To(Equal(gethStorage))
|
||||
|
||||
slvCountA.Set(big.NewInt(0))
|
||||
})
|
||||
|
||||
It("get storage after redeploying", func() {
|
||||
slvContract, contractErr = integration.Create2Contract("SLVToken", contractSalt)
|
||||
Expect(contractErr).ToNot(HaveOccurred())
|
||||
time.Sleep(sleepInterval)
|
||||
|
||||
countAIndex := "0x5"
|
||||
|
||||
gethStorage, err := gethClient.StorageAt(ctx, common.HexToAddress(slvContract.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
gethCountA := new(big.Int).SetBytes(gethStorage)
|
||||
Expect(gethCountA.String()).To(Equal(slvCountA.String()))
|
||||
|
||||
ipldStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(slvContract.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
ipldCountA := new(big.Int).SetBytes(ipldStorage)
|
||||
Expect(ipldCountA.String()).To(Equal(slvCountA.String()))
|
||||
|
||||
Expect(gethStorage).To(Equal(ipldStorage))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("eth call", func() {
|
||||
BeforeEach(func() {
|
||||
if directProxyEthCalls {
|
||||
Skip("skipping no-direct-proxy-forwarding integration tests")
|
||||
}
|
||||
contract, contractErr = integration.DeployContract()
|
||||
erc20TotalSupply, bigIntResult = new(big.Int).SetString("1000000000000000000000", 10)
|
||||
|
||||
@@ -505,9 +563,6 @@ var _ = Describe("Integration test", func() {
|
||||
|
||||
Describe("Chain ID", func() {
|
||||
It("Check chain id", func() {
|
||||
if directProxyEthCalls {
|
||||
Skip("skipping no-direct-proxy-forwarding integration tests")
|
||||
}
|
||||
gethChainId, err := gethClient.ChainID(ctx)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
@@ -537,7 +592,7 @@ func compareTxs(tx1 *types.Transaction, tx2 *types.Transaction) {
|
||||
Expect(tx1.Hash()).To(Equal(tx2.Hash()))
|
||||
Expect(tx1.Size()).To(Equal(tx2.Size()))
|
||||
|
||||
signer := types.NewEIP155Signer(big.NewInt(4))
|
||||
signer := types.NewEIP155Signer(big.NewInt(99))
|
||||
|
||||
gethSender, err := types.Sender(signer, tx1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
@@ -0,0 +1,674 @@
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/statediff/types"
|
||||
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
integration "github.com/vulcanize/ipld-eth-server/v3/test"
|
||||
)
|
||||
|
||||
var (
|
||||
gethMethod = "statediff_watchAddress"
|
||||
ipldMethod = "vdb_watchAddress"
|
||||
|
||||
sleepInterval = 2 * time.Second
|
||||
)
|
||||
|
||||
var _ = Describe("WatchAddress integration test", func() {
|
||||
dbWrite, err := strconv.ParseBool(os.Getenv("DB_WRITE"))
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
watchedAddressServiceEnabled, err := strconv.ParseBool(os.Getenv("WATCHED_ADDRESS_GAP_FILLER_ENABLED"))
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
gethHttpPath := "http://127.0.0.1:8545"
|
||||
gethRPCClient, err := rpc.Dial(gethHttpPath)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
ipldEthHttpPath := "http://127.0.0.1:8081"
|
||||
ipldClient, err := ethclient.Dial(ipldEthHttpPath)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
ipldRPCClient, err := rpc.Dial(ipldEthHttpPath)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
var (
|
||||
ctx = context.Background()
|
||||
|
||||
txErr error
|
||||
contractErr error
|
||||
incErr error
|
||||
|
||||
contract1 *integration.ContractDeployed
|
||||
contract2 *integration.ContractDeployed
|
||||
contract3 *integration.ContractDeployed
|
||||
|
||||
countAIndex string
|
||||
|
||||
prevBalance1 *big.Int
|
||||
prevBalance2 *big.Int
|
||||
prevBalance3 *big.Int
|
||||
|
||||
actualBalance1 *big.Int
|
||||
actualBalance2 *big.Int
|
||||
actualBalance3 *big.Int
|
||||
|
||||
prevCountA1 *big.Int
|
||||
prevCountA2 *big.Int
|
||||
prevCountA3 *big.Int
|
||||
|
||||
actualCountA1 *big.Int
|
||||
actualCountA2 *big.Int
|
||||
actualCountA3 *big.Int
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
if !dbWrite || watchedAddressServiceEnabled {
|
||||
Skip("skipping WatchAddress API integration tests")
|
||||
}
|
||||
})
|
||||
|
||||
It("test init", func() {
|
||||
// Deploy three contracts
|
||||
contract1, contractErr = integration.DeploySLVContract()
|
||||
Expect(contractErr).ToNot(HaveOccurred())
|
||||
|
||||
contract2, contractErr = integration.DeploySLVContract()
|
||||
Expect(contractErr).ToNot(HaveOccurred())
|
||||
|
||||
contract3, contractErr = integration.DeploySLVContract()
|
||||
Expect(contractErr).ToNot(HaveOccurred())
|
||||
|
||||
// Get the storage slot key
|
||||
storageSlotAKey, err := integration.GetStorageSlotKey("SLVToken", "countA")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countAIndex = storageSlotAKey.Key
|
||||
|
||||
// Clear out watched addresses
|
||||
err = integration.ClearWatchedAddresses(gethRPCClient)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// Get initial balances for all the contracts
|
||||
// Contract 1
|
||||
actualBalance1 = big.NewInt(0)
|
||||
initBalance1, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract1.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(initBalance1.String()).To(Equal(actualBalance1.String()))
|
||||
prevBalance1 = big.NewInt(0)
|
||||
|
||||
// Contract 2
|
||||
actualBalance2 = big.NewInt(0)
|
||||
initBalance2, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract2.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(initBalance2.String()).To(Equal(actualBalance2.String()))
|
||||
prevBalance2 = big.NewInt(0)
|
||||
|
||||
// Contract 3
|
||||
actualBalance3 = big.NewInt(0)
|
||||
initBalance3, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract3.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(initBalance3.String()).To(Equal(actualBalance3.String()))
|
||||
prevBalance3 = big.NewInt(0)
|
||||
|
||||
// Get initial storage values for the contracts
|
||||
// Contract 1, countA
|
||||
actualCountA1 = big.NewInt(0)
|
||||
ipldCountA1Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
ipldCountA1 := new(big.Int).SetBytes(ipldCountA1Storage)
|
||||
Expect(ipldCountA1.String()).To(Equal(actualCountA1.String()))
|
||||
prevCountA1 = big.NewInt(0)
|
||||
|
||||
// Contract 2, countA
|
||||
actualCountA2 = big.NewInt(0)
|
||||
ipldCountA2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
ipldCountA2 := new(big.Int).SetBytes(ipldCountA2Storage)
|
||||
Expect(ipldCountA2.String()).To(Equal(actualCountA2.String()))
|
||||
prevCountA2 = big.NewInt(0)
|
||||
|
||||
// Contract 3, countA
|
||||
actualCountA3 = big.NewInt(0)
|
||||
ipldCountA3Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract3.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
ipldCountA3 := new(big.Int).SetBytes(ipldCountA3Storage)
|
||||
Expect(ipldCountA3.String()).To(Equal(actualCountA2.String()))
|
||||
prevCountA3 = big.NewInt(0)
|
||||
})
|
||||
|
||||
defer It("test cleanup", func() {
|
||||
// Clear out watched addresses
|
||||
err := integration.ClearWatchedAddresses(gethRPCClient)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
Context("no contracts being watched", func() {
|
||||
It("indexes state for all the contracts", func() {
|
||||
// WatchedAddresses = []
|
||||
// Send eth to all three contract accounts
|
||||
// Contract 1
|
||||
_, txErr = integration.SendEth(contract1.Address, "0.01")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
actualBalance1.Add(actualBalance1, big.NewInt(10000000000000000))
|
||||
|
||||
balance1AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract1.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance1AfterTransfer.String()).To(Equal(actualBalance1.String()))
|
||||
prevBalance1.Set(actualBalance1)
|
||||
|
||||
// Contract 2
|
||||
_, txErr = integration.SendEth(contract2.Address, "0.01")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
actualBalance2.Add(actualBalance2, big.NewInt(10000000000000000))
|
||||
|
||||
balance2AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract2.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance2AfterTransfer.String()).To(Equal(actualBalance2.String()))
|
||||
prevBalance2.Set(actualBalance2)
|
||||
|
||||
// Contract 3
|
||||
_, txErr = integration.SendEth(contract3.Address, "0.01")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
actualBalance3.Add(actualBalance3, big.NewInt(10000000000000000))
|
||||
|
||||
balance3AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract3.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance3AfterTransfer.String()).To(Equal(actualBalance3.String()))
|
||||
prevBalance3.Set(actualBalance3)
|
||||
|
||||
// Increment counts
|
||||
// Contract 1, countA
|
||||
_, incErr = integration.IncrementCount(contract1.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA1.Add(actualCountA1, big.NewInt(1))
|
||||
|
||||
countA1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1AfterIncrement := new(big.Int).SetBytes(countA1AfterIncrementStorage)
|
||||
Expect(countA1AfterIncrement.String()).To(Equal(actualCountA1.String()))
|
||||
prevCountA1.Set(actualCountA1)
|
||||
|
||||
// Contract 2, countA
|
||||
_, incErr = integration.IncrementCount(contract2.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA2.Add(actualCountA2, big.NewInt(1))
|
||||
|
||||
countA2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2AfterIncrement := new(big.Int).SetBytes(countA2AfterIncrementStorage)
|
||||
Expect(countA2AfterIncrement.String()).To(Equal(actualCountA2.String()))
|
||||
prevCountA2.Set(actualCountA2)
|
||||
|
||||
// Contract 3, countA
|
||||
_, incErr = integration.IncrementCount(contract3.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA3.Add(actualCountA3, big.NewInt(1))
|
||||
|
||||
countA3AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract3.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA3AfterIncrement := new(big.Int).SetBytes(countA3AfterIncrementStorage)
|
||||
Expect(countA3AfterIncrement.String()).To(Equal(actualCountA3.String()))
|
||||
prevCountA3.Set(actualCountA3)
|
||||
})
|
||||
})
|
||||
|
||||
Context("one contract being watched", func() {
|
||||
It("indexes state only for the watched contract", func() {
|
||||
operation := types.Add
|
||||
args := []types.WatchAddressArg{
|
||||
{
|
||||
Address: contract1.Address,
|
||||
CreatedAt: uint64(contract1.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, operation, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// WatchedAddresses = [Contract1]
|
||||
// Send eth to all three contract accounts
|
||||
// Contract 1
|
||||
_, txErr = integration.SendEth(contract1.Address, "0.01")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
actualBalance1.Add(actualBalance1, big.NewInt(10000000000000000))
|
||||
|
||||
balance1AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract1.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance1AfterTransfer.String()).To(Equal(actualBalance1.String()))
|
||||
prevBalance1.Set(actualBalance1)
|
||||
|
||||
// Contract 2
|
||||
_, txErr = integration.SendEth(contract2.Address, "0.01")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
actualBalance2.Add(actualBalance2, big.NewInt(10000000000000000))
|
||||
|
||||
balance2AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract2.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance2AfterTransfer.String()).To(Equal(prevBalance2.String()))
|
||||
|
||||
// Contract 3
|
||||
_, txErr = integration.SendEth(contract3.Address, "0.01")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
actualBalance3.Add(actualBalance3, big.NewInt(10000000000000000))
|
||||
|
||||
balance3AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract3.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance3AfterTransfer.String()).To(Equal(prevBalance3.String()))
|
||||
|
||||
// Increment counts
|
||||
// Contract 1, countA
|
||||
_, incErr = integration.IncrementCount(contract1.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA1.Add(actualCountA1, big.NewInt(1))
|
||||
|
||||
countA1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1AfterIncrement := new(big.Int).SetBytes(countA1AfterIncrementStorage)
|
||||
Expect(countA1AfterIncrement.String()).To(Equal(actualCountA1.String()))
|
||||
prevCountA1.Set(actualCountA1)
|
||||
|
||||
// Contract 2, countA
|
||||
_, incErr = integration.IncrementCount(contract2.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA2.Add(actualCountA2, big.NewInt(1))
|
||||
|
||||
countA2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2AfterIncrement := new(big.Int).SetBytes(countA2AfterIncrementStorage)
|
||||
Expect(countA2AfterIncrement.String()).To(Equal(prevCountA2.String()))
|
||||
|
||||
// Contract 3, countA
|
||||
_, incErr = integration.IncrementCount(contract3.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA3.Add(actualCountA3, big.NewInt(1))
|
||||
|
||||
countA3AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract3.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA3AfterIncrement := new(big.Int).SetBytes(countA3AfterIncrementStorage)
|
||||
Expect(countA3AfterIncrement.String()).To(Equal(prevCountA3.String()))
|
||||
})
|
||||
})
|
||||
|
||||
Context("contract added to a non-empty watch-list", func() {
|
||||
It("indexes state only for the watched contracts", func() {
|
||||
operation := types.Add
|
||||
args := []types.WatchAddressArg{
|
||||
{
|
||||
Address: contract2.Address,
|
||||
CreatedAt: uint64(contract2.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, operation, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// WatchedAddresses = [Contract1, Contract2]
|
||||
// Send eth to all three contract accounts
|
||||
// Contract 1
|
||||
_, txErr = integration.SendEth(contract1.Address, "0.01")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
actualBalance1.Add(actualBalance1, big.NewInt(10000000000000000))
|
||||
|
||||
balance1AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract1.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance1AfterTransfer.String()).To(Equal(actualBalance1.String()))
|
||||
prevBalance1.Set(actualBalance1)
|
||||
|
||||
// Contract 2
|
||||
_, txErr = integration.SendEth(contract2.Address, "0.01")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
actualBalance2.Add(actualBalance2, big.NewInt(10000000000000000))
|
||||
|
||||
balance2AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract2.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance2AfterTransfer.String()).To(Equal(actualBalance2.String()))
|
||||
prevBalance2.Set(actualBalance2)
|
||||
|
||||
// Contract 3
|
||||
_, txErr = integration.SendEth(contract3.Address, "0.01")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
actualBalance3.Add(actualBalance3, big.NewInt(10000000000000000))
|
||||
|
||||
balance3AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract3.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance3AfterTransfer.String()).To(Equal(prevBalance3.String()))
|
||||
|
||||
// Increment counts
|
||||
// Contract 1, countA
|
||||
_, incErr = integration.IncrementCount(contract1.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA1.Add(actualCountA1, big.NewInt(1))
|
||||
|
||||
countA1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1AfterIncrement := new(big.Int).SetBytes(countA1AfterIncrementStorage)
|
||||
Expect(countA1AfterIncrement.String()).To(Equal(actualCountA1.String()))
|
||||
prevCountA1.Set(actualCountA1)
|
||||
|
||||
// Contract 2, countA
|
||||
_, incErr = integration.IncrementCount(contract2.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA2.Add(actualCountA2, big.NewInt(1))
|
||||
|
||||
countA2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2AfterIncrement := new(big.Int).SetBytes(countA2AfterIncrementStorage)
|
||||
Expect(countA2AfterIncrement.String()).To(Equal(actualCountA2.String()))
|
||||
prevCountA2.Set(actualCountA2)
|
||||
|
||||
// Contract 3, countA
|
||||
_, incErr = integration.IncrementCount(contract3.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA3.Add(actualCountA3, big.NewInt(1))
|
||||
|
||||
countA3AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract3.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA3AfterIncrement := new(big.Int).SetBytes(countA3AfterIncrementStorage)
|
||||
Expect(countA3AfterIncrement.String()).To(Equal(prevCountA3.String()))
|
||||
})
|
||||
})
|
||||
|
||||
Context("contract removed from the watch-list", func() {
|
||||
It("indexes state only for the watched contract", func() {
|
||||
operation := types.Remove
|
||||
args := []types.WatchAddressArg{
|
||||
{
|
||||
Address: contract1.Address,
|
||||
CreatedAt: uint64(contract1.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, operation, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// WatchedAddresses = [Contract2]
|
||||
// Send eth to all three contract accounts
|
||||
// Contract 1
|
||||
_, txErr = integration.SendEth(contract1.Address, "0.01")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
actualBalance1.Add(actualBalance1, big.NewInt(10000000000000000))
|
||||
|
||||
balance1AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract1.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance1AfterTransfer.String()).To(Equal(prevBalance1.String()))
|
||||
|
||||
// Contract 2
|
||||
_, txErr = integration.SendEth(contract2.Address, "0.01")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
actualBalance2.Add(actualBalance2, big.NewInt(10000000000000000))
|
||||
|
||||
balance2AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract2.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance2AfterTransfer.String()).To(Equal(actualBalance2.String()))
|
||||
prevBalance2.Set(actualBalance2)
|
||||
|
||||
// Contract 3
|
||||
_, txErr = integration.SendEth(contract3.Address, "0.01")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
actualBalance3.Add(actualBalance3, big.NewInt(10000000000000000))
|
||||
|
||||
balance3AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract3.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance3AfterTransfer.String()).To(Equal(prevBalance3.String()))
|
||||
|
||||
// Increment counts
|
||||
// Contract 1, countA
|
||||
_, incErr = integration.IncrementCount(contract1.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA1.Add(actualCountA1, big.NewInt(1))
|
||||
|
||||
countA1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1AfterIncrement := new(big.Int).SetBytes(countA1AfterIncrementStorage)
|
||||
Expect(countA1AfterIncrement.String()).To(Equal(prevCountA1.String()))
|
||||
|
||||
// Contract 2, countA
|
||||
_, incErr = integration.IncrementCount(contract2.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA2.Add(actualCountA2, big.NewInt(1))
|
||||
|
||||
countA2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2AfterIncrement := new(big.Int).SetBytes(countA2AfterIncrementStorage)
|
||||
Expect(countA2AfterIncrement.String()).To(Equal(actualCountA2.String()))
|
||||
prevCountA2.Set(actualCountA2)
|
||||
|
||||
// Contract 3, countA
|
||||
_, incErr = integration.IncrementCount(contract3.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA3.Add(actualCountA3, big.NewInt(1))
|
||||
|
||||
countA3AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract3.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA3AfterIncrement := new(big.Int).SetBytes(countA3AfterIncrementStorage)
|
||||
Expect(countA3AfterIncrement.String()).To(Equal(prevCountA3.String()))
|
||||
})
|
||||
})
|
||||
|
||||
Context("list of watched addresses set", func() {
|
||||
It("indexes state only for the watched contracts", func() {
|
||||
operation := types.Set
|
||||
args := []types.WatchAddressArg{
|
||||
{
|
||||
Address: contract1.Address,
|
||||
CreatedAt: uint64(contract1.BlockNumber),
|
||||
},
|
||||
{
|
||||
Address: contract3.Address,
|
||||
CreatedAt: uint64(contract3.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, operation, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// WatchedAddresses = [Contract1, Contract3]
|
||||
// Send eth to all three contract accounts
|
||||
// Contract 1
|
||||
_, txErr = integration.SendEth(contract1.Address, "0.01")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
actualBalance1.Add(actualBalance1, big.NewInt(10000000000000000))
|
||||
|
||||
balance1AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract1.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance1AfterTransfer.String()).To(Equal(actualBalance1.String()))
|
||||
prevBalance1.Set(actualBalance1)
|
||||
|
||||
// Contract 2
|
||||
_, txErr = integration.SendEth(contract2.Address, "0.01")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
actualBalance2.Add(actualBalance2, big.NewInt(10000000000000000))
|
||||
|
||||
balance2AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract2.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance2AfterTransfer.String()).To(Equal(prevBalance2.String()))
|
||||
|
||||
// Contract 3
|
||||
_, txErr = integration.SendEth(contract3.Address, "0.01")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
actualBalance3.Add(actualBalance3, big.NewInt(10000000000000000))
|
||||
|
||||
balance3AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract3.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance3AfterTransfer.String()).To(Equal(actualBalance3.String()))
|
||||
prevBalance3.Set(actualBalance3)
|
||||
|
||||
// Increment counts
|
||||
// Contract 1, countA
|
||||
_, incErr = integration.IncrementCount(contract1.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA1.Add(actualCountA1, big.NewInt(1))
|
||||
|
||||
countA1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1AfterIncrement := new(big.Int).SetBytes(countA1AfterIncrementStorage)
|
||||
Expect(countA1AfterIncrement.String()).To(Equal(actualCountA1.String()))
|
||||
prevCountA1.Set(actualCountA1)
|
||||
|
||||
// Contract 2, countA
|
||||
_, incErr = integration.IncrementCount(contract2.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA2.Add(actualCountA2, big.NewInt(1))
|
||||
|
||||
countA2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2AfterIncrement := new(big.Int).SetBytes(countA2AfterIncrementStorage)
|
||||
Expect(countA2AfterIncrement.String()).To(Equal(prevCountA2.String()))
|
||||
|
||||
// Contract 3, countA
|
||||
_, incErr = integration.IncrementCount(contract3.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA3.Add(actualCountA3, big.NewInt(1))
|
||||
|
||||
countA3AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract3.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA3AfterIncrement := new(big.Int).SetBytes(countA3AfterIncrementStorage)
|
||||
Expect(countA3AfterIncrement.String()).To(Equal(actualCountA3.String()))
|
||||
prevCountA3.Set(actualCountA3)
|
||||
})
|
||||
})
|
||||
|
||||
Context("list of watched addresses cleared", func() {
|
||||
It("indexes state for all the contracts", func() {
|
||||
operation := types.Clear
|
||||
args := []types.WatchAddressArg{}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, operation, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// WatchedAddresses = []
|
||||
// Send eth to all three contract accounts
|
||||
// Contract 1
|
||||
_, txErr = integration.SendEth(contract1.Address, "0.01")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
actualBalance1.Add(actualBalance1, big.NewInt(10000000000000000))
|
||||
|
||||
balance1AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract1.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance1AfterTransfer.String()).To(Equal(actualBalance1.String()))
|
||||
prevBalance1.Set(actualBalance1)
|
||||
|
||||
// Contract 2
|
||||
_, txErr = integration.SendEth(contract2.Address, "0.01")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
actualBalance2.Add(actualBalance2, big.NewInt(10000000000000000))
|
||||
|
||||
balance2AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract2.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance2AfterTransfer.String()).To(Equal(actualBalance2.String()))
|
||||
prevBalance2.Set(actualBalance2)
|
||||
|
||||
// Contract 3
|
||||
_, txErr = integration.SendEth(contract3.Address, "0.01")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
actualBalance3.Add(actualBalance3, big.NewInt(10000000000000000))
|
||||
|
||||
balance3AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract3.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance3AfterTransfer.String()).To(Equal(actualBalance3.String()))
|
||||
prevBalance3.Set(actualBalance3)
|
||||
|
||||
// Increment counts
|
||||
// Contract 1, countA
|
||||
_, incErr = integration.IncrementCount(contract1.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA1.Add(actualCountA1, big.NewInt(1))
|
||||
|
||||
countA1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1AfterIncrement := new(big.Int).SetBytes(countA1AfterIncrementStorage)
|
||||
Expect(countA1AfterIncrement.String()).To(Equal(actualCountA1.String()))
|
||||
prevCountA1.Set(actualCountA1)
|
||||
|
||||
// Contract 2, countA
|
||||
_, incErr = integration.IncrementCount(contract2.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA2.Add(actualCountA2, big.NewInt(1))
|
||||
|
||||
countA2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2AfterIncrement := new(big.Int).SetBytes(countA2AfterIncrementStorage)
|
||||
Expect(countA2AfterIncrement.String()).To(Equal(actualCountA2.String()))
|
||||
prevCountA2.Set(actualCountA2)
|
||||
|
||||
// Contract 3, countA
|
||||
_, incErr = integration.IncrementCount(contract3.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA3.Add(actualCountA3, big.NewInt(1))
|
||||
|
||||
countA3AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract3.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA3AfterIncrement := new(big.Int).SetBytes(countA3AfterIncrementStorage)
|
||||
Expect(countA3AfterIncrement.String()).To(Equal(actualCountA3.String()))
|
||||
prevCountA3.Set(actualCountA3)
|
||||
})
|
||||
})
|
||||
|
||||
Context("with invalid args", func() {
|
||||
It("returns an error on invalid operation arg", func() {
|
||||
operation := "WrongOp"
|
||||
args := []sdtypes.WatchAddressArg{}
|
||||
|
||||
gethErr := gethRPCClient.Call(nil, gethMethod, operation, args)
|
||||
Expect(gethErr).To(HaveOccurred())
|
||||
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, operation, args)
|
||||
Expect(ipldErr).To(HaveOccurred())
|
||||
|
||||
Expect(ipldErr).To(Equal(gethErr))
|
||||
})
|
||||
|
||||
It("returns an error on args of invalid type", func() {
|
||||
operation := types.Add
|
||||
args := []string{"WrongArg"}
|
||||
|
||||
gethErr := gethRPCClient.Call(nil, gethMethod, operation, args)
|
||||
Expect(gethErr).To(HaveOccurred())
|
||||
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, operation, args)
|
||||
Expect(ipldErr).To(HaveOccurred())
|
||||
|
||||
Expect(ipldErr).To(Equal(gethErr))
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,318 @@
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/statediff/types"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
integration "github.com/vulcanize/ipld-eth-server/v3/test"
|
||||
)
|
||||
|
||||
var _ = Describe("Watched address gap filling service integration test", func() {
|
||||
dbWrite, err := strconv.ParseBool(os.Getenv("DB_WRITE"))
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
watchedAddressServiceEnabled, err := strconv.ParseBool(os.Getenv("WATCHED_ADDRESS_GAP_FILLER_ENABLED"))
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
serviceInterval, err := strconv.ParseInt(os.Getenv("WATCHED_ADDRESS_GAP_FILLER_INTERVAL"), 10, 0)
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
gethHttpPath := "http://127.0.0.1:8545"
|
||||
gethRPCClient, err := rpc.Dial(gethHttpPath)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
ipldEthHttpPath := "http://127.0.0.1:8081"
|
||||
ipldClient, err := ethclient.Dial(ipldEthHttpPath)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
ipldRPCClient, err := rpc.Dial(ipldEthHttpPath)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
var (
|
||||
ctx = context.Background()
|
||||
|
||||
contractErr error
|
||||
txErr error
|
||||
|
||||
GLD1 *integration.ContractDeployed
|
||||
SLV1 *integration.ContractDeployed
|
||||
SLV2 *integration.ContractDeployed
|
||||
|
||||
countAIndex string
|
||||
countBIndex string
|
||||
|
||||
oldCountA1 = big.NewInt(0)
|
||||
oldCountA2 = big.NewInt(0)
|
||||
oldCountB2 = big.NewInt(0)
|
||||
|
||||
updatedCountA1 = big.NewInt(1)
|
||||
updatedCountA2 = big.NewInt(1)
|
||||
updatedCountB2 = big.NewInt(1)
|
||||
|
||||
SLV2CountBIncrementedAt *integration.CountIncremented
|
||||
|
||||
contract1Salt = "contract1SLV"
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
if !dbWrite || !watchedAddressServiceEnabled {
|
||||
Skip("skipping watched address gap filling service integration tests")
|
||||
}
|
||||
})
|
||||
|
||||
It("test init", func() {
|
||||
// Clear out watched addresses
|
||||
err := integration.ClearWatchedAddresses(gethRPCClient)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// Deploy a GLD contract
|
||||
GLD1, contractErr = integration.DeployContract()
|
||||
Expect(contractErr).ToNot(HaveOccurred())
|
||||
|
||||
// Watch GLD1 contract
|
||||
operation := types.Add
|
||||
args := []types.WatchAddressArg{
|
||||
{
|
||||
Address: GLD1.Address,
|
||||
CreatedAt: uint64(GLD1.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, operation, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// Deploy two SLV contracts and update storage slots
|
||||
SLV1, contractErr = integration.Create2Contract("SLVToken", contract1Salt)
|
||||
Expect(contractErr).ToNot(HaveOccurred())
|
||||
|
||||
_, txErr = integration.IncrementCount(SLV1.Address, "A")
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
|
||||
SLV2, contractErr = integration.DeploySLVContract()
|
||||
Expect(contractErr).ToNot(HaveOccurred())
|
||||
|
||||
_, txErr = integration.IncrementCount(SLV2.Address, "A")
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
SLV2CountBIncrementedAt, txErr = integration.IncrementCount(SLV2.Address, "B")
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
|
||||
// Get storage slot keys
|
||||
storageSlotAKey, err := integration.GetStorageSlotKey("SLVToken", "countA")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countAIndex = storageSlotAKey.Key
|
||||
|
||||
storageSlotBKey, err := integration.GetStorageSlotKey("SLVToken", "countB")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countBIndex = storageSlotBKey.Key
|
||||
})
|
||||
|
||||
defer It("test cleanup", func() {
|
||||
// Destroy create2 contract
|
||||
_, err := integration.DestroySLVContract(SLV1.Address)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// Clear out watched addresses
|
||||
err = integration.ClearWatchedAddresses(gethRPCClient)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
Context("previously unwatched contract watched", func() {
|
||||
It("indexes state only for watched contract", func() {
|
||||
// WatchedAddresses = [GLD1]
|
||||
// SLV1, countA
|
||||
countA1Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1 := new(big.Int).SetBytes(countA1Storage)
|
||||
Expect(countA1.String()).To(Equal(oldCountA1.String()))
|
||||
|
||||
// SLV2, countA
|
||||
countA2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2 := new(big.Int).SetBytes(countA2Storage)
|
||||
Expect(countA2.String()).To(Equal(oldCountA2.String()))
|
||||
|
||||
// SLV2, countB
|
||||
countB2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV2.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB2 := new(big.Int).SetBytes(countB2Storage)
|
||||
Expect(countB2.String()).To(Equal(oldCountB2.String()))
|
||||
})
|
||||
|
||||
It("indexes past state on watching a contract", func() {
|
||||
// Watch SLV1 contract
|
||||
args := []types.WatchAddressArg{
|
||||
{
|
||||
Address: SLV1.Address,
|
||||
CreatedAt: uint64(SLV1.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, types.Add, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// Sleep for service interval + few extra seconds
|
||||
time.Sleep(time.Duration(serviceInterval+2) * time.Second)
|
||||
|
||||
// WatchedAddresses = [GLD1, SLV1]
|
||||
// SLV1, countA
|
||||
countA1Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1 := new(big.Int).SetBytes(countA1Storage)
|
||||
Expect(countA1.String()).To(Equal(updatedCountA1.String()))
|
||||
|
||||
// SLV2, countA
|
||||
countA2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2 := new(big.Int).SetBytes(countA2Storage)
|
||||
Expect(countA2.String()).To(Equal(oldCountA2.String()))
|
||||
|
||||
// SLV2, countB
|
||||
countB2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV2.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB2 := new(big.Int).SetBytes(countB2Storage)
|
||||
Expect(countB2.String()).To(Equal(oldCountB2.String()))
|
||||
})
|
||||
})
|
||||
|
||||
Context("previously unwatched contract watched (different 'created_at')", func() {
|
||||
It("indexes past state from 'created_at' onwards on watching a contract", func() {
|
||||
// Watch SLV2 (created_at -> countB incremented) contract
|
||||
args := []types.WatchAddressArg{
|
||||
{
|
||||
Address: SLV2.Address,
|
||||
CreatedAt: uint64(SLV2CountBIncrementedAt.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, types.Add, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// Sleep for service interval + few extra seconds
|
||||
time.Sleep(time.Duration(serviceInterval+2) * time.Second)
|
||||
|
||||
// WatchedAddresses = [GLD1, SLV1, SLV2]
|
||||
// SLV2, countA
|
||||
countA2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2 := new(big.Int).SetBytes(countA2Storage)
|
||||
Expect(countA2.String()).To(Equal(oldCountA2.String()))
|
||||
|
||||
// SLV2, countB
|
||||
countB2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV2.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB2 := new(big.Int).SetBytes(countB2Storage)
|
||||
Expect(countB2.String()).To(Equal(updatedCountB2.String()))
|
||||
})
|
||||
|
||||
It("indexes missing past state on watching a contract from an earlier 'created_at'", func() {
|
||||
// Remove SLV2 (created_at -> countB incremented) watched contract
|
||||
args := []types.WatchAddressArg{
|
||||
{
|
||||
Address: SLV2.Address,
|
||||
CreatedAt: uint64(SLV2CountBIncrementedAt.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, types.Remove, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// Watch SLV2 (created_at -> deployment) contract
|
||||
args = []types.WatchAddressArg{
|
||||
{
|
||||
Address: SLV2.Address,
|
||||
CreatedAt: uint64(SLV2.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr = ipldRPCClient.Call(nil, ipldMethod, types.Add, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// Sleep for service interval + few extra seconds
|
||||
time.Sleep(time.Duration(serviceInterval+2) * time.Second)
|
||||
|
||||
// WatchedAddresses = [GLD1, SLV1, SLV2]
|
||||
// SLV2, countA
|
||||
countA2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2 := new(big.Int).SetBytes(countA2Storage)
|
||||
Expect(countA2.String()).To(Equal(updatedCountA2.String()))
|
||||
|
||||
// SLV2, countB
|
||||
countB2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV2.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB2 := new(big.Int).SetBytes(countB2Storage)
|
||||
Expect(countB2.String()).To(Equal(updatedCountB2.String()))
|
||||
})
|
||||
})
|
||||
|
||||
Context("destroyed contract redeployed and watched", func() {
|
||||
It("returns zero value for destroyed contract", func() {
|
||||
_, err := integration.DestroySLVContract(SLV1.Address)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
updatedCountA1 = big.NewInt(0)
|
||||
|
||||
operation := types.Remove
|
||||
args := []types.WatchAddressArg{
|
||||
{
|
||||
Address: SLV1.Address,
|
||||
CreatedAt: uint64(SLV1.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, operation, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// WatchedAddresses = [GLD1, SLV2]
|
||||
// SLV1, countA
|
||||
countA1Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1 := new(big.Int).SetBytes(countA1Storage)
|
||||
Expect(countA1.String()).To(Equal(updatedCountA1.String()))
|
||||
oldCountA1.Set(updatedCountA1)
|
||||
})
|
||||
|
||||
It("indexes state for redeployed contract", func() {
|
||||
// Redeploy contract
|
||||
SLV1, contractErr = integration.Create2Contract("SLVToken", contract1Salt)
|
||||
Expect(contractErr).ToNot(HaveOccurred())
|
||||
|
||||
// Add to watched address
|
||||
operation := types.Add
|
||||
args := []types.WatchAddressArg{
|
||||
{
|
||||
Address: SLV1.Address,
|
||||
CreatedAt: uint64(SLV1.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, operation, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// Sleep for service interval + few extra seconds
|
||||
time.Sleep(time.Duration(serviceInterval+2) * time.Second)
|
||||
|
||||
// WatchedAddresses = [GLD1, SLV2, SLV1]
|
||||
// SLV1, countA
|
||||
countA1Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1 := new(big.Int).SetBytes(countA1Storage)
|
||||
Expect(countA1.String()).To(Equal(updatedCountA1.String()))
|
||||
oldCountA1.Set(updatedCountA1)
|
||||
|
||||
// Update storage slots
|
||||
_, txErr = integration.IncrementCount(SLV1.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
updatedCountA1.Add(updatedCountA1, big.NewInt(1))
|
||||
|
||||
countA1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1AfterIncrement := new(big.Int).SetBytes(countA1AfterIncrementStorage)
|
||||
Expect(countA1AfterIncrement.String()).To(Equal(updatedCountA1.String()))
|
||||
oldCountA1.Set(updatedCountA1)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -19,12 +19,12 @@ package test_config
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/postgres"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var DBConfig postgres.ConnectionParams
|
||||
var DBConfig postgres.Config
|
||||
|
||||
func init() {
|
||||
setTestConfig()
|
||||
@@ -52,9 +52,9 @@ func setTestConfig() {
|
||||
port := vip.GetInt("database.port")
|
||||
name := vip.GetString("database.name")
|
||||
|
||||
DBConfig = postgres.ConnectionParams{
|
||||
Hostname: hn,
|
||||
Name: name,
|
||||
Port: port,
|
||||
DBConfig = postgres.Config{
|
||||
Hostname: hn,
|
||||
DatabaseName: name,
|
||||
Port: port,
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -19,9 +19,9 @@ package version
|
||||
import "fmt"
|
||||
|
||||
const (
|
||||
Major = 0 // Major version component of the current release
|
||||
Minor = 3 // Minor version component of the current release
|
||||
Patch = 9 // Patch version component of the current release
|
||||
Major = 2 // Major version component of the current release
|
||||
Minor = 0 // Minor version component of the current release
|
||||
Patch = 0 // Patch version component of the current release
|
||||
Meta = "" // Version metadata to append to the version string
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user