Environment improvements for Docker and testing. #83

Merged
telackey merged 5 commits from telackey/testenv into main 2022-11-03 02:31:04 +00:00
6 changed files with 87 additions and 68 deletions

View File

@ -13,9 +13,9 @@ RUN GCO_ENABLED=0 GOOS=linux go build -race -ldflags="-s -w" -o ipld-eth-beacon-
RUN chmod +x ipld-eth-beacon-indexer RUN chmod +x ipld-eth-beacon-indexer
FROM frolvlad/alpine-bash:latest FROM frolvlad/alpine-bash:latest
RUN apk --no-cache add ca-certificates libstdc++ busybox-extras RUN apk --no-cache add ca-certificates libstdc++ busybox-extras gettext libintl
WORKDIR /root/ WORKDIR /root/
COPY --from=builder /go/src/github.com/vulcanize/ipld-eth-beacon-indexer/ipld-eth-beacon-indexer /root/ipld-eth-beacon-indexer COPY --from=builder /go/src/github.com/vulcanize/ipld-eth-beacon-indexer/ipld-eth-beacon-indexer /root/ipld-eth-beacon-indexer
ADD entrypoint.sh . ADD entrypoint.sh .
ADD ipld-eth-beacon-config.json . ADD ipld-eth-beacon-config-docker.json .
ENTRYPOINT ["./entrypoint.sh"] ENTRYPOINT ["./entrypoint.sh"]

View File

@ -3,6 +3,8 @@
sleep 10 sleep 10
echo "Starting ipld-eth-beacon-indexer" echo "Starting ipld-eth-beacon-indexer"
cat /root/ipld-eth-beacon-config-docker.json | envsubst > /root/ipld-eth-beacon-config.json
echo /root/ipld-eth-beacon-indexer capture ${CAPTURE_MODE} --config /root/ipld-eth-beacon-config.json > /root/ipld-eth-beacon-indexer.output echo /root/ipld-eth-beacon-indexer capture ${CAPTURE_MODE} --config /root/ipld-eth-beacon-config.json > /root/ipld-eth-beacon-indexer.output
if [ ${CAPTURE_MODE} == "boot" ]; then if [ ${CAPTURE_MODE} == "boot" ]; then
@ -14,9 +16,10 @@ if [ ${CAPTURE_MODE} == "boot" ]; then
else else
echo "ipld-eth-beacon-indexer boot succeeded" echo "ipld-eth-beacon-indexer boot succeeded"
fi fi
echo $rv > /root/HEALTH
echo $rv echo $rv > /root/HEALTH
cat /root/ipld-eth-beacon-indexer.output echo $rv
cat /root/ipld-eth-beacon-indexer.output
tail -f /dev/null tail -f /dev/null
else else

View File

@ -0,0 +1,44 @@
{
"db": {
"address": "${POSTGRES_HOST}",
"password": "${POSTGRES_PASSWORD}",
"port": ${POSTGRES_PORT},
"username": "${POSTGRES_USER}",
"name": "${POSTGRES_DB}",
"driver": "PGX"
},
"bc": {
"address": "${LIGHTHOUSE_HOST}",
"port": ${LIGHTHOUSE_PORT},
"type": "lighthouse",
"bootRetryInterval": 30,
"bootMaxRetry": 5,
"maxHistoricProcessWorker": ${BC_MAX_HISTORIC_PROCESS_WORKER},
"connectionProtocol": "${LIGHTHOUSE_PROTOCOL}",
"uniqueNodeIdentifier": ${BC_UNIQUE_NODE_IDENTIFIER},
"checkDb": ${BC_CHECK_DB},
"performBeaconStateProcessing": ${BC_BEACON_STATE_PROCESSING_ENABLED},
"performBeaconBlockProcessing": ${BC_BEACON_BLOCK_PROCESSING_ENABLED},
"minimumSlot": ${BC_MINIMUM_SLOT}
},
"t": {
"skipSync": true
},
"log": {
"level": "${LOG_LEVEL}",
"output": true,
"file": "./ipld-eth-beacon-indexer.log",
"format": "json"
},
"kg": {
"increment": ${KG_INCREMENT},
"processKnownGaps": ${KG_PROCESS_KNOWN_GAPS_ENABLED},
"maxKnownGapsWorker": ${KG_MAX_KNOWN_GAPS_WORKER},
"minimumSlot": ${KG_MINIMUM_SLOT}
},
"pm": {
"address": "${PROM_HOST}",
"port": ${PROM_PORT},
"metrics": ${PROM_METRICS_ENABLED}
}
}

View File

@ -1,44 +0,0 @@
{
"db": {
"address": "localhost",
"password": "password",
"port": 5432,
"username": "vdbm",
"name": "vulcanize_db",
"driver": "PGX"
},
"bc": {
"address": "localhost",
"port": 5052,
"type": "lighthouse",
"bootRetryInterval": 30,
"bootMaxRetry": 5,
"maxHistoricProcessWorker": 2,
"connectionProtocol": "http",
"uniqueNodeIdentifier": 100,
"checkDb": true,
"performBeaconStateProcessing": false,
"performBeaconBlockProcessing": true,
"minimumSlot": 4700013
},
"t": {
"skipSync": true
},
"log": {
"level": "debug",
"output": true,
"file": "./ipld-eth-beacon-indexer.log",
"format": "json"
},
"kg": {
"increment": 10000,
"processKnownGaps": true,
"maxKnownGapsWorker": 2,
"minimumSlot": 4700013
},
"pm": {
"address": "localhost",
"port": 9000,
"metrics": true
}
}

View File

@ -17,12 +17,14 @@ import (
"github.com/vulcanize/ipld-eth-beacon-indexer/pkg/beaconclient" "github.com/vulcanize/ipld-eth-beacon-indexer/pkg/beaconclient"
"github.com/vulcanize/ipld-eth-beacon-indexer/pkg/database/sql" "github.com/vulcanize/ipld-eth-beacon-indexer/pkg/database/sql"
"math/big" "math/big"
"os"
"strconv"
"time" "time"
) )
var _ = Describe("e2emerge", Label("e2e"), func() { var _ = Describe("e2emerge", Label("e2e"), func() {
e2eConfig := TestConfig e2eConfig := TestConfig
e2eConfig.port = 5052 e2eConfig.port = getEnvInt("TEST_E2E_LIGHTHOUSE_PORT", 5052)
e2eConfig.performBeaconStateProcessing = false e2eConfig.performBeaconStateProcessing = false
e2eConfig.performBeaconBlockProcessing = true e2eConfig.performBeaconBlockProcessing = true
@ -123,10 +125,10 @@ func sendTestTx() (*SentTx, error) {
tx, err := sendTransaction( tx, err := sendTransaction(
ctx, ctx,
eth, eth,
"0xe6ce22afe802caf5ff7d3845cec8c736ecc8d61f", getEnvStr("TEST_E2E_FROM_ADDR", "0xe6ce22afe802caf5ff7d3845cec8c736ecc8d61f"),
"0xe22AD83A0dE117bA0d03d5E94Eb4E0d80a69C62a", getEnvStr("TEST_E2E_TO_ADDR", "0xe22AD83A0dE117bA0d03d5E94Eb4E0d80a69C62a"),
10, int64(getEnvInt("TEST_E2E_AMOUNT", 10)),
"0x888814df89c4358d7ddb3fa4b0213e7331239a80e1f013eaa7b2deca2a41a218", getEnvStr("TEST_E2E_SIGNING_KEY", "0x888814df89c4358d7ddb3fa4b0213e7331239a80e1f013eaa7b2deca2a41a218"),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
@ -155,7 +157,7 @@ func sendTestTx() (*SentTx, error) {
} }
func createClient() (*ethclient.Client, error) { func createClient() (*ethclient.Client, error) {
return ethclient.Dial("http://localhost:8545") return ethclient.Dial(getEnvStr("TEST_E2E_GETH_URL", "http://localhost:8545"))
} }
// sendTransaction sends a transaction with 1 ETH to a specified address. // sendTransaction sends a transaction with 1 ETH to a specified address.
@ -165,7 +167,7 @@ func sendTransaction(ctx context.Context, eth *ethclient.Client, fromAddr string
to = common.HexToAddress(toAddr) to = common.HexToAddress(toAddr)
sk = crypto.ToECDSAUnsafe(common.FromHex(signingKey)) sk = crypto.ToECDSAUnsafe(common.FromHex(signingKey))
value = big.NewInt(amount) value = big.NewInt(amount)
gasLimit = uint64(21000) gasLimit = uint64(getEnvInt("TEST_E2E_GAS_LIMIT", 21000))
) )
// Retrieve the chainid (needed for signer) // Retrieve the chainid (needed for signer)
chainid, err := eth.ChainID(ctx) chainid, err := eth.ChainID(ctx)
@ -180,6 +182,8 @@ func sendTransaction(ctx context.Context, eth *ethclient.Client, fromAddr string
// Get suggested gas price // Get suggested gas price
tipCap, _ := eth.SuggestGasTipCap(ctx) tipCap, _ := eth.SuggestGasTipCap(ctx)
feeCap, _ := eth.SuggestGasPrice(ctx) feeCap, _ := eth.SuggestGasPrice(ctx)
log.Info("Tip cap: ", tipCap)
log.Info("Fee cap: ", feeCap)
// Create a new transaction // Create a new transaction
tx := types.NewTx( tx := types.NewTx(
&types.DynamicFeeTx{ &types.DynamicFeeTx{
@ -197,3 +201,25 @@ func sendTransaction(ctx context.Context, eth *ethclient.Client, fromAddr string
// Send the transaction to our node // Send the transaction to our node
return signedTx, eth.SendTransaction(ctx, signedTx) return signedTx, eth.SendTransaction(ctx, signedTx)
} }
func getEnvStr(envVar string, def string) string {
value, set := os.LookupEnv(envVar)
if set {
return value
} else {
return def
}
}
func getEnvInt(envVar string, def int) int {
value, set := os.LookupEnv(envVar)
if set {
number, err := strconv.Atoi(value)
if err != nil {
return def
}
return number
} else {
return def
}
}

View File

@ -3,7 +3,6 @@ package beaconclient_test
import ( import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"os" "os"
"strconv"
"time" "time"
. "github.com/onsi/ginkgo/v2" . "github.com/onsi/ginkgo/v2"
@ -15,9 +14,9 @@ var (
prodConfig = Config{ prodConfig = Config{
protocol: os.Getenv("bc_protocol"), protocol: os.Getenv("bc_protocol"),
address: os.Getenv("bc_address"), address: os.Getenv("bc_address"),
port: getEnvInt(os.Getenv("bc_port")), port: getEnvInt(os.Getenv("bc_port"), 5052),
dbHost: os.Getenv("db_host"), dbHost: os.Getenv("db_host"),
dbPort: getEnvInt(os.Getenv("db_port")), dbPort: getEnvInt(os.Getenv("db_port"), 8076),
dbName: os.Getenv("db_name"), dbName: os.Getenv("db_name"),
dbUser: os.Getenv("db_user"), dbUser: os.Getenv("db_user"),
dbPassword: os.Getenv("db_password"), dbPassword: os.Getenv("db_password"),
@ -62,15 +61,6 @@ var _ = Describe("Systemvalidation", Label("system"), func() {
}) })
}) })
// Wrapper function to get int env variables.
func getEnvInt(envVar string) int {
val, err := strconv.Atoi(envVar)
if err != nil {
return 0
}
return val
}
// Start head tracking and wait for the expected results. // Start head tracking and wait for the expected results.
func processProdHeadBlocks(bc *beaconclient.BeaconClient, expectedInserts, expectedReorgs, expectedKnownGaps, expectedKnownGapsReprocessError uint64) { func processProdHeadBlocks(bc *beaconclient.BeaconClient, expectedInserts, expectedReorgs, expectedKnownGaps, expectedKnownGapsReprocessError uint64) {
go bc.CaptureHead() go bc.CaptureHead()