Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update & increase resliency of e2e tests #38

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ METRIC_PARTITIONING_ROUTINE_DELAY_FIRST_RUN_SECONDS=10
# defaults to 7 days / 1 week if not set,
# max value of 28, min value of 1
METRIC_PARTITIONINING_PREFILL_PERIOD_DAYS=7
# Used by `ready` script to ensure metric partitions have been created.
MINIMUM_REQUIRED_PARTITIONS=30

##### Database Config
POSTGRES_PASSWORD=password
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ refresh:
.PHONY: ready
ready:
./scripts/wait-for-kava-node-running.sh && \
./scripts/wait-for-proxy-service-running.sh
./scripts/wait-for-proxy-service-running.sh && \
./scripts/wait-for-proxy-service-database-metric-partitions.sh

.PHONY: logs
# follow the logs from all the dockerized services
Expand Down
10 changes: 8 additions & 2 deletions docker/kava/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,16 @@ laddr = "tcp://0.0.0.0:26657"
cors_allowed_origins = []

# A list of methods the client is allowed to use with cross-domain requests
cors_allowed_methods = ["HEAD", "GET", "POST", ]
cors_allowed_methods = ["HEAD", "GET", "POST"]

# A list of non simple headers the client is allowed to use with cross-domain requests
cors_allowed_headers = ["Origin", "Accept", "Content-Type", "X-Requested-With", "X-Server-Time", ]
cors_allowed_headers = [
"Origin",
"Accept",
"Content-Type",
"X-Requested-With",
"X-Server-Time",
]

# TCP or UNIX socket address for the gRPC server to listen on
# NOTE: This server only supports /broadcast_tx_commit
Expand Down
134 changes: 35 additions & 99 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/kava-labs/kava-proxy-service/decode"
"github.com/kava-labs/kava-proxy-service/logging"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -54,42 +55,30 @@ var (
func TestE2ETestProxyReturnsNonZeroLatestBlockHeader(t *testing.T) {
client, err := ethclient.Dial(proxyServiceURL)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

header, err := client.HeaderByNumber(testContext, nil)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

assert.Greater(t, int(header.Number.Int64()), 0)
}

func TestE2ETestProxyProxiesForMultipleHosts(t *testing.T) {
client, err := ethclient.Dial(proxyServiceURL)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

header, err := client.HeaderByNumber(testContext, nil)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

assert.Greater(t, int(header.Number.Int64()), 0)

dataClient, err := ethclient.Dial(proxyServiceDataURL)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

header, err = dataClient.HeaderByNumber(testContext, nil)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

assert.Greater(t, int(header.Number.Int64()), 0)
}
Expand All @@ -99,15 +88,11 @@ func TestE2ETestProxyCreatesRequestMetricForEachRequest(t *testing.T) {
// create api and database clients
client, err := ethclient.Dial(proxyServiceURL)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

databaseClient, err := database.NewPostgresClient(databaseConfig)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

// make request to api and track start / end time of the request to
startTime := time.Now()
Expand All @@ -116,9 +101,7 @@ func TestE2ETestProxyCreatesRequestMetricForEachRequest(t *testing.T) {

endTime := time.Now()

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

// lookup all the request metrics in the database
// paging as necessary
Expand All @@ -127,18 +110,14 @@ func TestE2ETestProxyCreatesRequestMetricForEachRequest(t *testing.T) {

proxiedRequestMetricsPage, nextCursor, err := database.ListProxiedRequestMetricsWithPagination(testContext, databaseClient.DB, nextCursor, 10000)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

proxiedRequestMetrics = proxiedRequestMetricsPage

for nextCursor != 0 {
proxiedRequestMetricsPage, nextCursor, err = database.ListProxiedRequestMetricsWithPagination(testContext, databaseClient.DB, nextCursor, 10000)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

proxiedRequestMetrics = append(proxiedRequestMetrics, proxiedRequestMetricsPage...)

Expand Down Expand Up @@ -177,24 +156,18 @@ func TestE2ETestProxyTracksBlockNumberForEth_getBlockByNumberRequest(t *testing.
// create api and database clients
client, err := ethclient.Dial(proxyServiceURL)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

databaseClient, err := database.NewPostgresClient(databaseConfig)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

// get the latest queryable block number
// need to do this dynamically since not all blocks
// are queryable for a given network
response, err := client.HeaderByNumber(testContext, nil)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

requestBlockNumber := response.Number

Expand All @@ -205,9 +178,7 @@ func TestE2ETestProxyTracksBlockNumberForEth_getBlockByNumberRequest(t *testing.

endTime := time.Now()

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

// lookup all the request metrics in the database
// paging as necessary
Expand All @@ -216,18 +187,14 @@ func TestE2ETestProxyTracksBlockNumberForEth_getBlockByNumberRequest(t *testing.

proxiedRequestMetricsPage, nextCursor, err := database.ListProxiedRequestMetricsWithPagination(testContext, databaseClient.DB, nextCursor, 10000)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

proxiedRequestMetrics = proxiedRequestMetricsPage

for nextCursor != 0 {
proxiedRequestMetricsPage, nextCursor, err = database.ListProxiedRequestMetricsWithPagination(testContext, databaseClient.DB, nextCursor, 10000)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

proxiedRequestMetrics = append(proxiedRequestMetrics, proxiedRequestMetricsPage...)

Expand Down Expand Up @@ -260,15 +227,11 @@ func TestE2ETestProxyTracksBlockTagForEth_getBlockByNumberRequest(t *testing.T)
// create api and database clients
client, err := ethclient.Dial(proxyServiceURL)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

databaseClient, err := database.NewPostgresClient(databaseConfig)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

// make request to api and track start / end time of the request to
startTime := time.Now()
Expand All @@ -278,9 +241,7 @@ func TestE2ETestProxyTracksBlockTagForEth_getBlockByNumberRequest(t *testing.T)

endTime := time.Now()

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

// lookup all the request metrics in the database
// paging as necessary
Expand All @@ -289,18 +250,14 @@ func TestE2ETestProxyTracksBlockTagForEth_getBlockByNumberRequest(t *testing.T)

proxiedRequestMetricsPage, nextCursor, err := database.ListProxiedRequestMetricsWithPagination(testContext, databaseClient.DB, nextCursor, 10000)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

proxiedRequestMetrics = proxiedRequestMetricsPage

for nextCursor != 0 {
proxiedRequestMetricsPage, nextCursor, err = database.ListProxiedRequestMetricsWithPagination(testContext, databaseClient.DB, nextCursor, 10000)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

proxiedRequestMetrics = append(proxiedRequestMetrics, proxiedRequestMetricsPage...)

Expand Down Expand Up @@ -336,25 +293,17 @@ func TestE2ETestProxyTracksBlockNumberForMethodsWithBlockNumberParam(t *testing.

// create api and database clients
client, err := ethclient.Dial(proxyServiceURL)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

databaseClient, err := database.NewPostgresClient(databaseConfig)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

// get the latest queryable block number
// need to do this dynamically since not all blocks
// are queryable for a given network
latestBlock, err := client.HeaderByNumber(testContext, nil)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

requestBlockNumber := latestBlock.Number

Expand Down Expand Up @@ -385,7 +334,8 @@ func TestE2ETestProxyTracksBlockNumberForMethodsWithBlockNumberParam(t *testing.
// eth_call
_, _ = client.CallContract(testContext, ethereum.CallMsg{}, requestBlockNumber)

endTime := time.Now()
// plus a buffer for slower connections (amd64 lol) :)
endTime := time.Now().Add(10)

// lookup all the request metrics in the database
// paging as necessary
Expand All @@ -394,18 +344,14 @@ func TestE2ETestProxyTracksBlockNumberForMethodsWithBlockNumberParam(t *testing.

proxiedRequestMetricsPage, nextCursor, err := database.ListProxiedRequestMetricsWithPagination(testContext, databaseClient.DB, nextCursor, 10000)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

proxiedRequestMetrics = proxiedRequestMetricsPage

for nextCursor != 0 {
proxiedRequestMetricsPage, nextCursor, err = database.ListProxiedRequestMetricsWithPagination(testContext, databaseClient.DB, nextCursor, 10000)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

proxiedRequestMetrics = append(proxiedRequestMetrics, proxiedRequestMetricsPage...)

Expand Down Expand Up @@ -446,24 +392,18 @@ func TestE2ETestProxyTracksBlockNumberForMethodsWithBlockHashParam(t *testing.T)
// create api and database clients
client, err := ethclient.Dial(proxyServiceURL)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

databaseClient, err := database.NewPostgresClient(databaseConfig)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

// get the latest queryable block number
// need to do this dynamically since not all blocks
// are queryable for a given network
latestBlock, err := client.HeaderByNumber(testContext, nil)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

requestBlockHash := latestBlock.ParentHash
// minus one since we are looking up the parent block
Expand Down Expand Up @@ -492,18 +432,14 @@ func TestE2ETestProxyTracksBlockNumberForMethodsWithBlockHashParam(t *testing.T)

proxiedRequestMetricsPage, nextCursor, err := database.ListProxiedRequestMetricsWithPagination(testContext, databaseClient.DB, nextCursor, 10000)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

proxiedRequestMetrics = proxiedRequestMetricsPage

for nextCursor != 0 {
proxiedRequestMetricsPage, nextCursor, err = database.ListProxiedRequestMetricsWithPagination(testContext, databaseClient.DB, nextCursor, 10000)

if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

proxiedRequestMetrics = append(proxiedRequestMetrics, proxiedRequestMetricsPage...)

Expand Down
Loading