Skip to content

Commit f6ed894

Browse files
committed
feat: testing environment.
1 parent b36f125 commit f6ed894

File tree

22 files changed

+171
-573
lines changed

22 files changed

+171
-573
lines changed

Cargo.lock

Lines changed: 6 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ movement-aptos-core = { path = "util/movement-aptos/core" }
216216
movement-aptos-core-util = { path = "util/movement-aptos/core-util" }
217217
mtma-types = { path = "util/types" }
218218

219+
## Environments
220+
### util
221+
mtma-environment-types = { path = "environments/util/types" }
222+
### core
223+
mtma-testing-environment = { path = "environments/core/testing" }
224+
mtma-provisioner-environment = { path = "environments/core/provisioner" }
225+
mtma-box-environment = { path = "environments/box/provisioner" }
226+
219227
[workspace.lints.clippy]
220228
debug_assert_with_mut_call = "deny"
221229
inefficient_to_string = "deny"

environments/core/testing/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ movement-signer-loader = { workspace = true }
3535
hex = { workspace = true }
3636
mtma-types = { workspace = true }
3737
movement-core = { workspace = true }
38+
mtma-environment-types = { workspace = true }
39+
kestrel = { workspace = true }
3840

3941
[lints]
4042
workspace = true
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// Contains the configuration structs and logic for the migration.
22
pub mod config;
33
/// Contains the logic for the migration.
4-
pub mod migrate;
4+
pub mod environment;
55

66
pub use config::*;
7-
pub use migrate::*;
7+
pub use environment::*;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use crate::TestingEnvironment;
2+
use clap::Parser;
3+
use serde::{Deserialize, Serialize};
4+
use std::fmt::Debug;
5+
6+
/// Errors thrown when working with the [Config].
7+
#[derive(Debug, thiserror::Error)]
8+
pub enum EnvironmentConfigError {
9+
#[error("failed to build from config: {0}")]
10+
Build(#[source] Box<dyn std::error::Error + Send + Sync>),
11+
}
12+
13+
/// The config for the [TestingEnvironment].
14+
///
15+
/// All fields should be easily statically encodable to a CLI argument.
16+
/// This is the frontend for the core API.
17+
#[derive(Parser, Debug, Serialize, Deserialize, Clone, Default)]
18+
#[clap(help_expected = true)]
19+
pub struct Config {}
20+
21+
impl Config {
22+
/// Builds the [TestingEnvironment] struct from the config.
23+
///
24+
/// Note: preserving faillibility here because we may add debug path configuration to the [TestingEnvironment] soon.
25+
pub fn build(&self) -> Result<TestingEnvironment, EnvironmentConfigError> {
26+
Ok(TestingEnvironment::new())
27+
}
28+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
use anyhow::Context;
2+
use movement_core::Overlays;
3+
use mtma_environment_types::{EnvironmentError, Environmentish};
4+
use mtma_migrator_types::migrator::MovementMigrator;
5+
use std::fmt::Debug;
6+
7+
/// Errors thrown when using the [TestingEnvironment].
8+
#[derive(Debug, thiserror::Error)]
9+
pub enum TestingEnvironmentError {
10+
#[error("Testing Environment: failed with an internal error: {0}")]
11+
Internal(#[source] Box<dyn std::error::Error + Send + Sync>),
12+
}
13+
14+
impl From<TestingEnvironmentError> for EnvironmentError {
15+
fn from(e: TestingEnvironmentError) -> Self {
16+
EnvironmentError::Internal(e.into())
17+
}
18+
}
19+
20+
pub struct TestingEnvironment {}
21+
22+
impl TestingEnvironment {
23+
pub fn new() -> Self {
24+
Self {}
25+
}
26+
}
27+
28+
impl Environmentish for TestingEnvironment {
29+
async fn build_movement_migrator(&self) -> Result<MovementMigrator, EnvironmentError> {
30+
// Form the migrator.
31+
let mut movement_migrator = MovementMigrator::try_temp()
32+
.map_err(|e| TestingEnvironmentError::Internal(e.into()))?;
33+
movement_migrator.set_overlays(Overlays::default());
34+
35+
// Start the migrator so that it's running in the background.
36+
// In the future, some migrators may be for already running nodes.
37+
let movement_migrator_for_task = movement_migrator.clone();
38+
let movement_migrator_task = kestrel::task(async move {
39+
movement_migrator_for_task.run().await?;
40+
Ok::<_, anyhow::Error>(())
41+
});
42+
43+
// wait for the rest client to be ready
44+
// once we have this, there should also be a config, so we can then kill off the migrator and proceed
45+
movement_migrator
46+
.wait_for_rest_client_ready(tokio::time::Duration::from_secs(600)) // we wait for up to ten minutes because the nix flake in .vendors/movementcan be a bit slow the first time
47+
.await
48+
.context(
49+
"failed to wait for movement migrator rest client while running accounts equal manual prelude",
50+
).map_err(|e| TestingEnvironmentError::Internal(e.into()))?;
51+
52+
kestrel::end!(movement_migrator_task)
53+
.context("failed to end movement migrator task")
54+
.map_err(|e| TestingEnvironmentError::Internal(e.into()))?;
55+
56+
Ok(movement_migrator)
57+
}
58+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
pub mod migrate;
2-
pub use migrate::*;
1+
pub mod environment;
2+
pub use environment::*;

environments/core/testing/src/migrate/config.rs

Lines changed: 0 additions & 103 deletions
This file was deleted.

environments/core/testing/src/migrate/migrate.rs

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)