diff --git a/cmd/crates/soroban-test/tests/it/integration/hello_world.rs b/cmd/crates/soroban-test/tests/it/integration/hello_world.rs index 359252e377..63c580bef8 100644 --- a/cmd/crates/soroban-test/tests/it/integration/hello_world.rs +++ b/cmd/crates/soroban-test/tests/it/integration/hello_world.rs @@ -270,6 +270,27 @@ async fn contract_data_read() { .stdout(predicates::str::starts_with("COUNTER,2")); } +#[tokio::test] +pub fn half_max_instructions(){ + let sandbox = TestEnv::new(); + let wasm = HELLO_WORLD; + sandbox + .new_assert_cmd("contract") + .arg("deploy") + .arg("--fee") + .arg("1000000") + .arg("--instructions") + .arg(&(u32::MAX / 2).to_string()) + .arg("--wasm") + .arg(wasm.path()) + .arg("--salt") + .arg(TEST_SALT) + .arg("--ignore-checks") + .assert() + .stderr("") + .stdout_as_str() +} + async fn invoke_with_seed(sandbox: &TestEnv, id: &str, seed_phrase: &str) { invoke_with_source(sandbox, seed_phrase, id).await; } diff --git a/cmd/crates/soroban-test/tests/it/integration/util.rs b/cmd/crates/soroban-test/tests/it/integration/util.rs index e8471d4475..a929f3267b 100644 --- a/cmd/crates/soroban-test/tests/it/integration/util.rs +++ b/cmd/crates/soroban-test/tests/it/integration/util.rs @@ -33,8 +33,6 @@ pub fn deploy_contract(sandbox: &TestEnv, wasm: &Wasm) -> String { .arg("deploy") .arg("--fee") .arg("1000000") - .arg("--instructions") - .arg(&(u32::MAX / 2).to_string()) .arg("--wasm") .arg(wasm.path()) .arg("--salt") diff --git a/cmd/soroban-cli/src/fee.rs b/cmd/soroban-cli/src/fee.rs index 70f427bb9c..353fe6e5db 100644 --- a/cmd/soroban-cli/src/fee.rs +++ b/cmd/soroban-cli/src/fee.rs @@ -1,4 +1,5 @@ use clap::arg; +use soroban_env_host::xdr; use soroban_rpc::Assembled; use crate::commands::HEADING_RPC; @@ -22,11 +23,24 @@ impl Args { if let Some(instructions) = self.instructions { txn.set_max_instructions(instructions) } else { - txn + add_padding_to_instructions(txn) } } } +pub fn add_padding_to_instructions(txn: Assembled) -> Assembled { + let xdr::TransactionExt::V1(xdr::SorobanTransactionData { + resources: xdr::SorobanResources { instructions, .. }, + .. + }) = txn.transaction().ext + else { + return txn; + }; + // Start with 150% + let instructions = (instructions.checked_mul(150 / 100)).unwrap_or(instructions); + txn.set_max_instructions(instructions) +} + impl Default for Args { fn default() -> Self { Self {