Skip to content

Commit 9a7cfd5

Browse files
cli: Test command deploys programs on localnet when skipping validator launch (otter-sec#324)
1 parent 0d8d94f commit 9a7cfd5

1 file changed

Lines changed: 25 additions & 22 deletions

File tree

cli/src/main.rs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -957,29 +957,32 @@ fn test(
957957
file: Option<String>,
958958
) -> Result<()> {
959959
with_workspace(cfg_override, |cfg, _path, _cargo| {
960-
// Bootup validator, if needed.
961-
let validator_handle = match cfg.provider.cluster.url() {
962-
"http://127.0.0.1:8899" => {
963-
if !skip_build {
964-
build(cfg_override, None, false)?;
965-
}
966-
let flags = match skip_deploy {
967-
true => None,
968-
false => Some(genesis_flags(cfg)?),
969-
};
970-
match skip_local_validator {
971-
true => None,
972-
false => Some(start_test_validator(cfg, flags)?),
973-
}
974-
}
975-
_ => {
976-
if !skip_deploy {
977-
build(cfg_override, None, false)?;
978-
deploy(cfg_override, None)?;
979-
}
980-
None
960+
// Build if needed.
961+
if !skip_build {
962+
build(cfg_override, None, false)?;
963+
}
964+
965+
// Run the deploy against the cluster in two cases:
966+
//
967+
// 1. The cluster is not localnet.
968+
// 2. The cluster is localnet, but we're not booting a local validator.
969+
//
970+
// In either case, skip the deploy if the user specifies.
971+
let is_localnet = cfg.provider.cluster == Cluster::Localnet;
972+
if !is_localnet || (is_localnet && skip_local_validator) {
973+
if !skip_deploy {
974+
deploy(cfg_override, None)?;
981975
}
982-
};
976+
}
977+
// Start local test validator, if needed.
978+
let mut validator_handle = None;
979+
if is_localnet && (!skip_local_validator) {
980+
let flags = match skip_deploy {
981+
true => None,
982+
false => Some(genesis_flags(cfg)?),
983+
};
984+
validator_handle = Some(start_test_validator(cfg, flags)?);
985+
}
983986

984987
// Setup log reader.
985988
let log_streams = stream_logs(&cfg.provider.cluster.url());

0 commit comments

Comments
 (0)