Skip to content

Commit

Permalink
use sdk parser cli
Browse files Browse the repository at this point in the history
  • Loading branch information
yuunlimm committed Oct 16, 2024
1 parent 46875c2 commit 35c113e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 96 deletions.
17 changes: 9 additions & 8 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
104 changes: 52 additions & 52 deletions rust/integration-tests/src/cli_parser.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
}

// Define a global static to store the parsed arguments
#[allow(dead_code)]
static TEST_CONFIG: Lazy<Mutex<TestArgs>> = 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<String>) {
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<String> = 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<String> = 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<String>,
// }
//
// // Define a global static to store the parsed arguments
// #[allow(dead_code)]
// static TEST_CONFIG: Lazy<Mutex<TestArgs>> = 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<String>) {
// 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<String> = 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<String> = 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,
// }
// }
38 changes: 5 additions & 33 deletions rust/integration-tests/src/diff_tests/all_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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";

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -211,28 +207,4 @@ mod test {
},
]
}

/// Helper function to construct the output file path with the table name
/// naming convention:
/// imported txn -> <expected_db_output_files>/imported_testnet_txns/<processor_name>/<txn_version>/<table_name>.json
/// scripted txn -> <expected_db_output_files>/scripted_txns/<processor_name>/<txn_name>/<table_name>.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(())
}
}

0 comments on commit 35c113e

Please sign in to comment.