Skip to content

Commit

Permalink
Merge pull request #519 from oasisprotocol/andrew7234/item-analyzer-r…
Browse files Browse the repository at this point in the history
…egression-tests

testing: extend regression tests to item analyzers
  • Loading branch information
Andrew7234 authored Sep 23, 2023
2 parents 8c05889 + a70d004 commit ba51dd9
Show file tree
Hide file tree
Showing 31 changed files with 1,947 additions and 62 deletions.
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,19 @@ test-e2e:
@$(GO) test -race -coverpkg=./... -coverprofile=coverage.txt -covermode=atomic -v ./tests/e2e

fill-cache-for-e2e-regression: nexus
cp tests/e2e_regression/e2e_config.yml /tmp/nexus_fill_e2e_regression_cache.yml
sed -i -E 's/query_on_cache_miss: false/query_on_cache_miss: true/g' /tmp/nexus_fill_e2e_regression_cache.yml
./nexus --config /tmp/nexus_fill_e2e_regression_cache.yml analyze
@./tests/e2e_regression/ensure_consistent_config.sh
cp tests/e2e_regression/e2e_config_1.yml /tmp/nexus_fill_e2e_regression_cache_1.yml
cp tests/e2e_regression/e2e_config_2.yml /tmp/nexus_fill_e2e_regression_cache_2.yml
sed -i -E 's/query_on_cache_miss: false/query_on_cache_miss: true/g' /tmp/nexus_fill_e2e_regression_cache_*.yml
./nexus --config /tmp/nexus_fill_e2e_regression_cache_1.yml analyze
./nexus --config /tmp/nexus_fill_e2e_regression_cache_2.yml analyze

# Run the api tests locally, assuming the environment is set up with an oasis-node that is
# accessible as specified in the config file.
test-e2e-regression: nexus
./nexus --config tests/e2e_regression/e2e_config.yml analyze
@./tests/e2e_regression/ensure_consistent_config.sh
./nexus --config tests/e2e_regression/e2e_config_1.yml analyze
./nexus --config tests/e2e_regression/e2e_config_2.yml analyze
@$(ECHO) "$(CYAN)*** Analyzers finished; starting api tests...$(OFF)"
./tests/e2e_regression/run.sh

Expand Down
5 changes: 3 additions & 2 deletions storage/client/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ const (
EntityNodeIds = `
SELECT id
FROM chain.nodes
WHERE entity_id = $1::text`
WHERE entity_id = $1::text
ORDER BY id`

EntityNodes = `
SELECT id, entity_id, expiration, tls_pubkey, tls_next_pubkey, p2p_pubkey, consensus_pubkey, roles
Expand Down Expand Up @@ -524,7 +525,7 @@ const (
WHERE
(balances.runtime = $1::runtime) AND
(balances.token_address = $2::oasis_addr)
ORDER BY balance DESC
ORDER BY balance DESC, holder_addr
LIMIT $3::bigint
OFFSET $4::bigint`

Expand Down
42 changes: 42 additions & 0 deletions tests/e2e_regression/e2e_config_1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
analysis:
source:
cache:
cache_dir: tests/e2e_regression/rpc-cache
query_on_cache_miss: false
chain_name: mainnet
nodes:
damask:
default: { rpc: unix:/tmp/node.sock }
fast_startup: true
analyzers:
# metadata_registry:
# interval: 5m
# node_stats: {}
# aggregate_stats: {}
consensus:
from: 8_048_956 # Damask genesis
to: 8_049_056 # 100 blocks; fast enough for early testing
emerald:
from: 1_003_298 # round at Damask genesis
to: 1_003_598
# sapphire:
# from: 0 # first round in Damask
storage:
backend: postgres
endpoint: postgresql://rwuser:password@localhost:5432/indexer?sslmode=disable
DANGER__WIPE_STORAGE_ON_STARTUP: true
migrations: file://storage/migrations

server:
chain_name: mainnet
endpoint: localhost:8008
storage:
endpoint: postgresql://api:password@localhost:5432/indexer?sslmode=disable
backend: postgres

log:
level: debug
format: json

metrics:
pull_endpoint: localhost:8009
41 changes: 41 additions & 0 deletions tests/e2e_regression/e2e_config_2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
analysis:
source:
cache:
cache_dir: tests/e2e_regression/rpc-cache
query_on_cache_miss: false
chain_name: mainnet
nodes:
damask:
default: { rpc: unix:/tmp/node.sock }
fast_startup: true
analyzers:
# metadata_registry:
# interval: 5m
# node_stats: {}
# aggregate_stats: {}
# consensus:
# from: 8_048_956 # Damask genesis
# to: 8_049_056 # 100 blocks; fast enough for early testing
# emerald:
# from: 1_003_298 # round at Damask genesis
# to: 1_003_598
# sapphire:
# from: 0 # first round in Damask
evm_tokens_emerald:
stop_on_empty_queue: true
evm_token_balances_emerald:
stop_on_empty_queue: true
evm_contract_code_emerald:
stop_on_empty_queue: true
storage:
backend: postgres
endpoint: postgresql://rwuser:password@localhost:5432/indexer?sslmode=disable
# DANGER__WIPE_STORAGE_ON_STARTUP: true
migrations: file://storage/migrations

log:
level: debug
format: json

metrics:
pull_endpoint: localhost:8009
24 changes: 24 additions & 0 deletions tests/e2e_regression/ensure_consistent_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -euo pipefail

# Our e2e regression test runs the analyzer twice in close succession. This is a slightly hacky but
# simple way to ensure block analyzers run first, and non-block analyzers perform EVM queries always
# at the same height, thereby hitting the offline response cache.
#
# This script compares the key parameters of the two config files used in the two runs. If any of
# those parameters differ, it shows the diff and exits with an error.

# Element of the config files that we'll compare
important_attrs='{"cache": .analysis.source.cache.cache_dir, "chain_name": .analysis.source.chain_name, "db": .analysis.storage.endpoint}'

# Enables aliases to work in non-interactive shells.
shopt -s expand_aliases

# A converter whose only dependency is python3, which is likely preinstalled
alias yaml2json="python3 -c 'import sys,yaml,json; print(json.dumps(yaml.safe_load(str(sys.stdin.read()))))'"

# Compare
cat tests/e2e_regression/e2e_config_1.yml | yaml2json | jq "$important_attrs" > /tmp/e2e_config_1.summary
cat tests/e2e_regression/e2e_config_2.yml | yaml2json | jq "$important_attrs" > /tmp/e2e_config_2.summary
diff /tmp/e2e_config_1.summary /tmp/e2e_config_2.summary || { echo "The two config files for e2e tests differ in key parameters! See diff above."; exit 1; }
34 changes: 34 additions & 0 deletions tests/e2e_regression/expected/emerald_account_with_evm_token.body
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"address": "oasis1qpwx3ptmvcceqkd4syjmqf9jmdlf90xmuuy0f6y9",
"address_preimage": {
"address_data": "Utw6hind6cMAHNjmGTAcsO9qrmI=",
"context": "oasis-runtime-sdk/address: secp256k1eth",
"context_version": 0
},
"balances": [],
"evm_balances": [
{
"balance": "61055757056562273564127",
"token_contract_addr": "oasis1qpgcp5jzlgk4hcenaj2x82rqk8rrve2keyuc8aaf",
"token_contract_addr_eth": "0x21C718C22D52d0F3a789b752D4c2fD5908a8A733",
"token_decimals": 18,
"token_name": "Wrapped ROSE",
"token_symbol": "wROSE",
"token_type": "ERC20"
},
{
"balance": "39480182353477716916987",
"token_contract_addr": "oasis1qqed7mp902c0n76h5tk4k3fgu3vnhd5yhql4482n",
"token_contract_addr_eth": "0xBC033203796CC2C8C543a5aAe93a9a643320433D",
"token_decimals": 18,
"token_name": "ValleySwap Token",
"token_symbol": "VS",
"token_type": "ERC20"
}
],
"stats": {
"num_txns": 10,
"total_received": "0",
"total_sent": "0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Origin
Date: UNINTERESTING
Content-Length: UNINTERESTING

3 changes: 2 additions & 1 deletion tests/e2e_regression/expected/emerald_contract_account.body

Large diffs are not rendered by default.

Loading

0 comments on commit ba51dd9

Please sign in to comment.