Skip to content

Commit 7e5fed6

Browse files
authored
Ensure simulation only runs once. (#2116)
1 parent 71f2729 commit 7e5fed6

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

  • cmd/soroban-cli/src/commands/contract

cmd/soroban-cli/src/commands/contract/invoke.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,16 @@ impl NetworkRunnable for Cmd {
244244

245245
let (function, spec, host_function_params, signers) = params;
246246

247-
let simulate_if_needed = || async {
248-
self.simulate(&host_function_params, &default_account_entry(), &client)
249-
.await
250-
};
251-
252-
let should_send = if self.fee.build_only {
253-
ShouldSend::Yes
247+
// `self.fee.build_only` will be checked again below and the fn will return a TxnResult::Txn
248+
// if the user passed the --build-only flag
249+
let (should_send, cached_simulation) = if self.fee.build_only {
250+
(ShouldSend::Yes, None)
254251
} else {
255-
let assembled = simulate_if_needed().await?;
256-
self.should_send_tx(&assembled.sim_res)?
252+
let assembled = self
253+
.simulate(&host_function_params, &default_account_entry(), &client)
254+
.await?;
255+
let should_send = self.should_send_tx(&assembled.sim_res)?;
256+
(should_send, Some(assembled))
257257
};
258258

259259
let account_details = if should_send == ShouldSend::Yes {
@@ -271,7 +271,9 @@ impl NetworkRunnable for Cmd {
271271
);
272272
}
273273

274-
let assembled = simulate_if_needed().await?;
274+
let assembled = cached_simulation.expect(
275+
"cached_simulation should be available when should_send != Yes and not build_only",
276+
);
275277
let sim_res = assembled.sim_response();
276278
let return_value = sim_res.results()?;
277279
let events = sim_res.events()?;

0 commit comments

Comments
 (0)