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

Fixes for Rust 1.81.0 #1333

Merged
merged 8 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 14 additions & 0 deletions Cargo.lock

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

17 changes: 12 additions & 5 deletions soroban-sdk-macros/src/derive_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn derive_pub_fn(
});

// Prepare the argument inputs.
let (wrap_args, wrap_calls): (Vec<_>, Vec<_>) = inputs
let (wrap_args, passthrough_calls, wrap_calls): (Vec<_>, Vec<_>, Vec<_>) = inputs
.iter()
.skip(if env_input.is_some() { 1 } else { 0 })
.enumerate()
Expand Down Expand Up @@ -78,6 +78,7 @@ pub fn derive_pub_fn(
colon_token: Colon::default(),
ty: Box::new(Type::Verbatim(quote! { #crate_path::Val })),
});
let passthrough_call = quote! { #ident };
let call = quote! {
<_ as #crate_path::unwrap::UnwrapOptimized>::unwrap_optimized(
<_ as #crate_path::TryFromValForContractFn<#crate_path::Env, #crate_path::Val>>::try_from_val_for_contract_fn(
Expand All @@ -86,11 +87,11 @@ pub fn derive_pub_fn(
)
)
};
(arg, call)
(arg, passthrough_call, call)
}
FnArg::Receiver(_) => {
errors.push(Error::new(a.span(), "self argument not supported"));
(a.clone(), quote! {})
(a.clone(), quote! {}, quote! {})
}
})
.multiunzip();
Expand Down Expand Up @@ -132,8 +133,7 @@ pub fn derive_pub_fn(
use super::*;

#[deprecated(note = #deprecated_note)]
#[cfg_attr(target_family = "wasm", export_name = #wrap_export_name)]
pub extern fn invoke_raw(env: #crate_path::Env, #(#wrap_args),*) -> #crate_path::Val {
pub fn invoke_raw(env: #crate_path::Env, #(#wrap_args),*) -> #crate_path::Val {
#use_trait;
<_ as #crate_path::IntoVal<#crate_path::Env, #crate_path::Val>>::into_val(
#[allow(deprecated)]
Expand All @@ -154,6 +154,13 @@ pub fn derive_pub_fn(
invoke_raw(env, #(#slice_args),*)
}

#[deprecated(note = #deprecated_note)]
#[cfg_attr(target_family = "wasm", export_name = #wrap_export_name)]
pub extern fn invoke_raw_extern(env: #crate_path::Env, #(#wrap_args),*) -> #crate_path::Val {
#[allow(deprecated)]
invoke_raw(env, #(#passthrough_calls),*)
}

use super::*;
}
})
Expand Down
129 changes: 129 additions & 0 deletions tests/auth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,4 +482,133 @@ mod test_b {
}
}
}

mod wasm {
leighmcculloch marked this conversation as resolved.
Show resolved Hide resolved
use super::*;

#[test]
fn test_with_real_contract_wasm_auth_approve() {
let e = Env::default();

let contract_a_id = e.register_contract(None, ContractA);
let contract_b_id = e.register_contract(None, ContractB);
let client = ContractBClient::new(&e, &contract_b_id);

mod imported_auth_approve {
soroban_sdk::contractimport!(
file = "../../target/wasm32-unknown-unknown/release/test_auth_approve.wasm"
);
}

let a = e.register_contract_wasm(None, imported_auth_approve::WASM);
let a_xdr: ScAddress = (&a).try_into().unwrap();

let r = client
.set_auths(&[SorobanAuthorizationEntry {
credentials: SorobanCredentials::Address(SorobanAddressCredentials {
address: a_xdr.clone(),
nonce: 789,
signature_expiration_ledger: 150,
signature: ScVal::Void,
}),
root_invocation: SorobanAuthorizedInvocation {
function: SorobanAuthorizedFunction::ContractFn(InvokeContractArgs {
contract_address: contract_b_id.clone().try_into().unwrap(),
function_name: StringM::try_from("fn2").unwrap().into(),
args: std::vec![ScVal::I32(1), ScVal::I32(2),].try_into().unwrap(),
}),
sub_invocations: std::vec![SorobanAuthorizedInvocation {
function: SorobanAuthorizedFunction::ContractFn(InvokeContractArgs {
contract_address: contract_a_id.clone().try_into().unwrap(),
function_name: StringM::try_from("fn1").unwrap().into(),
args: std::vec![ScVal::Address(a_xdr.clone())].try_into().unwrap(),
},),
sub_invocations: Default::default()
}]
.try_into()
.unwrap(),
},
}])
.try_fn2(&a, &contract_a_id);

assert_eq!(r, Ok(Ok(2)));

assert_eq!(
e.auths(),
[(
a.clone(),
AuthorizedInvocation {
function: AuthorizedFunction::Contract((
contract_b_id.clone(),
symbol_short!("fn2"),
(1, 2).into_val(&e),
)),
sub_invocations: std::vec![AuthorizedInvocation {
function: AuthorizedFunction::Contract((
contract_a_id.clone(),
symbol_short!("fn1"),
(&a,).into_val(&e),
)),
sub_invocations: std::vec![]
}]
}
),],
);
}

#[test]
fn test_with_real_contract_wasm_auth_decline() {
let e = Env::default();

let contract_a_id = e.register_contract(None, ContractA);
let contract_b_id = e.register_contract(None, ContractB);
let client = ContractBClient::new(&e, &contract_b_id);

mod imported_auth_decline {
soroban_sdk::contractimport!(
file = "../../target/wasm32-unknown-unknown/release/test_auth_decline.wasm"
);
}

let a = e.register_contract_wasm(None, imported_auth_decline::WASM);
let a_xdr: ScAddress = (&a).try_into().unwrap();

let r = client
.set_auths(&[SorobanAuthorizationEntry {
credentials: SorobanCredentials::Address(SorobanAddressCredentials {
address: a_xdr.clone(),
nonce: 789,
signature_expiration_ledger: 150,
signature: ScVal::Void,
}),
root_invocation: SorobanAuthorizedInvocation {
function: SorobanAuthorizedFunction::ContractFn(InvokeContractArgs {
contract_address: contract_b_id.try_into().unwrap(),
function_name: StringM::try_from("fn2").unwrap().into(),
args: std::vec![ScVal::I32(1), ScVal::I32(2),].try_into().unwrap(),
}),
sub_invocations: std::vec![SorobanAuthorizedInvocation {
function: SorobanAuthorizedFunction::ContractFn(InvokeContractArgs {
contract_address: contract_a_id.clone().try_into().unwrap(),
function_name: StringM::try_from("fn1").unwrap().into(),
args: std::vec![ScVal::Address(a_xdr.clone())].try_into().unwrap(),
},),
sub_invocations: Default::default()
}]
.try_into()
.unwrap(),
},
}])
.try_fn2(&a, &contract_a_id);

assert_eq!(
r,
Err(Ok(Error::from_scerror(ScError::Context(
ScErrorCode::InvalidAction
))))
);

assert_eq!(e.auths(), []);
}
}
}
Loading
Loading