From 35c113e5326886257afc243aa0fa065602ad57cd Mon Sep 17 00:00:00 2001 From: yuunlimm Date: Wed, 16 Oct 2024 12:23:57 -0700 Subject: [PATCH] use sdk parser cli --- rust/Cargo.lock | 17 +-- rust/Cargo.toml | 6 +- rust/integration-tests/src/cli_parser.rs | 104 +++++++++--------- .../src/diff_tests/all_tests.rs | 38 +------ 4 files changed, 69 insertions(+), 96 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index f4a5aafb8..e8c5fb347 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -141,7 +141,7 @@ checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" [[package]] name = "aptos-indexer-processor-sdk" version = "0.1.0" -source = "git+https://github.com/aptos-labs/aptos-indexer-processor-sdk.git?rev=d7a6c8492c0ef73c19d8d83dae537065481e240f#d7a6c8492c0ef73c19d8d83dae537065481e240f" +source = "git+https://github.com/aptos-labs/aptos-indexer-processor-sdk.git?rev=8d8c6625abf32d890128eb824ac3006fd8115842#8d8c6625abf32d890128eb824ac3006fd8115842" dependencies = [ "ahash", "anyhow", @@ -174,7 +174,7 @@ dependencies = [ [[package]] name = "aptos-indexer-processor-sdk-server-framework" version = "1.0.0" -source = "git+https://github.com/aptos-labs/aptos-indexer-processor-sdk.git?rev=d7a6c8492c0ef73c19d8d83dae537065481e240f#d7a6c8492c0ef73c19d8d83dae537065481e240f" +source = "git+https://github.com/aptos-labs/aptos-indexer-processor-sdk.git?rev=8d8c6625abf32d890128eb824ac3006fd8115842#8d8c6625abf32d890128eb824ac3006fd8115842" dependencies = [ "anyhow", "aptos-indexer-processor-sdk", @@ -207,7 +207,7 @@ dependencies = [ [[package]] name = "aptos-indexer-testing-framework" version = "0.1.0" -source = "git+https://github.com/aptos-labs/aptos-indexer-processor-sdk.git?rev=d7a6c8492c0ef73c19d8d83dae537065481e240f#d7a6c8492c0ef73c19d8d83dae537065481e240f" +source = "git+https://github.com/aptos-labs/aptos-indexer-processor-sdk.git?rev=8d8c6625abf32d890128eb824ac3006fd8115842#8d8c6625abf32d890128eb824ac3006fd8115842" dependencies = [ "anyhow", "aptos-indexer-processor-sdk", @@ -219,6 +219,7 @@ dependencies = [ "futures", "futures-util", "native-tls", + "once_cell", "postgres-native-tls", "serde_json", "testcontainers", @@ -233,10 +234,10 @@ dependencies = [ [[package]] name = "aptos-indexer-transaction-stream" version = "0.1.0" -source = "git+https://github.com/aptos-labs/aptos-indexer-processor-sdk.git?rev=d7a6c8492c0ef73c19d8d83dae537065481e240f#d7a6c8492c0ef73c19d8d83dae537065481e240f" +source = "git+https://github.com/aptos-labs/aptos-indexer-processor-sdk.git?rev=8d8c6625abf32d890128eb824ac3006fd8115842#8d8c6625abf32d890128eb824ac3006fd8115842" dependencies = [ "anyhow", - "aptos-moving-average 0.1.0 (git+https://github.com/aptos-labs/aptos-indexer-processor-sdk.git?rev=d7a6c8492c0ef73c19d8d83dae537065481e240f)", + "aptos-moving-average 0.1.0 (git+https://github.com/aptos-labs/aptos-indexer-processor-sdk.git?rev=8d8c6625abf32d890128eb824ac3006fd8115842)", "aptos-protos 1.3.1 (git+https://github.com/aptos-labs/aptos-core.git?rev=5c48aee129b5a141be2792ffa3d9bd0a1a61c9cb)", "chrono", "futures-util", @@ -261,7 +262,7 @@ dependencies = [ [[package]] name = "aptos-moving-average" version = "0.1.0" -source = "git+https://github.com/aptos-labs/aptos-indexer-processor-sdk.git?rev=d7a6c8492c0ef73c19d8d83dae537065481e240f#d7a6c8492c0ef73c19d8d83dae537065481e240f" +source = "git+https://github.com/aptos-labs/aptos-indexer-processor-sdk.git?rev=8d8c6625abf32d890128eb824ac3006fd8115842#8d8c6625abf32d890128eb824ac3006fd8115842" dependencies = [ "chrono", ] @@ -2245,7 +2246,7 @@ dependencies = [ [[package]] name = "instrumented-channel" version = "0.1.0" -source = "git+https://github.com/aptos-labs/aptos-indexer-processor-sdk.git?rev=d7a6c8492c0ef73c19d8d83dae537065481e240f#d7a6c8492c0ef73c19d8d83dae537065481e240f" +source = "git+https://github.com/aptos-labs/aptos-indexer-processor-sdk.git?rev=8d8c6625abf32d890128eb824ac3006fd8115842#8d8c6625abf32d890128eb824ac3006fd8115842" dependencies = [ "delegate", "derive_builder", @@ -4128,7 +4129,7 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "sample" version = "0.1.0" -source = "git+https://github.com/aptos-labs/aptos-indexer-processor-sdk.git?rev=d7a6c8492c0ef73c19d8d83dae537065481e240f#d7a6c8492c0ef73c19d8d83dae537065481e240f" +source = "git+https://github.com/aptos-labs/aptos-indexer-processor-sdk.git?rev=8d8c6625abf32d890128eb824ac3006fd8115842#8d8c6625abf32d890128eb824ac3006fd8115842" dependencies = [ "tracing", ] diff --git a/rust/Cargo.toml b/rust/Cargo.toml index ebc98186a..5ab627fb9 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -30,12 +30,12 @@ testing-transactions = { path = "testing-transactions" } ahash = { version = "0.8.7", features = ["serde"] } anyhow = "1.0.86" -aptos-indexer-processor-sdk = { git = "https://github.com/aptos-labs/aptos-indexer-processor-sdk.git", rev = "d7a6c8492c0ef73c19d8d83dae537065481e240f" } -aptos-indexer-processor-sdk-server-framework = { git = "https://github.com/aptos-labs/aptos-indexer-processor-sdk.git", rev = "d7a6c8492c0ef73c19d8d83dae537065481e240f" } +aptos-indexer-processor-sdk = { git = "https://github.com/aptos-labs/aptos-indexer-processor-sdk.git", rev = "8d8c6625abf32d890128eb824ac3006fd8115842" } +aptos-indexer-processor-sdk-server-framework = { git = "https://github.com/aptos-labs/aptos-indexer-processor-sdk.git", rev = "8d8c6625abf32d890128eb824ac3006fd8115842" } aptos-protos = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "5c48aee129b5a141be2792ffa3d9bd0a1a61c9cb" } aptos-system-utils = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "202bdccff2b2d333a385ae86a4fcf23e89da9f62" } aptos-indexer-test-transactions = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "c583502c69529fddbbf7e47bf920f1dc60e71b72" } -aptos-indexer-testing-framework = { git = "https://github.com/aptos-labs/aptos-indexer-processor-sdk.git", rev = "d7a6c8492c0ef73c19d8d83dae537065481e240f" } +aptos-indexer-testing-framework = { git = "https://github.com/aptos-labs/aptos-indexer-processor-sdk.git", rev = "8d8c6625abf32d890128eb824ac3006fd8115842" } async-trait = "0.1.53" backtrace = "0.3.58" diff --git a/rust/integration-tests/src/cli_parser.rs b/rust/integration-tests/src/cli_parser.rs index 816b70779..3f5d892b9 100644 --- a/rust/integration-tests/src/cli_parser.rs +++ b/rust/integration-tests/src/cli_parser.rs @@ -1,52 +1,52 @@ -use once_cell::sync::Lazy; -use std::sync::Mutex; - -#[derive(Debug, Clone)] -pub struct TestArgs { - pub generate_output: bool, - pub output_path: Option, -} - -// Define a global static to store the parsed arguments -#[allow(dead_code)] -static TEST_CONFIG: Lazy> = Lazy::new(|| { - let args = parse_test_args(); - Mutex::new(args) -}); - -// Function to fetch global test args -#[allow(dead_code)] -pub fn get_test_config() -> (bool, Option) { - let test_args = TEST_CONFIG.lock().unwrap().clone(); - (test_args.generate_output, test_args.output_path) -} - -pub fn parse_test_args() -> TestArgs { - let raw_args: Vec = std::env::args().collect(); - - // Find the "--" separator (if it exists) - let clap_args_position = raw_args.iter().position(|arg| arg == "--"); - - // Only pass the arguments that come after "--", if it exists - let custom_args: Vec = match clap_args_position { - Some(position) => raw_args[position + 1..].to_vec(), // Slice after `--` - None => Vec::new(), // If no `--` is found, treat as no custom args - }; - - // Manually parse the "--generate-output" flag - let generate_output_flag = custom_args.contains(&"--generate-output".to_string()); - - // Manually parse the "--output-path" flag and get its associated value - let output_path = custom_args - .windows(2) - .find(|args| args[0] == "--output-path") - .map(|args| args[1].clone()); - - println!("Parsed generate_output_flag: {}", generate_output_flag); - println!("Parsed output_path: {:?}", output_path); - - TestArgs { - generate_output: generate_output_flag, - output_path, - } -} +// use once_cell::sync::Lazy; +// use std::sync::Mutex; +// +// #[derive(Debug, Clone)] +// pub struct TestArgs { +// pub generate_output: bool, +// pub output_path: Option, +// } +// +// // Define a global static to store the parsed arguments +// #[allow(dead_code)] +// static TEST_CONFIG: Lazy> = Lazy::new(|| { +// let args = parse_test_args(); +// Mutex::new(args) +// }); +// +// // Function to fetch global test args +// #[allow(dead_code)] +// pub fn get_test_config() -> (bool, Option) { +// let test_args = TEST_CONFIG.lock().unwrap().clone(); +// (test_args.generate_output, test_args.output_path) +// } +// +// pub fn parse_test_args() -> TestArgs { +// let raw_args: Vec = std::env::args().collect(); +// +// // Find the "--" separator (if it exists) +// let clap_args_position = raw_args.iter().position(|arg| arg == "--"); +// +// // Only pass the arguments that come after "--", if it exists +// let custom_args: Vec = match clap_args_position { +// Some(position) => raw_args[position + 1..].to_vec(), // Slice after `--` +// None => Vec::new(), // If no `--` is found, treat as no custom args +// }; +// +// // Manually parse the "--generate-output" flag +// let generate_output_flag = custom_args.contains(&"--generate-output".to_string()); +// +// // Manually parse the "--output-path" flag and get its associated value +// let output_path = custom_args +// .windows(2) +// .find(|args| args[0] == "--output-path") +// .map(|args| args[1].clone()); +// +// println!("Parsed generate_output_flag: {}", generate_output_flag); +// println!("Parsed output_path: {:?}", output_path); +// +// TestArgs { +// generate_output: generate_output_flag, +// output_path, +// } +// } diff --git a/rust/integration-tests/src/diff_tests/all_tests.rs b/rust/integration-tests/src/diff_tests/all_tests.rs index 068e31304..e7acab52c 100644 --- a/rust/integration-tests/src/diff_tests/all_tests.rs +++ b/rust/integration-tests/src/diff_tests/all_tests.rs @@ -3,7 +3,6 @@ mod test { use crate::{ - cli_parser::get_test_config, diff_test_helper::{ event_processor::load_data as load_event_data, fungible_asset_processor::load_data as load_fungible_asset_data, @@ -15,19 +14,16 @@ mod test { }, DiffTest, TestContext, TestProcessorConfig, TestType, }; - use anyhow::Context; use aptos_indexer_test_transactions::{ ALL_IMPORTED_MAINNET_TXNS, ALL_IMPORTED_TESTNET_TXNS, ALL_SCRIPTED_TRANSACTIONS, }; + use aptos_indexer_testing_framework::{ + cli_parser::get_test_config, new_test_context::generate_output_file, + }; use assert_json_diff::assert_json_eq; use diesel::pg::PgConnection; use processor::processors::token_v2_processor::TokenV2ProcessorConfig; - use serde_json::to_string_pretty; - use std::{ - fs, - path::{Path, PathBuf}, - }; - use aptos_indexer_testing_framework::new_test_context::generate_output_file; + use std::fs; const DEFAULT_OUTPUT_FOLDER: &str = "expected_db_output_files"; @@ -96,7 +92,7 @@ mod test { test_context: &TestContext, generate_output_flag: bool, output_path: String, - scripted: bool, + _scripted: bool, get_expected_json_path_fn: fn(&str, &str, &str) -> String, ) { for processor_config in processor_configs { @@ -211,28 +207,4 @@ mod test { }, ] } - - /// Helper function to construct the output file path with the table name - /// naming convention: - /// imported txn -> /imported_testnet_txns///.json - /// scripted txn -> /scripted_txns///.json - fn construct_file_path( - output_dir: &str, - processor_name: &str, - folder_name: &str, - table_name: &str, - ) -> PathBuf { - Path::new(output_dir) - .join(processor_name) - .join(folder_name) - .join(format!("{}.json", table_name)) // Including table_name in the format - } - - // Helper function to ensure the directory exists - fn ensure_directory_exists(path: &Path) -> anyhow::Result<()> { - if let Some(parent_dir) = path.parent() { - fs::create_dir_all(parent_dir).context("Failed to create directory")?; - } - Ok(()) - } }