Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SDK to recent env #1042

Merged
merged 4 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ soroban-token-sdk = { version = "0.9.2", path = "soroban-token-sdk" }
[workspace.dependencies.soroban-env-common]
version = "0.0.17"
git = "https://github.com/stellar/rs-soroban-env"
rev = "400d806387140553e4e685d232deb3a807ec0e36"
rev = "63cf7fe3d5ffc60db57fba97e9fc9c5778cd559c"

[workspace.dependencies.soroban-env-guest]
version = "0.0.17"
git = "https://github.com/stellar/rs-soroban-env"
rev = "400d806387140553e4e685d232deb3a807ec0e36"
rev = "63cf7fe3d5ffc60db57fba97e9fc9c5778cd559c"

[workspace.dependencies.soroban-env-host]
version = "0.0.17"
git = "https://github.com/stellar/rs-soroban-env"
rev = "400d806387140553e4e685d232deb3a807ec0e36"
rev = "63cf7fe3d5ffc60db57fba97e9fc9c5778cd559c"

[workspace.dependencies.stellar-strkey]
version = "0.0.7"
Expand All @@ -60,7 +60,7 @@ rev = "e6ba45c60c16de28c7522586b80ed0150157df73"
[workspace.dependencies.stellar-xdr]
version = "0.0.17"
git = "https://github.com/stellar/rs-stellar-xdr"
rev = "0f16673441898162c9996da6117be2280ef8fd84"
rev = "4eaf2388c1de6fc295ed5f7df8174c199923df5b"
default-features = false

#[patch."https://github.com/stellar/rs-soroban-env"]
Expand Down
9 changes: 2 additions & 7 deletions soroban-ledger-snapshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ use std::{
rc::Rc,
};

use soroban_env_common::xdr::{ScErrorCode, ScErrorType};
use soroban_env_host::{
storage::SnapshotSource,
xdr::{LedgerEntry, LedgerKey, ScError},
xdr::{LedgerEntry, LedgerKey, ScError, ScErrorCode},
Host, HostError, LedgerInfo,
};

Expand Down Expand Up @@ -175,11 +174,7 @@ impl SnapshotSource for &LedgerSnapshot {
fn get(&self, key: &Rc<LedgerKey>) -> Result<Rc<LedgerEntry>, HostError> {
match self.ledger_entries.iter().find(|(k, _)| **k == **key) {
Some((_, v)) => Ok(Rc::new(*v.clone())),
None => Err(ScError {
type_: ScErrorType::Storage,
code: ScErrorCode::MissingValue,
}
.into()),
None => Err(ScError::Storage(ScErrorCode::MissingValue).into()),
}
}
fn has(&self, key: &Rc<LedgerKey>) -> Result<bool, HostError> {
Expand Down
28 changes: 16 additions & 12 deletions soroban-sdk/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,14 @@ impl Env {
let storage = internal::storage::Storage::with_recording_footprint(rf);
let budget = internal::budget::Budget::default();
let env_impl = internal::EnvImpl::with_storage_and_budget(storage, budget.clone());
env_impl.set_source_account(xdr::AccountId(xdr::PublicKey::PublicKeyTypeEd25519(
xdr::Uint256(random()),
)));
env_impl.set_diagnostic_level(internal::DiagnosticLevel::Debug);
env_impl
.set_source_account(xdr::AccountId(xdr::PublicKey::PublicKeyTypeEd25519(
xdr::Uint256(random()),
)))
.unwrap();
env_impl
.set_diagnostic_level(internal::DiagnosticLevel::Debug)
.unwrap();
let env = Env {
env_impl,
snapshot: None,
Expand Down Expand Up @@ -704,14 +708,14 @@ impl Env {
.try_into_val(self)
.unwrap();

let prev_auth_manager = self.env_impl.snapshot_auth_manager();
self.env_impl.switch_to_recording_auth();
let prev_auth_manager = self.env_impl.snapshot_auth_manager().unwrap();
self.env_impl.switch_to_recording_auth().unwrap();
self.invoke_contract::<()>(
&token_id,
&soroban_sdk_macros::internal_symbol_short!("set_admin"),
(admin,).try_into_val(self).unwrap(),
);
self.env_impl.set_auth_manager(prev_auth_manager);
self.env_impl.set_auth_manager(prev_auth_manager).unwrap();
token_id
}

Expand All @@ -729,8 +733,8 @@ impl Env {
}

fn register_contract_with_source(&self, executable: xdr::ContractExecutable) -> Address {
let prev_auth_manager = self.env_impl.snapshot_auth_manager();
self.env_impl.switch_to_recording_auth();
let prev_auth_manager = self.env_impl.snapshot_auth_manager().unwrap();
self.env_impl.switch_to_recording_auth().unwrap();

let contract_id: Address = self
.env_impl
Expand All @@ -747,7 +751,7 @@ impl Env {
.try_into_val(self)
.unwrap();

self.env_impl.set_auth_manager(prev_auth_manager);
self.env_impl.set_auth_manager(prev_auth_manager).unwrap();

contract_id
}
Expand Down Expand Up @@ -879,7 +883,7 @@ impl Env {
/// }
/// ```
pub fn mock_all_auths(&self) {
self.env_impl.switch_to_recording_auth();
self.env_impl.switch_to_recording_auth().unwrap();
}

/// Returns a list of authorization trees that were seen during the last
Expand Down Expand Up @@ -1144,7 +1148,7 @@ impl Env {
let storage = internal::storage::Storage::with_recording_footprint(rs.clone());
let budget = internal::budget::Budget::default();
let env_impl = internal::EnvImpl::with_storage_and_budget(storage, budget.clone());
env_impl.switch_to_recording_auth();
env_impl.switch_to_recording_auth().unwrap();

let env = Env {
env_impl,
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ use crate::testutils;
impl testutils::Ledger for Ledger {
fn set(&self, li: testutils::LedgerInfo) {
let env = self.env();
env.host().set_ledger_info(li);
env.host().set_ledger_info(li).unwrap();
}

fn get(&self) -> testutils::LedgerInfo {
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl testutils::Logs for Logs {
.into_iter()
.filter_map(|e| match (&e.event.type_, &e.event.body) {
(ContractEventType::Diagnostic, ContractEventBody::V0(ce))
if &ce.topics == &log_topics =>
if &ce.topics == &log_topics.0 =>
{
Some(format!("{}", &e))
}
Expand Down
11 changes: 4 additions & 7 deletions soroban-sdk/src/tests/auth/auth_40_multi_one_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ impl ContractB {
}

#[test]
fn test_auth_separately() {
fn test_auth_not_allowed_with_separated_tree() {
let e = Env::default();
let contract_a_id = e.register_contract(None, ContractA);
let contract_b_id = e.register_contract(None, ContractB);
let client = ContractAClient::new(&e, &contract_a_id);

let a = Address::random(&e);

let c = client
assert!(client
.mock_auths(&[
MockAuth {
address: &a,
Expand All @@ -59,11 +59,8 @@ fn test_auth_separately() {
},
},
])
.fna(&contract_b_id, &a);

assert_eq!(c, 1);

println!("{:?}", e.auths());
.try_fna(&contract_b_id, &a)
.is_err());
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions soroban-sdk/src/tests/contract_invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn test_invoke_expect_string() {
}

#[test]
#[should_panic(expected = "Error(Context, InternalError)")]
#[should_panic(expected = "Error(WasmVm, InvalidAction)")]
fn test_invoke_expect_error() {
let e = Env::default();
let contract_id = e.register_contract(None, Contract);
Expand All @@ -40,8 +40,8 @@ fn test_try_invoke() {
assert_eq!(
res,
Err(Ok(soroban_sdk::Error::from_type_and_code(
ScErrorType::Context,
ScErrorCode::InternalError
ScErrorType::WasmVm,
ScErrorCode::InvalidAction
)))
);
}
5 changes: 3 additions & 2 deletions soroban-sdk/src/tests/token_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use soroban_sdk::{
token::{StellarAssetSpec, SPEC_XDR_INPUT, SPEC_XDR_LEN},
xdr::{Error, ReadXdr, ScSpecEntry},
};
use stellar_xdr::DepthLimitedRead;

extern crate std;

Expand All @@ -16,8 +17,8 @@ fn test_spec_xdr_len() {
#[test]
fn test_spec_xdr() -> Result<(), Error> {
let xdr = StellarAssetSpec::spec_xdr();
let mut cursor = std::io::Cursor::new(xdr);
for spec_entry in ScSpecEntry::read_xdr_iter(&mut cursor) {
let cursor = std::io::Cursor::new(xdr);
for spec_entry in ScSpecEntry::read_xdr_iter(&mut DepthLimitedRead::new(cursor, 1000)) {
spec_entry?;
}
Ok(())
Expand Down
14 changes: 7 additions & 7 deletions soroban-sdk/src/testutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,35 +89,35 @@ pub mod budget {

/// Reset the budget.
pub fn reset_default(&mut self) {
self.0.reset_default();
self.0.reset_default().unwrap();
}

pub fn reset_unlimited(&mut self) {
self.0.reset_unlimited();
self.0.reset_unlimited().unwrap();
}

pub fn reset_limits(&mut self, cpu: u64, mem: u64) {
self.0.reset_limits(cpu, mem);
self.0.reset_limits(cpu, mem).unwrap();
}

pub fn reset_tracker(&mut self) {
self.0.reset_tracker();
self.0.reset_tracker().unwrap();
}

/// Returns the CPU instruction cost.
///
/// Note that CPU instructions are likely to be underestimated when
/// running Rust code compared to running the WASM equivalent.
pub fn cpu_instruction_cost(&self) -> u64 {
self.0.get_cpu_insns_consumed()
self.0.get_cpu_insns_consumed().unwrap()
}

/// Returns the memory cost.
///
/// Note that memory is likely to be underestimated when running Rust
/// code compared to running the WASM equivalent.
pub fn memory_bytes_cost(&self) -> u64 {
self.0.get_cpu_insns_consumed()
self.0.get_cpu_insns_consumed().unwrap()
}

/// Get the input tracker associated with the cost. The tracker tracks
Expand All @@ -127,7 +127,7 @@ pub mod budget {
/// Note that VM cost types are likely to be underestimated when running
/// Rust code compared to running the WASM equivalent.
pub fn tracker(&self, cost_type: ContractCostType) -> (u64, Option<u64>) {
self.0.get_tracker(cost_type)
self.0.get_tracker(cost_type).unwrap()
}

/// Print the budget costs and inputs to stdout.
Expand Down
Loading