From 87e0756a4b4ace1cc4be7d78b1fed4eb71766b49 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 2 Jun 2022 09:39:10 -0700 Subject: [PATCH] sui: remove and ban the tracing-test crate --- Cargo.lock | 27 ---- crates/sui/Cargo.toml | 2 - crates/sui/src/unit_tests/cli_tests.rs | 178 +------------------------ crates/workspace-hack/Cargo.toml | 3 - crates/x/src/lint.rs | 14 +- 5 files changed, 14 insertions(+), 210 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1ccfe1f15f69e..3b6f53dbc99e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5774,11 +5774,9 @@ dependencies = [ "tempfile", "test-utils", "tokio", - "tokio-util 0.7.2", "toml", "tracing", "tracing-subscriber 0.3.11", - "tracing-test", "unescape", "workspace-hack", ] @@ -6978,29 +6976,6 @@ dependencies = [ "tracing-log", ] -[[package]] -name = "tracing-test" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3eb7bda2e93bbc9c5b247034acc6a4b3d04f033a3d4b8fc1cb87d4d1c7c7ebd7" -dependencies = [ - "lazy_static 1.4.0", - "tracing-core", - "tracing-subscriber 0.3.11", - "tracing-test-macro", -] - -[[package]] -name = "tracing-test-macro" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4801dca35e4e2cee957c469bd4a1c370fadb7894c0d50721a40eba3523e6e91c" -dependencies = [ - "lazy_static 1.4.0", - "quote", - "syn", -] - [[package]] name = "try-lock" version = "0.2.3" @@ -8141,8 +8116,6 @@ dependencies = [ "tracing-opentelemetry", "tracing-subscriber 0.2.25", "tracing-subscriber 0.3.11", - "tracing-test", - "tracing-test-macro", "try-lock", "tui", "twox-hash", diff --git a/crates/sui/Cargo.toml b/crates/sui/Cargo.toml index 533b24b832d37..6592e347d4d20 100644 --- a/crates/sui/Cargo.toml +++ b/crates/sui/Cargo.toml @@ -78,9 +78,7 @@ shell-words = "1.1.0" workspace-hack = { path = "../workspace-hack"} [dev-dependencies] -tracing-test = "0.2.1" pretty_assertions = "1.2.0" -tokio-util = { version = "0.7.2", features = ["codec"] } test-utils = { path = "../test-utils" } diff --git a/crates/sui/src/unit_tests/cli_tests.rs b/crates/sui/src/unit_tests/cli_tests.rs index 0a3a41f870d59..c1ff9eee3fc7e 100644 --- a/crates/sui/src/unit_tests/cli_tests.rs +++ b/crates/sui/src/unit_tests/cli_tests.rs @@ -1,11 +1,10 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -use std::{fmt::Write, fs::read_dir, ops::Add, path::PathBuf, str, time::Duration}; +use std::{fmt::Write, fs::read_dir, path::PathBuf, str, time::Duration}; use anyhow::anyhow; use serde_json::{json, Value}; -use tracing_test::traced_test; use sui::wallet_commands::SwitchResponse; use sui::{ @@ -22,30 +21,15 @@ use sui_config::{ use sui_core::gateway_types::{GetObjectDataResponse, SuiObject, SuiTransactionEffects}; use sui_json::SuiJsonValue; use sui_types::{ - base_types::{ObjectID, SequenceNumber, SuiAddress}, + base_types::{ObjectID, SuiAddress}, crypto::get_key_pair, gas_coin::GasCoin, - object::GAS_VALUE_FOR_TESTING, }; use test_utils::network::{setup_network_and_wallet, start_test_network}; const TEST_DATA_DIR: &str = "src/unit_tests/data/"; -macro_rules! retry_assert { - ($test:expr, $timeout:expr) => {{ - let mut duration = Duration::from_secs(0); - let max_duration: Duration = $timeout; - let sleep_duration = Duration::from_millis(100); - while duration.lt(&max_duration) && !$test { - tokio::time::sleep(sleep_duration).await; - duration = duration.add(sleep_duration); - } - assert!(duration.lt(&max_duration)); - }}; -} - -#[traced_test] #[tokio::test] async fn test_genesis() -> Result<(), anyhow::Error> { let temp_dir = tempfile::tempdir()?; @@ -68,7 +52,6 @@ async fn test_genesis() -> Result<(), anyhow::Error> { } .execute() .await?; - assert!(logs_contain("Network genesis completed.")); // Get all the new file names let files = read_dir(working_dir)? @@ -116,7 +99,6 @@ async fn test_genesis() -> Result<(), anyhow::Error> { Ok(()) } -#[traced_test] #[tokio::test] async fn test_addresses_command() -> Result<(), anyhow::Error> { let temp_dir = tempfile::tempdir()?; @@ -151,15 +133,9 @@ async fn test_addresses_command() -> Result<(), anyhow::Error> { .await? .print(true); - // Check log output contains all addresses - for address in &context.config.accounts { - assert!(logs_contain(&*format!("{address}"))); - } - Ok(()) } -#[traced_test] #[tokio::test] async fn test_objects_command() -> Result<(), anyhow::Error> { let (_network, mut context, address) = setup_network_and_wallet().await?; @@ -172,20 +148,14 @@ async fn test_objects_command() -> Result<(), anyhow::Error> { .await? .print(true); - let object_refs = context + let _object_refs = context .gateway .get_objects_owned_by_address(address) .await?; - // Check log output contains all object ids. - for oref in object_refs { - assert!(logs_contain(format!("{}", oref.object_id).as_str())) - } - Ok(()) } -#[traced_test] #[tokio::test] async fn test_create_example_nft_command() -> Result<(), anyhow::Error> { let (_network, mut context, address) = setup_network_and_wallet().await?; @@ -214,7 +184,6 @@ async fn test_create_example_nft_command() -> Result<(), anyhow::Error> { Ok(()) } -#[traced_test] #[tokio::test] async fn test_custom_genesis() -> Result<(), anyhow::Error> { // Create and save genesis config file @@ -255,16 +224,9 @@ async fn test_custom_genesis() -> Result<(), anyhow::Error> { .await? .print(true); - // confirm the object with custom object id. - retry_assert!( - logs_contain(format!("{object_id}").as_str()), - Duration::from_millis(5000) - ); - Ok(()) } -#[traced_test] #[tokio::test] async fn test_custom_genesis_with_custom_move_package() -> Result<(), anyhow::Error> { // Create and save genesis config file @@ -281,7 +243,6 @@ async fn test_custom_genesis_with_custom_move_package() -> Result<(), anyhow::Er // Start network let network = start_test_network(Some(config)).await?; - assert!(logs_contain("Loading 2 Move packages")); // Checks network config contains package ids let _network_conf = PersistedConfig::::read(&network.dir().join(SUI_NETWORK_CONFIG))?; @@ -297,7 +258,6 @@ async fn test_custom_genesis_with_custom_move_package() -> Result<(), anyhow::Er Ok(()) } -#[traced_test] #[tokio::test] async fn test_object_info_get_command() -> Result<(), anyhow::Error> { let (_network, mut context, address) = setup_network_and_wallet().await?; @@ -314,17 +274,10 @@ async fn test_object_info_get_command() -> Result<(), anyhow::Error> { .execute(&mut context) .await? .print(true); - let obj_owner = format!("{}", address); - - retry_assert!( - logs_contain(obj_owner.as_str()), - Duration::from_millis(5000) - ); Ok(()) } -#[traced_test] #[tokio::test] async fn test_gas_command() -> Result<(), anyhow::Error> { let (_network, mut context, address) = setup_network_and_wallet().await?; @@ -344,34 +297,9 @@ async fn test_gas_command() -> Result<(), anyhow::Error> { .execute(&mut context) .await? .print(true); - let object_id_str = format!("{object_id}"); tokio::time::sleep(Duration::from_millis(100)).await; - // Check that the value got printed - logs_assert(|lines: &[&str]| { - let matches = lines - .iter() - .filter_map(|line| { - if line.contains(&object_id_str) { - return extract_gas_info(line); - } - None - }) - .collect::>(); - - assert_eq!(matches.len(), 1); - - // Extract the values - let (obj_id, version, val) = *matches.get(0).unwrap(); - - assert_eq!(obj_id, object_id); - assert_eq!(version, SequenceNumber::new()); - assert_eq!(val, GAS_VALUE_FOR_TESTING); - - Ok(()) - }); - // Send an object WalletCommands::Transfer { to: recipient, @@ -389,56 +317,10 @@ async fn test_gas_command() -> Result<(), anyhow::Error> { .execute(&mut context) .await? .print(true); - tokio::time::sleep(Duration::from_millis(100)).await; - - // Check that the value got printed and updated - logs_assert(|lines: &[&str]| { - let matches = lines - .iter() - .filter_map(|line| { - if line.contains(&object_id_str) { - return extract_gas_info(line); - } - None - }) - .collect::>(); - - assert_eq!(matches.len(), 2); - - // Extract the values - let (obj_id, version, val) = *matches.get(1).unwrap(); - - assert_eq!(obj_id, object_id); - assert_eq!(version, SequenceNumber::from_u64(1)); - assert!(val < GAS_VALUE_FOR_TESTING); - - Ok(()) - }); Ok(()) } -fn extract_gas_info(s: &str) -> Option<(ObjectID, SequenceNumber, u64)> { - let tokens = s.split('|').map(|q| q.trim()).collect::>(); - if tokens.len() != 3 { - return None; - } - - let id_str = tokens[0] - .split(':') - .map(|q| q.trim()) - .collect::>() - .iter() - .last() - .unwrap() - .to_owned(); - Some(( - ObjectID::from_hex_literal(id_str).unwrap(), - SequenceNumber::from_u64(tokens[1].parse::().unwrap()), - tokens[2].parse::().unwrap(), - )) -} - async fn get_move_objects_by_type( context: &mut WalletContext, address: SuiAddress, @@ -504,7 +386,6 @@ async fn get_move_object( } #[allow(clippy::assertions_on_constants)] -#[traced_test] #[tokio::test] async fn test_move_call_args_linter_command() -> Result<(), anyhow::Error> { let (_network, mut context, address1) = setup_network_and_wallet().await?; @@ -532,11 +413,6 @@ async fn test_move_call_args_linter_command() -> Result<(), anyhow::Error> { .get_objects_owned_by_address(address1) .await?; - // Check log output contains all object ids. - for oref in &object_refs { - assert!(logs_contain(format!("{}", oref.object_id).as_str())) - } - // Create an object for address1 using Move call // Certain prep work @@ -567,12 +443,6 @@ async fn test_move_call_args_linter_command() -> Result<(), anyhow::Error> { .await?; resp.print(true); - retry_assert!( - logs_contain("Mutated Objects:"), - Duration::from_millis(1000) - ); - assert!(logs_contain("Created Objects:")); - // Get the created object let created_obj: ObjectID = if let WalletCommandResult::Call( _, @@ -667,17 +537,10 @@ async fn test_move_call_args_linter_command() -> Result<(), anyhow::Error> { .execute(&mut context) .await?; - retry_assert!( - logs_contain("Mutated Objects:"), - Duration::from_millis(1000) - ); - assert!(logs_contain("Created Objects:")); - Ok(()) } #[allow(clippy::assertions_on_constants)] -#[traced_test] #[tokio::test] async fn test_package_publish_command() -> Result<(), anyhow::Error> { let (_network, mut context, address) = setup_network_and_wallet().await?; @@ -714,16 +577,6 @@ async fn test_package_publish_command() -> Result<(), anyhow::Error> { unreachable!("Invalid response"); }; - // One is the actual module, while the other is the object created at init - retry_assert!( - logs_contain(&format!("{}", package.object_id)), - Duration::from_millis(5000) - ); - retry_assert!( - logs_contain(&format!("{}", created_obj.object_id)), - Duration::from_millis(5000) - ); - // Check the objects let resp = WalletCommands::Object { id: package.object_id, @@ -749,7 +602,6 @@ async fn test_package_publish_command() -> Result<(), anyhow::Error> { } #[allow(clippy::assertions_on_constants)] -#[traced_test] #[tokio::test] async fn test_native_transfer() -> Result<(), anyhow::Error> { let (_network, mut context, address) = setup_network_and_wallet().await?; @@ -788,15 +640,6 @@ async fn test_native_transfer() -> Result<(), anyhow::Error> { panic!() }; - retry_assert!( - logs_contain(&format!("{}", mut_obj1)), - Duration::from_millis(5000) - ); - retry_assert!( - logs_contain(&format!("{}", mut_obj2)), - Duration::from_millis(5000) - ); - // Sync both to fetch objects WalletCommands::SyncClientState { address: Some(address), @@ -874,7 +717,7 @@ async fn test_native_transfer() -> Result<(), anyhow::Error> { resp.print(true); // Get the mutated objects - let (mut_obj1, mut_obj2) = + let (_mut_obj1, _mut_obj2) = if let WalletCommandResult::Transfer(_, _, SuiTransactionEffects { mutated, .. }) = resp { ( mutated.get(0).unwrap().reference.object_id, @@ -885,15 +728,6 @@ async fn test_native_transfer() -> Result<(), anyhow::Error> { panic!() }; - retry_assert!( - logs_contain(&format!("{}", mut_obj1)), - Duration::from_millis(5000) - ); - retry_assert!( - logs_contain(&format!("{}", mut_obj2)), - Duration::from_millis(5000) - ); - Ok(()) } @@ -908,7 +742,6 @@ fn test_bug_1078() { } #[allow(clippy::assertions_on_constants)] -#[traced_test] #[tokio::test] async fn test_switch_command() -> Result<(), anyhow::Error> { let network = start_test_network(None).await?; @@ -1005,7 +838,6 @@ async fn test_switch_command() -> Result<(), anyhow::Error> { } #[allow(clippy::assertions_on_constants)] -#[traced_test] #[tokio::test] async fn test_active_address_command() -> Result<(), anyhow::Error> { let network = start_test_network(None).await?; @@ -1070,7 +902,6 @@ async fn get_object(id: ObjectID, context: &mut WalletContext) -> Option Result<(), anyhow::Error> { let (_network, mut context, address) = setup_network_and_wallet().await?; @@ -1153,7 +984,6 @@ async fn test_merge_coin() -> Result<(), anyhow::Error> { } #[allow(clippy::assertions_on_constants)] -#[traced_test] #[tokio::test] async fn test_split_coin() -> Result<(), anyhow::Error> { let (_network, mut context, address) = setup_network_and_wallet().await?; diff --git a/crates/workspace-hack/Cargo.toml b/crates/workspace-hack/Cargo.toml index 5199d95c0e6e7..208f990400410 100644 --- a/crates/workspace-hack/Cargo.toml +++ b/crates/workspace-hack/Cargo.toml @@ -449,7 +449,6 @@ tracing-log = { version = "0.1", features = ["log-tracer", "std", "trace-logger" tracing-opentelemetry = { version = "0.17", features = ["tracing-log"] } tracing-subscriber-6f8ce4dd05d13bba = { package = "tracing-subscriber", version = "0.2", default-features = false } tracing-subscriber-468e82937335b1c9 = { package = "tracing-subscriber", version = "0.3", features = ["alloc", "ansi", "ansi_term", "env-filter", "fmt", "lazy_static", "matchers", "regex", "registry", "sharded-slab", "smallvec", "std", "thread_local", "time", "tracing", "tracing-log"] } -tracing-test = { version = "0.2", default-features = false } try-lock = { version = "0.2", default-features = false } tui = { version = "0.17", features = ["crossterm"] } twox-hash = { version = "1", default-features = false } @@ -1010,8 +1009,6 @@ tracing-log = { version = "0.1", features = ["log-tracer", "std", "trace-logger" tracing-opentelemetry = { version = "0.17", features = ["tracing-log"] } tracing-subscriber-6f8ce4dd05d13bba = { package = "tracing-subscriber", version = "0.2", default-features = false } tracing-subscriber-468e82937335b1c9 = { package = "tracing-subscriber", version = "0.3", features = ["alloc", "ansi", "ansi_term", "env-filter", "fmt", "lazy_static", "matchers", "regex", "registry", "sharded-slab", "smallvec", "std", "thread_local", "time", "tracing", "tracing-log"] } -tracing-test = { version = "0.2", default-features = false } -tracing-test-macro = { version = "0.2", default-features = false } try-lock = { version = "0.2", default-features = false } tui = { version = "0.17", features = ["crossterm"] } twox-hash = { version = "1", default-features = false } diff --git a/crates/x/src/lint.rs b/crates/x/src/lint.rs index 0b17f8c1d0d5f..5ece95f8026b7 100644 --- a/crates/x/src/lint.rs +++ b/crates/x/src/lint.rs @@ -22,10 +22,16 @@ pub struct Args { pub fn run(args: Args) -> crate::Result<()> { let direct_dups_config = DirectDepDupsConfig { allow: vec![] }; let banned_deps_config = BannedDepsConfig { - direct: vec![( - "lazy_static".to_owned(), - "use once_cell::sync::Lazy instead".to_owned(), - )] + direct: vec![ + ( + "lazy_static".to_owned(), + "use once_cell::sync::Lazy instead".to_owned(), + ), + ( + "tracing-test".to_owned(), + "you should not be testing against log lines".to_owned(), + ), + ] .into_iter() .collect(), };