-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CLI] Restructure local testnet code
- Loading branch information
Showing
10 changed files
with
522 additions
and
288 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use super::{health_checker::HealthChecker, traits::ServiceManager, RunLocalTestnet}; | ||
use anyhow::Result; | ||
use aptos_faucet_core::server::{FunderKeyEnum, RunConfig}; | ||
use async_trait::async_trait; | ||
use clap::Parser; | ||
use reqwest::Url; | ||
use std::path::PathBuf; | ||
|
||
/// Args related to running a faucet in the local testnet. | ||
#[derive(Debug, Parser)] | ||
pub struct FaucetArgs { | ||
/// Do not run a faucet alongside the node. | ||
/// | ||
/// Running a faucet alongside the node allows you to create and fund accounts | ||
/// for testing. | ||
#[clap(long)] | ||
pub no_faucet: bool, | ||
|
||
/// This does nothing, we already run a faucet by default. We only keep this here | ||
/// for backwards compatibility with tests. We will remove this once the commit | ||
/// that added --no-faucet makes its way to the testnet branch. | ||
#[clap(long, hide = true)] | ||
pub with_faucet: bool, | ||
|
||
/// Port to run the faucet on. | ||
/// | ||
/// When running, you'll be able to use the faucet at `http://127.0.0.1:<port>/mint` e.g. | ||
/// `http//127.0.0.1:8081/mint` | ||
#[clap(long, default_value_t = 8081)] | ||
pub faucet_port: u16, | ||
|
||
/// Disable the delegation of faucet minting to a dedicated account. | ||
#[clap(long)] | ||
pub do_not_delegate: bool, | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct FaucetManager { | ||
config: RunConfig, | ||
prerequisite_health_checkers: Vec<HealthChecker>, | ||
} | ||
|
||
impl FaucetManager { | ||
pub fn new( | ||
args: &RunLocalTestnet, | ||
prerequisite_health_checkers: Vec<HealthChecker>, | ||
test_dir: PathBuf, | ||
node_api_url: Url, | ||
) -> Result<Self> { | ||
Ok(Self { | ||
config: RunConfig::build_for_cli( | ||
node_api_url.clone(), | ||
args.faucet_args.faucet_port, | ||
FunderKeyEnum::KeyFile(test_dir.join("mint.key")), | ||
args.faucet_args.do_not_delegate, | ||
None, | ||
), | ||
prerequisite_health_checkers, | ||
}) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl ServiceManager for FaucetManager { | ||
fn get_name(&self) -> String { | ||
"Faucet".to_string() | ||
} | ||
|
||
fn get_healthchecks(&self) -> Vec<HealthChecker> { | ||
vec![HealthChecker::http_checker_from_port( | ||
self.config.server_config.listen_port, | ||
self.get_name(), | ||
)] | ||
} | ||
|
||
fn get_prerequisite_health_checkers(&self) -> Vec<&HealthChecker> { | ||
self.prerequisite_health_checkers.iter().collect() | ||
} | ||
|
||
async fn run_service(self: Box<Self>) -> Result<()> { | ||
self.config.run().await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.