|
| 1 | +#[cfg(test)] |
| 2 | +pub mod test { |
| 3 | + |
| 4 | + use anyhow::Context; |
| 5 | + use mtma_node_test_types::criterion::movement_executor::maptos_opt_executor::aptos_types::account_address::AccountAddress; |
| 6 | + use mtma_migrator_pre_l1_merge_core::config::Config as PreL1MergeConfig; |
| 7 | + use mtma_migrator_test_accounts_equal_criterion::AccountsEqual; |
| 8 | + use mtma_migrator_test_types::check::checked_migration; |
| 9 | + use mtma_migrator_types::migrator::{movement_migrator::{Overlays, MovementMigrator, Runner}}; |
| 10 | + use mtma_node_test_types::prelude::Prelude; |
| 11 | + use std::str::FromStr; |
| 12 | + use tracing::info; |
| 13 | + use movement_core::Movement; |
| 14 | + use mtma_types::movement::movement_config::Config as MovementConfig; |
| 15 | + use hex; |
| 16 | + use mtma_types::movement::aptos_sdk::types::account_config::aptos_test_root_address; |
| 17 | + |
| 18 | + #[tokio::test(flavor = "multi_thread")] |
| 19 | + #[tracing_test::traced_test] |
| 20 | + async fn test_accounts_equal() -> Result<(), anyhow::Error> { |
| 21 | + // use a scope to ensure everything is dropped |
| 22 | + { |
| 23 | + // Create a MovementConfig with the correct port |
| 24 | + let mut movement_config = MovementConfig::default(); |
| 25 | + movement_config |
| 26 | + .execution_config |
| 27 | + .maptos_config |
| 28 | + .client |
| 29 | + .maptos_rest_connection_port = 30731; |
| 30 | + |
| 31 | + // Get the account address from the same MovementConfig |
| 32 | + let account_address = aptos_test_root_address(); |
| 33 | + |
| 34 | + // Create a Movement instance with the config |
| 35 | + let movement = Movement::new( |
| 36 | + movement_config.clone(), |
| 37 | + movement_core::MovementWorkspace::try_temp()?, |
| 38 | + Overlays::default(), |
| 39 | + true, |
| 40 | + true, |
| 41 | + ); |
| 42 | + |
| 43 | + // Form the migrator with the configured Movement instance |
| 44 | + let mut movement_migrator = MovementMigrator::new(Runner::Movement(movement)); |
| 45 | + |
| 46 | + // Start the migrator so that it's running in the background. |
| 47 | + // In the future, some migrators may be for already running nodes. |
| 48 | + let movement_migrator_for_task = movement_migrator.clone(); |
| 49 | + let movement_migrator_task = kestrel::task(async move { |
| 50 | + movement_migrator_for_task.run().await?; |
| 51 | + Ok::<_, anyhow::Error>(()) |
| 52 | + }); |
| 53 | + |
| 54 | + // Wait for the Celestia light node to be ready |
| 55 | + tokio::time::sleep(tokio::time::Duration::from_secs(5)).await; |
| 56 | + |
| 57 | + // wait for the rest client to be ready |
| 58 | + info!("Waiting for REST client to be ready (timeout: 600s)"); |
| 59 | + let mut rest_api_url = movement_migrator |
| 60 | + .wait_for_rest_api_url(tokio::time::Duration::from_secs(600)) |
| 61 | + .await?; |
| 62 | + info!("REST API URL: {}", rest_api_url); |
| 63 | + |
| 64 | + movement_migrator |
| 65 | + .wait_for_rest_client_ready(tokio::time::Duration::from_secs(600)) |
| 66 | + .await |
| 67 | + .context( |
| 68 | + "failed to wait for movement migrator rest client while running accounts equal manual prelude", |
| 69 | + )?; |
| 70 | + info!("REST client is ready"); |
| 71 | + |
| 72 | + // Wait for the account to be created |
| 73 | + info!("Getting REST client for account check (timeout: 30s)"); |
| 74 | + let rest_client = movement_migrator |
| 75 | + .wait_for_rest_client_ready(tokio::time::Duration::from_secs(30)) |
| 76 | + .await |
| 77 | + .context("failed to get rest client")?; |
| 78 | + info!("Checking for account existence, address: {}", account_address); |
| 79 | + match rest_client.get_account(account_address).await { |
| 80 | + Ok(_) => { |
| 81 | + info!("Account found"); |
| 82 | + } |
| 83 | + Err(e) => { |
| 84 | + info!("Account not found: {:?}", e); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + // Form the prelude. |
| 89 | + info!("Creating empty prelude"); |
| 90 | + let prelude = Prelude::new_empty(); |
| 91 | + |
| 92 | + // Form the migration. |
| 93 | + let mut migration_config = PreL1MergeConfig::default(); |
| 94 | + migration_config.account_address = Some(account_address); |
| 95 | + let migration = migration_config.build()?; |
| 96 | + |
| 97 | + // Run the checked migration (skipping the accounts equal check). |
| 98 | + info!("Running migration"); |
| 99 | + match checked_migration( |
| 100 | + &mut movement_migrator, |
| 101 | + &prelude, |
| 102 | + &migration, |
| 103 | + Vec::<AccountsEqual>::new(), |
| 104 | + ) |
| 105 | + .await |
| 106 | + { |
| 107 | + Ok(()) => {} |
| 108 | + Err(e) => { |
| 109 | + info!("Migration failed: {:?}", e); |
| 110 | + return Err(anyhow::anyhow!("Migration failed: {:?}", e)); |
| 111 | + } |
| 112 | + } |
| 113 | + info!("Migration succeeded"); |
| 114 | + |
| 115 | + // Let the task run in the background and let the Drop implementation handle the shutdown |
| 116 | + drop(movement_migrator_task); |
| 117 | + } |
| 118 | + |
| 119 | + // exit the test is fine when you only have one test per crate because when cargo test is run across a workspace, it actually multi-processes the tests by crate |
| 120 | + std::process::exit(0); |
| 121 | + |
| 122 | + Ok(()) |
| 123 | + } |
| 124 | +} |
0 commit comments