-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/ledger-tests-org-update
- Loading branch information
Showing
11 changed files
with
185 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod bindings; | ||
mod custom_types; | ||
mod dotenv; | ||
mod hello_world; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use super::util::deploy_swap; | ||
use soroban_test::{TestEnv, LOCAL_NETWORK_PASSPHRASE}; | ||
|
||
const OUTPUT_DIR: &str = "./bindings-output"; | ||
|
||
#[tokio::test] | ||
async fn invoke_test_generate_typescript_bindings() { | ||
let sandbox = &TestEnv::new(); | ||
let contract_id = deploy_swap(sandbox).await; | ||
let outdir = sandbox.dir().join(OUTPUT_DIR); | ||
let cmd = sandbox.cmd_arr::<soroban_cli::commands::contract::bindings::typescript::Cmd>(&[ | ||
"--network-passphrase", | ||
LOCAL_NETWORK_PASSPHRASE, | ||
"--rpc-url", | ||
&sandbox.rpc_url, | ||
"--output-dir", | ||
&outdir.display().to_string(), | ||
"--overwrite", | ||
"--contract-id", | ||
&contract_id.to_string(), | ||
]); | ||
|
||
let result = sandbox.run_cmd_with(cmd, "test").await; | ||
|
||
assert!(result.is_ok(), "Failed to generate TypeScript bindings"); | ||
|
||
assert!(outdir.exists(), "Output directory does not exist"); | ||
|
||
let files = std::fs::read_dir(outdir).expect("Failed to read output directory"); | ||
assert!( | ||
files.count() > 0, | ||
"No files generated in the output directory" | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,6 @@ simple_account | |
single_offer | ||
timelock | ||
token | ||
ttl | ||
upgradeable_contract | ||
workspace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use soroban_env_host::xdr; | ||
|
||
use soroban_env_host::xdr::{ | ||
ContractDataEntry, ContractExecutable, ScContractInstance, ScSpecEntry, ScVal, | ||
}; | ||
|
||
use soroban_spec::read::FromWasmError; | ||
pub use soroban_spec_tools::contract as contract_spec; | ||
|
||
use crate::commands::config::{self, locator}; | ||
use crate::commands::network; | ||
use crate::commands::{config::data, global}; | ||
use crate::rpc; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
#[error("parsing contract spec: {0}")] | ||
CannotParseContractSpec(FromWasmError), | ||
#[error(transparent)] | ||
Rpc(#[from] rpc::Error), | ||
#[error("missing result")] | ||
MissingResult, | ||
#[error(transparent)] | ||
Data(#[from] data::Error), | ||
#[error(transparent)] | ||
Xdr(#[from] xdr::Error), | ||
#[error(transparent)] | ||
Network(#[from] network::Error), | ||
#[error(transparent)] | ||
Config(#[from] config::Error), | ||
} | ||
|
||
/// | ||
/// # Errors | ||
pub async fn get_remote_contract_spec( | ||
contract_id: &[u8; 32], | ||
locator: &locator::Args, | ||
network: &network::Args, | ||
global_args: Option<&global::Args>, | ||
config: Option<&config::Args>, | ||
) -> Result<Vec<ScSpecEntry>, Error> { | ||
let network = config.map_or_else( | ||
|| network.get(locator).map_err(Error::from), | ||
|c| c.get_network().map_err(Error::from), | ||
)?; | ||
tracing::trace!(?network); | ||
let client = rpc::Client::new(&network.rpc_url)?; | ||
// Get contract data | ||
let r = client.get_contract_data(contract_id).await?; | ||
tracing::trace!("{r:?}"); | ||
|
||
let ContractDataEntry { | ||
val: ScVal::ContractInstance(ScContractInstance { executable, .. }), | ||
.. | ||
} = r | ||
else { | ||
return Err(Error::MissingResult); | ||
}; | ||
|
||
// Get the contract spec entries based on the executable type | ||
Ok(match executable { | ||
ContractExecutable::Wasm(hash) => { | ||
let hash = hash.to_string(); | ||
if let Ok(entries) = data::read_spec(&hash) { | ||
entries | ||
} else { | ||
let res = client.get_remote_contract_spec(contract_id).await?; | ||
if global_args.map_or(true, |a| !a.no_cache) { | ||
data::write_spec(&hash, &res)?; | ||
} | ||
res | ||
} | ||
} | ||
ContractExecutable::StellarAsset => { | ||
soroban_spec::read::parse_raw(&soroban_sdk::token::StellarAssetSpec::spec_xdr())? | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file removed
0
cmd/soroban-cli/src/utils/contract-init-template/.soroban/contract-ids/.gitkeep
Empty file.