Skip to content

Commit

Permalink
feat: create structure for cli e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmovses committed Feb 4, 2025
1 parent 57e2c90 commit d287042
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 1 deletion.
4 changes: 4 additions & 0 deletions networks/movement/movement-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ path = "src/bin/e2e/whitelist.rs"
name = "movement-tests-e2e-ggp-gas-fee"
path = "src/bin/e2e/ggp_gas_fee.rs"

[[bin]]
name = "movement-tests-e2e-admin-cli"
path = "src/bin/e2e/admin_cli.rs"


[dependencies]
aptos-sdk = { workspace = true }
Expand Down
124 changes: 124 additions & 0 deletions networks/movement/movement-client/src/bin/e2e/admin_cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
use anyhow::Context;
use aptos_sdk::{
coin_client::CoinClient,
crypto::{SigningKey, ValidCryptoMaterialStringExt},
move_types::{
identifier::Identifier,
language_storage::{ModuleId, TypeTag},
},
rest_client::{Client, FaucetClient, Transaction},
transaction_builder::TransactionFactory,
types::{account_address::AccountAddress, transaction::TransactionPayload},
};
use aptos_types::{
account_config::{RotationProofChallenge, CORE_CODE_ADDRESS},
chain_id::ChainId,
transaction::EntryFunction,
};
use movement_client::types::LocalAccount;
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use std::str::FromStr;
//use tokio::process::Command;
use tracing::info;
use tracing_subscriber::EnvFilter;
use url::Url;

static SUZUKA_CONFIG: Lazy<movement_config::Config> = Lazy::new(|| {
let dot_movement = dot_movement::DotMovement::try_from_env().unwrap();
dot_movement.try_get_config_from_json::<movement_config::Config>().unwrap()
});

static NODE_URL: Lazy<Url> = Lazy::new(|| {
let node_connection_address = SUZUKA_CONFIG
.execution_config
.maptos_config
.client
.maptos_rest_connection_hostname
.clone();
let node_connection_port =
SUZUKA_CONFIG.execution_config.maptos_config.client.maptos_rest_connection_port;
let node_connection_url =
format!("http://{}:{}", node_connection_address, node_connection_port);
Url::from_str(&node_connection_url).unwrap()
});

static FAUCET_URL: Lazy<Url> = Lazy::new(|| {
let faucet_listen_address = SUZUKA_CONFIG
.execution_config
.maptos_config
.client
.maptos_faucet_rest_connection_hostname
.clone();
let faucet_listen_port = SUZUKA_CONFIG
.execution_config
.maptos_config
.client
.maptos_faucet_rest_connection_port;

let faucet_listen_url = format!("http://{}:{}", faucet_listen_address, faucet_listen_port);

Url::from_str(faucet_listen_url.as_str()).unwrap()
});

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
)
.init();

// Initialize clients
let rest_client = Client::new(NODE_URL.clone());
let faucet_client = FaucetClient::new(FAUCET_URL.clone(), NODE_URL.clone());
let coin_client = CoinClient::new(&rest_client);

// Load core resource account
let mut core_resources_account = LocalAccount::from_private_key(
SUZUKA_CONFIG
.execution_config
.maptos_config
.chain
.maptos_private_key
.to_encoded_string()?
.as_str(),
0,
)?;
info!(
"Core Resources Account keypairs: {:?}, {:?}",
core_resources_account.private_key(),
core_resources_account.public_key()
);
info!("Core Resources Account address: {}", core_resources_account.address());

// Fund the account
faucet_client.fund(core_resources_account.address(), 100_000_000_000).await?;

let state = rest_client
.get_ledger_information()
.await
.context("Failed in getting chain id")?
.into_inner();

// Generate recipient account
let recipient = LocalAccount::generate(&mut rand::rngs::OsRng);

faucet_client.fund(recipient.address(), 100_000_000_000).await?;

let recipient_bal = coin_client
.get_account_balance(&recipient.address())
.await
.context("Failed to get recipient's account balance")?;

let core_resource_bal = coin_client
.get_account_balance(&core_resources_account.address())
.await
.context("Failed to get core resources account balance")?;

info!("Recipient's balance: {:?}", recipient_bal);
info!("Core Resources Account balance: {:?}", core_resource_bal);

Ok(())
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ processes:

setup:
environment:
- APTOS_ACCOUNT_WHITELIST=$DOT_MOVEMENT_PATH/default_signer_address_whitelist
- MAPTOS_PRIVATE_KEY=random

movement-faucet:
Expand All @@ -15,6 +14,7 @@ processes:
test-admin-cli:
command: |
## The Cli command that an admin would run recipient is 0xdead address
movement account fund-with-faucet && \
cargo run -p movement-full-node admin ops mint-to --movement-path ".movement/" -a 42 -r "000000000000000000000000000000000000000000000000000000000000dead"
depends_on:
movement-full-node:
Expand Down

0 comments on commit d287042

Please sign in to comment.