Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic integration test #34

Merged
merged 10 commits into from
Feb 17, 2025
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;
}
Comment on lines +275 to 278
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider adding error handling and logging for failed transactions.

The current implementation only tracks successful transactions but doesn't handle or log failed transactions, which could make debugging issues more difficult.

Consider modifying the TransactionProcessed handler to track both successful and failed transactions:

-    SimnetEvent::TransactionProcessed(_dt, _meta, _err) => {
-        app.successful_transactions += 1;
-    }
+    SimnetEvent::TransactionProcessed(dt, meta, err) => {
+        if err.is_none() {
+            app.successful_transactions += 1;
+        } else {
+            app.events.push_front((
+                EventType::Failure,
+                dt,
+                format!("Transaction failed: {:?}", err),
+            ));
+        }
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
SimnetEvent::TransactionReceived(_dt, _transaction) => {}
SimnetEvent::TransactionProcessed(_dt, _meta, _err) => {
app.successful_transactions += 1;
}
SimnetEvent::TransactionReceived(_dt, _transaction) => {}
SimnetEvent::TransactionProcessed(dt, meta, err) => {
if err.is_none() {
app.successful_transactions += 1;
} else {
app.events.push_front((
EventType::Failure,
dt,
format!("Transaction failed: {:?}", err),
));
}
}

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 @@ -28,6 +28,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: 2 additions & 14 deletions crates/core/src/rpc/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,20 +617,8 @@ impl Full for SurfpoolFullRpc {
meta: Self::Metadata,
_config: Option<RpcContextConfig>,
) -> Result<RpcResponse<RpcBlockhash>> {
// Retrieve svm state
let Some(ctx) = meta else {
return Err(RpcCustomError::NodeUnhealthy {
num_slots_behind: None,
}
.into());
};
// Lock read access
let Ok(state_reader) = ctx.state.read() else {
return Err(RpcCustomError::NodeUnhealthy {
num_slots_behind: None,
}
.into());
};
let state_reader = meta.get_state()?;

// Todo: are we returning the right block height?
let last_valid_block_height = state_reader.epoch_info.block_height;
let value = RpcBlockhash {
Expand Down
16 changes: 13 additions & 3 deletions crates/core/src/simnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,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 @@ -329,7 +334,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 @@ -542,11 +547,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