Skip to content

Commit

Permalink
fix: add padding to instruction from sim if one is not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Feb 27, 2024
1 parent e56f48e commit d6f1cb6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
21 changes: 21 additions & 0 deletions cmd/crates/soroban-test/tests/it/integration/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/crates/soroban-test/tests/it/integration/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
16 changes: 15 additions & 1 deletion cmd/soroban-cli/src/fee.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use clap::arg;
use soroban_env_host::xdr;
use soroban_rpc::Assembled;

use crate::commands::HEADING_RPC;
Expand All @@ -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 {
Expand Down

0 comments on commit d6f1cb6

Please sign in to comment.