Skip to content

Commit

Permalink
feat: testing infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
Dodecahedr0x authored Feb 17, 2025
1 parent 6f189c5 commit 49be1f2
Show file tree
Hide file tree
Showing 10 changed files with 300 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct Opts {
#[derive(Subcommand, PartialEq, Clone, Debug)]
enum Command {
/// Start Simnet
#[clap(name = "run", bin_name = "run", aliases = &["run", "start", "simnet"])]
#[clap(name = "run", bin_name = "run", aliases = &["start", "simnet"])]
Simnet(StartSimnet),
/// Generate shell completions scripts
#[clap(name = "completions", bin_name = "completions", aliases = &["completion"])]
Expand All @@ -74,7 +74,7 @@ pub struct StartSimnet {
#[arg(long = "port", short = 'p', default_value = DEFAULT_SIMNET_PORT)]
pub simnet_port: u16,
/// Set the Simnet host address
#[arg(long = "host", short = 'h', default_value = DEFAULT_NETWORK_HOST)]
#[arg(long = "host", short = 'o', default_value = DEFAULT_NETWORK_HOST)]
pub network_host: String,
/// Set the slot time
#[arg(long = "slot-time", short = 's', default_value = DEFAULT_SLOT_TIME_MS)]
Expand Down
8 changes: 8 additions & 0 deletions crates/cli/src/cli/simnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ fn log_events(
);
}
}
SimnetEvent::TransactionProcessed(_dt, _meta, _err) => {
if deployment_completed {
info!(
ctx.expect_logger(),
"Transaction processed {}", _meta.signature
);
}
}
SimnetEvent::BlockHashExpired => {}
SimnetEvent::Aborted(error) => {
error!(ctx.expect_logger(), "{}", error);
Expand Down
3 changes: 2 additions & 1 deletion crates/cli/src/tui/simnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
SimnetEvent::WarnLog(dt, log) => {
app.events.push_front((EventType::Warning, dt, log));
}
SimnetEvent::TransactionReceived(_dt, _transaction) => {
SimnetEvent::TransactionReceived(_dt, _transaction) => {}
SimnetEvent::TransactionProcessed(_dt, _meta, _err) => {
app.successful_transactions += 1;
}
SimnetEvent::BlockHashExpired => {}
Expand Down
2 changes: 1 addition & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ hiro-system-kit = { version = "0.3.4" }
chrono = "0.4"
jsonrpc-core = "18.0.0"
jsonrpc-derive = "18.0.0"
jsonrpc-core-client = "18.0.0"
jsonrpc-core-client = { version = "18.0.0", features = ["http"] }
jsonrpc-http-server = "18.0.0"
libc = "0.2.169"
regex = "1.11.1"
Expand Down
3 changes: 1 addition & 2 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ pub async fn start_simnet(
simnet_events_tx: Sender<SimnetEvent>,
simnet_commands_rx: Receiver<SimnetCommand>,
) -> Result<(), Box<dyn std::error::Error>> {
simnet::start(config, simnet_events_tx, simnet_commands_rx).await?;
Ok(())
simnet::start(config, simnet_events_tx, simnet_commands_rx).await
}
16 changes: 13 additions & 3 deletions crates/core/src/simnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ pub enum SimnetEvent {
WarnLog(DateTime<Local>, String),
DebugLog(DateTime<Local>, String),
TransactionReceived(DateTime<Local>, VersionedTransaction),
TransactionProcessed(
DateTime<Local>,
TransactionMetadata,
Option<TransactionError>,
),
AccountUpdate(DateTime<Local>, Pubkey),
}

Expand Down Expand Up @@ -330,7 +335,7 @@ pub async fn start(

let plugin_name = result["name"].as_str().map(|s| s.to_owned());

let config_file = geyser_plugin_config_file
let _config_file = geyser_plugin_config_file
.as_os_str()
.to_str()
.ok_or(GeyserPluginManagerError::InvalidPluginPath)?;
Expand Down Expand Up @@ -543,11 +548,16 @@ pub async fn start(
EntryStatus::Processed(TransactionWithStatusMeta(
slot,
transaction.clone(),
meta,
err,
meta.clone(),
err.clone(),
)),
);
let _ = status_tx.try_send(TransactionConfirmationStatus::Processed);
let _ = simnet_events_tx.try_send(SimnetEvent::TransactionProcessed(
Local::now(),
meta,
err,
));
transactions_processed.push((key, transaction, status_tx));
num_transactions += 1;
}
Expand Down
27 changes: 25 additions & 2 deletions crates/core/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use solana_sdk::pubkey::Pubkey;
use std::path::PathBuf;

#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq, Default)]
pub enum RunloopTriggerMode {
#[default]
Clock,
Manual,
Transaction,
}

#[derive(Debug)]
#[derive(Clone, Debug, Default)]
pub struct SurfpoolConfig {
pub simnet: SimnetConfig,
pub rpc: RpcConfig,
Expand All @@ -24,6 +25,18 @@ pub struct SimnetConfig {
pub airdrop_token_amount: u64,
}

impl Default for SimnetConfig {
fn default() -> Self {
Self {
remote_rpc_url: "https://api.mainnet-beta.solana.com".to_string(),
slot_time: 0,
runloop_trigger_mode: RunloopTriggerMode::Clock,
airdrop_addresses: vec![],
airdrop_token_amount: 0,
}
}
}

#[derive(Clone, Debug)]
pub struct RpcConfig {
pub bind_host: String,
Expand All @@ -36,3 +49,13 @@ impl RpcConfig {
format!("{}:{}", self.bind_host, self.bind_port)
}
}

impl Default for RpcConfig {
fn default() -> Self {
Self {
remote_rpc_url: "https://api.mainnet-beta.solana.com".to_string(),
bind_host: "127.0.0.1".to_string(),
bind_port: 8899,
}
}
}
12 changes: 12 additions & 0 deletions crates/core/tests/helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use std::net::TcpListener;

pub fn get_free_port() -> Result<u16, String> {
let listener =
TcpListener::bind("127.0.0.1:0").map_err(|e| format!("Failed to bind to port 0: {}", e))?;
let port = listener
.local_addr()
.map_err(|e| format!("failed to parse address: {}", e))?
.port();
drop(listener);
Ok(port)
}
Loading

0 comments on commit 49be1f2

Please sign in to comment.