diff --git a/protocol-testing/docker-compose.yaml b/protocol-testing/docker-compose.yaml index 124c581..393ac6e 100644 --- a/protocol-testing/docker-compose.yaml +++ b/protocol-testing/docker-compose.yaml @@ -27,6 +27,8 @@ services: RPC_URL: "${RPC_URL}" SUBSTREAMS_API_TOKEN: "${SUBSTREAMS_API_TOKEN}" AUTH_API_KEY: "${AUTH_API_KEY}" + # PROTOCOLS to test separated by space and with optional filter + # e.g. "ethereum-balancer-v2=weighted_legacy_creation ethereum-ekubo-v2" entrypoint: ["/entrypoint.sh", "${PROTOCOLS}"] volumes: diff --git a/protocol-testing/entrypoint.sh b/protocol-testing/entrypoint.sh index ecfb401..676af4e 100644 --- a/protocol-testing/entrypoint.sh +++ b/protocol-testing/entrypoint.sh @@ -2,11 +2,22 @@ set -e if [ "$#" -lt 1 ]; then - echo "Usage: $0 test1 [test2 ...]" - exit 1 + echo "Usage: $0 protocol1[=filter] [protocol2 ...] or \"$0 'protocol1[=filter] protocol2'\"" + exit 1 fi -for test in "$@"; do - echo "Running test: /app/substreams/$test" - tycho-protocol-sdk --package-path "/app/substreams/$test" --db-url "$DATABASE_URL" +if [ "$#" -eq 1 ] && [[ "$1" == *" "* ]]; then + IFS=' ' read -r -a args <<< "$1" +else + args=("$@") +fi + +for test in "${args[@]}"; do + protocol="${test%%=*}" + filter="${test#*=}" + if [[ "$test" == *"="* ]]; then + tycho-protocol-sdk --package-path "/app/substreams/$protocol" --db-url "$DATABASE_URL" --match-test "$filter" + else + tycho-protocol-sdk --package-path "/app/substreams/$protocol" --db-url "$DATABASE_URL" + fi done diff --git a/protocol-testing/src/test_runner.rs b/protocol-testing/src/test_runner.rs index 13bb82e..6e8d3fa 100644 --- a/protocol-testing/src/test_runner.rs +++ b/protocol-testing/src/test_runner.rs @@ -78,21 +78,27 @@ impl TestRunner { .map(|size| size.cols as usize - 35) // Remove length of log prefix .unwrap_or(80); - info!("Running {} tests ...\n", config.tests.len()); + let tests = match &self.match_test { + Some(filter) => config + .tests + .iter() + .filter(|test| test.name.contains(filter)) + .collect::>(), + None => config + .tests + .iter() + .collect::>(), + }; + let tests_count = tests.len(); + + info!("Running {} tests ...\n", tests_count); info!("{}\n", "-".repeat(terminal_width)); let mut failed_tests: Vec = Vec::new(); let mut count = 1; - for test in &config.tests { + for test in &tests { info!("TEST {}: {}", count, test.name); - if let Some(match_test) = &self.match_test { - if !test.name.contains(match_test) { - info!("Skipping test (does not match filter: {match_test})\n"); - count += 1; - continue; - } - } match self.run_test(test, &config, config.skip_balance_check) { Ok(_) => { @@ -109,7 +115,7 @@ impl TestRunner { } info!("Tests finished!"); - info!("Passed {}/{}", config.tests.len() - failed_tests.len(), config.tests.len()); + info!("Passed {}/{}", tests_count - failed_tests.len(), tests_count); if !failed_tests.is_empty() { error!("Failed: {}", failed_tests.join(", ")); }