Skip to content

Commit

Permalink
Merge branch 'main' into chore/add-examples-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
BlaineHeffron authored Jul 30, 2024
2 parents 9de18f3 + ba24fda commit 37b7444
Show file tree
Hide file tree
Showing 28 changed files with 120 additions and 124 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
types: [published]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref_protected == 'true' && github.sha || github.ref }}-{{ github.event_name }}
cancel-in-progress: true

defaults:
run:
shell: bash
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/dependency-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
branches: [main, release/**]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref_protected == 'true' && github.sha || github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
branches: [main, release/**]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref_protected == 'true' && github.sha || github.ref }}
cancel-in-progress: true

jobs:
integration:
name: System tests
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/full-help-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: CLI Help Doc

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref_protected == 'true' && github.sha || github.ref }}
cancel-in-progress: true

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/ledger-emulator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
branches: [main, release/**]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref_protected == 'true' && github.sha || github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/rpc-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
branches: [main, release/**]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref_protected == 'true' && github.sha || github.ref }}
cancel-in-progress: true

jobs:
test:
name: test RPC
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
branches: [main, release/**]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref_protected == 'true' && github.sha || github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash
Expand Down
25 changes: 0 additions & 25 deletions .github/workflows/update-completed-sprint-on-issue-closed.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ captive-core/
!test.toml
*.sqlite
test_snapshots
.vscode/settings.json
.vscode/settings.json
.idea
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/crates/soroban-spec-json/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ sha2 = "0.9.9"
workspace = true
features = ["curr", "std", "serde"]

[dev_dependencies]
[dev-dependencies]
pretty_assertions = "1.2.1"
2 changes: 1 addition & 1 deletion cmd/crates/soroban-spec-typescript/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ base64 = { workspace = true }
workspace = true
features = ["curr", "std", "serde", "base64"]

[dev_dependencies]
[dev-dependencies]
temp-dir = "0.1.11"
pretty_assertions = "1.2.1"
walkdir = "2.3.3"
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ doctest = false
[dependencies]
soroban-sdk = { workspace = true }

[dev_dependencies]
[dev-dependencies]
soroban-sdk = { workspace = true, features = ["testutils"] }
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ crate-type = ["cdylib"]
soroban-sdk = { workspace = true }
soroban-token-sdk = { workspace = true }

[dev_dependencies]
[dev-dependencies]
soroban-sdk = { workspace = true, features = ["testutils"] }
1 change: 1 addition & 0 deletions cmd/crates/soroban-test/tests/it/integration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod bindings;
mod custom_types;
mod dotenv;
mod fund;
mod hello_world;
mod tx;
mod util;
Expand Down
19 changes: 19 additions & 0 deletions cmd/crates/soroban-test/tests/it/integration/fund.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use soroban_test::TestEnv;

#[tokio::test]
#[allow(clippy::too_many_lines)]
async fn fund() {
let sandbox = &TestEnv::new();
sandbox
.new_assert_cmd("keys")
.arg("generate")
.arg("test")
.assert()
.success();
sandbox
.new_assert_cmd("keys")
.arg("fund")
.arg("test")
.assert()
.stderr(predicates::str::contains("funding failed"));
}
6 changes: 0 additions & 6 deletions cmd/crates/soroban-test/tests/it/integration/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ async fn invoke() {
let sandbox = &TestEnv::new();
let c = soroban_rpc::Client::new(&sandbox.rpc_url).unwrap();
let GetLatestLedgerResponse { sequence, .. } = c.get_latest_ledger().await.unwrap();
sandbox
.new_assert_cmd("keys")
.arg("fund")
.arg("test")
.assert()
.stderr(predicates::str::contains("Account already exists"));
sandbox
.new_assert_cmd("keys")
.arg("fund")
Expand Down
4 changes: 2 additions & 2 deletions cmd/soroban-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ default-run = "soroban"

[[bin]]
name = "stellar"
path = "src/bin/main.rs"
path = "src/bin/stellar.rs"

[[bin]]
name = "soroban"
path = "src/bin/main.rs"
path = "src/bin/soroban.rs"

[package.metadata.binstall]
pkg-url = "{ repo }/releases/download/v{ version }/{ name }-{ version }-{ target }{ archive-suffix }"
Expand Down
File renamed without changes.
File renamed without changes.
84 changes: 18 additions & 66 deletions cmd/soroban-cli/src/commands/contract/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,15 @@ use std::str::FromStr;
use std::{fmt::Debug, fs, io};

use clap::{arg, command, Parser};
use soroban_env_host::{
budget::Budget,
storage::Storage,
xdr::{
self, ContractCodeEntry, ContractDataDurability, ContractDataEntry, ContractExecutable,
Error as XdrError, LedgerEntryData, LedgerKey, LedgerKeyContractCode,
LedgerKeyContractData, ScAddress, ScContractInstance, ScVal,
},
};

use soroban_spec::read::FromWasmError;
use stellar_strkey::DecodeError;
use stellar_xdr::curr::{ContractDataEntry, ContractExecutable, ScVal};

use crate::commands::contract::fetch::Error::{ContractIsStellarAsset, UnexpectedContractToken};
use crate::commands::{global, NetworkRunnable};
use crate::config::{
self, locator,
network::{self, Network},
};
use crate::utils::rpc::get_remote_wasm_from_hash;
use crate::{
rpc::{self, Client},
Pwd,
Expand Down Expand Up @@ -69,25 +60,20 @@ pub enum Error {
#[error(transparent)]
Locator(#[from] locator::Error),
#[error(transparent)]
Xdr(#[from] XdrError),
#[error(transparent)]
Spec(#[from] soroban_spec::read::FromWasmError),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error("missing result")]
MissingResult,
#[error("unexpected contract code data type: {0:?}")]
UnexpectedContractCodeDataType(LedgerEntryData),
#[error("reading file {0:?}: {1}")]
CannotWriteContractFile(PathBuf, io::Error),
#[error("cannot parse contract ID {0}: {1}")]
CannotParseContractId(String, DecodeError),
#[error("network details not provided")]
NetworkNotProvided,
#[error(transparent)]
Network(#[from] network::Error),
#[error("cannot create contract directory for {0:?}")]
CannotCreateContractDir(PathBuf),
#[error("unexpected contract data {0:?}")]
UnexpectedContractToken(ContractDataEntry),
#[error(
"cannot fetch wasm for contract because the contract is \
a network built-in asset contract that does not have a downloadable code binary"
)]
ContractIsStellarAsset(),
}

impl From<Infallible> for Error {
Expand Down Expand Up @@ -150,49 +136,15 @@ impl NetworkRunnable for Cmd {
client
.verify_network_passphrase(Some(&network.network_passphrase))
.await?;
Ok(client.get_remote_wasm(&contract_id).await?)
}
}
pub fn get_contract_wasm_from_storage(
storage: &mut Storage,
contract_id: [u8; 32],
) -> Result<Vec<u8>, FromWasmError> {
let key = LedgerKey::ContractData(LedgerKeyContractData {
contract: ScAddress::Contract(contract_id.into()),
key: ScVal::LedgerKeyContractInstance,
durability: ContractDataDurability::Persistent,
});
match storage.get(&key.into(), &Budget::default()) {
Ok(rc) => match rc.as_ref() {
xdr::LedgerEntry {
data:
LedgerEntryData::ContractData(ContractDataEntry {
val: ScVal::ContractInstance(ScContractInstance { executable, .. }),
..
}),
..
} => match executable {
let data_entry = client.get_contract_data(&contract_id).await?;
if let ScVal::ContractInstance(contract) = &data_entry.val {
return match &contract.executable {
ContractExecutable::Wasm(hash) => {
if let Ok(rc) = storage.get(
&LedgerKey::ContractCode(LedgerKeyContractCode { hash: hash.clone() })
.into(),
&Budget::default(),
) {
match rc.as_ref() {
xdr::LedgerEntry {
data: LedgerEntryData::ContractCode(ContractCodeEntry { code, .. }),
..
} => Ok(code.to_vec()),
_ => Err(FromWasmError::NotFound),
}
} else {
Err(FromWasmError::NotFound)
}
Ok(get_remote_wasm_from_hash(&client, hash).await?)
}
ContractExecutable::StellarAsset => todo!(),
},
_ => Err(FromWasmError::NotFound),
},
_ => Err(FromWasmError::NotFound),
ContractExecutable::StellarAsset => Err(ContractIsStellarAsset()),
};
}
return Err(UnexpectedContractToken(data_entry));
}
}
2 changes: 0 additions & 2 deletions cmd/soroban-cli/src/commands/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ pub enum Error {
InvalidUrl(String),
#[error("Inproper response {0}")]
InproperResponse(String),
#[error("Currently not supported on windows. Please visit:\n{0}")]
WindowsNotSupported(String),
}

impl Cmd {
Expand Down
16 changes: 7 additions & 9 deletions cmd/soroban-cli/src/config/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ pub enum Error {
FailedToParseJSON(String, serde_json::Error),
#[error("Invalid URL {0}")]
InvalidUrl(String),
#[error("Inproper response {0}")]
InproperResponse(String),
#[error("Currently not supported on windows. Please visit:\n{0}")]
WindowsNotSupported(String),
#[error("funding failed: {0}")]
FundingFailed(String),
}

#[derive(Debug, clap::Args, Clone, Default)]
Expand Down Expand Up @@ -151,16 +149,16 @@ impl Network {
return Err(Error::InvalidUrl(uri.to_string()));
}
};
let request_successful = response.status().is_success();
let body = hyper::body::to_bytes(response.into_body()).await?;
let res = serde_json::from_slice::<serde_json::Value>(&body)
.map_err(|e| Error::FailedToParseJSON(uri.to_string(), e))?;
tracing::debug!("{res:#?}");
if let Some(detail) = res.get("detail").and_then(Value::as_str) {
if detail.contains("createAccountAlreadyExist") {
eprintln!("Account already exists");
if !request_successful {
if let Some(detail) = res.get("detail").and_then(Value::as_str) {
return Err(Error::FundingFailed(detail.to_string()));
}
} else if res.get("successful").is_none() {
return Err(Error::InproperResponse(res.to_string()));
return Err(Error::FundingFailed("unknown cause".to_string()));
}
Ok(())
}
Expand Down
Loading

0 comments on commit 37b7444

Please sign in to comment.