diff --git a/.github/workflows/_move_tests.yml b/.github/workflows/_move_tests.yml index a98c7ad8f3f..54c8b002f08 100644 --- a/.github/workflows/_move_tests.yml +++ b/.github/workflows/_move_tests.yml @@ -26,4 +26,24 @@ jobs: tool: nextest - name: Run move tests run: | - cargo nextest run -p iota-framework-tests -- unit_tests:: + cargo nextest run -E + 'package(iota-framework-tests) + or (package(iota-core) and test(quorum_driver::)) + or package(iota-benchmark) + or test(move_tests::)' + + move-simtest: + timeout-minutes: 10 + runs-on: [self-hosted] + steps: + - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 + - uses: taiki-e/install-action@375e0c7f08a66b8c2ba7e7eef31a6f91043a81b0 # v2.44.38 + with: + tool: nextest + - name: Run move tests + run: | + scripts/simtest/cargo-simtest simtest --profile ci -E + 'package(iota-framework-tests) + or (package(iota-core) and test(quorum_driver::)) + or package(iota-benchmark) + or test(move_tests::)' diff --git a/crates/iota-core/src/unit_tests/authority_aggregator_tests.rs b/crates/iota-core/src/unit_tests/authority_aggregator_tests.rs index f0ec7181006..ac734a40e8f 100644 --- a/crates/iota-core/src/unit_tests/authority_aggregator_tests.rs +++ b/crates/iota-core/src/unit_tests/authority_aggregator_tests.rs @@ -345,254 +345,262 @@ fn effects_with_tx(digest: TransactionDigest) -> TransactionEffects { effects } -/// The intent of this is to test whether client side timeouts -/// have any impact on the server execution. Turns out because -/// we spawn a tokio task on the server, client timing out and -/// terminating the connection does not stop server from completing -/// execution on its side -#[sim_test(config = "constant_latency_ms(1)")] -async fn test_quorum_map_and_reduce_timeout() { - let build_config = BuildConfig::new_for_testing(); - let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - path.extend(["src", "unit_tests", "data", "object_basics"]); - let client_ip = make_socket_addr(); - let modules: Vec<_> = build_config - .build(&path) - .unwrap() - .get_modules() - .cloned() - .collect(); - let pkg = Object::new_package_for_testing( - &modules, - TransactionDigest::genesis_marker(), - BuiltInFramework::genesis_move_packages(), - ) - .unwrap(); - let (addr1, key1): (_, AccountKeyPair) = get_key_pair(); - let gas_object1 = Object::with_owner_for_testing(addr1); - let genesis_objects = vec![pkg.clone(), gas_object1.clone()]; - let (mut authorities, _, genesis, _) = init_local_authorities(4, genesis_objects).await; - let rgp = reference_gas_price(&authorities); - let pkg = genesis.object(pkg.id()).unwrap(); - let gas_object1 = genesis.object(gas_object1.id()).unwrap(); - let gas_ref_1 = gas_object1.compute_object_reference(); - let tx = create_object_move_transaction(addr1, &key1, addr1, 100, pkg.id(), gas_ref_1, rgp); - let certified_tx = authorities - .process_transaction(tx.clone(), Some(client_ip)) - .await; - assert!(certified_tx.is_ok()); - let certificate = certified_tx.unwrap().into_cert_for_testing(); - // Send request with a very small timeout to trigger timeout error - authorities.timeouts.pre_quorum_timeout = Duration::from_nanos(0); - authorities.timeouts.post_quorum_timeout = Duration::from_nanos(0); - let request = HandleCertificateRequestV1 { - certificate: certificate.clone(), - include_events: true, - include_input_objects: false, - include_output_objects: false, - include_auxiliary_data: false, - }; - let certified_effects = authorities - .process_certificate(request, Some(client_ip)) - .await; - // Ensure it is an error - assert!(certified_effects.is_err()); - assert!(matches!( - certified_effects, - Err(AggregatorProcessCertificateError::RetryableExecuteCertificate { .. }) - )); - tokio::time::sleep(tokio::time::Duration::from_secs(10)).await; - let tx_info = TransactionInfoRequest { - transaction_digest: *tx.digest(), - }; - for (_, client) in authorities.authority_clients.iter() { - let resp = client - .handle_transaction_info_request(tx_info.clone()) +mod move_tests { + use super::*; + + /// The intent of this is to test whether client side timeouts + /// have any impact on the server execution. Turns out because + /// we spawn a tokio task on the server, client timing out and + /// terminating the connection does not stop server from completing + /// execution on its side + #[sim_test(config = "constant_latency_ms(1)")] + async fn test_quorum_map_and_reduce_timeout() { + let build_config = BuildConfig::new_for_testing(); + let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + path.extend(["src", "unit_tests", "data", "object_basics"]); + let client_ip = make_socket_addr(); + let modules: Vec<_> = build_config + .build(&path) + .unwrap() + .get_modules() + .cloned() + .collect(); + let pkg = Object::new_package_for_testing( + &modules, + TransactionDigest::genesis_marker(), + BuiltInFramework::genesis_move_packages(), + ) + .unwrap(); + let (addr1, key1): (_, AccountKeyPair) = get_key_pair(); + let gas_object1 = Object::with_owner_for_testing(addr1); + let genesis_objects = vec![pkg.clone(), gas_object1.clone()]; + let (mut authorities, _, genesis, _) = init_local_authorities(4, genesis_objects).await; + let rgp = reference_gas_price(&authorities); + let pkg = genesis.object(pkg.id()).unwrap(); + let gas_object1 = genesis.object(gas_object1.id()).unwrap(); + let gas_ref_1 = gas_object1.compute_object_reference(); + let tx = create_object_move_transaction(addr1, &key1, addr1, 100, pkg.id(), gas_ref_1, rgp); + let certified_tx = authorities + .process_transaction(tx.clone(), Some(client_ip)) .await; - // Server should return a signed effect even though previous calls - // failed due to timeout - assert!(resp.is_ok()); - assert!(resp.unwrap().is_executed()); + assert!(certified_tx.is_ok()); + let certificate = certified_tx.unwrap().into_cert_for_testing(); + // Send request with a very small timeout to trigger timeout error + authorities.timeouts.pre_quorum_timeout = Duration::from_nanos(0); + authorities.timeouts.post_quorum_timeout = Duration::from_nanos(0); + let request = HandleCertificateRequestV1 { + certificate: certificate.clone(), + include_events: true, + include_input_objects: false, + include_output_objects: false, + include_auxiliary_data: false, + }; + let certified_effects = authorities + .process_certificate(request, Some(client_ip)) + .await; + // Ensure it is an error + assert!(certified_effects.is_err()); + assert!(matches!( + certified_effects, + Err(AggregatorProcessCertificateError::RetryableExecuteCertificate { .. }) + )); + tokio::time::sleep(tokio::time::Duration::from_secs(10)).await; + let tx_info = TransactionInfoRequest { + transaction_digest: *tx.digest(), + }; + for (_, client) in authorities.authority_clients.iter() { + let resp = client + .handle_transaction_info_request(tx_info.clone()) + .await; + // Server should return a signed effect even though previous calls + // failed due to timeout + assert!(resp.is_ok()); + assert!(resp.unwrap().is_executed()); + } } -} -#[sim_test] -async fn test_map_reducer() { - let (authorities, _, _, _) = init_local_authorities(4, vec![]).await; - - // Test: mapper errors do not get propagated up, reducer works - let res = quorum_map_then_reduce_with_timeout::<_, _, _, _, _, (), _, _, _>( - authorities.committee.clone(), - authorities.authority_clients.clone(), - 0usize, - |_name, _client| { - Box::pin(async move { - let res: Result = Err(IotaError::TooManyIncorrectAuthorities { - errors: vec![], - action: "".to_string(), - }); - res - }) - }, - |mut accumulated_state, _authority_name, _authority_weight, result| { - Box::pin(async move { - assert!(matches!( - result, - Err(IotaError::TooManyIncorrectAuthorities { .. }) - )); - accumulated_state += 1; - ReduceOutput::Continue(accumulated_state) - }) - }, - Duration::from_millis(1000), - ) - .await - .unwrap_err(); - assert_eq!(4, res); - - // Test: early end - let res = quorum_map_then_reduce_with_timeout( - authorities.committee.clone(), - authorities.authority_clients.clone(), - 0usize, - |_name, _client| Box::pin(async move { Ok::<(), anyhow::Error>(()) }), - |mut accumulated_state, _authority_name, _authority_weight, _result| { - Box::pin(async move { - if accumulated_state > 2 { - ReduceOutput::Success(accumulated_state) - } else { + #[sim_test] + async fn test_map_reducer() { + let (authorities, _, _, _) = init_local_authorities(4, vec![]).await; + + // Test: mapper errors do not get propagated up, reducer works + let res = quorum_map_then_reduce_with_timeout::<_, _, _, _, _, (), _, _, _>( + authorities.committee.clone(), + authorities.authority_clients.clone(), + 0usize, + |_name, _client| { + Box::pin(async move { + let res: Result = + Err(IotaError::TooManyIncorrectAuthorities { + errors: vec![], + action: "".to_string(), + }); + res + }) + }, + |mut accumulated_state, _authority_name, _authority_weight, result| { + Box::pin(async move { + assert!(matches!( + result, + Err(IotaError::TooManyIncorrectAuthorities { .. }) + )); accumulated_state += 1; ReduceOutput::Continue(accumulated_state) - } - }) - }, - Duration::from_millis(1000), - ) - .await - .unwrap(); - assert_eq!(3, res.0); - - // Test: Global timeout works - let res = quorum_map_then_reduce_with_timeout::<_, _, _, _, _, (), _, _, _>( - authorities.committee.clone(), - authorities.authority_clients.clone(), - 0usize, - |_name, _client| { - Box::pin(async move { - // 10 mins - tokio::time::sleep(Duration::from_secs(10 * 60)).await; - Ok::<(), anyhow::Error>(()) - }) - }, - |_accumulated_state, _authority_name, _authority_weight, _result| { - Box::pin(async move { ReduceOutput::Continue(0) }) - }, - Duration::from_millis(10), - ) - .await - .unwrap_err(); - assert_eq!(0, res); - - // Test: Local timeout works - let bad_auth = *authorities.committee.sample(); - let res = quorum_map_then_reduce_with_timeout::<_, _, _, _, _, (), _, _, _>( - authorities.committee.clone(), - authorities.authority_clients.clone(), - HashSet::new(), - |_name, _client| { - Box::pin(async move { - // 10 mins - if _name == bad_auth { + }) + }, + Duration::from_millis(1000), + ) + .await + .unwrap_err(); + assert_eq!(4, res); + + // Test: early end + let res = quorum_map_then_reduce_with_timeout( + authorities.committee.clone(), + authorities.authority_clients.clone(), + 0usize, + |_name, _client| Box::pin(async move { Ok::<(), anyhow::Error>(()) }), + |mut accumulated_state, _authority_name, _authority_weight, _result| { + Box::pin(async move { + if accumulated_state > 2 { + ReduceOutput::Success(accumulated_state) + } else { + accumulated_state += 1; + ReduceOutput::Continue(accumulated_state) + } + }) + }, + Duration::from_millis(1000), + ) + .await + .unwrap(); + assert_eq!(3, res.0); + + // Test: Global timeout works + let res = quorum_map_then_reduce_with_timeout::<_, _, _, _, _, (), _, _, _>( + authorities.committee.clone(), + authorities.authority_clients.clone(), + 0usize, + |_name, _client| { + Box::pin(async move { + // 10 mins tokio::time::sleep(Duration::from_secs(10 * 60)).await; - } - Ok::<(), anyhow::Error>(()) - }) - }, - |mut accumulated_state, authority_name, _authority_weight, _result| { - Box::pin(async move { - accumulated_state.insert(authority_name); - if accumulated_state.len() <= 3 { - ReduceOutput::Continue(accumulated_state) - } else { - ReduceOutput::ContinueWithTimeout(accumulated_state, Duration::from_millis(10)) - } - }) - }, - // large delay - Duration::from_millis(10 * 60), - ) - .await; - assert_eq!(res.as_ref().unwrap_err().len(), 3); - assert!(!res.as_ref().unwrap_err().contains(&bad_auth)); -} + Ok::<(), anyhow::Error>(()) + }) + }, + |_accumulated_state, _authority_name, _authority_weight, _result| { + Box::pin(async move { ReduceOutput::Continue(0) }) + }, + Duration::from_millis(10), + ) + .await + .unwrap_err(); + assert_eq!(0, res); + + // Test: Local timeout works + let bad_auth = *authorities.committee.sample(); + let res = quorum_map_then_reduce_with_timeout::<_, _, _, _, _, (), _, _, _>( + authorities.committee.clone(), + authorities.authority_clients.clone(), + HashSet::new(), + |_name, _client| { + Box::pin(async move { + // 10 mins + if _name == bad_auth { + tokio::time::sleep(Duration::from_secs(10 * 60)).await; + } + Ok::<(), anyhow::Error>(()) + }) + }, + |mut accumulated_state, authority_name, _authority_weight, _result| { + Box::pin(async move { + accumulated_state.insert(authority_name); + if accumulated_state.len() <= 3 { + ReduceOutput::Continue(accumulated_state) + } else { + ReduceOutput::ContinueWithTimeout( + accumulated_state, + Duration::from_millis(10), + ) + } + }) + }, + // large delay + Duration::from_millis(10 * 60), + ) + .await; + assert_eq!(res.as_ref().unwrap_err().len(), 3); + assert!(!res.as_ref().unwrap_err().contains(&bad_auth)); + } -#[sim_test] -async fn test_process_transaction_fault_success() { - // This test exercises the 4 different possible failing case when one authority - // is faulty. A transaction is sent to all authories, however one of them - // will error out either before or after processing the transaction. - // A cert should still be created, and sent out to all authorities again. This - // time a different authority errors out either before or after processing - // the cert. - for i in 0..4 { - let mut config_before_process_transaction = LocalAuthorityClientFaultConfig::default(); - if i % 2 == 0 { - config_before_process_transaction.fail_before_handle_transaction = true; - } else { - config_before_process_transaction.fail_after_handle_transaction = true; - } - let mut config_before_process_certificate = LocalAuthorityClientFaultConfig::default(); - if i < 2 { - config_before_process_certificate.fail_before_handle_confirmation = true; - } else { - config_before_process_certificate.fail_after_handle_confirmation = true; + #[sim_test] + async fn test_process_transaction_fault_success() { + // This test exercises the 4 different possible failing case when one authority + // is faulty. A transaction is sent to all authories, however one of them + // will error out either before or after processing the transaction. + // A cert should still be created, and sent out to all authorities again. This + // time a different authority errors out either before or after processing + // the cert. + for i in 0..4 { + let mut config_before_process_transaction = LocalAuthorityClientFaultConfig::default(); + if i % 2 == 0 { + config_before_process_transaction.fail_before_handle_transaction = true; + } else { + config_before_process_transaction.fail_after_handle_transaction = true; + } + let mut config_before_process_certificate = LocalAuthorityClientFaultConfig::default(); + if i < 2 { + config_before_process_certificate.fail_before_handle_confirmation = true; + } else { + config_before_process_certificate.fail_after_handle_confirmation = true; + } + assert!( + execute_transaction_with_fault_configs( + &[(0, config_before_process_transaction)], + &[(1, config_before_process_certificate)], + ) + .await + ); } + } + + #[sim_test] + async fn test_process_transaction_fault_fail() { + // This test exercises the cases when there are 2 authorities faulty, + // and hence no quorum could be formed. This is tested on the + // process_transaction phase. + let fail_before_process_transaction_config = LocalAuthorityClientFaultConfig { + fail_before_handle_transaction: true, + ..Default::default() + }; assert!( - execute_transaction_with_fault_configs(&[(0, config_before_process_transaction)], &[( - 1, - config_before_process_certificate - )],) + !execute_transaction_with_fault_configs( + &[ + (0, fail_before_process_transaction_config), + (1, fail_before_process_transaction_config), + ], + &[], + ) .await ); } -} -#[sim_test] -async fn test_process_transaction_fault_fail() { - // This test exercises the cases when there are 2 authorities faulty, - // and hence no quorum could be formed. This is tested on the - // process_transaction phase. - let fail_before_process_transaction_config = LocalAuthorityClientFaultConfig { - fail_before_handle_transaction: true, - ..Default::default() - }; - assert!( - !execute_transaction_with_fault_configs( - &[ - (0, fail_before_process_transaction_config), - (1, fail_before_process_transaction_config), - ], - &[], - ) - .await - ); -} - -#[sim_test] -async fn test_process_certificate_fault_fail() { - // Similar to test_process_transaction_fault_fail but tested on the - // process_certificate phase. - let fail_before_process_certificate_config = LocalAuthorityClientFaultConfig { - fail_before_handle_confirmation: true, - ..Default::default() - }; - assert!( - !execute_transaction_with_fault_configs(&[], &[ - (0, fail_before_process_certificate_config), - (1, fail_before_process_certificate_config), - ],) - .await - ); + #[sim_test] + async fn test_process_certificate_fault_fail() { + // Similar to test_process_transaction_fault_fail but tested on the + // process_certificate phase. + let fail_before_process_certificate_config = LocalAuthorityClientFaultConfig { + fail_before_handle_confirmation: true, + ..Default::default() + }; + assert!( + !execute_transaction_with_fault_configs(&[], &[ + (0, fail_before_process_certificate_config), + (1, fail_before_process_certificate_config), + ],) + .await + ); + } } #[tokio::test(start_paused = true)] diff --git a/crates/iota-core/src/unit_tests/execution_driver_tests.rs b/crates/iota-core/src/unit_tests/execution_driver_tests.rs index 50363e411c1..e41d0583860 100644 --- a/crates/iota-core/src/unit_tests/execution_driver_tests.rs +++ b/crates/iota-core/src/unit_tests/execution_driver_tests.rs @@ -298,268 +298,300 @@ async fn execute_shared_on_first_three_authorities( (cert, effects) } -#[tokio::test(flavor = "current_thread", start_paused = true)] -async fn test_execution_with_dependencies() { - telemetry_subscribers::init_for_testing(); - - // ---- Initialize a network with three accounts, each with 10 gas objects. - - const NUM_ACCOUNTS: usize = 3; - let accounts: Vec<(_, AccountKeyPair)> = - (0..NUM_ACCOUNTS).map(|_| get_key_pair()).collect_vec(); - - const NUM_GAS_OBJECTS_PER_ACCOUNT: usize = 10; - let gas_objects = (0..NUM_ACCOUNTS) - .map(|i| { - (0..NUM_GAS_OBJECTS_PER_ACCOUNT) - .map(|_| Object::with_owner_for_testing(accounts[i].0)) - .collect_vec() - }) - .collect_vec(); - let all_gas_objects = gas_objects.clone().into_iter().flatten().collect_vec(); - - let (aggregator, authorities, _genesis, package) = - init_local_authorities(4, all_gas_objects.clone()).await; - let authority_clients: Vec<_> = authorities - .iter() - .map(|a| aggregator.authority_clients[&a.name].clone()) - .collect(); - let rgp = authorities - .first() - .unwrap() - .reference_gas_price_for_testing() - .unwrap(); - - // ---- Create an owned object and a shared counter. - - let mut executed_owned_certs = Vec::new(); - let mut executed_shared_certs = Vec::new(); - - // Initialize an object owned by 1st account. - let (addr1, key1): &(_, AccountKeyPair) = &accounts[0]; - let gas_ref = get_latest_ref(authority_clients[0].clone(), gas_objects[0][0].id()).await; - let tx1 = create_object_move_transaction(*addr1, key1, *addr1, 100, package, gas_ref, rgp); - let (cert, effects1) = - execute_owned_on_first_three_authorities(&authority_clients, &aggregator.committee, &tx1) - .await; - executed_owned_certs.push(cert); - let mut owned_object_ref = effects1.created()[0].0; - - // Initialize a shared counter, re-using gas_ref_0 so it has to execute after - // tx1. - let gas_ref = get_latest_ref(authority_clients[0].clone(), gas_objects[0][0].id()).await; - let tx2 = TestTransactionBuilder::new(*addr1, gas_ref, rgp) - .call_counter_create(package) - .build_and_sign(key1); - let (cert, effects2) = - execute_owned_on_first_three_authorities(&authority_clients, &aggregator.committee, &tx2) - .await; - executed_owned_certs.push(cert); - let (mut shared_counter_ref, owner) = effects2.created()[0]; - let shared_counter_initial_version = if let Owner::Shared { - initial_shared_version, - } = owner - { - // Because the gas object used has version 2, the initial lamport timestamp of - // the shared counter is 3. - assert_eq!(initial_shared_version.value(), 3); - initial_shared_version - } else { - panic!("Not a shared object! {:?} {:?}", shared_counter_ref, owner); - }; +mod move_tests { + use super::*; + + #[tokio::test(flavor = "current_thread", start_paused = true)] + async fn test_execution_with_dependencies() { + telemetry_subscribers::init_for_testing(); + + // ---- Initialize a network with three accounts, each with 10 gas objects. + + const NUM_ACCOUNTS: usize = 3; + let accounts: Vec<(_, AccountKeyPair)> = + (0..NUM_ACCOUNTS).map(|_| get_key_pair()).collect_vec(); + + const NUM_GAS_OBJECTS_PER_ACCOUNT: usize = 10; + let gas_objects = (0..NUM_ACCOUNTS) + .map(|i| { + (0..NUM_GAS_OBJECTS_PER_ACCOUNT) + .map(|_| Object::with_owner_for_testing(accounts[i].0)) + .collect_vec() + }) + .collect_vec(); + let all_gas_objects = gas_objects.clone().into_iter().flatten().collect_vec(); + + let (aggregator, authorities, _genesis, package) = + init_local_authorities(4, all_gas_objects.clone()).await; + let authority_clients: Vec<_> = authorities + .iter() + .map(|a| aggregator.authority_clients[&a.name].clone()) + .collect(); + let rgp = authorities + .first() + .unwrap() + .reference_gas_price_for_testing() + .unwrap(); - // ---- Execute transactions with dependencies on first 3 nodes in the - // dependency order. + // ---- Create an owned object and a shared counter. - // In each iteration, creates an owned and a shared transaction that depends on - // previous input and gas objects. - for i in 0..100 { - let source_index = i % NUM_ACCOUNTS; - let (source_addr, source_key) = &accounts[source_index]; + let mut executed_owned_certs = Vec::new(); + let mut executed_shared_certs = Vec::new(); - let gas_ref = get_latest_ref( - authority_clients[source_index].clone(), - gas_objects[source_index][i * 3 % NUM_GAS_OBJECTS_PER_ACCOUNT].id(), + // Initialize an object owned by 1st account. + let (addr1, key1): &(_, AccountKeyPair) = &accounts[0]; + let gas_ref = get_latest_ref(authority_clients[0].clone(), gas_objects[0][0].id()).await; + let tx1 = create_object_move_transaction(*addr1, key1, *addr1, 100, package, gas_ref, rgp); + let (cert, effects1) = execute_owned_on_first_three_authorities( + &authority_clients, + &aggregator.committee, + &tx1, ) .await; - let (dest_addr, _) = &accounts[(i + 1) % NUM_ACCOUNTS]; - let owned_tx = make_transfer_object_move_transaction( - *source_addr, - source_key, - *dest_addr, - owned_object_ref, - package, - gas_ref, - TEST_ONLY_GAS_UNIT_FOR_HEAVY_COMPUTATION_STORAGE, - rgp, - ); - let (cert, effects) = execute_owned_on_first_three_authorities( + executed_owned_certs.push(cert); + let mut owned_object_ref = effects1.created()[0].0; + + // Initialize a shared counter, re-using gas_ref_0 so it has to execute after + // tx1. + let gas_ref = get_latest_ref(authority_clients[0].clone(), gas_objects[0][0].id()).await; + let tx2 = TestTransactionBuilder::new(*addr1, gas_ref, rgp) + .call_counter_create(package) + .build_and_sign(key1); + let (cert, effects2) = execute_owned_on_first_three_authorities( &authority_clients, &aggregator.committee, - &owned_tx, + &tx2, ) .await; executed_owned_certs.push(cert); - owned_object_ref = effects.mutated_excluding_gas().first().unwrap().0; + let (mut shared_counter_ref, owner) = effects2.created()[0]; + let shared_counter_initial_version = if let Owner::Shared { + initial_shared_version, + } = owner + { + // Because the gas object used has version 2, the initial lamport timestamp of + // the shared counter is 3. + assert_eq!(initial_shared_version.value(), 3); + initial_shared_version + } else { + panic!("Not a shared object! {:?} {:?}", shared_counter_ref, owner); + }; - let gas_ref = get_latest_ref( - authority_clients[source_index].clone(), - gas_objects[source_index][i * 7 % NUM_GAS_OBJECTS_PER_ACCOUNT].id(), - ) - .await; - let shared_tx = TestTransactionBuilder::new(*source_addr, gas_ref, rgp) - .call_counter_increment( + // ---- Execute transactions with dependencies on first 3 nodes in the + // dependency order. + + // In each iteration, creates an owned and a shared transaction that depends on + // previous input and gas objects. + for i in 0..100 { + let source_index = i % NUM_ACCOUNTS; + let (source_addr, source_key) = &accounts[source_index]; + + let gas_ref = get_latest_ref( + authority_clients[source_index].clone(), + gas_objects[source_index][i * 3 % NUM_GAS_OBJECTS_PER_ACCOUNT].id(), + ) + .await; + let (dest_addr, _) = &accounts[(i + 1) % NUM_ACCOUNTS]; + let owned_tx = make_transfer_object_move_transaction( + *source_addr, + source_key, + *dest_addr, + owned_object_ref, package, - shared_counter_ref.0, - shared_counter_initial_version, + gas_ref, + TEST_ONLY_GAS_UNIT_FOR_HEAVY_COMPUTATION_STORAGE, + rgp, + ); + let (cert, effects) = execute_owned_on_first_three_authorities( + &authority_clients, + &aggregator.committee, + &owned_tx, ) - .build_and_sign(source_key); - let (cert, effects) = execute_shared_on_first_three_authorities( - &authority_clients, - &aggregator.committee, - &shared_tx, - ) - .await; - executed_shared_certs.push(cert); - shared_counter_ref = effects.mutated_excluding_gas().first().unwrap().0; - } + .await; + executed_owned_certs.push(cert); + owned_object_ref = effects.mutated_excluding_gas().first().unwrap().0; - // ---- Execute transactions in reverse dependency order on the last authority. + let gas_ref = get_latest_ref( + authority_clients[source_index].clone(), + gas_objects[source_index][i * 7 % NUM_GAS_OBJECTS_PER_ACCOUNT].id(), + ) + .await; + let shared_tx = TestTransactionBuilder::new(*source_addr, gas_ref, rgp) + .call_counter_increment( + package, + shared_counter_ref.0, + shared_counter_initial_version, + ) + .build_and_sign(source_key); + let (cert, effects) = execute_shared_on_first_three_authorities( + &authority_clients, + &aggregator.committee, + &shared_tx, + ) + .await; + executed_shared_certs.push(cert); + shared_counter_ref = effects.mutated_excluding_gas().first().unwrap().0; + } - // Sets shared object locks in the executed order. - for cert in executed_shared_certs.iter() { - send_consensus_no_execution(&authorities[3], cert).await; - } + // ---- Execute transactions in reverse dependency order on the last authority. - // Enqueue certs out of dependency order for executions. - for cert in executed_shared_certs.iter().rev() { - authorities[3].enqueue_certificates_for_execution( - vec![cert.clone()], - &authorities[3].epoch_store_for_testing(), - ); - } - for cert in executed_owned_certs.iter().rev() { - authorities[3].enqueue_certificates_for_execution( - vec![cert.clone()], - &authorities[3].epoch_store_for_testing(), - ); - } + // Sets shared object locks in the executed order. + for cert in executed_shared_certs.iter() { + send_consensus_no_execution(&authorities[3], cert).await; + } - // All certs should get executed eventually. - let digests: Vec<_> = executed_shared_certs - .iter() - .chain(executed_owned_certs.iter()) - .map(|cert| *cert.digest()) - .collect(); - authorities[3] - .get_transaction_cache_reader() - .notify_read_executed_effects(&digests) - .await - .unwrap(); -} + // Enqueue certs out of dependency order for executions. + for cert in executed_shared_certs.iter().rev() { + authorities[3].enqueue_certificates_for_execution( + vec![cert.clone()], + &authorities[3].epoch_store_for_testing(), + ); + } + for cert in executed_owned_certs.iter().rev() { + authorities[3].enqueue_certificates_for_execution( + vec![cert.clone()], + &authorities[3].epoch_store_for_testing(), + ); + } -fn make_socket_addr() -> std::net::SocketAddr { - SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 0) -} + // All certs should get executed eventually. + let digests: Vec<_> = executed_shared_certs + .iter() + .chain(executed_owned_certs.iter()) + .map(|cert| *cert.digest()) + .collect(); + authorities[3] + .get_transaction_cache_reader() + .notify_read_executed_effects(&digests) + .await + .unwrap(); + } -async fn try_sign_on_first_three_authorities( - authority_clients: &[Arc>], - committee: &Committee, - txn: &Transaction, -) -> IotaResult { - for client in authority_clients.iter().take(3) { - client - .handle_transaction(txn.clone(), Some(make_socket_addr())) - .await?; + fn make_socket_addr() -> std::net::SocketAddr { + SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 0) } - extract_cert(authority_clients, committee, txn.digest()) - .await - .try_into_verified_for_testing(committee, &Default::default()) -} -#[tokio::test(flavor = "current_thread", start_paused = true)] -async fn test_per_object_overload() { - telemetry_subscribers::init_for_testing(); + async fn try_sign_on_first_three_authorities( + authority_clients: &[Arc>], + committee: &Committee, + txn: &Transaction, + ) -> IotaResult { + for client in authority_clients.iter().take(3) { + client + .handle_transaction(txn.clone(), Some(make_socket_addr())) + .await?; + } + extract_cert(authority_clients, committee, txn.digest()) + .await + .try_into_verified_for_testing(committee, &Default::default()) + } - // Initialize a network with 1 account and 2000 gas objects. - let (addr, key): (_, AccountKeyPair) = get_key_pair(); - const NUM_GAS_OBJECTS_PER_ACCOUNT: usize = 2000; - let gas_objects = (0..NUM_GAS_OBJECTS_PER_ACCOUNT) - .map(|_| Object::with_owner_for_testing(addr)) - .collect_vec(); - let (aggregator, authorities, _genesis, package) = - init_local_authorities(4, gas_objects.clone()).await; - let rgp = authorities - .first() - .unwrap() - .reference_gas_price_for_testing() + #[tokio::test(flavor = "current_thread", start_paused = true)] + async fn test_per_object_overload() { + telemetry_subscribers::init_for_testing(); + + // Initialize a network with 1 account and 2000 gas objects. + let (addr, key): (_, AccountKeyPair) = get_key_pair(); + const NUM_GAS_OBJECTS_PER_ACCOUNT: usize = 2000; + let gas_objects = (0..NUM_GAS_OBJECTS_PER_ACCOUNT) + .map(|_| Object::with_owner_for_testing(addr)) + .collect_vec(); + let (aggregator, authorities, _genesis, package) = + init_local_authorities(4, gas_objects.clone()).await; + let rgp = authorities + .first() + .unwrap() + .reference_gas_price_for_testing() + .unwrap(); + let authority_clients: Vec<_> = authorities + .iter() + .map(|a| aggregator.authority_clients[&a.name].clone()) + .collect(); + + // Create a shared counter. + let gas_ref = get_latest_ref(authority_clients[0].clone(), gas_objects[0].id()).await; + let create_counter_txn = TestTransactionBuilder::new(addr, gas_ref, rgp) + .call_counter_create(package) + .build_and_sign(&key); + let create_counter_cert = try_sign_on_first_three_authorities( + &authority_clients, + &aggregator.committee, + &create_counter_txn, + ) + .await .unwrap(); - let authority_clients: Vec<_> = authorities - .iter() - .map(|a| aggregator.authority_clients[&a.name].clone()) - .collect(); - - // Create a shared counter. - let gas_ref = get_latest_ref(authority_clients[0].clone(), gas_objects[0].id()).await; - let create_counter_txn = TestTransactionBuilder::new(addr, gas_ref, rgp) - .call_counter_create(package) - .build_and_sign(&key); - let create_counter_cert = try_sign_on_first_three_authorities( - &authority_clients, - &aggregator.committee, - &create_counter_txn, - ) - .await - .unwrap(); - for authority in authorities.iter().take(3) { - send_consensus(authority, &create_counter_cert).await; - } - for authority in authorities.iter().take(3) { - authority + for authority in authorities.iter().take(3) { + send_consensus(authority, &create_counter_cert).await; + } + for authority in authorities.iter().take(3) { + authority + .get_transaction_cache_reader() + .notify_read_executed_effects(&[*create_counter_cert.digest()]) + .await + .unwrap() + .pop() + .unwrap(); + } + + // Signing and executing this transaction on the last authority should succeed. + authority_clients[3] + .handle_transaction(create_counter_txn.clone(), Some(make_socket_addr())) + .await + .unwrap(); + send_consensus(&authorities[3], &create_counter_cert).await; + let create_counter_effects = authorities[3] .get_transaction_cache_reader() .notify_read_executed_effects(&[*create_counter_cert.digest()]) .await .unwrap() .pop() .unwrap(); - } + let (shared_counter_ref, owner) = create_counter_effects.created()[0]; + let Owner::Shared { + initial_shared_version: shared_counter_initial_version, + } = owner + else { + panic!("Not a shared object! {:?} {:?}", shared_counter_ref, owner); + }; - // Signing and executing this transaction on the last authority should succeed. - authority_clients[3] - .handle_transaction(create_counter_txn.clone(), Some(make_socket_addr())) - .await - .unwrap(); - send_consensus(&authorities[3], &create_counter_cert).await; - let create_counter_effects = authorities[3] - .get_transaction_cache_reader() - .notify_read_executed_effects(&[*create_counter_cert.digest()]) - .await - .unwrap() - .pop() - .unwrap(); - let (shared_counter_ref, owner) = create_counter_effects.created()[0]; - let Owner::Shared { - initial_shared_version: shared_counter_initial_version, - } = owner - else { - panic!("Not a shared object! {:?} {:?}", shared_counter_ref, owner); - }; + // Stop execution on the last authority, to simulate having a backlog. + authorities[3].shutdown_execution_for_test(); + // Make sure execution driver has exited. + sleep(Duration::from_secs(1)).await; + + // Sign and try execute 1000 txns on the first three authorities. And enqueue + // them on the last authority. First shared counter txn has input object + // available on authority 3. So to overload authority 3, 1 more + // txn is needed. + let num_txns = authorities[3] + .overload_config() + .max_transaction_manager_per_object_queue_length + + 1; + for gas_object in gas_objects.iter().take(num_txns) { + let gas_ref = get_latest_ref(authority_clients[0].clone(), gas_object.id()).await; + let shared_txn = TestTransactionBuilder::new(addr, gas_ref, rgp) + .call_counter_increment( + package, + shared_counter_ref.0, + shared_counter_initial_version, + ) + .build_and_sign(&key); + let shared_cert = try_sign_on_first_three_authorities( + &authority_clients, + &aggregator.committee, + &shared_txn, + ) + .await + .unwrap(); + for authority in authorities.iter().take(3) { + send_consensus(authority, &shared_cert).await; + } + send_consensus(&authorities[3], &shared_cert).await; + } - // Stop execution on the last authority, to simulate having a backlog. - authorities[3].shutdown_execution_for_test(); - // Make sure execution driver has exited. - sleep(Duration::from_secs(1)).await; - - // Sign and try execute 1000 txns on the first three authorities. And enqueue - // them on the last authority. First shared counter txn has input object - // available on authority 3. So to overload authority 3, 1 more - // txn is needed. - let num_txns = authorities[3] - .overload_config() - .max_transaction_manager_per_object_queue_length - + 1; - for gas_object in gas_objects.iter().take(num_txns) { - let gas_ref = get_latest_ref(authority_clients[0].clone(), gas_object.id()).await; + // Trying to sign a new transaction would now fail. + let gas_ref = + get_latest_ref(authority_clients[0].clone(), gas_objects[num_txns].id()).await; let shared_txn = TestTransactionBuilder::new(addr, gas_ref, rgp) .call_counter_increment( package, @@ -567,125 +599,129 @@ async fn test_per_object_overload() { shared_counter_initial_version, ) .build_and_sign(&key); - let shared_cert = try_sign_on_first_three_authorities( + let res = authorities[3] + .transaction_manager() + .check_execution_overload(authorities[3].overload_config(), shared_txn.data()); + let message = format!("{res:?}"); + assert!( + message.contains("TooManyTransactionsPendingOnObject"), + "{}", + message + ); + } + + #[tokio::test] + async fn test_txn_age_overload() { + telemetry_subscribers::init_for_testing(); + + // Initialize a network with 1 account and 3 gas objects. + let (addr, key): (_, AccountKeyPair) = get_key_pair(); + let gas_objects = (0..3) + .map(|_| Object::with_owner_for_testing(addr)) + .collect_vec(); + let (aggregator, authorities, _genesis, package) = + init_local_authorities_with_overload_thresholds( + 4, + gas_objects.clone(), + AuthorityOverloadConfig { + max_txn_age_in_queue: Duration::from_secs(5), + ..Default::default() + }, + ) + .await; + let rgp = authorities + .first() + .unwrap() + .reference_gas_price_for_testing() + .unwrap(); + let authority_clients: Vec<_> = authorities + .iter() + .map(|a| aggregator.authority_clients[&a.name].clone()) + .collect(); + + // Create a shared counter. + let gas_ref = get_latest_ref(authority_clients[0].clone(), gas_objects[0].id()).await; + let create_counter_txn = TestTransactionBuilder::new(addr, gas_ref, rgp) + .call_counter_create(package) + .build_and_sign(&key); + let create_counter_cert = try_sign_on_first_three_authorities( &authority_clients, &aggregator.committee, - &shared_txn, + &create_counter_txn, ) .await .unwrap(); for authority in authorities.iter().take(3) { - send_consensus(authority, &shared_cert).await; + send_consensus(authority, &create_counter_cert).await; + } + for authority in authorities.iter().take(3) { + authority + .get_transaction_cache_reader() + .notify_read_executed_effects(&[*create_counter_cert.digest()]) + .await + .unwrap() + .pop() + .unwrap(); } - send_consensus(&authorities[3], &shared_cert).await; - } - - // Trying to sign a new transaction would now fail. - let gas_ref = get_latest_ref(authority_clients[0].clone(), gas_objects[num_txns].id()).await; - let shared_txn = TestTransactionBuilder::new(addr, gas_ref, rgp) - .call_counter_increment( - package, - shared_counter_ref.0, - shared_counter_initial_version, - ) - .build_and_sign(&key); - let res = authorities[3] - .transaction_manager() - .check_execution_overload(authorities[3].overload_config(), shared_txn.data()); - let message = format!("{res:?}"); - assert!( - message.contains("TooManyTransactionsPendingOnObject"), - "{}", - message - ); -} - -#[tokio::test] -async fn test_txn_age_overload() { - telemetry_subscribers::init_for_testing(); - // Initialize a network with 1 account and 3 gas objects. - let (addr, key): (_, AccountKeyPair) = get_key_pair(); - let gas_objects = (0..3) - .map(|_| Object::with_owner_for_testing(addr)) - .collect_vec(); - let (aggregator, authorities, _genesis, package) = - init_local_authorities_with_overload_thresholds( - 4, - gas_objects.clone(), - AuthorityOverloadConfig { - max_txn_age_in_queue: Duration::from_secs(5), - ..Default::default() - }, - ) - .await; - let rgp = authorities - .first() - .unwrap() - .reference_gas_price_for_testing() - .unwrap(); - let authority_clients: Vec<_> = authorities - .iter() - .map(|a| aggregator.authority_clients[&a.name].clone()) - .collect(); - - // Create a shared counter. - let gas_ref = get_latest_ref(authority_clients[0].clone(), gas_objects[0].id()).await; - let create_counter_txn = TestTransactionBuilder::new(addr, gas_ref, rgp) - .call_counter_create(package) - .build_and_sign(&key); - let create_counter_cert = try_sign_on_first_three_authorities( - &authority_clients, - &aggregator.committee, - &create_counter_txn, - ) - .await - .unwrap(); - for authority in authorities.iter().take(3) { - send_consensus(authority, &create_counter_cert).await; - } - for authority in authorities.iter().take(3) { - authority + // Signing and executing this transaction on the last authority should succeed. + authority_clients[3] + .handle_transaction(create_counter_txn.clone(), Some(make_socket_addr())) + .await + .unwrap(); + send_consensus(&authorities[3], &create_counter_cert).await; + let create_counter_effects = authorities[3] .get_transaction_cache_reader() .notify_read_executed_effects(&[*create_counter_cert.digest()]) .await .unwrap() .pop() .unwrap(); - } + let (shared_counter_ref, owner) = create_counter_effects.created()[0]; + let Owner::Shared { + initial_shared_version: shared_counter_initial_version, + } = owner + else { + panic!("Not a shared object! {:?} {:?}", shared_counter_ref, owner); + }; - // Signing and executing this transaction on the last authority should succeed. - authority_clients[3] - .handle_transaction(create_counter_txn.clone(), Some(make_socket_addr())) - .await - .unwrap(); - send_consensus(&authorities[3], &create_counter_cert).await; - let create_counter_effects = authorities[3] - .get_transaction_cache_reader() - .notify_read_executed_effects(&[*create_counter_cert.digest()]) - .await - .unwrap() - .pop() - .unwrap(); - let (shared_counter_ref, owner) = create_counter_effects.created()[0]; - let Owner::Shared { - initial_shared_version: shared_counter_initial_version, - } = owner - else { - panic!("Not a shared object! {:?} {:?}", shared_counter_ref, owner); - }; + // Stop execution on the last authority, to simulate having a backlog. + authorities[3].shutdown_execution_for_test(); + // Make sure execution driver has exited. + sleep(Duration::from_secs(1)).await; + + // Sign and try execute 2 txns on the first three authorities. And enqueue them + // on the last authority. First shared counter txn has input object + // available on authority 3. So to put a txn in the queue, we + // will need another txn. + for gas_object in gas_objects.iter().take(2) { + let gas_ref = get_latest_ref(authority_clients[0].clone(), gas_object.id()).await; + let shared_txn = TestTransactionBuilder::new(addr, gas_ref, rgp) + .call_counter_increment( + package, + shared_counter_ref.0, + shared_counter_initial_version, + ) + .build_and_sign(&key); + let shared_cert = try_sign_on_first_three_authorities( + &authority_clients, + &aggregator.committee, + &shared_txn, + ) + .await + .unwrap(); + for authority in authorities.iter().take(3) { + send_consensus(authority, &shared_cert).await; + } + send_consensus(&authorities[3], &shared_cert).await; + } + + // Sleep for 6 seconds to make sure the transaction is old enough since our + // threshold is 5. + tokio::time::sleep(Duration::from_secs(6)).await; - // Stop execution on the last authority, to simulate having a backlog. - authorities[3].shutdown_execution_for_test(); - // Make sure execution driver has exited. - sleep(Duration::from_secs(1)).await; - - // Sign and try execute 2 txns on the first three authorities. And enqueue them - // on the last authority. First shared counter txn has input object - // available on authority 3. So to put a txn in the queue, we - // will need another txn. - for gas_object in gas_objects.iter().take(2) { - let gas_ref = get_latest_ref(authority_clients[0].clone(), gas_object.id()).await; + // Trying to sign a new transaction would now fail. + let gas_ref = get_latest_ref(authority_clients[0].clone(), gas_objects[2].id()).await; let shared_txn = TestTransactionBuilder::new(addr, gas_ref, rgp) .call_counter_increment( package, @@ -693,41 +729,16 @@ async fn test_txn_age_overload() { shared_counter_initial_version, ) .build_and_sign(&key); - let shared_cert = try_sign_on_first_three_authorities( - &authority_clients, - &aggregator.committee, - &shared_txn, - ) - .await - .unwrap(); - for authority in authorities.iter().take(3) { - send_consensus(authority, &shared_cert).await; - } - send_consensus(&authorities[3], &shared_cert).await; + let res = authorities[3] + .transaction_manager() + .check_execution_overload(authorities[3].overload_config(), shared_txn.data()); + let message = format!("{res:?}"); + assert!( + message.contains("TooOldTransactionPendingOnObject"), + "{}", + message + ); } - - // Sleep for 6 seconds to make sure the transaction is old enough since our - // threshold is 5. - tokio::time::sleep(Duration::from_secs(6)).await; - - // Trying to sign a new transaction would now fail. - let gas_ref = get_latest_ref(authority_clients[0].clone(), gas_objects[2].id()).await; - let shared_txn = TestTransactionBuilder::new(addr, gas_ref, rgp) - .call_counter_increment( - package, - shared_counter_ref.0, - shared_counter_initial_version, - ) - .build_and_sign(&key); - let res = authorities[3] - .transaction_manager() - .check_execution_overload(authorities[3].overload_config(), shared_txn.data()); - let message = format!("{res:?}"); - assert!( - message.contains("TooOldTransactionPendingOnObject"), - "{}", - message - ); } // Tests that when validator is in load shedding mode, it can pushback txn diff --git a/crates/iota-json-rpc-tests/tests/read_api.rs b/crates/iota-json-rpc-tests/tests/read_api.rs index 8602e391c05..a38376ce97b 100644 --- a/crates/iota-json-rpc-tests/tests/read_api.rs +++ b/crates/iota-json-rpc-tests/tests/read_api.rs @@ -1487,104 +1487,108 @@ async fn try_get_past_object_version_not_found() { assert!(at_least_one_version_not_found) } -#[sim_test] -async fn try_get_past_object_deleted() { - let cluster = TestClusterBuilder::new().build().await; - let http_client = cluster.rpc_client(); - let address = cluster.get_address_0(); - - let objects = cluster - .get_owned_objects(address, Some(IotaObjectDataOptions::full_content())) - .await - .unwrap(); +mod move_tests { + use super::*; - assert_eq!(5, objects.len()); + #[sim_test] + async fn try_get_past_object_deleted() { + let cluster = TestClusterBuilder::new().build().await; + let http_client = cluster.rpc_client(); + let address = cluster.get_address_0(); - let tx_block_response = publish_move_package(&cluster).await; + let objects = cluster + .get_owned_objects(address, Some(IotaObjectDataOptions::full_content())) + .await + .unwrap(); - let package_id = tx_block_response - .object_changes - .unwrap() - .iter() - .filter_map(|obj_change| match obj_change { - ObjectChange::Published { package_id, .. } => Some(*package_id), - _ => None, - }) - .collect::>()[0]; + assert_eq!(5, objects.len()); - let tx_block_response = cluster - .sign_and_execute_transaction( - &cluster - .test_transaction_builder() - .await - .move_call(package_id, "object_basics", "create", vec![ - 1u64.into(), - CallArg::Pure(address.to_vec()), - ]) - .build(), - ) - .await; + let tx_block_response = publish_move_package(&cluster).await; - let created_object_id = tx_block_response - .object_changes - .unwrap() - .iter() - .filter_map(|obj_change| match obj_change { - ObjectChange::Created { object_id, .. } => Some(*object_id), - _ => None, - }) - .collect::>()[0]; + let package_id = tx_block_response + .object_changes + .unwrap() + .iter() + .filter_map(|obj_change| match obj_change { + ObjectChange::Published { package_id, .. } => Some(*package_id), + _ => None, + }) + .collect::>()[0]; + + let tx_block_response = cluster + .sign_and_execute_transaction( + &cluster + .test_transaction_builder() + .await + .move_call(package_id, "object_basics", "create", vec![ + 1u64.into(), + CallArg::Pure(address.to_vec()), + ]) + .build(), + ) + .await; - let objects = cluster - .get_owned_objects(address, Some(IotaObjectDataOptions::full_content())) - .await - .unwrap(); + let created_object_id = tx_block_response + .object_changes + .unwrap() + .iter() + .filter_map(|obj_change| match obj_change { + ObjectChange::Created { object_id, .. } => Some(*object_id), + _ => None, + }) + .collect::>()[0]; - let object_ids = objects - .iter() - .map(|a| a.object_id().unwrap()) - .collect::>(); + let objects = cluster + .get_owned_objects(address, Some(IotaObjectDataOptions::full_content())) + .await + .unwrap(); - assert_eq!(7, objects.len()); - assert!(object_ids.contains(&created_object_id)); + let object_ids = objects + .iter() + .map(|a| a.object_id().unwrap()) + .collect::>(); - let created_object = http_client - .get_object(created_object_id, None) - .await - .unwrap() - .data - .unwrap(); + assert_eq!(7, objects.len()); + assert!(object_ids.contains(&created_object_id)); - let arg = CallArg::Object(iota_types::transaction::ObjectArg::ImmOrOwnedObject(( - created_object.object_id, - created_object.version, - created_object.digest, - ))); + let created_object = http_client + .get_object(created_object_id, None) + .await + .unwrap() + .data + .unwrap(); - let tx_block_response = cluster - .sign_and_execute_transaction( - &cluster - .test_transaction_builder() - .await - .move_call(package_id, "object_basics", "delete", vec![arg]) - .build(), - ) - .await; + let arg = CallArg::Object(iota_types::transaction::ObjectArg::ImmOrOwnedObject(( + created_object.object_id, + created_object.version, + created_object.digest, + ))); + + let tx_block_response = cluster + .sign_and_execute_transaction( + &cluster + .test_transaction_builder() + .await + .move_call(package_id, "object_basics", "delete", vec![arg]) + .build(), + ) + .await; - assert_eq!( - tx_block_response.effects.as_ref().unwrap().deleted().len(), - 1 - ); + assert_eq!( + tx_block_response.effects.as_ref().unwrap().deleted().len(), + 1 + ); - let seq_num = SequenceNumber::from_u64(4); - let rpc_past_obj = http_client - .try_get_past_object(created_object_id, seq_num, None) - .await - .unwrap(); + let seq_num = SequenceNumber::from_u64(4); + let rpc_past_obj = http_client + .try_get_past_object(created_object_id, seq_num, None) + .await + .unwrap(); - assert!( - matches!(rpc_past_obj, IotaPastObjectResponse::ObjectDeleted(obj) if obj.object_id == created_object_id && obj.version == seq_num) - ); + assert!( + matches!(rpc_past_obj, IotaPastObjectResponse::ObjectDeleted(obj) if obj.object_id == created_object_id && obj.version == seq_num) + ); + } } #[sim_test] diff --git a/crates/iota-json-rpc-tests/tests/transaction_builder_api.rs b/crates/iota-json-rpc-tests/tests/transaction_builder_api.rs index cf7dc69998d..558a8cfa92d 100644 --- a/crates/iota-json-rpc-tests/tests/transaction_builder_api.rs +++ b/crates/iota-json-rpc-tests/tests/transaction_builder_api.rs @@ -298,49 +298,53 @@ async fn test_pay_all_iota() -> Result<(), anyhow::Error> { Ok(()) } -#[sim_test] -async fn test_publish() -> Result<(), anyhow::Error> { - let cluster = TestClusterBuilder::new().build().await; - let http_client = cluster.rpc_client(); - let address = cluster.get_address_0(); - - let objects = http_client - .get_owned_objects( - address, - Some(IotaObjectResponseQuery::new_with_options( - IotaObjectDataOptions::new() - .with_type() - .with_owner() - .with_previous_transaction(), - )), - None, - None, - ) - .await?; - let gas = objects.data.first().unwrap().object().unwrap(); - - let compiled_package = - BuildConfig::new_for_testing().build(Path::new("../../examples/move/basics"))?; - let compiled_modules_bytes = - compiled_package.get_package_base64(/* with_unpublished_deps */ false); - let dependencies = compiled_package.get_dependency_storage_package_ids(); - - let transaction_bytes: TransactionBlockBytes = http_client - .publish( - address, - compiled_modules_bytes, - dependencies, - Some(gas.object_id), - 100_000_000.into(), - ) - .await?; +mod move_tests { + use super::*; + + #[sim_test] + async fn test_publish() -> Result<(), anyhow::Error> { + let cluster = TestClusterBuilder::new().build().await; + let http_client = cluster.rpc_client(); + let address = cluster.get_address_0(); + + let objects = http_client + .get_owned_objects( + address, + Some(IotaObjectResponseQuery::new_with_options( + IotaObjectDataOptions::new() + .with_type() + .with_owner() + .with_previous_transaction(), + )), + None, + None, + ) + .await?; + let gas = objects.data.first().unwrap().object().unwrap(); + + let compiled_package = + BuildConfig::new_for_testing().build(Path::new("../../examples/move/basics"))?; + let compiled_modules_bytes = + compiled_package.get_package_base64(/* with_unpublished_deps */ false); + let dependencies = compiled_package.get_dependency_storage_package_ids(); + + let transaction_bytes: TransactionBlockBytes = http_client + .publish( + address, + compiled_modules_bytes, + dependencies, + Some(gas.object_id), + 100_000_000.into(), + ) + .await?; - let tx_response = execute_tx(&cluster, http_client, transaction_bytes) - .await - .unwrap(); + let tx_response = execute_tx(&cluster, http_client, transaction_bytes) + .await + .unwrap(); - matches!(tx_response, IotaTransactionBlockResponse {effects, ..} if effects.as_ref().unwrap().created().len() == 6); - Ok(()) + matches!(tx_response, IotaTransactionBlockResponse {effects, ..} if effects.as_ref().unwrap().created().len() == 6); + Ok(()) + } } #[sim_test] diff --git a/crates/iota-json/src/tests.rs b/crates/iota-json/src/tests.rs index 6a899b12ebd..b97880f0efa 100644 --- a/crates/iota-json/src/tests.rs +++ b/crates/iota-json/src/tests.rs @@ -423,91 +423,95 @@ fn test_basic_args_linter_pure_args_good() { } } -#[test] -fn test_basic_args_linter_top_level() { - let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../examples/move/basics"); - let compiled_modules = BuildConfig::new_for_testing() - .build(&path) - .unwrap() - .into_modules(); - let example_package = Object::new_package_for_testing( - &compiled_modules, - TransactionDigest::genesis_marker(), - BuiltInFramework::genesis_move_packages(), - ) - .unwrap(); - let package = example_package.data.try_as_package().unwrap(); - - let module = Identifier::new("resolve_args").unwrap(); - let function = Identifier::new("foo").unwrap(); - - // Function signature: - // foo( - // _foo: &mut Foo, - // _bar: vector, - // _name: vector, - // _index: u64, - // _flag: u8, - // _recipient: address, - // _ctx: &mut TxContext, - // ) - - let foo_id = ObjectID::random(); - let bar_id = ObjectID::random(); - let baz_id = ObjectID::random(); - let recipient_addr = IotaAddress::random_for_testing_only(); - - let foo = json!(foo_id.to_canonical_string(/* with_prefix */ true)); - let bar = json!([ - bar_id.to_canonical_string(/* with_prefix */ true), - baz_id.to_canonical_string(/* with_prefix */ true), - ]); - - let name = json!("Name"); - let index = json!("12345678"); - let flag = json!(89); - let recipient = json!(recipient_addr.to_string()); - - let args: Vec<_> = [ - foo.clone(), - bar.clone(), - name.clone(), - index.clone(), - flag, - recipient.clone(), - ] - .into_iter() - .map(|q| IotaJsonValue::new(q.clone()).unwrap()) - .collect(); - - let json_args: Vec<_> = - resolve_move_function_args(package, module.clone(), function.clone(), &[], args) +mod move_tests { + use super::*; + + #[test] + fn test_basic_args_linter_top_level() { + let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../examples/move/basics"); + let compiled_modules = BuildConfig::new_for_testing() + .build(&path) .unwrap() - .into_iter() - .map(|(arg, _)| arg) - .collect(); - - use ResolvedCallArg as RCA; - fn pure(t: &T) -> RCA { - RCA::Pure(bcs::to_bytes(t).unwrap()) - } - - assert_eq!(json_args, vec![ - RCA::Object(foo_id), - RCA::ObjVec(vec![bar_id, baz_id]), - pure(&"Name"), - pure(&12345678u64), - pure(&89u8), - pure(&recipient_addr), - ],); - - // Flag is u8 so too large - let args: Vec<_> = [foo, bar, name, index, json!(10000u64), recipient] + .into_modules(); + let example_package = Object::new_package_for_testing( + &compiled_modules, + TransactionDigest::genesis_marker(), + BuiltInFramework::genesis_move_packages(), + ) + .unwrap(); + let package = example_package.data.try_as_package().unwrap(); + + let module = Identifier::new("resolve_args").unwrap(); + let function = Identifier::new("foo").unwrap(); + + // Function signature: + // foo( + // _foo: &mut Foo, + // _bar: vector, + // _name: vector, + // _index: u64, + // _flag: u8, + // _recipient: address, + // _ctx: &mut TxContext, + // ) + + let foo_id = ObjectID::random(); + let bar_id = ObjectID::random(); + let baz_id = ObjectID::random(); + let recipient_addr = IotaAddress::random_for_testing_only(); + + let foo = json!(foo_id.to_canonical_string(/* with_prefix */ true)); + let bar = json!([ + bar_id.to_canonical_string(/* with_prefix */ true), + baz_id.to_canonical_string(/* with_prefix */ true), + ]); + + let name = json!("Name"); + let index = json!("12345678"); + let flag = json!(89); + let recipient = json!(recipient_addr.to_string()); + + let args: Vec<_> = [ + foo.clone(), + bar.clone(), + name.clone(), + index.clone(), + flag, + recipient.clone(), + ] .into_iter() .map(|q| IotaJsonValue::new(q.clone()).unwrap()) .collect(); - assert!(resolve_move_function_args(package, module, function, &[], args,).is_err()); + let json_args: Vec<_> = + resolve_move_function_args(package, module.clone(), function.clone(), &[], args) + .unwrap() + .into_iter() + .map(|(arg, _)| arg) + .collect(); + + use ResolvedCallArg as RCA; + fn pure(t: &T) -> RCA { + RCA::Pure(bcs::to_bytes(t).unwrap()) + } + + assert_eq!(json_args, vec![ + RCA::Object(foo_id), + RCA::ObjVec(vec![bar_id, baz_id]), + pure(&"Name"), + pure(&12345678u64), + pure(&89u8), + pure(&recipient_addr), + ],); + + // Flag is u8 so too large + let args: Vec<_> = [foo, bar, name, index, json!(10000u64), recipient] + .into_iter() + .map(|q| IotaJsonValue::new(q.clone()).unwrap()) + .collect(); + + assert!(resolve_move_function_args(package, module, function, &[], args,).is_err()); + } } #[test] diff --git a/crates/iota-rosetta/src/unit_tests/balance_changing_tx_tests.rs b/crates/iota-rosetta/src/unit_tests/balance_changing_tx_tests.rs index f6e3f1904f5..88c4cb16308 100644 --- a/crates/iota-rosetta/src/unit_tests/balance_changing_tx_tests.rs +++ b/crates/iota-rosetta/src/unit_tests/balance_changing_tx_tests.rs @@ -139,98 +139,102 @@ async fn test_transfer_object() { .await; } -#[tokio::test] -async fn test_publish_and_move_call() { - let network = TestClusterBuilder::new().build().await; - let client = network.wallet.get_client().await.unwrap(); - let keystore = network.wallet.config().keystore(); - let rgp = network.get_reference_gas_price().await; - - // Test publish - let addresses = network.get_addresses(); - let sender = get_random_address(&addresses, vec![]); - let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - path.extend(["..", "..", "examples", "move", "coin"]); - let compiled_package = BuildConfig::new_for_testing().build(&path).unwrap(); - let compiled_modules_bytes = - compiled_package.get_package_bytes(/* with_unpublished_deps */ false); - let dependencies = compiled_package.get_dependency_storage_package_ids(); +mod move_tests { + use super::*; + + #[tokio::test] + async fn test_publish_and_move_call() { + let network = TestClusterBuilder::new().build().await; + let client = network.wallet.get_client().await.unwrap(); + let keystore = network.wallet.config().keystore(); + let rgp = network.get_reference_gas_price().await; + + // Test publish + let addresses = network.get_addresses(); + let sender = get_random_address(&addresses, vec![]); + let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + path.extend(["..", "..", "examples", "move", "coin"]); + let compiled_package = BuildConfig::new_for_testing().build(&path).unwrap(); + let compiled_modules_bytes = + compiled_package.get_package_bytes(/* with_unpublished_deps */ false); + let dependencies = compiled_package.get_dependency_storage_package_ids(); + + let pt = { + let mut builder = ProgrammableTransactionBuilder::new(); + builder.publish_immutable(compiled_modules_bytes, dependencies); + builder.finish() + }; + let response = test_transaction( + &client, + keystore, + vec![], + sender, + pt, + vec![], + rgp * TEST_ONLY_GAS_UNIT_FOR_HEAVY_COMPUTATION_STORAGE, + rgp, + false, + ) + .await; + let object_changes = response.object_changes.unwrap(); - let pt = { - let mut builder = ProgrammableTransactionBuilder::new(); - builder.publish_immutable(compiled_modules_bytes, dependencies); - builder.finish() - }; - let response = test_transaction( - &client, - keystore, - vec![], - sender, - pt, - vec![], - rgp * TEST_ONLY_GAS_UNIT_FOR_HEAVY_COMPUTATION_STORAGE, - rgp, - false, - ) - .await; - let object_changes = response.object_changes.unwrap(); + // Test move call (reuse published module from above test) + let package = object_changes + .iter() + .find_map(|change| { + if let ObjectChange::Published { package_id, .. } = change { + Some(package_id) + } else { + None + } + }) + .unwrap(); - // Test move call (reuse published module from above test) - let package = object_changes - .iter() - .find_map(|change| { - if let ObjectChange::Published { package_id, .. } = change { - Some(package_id) - } else { - None + let treasury = find_module_object(&object_changes, |type_| { + if type_.name.as_str() != "TreasuryCap" { + return false; } - }) - .unwrap(); - let treasury = find_module_object(&object_changes, |type_| { - if type_.name.as_str() != "TreasuryCap" { - return false; - } + let Some(TypeTag::Struct(otw)) = type_.type_params.first() else { + return false; + }; - let Some(TypeTag::Struct(otw)) = type_.type_params.first() else { - return false; + otw.name.as_str() == "MY_COIN" + }); + + let treasury = treasury.clone().reference.to_object_ref(); + let recipient = *addresses.choose(&mut OsRng).unwrap(); + let pt = { + let mut builder = ProgrammableTransactionBuilder::new(); + builder + .move_call( + *package, + Identifier::from_str("my_coin").unwrap(), + Identifier::from_str("mint").unwrap(), + vec![], + vec![ + CallArg::Object(ObjectArg::ImmOrOwnedObject(treasury)), + CallArg::Pure(bcs::to_bytes(&10000u64).unwrap()), + CallArg::Pure(bcs::to_bytes(&recipient).unwrap()), + ], + ) + .unwrap(); + builder.finish() }; - otw.name.as_str() == "MY_COIN" - }); - - let treasury = treasury.clone().reference.to_object_ref(); - let recipient = *addresses.choose(&mut OsRng).unwrap(); - let pt = { - let mut builder = ProgrammableTransactionBuilder::new(); - builder - .move_call( - *package, - Identifier::from_str("my_coin").unwrap(), - Identifier::from_str("mint").unwrap(), - vec![], - vec![ - CallArg::Object(ObjectArg::ImmOrOwnedObject(treasury)), - CallArg::Pure(bcs::to_bytes(&10000u64).unwrap()), - CallArg::Pure(bcs::to_bytes(&recipient).unwrap()), - ], - ) - .unwrap(); - builder.finish() - }; - - test_transaction( - &client, - keystore, - vec![], - sender, - pt, - vec![], - rgp * TEST_ONLY_GAS_UNIT_FOR_GENERIC, - rgp, - false, - ) - .await; + test_transaction( + &client, + keystore, + vec![], + sender, + pt, + vec![], + rgp * TEST_ONLY_GAS_UNIT_FOR_GENERIC, + rgp, + false, + ) + .await; + } } #[tokio::test]