Skip to main content

mintv2_module_tests/
tests.rs

1use anyhow::ensure;
2use clap::Parser;
3use devimint::cmd;
4use devimint::devfed::DevJitFed;
5use devimint::federation::Client;
6use fedimint_core::envs::{FM_ENABLE_MODULE_MINT_ENV, FM_ENABLE_MODULE_MINTV2_ENV};
7use fedimint_mintv2_client::FinalReceiveOperationState;
8use tracing::info;
9
10#[derive(Parser)]
11#[command(name = "mintv2-module-tests")]
12#[command(about = "MintV2 module integration tests", long_about = None)]
13struct Cli {}
14
15#[tokio::main]
16async fn main() -> anyhow::Result<()> {
17    let _cli = Cli::parse();
18
19    // Enable MintV2 module and disable MintV1 for these tests
20    unsafe { std::env::set_var(FM_ENABLE_MODULE_MINTV2_ENV, "true") };
21    unsafe { std::env::set_var(FM_ENABLE_MODULE_MINT_ENV, "false") };
22
23    devimint::run_devfed_test()
24        .call(|dev_fed, _process_mgr| async move { test_mintv2(&dev_fed).await })
25        .await
26}
27
28async fn module_is_present(client: &Client, kind: &str) -> anyhow::Result<bool> {
29    let modules = cmd!(client, "module").out_json().await?;
30
31    let modules = modules["list"].as_array().expect("module list is an array");
32
33    Ok(modules.iter().any(|m| m["kind"].as_str() == Some(kind)))
34}
35
36async fn test_mintv2(dev_fed: &DevJitFed) -> anyhow::Result<()> {
37    let federation = dev_fed.fed().await?;
38
39    let client = federation.new_joined_client("mintv2-test-client").await?;
40
41    info!("Verify that mint is not present and mintv2 is present...");
42
43    ensure!(
44        !module_is_present(&client, "mint").await?,
45        "mint module should not be present"
46    );
47
48    ensure!(
49        module_is_present(&client, "mintv2").await?,
50        "mintv2 module should be present"
51    );
52
53    info!("Testing peg-in...");
54
55    federation.pegin_client(10_000, &client).await?;
56
57    info!("Testing ecash send...");
58
59    let ecash = cmd!(client, "module", "mintv2", "send", "1000000")
60        .out_json()
61        .await?
62        .as_str()
63        .expect("ecash should be a string")
64        .to_string();
65
66    info!("Testing ecash receive...");
67
68    let value = cmd!(client, "module", "mintv2", "receive", ecash)
69        .out_json()
70        .await?;
71
72    assert_eq!(
73        FinalReceiveOperationState::Success,
74        serde_json::from_value(value)?,
75        "Receive operation should succeed"
76    );
77
78    info!("MintV2 module tests complete!");
79
80    Ok(())
81}