Skip to content

Commit

Permalink
Merge branch 'main' into i1187
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch committed May 9, 2024
2 parents 9d54807 + 199a88a commit 1e06f26
Show file tree
Hide file tree
Showing 21 changed files with 344 additions and 120 deletions.
48 changes: 48 additions & 0 deletions FULL_HELP_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ Deploy builtin Soroban Asset Contract
Possible values: `true`, `false`

* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction only write the base64 xdr to stdout

Possible values: `true`, `false`

* `--sim-only` — Simulation the transaction only write the base64 xdr to stdout

Possible values: `true`, `false`




Expand Down Expand Up @@ -390,6 +398,14 @@ If no keys are specified the contract itself is extended.
Possible values: `true`, `false`

* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction only write the base64 xdr to stdout

Possible values: `true`, `false`

* `--sim-only` — Simulation the transaction only write the base64 xdr to stdout

Possible values: `true`, `false`




Expand Down Expand Up @@ -422,6 +438,14 @@ Deploy a wasm contract
Possible values: `true`, `false`

* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction only write the base64 xdr to stdout

Possible values: `true`, `false`

* `--sim-only` — Simulation the transaction only write the base64 xdr to stdout

Possible values: `true`, `false`

* `-i`, `--ignore-checks` — Whether to ignore safety checks when deploying contracts

Default value: `false`
Expand Down Expand Up @@ -586,6 +610,14 @@ Install a WASM file to the ledger without creating a contract instance
Possible values: `true`, `false`

* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction only write the base64 xdr to stdout

Possible values: `true`, `false`

* `--sim-only` — Simulation the transaction only write the base64 xdr to stdout

Possible values: `true`, `false`

* `--wasm <WASM>` — Path to wasm binary
* `-i`, `--ignore-checks` — Whether to ignore safety checks when deploying contracts

Expand Down Expand Up @@ -635,6 +667,14 @@ soroban contract invoke ... -- --help
Possible values: `true`, `false`

* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction only write the base64 xdr to stdout

Possible values: `true`, `false`

* `--sim-only` — Simulation the transaction only write the base64 xdr to stdout

Possible values: `true`, `false`




Expand Down Expand Up @@ -747,6 +787,14 @@ If no keys are specificed the contract itself is restored.
Possible values: `true`, `false`

* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction only write the base64 xdr to stdout

Possible values: `true`, `false`

* `--sim-only` — Simulation the transaction only write the base64 xdr to stdout

Possible values: `true`, `false`




Expand Down
3 changes: 1 addition & 2 deletions cmd/crates/soroban-spec-tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,8 +1137,7 @@ impl Spec {
ScSpecEntry::UdtStructV0(ScSpecUdtStructV0 { fields, .. })
if fields
.first()
.map(|f| f.name.to_utf8_string_lossy() == "0")
.unwrap_or_default() =>
.is_some_and(|f| f.name.to_utf8_string_lossy() == "0") =>
{
let fields = fields
.iter()
Expand Down
4 changes: 3 additions & 1 deletion cmd/crates/soroban-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ impl TestEnv {
source: &str,
) -> Result<String, invoke::Error> {
let cmd = self.cmd_with_config::<I, invoke::Cmd>(command_str);
self.run_cmd_with(cmd, source).await
self.run_cmd_with(cmd, source)
.await
.map(|r| r.into_result().unwrap())
}

/// A convenience method for using the invoke command.
Expand Down
27 changes: 22 additions & 5 deletions cmd/crates/soroban-test/tests/it/integration/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use predicates::boolean::PredicateBooleanExt;
use soroban_cli::commands::{
config::{locator, secret},
contract::{self, fetch},
txn_result::TxnResult,
};
use soroban_rpc::GetLatestLedgerResponse;
use soroban_test::{AssertExt, TestEnv, LOCAL_NETWORK_PASSPHRASE};
Expand All @@ -11,6 +12,18 @@ use crate::integration::util::extend_contract;
use super::util::{deploy_hello, extend, HELLO_WORLD};

#[allow(clippy::too_many_lines)]
#[tokio::test]
async fn invoke_view_with_non_existent_source_account() {
let sandbox = &TestEnv::new();
let id = deploy_hello(sandbox).await;
let world = "world";
let mut cmd = hello_world_cmd(&id, world);
cmd.config.source_account = String::new();
cmd.is_view = true;
let res = sandbox.run_cmd_with(cmd, "test").await.unwrap();
assert_eq!(res, TxnResult::Res(format!(r#"["Hello",{world:?}]"#)));
}

#[tokio::test]
async fn invoke() {
let sandbox = &TestEnv::new();
Expand Down Expand Up @@ -140,14 +153,18 @@ fn invoke_hello_world(sandbox: &TestEnv, id: &str) {
.success();
}

async fn invoke_hello_world_with_lib(e: &TestEnv, id: &str) {
let cmd = contract::invoke::Cmd {
fn hello_world_cmd(id: &str, arg: &str) -> contract::invoke::Cmd {
contract::invoke::Cmd {
contract_id: id.to_string(),
slop: vec!["hello".into(), "--world=world".into()],
slop: vec!["hello".into(), format!("--world={arg}").into()],
..Default::default()
};
}
}

async fn invoke_hello_world_with_lib(e: &TestEnv, id: &str) {
let cmd = hello_world_cmd(id, "world");
let res = e.run_cmd_with(cmd, "test").await.unwrap();
assert_eq!(res, r#"["Hello","world"]"#);
assert_eq!(res, TxnResult::Res(r#"["Hello","world"]"#.to_string()));
}

fn invoke_auth(sandbox: &TestEnv, id: &str, addr: &str) {
Expand Down
7 changes: 6 additions & 1 deletion cmd/crates/soroban-test/tests/it/integration/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ pub async fn deploy_contract(sandbox: &TestEnv, wasm: &Wasm<'static>) -> String
TEST_SALT,
"--ignore-checks",
]);
sandbox.run_cmd_with(cmd, "test").await.unwrap()
sandbox
.run_cmd_with(cmd, "test")
.await
.unwrap()
.into_result()
.unwrap()
}

pub async fn extend_contract(sandbox: &TestEnv, id: &str) {
Expand Down
5 changes: 4 additions & 1 deletion cmd/crates/soroban-test/tests/it/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ pub async fn invoke_custom(
) -> Result<String, contract::invoke::Error> {
let mut i: contract::invoke::Cmd = sandbox.cmd_with_config(&["--id", id, "--", func, arg]);
i.wasm = Some(wasm.to_path_buf());
sandbox.run_cmd_with(i, TEST_ACCOUNT).await
sandbox
.run_cmd_with(i, TEST_ACCOUNT)
.await
.map(|r| r.into_result().unwrap())
}

pub const DEFAULT_CONTRACT_ID: &str = "CDR6QKTWZQYW6YUJ7UP7XXZRLWQPFRV6SWBLQS4ZQOSAF4BOUD77OO5Z";
16 changes: 12 additions & 4 deletions cmd/soroban-cli/src/commands/contract/deploy/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use std::{array::TryFromSliceError, fmt::Debug, num::ParseIntError};
use crate::{
commands::{
config::{self, data},
global, network, NetworkRunnable,
global, network,
txn_result::TxnResult,
NetworkRunnable,
},
rpc::{Client, Error as SorobanRpcError},
utils::{contract_id_hash_from_asset, parsing::parse_asset},
Expand Down Expand Up @@ -74,13 +76,13 @@ impl Cmd {
#[async_trait::async_trait]
impl NetworkRunnable for Cmd {
type Error = Error;
type Result = String;
type Result = TxnResult<stellar_strkey::Contract>;

async fn run_against_rpc_server(
&self,
args: Option<&global::Args>,
config: Option<&config::Args>,
) -> Result<String, Error> {
) -> Result<Self::Result, Error> {
let config = config.unwrap_or(&self.config);
// Parse asset
let asset = parse_asset(&self.asset)?;
Expand Down Expand Up @@ -108,8 +110,14 @@ impl NetworkRunnable for Cmd {
network_passphrase,
&key,
)?;
if self.fee.build_only {
return Ok(TxnResult::Txn(tx));
}
let txn = client.create_assembled_transaction(&tx).await?;
let txn = self.fee.apply_to_assembled_txn(txn);
if self.fee.sim_only {
return Ok(TxnResult::Txn(txn.transaction().clone()));
}
let get_txn_resp = client
.send_assembled_transaction(txn, &key, &[], network_passphrase, None, None)
.await?
Expand All @@ -118,7 +126,7 @@ impl NetworkRunnable for Cmd {
data::write(get_txn_resp, &network.rpc_uri()?)?;
}

Ok(stellar_strkey::Contract(contract_id.0).to_string())
Ok(TxnResult::Res(stellar_strkey::Contract(contract_id.0)))
}
}

Expand Down
43 changes: 31 additions & 12 deletions cmd/soroban-cli/src/commands/contract/deploy/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ use soroban_env_host::{
use crate::commands::{
config::data,
contract::{self, id::wasm::get_contract_id},
global, network, NetworkRunnable,
global, network,
txn_result::TxnResult,
NetworkRunnable,
};
use crate::{
commands::{config, contract::install, HEADING_RPC},
Expand Down Expand Up @@ -96,6 +98,8 @@ pub enum Error {
Data(#[from] data::Error),
#[error(transparent)]
Network(#[from] network::Error),
#[error(transparent)]
Wasm(#[from] wasm::Error),
}

impl Cmd {
Expand All @@ -109,23 +113,29 @@ impl Cmd {
#[async_trait::async_trait]
impl NetworkRunnable for Cmd {
type Error = Error;
type Result = String;
type Result = TxnResult<String>;

async fn run_against_rpc_server(
&self,
global_args: Option<&global::Args>,
config: Option<&config::Args>,
) -> Result<String, Error> {
) -> Result<TxnResult<String>, Error> {
let config = config.unwrap_or(&self.config);
let wasm_hash = if let Some(wasm) = &self.wasm {
let hash = install::Cmd {
wasm: wasm::Args { wasm: wasm.clone() },
config: config.clone(),
fee: self.fee.clone(),
ignore_checks: self.ignore_checks,
}
.run_against_rpc_server(global_args, Some(config))
.await?;
let hash = if self.fee.build_only {
wasm::Args { wasm: wasm.clone() }.hash()?
} else {
install::Cmd {
wasm: wasm::Args { wasm: wasm.clone() },
config: config.clone(),
fee: self.fee.clone(),
ignore_checks: self.ignore_checks,
}
.run_against_rpc_server(global_args, Some(config))
.await?
.into_result()
.expect("the value (hash) is expected because it should always be available since build-only is a shared parameter")
};
hex::encode(hash)
} else {
self.wasm_hash
Expand Down Expand Up @@ -169,16 +179,25 @@ impl NetworkRunnable for Cmd {
salt,
&key,
)?;
if self.fee.build_only {
return Ok(TxnResult::Txn(txn));
}

let txn = client.create_assembled_transaction(&txn).await?;
let txn = self.fee.apply_to_assembled_txn(txn);
if self.fee.sim_only {
return Ok(TxnResult::Txn(txn.transaction().clone()));
}
let get_txn_resp = client
.send_assembled_transaction(txn, &key, &[], &network.network_passphrase, None, None)
.await?
.try_into()?;
if global_args.map_or(true, |a| !a.no_cache) {
data::write(get_txn_resp, &network.rpc_uri()?)?;
}
Ok(stellar_strkey::Contract(contract_id.0).to_string())
Ok(TxnResult::Res(
stellar_strkey::Contract(contract_id.0).to_string(),
))
}
}

Expand Down
Loading

0 comments on commit 1e06f26

Please sign in to comment.