Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 44 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ mtma-migrator-test-matching-feature-flags-criterion = { path = "checks/migrator/
mtma-migrator-test-transacting-criterion = { path = "checks/migrator/citeria/transacting" }
mtma-migrator-test-accounts-equal-criterion = { path = "checks/migrator/citeria/accounts-equal" }
mtma-migrator-test-balances-equal-criterion = { path = "checks/migrator/citeria/balances-equal" }
mtma-migrator-test-governance-criterion = { path = "checks/migrator/citeria/governance" }

## util
bcs-ext = { path = "util/bcs-ext" }
Expand Down
26 changes: 26 additions & 0 deletions checks/migrator/checks/governance/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "mtma-migrator-governance"
version = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
authors = { workspace = true }
homepage = { workspace = true }
publish = { workspace = true }
rust-version = { workspace = true }

[dependencies]
mtma-migrator-types = { workspace = true }
mtma-migrator-test-types = { workspace = true }
anyhow = { workspace = true }
mtma-migrator-test-governance-criterion = { workspace = true }
mtma-node-null-core = { workspace = true }
tokio = { workspace = true }
kestrel = { workspace = true }
mtma-node-test-types = { workspace = true }

[dev-dependencies]
tracing-test = { workspace = true }
tracing = { workspace = true }

[lints]
workspace = true
2 changes: 2 additions & 0 deletions checks/migrator/checks/governance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Migration Executor Checks Sketchpad
A sketchpad for playing around with checks on the testpad.
45 changes: 45 additions & 0 deletions checks/migrator/checks/governance/src/governance.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#[cfg(test)]
pub mod test {
use mtma_migrator_test_governance_criterion::GovernanceCheck;
use mtma_migrator_test_types::check::checked_migration;
use mtma_migrator_types::migrator::{movement_migrator::Overlays, MovementMigrator};
use mtma_node_null_core::config::Config as MtmaNullConfig;
use mtma_node_test_types::prelude::Prelude;

#[tokio::test]
#[tracing_test::traced_test]
#[ignore = "activate when runtime problems are solved"]
async fn test_governance() -> Result<(), anyhow::Error> {
// Form the migrator.
let mut movement_migrator = MovementMigrator::try_temp()?;
// TODO: use `MovementMigrator::try_debug_home()`
// let mut movement_migrator = MovementMigrator::try_debug_home()?;
movement_migrator.set_overlays(Overlays::default());

// Start the migrator so that it's running in the background.
// In the future, some migrators may be for already running nodes.
let movement_migrator_for_task = movement_migrator.clone();
let movement_migrator_task = kestrel::task(async move {
movement_migrator_for_task.run().await?;
Ok::<_, anyhow::Error>(())
});

tokio::time::sleep(tokio::time::Duration::from_secs(30)).await;

kestrel::end!(movement_migrator_task)?;

// Form the prelude.
// todo: this needs to be updated to use the prelude generator
let prelude = Prelude::new_empty();

// Form the migration.
let migration_config = MtmaNullConfig::default();
let migration = migration_config.build()?;

// Run the checked migration.
let governance = GovernanceCheck::new();
checked_migration(&mut movement_migrator, &prelude, &migration, vec![governance]).await?;

Ok(())
}
}
1 change: 1 addition & 0 deletions checks/migrator/checks/governance/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod governance;
21 changes: 21 additions & 0 deletions checks/migrator/citeria/governance/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "mtma-migrator-test-governance-criterion"
version = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
authors = { workspace = true }
homepage = { workspace = true }
publish = { workspace = true }
rust-version = { workspace = true }

[dependencies]
anyhow = { workspace = true }
aptos-rest-client = { workspace = true }
movement-client = { workspace = true }
mtma-migrator-test-types = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }

[lints]
workspace = true
75 changes: 75 additions & 0 deletions checks/migrator/citeria/governance/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use aptos_rest_client::aptos_api_types;
use mtma_migrator_test_types::criterion::{
Criterion, CriterionError, Criterionish, MovementAptosMigrator, MovementMigrator,
};
use std::str::FromStr;

pub struct GovernanceCheck;

impl GovernanceCheck {
pub fn new() -> Self {
Self {}
}

pub fn criterion() -> Criterion<Self> {
Criterion::new(Self {})
}
}

impl Criterionish for GovernanceCheck {
async fn satisfies(
&self,
_movement_migrator: &MovementMigrator,
movement_aptos_migrator: &MovementAptosMigrator,
) -> Result<(), CriterionError> {
let movement_aptos_rest_client = movement_aptos_migrator
.wait_for_rest_client_ready(tokio::time::Duration::from_secs(30))
.await
.map_err(|e| CriterionError::Internal(e.into()))?;

let request = aptos_api_types::ViewRequest {
function: aptos_api_types::EntryFunctionId::from_str(
"0x1::aptos_governance::get_required_proposer_stake",
)
.map_err(|e| CriterionError::Internal(e.into()))?,
type_arguments: vec![],
arguments: vec![],
};

let required_proposer_stake = movement_aptos_rest_client
.view(&request, None)
.await
.map_err(|e| {
CriterionError::Internal(
format!(
"failed to get Aptos required proposer state (request failed): {:?}",
e
)
.into(),
)
})?
.into_inner();

let required_proposer_stake = required_proposer_stake.get(0).ok_or_else(|| {
CriterionError::Internal(
"failed to get Aptos required proposer state: response is empty"
.to_string()
.into(),
)
})?;

let required_proposer_stake = required_proposer_stake.as_u64().ok_or_else(|| {
CriterionError::Internal(
format!(
"failed to get Aptos required proposer state: can't convert {:?} into an u64",
required_proposer_stake
)
.into(),
)
})?;

assert!(required_proposer_stake > 0);

Ok(())
}
}
Loading