diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 67841db6ebd1ec..023cd3a0a29aa9 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -62,7 +62,7 @@ jobs: - name: Set env run: | echo "VITE_SUI_BIN=$PWD/target/debug/sui" >> $GITHUB_ENV - echo "E2E_RUN_LOCAL_NET_CMD=(RUST_LOG=info RUST_BACKTRACE=1 $(echo $PWD/target/debug/sui) --with-faucet --with-indexer --pg-port 5432 --pg-db-name sui_indexer_v2 --with-graphql --graphql-port 9125 --random-genesis)" >> $GITHUB_ENV + echo "E2E_RUN_LOCAL_NET_CMD=(RUST_LOG=info RUST_BACKTRACE=1 $(echo $PWD/target/debug/sui) start --with-faucet --with-indexer --pg-port 5432 --pg-db-name sui_indexer_v2 --with-graphql --graphql-port 9125 --random-genesis)" >> $GITHUB_ENV - name: Run TS SDK e2e tests if: ${{ needs.diff.outputs.isTypescriptSDK == 'true' || needs.diff.outputs.isRust == 'true'}} diff --git a/crates/sui-cluster-test/Cargo.toml b/crates/sui-cluster-test/Cargo.toml index c7e1afeba8a7dc..a6477761d408b5 100644 --- a/crates/sui-cluster-test/Cargo.toml +++ b/crates/sui-cluster-test/Cargo.toml @@ -29,7 +29,6 @@ sui-indexer.workspace = true sui-faucet.workspace = true sui-graphql-rpc.workspace = true sui-swarm.workspace = true -# sui.workspace = true sui-swarm-config.workspace = true sui-json-rpc-types.workspace = true sui-sdk.workspace = true diff --git a/crates/sui-faucet/src/faucet/simple_faucet.rs b/crates/sui-faucet/src/faucet/simple_faucet.rs index f93b4cfa5ba6c3..017b4de25af0d5 100644 --- a/crates/sui-faucet/src/faucet/simple_faucet.rs +++ b/crates/sui-faucet/src/faucet/simple_faucet.rs @@ -1086,15 +1086,45 @@ pub async fn batch_transfer_gases( #[cfg(test)] mod tests { - use sui::{ - client_commands::{Opts, OptsWithGas, SuiClientCommandResult, SuiClientCommands}, - key_identity::KeyIdentity, - }; + use super::*; + use anyhow::*; + use shared_crypto::intent::Intent; use sui_json_rpc_types::SuiExecutionStatus; + use sui_json_rpc_types::SuiTransactionBlockEffects; use sui_sdk::wallet_context::WalletContext; + use sui_types::transaction::SenderSignedData; + use sui_types::transaction::TransactionDataAPI; use test_cluster::TestClusterBuilder; - use super::*; + async fn execute_tx( + ctx: &mut WalletContext, + tx_data: TransactionData, + ) -> Result { + let signature = ctx.config.keystore.sign_secure( + &tx_data.sender(), + &tx_data, + Intent::sui_transaction(), + )?; + let sender_signed_data = SenderSignedData::new_from_sender_signature(tx_data, signature); + let transaction = Transaction::new(sender_signed_data); + let response = ctx.execute_transaction_may_fail(transaction).await?; + let result_effects = response.clone().effects; + + if let Some(effects) = result_effects { + if matches!(effects.status(), SuiExecutionStatus::Failure { .. }) { + Err(anyhow!( + "Error executing transaction: {:#?}", + effects.status() + )) + } else { + Ok(effects) + } + } else { + Err(anyhow!( + "Effects from SuiTransactionBlockResult should not be empty" + )) + } + } #[tokio::test] async fn simple_faucet_basic_interface_should_work() { @@ -1106,17 +1136,25 @@ mod tests { let address = test_cluster.get_address_0(); let mut context = test_cluster.wallet; - let gases = get_current_gases(address, &mut context).await; - // Split some extra gas coins so that we can test batch queue - SuiClientCommands::SplitCoin { - coin_id: *gases[0].id(), - amounts: None, - count: Some(10), - opts: OptsWithGas::for_testing(None, 50_000_000), - } - .execute(&mut context) - .await - .expect("split failed"); + let gas_coins = context + .get_all_gas_objects_owned_by_address(address) + .await + .unwrap(); + let client = context.get_client().await.unwrap(); + let tx_kind = client + .transaction_builder() + .split_coin_tx_kind(gas_coins.first().unwrap().0, None, Some(10)) + .await + .unwrap(); + let gas_budget = 50_000_000; + let rgp = context.get_reference_gas_price().await.unwrap(); + let tx_data = client + .transaction_builder() + .tx_data(address, tx_kind, gas_budget, rgp, vec![], None) + .await + .unwrap(); + + execute_tx(&mut context, tx_data).await.unwrap(); let faucet = SimpleFaucet::new( context, @@ -1140,13 +1178,17 @@ mod tests { assert_eq!(discarded, faucet.metrics.total_discarded_coins.get()); } + // #[tokio::test] async fn test_init_gas_queue() { let test_cluster = TestClusterBuilder::new().build().await; let address = test_cluster.get_address_0(); - let mut context = test_cluster.wallet; - let gases = get_current_gases(address, &mut context).await; - let gases = HashSet::from_iter(gases.into_iter().map(|gas| *gas.id())); + let context = test_cluster.wallet; + let gas_coins = context + .get_all_gas_objects_owned_by_address(address) + .await + .unwrap(); + let gas_coins = HashSet::from_iter(gas_coins.into_iter().map(|gas| gas.0)); let tmp = tempfile::tempdir().unwrap(); let prom_registry = Registry::new(); @@ -1163,13 +1205,13 @@ mod tests { let available = faucet.metrics.total_available_coins.get(); let faucet_unwrapped = &mut Arc::try_unwrap(faucet).unwrap(); - let candidates = faucet_unwrapped.drain_gas_queue(gases.len()).await; + let candidates = faucet_unwrapped.drain_gas_queue(gas_coins.len()).await; assert_eq!(available as usize, candidates.len()); assert_eq!( - candidates, gases, + candidates, gas_coins, "gases: {:?}, candidates: {:?}", - gases, candidates + gas_coins, candidates ); } @@ -1177,10 +1219,12 @@ mod tests { async fn test_transfer_state() { let test_cluster = TestClusterBuilder::new().build().await; let address = test_cluster.get_address_0(); - let mut context = test_cluster.wallet; - let gases = get_current_gases(address, &mut context).await; - - let gases = HashSet::from_iter(gases.into_iter().map(|gas| *gas.id())); + let context = test_cluster.wallet; + let gas_coins = context + .get_all_gas_objects_owned_by_address(address) + .await + .unwrap(); + let gas_coins = HashSet::from_iter(gas_coins.into_iter().map(|gas| gas.0)); let tmp = tempfile::tempdir().unwrap(); let prom_registry = Registry::new(); @@ -1194,7 +1238,7 @@ mod tests { .await .unwrap(); - let number_of_coins = gases.len(); + let number_of_coins = gas_coins.len(); let amounts = &vec![1; number_of_coins]; let _ = futures::future::join_all((0..number_of_coins).map(|_| { faucet.send( @@ -1213,12 +1257,12 @@ mod tests { faucet.shutdown_batch_send_task(); let faucet_unwrapped: &mut SimpleFaucet = &mut Arc::try_unwrap(faucet).unwrap(); - let candidates = faucet_unwrapped.drain_gas_queue(gases.len()).await; + let candidates = faucet_unwrapped.drain_gas_queue(gas_coins.len()).await; assert_eq!(available as usize, candidates.len()); assert_eq!( - candidates, gases, + candidates, gas_coins, "gases: {:?}, candidates: {:?}", - gases, candidates + gas_coins, candidates ); } @@ -1231,17 +1275,25 @@ mod tests { let tmp = tempfile::tempdir().unwrap(); let address = test_cluster.get_address_0(); let mut context = test_cluster.wallet; - let gases = get_current_gases(address, &mut context).await; - // Split some extra gas coins so that we can test batch queue - SuiClientCommands::SplitCoin { - coin_id: *gases[0].id(), - amounts: None, - count: Some(10), - opts: OptsWithGas::for_testing(None, 50_000_000), - } - .execute(&mut context) - .await - .expect("split failed"); + let gas_coins = context + .get_all_gas_objects_owned_by_address(address) + .await + .unwrap(); + let client = context.get_client().await.unwrap(); + let tx_kind = client + .transaction_builder() + .split_coin_tx_kind(gas_coins.first().unwrap().0, None, Some(10)) + .await + .unwrap(); + let gas_budget = 50_000_000; + let rgp = context.get_reference_gas_price().await.unwrap(); + let tx_data = client + .transaction_builder() + .tx_data(address, tx_kind, gas_budget, rgp, vec![], None) + .await + .unwrap(); + + execute_tx(&mut context, tx_data).await.unwrap(); let faucet = SimpleFaucet::new( context, @@ -1312,70 +1364,24 @@ mod tests { } } - #[tokio::test] - async fn test_ttl_cache_expires_after_duration() { - let test_cluster = TestClusterBuilder::new().build().await; - let context = test_cluster.wallet; - // We set it to a fast expiration for the purposes of testing and so these requests don't have time to pass - // through the batch process. - let config = FaucetConfig { - ttl_expiration: 1, - ..Default::default() - }; - let prom_registry = Registry::new(); - let tmp = tempfile::tempdir().unwrap(); - let faucet = SimpleFaucet::new( - context, - &prom_registry, - &tmp.path().join("faucet.wal"), - config, - ) - .await - .unwrap(); - - let amounts = &vec![1; 1]; - // Create a vector containing five randomly generated addresses - let target_addresses: Vec = (0..5) - .map(|_| SuiAddress::random_for_testing_only()) - .collect(); - - let response = futures::future::join_all( - target_addresses - .iter() - .map(|address| faucet.batch_send(Uuid::new_v4(), *address, amounts)), - ) - .await - .into_iter() - .map(|res| res.unwrap()) - .collect::>(); - - // Check that TTL cache expires - tokio::time::sleep(Duration::from_secs(10)).await; - let status_results = futures::future::join_all( - response - .clone() - .iter() - .map(|task| faucet.get_batch_send_status(Uuid::parse_str(&task.task).unwrap())), - ) - .await; - - let all_errors = status_results.iter().all(Result::is_err); - assert!(all_errors); - } - #[tokio::test] async fn test_discard_invalid_gas() { let test_cluster = TestClusterBuilder::new().build().await; let address = test_cluster.get_address_0(); - let mut context = test_cluster.wallet; - let mut gases = get_current_gases(address, &mut context).await; + let context = test_cluster.wallet; + let mut gas_coins = context + .get_all_gas_objects_owned_by_address(address) + .await + .unwrap(); - let bad_gas = gases.swap_remove(0); - let gases = HashSet::from_iter(gases.into_iter().map(|gas| *gas.id())); + let bad_gas = gas_coins.swap_remove(0); + let gas_coins = HashSet::from_iter(gas_coins.into_iter().map(|gas| gas.0)); let tmp = tempfile::tempdir().unwrap(); let prom_registry = Registry::new(); let config = FaucetConfig::default(); + + let client = context.get_client().await.unwrap(); let faucet = SimpleFaucet::new( context, &prom_registry, @@ -1385,29 +1391,22 @@ mod tests { .await .unwrap(); faucet.shutdown_batch_send_task(); - let faucet: &mut SimpleFaucet = &mut Arc::try_unwrap(faucet).unwrap(); - // Now we transfer one gas out - let res = SuiClientCommands::PayAllSui { - input_coins: vec![*bad_gas.id()], - recipient: KeyIdentity::Address(SuiAddress::random_for_testing_only()), - opts: Opts::for_testing(2_000_000), - } - .execute(faucet.wallet_mut()) - .await - .unwrap(); - - if let SuiClientCommandResult::TransactionBlock(response) = res { - assert!(matches!( - response.effects.unwrap().status(), - SuiExecutionStatus::Success - )); - } else { - panic!("PayAllSui command did not return SuiClientCommandResult::TransactionBlock"); - }; + let gas_budget = 50_000_000; + let tx_data = client + .transaction_builder() + .pay_all_sui( + address, + vec![bad_gas.0], + SuiAddress::random_for_testing_only(), + gas_budget, + ) + .await + .unwrap(); + execute_tx(faucet.wallet_mut(), tx_data).await.unwrap(); - let number_of_coins = gases.len(); + let number_of_coins = gas_coins.len(); let amounts = &vec![1; number_of_coins]; // We traverse the list twice, which must trigger the transferred gas to be kicked out futures::future::join_all((0..2).map(|_| { @@ -1423,13 +1422,13 @@ mod tests { // Note `gases` does not contain the bad gas. let available = faucet.metrics.total_available_coins.get(); let discarded = faucet.metrics.total_discarded_coins.get(); - let candidates = faucet.drain_gas_queue(gases.len()).await; + let candidates = faucet.drain_gas_queue(gas_coins.len()).await; assert_eq!(available as usize, candidates.len()); assert_eq!(discarded, 1); assert_eq!( - candidates, gases, + candidates, gas_coins, "gases: {:?}, candidates: {:?}", - gases, candidates + gas_coins, candidates ); } @@ -1504,39 +1503,45 @@ mod tests { let test_cluster = TestClusterBuilder::new().build().await; let address = test_cluster.get_address_0(); let mut context = test_cluster.wallet; - let gases = get_current_gases(address, &mut context).await; + let gas_coins = context + .get_all_gas_objects_owned_by_address(address) + .await + .unwrap(); // split out a coin that has a very small balance such that // this coin will be not used later on. This is the new default amount for faucet due to gas changes let config = FaucetConfig::default(); let tiny_value = (config.num_coins as u64 * config.amount) + 1; - let res = SuiClientCommands::SplitCoin { - coin_id: *gases[0].id(), - amounts: Some(vec![tiny_value]), - count: None, - opts: OptsWithGas::for_testing(None, 50_000_000), - } - .execute(&mut context) - .await; + let client = context.get_client().await.unwrap(); + let tx_kind = client + .transaction_builder() + .split_coin_tx_kind(gas_coins.first().unwrap().0, Some(vec![tiny_value]), None) + .await + .unwrap(); + let gas_budget = 50_000_000; + let rgp = context.get_reference_gas_price().await.unwrap(); + let tx_data = client + .transaction_builder() + .tx_data(address, tx_kind, gas_budget, rgp, vec![], None) + .await + .unwrap(); - let tiny_coin_id = if let SuiClientCommandResult::TransactionBlock(resp) = res.unwrap() { - resp.effects.as_ref().unwrap().created()[0] - .reference - .object_id - } else { - panic!("SplitCoin command did not return SuiClientCommandResult::TransactionBlock"); - }; + let effects = execute_tx(&mut context, tx_data).await.unwrap(); + + let tiny_coin_id = effects.created()[0].reference.object_id; // Get the latest list of gas - let gases = get_current_gases(address, &mut context).await; - let tiny_amount = gases + let gas_coins = context.gas_objects(address).await.unwrap(); + + let tiny_amount = gas_coins .iter() - .find(|gas| gas.id() == &tiny_coin_id) + .find(|gas| gas.1.object_id == tiny_coin_id) .unwrap() - .value(); + .0; assert_eq!(tiny_amount, tiny_value); - let gases: HashSet = HashSet::from_iter(gases.into_iter().map(|gas| *gas.id())); + let gas_coins: HashSet = + HashSet::from_iter(gas_coins.into_iter().map(|gas| gas.1.object_id)); let tmp = tempfile::tempdir().unwrap(); let prom_registry = Registry::new(); @@ -1553,7 +1558,7 @@ mod tests { let faucet: &mut SimpleFaucet = &mut Arc::try_unwrap(faucet).unwrap(); // Ask for a value higher than tiny coin + DEFAULT_GAS_COMPUTATION_BUCKET - let number_of_coins = gases.len(); + let number_of_coins = gas_coins.len(); let amounts = &vec![tiny_value + 1; number_of_coins]; // We traverse the list ten times, which must trigger the tiny gas to be examined and then discarded futures::future::join_all((0..10).map(|_| { @@ -1576,7 +1581,7 @@ mod tests { let discarded = faucet.metrics.total_discarded_coins.get(); info!("discarded: {:?}", discarded); - let candidates = faucet.drain_gas_queue(gases.len() - 1).await; + let candidates = faucet.drain_gas_queue(gas_coins.len() - 1).await; assert_eq!(discarded, 1); assert!(candidates.get(&tiny_coin_id).is_none()); @@ -1587,38 +1592,50 @@ mod tests { let test_cluster = TestClusterBuilder::new().build().await; let address = test_cluster.get_address_0(); let mut context = test_cluster.wallet; - let gases = get_current_gases(address, &mut context).await; + let gas_coins = context + .get_all_gas_objects_owned_by_address(address) + .await + .unwrap(); let config = FaucetConfig::default(); // The coin that is split off stays because we don't try to refresh the coin vector let reasonable_value = (config.num_coins as u64 * config.amount) * 10; - SuiClientCommands::SplitCoin { - coin_id: *gases[0].id(), - amounts: Some(vec![reasonable_value]), - count: None, - opts: OptsWithGas::for_testing(None, 50_000_000), - } - .execute(&mut context) - .await - .expect("split failed"); + let client = context.get_client().await.unwrap(); + let tx_kind = client + .transaction_builder() + .split_coin_tx_kind( + gas_coins.first().unwrap().0, + Some(vec![reasonable_value]), + None, + ) + .await + .unwrap(); + let gas_budget = 50_000_000; + let rgp = context.get_reference_gas_price().await.unwrap(); + let tx_data = client + .transaction_builder() + .tx_data(address, tx_kind, gas_budget, rgp, vec![], None) + .await + .unwrap(); + execute_tx(&mut context, tx_data).await.unwrap(); let destination_address = SuiAddress::random_for_testing_only(); // Transfer all valid gases away except for 1 - for gas in gases.iter().take(gases.len() - 1) { - SuiClientCommands::TransferSui { - to: KeyIdentity::Address(destination_address), - sui_coin_object_id: *gas.id(), - amount: None, - opts: Opts::for_testing(50_000_000), - } - .execute(&mut context) - .await - .expect("transfer failed"); + for gas in gas_coins.iter().take(gas_coins.len() - 1) { + let tx_data = client + .transaction_builder() + .transfer_sui(address, gas.0, gas_budget, destination_address, None) + .await + .unwrap(); + execute_tx(&mut context, tx_data).await.unwrap(); } // Assert that the coins were transferred away successfully to destination address - let gases = get_current_gases(destination_address, &mut context).await; - assert!(!gases.is_empty()); + let gas_coins = context + .get_all_gas_objects_owned_by_address(address) + .await + .unwrap(); + assert!(!gas_coins.is_empty()); let tmp = tempfile::tempdir().unwrap(); let prom_registry = Registry::new(); @@ -1656,37 +1673,49 @@ mod tests { let test_cluster = TestClusterBuilder::new().build().await; let address = test_cluster.get_address_0(); let mut context = test_cluster.wallet; - let gases = get_current_gases(address, &mut context).await; + let gas_coins = context + .get_all_gas_objects_owned_by_address(address) + .await + .unwrap(); let config = FaucetConfig::default(); let tiny_value = (config.num_coins as u64 * config.amount) + 1; - let _res = SuiClientCommands::SplitCoin { - coin_id: *gases[0].id(), - amounts: Some(vec![tiny_value]), - count: None, - opts: OptsWithGas::for_testing(None, 50_000_000), - } - .execute(&mut context) - .await; + let client = context.get_client().await.unwrap(); + let tx_kind = client + .transaction_builder() + .split_coin_tx_kind(gas_coins.first().unwrap().0, Some(vec![tiny_value]), None) + .await + .unwrap(); + + let gas_budget = 50_000_000; + let rgp = context.get_reference_gas_price().await.unwrap(); + + let tx_data = client + .transaction_builder() + .tx_data(address, tx_kind, gas_budget, rgp, vec![], None) + .await + .unwrap(); + + execute_tx(&mut context, tx_data).await.unwrap(); let destination_address = SuiAddress::random_for_testing_only(); // Transfer all valid gases away - for gas in gases { - SuiClientCommands::TransferSui { - to: KeyIdentity::Address(destination_address), - sui_coin_object_id: *gas.id(), - amount: None, - opts: Opts::for_testing(50_000_000), - } - .execute(&mut context) - .await - .expect("transfer failed"); + for gas in gas_coins { + let tx_data = client + .transaction_builder() + .transfer_sui(address, gas.0, gas_budget, destination_address, None) + .await + .unwrap(); + execute_tx(&mut context, tx_data).await.unwrap(); } // Assert that the coins were transferred away successfully to destination address - let gases = get_current_gases(destination_address, &mut context).await; - assert!(!gases.is_empty()); + let gas_coins = context + .get_all_gas_objects_owned_by_address(destination_address) + .await + .unwrap(); + assert!(!gas_coins.is_empty()); let tmp = tempfile::tempdir().unwrap(); let prom_registry = Registry::new(); @@ -1787,17 +1816,24 @@ mod tests { let config: FaucetConfig = Default::default(); let address = test_cluster.get_address_0(); let mut context = test_cluster.wallet; - let gases = get_current_gases(address, &mut context).await; - // Split some extra gas coins so that we can test batch queue - SuiClientCommands::SplitCoin { - coin_id: *gases[0].id(), - amounts: None, - count: Some(10), - opts: OptsWithGas::for_testing(None, 50_000_000), - } - .execute(&mut context) - .await - .expect("split failed"); + let gas_coins = context + .get_all_gas_objects_owned_by_address(address) + .await + .unwrap(); + let client = context.get_client().await.unwrap(); + let tx_kind = client + .transaction_builder() + .split_coin_tx_kind(gas_coins.first().unwrap().0, None, Some(10)) + .await + .unwrap(); + let gas_budget = 50_000_000; + let rgp = context.get_reference_gas_price().await.unwrap(); + let tx_data = client + .transaction_builder() + .tx_data(address, tx_kind, gas_budget, rgp, vec![], None) + .await + .unwrap(); + execute_tx(&mut context, tx_data).await.unwrap(); let prom_registry = Registry::new(); let tmp = tempfile::tempdir().unwrap(); @@ -1898,18 +1934,4 @@ mod tests { actual_amounts.sort_unstable(); assert_eq!(actual_amounts, amounts); } - - async fn get_current_gases(address: SuiAddress, context: &mut WalletContext) -> Vec { - // Get the latest list of gas - let results = SuiClientCommands::Gas { - address: Some(KeyIdentity::Address(address)), - } - .execute(context) - .await - .unwrap(); - match results { - SuiClientCommandResult::Gas(gases) => gases, - other => panic!("Expect SuiClientCommandResult::Gas, but got {:?}", other), - } - } } diff --git a/crates/sui-rpc-loadgen/README.md b/crates/sui-rpc-loadgen/README.md index 14cc29ed6fc177..cb3f5524b42c2e 100644 --- a/crates/sui-rpc-loadgen/README.md +++ b/crates/sui-rpc-loadgen/README.md @@ -17,7 +17,7 @@ Run the following command to see available commands: cargo run --bin sui-rpc-loadgen -- -h ``` -To try this locally, use `RUST_LOG=consensus=off cargo run --bin sui -- start --with-faucet --with-indexer`. Recommend setting `database-url` to an env variable. +To try this locally, use `RUST_LOG=consensus=off cargo run --bin sui -- start --with-faucet --with-indexer --random-genesis`. Recommend setting `database-url` to an env variable. ### Example 1: Get All Checkpoints diff --git a/crates/sui/src/faucet.rs b/crates/sui/src/faucet.rs index f5c69b080e2f62..7acfb0cbef3c73 100644 --- a/crates/sui/src/faucet.rs +++ b/crates/sui/src/faucet.rs @@ -172,7 +172,7 @@ pub fn new_wallet_context_for_faucet( keystore, envs: vec![SuiEnv { alias: "localnet".to_string(), - rpc: fullnode_url.into(), + rpc: fullnode_url, ws: None, basic_auth: None, }], diff --git a/crates/sui/src/lib.rs b/crates/sui/src/lib.rs index c5066d1a478489..cb0f08eff8c137 100644 --- a/crates/sui/src/lib.rs +++ b/crates/sui/src/lib.rs @@ -7,13 +7,13 @@ pub mod client_commands; pub mod client_ptb; pub mod console; pub mod displays; +pub mod faucet; pub mod fire_drill; pub mod genesis_ceremony; pub mod genesis_inspector; pub mod key_identity; pub mod keytool; pub mod shell; -pub mod faucet; pub mod sui_commands; pub mod validator_commands; mod verifier_meter; diff --git a/crates/sui/src/sui_commands.rs b/crates/sui/src/sui_commands.rs index c3369124a06b9f..06e705433173ef 100644 --- a/crates/sui/src/sui_commands.rs +++ b/crates/sui/src/sui_commands.rs @@ -571,8 +571,13 @@ async fn start( if let Some(config) = config.clone() { swarm_builder = swarm_builder.dir(config); } - swarm_builder = - swarm_builder.with_epoch_duration_ms(epoch_duration_ms.unwrap_or_else(|| 60000)); + + let epoch_duration_ms = if let Some(epoch_ms) = epoch_duration_ms { + epoch_ms + } else { + 60000 + }; + swarm_builder = swarm_builder.with_epoch_duration_ms(epoch_duration_ms); } else { // load from config dir that was passed, or generate a new genesis if there is no config // dir passed and there is no config_dir in the default location @@ -625,7 +630,7 @@ async fn start( info!("Cluster started"); // the indexer requires a full url - let fullnode_url = format!("http://{}", fullnode_url.to_string()); + let fullnode_url = format!("http://{}", fullnode_url); info!("Fullnode URL: {}", fullnode_url); let pg_address = format!("postgres://{pg_user}:{pg_password}@{pg_host}:{pg_port}/{pg_db_name}"); @@ -681,7 +686,7 @@ async fn start( let simple_faucet = SimpleFaucet::new( new_wallet_context_for_faucet(faucet_key, config_dir.clone(), fullnode_url.clone())?, &prom_registry, - &config_dir.join("faucet.wal").as_path(), + config_dir.join("faucet.wal").as_path(), config, ) .await diff --git a/crates/sui/tests/cli_tests.rs b/crates/sui/tests/cli_tests.rs index c773db7a479211..667680aed9feb8 100644 --- a/crates/sui/tests/cli_tests.rs +++ b/crates/sui/tests/cli_tests.rs @@ -66,7 +66,22 @@ async fn test_genesis() -> Result<(), anyhow::Error> { // Start network without authorities let start = SuiCommand::Start { - config: Some(config), + config_dir: Some(config), + random_genesis: false, + with_graphql: false, + with_faucet: false, + with_indexer: false, + fullnode_rpc_port: 9000, + faucet_port: 9123, + graphql_host: "127.0.0.1".to_string(), + graphql_port: 8000, + indexer_rpc_port: 9124, + pg_port: 5432, + pg_host: "localhost".to_string(), + pg_db_name: "sui_indexer".to_string(), + pg_user: "postgres".to_string(), + pg_password: "postgrespw".to_string(), + epoch_duration_ms: None, no_full_node: false, } .execute() diff --git a/docs/content/guides/developer/getting-started/local-network.mdx b/docs/content/guides/developer/getting-started/local-network.mdx index a141b276f2a995..51420c07954482 100644 --- a/docs/content/guides/developer/getting-started/local-network.mdx +++ b/docs/content/guides/developer/getting-started/local-network.mdx @@ -14,11 +14,11 @@ To start the local network, run the following command after you installed Sui CL RUST_LOG="off,sui_node=info" sui start --with-faucet --random-genesis ``` -This will: -* call the Sui CLI binary with two flags: +This command: +* calls the Sui CLI binary with two flags: * `--with-faucet` to start a faucet service * `--random-genesis` to generate a new genesis and not persist the local network state -* instruct Rust to set specific logging through the `RUST_LOG`=`off,sui_node=info` flags, which turns off logging for all components except `sui-node`. If you want to see more detailed logs, you can remove `RUST_LOG` from the command. +* instructs Rust to set specific logging through the `RUST_LOG`=`off,sui_node=info` flags, which turns off logging for all components except `sui-node`. If you want to see more detailed logs, you can remove `RUST_LOG` from the command. :::info Each time you start the network by passing `--random-genesis`, the local network starts from a random genesis with no previous data, and the local network is not persisted. If you'd like to persist data, skip passing the `--random-genesis` flag. For more details, see the [Persist local network state](#persist-local-network) section. @@ -50,9 +50,9 @@ Use `sui start --help` to see these options in your console. ### Persist local network state -By default, when using `sui start` the command will use an existing Genesis and network configuration if the `~/.sui/sui_config` folder exists and if it has a `genesis.blob` file, or generate a new Genesis configuration if the folder does not exist. If the `--config-dir` is passed, it will check for the `genesis.blob` file and generate one if it does not exist. +By default, when using `sui start` the command uses an existing genesis and network configuration if the `~/.sui/sui_config` folder exists and includes a `genesis.blob` file. If the folder doesn't exist, it creates the folder and generates a new genesis configuration. If you pass `--config-dir`, the command checks for the `genesis.blob` file and network config file. -Whenever you stop and start again the network without passing `--random-genesis` flag, all history will be preserved and will be accessible. +Whenever you stop and start the network without passing the `--random-genesis` flag, all history is preserved and accessible. :::info To generate a custom genesis, use the `sui genesis` command and pass the desired custom values. For more information about possible flags and options, run `sui genesis --help`. diff --git a/scripts/sui-test-validator.sh b/scripts/sui-test-validator.sh index 8616c857782b21..08afffbb9a2a34 100755 --- a/scripts/sui-test-validator.sh +++ b/scripts/sui-test-validator.sh @@ -1,4 +1,6 @@ #!/bin/bash +# Copyright (c) Mysten Labs, Inc. +# SPDX-License-Identifier: Apache-2.0 echo "sui-test-validator binary has been deprecated in favor of sui start, which is a more powerful command that allows you to start the local network with more options. This script offers backward compatibiltiy, but ideally, you should migrate to sui start instead. Use sui start --help to see all the flags and options.