Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
heytdep committed Nov 6, 2024
1 parent efd3537 commit 22f5770
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
2 changes: 1 addition & 1 deletion soroban-env-host/src/host/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ impl Host {
// this is the "loosened" path of calling a contract.
// TODO: A `reentry` flag will be passed from `try_call` into here.
// Default behaviour is to pass in `ContractReentryMode::Prohibited` to disable
// reentry, but it is the `call_data` parameter that controls this mode.
// reentry, but it is the `call_data` parameter that controls this mode.
let res = self.call_n_internal(
&self.contract_id_from_address(contract_address)?,
func,
Expand Down
45 changes: 24 additions & 21 deletions soroban-env-host/src/test/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2401,28 +2401,39 @@ mod cap_58_constructor {
mod cap_xx_opt_in_reentry {
use crate::{Host, HostError, MeteredOrdMap};
use soroban_env_common::{AddressObject, Env, Symbol, TryFromVal, TryIntoVal, Val, VecObject};
use soroban_test_wasms::{SIMPLE_NO_REENTRY_CONTRACT_B, SIMPLE_REENTRY_CONTRACT_A, SIMPLE_REENTRY_CONTRACT_B};
use stellar_xdr::curr::{ContractEvent, ContractEventBody, ContractEventType, ContractEventV0, ExtensionPoint, Hash, ScSymbol, ScVal};
use soroban_test_wasms::{
SIMPLE_NO_REENTRY_CONTRACT_B, SIMPLE_REENTRY_CONTRACT_A, SIMPLE_REENTRY_CONTRACT_B,
};
use stellar_xdr::curr::{
ContractEvent, ContractEventBody, ContractEventType, ContractEventV0, ExtensionPoint, Hash,
ScSymbol, ScVal,
};

#[test]
fn test_reentry_enabled() {
let host = Host::test_host_with_recording_footprint();
let contract_id_a = host.register_test_contract_wasm(SIMPLE_REENTRY_CONTRACT_A);
let contract_id_b = host.register_test_contract_wasm(SIMPLE_REENTRY_CONTRACT_B);
host.enable_debug().unwrap();
let args = test_vec![
&host,
contract_id_b
].into();
let args = test_vec![&host, contract_id_b].into();
call_contract(&host, contract_id_a, args);

let event_body = ContractEventBody::V0(ContractEventV0 {
topics: host.map_err(vec![ScVal::Symbol(ScSymbol("first_soroban_reentry".try_into().unwrap()))].try_into()).unwrap(),
data: ScVal::Void
}
);
topics: host
.map_err(
vec![ScVal::Symbol(ScSymbol(
"first_soroban_reentry".try_into().unwrap(),
))]
.try_into(),
)
.unwrap(),
data: ScVal::Void,
});
let events = host.get_events().unwrap().0;
match events.iter().find(|he| he.event.type_ == ContractEventType::Contract) {
match events
.iter()
.find(|he| he.event.type_ == ContractEventType::Contract)
{
Some(he) if he.event.type_ == ContractEventType::Contract => {
assert_eq!(he.event.body, event_body)
}
Expand All @@ -2437,20 +2448,12 @@ mod cap_xx_opt_in_reentry {
let contract_id_a = host.register_test_contract_wasm(SIMPLE_REENTRY_CONTRACT_A);
let contract_id_b = host.register_test_contract_wasm(SIMPLE_NO_REENTRY_CONTRACT_B);
host.enable_debug().unwrap();
let args = test_vec![
&host,
contract_id_b
].into();
let args = test_vec![&host, contract_id_b].into();
call_contract(&host, contract_id_a, args);
}

fn call_contract(host: &Host, called: AddressObject, args: VecObject) {
let fname = Symbol::try_from_val(host, &"test_reentry").unwrap();
host.call(
called,
fname,
args
)
.unwrap();
host.call(called, fname, args).unwrap();
}
}
5 changes: 2 additions & 3 deletions soroban-test-wasms/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,12 @@ pub const CONSTRUCTOR_WITH_RESULT: &[u8] =
pub const CUSTOM_ACCOUNT_CONTEXT_TEST_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/22/test_custom_account_context.wasm").as_slice();


// Protocol 23 Wasms.
pub const SIMPLE_REENTRY_CONTRACT_A: &[u8] =
include_bytes!("../wasm-workspace/opt/23/example_reentry_a.wasm").as_slice();

pub const SIMPLE_REENTRY_CONTRACT_B: &[u8] =
include_bytes!("../wasm-workspace/opt/23/example_reentry_b.wasm").as_slice();
include_bytes!("../wasm-workspace/opt/23/example_reentry_b.wasm").as_slice();

pub const SIMPLE_NO_REENTRY_CONTRACT_B: &[u8] =
include_bytes!("../wasm-workspace/opt/23/example_no_reentry_b.wasm").as_slice();
include_bytes!("../wasm-workspace/opt/23/example_no_reentry_b.wasm").as_slice();

0 comments on commit 22f5770

Please sign in to comment.