From 882889ecae7f72698dd41b17b085065b2815f8b0 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Fri, 26 Sep 2025 16:57:21 +1000 Subject: [PATCH 01/24] add job to expand test vectors to track changes to generated code --- .github/workflows/rust.yml | 17 +- Makefile | 15 + tests-expanded/proc_macros_tests.rs | 33 + tests-expanded/test_account_tests.rs | 606 ++++ tests-expanded/test_account_wasm32v1-none.rs | 276 ++ tests-expanded/test_add_i128_tests.rs | 368 +++ tests-expanded/test_add_i128_wasm32v1-none.rs | 135 + tests-expanded/test_add_u128_tests.rs | 368 +++ tests-expanded/test_add_u128_wasm32v1-none.rs | 135 + tests-expanded/test_add_u64_tests.rs | 368 +++ tests-expanded/test_add_u64_wasm32v1-none.rs | 135 + tests-expanded/test_alloc_tests.rs | 640 ++++ tests-expanded/test_alloc_wasm32v1-none.rs | 129 + tests-expanded/test_auth_tests.rs | 2836 +++++++++++++++++ tests-expanded/test_auth_wasm32v1-none.rs | 247 ++ tests-expanded/test_bls_tests.rs | 1478 +++++++++ tests-expanded/test_bls_wasm32v1-none.rs | 435 +++ tests-expanded/test_constructor_tests.rs | 1196 +++++++ .../test_constructor_wasm32v1-none.rs | 305 ++ tests-expanded/test_contract_data_tests.rs | 622 ++++ .../test_contract_data_wasm32v1-none.rs | 307 ++ tests-expanded/test_empty2_tests.rs | 195 ++ tests-expanded/test_empty2_wasm32v1-none.rs | 29 + tests-expanded/test_empty_tests.rs | 333 ++ tests-expanded/test_empty_wasm32v1-none.rs | 105 + tests-expanded/test_errors_tests.rs | 1446 +++++++++ tests-expanded/test_errors_wasm32v1-none.rs | 364 +++ tests-expanded/test_events_tests.rs | 792 +++++ tests-expanded/test_events_wasm32v1-none.rs | 338 ++ tests-expanded/test_fuzz_tests.rs | 334 ++ tests-expanded/test_fuzz_wasm32v1-none.rs | 139 + tests-expanded/test_import_contract_tests.rs | 587 ++++ .../test_import_contract_wasm32v1-none.rs | 233 ++ tests-expanded/test_invoke_contract_tests.rs | 717 +++++ .../test_invoke_contract_wasm32v1-none.rs | 294 ++ tests-expanded/test_logging_tests.rs | 447 +++ tests-expanded/test_logging_wasm32v1-none.rs | 188 ++ tests-expanded/test_macros_tests.rs | 334 ++ tests-expanded/test_macros_wasm32v1-none.rs | 106 + tests-expanded/test_modular_tests.rs | 712 +++++ tests-expanded/test_modular_wasm32v1-none.rs | 286 ++ tests-expanded/test_multiimpl_tests.rs | 650 ++++ .../test_multiimpl_wasm32v1-none.rs | 267 ++ tests-expanded/test_udt_tests.rs | 2309 ++++++++++++++ tests-expanded/test_udt_wasm32v1-none.rs | 618 ++++ .../test_workspace_contract_tests.rs | 352 ++ .../test_workspace_contract_wasm32v1-none.rs | 111 + tests-expanded/test_workspace_lib_tests.rs | 360 +++ tests-expanded/test_zero_tests.rs | 145 + tests-expanded/test_zero_wasm32v1-none.rs | 26 + 50 files changed, 23467 insertions(+), 1 deletion(-) create mode 100644 tests-expanded/proc_macros_tests.rs create mode 100644 tests-expanded/test_account_tests.rs create mode 100644 tests-expanded/test_account_wasm32v1-none.rs create mode 100644 tests-expanded/test_add_i128_tests.rs create mode 100644 tests-expanded/test_add_i128_wasm32v1-none.rs create mode 100644 tests-expanded/test_add_u128_tests.rs create mode 100644 tests-expanded/test_add_u128_wasm32v1-none.rs create mode 100644 tests-expanded/test_add_u64_tests.rs create mode 100644 tests-expanded/test_add_u64_wasm32v1-none.rs create mode 100644 tests-expanded/test_alloc_tests.rs create mode 100644 tests-expanded/test_alloc_wasm32v1-none.rs create mode 100644 tests-expanded/test_auth_tests.rs create mode 100644 tests-expanded/test_auth_wasm32v1-none.rs create mode 100644 tests-expanded/test_bls_tests.rs create mode 100644 tests-expanded/test_bls_wasm32v1-none.rs create mode 100644 tests-expanded/test_constructor_tests.rs create mode 100644 tests-expanded/test_constructor_wasm32v1-none.rs create mode 100644 tests-expanded/test_contract_data_tests.rs create mode 100644 tests-expanded/test_contract_data_wasm32v1-none.rs create mode 100644 tests-expanded/test_empty2_tests.rs create mode 100644 tests-expanded/test_empty2_wasm32v1-none.rs create mode 100644 tests-expanded/test_empty_tests.rs create mode 100644 tests-expanded/test_empty_wasm32v1-none.rs create mode 100644 tests-expanded/test_errors_tests.rs create mode 100644 tests-expanded/test_errors_wasm32v1-none.rs create mode 100644 tests-expanded/test_events_tests.rs create mode 100644 tests-expanded/test_events_wasm32v1-none.rs create mode 100644 tests-expanded/test_fuzz_tests.rs create mode 100644 tests-expanded/test_fuzz_wasm32v1-none.rs create mode 100644 tests-expanded/test_import_contract_tests.rs create mode 100644 tests-expanded/test_import_contract_wasm32v1-none.rs create mode 100644 tests-expanded/test_invoke_contract_tests.rs create mode 100644 tests-expanded/test_invoke_contract_wasm32v1-none.rs create mode 100644 tests-expanded/test_logging_tests.rs create mode 100644 tests-expanded/test_logging_wasm32v1-none.rs create mode 100644 tests-expanded/test_macros_tests.rs create mode 100644 tests-expanded/test_macros_wasm32v1-none.rs create mode 100644 tests-expanded/test_modular_tests.rs create mode 100644 tests-expanded/test_modular_wasm32v1-none.rs create mode 100644 tests-expanded/test_multiimpl_tests.rs create mode 100644 tests-expanded/test_multiimpl_wasm32v1-none.rs create mode 100644 tests-expanded/test_udt_tests.rs create mode 100644 tests-expanded/test_udt_wasm32v1-none.rs create mode 100644 tests-expanded/test_workspace_contract_tests.rs create mode 100644 tests-expanded/test_workspace_contract_wasm32v1-none.rs create mode 100644 tests-expanded/test_workspace_lib_tests.rs create mode 100644 tests-expanded/test_zero_tests.rs create mode 100644 tests-expanded/test_zero_wasm32v1-none.rs diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index c087f5f80..0f3638878 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -18,7 +18,7 @@ jobs: complete: if: always() - needs: [fmt, check-git-rev-deps, semver-checks, build-and-test, build-fuzz, docs, readme, migration-docs] + needs: [fmt, check-git-rev-deps, semver-checks, build-and-test, build-fuzz, docs, readme, migration-docs, expand] runs-on: ubuntu-latest steps: - if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') @@ -179,6 +179,21 @@ jobs: git grep "${version}" -- soroban-sdk/src/_migrating.rs \ || (echo "The _migrating ${version} section is missing." && exit 1) + expand-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: stellar/actions/rust-cache@main + - run: rustup update + - run: rustup target add wasm32v1-none + - uses: stellar/binaries@v42 + with: + name: cargo-expand + version: 1.0.116 + - run: make expand-tests + - name: Check no diffs exist + run: git add -N . && git diff HEAD --exit-code + publish-dry-run: if: github.event_name == 'push' || startsWith(github.head_ref, 'release/') strategy: diff --git a/Makefile b/Makefile index 998048171..dacbea09e 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,21 @@ readme: | jq -r '.index[.root|tostring].docs' \ > README.md +# Expands the generated code within each test vector contract that lives in the +# tests/ directory. Serves to surface visible changes in generated code that +# may not be obvious when making changes to sdk macros. +expand-tests: + rm -fr tests-expanded + mkdir -p tests-expanded + cargo metadata --format-version 1 | jq -r '.packages[] | select(.manifest_path | contains("/tests/")) | "\(.name) \(.manifest_path | split("/") | .[:-1] | join("/")) \(any(.targets[]; any(.kind[]; . == "cdylib")))"' | while read package dir is_cdylib; do \ + echo "Expanding $$package for host target including tests"; \ + cargo expand --package $$package --tests | rustfmt > tests-expanded/$${package}_tests.rs; \ + if [ "$$is_cdylib" = "true" ]; then \ + echo "Expanding $$package for wasm32v1-none target without tests"; \ + cargo expand --package $$package --release --target wasm32v1-none | rustfmt > tests-expanded/$${package}_wasm32v1-none.rs; \ + fi; \ + done + fmt: cargo fmt --all diff --git a/tests-expanded/proc_macros_tests.rs b/tests-expanded/proc_macros_tests.rs new file mode 100644 index 000000000..383298ba7 --- /dev/null +++ b/tests-expanded/proc_macros_tests.rs @@ -0,0 +1,33 @@ +#![feature(prelude_import)] +#[macro_use] +extern crate std; +/// A collection of proc-macros used by the test_macros test vector to validate that the +/// soroban-sdk macros are composable and compatible with a variety of other macros. +use proc_macro::TokenStream; +use quote::quote; +#[prelude_import] +use std::prelude::rust_2021::*; +use syn::{parse_macro_input, ItemFn}; +/// An attribute macro that expects to be used on a function. +#[proc_macro_attribute] +pub fn parse_item_fn(_metadata: TokenStream, input: TokenStream) -> TokenStream { + let item = match ::syn::parse::(input) { + ::syn::__private::Ok(data) => data, + ::syn::__private::Err(err) => { + return ::syn::__private::TokenStream::from(err.to_compile_error()); + } + }; + { + let mut _s = ::quote::__private::TokenStream::new(); + ::quote::ToTokens::to_tokens(&item, &mut _s); + _s + } + .into() +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[]) +} diff --git a/tests-expanded/test_account_tests.rs b/tests-expanded/test_account_tests.rs new file mode 100644 index 000000000..66d0283f9 --- /dev/null +++ b/tests-expanded/test_account_tests.rs @@ -0,0 +1,606 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{ + auth::Context, auth::CustomAccountInterface, contract, contracterror, contractimpl, + crypto::Hash, Env, Vec, +}; +pub enum Error { + Fail = 1, +} +#[automatically_derived] +impl ::core::marker::Copy for Error {} +#[automatically_derived] +impl ::core::clone::Clone for Error { + #[inline] + fn clone(&self) -> Error { + *self + } +} +#[automatically_derived] +impl ::core::marker::StructuralPartialEq for Error {} +#[automatically_derived] +impl ::core::cmp::PartialEq for Error { + #[inline] + fn eq(&self, other: &Error) -> bool { + true + } +} +#[automatically_derived] +impl ::core::cmp::Eq for Error { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () {} +} +#[automatically_derived] +impl ::core::cmp::PartialOrd for Error { + #[inline] + fn partial_cmp(&self, other: &Error) -> ::core::option::Option<::core::cmp::Ordering> { + ::core::option::Option::Some(::core::cmp::Ordering::Equal) + } +} +#[automatically_derived] +impl ::core::cmp::Ord for Error { + #[inline] + fn cmp(&self, other: &Error) -> ::core::cmp::Ordering { + ::core::cmp::Ordering::Equal + } +} +pub static __SPEC_XDR_TYPE_ERROR: [u8; 44usize] = Error::spec_xdr(); +impl Error { + pub const fn spec_xdr() -> [u8; 44usize] { + *b"\0\0\0\x04\0\0\0\0\0\0\0\0\0\0\0\x05Error\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\x04Fail\0\0\0\x01" + } +} +impl TryFrom for Error { + type Error = soroban_sdk::Error; + #[inline(always)] + fn try_from(error: soroban_sdk::Error) -> Result { + if error.is_type(soroban_sdk::xdr::ScErrorType::Contract) { + let discriminant = error.get_code(); + Ok(match discriminant { + 1u32 => Self::Fail, + _ => return Err(error), + }) + } else { + Err(error) + } + } +} +impl TryFrom<&soroban_sdk::Error> for Error { + type Error = soroban_sdk::Error; + #[inline(always)] + fn try_from(error: &soroban_sdk::Error) -> Result { + <_ as TryFrom>::try_from(*error) + } +} +impl From for soroban_sdk::Error { + #[inline(always)] + fn from(val: Error) -> soroban_sdk::Error { + <_ as From<&Error>>::from(&val) + } +} +impl From<&Error> for soroban_sdk::Error { + #[inline(always)] + fn from(val: &Error) -> soroban_sdk::Error { + match val { + Error::Fail => soroban_sdk::Error::from_contract_error(1u32), + } + } +} +impl TryFrom for Error { + type Error = soroban_sdk::InvokeError; + #[inline(always)] + fn try_from(error: soroban_sdk::InvokeError) -> Result { + match error { + soroban_sdk::InvokeError::Abort => Err(error), + soroban_sdk::InvokeError::Contract(code) => Ok(match code { + 1u32 => Self::Fail, + _ => return Err(error), + }), + } + } +} +impl TryFrom<&soroban_sdk::InvokeError> for Error { + type Error = soroban_sdk::InvokeError; + #[inline(always)] + fn try_from(error: &soroban_sdk::InvokeError) -> Result { + <_ as TryFrom>::try_from(*error) + } +} +impl From for soroban_sdk::InvokeError { + #[inline(always)] + fn from(val: Error) -> soroban_sdk::InvokeError { + <_ as From<&Error>>::from(&val) + } +} +impl From<&Error> for soroban_sdk::InvokeError { + #[inline(always)] + fn from(val: &Error) -> soroban_sdk::InvokeError { + match val { + Error::Fail => soroban_sdk::InvokeError::Contract(1u32), + } + } +} +impl soroban_sdk::TryFromVal for Error { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::TryIntoVal; + let error: soroban_sdk::Error = val.try_into_val(env)?; + error.try_into().map_err(|_| soroban_sdk::ConversionError) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &Error, + ) -> Result { + let error: soroban_sdk::Error = val.into(); + Ok(error.into()) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&Error, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } +} +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +impl CustomAccountInterface for Contract { + type Error = Error; + type Signature = (); + #[allow(non_snake_case)] + fn __check_auth( + _env: Env, + _signature_payload: Hash<32>, + _signatures: Self::Signature, + _auth_contexts: Vec, + ) -> Result<(), Error> { + Ok(()) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +#[allow(non_snake_case)] +pub mod __Contract____check_auth__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[allow(non_snake_case)] + pub static __SPEC_XDR_FN___CHECK_AUTH: [u8; 156usize] = + super::Contract::spec_xdr___check_auth(); +} +impl Contract { + #[allow(non_snake_case)] + #[allow(non_snake_case)] + pub const fn spec_xdr___check_auth() -> [u8; 156usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x0c__check_auth\0\0\0\x03\0\0\0\0\0\0\0\x11signature_payload\0\0\0\0\0\x03\xee\0\0\0 \0\0\0\0\0\0\0\nsignatures\0\0\0\0\x03\xed\0\0\0\0\0\0\0\0\0\0\0\rauth_contexts\0\0\0\0\0\x03\xea\0\0\x07\xd0\0\0\0\x07Context\0\0\0\0\x01\0\0\x03\xe9\0\0\x03\xed\0\0\0\0\0\0\0\x03" + } +} +impl<'a> ContractClient<'a> {} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn __check_auth<'i>( + _signature_payload: &'i Hash<32>, + _signatures: &'i (), + _auth_contexts: &'i Vec, + ) -> (&'i Hash<32>, &'i (), &'i Vec) { + (_signature_payload, _signatures, _auth_contexts) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +#[allow(non_snake_case)] +pub mod __Contract____check_auth { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).__check_auth` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + use super::CustomAccountInterface; + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::__check_auth( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_2), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).__check_auth` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 3usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 3usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize], args[1usize], args[2usize]) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).__check_auth` instead")] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1, arg_2) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract_CustomAccountInterface_d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor( +) { + ::register( + "__check_auth", + #[allow(deprecated)] + &__Contract____check_auth::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract_CustomAccountInterface_d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract_CustomAccountInterface_d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor() -> usize { + __Contract_CustomAccountInterface_d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor(); + 0 + } + __Contract_CustomAccountInterface_d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor +}; +mod test { + use crate::Contract; + use soroban_sdk::{ + contract, + testutils::{MockAuth, MockAuthInvoke}, + Env, IntoVal, + }; + struct TestContract; + ///TestContractArgs is a type for building arg lists for functions defined in "TestContract". + pub struct TestContractArgs; + ///TestContractClient is a client for calling the contract defined in "TestContract". + pub struct TestContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, + } + impl<'a> TestContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } + } + mod __testcontract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } + } + impl soroban_sdk::testutils::ContractFunctionRegister for TestContract { + fn register(name: &'static str, func: &'static __testcontract_fn_set_registry::F) { + __testcontract_fn_set_registry::register(name, func); + } + } + #[doc(hidden)] + impl soroban_sdk::testutils::ContractFunctionSet for TestContract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __testcontract_fn_set_registry::call(func, env, args) + } + } + extern crate test; + #[rustc_test_marker = "test::test"] + #[doc(hidden)] + pub const test: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/account/src/lib.rs", + start_line: 45usize, + start_col: 8usize, + end_line: 45usize, + end_col: 12usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test()), + ), + }; + fn test() { + let e = Env::default(); + let test_contract_id = e.register(TestContract, ()); + let contract_id = e.register(Contract, ()); + e.set_auths(&[MockAuth { + address: &contract_id, + invoke: &MockAuthInvoke { + contract: &test_contract_id, + fn_name: "", + args: ().into_val(&e), + sub_invokes: &[], + }, + } + .into()]); + e.as_contract(&test_contract_id, || contract_id.require_auth()); + } +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[&test]) +} diff --git a/tests-expanded/test_account_wasm32v1-none.rs b/tests-expanded/test_account_wasm32v1-none.rs new file mode 100644 index 000000000..fbf76138b --- /dev/null +++ b/tests-expanded/test_account_wasm32v1-none.rs @@ -0,0 +1,276 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{ + auth::Context, auth::CustomAccountInterface, contract, contracterror, contractimpl, + crypto::Hash, Env, Vec, +}; +pub enum Error { + Fail = 1, +} +#[automatically_derived] +impl ::core::marker::Copy for Error {} +#[automatically_derived] +impl ::core::clone::Clone for Error { + #[inline] + fn clone(&self) -> Error { + *self + } +} +#[automatically_derived] +impl ::core::marker::StructuralPartialEq for Error {} +#[automatically_derived] +impl ::core::cmp::PartialEq for Error { + #[inline] + fn eq(&self, other: &Error) -> bool { + true + } +} +#[automatically_derived] +impl ::core::cmp::Eq for Error { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () {} +} +#[automatically_derived] +impl ::core::cmp::PartialOrd for Error { + #[inline] + fn partial_cmp(&self, other: &Error) -> ::core::option::Option<::core::cmp::Ordering> { + ::core::option::Option::Some(::core::cmp::Ordering::Equal) + } +} +#[automatically_derived] +impl ::core::cmp::Ord for Error { + #[inline] + fn cmp(&self, other: &Error) -> ::core::cmp::Ordering { + ::core::cmp::Ordering::Equal + } +} +#[link_section = "contractspecv0"] +pub static __SPEC_XDR_TYPE_ERROR: [u8; 44usize] = Error::spec_xdr(); +impl Error { + pub const fn spec_xdr() -> [u8; 44usize] { + *b"\0\0\0\x04\0\0\0\0\0\0\0\0\0\0\0\x05Error\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\x04Fail\0\0\0\x01" + } +} +impl TryFrom for Error { + type Error = soroban_sdk::Error; + #[inline(always)] + fn try_from(error: soroban_sdk::Error) -> Result { + if error.is_type(soroban_sdk::xdr::ScErrorType::Contract) { + let discriminant = error.get_code(); + Ok(match discriminant { + 1u32 => Self::Fail, + _ => return Err(error), + }) + } else { + Err(error) + } + } +} +impl TryFrom<&soroban_sdk::Error> for Error { + type Error = soroban_sdk::Error; + #[inline(always)] + fn try_from(error: &soroban_sdk::Error) -> Result { + <_ as TryFrom>::try_from(*error) + } +} +impl From for soroban_sdk::Error { + #[inline(always)] + fn from(val: Error) -> soroban_sdk::Error { + <_ as From<&Error>>::from(&val) + } +} +impl From<&Error> for soroban_sdk::Error { + #[inline(always)] + fn from(val: &Error) -> soroban_sdk::Error { + match val { + Error::Fail => soroban_sdk::Error::from_contract_error(1u32), + } + } +} +impl TryFrom for Error { + type Error = soroban_sdk::InvokeError; + #[inline(always)] + fn try_from(error: soroban_sdk::InvokeError) -> Result { + match error { + soroban_sdk::InvokeError::Abort => Err(error), + soroban_sdk::InvokeError::Contract(code) => Ok(match code { + 1u32 => Self::Fail, + _ => return Err(error), + }), + } + } +} +impl TryFrom<&soroban_sdk::InvokeError> for Error { + type Error = soroban_sdk::InvokeError; + #[inline(always)] + fn try_from(error: &soroban_sdk::InvokeError) -> Result { + <_ as TryFrom>::try_from(*error) + } +} +impl From for soroban_sdk::InvokeError { + #[inline(always)] + fn from(val: Error) -> soroban_sdk::InvokeError { + <_ as From<&Error>>::from(&val) + } +} +impl From<&Error> for soroban_sdk::InvokeError { + #[inline(always)] + fn from(val: &Error) -> soroban_sdk::InvokeError { + match val { + Error::Fail => soroban_sdk::InvokeError::Contract(1u32), + } + } +} +impl soroban_sdk::TryFromVal for Error { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::TryIntoVal; + let error: soroban_sdk::Error = val.try_into_val(env)?; + error.try_into().map_err(|_| soroban_sdk::ConversionError) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &Error, + ) -> Result { + let error: soroban_sdk::Error = val.into(); + Ok(error.into()) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&Error, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } +} +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl CustomAccountInterface for Contract { + type Error = Error; + type Signature = (); + #[allow(non_snake_case)] + fn __check_auth( + _env: Env, + _signature_payload: Hash<32>, + _signatures: Self::Signature, + _auth_contexts: Vec, + ) -> Result<(), Error> { + Ok(()) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +#[allow(non_snake_case)] +pub mod __Contract____check_auth__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[allow(non_snake_case)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN___CHECK_AUTH: [u8; 156usize] = + super::Contract::spec_xdr___check_auth(); +} +impl Contract { + #[allow(non_snake_case)] + #[allow(non_snake_case)] + pub const fn spec_xdr___check_auth() -> [u8; 156usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x0c__check_auth\0\0\0\x03\0\0\0\0\0\0\0\x11signature_payload\0\0\0\0\0\x03\xee\0\0\0 \0\0\0\0\0\0\0\nsignatures\0\0\0\0\x03\xed\0\0\0\0\0\0\0\0\0\0\0\rauth_contexts\0\0\0\0\0\x03\xea\0\0\x07\xd0\0\0\0\x07Context\0\0\0\0\x01\0\0\x03\xe9\0\0\x03\xed\0\0\0\0\0\0\0\x03" + } +} +impl<'a> ContractClient<'a> {} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn __check_auth<'i>( + _signature_payload: &'i Hash<32>, + _signatures: &'i (), + _auth_contexts: &'i Vec, + ) -> (&'i Hash<32>, &'i (), &'i Vec) { + (_signature_payload, _signatures, _auth_contexts) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +#[allow(non_snake_case)] +pub mod __Contract____check_auth { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).__check_auth` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + use super::CustomAccountInterface; + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::__check_auth( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_2), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).__check_auth` instead")] + #[export_name = "__check_auth"] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1, arg_2) + } + use super::*; +} diff --git a/tests-expanded/test_add_i128_tests.rs b/tests-expanded/test_add_i128_tests.rs new file mode 100644 index 000000000..618094b27 --- /dev/null +++ b/tests-expanded/test_add_i128_tests.rs @@ -0,0 +1,368 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +impl Contract { + pub fn add(a: i128, b: i128) -> i128 { + a + b + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_ADD: [u8; 60usize] = super::Contract::spec_xdr_add(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_add() -> [u8; 60usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x0b\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x0b\0\0\0\x01\0\0\0\x0b" + } +} +impl<'a> ContractClient<'a> { + pub fn add(&self, a: &i128, b: &i128) -> i128 { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_add( + &self, + a: &i128, + b: &i128, + ) -> Result< + Result>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn add<'i>(a: &'i i128, b: &'i i128) -> (&'i i128, &'i i128) { + (a, b) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::add( + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 2usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 2usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize], args[1usize]) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add` instead")] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor() { + ::register( + "add", + #[allow(deprecated)] + &__Contract__add::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor() -> usize { + __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor(); + 0 + } + __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor +}; +mod test { + use crate::{Contract, ContractClient}; + use soroban_sdk::Env; + extern crate test; + #[rustc_test_marker = "test::test_add"] + #[doc(hidden)] + pub const test_add: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test_add"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/add_i128/src/lib.rs", + start_line: 21usize, + start_col: 8usize, + end_line: 21usize, + end_col: 16usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_add()), + ), + }; + fn test_add() { + let e = Env::default(); + let contract_id = e.register(Contract, ()); + let client = ContractClient::new(&e, &contract_id); + let x = 2i128.pow(70); + let y = 4i128.pow(20); + let z = client.add(&x, &y); + if !(z == x + y) { + ::core::panicking::panic("assertion failed: z == x + y") + } + } +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[&test_add]) +} diff --git a/tests-expanded/test_add_i128_wasm32v1-none.rs b/tests-expanded/test_add_i128_wasm32v1-none.rs new file mode 100644 index 000000000..7aeee3f27 --- /dev/null +++ b/tests-expanded/test_add_i128_wasm32v1-none.rs @@ -0,0 +1,135 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl Contract { + pub fn add(a: i128, b: i128) -> i128 { + a + b + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_ADD: [u8; 60usize] = super::Contract::spec_xdr_add(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_add() -> [u8; 60usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x0b\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x0b\0\0\0\x01\0\0\0\x0b" + } +} +impl<'a> ContractClient<'a> { + pub fn add(&self, a: &i128, b: &i128) -> i128 { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + res + } + pub fn try_add( + &self, + a: &i128, + b: &i128, + ) -> Result< + Result>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn add<'i>(a: &'i i128, b: &'i i128) -> (&'i i128, &'i i128) { + (a, b) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::add( + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add` instead")] + #[export_name = "add"] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} diff --git a/tests-expanded/test_add_u128_tests.rs b/tests-expanded/test_add_u128_tests.rs new file mode 100644 index 000000000..72447bcc9 --- /dev/null +++ b/tests-expanded/test_add_u128_tests.rs @@ -0,0 +1,368 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +impl Contract { + pub fn add(a: u128, b: u128) -> u128 { + a + b + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_ADD: [u8; 60usize] = super::Contract::spec_xdr_add(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_add() -> [u8; 60usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\n\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\n\0\0\0\x01\0\0\0\n" + } +} +impl<'a> ContractClient<'a> { + pub fn add(&self, a: &u128, b: &u128) -> u128 { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_add( + &self, + a: &u128, + b: &u128, + ) -> Result< + Result>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn add<'i>(a: &'i u128, b: &'i u128) -> (&'i u128, &'i u128) { + (a, b) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::add( + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 2usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 2usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize], args[1usize]) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add` instead")] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor() { + ::register( + "add", + #[allow(deprecated)] + &__Contract__add::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor() -> usize { + __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor(); + 0 + } + __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor +}; +mod test { + use crate::{Contract, ContractClient}; + use soroban_sdk::Env; + extern crate test; + #[rustc_test_marker = "test::test_add"] + #[doc(hidden)] + pub const test_add: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test_add"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/add_u128/src/lib.rs", + start_line: 21usize, + start_col: 8usize, + end_line: 21usize, + end_col: 16usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_add()), + ), + }; + fn test_add() { + let e = Env::default(); + let contract_id = e.register(Contract, ()); + let client = ContractClient::new(&e, &contract_id); + let x = 2u128.pow(70); + let y = 4u128.pow(20); + let z = client.add(&x, &y); + if !(z == x + y) { + ::core::panicking::panic("assertion failed: z == x + y") + } + } +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[&test_add]) +} diff --git a/tests-expanded/test_add_u128_wasm32v1-none.rs b/tests-expanded/test_add_u128_wasm32v1-none.rs new file mode 100644 index 000000000..513a58368 --- /dev/null +++ b/tests-expanded/test_add_u128_wasm32v1-none.rs @@ -0,0 +1,135 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl Contract { + pub fn add(a: u128, b: u128) -> u128 { + a + b + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_ADD: [u8; 60usize] = super::Contract::spec_xdr_add(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_add() -> [u8; 60usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\n\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\n\0\0\0\x01\0\0\0\n" + } +} +impl<'a> ContractClient<'a> { + pub fn add(&self, a: &u128, b: &u128) -> u128 { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + res + } + pub fn try_add( + &self, + a: &u128, + b: &u128, + ) -> Result< + Result>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn add<'i>(a: &'i u128, b: &'i u128) -> (&'i u128, &'i u128) { + (a, b) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::add( + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add` instead")] + #[export_name = "add"] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} diff --git a/tests-expanded/test_add_u64_tests.rs b/tests-expanded/test_add_u64_tests.rs new file mode 100644 index 000000000..8385950c2 --- /dev/null +++ b/tests-expanded/test_add_u64_tests.rs @@ -0,0 +1,368 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +impl Contract { + pub fn add(a: u64, b: u64) -> u64 { + a + b + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_ADD: [u8; 60usize] = super::Contract::spec_xdr_add(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_add() -> [u8; 60usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x06\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x06\0\0\0\x01\0\0\0\x06" + } +} +impl<'a> ContractClient<'a> { + pub fn add(&self, a: &u64, b: &u64) -> u64 { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_add( + &self, + a: &u64, + b: &u64, + ) -> Result< + Result>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn add<'i>(a: &'i u64, b: &'i u64) -> (&'i u64, &'i u64) { + (a, b) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::add( + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 2usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 2usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize], args[1usize]) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add` instead")] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor() { + ::register( + "add", + #[allow(deprecated)] + &__Contract__add::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor() -> usize { + __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor(); + 0 + } + __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor +}; +mod test { + use crate::{Contract, ContractClient}; + use soroban_sdk::Env; + extern crate test; + #[rustc_test_marker = "test::test_add"] + #[doc(hidden)] + pub const test_add: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test_add"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/add_u64/src/lib.rs", + start_line: 21usize, + start_col: 8usize, + end_line: 21usize, + end_col: 16usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_add()), + ), + }; + fn test_add() { + let e = Env::default(); + let contract_id = e.register(Contract, ()); + let client = ContractClient::new(&e, &contract_id); + let x = 10u64; + let y = 12u64; + let z = client.add(&x, &y); + if !(z == 22) { + ::core::panicking::panic("assertion failed: z == 22") + } + } +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[&test_add]) +} diff --git a/tests-expanded/test_add_u64_wasm32v1-none.rs b/tests-expanded/test_add_u64_wasm32v1-none.rs new file mode 100644 index 000000000..2da2616b4 --- /dev/null +++ b/tests-expanded/test_add_u64_wasm32v1-none.rs @@ -0,0 +1,135 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl Contract { + pub fn add(a: u64, b: u64) -> u64 { + a + b + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_ADD: [u8; 60usize] = super::Contract::spec_xdr_add(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_add() -> [u8; 60usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x06\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x06\0\0\0\x01\0\0\0\x06" + } +} +impl<'a> ContractClient<'a> { + pub fn add(&self, a: &u64, b: &u64) -> u64 { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + res + } + pub fn try_add( + &self, + a: &u64, + b: &u64, + ) -> Result< + Result>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn add<'i>(a: &'i u64, b: &'i u64) -> (&'i u64, &'i u64) { + (a, b) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::add( + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add` instead")] + #[export_name = "add"] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} diff --git a/tests-expanded/test_alloc_tests.rs b/tests-expanded/test_alloc_tests.rs new file mode 100644 index 000000000..2527f7208 --- /dev/null +++ b/tests-expanded/test_alloc_tests.rs @@ -0,0 +1,640 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl, Env}; +extern crate alloc; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +impl Contract { + pub fn num_list(env: Env, count: u32) -> soroban_sdk::Vec { + let mut v1 = ::alloc::vec::Vec::new(); + (0..count).for_each(|i| v1.push(i)); + let mut v2 = ::soroban_sdk::Vec::new(&env); + for i in v1 { + v2.push_back(i); + } + v2 + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__num_list__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_NUM_LIST: [u8; 56usize] = super::Contract::spec_xdr_num_list(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_num_list() -> [u8; 56usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x08num_list\0\0\0\x01\0\0\0\0\0\0\0\x05count\0\0\0\0\0\0\x04\0\0\0\x01\0\0\x03\xea\0\0\0\x04" + } +} +impl<'a> ContractClient<'a> { + pub fn num_list(&self, count: &u32) -> soroban_sdk::Vec { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("num_list"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [count.into_val(&self.env)]), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_num_list( + &self, + count: &u32, + ) -> Result< + Result< + soroban_sdk::Vec, + as soroban_sdk::TryFromVal< + soroban_sdk::Env, + soroban_sdk::Val, + >>::Error, + >, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("num_list"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [count.into_val(&self.env)]), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn num_list<'i>(count: &'i u32) -> (&'i u32,) { + (count,) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__num_list { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).num_list` instead")] + pub fn invoke_raw(env: soroban_sdk::Env, arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::num_list( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).num_list` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 1usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 1usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize]) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).num_list` instead")] + pub extern "C" fn invoke_raw_extern(arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__526e07cb9219443e6b3ef052e7872bf9e5bfee9b91633ed921601b5e93014bb7_ctor() { + ::register( + "num_list", + #[allow(deprecated)] + &__Contract__num_list::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__526e07cb9219443e6b3ef052e7872bf9e5bfee9b91633ed921601b5e93014bb7_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__526e07cb9219443e6b3ef052e7872bf9e5bfee9b91633ed921601b5e93014bb7_ctor___rust_ctor___ctor() -> usize { + __Contract__526e07cb9219443e6b3ef052e7872bf9e5bfee9b91633ed921601b5e93014bb7_ctor(); + 0 + } + __Contract__526e07cb9219443e6b3ef052e7872bf9e5bfee9b91633ed921601b5e93014bb7_ctor___rust_ctor___ctor +}; +mod test { + use crate::{Contract, ContractClient}; + use soroban_sdk::{testutils::EnvTestConfig, vec, Env}; + mod imported { + pub const WASM: &[u8] = b"\0asm\x01\0\0\0\x01#\x07`\0\x01~`\x02~~\x01~`\x01\x7f\0`\0\0`\x01\x7f\x01\x7f`\x01~\x01~`\x03\x7f\x7f\x7f\x01\x7f\x02\r\x02\x01v\x01_\0\0\x01v\x016\0\x01\x03\r\x0c\x02\x03\x04\x03\x02\x05\x02\x02\x03\x03\x06\x06\x04\x05\x01p\x01\x01\x01\x05\x03\x01\0\x11\x06!\x04\x7f\x01A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x88\x80\xc0\0\x0b\x7f\0A\x90\x80\xc0\0\x0b\x074\x05\x06memory\x02\0\x08num_list\0\x07\x01_\x03\x01\n__data_end\x03\x02\x0b__heap_base\x03\x03\n\xf9\r\x0c\xab\x02\x01\x06\x7f\x02@\x02@ \0(\x02\0\"\x01A\x01tA\x01 \x01\x1b\"\x02A\xff\xff\xff\xff\x03K\r\0 \x02A\x04 \x02A\x04K\x1b\"\x03A\x02t\"\x04A\xfd\xff\xff\xff\x07O\r\0\x02@\x02@ \x01E\r\0 \0(\x02\x04!\x05\x10\x83\x80\x80\x80\0A\0(\x02\x80\x80\xc0\x80\0\"\x02A\x03j\"\x06 \x02I\r\x02\x02@\x02@ \x06A|q\"\x02 \x04j\"\x06A\0(\x02\x84\x80\xc0\x80\0M\r\0 \x04\x10\x84\x80\x80\x80\0!\x02\x0c\x01\x0bA\0 \x066\x02\x80\x80\xc0\x80\0\x0b \x02E\r\x03 \x02 \x05 \x01A\x02t\x10\x8d\x80\x80\x80\0\x1a\x0c\x01\x0b\x10\x83\x80\x80\x80\0A\0(\x02\x80\x80\xc0\x80\0\"\x02A\x03j\"\x01 \x02I\r\x01\x02@\x02@ \x01A|q\"\x02 \x04j\"\x01A\0(\x02\x84\x80\xc0\x80\0M\r\0 \x04\x10\x84\x80\x80\x80\0!\x02\x0c\x01\x0bA\0 \x016\x02\x80\x80\xc0\x80\0\x0b \x02E\r\x02\x0b \0 \x036\x02\0 \0 \x026\x02\x04\x0f\x0b\x10\x85\x80\x80\x80\0\0\x0b \x04\x10\x86\x80\x80\x80\0\0\x0bC\x01\x01\x7f\x02@\x02@A\0(\x02\x84\x80\xc0\x80\0\r\0?\0\"\0A\xff\xff\x03K\r\x01A\0 \0A\x10t\"\06\x02\x84\x80\xc0\x80\0A\0 \06\x02\x80\x80\xc0\x80\0\x0b\x0f\x0b\x10\x85\x80\x80\x80\0\0\x0b\x91\x01\x01\x04\x7f \0A\xff\xff\x03j\"\x01A\x80\x80|q!\x02 \x01A\x10v!\x03\x02@\x02@\x03@ \x03@\0A\x7fF\r\x01A\0A\0(\x02\x84\x80\xc0\x80\0 \x02j6\x02\x84\x80\xc0\x80\0\x10\x83\x80\x80\x80\0A\0(\x02\x80\x80\xc0\x80\0\"\x01A\x03j\"\x04 \x01I\r\x02 \x04A|q\"\x01 \0j\"\x04A\0(\x02\x84\x80\xc0\x80\0K\r\0\x0bA\0 \x046\x02\x80\x80\xc0\x80\0 \x01\x0f\x0b\x10\x8b\x80\x80\x80\0\0\x0b\x10\x85\x80\x80\x80\0\0\x0b\t\0\x10\x8a\x80\x80\x80\0\0\x0b\x0b\0 \0\x10\x88\x80\x80\x80\0\0\x0b\xee\x01\x01\x05\x7f#\x80\x80\x80\x80\0A\x10k\"\x01$\x80\x80\x80\x80\0\x02@ \0B\xff\x01\x83B\x04R\r\0 \0B \x88\xa7!\x02A\0!\x03 \x01A\06\x02\x0c \x01B\x80\x80\x80\x80\xc0\07\x02\x04A\x04!\x04A\0!\x05\x02@\x03@ \x02 \x05F\r\x01\x02@ \x05 \x01(\x02\x04G\r\0 \x01A\x04j\x10\x82\x80\x80\x80\0 \x01(\x02\x08!\x04\x0b \x04 \x03j \x056\x02\0 \x01 \x05A\x01j\"\x056\x02\x0c \x03A\x04j!\x03 \x05!\x05\x0c\0\x0b\x0b \x02A\x02t!\x05\x10\x80\x80\x80\x80\0!\0 \x01(\x02\x08!\x03\x02@\x03@ \x05E\r\x01 \x05A|j!\x05 \0 \x035\x02\0B \x86B\x04\x84\x10\x81\x80\x80\x80\0!\0 \x03A\x04j!\x03\x0c\0\x0b\x0b \x01A\x10j$\x80\x80\x80\x80\0 \0\x0f\x0b\0\x0b\x0b\0 \0\x10\x89\x80\x80\x80\0\0\x0b\t\0\x10\x8a\x80\x80\x80\0\0\x0b\x03\0\0\x0b\t\0\x10\x85\x80\x80\x80\0\0\x0b\xb9\x07\x01\x0c\x7f#\x80\x80\x80\x80\0A\x10k!\x03\x02@\x02@ \x02A\x10O\r\0 \0!\x04\x0c\x01\x0b\x02@ \0 \0A\0 \0kA\x03q\"\x05j\"\x06O\r\0 \x05A\x7fj!\x07 \0!\x04 \x01!\x08\x02@ \x05E\r\0 \x05!\t \0!\x04 \x01!\x08\x03@ \x04 \x08-\0\0:\0\0 \x08A\x01j!\x08 \x04A\x01j!\x04 \tA\x7fj\"\t\r\0\x0b\x0b \x07A\x07I\r\0\x03@ \x04 \x08-\0\0:\0\0 \x04A\x01j \x08A\x01j-\0\0:\0\0 \x04A\x02j \x08A\x02j-\0\0:\0\0 \x04A\x03j \x08A\x03j-\0\0:\0\0 \x04A\x04j \x08A\x04j-\0\0:\0\0 \x04A\x05j \x08A\x05j-\0\0:\0\0 \x04A\x06j \x08A\x06j-\0\0:\0\0 \x04A\x07j \x08A\x07j-\0\0:\0\0 \x08A\x08j!\x08 \x04A\x08j\"\x04 \x06G\r\0\x0b\x0b \x06 \x02 \x05k\"\tA|q\"\x07j!\x04\x02@\x02@ \x01 \x05j\"\x08A\x03q\"\x01\r\0 \x06 \x04O\r\x01 \x08!\x01\x03@ \x06 \x01(\x02\06\x02\0 \x01A\x04j!\x01 \x06A\x04j\"\x06 \x04I\r\0\x0c\x02\x0b\x0bA\0!\x02 \x03A\06\x02\x0c \x03A\x0cj \x01r!\x05\x02@A\x04 \x01k\"\nA\x01qE\r\0 \x05 \x08-\0\0:\0\0A\x01!\x02\x0b\x02@ \nA\x02qE\r\0 \x05 \x02j \x08 \x02j/\x01\0;\x01\0\x0b \x08 \x01k!\x02 \x01A\x03t!\x0b \x03(\x02\x0c!\x05\x02@\x02@ \x06A\x04j \x04I\r\0 \x06!\x0c\x0c\x01\x0bA\0 \x0bkA\x18q!\r\x03@ \x06 \x05 \x0bv \x02A\x04j\"\x02(\x02\0\"\x05 \rtr6\x02\0 \x06A\x08j!\n \x06A\x04j\"\x0c!\x06 \n \x04I\r\0\x0b\x0bA\0!\x06 \x03A\0:\0\x08 \x03A\0:\0\x06\x02@\x02@ \x01A\x01G\r\0 \x03A\x08j!\rA\0!\x01A\0!\nA\0!\x0e\x0c\x01\x0b \x02A\x05j-\0\0!\n \x03 \x02A\x04j-\0\0\"\x01:\0\x08 \nA\x08t!\nA\x02!\x0e \x03A\x06j!\r\x0b\x02@ \x08A\x01qE\r\0 \r \x02A\x04j \x0ej-\0\0:\0\0 \x03-\0\x06A\x10t!\x06 \x03-\0\x08!\x01\x0b \x0c \n \x06r \x01A\xff\x01qrA\0 \x0bkA\x18qt \x05 \x0bvr6\x02\0\x0b \tA\x03q!\x02 \x08 \x07j!\x01\x0b\x02@ \x04 \x04 \x02j\"\x06O\r\0 \x02A\x7fj!\t\x02@ \x02A\x07q\"\x08E\r\0\x03@ \x04 \x01-\0\0:\0\0 \x01A\x01j!\x01 \x04A\x01j!\x04 \x08A\x7fj\"\x08\r\0\x0b\x0b \tA\x07I\r\0\x03@ \x04 \x01-\0\0:\0\0 \x04A\x01j \x01A\x01j-\0\0:\0\0 \x04A\x02j \x01A\x02j-\0\0:\0\0 \x04A\x03j \x01A\x03j-\0\0:\0\0 \x04A\x04j \x01A\x04j-\0\0:\0\0 \x04A\x05j \x01A\x05j-\0\0:\0\0 \x04A\x06j \x01A\x06j-\0\0:\0\0 \x04A\x07j \x01A\x07j-\0\0:\0\0 \x01A\x08j!\x01 \x04A\x08j\"\x04 \x06G\r\0\x0b\x0b \0\x0b\x0e\0 \0 \x01 \x02\x10\x8c\x80\x80\x80\0\x0b\x0b\t\x01\0A\x80\x80\xc0\0\x0b\0\0G\x0econtractspecv0\0\0\0\0\0\0\0\0\0\0\0\x08num_list\0\0\0\x01\0\0\0\0\0\0\0\x05count\0\0\0\0\0\0\x04\0\0\0\x01\0\0\x03\xea\0\0\0\x04\0\x1e\x11contractenvmetav0\0\0\0\0\0\0\0\x17\0\0\0\0\0w\x0econtractmetav0\0\0\0\0\0\0\0\x05rsver\0\0\0\0\0\0\x061.89.0\0\0\0\0\0\0\0\0\0\x08rssdkver\0\0\0523.0.2#07757a358c22c45669af2bf51500ae83c33f9a26-dirty\0\0\0"; + pub trait Contract { + fn num_list(env: soroban_sdk::Env, count: u32) -> soroban_sdk::Vec; + } + ///Client is a client for calling the contract defined in "Contract". + pub struct Client<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, + } + impl<'a> Client<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths( + &self, + auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry], + ) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths( + &self, + mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>], + ) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } + } + impl<'a> Client<'a> { + pub fn num_list(&self, count: &u32) -> soroban_sdk::Vec { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("num_list"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [count.into_val(&self.env)]), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_num_list( + &self, + count: &u32, + ) -> Result< + Result< + soroban_sdk::Vec, + as soroban_sdk::TryFromVal< + soroban_sdk::Env, + soroban_sdk::Val, + >>::Error, + >, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("num_list"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [count.into_val(&self.env)]), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + } + ///Args is a type for building arg lists for functions defined in "Contract". + pub struct Args; + impl Args { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn num_list<'i>(count: &'i u32) -> (&'i u32,) { + (count,) + } + } + } + mod native { + use super::*; + extern crate test; + #[rustc_test_marker = "test::native::test"] + #[doc(hidden)] + pub const test: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::native::test"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/alloc/src/test.rs", + start_line: 16usize, + start_col: 16usize, + end_line: 16usize, + end_col: 20usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test()), + ), + }; + fn test() { + let e = Env::new_with_config(EnvTestConfig { + capture_snapshot_at_drop: false, + }); + let contract_id = e.register(Contract, ()); + let client = ContractClient::new(&e, &contract_id); + let list = client.num_list(&50); + match ( + &list, + &::soroban_sdk::Vec::from_array( + &e, + [ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, + ], + ), + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + } + } + } + mod wasm { + use super::*; + extern crate test; + #[rustc_test_marker = "test::wasm::test"] + #[doc(hidden)] + pub const test: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::wasm::test"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/alloc/src/test.rs", + start_line: 16usize, + start_col: 16usize, + end_line: 16usize, + end_col: 20usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test()), + ), + }; + fn test() { + let e = Env::new_with_config(EnvTestConfig { + capture_snapshot_at_drop: false, + }); + let contract_id = e.register(imported::WASM, ()); + let client = ContractClient::new(&e, &contract_id); + let list = client.num_list(&50); + match ( + &list, + &::soroban_sdk::Vec::from_array( + &e, + [ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, + ], + ), + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + } + } + } +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[&test, &test]) +} diff --git a/tests-expanded/test_alloc_wasm32v1-none.rs b/tests-expanded/test_alloc_wasm32v1-none.rs new file mode 100644 index 000000000..17e2683ca --- /dev/null +++ b/tests-expanded/test_alloc_wasm32v1-none.rs @@ -0,0 +1,129 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl, Env}; +extern crate alloc; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl Contract { + pub fn num_list(env: Env, count: u32) -> soroban_sdk::Vec { + let mut v1 = ::alloc::vec::Vec::new(); + (0..count).for_each(|i| v1.push(i)); + let mut v2 = ::soroban_sdk::Vec::new(&env); + for i in v1 { + v2.push_back(i); + } + v2 + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__num_list__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_NUM_LIST: [u8; 56usize] = super::Contract::spec_xdr_num_list(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_num_list() -> [u8; 56usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x08num_list\0\0\0\x01\0\0\0\0\0\0\0\x05count\0\0\0\0\0\0\x04\0\0\0\x01\0\0\x03\xea\0\0\0\x04" + } +} +impl<'a> ContractClient<'a> { + pub fn num_list(&self, count: &u32) -> soroban_sdk::Vec { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("num_list"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [count.into_val(&self.env)]), + ); + res + } + pub fn try_num_list( + &self, + count: &u32, + ) -> Result< + Result< + soroban_sdk::Vec, + as soroban_sdk::TryFromVal< + soroban_sdk::Env, + soroban_sdk::Val, + >>::Error, + >, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("num_list"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [count.into_val(&self.env)]), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn num_list<'i>(count: &'i u32) -> (&'i u32,) { + (count,) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__num_list { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).num_list` instead")] + pub fn invoke_raw(env: soroban_sdk::Env, arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::num_list( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).num_list` instead")] + #[export_name = "num_list"] + pub extern "C" fn invoke_raw_extern(arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0) + } + use super::*; +} diff --git a/tests-expanded/test_auth_tests.rs b/tests-expanded/test_auth_tests.rs new file mode 100644 index 000000000..cdd23c585 --- /dev/null +++ b/tests-expanded/test_auth_tests.rs @@ -0,0 +1,2836 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl, Address, Env, IntoVal}; +pub struct ContractA; +///ContractAArgs is a type for building arg lists for functions defined in "ContractA". +pub struct ContractAArgs; +///ContractAClient is a client for calling the contract defined in "ContractA". +pub struct ContractAClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractAClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contracta_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for ContractA { + fn register(name: &'static str, func: &'static __contracta_fn_set_registry::F) { + __contracta_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for ContractA { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contracta_fn_set_registry::call(func, env, args) + } +} +impl ContractA { + pub fn fn1(a: Address) -> u64 { + a.require_auth(); + 2 + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __ContractA__fn1__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_FN1: [u8; 44usize] = super::ContractA::spec_xdr_fn1(); +} +impl ContractA { + #[allow(non_snake_case)] + pub const fn spec_xdr_fn1() -> [u8; 44usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03fn1\0\0\0\0\x01\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x13\0\0\0\x01\0\0\0\x06" + } +} +impl<'a> ContractAClient<'a> { + pub fn fn1(&self, a: &Address) -> u64 { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("fn1"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [a.into_val(&self.env)]), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_fn1( + &self, + a: &Address, + ) -> Result< + Result>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("fn1"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [a.into_val(&self.env)]), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractAArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn fn1<'i>(a: &'i Address) -> (&'i Address,) { + (a,) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __ContractA__fn1 { + use super::*; + #[deprecated(note = "use `ContractAClient::new(&env, &contract_id).fn1` instead")] + pub fn invoke_raw(env: soroban_sdk::Env, arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::fn1( + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractAClient::new(&env, &contract_id).fn1` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 1usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 1usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize]) + } + #[deprecated(note = "use `ContractAClient::new(&env, &contract_id).fn1` instead")] + pub extern "C" fn invoke_raw_extern(arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __ContractA__7c3764b58a7ababbe8a6b452f6a400d8ae3704b80f8c5ea1b251eebbc8698020_ctor() { + ::register( + "fn1", + #[allow(deprecated)] + &__ContractA__fn1::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __ContractA__7c3764b58a7ababbe8a6b452f6a400d8ae3704b80f8c5ea1b251eebbc8698020_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __ContractA__7c3764b58a7ababbe8a6b452f6a400d8ae3704b80f8c5ea1b251eebbc8698020_ctor___rust_ctor___ctor() -> usize { + __ContractA__7c3764b58a7ababbe8a6b452f6a400d8ae3704b80f8c5ea1b251eebbc8698020_ctor(); + 0 + } + __ContractA__7c3764b58a7ababbe8a6b452f6a400d8ae3704b80f8c5ea1b251eebbc8698020_ctor___rust_ctor___ctor +}; +mod test_a { + use super::*; + use soroban_sdk::{ + contracterror, + testutils::{ + Address as _, AuthorizedFunction, AuthorizedInvocation, MockAuth, MockAuthInvoke, + }, + xdr::{ + InvokeContractArgs, ScAddress, ScError, ScErrorCode, ScVal, SorobanAddressCredentials, + SorobanAuthorizationEntry, SorobanAuthorizedFunction, SorobanAuthorizedInvocation, + SorobanCredentials, StringM, VecM, + }, + Address, Env, Error, Symbol, Val, + }; + extern crate std; + extern crate test; + #[rustc_test_marker = "test_a::test_with_mock_all_auth"] + #[doc(hidden)] + pub const test_with_mock_all_auth: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test_a::test_with_mock_all_auth"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/auth/src/lib.rs", + start_line: 33usize, + start_col: 8usize, + end_line: 33usize, + end_col: 31usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_with_mock_all_auth()), + ), + }; + fn test_with_mock_all_auth() { + let e = Env::default(); + let contract_id = e.register(ContractA, ()); + let client = ContractAClient::new(&e, &contract_id); + let a = Address::generate(&e); + let r = client.mock_all_auths().fn1(&a); + match (&r, &2) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match ( + &e.auths(), + &<[_]>::into_vec(::alloc::boxed::box_new([( + a.clone(), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + contract_id.clone(), + Symbol::new(&e, "fn1"), + (&a,).into_val(&e), + )), + sub_invocations: ::alloc::vec::Vec::new(), + }, + )])), + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + } + extern crate test; + #[rustc_test_marker = "test_a::test_with_mock_auth"] + #[doc(hidden)] + pub const test_with_mock_auth: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test_a::test_with_mock_auth"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/auth/src/lib.rs", + start_line: 60usize, + start_col: 8usize, + end_line: 60usize, + end_col: 27usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_with_mock_auth()), + ), + }; + fn test_with_mock_auth() { + let e = Env::default(); + let contract_id = e.register(ContractA, ()); + let client = ContractAClient::new(&e, &contract_id); + let a = Address::generate(&e); + let r = client + .mock_auths(&[MockAuth { + address: &a, + invoke: &MockAuthInvoke { + contract: &contract_id, + fn_name: "fn1", + args: (&a,).into_val(&e), + sub_invokes: &[], + }, + }]) + .fn1(&a); + match (&r, &2) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match ( + &e.auths(), + &<[_]>::into_vec(::alloc::boxed::box_new([( + a.clone(), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + contract_id.clone(), + Symbol::new(&e, "fn1"), + (&a,).into_val(&e), + )), + sub_invocations: ::alloc::vec::Vec::new(), + }, + )])), + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + } + extern crate test; + #[rustc_test_marker = "test_a::test_with_real_contract_auth_approve"] + #[doc(hidden)] + pub const test_with_real_contract_auth_approve: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test_a::test_with_real_contract_auth_approve"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/auth/src/lib.rs", + start_line: 97usize, + start_col: 8usize, + end_line: 97usize, + end_col: 44usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_with_real_contract_auth_approve()), + ), + }; + fn test_with_real_contract_auth_approve() { + let e = Env::default(); + let contract_id = e.register(ContractA, ()); + let client = ContractAClient::new(&e, &contract_id); + let a = e.register(auth_approve::Contract, ()); + let a_xdr: ScAddress = (&a).try_into().unwrap(); + let r = client + .set_auths(&[SorobanAuthorizationEntry { + credentials: SorobanCredentials::Address(SorobanAddressCredentials { + address: a_xdr.clone(), + nonce: 123, + signature_expiration_ledger: 100, + signature: ScVal::Void, + }), + root_invocation: SorobanAuthorizedInvocation { + function: SorobanAuthorizedFunction::ContractFn(InvokeContractArgs { + contract_address: contract_id.clone().try_into().unwrap(), + function_name: StringM::try_from("fn1").unwrap().into(), + args: <[_]>::into_vec(::alloc::boxed::box_new([ScVal::Address( + a_xdr.clone(), + )])) + .try_into() + .unwrap(), + }), + sub_invocations: VecM::default(), + }, + }]) + .fn1(&a); + match (&r, &2) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match ( + &e.auths(), + &<[_]>::into_vec(::alloc::boxed::box_new([( + a.clone(), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + contract_id.clone(), + Symbol::new(&e, "fn1"), + (&a,).into_val(&e), + )), + sub_invocations: ::alloc::vec::Vec::new(), + }, + )])), + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + } + extern crate test; + #[rustc_test_marker = "test_a::test_with_real_contract_auth_decline"] + #[doc(hidden)] + pub const test_with_real_contract_auth_decline: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test_a::test_with_real_contract_auth_decline"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/auth/src/lib.rs", + start_line: 143usize, + start_col: 8usize, + end_line: 143usize, + end_col: 44usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_with_real_contract_auth_decline()), + ), + }; + fn test_with_real_contract_auth_decline() { + let e = Env::default(); + let contract_id = e.register(ContractA, ()); + let client = ContractAClient::new(&e, &contract_id); + let a = e.register(auth_decline::Contract, ()); + let a_xdr: ScAddress = (&a).try_into().unwrap(); + let r = client + .set_auths(&[SorobanAuthorizationEntry { + credentials: SorobanCredentials::Address(SorobanAddressCredentials { + address: a_xdr.clone(), + nonce: 456, + signature_expiration_ledger: u32::MAX, + signature: ScVal::Void, + }), + root_invocation: SorobanAuthorizedInvocation { + function: SorobanAuthorizedFunction::ContractFn(InvokeContractArgs { + contract_address: contract_id.try_into().unwrap(), + function_name: StringM::try_from("fn1").unwrap().into(), + args: <[_]>::into_vec(::alloc::boxed::box_new([ScVal::Address( + a_xdr.clone(), + )])) + .try_into() + .unwrap(), + }), + sub_invocations: VecM::default(), + }, + }]) + .try_fn1(&a); + match ( + &r, + &Err(Ok(Error::from_scerror(ScError::Context( + ScErrorCode::InvalidAction, + )))), + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match (&e.auths(), &[]) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + } + mod auth_approve { + use super::*; + pub struct Contract; + ///ContractArgs is a type for building arg lists for functions defined in "Contract". + pub struct ContractArgs; + ///ContractClient is a client for calling the contract defined in "Contract". + pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, + } + impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths( + &self, + auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry], + ) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths( + &self, + mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>], + ) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } + } + mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } + } + impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } + } + #[doc(hidden)] + impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } + } + impl Contract { + #[allow(non_snake_case)] + pub fn __check_auth(_signature_payload: Val, _signatures: Val, _auth_context: Val) {} + } + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_snake_case)] + pub mod __Contract____check_auth__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[allow(non_snake_case)] + pub static __SPEC_XDR_FN___CHECK_AUTH: [u8; 112usize] = + super::Contract::spec_xdr___check_auth(); + } + impl Contract { + #[allow(non_snake_case)] + #[allow(non_snake_case)] + pub const fn spec_xdr___check_auth() -> [u8; 112usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x0c__check_auth\0\0\0\x03\0\0\0\0\0\0\0\x11signature_payload\0\0\0\0\0\0\0\0\0\0\0\0\0\0\nsignatures\0\0\0\0\0\0\0\0\0\0\0\0\0\x0cauth_context\0\0\0\0\0\0\0\0" + } + } + impl<'a> ContractClient<'a> {} + impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn __check_auth<'i>( + _signature_payload: &'i Val, + _signatures: &'i Val, + _auth_context: &'i Val, + ) -> (&'i Val, &'i Val, &'i Val) { + (_signature_payload, _signatures, _auth_context) + } + } + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_snake_case)] + pub mod __Contract____check_auth { + use super::*; + #[deprecated( + note = "use `ContractClient::new(&env, &contract_id).__check_auth` instead" + )] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::__check_auth( + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn( + &env, &arg_0 + ), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn( + &env, &arg_1 + ), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn( + &env, &arg_2 + ), + ), + ), + &env, + ) + } + #[deprecated( + note = "use `ContractClient::new(&env, &contract_id).__check_auth` instead" + )] + pub fn invoke_raw_slice( + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> soroban_sdk::Val { + if args.len() != 3usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 3usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize], args[1usize], args[2usize]) + } + #[deprecated( + note = "use `ContractClient::new(&env, &contract_id).__check_auth` instead" + )] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1, arg_2) + } + use super::*; + } + #[doc(hidden)] + #[allow(non_snake_case)] + extern "C" fn __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor( + ) { + ::register( + "__check_auth", + #[allow(deprecated)] + &__Contract____check_auth::invoke_raw_slice, + ); + } + #[used] + #[allow(non_upper_case_globals, non_snake_case)] + #[doc(hidden)] + #[link_section = "__DATA,__mod_init_func"] + static __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor() -> usize { + __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor(); + 0 + } + __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor + }; + } + mod auth_decline { + use super::*; + pub struct Contract; + ///ContractArgs is a type for building arg lists for functions defined in "Contract". + pub struct ContractArgs; + ///ContractClient is a client for calling the contract defined in "Contract". + pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, + } + impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths( + &self, + auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry], + ) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths( + &self, + mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>], + ) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } + } + mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } + } + impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } + } + #[doc(hidden)] + impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } + } + #[repr(u32)] + pub enum Error { + Decline = 1, + } + #[automatically_derived] + impl ::core::marker::Copy for Error {} + #[automatically_derived] + impl ::core::clone::Clone for Error { + #[inline] + fn clone(&self) -> Error { + *self + } + } + #[automatically_derived] + impl ::core::fmt::Debug for Error { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::write_str(f, "Decline") + } + } + #[automatically_derived] + impl ::core::cmp::Eq for Error { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () {} + } + #[automatically_derived] + impl ::core::marker::StructuralPartialEq for Error {} + #[automatically_derived] + impl ::core::cmp::PartialEq for Error { + #[inline] + fn eq(&self, other: &Error) -> bool { + true + } + } + #[automatically_derived] + impl ::core::cmp::PartialOrd for Error { + #[inline] + fn partial_cmp(&self, other: &Error) -> ::core::option::Option<::core::cmp::Ordering> { + ::core::option::Option::Some(::core::cmp::Ordering::Equal) + } + } + #[automatically_derived] + impl ::core::cmp::Ord for Error { + #[inline] + fn cmp(&self, other: &Error) -> ::core::cmp::Ordering { + ::core::cmp::Ordering::Equal + } + } + pub static __SPEC_XDR_TYPE_ERROR: [u8; 48usize] = Error::spec_xdr(); + impl Error { + pub const fn spec_xdr() -> [u8; 48usize] { + *b"\0\0\0\x04\0\0\0\0\0\0\0\0\0\0\0\x05Error\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\x07Decline\0\0\0\0\x01" + } + } + impl TryFrom for Error { + type Error = soroban_sdk::Error; + #[inline(always)] + fn try_from(error: soroban_sdk::Error) -> Result { + if error.is_type(soroban_sdk::xdr::ScErrorType::Contract) { + let discriminant = error.get_code(); + Ok(match discriminant { + 1u32 => Self::Decline, + _ => return Err(error), + }) + } else { + Err(error) + } + } + } + impl TryFrom<&soroban_sdk::Error> for Error { + type Error = soroban_sdk::Error; + #[inline(always)] + fn try_from(error: &soroban_sdk::Error) -> Result { + <_ as TryFrom>::try_from(*error) + } + } + impl From for soroban_sdk::Error { + #[inline(always)] + fn from(val: Error) -> soroban_sdk::Error { + <_ as From<&Error>>::from(&val) + } + } + impl From<&Error> for soroban_sdk::Error { + #[inline(always)] + fn from(val: &Error) -> soroban_sdk::Error { + match val { + Error::Decline => soroban_sdk::Error::from_contract_error(1u32), + } + } + } + impl TryFrom for Error { + type Error = soroban_sdk::InvokeError; + #[inline(always)] + fn try_from(error: soroban_sdk::InvokeError) -> Result { + match error { + soroban_sdk::InvokeError::Abort => Err(error), + soroban_sdk::InvokeError::Contract(code) => Ok(match code { + 1u32 => Self::Decline, + _ => return Err(error), + }), + } + } + } + impl TryFrom<&soroban_sdk::InvokeError> for Error { + type Error = soroban_sdk::InvokeError; + #[inline(always)] + fn try_from( + error: &soroban_sdk::InvokeError, + ) -> Result { + <_ as TryFrom>::try_from(*error) + } + } + impl From for soroban_sdk::InvokeError { + #[inline(always)] + fn from(val: Error) -> soroban_sdk::InvokeError { + <_ as From<&Error>>::from(&val) + } + } + impl From<&Error> for soroban_sdk::InvokeError { + #[inline(always)] + fn from(val: &Error) -> soroban_sdk::InvokeError { + match val { + Error::Decline => soroban_sdk::InvokeError::Contract(1u32), + } + } + } + impl soroban_sdk::TryFromVal for Error { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::TryIntoVal; + let error: soroban_sdk::Error = val.try_into_val(env)?; + error.try_into().map_err(|_| soroban_sdk::ConversionError) + } + } + impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &Error, + ) -> Result { + let error: soroban_sdk::Error = val.into(); + Ok(error.into()) + } + } + impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&Error, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } + } + impl Contract { + #[allow(non_snake_case)] + pub fn __check_auth( + _signature_payload: Val, + _signatures: Val, + _auth_context: Val, + ) -> Result<(), Error> { + Err(Error::Decline) + } + } + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_snake_case)] + pub mod __Contract____check_auth__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[allow(non_snake_case)] + pub static __SPEC_XDR_FN___CHECK_AUTH: [u8; 128usize] = + super::Contract::spec_xdr___check_auth(); + } + impl Contract { + #[allow(non_snake_case)] + #[allow(non_snake_case)] + pub const fn spec_xdr___check_auth() -> [u8; 128usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x0c__check_auth\0\0\0\x03\0\0\0\0\0\0\0\x11signature_payload\0\0\0\0\0\0\0\0\0\0\0\0\0\0\nsignatures\0\0\0\0\0\0\0\0\0\0\0\0\0\x0cauth_context\0\0\0\0\0\0\0\x01\0\0\x03\xe9\0\0\x03\xed\0\0\0\0\0\0\0\x03" + } + } + impl<'a> ContractClient<'a> {} + impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn __check_auth<'i>( + _signature_payload: &'i Val, + _signatures: &'i Val, + _auth_context: &'i Val, + ) -> (&'i Val, &'i Val, &'i Val) { + (_signature_payload, _signatures, _auth_context) + } + } + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_snake_case)] + pub mod __Contract____check_auth { + use super::*; + #[deprecated( + note = "use `ContractClient::new(&env, &contract_id).__check_auth` instead" + )] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::__check_auth( + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn( + &env, &arg_0 + ), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn( + &env, &arg_1 + ), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn( + &env, &arg_2 + ), + ), + ), + &env, + ) + } + #[deprecated( + note = "use `ContractClient::new(&env, &contract_id).__check_auth` instead" + )] + pub fn invoke_raw_slice( + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> soroban_sdk::Val { + if args.len() != 3usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 3usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize], args[1usize], args[2usize]) + } + #[deprecated( + note = "use `ContractClient::new(&env, &contract_id).__check_auth` instead" + )] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1, arg_2) + } + use super::*; + } + #[doc(hidden)] + #[allow(non_snake_case)] + extern "C" fn __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor( + ) { + ::register( + "__check_auth", + #[allow(deprecated)] + &__Contract____check_auth::invoke_raw_slice, + ); + } + #[used] + #[allow(non_upper_case_globals, non_snake_case)] + #[doc(hidden)] + #[link_section = "__DATA,__mod_init_func"] + static __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor() -> usize { + __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor(); + 0 + } + __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor + }; + } +} +pub struct ContractB; +///ContractBArgs is a type for building arg lists for functions defined in "ContractB". +pub struct ContractBArgs; +///ContractBClient is a client for calling the contract defined in "ContractB". +pub struct ContractBClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractBClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contractb_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for ContractB { + fn register(name: &'static str, func: &'static __contractb_fn_set_registry::F) { + __contractb_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for ContractB { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contractb_fn_set_registry::call(func, env, args) + } +} +impl ContractB { + pub fn fn2(e: Env, a: Address, sub: Address) -> u64 { + a.require_auth_for_args((1, 2).into_val(&e)); + let client = ContractAClient::new(&e, &sub); + client.fn1(&a) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __ContractB__fn2__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_FN2: [u8; 60usize] = super::ContractB::spec_xdr_fn2(); +} +impl ContractB { + #[allow(non_snake_case)] + pub const fn spec_xdr_fn2() -> [u8; 60usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03fn2\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x13\0\0\0\0\0\0\0\x03sub\0\0\0\0\x13\0\0\0\x01\0\0\0\x06" + } +} +impl<'a> ContractBClient<'a> { + pub fn fn2(&self, a: &Address, sub: &Address) -> u64 { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("fn2"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), sub.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_fn2( + &self, + a: &Address, + sub: &Address, + ) -> Result< + Result>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("fn2"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), sub.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractBArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn fn2<'i>(a: &'i Address, sub: &'i Address) -> (&'i Address, &'i Address) { + (a, sub) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __ContractB__fn2 { + use super::*; + #[deprecated(note = "use `ContractBClient::new(&env, &contract_id).fn2` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::fn2( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractBClient::new(&env, &contract_id).fn2` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 2usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 2usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize], args[1usize]) + } + #[deprecated(note = "use `ContractBClient::new(&env, &contract_id).fn2` instead")] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __ContractB__389cfcb1cb10680376b4cd5cf632e6b11c3e59494c10e1d42514faf6c4c21b84_ctor() { + ::register( + "fn2", + #[allow(deprecated)] + &__ContractB__fn2::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __ContractB__389cfcb1cb10680376b4cd5cf632e6b11c3e59494c10e1d42514faf6c4c21b84_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __ContractB__389cfcb1cb10680376b4cd5cf632e6b11c3e59494c10e1d42514faf6c4c21b84_ctor___rust_ctor___ctor() -> usize { + __ContractB__389cfcb1cb10680376b4cd5cf632e6b11c3e59494c10e1d42514faf6c4c21b84_ctor(); + 0 + } + __ContractB__389cfcb1cb10680376b4cd5cf632e6b11c3e59494c10e1d42514faf6c4c21b84_ctor___rust_ctor___ctor +}; +mod test_b { + use super::*; + use soroban_sdk::{ + contracterror, symbol_short, + testutils::{ + Address as _, AuthorizedFunction, AuthorizedInvocation, MockAuth, MockAuthInvoke, + }, + xdr::{ + InvokeContractArgs, ScAddress, ScError, ScErrorCode, ScVal, SorobanAddressCredentials, + SorobanAuthorizationEntry, SorobanAuthorizedFunction, SorobanAuthorizedInvocation, + SorobanCredentials, StringM, + }, + Address, Env, Error, Val, + }; + extern crate std; + extern crate test; + #[rustc_test_marker = "test_b::test_with_mock_all_auth"] + #[doc(hidden)] + pub const test_with_mock_all_auth: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test_b::test_with_mock_all_auth"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/auth/src/lib.rs", + start_line: 251usize, + start_col: 8usize, + end_line: 251usize, + end_col: 31usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_with_mock_all_auth()), + ), + }; + fn test_with_mock_all_auth() { + let e = Env::default(); + let contract_a_id = e.register(ContractA, ()); + let contract_b_id = e.register(ContractB, ()); + let client = ContractBClient::new(&e, &contract_b_id); + let a = Address::generate(&e); + let r = client.mock_all_auths().fn2(&a, &contract_a_id); + match (&r, &2) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match ( + &e.auths(), + &[( + a.clone(), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + contract_b_id.clone(), + { + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("fn2"); + SYMBOL + }, + (1, 2).into_val(&e), + )), + sub_invocations: <[_]>::into_vec(::alloc::boxed::box_new([ + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + contract_a_id.clone(), + { + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = + soroban_sdk::Symbol::short("fn1"); + SYMBOL + }, + (&a,).into_val(&e), + )), + sub_invocations: ::alloc::vec::Vec::new(), + }, + ])), + }, + )], + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + } + extern crate test; + #[rustc_test_marker = "test_b::test_with_mock_auth"] + #[doc(hidden)] + pub const test_with_mock_auth: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test_b::test_with_mock_auth"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/auth/src/lib.rs", + start_line: 286usize, + start_col: 8usize, + end_line: 286usize, + end_col: 27usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_with_mock_auth()), + ), + }; + fn test_with_mock_auth() { + let e = Env::default(); + let contract_a_id = e.register(ContractA, ()); + let contract_b_id = e.register(ContractB, ()); + let client = ContractBClient::new(&e, &contract_b_id); + let a = Address::generate(&e); + let r = client + .mock_auths(&[MockAuth { + address: &a, + invoke: &MockAuthInvoke { + contract: &contract_b_id, + fn_name: "fn2", + args: (1, 2).into_val(&e), + sub_invokes: &[MockAuthInvoke { + contract: &contract_a_id, + fn_name: "fn1", + args: (&a,).into_val(&e), + sub_invokes: &[], + }], + }, + }]) + .fn2(&a, &contract_a_id); + match (&r, &2) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match ( + &e.auths(), + &[( + a.clone(), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + contract_b_id.clone(), + { + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("fn2"); + SYMBOL + }, + (1, 2).into_val(&e), + )), + sub_invocations: <[_]>::into_vec(::alloc::boxed::box_new([ + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + contract_a_id.clone(), + { + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = + soroban_sdk::Symbol::short("fn1"); + SYMBOL + }, + (&a,).into_val(&e), + )), + sub_invocations: ::alloc::vec::Vec::new(), + }, + ])), + }, + )], + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + } + extern crate test; + #[rustc_test_marker = "test_b::test_with_real_contract_auth_approve"] + #[doc(hidden)] + pub const test_with_real_contract_auth_approve: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test_b::test_with_real_contract_auth_approve"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/auth/src/lib.rs", + start_line: 336usize, + start_col: 8usize, + end_line: 336usize, + end_col: 44usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_with_real_contract_auth_approve()), + ), + }; + fn test_with_real_contract_auth_approve() { + let e = Env::default(); + let contract_a_id = e.register(ContractA, ()); + let contract_b_id = e.register(ContractB, ()); + let client = ContractBClient::new(&e, &contract_b_id); + let a = e.register(auth_approve::Contract, ()); + let a_xdr: ScAddress = (&a).try_into().unwrap(); + let r = client + .set_auths(&[SorobanAuthorizationEntry { + credentials: SorobanCredentials::Address(SorobanAddressCredentials { + address: a_xdr.clone(), + nonce: 543, + signature_expiration_ledger: 100, + 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: <[_]>::into_vec(::alloc::boxed::box_new([ + ScVal::I32(1), + ScVal::I32(2), + ])) + .try_into() + .unwrap(), + }), + sub_invocations: <[_]>::into_vec(::alloc::boxed::box_new([ + SorobanAuthorizedInvocation { + function: SorobanAuthorizedFunction::ContractFn(InvokeContractArgs { + contract_address: contract_a_id.clone().try_into().unwrap(), + function_name: StringM::try_from("fn1").unwrap().into(), + args: <[_]>::into_vec(::alloc::boxed::box_new([ScVal::Address( + a_xdr.clone(), + )])) + .try_into() + .unwrap(), + }), + sub_invocations: Default::default(), + }, + ])) + .try_into() + .unwrap(), + }, + }]) + .fn2(&a, &contract_a_id); + match (&r, &2) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match ( + &e.auths(), + &[( + a.clone(), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + contract_b_id.clone(), + { + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("fn2"); + SYMBOL + }, + (1, 2).into_val(&e), + )), + sub_invocations: <[_]>::into_vec(::alloc::boxed::box_new([ + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + contract_a_id.clone(), + { + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = + soroban_sdk::Symbol::short("fn1"); + SYMBOL + }, + (&a,).into_val(&e), + )), + sub_invocations: ::alloc::vec::Vec::new(), + }, + ])), + }, + )], + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + } + extern crate test; + #[rustc_test_marker = "test_b::test_with_real_contract_auth_decline"] + #[doc(hidden)] + pub const test_with_real_contract_auth_decline: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test_b::test_with_real_contract_auth_decline"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/auth/src/lib.rs", + start_line: 399usize, + start_col: 8usize, + end_line: 399usize, + end_col: 44usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_with_real_contract_auth_decline()), + ), + }; + fn test_with_real_contract_auth_decline() { + let e = Env::default(); + let contract_a_id = e.register(ContractA, ()); + let contract_b_id = e.register(ContractB, ()); + let client = ContractBClient::new(&e, &contract_b_id); + let a = e.register(auth_decline::Contract, ()); + 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: <[_]>::into_vec(::alloc::boxed::box_new([ + ScVal::I32(1), + ScVal::I32(2), + ])) + .try_into() + .unwrap(), + }), + sub_invocations: <[_]>::into_vec(::alloc::boxed::box_new([ + SorobanAuthorizedInvocation { + function: SorobanAuthorizedFunction::ContractFn(InvokeContractArgs { + contract_address: contract_a_id.clone().try_into().unwrap(), + function_name: StringM::try_from("fn1").unwrap().into(), + args: <[_]>::into_vec(::alloc::boxed::box_new([ScVal::Address( + a_xdr.clone(), + )])) + .try_into() + .unwrap(), + }), + sub_invocations: Default::default(), + }, + ])) + .try_into() + .unwrap(), + }, + }]) + .try_fn2(&a, &contract_a_id); + match ( + &r, + &Err(Ok(Error::from_scerror(ScError::Context( + ScErrorCode::InvalidAction, + )))), + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match (&e.auths(), &[]) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + } + mod auth_approve { + use super::*; + pub struct Contract; + ///ContractArgs is a type for building arg lists for functions defined in "Contract". + pub struct ContractArgs; + ///ContractClient is a client for calling the contract defined in "Contract". + pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, + } + impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths( + &self, + auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry], + ) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths( + &self, + mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>], + ) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } + } + mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } + } + impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } + } + #[doc(hidden)] + impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } + } + impl Contract { + #[allow(non_snake_case)] + pub fn __check_auth(_signature_payload: Val, _signatures: Val, _auth_context: Val) {} + } + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_snake_case)] + pub mod __Contract____check_auth__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[allow(non_snake_case)] + pub static __SPEC_XDR_FN___CHECK_AUTH: [u8; 112usize] = + super::Contract::spec_xdr___check_auth(); + } + impl Contract { + #[allow(non_snake_case)] + #[allow(non_snake_case)] + pub const fn spec_xdr___check_auth() -> [u8; 112usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x0c__check_auth\0\0\0\x03\0\0\0\0\0\0\0\x11signature_payload\0\0\0\0\0\0\0\0\0\0\0\0\0\0\nsignatures\0\0\0\0\0\0\0\0\0\0\0\0\0\x0cauth_context\0\0\0\0\0\0\0\0" + } + } + impl<'a> ContractClient<'a> {} + impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn __check_auth<'i>( + _signature_payload: &'i Val, + _signatures: &'i Val, + _auth_context: &'i Val, + ) -> (&'i Val, &'i Val, &'i Val) { + (_signature_payload, _signatures, _auth_context) + } + } + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_snake_case)] + pub mod __Contract____check_auth { + use super::*; + #[deprecated( + note = "use `ContractClient::new(&env, &contract_id).__check_auth` instead" + )] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::__check_auth( + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn( + &env, &arg_0 + ), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn( + &env, &arg_1 + ), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn( + &env, &arg_2 + ), + ), + ), + &env, + ) + } + #[deprecated( + note = "use `ContractClient::new(&env, &contract_id).__check_auth` instead" + )] + pub fn invoke_raw_slice( + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> soroban_sdk::Val { + if args.len() != 3usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 3usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize], args[1usize], args[2usize]) + } + #[deprecated( + note = "use `ContractClient::new(&env, &contract_id).__check_auth` instead" + )] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1, arg_2) + } + use super::*; + } + #[doc(hidden)] + #[allow(non_snake_case)] + extern "C" fn __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor( + ) { + ::register( + "__check_auth", + #[allow(deprecated)] + &__Contract____check_auth::invoke_raw_slice, + ); + } + #[used] + #[allow(non_upper_case_globals, non_snake_case)] + #[doc(hidden)] + #[link_section = "__DATA,__mod_init_func"] + static __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor() -> usize { + __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor(); + 0 + } + __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor + }; + } + mod auth_decline { + use super::*; + pub struct Contract; + ///ContractArgs is a type for building arg lists for functions defined in "Contract". + pub struct ContractArgs; + ///ContractClient is a client for calling the contract defined in "Contract". + pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, + } + impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths( + &self, + auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry], + ) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths( + &self, + mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>], + ) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } + } + mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } + } + impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } + } + #[doc(hidden)] + impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } + } + #[repr(u32)] + pub enum Error { + Decline = 1, + } + #[automatically_derived] + impl ::core::marker::Copy for Error {} + #[automatically_derived] + impl ::core::clone::Clone for Error { + #[inline] + fn clone(&self) -> Error { + *self + } + } + #[automatically_derived] + impl ::core::fmt::Debug for Error { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::write_str(f, "Decline") + } + } + #[automatically_derived] + impl ::core::cmp::Eq for Error { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () {} + } + #[automatically_derived] + impl ::core::marker::StructuralPartialEq for Error {} + #[automatically_derived] + impl ::core::cmp::PartialEq for Error { + #[inline] + fn eq(&self, other: &Error) -> bool { + true + } + } + #[automatically_derived] + impl ::core::cmp::PartialOrd for Error { + #[inline] + fn partial_cmp(&self, other: &Error) -> ::core::option::Option<::core::cmp::Ordering> { + ::core::option::Option::Some(::core::cmp::Ordering::Equal) + } + } + #[automatically_derived] + impl ::core::cmp::Ord for Error { + #[inline] + fn cmp(&self, other: &Error) -> ::core::cmp::Ordering { + ::core::cmp::Ordering::Equal + } + } + pub static __SPEC_XDR_TYPE_ERROR: [u8; 48usize] = Error::spec_xdr(); + impl Error { + pub const fn spec_xdr() -> [u8; 48usize] { + *b"\0\0\0\x04\0\0\0\0\0\0\0\0\0\0\0\x05Error\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\x07Decline\0\0\0\0\x01" + } + } + impl TryFrom for Error { + type Error = soroban_sdk::Error; + #[inline(always)] + fn try_from(error: soroban_sdk::Error) -> Result { + if error.is_type(soroban_sdk::xdr::ScErrorType::Contract) { + let discriminant = error.get_code(); + Ok(match discriminant { + 1u32 => Self::Decline, + _ => return Err(error), + }) + } else { + Err(error) + } + } + } + impl TryFrom<&soroban_sdk::Error> for Error { + type Error = soroban_sdk::Error; + #[inline(always)] + fn try_from(error: &soroban_sdk::Error) -> Result { + <_ as TryFrom>::try_from(*error) + } + } + impl From for soroban_sdk::Error { + #[inline(always)] + fn from(val: Error) -> soroban_sdk::Error { + <_ as From<&Error>>::from(&val) + } + } + impl From<&Error> for soroban_sdk::Error { + #[inline(always)] + fn from(val: &Error) -> soroban_sdk::Error { + match val { + Error::Decline => soroban_sdk::Error::from_contract_error(1u32), + } + } + } + impl TryFrom for Error { + type Error = soroban_sdk::InvokeError; + #[inline(always)] + fn try_from(error: soroban_sdk::InvokeError) -> Result { + match error { + soroban_sdk::InvokeError::Abort => Err(error), + soroban_sdk::InvokeError::Contract(code) => Ok(match code { + 1u32 => Self::Decline, + _ => return Err(error), + }), + } + } + } + impl TryFrom<&soroban_sdk::InvokeError> for Error { + type Error = soroban_sdk::InvokeError; + #[inline(always)] + fn try_from( + error: &soroban_sdk::InvokeError, + ) -> Result { + <_ as TryFrom>::try_from(*error) + } + } + impl From for soroban_sdk::InvokeError { + #[inline(always)] + fn from(val: Error) -> soroban_sdk::InvokeError { + <_ as From<&Error>>::from(&val) + } + } + impl From<&Error> for soroban_sdk::InvokeError { + #[inline(always)] + fn from(val: &Error) -> soroban_sdk::InvokeError { + match val { + Error::Decline => soroban_sdk::InvokeError::Contract(1u32), + } + } + } + impl soroban_sdk::TryFromVal for Error { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::TryIntoVal; + let error: soroban_sdk::Error = val.try_into_val(env)?; + error.try_into().map_err(|_| soroban_sdk::ConversionError) + } + } + impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &Error, + ) -> Result { + let error: soroban_sdk::Error = val.into(); + Ok(error.into()) + } + } + impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&Error, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } + } + impl Contract { + #[allow(non_snake_case)] + pub fn __check_auth( + _signature_payload: Val, + _signatures: Val, + _auth_context: Val, + ) -> Result<(), Error> { + Err(Error::Decline) + } + } + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_snake_case)] + pub mod __Contract____check_auth__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[allow(non_snake_case)] + pub static __SPEC_XDR_FN___CHECK_AUTH: [u8; 128usize] = + super::Contract::spec_xdr___check_auth(); + } + impl Contract { + #[allow(non_snake_case)] + #[allow(non_snake_case)] + pub const fn spec_xdr___check_auth() -> [u8; 128usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x0c__check_auth\0\0\0\x03\0\0\0\0\0\0\0\x11signature_payload\0\0\0\0\0\0\0\0\0\0\0\0\0\0\nsignatures\0\0\0\0\0\0\0\0\0\0\0\0\0\x0cauth_context\0\0\0\0\0\0\0\x01\0\0\x03\xe9\0\0\x03\xed\0\0\0\0\0\0\0\x03" + } + } + impl<'a> ContractClient<'a> {} + impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn __check_auth<'i>( + _signature_payload: &'i Val, + _signatures: &'i Val, + _auth_context: &'i Val, + ) -> (&'i Val, &'i Val, &'i Val) { + (_signature_payload, _signatures, _auth_context) + } + } + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_snake_case)] + pub mod __Contract____check_auth { + use super::*; + #[deprecated( + note = "use `ContractClient::new(&env, &contract_id).__check_auth` instead" + )] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::__check_auth( + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn( + &env, &arg_0 + ), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn( + &env, &arg_1 + ), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn( + &env, &arg_2 + ), + ), + ), + &env, + ) + } + #[deprecated( + note = "use `ContractClient::new(&env, &contract_id).__check_auth` instead" + )] + pub fn invoke_raw_slice( + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> soroban_sdk::Val { + if args.len() != 3usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 3usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize], args[1usize], args[2usize]) + } + #[deprecated( + note = "use `ContractClient::new(&env, &contract_id).__check_auth` instead" + )] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1, arg_2) + } + use super::*; + } + #[doc(hidden)] + #[allow(non_snake_case)] + extern "C" fn __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor( + ) { + ::register( + "__check_auth", + #[allow(deprecated)] + &__Contract____check_auth::invoke_raw_slice, + ); + } + #[used] + #[allow(non_upper_case_globals, non_snake_case)] + #[doc(hidden)] + #[link_section = "__DATA,__mod_init_func"] + static __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor() -> usize { + __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor(); + 0 + } + __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor + }; + } +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[ + &test_with_mock_all_auth, + &test_with_mock_auth, + &test_with_real_contract_auth_approve, + &test_with_real_contract_auth_decline, + &test_with_mock_all_auth, + &test_with_mock_auth, + &test_with_real_contract_auth_approve, + &test_with_real_contract_auth_decline, + ]) +} diff --git a/tests-expanded/test_auth_wasm32v1-none.rs b/tests-expanded/test_auth_wasm32v1-none.rs new file mode 100644 index 000000000..e58039e37 --- /dev/null +++ b/tests-expanded/test_auth_wasm32v1-none.rs @@ -0,0 +1,247 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl, Address, Env, IntoVal}; +pub struct ContractA; +///ContractAArgs is a type for building arg lists for functions defined in "ContractA". +pub struct ContractAArgs; +///ContractAClient is a client for calling the contract defined in "ContractA". +pub struct ContractAClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractAClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl ContractA { + pub fn fn1(a: Address) -> u64 { + a.require_auth(); + 2 + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __ContractA__fn1__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_FN1: [u8; 44usize] = super::ContractA::spec_xdr_fn1(); +} +impl ContractA { + #[allow(non_snake_case)] + pub const fn spec_xdr_fn1() -> [u8; 44usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03fn1\0\0\0\0\x01\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x13\0\0\0\x01\0\0\0\x06" + } +} +impl<'a> ContractAClient<'a> { + pub fn fn1(&self, a: &Address) -> u64 { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("fn1"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [a.into_val(&self.env)]), + ); + res + } + pub fn try_fn1( + &self, + a: &Address, + ) -> Result< + Result>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("fn1"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [a.into_val(&self.env)]), + ); + res + } +} +impl ContractAArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn fn1<'i>(a: &'i Address) -> (&'i Address,) { + (a,) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __ContractA__fn1 { + use super::*; + #[deprecated(note = "use `ContractAClient::new(&env, &contract_id).fn1` instead")] + pub fn invoke_raw(env: soroban_sdk::Env, arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::fn1( + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractAClient::new(&env, &contract_id).fn1` instead")] + #[export_name = "fn1"] + pub extern "C" fn invoke_raw_extern(arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0) + } + use super::*; +} +pub struct ContractB; +///ContractBArgs is a type for building arg lists for functions defined in "ContractB". +pub struct ContractBArgs; +///ContractBClient is a client for calling the contract defined in "ContractB". +pub struct ContractBClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractBClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl ContractB { + pub fn fn2(e: Env, a: Address, sub: Address) -> u64 { + a.require_auth_for_args((1, 2).into_val(&e)); + let client = ContractAClient::new(&e, &sub); + client.fn1(&a) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __ContractB__fn2__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_FN2: [u8; 60usize] = super::ContractB::spec_xdr_fn2(); +} +impl ContractB { + #[allow(non_snake_case)] + pub const fn spec_xdr_fn2() -> [u8; 60usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03fn2\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x13\0\0\0\0\0\0\0\x03sub\0\0\0\0\x13\0\0\0\x01\0\0\0\x06" + } +} +impl<'a> ContractBClient<'a> { + pub fn fn2(&self, a: &Address, sub: &Address) -> u64 { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("fn2"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), sub.into_val(&self.env)], + ), + ); + res + } + pub fn try_fn2( + &self, + a: &Address, + sub: &Address, + ) -> Result< + Result>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("fn2"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), sub.into_val(&self.env)], + ), + ); + res + } +} +impl ContractBArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn fn2<'i>(a: &'i Address, sub: &'i Address) -> (&'i Address, &'i Address) { + (a, sub) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __ContractB__fn2 { + use super::*; + #[deprecated(note = "use `ContractBClient::new(&env, &contract_id).fn2` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::fn2( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractBClient::new(&env, &contract_id).fn2` instead")] + #[export_name = "fn2"] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} diff --git a/tests-expanded/test_bls_tests.rs b/tests-expanded/test_bls_tests.rs new file mode 100644 index 000000000..aa3ae89a1 --- /dev/null +++ b/tests-expanded/test_bls_tests.rs @@ -0,0 +1,1478 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{ + contract, contractimpl, contracttype, + crypto::bls12_381::{Fp, Fp2, Fr, G1Affine, G2Affine}, + log, Env, +}; +pub struct DummyProof { + pub fp: Fp, + pub fp2: Fp2, + pub g1: G1Affine, + pub g2: G2Affine, + pub fr: Fr, +} +pub static __SPEC_XDR_TYPE_DUMMYPROOF: [u8; 128usize] = DummyProof::spec_xdr(); +impl DummyProof { + pub const fn spec_xdr() -> [u8; 128usize] { + *b"\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\nDummyProof\0\0\0\0\0\x05\0\0\0\0\0\0\0\x02fp\0\0\0\0\x03\xee\0\0\00\0\0\0\0\0\0\0\x03fp2\0\0\0\x03\xee\0\0\0`\0\0\0\0\0\0\0\x02fr\0\0\0\0\0\x0c\0\0\0\0\0\0\0\x02g1\0\0\0\0\x03\xee\0\0\0`\0\0\0\0\0\0\0\x02g2\0\0\0\0\x03\xee\0\0\0\xc0" + } +} +impl soroban_sdk::TryFromVal for DummyProof { + type Error = soroban_sdk::ConversionError; + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::{ConversionError, EnvBase, MapObject, TryIntoVal, Val}; + const KEYS: [&'static str; 5usize] = ["fp", "fp2", "fr", "g1", "g2"]; + let mut vals: [Val; 5usize] = [Val::VOID.to_val(); 5usize]; + let map: MapObject = val.try_into().map_err(|_| ConversionError)?; + env.map_unpack_to_slice(map, &KEYS, &mut vals) + .map_err(|_| ConversionError)?; + Ok(Self { + fp: vals[0] + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?, + fp2: vals[1] + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?, + fr: vals[2] + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?, + g1: vals[3] + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?, + g2: vals[4] + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?, + }) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + fn try_from_val( + env: &soroban_sdk::Env, + val: &DummyProof, + ) -> Result { + use soroban_sdk::{ConversionError, EnvBase, TryIntoVal, Val}; + const KEYS: [&'static str; 5usize] = ["fp", "fp2", "fr", "g1", "g2"]; + let vals: [Val; 5usize] = [ + (&val.fp).try_into_val(env).map_err(|_| ConversionError)?, + (&val.fp2).try_into_val(env).map_err(|_| ConversionError)?, + (&val.fr).try_into_val(env).map_err(|_| ConversionError)?, + (&val.g1).try_into_val(env).map_err(|_| ConversionError)?, + (&val.g2).try_into_val(env).map_err(|_| ConversionError)?, + ]; + Ok(env + .map_new_from_slices(&KEYS, &vals) + .map_err(|_| ConversionError)? + .into()) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&DummyProof, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } +} +impl soroban_sdk::TryFromVal for DummyProof { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::xdr::ScMap, + ) -> Result { + use soroban_sdk::xdr::Validate; + use soroban_sdk::TryIntoVal; + let map = val; + if map.len() != 5usize { + return Err(soroban_sdk::xdr::Error::Invalid); + } + map.validate()?; + Ok(Self { + fp: { + let key: soroban_sdk::xdr::ScVal = soroban_sdk::xdr::ScSymbol( + "fp".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(); + let idx = map + .binary_search_by_key(&key, |entry| entry.key.clone()) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + let rv: soroban_sdk::Val = (&map[idx].val.clone()) + .try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + rv.try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)? + }, + fp2: { + let key: soroban_sdk::xdr::ScVal = soroban_sdk::xdr::ScSymbol( + "fp2" + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(); + let idx = map + .binary_search_by_key(&key, |entry| entry.key.clone()) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + let rv: soroban_sdk::Val = (&map[idx].val.clone()) + .try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + rv.try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)? + }, + fr: { + let key: soroban_sdk::xdr::ScVal = soroban_sdk::xdr::ScSymbol( + "fr".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(); + let idx = map + .binary_search_by_key(&key, |entry| entry.key.clone()) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + let rv: soroban_sdk::Val = (&map[idx].val.clone()) + .try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + rv.try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)? + }, + g1: { + let key: soroban_sdk::xdr::ScVal = soroban_sdk::xdr::ScSymbol( + "g1".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(); + let idx = map + .binary_search_by_key(&key, |entry| entry.key.clone()) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + let rv: soroban_sdk::Val = (&map[idx].val.clone()) + .try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + rv.try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)? + }, + g2: { + let key: soroban_sdk::xdr::ScVal = soroban_sdk::xdr::ScSymbol( + "g2".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(); + let idx = map + .binary_search_by_key(&key, |entry| entry.key.clone()) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + let rv: soroban_sdk::Val = (&map[idx].val.clone()) + .try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + rv.try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)? + }, + }) + } +} +impl soroban_sdk::TryFromVal for DummyProof { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::xdr::ScVal, + ) -> Result { + if let soroban_sdk::xdr::ScVal::Map(Some(map)) = val { + <_ as soroban_sdk::TryFromVal<_, _>>::try_from_val(env, map) + } else { + Err(soroban_sdk::xdr::Error::Invalid) + } + } +} +impl TryFrom<&DummyProof> for soroban_sdk::xdr::ScMap { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: &DummyProof) -> Result { + extern crate alloc; + use soroban_sdk::TryFromVal; + soroban_sdk::xdr::ScMap::sorted_from(<[_]>::into_vec(::alloc::boxed::box_new([ + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "fp".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(), + val: (&val.fp) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + }, + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "fp2" + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(), + val: (&val.fp2) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + }, + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "fr".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(), + val: (&val.fr) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + }, + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "g1".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(), + val: (&val.g1) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + }, + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "g2".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(), + val: (&val.g2) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + }, + ]))) + } +} +impl TryFrom for soroban_sdk::xdr::ScMap { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: DummyProof) -> Result { + (&val).try_into() + } +} +impl TryFrom<&DummyProof> for soroban_sdk::xdr::ScVal { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: &DummyProof) -> Result { + Ok(soroban_sdk::xdr::ScVal::Map(Some(val.try_into()?))) + } +} +impl TryFrom for soroban_sdk::xdr::ScVal { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: DummyProof) -> Result { + (&val).try_into() + } +} +const _: () = { + use soroban_sdk::testutils::arbitrary::arbitrary; + use soroban_sdk::testutils::arbitrary::std; + pub struct ArbitraryDummyProof { + fp: ::Prototype, + fp2: ::Prototype, + g1: ::Prototype, + g2: ::Prototype, + fr: ::Prototype, + } + #[automatically_derived] + impl ::core::fmt::Debug for ArbitraryDummyProof { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_struct_field5_finish( + f, + "ArbitraryDummyProof", + "fp", + &self.fp, + "fp2", + &self.fp2, + "g1", + &self.g1, + "g2", + &self.g2, + "fr", + &&self.fr, + ) + } + } + #[automatically_derived] + impl ::core::clone::Clone for ArbitraryDummyProof { + #[inline] + fn clone(&self) -> ArbitraryDummyProof { + ArbitraryDummyProof { + fp: ::core::clone::Clone::clone(&self.fp), + fp2: ::core::clone::Clone::clone(&self.fp2), + g1: ::core::clone::Clone::clone(&self.g1), + g2: ::core::clone::Clone::clone(&self.g2), + fr: ::core::clone::Clone::clone(&self.fr), + } + } + } + #[automatically_derived] + impl ::core::cmp::Eq for ArbitraryDummyProof { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () { + let _: ::core::cmp::AssertParamIsEq< + ::Prototype, + >; + let _: ::core::cmp::AssertParamIsEq< + ::Prototype, + >; + let _: ::core::cmp::AssertParamIsEq< + ::Prototype, + >; + let _: ::core::cmp::AssertParamIsEq< + ::Prototype, + >; + let _: ::core::cmp::AssertParamIsEq< + ::Prototype, + >; + } + } + #[automatically_derived] + impl ::core::marker::StructuralPartialEq for ArbitraryDummyProof {} + #[automatically_derived] + impl ::core::cmp::PartialEq for ArbitraryDummyProof { + #[inline] + fn eq(&self, other: &ArbitraryDummyProof) -> bool { + self.fp == other.fp + && self.fp2 == other.fp2 + && self.g1 == other.g1 + && self.g2 == other.g2 + && self.fr == other.fr + } + } + #[automatically_derived] + impl ::core::cmp::Ord for ArbitraryDummyProof { + #[inline] + fn cmp(&self, other: &ArbitraryDummyProof) -> ::core::cmp::Ordering { + match ::core::cmp::Ord::cmp(&self.fp, &other.fp) { + ::core::cmp::Ordering::Equal => { + match ::core::cmp::Ord::cmp(&self.fp2, &other.fp2) { + ::core::cmp::Ordering::Equal => { + match ::core::cmp::Ord::cmp(&self.g1, &other.g1) { + ::core::cmp::Ordering::Equal => { + match ::core::cmp::Ord::cmp(&self.g2, &other.g2) { + ::core::cmp::Ordering::Equal => { + ::core::cmp::Ord::cmp(&self.fr, &other.fr) + } + cmp => cmp, + } + } + cmp => cmp, + } + } + cmp => cmp, + } + } + cmp => cmp, + } + } + } + #[automatically_derived] + impl ::core::cmp::PartialOrd for ArbitraryDummyProof { + #[inline] + fn partial_cmp( + &self, + other: &ArbitraryDummyProof, + ) -> ::core::option::Option<::core::cmp::Ordering> { + match ::core::cmp::PartialOrd::partial_cmp(&self.fp, &other.fp) { + ::core::option::Option::Some(::core::cmp::Ordering::Equal) => { + match ::core::cmp::PartialOrd::partial_cmp(&self.fp2, &other.fp2) { + ::core::option::Option::Some(::core::cmp::Ordering::Equal) => { + match ::core::cmp::PartialOrd::partial_cmp(&self.g1, &other.g1) { + ::core::option::Option::Some(::core::cmp::Ordering::Equal) => { + match ::core::cmp::PartialOrd::partial_cmp(&self.g2, &other.g2) + { + ::core::option::Option::Some( + ::core::cmp::Ordering::Equal, + ) => ::core::cmp::PartialOrd::partial_cmp( + &self.fr, &other.fr, + ), + cmp => cmp, + } + } + cmp => cmp, + } + } + cmp => cmp, + } + } + cmp => cmp, + } + } + } + const _: () = { + #[allow(non_upper_case_globals)] + const RECURSIVE_COUNT_ArbitraryDummyProof: ::std::thread::LocalKey> = { + #[inline] + fn __init() -> std::cell::Cell { + std::cell::Cell::new(0) + } + unsafe { + ::std::thread::LocalKey::new( + const { + if ::std::mem::needs_drop::>() { + |init| { + #[thread_local] + static VAL: ::std::thread::local_impl::LazyStorage< + std::cell::Cell, + (), + > = ::std::thread::local_impl::LazyStorage::new(); + VAL.get_or_init(init, __init) + } + } else { + |init| { + #[thread_local] + static VAL: ::std::thread::local_impl::LazyStorage< + std::cell::Cell, + !, + > = ::std::thread::local_impl::LazyStorage::new(); + VAL.get_or_init(init, __init) + } + } + }, + ) + } + }; + #[automatically_derived] + impl<'arbitrary> arbitrary::Arbitrary<'arbitrary> for ArbitraryDummyProof { + fn arbitrary(u: &mut arbitrary::Unstructured<'arbitrary>) -> arbitrary::Result { + let guard_against_recursion = u.is_empty(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryDummyProof.with(|count| { + if count.get() > 0 { + return Err(arbitrary::Error::NotEnoughData); + } + count.set(count.get() + 1); + Ok(()) + })?; + } + let result = (|| { + Ok(ArbitraryDummyProof { + fp: arbitrary::Arbitrary::arbitrary(u)?, + fp2: arbitrary::Arbitrary::arbitrary(u)?, + g1: arbitrary::Arbitrary::arbitrary(u)?, + g2: arbitrary::Arbitrary::arbitrary(u)?, + fr: arbitrary::Arbitrary::arbitrary(u)?, + }) + })(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryDummyProof.with(|count| { + count.set(count.get() - 1); + }); + } + result + } + fn arbitrary_take_rest( + mut u: arbitrary::Unstructured<'arbitrary>, + ) -> arbitrary::Result { + let guard_against_recursion = u.is_empty(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryDummyProof.with(|count| { + if count.get() > 0 { + return Err(arbitrary::Error::NotEnoughData); + } + count.set(count.get() + 1); + Ok(()) + })?; + } + let result = (|| { + Ok(ArbitraryDummyProof { + fp: arbitrary::Arbitrary::arbitrary(&mut u)?, + fp2: arbitrary::Arbitrary::arbitrary(&mut u)?, + g1: arbitrary::Arbitrary::arbitrary(&mut u)?, + g2: arbitrary::Arbitrary::arbitrary(&mut u)?, + fr: arbitrary::Arbitrary::arbitrary_take_rest(u)?, + }) + })(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryDummyProof.with(|count| { + count.set(count.get() - 1); + }); + } + result + } + #[inline] + fn size_hint(depth: usize) -> (usize, Option) { + arbitrary::size_hint::recursion_guard(depth, |depth| { + arbitrary::size_hint::and_all( + &[ + <::Prototype as arbitrary::Arbitrary>::size_hint( + depth, + ), + <::Prototype as arbitrary::Arbitrary>::size_hint( + depth, + ), + <::Prototype as arbitrary::Arbitrary>::size_hint( + depth, + ), + <::Prototype as arbitrary::Arbitrary>::size_hint( + depth, + ), + <::Prototype as arbitrary::Arbitrary>::size_hint( + depth, + ), + ], + ) + }) + } + } + }; + impl soroban_sdk::testutils::arbitrary::SorobanArbitrary for DummyProof { + type Prototype = ArbitraryDummyProof; + } + impl soroban_sdk::TryFromVal for DummyProof { + type Error = soroban_sdk::ConversionError; + fn try_from_val( + env: &soroban_sdk::Env, + v: &ArbitraryDummyProof, + ) -> std::result::Result { + Ok(DummyProof { + fp: soroban_sdk::IntoVal::into_val(&v.fp, env), + fp2: soroban_sdk::IntoVal::into_val(&v.fp2, env), + g1: soroban_sdk::IntoVal::into_val(&v.g1, env), + g2: soroban_sdk::IntoVal::into_val(&v.g2, env), + fr: soroban_sdk::IntoVal::into_val(&v.fr, env), + }) + } + } +}; +#[automatically_derived] +impl ::core::clone::Clone for DummyProof { + #[inline] + fn clone(&self) -> DummyProof { + DummyProof { + fp: ::core::clone::Clone::clone(&self.fp), + fp2: ::core::clone::Clone::clone(&self.fp2), + g1: ::core::clone::Clone::clone(&self.g1), + g2: ::core::clone::Clone::clone(&self.g2), + fr: ::core::clone::Clone::clone(&self.fr), + } + } +} +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +impl Contract { + pub fn g1_mul(env: Env, p: G1Affine, s: Fr) -> G1Affine { + env.crypto().bls12_381().g1_mul(&p, &s) + } + pub fn g2_mul(env: Env, p: G2Affine, s: Fr) -> G2Affine { + env.crypto().bls12_381().g2_mul(&p, &s) + } + pub fn dummy_verify(env: Env, proof: DummyProof) -> bool { + let g1 = env.crypto().bls12_381().map_fp_to_g1(&proof.fp); + let in1 = env.crypto().bls12_381().g1_is_in_subgroup(&g1); + if true { + (&env).logs().add( + "`map_fp_to_g1` result is in subgroup: ", + &[<_ as ::soroban_sdk::IntoVal>::into_val(&in1, &env)], + ); + } + let g2 = env.crypto().bls12_381().map_fp2_to_g2(&proof.fp2); + let in2 = env.crypto().bls12_381().g2_is_in_subgroup(&g2); + if true { + (&env).logs().add( + "`map_fp2_to_g2` result is in subgroup: ", + &[<_ as ::soroban_sdk::IntoVal>::into_val(&in2, &env)], + ); + } + let g1_mul = env.crypto().bls12_381().g1_mul(&proof.g1, &proof.fr); + let g2_mul = env.crypto().bls12_381().g2_mul(&proof.g2, &proof.fr); + let vp1 = soroban_sdk::Vec::from_array(&env, [g1_mul]); + let vp2 = soroban_sdk::Vec::from_array(&env, [g2_mul]); + env.crypto().bls12_381().pairing_check(vp1, vp2) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__g1_mul__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_G1_MUL: [u8; 72usize] = super::Contract::spec_xdr_g1_mul(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_g1_mul() -> [u8; 72usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x06g1_mul\0\0\0\0\0\x02\0\0\0\0\0\0\0\x01p\0\0\0\0\0\x03\xee\0\0\0`\0\0\0\0\0\0\0\x01s\0\0\0\0\0\0\x0c\0\0\0\x01\0\0\x03\xee\0\0\0`" + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__g2_mul__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_G2_MUL: [u8; 72usize] = super::Contract::spec_xdr_g2_mul(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_g2_mul() -> [u8; 72usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x06g2_mul\0\0\0\0\0\x02\0\0\0\0\0\0\0\x01p\0\0\0\0\0\x03\xee\0\0\0\xc0\0\0\0\0\0\0\0\x01s\0\0\0\0\0\0\x0c\0\0\0\x01\0\0\x03\xee\0\0\0\xc0" + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__dummy_verify__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_DUMMY_VERIFY: [u8; 72usize] = super::Contract::spec_xdr_dummy_verify(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_dummy_verify() -> [u8; 72usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x0cdummy_verify\0\0\0\x01\0\0\0\0\0\0\0\x05proof\0\0\0\0\0\x07\xd0\0\0\0\nDummyProof\0\0\0\0\0\x01\0\0\0\x01" + } +} +impl<'a> ContractClient<'a> { + pub fn g1_mul(&self, p: &G1Affine, s: &Fr) -> G1Affine { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("g1_mul"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [p.into_val(&self.env), s.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_g1_mul( + &self, + p: &G1Affine, + s: &Fr, + ) -> Result< + Result< + G1Affine, + >::Error, + >, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("g1_mul"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [p.into_val(&self.env), s.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn g2_mul(&self, p: &G2Affine, s: &Fr) -> G2Affine { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("g2_mul"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [p.into_val(&self.env), s.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_g2_mul( + &self, + p: &G2Affine, + s: &Fr, + ) -> Result< + Result< + G2Affine, + >::Error, + >, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("g2_mul"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [p.into_val(&self.env), s.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn dummy_verify(&self, proof: &DummyProof) -> bool { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ soroban_sdk::Symbol::new(&self.env, "dummy_verify") }, + ::soroban_sdk::Vec::from_array(&self.env, [proof.into_val(&self.env)]), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_dummy_verify( + &self, + proof: &DummyProof, + ) -> Result< + Result>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ soroban_sdk::Symbol::new(&self.env, "dummy_verify") }, + ::soroban_sdk::Vec::from_array(&self.env, [proof.into_val(&self.env)]), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn g1_mul<'i>(p: &'i G1Affine, s: &'i Fr) -> (&'i G1Affine, &'i Fr) { + (p, s) + } + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn g2_mul<'i>(p: &'i G2Affine, s: &'i Fr) -> (&'i G2Affine, &'i Fr) { + (p, s) + } + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn dummy_verify<'i>(proof: &'i DummyProof) -> (&'i DummyProof,) { + (proof,) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__g1_mul { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).g1_mul` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::g1_mul( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).g1_mul` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 2usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 2usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize], args[1usize]) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).g1_mul` instead")] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__g2_mul { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).g2_mul` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::g2_mul( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).g2_mul` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 2usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 2usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize], args[1usize]) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).g2_mul` instead")] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__dummy_verify { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).dummy_verify` instead")] + pub fn invoke_raw(env: soroban_sdk::Env, arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::dummy_verify( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).dummy_verify` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 1usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 1usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize]) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).dummy_verify` instead")] + pub extern "C" fn invoke_raw_extern(arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__492d85ed5a5d2cb14995f41e785b3df9c7fcf4af92b6d50ce2c9fa7c9b1e350d_ctor() { + ::register( + "g1_mul", + #[allow(deprecated)] + &__Contract__g1_mul::invoke_raw_slice, + ); + ::register( + "g2_mul", + #[allow(deprecated)] + &__Contract__g2_mul::invoke_raw_slice, + ); + ::register( + "dummy_verify", + #[allow(deprecated)] + &__Contract__dummy_verify::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__492d85ed5a5d2cb14995f41e785b3df9c7fcf4af92b6d50ce2c9fa7c9b1e350d_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__492d85ed5a5d2cb14995f41e785b3df9c7fcf4af92b6d50ce2c9fa7c9b1e350d_ctor___rust_ctor___ctor() -> usize { + __Contract__492d85ed5a5d2cb14995f41e785b3df9c7fcf4af92b6d50ce2c9fa7c9b1e350d_ctor(); + 0 + } + __Contract__492d85ed5a5d2cb14995f41e785b3df9c7fcf4af92b6d50ce2c9fa7c9b1e350d_ctor___rust_ctor___ctor +}; +mod test { + use super::*; + use crate::{Contract, ContractClient}; + use soroban_sdk::{bytesn, Env}; + extern crate test; + #[rustc_test_marker = "test::test_g1_mul"] + #[doc(hidden)] + pub const test_g1_mul: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test_g1_mul"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/bls/src/lib.rs", + start_line: 56usize, + start_col: 8usize, + end_line: 56usize, + end_col: 19usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_g1_mul()), + ), + }; + fn test_g1_mul() { + let env = Env::default(); + let contract_id = env.register(Contract, ()); + let client = ContractClient::new(&env, &contract_id); + let g1 = G1Affine::from_bytes(::soroban_sdk::BytesN::from_array( + &env, + &[ + 23u8, 241u8, 211u8, 167u8, 49u8, 151u8, 215u8, 148u8, 38u8, 149u8, 99u8, 140u8, + 79u8, 169u8, 172u8, 15u8, 195u8, 104u8, 140u8, 79u8, 151u8, 116u8, 185u8, 5u8, + 161u8, 78u8, 58u8, 63u8, 23u8, 27u8, 172u8, 88u8, 108u8, 85u8, 232u8, 63u8, 249u8, + 122u8, 26u8, 239u8, 251u8, 58u8, 240u8, 10u8, 219u8, 34u8, 198u8, 187u8, 8u8, + 179u8, 244u8, 129u8, 227u8, 170u8, 160u8, 241u8, 160u8, 158u8, 48u8, 237u8, 116u8, + 29u8, 138u8, 228u8, 252u8, 245u8, 224u8, 149u8, 213u8, 208u8, 10u8, 246u8, 0u8, + 219u8, 24u8, 203u8, 44u8, 4u8, 179u8, 237u8, 208u8, 60u8, 199u8, 68u8, 162u8, + 136u8, 138u8, 228u8, 12u8, 170u8, 35u8, 41u8, 70u8, 197u8, 231u8, 225u8, + ], + )); + let zero = Fr::from_bytes(::soroban_sdk::BytesN::from_array( + &env, + &[ + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + ], + )); + let inf = G1Affine::from_bytes(::soroban_sdk::BytesN::from_array( + &env, + &[ + 64u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + ], + )); + let res = client.g1_mul(&g1, &zero); + match (&res, &inf) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + } + extern crate test; + #[rustc_test_marker = "test::test_g2_mul"] + #[doc(hidden)] + pub const test_g2_mul: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test_g2_mul"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/bls/src/lib.rs", + start_line: 73usize, + start_col: 8usize, + end_line: 73usize, + end_col: 19usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_g2_mul()), + ), + }; + fn test_g2_mul() { + let env = Env::default(); + let contract_id = env.register(Contract, ()); + let client = ContractClient::new(&env, &contract_id); + let g2 = G2Affine::from_bytes(::soroban_sdk::BytesN::from_array( + &env, + &[ + 19u8, 224u8, 43u8, 96u8, 82u8, 113u8, 159u8, 96u8, 125u8, 172u8, 211u8, 160u8, + 136u8, 39u8, 79u8, 101u8, 89u8, 107u8, 208u8, 208u8, 153u8, 32u8, 182u8, 26u8, + 181u8, 218u8, 97u8, 187u8, 220u8, 127u8, 80u8, 73u8, 51u8, 76u8, 241u8, 18u8, 19u8, + 148u8, 93u8, 87u8, 229u8, 172u8, 125u8, 5u8, 93u8, 4u8, 43u8, 126u8, 2u8, 74u8, + 162u8, 178u8, 240u8, 143u8, 10u8, 145u8, 38u8, 8u8, 5u8, 39u8, 45u8, 197u8, 16u8, + 81u8, 198u8, 228u8, 122u8, 212u8, 250u8, 64u8, 59u8, 2u8, 180u8, 81u8, 11u8, 100u8, + 122u8, 227u8, 209u8, 119u8, 11u8, 172u8, 3u8, 38u8, 168u8, 5u8, 187u8, 239u8, + 212u8, 128u8, 86u8, 200u8, 193u8, 33u8, 189u8, 184u8, 6u8, 6u8, 196u8, 160u8, 46u8, + 167u8, 52u8, 204u8, 50u8, 172u8, 210u8, 176u8, 43u8, 194u8, 139u8, 153u8, 203u8, + 62u8, 40u8, 126u8, 133u8, 167u8, 99u8, 175u8, 38u8, 116u8, 146u8, 171u8, 87u8, + 46u8, 153u8, 171u8, 63u8, 55u8, 13u8, 39u8, 92u8, 236u8, 29u8, 161u8, 170u8, 169u8, + 7u8, 95u8, 240u8, 95u8, 121u8, 190u8, 12u8, 229u8, 213u8, 39u8, 114u8, 125u8, + 110u8, 17u8, 140u8, 201u8, 205u8, 198u8, 218u8, 46u8, 53u8, 26u8, 173u8, 253u8, + 155u8, 170u8, 140u8, 189u8, 211u8, 167u8, 109u8, 66u8, 154u8, 105u8, 81u8, 96u8, + 209u8, 44u8, 146u8, 58u8, 201u8, 204u8, 59u8, 172u8, 162u8, 137u8, 225u8, 147u8, + 84u8, 134u8, 8u8, 184u8, 40u8, 1u8, + ], + )); + let zero = Fr::from_bytes(::soroban_sdk::BytesN::from_array( + &env, + &[ + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + ], + )); + let inf = G2Affine::from_bytes(::soroban_sdk::BytesN::from_array( + &env, + &[ + 64u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + ], + )); + let res = client.g2_mul(&g2, &zero); + match (&res, &inf) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + } + extern crate test; + #[rustc_test_marker = "test::test_dummy_verify"] + #[doc(hidden)] + pub const test_dummy_verify: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test_dummy_verify"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/bls/src/lib.rs", + start_line: 90usize, + start_col: 8usize, + end_line: 90usize, + end_col: 25usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_dummy_verify()), + ), + }; + fn test_dummy_verify() { + let env = Env::default(); + let contract_id = env.register(Contract, ()); + let client = ContractClient::new(&env, &contract_id); + let fp = Fp::from_bytes(::soroban_sdk::BytesN::from_array( + &env, + &[ + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, + ], + )); + let fp2 = Fp2::from_bytes(::soroban_sdk::BytesN::from_array( + &env, + &[ + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, + ], + )); + let g1 = G1Affine::from_bytes(::soroban_sdk::BytesN::from_array( + &env, + &[ + 23u8, 241u8, 211u8, 167u8, 49u8, 151u8, 215u8, 148u8, 38u8, 149u8, 99u8, 140u8, + 79u8, 169u8, 172u8, 15u8, 195u8, 104u8, 140u8, 79u8, 151u8, 116u8, 185u8, 5u8, + 161u8, 78u8, 58u8, 63u8, 23u8, 27u8, 172u8, 88u8, 108u8, 85u8, 232u8, 63u8, 249u8, + 122u8, 26u8, 239u8, 251u8, 58u8, 240u8, 10u8, 219u8, 34u8, 198u8, 187u8, 8u8, + 179u8, 244u8, 129u8, 227u8, 170u8, 160u8, 241u8, 160u8, 158u8, 48u8, 237u8, 116u8, + 29u8, 138u8, 228u8, 252u8, 245u8, 224u8, 149u8, 213u8, 208u8, 10u8, 246u8, 0u8, + 219u8, 24u8, 203u8, 44u8, 4u8, 179u8, 237u8, 208u8, 60u8, 199u8, 68u8, 162u8, + 136u8, 138u8, 228u8, 12u8, 170u8, 35u8, 41u8, 70u8, 197u8, 231u8, 225u8, + ], + )); + let g2 = G2Affine::from_bytes(::soroban_sdk::BytesN::from_array( + &env, + &[ + 19u8, 224u8, 43u8, 96u8, 82u8, 113u8, 159u8, 96u8, 125u8, 172u8, 211u8, 160u8, + 136u8, 39u8, 79u8, 101u8, 89u8, 107u8, 208u8, 208u8, 153u8, 32u8, 182u8, 26u8, + 181u8, 218u8, 97u8, 187u8, 220u8, 127u8, 80u8, 73u8, 51u8, 76u8, 241u8, 18u8, 19u8, + 148u8, 93u8, 87u8, 229u8, 172u8, 125u8, 5u8, 93u8, 4u8, 43u8, 126u8, 2u8, 74u8, + 162u8, 178u8, 240u8, 143u8, 10u8, 145u8, 38u8, 8u8, 5u8, 39u8, 45u8, 197u8, 16u8, + 81u8, 198u8, 228u8, 122u8, 212u8, 250u8, 64u8, 59u8, 2u8, 180u8, 81u8, 11u8, 100u8, + 122u8, 227u8, 209u8, 119u8, 11u8, 172u8, 3u8, 38u8, 168u8, 5u8, 187u8, 239u8, + 212u8, 128u8, 86u8, 200u8, 193u8, 33u8, 189u8, 184u8, 6u8, 6u8, 196u8, 160u8, 46u8, + 167u8, 52u8, 204u8, 50u8, 172u8, 210u8, 176u8, 43u8, 194u8, 139u8, 153u8, 203u8, + 62u8, 40u8, 126u8, 133u8, 167u8, 99u8, 175u8, 38u8, 116u8, 146u8, 171u8, 87u8, + 46u8, 153u8, 171u8, 63u8, 55u8, 13u8, 39u8, 92u8, 236u8, 29u8, 161u8, 170u8, 169u8, + 7u8, 95u8, 240u8, 95u8, 121u8, 190u8, 12u8, 229u8, 213u8, 39u8, 114u8, 125u8, + 110u8, 17u8, 140u8, 201u8, 205u8, 198u8, 218u8, 46u8, 53u8, 26u8, 173u8, 253u8, + 155u8, 170u8, 140u8, 189u8, 211u8, 167u8, 109u8, 66u8, 154u8, 105u8, 81u8, 96u8, + 209u8, 44u8, 146u8, 58u8, 201u8, 204u8, 59u8, 172u8, 162u8, 137u8, 225u8, 147u8, + 84u8, 134u8, 8u8, 184u8, 40u8, 1u8, + ], + )); + let fr = Fr::from_bytes(::soroban_sdk::BytesN::from_array( + &env, + &[ + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, + 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, + ], + )); + let proof = DummyProof { + fp, + fp2, + g1, + g2, + fr, + }; + let res = client.dummy_verify(&proof); + if !!res { + ::core::panicking::panic("assertion failed: !res") + } + } +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[&test_dummy_verify, &test_g1_mul, &test_g2_mul]) +} diff --git a/tests-expanded/test_bls_wasm32v1-none.rs b/tests-expanded/test_bls_wasm32v1-none.rs new file mode 100644 index 000000000..7f320f2e1 --- /dev/null +++ b/tests-expanded/test_bls_wasm32v1-none.rs @@ -0,0 +1,435 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{ + contract, contractimpl, contracttype, + crypto::bls12_381::{Fp, Fp2, Fr, G1Affine, G2Affine}, + log, Env, +}; +pub struct DummyProof { + pub fp: Fp, + pub fp2: Fp2, + pub g1: G1Affine, + pub g2: G2Affine, + pub fr: Fr, +} +#[link_section = "contractspecv0"] +pub static __SPEC_XDR_TYPE_DUMMYPROOF: [u8; 128usize] = DummyProof::spec_xdr(); +impl DummyProof { + pub const fn spec_xdr() -> [u8; 128usize] { + *b"\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\nDummyProof\0\0\0\0\0\x05\0\0\0\0\0\0\0\x02fp\0\0\0\0\x03\xee\0\0\00\0\0\0\0\0\0\0\x03fp2\0\0\0\x03\xee\0\0\0`\0\0\0\0\0\0\0\x02fr\0\0\0\0\0\x0c\0\0\0\0\0\0\0\x02g1\0\0\0\0\x03\xee\0\0\0`\0\0\0\0\0\0\0\x02g2\0\0\0\0\x03\xee\0\0\0\xc0" + } +} +impl soroban_sdk::TryFromVal for DummyProof { + type Error = soroban_sdk::ConversionError; + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::{ConversionError, EnvBase, MapObject, TryIntoVal, Val}; + const KEYS: [&'static str; 5usize] = ["fp", "fp2", "fr", "g1", "g2"]; + let mut vals: [Val; 5usize] = [Val::VOID.to_val(); 5usize]; + let map: MapObject = val.try_into().map_err(|_| ConversionError)?; + env.map_unpack_to_slice(map, &KEYS, &mut vals) + .map_err(|_| ConversionError)?; + Ok(Self { + fp: vals[0] + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?, + fp2: vals[1] + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?, + fr: vals[2] + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?, + g1: vals[3] + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?, + g2: vals[4] + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?, + }) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + fn try_from_val( + env: &soroban_sdk::Env, + val: &DummyProof, + ) -> Result { + use soroban_sdk::{ConversionError, EnvBase, TryIntoVal, Val}; + const KEYS: [&'static str; 5usize] = ["fp", "fp2", "fr", "g1", "g2"]; + let vals: [Val; 5usize] = [ + (&val.fp).try_into_val(env).map_err(|_| ConversionError)?, + (&val.fp2).try_into_val(env).map_err(|_| ConversionError)?, + (&val.fr).try_into_val(env).map_err(|_| ConversionError)?, + (&val.g1).try_into_val(env).map_err(|_| ConversionError)?, + (&val.g2).try_into_val(env).map_err(|_| ConversionError)?, + ]; + Ok(env + .map_new_from_slices(&KEYS, &vals) + .map_err(|_| ConversionError)? + .into()) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&DummyProof, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } +} +#[automatically_derived] +impl ::core::clone::Clone for DummyProof { + #[inline] + fn clone(&self) -> DummyProof { + DummyProof { + fp: ::core::clone::Clone::clone(&self.fp), + fp2: ::core::clone::Clone::clone(&self.fp2), + g1: ::core::clone::Clone::clone(&self.g1), + g2: ::core::clone::Clone::clone(&self.g2), + fr: ::core::clone::Clone::clone(&self.fr), + } + } +} +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl Contract { + pub fn g1_mul(env: Env, p: G1Affine, s: Fr) -> G1Affine { + env.crypto().bls12_381().g1_mul(&p, &s) + } + pub fn g2_mul(env: Env, p: G2Affine, s: Fr) -> G2Affine { + env.crypto().bls12_381().g2_mul(&p, &s) + } + pub fn dummy_verify(env: Env, proof: DummyProof) -> bool { + let g1 = env.crypto().bls12_381().map_fp_to_g1(&proof.fp); + let in1 = env.crypto().bls12_381().g1_is_in_subgroup(&g1); + if false { + (&env).logs().add( + "`map_fp_to_g1` result is in subgroup: ", + &[<_ as ::soroban_sdk::IntoVal>::into_val(&in1, &env)], + ); + } + let g2 = env.crypto().bls12_381().map_fp2_to_g2(&proof.fp2); + let in2 = env.crypto().bls12_381().g2_is_in_subgroup(&g2); + if false { + (&env).logs().add( + "`map_fp2_to_g2` result is in subgroup: ", + &[<_ as ::soroban_sdk::IntoVal>::into_val(&in2, &env)], + ); + } + let g1_mul = env.crypto().bls12_381().g1_mul(&proof.g1, &proof.fr); + let g2_mul = env.crypto().bls12_381().g2_mul(&proof.g2, &proof.fr); + let vp1 = soroban_sdk::Vec::from_array(&env, [g1_mul]); + let vp2 = soroban_sdk::Vec::from_array(&env, [g2_mul]); + env.crypto().bls12_381().pairing_check(vp1, vp2) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__g1_mul__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_G1_MUL: [u8; 72usize] = super::Contract::spec_xdr_g1_mul(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_g1_mul() -> [u8; 72usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x06g1_mul\0\0\0\0\0\x02\0\0\0\0\0\0\0\x01p\0\0\0\0\0\x03\xee\0\0\0`\0\0\0\0\0\0\0\x01s\0\0\0\0\0\0\x0c\0\0\0\x01\0\0\x03\xee\0\0\0`" + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__g2_mul__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_G2_MUL: [u8; 72usize] = super::Contract::spec_xdr_g2_mul(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_g2_mul() -> [u8; 72usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x06g2_mul\0\0\0\0\0\x02\0\0\0\0\0\0\0\x01p\0\0\0\0\0\x03\xee\0\0\0\xc0\0\0\0\0\0\0\0\x01s\0\0\0\0\0\0\x0c\0\0\0\x01\0\0\x03\xee\0\0\0\xc0" + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__dummy_verify__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_DUMMY_VERIFY: [u8; 72usize] = super::Contract::spec_xdr_dummy_verify(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_dummy_verify() -> [u8; 72usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x0cdummy_verify\0\0\0\x01\0\0\0\0\0\0\0\x05proof\0\0\0\0\0\x07\xd0\0\0\0\nDummyProof\0\0\0\0\0\x01\0\0\0\x01" + } +} +impl<'a> ContractClient<'a> { + pub fn g1_mul(&self, p: &G1Affine, s: &Fr) -> G1Affine { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("g1_mul"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [p.into_val(&self.env), s.into_val(&self.env)], + ), + ); + res + } + pub fn try_g1_mul( + &self, + p: &G1Affine, + s: &Fr, + ) -> Result< + Result< + G1Affine, + >::Error, + >, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("g1_mul"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [p.into_val(&self.env), s.into_val(&self.env)], + ), + ); + res + } + pub fn g2_mul(&self, p: &G2Affine, s: &Fr) -> G2Affine { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("g2_mul"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [p.into_val(&self.env), s.into_val(&self.env)], + ), + ); + res + } + pub fn try_g2_mul( + &self, + p: &G2Affine, + s: &Fr, + ) -> Result< + Result< + G2Affine, + >::Error, + >, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("g2_mul"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [p.into_val(&self.env), s.into_val(&self.env)], + ), + ); + res + } + pub fn dummy_verify(&self, proof: &DummyProof) -> bool { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ soroban_sdk::Symbol::new(&self.env, "dummy_verify") }, + ::soroban_sdk::Vec::from_array(&self.env, [proof.into_val(&self.env)]), + ); + res + } + pub fn try_dummy_verify( + &self, + proof: &DummyProof, + ) -> Result< + Result>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ soroban_sdk::Symbol::new(&self.env, "dummy_verify") }, + ::soroban_sdk::Vec::from_array(&self.env, [proof.into_val(&self.env)]), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn g1_mul<'i>(p: &'i G1Affine, s: &'i Fr) -> (&'i G1Affine, &'i Fr) { + (p, s) + } + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn g2_mul<'i>(p: &'i G2Affine, s: &'i Fr) -> (&'i G2Affine, &'i Fr) { + (p, s) + } + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn dummy_verify<'i>(proof: &'i DummyProof) -> (&'i DummyProof,) { + (proof,) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__g1_mul { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).g1_mul` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::g1_mul( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).g1_mul` instead")] + #[export_name = "g1_mul"] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__g2_mul { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).g2_mul` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::g2_mul( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).g2_mul` instead")] + #[export_name = "g2_mul"] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__dummy_verify { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).dummy_verify` instead")] + pub fn invoke_raw(env: soroban_sdk::Env, arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::dummy_verify( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).dummy_verify` instead")] + #[export_name = "dummy_verify"] + pub extern "C" fn invoke_raw_extern(arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0) + } + use super::*; +} diff --git a/tests-expanded/test_constructor_tests.rs b/tests-expanded/test_constructor_tests.rs new file mode 100644 index 000000000..130b38ad6 --- /dev/null +++ b/tests-expanded/test_constructor_tests.rs @@ -0,0 +1,1196 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl, contracttype, Env}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +pub enum DataKey { + Persistent(u32), + Temp(u32), + Instance(u32), +} +pub static __SPEC_XDR_TYPE_DATAKEY: [u8; 112usize] = DataKey::spec_xdr(); +impl DataKey { + pub const fn spec_xdr() -> [u8; 112usize] { + *b"\0\0\0\x02\0\0\0\0\0\0\0\0\0\0\0\x07DataKey\0\0\0\0\x03\0\0\0\x01\0\0\0\0\0\0\0\nPersistent\0\0\0\0\0\x01\0\0\0\x04\0\0\0\x01\0\0\0\0\0\0\0\x04Temp\0\0\0\x01\0\0\0\x04\0\0\0\x01\0\0\0\0\0\0\0\x08Instance\0\0\0\x01\0\0\0\x04" + } +} +impl soroban_sdk::TryFromVal for DataKey { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::{EnvBase, TryFromVal, TryIntoVal}; + const CASES: &'static [&'static str] = &["Persistent", "Temp", "Instance"]; + let vec: soroban_sdk::Vec = val.try_into_val(env)?; + let mut iter = vec.try_iter(); + let discriminant: soroban_sdk::Symbol = iter + .next() + .ok_or(soroban_sdk::ConversionError)?? + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?; + Ok( + match u32::from(env.symbol_index_in_strs(discriminant.to_symbol_val(), CASES)?) as usize + { + 0 => { + if iter.len() > 1usize { + return Err(soroban_sdk::ConversionError); + } + Self::Persistent( + iter.next() + .ok_or(soroban_sdk::ConversionError)?? + .try_into_val(env)?, + ) + } + 1 => { + if iter.len() > 1usize { + return Err(soroban_sdk::ConversionError); + } + Self::Temp( + iter.next() + .ok_or(soroban_sdk::ConversionError)?? + .try_into_val(env)?, + ) + } + 2 => { + if iter.len() > 1usize { + return Err(soroban_sdk::ConversionError); + } + Self::Instance( + iter.next() + .ok_or(soroban_sdk::ConversionError)?? + .try_into_val(env)?, + ) + } + _ => Err(soroban_sdk::ConversionError {})?, + }, + ) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &DataKey, + ) -> Result { + use soroban_sdk::{TryFromVal, TryIntoVal}; + match val { + DataKey::Persistent(ref value0) => { + let tup: (soroban_sdk::Val, soroban_sdk::Val) = ( + soroban_sdk::Symbol::try_from_val(env, &"Persistent")?.to_val(), + value0.try_into_val(env)?, + ); + tup.try_into_val(env).map_err(Into::into) + } + DataKey::Temp(ref value0) => { + let tup: (soroban_sdk::Val, soroban_sdk::Val) = ( + soroban_sdk::Symbol::try_from_val(env, &"Temp")?.to_val(), + value0.try_into_val(env)?, + ); + tup.try_into_val(env).map_err(Into::into) + } + DataKey::Instance(ref value0) => { + let tup: (soroban_sdk::Val, soroban_sdk::Val) = ( + soroban_sdk::Symbol::try_from_val(env, &"Instance")?.to_val(), + value0.try_into_val(env)?, + ); + tup.try_into_val(env).map_err(Into::into) + } + } + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&DataKey, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } +} +impl soroban_sdk::TryFromVal for DataKey { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::xdr::ScVec, + ) -> Result { + use soroban_sdk::xdr::Validate; + use soroban_sdk::TryIntoVal; + let vec = val; + let mut iter = vec.iter(); + let discriminant: soroban_sdk::xdr::ScSymbol = iter + .next() + .ok_or(soroban_sdk::xdr::Error::Invalid)? + .clone() + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + let discriminant_name: &str = &discriminant.to_utf8_string()?; + Ok(match discriminant_name { + "Persistent" => { + if iter.len() > 1usize { + return Err(soroban_sdk::xdr::Error::Invalid); + } + let rv0: soroban_sdk::Val = iter + .next() + .ok_or(soroban_sdk::xdr::Error::Invalid)? + .try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + Self::Persistent( + rv0.try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + } + "Temp" => { + if iter.len() > 1usize { + return Err(soroban_sdk::xdr::Error::Invalid); + } + let rv0: soroban_sdk::Val = iter + .next() + .ok_or(soroban_sdk::xdr::Error::Invalid)? + .try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + Self::Temp( + rv0.try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + } + "Instance" => { + if iter.len() > 1usize { + return Err(soroban_sdk::xdr::Error::Invalid); + } + let rv0: soroban_sdk::Val = iter + .next() + .ok_or(soroban_sdk::xdr::Error::Invalid)? + .try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + Self::Instance( + rv0.try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + } + _ => Err(soroban_sdk::xdr::Error::Invalid)?, + }) + } +} +impl soroban_sdk::TryFromVal for DataKey { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::xdr::ScVal, + ) -> Result { + if let soroban_sdk::xdr::ScVal::Vec(Some(vec)) = val { + <_ as soroban_sdk::TryFromVal<_, _>>::try_from_val(env, vec) + } else { + Err(soroban_sdk::xdr::Error::Invalid) + } + } +} +impl TryFrom<&DataKey> for soroban_sdk::xdr::ScVec { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: &DataKey) -> Result { + extern crate alloc; + Ok(match val { + DataKey::Persistent(value0) => ( + soroban_sdk::xdr::ScSymbol( + "Persistent" + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ), + value0, + ) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + DataKey::Temp(value0) => ( + soroban_sdk::xdr::ScSymbol( + "Temp" + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ), + value0, + ) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + DataKey::Instance(value0) => ( + soroban_sdk::xdr::ScSymbol( + "Instance" + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ), + value0, + ) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + }) + } +} +impl TryFrom for soroban_sdk::xdr::ScVec { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: DataKey) -> Result { + (&val).try_into() + } +} +impl TryFrom<&DataKey> for soroban_sdk::xdr::ScVal { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: &DataKey) -> Result { + Ok(soroban_sdk::xdr::ScVal::Vec(Some(val.try_into()?))) + } +} +impl TryFrom for soroban_sdk::xdr::ScVal { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: DataKey) -> Result { + (&val).try_into() + } +} +const _: () = { + use soroban_sdk::testutils::arbitrary::arbitrary; + use soroban_sdk::testutils::arbitrary::std; + pub enum ArbitraryDataKey { + Persistent(::Prototype), + Temp(::Prototype), + Instance(::Prototype), + } + #[automatically_derived] + impl ::core::fmt::Debug for ArbitraryDataKey { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + ArbitraryDataKey::Persistent(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Persistent", &__self_0) + } + ArbitraryDataKey::Temp(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Temp", &__self_0) + } + ArbitraryDataKey::Instance(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Instance", &__self_0) + } + } + } + } + #[automatically_derived] + impl ::core::clone::Clone for ArbitraryDataKey { + #[inline] + fn clone(&self) -> ArbitraryDataKey { + match self { + ArbitraryDataKey::Persistent(__self_0) => { + ArbitraryDataKey::Persistent(::core::clone::Clone::clone(__self_0)) + } + ArbitraryDataKey::Temp(__self_0) => { + ArbitraryDataKey::Temp(::core::clone::Clone::clone(__self_0)) + } + ArbitraryDataKey::Instance(__self_0) => { + ArbitraryDataKey::Instance(::core::clone::Clone::clone(__self_0)) + } + } + } + } + #[automatically_derived] + impl ::core::cmp::Eq for ArbitraryDataKey { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () { + let _: ::core::cmp::AssertParamIsEq< + ::Prototype, + >; + let _: ::core::cmp::AssertParamIsEq< + ::Prototype, + >; + let _: ::core::cmp::AssertParamIsEq< + ::Prototype, + >; + } + } + #[automatically_derived] + impl ::core::marker::StructuralPartialEq for ArbitraryDataKey {} + #[automatically_derived] + impl ::core::cmp::PartialEq for ArbitraryDataKey { + #[inline] + fn eq(&self, other: &ArbitraryDataKey) -> bool { + let __self_discr = ::core::intrinsics::discriminant_value(self); + let __arg1_discr = ::core::intrinsics::discriminant_value(other); + __self_discr == __arg1_discr + && match (self, other) { + ( + ArbitraryDataKey::Persistent(__self_0), + ArbitraryDataKey::Persistent(__arg1_0), + ) => __self_0 == __arg1_0, + (ArbitraryDataKey::Temp(__self_0), ArbitraryDataKey::Temp(__arg1_0)) => { + __self_0 == __arg1_0 + } + ( + ArbitraryDataKey::Instance(__self_0), + ArbitraryDataKey::Instance(__arg1_0), + ) => __self_0 == __arg1_0, + _ => unsafe { ::core::intrinsics::unreachable() }, + } + } + } + #[automatically_derived] + impl ::core::cmp::Ord for ArbitraryDataKey { + #[inline] + fn cmp(&self, other: &ArbitraryDataKey) -> ::core::cmp::Ordering { + let __self_discr = ::core::intrinsics::discriminant_value(self); + let __arg1_discr = ::core::intrinsics::discriminant_value(other); + match ::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr) { + ::core::cmp::Ordering::Equal => match (self, other) { + ( + ArbitraryDataKey::Persistent(__self_0), + ArbitraryDataKey::Persistent(__arg1_0), + ) => ::core::cmp::Ord::cmp(__self_0, __arg1_0), + (ArbitraryDataKey::Temp(__self_0), ArbitraryDataKey::Temp(__arg1_0)) => { + ::core::cmp::Ord::cmp(__self_0, __arg1_0) + } + ( + ArbitraryDataKey::Instance(__self_0), + ArbitraryDataKey::Instance(__arg1_0), + ) => ::core::cmp::Ord::cmp(__self_0, __arg1_0), + _ => unsafe { ::core::intrinsics::unreachable() }, + }, + cmp => cmp, + } + } + } + #[automatically_derived] + impl ::core::cmp::PartialOrd for ArbitraryDataKey { + #[inline] + fn partial_cmp( + &self, + other: &ArbitraryDataKey, + ) -> ::core::option::Option<::core::cmp::Ordering> { + let __self_discr = ::core::intrinsics::discriminant_value(self); + let __arg1_discr = ::core::intrinsics::discriminant_value(other); + match (self, other) { + ( + ArbitraryDataKey::Persistent(__self_0), + ArbitraryDataKey::Persistent(__arg1_0), + ) => ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0), + (ArbitraryDataKey::Temp(__self_0), ArbitraryDataKey::Temp(__arg1_0)) => { + ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0) + } + (ArbitraryDataKey::Instance(__self_0), ArbitraryDataKey::Instance(__arg1_0)) => { + ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0) + } + _ => ::core::cmp::PartialOrd::partial_cmp(&__self_discr, &__arg1_discr), + } + } + } + const _: () = { + #[allow(non_upper_case_globals)] + const RECURSIVE_COUNT_ArbitraryDataKey: ::std::thread::LocalKey> = { + #[inline] + fn __init() -> std::cell::Cell { + std::cell::Cell::new(0) + } + unsafe { + ::std::thread::LocalKey::new( + const { + if ::std::mem::needs_drop::>() { + |init| { + #[thread_local] + static VAL: ::std::thread::local_impl::LazyStorage< + std::cell::Cell, + (), + > = ::std::thread::local_impl::LazyStorage::new(); + VAL.get_or_init(init, __init) + } + } else { + |init| { + #[thread_local] + static VAL: ::std::thread::local_impl::LazyStorage< + std::cell::Cell, + !, + > = ::std::thread::local_impl::LazyStorage::new(); + VAL.get_or_init(init, __init) + } + } + }, + ) + } + }; + #[automatically_derived] + impl<'arbitrary> arbitrary::Arbitrary<'arbitrary> for ArbitraryDataKey { + fn arbitrary(u: &mut arbitrary::Unstructured<'arbitrary>) -> arbitrary::Result { + let guard_against_recursion = u.is_empty(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryDataKey.with(|count| { + if count.get() > 0 { + return Err(arbitrary::Error::NotEnoughData); + } + count.set(count.get() + 1); + Ok(()) + })?; + } + let result = (|| { + Ok( + match (u64::from(::arbitrary(u)?) * 3u64) >> 32 + { + 0u64 => { + ArbitraryDataKey::Persistent(arbitrary::Arbitrary::arbitrary(u)?) + } + 1u64 => ArbitraryDataKey::Temp(arbitrary::Arbitrary::arbitrary(u)?), + 2u64 => ArbitraryDataKey::Instance(arbitrary::Arbitrary::arbitrary(u)?), + _ => { + ::core::panicking::panic("internal error: entered unreachable code") + } + }, + ) + })(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryDataKey.with(|count| { + count.set(count.get() - 1); + }); + } + result + } + fn arbitrary_take_rest( + mut u: arbitrary::Unstructured<'arbitrary>, + ) -> arbitrary::Result { + let guard_against_recursion = u.is_empty(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryDataKey.with(|count| { + if count.get() > 0 { + return Err(arbitrary::Error::NotEnoughData); + } + count.set(count.get() + 1); + Ok(()) + })?; + } + let result = (|| { + Ok( + match (u64::from(::arbitrary(&mut u)?) * 3u64) + >> 32 + { + 0u64 => ArbitraryDataKey::Persistent( + arbitrary::Arbitrary::arbitrary_take_rest(u)?, + ), + 1u64 => ArbitraryDataKey::Temp( + arbitrary::Arbitrary::arbitrary_take_rest(u)?, + ), + 2u64 => ArbitraryDataKey::Instance( + arbitrary::Arbitrary::arbitrary_take_rest(u)?, + ), + _ => { + ::core::panicking::panic("internal error: entered unreachable code") + } + }, + ) + })(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryDataKey.with(|count| { + count.set(count.get() - 1); + }); + } + result + } + #[inline] + fn size_hint(depth: usize) -> (usize, Option) { + arbitrary::size_hint::and( + ::size_hint(depth), + arbitrary::size_hint::recursion_guard(depth, |depth| { + arbitrary::size_hint::or_all( + &[ + arbitrary::size_hint::and_all( + &[ + <::Prototype as arbitrary::Arbitrary>::size_hint( + depth, + ), + ], + ), + arbitrary::size_hint::and_all( + &[ + <::Prototype as arbitrary::Arbitrary>::size_hint( + depth, + ), + ], + ), + arbitrary::size_hint::and_all( + &[ + <::Prototype as arbitrary::Arbitrary>::size_hint( + depth, + ), + ], + ), + ], + ) + }), + ) + } + } + }; + impl soroban_sdk::testutils::arbitrary::SorobanArbitrary for DataKey { + type Prototype = ArbitraryDataKey; + } + impl soroban_sdk::TryFromVal for DataKey { + type Error = soroban_sdk::ConversionError; + fn try_from_val( + env: &soroban_sdk::Env, + v: &ArbitraryDataKey, + ) -> std::result::Result { + Ok(match v { + ArbitraryDataKey::Persistent(field_0) => { + DataKey::Persistent(soroban_sdk::IntoVal::into_val(field_0, env)) + } + ArbitraryDataKey::Temp(field_0) => { + DataKey::Temp(soroban_sdk::IntoVal::into_val(field_0, env)) + } + ArbitraryDataKey::Instance(field_0) => { + DataKey::Instance(soroban_sdk::IntoVal::into_val(field_0, env)) + } + }) + } + } +}; +impl Contract { + pub fn __constructor(env: Env, init_key: u32, init_value: i64) { + env.storage() + .persistent() + .set(&DataKey::Persistent(init_key), &init_value); + env.storage() + .temporary() + .set(&DataKey::Temp(init_key * 2), &(init_value * 2)); + env.storage() + .instance() + .set(&DataKey::Instance(init_key * 3), &(init_value * 3)); + } + pub fn get_data(env: Env, key: DataKey) -> Option { + match key { + DataKey::Persistent(_) => env.storage().persistent().get(&key), + DataKey::Temp(_) => env.storage().temporary().get(&key), + DataKey::Instance(_) => env.storage().instance().get(&key), + } + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract____constructor__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN___CONSTRUCTOR: [u8; 80usize] = + super::Contract::spec_xdr___constructor(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr___constructor() -> [u8; 80usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\r__constructor\0\0\0\0\0\0\x02\0\0\0\0\0\0\0\x08init_key\0\0\0\x04\0\0\0\0\0\0\0\ninit_value\0\0\0\0\0\x07\0\0\0\0" + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__get_data__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_GET_DATA: [u8; 64usize] = super::Contract::spec_xdr_get_data(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_get_data() -> [u8; 64usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x08get_data\0\0\0\x01\0\0\0\0\0\0\0\x03key\0\0\0\x07\xd0\0\0\0\x07DataKey\0\0\0\0\x01\0\0\x03\xe8\0\0\0\x07" + } +} +impl<'a> ContractClient<'a> { + pub fn get_data(&self, key: &DataKey) -> Option { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("get_data"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [key.into_val(&self.env)]), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_get_data( + &self, + key: &DataKey, + ) -> Result< + Result< + Option, + as soroban_sdk::TryFromVal>::Error, + >, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("get_data"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [key.into_val(&self.env)]), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn __constructor<'i>(init_key: &'i u32, init_value: &'i i64) -> (&'i u32, &'i i64) { + (init_key, init_value) + } + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn get_data<'i>(key: &'i DataKey) -> (&'i DataKey,) { + (key,) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract____constructor { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).__constructor` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::__constructor( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).__constructor` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 2usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 2usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize], args[1usize]) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).__constructor` instead")] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__get_data { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).get_data` instead")] + pub fn invoke_raw(env: soroban_sdk::Env, arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::get_data( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).get_data` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 1usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 1usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize]) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).get_data` instead")] + pub extern "C" fn invoke_raw_extern(arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__99dc7227b32e52c8d11ead5dec3dd80bafdad62d74493e7341c782fd8cb13593_ctor() { + ::register( + "__constructor", + #[allow(deprecated)] + &__Contract____constructor::invoke_raw_slice, + ); + ::register( + "get_data", + #[allow(deprecated)] + &__Contract__get_data::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__99dc7227b32e52c8d11ead5dec3dd80bafdad62d74493e7341c782fd8cb13593_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__99dc7227b32e52c8d11ead5dec3dd80bafdad62d74493e7341c782fd8cb13593_ctor___rust_ctor___ctor() -> usize { + __Contract__99dc7227b32e52c8d11ead5dec3dd80bafdad62d74493e7341c782fd8cb13593_ctor(); + 0 + } + __Contract__99dc7227b32e52c8d11ead5dec3dd80bafdad62d74493e7341c782fd8cb13593_ctor___rust_ctor___ctor +}; +extern crate test; +#[rustc_test_marker = "test_constructor"] +#[doc(hidden)] +pub const test_constructor: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test_constructor"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/constructor/src/lib.rs", + start_line: 38usize, + start_col: 4usize, + end_line: 38usize, + end_col: 20usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_constructor()), + ), +}; +fn test_constructor() { + let env = Env::default(); + let contract_id = env.register(Contract, ContractArgs::__constructor(&100_u32, &1000_i64)); + let client = ContractClient::new(&env, &contract_id); + match (&client.get_data(&DataKey::Persistent(100)), &Some(1000)) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match (&client.get_data(&DataKey::Temp(200)), &Some(2000)) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match (&client.get_data(&DataKey::Instance(300)), &Some(3000)) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match (&client.get_data(&DataKey::Persistent(10)), &None) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match (&client.get_data(&DataKey::Temp(20)), &None) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match (&client.get_data(&DataKey::Instance(30)), &None) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + } +} +extern crate test; +#[rustc_test_marker = "test_passing_no_constructor_arguments_causes_panic"] +#[doc(hidden)] +pub const test_passing_no_constructor_arguments_causes_panic: test::TestDescAndFn = + test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test_passing_no_constructor_arguments_causes_panic"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/constructor/src/lib.rs", + start_line: 53usize, + start_col: 4usize, + end_line: 53usize, + end_col: 54usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::YesWithMessage( + "constructor invocation has failed with error", + ), + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_passing_no_constructor_arguments_causes_panic()), + ), + }; +#[should_panic(expected = "constructor invocation has failed with error")] +fn test_passing_no_constructor_arguments_causes_panic() { + let env = Env::default(); + let _ = env.register(Contract, ()); +} +extern crate test; +#[rustc_test_marker = "test_missing_constructor_arguments_causes_panic"] +#[doc(hidden)] +pub const test_missing_constructor_arguments_causes_panic: test::TestDescAndFn = + test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test_missing_constructor_arguments_causes_panic"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/constructor/src/lib.rs", + start_line: 60usize, + start_col: 4usize, + end_line: 60usize, + end_col: 51usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::YesWithMessage( + "constructor invocation has failed with error", + ), + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_missing_constructor_arguments_causes_panic()), + ), + }; +#[should_panic(expected = "constructor invocation has failed with error")] +fn test_missing_constructor_arguments_causes_panic() { + let env = Env::default(); + let _ = env.register(Contract, (100_u32,)); +} +extern crate test; +#[rustc_test_marker = "test_passing_extra_constructor_arguments_causes_panic"] +#[doc(hidden)] +pub const test_passing_extra_constructor_arguments_causes_panic: test::TestDescAndFn = + test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test_passing_extra_constructor_arguments_causes_panic"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/constructor/src/lib.rs", + start_line: 67usize, + start_col: 4usize, + end_line: 67usize, + end_col: 57usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::YesWithMessage( + "constructor invocation has failed with error", + ), + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_passing_extra_constructor_arguments_causes_panic()), + ), + }; +#[should_panic(expected = "constructor invocation has failed with error")] +fn test_passing_extra_constructor_arguments_causes_panic() { + let env = Env::default(); + let _ = env.register(Contract, (100_u32, 1000_i64, 123_u32)); +} +extern crate test; +#[rustc_test_marker = "test_passing_incorrectly_typed_constructor_arguments_causes_panic"] +#[doc(hidden)] +pub const test_passing_incorrectly_typed_constructor_arguments_causes_panic: test::TestDescAndFn = + test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName( + "test_passing_incorrectly_typed_constructor_arguments_causes_panic", + ), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/constructor/src/lib.rs", + start_line: 74usize, + start_col: 4usize, + end_line: 74usize, + end_col: 69usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::YesWithMessage( + "constructor invocation has failed with error", + ), + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || { + test::assert_test_result( + test_passing_incorrectly_typed_constructor_arguments_causes_panic(), + ) + }, + ), + }; +#[should_panic(expected = "constructor invocation has failed with error")] +fn test_passing_incorrectly_typed_constructor_arguments_causes_panic() { + let env = Env::default(); + let _ = env.register(Contract, (100_u32, 1000_u32)); +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[ + &test_constructor, + &test_missing_constructor_arguments_causes_panic, + &test_passing_extra_constructor_arguments_causes_panic, + &test_passing_incorrectly_typed_constructor_arguments_causes_panic, + &test_passing_no_constructor_arguments_causes_panic, + ]) +} diff --git a/tests-expanded/test_constructor_wasm32v1-none.rs b/tests-expanded/test_constructor_wasm32v1-none.rs new file mode 100644 index 000000000..8e13a3446 --- /dev/null +++ b/tests-expanded/test_constructor_wasm32v1-none.rs @@ -0,0 +1,305 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl, contracttype, Env}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +pub enum DataKey { + Persistent(u32), + Temp(u32), + Instance(u32), +} +#[link_section = "contractspecv0"] +pub static __SPEC_XDR_TYPE_DATAKEY: [u8; 112usize] = DataKey::spec_xdr(); +impl DataKey { + pub const fn spec_xdr() -> [u8; 112usize] { + *b"\0\0\0\x02\0\0\0\0\0\0\0\0\0\0\0\x07DataKey\0\0\0\0\x03\0\0\0\x01\0\0\0\0\0\0\0\nPersistent\0\0\0\0\0\x01\0\0\0\x04\0\0\0\x01\0\0\0\0\0\0\0\x04Temp\0\0\0\x01\0\0\0\x04\0\0\0\x01\0\0\0\0\0\0\0\x08Instance\0\0\0\x01\0\0\0\x04" + } +} +impl soroban_sdk::TryFromVal for DataKey { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::{EnvBase, TryFromVal, TryIntoVal}; + const CASES: &'static [&'static str] = &["Persistent", "Temp", "Instance"]; + let vec: soroban_sdk::Vec = val.try_into_val(env)?; + let mut iter = vec.try_iter(); + let discriminant: soroban_sdk::Symbol = iter + .next() + .ok_or(soroban_sdk::ConversionError)?? + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?; + Ok( + match u32::from(env.symbol_index_in_strs(discriminant.to_symbol_val(), CASES)?) as usize + { + 0 => { + if iter.len() > 1usize { + return Err(soroban_sdk::ConversionError); + } + Self::Persistent( + iter.next() + .ok_or(soroban_sdk::ConversionError)?? + .try_into_val(env)?, + ) + } + 1 => { + if iter.len() > 1usize { + return Err(soroban_sdk::ConversionError); + } + Self::Temp( + iter.next() + .ok_or(soroban_sdk::ConversionError)?? + .try_into_val(env)?, + ) + } + 2 => { + if iter.len() > 1usize { + return Err(soroban_sdk::ConversionError); + } + Self::Instance( + iter.next() + .ok_or(soroban_sdk::ConversionError)?? + .try_into_val(env)?, + ) + } + _ => Err(soroban_sdk::ConversionError {})?, + }, + ) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &DataKey, + ) -> Result { + use soroban_sdk::{TryFromVal, TryIntoVal}; + match val { + DataKey::Persistent(ref value0) => { + let tup: (soroban_sdk::Val, soroban_sdk::Val) = ( + soroban_sdk::Symbol::try_from_val(env, &"Persistent")?.to_val(), + value0.try_into_val(env)?, + ); + tup.try_into_val(env).map_err(Into::into) + } + DataKey::Temp(ref value0) => { + let tup: (soroban_sdk::Val, soroban_sdk::Val) = ( + soroban_sdk::Symbol::try_from_val(env, &"Temp")?.to_val(), + value0.try_into_val(env)?, + ); + tup.try_into_val(env).map_err(Into::into) + } + DataKey::Instance(ref value0) => { + let tup: (soroban_sdk::Val, soroban_sdk::Val) = ( + soroban_sdk::Symbol::try_from_val(env, &"Instance")?.to_val(), + value0.try_into_val(env)?, + ); + tup.try_into_val(env).map_err(Into::into) + } + } + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&DataKey, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } +} +impl Contract { + pub fn __constructor(env: Env, init_key: u32, init_value: i64) { + env.storage() + .persistent() + .set(&DataKey::Persistent(init_key), &init_value); + env.storage() + .temporary() + .set(&DataKey::Temp(init_key * 2), &(init_value * 2)); + env.storage() + .instance() + .set(&DataKey::Instance(init_key * 3), &(init_value * 3)); + } + pub fn get_data(env: Env, key: DataKey) -> Option { + match key { + DataKey::Persistent(_) => env.storage().persistent().get(&key), + DataKey::Temp(_) => env.storage().temporary().get(&key), + DataKey::Instance(_) => env.storage().instance().get(&key), + } + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract____constructor__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN___CONSTRUCTOR: [u8; 80usize] = + super::Contract::spec_xdr___constructor(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr___constructor() -> [u8; 80usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\r__constructor\0\0\0\0\0\0\x02\0\0\0\0\0\0\0\x08init_key\0\0\0\x04\0\0\0\0\0\0\0\ninit_value\0\0\0\0\0\x07\0\0\0\0" + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__get_data__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_GET_DATA: [u8; 64usize] = super::Contract::spec_xdr_get_data(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_get_data() -> [u8; 64usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x08get_data\0\0\0\x01\0\0\0\0\0\0\0\x03key\0\0\0\x07\xd0\0\0\0\x07DataKey\0\0\0\0\x01\0\0\x03\xe8\0\0\0\x07" + } +} +impl<'a> ContractClient<'a> { + pub fn get_data(&self, key: &DataKey) -> Option { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("get_data"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [key.into_val(&self.env)]), + ); + res + } + pub fn try_get_data( + &self, + key: &DataKey, + ) -> Result< + Result< + Option, + as soroban_sdk::TryFromVal>::Error, + >, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("get_data"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [key.into_val(&self.env)]), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn __constructor<'i>(init_key: &'i u32, init_value: &'i i64) -> (&'i u32, &'i i64) { + (init_key, init_value) + } + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn get_data<'i>(key: &'i DataKey) -> (&'i DataKey,) { + (key,) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract____constructor { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).__constructor` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::__constructor( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).__constructor` instead")] + #[export_name = "__constructor"] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__get_data { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).get_data` instead")] + pub fn invoke_raw(env: soroban_sdk::Env, arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::get_data( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).get_data` instead")] + #[export_name = "get_data"] + pub extern "C" fn invoke_raw_extern(arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0) + } + use super::*; +} diff --git a/tests-expanded/test_contract_data_tests.rs b/tests-expanded/test_contract_data_tests.rs new file mode 100644 index 000000000..a0a67a4e4 --- /dev/null +++ b/tests-expanded/test_contract_data_tests.rs @@ -0,0 +1,622 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl, Env, Symbol}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +impl Contract { + pub fn put(e: Env, key: Symbol, val: Symbol) { + e.storage().persistent().set(&key, &val) + } + pub fn get(e: Env, key: Symbol) -> Option { + e.storage().persistent().get(&key) + } + pub fn del(e: Env, key: Symbol) { + e.storage().persistent().remove(&key) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__put__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_PUT: [u8; 56usize] = super::Contract::spec_xdr_put(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_put() -> [u8; 56usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03put\0\0\0\0\x02\0\0\0\0\0\0\0\x03key\0\0\0\0\x11\0\0\0\0\0\0\0\x03val\0\0\0\0\x11\0\0\0\0" + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__get__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_GET: [u8; 48usize] = super::Contract::spec_xdr_get(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_get() -> [u8; 48usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03get\0\0\0\0\x01\0\0\0\0\0\0\0\x03key\0\0\0\0\x11\0\0\0\x01\0\0\x03\xe8\0\0\0\x11" + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__del__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_DEL: [u8; 40usize] = super::Contract::spec_xdr_del(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_del() -> [u8; 40usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03del\0\0\0\0\x01\0\0\0\0\0\0\0\x03key\0\0\0\0\x11\0\0\0\0" + } +} +impl<'a> ContractClient<'a> { + pub fn put(&self, key: &Symbol, val: &Symbol) -> () { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("put"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [key.into_val(&self.env), val.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_put( + &self, + key: &Symbol, + val: &Symbol, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("put"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [key.into_val(&self.env), val.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn get(&self, key: &Symbol) -> Option { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("get"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [key.into_val(&self.env)]), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_get( + &self, + key: &Symbol, + ) -> Result< + Result< + Option, + as soroban_sdk::TryFromVal>::Error, + >, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("get"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [key.into_val(&self.env)]), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn del(&self, key: &Symbol) -> () { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("del"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [key.into_val(&self.env)]), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_del( + &self, + key: &Symbol, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("del"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [key.into_val(&self.env)]), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn put<'i>(key: &'i Symbol, val: &'i Symbol) -> (&'i Symbol, &'i Symbol) { + (key, val) + } + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn get<'i>(key: &'i Symbol) -> (&'i Symbol,) { + (key,) + } + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn del<'i>(key: &'i Symbol) -> (&'i Symbol,) { + (key,) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__put { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).put` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::put( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).put` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 2usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 2usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize], args[1usize]) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).put` instead")] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__get { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).get` instead")] + pub fn invoke_raw(env: soroban_sdk::Env, arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::get( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).get` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 1usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 1usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize]) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).get` instead")] + pub extern "C" fn invoke_raw_extern(arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__del { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).del` instead")] + pub fn invoke_raw(env: soroban_sdk::Env, arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::del( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).del` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 1usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 1usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize]) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).del` instead")] + pub extern "C" fn invoke_raw_extern(arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__0e764744b384ee8739a8810d2509da0f2e8c1cbf45b7a6de3d69726f824c2c8c_ctor() { + ::register( + "put", + #[allow(deprecated)] + &__Contract__put::invoke_raw_slice, + ); + ::register( + "get", + #[allow(deprecated)] + &__Contract__get::invoke_raw_slice, + ); + ::register( + "del", + #[allow(deprecated)] + &__Contract__del::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__0e764744b384ee8739a8810d2509da0f2e8c1cbf45b7a6de3d69726f824c2c8c_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__0e764744b384ee8739a8810d2509da0f2e8c1cbf45b7a6de3d69726f824c2c8c_ctor___rust_ctor___ctor() -> usize { + __Contract__0e764744b384ee8739a8810d2509da0f2e8c1cbf45b7a6de3d69726f824c2c8c_ctor(); + 0 + } + __Contract__0e764744b384ee8739a8810d2509da0f2e8c1cbf45b7a6de3d69726f824c2c8c_ctor___rust_ctor___ctor +}; +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[]) +} diff --git a/tests-expanded/test_contract_data_wasm32v1-none.rs b/tests-expanded/test_contract_data_wasm32v1-none.rs new file mode 100644 index 000000000..5ca71926d --- /dev/null +++ b/tests-expanded/test_contract_data_wasm32v1-none.rs @@ -0,0 +1,307 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl, Env, Symbol}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl Contract { + pub fn put(e: Env, key: Symbol, val: Symbol) { + e.storage().persistent().set(&key, &val) + } + pub fn get(e: Env, key: Symbol) -> Option { + e.storage().persistent().get(&key) + } + pub fn del(e: Env, key: Symbol) { + e.storage().persistent().remove(&key) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__put__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_PUT: [u8; 56usize] = super::Contract::spec_xdr_put(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_put() -> [u8; 56usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03put\0\0\0\0\x02\0\0\0\0\0\0\0\x03key\0\0\0\0\x11\0\0\0\0\0\0\0\x03val\0\0\0\0\x11\0\0\0\0" + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__get__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_GET: [u8; 48usize] = super::Contract::spec_xdr_get(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_get() -> [u8; 48usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03get\0\0\0\0\x01\0\0\0\0\0\0\0\x03key\0\0\0\0\x11\0\0\0\x01\0\0\x03\xe8\0\0\0\x11" + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__del__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_DEL: [u8; 40usize] = super::Contract::spec_xdr_del(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_del() -> [u8; 40usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03del\0\0\0\0\x01\0\0\0\0\0\0\0\x03key\0\0\0\0\x11\0\0\0\0" + } +} +impl<'a> ContractClient<'a> { + pub fn put(&self, key: &Symbol, val: &Symbol) -> () { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("put"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [key.into_val(&self.env), val.into_val(&self.env)], + ), + ); + res + } + pub fn try_put( + &self, + key: &Symbol, + val: &Symbol, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("put"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [key.into_val(&self.env), val.into_val(&self.env)], + ), + ); + res + } + pub fn get(&self, key: &Symbol) -> Option { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("get"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [key.into_val(&self.env)]), + ); + res + } + pub fn try_get( + &self, + key: &Symbol, + ) -> Result< + Result< + Option, + as soroban_sdk::TryFromVal>::Error, + >, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("get"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [key.into_val(&self.env)]), + ); + res + } + pub fn del(&self, key: &Symbol) -> () { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("del"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [key.into_val(&self.env)]), + ); + res + } + pub fn try_del( + &self, + key: &Symbol, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("del"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [key.into_val(&self.env)]), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn put<'i>(key: &'i Symbol, val: &'i Symbol) -> (&'i Symbol, &'i Symbol) { + (key, val) + } + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn get<'i>(key: &'i Symbol) -> (&'i Symbol,) { + (key,) + } + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn del<'i>(key: &'i Symbol) -> (&'i Symbol,) { + (key,) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__put { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).put` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::put( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).put` instead")] + #[export_name = "put"] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__get { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).get` instead")] + pub fn invoke_raw(env: soroban_sdk::Env, arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::get( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).get` instead")] + #[export_name = "get"] + pub extern "C" fn invoke_raw_extern(arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__del { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).del` instead")] + pub fn invoke_raw(env: soroban_sdk::Env, arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::del( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).del` instead")] + #[export_name = "del"] + pub extern "C" fn invoke_raw_extern(arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0) + } + use super::*; +} diff --git a/tests-expanded/test_empty2_tests.rs b/tests-expanded/test_empty2_tests.rs new file mode 100644 index 000000000..f0d96cd31 --- /dev/null +++ b/tests-expanded/test_empty2_tests.rs @@ -0,0 +1,195 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +impl Contract {} +impl<'a> ContractClient<'a> {} +impl ContractArgs {} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_ctor() {} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_ctor___rust_ctor___ctor() -> usize { + __Contract__e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_ctor(); + 0 + } + __Contract__e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_ctor___rust_ctor___ctor +}; +mod test { + use crate::{Contract, ContractClient}; + use soroban_sdk::Env; + extern crate test; + #[rustc_test_marker = "test::test_hello"] + #[doc(hidden)] + pub const test_hello: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test_hello"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/empty2/src/lib.rs", + start_line: 17usize, + start_col: 8usize, + end_line: 17usize, + end_col: 18usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_hello()), + ), + }; + fn test_hello() { + let e = Env::default(); + let contract_id = e.register(Contract, ()); + let _client = ContractClient::new(&e, &contract_id); + } +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[&test_hello]) +} diff --git a/tests-expanded/test_empty2_wasm32v1-none.rs b/tests-expanded/test_empty2_wasm32v1-none.rs new file mode 100644 index 000000000..4edc6a71d --- /dev/null +++ b/tests-expanded/test_empty2_wasm32v1-none.rs @@ -0,0 +1,29 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl Contract {} +impl<'a> ContractClient<'a> {} +impl ContractArgs {} diff --git a/tests-expanded/test_empty_tests.rs b/tests-expanded/test_empty_tests.rs new file mode 100644 index 000000000..f83301bdf --- /dev/null +++ b/tests-expanded/test_empty_tests.rs @@ -0,0 +1,333 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +impl Contract { + pub fn empty() {} +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__empty__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_EMPTY: [u8; 28usize] = super::Contract::spec_xdr_empty(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_empty() -> [u8; 28usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x05empty\0\0\0\0\0\0\0\0\0\0\0" + } +} +impl<'a> ContractClient<'a> { + pub fn empty(&self) -> () { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("empty"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_empty( + &self, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("empty"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn empty<'i>() -> () { + () + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__empty { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::empty(), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 0usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 0usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty` instead")] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor() { + ::register( + "empty", + #[allow(deprecated)] + &__Contract__empty::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor___rust_ctor___ctor() -> usize { + __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor(); + 0 + } + __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor___rust_ctor___ctor +}; +mod test { + use crate::{Contract, ContractClient}; + use soroban_sdk::Env; + extern crate test; + #[rustc_test_marker = "test::test_hello"] + #[doc(hidden)] + pub const test_hello: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test_hello"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/empty/src/lib.rs", + start_line: 19usize, + start_col: 8usize, + end_line: 19usize, + end_col: 18usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_hello()), + ), + }; + fn test_hello() { + let e = Env::default(); + let contract_id = e.register(Contract, ()); + let client = ContractClient::new(&e, &contract_id); + client.empty(); + } +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[&test_hello]) +} diff --git a/tests-expanded/test_empty_wasm32v1-none.rs b/tests-expanded/test_empty_wasm32v1-none.rs new file mode 100644 index 000000000..4f56631dc --- /dev/null +++ b/tests-expanded/test_empty_wasm32v1-none.rs @@ -0,0 +1,105 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl Contract { + pub fn empty() {} +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__empty__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_EMPTY: [u8; 28usize] = super::Contract::spec_xdr_empty(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_empty() -> [u8; 28usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x05empty\0\0\0\0\0\0\0\0\0\0\0" + } +} +impl<'a> ContractClient<'a> { + pub fn empty(&self) -> () { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("empty"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + res + } + pub fn try_empty( + &self, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("empty"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn empty<'i>() -> () { + () + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__empty { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::empty(), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty` instead")] + #[export_name = "empty"] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; +} diff --git a/tests-expanded/test_errors_tests.rs b/tests-expanded/test_errors_tests.rs new file mode 100644 index 000000000..2927ac72c --- /dev/null +++ b/tests-expanded/test_errors_tests.rs @@ -0,0 +1,1446 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{ + contract, contracterror, contractimpl, contracttype, panic_with_error, symbol_short, Env, + Symbol, +}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +pub enum Flag { + A = 0, + B = 1, + C = 2, + D = 3, + E = 4, +} +#[automatically_derived] +impl ::core::marker::StructuralPartialEq for Flag {} +#[automatically_derived] +impl ::core::cmp::PartialEq for Flag { + #[inline] + fn eq(&self, other: &Flag) -> bool { + let __self_discr = ::core::intrinsics::discriminant_value(self); + let __arg1_discr = ::core::intrinsics::discriminant_value(other); + __self_discr == __arg1_discr + } +} +pub static __SPEC_XDR_TYPE_FLAG: [u8; 104usize] = Flag::spec_xdr(); +impl Flag { + pub const fn spec_xdr() -> [u8; 104usize] { + *b"\0\0\0\x03\0\0\0\0\0\0\0\0\0\0\0\x04Flag\0\0\0\x05\0\0\0\0\0\0\0\x01A\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x01B\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\x01C\0\0\0\0\0\0\x02\0\0\0\0\0\0\0\x01D\0\0\0\0\0\0\x03\0\0\0\0\0\0\0\x01E\0\0\0\0\0\0\x04" + } +} +impl soroban_sdk::TryFromVal for Flag { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::TryIntoVal; + let discriminant: u32 = val.try_into_val(env)?; + Ok(match discriminant { + 0u32 => Self::A, + 1u32 => Self::B, + 2u32 => Self::C, + 3u32 => Self::D, + 4u32 => Self::E, + _ => Err(soroban_sdk::ConversionError {})?, + }) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &Flag, + ) -> Result { + Ok(match val { + Flag::A => 0u32.into(), + Flag::B => 1u32.into(), + Flag::C => 2u32.into(), + Flag::D => 3u32.into(), + Flag::E => 4u32.into(), + }) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&Flag, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } +} +impl soroban_sdk::TryFromVal for Flag { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::xdr::ScVal, + ) -> Result { + if let soroban_sdk::xdr::ScVal::U32(discriminant) = val { + Ok(match *discriminant { + 0u32 => Self::A, + 1u32 => Self::B, + 2u32 => Self::C, + 3u32 => Self::D, + 4u32 => Self::E, + _ => Err(soroban_sdk::xdr::Error::Invalid)?, + }) + } else { + Err(soroban_sdk::xdr::Error::Invalid) + } + } +} +impl TryInto for &Flag { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_into(self) -> Result { + Ok(match self { + Flag::A => 0u32.into(), + Flag::B => 1u32.into(), + Flag::C => 2u32.into(), + Flag::D => 3u32.into(), + Flag::E => 4u32.into(), + }) + } +} +impl TryInto for Flag { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_into(self) -> Result { + Ok(match self { + Flag::A => 0u32.into(), + Flag::B => 1u32.into(), + Flag::C => 2u32.into(), + Flag::D => 3u32.into(), + Flag::E => 4u32.into(), + }) + } +} +const _: () = { + use soroban_sdk::testutils::arbitrary::arbitrary; + use soroban_sdk::testutils::arbitrary::std; + pub enum ArbitraryFlag { + A, + B, + C, + D, + E, + } + #[automatically_derived] + impl ::core::fmt::Debug for ArbitraryFlag { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::write_str( + f, + match self { + ArbitraryFlag::A => "A", + ArbitraryFlag::B => "B", + ArbitraryFlag::C => "C", + ArbitraryFlag::D => "D", + ArbitraryFlag::E => "E", + }, + ) + } + } + #[automatically_derived] + impl ::core::clone::Clone for ArbitraryFlag { + #[inline] + fn clone(&self) -> ArbitraryFlag { + match self { + ArbitraryFlag::A => ArbitraryFlag::A, + ArbitraryFlag::B => ArbitraryFlag::B, + ArbitraryFlag::C => ArbitraryFlag::C, + ArbitraryFlag::D => ArbitraryFlag::D, + ArbitraryFlag::E => ArbitraryFlag::E, + } + } + } + #[automatically_derived] + impl ::core::cmp::Eq for ArbitraryFlag { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () {} + } + #[automatically_derived] + impl ::core::marker::StructuralPartialEq for ArbitraryFlag {} + #[automatically_derived] + impl ::core::cmp::PartialEq for ArbitraryFlag { + #[inline] + fn eq(&self, other: &ArbitraryFlag) -> bool { + let __self_discr = ::core::intrinsics::discriminant_value(self); + let __arg1_discr = ::core::intrinsics::discriminant_value(other); + __self_discr == __arg1_discr + } + } + #[automatically_derived] + impl ::core::cmp::Ord for ArbitraryFlag { + #[inline] + fn cmp(&self, other: &ArbitraryFlag) -> ::core::cmp::Ordering { + let __self_discr = ::core::intrinsics::discriminant_value(self); + let __arg1_discr = ::core::intrinsics::discriminant_value(other); + ::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr) + } + } + #[automatically_derived] + impl ::core::cmp::PartialOrd for ArbitraryFlag { + #[inline] + fn partial_cmp( + &self, + other: &ArbitraryFlag, + ) -> ::core::option::Option<::core::cmp::Ordering> { + let __self_discr = ::core::intrinsics::discriminant_value(self); + let __arg1_discr = ::core::intrinsics::discriminant_value(other); + ::core::cmp::PartialOrd::partial_cmp(&__self_discr, &__arg1_discr) + } + } + const _: () = { + #[allow(non_upper_case_globals)] + const RECURSIVE_COUNT_ArbitraryFlag: ::std::thread::LocalKey> = { + #[inline] + fn __init() -> std::cell::Cell { + std::cell::Cell::new(0) + } + unsafe { + ::std::thread::LocalKey::new( + const { + if ::std::mem::needs_drop::>() { + |init| { + #[thread_local] + static VAL: ::std::thread::local_impl::LazyStorage< + std::cell::Cell, + (), + > = ::std::thread::local_impl::LazyStorage::new(); + VAL.get_or_init(init, __init) + } + } else { + |init| { + #[thread_local] + static VAL: ::std::thread::local_impl::LazyStorage< + std::cell::Cell, + !, + > = ::std::thread::local_impl::LazyStorage::new(); + VAL.get_or_init(init, __init) + } + } + }, + ) + } + }; + #[automatically_derived] + impl<'arbitrary> arbitrary::Arbitrary<'arbitrary> for ArbitraryFlag { + fn arbitrary(u: &mut arbitrary::Unstructured<'arbitrary>) -> arbitrary::Result { + let guard_against_recursion = u.is_empty(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryFlag.with(|count| { + if count.get() > 0 { + return Err(arbitrary::Error::NotEnoughData); + } + count.set(count.get() + 1); + Ok(()) + })?; + } + let result = (|| { + Ok( + match (u64::from(::arbitrary(u)?) * 5u64) >> 32 + { + 0u64 => ArbitraryFlag::A, + 1u64 => ArbitraryFlag::B, + 2u64 => ArbitraryFlag::C, + 3u64 => ArbitraryFlag::D, + 4u64 => ArbitraryFlag::E, + _ => { + ::core::panicking::panic("internal error: entered unreachable code") + } + }, + ) + })(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryFlag.with(|count| { + count.set(count.get() - 1); + }); + } + result + } + fn arbitrary_take_rest( + mut u: arbitrary::Unstructured<'arbitrary>, + ) -> arbitrary::Result { + let guard_against_recursion = u.is_empty(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryFlag.with(|count| { + if count.get() > 0 { + return Err(arbitrary::Error::NotEnoughData); + } + count.set(count.get() + 1); + Ok(()) + })?; + } + let result = (|| { + Ok( + match (u64::from(::arbitrary(&mut u)?) * 5u64) + >> 32 + { + 0u64 => ArbitraryFlag::A, + 1u64 => ArbitraryFlag::B, + 2u64 => ArbitraryFlag::C, + 3u64 => ArbitraryFlag::D, + 4u64 => ArbitraryFlag::E, + _ => { + ::core::panicking::panic("internal error: entered unreachable code") + } + }, + ) + })(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryFlag.with(|count| { + count.set(count.get() - 1); + }); + } + result + } + #[inline] + fn size_hint(depth: usize) -> (usize, Option) { + arbitrary::size_hint::and( + ::size_hint(depth), + arbitrary::size_hint::recursion_guard(depth, |depth| { + arbitrary::size_hint::or_all(&[ + arbitrary::size_hint::and_all(&[]), + arbitrary::size_hint::and_all(&[]), + arbitrary::size_hint::and_all(&[]), + arbitrary::size_hint::and_all(&[]), + arbitrary::size_hint::and_all(&[]), + ]) + }), + ) + } + } + }; + impl soroban_sdk::testutils::arbitrary::SorobanArbitrary for Flag { + type Prototype = ArbitraryFlag; + } + impl soroban_sdk::TryFromVal for Flag { + type Error = soroban_sdk::ConversionError; + fn try_from_val( + env: &soroban_sdk::Env, + v: &ArbitraryFlag, + ) -> std::result::Result { + Ok(match v { + ArbitraryFlag::A => Flag::A, + ArbitraryFlag::B => Flag::B, + ArbitraryFlag::C => Flag::C, + ArbitraryFlag::D => Flag::D, + ArbitraryFlag::E => Flag::E, + }) + } + } +}; +pub enum Error { + AnError = 1, +} +#[automatically_derived] +impl ::core::fmt::Debug for Error { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::write_str(f, "AnError") + } +} +#[automatically_derived] +impl ::core::cmp::Eq for Error { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () {} +} +#[automatically_derived] +impl ::core::marker::StructuralPartialEq for Error {} +#[automatically_derived] +impl ::core::cmp::PartialEq for Error { + #[inline] + fn eq(&self, other: &Error) -> bool { + true + } +} +pub static __SPEC_XDR_TYPE_ERROR: [u8; 48usize] = Error::spec_xdr(); +impl Error { + pub const fn spec_xdr() -> [u8; 48usize] { + *b"\0\0\0\x04\0\0\0\0\0\0\0\0\0\0\0\x05Error\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\x07AnError\0\0\0\0\x01" + } +} +impl TryFrom for Error { + type Error = soroban_sdk::Error; + #[inline(always)] + fn try_from(error: soroban_sdk::Error) -> Result { + if error.is_type(soroban_sdk::xdr::ScErrorType::Contract) { + let discriminant = error.get_code(); + Ok(match discriminant { + 1u32 => Self::AnError, + _ => return Err(error), + }) + } else { + Err(error) + } + } +} +impl TryFrom<&soroban_sdk::Error> for Error { + type Error = soroban_sdk::Error; + #[inline(always)] + fn try_from(error: &soroban_sdk::Error) -> Result { + <_ as TryFrom>::try_from(*error) + } +} +impl From for soroban_sdk::Error { + #[inline(always)] + fn from(val: Error) -> soroban_sdk::Error { + <_ as From<&Error>>::from(&val) + } +} +impl From<&Error> for soroban_sdk::Error { + #[inline(always)] + fn from(val: &Error) -> soroban_sdk::Error { + match val { + Error::AnError => soroban_sdk::Error::from_contract_error(1u32), + } + } +} +impl TryFrom for Error { + type Error = soroban_sdk::InvokeError; + #[inline(always)] + fn try_from(error: soroban_sdk::InvokeError) -> Result { + match error { + soroban_sdk::InvokeError::Abort => Err(error), + soroban_sdk::InvokeError::Contract(code) => Ok(match code { + 1u32 => Self::AnError, + _ => return Err(error), + }), + } + } +} +impl TryFrom<&soroban_sdk::InvokeError> for Error { + type Error = soroban_sdk::InvokeError; + #[inline(always)] + fn try_from(error: &soroban_sdk::InvokeError) -> Result { + <_ as TryFrom>::try_from(*error) + } +} +impl From for soroban_sdk::InvokeError { + #[inline(always)] + fn from(val: Error) -> soroban_sdk::InvokeError { + <_ as From<&Error>>::from(&val) + } +} +impl From<&Error> for soroban_sdk::InvokeError { + #[inline(always)] + fn from(val: &Error) -> soroban_sdk::InvokeError { + match val { + Error::AnError => soroban_sdk::InvokeError::Contract(1u32), + } + } +} +impl soroban_sdk::TryFromVal for Error { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::TryIntoVal; + let error: soroban_sdk::Error = val.try_into_val(env)?; + error.try_into().map_err(|_| soroban_sdk::ConversionError) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &Error, + ) -> Result { + let error: soroban_sdk::Error = val.into(); + Ok(error.into()) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&Error, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } +} +impl Contract { + pub fn hello(env: Env, flag: Flag) -> Result { + env.storage().persistent().set( + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("persisted"); + SYMBOL + }, + &true, + ); + if flag == Flag::A { + Ok({ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("hello"); + SYMBOL + }) + } else if flag == Flag::B { + Err(Error::AnError) + } else if flag == Flag::C { + { + (&env).panic_with_error(Error::AnError); + } + } else if flag == Flag::D { + { + ::core::panicking::panic_fmt(format_args!("an error")); + } + } else if flag == Flag::E { + { + (&env).panic_with_error(soroban_sdk::Error::from_contract_error(9)); + } + } else { + ::core::panicking::panic("not implemented") + } + } + pub fn persisted(env: Env) -> bool { + env.storage() + .persistent() + .get(&{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("persisted"); + SYMBOL + }) + .unwrap_or(false) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__hello__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_HELLO: [u8; 64usize] = super::Contract::spec_xdr_hello(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_hello() -> [u8; 64usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x05hello\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\x04flag\0\0\x07\xd0\0\0\0\x04Flag\0\0\0\x01\0\0\x03\xe9\0\0\0\x11\0\0\0\x03" + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__persisted__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_PERSISTED: [u8; 36usize] = super::Contract::spec_xdr_persisted(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_persisted() -> [u8; 36usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\tpersisted\0\0\0\0\0\0\0\0\0\0\x01\0\0\0\x01" + } +} +impl<'a> ContractClient<'a> { + pub fn hello(&self, flag: &Flag) -> Symbol { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("hello"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [flag.into_val(&self.env)]), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_hello( + &self, + flag: &Flag, + ) -> Result< + Result< + Symbol, + >::Error, + >, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("hello"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [flag.into_val(&self.env)]), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn persisted(&self) -> bool { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("persisted"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_persisted( + &self, + ) -> Result< + Result>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("persisted"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn hello<'i>(flag: &'i Flag) -> (&'i Flag,) { + (flag,) + } + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn persisted<'i>() -> () { + () + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__hello { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).hello` instead")] + pub fn invoke_raw(env: soroban_sdk::Env, arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::hello( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).hello` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 1usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 1usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize]) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).hello` instead")] + pub extern "C" fn invoke_raw_extern(arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__persisted { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).persisted` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::persisted(env.clone()), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).persisted` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 0usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 0usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).persisted` instead")] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__dc66cfa30fdb08b17ba29ed3da0a0be599deef8db57bfb9cd9b3dcbf8c3be498_ctor() { + ::register( + "hello", + #[allow(deprecated)] + &__Contract__hello::invoke_raw_slice, + ); + ::register( + "persisted", + #[allow(deprecated)] + &__Contract__persisted::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__dc66cfa30fdb08b17ba29ed3da0a0be599deef8db57bfb9cd9b3dcbf8c3be498_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__dc66cfa30fdb08b17ba29ed3da0a0be599deef8db57bfb9cd9b3dcbf8c3be498_ctor___rust_ctor___ctor() -> usize { + __Contract__dc66cfa30fdb08b17ba29ed3da0a0be599deef8db57bfb9cd9b3dcbf8c3be498_ctor(); + 0 + } + __Contract__dc66cfa30fdb08b17ba29ed3da0a0be599deef8db57bfb9cd9b3dcbf8c3be498_ctor___rust_ctor___ctor +}; +mod test { + use crate::{Contract, ContractClient, Error, Flag}; + use soroban_sdk::{symbol_short, xdr, Env, InvokeError}; + extern crate test; + #[rustc_test_marker = "test::hello_ok"] + #[doc(hidden)] + pub const hello_ok: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::hello_ok"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/errors/src/lib.rs", + start_line: 63usize, + start_col: 8usize, + end_line: 63usize, + end_col: 16usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(hello_ok()), + ), + }; + fn hello_ok() { + let e = Env::default(); + let contract_id = e.register(Contract, ()); + let client = ContractClient::new(&e, &contract_id); + let res = client.hello(&Flag::A); + match (&res, &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("hello"); + SYMBOL + }) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + if !client.persisted() { + ::core::panicking::panic("assertion failed: client.persisted()") + } + } + extern crate test; + #[rustc_test_marker = "test::try_hello_ok"] + #[doc(hidden)] + pub const try_hello_ok: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::try_hello_ok"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/errors/src/lib.rs", + start_line: 74usize, + start_col: 8usize, + end_line: 74usize, + end_col: 20usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(try_hello_ok()), + ), + }; + fn try_hello_ok() { + let e = Env::default(); + let contract_id = e.register(Contract, ()); + let client = ContractClient::new(&e, &contract_id); + let res = client.try_hello(&Flag::A); + match ( + &res, + &Ok(Ok({ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("hello"); + SYMBOL + })), + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + if !client.persisted() { + ::core::panicking::panic("assertion failed: client.persisted()") + } + } + extern crate test; + #[rustc_test_marker = "test::try_hello_error"] + #[doc(hidden)] + pub const try_hello_error: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::try_hello_error"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/errors/src/lib.rs", + start_line: 85usize, + start_col: 8usize, + end_line: 85usize, + end_col: 23usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(try_hello_error()), + ), + }; + fn try_hello_error() { + let e = Env::default(); + let contract_id = e.register(Contract, ()); + let client = ContractClient::new(&e, &contract_id); + let res = client.try_hello(&Flag::B); + match (&res, &Err(Ok(Error::AnError))) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + if !!client.persisted() { + ::core::panicking::panic("assertion failed: !client.persisted()") + } + } + extern crate test; + #[rustc_test_marker = "test::try_hello_error_panic"] + #[doc(hidden)] + pub const try_hello_error_panic: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::try_hello_error_panic"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/errors/src/lib.rs", + start_line: 96usize, + start_col: 8usize, + end_line: 96usize, + end_col: 29usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(try_hello_error_panic()), + ), + }; + fn try_hello_error_panic() { + let e = Env::default(); + let contract_id = e.register(Contract, ()); + let client = ContractClient::new(&e, &contract_id); + let res = client.try_hello(&Flag::C); + match (&res, &Err(Ok(Error::AnError))) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + if !!client.persisted() { + ::core::panicking::panic("assertion failed: !client.persisted()") + } + } + extern crate test; + #[rustc_test_marker = "test::try_hello_error_panic_string"] + #[doc(hidden)] + pub const try_hello_error_panic_string: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::try_hello_error_panic_string"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/errors/src/lib.rs", + start_line: 107usize, + start_col: 8usize, + end_line: 107usize, + end_col: 36usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(try_hello_error_panic_string()), + ), + }; + fn try_hello_error_panic_string() { + let e = Env::default(); + let contract_id = e.register(Contract, ()); + let client = ContractClient::new(&e, &contract_id); + let res = client.try_hello(&Flag::D); + match (&res, &Err(Err(InvokeError::Abort))) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + if !!client.persisted() { + ::core::panicking::panic("assertion failed: !client.persisted()") + } + } + extern crate test; + #[rustc_test_marker = "test::try_hello_error_unexpected_contract_error"] + #[doc(hidden)] + pub const try_hello_error_unexpected_contract_error: test::TestDescAndFn = + test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::try_hello_error_unexpected_contract_error"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/errors/src/lib.rs", + start_line: 118usize, + start_col: 8usize, + end_line: 118usize, + end_col: 49usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(try_hello_error_unexpected_contract_error()), + ), + }; + fn try_hello_error_unexpected_contract_error() { + let e = Env::default(); + let contract_id = e.register(Contract, ()); + let client = ContractClient::new(&e, &contract_id); + let res = client.try_hello(&Flag::E); + match (&res, &Err(Err(InvokeError::Contract(9)))) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + if !!client.persisted() { + ::core::panicking::panic("assertion failed: !client.persisted()") + } + } + extern crate test; + #[rustc_test_marker = "test::type_conversion"] + #[doc(hidden)] + pub const type_conversion: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::type_conversion"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/errors/src/lib.rs", + start_line: 129usize, + start_col: 8usize, + end_line: 129usize, + end_col: 23usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(type_conversion()), + ), + }; + fn type_conversion() { + match ( + &<_ as Into>::into(Error::AnError), + &InvokeError::Contract(1), + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match ( + &<_ as TryInto>::try_into(InvokeError::Contract(1)), + &Ok(Error::AnError), + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match ( + &<_ as TryInto>::try_into(InvokeError::Contract(2)), + &Err(InvokeError::Contract(2)), + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match ( + &<_ as TryInto>::try_into(InvokeError::Abort), + &Err(InvokeError::Abort), + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match ( + &<_ as Into>::into(Error::AnError), + &soroban_sdk::Error::from_contract_error(1), + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match ( + &<_ as TryInto>::try_into(soroban_sdk::Error::from_contract_error(1)), + &Ok(Error::AnError), + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match ( + &<_ as TryInto>::try_into(soroban_sdk::Error::from_contract_error(2)), + &Err(soroban_sdk::Error::from_contract_error(2)), + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match ( + &<_ as TryInto>::try_into(soroban_sdk::Error::from_type_and_code( + xdr::ScErrorType::Context, + xdr::ScErrorCode::InvalidAction, + )), + &Err(soroban_sdk::Error::from_type_and_code( + xdr::ScErrorType::Context, + xdr::ScErrorCode::InvalidAction, + )), + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match ( + &<_ as Into>::into(soroban_sdk::Error::from_contract_error(1)), + &InvokeError::Contract(1), + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match ( + &<_ as Into>::into(soroban_sdk::Error::from_type_and_code( + xdr::ScErrorType::Context, + xdr::ScErrorCode::InvalidAction, + )), + &InvokeError::Abort, + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + } +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[ + &hello_ok, + &try_hello_error, + &try_hello_error_panic, + &try_hello_error_panic_string, + &try_hello_error_unexpected_contract_error, + &try_hello_ok, + &type_conversion, + ]) +} diff --git a/tests-expanded/test_errors_wasm32v1-none.rs b/tests-expanded/test_errors_wasm32v1-none.rs new file mode 100644 index 000000000..b321525be --- /dev/null +++ b/tests-expanded/test_errors_wasm32v1-none.rs @@ -0,0 +1,364 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{ + contract, contracterror, contractimpl, contracttype, panic_with_error, symbol_short, Env, + Symbol, +}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +pub enum Flag { + A = 0, + B = 1, + C = 2, + D = 3, + E = 4, +} +#[automatically_derived] +impl ::core::marker::StructuralPartialEq for Flag {} +#[automatically_derived] +impl ::core::cmp::PartialEq for Flag { + #[inline] + fn eq(&self, other: &Flag) -> bool { + let __self_discr = ::core::intrinsics::discriminant_value(self); + let __arg1_discr = ::core::intrinsics::discriminant_value(other); + __self_discr == __arg1_discr + } +} +#[link_section = "contractspecv0"] +pub static __SPEC_XDR_TYPE_FLAG: [u8; 104usize] = Flag::spec_xdr(); +impl Flag { + pub const fn spec_xdr() -> [u8; 104usize] { + *b"\0\0\0\x03\0\0\0\0\0\0\0\0\0\0\0\x04Flag\0\0\0\x05\0\0\0\0\0\0\0\x01A\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x01B\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\x01C\0\0\0\0\0\0\x02\0\0\0\0\0\0\0\x01D\0\0\0\0\0\0\x03\0\0\0\0\0\0\0\x01E\0\0\0\0\0\0\x04" + } +} +impl soroban_sdk::TryFromVal for Flag { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::TryIntoVal; + let discriminant: u32 = val.try_into_val(env)?; + Ok(match discriminant { + 0u32 => Self::A, + 1u32 => Self::B, + 2u32 => Self::C, + 3u32 => Self::D, + 4u32 => Self::E, + _ => Err(soroban_sdk::ConversionError {})?, + }) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &Flag, + ) -> Result { + Ok(match val { + Flag::A => 0u32.into(), + Flag::B => 1u32.into(), + Flag::C => 2u32.into(), + Flag::D => 3u32.into(), + Flag::E => 4u32.into(), + }) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&Flag, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } +} +pub enum Error { + AnError = 1, +} +#[automatically_derived] +impl ::core::fmt::Debug for Error { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::write_str(f, "AnError") + } +} +#[automatically_derived] +impl ::core::cmp::Eq for Error { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () {} +} +#[automatically_derived] +impl ::core::marker::StructuralPartialEq for Error {} +#[automatically_derived] +impl ::core::cmp::PartialEq for Error { + #[inline] + fn eq(&self, other: &Error) -> bool { + true + } +} +#[link_section = "contractspecv0"] +pub static __SPEC_XDR_TYPE_ERROR: [u8; 48usize] = Error::spec_xdr(); +impl Error { + pub const fn spec_xdr() -> [u8; 48usize] { + *b"\0\0\0\x04\0\0\0\0\0\0\0\0\0\0\0\x05Error\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\x07AnError\0\0\0\0\x01" + } +} +impl TryFrom for Error { + type Error = soroban_sdk::Error; + #[inline(always)] + fn try_from(error: soroban_sdk::Error) -> Result { + if error.is_type(soroban_sdk::xdr::ScErrorType::Contract) { + let discriminant = error.get_code(); + Ok(match discriminant { + 1u32 => Self::AnError, + _ => return Err(error), + }) + } else { + Err(error) + } + } +} +impl TryFrom<&soroban_sdk::Error> for Error { + type Error = soroban_sdk::Error; + #[inline(always)] + fn try_from(error: &soroban_sdk::Error) -> Result { + <_ as TryFrom>::try_from(*error) + } +} +impl From for soroban_sdk::Error { + #[inline(always)] + fn from(val: Error) -> soroban_sdk::Error { + <_ as From<&Error>>::from(&val) + } +} +impl From<&Error> for soroban_sdk::Error { + #[inline(always)] + fn from(val: &Error) -> soroban_sdk::Error { + match val { + Error::AnError => soroban_sdk::Error::from_contract_error(1u32), + } + } +} +impl TryFrom for Error { + type Error = soroban_sdk::InvokeError; + #[inline(always)] + fn try_from(error: soroban_sdk::InvokeError) -> Result { + match error { + soroban_sdk::InvokeError::Abort => Err(error), + soroban_sdk::InvokeError::Contract(code) => Ok(match code { + 1u32 => Self::AnError, + _ => return Err(error), + }), + } + } +} +impl TryFrom<&soroban_sdk::InvokeError> for Error { + type Error = soroban_sdk::InvokeError; + #[inline(always)] + fn try_from(error: &soroban_sdk::InvokeError) -> Result { + <_ as TryFrom>::try_from(*error) + } +} +impl From for soroban_sdk::InvokeError { + #[inline(always)] + fn from(val: Error) -> soroban_sdk::InvokeError { + <_ as From<&Error>>::from(&val) + } +} +impl From<&Error> for soroban_sdk::InvokeError { + #[inline(always)] + fn from(val: &Error) -> soroban_sdk::InvokeError { + match val { + Error::AnError => soroban_sdk::InvokeError::Contract(1u32), + } + } +} +impl soroban_sdk::TryFromVal for Error { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::TryIntoVal; + let error: soroban_sdk::Error = val.try_into_val(env)?; + error.try_into().map_err(|_| soroban_sdk::ConversionError) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &Error, + ) -> Result { + let error: soroban_sdk::Error = val.into(); + Ok(error.into()) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&Error, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } +} +impl Contract { + pub fn hello(env: Env, flag: Flag) -> Result { + env.storage().persistent().set( + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("persisted"); + SYMBOL + }, + &true, + ); + if flag == Flag::A { + Ok({ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("hello"); + SYMBOL + }) + } else if flag == Flag::B { + Err(Error::AnError) + } else if flag == Flag::C { + { + (&env).panic_with_error(Error::AnError); + } + } else if flag == Flag::D { + { + ::core::panicking::panic_fmt(format_args!("an error")); + } + } else if flag == Flag::E { + { + (&env).panic_with_error(soroban_sdk::Error::from_contract_error(9)); + } + } else { + ::core::panicking::panic("not implemented") + } + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__hello__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_HELLO: [u8; 64usize] = super::Contract::spec_xdr_hello(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_hello() -> [u8; 64usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x05hello\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\x04flag\0\0\x07\xd0\0\0\0\x04Flag\0\0\0\x01\0\0\x03\xe9\0\0\0\x11\0\0\0\x03" + } +} +impl Contract {} +impl<'a> ContractClient<'a> { + pub fn hello(&self, flag: &Flag) -> Symbol { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("hello"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [flag.into_val(&self.env)]), + ); + res + } + pub fn try_hello( + &self, + flag: &Flag, + ) -> Result< + Result< + Symbol, + >::Error, + >, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("hello"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&self.env, [flag.into_val(&self.env)]), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn hello<'i>(flag: &'i Flag) -> (&'i Flag,) { + (flag,) + } + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn persisted<'i>() -> () { + () + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__hello { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).hello` instead")] + pub fn invoke_raw(env: soroban_sdk::Env, arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::hello( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).hello` instead")] + #[export_name = "hello"] + pub extern "C" fn invoke_raw_extern(arg_0: soroban_sdk::Val) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0) + } + use super::*; +} diff --git a/tests-expanded/test_events_tests.rs b/tests-expanded/test_events_tests.rs new file mode 100644 index 000000000..22d05751c --- /dev/null +++ b/tests-expanded/test_events_tests.rs @@ -0,0 +1,792 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractevent, contractimpl, Address, Env, MuxedAddress}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +pub struct Transfer { + from: Address, + to: Address, + amount: i128, + to_muxed_id: Option, +} +pub static __SPEC_XDR_EVENT_TRANSFER: [u8; 144usize] = Transfer::spec_xdr(); +impl Transfer { + pub const fn spec_xdr() -> [u8; 144usize] { + *b"\0\0\0\x05\0\0\0\0\0\0\0\0\0\0\0\x08Transfer\0\0\0\x01\0\0\0\x08transfer\0\0\0\x04\0\0\0\0\0\0\0\x04from\0\0\0\x13\0\0\0\x01\0\0\0\0\0\0\0\x02to\0\0\0\0\0\x13\0\0\0\x01\0\0\0\0\0\0\0\x06amount\0\0\0\0\0\x0b\0\0\0\0\0\0\0\0\0\0\0\x0bto_muxed_id\0\0\0\x03\xe8\0\0\0\x06\0\0\0\0\0\0\0\x02" + } +} +impl soroban_sdk::Event for Transfer { + fn topics(&self, env: &soroban_sdk::Env) -> soroban_sdk::Vec { + use soroban_sdk::IntoVal; + ( + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("transfer"); + SYMBOL + }, + { + let v: soroban_sdk::Val = self.from.into_val(env); + v + }, + { + let v: soroban_sdk::Val = self.to.into_val(env); + v + }, + ) + .into_val(env) + } + fn data(&self, env: &soroban_sdk::Env) -> soroban_sdk::Val { + use soroban_sdk::{unwrap::UnwrapInfallible, EnvBase, IntoVal}; + const KEYS: [&'static str; 2usize] = ["amount", "to_muxed_id"]; + let vals: [soroban_sdk::Val; 2usize] = + [self.amount.into_val(env), self.to_muxed_id.into_val(env)]; + env.map_new_from_slices(&KEYS, &vals) + .unwrap_infallible() + .into() + } +} +impl Transfer { + pub fn publish(&self, env: &soroban_sdk::Env) { + <_ as soroban_sdk::Event>::publish(self, env); + } +} +impl Contract { + pub fn transfer(env: Env, from: Address, to: MuxedAddress, amount: i128) { + Transfer { + from: from.clone(), + to: to.address(), + amount, + to_muxed_id: to.id(), + } + .publish(&env); + } + pub fn failed_transfer(env: Env, from: Address, to: Address, amount: i128) { + Transfer { + from: from.clone(), + to: to.clone(), + amount, + to_muxed_id: None, + } + .publish(&env); + { + ::core::panicking::panic_fmt(format_args!("fail")); + }; + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__transfer__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_TRANSFER: [u8; 80usize] = super::Contract::spec_xdr_transfer(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_transfer() -> [u8; 80usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x08transfer\0\0\0\x03\0\0\0\0\0\0\0\x04from\0\0\0\x13\0\0\0\0\0\0\0\x02to\0\0\0\0\0\x14\0\0\0\0\0\0\0\x06amount\0\0\0\0\0\x0b\0\0\0\0" + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__failed_transfer__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_FAILED_TRANSFER: [u8; 88usize] = + super::Contract::spec_xdr_failed_transfer(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_failed_transfer() -> [u8; 88usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x0ffailed_transfer\0\0\0\0\x03\0\0\0\0\0\0\0\x04from\0\0\0\x13\0\0\0\0\0\0\0\x02to\0\0\0\0\0\x13\0\0\0\0\0\0\0\x06amount\0\0\0\0\0\x0b\0\0\0\0" + } +} +impl<'a> ContractClient<'a> { + pub fn transfer(&self, from: &Address, to: impl Into, amount: &i128) -> () { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("transfer"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [ + from.into_val(&self.env), + to.into().into_val(&self.env), + amount.into_val(&self.env), + ], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_transfer( + &self, + from: &Address, + to: impl Into, + amount: &i128, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("transfer"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [ + from.into_val(&self.env), + to.into().into_val(&self.env), + amount.into_val(&self.env), + ], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn failed_transfer(&self, from: &Address, to: &Address, amount: &i128) -> () { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ soroban_sdk::Symbol::new(&self.env, "failed_transfer") }, + ::soroban_sdk::Vec::from_array( + &self.env, + [ + from.into_val(&self.env), + to.into_val(&self.env), + amount.into_val(&self.env), + ], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_failed_transfer( + &self, + from: &Address, + to: &Address, + amount: &i128, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ soroban_sdk::Symbol::new(&self.env, "failed_transfer") }, + ::soroban_sdk::Vec::from_array( + &self.env, + [ + from.into_val(&self.env), + to.into_val(&self.env), + amount.into_val(&self.env), + ], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn transfer<'i>( + from: &'i Address, + to: &'i MuxedAddress, + amount: &'i i128, + ) -> (&'i Address, &'i MuxedAddress, &'i i128) { + (from, to, amount) + } + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn failed_transfer<'i>( + from: &'i Address, + to: &'i Address, + amount: &'i i128, + ) -> (&'i Address, &'i Address, &'i i128) { + (from, to, amount) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__transfer { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).transfer` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::transfer( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_2), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).transfer` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 3usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 3usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize], args[1usize], args[2usize]) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).transfer` instead")] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1, arg_2) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__failed_transfer { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).failed_transfer` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::failed_transfer( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_2), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).failed_transfer` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 3usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 3usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize], args[1usize], args[2usize]) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).failed_transfer` instead")] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1, arg_2) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__a60968eb9ff75bf813738a9007ab5bbea9f174011ab4092819ed57e87eb6b301_ctor() { + ::register( + "transfer", + #[allow(deprecated)] + &__Contract__transfer::invoke_raw_slice, + ); + ::register( + "failed_transfer", + #[allow(deprecated)] + &__Contract__failed_transfer::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__a60968eb9ff75bf813738a9007ab5bbea9f174011ab4092819ed57e87eb6b301_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__a60968eb9ff75bf813738a9007ab5bbea9f174011ab4092819ed57e87eb6b301_ctor___rust_ctor___ctor() -> usize { + __Contract__a60968eb9ff75bf813738a9007ab5bbea9f174011ab4092819ed57e87eb6b301_ctor(); + 0 + } + __Contract__a60968eb9ff75bf813738a9007ab5bbea9f174011ab4092819ed57e87eb6b301_ctor___rust_ctor___ctor +}; +mod test { + extern crate alloc; + use crate::{Contract, ContractClient}; + use soroban_sdk::{ + map, symbol_short, + testutils::{Address as _, Events, MuxedAddress as _}, + vec, Address, Env, IntoVal, MuxedAddress, Symbol, Val, + }; + extern crate test; + #[rustc_test_marker = "test::test_event"] + #[doc(hidden)] + pub const test_event: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test_event"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/events/src/lib.rs", + start_line: 53usize, + start_col: 8usize, + end_line: 53usize, + end_col: 18usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_event()), + ), + }; + fn test_event() { + let env = Env::default(); + let contract_id = env.register(Contract, ()); + let client = ContractClient::new(&env, &contract_id); + let from = Address::generate(&env); + let to = MuxedAddress::generate(&env); + let amount = 1i128; + client.transfer(&from, &to, &amount); + match ( + &env.events().all(), + &::soroban_sdk::Vec::from_array( + &env, + [( + contract_id.clone(), + (Symbol::new(&env, "transfer"), &from, to.address()).into_val(&env), + ::soroban_sdk::Map::from_array( + &env, + [ + ( + { + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = + soroban_sdk::Symbol::short("amount"); + SYMBOL + }, + <_ as IntoVal>::into_val(&1i128, &env), + ), + ( + Symbol::new(&env, "to_muxed_id"), + <_ as IntoVal>::into_val(&to.id().unwrap(), &env), + ), + ], + ) + .to_val(), + )], + ), + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + } + extern crate test; + #[rustc_test_marker = "test::test_event_with_option_none"] + #[doc(hidden)] + pub const test_event_with_option_none: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test_event_with_option_none"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/events/src/lib.rs", + start_line: 91usize, + start_col: 8usize, + end_line: 91usize, + end_col: 35usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_event_with_option_none()), + ), + }; + fn test_event_with_option_none() { + let env = Env::default(); + let contract_id = env.register(Contract, ()); + let client = ContractClient::new(&env, &contract_id); + let from = Address::generate(&env); + let to = Address::generate(&env); + let amount = 1i128; + client.transfer(&from, &to, &amount); + match ( + &env.events().all(), + &::soroban_sdk::Vec::from_array( + &env, + [( + contract_id.clone(), + (Symbol::new(&env, "transfer"), &from, &to).into_val(&env), + ::soroban_sdk::Map::from_array( + &env, + [ + ( + { + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = + soroban_sdk::Symbol::short("amount"); + SYMBOL + }, + <_ as IntoVal>::into_val(&1i128, &env), + ), + (Symbol::new(&env, "to_muxed_id"), ().into_val(&env)), + ], + ) + .to_val(), + )], + ), + ) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + } + extern crate test; + #[rustc_test_marker = "test::test_no_events_recorded_for_failed_call"] + #[doc(hidden)] + pub const test_no_events_recorded_for_failed_call: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test_no_events_recorded_for_failed_call"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/events/src/lib.rs", + start_line: 126usize, + start_col: 8usize, + end_line: 126usize, + end_col: 47usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_no_events_recorded_for_failed_call()), + ), + }; + fn test_no_events_recorded_for_failed_call() { + let env = Env::default(); + let contract_id = env.register(Contract, ()); + let client = ContractClient::new(&env, &contract_id); + let from = Address::generate(&env); + let to = Address::generate(&env); + let _ = client.try_failed_transfer(&from, &to, &1); + match (&env.events().all(), &::soroban_sdk::Vec::new(&env)) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + } +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[ + &test_event, + &test_event_with_option_none, + &test_no_events_recorded_for_failed_call, + ]) +} diff --git a/tests-expanded/test_events_wasm32v1-none.rs b/tests-expanded/test_events_wasm32v1-none.rs new file mode 100644 index 000000000..506c67e6e --- /dev/null +++ b/tests-expanded/test_events_wasm32v1-none.rs @@ -0,0 +1,338 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractevent, contractimpl, Address, Env, MuxedAddress}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +pub struct Transfer { + from: Address, + to: Address, + amount: i128, + to_muxed_id: Option, +} +#[link_section = "contractspecv0"] +pub static __SPEC_XDR_EVENT_TRANSFER: [u8; 144usize] = Transfer::spec_xdr(); +impl Transfer { + pub const fn spec_xdr() -> [u8; 144usize] { + *b"\0\0\0\x05\0\0\0\0\0\0\0\0\0\0\0\x08Transfer\0\0\0\x01\0\0\0\x08transfer\0\0\0\x04\0\0\0\0\0\0\0\x04from\0\0\0\x13\0\0\0\x01\0\0\0\0\0\0\0\x02to\0\0\0\0\0\x13\0\0\0\x01\0\0\0\0\0\0\0\x06amount\0\0\0\0\0\x0b\0\0\0\0\0\0\0\0\0\0\0\x0bto_muxed_id\0\0\0\x03\xe8\0\0\0\x06\0\0\0\0\0\0\0\x02" + } +} +impl soroban_sdk::Event for Transfer { + fn topics(&self, env: &soroban_sdk::Env) -> soroban_sdk::Vec { + use soroban_sdk::IntoVal; + ( + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("transfer"); + SYMBOL + }, + { + let v: soroban_sdk::Val = self.from.into_val(env); + v + }, + { + let v: soroban_sdk::Val = self.to.into_val(env); + v + }, + ) + .into_val(env) + } + fn data(&self, env: &soroban_sdk::Env) -> soroban_sdk::Val { + use soroban_sdk::{unwrap::UnwrapInfallible, EnvBase, IntoVal}; + const KEYS: [&'static str; 2usize] = ["amount", "to_muxed_id"]; + let vals: [soroban_sdk::Val; 2usize] = + [self.amount.into_val(env), self.to_muxed_id.into_val(env)]; + env.map_new_from_slices(&KEYS, &vals) + .unwrap_infallible() + .into() + } +} +impl Transfer { + pub fn publish(&self, env: &soroban_sdk::Env) { + <_ as soroban_sdk::Event>::publish(self, env); + } +} +impl Contract { + pub fn transfer(env: Env, from: Address, to: MuxedAddress, amount: i128) { + Transfer { + from: from.clone(), + to: to.address(), + amount, + to_muxed_id: to.id(), + } + .publish(&env); + } + pub fn failed_transfer(env: Env, from: Address, to: Address, amount: i128) { + Transfer { + from: from.clone(), + to: to.clone(), + amount, + to_muxed_id: None, + } + .publish(&env); + { + ::core::panicking::panic_fmt(format_args!("fail")); + }; + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__transfer__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_TRANSFER: [u8; 80usize] = super::Contract::spec_xdr_transfer(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_transfer() -> [u8; 80usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x08transfer\0\0\0\x03\0\0\0\0\0\0\0\x04from\0\0\0\x13\0\0\0\0\0\0\0\x02to\0\0\0\0\0\x14\0\0\0\0\0\0\0\x06amount\0\0\0\0\0\x0b\0\0\0\0" + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__failed_transfer__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_FAILED_TRANSFER: [u8; 88usize] = + super::Contract::spec_xdr_failed_transfer(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_failed_transfer() -> [u8; 88usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x0ffailed_transfer\0\0\0\0\x03\0\0\0\0\0\0\0\x04from\0\0\0\x13\0\0\0\0\0\0\0\x02to\0\0\0\0\0\x13\0\0\0\0\0\0\0\x06amount\0\0\0\0\0\x0b\0\0\0\0" + } +} +impl<'a> ContractClient<'a> { + pub fn transfer(&self, from: &Address, to: impl Into, amount: &i128) -> () { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("transfer"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [ + from.into_val(&self.env), + to.into().into_val(&self.env), + amount.into_val(&self.env), + ], + ), + ); + res + } + pub fn try_transfer( + &self, + from: &Address, + to: impl Into, + amount: &i128, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("transfer"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [ + from.into_val(&self.env), + to.into().into_val(&self.env), + amount.into_val(&self.env), + ], + ), + ); + res + } + pub fn failed_transfer(&self, from: &Address, to: &Address, amount: &i128) -> () { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ soroban_sdk::Symbol::new(&self.env, "failed_transfer") }, + ::soroban_sdk::Vec::from_array( + &self.env, + [ + from.into_val(&self.env), + to.into_val(&self.env), + amount.into_val(&self.env), + ], + ), + ); + res + } + pub fn try_failed_transfer( + &self, + from: &Address, + to: &Address, + amount: &i128, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ soroban_sdk::Symbol::new(&self.env, "failed_transfer") }, + ::soroban_sdk::Vec::from_array( + &self.env, + [ + from.into_val(&self.env), + to.into_val(&self.env), + amount.into_val(&self.env), + ], + ), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn transfer<'i>( + from: &'i Address, + to: &'i MuxedAddress, + amount: &'i i128, + ) -> (&'i Address, &'i MuxedAddress, &'i i128) { + (from, to, amount) + } + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn failed_transfer<'i>( + from: &'i Address, + to: &'i Address, + amount: &'i i128, + ) -> (&'i Address, &'i Address, &'i i128) { + (from, to, amount) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__transfer { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).transfer` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::transfer( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_2), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).transfer` instead")] + #[export_name = "transfer"] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1, arg_2) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__failed_transfer { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).failed_transfer` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::failed_transfer( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_2), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).failed_transfer` instead")] + #[export_name = "failed_transfer"] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1, arg_2) + } + use super::*; +} diff --git a/tests-expanded/test_fuzz_tests.rs b/tests-expanded/test_fuzz_tests.rs new file mode 100644 index 000000000..a4a5c839d --- /dev/null +++ b/tests-expanded/test_fuzz_tests.rs @@ -0,0 +1,334 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl, U256}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +impl Contract { + pub fn run(a: U256, b: U256) { + if a < b { + { + ::core::panicking::panic_fmt(format_args!("unexpected")); + } + } + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__run__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_RUN: [u8; 56usize] = super::Contract::spec_xdr_run(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_run() -> [u8; 56usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03run\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x0c\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x0c\0\0\0\0" + } +} +impl<'a> ContractClient<'a> { + pub fn run(&self, a: &U256, b: &U256) -> () { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("run"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_run( + &self, + a: &U256, + b: &U256, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("run"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn run<'i>(a: &'i U256, b: &'i U256) -> (&'i U256, &'i U256) { + (a, b) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__run { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).run` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::run( + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).run` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 2usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 2usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize], args[1usize]) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).run` instead")] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__acba25512100f80b56fc3ccd14c65be55d94800cda77585c5f41a887e398f9be_ctor() { + ::register( + "run", + #[allow(deprecated)] + &__Contract__run::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__acba25512100f80b56fc3ccd14c65be55d94800cda77585c5f41a887e398f9be_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__acba25512100f80b56fc3ccd14c65be55d94800cda77585c5f41a887e398f9be_ctor___rust_ctor___ctor() -> usize { + __Contract__acba25512100f80b56fc3ccd14c65be55d94800cda77585c5f41a887e398f9be_ctor(); + 0 + } + __Contract__acba25512100f80b56fc3ccd14c65be55d94800cda77585c5f41a887e398f9be_ctor___rust_ctor___ctor +}; +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[]) +} diff --git a/tests-expanded/test_fuzz_wasm32v1-none.rs b/tests-expanded/test_fuzz_wasm32v1-none.rs new file mode 100644 index 000000000..a818cd3df --- /dev/null +++ b/tests-expanded/test_fuzz_wasm32v1-none.rs @@ -0,0 +1,139 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl, U256}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl Contract { + pub fn run(a: U256, b: U256) { + if a < b { + { + ::core::panicking::panic_fmt(format_args!("unexpected")); + } + } + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__run__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_RUN: [u8; 56usize] = super::Contract::spec_xdr_run(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_run() -> [u8; 56usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03run\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x0c\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x0c\0\0\0\0" + } +} +impl<'a> ContractClient<'a> { + pub fn run(&self, a: &U256, b: &U256) -> () { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("run"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + res + } + pub fn try_run( + &self, + a: &U256, + b: &U256, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("run"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn run<'i>(a: &'i U256, b: &'i U256) -> (&'i U256, &'i U256) { + (a, b) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__run { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).run` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::run( + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).run` instead")] + #[export_name = "run"] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} diff --git a/tests-expanded/test_import_contract_tests.rs b/tests-expanded/test_import_contract_tests.rs new file mode 100644 index 000000000..b684afb3c --- /dev/null +++ b/tests-expanded/test_import_contract_tests.rs @@ -0,0 +1,587 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl, Address, Env}; +mod addcontract { + pub const WASM: &[u8] = b"\0asm\x01\0\0\0\x01\x14\x04`\x01~\x01~`\x02\x7f~\0`\x02~~\x01~`\0\0\x02\r\x02\x01i\x010\0\0\x01i\x01_\0\0\x03\x05\x04\x01\x02\x03\x03\x05\x03\x01\0\x10\x06!\x04\x7f\x01A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x07/\x05\x06memory\x02\0\x03add\0\x03\x01_\x03\x01\n__data_end\x03\x02\x0b__heap_base\x03\x03\n\x89\x02\x04]\x02\x01\x7f\x01~\x02@\x02@ \x01\xa7A\xff\x01q\"\x02A\xc0\0F\r\0\x02@ \x02A\x06F\r\0B\x01!\x03B\x83\x90\x80\x80\x80\x01!\x01\x0c\x02\x0b \x01B\x08\x88!\x01B\0!\x03\x0c\x01\x0bB\0!\x03 \x01\x10\x80\x80\x80\x80\0!\x01\x0b \0 \x037\x03\0 \0 \x017\x03\x08\x0b\x9a\x01\x01\x01\x7f#\x80\x80\x80\x80\0A\x10k\"\x02$\x80\x80\x80\x80\0 \x02 \0\x10\x82\x80\x80\x80\0\x02@\x02@ \x02(\x02\0A\x01F\r\0 \x02)\x03\x08!\0 \x02 \x01\x10\x82\x80\x80\x80\0 \x02(\x02\0A\x01F\r\0 \0 \x02)\x03\x08|\"\x01 \0T\r\x01\x02@\x02@ \x01B\xff\xff\xff\xff\xff\xff\xff\xff\0V\r\0 \x01B\x08\x86B\x06\x84!\0\x0c\x01\x0b \x01\x10\x81\x80\x80\x80\0!\0\x0b \x02A\x10j$\x80\x80\x80\x80\0 \0\x0f\x0b\0\x0b\x10\x84\x80\x80\x80\0\0\x0b\t\0\x10\x85\x80\x80\x80\0\0\x0b\x03\0\0\x0b\x0b\t\x01\0A\x80\x80\xc0\0\x0b\0\0K\x0econtractspecv0\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x06\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x06\0\0\0\x01\0\0\0\x06\0\x1e\x11contractenvmetav0\0\0\0\0\0\0\0\x17\0\0\0\0\0w\x0econtractmetav0\0\0\0\0\0\0\0\x05rsver\0\0\0\0\0\0\x061.89.0\0\0\0\0\0\0\0\0\0\x08rssdkver\0\0\0523.0.2#07757a358c22c45669af2bf51500ae83c33f9a26-dirty\0\0\0"; + pub trait Contract { + fn add(env: soroban_sdk::Env, a: u64, b: u64) -> u64; + } + ///Client is a client for calling the contract defined in "Contract". + pub struct Client<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, + } + impl<'a> Client<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } + } + impl<'a> Client<'a> { + pub fn add(&self, a: &u64, b: &u64) -> u64 { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_add( + &self, + a: &u64, + b: &u64, + ) -> Result< + Result< + u64, + >::Error, + >, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + } + ///Args is a type for building arg lists for functions defined in "Contract". + pub struct Args; + impl Args { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn add<'i>(a: &'i u64, b: &'i u64) -> (&'i u64, &'i u64) { + (a, b) + } + } +} +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +impl Contract { + pub fn add_with(env: Env, contract_id: Address, x: u64, y: u64) -> u64 { + addcontract::Client::new(&env, &contract_id).add(&x, &y) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add_with__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_ADD_WITH: [u8; 88usize] = super::Contract::spec_xdr_add_with(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_add_with() -> [u8; 88usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x08add_with\0\0\0\x03\0\0\0\0\0\0\0\x0bcontract_id\0\0\0\0\x13\0\0\0\0\0\0\0\x01x\0\0\0\0\0\0\x06\0\0\0\0\0\0\0\x01y\0\0\0\0\0\0\x06\0\0\0\x01\0\0\0\x06" + } +} +impl<'a> ContractClient<'a> { + pub fn add_with(&self, contract_id: &Address, x: &u64, y: &u64) -> u64 { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add_with"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [ + contract_id.into_val(&self.env), + x.into_val(&self.env), + y.into_val(&self.env), + ], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_add_with( + &self, + contract_id: &Address, + x: &u64, + y: &u64, + ) -> Result< + Result>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add_with"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [ + contract_id.into_val(&self.env), + x.into_val(&self.env), + y.into_val(&self.env), + ], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn add_with<'i>( + contract_id: &'i Address, + x: &'i u64, + y: &'i u64, + ) -> (&'i Address, &'i u64, &'i u64) { + (contract_id, x, y) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add_with { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add_with` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::add_with( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_2), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add_with` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 3usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 3usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize], args[1usize], args[2usize]) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add_with` instead")] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1, arg_2) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e85117ee9756_ctor() { + ::register( + "add_with", + #[allow(deprecated)] + &__Contract__add_with::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e85117ee9756_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e85117ee9756_ctor___rust_ctor___ctor() -> usize { + __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e85117ee9756_ctor(); + 0 + } + __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e85117ee9756_ctor___rust_ctor___ctor +}; +mod test { + use crate::{addcontract, Contract, ContractClient}; + use soroban_sdk::Env; + extern crate test; + #[rustc_test_marker = "test::test_add"] + #[doc(hidden)] + pub const test_add: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test_add"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/import_contract/src/lib.rs", + start_line: 25usize, + start_col: 8usize, + end_line: 25usize, + end_col: 16usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_add()), + ), + }; + fn test_add() { + let e = Env::default(); + let add_contract_id = e.register(addcontract::WASM, ()); + let contract_id = e.register(Contract, ()); + let client = ContractClient::new(&e, &contract_id); + let x = 10u64; + let y = 12u64; + let z = client.add_with(&add_contract_id, &x, &y); + if !(z == 22) { + ::core::panicking::panic("assertion failed: z == 22") + } + } +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[&test_add]) +} diff --git a/tests-expanded/test_import_contract_wasm32v1-none.rs b/tests-expanded/test_import_contract_wasm32v1-none.rs new file mode 100644 index 000000000..86487a5e0 --- /dev/null +++ b/tests-expanded/test_import_contract_wasm32v1-none.rs @@ -0,0 +1,233 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl, Address, Env}; +mod addcontract { + pub const WASM: &[u8] = b"\0asm\x01\0\0\0\x01\x14\x04`\x01~\x01~`\x02\x7f~\0`\x02~~\x01~`\0\0\x02\r\x02\x01i\x010\0\0\x01i\x01_\0\0\x03\x05\x04\x01\x02\x03\x03\x05\x03\x01\0\x10\x06!\x04\x7f\x01A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x07/\x05\x06memory\x02\0\x03add\0\x03\x01_\x03\x01\n__data_end\x03\x02\x0b__heap_base\x03\x03\n\x89\x02\x04]\x02\x01\x7f\x01~\x02@\x02@ \x01\xa7A\xff\x01q\"\x02A\xc0\0F\r\0\x02@ \x02A\x06F\r\0B\x01!\x03B\x83\x90\x80\x80\x80\x01!\x01\x0c\x02\x0b \x01B\x08\x88!\x01B\0!\x03\x0c\x01\x0bB\0!\x03 \x01\x10\x80\x80\x80\x80\0!\x01\x0b \0 \x037\x03\0 \0 \x017\x03\x08\x0b\x9a\x01\x01\x01\x7f#\x80\x80\x80\x80\0A\x10k\"\x02$\x80\x80\x80\x80\0 \x02 \0\x10\x82\x80\x80\x80\0\x02@\x02@ \x02(\x02\0A\x01F\r\0 \x02)\x03\x08!\0 \x02 \x01\x10\x82\x80\x80\x80\0 \x02(\x02\0A\x01F\r\0 \0 \x02)\x03\x08|\"\x01 \0T\r\x01\x02@\x02@ \x01B\xff\xff\xff\xff\xff\xff\xff\xff\0V\r\0 \x01B\x08\x86B\x06\x84!\0\x0c\x01\x0b \x01\x10\x81\x80\x80\x80\0!\0\x0b \x02A\x10j$\x80\x80\x80\x80\0 \0\x0f\x0b\0\x0b\x10\x84\x80\x80\x80\0\0\x0b\t\0\x10\x85\x80\x80\x80\0\0\x0b\x03\0\0\x0b\x0b\t\x01\0A\x80\x80\xc0\0\x0b\0\0K\x0econtractspecv0\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x06\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x06\0\0\0\x01\0\0\0\x06\0\x1e\x11contractenvmetav0\0\0\0\0\0\0\0\x17\0\0\0\0\0w\x0econtractmetav0\0\0\0\0\0\0\0\x05rsver\0\0\0\0\0\0\x061.89.0\0\0\0\0\0\0\0\0\0\x08rssdkver\0\0\0523.0.2#07757a358c22c45669af2bf51500ae83c33f9a26-dirty\0\0\0"; + pub trait Contract { + fn add(env: soroban_sdk::Env, a: u64, b: u64) -> u64; + } + ///Client is a client for calling the contract defined in "Contract". + pub struct Client<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, + } + impl<'a> Client<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } + } + impl<'a> Client<'a> { + pub fn add(&self, a: &u64, b: &u64) -> u64 { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + res + } + pub fn try_add( + &self, + a: &u64, + b: &u64, + ) -> Result< + Result< + u64, + >::Error, + >, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + res + } + } + ///Args is a type for building arg lists for functions defined in "Contract". + pub struct Args; + impl Args { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn add<'i>(a: &'i u64, b: &'i u64) -> (&'i u64, &'i u64) { + (a, b) + } + } +} +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl Contract { + pub fn add_with(env: Env, contract_id: Address, x: u64, y: u64) -> u64 { + addcontract::Client::new(&env, &contract_id).add(&x, &y) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add_with__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_ADD_WITH: [u8; 88usize] = super::Contract::spec_xdr_add_with(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_add_with() -> [u8; 88usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x08add_with\0\0\0\x03\0\0\0\0\0\0\0\x0bcontract_id\0\0\0\0\x13\0\0\0\0\0\0\0\x01x\0\0\0\0\0\0\x06\0\0\0\0\0\0\0\x01y\0\0\0\0\0\0\x06\0\0\0\x01\0\0\0\x06" + } +} +impl<'a> ContractClient<'a> { + pub fn add_with(&self, contract_id: &Address, x: &u64, y: &u64) -> u64 { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add_with"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [ + contract_id.into_val(&self.env), + x.into_val(&self.env), + y.into_val(&self.env), + ], + ), + ); + res + } + pub fn try_add_with( + &self, + contract_id: &Address, + x: &u64, + y: &u64, + ) -> Result< + Result>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add_with"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [ + contract_id.into_val(&self.env), + x.into_val(&self.env), + y.into_val(&self.env), + ], + ), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn add_with<'i>( + contract_id: &'i Address, + x: &'i u64, + y: &'i u64, + ) -> (&'i Address, &'i u64, &'i u64) { + (contract_id, x, y) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add_with { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add_with` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::add_with( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_2), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add_with` instead")] + #[export_name = "add_with"] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1, arg_2) + } + use super::*; +} diff --git a/tests-expanded/test_invoke_contract_tests.rs b/tests-expanded/test_invoke_contract_tests.rs new file mode 100644 index 000000000..7212e0df8 --- /dev/null +++ b/tests-expanded/test_invoke_contract_tests.rs @@ -0,0 +1,717 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl, symbol_short, vec, Address, Env, IntoVal}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +impl Contract { + pub fn add_with(env: Env, x: i32, y: i32, contract_id: Address) -> i32 { + env.invoke_contract( + &contract_id, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&env, [x.into_val(&env), y.into_val(&env)]), + ) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add_with__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_ADD_WITH: [u8; 88usize] = super::Contract::spec_xdr_add_with(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_add_with() -> [u8; 88usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x08add_with\0\0\0\x03\0\0\0\0\0\0\0\x01x\0\0\0\0\0\0\x05\0\0\0\0\0\0\0\x01y\0\0\0\0\0\0\x05\0\0\0\0\0\0\0\x0bcontract_id\0\0\0\0\x13\0\0\0\x01\0\0\0\x05" + } +} +impl<'a> ContractClient<'a> { + pub fn add_with(&self, x: &i32, y: &i32, contract_id: &Address) -> i32 { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add_with"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [ + x.into_val(&self.env), + y.into_val(&self.env), + contract_id.into_val(&self.env), + ], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_add_with( + &self, + x: &i32, + y: &i32, + contract_id: &Address, + ) -> Result< + Result>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add_with"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [ + x.into_val(&self.env), + y.into_val(&self.env), + contract_id.into_val(&self.env), + ], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn add_with<'i>( + x: &'i i32, + y: &'i i32, + contract_id: &'i Address, + ) -> (&'i i32, &'i i32, &'i Address) { + (x, y, contract_id) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add_with { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add_with` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::add_with( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_2), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add_with` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 3usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 3usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize], args[1usize], args[2usize]) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add_with` instead")] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1, arg_2) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e85117ee9756_ctor() { + ::register( + "add_with", + #[allow(deprecated)] + &__Contract__add_with::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e85117ee9756_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e85117ee9756_ctor___rust_ctor___ctor() -> usize { + __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e85117ee9756_ctor(); + 0 + } + __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e85117ee9756_ctor___rust_ctor___ctor +}; +pub struct AddContract; +///AddContractArgs is a type for building arg lists for functions defined in "AddContract". +pub struct AddContractArgs; +///AddContractClient is a client for calling the contract defined in "AddContract". +pub struct AddContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> AddContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __addcontract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for AddContract { + fn register(name: &'static str, func: &'static __addcontract_fn_set_registry::F) { + __addcontract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for AddContract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __addcontract_fn_set_registry::call(func, env, args) + } +} +impl AddContract { + pub fn add(_: Env, a: i32, b: i32) -> i32 { + a + b + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __AddContract__add__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_ADD: [u8; 60usize] = super::AddContract::spec_xdr_add(); +} +impl AddContract { + #[allow(non_snake_case)] + pub const fn spec_xdr_add() -> [u8; 60usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x05\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x05\0\0\0\x01\0\0\0\x05" + } +} +impl<'a> AddContractClient<'a> { + pub fn add(&self, a: &i32, b: &i32) -> i32 { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_add( + &self, + a: &i32, + b: &i32, + ) -> Result< + Result>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl AddContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn add<'i>(a: &'i i32, b: &'i i32) -> (&'i i32, &'i i32) { + (a, b) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __AddContract__add { + use super::*; + #[deprecated(note = "use `AddContractClient::new(&env, &contract_id).add` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::add( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `AddContractClient::new(&env, &contract_id).add` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 2usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 2usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize], args[1usize]) + } + #[deprecated(note = "use `AddContractClient::new(&env, &contract_id).add` instead")] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __AddContract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor() +{ + ::register( + "add", + #[allow(deprecated)] + &__AddContract__add::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __AddContract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __AddContract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor() -> usize { + __AddContract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor(); + 0 + } + __AddContract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor +}; +mod test { + use crate::{AddContract, Contract, ContractClient}; + use soroban_sdk::Env; + extern crate test; + #[rustc_test_marker = "test::test_add"] + #[doc(hidden)] + pub const test_add: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test_add"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/invoke_contract/src/lib.rs", + start_line: 36usize, + start_col: 8usize, + end_line: 36usize, + end_col: 16usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_add()), + ), + }; + fn test_add() { + let e = Env::default(); + let add_contract_id = e.register(AddContract, ()); + let contract_id = e.register(Contract, ()); + let client = ContractClient::new(&e, &contract_id); + let x = 10i32; + let y = 12i32; + let z = client.add_with(&x, &y, &add_contract_id); + if !(z == 22) { + ::core::panicking::panic("assertion failed: z == 22") + } + } +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[&test_add]) +} diff --git a/tests-expanded/test_invoke_contract_wasm32v1-none.rs b/tests-expanded/test_invoke_contract_wasm32v1-none.rs new file mode 100644 index 000000000..6127c5008 --- /dev/null +++ b/tests-expanded/test_invoke_contract_wasm32v1-none.rs @@ -0,0 +1,294 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl, symbol_short, vec, Address, Env, IntoVal}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl Contract { + pub fn add_with(env: Env, x: i32, y: i32, contract_id: Address) -> i32 { + env.invoke_contract( + &contract_id, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array(&env, [x.into_val(&env), y.into_val(&env)]), + ) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add_with__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_ADD_WITH: [u8; 88usize] = super::Contract::spec_xdr_add_with(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_add_with() -> [u8; 88usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x08add_with\0\0\0\x03\0\0\0\0\0\0\0\x01x\0\0\0\0\0\0\x05\0\0\0\0\0\0\0\x01y\0\0\0\0\0\0\x05\0\0\0\0\0\0\0\x0bcontract_id\0\0\0\0\x13\0\0\0\x01\0\0\0\x05" + } +} +impl<'a> ContractClient<'a> { + pub fn add_with(&self, x: &i32, y: &i32, contract_id: &Address) -> i32 { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add_with"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [ + x.into_val(&self.env), + y.into_val(&self.env), + contract_id.into_val(&self.env), + ], + ), + ); + res + } + pub fn try_add_with( + &self, + x: &i32, + y: &i32, + contract_id: &Address, + ) -> Result< + Result>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add_with"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [ + x.into_val(&self.env), + y.into_val(&self.env), + contract_id.into_val(&self.env), + ], + ), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn add_with<'i>( + x: &'i i32, + y: &'i i32, + contract_id: &'i Address, + ) -> (&'i i32, &'i i32, &'i Address) { + (x, y, contract_id) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add_with { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add_with` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::add_with( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_2), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add_with` instead")] + #[export_name = "add_with"] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + arg_2: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1, arg_2) + } + use super::*; +} +pub struct AddContract; +///AddContractArgs is a type for building arg lists for functions defined in "AddContract". +pub struct AddContractArgs; +///AddContractClient is a client for calling the contract defined in "AddContract". +pub struct AddContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> AddContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl AddContract { + pub fn add(_: Env, a: i32, b: i32) -> i32 { + a + b + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __AddContract__add__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_ADD: [u8; 60usize] = super::AddContract::spec_xdr_add(); +} +impl AddContract { + #[allow(non_snake_case)] + pub const fn spec_xdr_add() -> [u8; 60usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x05\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x05\0\0\0\x01\0\0\0\x05" + } +} +impl<'a> AddContractClient<'a> { + pub fn add(&self, a: &i32, b: &i32) -> i32 { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + res + } + pub fn try_add( + &self, + a: &i32, + b: &i32, + ) -> Result< + Result>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + res + } +} +impl AddContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn add<'i>(a: &'i i32, b: &'i i32) -> (&'i i32, &'i i32) { + (a, b) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __AddContract__add { + use super::*; + #[deprecated(note = "use `AddContractClient::new(&env, &contract_id).add` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::add( + env.clone(), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `AddContractClient::new(&env, &contract_id).add` instead")] + #[export_name = "add"] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} diff --git a/tests-expanded/test_logging_tests.rs b/tests-expanded/test_logging_tests.rs new file mode 100644 index 000000000..c72e81a42 --- /dev/null +++ b/tests-expanded/test_logging_tests.rs @@ -0,0 +1,447 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl, log, symbol_short, Env}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +impl Contract { + pub fn hello(env: Env) { + if true { + (&env).logs().add("none", &[]); + } + if true { + (&env).logs().add("none", &[]); + } + if true { + (&env).logs().add( + "one:", + &[ + <_ as ::soroban_sdk::IntoVal>::into_val( + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("one"); + SYMBOL + }, + &env, + ), + ], + ); + } + if true { + (&env).logs().add( + "one:", + &[ + <_ as ::soroban_sdk::IntoVal>::into_val( + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("one"); + SYMBOL + }, + &env, + ), + ], + ); + } + if true { + (&env).logs().add( + "one and two:", + &[ + <_ as ::soroban_sdk::IntoVal>::into_val( + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("one"); + SYMBOL + }, + &env, + ), + <_ as ::soroban_sdk::IntoVal>::into_val( + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("two"); + SYMBOL + }, + &env, + ), + ], + ); + } + if true { + (&env).logs().add( + "one and two:", + &[ + <_ as ::soroban_sdk::IntoVal>::into_val( + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("one"); + SYMBOL + }, + &env, + ), + <_ as ::soroban_sdk::IntoVal>::into_val( + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("two"); + SYMBOL + }, + &env, + ), + ], + ); + } + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__hello__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_HELLO: [u8; 28usize] = super::Contract::spec_xdr_hello(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_hello() -> [u8; 28usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x05hello\0\0\0\0\0\0\0\0\0\0\0" + } +} +impl<'a> ContractClient<'a> { + pub fn hello(&self) -> () { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("hello"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_hello( + &self, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("hello"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn hello<'i>() -> () { + () + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__hello { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).hello` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::hello(env.clone()), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).hello` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 0usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 0usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).hello` instead")] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824_ctor() { + ::register( + "hello", + #[allow(deprecated)] + &__Contract__hello::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824_ctor___rust_ctor___ctor() -> usize { + __Contract__2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824_ctor(); + 0 + } + __Contract__2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824_ctor___rust_ctor___ctor +}; +mod test { + extern crate std; + use crate::{Contract, ContractClient}; + use soroban_sdk::{testutils::Logs, Env}; + extern crate test; + #[rustc_test_marker = "test::test_logging"] + #[doc(hidden)] + pub const test_logging: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test_logging"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/logging/src/lib.rs", + start_line: 38usize, + start_col: 8usize, + end_line: 38usize, + end_col: 20usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_logging()), + ), + }; + fn test_logging() { + let env = Env::default(); + let contract_id = env.register(Contract, ()); + let client = ContractClient::new(&env, &contract_id); + client.hello(); + env.logs().print(); + if true { + let pats = <[_]>::into_vec(::alloc::boxed::box_new([ + "\"none\"", + "\"none\"", + "[\"one:\", one]", + "[\"one:\", one]", + "[\"one and two:\", one, two]", + "[\"one and two:\", one, two]", + ])); + for (msg, pat) in env.logs().all().iter().zip(pats.iter()) { + if !msg.contains(pat) { + ::core::panicking::panic("assertion failed: msg.contains(pat)") + } + } + } else { + match (&env.logs().all(), &::alloc::vec::from_elem("", 0)) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + } + } +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[&test_logging]) +} diff --git a/tests-expanded/test_logging_wasm32v1-none.rs b/tests-expanded/test_logging_wasm32v1-none.rs new file mode 100644 index 000000000..0a9ec0e79 --- /dev/null +++ b/tests-expanded/test_logging_wasm32v1-none.rs @@ -0,0 +1,188 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl, log, symbol_short, Env}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl Contract { + pub fn hello(env: Env) { + if false { + (&env).logs().add("none", &[]); + } + if false { + (&env).logs().add("none", &[]); + } + if false { + (&env).logs().add( + "one:", + &[ + <_ as ::soroban_sdk::IntoVal>::into_val( + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("one"); + SYMBOL + }, + &env, + ), + ], + ); + } + if false { + (&env).logs().add( + "one:", + &[ + <_ as ::soroban_sdk::IntoVal>::into_val( + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("one"); + SYMBOL + }, + &env, + ), + ], + ); + } + if false { + (&env).logs().add( + "one and two:", + &[ + <_ as ::soroban_sdk::IntoVal>::into_val( + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("one"); + SYMBOL + }, + &env, + ), + <_ as ::soroban_sdk::IntoVal>::into_val( + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("two"); + SYMBOL + }, + &env, + ), + ], + ); + } + if false { + (&env).logs().add( + "one and two:", + &[ + <_ as ::soroban_sdk::IntoVal>::into_val( + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("one"); + SYMBOL + }, + &env, + ), + <_ as ::soroban_sdk::IntoVal>::into_val( + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("two"); + SYMBOL + }, + &env, + ), + ], + ); + } + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__hello__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_HELLO: [u8; 28usize] = super::Contract::spec_xdr_hello(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_hello() -> [u8; 28usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x05hello\0\0\0\0\0\0\0\0\0\0\0" + } +} +impl<'a> ContractClient<'a> { + pub fn hello(&self) -> () { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("hello"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + res + } + pub fn try_hello( + &self, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("hello"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn hello<'i>() -> () { + () + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__hello { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).hello` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::hello(env.clone()), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).hello` instead")] + #[export_name = "hello"] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; +} diff --git a/tests-expanded/test_macros_tests.rs b/tests-expanded/test_macros_tests.rs new file mode 100644 index 000000000..27bbd2bb1 --- /dev/null +++ b/tests-expanded/test_macros_tests.rs @@ -0,0 +1,334 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use proc_macros::parse_item_fn; +use soroban_sdk::{contract, contractimpl}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +impl Contract { + pub fn empty() {} +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__empty__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_EMPTY: [u8; 28usize] = super::Contract::spec_xdr_empty(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_empty() -> [u8; 28usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x05empty\0\0\0\0\0\0\0\0\0\0\0" + } +} +impl<'a> ContractClient<'a> { + pub fn empty(&self) -> () { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("empty"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_empty( + &self, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("empty"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn empty<'i>() -> () { + () + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__empty { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::empty(), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 0usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 0usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty` instead")] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor() { + ::register( + "empty", + #[allow(deprecated)] + &__Contract__empty::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor___rust_ctor___ctor() -> usize { + __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor(); + 0 + } + __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor___rust_ctor___ctor +}; +mod test { + use crate::{Contract, ContractClient}; + use soroban_sdk::Env; + extern crate test; + #[rustc_test_marker = "test::test_empty"] + #[doc(hidden)] + pub const test_empty: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test_empty"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/macros/src/lib.rs", + start_line: 25usize, + start_col: 8usize, + end_line: 25usize, + end_col: 18usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_empty()), + ), + }; + fn test_empty() { + let e = Env::default(); + let contract_id = e.register(Contract, ()); + let client = ContractClient::new(&e, &contract_id); + client.empty(); + } +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[&test_empty]) +} diff --git a/tests-expanded/test_macros_wasm32v1-none.rs b/tests-expanded/test_macros_wasm32v1-none.rs new file mode 100644 index 000000000..27f0c0f87 --- /dev/null +++ b/tests-expanded/test_macros_wasm32v1-none.rs @@ -0,0 +1,106 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use proc_macros::parse_item_fn; +use soroban_sdk::{contract, contractimpl}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl Contract { + pub fn empty() {} +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__empty__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_EMPTY: [u8; 28usize] = super::Contract::spec_xdr_empty(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_empty() -> [u8; 28usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x05empty\0\0\0\0\0\0\0\0\0\0\0" + } +} +impl<'a> ContractClient<'a> { + pub fn empty(&self) -> () { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("empty"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + res + } + pub fn try_empty( + &self, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("empty"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn empty<'i>() -> () { + () + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__empty { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::empty(), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty` instead")] + #[export_name = "empty"] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; +} diff --git a/tests-expanded/test_modular_tests.rs b/tests-expanded/test_modular_tests.rs new file mode 100644 index 000000000..64afde849 --- /dev/null +++ b/tests-expanded/test_modular_tests.rs @@ -0,0 +1,712 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl}; +mod feat1 { + use crate::Contract; + use crate::ContractArgs; + use crate::ContractClient; + use soroban_sdk::contractimpl; + impl Contract { + pub fn one() -> u32 { + 1 + } + } + #[doc(hidden)] + #[allow(non_snake_case)] + pub mod __Contract__one__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_ONE: [u8; 28usize] = super::Contract::spec_xdr_one(); + } + impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_one() -> [u8; 28usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03one\0\0\0\0\0\0\0\0\x01\0\0\0\x04" + } + } + impl<'a> ContractClient<'a> { + pub fn one(&self) -> u32 { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("one"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_one( + &self, + ) -> Result< + Result< + u32, + >::Error, + >, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("one"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + } + impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn one<'i>() -> () { + () + } + } + #[doc(hidden)] + #[allow(non_snake_case)] + pub mod __Contract__one { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).one` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::one(), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).one` instead")] + pub fn invoke_raw_slice( + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> soroban_sdk::Val { + if args.len() != 0usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 0usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).one` instead")] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; + } + #[doc(hidden)] + #[allow(non_snake_case)] + extern "C" fn __Contract__7692c3ad3540bb803c020b3aee66cd8887123234ea0c6e7143c0add73ff431ed_ctor( + ) { + ::register( + "one", + #[allow(deprecated)] + &__Contract__one::invoke_raw_slice, + ); + } + #[used] + #[allow(non_upper_case_globals, non_snake_case)] + #[doc(hidden)] + #[link_section = "__DATA,__mod_init_func"] + static __Contract__7692c3ad3540bb803c020b3aee66cd8887123234ea0c6e7143c0add73ff431ed_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__7692c3ad3540bb803c020b3aee66cd8887123234ea0c6e7143c0add73ff431ed_ctor___rust_ctor___ctor() -> usize { + __Contract__7692c3ad3540bb803c020b3aee66cd8887123234ea0c6e7143c0add73ff431ed_ctor(); + 0 + } + __Contract__7692c3ad3540bb803c020b3aee66cd8887123234ea0c6e7143c0add73ff431ed_ctor___rust_ctor___ctor + }; +} +mod feat2 { + use crate::ContractArgs; + use crate::ContractClient; + use soroban_sdk::contractimpl; + impl super::Contract { + pub fn two() -> u32 { + 2 + } + } + #[doc(hidden)] + #[allow(non_snake_case)] + pub mod __super__Contract__two__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_TWO: [u8; 28usize] = super::super::Contract::spec_xdr_two(); + } + impl super::Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_two() -> [u8; 28usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03two\0\0\0\0\0\0\0\0\x01\0\0\0\x04" + } + } + impl<'a> ContractClient<'a> { + pub fn two(&self) -> u32 { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("two"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_two( + &self, + ) -> Result< + Result< + u32, + >::Error, + >, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("two"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + } + impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn two<'i>() -> () { + () + } + } + #[doc(hidden)] + #[allow(non_snake_case)] + pub mod __super__Contract__two { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).two` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::two(), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).two` instead")] + pub fn invoke_raw_slice( + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> soroban_sdk::Val { + if args.len() != 0usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 0usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).two` instead")] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; + } + #[doc(hidden)] + #[allow(non_snake_case)] + extern "C" fn __super__Contract__3fc4ccfe745870e2c0d99f71f30ff0656c8dedd41cc1d7d3d376b0dbe685e2f3_ctor( + ) { + ::register( + "two", + #[allow(deprecated)] + &__super__Contract__two::invoke_raw_slice, + ); + } + #[used] + #[allow(non_upper_case_globals, non_snake_case)] + #[doc(hidden)] + #[link_section = "__DATA,__mod_init_func"] + static __super__Contract__3fc4ccfe745870e2c0d99f71f30ff0656c8dedd41cc1d7d3d376b0dbe685e2f3_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __super__Contract__3fc4ccfe745870e2c0d99f71f30ff0656c8dedd41cc1d7d3d376b0dbe685e2f3_ctor___rust_ctor___ctor() -> usize { + __super__Contract__3fc4ccfe745870e2c0d99f71f30ff0656c8dedd41cc1d7d3d376b0dbe685e2f3_ctor(); + 0 + } + __super__Contract__3fc4ccfe745870e2c0d99f71f30ff0656c8dedd41cc1d7d3d376b0dbe685e2f3_ctor___rust_ctor___ctor + }; +} +mod test { + use crate::{Contract, ContractClient}; + use soroban_sdk::Env; + extern crate test; + #[rustc_test_marker = "test::test"] + #[doc(hidden)] + pub const test: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/modular/src/test.rs", + start_line: 7usize, + start_col: 4usize, + end_line: 7usize, + end_col: 8usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test()), + ), + }; + fn test() { + let env = Env::default(); + let id = env.register(Contract, ()); + let client = ContractClient::new(&env, &id); + match (&client.zero(), &0) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match (&client.one(), &1) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + match (&client.two(), &2) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + } +} +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +impl Contract { + pub fn zero() -> u32 { + 0 + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__zero__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_ZERO: [u8; 28usize] = super::Contract::spec_xdr_zero(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_zero() -> [u8; 28usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x04zero\0\0\0\0\0\0\0\x01\0\0\0\x04" + } +} +impl<'a> ContractClient<'a> { + pub fn zero(&self) -> u32 { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("zero"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_zero( + &self, + ) -> Result< + Result>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("zero"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn zero<'i>() -> () { + () + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__zero { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).zero` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::zero(), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).zero` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 0usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 0usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).zero` instead")] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__f9194e73f9e9459e3450ea10a179cdf77aafa695beecd3b9344a98d111622243_ctor() { + ::register( + "zero", + #[allow(deprecated)] + &__Contract__zero::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__f9194e73f9e9459e3450ea10a179cdf77aafa695beecd3b9344a98d111622243_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__f9194e73f9e9459e3450ea10a179cdf77aafa695beecd3b9344a98d111622243_ctor___rust_ctor___ctor() -> usize { + __Contract__f9194e73f9e9459e3450ea10a179cdf77aafa695beecd3b9344a98d111622243_ctor(); + 0 + } + __Contract__f9194e73f9e9459e3450ea10a179cdf77aafa695beecd3b9344a98d111622243_ctor___rust_ctor___ctor +}; +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[&test]) +} diff --git a/tests-expanded/test_modular_wasm32v1-none.rs b/tests-expanded/test_modular_wasm32v1-none.rs new file mode 100644 index 000000000..ffe0d21be --- /dev/null +++ b/tests-expanded/test_modular_wasm32v1-none.rs @@ -0,0 +1,286 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl}; +mod feat1 { + use crate::Contract; + use crate::ContractArgs; + use crate::ContractClient; + use soroban_sdk::contractimpl; + impl Contract { + pub fn one() -> u32 { + 1 + } + } + #[doc(hidden)] + #[allow(non_snake_case)] + pub mod __Contract__one__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_ONE: [u8; 28usize] = super::Contract::spec_xdr_one(); + } + impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_one() -> [u8; 28usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03one\0\0\0\0\0\0\0\0\x01\0\0\0\x04" + } + } + impl<'a> ContractClient<'a> { + pub fn one(&self) -> u32 { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("one"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + res + } + pub fn try_one( + &self, + ) -> Result< + Result< + u32, + >::Error, + >, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("one"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + res + } + } + impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn one<'i>() -> () { + () + } + } + #[doc(hidden)] + #[allow(non_snake_case)] + pub mod __Contract__one { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).one` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::one(), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).one` instead")] + #[export_name = "one"] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; + } +} +mod feat2 { + use crate::ContractArgs; + use crate::ContractClient; + use soroban_sdk::contractimpl; + impl super::Contract { + pub fn two() -> u32 { + 2 + } + } + #[doc(hidden)] + #[allow(non_snake_case)] + pub mod __super__Contract__two__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_TWO: [u8; 28usize] = super::super::Contract::spec_xdr_two(); + } + impl super::Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_two() -> [u8; 28usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03two\0\0\0\0\0\0\0\0\x01\0\0\0\x04" + } + } + impl<'a> ContractClient<'a> { + pub fn two(&self) -> u32 { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("two"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + res + } + pub fn try_two( + &self, + ) -> Result< + Result< + u32, + >::Error, + >, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("two"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + res + } + } + impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn two<'i>() -> () { + () + } + } + #[doc(hidden)] + #[allow(non_snake_case)] + pub mod __super__Contract__two { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).two` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::two(), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).two` instead")] + #[export_name = "two"] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; + } +} +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl Contract { + pub fn zero() -> u32 { + 0 + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__zero__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_ZERO: [u8; 28usize] = super::Contract::spec_xdr_zero(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_zero() -> [u8; 28usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x04zero\0\0\0\0\0\0\0\x01\0\0\0\x04" + } +} +impl<'a> ContractClient<'a> { + pub fn zero(&self) -> u32 { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("zero"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + res + } + pub fn try_zero( + &self, + ) -> Result< + Result>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("zero"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn zero<'i>() -> () { + () + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__zero { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).zero` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::zero(), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).zero` instead")] + #[export_name = "zero"] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; +} diff --git a/tests-expanded/test_multiimpl_tests.rs b/tests-expanded/test_multiimpl_tests.rs new file mode 100644 index 000000000..576de882b --- /dev/null +++ b/tests-expanded/test_multiimpl_tests.rs @@ -0,0 +1,650 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +impl Contract { + pub fn empty() {} +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__empty__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_EMPTY: [u8; 28usize] = super::Contract::spec_xdr_empty(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_empty() -> [u8; 28usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x05empty\0\0\0\0\0\0\0\0\0\0\0" + } +} +impl<'a> ContractClient<'a> { + pub fn empty(&self) -> () { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("empty"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_empty( + &self, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("empty"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn empty<'i>() -> () { + () + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__empty { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::empty(), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 0usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 0usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty` instead")] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor() { + ::register( + "empty", + #[allow(deprecated)] + &__Contract__empty::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor___rust_ctor___ctor() -> usize { + __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor(); + 0 + } + __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor___rust_ctor___ctor +}; +impl Contract { + pub fn empty2() {} +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__empty2__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_EMPTY2: [u8; 28usize] = super::Contract::spec_xdr_empty2(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_empty2() -> [u8; 28usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x06empty2\0\0\0\0\0\0\0\0\0\0" + } +} +impl<'a> ContractClient<'a> { + pub fn empty2(&self) -> () { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("empty2"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_empty2( + &self, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("empty2"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn empty2<'i>() -> () { + () + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__empty2 { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty2` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::empty2(), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty2` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 0usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 0usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty2` instead")] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__a081c9c13231c3c184333e4fde14f4f10e045d30869e1b800f4338ab8a726ca4_ctor() { + ::register( + "empty2", + #[allow(deprecated)] + &__Contract__empty2::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__a081c9c13231c3c184333e4fde14f4f10e045d30869e1b800f4338ab8a726ca4_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__a081c9c13231c3c184333e4fde14f4f10e045d30869e1b800f4338ab8a726ca4_ctor___rust_ctor___ctor() -> usize { + __Contract__a081c9c13231c3c184333e4fde14f4f10e045d30869e1b800f4338ab8a726ca4_ctor(); + 0 + } + __Contract__a081c9c13231c3c184333e4fde14f4f10e045d30869e1b800f4338ab8a726ca4_ctor___rust_ctor___ctor +}; +trait Trait { + fn empty3() {} +} +impl Trait for Contract { + fn empty3() {} +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__empty3__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_EMPTY3: [u8; 28usize] = super::Contract::spec_xdr_empty3(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_empty3() -> [u8; 28usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x06empty3\0\0\0\0\0\0\0\0\0\0" + } +} +impl<'a> ContractClient<'a> { + pub fn empty3(&self) -> () { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("empty3"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_empty3( + &self, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("empty3"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn empty3<'i>() -> () { + () + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__empty3 { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty3` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + use super::Trait; + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::empty3(), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty3` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 0usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 0usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty3` instead")] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract_Trait_2be3aa1100044a64e8135c570a7b382cebaca742493cf17b77052a7ae50fa889_ctor( +) { + ::register( + "empty3", + #[allow(deprecated)] + &__Contract__empty3::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract_Trait_2be3aa1100044a64e8135c570a7b382cebaca742493cf17b77052a7ae50fa889_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract_Trait_2be3aa1100044a64e8135c570a7b382cebaca742493cf17b77052a7ae50fa889_ctor___rust_ctor___ctor() -> usize { + __Contract_Trait_2be3aa1100044a64e8135c570a7b382cebaca742493cf17b77052a7ae50fa889_ctor(); + 0 + } + __Contract_Trait_2be3aa1100044a64e8135c570a7b382cebaca742493cf17b77052a7ae50fa889_ctor___rust_ctor___ctor +}; +mod test { + use crate::{Contract, ContractClient}; + use soroban_sdk::Env; + extern crate test; + #[rustc_test_marker = "test::test_hello"] + #[doc(hidden)] + pub const test_hello: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test_hello"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/multiimpl/src/lib.rs", + start_line: 33usize, + start_col: 8usize, + end_line: 33usize, + end_col: 18usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_hello()), + ), + }; + fn test_hello() { + let e = Env::default(); + let contract_id = e.register(Contract, ()); + let client = ContractClient::new(&e, &contract_id); + client.empty(); + client.empty2(); + client.empty3(); + } +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[&test_hello]) +} diff --git a/tests-expanded/test_multiimpl_wasm32v1-none.rs b/tests-expanded/test_multiimpl_wasm32v1-none.rs new file mode 100644 index 000000000..eff397db0 --- /dev/null +++ b/tests-expanded/test_multiimpl_wasm32v1-none.rs @@ -0,0 +1,267 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl Contract { + pub fn empty() {} +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__empty__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_EMPTY: [u8; 28usize] = super::Contract::spec_xdr_empty(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_empty() -> [u8; 28usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x05empty\0\0\0\0\0\0\0\0\0\0\0" + } +} +impl<'a> ContractClient<'a> { + pub fn empty(&self) -> () { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("empty"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + res + } + pub fn try_empty( + &self, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("empty"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn empty<'i>() -> () { + () + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__empty { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::empty(), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty` instead")] + #[export_name = "empty"] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; +} +impl Contract { + pub fn empty2() {} +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__empty2__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_EMPTY2: [u8; 28usize] = super::Contract::spec_xdr_empty2(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_empty2() -> [u8; 28usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x06empty2\0\0\0\0\0\0\0\0\0\0" + } +} +impl<'a> ContractClient<'a> { + pub fn empty2(&self) -> () { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("empty2"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + res + } + pub fn try_empty2( + &self, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("empty2"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn empty2<'i>() -> () { + () + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__empty2 { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty2` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::empty2(), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty2` instead")] + #[export_name = "empty2"] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; +} +trait Trait { + fn empty3() {} +} +impl Trait for Contract { + fn empty3() {} +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__empty3__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_EMPTY3: [u8; 28usize] = super::Contract::spec_xdr_empty3(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_empty3() -> [u8; 28usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x06empty3\0\0\0\0\0\0\0\0\0\0" + } +} +impl<'a> ContractClient<'a> { + pub fn empty3(&self) -> () { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("empty3"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + res + } + pub fn try_empty3( + &self, + ) -> Result< + Result<(), <() as soroban_sdk::TryFromVal>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("empty3"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn empty3<'i>() -> () { + () + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__empty3 { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty3` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + use super::Trait; + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::empty3(), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).empty3` instead")] + #[export_name = "empty3"] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; +} diff --git a/tests-expanded/test_udt_tests.rs b/tests-expanded/test_udt_tests.rs new file mode 100644 index 000000000..023854081 --- /dev/null +++ b/tests-expanded/test_udt_tests.rs @@ -0,0 +1,2309 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl, contracttype, Vec}; +pub enum UdtEnum2 { + A = 10, + B = 15, +} +#[automatically_derived] +impl ::core::marker::Copy for UdtEnum2 {} +#[automatically_derived] +impl ::core::clone::Clone for UdtEnum2 { + #[inline] + fn clone(&self) -> UdtEnum2 { + *self + } +} +#[automatically_derived] +impl ::core::fmt::Debug for UdtEnum2 { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::write_str( + f, + match self { + UdtEnum2::A => "A", + UdtEnum2::B => "B", + }, + ) + } +} +#[automatically_derived] +impl ::core::cmp::Eq for UdtEnum2 { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () {} +} +#[automatically_derived] +impl ::core::marker::StructuralPartialEq for UdtEnum2 {} +#[automatically_derived] +impl ::core::cmp::PartialEq for UdtEnum2 { + #[inline] + fn eq(&self, other: &UdtEnum2) -> bool { + let __self_discr = ::core::intrinsics::discriminant_value(self); + let __arg1_discr = ::core::intrinsics::discriminant_value(other); + __self_discr == __arg1_discr + } +} +pub static __SPEC_XDR_TYPE_UDTENUM2: [u8; 60usize] = UdtEnum2::spec_xdr(); +impl UdtEnum2 { + pub const fn spec_xdr() -> [u8; 60usize] { + *b"\0\0\0\x03\0\0\0\0\0\0\0\0\0\0\0\x08UdtEnum2\0\0\0\x02\0\0\0\0\0\0\0\x01A\0\0\0\0\0\0\n\0\0\0\0\0\0\0\x01B\0\0\0\0\0\0\x0f" + } +} +impl soroban_sdk::TryFromVal for UdtEnum2 { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::TryIntoVal; + let discriminant: u32 = val.try_into_val(env)?; + Ok(match discriminant { + 10u32 => Self::A, + 15u32 => Self::B, + _ => Err(soroban_sdk::ConversionError {})?, + }) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &UdtEnum2, + ) -> Result { + Ok(match val { + UdtEnum2::A => 10u32.into(), + UdtEnum2::B => 15u32.into(), + }) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&UdtEnum2, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } +} +impl soroban_sdk::TryFromVal for UdtEnum2 { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::xdr::ScVal, + ) -> Result { + if let soroban_sdk::xdr::ScVal::U32(discriminant) = val { + Ok(match *discriminant { + 10u32 => Self::A, + 15u32 => Self::B, + _ => Err(soroban_sdk::xdr::Error::Invalid)?, + }) + } else { + Err(soroban_sdk::xdr::Error::Invalid) + } + } +} +impl TryInto for &UdtEnum2 { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_into(self) -> Result { + Ok(match self { + UdtEnum2::A => 10u32.into(), + UdtEnum2::B => 15u32.into(), + }) + } +} +impl TryInto for UdtEnum2 { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_into(self) -> Result { + Ok(match self { + UdtEnum2::A => 10u32.into(), + UdtEnum2::B => 15u32.into(), + }) + } +} +const _: () = { + use soroban_sdk::testutils::arbitrary::arbitrary; + use soroban_sdk::testutils::arbitrary::std; + pub enum ArbitraryUdtEnum2 { + A, + B, + } + #[automatically_derived] + impl ::core::fmt::Debug for ArbitraryUdtEnum2 { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::write_str( + f, + match self { + ArbitraryUdtEnum2::A => "A", + ArbitraryUdtEnum2::B => "B", + }, + ) + } + } + #[automatically_derived] + impl ::core::clone::Clone for ArbitraryUdtEnum2 { + #[inline] + fn clone(&self) -> ArbitraryUdtEnum2 { + match self { + ArbitraryUdtEnum2::A => ArbitraryUdtEnum2::A, + ArbitraryUdtEnum2::B => ArbitraryUdtEnum2::B, + } + } + } + #[automatically_derived] + impl ::core::cmp::Eq for ArbitraryUdtEnum2 { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () {} + } + #[automatically_derived] + impl ::core::marker::StructuralPartialEq for ArbitraryUdtEnum2 {} + #[automatically_derived] + impl ::core::cmp::PartialEq for ArbitraryUdtEnum2 { + #[inline] + fn eq(&self, other: &ArbitraryUdtEnum2) -> bool { + let __self_discr = ::core::intrinsics::discriminant_value(self); + let __arg1_discr = ::core::intrinsics::discriminant_value(other); + __self_discr == __arg1_discr + } + } + #[automatically_derived] + impl ::core::cmp::Ord for ArbitraryUdtEnum2 { + #[inline] + fn cmp(&self, other: &ArbitraryUdtEnum2) -> ::core::cmp::Ordering { + let __self_discr = ::core::intrinsics::discriminant_value(self); + let __arg1_discr = ::core::intrinsics::discriminant_value(other); + ::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr) + } + } + #[automatically_derived] + impl ::core::cmp::PartialOrd for ArbitraryUdtEnum2 { + #[inline] + fn partial_cmp( + &self, + other: &ArbitraryUdtEnum2, + ) -> ::core::option::Option<::core::cmp::Ordering> { + let __self_discr = ::core::intrinsics::discriminant_value(self); + let __arg1_discr = ::core::intrinsics::discriminant_value(other); + ::core::cmp::PartialOrd::partial_cmp(&__self_discr, &__arg1_discr) + } + } + const _: () = { + #[allow(non_upper_case_globals)] + const RECURSIVE_COUNT_ArbitraryUdtEnum2: ::std::thread::LocalKey> = { + #[inline] + fn __init() -> std::cell::Cell { + std::cell::Cell::new(0) + } + unsafe { + ::std::thread::LocalKey::new( + const { + if ::std::mem::needs_drop::>() { + |init| { + #[thread_local] + static VAL: ::std::thread::local_impl::LazyStorage< + std::cell::Cell, + (), + > = ::std::thread::local_impl::LazyStorage::new(); + VAL.get_or_init(init, __init) + } + } else { + |init| { + #[thread_local] + static VAL: ::std::thread::local_impl::LazyStorage< + std::cell::Cell, + !, + > = ::std::thread::local_impl::LazyStorage::new(); + VAL.get_or_init(init, __init) + } + } + }, + ) + } + }; + #[automatically_derived] + impl<'arbitrary> arbitrary::Arbitrary<'arbitrary> for ArbitraryUdtEnum2 { + fn arbitrary(u: &mut arbitrary::Unstructured<'arbitrary>) -> arbitrary::Result { + let guard_against_recursion = u.is_empty(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryUdtEnum2.with(|count| { + if count.get() > 0 { + return Err(arbitrary::Error::NotEnoughData); + } + count.set(count.get() + 1); + Ok(()) + })?; + } + let result = (|| { + Ok( + match (u64::from(::arbitrary(u)?) * 2u64) >> 32 + { + 0u64 => ArbitraryUdtEnum2::A, + 1u64 => ArbitraryUdtEnum2::B, + _ => { + ::core::panicking::panic("internal error: entered unreachable code") + } + }, + ) + })(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryUdtEnum2.with(|count| { + count.set(count.get() - 1); + }); + } + result + } + fn arbitrary_take_rest( + mut u: arbitrary::Unstructured<'arbitrary>, + ) -> arbitrary::Result { + let guard_against_recursion = u.is_empty(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryUdtEnum2.with(|count| { + if count.get() > 0 { + return Err(arbitrary::Error::NotEnoughData); + } + count.set(count.get() + 1); + Ok(()) + })?; + } + let result = (|| { + Ok( + match (u64::from(::arbitrary(&mut u)?) * 2u64) + >> 32 + { + 0u64 => ArbitraryUdtEnum2::A, + 1u64 => ArbitraryUdtEnum2::B, + _ => { + ::core::panicking::panic("internal error: entered unreachable code") + } + }, + ) + })(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryUdtEnum2.with(|count| { + count.set(count.get() - 1); + }); + } + result + } + #[inline] + fn size_hint(depth: usize) -> (usize, Option) { + arbitrary::size_hint::and( + ::size_hint(depth), + arbitrary::size_hint::recursion_guard(depth, |depth| { + arbitrary::size_hint::or_all(&[ + arbitrary::size_hint::and_all(&[]), + arbitrary::size_hint::and_all(&[]), + ]) + }), + ) + } + } + }; + impl soroban_sdk::testutils::arbitrary::SorobanArbitrary for UdtEnum2 { + type Prototype = ArbitraryUdtEnum2; + } + impl soroban_sdk::TryFromVal for UdtEnum2 { + type Error = soroban_sdk::ConversionError; + fn try_from_val( + env: &soroban_sdk::Env, + v: &ArbitraryUdtEnum2, + ) -> std::result::Result { + Ok(match v { + ArbitraryUdtEnum2::A => UdtEnum2::A, + ArbitraryUdtEnum2::B => UdtEnum2::B, + }) + } + } +}; +pub enum UdtEnum { + UdtA, + UdtB(UdtStruct), + UdtC(UdtEnum2), + UdtD(UdtTuple), +} +#[automatically_derived] +impl ::core::clone::Clone for UdtEnum { + #[inline] + fn clone(&self) -> UdtEnum { + match self { + UdtEnum::UdtA => UdtEnum::UdtA, + UdtEnum::UdtB(__self_0) => UdtEnum::UdtB(::core::clone::Clone::clone(__self_0)), + UdtEnum::UdtC(__self_0) => UdtEnum::UdtC(::core::clone::Clone::clone(__self_0)), + UdtEnum::UdtD(__self_0) => UdtEnum::UdtD(::core::clone::Clone::clone(__self_0)), + } + } +} +#[automatically_derived] +impl ::core::fmt::Debug for UdtEnum { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + UdtEnum::UdtA => ::core::fmt::Formatter::write_str(f, "UdtA"), + UdtEnum::UdtB(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "UdtB", &__self_0) + } + UdtEnum::UdtC(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "UdtC", &__self_0) + } + UdtEnum::UdtD(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "UdtD", &__self_0) + } + } + } +} +#[automatically_derived] +impl ::core::cmp::Eq for UdtEnum { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () { + let _: ::core::cmp::AssertParamIsEq; + let _: ::core::cmp::AssertParamIsEq; + let _: ::core::cmp::AssertParamIsEq; + } +} +#[automatically_derived] +impl ::core::marker::StructuralPartialEq for UdtEnum {} +#[automatically_derived] +impl ::core::cmp::PartialEq for UdtEnum { + #[inline] + fn eq(&self, other: &UdtEnum) -> bool { + let __self_discr = ::core::intrinsics::discriminant_value(self); + let __arg1_discr = ::core::intrinsics::discriminant_value(other); + __self_discr == __arg1_discr + && match (self, other) { + (UdtEnum::UdtB(__self_0), UdtEnum::UdtB(__arg1_0)) => __self_0 == __arg1_0, + (UdtEnum::UdtC(__self_0), UdtEnum::UdtC(__arg1_0)) => __self_0 == __arg1_0, + (UdtEnum::UdtD(__self_0), UdtEnum::UdtD(__arg1_0)) => __self_0 == __arg1_0, + _ => true, + } + } +} +pub static __SPEC_XDR_TYPE_UDTENUM: [u8; 156usize] = UdtEnum::spec_xdr(); +impl UdtEnum { + pub const fn spec_xdr() -> [u8; 156usize] { + *b"\0\0\0\x02\0\0\0\0\0\0\0\0\0\0\0\x07UdtEnum\0\0\0\0\x04\0\0\0\0\0\0\0\0\0\0\0\x04UdtA\0\0\0\x01\0\0\0\0\0\0\0\x04UdtB\0\0\0\x01\0\0\x07\xd0\0\0\0\tUdtStruct\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\x04UdtC\0\0\0\x01\0\0\x07\xd0\0\0\0\x08UdtEnum2\0\0\0\x01\0\0\0\0\0\0\0\x04UdtD\0\0\0\x01\0\0\x07\xd0\0\0\0\x08UdtTuple" + } +} +impl soroban_sdk::TryFromVal for UdtEnum { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::{EnvBase, TryFromVal, TryIntoVal}; + const CASES: &'static [&'static str] = &["UdtA", "UdtB", "UdtC", "UdtD"]; + let vec: soroban_sdk::Vec = val.try_into_val(env)?; + let mut iter = vec.try_iter(); + let discriminant: soroban_sdk::Symbol = iter + .next() + .ok_or(soroban_sdk::ConversionError)?? + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?; + Ok( + match u32::from(env.symbol_index_in_strs(discriminant.to_symbol_val(), CASES)?) as usize + { + 0 => { + if iter.len() > 0 { + return Err(soroban_sdk::ConversionError); + } + Self::UdtA + } + 1 => { + if iter.len() > 1usize { + return Err(soroban_sdk::ConversionError); + } + Self::UdtB( + iter.next() + .ok_or(soroban_sdk::ConversionError)?? + .try_into_val(env)?, + ) + } + 2 => { + if iter.len() > 1usize { + return Err(soroban_sdk::ConversionError); + } + Self::UdtC( + iter.next() + .ok_or(soroban_sdk::ConversionError)?? + .try_into_val(env)?, + ) + } + 3 => { + if iter.len() > 1usize { + return Err(soroban_sdk::ConversionError); + } + Self::UdtD( + iter.next() + .ok_or(soroban_sdk::ConversionError)?? + .try_into_val(env)?, + ) + } + _ => Err(soroban_sdk::ConversionError {})?, + }, + ) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &UdtEnum, + ) -> Result { + use soroban_sdk::{TryFromVal, TryIntoVal}; + match val { + UdtEnum::UdtA => { + let tup: (soroban_sdk::Val,) = + (soroban_sdk::Symbol::try_from_val(env, &"UdtA")?.to_val(),); + tup.try_into_val(env).map_err(Into::into) + } + UdtEnum::UdtB(ref value0) => { + let tup: (soroban_sdk::Val, soroban_sdk::Val) = ( + soroban_sdk::Symbol::try_from_val(env, &"UdtB")?.to_val(), + value0.try_into_val(env)?, + ); + tup.try_into_val(env).map_err(Into::into) + } + UdtEnum::UdtC(ref value0) => { + let tup: (soroban_sdk::Val, soroban_sdk::Val) = ( + soroban_sdk::Symbol::try_from_val(env, &"UdtC")?.to_val(), + value0.try_into_val(env)?, + ); + tup.try_into_val(env).map_err(Into::into) + } + UdtEnum::UdtD(ref value0) => { + let tup: (soroban_sdk::Val, soroban_sdk::Val) = ( + soroban_sdk::Symbol::try_from_val(env, &"UdtD")?.to_val(), + value0.try_into_val(env)?, + ); + tup.try_into_val(env).map_err(Into::into) + } + } + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&UdtEnum, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } +} +impl soroban_sdk::TryFromVal for UdtEnum { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::xdr::ScVec, + ) -> Result { + use soroban_sdk::xdr::Validate; + use soroban_sdk::TryIntoVal; + let vec = val; + let mut iter = vec.iter(); + let discriminant: soroban_sdk::xdr::ScSymbol = iter + .next() + .ok_or(soroban_sdk::xdr::Error::Invalid)? + .clone() + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + let discriminant_name: &str = &discriminant.to_utf8_string()?; + Ok(match discriminant_name { + "UdtA" => { + if iter.len() > 0 { + return Err(soroban_sdk::xdr::Error::Invalid); + } + Self::UdtA + } + "UdtB" => { + if iter.len() > 1usize { + return Err(soroban_sdk::xdr::Error::Invalid); + } + let rv0: soroban_sdk::Val = iter + .next() + .ok_or(soroban_sdk::xdr::Error::Invalid)? + .try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + Self::UdtB( + rv0.try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + } + "UdtC" => { + if iter.len() > 1usize { + return Err(soroban_sdk::xdr::Error::Invalid); + } + let rv0: soroban_sdk::Val = iter + .next() + .ok_or(soroban_sdk::xdr::Error::Invalid)? + .try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + Self::UdtC( + rv0.try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + } + "UdtD" => { + if iter.len() > 1usize { + return Err(soroban_sdk::xdr::Error::Invalid); + } + let rv0: soroban_sdk::Val = iter + .next() + .ok_or(soroban_sdk::xdr::Error::Invalid)? + .try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + Self::UdtD( + rv0.try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + } + _ => Err(soroban_sdk::xdr::Error::Invalid)?, + }) + } +} +impl soroban_sdk::TryFromVal for UdtEnum { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::xdr::ScVal, + ) -> Result { + if let soroban_sdk::xdr::ScVal::Vec(Some(vec)) = val { + <_ as soroban_sdk::TryFromVal<_, _>>::try_from_val(env, vec) + } else { + Err(soroban_sdk::xdr::Error::Invalid) + } + } +} +impl TryFrom<&UdtEnum> for soroban_sdk::xdr::ScVec { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: &UdtEnum) -> Result { + extern crate alloc; + Ok(match val { + UdtEnum::UdtA => { + let symbol = soroban_sdk::xdr::ScSymbol( + "UdtA" + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ); + let val = soroban_sdk::xdr::ScVal::Symbol(symbol); + (val,) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)? + } + UdtEnum::UdtB(value0) => ( + soroban_sdk::xdr::ScSymbol( + "UdtB" + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ), + value0, + ) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + UdtEnum::UdtC(value0) => ( + soroban_sdk::xdr::ScSymbol( + "UdtC" + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ), + value0, + ) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + UdtEnum::UdtD(value0) => ( + soroban_sdk::xdr::ScSymbol( + "UdtD" + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ), + value0, + ) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + }) + } +} +impl TryFrom for soroban_sdk::xdr::ScVec { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: UdtEnum) -> Result { + (&val).try_into() + } +} +impl TryFrom<&UdtEnum> for soroban_sdk::xdr::ScVal { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: &UdtEnum) -> Result { + Ok(soroban_sdk::xdr::ScVal::Vec(Some(val.try_into()?))) + } +} +impl TryFrom for soroban_sdk::xdr::ScVal { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: UdtEnum) -> Result { + (&val).try_into() + } +} +const _: () = { + use soroban_sdk::testutils::arbitrary::arbitrary; + use soroban_sdk::testutils::arbitrary::std; + pub enum ArbitraryUdtEnum { + UdtA, + UdtB(::Prototype), + UdtC(::Prototype), + UdtD(::Prototype), + } + #[automatically_derived] + impl ::core::fmt::Debug for ArbitraryUdtEnum { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + ArbitraryUdtEnum::UdtA => ::core::fmt::Formatter::write_str(f, "UdtA"), + ArbitraryUdtEnum::UdtB(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "UdtB", &__self_0) + } + ArbitraryUdtEnum::UdtC(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "UdtC", &__self_0) + } + ArbitraryUdtEnum::UdtD(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "UdtD", &__self_0) + } + } + } + } + #[automatically_derived] + impl ::core::clone::Clone for ArbitraryUdtEnum { + #[inline] + fn clone(&self) -> ArbitraryUdtEnum { + match self { + ArbitraryUdtEnum::UdtA => ArbitraryUdtEnum::UdtA, + ArbitraryUdtEnum::UdtB(__self_0) => { + ArbitraryUdtEnum::UdtB(::core::clone::Clone::clone(__self_0)) + } + ArbitraryUdtEnum::UdtC(__self_0) => { + ArbitraryUdtEnum::UdtC(::core::clone::Clone::clone(__self_0)) + } + ArbitraryUdtEnum::UdtD(__self_0) => { + ArbitraryUdtEnum::UdtD(::core::clone::Clone::clone(__self_0)) + } + } + } + } + #[automatically_derived] + impl ::core::cmp::Eq for ArbitraryUdtEnum { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () { + let _: ::core::cmp::AssertParamIsEq< + ::Prototype, + >; + let _: ::core::cmp::AssertParamIsEq< + ::Prototype, + >; + let _: ::core::cmp::AssertParamIsEq< + ::Prototype, + >; + } + } + #[automatically_derived] + impl ::core::marker::StructuralPartialEq for ArbitraryUdtEnum {} + #[automatically_derived] + impl ::core::cmp::PartialEq for ArbitraryUdtEnum { + #[inline] + fn eq(&self, other: &ArbitraryUdtEnum) -> bool { + let __self_discr = ::core::intrinsics::discriminant_value(self); + let __arg1_discr = ::core::intrinsics::discriminant_value(other); + __self_discr == __arg1_discr + && match (self, other) { + (ArbitraryUdtEnum::UdtB(__self_0), ArbitraryUdtEnum::UdtB(__arg1_0)) => { + __self_0 == __arg1_0 + } + (ArbitraryUdtEnum::UdtC(__self_0), ArbitraryUdtEnum::UdtC(__arg1_0)) => { + __self_0 == __arg1_0 + } + (ArbitraryUdtEnum::UdtD(__self_0), ArbitraryUdtEnum::UdtD(__arg1_0)) => { + __self_0 == __arg1_0 + } + _ => true, + } + } + } + #[automatically_derived] + impl ::core::cmp::Ord for ArbitraryUdtEnum { + #[inline] + fn cmp(&self, other: &ArbitraryUdtEnum) -> ::core::cmp::Ordering { + let __self_discr = ::core::intrinsics::discriminant_value(self); + let __arg1_discr = ::core::intrinsics::discriminant_value(other); + match ::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr) { + ::core::cmp::Ordering::Equal => match (self, other) { + (ArbitraryUdtEnum::UdtB(__self_0), ArbitraryUdtEnum::UdtB(__arg1_0)) => { + ::core::cmp::Ord::cmp(__self_0, __arg1_0) + } + (ArbitraryUdtEnum::UdtC(__self_0), ArbitraryUdtEnum::UdtC(__arg1_0)) => { + ::core::cmp::Ord::cmp(__self_0, __arg1_0) + } + (ArbitraryUdtEnum::UdtD(__self_0), ArbitraryUdtEnum::UdtD(__arg1_0)) => { + ::core::cmp::Ord::cmp(__self_0, __arg1_0) + } + _ => ::core::cmp::Ordering::Equal, + }, + cmp => cmp, + } + } + } + #[automatically_derived] + impl ::core::cmp::PartialOrd for ArbitraryUdtEnum { + #[inline] + fn partial_cmp( + &self, + other: &ArbitraryUdtEnum, + ) -> ::core::option::Option<::core::cmp::Ordering> { + let __self_discr = ::core::intrinsics::discriminant_value(self); + let __arg1_discr = ::core::intrinsics::discriminant_value(other); + match (self, other) { + (ArbitraryUdtEnum::UdtB(__self_0), ArbitraryUdtEnum::UdtB(__arg1_0)) => { + ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0) + } + (ArbitraryUdtEnum::UdtC(__self_0), ArbitraryUdtEnum::UdtC(__arg1_0)) => { + ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0) + } + (ArbitraryUdtEnum::UdtD(__self_0), ArbitraryUdtEnum::UdtD(__arg1_0)) => { + ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0) + } + _ => ::core::cmp::PartialOrd::partial_cmp(&__self_discr, &__arg1_discr), + } + } + } + const _: () = { + #[allow(non_upper_case_globals)] + const RECURSIVE_COUNT_ArbitraryUdtEnum: ::std::thread::LocalKey> = { + #[inline] + fn __init() -> std::cell::Cell { + std::cell::Cell::new(0) + } + unsafe { + ::std::thread::LocalKey::new( + const { + if ::std::mem::needs_drop::>() { + |init| { + #[thread_local] + static VAL: ::std::thread::local_impl::LazyStorage< + std::cell::Cell, + (), + > = ::std::thread::local_impl::LazyStorage::new(); + VAL.get_or_init(init, __init) + } + } else { + |init| { + #[thread_local] + static VAL: ::std::thread::local_impl::LazyStorage< + std::cell::Cell, + !, + > = ::std::thread::local_impl::LazyStorage::new(); + VAL.get_or_init(init, __init) + } + } + }, + ) + } + }; + #[automatically_derived] + impl<'arbitrary> arbitrary::Arbitrary<'arbitrary> for ArbitraryUdtEnum { + fn arbitrary(u: &mut arbitrary::Unstructured<'arbitrary>) -> arbitrary::Result { + let guard_against_recursion = u.is_empty(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryUdtEnum.with(|count| { + if count.get() > 0 { + return Err(arbitrary::Error::NotEnoughData); + } + count.set(count.get() + 1); + Ok(()) + })?; + } + let result = (|| { + Ok( + match (u64::from(::arbitrary(u)?) * 4u64) >> 32 + { + 0u64 => ArbitraryUdtEnum::UdtA, + 1u64 => ArbitraryUdtEnum::UdtB(arbitrary::Arbitrary::arbitrary(u)?), + 2u64 => ArbitraryUdtEnum::UdtC(arbitrary::Arbitrary::arbitrary(u)?), + 3u64 => ArbitraryUdtEnum::UdtD(arbitrary::Arbitrary::arbitrary(u)?), + _ => { + ::core::panicking::panic("internal error: entered unreachable code") + } + }, + ) + })(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryUdtEnum.with(|count| { + count.set(count.get() - 1); + }); + } + result + } + fn arbitrary_take_rest( + mut u: arbitrary::Unstructured<'arbitrary>, + ) -> arbitrary::Result { + let guard_against_recursion = u.is_empty(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryUdtEnum.with(|count| { + if count.get() > 0 { + return Err(arbitrary::Error::NotEnoughData); + } + count.set(count.get() + 1); + Ok(()) + })?; + } + let result = (|| { + Ok( + match (u64::from(::arbitrary(&mut u)?) * 4u64) + >> 32 + { + 0u64 => ArbitraryUdtEnum::UdtA, + 1u64 => ArbitraryUdtEnum::UdtB( + arbitrary::Arbitrary::arbitrary_take_rest(u)?, + ), + 2u64 => ArbitraryUdtEnum::UdtC( + arbitrary::Arbitrary::arbitrary_take_rest(u)?, + ), + 3u64 => ArbitraryUdtEnum::UdtD( + arbitrary::Arbitrary::arbitrary_take_rest(u)?, + ), + _ => { + ::core::panicking::panic("internal error: entered unreachable code") + } + }, + ) + })(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryUdtEnum.with(|count| { + count.set(count.get() - 1); + }); + } + result + } + #[inline] + fn size_hint(depth: usize) -> (usize, Option) { + arbitrary::size_hint::and( + ::size_hint(depth), + arbitrary::size_hint::recursion_guard(depth, |depth| { + arbitrary::size_hint::or_all( + &[ + arbitrary::size_hint::and_all(&[]), + arbitrary::size_hint::and_all( + &[ + <::Prototype as arbitrary::Arbitrary>::size_hint( + depth, + ), + ], + ), + arbitrary::size_hint::and_all( + &[ + <::Prototype as arbitrary::Arbitrary>::size_hint( + depth, + ), + ], + ), + arbitrary::size_hint::and_all( + &[ + <::Prototype as arbitrary::Arbitrary>::size_hint( + depth, + ), + ], + ), + ], + ) + }), + ) + } + } + }; + impl soroban_sdk::testutils::arbitrary::SorobanArbitrary for UdtEnum { + type Prototype = ArbitraryUdtEnum; + } + impl soroban_sdk::TryFromVal for UdtEnum { + type Error = soroban_sdk::ConversionError; + fn try_from_val( + env: &soroban_sdk::Env, + v: &ArbitraryUdtEnum, + ) -> std::result::Result { + Ok(match v { + ArbitraryUdtEnum::UdtA => UdtEnum::UdtA, + ArbitraryUdtEnum::UdtB(field_0) => { + UdtEnum::UdtB(soroban_sdk::IntoVal::into_val(field_0, env)) + } + ArbitraryUdtEnum::UdtC(field_0) => { + UdtEnum::UdtC(soroban_sdk::IntoVal::into_val(field_0, env)) + } + ArbitraryUdtEnum::UdtD(field_0) => { + UdtEnum::UdtD(soroban_sdk::IntoVal::into_val(field_0, env)) + } + }) + } + } +}; +pub struct UdtTuple(pub i64, pub Vec); +#[automatically_derived] +impl ::core::clone::Clone for UdtTuple { + #[inline] + fn clone(&self) -> UdtTuple { + UdtTuple( + ::core::clone::Clone::clone(&self.0), + ::core::clone::Clone::clone(&self.1), + ) + } +} +#[automatically_derived] +impl ::core::fmt::Debug for UdtTuple { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field2_finish(f, "UdtTuple", &self.0, &&self.1) + } +} +#[automatically_derived] +impl ::core::cmp::Eq for UdtTuple { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () { + let _: ::core::cmp::AssertParamIsEq; + let _: ::core::cmp::AssertParamIsEq>; + } +} +#[automatically_derived] +impl ::core::marker::StructuralPartialEq for UdtTuple {} +#[automatically_derived] +impl ::core::cmp::PartialEq for UdtTuple { + #[inline] + fn eq(&self, other: &UdtTuple) -> bool { + self.0 == other.0 && self.1 == other.1 + } +} +pub static __SPEC_XDR_TYPE_UDTTUPLE: [u8; 64usize] = UdtTuple::spec_xdr(); +impl UdtTuple { + pub const fn spec_xdr() -> [u8; 64usize] { + *b"\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\x08UdtTuple\0\0\0\x02\0\0\0\0\0\0\0\x010\0\0\0\0\0\0\x07\0\0\0\0\0\0\0\x011\0\0\0\0\0\x03\xea\0\0\0\x07" + } +} +impl soroban_sdk::TryFromVal for UdtTuple { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::{ConversionError, EnvBase, TryIntoVal, Val, VecObject}; + let vec: VecObject = (*val).try_into().map_err(|_| ConversionError)?; + let mut vals: [Val; 2usize] = [Val::VOID.to_val(); 2usize]; + env.vec_unpack_to_slice(vec, &mut vals) + .map_err(|_| ConversionError)?; + Ok(Self { + 0: vals[0].try_into_val(env).map_err(|_| ConversionError)?, + 1: vals[1].try_into_val(env).map_err(|_| ConversionError)?, + }) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &UdtTuple, + ) -> Result { + use soroban_sdk::{ConversionError, EnvBase, TryIntoVal, Val}; + let vals: [Val; 2usize] = [ + (&val.0).try_into_val(env).map_err(|_| ConversionError)?, + (&val.1).try_into_val(env).map_err(|_| ConversionError)?, + ]; + Ok(env + .vec_new_from_slice(&vals) + .map_err(|_| ConversionError)? + .into()) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&UdtTuple, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } +} +impl soroban_sdk::TryFromVal for UdtTuple { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::xdr::ScVec, + ) -> Result { + use soroban_sdk::xdr::Validate; + use soroban_sdk::TryIntoVal; + let vec = val; + if vec.len() != 2usize { + return Err(soroban_sdk::xdr::Error::Invalid); + } + Ok(Self { + 0: { + let rv: soroban_sdk::Val = (&vec[0].clone()) + .try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + rv.try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)? + }, + 1: { + let rv: soroban_sdk::Val = (&vec[1].clone()) + .try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + rv.try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)? + }, + }) + } +} +impl soroban_sdk::TryFromVal for UdtTuple { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::xdr::ScVal, + ) -> Result { + if let soroban_sdk::xdr::ScVal::Vec(Some(vec)) = val { + <_ as soroban_sdk::TryFromVal<_, _>>::try_from_val(env, vec) + } else { + Err(soroban_sdk::xdr::Error::Invalid) + } + } +} +impl TryFrom<&UdtTuple> for soroban_sdk::xdr::ScVec { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: &UdtTuple) -> Result { + extern crate alloc; + use soroban_sdk::TryFromVal; + Ok(soroban_sdk::xdr::ScVec( + <[_]>::into_vec(::alloc::boxed::box_new([ + (&val.0) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + (&val.1) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ])) + .try_into()?, + )) + } +} +impl TryFrom for soroban_sdk::xdr::ScVec { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: UdtTuple) -> Result { + (&val).try_into() + } +} +impl TryFrom<&UdtTuple> for soroban_sdk::xdr::ScVal { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: &UdtTuple) -> Result { + Ok(soroban_sdk::xdr::ScVal::Vec(Some(val.try_into()?))) + } +} +impl TryFrom for soroban_sdk::xdr::ScVal { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: UdtTuple) -> Result { + (&val).try_into() + } +} +const _: () = { + use soroban_sdk::testutils::arbitrary::arbitrary; + use soroban_sdk::testutils::arbitrary::std; + pub struct ArbitraryUdtTuple( + ::Prototype, + as soroban_sdk::testutils::arbitrary::SorobanArbitrary>::Prototype, + ); + #[automatically_derived] + impl ::core::fmt::Debug for ArbitraryUdtTuple { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field2_finish( + f, + "ArbitraryUdtTuple", + &self.0, + &&self.1, + ) + } + } + #[automatically_derived] + impl ::core::clone::Clone for ArbitraryUdtTuple { + #[inline] + fn clone(&self) -> ArbitraryUdtTuple { + ArbitraryUdtTuple( + ::core::clone::Clone::clone(&self.0), + ::core::clone::Clone::clone(&self.1), + ) + } + } + #[automatically_derived] + impl ::core::cmp::Eq for ArbitraryUdtTuple { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () { + let _: ::core::cmp::AssertParamIsEq< + ::Prototype, + >; + let _: ::core::cmp::AssertParamIsEq< + as soroban_sdk::testutils::arbitrary::SorobanArbitrary>::Prototype, + >; + } + } + #[automatically_derived] + impl ::core::marker::StructuralPartialEq for ArbitraryUdtTuple {} + #[automatically_derived] + impl ::core::cmp::PartialEq for ArbitraryUdtTuple { + #[inline] + fn eq(&self, other: &ArbitraryUdtTuple) -> bool { + self.0 == other.0 && self.1 == other.1 + } + } + #[automatically_derived] + impl ::core::cmp::Ord for ArbitraryUdtTuple { + #[inline] + fn cmp(&self, other: &ArbitraryUdtTuple) -> ::core::cmp::Ordering { + match ::core::cmp::Ord::cmp(&self.0, &other.0) { + ::core::cmp::Ordering::Equal => ::core::cmp::Ord::cmp(&self.1, &other.1), + cmp => cmp, + } + } + } + #[automatically_derived] + impl ::core::cmp::PartialOrd for ArbitraryUdtTuple { + #[inline] + fn partial_cmp( + &self, + other: &ArbitraryUdtTuple, + ) -> ::core::option::Option<::core::cmp::Ordering> { + match ::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0) { + ::core::option::Option::Some(::core::cmp::Ordering::Equal) => { + ::core::cmp::PartialOrd::partial_cmp(&self.1, &other.1) + } + cmp => cmp, + } + } + } + const _: () = { + #[allow(non_upper_case_globals)] + const RECURSIVE_COUNT_ArbitraryUdtTuple: ::std::thread::LocalKey> = { + #[inline] + fn __init() -> std::cell::Cell { + std::cell::Cell::new(0) + } + unsafe { + ::std::thread::LocalKey::new( + const { + if ::std::mem::needs_drop::>() { + |init| { + #[thread_local] + static VAL: ::std::thread::local_impl::LazyStorage< + std::cell::Cell, + (), + > = ::std::thread::local_impl::LazyStorage::new(); + VAL.get_or_init(init, __init) + } + } else { + |init| { + #[thread_local] + static VAL: ::std::thread::local_impl::LazyStorage< + std::cell::Cell, + !, + > = ::std::thread::local_impl::LazyStorage::new(); + VAL.get_or_init(init, __init) + } + } + }, + ) + } + }; + #[automatically_derived] + impl<'arbitrary> arbitrary::Arbitrary<'arbitrary> for ArbitraryUdtTuple { + fn arbitrary(u: &mut arbitrary::Unstructured<'arbitrary>) -> arbitrary::Result { + let guard_against_recursion = u.is_empty(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryUdtTuple.with(|count| { + if count.get() > 0 { + return Err(arbitrary::Error::NotEnoughData); + } + count.set(count.get() + 1); + Ok(()) + })?; + } + let result = (|| { + Ok(ArbitraryUdtTuple( + arbitrary::Arbitrary::arbitrary(u)?, + arbitrary::Arbitrary::arbitrary(u)?, + )) + })(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryUdtTuple.with(|count| { + count.set(count.get() - 1); + }); + } + result + } + fn arbitrary_take_rest( + mut u: arbitrary::Unstructured<'arbitrary>, + ) -> arbitrary::Result { + let guard_against_recursion = u.is_empty(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryUdtTuple.with(|count| { + if count.get() > 0 { + return Err(arbitrary::Error::NotEnoughData); + } + count.set(count.get() + 1); + Ok(()) + })?; + } + let result = (|| { + Ok(ArbitraryUdtTuple( + arbitrary::Arbitrary::arbitrary(&mut u)?, + arbitrary::Arbitrary::arbitrary_take_rest(u)?, + )) + })(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryUdtTuple.with(|count| { + count.set(count.get() - 1); + }); + } + result + } + #[inline] + fn size_hint(depth: usize) -> (usize, Option) { + arbitrary::size_hint::recursion_guard(depth, |depth| { + arbitrary::size_hint::and_all( + &[ + <::Prototype as arbitrary::Arbitrary>::size_hint( + depth, + ), + < as soroban_sdk::testutils::arbitrary::SorobanArbitrary>::Prototype as arbitrary::Arbitrary>::size_hint( + depth, + ), + ], + ) + }) + } + } + }; + impl soroban_sdk::testutils::arbitrary::SorobanArbitrary for UdtTuple { + type Prototype = ArbitraryUdtTuple; + } + impl soroban_sdk::TryFromVal for UdtTuple { + type Error = soroban_sdk::ConversionError; + fn try_from_val( + env: &soroban_sdk::Env, + v: &ArbitraryUdtTuple, + ) -> std::result::Result { + Ok(UdtTuple( + soroban_sdk::IntoVal::into_val(&v.0, env), + soroban_sdk::IntoVal::into_val(&v.1, env), + )) + } + } +}; +pub struct UdtStruct { + a: i64, + b: i64, + pub c: Vec, +} +#[automatically_derived] +impl ::core::clone::Clone for UdtStruct { + #[inline] + fn clone(&self) -> UdtStruct { + UdtStruct { + a: ::core::clone::Clone::clone(&self.a), + b: ::core::clone::Clone::clone(&self.b), + c: ::core::clone::Clone::clone(&self.c), + } + } +} +#[automatically_derived] +impl ::core::fmt::Debug for UdtStruct { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_struct_field3_finish( + f, + "UdtStruct", + "a", + &self.a, + "b", + &self.b, + "c", + &&self.c, + ) + } +} +#[automatically_derived] +impl ::core::cmp::Eq for UdtStruct { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () { + let _: ::core::cmp::AssertParamIsEq; + let _: ::core::cmp::AssertParamIsEq>; + } +} +#[automatically_derived] +impl ::core::marker::StructuralPartialEq for UdtStruct {} +#[automatically_derived] +impl ::core::cmp::PartialEq for UdtStruct { + #[inline] + fn eq(&self, other: &UdtStruct) -> bool { + self.a == other.a && self.b == other.b && self.c == other.c + } +} +pub static __SPEC_XDR_TYPE_UDTSTRUCT: [u8; 84usize] = UdtStruct::spec_xdr(); +impl UdtStruct { + pub const fn spec_xdr() -> [u8; 84usize] { + *b"\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\tUdtStruct\0\0\0\0\0\0\x03\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x07\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x07\0\0\0\0\0\0\0\x01c\0\0\0\0\0\x03\xea\0\0\0\x07" + } +} +impl soroban_sdk::TryFromVal for UdtStruct { + type Error = soroban_sdk::ConversionError; + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::{ConversionError, EnvBase, MapObject, TryIntoVal, Val}; + const KEYS: [&'static str; 3usize] = ["a", "b", "c"]; + let mut vals: [Val; 3usize] = [Val::VOID.to_val(); 3usize]; + let map: MapObject = val.try_into().map_err(|_| ConversionError)?; + env.map_unpack_to_slice(map, &KEYS, &mut vals) + .map_err(|_| ConversionError)?; + Ok(Self { + a: vals[0] + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?, + b: vals[1] + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?, + c: vals[2] + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?, + }) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + fn try_from_val( + env: &soroban_sdk::Env, + val: &UdtStruct, + ) -> Result { + use soroban_sdk::{ConversionError, EnvBase, TryIntoVal, Val}; + const KEYS: [&'static str; 3usize] = ["a", "b", "c"]; + let vals: [Val; 3usize] = [ + (&val.a).try_into_val(env).map_err(|_| ConversionError)?, + (&val.b).try_into_val(env).map_err(|_| ConversionError)?, + (&val.c).try_into_val(env).map_err(|_| ConversionError)?, + ]; + Ok(env + .map_new_from_slices(&KEYS, &vals) + .map_err(|_| ConversionError)? + .into()) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&UdtStruct, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } +} +impl soroban_sdk::TryFromVal for UdtStruct { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::xdr::ScMap, + ) -> Result { + use soroban_sdk::xdr::Validate; + use soroban_sdk::TryIntoVal; + let map = val; + if map.len() != 3usize { + return Err(soroban_sdk::xdr::Error::Invalid); + } + map.validate()?; + Ok(Self { + a: { + let key: soroban_sdk::xdr::ScVal = soroban_sdk::xdr::ScSymbol( + "a".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(); + let idx = map + .binary_search_by_key(&key, |entry| entry.key.clone()) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + let rv: soroban_sdk::Val = (&map[idx].val.clone()) + .try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + rv.try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)? + }, + b: { + let key: soroban_sdk::xdr::ScVal = soroban_sdk::xdr::ScSymbol( + "b".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(); + let idx = map + .binary_search_by_key(&key, |entry| entry.key.clone()) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + let rv: soroban_sdk::Val = (&map[idx].val.clone()) + .try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + rv.try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)? + }, + c: { + let key: soroban_sdk::xdr::ScVal = soroban_sdk::xdr::ScSymbol( + "c".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(); + let idx = map + .binary_search_by_key(&key, |entry| entry.key.clone()) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + let rv: soroban_sdk::Val = (&map[idx].val.clone()) + .try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + rv.try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)? + }, + }) + } +} +impl soroban_sdk::TryFromVal for UdtStruct { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::xdr::ScVal, + ) -> Result { + if let soroban_sdk::xdr::ScVal::Map(Some(map)) = val { + <_ as soroban_sdk::TryFromVal<_, _>>::try_from_val(env, map) + } else { + Err(soroban_sdk::xdr::Error::Invalid) + } + } +} +impl TryFrom<&UdtStruct> for soroban_sdk::xdr::ScMap { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: &UdtStruct) -> Result { + extern crate alloc; + use soroban_sdk::TryFromVal; + soroban_sdk::xdr::ScMap::sorted_from(<[_]>::into_vec(::alloc::boxed::box_new([ + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "a".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(), + val: (&val.a) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + }, + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "b".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(), + val: (&val.b) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + }, + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "c".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(), + val: (&val.c) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + }, + ]))) + } +} +impl TryFrom for soroban_sdk::xdr::ScMap { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: UdtStruct) -> Result { + (&val).try_into() + } +} +impl TryFrom<&UdtStruct> for soroban_sdk::xdr::ScVal { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: &UdtStruct) -> Result { + Ok(soroban_sdk::xdr::ScVal::Map(Some(val.try_into()?))) + } +} +impl TryFrom for soroban_sdk::xdr::ScVal { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: UdtStruct) -> Result { + (&val).try_into() + } +} +const _: () = { + use soroban_sdk::testutils::arbitrary::arbitrary; + use soroban_sdk::testutils::arbitrary::std; + pub struct ArbitraryUdtStruct { + a: ::Prototype, + b: ::Prototype, + c: as soroban_sdk::testutils::arbitrary::SorobanArbitrary>::Prototype, + } + #[automatically_derived] + impl ::core::fmt::Debug for ArbitraryUdtStruct { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_struct_field3_finish( + f, + "ArbitraryUdtStruct", + "a", + &self.a, + "b", + &self.b, + "c", + &&self.c, + ) + } + } + #[automatically_derived] + impl ::core::clone::Clone for ArbitraryUdtStruct { + #[inline] + fn clone(&self) -> ArbitraryUdtStruct { + ArbitraryUdtStruct { + a: ::core::clone::Clone::clone(&self.a), + b: ::core::clone::Clone::clone(&self.b), + c: ::core::clone::Clone::clone(&self.c), + } + } + } + #[automatically_derived] + impl ::core::cmp::Eq for ArbitraryUdtStruct { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () { + let _: ::core::cmp::AssertParamIsEq< + ::Prototype, + >; + let _: ::core::cmp::AssertParamIsEq< + ::Prototype, + >; + let _: ::core::cmp::AssertParamIsEq< + as soroban_sdk::testutils::arbitrary::SorobanArbitrary>::Prototype, + >; + } + } + #[automatically_derived] + impl ::core::marker::StructuralPartialEq for ArbitraryUdtStruct {} + #[automatically_derived] + impl ::core::cmp::PartialEq for ArbitraryUdtStruct { + #[inline] + fn eq(&self, other: &ArbitraryUdtStruct) -> bool { + self.a == other.a && self.b == other.b && self.c == other.c + } + } + #[automatically_derived] + impl ::core::cmp::Ord for ArbitraryUdtStruct { + #[inline] + fn cmp(&self, other: &ArbitraryUdtStruct) -> ::core::cmp::Ordering { + match ::core::cmp::Ord::cmp(&self.a, &other.a) { + ::core::cmp::Ordering::Equal => match ::core::cmp::Ord::cmp(&self.b, &other.b) { + ::core::cmp::Ordering::Equal => ::core::cmp::Ord::cmp(&self.c, &other.c), + cmp => cmp, + }, + cmp => cmp, + } + } + } + #[automatically_derived] + impl ::core::cmp::PartialOrd for ArbitraryUdtStruct { + #[inline] + fn partial_cmp( + &self, + other: &ArbitraryUdtStruct, + ) -> ::core::option::Option<::core::cmp::Ordering> { + match ::core::cmp::PartialOrd::partial_cmp(&self.a, &other.a) { + ::core::option::Option::Some(::core::cmp::Ordering::Equal) => { + match ::core::cmp::PartialOrd::partial_cmp(&self.b, &other.b) { + ::core::option::Option::Some(::core::cmp::Ordering::Equal) => { + ::core::cmp::PartialOrd::partial_cmp(&self.c, &other.c) + } + cmp => cmp, + } + } + cmp => cmp, + } + } + } + const _: () = { + #[allow(non_upper_case_globals)] + const RECURSIVE_COUNT_ArbitraryUdtStruct: ::std::thread::LocalKey> = { + #[inline] + fn __init() -> std::cell::Cell { + std::cell::Cell::new(0) + } + unsafe { + ::std::thread::LocalKey::new( + const { + if ::std::mem::needs_drop::>() { + |init| { + #[thread_local] + static VAL: ::std::thread::local_impl::LazyStorage< + std::cell::Cell, + (), + > = ::std::thread::local_impl::LazyStorage::new(); + VAL.get_or_init(init, __init) + } + } else { + |init| { + #[thread_local] + static VAL: ::std::thread::local_impl::LazyStorage< + std::cell::Cell, + !, + > = ::std::thread::local_impl::LazyStorage::new(); + VAL.get_or_init(init, __init) + } + } + }, + ) + } + }; + #[automatically_derived] + impl<'arbitrary> arbitrary::Arbitrary<'arbitrary> for ArbitraryUdtStruct { + fn arbitrary(u: &mut arbitrary::Unstructured<'arbitrary>) -> arbitrary::Result { + let guard_against_recursion = u.is_empty(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryUdtStruct.with(|count| { + if count.get() > 0 { + return Err(arbitrary::Error::NotEnoughData); + } + count.set(count.get() + 1); + Ok(()) + })?; + } + let result = (|| { + Ok(ArbitraryUdtStruct { + a: arbitrary::Arbitrary::arbitrary(u)?, + b: arbitrary::Arbitrary::arbitrary(u)?, + c: arbitrary::Arbitrary::arbitrary(u)?, + }) + })(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryUdtStruct.with(|count| { + count.set(count.get() - 1); + }); + } + result + } + fn arbitrary_take_rest( + mut u: arbitrary::Unstructured<'arbitrary>, + ) -> arbitrary::Result { + let guard_against_recursion = u.is_empty(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryUdtStruct.with(|count| { + if count.get() > 0 { + return Err(arbitrary::Error::NotEnoughData); + } + count.set(count.get() + 1); + Ok(()) + })?; + } + let result = (|| { + Ok(ArbitraryUdtStruct { + a: arbitrary::Arbitrary::arbitrary(&mut u)?, + b: arbitrary::Arbitrary::arbitrary(&mut u)?, + c: arbitrary::Arbitrary::arbitrary_take_rest(u)?, + }) + })(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryUdtStruct.with(|count| { + count.set(count.get() - 1); + }); + } + result + } + #[inline] + fn size_hint(depth: usize) -> (usize, Option) { + arbitrary::size_hint::recursion_guard(depth, |depth| { + arbitrary::size_hint::and_all( + &[ + <::Prototype as arbitrary::Arbitrary>::size_hint( + depth, + ), + <::Prototype as arbitrary::Arbitrary>::size_hint( + depth, + ), + < as soroban_sdk::testutils::arbitrary::SorobanArbitrary>::Prototype as arbitrary::Arbitrary>::size_hint( + depth, + ), + ], + ) + }) + } + } + }; + impl soroban_sdk::testutils::arbitrary::SorobanArbitrary for UdtStruct { + type Prototype = ArbitraryUdtStruct; + } + impl soroban_sdk::TryFromVal for UdtStruct { + type Error = soroban_sdk::ConversionError; + fn try_from_val( + env: &soroban_sdk::Env, + v: &ArbitraryUdtStruct, + ) -> std::result::Result { + Ok(UdtStruct { + a: soroban_sdk::IntoVal::into_val(&v.a, env), + b: soroban_sdk::IntoVal::into_val(&v.b, env), + c: soroban_sdk::IntoVal::into_val(&v.c, env), + }) + } + } +}; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +impl Contract { + pub fn add(a: UdtEnum, b: UdtEnum) -> i64 { + let a = match a { + UdtEnum::UdtA => 0, + UdtEnum::UdtB(udt) => udt.a + udt.b, + UdtEnum::UdtC(val) => val as i64, + UdtEnum::UdtD(tup) => tup.0 + tup.1.try_iter().fold(0i64, |sum, i| sum + i.unwrap()), + }; + let b = match b { + UdtEnum::UdtA => 0, + UdtEnum::UdtB(udt) => udt.a + udt.b, + UdtEnum::UdtC(val) => val as i64, + UdtEnum::UdtD(tup) => tup.0 + tup.1.try_iter().fold(0i64, |sum, i| sum + i.unwrap()), + }; + a + b + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_ADD: [u8; 84usize] = super::Contract::spec_xdr_add(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_add() -> [u8; 84usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\x07\xd0\0\0\0\x07UdtEnum\0\0\0\0\0\0\0\0\x01b\0\0\0\0\0\x07\xd0\0\0\0\x07UdtEnum\0\0\0\0\x01\0\0\0\x07" + } +} +impl<'a> ContractClient<'a> { + pub fn add(&self, a: &UdtEnum, b: &UdtEnum) -> i64 { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_add( + &self, + a: &UdtEnum, + b: &UdtEnum, + ) -> Result< + Result>::Error>, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn add<'i>(a: &'i UdtEnum, b: &'i UdtEnum) -> (&'i UdtEnum, &'i UdtEnum) { + (a, b) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::add( + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 2usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 2usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env, args[0usize], args[1usize]) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add` instead")] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor() { + ::register( + "add", + #[allow(deprecated)] + &__Contract__add::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor() -> usize { + __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor(); + 0 + } + __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor +}; +mod test { + use super::*; + use soroban_sdk::{vec, xdr::ScVal, Bytes, Env, TryFromVal}; + extern crate test; + #[rustc_test_marker = "test::test_serializing"] + #[doc(hidden)] + pub const test_serializing: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test_serializing"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/udt/src/lib.rs", + start_line: 60usize, + start_col: 8usize, + end_line: 60usize, + end_col: 24usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_serializing()), + ), + }; + fn test_serializing() { + use soroban_sdk::xdr::ToXdr; + let e = Env::default(); + let udt = UdtStruct { + a: 10, + b: 12, + c: ::soroban_sdk::Vec::from_array(&e, [1]), + }; + let bin = udt.to_xdr(&e); + let expected_bytes = [ + 0u8, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 15, 0, 0, 0, 1, 97, 0, 0, 0, 0, 0, 0, + 6, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 15, 0, 0, 0, 1, 98, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, + 0, 0, 0, 0, 12, 0, 0, 0, 15, 0, 0, 0, 1, 99, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 1, + ]; + let expected_bytes = Bytes::from_array(&e, &expected_bytes); + match (&bin, &expected_bytes) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + } + extern crate test; + #[rustc_test_marker = "test::test_add"] + #[doc(hidden)] + pub const test_add: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test_add"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/udt/src/lib.rs", + start_line: 80usize, + start_col: 8usize, + end_line: 80usize, + end_col: 16usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_add()), + ), + }; + fn test_add() { + let e = Env::default(); + let contract_id = e.register(Contract, ()); + let client = ContractClient::new(&e, &contract_id); + let udt = UdtStruct { + a: 10, + b: 12, + c: ::soroban_sdk::Vec::from_array(&e, [1]), + }; + let z = client.add(&UdtEnum::UdtA, &UdtEnum::UdtB(udt)); + match (&z, &22) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + let udt1 = UdtEnum2::A; + let udt2 = UdtTuple(1, ::soroban_sdk::Vec::from_array(&e, [2, 3])); + let z = client.add(&UdtEnum::UdtC(udt1), &UdtEnum::UdtD(udt2)); + match (&z, &16) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + } + extern crate test; + #[rustc_test_marker = "test::test_scval_accessibility_from_udt_types"] + #[doc(hidden)] + pub const test_scval_accessibility_from_udt_types: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test_scval_accessibility_from_udt_types"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/udt/src/lib.rs", + start_line: 100usize, + start_col: 8usize, + end_line: 100usize, + end_col: 47usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_scval_accessibility_from_udt_types()), + ), + }; + fn test_scval_accessibility_from_udt_types() { + let e = Env::default(); + let udt = UdtStruct { + a: 10, + b: 12, + c: ::soroban_sdk::Vec::from_array(&e, [1]), + }; + let val: ScVal = udt.clone().try_into().unwrap(); + let roundtrip = UdtStruct::try_from_val(&e, &val).unwrap(); + match (&udt, &roundtrip) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + } +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[ + &test_add, + &test_scval_accessibility_from_udt_types, + &test_serializing, + ]) +} diff --git a/tests-expanded/test_udt_wasm32v1-none.rs b/tests-expanded/test_udt_wasm32v1-none.rs new file mode 100644 index 000000000..5dd3f78f5 --- /dev/null +++ b/tests-expanded/test_udt_wasm32v1-none.rs @@ -0,0 +1,618 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl, contracttype, Vec}; +pub enum UdtEnum2 { + A = 10, + B = 15, +} +#[automatically_derived] +impl ::core::marker::Copy for UdtEnum2 {} +#[automatically_derived] +impl ::core::clone::Clone for UdtEnum2 { + #[inline] + fn clone(&self) -> UdtEnum2 { + *self + } +} +#[automatically_derived] +impl ::core::fmt::Debug for UdtEnum2 { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::write_str( + f, + match self { + UdtEnum2::A => "A", + UdtEnum2::B => "B", + }, + ) + } +} +#[automatically_derived] +impl ::core::cmp::Eq for UdtEnum2 { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () {} +} +#[automatically_derived] +impl ::core::marker::StructuralPartialEq for UdtEnum2 {} +#[automatically_derived] +impl ::core::cmp::PartialEq for UdtEnum2 { + #[inline] + fn eq(&self, other: &UdtEnum2) -> bool { + let __self_discr = ::core::intrinsics::discriminant_value(self); + let __arg1_discr = ::core::intrinsics::discriminant_value(other); + __self_discr == __arg1_discr + } +} +#[link_section = "contractspecv0"] +pub static __SPEC_XDR_TYPE_UDTENUM2: [u8; 60usize] = UdtEnum2::spec_xdr(); +impl UdtEnum2 { + pub const fn spec_xdr() -> [u8; 60usize] { + *b"\0\0\0\x03\0\0\0\0\0\0\0\0\0\0\0\x08UdtEnum2\0\0\0\x02\0\0\0\0\0\0\0\x01A\0\0\0\0\0\0\n\0\0\0\0\0\0\0\x01B\0\0\0\0\0\0\x0f" + } +} +impl soroban_sdk::TryFromVal for UdtEnum2 { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::TryIntoVal; + let discriminant: u32 = val.try_into_val(env)?; + Ok(match discriminant { + 10u32 => Self::A, + 15u32 => Self::B, + _ => Err(soroban_sdk::ConversionError {})?, + }) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &UdtEnum2, + ) -> Result { + Ok(match val { + UdtEnum2::A => 10u32.into(), + UdtEnum2::B => 15u32.into(), + }) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&UdtEnum2, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } +} +pub enum UdtEnum { + UdtA, + UdtB(UdtStruct), + UdtC(UdtEnum2), + UdtD(UdtTuple), +} +#[automatically_derived] +impl ::core::clone::Clone for UdtEnum { + #[inline] + fn clone(&self) -> UdtEnum { + match self { + UdtEnum::UdtA => UdtEnum::UdtA, + UdtEnum::UdtB(__self_0) => UdtEnum::UdtB(::core::clone::Clone::clone(__self_0)), + UdtEnum::UdtC(__self_0) => UdtEnum::UdtC(::core::clone::Clone::clone(__self_0)), + UdtEnum::UdtD(__self_0) => UdtEnum::UdtD(::core::clone::Clone::clone(__self_0)), + } + } +} +#[automatically_derived] +impl ::core::fmt::Debug for UdtEnum { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + UdtEnum::UdtA => ::core::fmt::Formatter::write_str(f, "UdtA"), + UdtEnum::UdtB(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "UdtB", &__self_0) + } + UdtEnum::UdtC(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "UdtC", &__self_0) + } + UdtEnum::UdtD(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "UdtD", &__self_0) + } + } + } +} +#[automatically_derived] +impl ::core::cmp::Eq for UdtEnum { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () { + let _: ::core::cmp::AssertParamIsEq; + let _: ::core::cmp::AssertParamIsEq; + let _: ::core::cmp::AssertParamIsEq; + } +} +#[automatically_derived] +impl ::core::marker::StructuralPartialEq for UdtEnum {} +#[automatically_derived] +impl ::core::cmp::PartialEq for UdtEnum { + #[inline] + fn eq(&self, other: &UdtEnum) -> bool { + let __self_discr = ::core::intrinsics::discriminant_value(self); + let __arg1_discr = ::core::intrinsics::discriminant_value(other); + __self_discr == __arg1_discr + && match (self, other) { + (UdtEnum::UdtB(__self_0), UdtEnum::UdtB(__arg1_0)) => __self_0 == __arg1_0, + (UdtEnum::UdtC(__self_0), UdtEnum::UdtC(__arg1_0)) => __self_0 == __arg1_0, + (UdtEnum::UdtD(__self_0), UdtEnum::UdtD(__arg1_0)) => __self_0 == __arg1_0, + _ => true, + } + } +} +#[link_section = "contractspecv0"] +pub static __SPEC_XDR_TYPE_UDTENUM: [u8; 156usize] = UdtEnum::spec_xdr(); +impl UdtEnum { + pub const fn spec_xdr() -> [u8; 156usize] { + *b"\0\0\0\x02\0\0\0\0\0\0\0\0\0\0\0\x07UdtEnum\0\0\0\0\x04\0\0\0\0\0\0\0\0\0\0\0\x04UdtA\0\0\0\x01\0\0\0\0\0\0\0\x04UdtB\0\0\0\x01\0\0\x07\xd0\0\0\0\tUdtStruct\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\x04UdtC\0\0\0\x01\0\0\x07\xd0\0\0\0\x08UdtEnum2\0\0\0\x01\0\0\0\0\0\0\0\x04UdtD\0\0\0\x01\0\0\x07\xd0\0\0\0\x08UdtTuple" + } +} +impl soroban_sdk::TryFromVal for UdtEnum { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::{EnvBase, TryFromVal, TryIntoVal}; + const CASES: &'static [&'static str] = &["UdtA", "UdtB", "UdtC", "UdtD"]; + let vec: soroban_sdk::Vec = val.try_into_val(env)?; + let mut iter = vec.try_iter(); + let discriminant: soroban_sdk::Symbol = iter + .next() + .ok_or(soroban_sdk::ConversionError)?? + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?; + Ok( + match u32::from(env.symbol_index_in_strs(discriminant.to_symbol_val(), CASES)?) as usize + { + 0 => { + if iter.len() > 0 { + return Err(soroban_sdk::ConversionError); + } + Self::UdtA + } + 1 => { + if iter.len() > 1usize { + return Err(soroban_sdk::ConversionError); + } + Self::UdtB( + iter.next() + .ok_or(soroban_sdk::ConversionError)?? + .try_into_val(env)?, + ) + } + 2 => { + if iter.len() > 1usize { + return Err(soroban_sdk::ConversionError); + } + Self::UdtC( + iter.next() + .ok_or(soroban_sdk::ConversionError)?? + .try_into_val(env)?, + ) + } + 3 => { + if iter.len() > 1usize { + return Err(soroban_sdk::ConversionError); + } + Self::UdtD( + iter.next() + .ok_or(soroban_sdk::ConversionError)?? + .try_into_val(env)?, + ) + } + _ => Err(soroban_sdk::ConversionError {})?, + }, + ) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &UdtEnum, + ) -> Result { + use soroban_sdk::{TryFromVal, TryIntoVal}; + match val { + UdtEnum::UdtA => { + let tup: (soroban_sdk::Val,) = + (soroban_sdk::Symbol::try_from_val(env, &"UdtA")?.to_val(),); + tup.try_into_val(env).map_err(Into::into) + } + UdtEnum::UdtB(ref value0) => { + let tup: (soroban_sdk::Val, soroban_sdk::Val) = ( + soroban_sdk::Symbol::try_from_val(env, &"UdtB")?.to_val(), + value0.try_into_val(env)?, + ); + tup.try_into_val(env).map_err(Into::into) + } + UdtEnum::UdtC(ref value0) => { + let tup: (soroban_sdk::Val, soroban_sdk::Val) = ( + soroban_sdk::Symbol::try_from_val(env, &"UdtC")?.to_val(), + value0.try_into_val(env)?, + ); + tup.try_into_val(env).map_err(Into::into) + } + UdtEnum::UdtD(ref value0) => { + let tup: (soroban_sdk::Val, soroban_sdk::Val) = ( + soroban_sdk::Symbol::try_from_val(env, &"UdtD")?.to_val(), + value0.try_into_val(env)?, + ); + tup.try_into_val(env).map_err(Into::into) + } + } + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&UdtEnum, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } +} +pub struct UdtTuple(pub i64, pub Vec); +#[automatically_derived] +impl ::core::clone::Clone for UdtTuple { + #[inline] + fn clone(&self) -> UdtTuple { + UdtTuple( + ::core::clone::Clone::clone(&self.0), + ::core::clone::Clone::clone(&self.1), + ) + } +} +#[automatically_derived] +impl ::core::fmt::Debug for UdtTuple { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field2_finish(f, "UdtTuple", &self.0, &&self.1) + } +} +#[automatically_derived] +impl ::core::cmp::Eq for UdtTuple { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () { + let _: ::core::cmp::AssertParamIsEq; + let _: ::core::cmp::AssertParamIsEq>; + } +} +#[automatically_derived] +impl ::core::marker::StructuralPartialEq for UdtTuple {} +#[automatically_derived] +impl ::core::cmp::PartialEq for UdtTuple { + #[inline] + fn eq(&self, other: &UdtTuple) -> bool { + self.0 == other.0 && self.1 == other.1 + } +} +#[link_section = "contractspecv0"] +pub static __SPEC_XDR_TYPE_UDTTUPLE: [u8; 64usize] = UdtTuple::spec_xdr(); +impl UdtTuple { + pub const fn spec_xdr() -> [u8; 64usize] { + *b"\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\x08UdtTuple\0\0\0\x02\0\0\0\0\0\0\0\x010\0\0\0\0\0\0\x07\0\0\0\0\0\0\0\x011\0\0\0\0\0\x03\xea\0\0\0\x07" + } +} +impl soroban_sdk::TryFromVal for UdtTuple { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::{ConversionError, EnvBase, TryIntoVal, Val, VecObject}; + let vec: VecObject = (*val).try_into().map_err(|_| ConversionError)?; + let mut vals: [Val; 2usize] = [Val::VOID.to_val(); 2usize]; + env.vec_unpack_to_slice(vec, &mut vals) + .map_err(|_| ConversionError)?; + Ok(Self { + 0: vals[0].try_into_val(env).map_err(|_| ConversionError)?, + 1: vals[1].try_into_val(env).map_err(|_| ConversionError)?, + }) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &UdtTuple, + ) -> Result { + use soroban_sdk::{ConversionError, EnvBase, TryIntoVal, Val}; + let vals: [Val; 2usize] = [ + (&val.0).try_into_val(env).map_err(|_| ConversionError)?, + (&val.1).try_into_val(env).map_err(|_| ConversionError)?, + ]; + Ok(env + .vec_new_from_slice(&vals) + .map_err(|_| ConversionError)? + .into()) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&UdtTuple, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } +} +pub struct UdtStruct { + a: i64, + b: i64, + pub c: Vec, +} +#[automatically_derived] +impl ::core::clone::Clone for UdtStruct { + #[inline] + fn clone(&self) -> UdtStruct { + UdtStruct { + a: ::core::clone::Clone::clone(&self.a), + b: ::core::clone::Clone::clone(&self.b), + c: ::core::clone::Clone::clone(&self.c), + } + } +} +#[automatically_derived] +impl ::core::fmt::Debug for UdtStruct { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_struct_field3_finish( + f, + "UdtStruct", + "a", + &self.a, + "b", + &self.b, + "c", + &&self.c, + ) + } +} +#[automatically_derived] +impl ::core::cmp::Eq for UdtStruct { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () { + let _: ::core::cmp::AssertParamIsEq; + let _: ::core::cmp::AssertParamIsEq>; + } +} +#[automatically_derived] +impl ::core::marker::StructuralPartialEq for UdtStruct {} +#[automatically_derived] +impl ::core::cmp::PartialEq for UdtStruct { + #[inline] + fn eq(&self, other: &UdtStruct) -> bool { + self.a == other.a && self.b == other.b && self.c == other.c + } +} +#[link_section = "contractspecv0"] +pub static __SPEC_XDR_TYPE_UDTSTRUCT: [u8; 84usize] = UdtStruct::spec_xdr(); +impl UdtStruct { + pub const fn spec_xdr() -> [u8; 84usize] { + *b"\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\tUdtStruct\0\0\0\0\0\0\x03\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x07\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x07\0\0\0\0\0\0\0\x01c\0\0\0\0\0\x03\xea\0\0\0\x07" + } +} +impl soroban_sdk::TryFromVal for UdtStruct { + type Error = soroban_sdk::ConversionError; + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::{ConversionError, EnvBase, MapObject, TryIntoVal, Val}; + const KEYS: [&'static str; 3usize] = ["a", "b", "c"]; + let mut vals: [Val; 3usize] = [Val::VOID.to_val(); 3usize]; + let map: MapObject = val.try_into().map_err(|_| ConversionError)?; + env.map_unpack_to_slice(map, &KEYS, &mut vals) + .map_err(|_| ConversionError)?; + Ok(Self { + a: vals[0] + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?, + b: vals[1] + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?, + c: vals[2] + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?, + }) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + fn try_from_val( + env: &soroban_sdk::Env, + val: &UdtStruct, + ) -> Result { + use soroban_sdk::{ConversionError, EnvBase, TryIntoVal, Val}; + const KEYS: [&'static str; 3usize] = ["a", "b", "c"]; + let vals: [Val; 3usize] = [ + (&val.a).try_into_val(env).map_err(|_| ConversionError)?, + (&val.b).try_into_val(env).map_err(|_| ConversionError)?, + (&val.c).try_into_val(env).map_err(|_| ConversionError)?, + ]; + Ok(env + .map_new_from_slices(&KEYS, &vals) + .map_err(|_| ConversionError)? + .into()) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&UdtStruct, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } +} +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl Contract { + pub fn add(a: UdtEnum, b: UdtEnum) -> i64 { + let a = match a { + UdtEnum::UdtA => 0, + UdtEnum::UdtB(udt) => udt.a + udt.b, + UdtEnum::UdtC(val) => val as i64, + UdtEnum::UdtD(tup) => tup.0 + tup.1.try_iter().fold(0i64, |sum, i| sum + i.unwrap()), + }; + let b = match b { + UdtEnum::UdtA => 0, + UdtEnum::UdtB(udt) => udt.a + udt.b, + UdtEnum::UdtC(val) => val as i64, + UdtEnum::UdtD(tup) => tup.0 + tup.1.try_iter().fold(0i64, |sum, i| sum + i.unwrap()), + }; + a + b + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_ADD: [u8; 84usize] = super::Contract::spec_xdr_add(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_add() -> [u8; 84usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\x07\xd0\0\0\0\x07UdtEnum\0\0\0\0\0\0\0\0\x01b\0\0\0\0\0\x07\xd0\0\0\0\x07UdtEnum\0\0\0\0\x01\0\0\0\x07" + } +} +impl<'a> ContractClient<'a> { + pub fn add(&self, a: &UdtEnum, b: &UdtEnum) -> i64 { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + res + } + pub fn try_add( + &self, + a: &UdtEnum, + b: &UdtEnum, + ) -> Result< + Result>::Error>, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("add"); + SYMBOL + }, + ::soroban_sdk::Vec::from_array( + &self.env, + [a.into_val(&self.env), b.into_val(&self.env)], + ), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn add<'i>(a: &'i UdtEnum, b: &'i UdtEnum) -> (&'i UdtEnum, &'i UdtEnum) { + (a, b) + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__add { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add` instead")] + pub fn invoke_raw( + env: soroban_sdk::Env, + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::add( + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_0), + ), + <_ as soroban_sdk::unwrap::UnwrapOptimized>::unwrap_optimized( + <_ as soroban_sdk::TryFromValForContractFn< + soroban_sdk::Env, + soroban_sdk::Val, + >>::try_from_val_for_contract_fn(&env, &arg_1), + ), + ), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).add` instead")] + #[export_name = "add"] + pub extern "C" fn invoke_raw_extern( + arg_0: soroban_sdk::Val, + arg_1: soroban_sdk::Val, + ) -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default(), arg_0, arg_1) + } + use super::*; +} diff --git a/tests-expanded/test_workspace_contract_tests.rs b/tests-expanded/test_workspace_contract_tests.rs new file mode 100644 index 000000000..8dcc2b09d --- /dev/null +++ b/tests-expanded/test_workspace_contract_tests.rs @@ -0,0 +1,352 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl}; +use test_workspace_lib::Value; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod __contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for Contract { + fn register(name: &'static str, func: &'static __contract_fn_set_registry::F) { + __contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + __contract_fn_set_registry::call(func, env, args) + } +} +impl Contract { + pub fn value() -> Value { + return Value { value: 13 }; + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__value__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + pub static __SPEC_XDR_FN_VALUE: [u8; 44usize] = super::Contract::spec_xdr_value(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_value() -> [u8; 44usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x05value\0\0\0\0\0\0\0\0\0\0\x01\0\0\x07\xd0\0\0\0\x05Value\0\0\0" + } +} +impl<'a> ContractClient<'a> { + pub fn value(&self) -> Value { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + if self.allow_non_root_auth { + self.env.mock_all_auths_allowing_non_root_auth(); + } else { + self.env.mock_all_auths(); + } + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("value"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } + pub fn try_value( + &self, + ) -> Result< + Result< + Value, + >::Error, + >, + Result, + > { + use core::ops::Not; + let old_auth_manager = self + .env + .in_contract() + .not() + .then(|| self.env.host().snapshot_auth_manager().unwrap()); + { + if let Some(set_auths) = self.set_auths { + self.env.set_auths(set_auths); + } + if let Some(mock_auths) = self.mock_auths { + self.env.mock_auths(mock_auths); + } + if self.mock_all_auths { + self.env.mock_all_auths(); + } + } + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("value"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + if let Some(old_auth_manager) = old_auth_manager { + self.env.host().set_auth_manager(old_auth_manager).unwrap(); + } + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn value<'i>() -> () { + () + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__value { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).value` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::value(), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).value` instead")] + pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val { + if args.len() != 0usize { + { + ::core::panicking::panic_fmt(format_args!( + "invalid number of input arguments: {0} expected, got {1}", + 0usize, + args.len(), + )); + }; + } + #[allow(deprecated)] + invoke_raw(env) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).value` instead")] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; +} +#[doc(hidden)] +#[allow(non_snake_case)] +extern "C" fn __Contract__cd42404d52ad55ccfa9aca4adc828aa5800ad9d385a0671fbcbf724118320619_ctor() { + ::register( + "value", + #[allow(deprecated)] + &__Contract__value::invoke_raw_slice, + ); +} +#[used] +#[allow(non_upper_case_globals, non_snake_case)] +#[doc(hidden)] +#[link_section = "__DATA,__mod_init_func"] +static __Contract__cd42404d52ad55ccfa9aca4adc828aa5800ad9d385a0671fbcbf724118320619_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { + #[allow(non_snake_case)] + unsafe extern "C" fn __Contract__cd42404d52ad55ccfa9aca4adc828aa5800ad9d385a0671fbcbf724118320619_ctor___rust_ctor___ctor() -> usize { + __Contract__cd42404d52ad55ccfa9aca4adc828aa5800ad9d385a0671fbcbf724118320619_ctor(); + 0 + } + __Contract__cd42404d52ad55ccfa9aca4adc828aa5800ad9d385a0671fbcbf724118320619_ctor___rust_ctor___ctor +}; +mod test { + use super::*; + use soroban_sdk::Env; + extern crate test; + #[rustc_test_marker = "test::test_add"] + #[doc(hidden)] + pub const test_add: test::TestDescAndFn = test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("test::test_add"), + ignore: false, + ignore_message: ::core::option::Option::None, + source_file: "tests/workspace_contract/src/lib.rs", + start_line: 22usize, + start_col: 8usize, + end_line: 22usize, + end_col: 16usize, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::UnitTest, + }, + testfn: test::StaticTestFn( + #[coverage(off)] + || test::assert_test_result(test_add()), + ), + }; + fn test_add() { + let e = Env::default(); + let contract_id = e.register(Contract, ()); + let client = ContractClient::new(&e, &contract_id); + let z = client.value(); + match (&z, &Value { value: 13 }) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + let kind = ::core::panicking::AssertKind::Eq; + ::core::panicking::assert_failed( + kind, + &*left_val, + &*right_val, + ::core::option::Option::None, + ); + } + } + }; + } +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[&test_add]) +} diff --git a/tests-expanded/test_workspace_contract_wasm32v1-none.rs b/tests-expanded/test_workspace_contract_wasm32v1-none.rs new file mode 100644 index 000000000..f6df76f7a --- /dev/null +++ b/tests-expanded/test_workspace_contract_wasm32v1-none.rs @@ -0,0 +1,111 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::{contract, contractimpl}; +use test_workspace_lib::Value; +pub struct Contract; +///ContractArgs is a type for building arg lists for functions defined in "Contract". +pub struct ContractArgs; +///ContractClient is a client for calling the contract defined in "Contract". +pub struct ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} +impl Contract { + pub fn value() -> Value { + return Value { value: 13 }; + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__value__spec { + #[doc(hidden)] + #[allow(non_snake_case)] + #[allow(non_upper_case_globals)] + #[link_section = "contractspecv0"] + pub static __SPEC_XDR_FN_VALUE: [u8; 44usize] = super::Contract::spec_xdr_value(); +} +impl Contract { + #[allow(non_snake_case)] + pub const fn spec_xdr_value() -> [u8; 44usize] { + *b"\0\0\0\0\0\0\0\0\0\0\0\x05value\0\0\0\0\0\0\0\0\0\0\x01\0\0\x07\xd0\0\0\0\x05Value\0\0\0" + } +} +impl<'a> ContractClient<'a> { + pub fn value(&self) -> Value { + use core::ops::Not; + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("value"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + res + } + pub fn try_value( + &self, + ) -> Result< + Result< + Value, + >::Error, + >, + Result, + > { + use soroban_sdk::{FromVal, IntoVal}; + let res = self.env.try_invoke_contract( + &self.address, + &{ + #[allow(deprecated)] + const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("value"); + SYMBOL + }, + ::soroban_sdk::Vec::new(&self.env), + ); + res + } +} +impl ContractArgs { + #[inline(always)] + #[allow(clippy::unused_unit)] + pub fn value<'i>() -> () { + () + } +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub mod __Contract__value { + use super::*; + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).value` instead")] + pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val { + <_ as soroban_sdk::IntoVal>::into_val( + #[allow(deprecated)] + &::value(), + &env, + ) + } + #[deprecated(note = "use `ContractClient::new(&env, &contract_id).value` instead")] + #[export_name = "value"] + pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val { + #[allow(deprecated)] + invoke_raw(soroban_sdk::Env::default()) + } + use super::*; +} diff --git a/tests-expanded/test_workspace_lib_tests.rs b/tests-expanded/test_workspace_lib_tests.rs new file mode 100644 index 000000000..680a0c8c9 --- /dev/null +++ b/tests-expanded/test_workspace_lib_tests.rs @@ -0,0 +1,360 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::contracttype; +pub struct Value { + pub value: i32, +} +#[automatically_derived] +impl ::core::fmt::Debug for Value { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_struct_field1_finish(f, "Value", "value", &&self.value) + } +} +#[automatically_derived] +impl ::core::cmp::Eq for Value { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () { + let _: ::core::cmp::AssertParamIsEq; + } +} +#[automatically_derived] +impl ::core::marker::StructuralPartialEq for Value {} +#[automatically_derived] +impl ::core::cmp::PartialEq for Value { + #[inline] + fn eq(&self, other: &Value) -> bool { + self.value == other.value + } +} +pub static __SPEC_XDR_TYPE_VALUE: [u8; 48usize] = Value::spec_xdr(); +impl Value { + pub const fn spec_xdr() -> [u8; 48usize] { + *b"\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\x05Value\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\x05value\0\0\0\0\0\0\x05" + } +} +impl soroban_sdk::TryFromVal for Value { + type Error = soroban_sdk::ConversionError; + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::{ConversionError, EnvBase, MapObject, TryIntoVal, Val}; + const KEYS: [&'static str; 1usize] = ["value"]; + let mut vals: [Val; 1usize] = [Val::VOID.to_val(); 1usize]; + let map: MapObject = val.try_into().map_err(|_| ConversionError)?; + env.map_unpack_to_slice(map, &KEYS, &mut vals) + .map_err(|_| ConversionError)?; + Ok(Self { + value: vals[0] + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?, + }) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + fn try_from_val( + env: &soroban_sdk::Env, + val: &Value, + ) -> Result { + use soroban_sdk::{ConversionError, EnvBase, TryIntoVal, Val}; + const KEYS: [&'static str; 1usize] = ["value"]; + let vals: [Val; 1usize] = [(&val.value) + .try_into_val(env) + .map_err(|_| ConversionError)?]; + Ok(env + .map_new_from_slices(&KEYS, &vals) + .map_err(|_| ConversionError)? + .into()) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&Value, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } +} +impl soroban_sdk::TryFromVal for Value { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::xdr::ScMap, + ) -> Result { + use soroban_sdk::xdr::Validate; + use soroban_sdk::TryIntoVal; + let map = val; + if map.len() != 1usize { + return Err(soroban_sdk::xdr::Error::Invalid); + } + map.validate()?; + Ok(Self { + value: { + let key: soroban_sdk::xdr::ScVal = soroban_sdk::xdr::ScSymbol( + "value" + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(); + let idx = map + .binary_search_by_key(&key, |entry| entry.key.clone()) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + let rv: soroban_sdk::Val = (&map[idx].val.clone()) + .try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?; + rv.try_into_val(env) + .map_err(|_| soroban_sdk::xdr::Error::Invalid)? + }, + }) + } +} +impl soroban_sdk::TryFromVal for Value { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::xdr::ScVal, + ) -> Result { + if let soroban_sdk::xdr::ScVal::Map(Some(map)) = val { + <_ as soroban_sdk::TryFromVal<_, _>>::try_from_val(env, map) + } else { + Err(soroban_sdk::xdr::Error::Invalid) + } + } +} +impl TryFrom<&Value> for soroban_sdk::xdr::ScMap { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: &Value) -> Result { + extern crate alloc; + use soroban_sdk::TryFromVal; + soroban_sdk::xdr::ScMap::sorted_from(<[_]>::into_vec(::alloc::boxed::box_new([ + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "value" + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(), + val: (&val.value) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + }, + ]))) + } +} +impl TryFrom for soroban_sdk::xdr::ScMap { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: Value) -> Result { + (&val).try_into() + } +} +impl TryFrom<&Value> for soroban_sdk::xdr::ScVal { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: &Value) -> Result { + Ok(soroban_sdk::xdr::ScVal::Map(Some(val.try_into()?))) + } +} +impl TryFrom for soroban_sdk::xdr::ScVal { + type Error = soroban_sdk::xdr::Error; + #[inline(always)] + fn try_from(val: Value) -> Result { + (&val).try_into() + } +} +const _: () = { + use soroban_sdk::testutils::arbitrary::arbitrary; + use soroban_sdk::testutils::arbitrary::std; + pub struct ArbitraryValue { + value: ::Prototype, + } + #[automatically_derived] + impl ::core::fmt::Debug for ArbitraryValue { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_struct_field1_finish( + f, + "ArbitraryValue", + "value", + &&self.value, + ) + } + } + #[automatically_derived] + impl ::core::clone::Clone for ArbitraryValue { + #[inline] + fn clone(&self) -> ArbitraryValue { + ArbitraryValue { + value: ::core::clone::Clone::clone(&self.value), + } + } + } + #[automatically_derived] + impl ::core::cmp::Eq for ArbitraryValue { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () { + let _: ::core::cmp::AssertParamIsEq< + ::Prototype, + >; + } + } + #[automatically_derived] + impl ::core::marker::StructuralPartialEq for ArbitraryValue {} + #[automatically_derived] + impl ::core::cmp::PartialEq for ArbitraryValue { + #[inline] + fn eq(&self, other: &ArbitraryValue) -> bool { + self.value == other.value + } + } + #[automatically_derived] + impl ::core::cmp::Ord for ArbitraryValue { + #[inline] + fn cmp(&self, other: &ArbitraryValue) -> ::core::cmp::Ordering { + ::core::cmp::Ord::cmp(&self.value, &other.value) + } + } + #[automatically_derived] + impl ::core::cmp::PartialOrd for ArbitraryValue { + #[inline] + fn partial_cmp( + &self, + other: &ArbitraryValue, + ) -> ::core::option::Option<::core::cmp::Ordering> { + ::core::cmp::PartialOrd::partial_cmp(&self.value, &other.value) + } + } + const _: () = { + #[allow(non_upper_case_globals)] + const RECURSIVE_COUNT_ArbitraryValue: ::std::thread::LocalKey> = { + #[inline] + fn __init() -> std::cell::Cell { + std::cell::Cell::new(0) + } + unsafe { + ::std::thread::LocalKey::new( + const { + if ::std::mem::needs_drop::>() { + |init| { + #[thread_local] + static VAL: ::std::thread::local_impl::LazyStorage< + std::cell::Cell, + (), + > = ::std::thread::local_impl::LazyStorage::new(); + VAL.get_or_init(init, __init) + } + } else { + |init| { + #[thread_local] + static VAL: ::std::thread::local_impl::LazyStorage< + std::cell::Cell, + !, + > = ::std::thread::local_impl::LazyStorage::new(); + VAL.get_or_init(init, __init) + } + } + }, + ) + } + }; + #[automatically_derived] + impl<'arbitrary> arbitrary::Arbitrary<'arbitrary> for ArbitraryValue { + fn arbitrary(u: &mut arbitrary::Unstructured<'arbitrary>) -> arbitrary::Result { + let guard_against_recursion = u.is_empty(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryValue.with(|count| { + if count.get() > 0 { + return Err(arbitrary::Error::NotEnoughData); + } + count.set(count.get() + 1); + Ok(()) + })?; + } + let result = (|| { + Ok(ArbitraryValue { + value: arbitrary::Arbitrary::arbitrary(u)?, + }) + })(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryValue.with(|count| { + count.set(count.get() - 1); + }); + } + result + } + fn arbitrary_take_rest( + mut u: arbitrary::Unstructured<'arbitrary>, + ) -> arbitrary::Result { + let guard_against_recursion = u.is_empty(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryValue.with(|count| { + if count.get() > 0 { + return Err(arbitrary::Error::NotEnoughData); + } + count.set(count.get() + 1); + Ok(()) + })?; + } + let result = (|| { + Ok(ArbitraryValue { + value: arbitrary::Arbitrary::arbitrary_take_rest(u)?, + }) + })(); + if guard_against_recursion { + RECURSIVE_COUNT_ArbitraryValue.with(|count| { + count.set(count.get() - 1); + }); + } + result + } + #[inline] + fn size_hint(depth: usize) -> (usize, Option) { + arbitrary::size_hint::recursion_guard(depth, |depth| { + arbitrary::size_hint::and_all( + &[ + <::Prototype as arbitrary::Arbitrary>::size_hint( + depth, + ), + ], + ) + }) + } + } + }; + impl soroban_sdk::testutils::arbitrary::SorobanArbitrary for Value { + type Prototype = ArbitraryValue; + } + impl soroban_sdk::TryFromVal for Value { + type Error = soroban_sdk::ConversionError; + fn try_from_val( + env: &soroban_sdk::Env, + v: &ArbitraryValue, + ) -> std::result::Result { + Ok(Value { + value: soroban_sdk::IntoVal::into_val(&v.value, env), + }) + } + } +}; +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[]) +} diff --git a/tests-expanded/test_zero_tests.rs b/tests-expanded/test_zero_tests.rs new file mode 100644 index 000000000..6c2443a14 --- /dev/null +++ b/tests-expanded/test_zero_tests.rs @@ -0,0 +1,145 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::contract; +struct _Contract; +///_ContractArgs is a type for building arg lists for functions defined in "_Contract". +pub struct _ContractArgs; +///_ContractClient is a client for calling the contract defined in "_Contract". +pub struct _ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + set_auths: Option<&'a [soroban_sdk::xdr::SorobanAuthorizationEntry]>, + #[doc(hidden)] + mock_auths: Option<&'a [soroban_sdk::testutils::MockAuth<'a>]>, + #[doc(hidden)] + mock_all_auths: bool, + #[doc(hidden)] + allow_non_root_auth: bool, +} +impl<'a> _ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Set authorizations in the environment which will be consumed by + /// contracts when they invoke `Address::require_auth` or + /// `Address::require_auth_for_args` functions. + /// + /// Requires valid signatures for the authorization to be successful. + /// To mock auth without requiring valid signatures, use `mock_auths`. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn set_auths(&self, auths: &'a [soroban_sdk::xdr::SorobanAuthorizationEntry]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: Some(auths), + mock_auths: self.mock_auths.clone(), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock authorizations in the environment which will cause matching invokes + /// of `Address::require_auth` and `Address::require_auth_for_args` to + /// pass. + /// + /// See `soroban_sdk::Env::set_auths` for more details and examples. + pub fn mock_auths(&self, mock_auths: &'a [soroban_sdk::testutils::MockAuth<'a>]) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: self.set_auths.clone(), + mock_auths: Some(mock_auths), + mock_all_auths: false, + allow_non_root_auth: false, + } + } + /// Mock all calls to the `Address::require_auth` and + /// `Address::require_auth_for_args` functions in invoked contracts, + /// having them succeed as if authorization was provided. + /// + /// See `soroban_sdk::Env::mock_all_auths` for more details and + /// examples. + pub fn mock_all_auths(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: false, + } + } + /// A version of `mock_all_auths` that allows authorizations that + /// are not present in the root invocation. + /// + /// Refer to `mock_all_auths` documentation for details and + /// prefer using `mock_all_auths` unless non-root authorization is + /// required. + /// + /// See `soroban_sdk::Env::mock_all_auths_allowing_non_root_auth` + /// for more details and examples. + pub fn mock_all_auths_allowing_non_root_auth(&self) -> Self { + Self { + env: self.env.clone(), + address: self.address.clone(), + set_auths: None, + mock_auths: None, + mock_all_auths: true, + allow_non_root_auth: true, + } + } +} +mod ___contract_fn_set_registry { + use super::*; + extern crate std; + use std::collections::BTreeMap; + use std::sync::Mutex; + pub type F = soroban_sdk::testutils::ContractFunctionF; + static FUNCS: Mutex> = Mutex::new(BTreeMap::new()); + pub fn register(name: &'static str, func: &'static F) { + FUNCS.lock().unwrap().insert(name, func); + } + pub fn call( + name: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + let fopt: Option<&'static F> = FUNCS.lock().unwrap().get(name).map(|f| f.clone()); + fopt.map(|f| f(env, args)) + } +} +impl soroban_sdk::testutils::ContractFunctionRegister for _Contract { + fn register(name: &'static str, func: &'static ___contract_fn_set_registry::F) { + ___contract_fn_set_registry::register(name, func); + } +} +#[doc(hidden)] +impl soroban_sdk::testutils::ContractFunctionSet for _Contract { + fn call( + &self, + func: &str, + env: soroban_sdk::Env, + args: &[soroban_sdk::Val], + ) -> Option { + ___contract_fn_set_registry::call(func, env, args) + } +} +#[rustc_main] +#[coverage(off)] +#[doc(hidden)] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[]) +} diff --git a/tests-expanded/test_zero_wasm32v1-none.rs b/tests-expanded/test_zero_wasm32v1-none.rs new file mode 100644 index 000000000..4fdd0f007 --- /dev/null +++ b/tests-expanded/test_zero_wasm32v1-none.rs @@ -0,0 +1,26 @@ +#![feature(prelude_import)] +#![no_std] +#[macro_use] +extern crate core; +#[prelude_import] +use core::prelude::rust_2021::*; +use soroban_sdk::contract; +struct _Contract; +///_ContractArgs is a type for building arg lists for functions defined in "_Contract". +pub struct _ContractArgs; +///_ContractClient is a client for calling the contract defined in "_Contract". +pub struct _ContractClient<'a> { + pub env: soroban_sdk::Env, + pub address: soroban_sdk::Address, + #[doc(hidden)] + _phantom: core::marker::PhantomData<&'a ()>, +} +impl<'a> _ContractClient<'a> { + pub fn new(env: &soroban_sdk::Env, address: &soroban_sdk::Address) -> Self { + Self { + env: env.clone(), + address: address.clone(), + _phantom: core::marker::PhantomData, + } + } +} From 942cdf779d152992f3135208af127a11858da183 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Fri, 26 Sep 2025 17:02:26 +1000 Subject: [PATCH 02/24] rename expand workflow to expand-tests --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 0f3638878..f1ae05591 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -18,7 +18,7 @@ jobs: complete: if: always() - needs: [fmt, check-git-rev-deps, semver-checks, build-and-test, build-fuzz, docs, readme, migration-docs, expand] + needs: [fmt, check-git-rev-deps, semver-checks, build-and-test, build-fuzz, docs, readme, migration-docs, expand-tests] runs-on: ubuntu-latest steps: - if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') From 0ab915bbbfb19201d06e8bd88bc057a3cfefdadd Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Sat, 27 Sep 2025 17:54:49 +1000 Subject: [PATCH 03/24] update cargo-expand version to 1.0.116 --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index f1ae05591..e0da998b4 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -186,7 +186,7 @@ jobs: - uses: stellar/actions/rust-cache@main - run: rustup update - run: rustup target add wasm32v1-none - - uses: stellar/binaries@v42 + - uses: stellar/binaries@v44 with: name: cargo-expand version: 1.0.116 From e980a00333e89ab42ee6c762a1258f6ada622080 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Sat, 27 Sep 2025 17:55:49 +1000 Subject: [PATCH 04/24] update stellar binaries to v41 and cargo-semver-checks to v0.44 --- .github/workflows/rust.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e0da998b4..497f42972 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -57,10 +57,10 @@ jobs: steps: - uses: actions/checkout@v3 - run: rustup update - - uses: stellar/binaries@v40 + - uses: stellar/binaries@v41 with: name: cargo-semver-checks - version: 0.42.0 + version: 0.44.0 - run: > cargo semver-checks --exclude soroban-token-spec From cf19bf2f23ea092ae4ddc41473b3968528ddc63c Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Sat, 27 Sep 2025 23:42:51 +1000 Subject: [PATCH 05/24] always expand with the linux target --- Makefile | 2 +- tests-expanded/test_account_tests.rs | 3 ++- tests-expanded/test_add_i128_tests.rs | 3 ++- tests-expanded/test_add_u128_tests.rs | 3 ++- tests-expanded/test_add_u64_tests.rs | 3 ++- tests-expanded/test_alloc_tests.rs | 3 ++- tests-expanded/test_auth_tests.rs | 18 ++++++++++++------ tests-expanded/test_bls_tests.rs | 3 ++- tests-expanded/test_constructor_tests.rs | 3 ++- tests-expanded/test_contract_data_tests.rs | 3 ++- tests-expanded/test_empty2_tests.rs | 3 ++- tests-expanded/test_empty_tests.rs | 3 ++- tests-expanded/test_errors_tests.rs | 3 ++- tests-expanded/test_events_tests.rs | 3 ++- tests-expanded/test_fuzz_tests.rs | 3 ++- tests-expanded/test_import_contract_tests.rs | 3 ++- tests-expanded/test_invoke_contract_tests.rs | 6 ++++-- tests-expanded/test_logging_tests.rs | 3 ++- tests-expanded/test_macros_tests.rs | 3 ++- tests-expanded/test_modular_tests.rs | 9 ++++++--- tests-expanded/test_multiimpl_tests.rs | 9 ++++++--- tests-expanded/test_udt_tests.rs | 3 ++- .../test_workspace_contract_tests.rs | 3 ++- 23 files changed, 65 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index dacbea09e..e93cdfe61 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ expand-tests: mkdir -p tests-expanded cargo metadata --format-version 1 | jq -r '.packages[] | select(.manifest_path | contains("/tests/")) | "\(.name) \(.manifest_path | split("/") | .[:-1] | join("/")) \(any(.targets[]; any(.kind[]; . == "cdylib")))"' | while read package dir is_cdylib; do \ echo "Expanding $$package for host target including tests"; \ - cargo expand --package $$package --tests | rustfmt > tests-expanded/$${package}_tests.rs; \ + cargo expand --package $$package --tests --target x86_64-unknown-linux-gnu | rustfmt > tests-expanded/$${package}_tests.rs; \ if [ "$$is_cdylib" = "true" ]; then \ echo "Expanding $$package for wasm32v1-none target without tests"; \ cargo expand --package $$package --release --target wasm32v1-none | rustfmt > tests-expanded/$${package}_wasm32v1-none.rs; \ diff --git a/tests-expanded/test_account_tests.rs b/tests-expanded/test_account_tests.rs index 66d0283f9..de7e9e307 100644 --- a/tests-expanded/test_account_tests.rs +++ b/tests-expanded/test_account_tests.rs @@ -410,9 +410,10 @@ extern "C" fn __Contract_CustomAccountInterface_d465b6861ce11142d9f64c1622e1ad88 #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract_CustomAccountInterface_d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract_CustomAccountInterface_d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor() -> usize { __Contract_CustomAccountInterface_d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor(); 0 diff --git a/tests-expanded/test_add_i128_tests.rs b/tests-expanded/test_add_i128_tests.rs index 618094b27..7c3ecc0a8 100644 --- a/tests-expanded/test_add_i128_tests.rs +++ b/tests-expanded/test_add_i128_tests.rs @@ -312,9 +312,10 @@ extern "C" fn __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46 #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor() -> usize { __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor(); 0 diff --git a/tests-expanded/test_add_u128_tests.rs b/tests-expanded/test_add_u128_tests.rs index 72447bcc9..6beb11068 100644 --- a/tests-expanded/test_add_u128_tests.rs +++ b/tests-expanded/test_add_u128_tests.rs @@ -312,9 +312,10 @@ extern "C" fn __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46 #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor() -> usize { __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor(); 0 diff --git a/tests-expanded/test_add_u64_tests.rs b/tests-expanded/test_add_u64_tests.rs index 8385950c2..aa945dc57 100644 --- a/tests-expanded/test_add_u64_tests.rs +++ b/tests-expanded/test_add_u64_tests.rs @@ -312,9 +312,10 @@ extern "C" fn __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46 #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor() -> usize { __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor(); 0 diff --git a/tests-expanded/test_alloc_tests.rs b/tests-expanded/test_alloc_tests.rs index 2527f7208..e5bda0006 100644 --- a/tests-expanded/test_alloc_tests.rs +++ b/tests-expanded/test_alloc_tests.rs @@ -306,9 +306,10 @@ extern "C" fn __Contract__526e07cb9219443e6b3ef052e7872bf9e5bfee9b91633ed921601b #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__526e07cb9219443e6b3ef052e7872bf9e5bfee9b91633ed921601b5e93014bb7_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__526e07cb9219443e6b3ef052e7872bf9e5bfee9b91633ed921601b5e93014bb7_ctor___rust_ctor___ctor() -> usize { __Contract__526e07cb9219443e6b3ef052e7872bf9e5bfee9b91633ed921601b5e93014bb7_ctor(); 0 diff --git a/tests-expanded/test_auth_tests.rs b/tests-expanded/test_auth_tests.rs index cdd23c585..022745827 100644 --- a/tests-expanded/test_auth_tests.rs +++ b/tests-expanded/test_auth_tests.rs @@ -293,9 +293,10 @@ extern "C" fn __ContractA__7c3764b58a7ababbe8a6b452f6a400d8ae3704b80f8c5ea1b251e #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __ContractA__7c3764b58a7ababbe8a6b452f6a400d8ae3704b80f8c5ea1b251eebbc8698020_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __ContractA__7c3764b58a7ababbe8a6b452f6a400d8ae3704b80f8c5ea1b251eebbc8698020_ctor___rust_ctor___ctor() -> usize { __ContractA__7c3764b58a7ababbe8a6b452f6a400d8ae3704b80f8c5ea1b251eebbc8698020_ctor(); 0 @@ -902,9 +903,10 @@ mod test_a { #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] - #[link_section = "__DATA,__mod_init_func"] + #[link_section = ".init_array"] static __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor() -> usize { __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor(); 0 @@ -1342,9 +1344,10 @@ mod test_a { #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] - #[link_section = "__DATA,__mod_init_func"] + #[link_section = ".init_array"] static __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor() -> usize { __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor(); 0 @@ -1663,9 +1666,10 @@ extern "C" fn __ContractB__389cfcb1cb10680376b4cd5cf632e6b11c3e59494c10e1d42514f #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __ContractB__389cfcb1cb10680376b4cd5cf632e6b11c3e59494c10e1d42514faf6c4c21b84_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __ContractB__389cfcb1cb10680376b4cd5cf632e6b11c3e59494c10e1d42514faf6c4c21b84_ctor___rust_ctor___ctor() -> usize { __ContractB__389cfcb1cb10680376b4cd5cf632e6b11c3e59494c10e1d42514faf6c4c21b84_ctor(); 0 @@ -2367,9 +2371,10 @@ mod test_b { #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] - #[link_section = "__DATA,__mod_init_func"] + #[link_section = ".init_array"] static __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor() -> usize { __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor(); 0 @@ -2807,9 +2812,10 @@ mod test_b { #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] - #[link_section = "__DATA,__mod_init_func"] + #[link_section = ".init_array"] static __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor() -> usize { __Contract__d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor(); 0 diff --git a/tests-expanded/test_bls_tests.rs b/tests-expanded/test_bls_tests.rs index aa3ae89a1..cb8ead6bb 100644 --- a/tests-expanded/test_bls_tests.rs +++ b/tests-expanded/test_bls_tests.rs @@ -1196,9 +1196,10 @@ extern "C" fn __Contract__492d85ed5a5d2cb14995f41e785b3df9c7fcf4af92b6d50ce2c9fa #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__492d85ed5a5d2cb14995f41e785b3df9c7fcf4af92b6d50ce2c9fa7c9b1e350d_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__492d85ed5a5d2cb14995f41e785b3df9c7fcf4af92b6d50ce2c9fa7c9b1e350d_ctor___rust_ctor___ctor() -> usize { __Contract__492d85ed5a5d2cb14995f41e785b3df9c7fcf4af92b6d50ce2c9fa7c9b1e350d_ctor(); 0 diff --git a/tests-expanded/test_constructor_tests.rs b/tests-expanded/test_constructor_tests.rs index 130b38ad6..e967d9153 100644 --- a/tests-expanded/test_constructor_tests.rs +++ b/tests-expanded/test_constructor_tests.rs @@ -936,9 +936,10 @@ extern "C" fn __Contract__99dc7227b32e52c8d11ead5dec3dd80bafdad62d74493e7341c782 #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__99dc7227b32e52c8d11ead5dec3dd80bafdad62d74493e7341c782fd8cb13593_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__99dc7227b32e52c8d11ead5dec3dd80bafdad62d74493e7341c782fd8cb13593_ctor___rust_ctor___ctor() -> usize { __Contract__99dc7227b32e52c8d11ead5dec3dd80bafdad62d74493e7341c782fd8cb13593_ctor(); 0 diff --git a/tests-expanded/test_contract_data_tests.rs b/tests-expanded/test_contract_data_tests.rs index a0a67a4e4..5ec29ef8c 100644 --- a/tests-expanded/test_contract_data_tests.rs +++ b/tests-expanded/test_contract_data_tests.rs @@ -604,9 +604,10 @@ extern "C" fn __Contract__0e764744b384ee8739a8810d2509da0f2e8c1cbf45b7a6de3d6972 #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__0e764744b384ee8739a8810d2509da0f2e8c1cbf45b7a6de3d69726f824c2c8c_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__0e764744b384ee8739a8810d2509da0f2e8c1cbf45b7a6de3d69726f824c2c8c_ctor___rust_ctor___ctor() -> usize { __Contract__0e764744b384ee8739a8810d2509da0f2e8c1cbf45b7a6de3d69726f824c2c8c_ctor(); 0 diff --git a/tests-expanded/test_empty2_tests.rs b/tests-expanded/test_empty2_tests.rs index f0d96cd31..c1e410399 100644 --- a/tests-expanded/test_empty2_tests.rs +++ b/tests-expanded/test_empty2_tests.rs @@ -145,9 +145,10 @@ extern "C" fn __Contract__e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca49599 #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_ctor___rust_ctor___ctor() -> usize { __Contract__e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_ctor(); 0 diff --git a/tests-expanded/test_empty_tests.rs b/tests-expanded/test_empty_tests.rs index f83301bdf..5236a8110 100644 --- a/tests-expanded/test_empty_tests.rs +++ b/tests-expanded/test_empty_tests.rs @@ -282,9 +282,10 @@ extern "C" fn __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor___rust_ctor___ctor() -> usize { __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor(); 0 diff --git a/tests-expanded/test_errors_tests.rs b/tests-expanded/test_errors_tests.rs index 2927ac72c..5fa081641 100644 --- a/tests-expanded/test_errors_tests.rs +++ b/tests-expanded/test_errors_tests.rs @@ -940,9 +940,10 @@ extern "C" fn __Contract__dc66cfa30fdb08b17ba29ed3da0a0be599deef8db57bfb9cd9b3dc #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__dc66cfa30fdb08b17ba29ed3da0a0be599deef8db57bfb9cd9b3dcbf8c3be498_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__dc66cfa30fdb08b17ba29ed3da0a0be599deef8db57bfb9cd9b3dcbf8c3be498_ctor___rust_ctor___ctor() -> usize { __Contract__dc66cfa30fdb08b17ba29ed3da0a0be599deef8db57bfb9cd9b3dcbf8c3be498_ctor(); 0 diff --git a/tests-expanded/test_events_tests.rs b/tests-expanded/test_events_tests.rs index 22d05751c..38991c925 100644 --- a/tests-expanded/test_events_tests.rs +++ b/tests-expanded/test_events_tests.rs @@ -574,9 +574,10 @@ extern "C" fn __Contract__a60968eb9ff75bf813738a9007ab5bbea9f174011ab4092819ed57 #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__a60968eb9ff75bf813738a9007ab5bbea9f174011ab4092819ed57e87eb6b301_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__a60968eb9ff75bf813738a9007ab5bbea9f174011ab4092819ed57e87eb6b301_ctor___rust_ctor___ctor() -> usize { __Contract__a60968eb9ff75bf813738a9007ab5bbea9f174011ab4092819ed57e87eb6b301_ctor(); 0 diff --git a/tests-expanded/test_fuzz_tests.rs b/tests-expanded/test_fuzz_tests.rs index a4a5c839d..1b01a802c 100644 --- a/tests-expanded/test_fuzz_tests.rs +++ b/tests-expanded/test_fuzz_tests.rs @@ -316,9 +316,10 @@ extern "C" fn __Contract__acba25512100f80b56fc3ccd14c65be55d94800cda77585c5f41a8 #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__acba25512100f80b56fc3ccd14c65be55d94800cda77585c5f41a887e398f9be_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__acba25512100f80b56fc3ccd14c65be55d94800cda77585c5f41a887e398f9be_ctor___rust_ctor___ctor() -> usize { __Contract__acba25512100f80b56fc3ccd14c65be55d94800cda77585c5f41a887e398f9be_ctor(); 0 diff --git a/tests-expanded/test_import_contract_tests.rs b/tests-expanded/test_import_contract_tests.rs index b684afb3c..c3713d43d 100644 --- a/tests-expanded/test_import_contract_tests.rs +++ b/tests-expanded/test_import_contract_tests.rs @@ -530,9 +530,10 @@ extern "C" fn __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e8 #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e85117ee9756_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e85117ee9756_ctor___rust_ctor___ctor() -> usize { __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e85117ee9756_ctor(); 0 diff --git a/tests-expanded/test_invoke_contract_tests.rs b/tests-expanded/test_invoke_contract_tests.rs index 7212e0df8..c1c1d8239 100644 --- a/tests-expanded/test_invoke_contract_tests.rs +++ b/tests-expanded/test_invoke_contract_tests.rs @@ -342,9 +342,10 @@ extern "C" fn __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e8 #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e85117ee9756_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e85117ee9756_ctor___rust_ctor___ctor() -> usize { __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e85117ee9756_ctor(); 0 @@ -660,9 +661,10 @@ extern "C" fn __AddContract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cf #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __AddContract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __AddContract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor() -> usize { __AddContract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor(); 0 diff --git a/tests-expanded/test_logging_tests.rs b/tests-expanded/test_logging_tests.rs index c72e81a42..0d91c718c 100644 --- a/tests-expanded/test_logging_tests.rs +++ b/tests-expanded/test_logging_tests.rs @@ -365,9 +365,10 @@ extern "C" fn __Contract__2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e730433 #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824_ctor___rust_ctor___ctor() -> usize { __Contract__2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824_ctor(); 0 diff --git a/tests-expanded/test_macros_tests.rs b/tests-expanded/test_macros_tests.rs index 27bbd2bb1..c7faa9f8c 100644 --- a/tests-expanded/test_macros_tests.rs +++ b/tests-expanded/test_macros_tests.rs @@ -283,9 +283,10 @@ extern "C" fn __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor___rust_ctor___ctor() -> usize { __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor(); 0 diff --git a/tests-expanded/test_modular_tests.rs b/tests-expanded/test_modular_tests.rs index 64afde849..22a8c2241 100644 --- a/tests-expanded/test_modular_tests.rs +++ b/tests-expanded/test_modular_tests.rs @@ -165,9 +165,10 @@ mod feat1 { #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] - #[link_section = "__DATA,__mod_init_func"] + #[link_section = ".init_array"] static __Contract__7692c3ad3540bb803c020b3aee66cd8887123234ea0c6e7143c0add73ff431ed_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__7692c3ad3540bb803c020b3aee66cd8887123234ea0c6e7143c0add73ff431ed_ctor___rust_ctor___ctor() -> usize { __Contract__7692c3ad3540bb803c020b3aee66cd8887123234ea0c6e7143c0add73ff431ed_ctor(); 0 @@ -334,9 +335,10 @@ mod feat2 { #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] - #[link_section = "__DATA,__mod_init_func"] + #[link_section = ".init_array"] static __super__Contract__3fc4ccfe745870e2c0d99f71f30ff0656c8dedd41cc1d7d3d376b0dbe685e2f3_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __super__Contract__3fc4ccfe745870e2c0d99f71f30ff0656c8dedd41cc1d7d3d376b0dbe685e2f3_ctor___rust_ctor___ctor() -> usize { __super__Contract__3fc4ccfe745870e2c0d99f71f30ff0656c8dedd41cc1d7d3d376b0dbe685e2f3_ctor(); 0 @@ -694,9 +696,10 @@ extern "C" fn __Contract__f9194e73f9e9459e3450ea10a179cdf77aafa695beecd3b9344a98 #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__f9194e73f9e9459e3450ea10a179cdf77aafa695beecd3b9344a98d111622243_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__f9194e73f9e9459e3450ea10a179cdf77aafa695beecd3b9344a98d111622243_ctor___rust_ctor___ctor() -> usize { __Contract__f9194e73f9e9459e3450ea10a179cdf77aafa695beecd3b9344a98d111622243_ctor(); 0 diff --git a/tests-expanded/test_multiimpl_tests.rs b/tests-expanded/test_multiimpl_tests.rs index 576de882b..6d767e266 100644 --- a/tests-expanded/test_multiimpl_tests.rs +++ b/tests-expanded/test_multiimpl_tests.rs @@ -282,9 +282,10 @@ extern "C" fn __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor___rust_ctor___ctor() -> usize { __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor(); 0 @@ -437,9 +438,10 @@ extern "C" fn __Contract__a081c9c13231c3c184333e4fde14f4f10e045d30869e1b800f4338 #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__a081c9c13231c3c184333e4fde14f4f10e045d30869e1b800f4338ab8a726ca4_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__a081c9c13231c3c184333e4fde14f4f10e045d30869e1b800f4338ab8a726ca4_ctor___rust_ctor___ctor() -> usize { __Contract__a081c9c13231c3c184333e4fde14f4f10e045d30869e1b800f4338ab8a726ca4_ctor(); 0 @@ -597,9 +599,10 @@ extern "C" fn __Contract_Trait_2be3aa1100044a64e8135c570a7b382cebaca742493cf17b7 #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract_Trait_2be3aa1100044a64e8135c570a7b382cebaca742493cf17b77052a7ae50fa889_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract_Trait_2be3aa1100044a64e8135c570a7b382cebaca742493cf17b77052a7ae50fa889_ctor___rust_ctor___ctor() -> usize { __Contract_Trait_2be3aa1100044a64e8135c570a7b382cebaca742493cf17b77052a7ae50fa889_ctor(); 0 diff --git a/tests-expanded/test_udt_tests.rs b/tests-expanded/test_udt_tests.rs index 023854081..ff6bbef27 100644 --- a/tests-expanded/test_udt_tests.rs +++ b/tests-expanded/test_udt_tests.rs @@ -2121,9 +2121,10 @@ extern "C" fn __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46 #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor() -> usize { __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor(); 0 diff --git a/tests-expanded/test_workspace_contract_tests.rs b/tests-expanded/test_workspace_contract_tests.rs index 8dcc2b09d..8df3686f7 100644 --- a/tests-expanded/test_workspace_contract_tests.rs +++ b/tests-expanded/test_workspace_contract_tests.rs @@ -288,9 +288,10 @@ extern "C" fn __Contract__cd42404d52ad55ccfa9aca4adc828aa5800ad9d385a0671fbcbf72 #[used] #[allow(non_upper_case_globals, non_snake_case)] #[doc(hidden)] -#[link_section = "__DATA,__mod_init_func"] +#[link_section = ".init_array"] static __Contract__cd42404d52ad55ccfa9aca4adc828aa5800ad9d385a0671fbcbf724118320619_ctor___rust_ctor___ctor: unsafe extern "C" fn() -> usize = { #[allow(non_snake_case)] + #[link_section = ".text.startup"] unsafe extern "C" fn __Contract__cd42404d52ad55ccfa9aca4adc828aa5800ad9d385a0671fbcbf724118320619_ctor___rust_ctor___ctor() -> usize { __Contract__cd42404d52ad55ccfa9aca4adc828aa5800ad9d385a0671fbcbf724118320619_ctor(); 0 From 026434c3bcafaebb26295375607ea2eb8eec2715 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Sat, 27 Sep 2025 23:57:34 +1000 Subject: [PATCH 06/24] make wasms build before expand so that wasm files are available to import --- Makefile | 2 +- tests-expanded/test_alloc_tests.rs | 2 +- tests-expanded/test_import_contract_tests.rs | 2 +- tests-expanded/test_import_contract_wasm32v1-none.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index e93cdfe61..32d12b2e2 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ readme: # Expands the generated code within each test vector contract that lives in the # tests/ directory. Serves to surface visible changes in generated code that # may not be obvious when making changes to sdk macros. -expand-tests: +expand-tests: build rm -fr tests-expanded mkdir -p tests-expanded cargo metadata --format-version 1 | jq -r '.packages[] | select(.manifest_path | contains("/tests/")) | "\(.name) \(.manifest_path | split("/") | .[:-1] | join("/")) \(any(.targets[]; any(.kind[]; . == "cdylib")))"' | while read package dir is_cdylib; do \ diff --git a/tests-expanded/test_alloc_tests.rs b/tests-expanded/test_alloc_tests.rs index e5bda0006..f76a8538f 100644 --- a/tests-expanded/test_alloc_tests.rs +++ b/tests-expanded/test_alloc_tests.rs @@ -320,7 +320,7 @@ mod test { use crate::{Contract, ContractClient}; use soroban_sdk::{testutils::EnvTestConfig, vec, Env}; mod imported { - pub const WASM: &[u8] = b"\0asm\x01\0\0\0\x01#\x07`\0\x01~`\x02~~\x01~`\x01\x7f\0`\0\0`\x01\x7f\x01\x7f`\x01~\x01~`\x03\x7f\x7f\x7f\x01\x7f\x02\r\x02\x01v\x01_\0\0\x01v\x016\0\x01\x03\r\x0c\x02\x03\x04\x03\x02\x05\x02\x02\x03\x03\x06\x06\x04\x05\x01p\x01\x01\x01\x05\x03\x01\0\x11\x06!\x04\x7f\x01A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x88\x80\xc0\0\x0b\x7f\0A\x90\x80\xc0\0\x0b\x074\x05\x06memory\x02\0\x08num_list\0\x07\x01_\x03\x01\n__data_end\x03\x02\x0b__heap_base\x03\x03\n\xf9\r\x0c\xab\x02\x01\x06\x7f\x02@\x02@ \0(\x02\0\"\x01A\x01tA\x01 \x01\x1b\"\x02A\xff\xff\xff\xff\x03K\r\0 \x02A\x04 \x02A\x04K\x1b\"\x03A\x02t\"\x04A\xfd\xff\xff\xff\x07O\r\0\x02@\x02@ \x01E\r\0 \0(\x02\x04!\x05\x10\x83\x80\x80\x80\0A\0(\x02\x80\x80\xc0\x80\0\"\x02A\x03j\"\x06 \x02I\r\x02\x02@\x02@ \x06A|q\"\x02 \x04j\"\x06A\0(\x02\x84\x80\xc0\x80\0M\r\0 \x04\x10\x84\x80\x80\x80\0!\x02\x0c\x01\x0bA\0 \x066\x02\x80\x80\xc0\x80\0\x0b \x02E\r\x03 \x02 \x05 \x01A\x02t\x10\x8d\x80\x80\x80\0\x1a\x0c\x01\x0b\x10\x83\x80\x80\x80\0A\0(\x02\x80\x80\xc0\x80\0\"\x02A\x03j\"\x01 \x02I\r\x01\x02@\x02@ \x01A|q\"\x02 \x04j\"\x01A\0(\x02\x84\x80\xc0\x80\0M\r\0 \x04\x10\x84\x80\x80\x80\0!\x02\x0c\x01\x0bA\0 \x016\x02\x80\x80\xc0\x80\0\x0b \x02E\r\x02\x0b \0 \x036\x02\0 \0 \x026\x02\x04\x0f\x0b\x10\x85\x80\x80\x80\0\0\x0b \x04\x10\x86\x80\x80\x80\0\0\x0bC\x01\x01\x7f\x02@\x02@A\0(\x02\x84\x80\xc0\x80\0\r\0?\0\"\0A\xff\xff\x03K\r\x01A\0 \0A\x10t\"\06\x02\x84\x80\xc0\x80\0A\0 \06\x02\x80\x80\xc0\x80\0\x0b\x0f\x0b\x10\x85\x80\x80\x80\0\0\x0b\x91\x01\x01\x04\x7f \0A\xff\xff\x03j\"\x01A\x80\x80|q!\x02 \x01A\x10v!\x03\x02@\x02@\x03@ \x03@\0A\x7fF\r\x01A\0A\0(\x02\x84\x80\xc0\x80\0 \x02j6\x02\x84\x80\xc0\x80\0\x10\x83\x80\x80\x80\0A\0(\x02\x80\x80\xc0\x80\0\"\x01A\x03j\"\x04 \x01I\r\x02 \x04A|q\"\x01 \0j\"\x04A\0(\x02\x84\x80\xc0\x80\0K\r\0\x0bA\0 \x046\x02\x80\x80\xc0\x80\0 \x01\x0f\x0b\x10\x8b\x80\x80\x80\0\0\x0b\x10\x85\x80\x80\x80\0\0\x0b\t\0\x10\x8a\x80\x80\x80\0\0\x0b\x0b\0 \0\x10\x88\x80\x80\x80\0\0\x0b\xee\x01\x01\x05\x7f#\x80\x80\x80\x80\0A\x10k\"\x01$\x80\x80\x80\x80\0\x02@ \0B\xff\x01\x83B\x04R\r\0 \0B \x88\xa7!\x02A\0!\x03 \x01A\06\x02\x0c \x01B\x80\x80\x80\x80\xc0\07\x02\x04A\x04!\x04A\0!\x05\x02@\x03@ \x02 \x05F\r\x01\x02@ \x05 \x01(\x02\x04G\r\0 \x01A\x04j\x10\x82\x80\x80\x80\0 \x01(\x02\x08!\x04\x0b \x04 \x03j \x056\x02\0 \x01 \x05A\x01j\"\x056\x02\x0c \x03A\x04j!\x03 \x05!\x05\x0c\0\x0b\x0b \x02A\x02t!\x05\x10\x80\x80\x80\x80\0!\0 \x01(\x02\x08!\x03\x02@\x03@ \x05E\r\x01 \x05A|j!\x05 \0 \x035\x02\0B \x86B\x04\x84\x10\x81\x80\x80\x80\0!\0 \x03A\x04j!\x03\x0c\0\x0b\x0b \x01A\x10j$\x80\x80\x80\x80\0 \0\x0f\x0b\0\x0b\x0b\0 \0\x10\x89\x80\x80\x80\0\0\x0b\t\0\x10\x8a\x80\x80\x80\0\0\x0b\x03\0\0\x0b\t\0\x10\x85\x80\x80\x80\0\0\x0b\xb9\x07\x01\x0c\x7f#\x80\x80\x80\x80\0A\x10k!\x03\x02@\x02@ \x02A\x10O\r\0 \0!\x04\x0c\x01\x0b\x02@ \0 \0A\0 \0kA\x03q\"\x05j\"\x06O\r\0 \x05A\x7fj!\x07 \0!\x04 \x01!\x08\x02@ \x05E\r\0 \x05!\t \0!\x04 \x01!\x08\x03@ \x04 \x08-\0\0:\0\0 \x08A\x01j!\x08 \x04A\x01j!\x04 \tA\x7fj\"\t\r\0\x0b\x0b \x07A\x07I\r\0\x03@ \x04 \x08-\0\0:\0\0 \x04A\x01j \x08A\x01j-\0\0:\0\0 \x04A\x02j \x08A\x02j-\0\0:\0\0 \x04A\x03j \x08A\x03j-\0\0:\0\0 \x04A\x04j \x08A\x04j-\0\0:\0\0 \x04A\x05j \x08A\x05j-\0\0:\0\0 \x04A\x06j \x08A\x06j-\0\0:\0\0 \x04A\x07j \x08A\x07j-\0\0:\0\0 \x08A\x08j!\x08 \x04A\x08j\"\x04 \x06G\r\0\x0b\x0b \x06 \x02 \x05k\"\tA|q\"\x07j!\x04\x02@\x02@ \x01 \x05j\"\x08A\x03q\"\x01\r\0 \x06 \x04O\r\x01 \x08!\x01\x03@ \x06 \x01(\x02\06\x02\0 \x01A\x04j!\x01 \x06A\x04j\"\x06 \x04I\r\0\x0c\x02\x0b\x0bA\0!\x02 \x03A\06\x02\x0c \x03A\x0cj \x01r!\x05\x02@A\x04 \x01k\"\nA\x01qE\r\0 \x05 \x08-\0\0:\0\0A\x01!\x02\x0b\x02@ \nA\x02qE\r\0 \x05 \x02j \x08 \x02j/\x01\0;\x01\0\x0b \x08 \x01k!\x02 \x01A\x03t!\x0b \x03(\x02\x0c!\x05\x02@\x02@ \x06A\x04j \x04I\r\0 \x06!\x0c\x0c\x01\x0bA\0 \x0bkA\x18q!\r\x03@ \x06 \x05 \x0bv \x02A\x04j\"\x02(\x02\0\"\x05 \rtr6\x02\0 \x06A\x08j!\n \x06A\x04j\"\x0c!\x06 \n \x04I\r\0\x0b\x0bA\0!\x06 \x03A\0:\0\x08 \x03A\0:\0\x06\x02@\x02@ \x01A\x01G\r\0 \x03A\x08j!\rA\0!\x01A\0!\nA\0!\x0e\x0c\x01\x0b \x02A\x05j-\0\0!\n \x03 \x02A\x04j-\0\0\"\x01:\0\x08 \nA\x08t!\nA\x02!\x0e \x03A\x06j!\r\x0b\x02@ \x08A\x01qE\r\0 \r \x02A\x04j \x0ej-\0\0:\0\0 \x03-\0\x06A\x10t!\x06 \x03-\0\x08!\x01\x0b \x0c \n \x06r \x01A\xff\x01qrA\0 \x0bkA\x18qt \x05 \x0bvr6\x02\0\x0b \tA\x03q!\x02 \x08 \x07j!\x01\x0b\x02@ \x04 \x04 \x02j\"\x06O\r\0 \x02A\x7fj!\t\x02@ \x02A\x07q\"\x08E\r\0\x03@ \x04 \x01-\0\0:\0\0 \x01A\x01j!\x01 \x04A\x01j!\x04 \x08A\x7fj\"\x08\r\0\x0b\x0b \tA\x07I\r\0\x03@ \x04 \x01-\0\0:\0\0 \x04A\x01j \x01A\x01j-\0\0:\0\0 \x04A\x02j \x01A\x02j-\0\0:\0\0 \x04A\x03j \x01A\x03j-\0\0:\0\0 \x04A\x04j \x01A\x04j-\0\0:\0\0 \x04A\x05j \x01A\x05j-\0\0:\0\0 \x04A\x06j \x01A\x06j-\0\0:\0\0 \x04A\x07j \x01A\x07j-\0\0:\0\0 \x01A\x08j!\x01 \x04A\x08j\"\x04 \x06G\r\0\x0b\x0b \0\x0b\x0e\0 \0 \x01 \x02\x10\x8c\x80\x80\x80\0\x0b\x0b\t\x01\0A\x80\x80\xc0\0\x0b\0\0G\x0econtractspecv0\0\0\0\0\0\0\0\0\0\0\0\x08num_list\0\0\0\x01\0\0\0\0\0\0\0\x05count\0\0\0\0\0\0\x04\0\0\0\x01\0\0\x03\xea\0\0\0\x04\0\x1e\x11contractenvmetav0\0\0\0\0\0\0\0\x17\0\0\0\0\0w\x0econtractmetav0\0\0\0\0\0\0\0\x05rsver\0\0\0\0\0\0\x061.89.0\0\0\0\0\0\0\0\0\0\x08rssdkver\0\0\0523.0.2#07757a358c22c45669af2bf51500ae83c33f9a26-dirty\0\0\0"; + pub const WASM: &[u8] = b"\0asm\x01\0\0\0\x01#\x07`\0\x01~`\x02~~\x01~`\x01\x7f\0`\0\0`\x01\x7f\x01\x7f`\x01~\x01~`\x03\x7f\x7f\x7f\x01\x7f\x02\r\x02\x01v\x01_\0\0\x01v\x016\0\x01\x03\r\x0c\x02\x03\x04\x03\x02\x05\x02\x02\x03\x03\x06\x06\x04\x05\x01p\x01\x01\x01\x05\x03\x01\0\x11\x06!\x04\x7f\x01A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x88\x80\xc0\0\x0b\x7f\0A\x90\x80\xc0\0\x0b\x074\x05\x06memory\x02\0\x08num_list\0\x07\x01_\x03\x01\n__data_end\x03\x02\x0b__heap_base\x03\x03\n\xf9\r\x0c\xab\x02\x01\x06\x7f\x02@\x02@ \0(\x02\0\"\x01A\x01tA\x01 \x01\x1b\"\x02A\xff\xff\xff\xff\x03K\r\0 \x02A\x04 \x02A\x04K\x1b\"\x03A\x02t\"\x04A\xfd\xff\xff\xff\x07O\r\0\x02@\x02@ \x01E\r\0 \0(\x02\x04!\x05\x10\x83\x80\x80\x80\0A\0(\x02\x80\x80\xc0\x80\0\"\x02A\x03j\"\x06 \x02I\r\x02\x02@\x02@ \x06A|q\"\x02 \x04j\"\x06A\0(\x02\x84\x80\xc0\x80\0M\r\0 \x04\x10\x84\x80\x80\x80\0!\x02\x0c\x01\x0bA\0 \x066\x02\x80\x80\xc0\x80\0\x0b \x02E\r\x03 \x02 \x05 \x01A\x02t\x10\x8d\x80\x80\x80\0\x1a\x0c\x01\x0b\x10\x83\x80\x80\x80\0A\0(\x02\x80\x80\xc0\x80\0\"\x01A\x03j\"\x02 \x01I\r\x01\x02@\x02@ \x02A|q\"\x02 \x04j\"\x01A\0(\x02\x84\x80\xc0\x80\0M\r\0 \x04\x10\x84\x80\x80\x80\0!\x02\x0c\x01\x0bA\0 \x016\x02\x80\x80\xc0\x80\0\x0b \x02E\r\x02\x0b \0 \x036\x02\0 \0 \x026\x02\x04\x0f\x0b\x10\x85\x80\x80\x80\0\0\x0b \x04\x10\x86\x80\x80\x80\0\0\x0bC\x01\x01\x7f\x02@\x02@A\0(\x02\x84\x80\xc0\x80\0\r\0?\0\"\0A\xff\xff\x03K\r\x01A\0 \0A\x10t\"\06\x02\x84\x80\xc0\x80\0A\0 \06\x02\x80\x80\xc0\x80\0\x0b\x0f\x0b\x10\x85\x80\x80\x80\0\0\x0b\x91\x01\x01\x04\x7f \0A\xff\xff\x03j\"\x01A\x80\x80|q!\x02 \x01A\x10v!\x03\x02@\x02@\x03@ \x03@\0A\x7fF\r\x01A\0A\0(\x02\x84\x80\xc0\x80\0 \x02j6\x02\x84\x80\xc0\x80\0\x10\x83\x80\x80\x80\0A\0(\x02\x80\x80\xc0\x80\0\"\x01A\x03j\"\x04 \x01I\r\x02 \x04A|q\"\x01 \0j\"\x04A\0(\x02\x84\x80\xc0\x80\0K\r\0\x0bA\0 \x046\x02\x80\x80\xc0\x80\0 \x01\x0f\x0b\x10\x8b\x80\x80\x80\0\0\x0b\x10\x85\x80\x80\x80\0\0\x0b\t\0\x10\x8a\x80\x80\x80\0\0\x0b\x0b\0 \0\x10\x88\x80\x80\x80\0\0\x0b\xee\x01\x01\x05\x7f#\x80\x80\x80\x80\0A\x10k\"\x01$\x80\x80\x80\x80\0\x02@ \0B\xff\x01\x83B\x04R\r\0 \0B \x88\xa7!\x02A\0!\x03 \x01A\06\x02\x0c \x01B\x80\x80\x80\x80\xc0\07\x02\x04A\x04!\x04A\0!\x05\x02@\x03@ \x02 \x05F\r\x01\x02@ \x05 \x01(\x02\x04G\r\0 \x01A\x04j\x10\x82\x80\x80\x80\0 \x01(\x02\x08!\x04\x0b \x04 \x03j \x056\x02\0 \x01 \x05A\x01j\"\x056\x02\x0c \x03A\x04j!\x03 \x05!\x05\x0c\0\x0b\x0b \x02A\x02t!\x05\x10\x80\x80\x80\x80\0!\0 \x01(\x02\x08!\x03\x02@\x03@ \x05E\r\x01 \x05A|j!\x05 \0 \x035\x02\0B \x86B\x04\x84\x10\x81\x80\x80\x80\0!\0 \x03A\x04j!\x03\x0c\0\x0b\x0b \x01A\x10j$\x80\x80\x80\x80\0 \0\x0f\x0b\0\x0b\x0b\0 \0\x10\x89\x80\x80\x80\0\0\x0b\t\0\x10\x8a\x80\x80\x80\0\0\x0b\x03\0\0\x0b\t\0\x10\x85\x80\x80\x80\0\0\x0b\xb9\x07\x01\x0c\x7f#\x80\x80\x80\x80\0A\x10k!\x03\x02@\x02@ \x02A\x10O\r\0 \0!\x04\x0c\x01\x0b\x02@ \0 \0A\0 \0kA\x03q\"\x05j\"\x06O\r\0 \x05A\x7fj!\x07 \0!\x04 \x01!\x08\x02@ \x05E\r\0 \x05!\t \0!\x04 \x01!\x08\x03@ \x04 \x08-\0\0:\0\0 \x08A\x01j!\x08 \x04A\x01j!\x04 \tA\x7fj\"\t\r\0\x0b\x0b \x07A\x07I\r\0\x03@ \x04 \x08-\0\0:\0\0 \x04A\x01j \x08A\x01j-\0\0:\0\0 \x04A\x02j \x08A\x02j-\0\0:\0\0 \x04A\x03j \x08A\x03j-\0\0:\0\0 \x04A\x04j \x08A\x04j-\0\0:\0\0 \x04A\x05j \x08A\x05j-\0\0:\0\0 \x04A\x06j \x08A\x06j-\0\0:\0\0 \x04A\x07j \x08A\x07j-\0\0:\0\0 \x08A\x08j!\x08 \x04A\x08j\"\x04 \x06G\r\0\x0b\x0b \x06 \x02 \x05k\"\tA|q\"\x07j!\x04\x02@\x02@ \x01 \x05j\"\x08A\x03q\"\x01\r\0 \x06 \x04O\r\x01 \x08!\x01\x03@ \x06 \x01(\x02\06\x02\0 \x01A\x04j!\x01 \x06A\x04j\"\x06 \x04I\r\0\x0c\x02\x0b\x0bA\0!\x02 \x03A\06\x02\x0c \x03A\x0cj \x01r!\x05\x02@A\x04 \x01k\"\nA\x01qE\r\0 \x05 \x08-\0\0:\0\0A\x01!\x02\x0b\x02@ \nA\x02qE\r\0 \x05 \x02j \x08 \x02j/\x01\0;\x01\0\x0b \x08 \x01k!\x02 \x01A\x03t!\x0b \x03(\x02\x0c!\x05\x02@\x02@ \x06A\x04j \x04I\r\0 \x06!\x0c\x0c\x01\x0bA\0 \x0bkA\x18q!\r\x03@ \x06 \x05 \x0bv \x02A\x04j\"\x02(\x02\0\"\x05 \rtr6\x02\0 \x06A\x08j!\n \x06A\x04j\"\x0c!\x06 \n \x04I\r\0\x0b\x0bA\0!\x06 \x03A\0:\0\x08 \x03A\0:\0\x06\x02@\x02@ \x01A\x01G\r\0 \x03A\x08j!\rA\0!\x01A\0!\nA\0!\x0e\x0c\x01\x0b \x02A\x05j-\0\0!\n \x03 \x02A\x04j-\0\0\"\x01:\0\x08 \nA\x08t!\nA\x02!\x0e \x03A\x06j!\r\x0b\x02@ \x08A\x01qE\r\0 \r \x02A\x04j \x0ej-\0\0:\0\0 \x03-\0\x06A\x10t!\x06 \x03-\0\x08!\x01\x0b \x0c \n \x06r \x01A\xff\x01qrA\0 \x0bkA\x18qt \x05 \x0bvr6\x02\0\x0b \tA\x03q!\x02 \x08 \x07j!\x01\x0b\x02@ \x04 \x04 \x02j\"\x06O\r\0 \x02A\x7fj!\t\x02@ \x02A\x07q\"\x08E\r\0\x03@ \x04 \x01-\0\0:\0\0 \x01A\x01j!\x01 \x04A\x01j!\x04 \x08A\x7fj\"\x08\r\0\x0b\x0b \tA\x07I\r\0\x03@ \x04 \x01-\0\0:\0\0 \x04A\x01j \x01A\x01j-\0\0:\0\0 \x04A\x02j \x01A\x02j-\0\0:\0\0 \x04A\x03j \x01A\x03j-\0\0:\0\0 \x04A\x04j \x01A\x04j-\0\0:\0\0 \x04A\x05j \x01A\x05j-\0\0:\0\0 \x04A\x06j \x01A\x06j-\0\0:\0\0 \x04A\x07j \x01A\x07j-\0\0:\0\0 \x01A\x08j!\x01 \x04A\x08j\"\x04 \x06G\r\0\x0b\x0b \0\x0b\x0e\0 \0 \x01 \x02\x10\x8c\x80\x80\x80\0\x0b\x0b\t\x01\0A\x80\x80\xc0\0\x0b\0\0G\x0econtractspecv0\0\0\0\0\0\0\0\0\0\0\0\x08num_list\0\0\0\x01\0\0\0\0\0\0\0\x05count\0\0\0\0\0\0\x04\0\0\0\x01\0\0\x03\xea\0\0\0\x04\0\x1e\x11contractenvmetav0\0\0\0\0\0\0\0\x17\0\0\0\0\0w\x0econtractmetav0\0\0\0\0\0\0\0\x05rsver\0\0\0\0\0\0\x061.90.0\0\0\0\0\0\0\0\0\0\x08rssdkver\0\0\0523.0.2#cf19bf2f23ea092ae4ddc41473b3968528ddc63c-dirty\0\0\0"; pub trait Contract { fn num_list(env: soroban_sdk::Env, count: u32) -> soroban_sdk::Vec; } diff --git a/tests-expanded/test_import_contract_tests.rs b/tests-expanded/test_import_contract_tests.rs index c3713d43d..d4ee30c46 100644 --- a/tests-expanded/test_import_contract_tests.rs +++ b/tests-expanded/test_import_contract_tests.rs @@ -6,7 +6,7 @@ extern crate core; use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl, Address, Env}; mod addcontract { - pub const WASM: &[u8] = b"\0asm\x01\0\0\0\x01\x14\x04`\x01~\x01~`\x02\x7f~\0`\x02~~\x01~`\0\0\x02\r\x02\x01i\x010\0\0\x01i\x01_\0\0\x03\x05\x04\x01\x02\x03\x03\x05\x03\x01\0\x10\x06!\x04\x7f\x01A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x07/\x05\x06memory\x02\0\x03add\0\x03\x01_\x03\x01\n__data_end\x03\x02\x0b__heap_base\x03\x03\n\x89\x02\x04]\x02\x01\x7f\x01~\x02@\x02@ \x01\xa7A\xff\x01q\"\x02A\xc0\0F\r\0\x02@ \x02A\x06F\r\0B\x01!\x03B\x83\x90\x80\x80\x80\x01!\x01\x0c\x02\x0b \x01B\x08\x88!\x01B\0!\x03\x0c\x01\x0bB\0!\x03 \x01\x10\x80\x80\x80\x80\0!\x01\x0b \0 \x037\x03\0 \0 \x017\x03\x08\x0b\x9a\x01\x01\x01\x7f#\x80\x80\x80\x80\0A\x10k\"\x02$\x80\x80\x80\x80\0 \x02 \0\x10\x82\x80\x80\x80\0\x02@\x02@ \x02(\x02\0A\x01F\r\0 \x02)\x03\x08!\0 \x02 \x01\x10\x82\x80\x80\x80\0 \x02(\x02\0A\x01F\r\0 \0 \x02)\x03\x08|\"\x01 \0T\r\x01\x02@\x02@ \x01B\xff\xff\xff\xff\xff\xff\xff\xff\0V\r\0 \x01B\x08\x86B\x06\x84!\0\x0c\x01\x0b \x01\x10\x81\x80\x80\x80\0!\0\x0b \x02A\x10j$\x80\x80\x80\x80\0 \0\x0f\x0b\0\x0b\x10\x84\x80\x80\x80\0\0\x0b\t\0\x10\x85\x80\x80\x80\0\0\x0b\x03\0\0\x0b\x0b\t\x01\0A\x80\x80\xc0\0\x0b\0\0K\x0econtractspecv0\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x06\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x06\0\0\0\x01\0\0\0\x06\0\x1e\x11contractenvmetav0\0\0\0\0\0\0\0\x17\0\0\0\0\0w\x0econtractmetav0\0\0\0\0\0\0\0\x05rsver\0\0\0\0\0\0\x061.89.0\0\0\0\0\0\0\0\0\0\x08rssdkver\0\0\0523.0.2#07757a358c22c45669af2bf51500ae83c33f9a26-dirty\0\0\0"; + pub const WASM: &[u8] = b"\0asm\x01\0\0\0\x01\x14\x04`\x01~\x01~`\x02\x7f~\0`\x02~~\x01~`\0\0\x02\r\x02\x01i\x010\0\0\x01i\x01_\0\0\x03\x05\x04\x01\x02\x03\x03\x05\x03\x01\0\x10\x06!\x04\x7f\x01A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x07/\x05\x06memory\x02\0\x03add\0\x03\x01_\x03\x01\n__data_end\x03\x02\x0b__heap_base\x03\x03\n\x89\x02\x04]\x02\x01\x7f\x01~\x02@\x02@ \x01\xa7A\xff\x01q\"\x02A\xc0\0F\r\0\x02@ \x02A\x06F\r\0B\x01!\x03B\x83\x90\x80\x80\x80\x01!\x01\x0c\x02\x0b \x01B\x08\x88!\x01B\0!\x03\x0c\x01\x0bB\0!\x03 \x01\x10\x80\x80\x80\x80\0!\x01\x0b \0 \x037\x03\0 \0 \x017\x03\x08\x0b\x9a\x01\x01\x01\x7f#\x80\x80\x80\x80\0A\x10k\"\x02$\x80\x80\x80\x80\0 \x02 \0\x10\x82\x80\x80\x80\0\x02@\x02@ \x02(\x02\0A\x01F\r\0 \x02)\x03\x08!\0 \x02 \x01\x10\x82\x80\x80\x80\0 \x02(\x02\0A\x01F\r\0 \0 \x02)\x03\x08|\"\x01 \0T\r\x01\x02@\x02@ \x01B\xff\xff\xff\xff\xff\xff\xff\xff\0V\r\0 \x01B\x08\x86B\x06\x84!\0\x0c\x01\x0b \x01\x10\x81\x80\x80\x80\0!\0\x0b \x02A\x10j$\x80\x80\x80\x80\0 \0\x0f\x0b\0\x0b\x10\x84\x80\x80\x80\0\0\x0b\t\0\x10\x85\x80\x80\x80\0\0\x0b\x03\0\0\x0b\x0b\t\x01\0A\x80\x80\xc0\0\x0b\0\0K\x0econtractspecv0\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x06\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x06\0\0\0\x01\0\0\0\x06\0\x1e\x11contractenvmetav0\0\0\0\0\0\0\0\x17\0\0\0\0\0w\x0econtractmetav0\0\0\0\0\0\0\0\x05rsver\0\0\0\0\0\0\x061.90.0\0\0\0\0\0\0\0\0\0\x08rssdkver\0\0\0523.0.2#cf19bf2f23ea092ae4ddc41473b3968528ddc63c-dirty\0\0\0"; pub trait Contract { fn add(env: soroban_sdk::Env, a: u64, b: u64) -> u64; } diff --git a/tests-expanded/test_import_contract_wasm32v1-none.rs b/tests-expanded/test_import_contract_wasm32v1-none.rs index 86487a5e0..c1b2d2619 100644 --- a/tests-expanded/test_import_contract_wasm32v1-none.rs +++ b/tests-expanded/test_import_contract_wasm32v1-none.rs @@ -6,7 +6,7 @@ extern crate core; use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl, Address, Env}; mod addcontract { - pub const WASM: &[u8] = b"\0asm\x01\0\0\0\x01\x14\x04`\x01~\x01~`\x02\x7f~\0`\x02~~\x01~`\0\0\x02\r\x02\x01i\x010\0\0\x01i\x01_\0\0\x03\x05\x04\x01\x02\x03\x03\x05\x03\x01\0\x10\x06!\x04\x7f\x01A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x07/\x05\x06memory\x02\0\x03add\0\x03\x01_\x03\x01\n__data_end\x03\x02\x0b__heap_base\x03\x03\n\x89\x02\x04]\x02\x01\x7f\x01~\x02@\x02@ \x01\xa7A\xff\x01q\"\x02A\xc0\0F\r\0\x02@ \x02A\x06F\r\0B\x01!\x03B\x83\x90\x80\x80\x80\x01!\x01\x0c\x02\x0b \x01B\x08\x88!\x01B\0!\x03\x0c\x01\x0bB\0!\x03 \x01\x10\x80\x80\x80\x80\0!\x01\x0b \0 \x037\x03\0 \0 \x017\x03\x08\x0b\x9a\x01\x01\x01\x7f#\x80\x80\x80\x80\0A\x10k\"\x02$\x80\x80\x80\x80\0 \x02 \0\x10\x82\x80\x80\x80\0\x02@\x02@ \x02(\x02\0A\x01F\r\0 \x02)\x03\x08!\0 \x02 \x01\x10\x82\x80\x80\x80\0 \x02(\x02\0A\x01F\r\0 \0 \x02)\x03\x08|\"\x01 \0T\r\x01\x02@\x02@ \x01B\xff\xff\xff\xff\xff\xff\xff\xff\0V\r\0 \x01B\x08\x86B\x06\x84!\0\x0c\x01\x0b \x01\x10\x81\x80\x80\x80\0!\0\x0b \x02A\x10j$\x80\x80\x80\x80\0 \0\x0f\x0b\0\x0b\x10\x84\x80\x80\x80\0\0\x0b\t\0\x10\x85\x80\x80\x80\0\0\x0b\x03\0\0\x0b\x0b\t\x01\0A\x80\x80\xc0\0\x0b\0\0K\x0econtractspecv0\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x06\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x06\0\0\0\x01\0\0\0\x06\0\x1e\x11contractenvmetav0\0\0\0\0\0\0\0\x17\0\0\0\0\0w\x0econtractmetav0\0\0\0\0\0\0\0\x05rsver\0\0\0\0\0\0\x061.89.0\0\0\0\0\0\0\0\0\0\x08rssdkver\0\0\0523.0.2#07757a358c22c45669af2bf51500ae83c33f9a26-dirty\0\0\0"; + pub const WASM: &[u8] = b"\0asm\x01\0\0\0\x01\x14\x04`\x01~\x01~`\x02\x7f~\0`\x02~~\x01~`\0\0\x02\r\x02\x01i\x010\0\0\x01i\x01_\0\0\x03\x05\x04\x01\x02\x03\x03\x05\x03\x01\0\x10\x06!\x04\x7f\x01A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x07/\x05\x06memory\x02\0\x03add\0\x03\x01_\x03\x01\n__data_end\x03\x02\x0b__heap_base\x03\x03\n\x89\x02\x04]\x02\x01\x7f\x01~\x02@\x02@ \x01\xa7A\xff\x01q\"\x02A\xc0\0F\r\0\x02@ \x02A\x06F\r\0B\x01!\x03B\x83\x90\x80\x80\x80\x01!\x01\x0c\x02\x0b \x01B\x08\x88!\x01B\0!\x03\x0c\x01\x0bB\0!\x03 \x01\x10\x80\x80\x80\x80\0!\x01\x0b \0 \x037\x03\0 \0 \x017\x03\x08\x0b\x9a\x01\x01\x01\x7f#\x80\x80\x80\x80\0A\x10k\"\x02$\x80\x80\x80\x80\0 \x02 \0\x10\x82\x80\x80\x80\0\x02@\x02@ \x02(\x02\0A\x01F\r\0 \x02)\x03\x08!\0 \x02 \x01\x10\x82\x80\x80\x80\0 \x02(\x02\0A\x01F\r\0 \0 \x02)\x03\x08|\"\x01 \0T\r\x01\x02@\x02@ \x01B\xff\xff\xff\xff\xff\xff\xff\xff\0V\r\0 \x01B\x08\x86B\x06\x84!\0\x0c\x01\x0b \x01\x10\x81\x80\x80\x80\0!\0\x0b \x02A\x10j$\x80\x80\x80\x80\0 \0\x0f\x0b\0\x0b\x10\x84\x80\x80\x80\0\0\x0b\t\0\x10\x85\x80\x80\x80\0\0\x0b\x03\0\0\x0b\x0b\t\x01\0A\x80\x80\xc0\0\x0b\0\0K\x0econtractspecv0\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x06\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x06\0\0\0\x01\0\0\0\x06\0\x1e\x11contractenvmetav0\0\0\0\0\0\0\0\x17\0\0\0\0\0w\x0econtractmetav0\0\0\0\0\0\0\0\x05rsver\0\0\0\0\0\0\x061.90.0\0\0\0\0\0\0\0\0\0\x08rssdkver\0\0\0523.0.2#cf19bf2f23ea092ae4ddc41473b3968528ddc63c-dirty\0\0\0"; pub trait Contract { fn add(env: soroban_sdk::Env, a: u64, b: u64) -> u64; } From d79d9ec376442a43f0ae4662f3a795fd152822e1 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Sat, 27 Sep 2025 23:59:15 +1000 Subject: [PATCH 07/24] add cargo-hack binary dependency --- .github/workflows/rust.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 497f42972..c0cff77ac 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -186,6 +186,10 @@ jobs: - uses: stellar/actions/rust-cache@main - run: rustup update - run: rustup target add wasm32v1-none + - uses: stellar/binaries@v37 + with: + name: cargo-hack + version: 0.5.28 - uses: stellar/binaries@v44 with: name: cargo-expand From 24ffc6f19e48634c9c0f912f7d1f5b18ccae99b7 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 30 Sep 2025 13:28:29 +1000 Subject: [PATCH 08/24] upd --- .github/workflows/rust.yml | 4 +- Makefile | 11 +- tests-expanded/proc_macros_tests.rs | 33 ---- tests-expanded/test_account_tests.rs | 7 +- tests-expanded/test_account_wasm32v1-none.rs | 5 +- tests-expanded/test_add_i128_tests.rs | 7 +- tests-expanded/test_add_i128_wasm32v1-none.rs | 5 +- tests-expanded/test_add_u128_tests.rs | 7 +- tests-expanded/test_add_u128_wasm32v1-none.rs | 5 +- tests-expanded/test_add_u64_tests.rs | 7 +- tests-expanded/test_add_u64_wasm32v1-none.rs | 5 +- tests-expanded/test_alloc_tests.rs | 20 +- tests-expanded/test_alloc_wasm32v1-none.rs | 5 +- tests-expanded/test_auth_tests.rs | 179 ++++++++++-------- tests-expanded/test_auth_wasm32v1-none.rs | 5 +- tests-expanded/test_bls_tests.rs | 106 ++++++----- tests-expanded/test_bls_wasm32v1-none.rs | 5 +- tests-expanded/test_constructor_tests.rs | 10 +- .../test_constructor_wasm32v1-none.rs | 5 +- tests-expanded/test_contract_data_tests.rs | 5 +- .../test_contract_data_wasm32v1-none.rs | 5 +- tests-expanded/test_empty2_tests.rs | 7 +- tests-expanded/test_empty2_wasm32v1-none.rs | 5 +- tests-expanded/test_empty_tests.rs | 7 +- tests-expanded/test_empty_wasm32v1-none.rs | 5 +- tests-expanded/test_errors_tests.rs | 20 +- tests-expanded/test_errors_wasm32v1-none.rs | 5 +- tests-expanded/test_events_tests.rs | 9 +- tests-expanded/test_events_wasm32v1-none.rs | 5 +- tests-expanded/test_fuzz_tests.rs | 5 +- tests-expanded/test_fuzz_wasm32v1-none.rs | 5 +- tests-expanded/test_import_contract_tests.rs | 9 +- .../test_import_contract_wasm32v1-none.rs | 7 +- tests-expanded/test_invoke_contract_tests.rs | 7 +- .../test_invoke_contract_wasm32v1-none.rs | 5 +- tests-expanded/test_logging_tests.rs | 26 ++- tests-expanded/test_logging_wasm32v1-none.rs | 5 +- tests-expanded/test_macros_tests.rs | 7 +- tests-expanded/test_macros_wasm32v1-none.rs | 5 +- tests-expanded/test_modular_tests.rs | 7 +- tests-expanded/test_modular_wasm32v1-none.rs | 5 +- tests-expanded/test_multiimpl_tests.rs | 7 +- .../test_multiimpl_wasm32v1-none.rs | 5 +- tests-expanded/test_udt_tests.rs | 89 +++++---- tests-expanded/test_udt_wasm32v1-none.rs | 5 +- .../test_workspace_contract_tests.rs | 7 +- .../test_workspace_contract_wasm32v1-none.rs | 5 +- tests-expanded/test_workspace_lib_tests.rs | 14 +- .../test_workspace_lib_wasm32v1-none.rs | 89 +++++++++ tests-expanded/test_zero_tests.rs | 5 +- tests-expanded/test_zero_wasm32v1-none.rs | 5 +- 51 files changed, 514 insertions(+), 314 deletions(-) delete mode 100644 tests-expanded/proc_macros_tests.rs create mode 100644 tests-expanded/test_workspace_lib_wasm32v1-none.rs diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e5ccf1980..2a9863ab6 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -218,11 +218,11 @@ jobs: - uses: stellar/actions/rust-cache@main - run: rustup update - run: rustup target add wasm32v1-none - - uses: stellar/binaries@v37 + - uses: stellar/binaries@v45 with: name: cargo-hack version: 0.5.28 - - uses: stellar/binaries@v44 + - uses: stellar/binaries@v45 with: name: cargo-expand version: 1.0.116 diff --git a/Makefile b/Makefile index eff57d86e..ffaa3e1e3 100644 --- a/Makefile +++ b/Makefile @@ -46,16 +46,15 @@ readme: # Expands the generated code within each test vector contract that lives in the # tests/ directory. Serves to surface visible changes in generated code that # may not be obvious when making changes to sdk macros. -expand-tests: build +expand-tests: build-test-wasms rm -fr tests-expanded mkdir -p tests-expanded - cargo metadata --format-version 1 | jq -r '.packages[] | select(.manifest_path | contains("/tests/")) | "\(.name) \(.manifest_path | split("/") | .[:-1] | join("/")) \(any(.targets[]; any(.kind[]; . == "cdylib")))"' | while read package dir is_cdylib; do \ - echo "Expanding $$package for host target including tests"; \ + for package in $(TEST_CRATES); do \ + echo "Expanding $$package for linux target including tests"; \ cargo expand --package $$package --tests --target x86_64-unknown-linux-gnu | rustfmt > tests-expanded/$${package}_tests.rs; \ - if [ "$$is_cdylib" = "true" ]; then \ - echo "Expanding $$package for wasm32v1-none target without tests"; \ + echo "Expanding $$package for wasm32v1-none target without tests"; \ + RUSTFLAGS='--cfg soroban_sdk_internal_no_rssdkver_meta' \ cargo expand --package $$package --release --target wasm32v1-none | rustfmt > tests-expanded/$${package}_wasm32v1-none.rs; \ - fi; \ done fmt: diff --git a/tests-expanded/proc_macros_tests.rs b/tests-expanded/proc_macros_tests.rs deleted file mode 100644 index 383298ba7..000000000 --- a/tests-expanded/proc_macros_tests.rs +++ /dev/null @@ -1,33 +0,0 @@ -#![feature(prelude_import)] -#[macro_use] -extern crate std; -/// A collection of proc-macros used by the test_macros test vector to validate that the -/// soroban-sdk macros are composable and compatible with a variety of other macros. -use proc_macro::TokenStream; -use quote::quote; -#[prelude_import] -use std::prelude::rust_2021::*; -use syn::{parse_macro_input, ItemFn}; -/// An attribute macro that expects to be used on a function. -#[proc_macro_attribute] -pub fn parse_item_fn(_metadata: TokenStream, input: TokenStream) -> TokenStream { - let item = match ::syn::parse::(input) { - ::syn::__private::Ok(data) => data, - ::syn::__private::Err(err) => { - return ::syn::__private::TokenStream::from(err.to_compile_error()); - } - }; - { - let mut _s = ::quote::__private::TokenStream::new(); - ::quote::ToTokens::to_tokens(&item, &mut _s); - _s - } - .into() -} -#[rustc_main] -#[coverage(off)] -#[doc(hidden)] -pub fn main() -> () { - extern crate test; - test::test_main_static(&[]) -} diff --git a/tests-expanded/test_account_tests.rs b/tests-expanded/test_account_tests.rs index de7e9e307..f2bd6aa6e 100644 --- a/tests-expanded/test_account_tests.rs +++ b/tests-expanded/test_account_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{ auth::Context, auth::CustomAccountInterface, contract, contracterror, contractimpl, crypto::Hash, Env, Vec, @@ -420,6 +421,7 @@ static __Contract_CustomAccountInterface_d465b6861ce11142d9f64c1622e1ad88ae003d9 } __Contract_CustomAccountInterface_d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor }; +#[cfg(test)] mod test { use crate::Contract; use soroban_sdk::{ @@ -559,6 +561,7 @@ mod test { } } extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test"] #[doc(hidden)] pub const test: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_account_wasm32v1-none.rs b/tests-expanded/test_account_wasm32v1-none.rs index fbf76138b..9a475be7c 100644 --- a/tests-expanded/test_account_wasm32v1-none.rs +++ b/tests-expanded/test_account_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{ auth::Context, auth::CustomAccountInterface, contract, contracterror, contractimpl, crypto::Hash, Env, Vec, diff --git a/tests-expanded/test_add_i128_tests.rs b/tests-expanded/test_add_i128_tests.rs index 7c3ecc0a8..ed975fd13 100644 --- a/tests-expanded/test_add_i128_tests.rs +++ b/tests-expanded/test_add_i128_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". @@ -322,10 +323,12 @@ static __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4 } __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor }; +#[cfg(test)] mod test { use crate::{Contract, ContractClient}; use soroban_sdk::Env; extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test_add"] #[doc(hidden)] pub const test_add: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_add_i128_wasm32v1-none.rs b/tests-expanded/test_add_i128_wasm32v1-none.rs index 7aeee3f27..3a7446919 100644 --- a/tests-expanded/test_add_i128_wasm32v1-none.rs +++ b/tests-expanded/test_add_i128_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_add_u128_tests.rs b/tests-expanded/test_add_u128_tests.rs index 6beb11068..f656bb357 100644 --- a/tests-expanded/test_add_u128_tests.rs +++ b/tests-expanded/test_add_u128_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". @@ -322,10 +323,12 @@ static __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4 } __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor }; +#[cfg(test)] mod test { use crate::{Contract, ContractClient}; use soroban_sdk::Env; extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test_add"] #[doc(hidden)] pub const test_add: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_add_u128_wasm32v1-none.rs b/tests-expanded/test_add_u128_wasm32v1-none.rs index 513a58368..2cc45382f 100644 --- a/tests-expanded/test_add_u128_wasm32v1-none.rs +++ b/tests-expanded/test_add_u128_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_add_u64_tests.rs b/tests-expanded/test_add_u64_tests.rs index aa945dc57..4079f7e3f 100644 --- a/tests-expanded/test_add_u64_tests.rs +++ b/tests-expanded/test_add_u64_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". @@ -322,10 +323,12 @@ static __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4 } __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor }; +#[cfg(test)] mod test { use crate::{Contract, ContractClient}; use soroban_sdk::Env; extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test_add"] #[doc(hidden)] pub const test_add: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_add_u64_wasm32v1-none.rs b/tests-expanded/test_add_u64_wasm32v1-none.rs index 2da2616b4..9b95d76ba 100644 --- a/tests-expanded/test_add_u64_wasm32v1-none.rs +++ b/tests-expanded/test_add_u64_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_alloc_tests.rs b/tests-expanded/test_alloc_tests.rs index f76a8538f..bd9b20444 100644 --- a/tests-expanded/test_alloc_tests.rs +++ b/tests-expanded/test_alloc_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl, Env}; extern crate alloc; pub struct Contract; @@ -317,10 +318,11 @@ static __Contract__526e07cb9219443e6b3ef052e7872bf9e5bfee9b91633ed921601b5e93014 __Contract__526e07cb9219443e6b3ef052e7872bf9e5bfee9b91633ed921601b5e93014bb7_ctor___rust_ctor___ctor }; mod test { + #![cfg(test)] use crate::{Contract, ContractClient}; - use soroban_sdk::{testutils::EnvTestConfig, vec, Env}; + use soroban_sdk::{vec, Env}; mod imported { - pub const WASM: &[u8] = b"\0asm\x01\0\0\0\x01#\x07`\0\x01~`\x02~~\x01~`\x01\x7f\0`\0\0`\x01\x7f\x01\x7f`\x01~\x01~`\x03\x7f\x7f\x7f\x01\x7f\x02\r\x02\x01v\x01_\0\0\x01v\x016\0\x01\x03\r\x0c\x02\x03\x04\x03\x02\x05\x02\x02\x03\x03\x06\x06\x04\x05\x01p\x01\x01\x01\x05\x03\x01\0\x11\x06!\x04\x7f\x01A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x88\x80\xc0\0\x0b\x7f\0A\x90\x80\xc0\0\x0b\x074\x05\x06memory\x02\0\x08num_list\0\x07\x01_\x03\x01\n__data_end\x03\x02\x0b__heap_base\x03\x03\n\xf9\r\x0c\xab\x02\x01\x06\x7f\x02@\x02@ \0(\x02\0\"\x01A\x01tA\x01 \x01\x1b\"\x02A\xff\xff\xff\xff\x03K\r\0 \x02A\x04 \x02A\x04K\x1b\"\x03A\x02t\"\x04A\xfd\xff\xff\xff\x07O\r\0\x02@\x02@ \x01E\r\0 \0(\x02\x04!\x05\x10\x83\x80\x80\x80\0A\0(\x02\x80\x80\xc0\x80\0\"\x02A\x03j\"\x06 \x02I\r\x02\x02@\x02@ \x06A|q\"\x02 \x04j\"\x06A\0(\x02\x84\x80\xc0\x80\0M\r\0 \x04\x10\x84\x80\x80\x80\0!\x02\x0c\x01\x0bA\0 \x066\x02\x80\x80\xc0\x80\0\x0b \x02E\r\x03 \x02 \x05 \x01A\x02t\x10\x8d\x80\x80\x80\0\x1a\x0c\x01\x0b\x10\x83\x80\x80\x80\0A\0(\x02\x80\x80\xc0\x80\0\"\x01A\x03j\"\x02 \x01I\r\x01\x02@\x02@ \x02A|q\"\x02 \x04j\"\x01A\0(\x02\x84\x80\xc0\x80\0M\r\0 \x04\x10\x84\x80\x80\x80\0!\x02\x0c\x01\x0bA\0 \x016\x02\x80\x80\xc0\x80\0\x0b \x02E\r\x02\x0b \0 \x036\x02\0 \0 \x026\x02\x04\x0f\x0b\x10\x85\x80\x80\x80\0\0\x0b \x04\x10\x86\x80\x80\x80\0\0\x0bC\x01\x01\x7f\x02@\x02@A\0(\x02\x84\x80\xc0\x80\0\r\0?\0\"\0A\xff\xff\x03K\r\x01A\0 \0A\x10t\"\06\x02\x84\x80\xc0\x80\0A\0 \06\x02\x80\x80\xc0\x80\0\x0b\x0f\x0b\x10\x85\x80\x80\x80\0\0\x0b\x91\x01\x01\x04\x7f \0A\xff\xff\x03j\"\x01A\x80\x80|q!\x02 \x01A\x10v!\x03\x02@\x02@\x03@ \x03@\0A\x7fF\r\x01A\0A\0(\x02\x84\x80\xc0\x80\0 \x02j6\x02\x84\x80\xc0\x80\0\x10\x83\x80\x80\x80\0A\0(\x02\x80\x80\xc0\x80\0\"\x01A\x03j\"\x04 \x01I\r\x02 \x04A|q\"\x01 \0j\"\x04A\0(\x02\x84\x80\xc0\x80\0K\r\0\x0bA\0 \x046\x02\x80\x80\xc0\x80\0 \x01\x0f\x0b\x10\x8b\x80\x80\x80\0\0\x0b\x10\x85\x80\x80\x80\0\0\x0b\t\0\x10\x8a\x80\x80\x80\0\0\x0b\x0b\0 \0\x10\x88\x80\x80\x80\0\0\x0b\xee\x01\x01\x05\x7f#\x80\x80\x80\x80\0A\x10k\"\x01$\x80\x80\x80\x80\0\x02@ \0B\xff\x01\x83B\x04R\r\0 \0B \x88\xa7!\x02A\0!\x03 \x01A\06\x02\x0c \x01B\x80\x80\x80\x80\xc0\07\x02\x04A\x04!\x04A\0!\x05\x02@\x03@ \x02 \x05F\r\x01\x02@ \x05 \x01(\x02\x04G\r\0 \x01A\x04j\x10\x82\x80\x80\x80\0 \x01(\x02\x08!\x04\x0b \x04 \x03j \x056\x02\0 \x01 \x05A\x01j\"\x056\x02\x0c \x03A\x04j!\x03 \x05!\x05\x0c\0\x0b\x0b \x02A\x02t!\x05\x10\x80\x80\x80\x80\0!\0 \x01(\x02\x08!\x03\x02@\x03@ \x05E\r\x01 \x05A|j!\x05 \0 \x035\x02\0B \x86B\x04\x84\x10\x81\x80\x80\x80\0!\0 \x03A\x04j!\x03\x0c\0\x0b\x0b \x01A\x10j$\x80\x80\x80\x80\0 \0\x0f\x0b\0\x0b\x0b\0 \0\x10\x89\x80\x80\x80\0\0\x0b\t\0\x10\x8a\x80\x80\x80\0\0\x0b\x03\0\0\x0b\t\0\x10\x85\x80\x80\x80\0\0\x0b\xb9\x07\x01\x0c\x7f#\x80\x80\x80\x80\0A\x10k!\x03\x02@\x02@ \x02A\x10O\r\0 \0!\x04\x0c\x01\x0b\x02@ \0 \0A\0 \0kA\x03q\"\x05j\"\x06O\r\0 \x05A\x7fj!\x07 \0!\x04 \x01!\x08\x02@ \x05E\r\0 \x05!\t \0!\x04 \x01!\x08\x03@ \x04 \x08-\0\0:\0\0 \x08A\x01j!\x08 \x04A\x01j!\x04 \tA\x7fj\"\t\r\0\x0b\x0b \x07A\x07I\r\0\x03@ \x04 \x08-\0\0:\0\0 \x04A\x01j \x08A\x01j-\0\0:\0\0 \x04A\x02j \x08A\x02j-\0\0:\0\0 \x04A\x03j \x08A\x03j-\0\0:\0\0 \x04A\x04j \x08A\x04j-\0\0:\0\0 \x04A\x05j \x08A\x05j-\0\0:\0\0 \x04A\x06j \x08A\x06j-\0\0:\0\0 \x04A\x07j \x08A\x07j-\0\0:\0\0 \x08A\x08j!\x08 \x04A\x08j\"\x04 \x06G\r\0\x0b\x0b \x06 \x02 \x05k\"\tA|q\"\x07j!\x04\x02@\x02@ \x01 \x05j\"\x08A\x03q\"\x01\r\0 \x06 \x04O\r\x01 \x08!\x01\x03@ \x06 \x01(\x02\06\x02\0 \x01A\x04j!\x01 \x06A\x04j\"\x06 \x04I\r\0\x0c\x02\x0b\x0bA\0!\x02 \x03A\06\x02\x0c \x03A\x0cj \x01r!\x05\x02@A\x04 \x01k\"\nA\x01qE\r\0 \x05 \x08-\0\0:\0\0A\x01!\x02\x0b\x02@ \nA\x02qE\r\0 \x05 \x02j \x08 \x02j/\x01\0;\x01\0\x0b \x08 \x01k!\x02 \x01A\x03t!\x0b \x03(\x02\x0c!\x05\x02@\x02@ \x06A\x04j \x04I\r\0 \x06!\x0c\x0c\x01\x0bA\0 \x0bkA\x18q!\r\x03@ \x06 \x05 \x0bv \x02A\x04j\"\x02(\x02\0\"\x05 \rtr6\x02\0 \x06A\x08j!\n \x06A\x04j\"\x0c!\x06 \n \x04I\r\0\x0b\x0bA\0!\x06 \x03A\0:\0\x08 \x03A\0:\0\x06\x02@\x02@ \x01A\x01G\r\0 \x03A\x08j!\rA\0!\x01A\0!\nA\0!\x0e\x0c\x01\x0b \x02A\x05j-\0\0!\n \x03 \x02A\x04j-\0\0\"\x01:\0\x08 \nA\x08t!\nA\x02!\x0e \x03A\x06j!\r\x0b\x02@ \x08A\x01qE\r\0 \r \x02A\x04j \x0ej-\0\0:\0\0 \x03-\0\x06A\x10t!\x06 \x03-\0\x08!\x01\x0b \x0c \n \x06r \x01A\xff\x01qrA\0 \x0bkA\x18qt \x05 \x0bvr6\x02\0\x0b \tA\x03q!\x02 \x08 \x07j!\x01\x0b\x02@ \x04 \x04 \x02j\"\x06O\r\0 \x02A\x7fj!\t\x02@ \x02A\x07q\"\x08E\r\0\x03@ \x04 \x01-\0\0:\0\0 \x01A\x01j!\x01 \x04A\x01j!\x04 \x08A\x7fj\"\x08\r\0\x0b\x0b \tA\x07I\r\0\x03@ \x04 \x01-\0\0:\0\0 \x04A\x01j \x01A\x01j-\0\0:\0\0 \x04A\x02j \x01A\x02j-\0\0:\0\0 \x04A\x03j \x01A\x03j-\0\0:\0\0 \x04A\x04j \x01A\x04j-\0\0:\0\0 \x04A\x05j \x01A\x05j-\0\0:\0\0 \x04A\x06j \x01A\x06j-\0\0:\0\0 \x04A\x07j \x01A\x07j-\0\0:\0\0 \x01A\x08j!\x01 \x04A\x08j\"\x04 \x06G\r\0\x0b\x0b \0\x0b\x0e\0 \0 \x01 \x02\x10\x8c\x80\x80\x80\0\x0b\x0b\t\x01\0A\x80\x80\xc0\0\x0b\0\0G\x0econtractspecv0\0\0\0\0\0\0\0\0\0\0\0\x08num_list\0\0\0\x01\0\0\0\0\0\0\0\x05count\0\0\0\0\0\0\x04\0\0\0\x01\0\0\x03\xea\0\0\0\x04\0\x1e\x11contractenvmetav0\0\0\0\0\0\0\0\x17\0\0\0\0\0w\x0econtractmetav0\0\0\0\0\0\0\0\x05rsver\0\0\0\0\0\0\x061.90.0\0\0\0\0\0\0\0\0\0\x08rssdkver\0\0\0523.0.2#cf19bf2f23ea092ae4ddc41473b3968528ddc63c-dirty\0\0\0"; + pub const WASM: &[u8] = b"\0asm\x01\0\0\0\x01.\t`\0\x01~`\x02~~\x01~`\x02\x7f\x7f\0`\0\0`\x01\x7f\x01\x7f`\x03\x7f\x7f\x7f\0`\x01\x7f\0`\x01~\x01~`\x03\x7f\x7f\x7f\x01\x7f\x02\r\x02\x01v\x01_\0\0\x01v\x016\0\x01\x03\x10\x0f\x02\x03\x04\x03\x05\x06\x02\x07\x06\x06\x03\x06\x03\x03\x08\x05\x03\x01\0\x11\x06!\x04\x7f\x01A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x8c\x80\xc0\0\x0b\x7f\0A\x90\x80\xc0\0\x0b\x074\x05\x06memory\x02\0\x08num_list\0\t\x01_\x03\x01\n__data_end\x03\x02\x0b__heap_base\x03\x03\n\xd8\x0e\x0f\x85\x01\x01\x02\x7f\x02@\x02@ \x01\r\0A\x04!\x02\x0c\x01\x0bA\0-\0\x80\x80\xc0\x80\0\x1a\x10\x83\x80\x80\x80\0\x02@A\0(\x02\x84\x80\xc0\x80\0\"\x02A\x03j\"\x03 \x02I\r\0\x02@ \x03A|q\"\x02 \x01j\"\x03A\0(\x02\x88\x80\xc0\x80\0M\r\0 \x01\x10\x84\x80\x80\x80\0!\x02\x0c\x02\x0bA\0 \x036\x02\x84\x80\xc0\x80\0\x0c\x01\x0b\x10\x85\x80\x80\x80\0\0\x0b \0 \x016\x02\x04 \0 \x026\x02\0\x0bC\x01\x01\x7f\x02@\x02@A\0(\x02\x88\x80\xc0\x80\0\r\0?\0\"\0A\xff\xff\x03K\r\x01A\0 \0A\x10t\"\06\x02\x88\x80\xc0\x80\0A\0 \06\x02\x84\x80\xc0\x80\0\x0b\x0f\x0b\x10\x85\x80\x80\x80\0\0\x0b\x91\x01\x01\x04\x7f \0A\xff\xff\x03j\"\x01A\x80\x80|q!\x02 \x01A\x10v!\x03\x02@\x02@\x03@ \x03@\0A\x7fF\r\x01A\0A\0(\x02\x88\x80\xc0\x80\0 \x02j6\x02\x88\x80\xc0\x80\0\x10\x83\x80\x80\x80\0A\0(\x02\x84\x80\xc0\x80\0\"\x01A\x03j\"\x04 \x01I\r\x02 \x04A|q\"\x01 \0j\"\x04A\0(\x02\x88\x80\xc0\x80\0K\r\0\x0bA\0 \x046\x02\x84\x80\xc0\x80\0 \x01\x0f\x0b\x10\x8f\x80\x80\x80\0\0\x0b\x10\x85\x80\x80\x80\0\0\x0b\t\0\x10\x8e\x80\x80\x80\0\0\x0b\x94\x02\x01\x04\x7f#\x80\x80\x80\x80\0A\x10k\"\x03$\x80\x80\x80\x80\0\x02@\x02@\x02@ \x02(\x02\x04E\r\0\x02@ \x02(\x02\x08\"\x04\r\0 \x03A\x08j \x01\x10\x82\x80\x80\x80\0 \x03(\x02\x0c!\x04 \x03(\x02\x08!\x02\x0c\x02\x0b \x02(\x02\0!\x05\x10\x83\x80\x80\x80\0A\0(\x02\x84\x80\xc0\x80\0\"\x02A\x03j\"\x06 \x02I\r\x02\x02@\x02@ \x06A|q\"\x02 \x01j\"\x06A\0(\x02\x88\x80\xc0\x80\0M\r\0 \x01\x10\x84\x80\x80\x80\0!\x02\x0c\x01\x0bA\0 \x066\x02\x84\x80\xc0\x80\0\x0b\x02@\x02@ \x02\r\0A\0!\x02\x0c\x01\x0b \x02 \x05 \x04\x10\x90\x80\x80\x80\0\x1a\x0b \x01!\x04\x0c\x01\x0b \x03 \x01\x10\x82\x80\x80\x80\0 \x03(\x02\x04!\x04 \x03(\x02\0!\x02\x0b \0 \x02A\x04 \x02\x1b6\x02\x04 \0 \x02E6\x02\0 \0 \x04 \x01 \x02\x1b6\x02\x08 \x03A\x10j$\x80\x80\x80\x80\0\x0f\x0b\x10\x85\x80\x80\x80\0\0\x0b\xec\x01\x01\x06\x7f#\x80\x80\x80\x80\0A k\"\x01$\x80\x80\x80\x80\0A\0!\x02\x02@\x02@\x02@\x02@ \0(\x02\0\"\x03A\x7fF\r\0 \x03A\x01t \x03A\x01j \x03A\0J\x1b\"\x04A\xff\xff\xff\xff\x03M\r\x01\x0b\x0c\x01\x0b \x04A\x04 \x04A\x04K\x1b\"\x05A\x02t\"\x04A\xfc\xff\xff\xff\x07K\r\0\x02@\x02@ \x03\r\0A\0!\x03\x0c\x01\x0b \x01 \x03A\x02t6\x02\x1c \x01 \0(\x02\x046\x02\x14A\x04!\x03\x0b \x01 \x036\x02\x18 \x01A\x08j \x04 \x01A\x14j\x10\x86\x80\x80\x80\0 \x01(\x02\x08A\x01G\r\x01 \x01(\x02\x10!\x06 \x01(\x02\x0c!\x02\x0b \x02 \x06\x10\x88\x80\x80\x80\0\0\x0b \x01(\x02\x0c!\x03 \0 \x056\x02\0 \0 \x036\x02\x04 \x01A j$\x80\x80\x80\x80\0\x0b\x19\0\x02@ \0\r\0\x10\x8c\x80\x80\x80\0\0\x0b \x01\x10\x8d\x80\x80\x80\0\0\x0b\xee\x01\x01\x06\x7f#\x80\x80\x80\x80\0A\x10k\"\x01$\x80\x80\x80\x80\0\x02@\x02@ \0B\xff\x01\x83B\x04R\r\0 \0B \x88\xa7!\x02A\0!\x03 \x01A\06\x02\x0c \x01B\x80\x80\x80\x80\xc0\07\x02\x04A\x01!\x04A\x04!\x05A\0!\x06\x02@\x03@ \x06 \x02O\r\x01\x02@ \x04A\x7fj \x01(\x02\x04G\r\0 \x01A\x04j\x10\x87\x80\x80\x80\0 \x01(\x02\x08!\x05\x0b \x05 \x03j \x066\x02\0 \x03A\x04j!\x03 \x01 \x046\x02\x0c \x04A\x01j!\x04 \x06 \x06 \x02Ij!\x06\x0c\0\x0b\x0b\x10\x80\x80\x80\x80\0!\0\x03@ \x03E\r\x02 \x03A|j!\x03 \0 \x055\x02\0B \x86B\x04\x84\x10\x81\x80\x80\x80\0!\0 \x05A\x04j!\x05\x0c\0\x0b\x0b\0\x0b \x01A\x10j$\x80\x80\x80\x80\0 \0\x0b\x0b\0 \0\x10\x8b\x80\x80\x80\0\0\x0b\t\0\x10\x8e\x80\x80\x80\0\0\x0b\t\0\x10\x8e\x80\x80\x80\0\0\x0b\x0b\0 \0\x10\x8a\x80\x80\x80\0\0\x0b\x03\0\0\x0b\t\0\x10\x85\x80\x80\x80\0\0\x0b\xa5\x05\x01\x08\x7f\x02@\x02@ \x02A\x10O\r\0 \0!\x03\x0c\x01\x0b\x02@ \0A\0 \0kA\x03q\"\x04j\"\x05 \0M\r\0 \x04A\x7fj!\x06 \0!\x03 \x01!\x07\x02@ \x04E\r\0 \x04!\x08 \0!\x03 \x01!\x07\x03@ \x03 \x07-\0\0:\0\0 \x07A\x01j!\x07 \x03A\x01j!\x03 \x08A\x7fj\"\x08\r\0\x0b\x0b \x06A\x07I\r\0\x03@ \x03 \x07-\0\0:\0\0 \x03A\x01j \x07A\x01j-\0\0:\0\0 \x03A\x02j \x07A\x02j-\0\0:\0\0 \x03A\x03j \x07A\x03j-\0\0:\0\0 \x03A\x04j \x07A\x04j-\0\0:\0\0 \x03A\x05j \x07A\x05j-\0\0:\0\0 \x03A\x06j \x07A\x06j-\0\0:\0\0 \x03A\x07j \x07A\x07j-\0\0:\0\0 \x07A\x08j!\x07 \x03A\x08j\"\x03 \x05G\r\0\x0b\x0b \x05 \x02 \x04k\"\x08A|q\"\x06j!\x03\x02@\x02@ \x01 \x04j\"\x07A\x03q\r\0 \x05 \x03O\r\x01 \x07!\x01\x03@ \x05 \x01(\x02\06\x02\0 \x01A\x04j!\x01 \x05A\x04j\"\x05 \x03I\r\0\x0c\x02\x0b\x0b \x05 \x03O\r\0 \x07A\x03t\"\x02A\x18q!\x04 \x07A|q\"\tA\x04j!\x01A\0 \x02kA\x18q!\n \t(\x02\0!\x02\x03@ \x05 \x02 \x04v \x01(\x02\0\"\x02 \ntr6\x02\0 \x01A\x04j!\x01 \x05A\x04j\"\x05 \x03I\r\0\x0b\x0b \x08A\x03q!\x02 \x07 \x06j!\x01\x0b\x02@ \x03 \x03 \x02j\"\x05O\r\0 \x02A\x7fj!\x08\x02@ \x02A\x07q\"\x07E\r\0\x03@ \x03 \x01-\0\0:\0\0 \x01A\x01j!\x01 \x03A\x01j!\x03 \x07A\x7fj\"\x07\r\0\x0b\x0b \x08A\x07I\r\0\x03@ \x03 \x01-\0\0:\0\0 \x03A\x01j \x01A\x01j-\0\0:\0\0 \x03A\x02j \x01A\x02j-\0\0:\0\0 \x03A\x03j \x01A\x03j-\0\0:\0\0 \x03A\x04j \x01A\x04j-\0\0:\0\0 \x03A\x05j \x01A\x05j-\0\0:\0\0 \x03A\x06j \x01A\x06j-\0\0:\0\0 \x03A\x07j \x01A\x07j-\0\0:\0\0 \x01A\x08j!\x01 \x03A\x08j\"\x03 \x05G\r\0\x0b\x0b \0\x0b\x0b\t\x01\0A\x80\x80\xc0\0\x0b\0\0G\x0econtractspecv0\0\0\0\0\0\0\0\0\0\0\0\x08num_list\0\0\0\x01\0\0\0\0\0\0\0\x05count\0\0\0\0\0\0\x04\0\0\0\x01\0\0\x03\xea\0\0\0\x04\0\x1e\x11contractenvmetav0\0\0\0\0\0\0\0\x17\0\0\0\0\0+\x0econtractmetav0\0\0\0\0\0\0\0\x05rsver\0\0\0\0\0\0\x061.84.0\0\0"; pub trait Contract { fn num_list(env: soroban_sdk::Env, count: u32) -> soroban_sdk::Vec; } @@ -520,6 +522,7 @@ mod test { mod native { use super::*; extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::native::test"] #[doc(hidden)] pub const test: test::TestDescAndFn = test::TestDescAndFn { @@ -543,9 +546,7 @@ mod test { ), }; fn test() { - let e = Env::new_with_config(EnvTestConfig { - capture_snapshot_at_drop: false, - }); + let e = Env::default(); let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let list = client.num_list(&50); @@ -577,6 +578,7 @@ mod test { mod wasm { use super::*; extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::wasm::test"] #[doc(hidden)] pub const test: test::TestDescAndFn = test::TestDescAndFn { @@ -600,9 +602,7 @@ mod test { ), }; fn test() { - let e = Env::new_with_config(EnvTestConfig { - capture_snapshot_at_drop: false, - }); + let e = Env::default(); let contract_id = e.register(imported::WASM, ()); let client = ContractClient::new(&e, &contract_id); let list = client.num_list(&50); diff --git a/tests-expanded/test_alloc_wasm32v1-none.rs b/tests-expanded/test_alloc_wasm32v1-none.rs index 17e2683ca..884f99cfe 100644 --- a/tests-expanded/test_alloc_wasm32v1-none.rs +++ b/tests-expanded/test_alloc_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl, Env}; extern crate alloc; pub struct Contract; diff --git a/tests-expanded/test_auth_tests.rs b/tests-expanded/test_auth_tests.rs index 022745827..3c06f0d49 100644 --- a/tests-expanded/test_auth_tests.rs +++ b/tests-expanded/test_auth_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl, Address, Env, IntoVal}; pub struct ContractA; ///ContractAArgs is a type for building arg lists for functions defined in "ContractA". @@ -303,6 +304,7 @@ static __ContractA__7c3764b58a7ababbe8a6b452f6a400d8ae3704b80f8c5ea1b251eebbc869 } __ContractA__7c3764b58a7ababbe8a6b452f6a400d8ae3704b80f8c5ea1b251eebbc8698020_ctor___rust_ctor___ctor }; +#[cfg(test)] mod test_a { use super::*; use soroban_sdk::{ @@ -319,6 +321,7 @@ mod test_a { }; extern crate std; extern crate test; + #[cfg(test)] #[rustc_test_marker = "test_a::test_with_mock_all_auth"] #[doc(hidden)] pub const test_with_mock_all_auth: test::TestDescAndFn = test::TestDescAndFn { @@ -362,17 +365,20 @@ mod test_a { }; match ( &e.auths(), - &<[_]>::into_vec(::alloc::boxed::box_new([( - a.clone(), - AuthorizedInvocation { - function: AuthorizedFunction::Contract(( - contract_id.clone(), - Symbol::new(&e, "fn1"), - (&a,).into_val(&e), - )), - sub_invocations: ::alloc::vec::Vec::new(), - }, - )])), + &<[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([( + a.clone(), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + contract_id.clone(), + Symbol::new(&e, "fn1"), + (&a,).into_val(&e), + )), + sub_invocations: ::alloc::vec::Vec::new(), + }, + )]), + ), ) { (left_val, right_val) => { if !(*left_val == *right_val) { @@ -388,6 +394,7 @@ mod test_a { }; } extern crate test; + #[cfg(test)] #[rustc_test_marker = "test_a::test_with_mock_auth"] #[doc(hidden)] pub const test_with_mock_auth: test::TestDescAndFn = test::TestDescAndFn { @@ -441,17 +448,20 @@ mod test_a { }; match ( &e.auths(), - &<[_]>::into_vec(::alloc::boxed::box_new([( - a.clone(), - AuthorizedInvocation { - function: AuthorizedFunction::Contract(( - contract_id.clone(), - Symbol::new(&e, "fn1"), - (&a,).into_val(&e), - )), - sub_invocations: ::alloc::vec::Vec::new(), - }, - )])), + &<[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([( + a.clone(), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + contract_id.clone(), + Symbol::new(&e, "fn1"), + (&a,).into_val(&e), + )), + sub_invocations: ::alloc::vec::Vec::new(), + }, + )]), + ), ) { (left_val, right_val) => { if !(*left_val == *right_val) { @@ -467,6 +477,7 @@ mod test_a { }; } extern crate test; + #[cfg(test)] #[rustc_test_marker = "test_a::test_with_real_contract_auth_approve"] #[doc(hidden)] pub const test_with_real_contract_auth_approve: test::TestDescAndFn = test::TestDescAndFn { @@ -507,9 +518,10 @@ mod test_a { function: SorobanAuthorizedFunction::ContractFn(InvokeContractArgs { contract_address: contract_id.clone().try_into().unwrap(), function_name: StringM::try_from("fn1").unwrap().into(), - args: <[_]>::into_vec(::alloc::boxed::box_new([ScVal::Address( - a_xdr.clone(), - )])) + args: <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ScVal::Address(a_xdr.clone())]), + ) .try_into() .unwrap(), }), @@ -532,17 +544,20 @@ mod test_a { }; match ( &e.auths(), - &<[_]>::into_vec(::alloc::boxed::box_new([( - a.clone(), - AuthorizedInvocation { - function: AuthorizedFunction::Contract(( - contract_id.clone(), - Symbol::new(&e, "fn1"), - (&a,).into_val(&e), - )), - sub_invocations: ::alloc::vec::Vec::new(), - }, - )])), + &<[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([( + a.clone(), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + contract_id.clone(), + Symbol::new(&e, "fn1"), + (&a,).into_val(&e), + )), + sub_invocations: ::alloc::vec::Vec::new(), + }, + )]), + ), ) { (left_val, right_val) => { if !(*left_val == *right_val) { @@ -558,6 +573,7 @@ mod test_a { }; } extern crate test; + #[cfg(test)] #[rustc_test_marker = "test_a::test_with_real_contract_auth_decline"] #[doc(hidden)] pub const test_with_real_contract_auth_decline: test::TestDescAndFn = test::TestDescAndFn { @@ -598,9 +614,10 @@ mod test_a { function: SorobanAuthorizedFunction::ContractFn(InvokeContractArgs { contract_address: contract_id.try_into().unwrap(), function_name: StringM::try_from("fn1").unwrap().into(), - args: <[_]>::into_vec(::alloc::boxed::box_new([ScVal::Address( - a_xdr.clone(), - )])) + args: <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ScVal::Address(a_xdr.clone())]), + ) .try_into() .unwrap(), }), @@ -1676,6 +1693,7 @@ static __ContractB__389cfcb1cb10680376b4cd5cf632e6b11c3e59494c10e1d42514faf6c4c2 } __ContractB__389cfcb1cb10680376b4cd5cf632e6b11c3e59494c10e1d42514faf6c4c21b84_ctor___rust_ctor___ctor }; +#[cfg(test)] mod test_b { use super::*; use soroban_sdk::{ @@ -1692,6 +1710,7 @@ mod test_b { }; extern crate std; extern crate test; + #[cfg(test)] #[rustc_test_marker = "test_b::test_with_mock_all_auth"] #[doc(hidden)] pub const test_with_mock_all_auth: test::TestDescAndFn = test::TestDescAndFn { @@ -1748,8 +1767,9 @@ mod test_b { }, (1, 2).into_val(&e), )), - sub_invocations: <[_]>::into_vec(::alloc::boxed::box_new([ - AuthorizedInvocation { + sub_invocations: <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([AuthorizedInvocation { function: AuthorizedFunction::Contract(( contract_a_id.clone(), { @@ -1761,8 +1781,8 @@ mod test_b { (&a,).into_val(&e), )), sub_invocations: ::alloc::vec::Vec::new(), - }, - ])), + }]), + ), }, )], ) { @@ -1780,6 +1800,7 @@ mod test_b { }; } extern crate test; + #[cfg(test)] #[rustc_test_marker = "test_b::test_with_mock_auth"] #[doc(hidden)] pub const test_with_mock_auth: test::TestDescAndFn = test::TestDescAndFn { @@ -1851,8 +1872,9 @@ mod test_b { }, (1, 2).into_val(&e), )), - sub_invocations: <[_]>::into_vec(::alloc::boxed::box_new([ - AuthorizedInvocation { + sub_invocations: <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([AuthorizedInvocation { function: AuthorizedFunction::Contract(( contract_a_id.clone(), { @@ -1864,8 +1886,8 @@ mod test_b { (&a,).into_val(&e), )), sub_invocations: ::alloc::vec::Vec::new(), - }, - ])), + }]), + ), }, )], ) { @@ -1883,6 +1905,7 @@ mod test_b { }; } extern crate test; + #[cfg(test)] #[rustc_test_marker = "test_b::test_with_real_contract_auth_approve"] #[doc(hidden)] pub const test_with_real_contract_auth_approve: test::TestDescAndFn = test::TestDescAndFn { @@ -1924,27 +1947,29 @@ mod test_b { function: SorobanAuthorizedFunction::ContractFn(InvokeContractArgs { contract_address: contract_b_id.clone().try_into().unwrap(), function_name: StringM::try_from("fn2").unwrap().into(), - args: <[_]>::into_vec(::alloc::boxed::box_new([ - ScVal::I32(1), - ScVal::I32(2), - ])) + args: <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ScVal::I32(1), ScVal::I32(2)]), + ) .try_into() .unwrap(), }), - sub_invocations: <[_]>::into_vec(::alloc::boxed::box_new([ - SorobanAuthorizedInvocation { + sub_invocations: <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([SorobanAuthorizedInvocation { function: SorobanAuthorizedFunction::ContractFn(InvokeContractArgs { contract_address: contract_a_id.clone().try_into().unwrap(), function_name: StringM::try_from("fn1").unwrap().into(), - args: <[_]>::into_vec(::alloc::boxed::box_new([ScVal::Address( - a_xdr.clone(), - )])) + args: <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ScVal::Address(a_xdr.clone())]), + ) .try_into() .unwrap(), }), sub_invocations: Default::default(), - }, - ])) + }]), + ) .try_into() .unwrap(), }, @@ -1977,8 +2002,9 @@ mod test_b { }, (1, 2).into_val(&e), )), - sub_invocations: <[_]>::into_vec(::alloc::boxed::box_new([ - AuthorizedInvocation { + sub_invocations: <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([AuthorizedInvocation { function: AuthorizedFunction::Contract(( contract_a_id.clone(), { @@ -1990,8 +2016,8 @@ mod test_b { (&a,).into_val(&e), )), sub_invocations: ::alloc::vec::Vec::new(), - }, - ])), + }]), + ), }, )], ) { @@ -2009,6 +2035,7 @@ mod test_b { }; } extern crate test; + #[cfg(test)] #[rustc_test_marker = "test_b::test_with_real_contract_auth_decline"] #[doc(hidden)] pub const test_with_real_contract_auth_decline: test::TestDescAndFn = test::TestDescAndFn { @@ -2050,27 +2077,29 @@ mod test_b { function: SorobanAuthorizedFunction::ContractFn(InvokeContractArgs { contract_address: contract_b_id.try_into().unwrap(), function_name: StringM::try_from("fn2").unwrap().into(), - args: <[_]>::into_vec(::alloc::boxed::box_new([ - ScVal::I32(1), - ScVal::I32(2), - ])) + args: <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ScVal::I32(1), ScVal::I32(2)]), + ) .try_into() .unwrap(), }), - sub_invocations: <[_]>::into_vec(::alloc::boxed::box_new([ - SorobanAuthorizedInvocation { + sub_invocations: <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([SorobanAuthorizedInvocation { function: SorobanAuthorizedFunction::ContractFn(InvokeContractArgs { contract_address: contract_a_id.clone().try_into().unwrap(), function_name: StringM::try_from("fn1").unwrap().into(), - args: <[_]>::into_vec(::alloc::boxed::box_new([ScVal::Address( - a_xdr.clone(), - )])) + args: <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ScVal::Address(a_xdr.clone())]), + ) .try_into() .unwrap(), }), sub_invocations: Default::default(), - }, - ])) + }]), + ) .try_into() .unwrap(), }, diff --git a/tests-expanded/test_auth_wasm32v1-none.rs b/tests-expanded/test_auth_wasm32v1-none.rs index e58039e37..ef944a979 100644 --- a/tests-expanded/test_auth_wasm32v1-none.rs +++ b/tests-expanded/test_auth_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl, Address, Env, IntoVal}; pub struct ContractA; ///ContractAArgs is a type for building arg lists for functions defined in "ContractA". diff --git a/tests-expanded/test_bls_tests.rs b/tests-expanded/test_bls_tests.rs index cb8ead6bb..d8071fb0f 100644 --- a/tests-expanded/test_bls_tests.rs +++ b/tests-expanded/test_bls_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{ contract, contractimpl, contracttype, crypto::bls12_381::{Fp, Fp2, Fr, G1Affine, G2Affine}, @@ -198,59 +199,62 @@ impl TryFrom<&DummyProof> for soroban_sdk::xdr::ScMap { fn try_from(val: &DummyProof) -> Result { extern crate alloc; use soroban_sdk::TryFromVal; - soroban_sdk::xdr::ScMap::sorted_from(<[_]>::into_vec(::alloc::boxed::box_new([ - soroban_sdk::xdr::ScMapEntry { - key: soroban_sdk::xdr::ScSymbol( - "fp".try_into() + soroban_sdk::xdr::ScMap::sorted_from(<[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "fp".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(), + val: (&val.fp) + .try_into() .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - ) - .into(), - val: (&val.fp) - .try_into() - .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - }, - soroban_sdk::xdr::ScMapEntry { - key: soroban_sdk::xdr::ScSymbol( - "fp2" + }, + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "fp2" + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(), + val: (&val.fp2) .try_into() .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - ) - .into(), - val: (&val.fp2) - .try_into() - .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - }, - soroban_sdk::xdr::ScMapEntry { - key: soroban_sdk::xdr::ScSymbol( - "fr".try_into() + }, + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "fr".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(), + val: (&val.fr) + .try_into() .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - ) - .into(), - val: (&val.fr) - .try_into() - .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - }, - soroban_sdk::xdr::ScMapEntry { - key: soroban_sdk::xdr::ScSymbol( - "g1".try_into() + }, + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "g1".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(), + val: (&val.g1) + .try_into() .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - ) - .into(), - val: (&val.g1) - .try_into() - .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - }, - soroban_sdk::xdr::ScMapEntry { - key: soroban_sdk::xdr::ScSymbol( - "g2".try_into() + }, + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "g2".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(), + val: (&val.g2) + .try_into() .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - ) - .into(), - val: (&val.g2) - .try_into() - .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - }, - ]))) + }, + ]), + )) } } impl TryFrom for soroban_sdk::xdr::ScMap { @@ -1206,11 +1210,13 @@ static __Contract__492d85ed5a5d2cb14995f41e785b3df9c7fcf4af92b6d50ce2c9fa7c9b1e3 } __Contract__492d85ed5a5d2cb14995f41e785b3df9c7fcf4af92b6d50ce2c9fa7c9b1e350d_ctor___rust_ctor___ctor }; +#[cfg(test)] mod test { use super::*; use crate::{Contract, ContractClient}; use soroban_sdk::{bytesn, Env}; extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test_g1_mul"] #[doc(hidden)] pub const test_g1_mul: test::TestDescAndFn = test::TestDescAndFn { @@ -1284,6 +1290,7 @@ mod test { }; } extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test_g2_mul"] #[doc(hidden)] pub const test_g2_mul: test::TestDescAndFn = test::TestDescAndFn { @@ -1371,6 +1378,7 @@ mod test { }; } extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test_dummy_verify"] #[doc(hidden)] pub const test_dummy_verify: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_bls_wasm32v1-none.rs b/tests-expanded/test_bls_wasm32v1-none.rs index 7f320f2e1..30cb06ea0 100644 --- a/tests-expanded/test_bls_wasm32v1-none.rs +++ b/tests-expanded/test_bls_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{ contract, contractimpl, contracttype, crypto::bls12_381::{Fp, Fp2, Fr, G1Affine, G2Affine}, diff --git a/tests-expanded/test_constructor_tests.rs b/tests-expanded/test_constructor_tests.rs index e967d9153..b4a1a9432 100644 --- a/tests-expanded/test_constructor_tests.rs +++ b/tests-expanded/test_constructor_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl, contracttype, Env}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". @@ -947,6 +948,7 @@ static __Contract__99dc7227b32e52c8d11ead5dec3dd80bafdad62d74493e7341c782fd8cb13 __Contract__99dc7227b32e52c8d11ead5dec3dd80bafdad62d74493e7341c782fd8cb13593_ctor___rust_ctor___ctor }; extern crate test; +#[cfg(test)] #[rustc_test_marker = "test_constructor"] #[doc(hidden)] pub const test_constructor: test::TestDescAndFn = test::TestDescAndFn { @@ -1053,6 +1055,7 @@ fn test_constructor() { } } extern crate test; +#[cfg(test)] #[rustc_test_marker = "test_passing_no_constructor_arguments_causes_panic"] #[doc(hidden)] pub const test_passing_no_constructor_arguments_causes_panic: test::TestDescAndFn = @@ -1084,6 +1087,7 @@ fn test_passing_no_constructor_arguments_causes_panic() { let _ = env.register(Contract, ()); } extern crate test; +#[cfg(test)] #[rustc_test_marker = "test_missing_constructor_arguments_causes_panic"] #[doc(hidden)] pub const test_missing_constructor_arguments_causes_panic: test::TestDescAndFn = @@ -1115,6 +1119,7 @@ fn test_missing_constructor_arguments_causes_panic() { let _ = env.register(Contract, (100_u32,)); } extern crate test; +#[cfg(test)] #[rustc_test_marker = "test_passing_extra_constructor_arguments_causes_panic"] #[doc(hidden)] pub const test_passing_extra_constructor_arguments_causes_panic: test::TestDescAndFn = @@ -1146,6 +1151,7 @@ fn test_passing_extra_constructor_arguments_causes_panic() { let _ = env.register(Contract, (100_u32, 1000_i64, 123_u32)); } extern crate test; +#[cfg(test)] #[rustc_test_marker = "test_passing_incorrectly_typed_constructor_arguments_causes_panic"] #[doc(hidden)] pub const test_passing_incorrectly_typed_constructor_arguments_causes_panic: test::TestDescAndFn = diff --git a/tests-expanded/test_constructor_wasm32v1-none.rs b/tests-expanded/test_constructor_wasm32v1-none.rs index 8e13a3446..330c69836 100644 --- a/tests-expanded/test_constructor_wasm32v1-none.rs +++ b/tests-expanded/test_constructor_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl, contracttype, Env}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_contract_data_tests.rs b/tests-expanded/test_contract_data_tests.rs index 5ec29ef8c..9c48c9200 100644 --- a/tests-expanded/test_contract_data_tests.rs +++ b/tests-expanded/test_contract_data_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl, Env, Symbol}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_contract_data_wasm32v1-none.rs b/tests-expanded/test_contract_data_wasm32v1-none.rs index 5ca71926d..6a3835fdd 100644 --- a/tests-expanded/test_contract_data_wasm32v1-none.rs +++ b/tests-expanded/test_contract_data_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl, Env, Symbol}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_empty2_tests.rs b/tests-expanded/test_empty2_tests.rs index c1e410399..3b874ec59 100644 --- a/tests-expanded/test_empty2_tests.rs +++ b/tests-expanded/test_empty2_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". @@ -155,10 +156,12 @@ static __Contract__e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b } __Contract__e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_ctor___rust_ctor___ctor }; +#[cfg(test)] mod test { use crate::{Contract, ContractClient}; use soroban_sdk::Env; extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test_hello"] #[doc(hidden)] pub const test_hello: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_empty2_wasm32v1-none.rs b/tests-expanded/test_empty2_wasm32v1-none.rs index 4edc6a71d..1af6429f4 100644 --- a/tests-expanded/test_empty2_wasm32v1-none.rs +++ b/tests-expanded/test_empty2_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_empty_tests.rs b/tests-expanded/test_empty_tests.rs index 5236a8110..f8f51d99c 100644 --- a/tests-expanded/test_empty_tests.rs +++ b/tests-expanded/test_empty_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". @@ -292,10 +293,12 @@ static __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f } __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor___rust_ctor___ctor }; +#[cfg(test)] mod test { use crate::{Contract, ContractClient}; use soroban_sdk::Env; extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test_hello"] #[doc(hidden)] pub const test_hello: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_empty_wasm32v1-none.rs b/tests-expanded/test_empty_wasm32v1-none.rs index 4f56631dc..1d2f0f150 100644 --- a/tests-expanded/test_empty_wasm32v1-none.rs +++ b/tests-expanded/test_empty_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_errors_tests.rs b/tests-expanded/test_errors_tests.rs index 5fa081641..3a95468c0 100644 --- a/tests-expanded/test_errors_tests.rs +++ b/tests-expanded/test_errors_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{ contract, contracterror, contractimpl, contracttype, panic_with_error, symbol_short, Env, Symbol, @@ -642,6 +643,7 @@ impl Contract { ::core::panicking::panic("not implemented") } } + #[cfg(test)] pub fn persisted(env: Env) -> bool { env.storage() .persistent() @@ -668,15 +670,18 @@ impl Contract { } } #[doc(hidden)] +#[cfg(test)] #[allow(non_snake_case)] pub mod __Contract__persisted__spec { #[doc(hidden)] #[allow(non_snake_case)] #[allow(non_upper_case_globals)] + #[cfg(test)] pub static __SPEC_XDR_FN_PERSISTED: [u8; 36usize] = super::Contract::spec_xdr_persisted(); } impl Contract { #[allow(non_snake_case)] + #[cfg(test)] pub const fn spec_xdr_persisted() -> [u8; 36usize] { *b"\0\0\0\0\0\0\0\0\0\0\0\tpersisted\0\0\0\0\0\0\0\0\0\0\x01\0\0\0\x01" } @@ -761,6 +766,7 @@ impl<'a> ContractClient<'a> { } res } + #[cfg(test)] pub fn persisted(&self) -> bool { use core::ops::Not; let old_auth_manager = self @@ -798,6 +804,7 @@ impl<'a> ContractClient<'a> { } res } + #[cfg(test)] pub fn try_persisted( &self, ) -> Result< @@ -891,6 +898,7 @@ pub mod __Contract__hello { use super::*; } #[doc(hidden)] +#[cfg(test)] #[allow(non_snake_case)] pub mod __Contract__persisted { use super::*; @@ -950,10 +958,12 @@ static __Contract__dc66cfa30fdb08b17ba29ed3da0a0be599deef8db57bfb9cd9b3dcbf8c3be } __Contract__dc66cfa30fdb08b17ba29ed3da0a0be599deef8db57bfb9cd9b3dcbf8c3be498_ctor___rust_ctor___ctor }; +#[cfg(test)] mod test { use crate::{Contract, ContractClient, Error, Flag}; use soroban_sdk::{symbol_short, xdr, Env, InvokeError}; extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::hello_ok"] #[doc(hidden)] pub const hello_ok: test::TestDescAndFn = test::TestDescAndFn { @@ -1003,6 +1013,7 @@ mod test { } } extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::try_hello_ok"] #[doc(hidden)] pub const try_hello_ok: test::TestDescAndFn = test::TestDescAndFn { @@ -1055,6 +1066,7 @@ mod test { } } extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::try_hello_error"] #[doc(hidden)] pub const try_hello_error: test::TestDescAndFn = test::TestDescAndFn { @@ -1100,6 +1112,7 @@ mod test { } } extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::try_hello_error_panic"] #[doc(hidden)] pub const try_hello_error_panic: test::TestDescAndFn = test::TestDescAndFn { @@ -1145,6 +1158,7 @@ mod test { } } extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::try_hello_error_panic_string"] #[doc(hidden)] pub const try_hello_error_panic_string: test::TestDescAndFn = test::TestDescAndFn { @@ -1190,6 +1204,7 @@ mod test { } } extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::try_hello_error_unexpected_contract_error"] #[doc(hidden)] pub const try_hello_error_unexpected_contract_error: test::TestDescAndFn = @@ -1236,6 +1251,7 @@ mod test { } } extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::type_conversion"] #[doc(hidden)] pub const type_conversion: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_errors_wasm32v1-none.rs b/tests-expanded/test_errors_wasm32v1-none.rs index b321525be..6e6da9a29 100644 --- a/tests-expanded/test_errors_wasm32v1-none.rs +++ b/tests-expanded/test_errors_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{ contract, contracterror, contractimpl, contracttype, panic_with_error, symbol_short, Env, Symbol, diff --git a/tests-expanded/test_events_tests.rs b/tests-expanded/test_events_tests.rs index 38991c925..9bde77d9b 100644 --- a/tests-expanded/test_events_tests.rs +++ b/tests-expanded/test_events_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractevent, contractimpl, Address, Env, MuxedAddress}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". @@ -584,6 +585,7 @@ static __Contract__a60968eb9ff75bf813738a9007ab5bbea9f174011ab4092819ed57e87eb6b } __Contract__a60968eb9ff75bf813738a9007ab5bbea9f174011ab4092819ed57e87eb6b301_ctor___rust_ctor___ctor }; +#[cfg(test)] mod test { extern crate alloc; use crate::{Contract, ContractClient}; @@ -593,6 +595,7 @@ mod test { vec, Address, Env, IntoVal, MuxedAddress, Symbol, Val, }; extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test_event"] #[doc(hidden)] pub const test_event: test::TestDescAndFn = test::TestDescAndFn { @@ -666,6 +669,7 @@ mod test { }; } extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test_event_with_option_none"] #[doc(hidden)] pub const test_event_with_option_none: test::TestDescAndFn = test::TestDescAndFn { @@ -736,6 +740,7 @@ mod test { }; } extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test_no_events_recorded_for_failed_call"] #[doc(hidden)] pub const test_no_events_recorded_for_failed_call: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_events_wasm32v1-none.rs b/tests-expanded/test_events_wasm32v1-none.rs index 506c67e6e..43ae60136 100644 --- a/tests-expanded/test_events_wasm32v1-none.rs +++ b/tests-expanded/test_events_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractevent, contractimpl, Address, Env, MuxedAddress}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_fuzz_tests.rs b/tests-expanded/test_fuzz_tests.rs index 1b01a802c..690827270 100644 --- a/tests-expanded/test_fuzz_tests.rs +++ b/tests-expanded/test_fuzz_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl, U256}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_fuzz_wasm32v1-none.rs b/tests-expanded/test_fuzz_wasm32v1-none.rs index a818cd3df..7690e8ab7 100644 --- a/tests-expanded/test_fuzz_wasm32v1-none.rs +++ b/tests-expanded/test_fuzz_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl, U256}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_import_contract_tests.rs b/tests-expanded/test_import_contract_tests.rs index d4ee30c46..0c80053ee 100644 --- a/tests-expanded/test_import_contract_tests.rs +++ b/tests-expanded/test_import_contract_tests.rs @@ -1,12 +1,13 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl, Address, Env}; mod addcontract { - pub const WASM: &[u8] = b"\0asm\x01\0\0\0\x01\x14\x04`\x01~\x01~`\x02\x7f~\0`\x02~~\x01~`\0\0\x02\r\x02\x01i\x010\0\0\x01i\x01_\0\0\x03\x05\x04\x01\x02\x03\x03\x05\x03\x01\0\x10\x06!\x04\x7f\x01A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x07/\x05\x06memory\x02\0\x03add\0\x03\x01_\x03\x01\n__data_end\x03\x02\x0b__heap_base\x03\x03\n\x89\x02\x04]\x02\x01\x7f\x01~\x02@\x02@ \x01\xa7A\xff\x01q\"\x02A\xc0\0F\r\0\x02@ \x02A\x06F\r\0B\x01!\x03B\x83\x90\x80\x80\x80\x01!\x01\x0c\x02\x0b \x01B\x08\x88!\x01B\0!\x03\x0c\x01\x0bB\0!\x03 \x01\x10\x80\x80\x80\x80\0!\x01\x0b \0 \x037\x03\0 \0 \x017\x03\x08\x0b\x9a\x01\x01\x01\x7f#\x80\x80\x80\x80\0A\x10k\"\x02$\x80\x80\x80\x80\0 \x02 \0\x10\x82\x80\x80\x80\0\x02@\x02@ \x02(\x02\0A\x01F\r\0 \x02)\x03\x08!\0 \x02 \x01\x10\x82\x80\x80\x80\0 \x02(\x02\0A\x01F\r\0 \0 \x02)\x03\x08|\"\x01 \0T\r\x01\x02@\x02@ \x01B\xff\xff\xff\xff\xff\xff\xff\xff\0V\r\0 \x01B\x08\x86B\x06\x84!\0\x0c\x01\x0b \x01\x10\x81\x80\x80\x80\0!\0\x0b \x02A\x10j$\x80\x80\x80\x80\0 \0\x0f\x0b\0\x0b\x10\x84\x80\x80\x80\0\0\x0b\t\0\x10\x85\x80\x80\x80\0\0\x0b\x03\0\0\x0b\x0b\t\x01\0A\x80\x80\xc0\0\x0b\0\0K\x0econtractspecv0\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x06\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x06\0\0\0\x01\0\0\0\x06\0\x1e\x11contractenvmetav0\0\0\0\0\0\0\0\x17\0\0\0\0\0w\x0econtractmetav0\0\0\0\0\0\0\0\x05rsver\0\0\0\0\0\0\x061.90.0\0\0\0\0\0\0\0\0\0\x08rssdkver\0\0\0523.0.2#cf19bf2f23ea092ae4ddc41473b3968528ddc63c-dirty\0\0\0"; + pub const WASM: &[u8] = b"\0asm\x01\0\0\0\x01\x14\x04`\x01~\x01~`\x02\x7f~\0`\x02~~\x01~`\0\0\x02\r\x02\x01i\x010\0\0\x01i\x01_\0\0\x03\x05\x04\x01\x02\x03\x03\x05\x03\x01\0\x10\x06!\x04\x7f\x01A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x07/\x05\x06memory\x02\0\x03add\0\x03\x01_\x03\x01\n__data_end\x03\x02\x0b__heap_base\x03\x03\n\x89\x02\x04]\x02\x01\x7f\x01~\x02@\x02@ \x01\xa7A\xff\x01q\"\x02A\xc0\0F\r\0\x02@ \x02A\x06F\r\0B\x01!\x03B\x83\x90\x80\x80\x80\x01!\x01\x0c\x02\x0b \x01B\x08\x88!\x01B\0!\x03\x0c\x01\x0bB\0!\x03 \x01\x10\x80\x80\x80\x80\0!\x01\x0b \0 \x037\x03\0 \0 \x017\x03\x08\x0b\x9a\x01\x01\x01\x7f#\x80\x80\x80\x80\0A\x10k\"\x02$\x80\x80\x80\x80\0 \x02 \0\x10\x82\x80\x80\x80\0\x02@\x02@ \x02(\x02\0A\x01F\r\0 \x02)\x03\x08!\0 \x02 \x01\x10\x82\x80\x80\x80\0 \x02(\x02\0A\x01F\r\0 \0 \x02)\x03\x08|\"\x01 \0T\r\x01\x02@\x02@ \x01B\xff\xff\xff\xff\xff\xff\xff\xff\0V\r\0 \x01B\x08\x86B\x06\x84!\0\x0c\x01\x0b \x01\x10\x81\x80\x80\x80\0!\0\x0b \x02A\x10j$\x80\x80\x80\x80\0 \0\x0f\x0b\0\x0b\x10\x84\x80\x80\x80\0\0\x0b\t\0\x10\x85\x80\x80\x80\0\0\x0b\x03\0\0\x0b\x0b\t\x01\0A\x80\x80\xc0\0\x0b\0\0K\x0econtractspecv0\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x06\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x06\0\0\0\x01\0\0\0\x06\0\x1e\x11contractenvmetav0\0\0\0\0\0\0\0\x17\0\0\0\0\0+\x0econtractmetav0\0\0\0\0\0\0\0\x05rsver\0\0\0\0\0\0\x061.84.0\0\0"; pub trait Contract { fn add(env: soroban_sdk::Env, a: u64, b: u64) -> u64; } @@ -540,10 +541,12 @@ static __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e85117ee9 } __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e85117ee9756_ctor___rust_ctor___ctor }; +#[cfg(test)] mod test { use crate::{addcontract, Contract, ContractClient}; use soroban_sdk::Env; extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test_add"] #[doc(hidden)] pub const test_add: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_import_contract_wasm32v1-none.rs b/tests-expanded/test_import_contract_wasm32v1-none.rs index c1b2d2619..29bd751da 100644 --- a/tests-expanded/test_import_contract_wasm32v1-none.rs +++ b/tests-expanded/test_import_contract_wasm32v1-none.rs @@ -1,12 +1,13 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl, Address, Env}; mod addcontract { - pub const WASM: &[u8] = b"\0asm\x01\0\0\0\x01\x14\x04`\x01~\x01~`\x02\x7f~\0`\x02~~\x01~`\0\0\x02\r\x02\x01i\x010\0\0\x01i\x01_\0\0\x03\x05\x04\x01\x02\x03\x03\x05\x03\x01\0\x10\x06!\x04\x7f\x01A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x07/\x05\x06memory\x02\0\x03add\0\x03\x01_\x03\x01\n__data_end\x03\x02\x0b__heap_base\x03\x03\n\x89\x02\x04]\x02\x01\x7f\x01~\x02@\x02@ \x01\xa7A\xff\x01q\"\x02A\xc0\0F\r\0\x02@ \x02A\x06F\r\0B\x01!\x03B\x83\x90\x80\x80\x80\x01!\x01\x0c\x02\x0b \x01B\x08\x88!\x01B\0!\x03\x0c\x01\x0bB\0!\x03 \x01\x10\x80\x80\x80\x80\0!\x01\x0b \0 \x037\x03\0 \0 \x017\x03\x08\x0b\x9a\x01\x01\x01\x7f#\x80\x80\x80\x80\0A\x10k\"\x02$\x80\x80\x80\x80\0 \x02 \0\x10\x82\x80\x80\x80\0\x02@\x02@ \x02(\x02\0A\x01F\r\0 \x02)\x03\x08!\0 \x02 \x01\x10\x82\x80\x80\x80\0 \x02(\x02\0A\x01F\r\0 \0 \x02)\x03\x08|\"\x01 \0T\r\x01\x02@\x02@ \x01B\xff\xff\xff\xff\xff\xff\xff\xff\0V\r\0 \x01B\x08\x86B\x06\x84!\0\x0c\x01\x0b \x01\x10\x81\x80\x80\x80\0!\0\x0b \x02A\x10j$\x80\x80\x80\x80\0 \0\x0f\x0b\0\x0b\x10\x84\x80\x80\x80\0\0\x0b\t\0\x10\x85\x80\x80\x80\0\0\x0b\x03\0\0\x0b\x0b\t\x01\0A\x80\x80\xc0\0\x0b\0\0K\x0econtractspecv0\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x06\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x06\0\0\0\x01\0\0\0\x06\0\x1e\x11contractenvmetav0\0\0\0\0\0\0\0\x17\0\0\0\0\0w\x0econtractmetav0\0\0\0\0\0\0\0\x05rsver\0\0\0\0\0\0\x061.90.0\0\0\0\0\0\0\0\0\0\x08rssdkver\0\0\0523.0.2#cf19bf2f23ea092ae4ddc41473b3968528ddc63c-dirty\0\0\0"; + pub const WASM: &[u8] = b"\0asm\x01\0\0\0\x01\x14\x04`\x01~\x01~`\x02\x7f~\0`\x02~~\x01~`\0\0\x02\r\x02\x01i\x010\0\0\x01i\x01_\0\0\x03\x05\x04\x01\x02\x03\x03\x05\x03\x01\0\x10\x06!\x04\x7f\x01A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x07/\x05\x06memory\x02\0\x03add\0\x03\x01_\x03\x01\n__data_end\x03\x02\x0b__heap_base\x03\x03\n\x89\x02\x04]\x02\x01\x7f\x01~\x02@\x02@ \x01\xa7A\xff\x01q\"\x02A\xc0\0F\r\0\x02@ \x02A\x06F\r\0B\x01!\x03B\x83\x90\x80\x80\x80\x01!\x01\x0c\x02\x0b \x01B\x08\x88!\x01B\0!\x03\x0c\x01\x0bB\0!\x03 \x01\x10\x80\x80\x80\x80\0!\x01\x0b \0 \x037\x03\0 \0 \x017\x03\x08\x0b\x9a\x01\x01\x01\x7f#\x80\x80\x80\x80\0A\x10k\"\x02$\x80\x80\x80\x80\0 \x02 \0\x10\x82\x80\x80\x80\0\x02@\x02@ \x02(\x02\0A\x01F\r\0 \x02)\x03\x08!\0 \x02 \x01\x10\x82\x80\x80\x80\0 \x02(\x02\0A\x01F\r\0 \0 \x02)\x03\x08|\"\x01 \0T\r\x01\x02@\x02@ \x01B\xff\xff\xff\xff\xff\xff\xff\xff\0V\r\0 \x01B\x08\x86B\x06\x84!\0\x0c\x01\x0b \x01\x10\x81\x80\x80\x80\0!\0\x0b \x02A\x10j$\x80\x80\x80\x80\0 \0\x0f\x0b\0\x0b\x10\x84\x80\x80\x80\0\0\x0b\t\0\x10\x85\x80\x80\x80\0\0\x0b\x03\0\0\x0b\x0b\t\x01\0A\x80\x80\xc0\0\x0b\0\0K\x0econtractspecv0\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x06\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x06\0\0\0\x01\0\0\0\x06\0\x1e\x11contractenvmetav0\0\0\0\0\0\0\0\x17\0\0\0\0\0+\x0econtractmetav0\0\0\0\0\0\0\0\x05rsver\0\0\0\0\0\0\x061.84.0\0\0"; pub trait Contract { fn add(env: soroban_sdk::Env, a: u64, b: u64) -> u64; } diff --git a/tests-expanded/test_invoke_contract_tests.rs b/tests-expanded/test_invoke_contract_tests.rs index c1c1d8239..25806dcb4 100644 --- a/tests-expanded/test_invoke_contract_tests.rs +++ b/tests-expanded/test_invoke_contract_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl, symbol_short, vec, Address, Env, IntoVal}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". @@ -671,10 +672,12 @@ static __AddContract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65 } __AddContract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor }; +#[cfg(test)] mod test { use crate::{AddContract, Contract, ContractClient}; use soroban_sdk::Env; extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test_add"] #[doc(hidden)] pub const test_add: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_invoke_contract_wasm32v1-none.rs b/tests-expanded/test_invoke_contract_wasm32v1-none.rs index 6127c5008..301554712 100644 --- a/tests-expanded/test_invoke_contract_wasm32v1-none.rs +++ b/tests-expanded/test_invoke_contract_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl, symbol_short, vec, Address, Env, IntoVal}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_logging_tests.rs b/tests-expanded/test_logging_tests.rs index 0d91c718c..658230ee4 100644 --- a/tests-expanded/test_logging_tests.rs +++ b/tests-expanded/test_logging_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl, log, symbol_short, Env}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". @@ -375,11 +376,13 @@ static __Contract__2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9 } __Contract__2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824_ctor___rust_ctor___ctor }; +#[cfg(test)] mod test { extern crate std; use crate::{Contract, ContractClient}; use soroban_sdk::{testutils::Logs, Env}; extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test_logging"] #[doc(hidden)] pub const test_logging: test::TestDescAndFn = test::TestDescAndFn { @@ -409,14 +412,17 @@ mod test { client.hello(); env.logs().print(); if true { - let pats = <[_]>::into_vec(::alloc::boxed::box_new([ - "\"none\"", - "\"none\"", - "[\"one:\", one]", - "[\"one:\", one]", - "[\"one and two:\", one, two]", - "[\"one and two:\", one, two]", - ])); + let pats = <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + "\"none\"", + "\"none\"", + "[\"one:\", one]", + "[\"one:\", one]", + "[\"one and two:\", one, two]", + "[\"one and two:\", one, two]", + ]), + ); for (msg, pat) in env.logs().all().iter().zip(pats.iter()) { if !msg.contains(pat) { ::core::panicking::panic("assertion failed: msg.contains(pat)") diff --git a/tests-expanded/test_logging_wasm32v1-none.rs b/tests-expanded/test_logging_wasm32v1-none.rs index 0a9ec0e79..9b77acf39 100644 --- a/tests-expanded/test_logging_wasm32v1-none.rs +++ b/tests-expanded/test_logging_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl, log, symbol_short, Env}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_macros_tests.rs b/tests-expanded/test_macros_tests.rs index c7faa9f8c..152193d35 100644 --- a/tests-expanded/test_macros_tests.rs +++ b/tests-expanded/test_macros_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use proc_macros::parse_item_fn; use soroban_sdk::{contract, contractimpl}; pub struct Contract; @@ -293,10 +294,12 @@ static __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f } __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor___rust_ctor___ctor }; +#[cfg(test)] mod test { use crate::{Contract, ContractClient}; use soroban_sdk::Env; extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test_empty"] #[doc(hidden)] pub const test_empty: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_macros_wasm32v1-none.rs b/tests-expanded/test_macros_wasm32v1-none.rs index 27f0c0f87..74073b0c4 100644 --- a/tests-expanded/test_macros_wasm32v1-none.rs +++ b/tests-expanded/test_macros_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use proc_macros::parse_item_fn; use soroban_sdk::{contract, contractimpl}; pub struct Contract; diff --git a/tests-expanded/test_modular_tests.rs b/tests-expanded/test_modular_tests.rs index 22a8c2241..112c88726 100644 --- a/tests-expanded/test_modular_tests.rs +++ b/tests-expanded/test_modular_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl}; mod feat1 { use crate::Contract; @@ -347,9 +348,11 @@ mod feat2 { }; } mod test { + #![cfg(test)] use crate::{Contract, ContractClient}; use soroban_sdk::Env; extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test"] #[doc(hidden)] pub const test: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_modular_wasm32v1-none.rs b/tests-expanded/test_modular_wasm32v1-none.rs index ffe0d21be..16b25df27 100644 --- a/tests-expanded/test_modular_wasm32v1-none.rs +++ b/tests-expanded/test_modular_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl}; mod feat1 { use crate::Contract; diff --git a/tests-expanded/test_multiimpl_tests.rs b/tests-expanded/test_multiimpl_tests.rs index 6d767e266..e0586c95b 100644 --- a/tests-expanded/test_multiimpl_tests.rs +++ b/tests-expanded/test_multiimpl_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". @@ -609,10 +610,12 @@ static __Contract_Trait_2be3aa1100044a64e8135c570a7b382cebaca742493cf17b77052a7a } __Contract_Trait_2be3aa1100044a64e8135c570a7b382cebaca742493cf17b77052a7ae50fa889_ctor___rust_ctor___ctor }; +#[cfg(test)] mod test { use crate::{Contract, ContractClient}; use soroban_sdk::Env; extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test_hello"] #[doc(hidden)] pub const test_hello: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_multiimpl_wasm32v1-none.rs b/tests-expanded/test_multiimpl_wasm32v1-none.rs index eff397db0..63069fd00 100644 --- a/tests-expanded/test_multiimpl_wasm32v1-none.rs +++ b/tests-expanded/test_multiimpl_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_udt_tests.rs b/tests-expanded/test_udt_tests.rs index ff6bbef27..13f51f9dd 100644 --- a/tests-expanded/test_udt_tests.rs +++ b/tests-expanded/test_udt_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl, contracttype, Vec}; pub enum UdtEnum2 { A = 10, @@ -1103,14 +1104,17 @@ impl TryFrom<&UdtTuple> for soroban_sdk::xdr::ScVec { extern crate alloc; use soroban_sdk::TryFromVal; Ok(soroban_sdk::xdr::ScVec( - <[_]>::into_vec(::alloc::boxed::box_new([ - (&val.0) - .try_into() - .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - (&val.1) - .try_into() - .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - ])) + <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + (&val.0) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + (&val.1) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ]), + ) .try_into()?, )) } @@ -1527,38 +1531,41 @@ impl TryFrom<&UdtStruct> for soroban_sdk::xdr::ScMap { fn try_from(val: &UdtStruct) -> Result { extern crate alloc; use soroban_sdk::TryFromVal; - soroban_sdk::xdr::ScMap::sorted_from(<[_]>::into_vec(::alloc::boxed::box_new([ - soroban_sdk::xdr::ScMapEntry { - key: soroban_sdk::xdr::ScSymbol( - "a".try_into() + soroban_sdk::xdr::ScMap::sorted_from(<[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "a".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(), + val: (&val.a) + .try_into() .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - ) - .into(), - val: (&val.a) - .try_into() - .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - }, - soroban_sdk::xdr::ScMapEntry { - key: soroban_sdk::xdr::ScSymbol( - "b".try_into() + }, + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "b".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(), + val: (&val.b) + .try_into() .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - ) - .into(), - val: (&val.b) - .try_into() - .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - }, - soroban_sdk::xdr::ScMapEntry { - key: soroban_sdk::xdr::ScSymbol( - "c".try_into() + }, + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "c".try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ) + .into(), + val: (&val.c) + .try_into() .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - ) - .into(), - val: (&val.c) - .try_into() - .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - }, - ]))) + }, + ]), + )) } } impl TryFrom for soroban_sdk::xdr::ScMap { @@ -2131,10 +2138,12 @@ static __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4 } __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor }; +#[cfg(test)] mod test { use super::*; use soroban_sdk::{vec, xdr::ScVal, Bytes, Env, TryFromVal}; extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test_serializing"] #[doc(hidden)] pub const test_serializing: test::TestDescAndFn = test::TestDescAndFn { @@ -2188,6 +2197,7 @@ mod test { }; } extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test_add"] #[doc(hidden)] pub const test_add: test::TestDescAndFn = test::TestDescAndFn { @@ -2251,6 +2261,7 @@ mod test { }; } extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test_scval_accessibility_from_udt_types"] #[doc(hidden)] pub const test_scval_accessibility_from_udt_types: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_udt_wasm32v1-none.rs b/tests-expanded/test_udt_wasm32v1-none.rs index 5dd3f78f5..3216e3d81 100644 --- a/tests-expanded/test_udt_wasm32v1-none.rs +++ b/tests-expanded/test_udt_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl, contracttype, Vec}; pub enum UdtEnum2 { A = 10, diff --git a/tests-expanded/test_workspace_contract_tests.rs b/tests-expanded/test_workspace_contract_tests.rs index 8df3686f7..d852f9395 100644 --- a/tests-expanded/test_workspace_contract_tests.rs +++ b/tests-expanded/test_workspace_contract_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl}; use test_workspace_lib::Value; pub struct Contract; @@ -298,10 +299,12 @@ static __Contract__cd42404d52ad55ccfa9aca4adc828aa5800ad9d385a0671fbcbf724118320 } __Contract__cd42404d52ad55ccfa9aca4adc828aa5800ad9d385a0671fbcbf724118320619_ctor___rust_ctor___ctor }; +#[cfg(test)] mod test { use super::*; use soroban_sdk::Env; extern crate test; + #[cfg(test)] #[rustc_test_marker = "test::test_add"] #[doc(hidden)] pub const test_add: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_workspace_contract_wasm32v1-none.rs b/tests-expanded/test_workspace_contract_wasm32v1-none.rs index f6df76f7a..32fe1c861 100644 --- a/tests-expanded/test_workspace_contract_wasm32v1-none.rs +++ b/tests-expanded/test_workspace_contract_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::{contract, contractimpl}; use test_workspace_lib::Value; pub struct Contract; diff --git a/tests-expanded/test_workspace_lib_tests.rs b/tests-expanded/test_workspace_lib_tests.rs index 680a0c8c9..e019f3ee6 100644 --- a/tests-expanded/test_workspace_lib_tests.rs +++ b/tests-expanded/test_workspace_lib_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::contracttype; pub struct Value { pub value: i32, @@ -139,8 +140,9 @@ impl TryFrom<&Value> for soroban_sdk::xdr::ScMap { fn try_from(val: &Value) -> Result { extern crate alloc; use soroban_sdk::TryFromVal; - soroban_sdk::xdr::ScMap::sorted_from(<[_]>::into_vec(::alloc::boxed::box_new([ - soroban_sdk::xdr::ScMapEntry { + soroban_sdk::xdr::ScMap::sorted_from(<[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([soroban_sdk::xdr::ScMapEntry { key: soroban_sdk::xdr::ScSymbol( "value" .try_into() @@ -150,8 +152,8 @@ impl TryFrom<&Value> for soroban_sdk::xdr::ScMap { val: (&val.value) .try_into() .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - }, - ]))) + }]), + )) } } impl TryFrom for soroban_sdk::xdr::ScMap { diff --git a/tests-expanded/test_workspace_lib_wasm32v1-none.rs b/tests-expanded/test_workspace_lib_wasm32v1-none.rs new file mode 100644 index 000000000..9c4e36b5c --- /dev/null +++ b/tests-expanded/test_workspace_lib_wasm32v1-none.rs @@ -0,0 +1,89 @@ +#![feature(prelude_import)] +#![no_std] +#[prelude_import] +use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; +use soroban_sdk::contracttype; +pub struct Value { + pub value: i32, +} +#[automatically_derived] +impl ::core::fmt::Debug for Value { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_struct_field1_finish(f, "Value", "value", &&self.value) + } +} +#[automatically_derived] +impl ::core::cmp::Eq for Value { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () { + let _: ::core::cmp::AssertParamIsEq; + } +} +#[automatically_derived] +impl ::core::marker::StructuralPartialEq for Value {} +#[automatically_derived] +impl ::core::cmp::PartialEq for Value { + #[inline] + fn eq(&self, other: &Value) -> bool { + self.value == other.value + } +} +#[link_section = "contractspecv0"] +pub static __SPEC_XDR_TYPE_VALUE: [u8; 48usize] = Value::spec_xdr(); +impl Value { + pub const fn spec_xdr() -> [u8; 48usize] { + *b"\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\x05Value\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\x05value\0\0\0\0\0\0\x05" + } +} +impl soroban_sdk::TryFromVal for Value { + type Error = soroban_sdk::ConversionError; + fn try_from_val( + env: &soroban_sdk::Env, + val: &soroban_sdk::Val, + ) -> Result { + use soroban_sdk::{ConversionError, EnvBase, MapObject, TryIntoVal, Val}; + const KEYS: [&'static str; 1usize] = ["value"]; + let mut vals: [Val; 1usize] = [Val::VOID.to_val(); 1usize]; + let map: MapObject = val.try_into().map_err(|_| ConversionError)?; + env.map_unpack_to_slice(map, &KEYS, &mut vals) + .map_err(|_| ConversionError)?; + Ok(Self { + value: vals[0] + .try_into_val(env) + .map_err(|_| soroban_sdk::ConversionError)?, + }) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + fn try_from_val( + env: &soroban_sdk::Env, + val: &Value, + ) -> Result { + use soroban_sdk::{ConversionError, EnvBase, TryIntoVal, Val}; + const KEYS: [&'static str; 1usize] = ["value"]; + let vals: [Val; 1usize] = [(&val.value) + .try_into_val(env) + .map_err(|_| ConversionError)?]; + Ok(env + .map_new_from_slices(&KEYS, &vals) + .map_err(|_| ConversionError)? + .into()) + } +} +impl soroban_sdk::TryFromVal for soroban_sdk::Val { + type Error = soroban_sdk::ConversionError; + #[inline(always)] + fn try_from_val( + env: &soroban_sdk::Env, + val: &&Value, + ) -> Result { + <_ as soroban_sdk::TryFromVal>::try_from_val(env, *val) + } +} diff --git a/tests-expanded/test_zero_tests.rs b/tests-expanded/test_zero_tests.rs index 6c2443a14..5dc2a00a9 100644 --- a/tests-expanded/test_zero_tests.rs +++ b/tests-expanded/test_zero_tests.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::contract; struct _Contract; ///_ContractArgs is a type for building arg lists for functions defined in "_Contract". diff --git a/tests-expanded/test_zero_wasm32v1-none.rs b/tests-expanded/test_zero_wasm32v1-none.rs index 4fdd0f007..3961de10d 100644 --- a/tests-expanded/test_zero_wasm32v1-none.rs +++ b/tests-expanded/test_zero_wasm32v1-none.rs @@ -1,9 +1,10 @@ #![feature(prelude_import)] #![no_std] -#[macro_use] -extern crate core; #[prelude_import] use core::prelude::rust_2021::*; +#[macro_use] +extern crate core; +extern crate compiler_builtins as _; use soroban_sdk::contract; struct _Contract; ///_ContractArgs is a type for building arg lists for functions defined in "_Contract". From 5c3123dfdf1da54c5fde4771c7e234e316da7993 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 30 Sep 2025 13:32:53 +1000 Subject: [PATCH 09/24] Recombine the build and test ci runs --- .github/workflows/rust.yml | 64 +++++--------------------------------- 1 file changed, 8 insertions(+), 56 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index c6d452150..a9bb7f390 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -21,7 +21,7 @@ jobs: complete: if: always() - needs: [fmt, check-git-rev-deps, semver-checks, build, test, build-fuzz, docs, readme, migration-docs] + needs: [fmt, check-git-rev-deps, semver-checks, build-and-test, build-fuzz, docs, readme, migration-docs] runs-on: ubuntu-latest steps: - if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') @@ -70,7 +70,7 @@ jobs: --exclude soroban-token-spec --exclude stellar-asset-spec - build: + build-and-test: strategy: fail-fast: false matrix: @@ -108,62 +108,14 @@ jobs: with: name: cargo-hack version: 0.5.28 - - run: make build-libs - - run: make build-test-wasms TEST_CRATES_RUSTUP_TOOLCHAIN= - - name: Upload test wasms - uses: actions/upload-artifact@v4 - with: - name: test-wasms-${{ matrix.rust }}-${{ matrix.sys.target }} - path: target/wasm32v1-none/release/test_*.wasm - retention-days: ${{ env.ARTIFACT_RETENTION_DAYS_FOR_TEST_WASMS }} - - test: - needs: build - strategy: - fail-fast: false - matrix: - rust: [msrv, latest] - sys: - - os: ubuntu-latest - target: x86_64-unknown-linux-gnu - - os: ubuntu-24.04-arm - target: aarch64-unknown-linux-gnu - - os: macos-15-intel - target: x86_64-apple-darwin - - os: macos-latest - target: aarch64-apple-darwin - - os: windows-latest - target: x86_64-pc-windows-msvc - runs-on: ${{ matrix.sys.os }} - steps: - - uses: actions/checkout@v3 - - uses: stellar/actions/rust-cache@main - - name: Use the minimum supported Rust version - if: matrix.rust == 'msrv' - run: | - msrv="$(cargo metadata --format-version 1 --no-deps | jq -r '.packages | map(.rust_version) | map(values) | min')" - rustup override set $msrv - rustup component add clippy rustfmt - - name: Error on warnings only for msrv - if: matrix.rust == 'msrv' - run: echo RUSTFLAGS='-Dwarnings' >> $GITHUB_ENV - - run: rustup update - - run: cargo version - - run: rustup target add ${{ matrix.sys.target }} - - run: rustup target add wasm32v1-none - - run: echo CARGO_BUILD_TARGET='${{ matrix.sys.target }}' >> $GITHUB_ENV - - uses: stellar/binaries@v45 - with: - name: cargo-hack - version: 0.5.28 - - name: Restore test wasms for tests from one of the msrv builds - uses: actions/download-artifact@v5 - with: - name: test-wasms-msrv-x86_64-unknown-linux-gnu - path: target/wasm32v1-none/release/ + - name: Build libs with current rust toolchain + run: make build-libs + - name: Build test wasms with current rust toolchain + run: make build-test-wasms TEST_CRATES_RUSTUP_TOOLCHAIN= - name: Clear test snapshots for checking no diffs exists after test run run: rm -fr **/test_snapshots - - run: make test + - name: Run test with current rust toolchain (will also rebuild test wasms with msrv rust toolchain for test reproducibility) + run: make build-test-wasms test - name: Check no diffs exist run: git add -N . && git diff HEAD --exit-code From e234ee1f36dd408634bfbf994139a51214985283 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 30 Sep 2025 15:05:13 +1000 Subject: [PATCH 10/24] combine msrv and latest tests into single runs --- .github/workflows/rust.yml | 47 +++++++++++++++++++------------------- Makefile | 19 +++++++++++---- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a9bb7f390..12a8ef137 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -74,7 +74,6 @@ jobs: strategy: fail-fast: false matrix: - rust: [msrv, latest] sys: - os: ubuntu-latest target: x86_64-unknown-linux-gnu @@ -90,34 +89,36 @@ jobs: steps: - uses: actions/checkout@v3 - uses: stellar/actions/rust-cache@main - - name: Use the minimum supported Rust version - if: matrix.rust == 'msrv' + - name: Install msrv run: | - msrv="$(cargo metadata --format-version 1 --no-deps | jq -r '.packages | map(.rust_version) | map(values) | min')" - rustup override set $msrv - rustup component add clippy rustfmt - - name: Error on warnings only for msrv - if: matrix.rust == 'msrv' - run: echo RUSTFLAGS='-Dwarnings' >> $GITHUB_ENV - - run: rustup update - - run: cargo version - - run: rustup target add ${{ matrix.sys.target }} - - run: rustup target add wasm32v1-none + msrv="$(make msrv)" + rustup install $msrv + rustup target add --toolchain $msrv ${{ matrix.sys.target }} + rustup target add --toolchain $msrv wasm32v1-none + - name: Install latest + run: | + rustup update + rustup target add ${{ matrix.sys.target }} + rustup target add wasm32v1-none - run: echo CARGO_BUILD_TARGET='${{ matrix.sys.target }}' >> $GITHUB_ENV - uses: stellar/binaries@v45 with: name: cargo-hack version: 0.5.28 - - name: Build libs with current rust toolchain - run: make build-libs - - name: Build test wasms with current rust toolchain - run: make build-test-wasms TEST_CRATES_RUSTUP_TOOLCHAIN= - - name: Clear test snapshots for checking no diffs exists after test run - run: rm -fr **/test_snapshots - - name: Run test with current rust toolchain (will also rebuild test wasms with msrv rust toolchain for test reproducibility) - run: make build-test-wasms test - - name: Check no diffs exist - run: git add -N . && git diff HEAD --exit-code + # Build with latest Rust + - run: make build-libs + - run: make build-test-wasms + # Build with MSRV Rust + - run: make build-libs RUST=msrv + - run: make build-test-wasms RUST=msrv + # Run tests with latest + - run: rm -fr **/test_snapshots + - run: make test + - run: git add -N . && git diff HEAD --exit-code + # Run tests with MSRV + - run: rm -fr **/test_snapshots + - run: make test RUST=msrv + - run: git add -N . && git diff HEAD --exit-code build-fuzz: runs-on: ubuntu-latest diff --git a/Makefile b/Makefile index 1fca66cf2..cec8e8f88 100644 --- a/Makefile +++ b/Makefile @@ -2,14 +2,22 @@ LIB_CRATES = $(shell cargo metadata --no-deps --format-version 1 | jq -r '.packa TEST_CRATES = $(shell cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name | startswith("test_")) | .name' | tr '\n' ' ') MSRV = $(shell cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "soroban-sdk") | .rust_version') -TEST_CRATES_RUSTUP_TOOLCHAIN?=$(MSRV) -all: check test +RUST?= +ifeq ($(RUST),msrv) +export RUSTUP_TOOLCHAIN=$(MSRV) +else +export RUSTUP_TOOLCHAIN=$(RUST) +endif +ifeq ($(RUSTUP_TOOLCHAIN),$(MSRV)) export RUSTFLAGS=-Dwarnings +endif CARGO_DOC_ARGS?=--open +default: test + doc: fmt cargo test --doc $(foreach c,$(LIB_CRATES),--package $(c)) --features testutils,alloc,hazmat cargo +nightly doc --no-deps $(foreach c,$(LIB_CRATES),--package $(c)) --all-features $(CARGO_DOC_ARGS) @@ -23,9 +31,7 @@ build-libs: fmt cargo hack build --release $(foreach c,$(LIB_CRATES),--package $(c)) build-test-wasms: fmt - # Build the test wasms with MSRV by default, with some meta disabled for - # binary stability for tests. - RUSTUP_TOOLCHAIN=$(TEST_CRATES_RUSTUP_TOOLCHAIN) \ + # Build the test wasms with some meta disabled for binary stability for tests. RUSTFLAGS='--cfg soroban_sdk_internal_no_rssdkver_meta' \ cargo hack build --release --target wasm32v1-none $(foreach c,$(TEST_CRATES),--package $(c)) ; \ cd target/wasm32v1-none/release/ && \ @@ -48,3 +54,6 @@ fmt: clean: cargo clean + +msrv: + @echo $(MSRV) From d6867ff9ec87d7bf2ba004fca5ad0dca2ad6b88a Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 30 Sep 2025 15:10:39 +1000 Subject: [PATCH 11/24] Revert "combine msrv and latest tests into single runs" This reverts commit e234ee1f36dd408634bfbf994139a51214985283. --- .github/workflows/rust.yml | 47 +++++++++++++++++++------------------- Makefile | 19 ++++----------- 2 files changed, 28 insertions(+), 38 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 12a8ef137..a9bb7f390 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -74,6 +74,7 @@ jobs: strategy: fail-fast: false matrix: + rust: [msrv, latest] sys: - os: ubuntu-latest target: x86_64-unknown-linux-gnu @@ -89,36 +90,34 @@ jobs: steps: - uses: actions/checkout@v3 - uses: stellar/actions/rust-cache@main - - name: Install msrv + - name: Use the minimum supported Rust version + if: matrix.rust == 'msrv' run: | - msrv="$(make msrv)" - rustup install $msrv - rustup target add --toolchain $msrv ${{ matrix.sys.target }} - rustup target add --toolchain $msrv wasm32v1-none - - name: Install latest - run: | - rustup update - rustup target add ${{ matrix.sys.target }} - rustup target add wasm32v1-none + msrv="$(cargo metadata --format-version 1 --no-deps | jq -r '.packages | map(.rust_version) | map(values) | min')" + rustup override set $msrv + rustup component add clippy rustfmt + - name: Error on warnings only for msrv + if: matrix.rust == 'msrv' + run: echo RUSTFLAGS='-Dwarnings' >> $GITHUB_ENV + - run: rustup update + - run: cargo version + - run: rustup target add ${{ matrix.sys.target }} + - run: rustup target add wasm32v1-none - run: echo CARGO_BUILD_TARGET='${{ matrix.sys.target }}' >> $GITHUB_ENV - uses: stellar/binaries@v45 with: name: cargo-hack version: 0.5.28 - # Build with latest Rust - - run: make build-libs - - run: make build-test-wasms - # Build with MSRV Rust - - run: make build-libs RUST=msrv - - run: make build-test-wasms RUST=msrv - # Run tests with latest - - run: rm -fr **/test_snapshots - - run: make test - - run: git add -N . && git diff HEAD --exit-code - # Run tests with MSRV - - run: rm -fr **/test_snapshots - - run: make test RUST=msrv - - run: git add -N . && git diff HEAD --exit-code + - name: Build libs with current rust toolchain + run: make build-libs + - name: Build test wasms with current rust toolchain + run: make build-test-wasms TEST_CRATES_RUSTUP_TOOLCHAIN= + - name: Clear test snapshots for checking no diffs exists after test run + run: rm -fr **/test_snapshots + - name: Run test with current rust toolchain (will also rebuild test wasms with msrv rust toolchain for test reproducibility) + run: make build-test-wasms test + - name: Check no diffs exist + run: git add -N . && git diff HEAD --exit-code build-fuzz: runs-on: ubuntu-latest diff --git a/Makefile b/Makefile index cec8e8f88..1fca66cf2 100644 --- a/Makefile +++ b/Makefile @@ -2,22 +2,14 @@ LIB_CRATES = $(shell cargo metadata --no-deps --format-version 1 | jq -r '.packa TEST_CRATES = $(shell cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name | startswith("test_")) | .name' | tr '\n' ' ') MSRV = $(shell cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "soroban-sdk") | .rust_version') +TEST_CRATES_RUSTUP_TOOLCHAIN?=$(MSRV) -RUST?= -ifeq ($(RUST),msrv) -export RUSTUP_TOOLCHAIN=$(MSRV) -else -export RUSTUP_TOOLCHAIN=$(RUST) -endif +all: check test -ifeq ($(RUSTUP_TOOLCHAIN),$(MSRV)) export RUSTFLAGS=-Dwarnings -endif CARGO_DOC_ARGS?=--open -default: test - doc: fmt cargo test --doc $(foreach c,$(LIB_CRATES),--package $(c)) --features testutils,alloc,hazmat cargo +nightly doc --no-deps $(foreach c,$(LIB_CRATES),--package $(c)) --all-features $(CARGO_DOC_ARGS) @@ -31,7 +23,9 @@ build-libs: fmt cargo hack build --release $(foreach c,$(LIB_CRATES),--package $(c)) build-test-wasms: fmt - # Build the test wasms with some meta disabled for binary stability for tests. + # Build the test wasms with MSRV by default, with some meta disabled for + # binary stability for tests. + RUSTUP_TOOLCHAIN=$(TEST_CRATES_RUSTUP_TOOLCHAIN) \ RUSTFLAGS='--cfg soroban_sdk_internal_no_rssdkver_meta' \ cargo hack build --release --target wasm32v1-none $(foreach c,$(TEST_CRATES),--package $(c)) ; \ cd target/wasm32v1-none/release/ && \ @@ -54,6 +48,3 @@ fmt: clean: cargo clean - -msrv: - @echo $(MSRV) From dad1edcb6aa4fcf250365137757bce78150e1ad5 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 30 Sep 2025 16:05:26 +1000 Subject: [PATCH 12/24] update rust workflow to use makefile for msrv and add target updates --- .github/workflows/rust.yml | 10 +++++----- Makefile | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a9bb7f390..d39b5a625 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -93,16 +93,16 @@ jobs: - name: Use the minimum supported Rust version if: matrix.rust == 'msrv' run: | - msrv="$(cargo metadata --format-version 1 --no-deps | jq -r '.packages | map(.rust_version) | map(values) | min')" + msrv="$(make msrv)" rustup override set $msrv rustup component add clippy rustfmt + - run: | + rustup update + rustup target add ${{ matrix.sys.target }} + rustup target add wasm32v1-none - name: Error on warnings only for msrv if: matrix.rust == 'msrv' run: echo RUSTFLAGS='-Dwarnings' >> $GITHUB_ENV - - run: rustup update - - run: cargo version - - run: rustup target add ${{ matrix.sys.target }} - - run: rustup target add wasm32v1-none - run: echo CARGO_BUILD_TARGET='${{ matrix.sys.target }}' >> $GITHUB_ENV - uses: stellar/binaries@v45 with: diff --git a/Makefile b/Makefile index 1fca66cf2..324e96aa0 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,6 @@ TEST_CRATES_RUSTUP_TOOLCHAIN?=$(MSRV) all: check test -export RUSTFLAGS=-Dwarnings - CARGO_DOC_ARGS?=--open doc: fmt @@ -48,3 +46,6 @@ fmt: clean: cargo clean + +msrv: + @echo $(MSRV) From 11770c30f1f55fb782eb0e7e79e43f931b6b5f72 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 30 Sep 2025 16:14:55 +1000 Subject: [PATCH 13/24] fix installed rusts --- .github/workflows/rust.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d39b5a625..d8841e3ea 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -90,16 +90,22 @@ jobs: steps: - uses: actions/checkout@v3 - uses: stellar/actions/rust-cache@main - - name: Use the minimum supported Rust version + - name: Install minimum supported Rust version if: matrix.rust == 'msrv' run: | msrv="$(make msrv)" - rustup override set $msrv + rustup install $msrv rustup component add clippy rustfmt - - run: | + rustup target add --toolchain $msrv ${{ matrix.sys.target }} + rustup target add --toolchain $msrv wasm32v1-none + - name: Install latest Rust version + run: | rustup update rustup target add ${{ matrix.sys.target }} rustup target add wasm32v1-none + - name: Use the minimum supported Rust version + if: matrix.rust == 'msrv' + run: echo RUSTUP_TOOLCHAIN="$(make msrv) >> $GITHUB_ENV - name: Error on warnings only for msrv if: matrix.rust == 'msrv' run: echo RUSTFLAGS='-Dwarnings' >> $GITHUB_ENV From 2f59f5c310dce6648a5273a9bdbd92f2b9d7c4f0 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 30 Sep 2025 16:15:47 +1000 Subject: [PATCH 14/24] update rust installation to use msrv and latest versions --- .github/workflows/rust.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 32a197790..74ebe1399 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -174,8 +174,15 @@ jobs: steps: - uses: actions/checkout@v5 - uses: stellar/actions/rust-cache@main - - run: rustup update - - run: rustup target add wasm32v1-none + - name: Install minimum supported Rust version + if: matrix.rust == 'msrv' + run: | + msrv="$(make msrv)" + rustup install $msrv + rustup target add --toolchain $msrv wasm32v1-none + - name: Install latest Rust version + run: | + rustup update - uses: stellar/binaries@v45 with: name: cargo-hack From c1ed995f109e6848e21719a4b2da3f17e0a43f64 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 30 Sep 2025 16:49:14 +1000 Subject: [PATCH 15/24] few fix ups --- .github/workflows/rust.yml | 46 ++++++++++++++++++++++++-------------- Makefile | 13 ++++++----- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index c6d452150..1e88f4e41 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -90,19 +90,25 @@ jobs: steps: - uses: actions/checkout@v3 - uses: stellar/actions/rust-cache@main - - name: Use the minimum supported Rust version + - name: Install minimum supported rust version if: matrix.rust == 'msrv' run: | - msrv="$(cargo metadata --format-version 1 --no-deps | jq -r '.packages | map(.rust_version) | map(values) | min')" - rustup override set $msrv - rustup component add clippy rustfmt + msrv="$(make msrv)" + rustup install $msrv + rustup target add --toolchain $msrv ${{ matrix.sys.target }} + rustup target add --toolchain $msrv wasm32v1-none + - name: Install latest rust version + if: matrix.rust == 'latest' + run: | + rustup update + rustup target add ${{ matrix.sys.target }} + rustup target add wasm32v1-none + - name: Use the minimum supported rust version + if: matrix.rust == 'msrv' + run: echo RUSTUP_TOOLCHAIN="$(make msrv)" >> $GITHUB_ENV - name: Error on warnings only for msrv if: matrix.rust == 'msrv' run: echo RUSTFLAGS='-Dwarnings' >> $GITHUB_ENV - - run: rustup update - - run: cargo version - - run: rustup target add ${{ matrix.sys.target }} - - run: rustup target add wasm32v1-none - run: echo CARGO_BUILD_TARGET='${{ matrix.sys.target }}' >> $GITHUB_ENV - uses: stellar/binaries@v45 with: @@ -138,19 +144,25 @@ jobs: steps: - uses: actions/checkout@v3 - uses: stellar/actions/rust-cache@main - - name: Use the minimum supported Rust version + - name: Install minimum supported rust version if: matrix.rust == 'msrv' run: | - msrv="$(cargo metadata --format-version 1 --no-deps | jq -r '.packages | map(.rust_version) | map(values) | min')" - rustup override set $msrv - rustup component add clippy rustfmt + msrv="$(make msrv)" + rustup install $msrv + rustup target add --toolchain $msrv ${{ matrix.sys.target }} + rustup target add --toolchain $msrv wasm32v1-none + - name: Install latest rust version + if: matrix.rust == 'latest' + run: | + rustup update + rustup target add ${{ matrix.sys.target }} + rustup target add wasm32v1-none + - name: Use the minimum supported rust version + if: matrix.rust == 'msrv' + run: echo RUSTUP_TOOLCHAIN="$(make msrv)" >> $GITHUB_ENV - name: Error on warnings only for msrv if: matrix.rust == 'msrv' run: echo RUSTFLAGS='-Dwarnings' >> $GITHUB_ENV - - run: rustup update - - run: cargo version - - run: rustup target add ${{ matrix.sys.target }} - - run: rustup target add wasm32v1-none - run: echo CARGO_BUILD_TARGET='${{ matrix.sys.target }}' >> $GITHUB_ENV - uses: stellar/binaries@v45 with: @@ -163,7 +175,7 @@ jobs: path: target/wasm32v1-none/release/ - name: Clear test snapshots for checking no diffs exists after test run run: rm -fr **/test_snapshots - - run: make test + - run: make test-only - name: Check no diffs exist run: git add -N . && git diff HEAD --exit-code diff --git a/Makefile b/Makefile index 1fca66cf2..7793d0801 100644 --- a/Makefile +++ b/Makefile @@ -4,17 +4,17 @@ TEST_CRATES = $(shell cargo metadata --no-deps --format-version 1 | jq -r '.pack MSRV = $(shell cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "soroban-sdk") | .rust_version') TEST_CRATES_RUSTUP_TOOLCHAIN?=$(MSRV) -all: check test - -export RUSTFLAGS=-Dwarnings - CARGO_DOC_ARGS?=--open +default: test + doc: fmt cargo test --doc $(foreach c,$(LIB_CRATES),--package $(c)) --features testutils,alloc,hazmat cargo +nightly doc --no-deps $(foreach c,$(LIB_CRATES),--package $(c)) --all-features $(CARGO_DOC_ARGS) -test: fmt build-test-wasms +test: fmt build-test-wasms test-only + +test-only: cargo hack --feature-powerset --ignore-unknown-features --features testutils --exclude-features docs test build: build-libs build-test-wasms @@ -48,3 +48,6 @@ fmt: clean: cargo clean + +msrv: + @echo $(MSRV) From db7882d9eac62d874f3a658b24a3cb9fb0dbba80 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 30 Sep 2025 16:56:23 +1000 Subject: [PATCH 16/24] add clippy and rustfmt components for msrv toolchain --- .github/workflows/rust.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1e88f4e41..395341c1b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -95,6 +95,7 @@ jobs: run: | msrv="$(make msrv)" rustup install $msrv + rustup component add --toolchain $msrv clippy rustfmt rustup target add --toolchain $msrv ${{ matrix.sys.target }} rustup target add --toolchain $msrv wasm32v1-none - name: Install latest rust version @@ -149,6 +150,7 @@ jobs: run: | msrv="$(make msrv)" rustup install $msrv + rustup component add --toolchain $msrv clippy rustfmt rustup target add --toolchain $msrv ${{ matrix.sys.target }} rustup target add --toolchain $msrv wasm32v1-none - name: Install latest rust version From 78a33d62815643a7b3167e99f4734dfa1de0ba97 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 30 Sep 2025 17:02:05 +1000 Subject: [PATCH 17/24] add conditional check for latest rust version --- .github/workflows/rust.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index c52632e83..f9a455eb8 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -223,6 +223,7 @@ jobs: rustup install $msrv rustup target add --toolchain $msrv wasm32v1-none - name: Install latest rust version + if: matrix.rust == 'latest' run: | rustup update - uses: stellar/binaries@v45 From ba10ad4b9e65a741c0594fd6eda1cec559a6e4b0 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 30 Sep 2025 17:02:59 +1000 Subject: [PATCH 18/24] add build-fuzz job to workflow --- .github/workflows/rust.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index f9a455eb8..699842f1c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -181,6 +181,18 @@ jobs: - name: Check no diffs exist run: git add -N . && git diff HEAD --exit-code + build-fuzz: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: stellar/actions/rust-cache@main + - run: rustup install nightly + - uses: stellar/binaries@v45 + with: + name: cargo-fuzz + version: 0.13.1 + - run: make build-fuzz + docs: runs-on: ubuntu-latest steps: From 04911468b2b82feefda7caf67e36ff6fa842e65f Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 30 Sep 2025 17:03:22 +1000 Subject: [PATCH 19/24] add check for uncommitted changes in ci --- .github/workflows/rust.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 699842f1c..9ae99f6d1 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -192,6 +192,8 @@ jobs: name: cargo-fuzz version: 0.13.1 - run: make build-fuzz + - name: Check no diffs exist + run: git add -N . && git diff HEAD --exit-code docs: runs-on: ubuntu-latest From a7a839422737a66f000a27d9e83661059ebb4597 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 30 Sep 2025 17:33:57 +1000 Subject: [PATCH 20/24] add cargo version check to workflows --- .github/workflows/rust.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 395341c1b..0839f428d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -115,6 +115,7 @@ jobs: with: name: cargo-hack version: 0.5.28 + - run: cargo version - run: make build-libs - run: make build-test-wasms TEST_CRATES_RUSTUP_TOOLCHAIN= - name: Upload test wasms @@ -177,6 +178,7 @@ jobs: path: target/wasm32v1-none/release/ - name: Clear test snapshots for checking no diffs exists after test run run: rm -fr **/test_snapshots + - run: cargo version - run: make test-only - name: Check no diffs exist run: git add -N . && git diff HEAD --exit-code From b484483bab8eb90807343ddedda16ff2fa4553dc Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 30 Sep 2025 17:50:30 +1000 Subject: [PATCH 21/24] update rust workflow to use toolchain variable and cache --- .github/workflows/rust.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 0839f428d..a6dd35722 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -89,7 +89,6 @@ jobs: runs-on: ${{ matrix.sys.os }} steps: - uses: actions/checkout@v3 - - uses: stellar/actions/rust-cache@main - name: Install minimum supported rust version if: matrix.rust == 'msrv' run: | @@ -107,6 +106,10 @@ jobs: - name: Use the minimum supported rust version if: matrix.rust == 'msrv' run: echo RUSTUP_TOOLCHAIN="$(make msrv)" >> $GITHUB_ENV + - name: Set latest toolchain + if: matrix.rust == 'latest' + run: echo RUSTUP_TOOLCHAIN="$(rustup show active-toolchain | cut -d' ' -f1)" >> $GITHUB_ENV + - uses: stellar/actions/rust-cache@main - name: Error on warnings only for msrv if: matrix.rust == 'msrv' run: echo RUSTFLAGS='-Dwarnings' >> $GITHUB_ENV @@ -117,7 +120,7 @@ jobs: version: 0.5.28 - run: cargo version - run: make build-libs - - run: make build-test-wasms TEST_CRATES_RUSTUP_TOOLCHAIN= + - run: make build-test-wasms TEST_CRATES_RUSTUP_TOOLCHAIN=$RUSTUP_TOOLCHAIN - name: Upload test wasms uses: actions/upload-artifact@v4 with: @@ -145,7 +148,6 @@ jobs: runs-on: ${{ matrix.sys.os }} steps: - uses: actions/checkout@v3 - - uses: stellar/actions/rust-cache@main - name: Install minimum supported rust version if: matrix.rust == 'msrv' run: | @@ -163,6 +165,10 @@ jobs: - name: Use the minimum supported rust version if: matrix.rust == 'msrv' run: echo RUSTUP_TOOLCHAIN="$(make msrv)" >> $GITHUB_ENV + - name: Set latest toolchain + if: matrix.rust == 'latest' + run: echo RUSTUP_TOOLCHAIN="$(rustup show active-toolchain | cut -d' ' -f1)" >> $GITHUB_ENV + - uses: stellar/actions/rust-cache@main - name: Error on warnings only for msrv if: matrix.rust == 'msrv' run: echo RUSTFLAGS='-Dwarnings' >> $GITHUB_ENV From 9536acfe7a9a154a57aa4fb09c8c600ba511c538 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 30 Sep 2025 19:44:30 +1000 Subject: [PATCH 22/24] remove conditional rust installation in ci workflow --- .github/workflows/rust.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 89cff7a07..4e8160cdf 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -239,13 +239,11 @@ jobs: - uses: actions/checkout@v5 - uses: stellar/actions/rust-cache@main - name: Install minimum supported rust version - if: matrix.rust == 'msrv' run: | msrv="$(make msrv)" rustup install $msrv rustup target add --toolchain $msrv wasm32v1-none - name: Install latest rust version - if: matrix.rust == 'latest' run: | rustup update - uses: stellar/binaries@v45 From 8ae32e33ddd4292cfe0616b994e14e3bfabc7ca1 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 30 Sep 2025 20:02:34 +1000 Subject: [PATCH 23/24] upd --- tests-expanded/test_account_tests.rs | 7 +- tests-expanded/test_account_wasm32v1-none.rs | 5 +- tests-expanded/test_add_i128_tests.rs | 7 +- tests-expanded/test_add_i128_wasm32v1-none.rs | 5 +- tests-expanded/test_add_u128_tests.rs | 7 +- tests-expanded/test_add_u128_wasm32v1-none.rs | 5 +- tests-expanded/test_add_u64_tests.rs | 7 +- tests-expanded/test_add_u64_wasm32v1-none.rs | 5 +- tests-expanded/test_alloc_tests.rs | 8 +- tests-expanded/test_alloc_wasm32v1-none.rs | 5 +- tests-expanded/test_auth_tests.rs | 179 ++++++++---------- tests-expanded/test_auth_wasm32v1-none.rs | 5 +- tests-expanded/test_bls_tests.rs | 106 +++++------ tests-expanded/test_bls_wasm32v1-none.rs | 5 +- tests-expanded/test_constructor_tests.rs | 10 +- .../test_constructor_wasm32v1-none.rs | 5 +- tests-expanded/test_contract_data_tests.rs | 5 +- .../test_contract_data_wasm32v1-none.rs | 5 +- tests-expanded/test_empty2_tests.rs | 7 +- tests-expanded/test_empty2_wasm32v1-none.rs | 5 +- tests-expanded/test_empty_tests.rs | 7 +- tests-expanded/test_empty_wasm32v1-none.rs | 5 +- tests-expanded/test_errors_tests.rs | 20 +- tests-expanded/test_errors_wasm32v1-none.rs | 5 +- tests-expanded/test_events_tests.rs | 9 +- tests-expanded/test_events_wasm32v1-none.rs | 5 +- tests-expanded/test_fuzz_tests.rs | 5 +- tests-expanded/test_fuzz_wasm32v1-none.rs | 5 +- tests-expanded/test_import_contract_tests.rs | 7 +- .../test_import_contract_wasm32v1-none.rs | 5 +- tests-expanded/test_invoke_contract_tests.rs | 7 +- .../test_invoke_contract_wasm32v1-none.rs | 5 +- tests-expanded/test_logging_tests.rs | 26 +-- tests-expanded/test_logging_wasm32v1-none.rs | 5 +- tests-expanded/test_macros_tests.rs | 7 +- tests-expanded/test_macros_wasm32v1-none.rs | 5 +- tests-expanded/test_modular_tests.rs | 7 +- tests-expanded/test_modular_wasm32v1-none.rs | 5 +- tests-expanded/test_multiimpl_tests.rs | 7 +- .../test_multiimpl_wasm32v1-none.rs | 5 +- tests-expanded/test_udt_tests.rs | 89 ++++----- tests-expanded/test_udt_wasm32v1-none.rs | 5 +- .../test_workspace_contract_tests.rs | 7 +- .../test_workspace_contract_wasm32v1-none.rs | 5 +- tests-expanded/test_workspace_lib_tests.rs | 14 +- .../test_workspace_lib_wasm32v1-none.rs | 5 +- tests-expanded/test_zero_tests.rs | 5 +- tests-expanded/test_zero_wasm32v1-none.rs | 5 +- 48 files changed, 265 insertions(+), 415 deletions(-) diff --git a/tests-expanded/test_account_tests.rs b/tests-expanded/test_account_tests.rs index f2bd6aa6e..de7e9e307 100644 --- a/tests-expanded/test_account_tests.rs +++ b/tests-expanded/test_account_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{ auth::Context, auth::CustomAccountInterface, contract, contracterror, contractimpl, crypto::Hash, Env, Vec, @@ -421,7 +420,6 @@ static __Contract_CustomAccountInterface_d465b6861ce11142d9f64c1622e1ad88ae003d9 } __Contract_CustomAccountInterface_d465b6861ce11142d9f64c1622e1ad88ae003d910de0a8493889a96a23449736_ctor___rust_ctor___ctor }; -#[cfg(test)] mod test { use crate::Contract; use soroban_sdk::{ @@ -561,7 +559,6 @@ mod test { } } extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test"] #[doc(hidden)] pub const test: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_account_wasm32v1-none.rs b/tests-expanded/test_account_wasm32v1-none.rs index 9a475be7c..fbf76138b 100644 --- a/tests-expanded/test_account_wasm32v1-none.rs +++ b/tests-expanded/test_account_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{ auth::Context, auth::CustomAccountInterface, contract, contracterror, contractimpl, crypto::Hash, Env, Vec, diff --git a/tests-expanded/test_add_i128_tests.rs b/tests-expanded/test_add_i128_tests.rs index ed975fd13..7c3ecc0a8 100644 --- a/tests-expanded/test_add_i128_tests.rs +++ b/tests-expanded/test_add_i128_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". @@ -323,12 +322,10 @@ static __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4 } __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor }; -#[cfg(test)] mod test { use crate::{Contract, ContractClient}; use soroban_sdk::Env; extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test_add"] #[doc(hidden)] pub const test_add: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_add_i128_wasm32v1-none.rs b/tests-expanded/test_add_i128_wasm32v1-none.rs index 3a7446919..7aeee3f27 100644 --- a/tests-expanded/test_add_i128_wasm32v1-none.rs +++ b/tests-expanded/test_add_i128_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_add_u128_tests.rs b/tests-expanded/test_add_u128_tests.rs index f656bb357..6beb11068 100644 --- a/tests-expanded/test_add_u128_tests.rs +++ b/tests-expanded/test_add_u128_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". @@ -323,12 +322,10 @@ static __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4 } __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor }; -#[cfg(test)] mod test { use crate::{Contract, ContractClient}; use soroban_sdk::Env; extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test_add"] #[doc(hidden)] pub const test_add: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_add_u128_wasm32v1-none.rs b/tests-expanded/test_add_u128_wasm32v1-none.rs index 2cc45382f..513a58368 100644 --- a/tests-expanded/test_add_u128_wasm32v1-none.rs +++ b/tests-expanded/test_add_u128_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_add_u64_tests.rs b/tests-expanded/test_add_u64_tests.rs index 4079f7e3f..aa945dc57 100644 --- a/tests-expanded/test_add_u64_tests.rs +++ b/tests-expanded/test_add_u64_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". @@ -323,12 +322,10 @@ static __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4 } __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor }; -#[cfg(test)] mod test { use crate::{Contract, ContractClient}; use soroban_sdk::Env; extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test_add"] #[doc(hidden)] pub const test_add: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_add_u64_wasm32v1-none.rs b/tests-expanded/test_add_u64_wasm32v1-none.rs index 9b95d76ba..2da2616b4 100644 --- a/tests-expanded/test_add_u64_wasm32v1-none.rs +++ b/tests-expanded/test_add_u64_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_alloc_tests.rs b/tests-expanded/test_alloc_tests.rs index bd9b20444..8e4bc04a2 100644 --- a/tests-expanded/test_alloc_tests.rs +++ b/tests-expanded/test_alloc_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl, Env}; extern crate alloc; pub struct Contract; @@ -318,7 +317,6 @@ static __Contract__526e07cb9219443e6b3ef052e7872bf9e5bfee9b91633ed921601b5e93014 __Contract__526e07cb9219443e6b3ef052e7872bf9e5bfee9b91633ed921601b5e93014bb7_ctor___rust_ctor___ctor }; mod test { - #![cfg(test)] use crate::{Contract, ContractClient}; use soroban_sdk::{vec, Env}; mod imported { @@ -522,7 +520,6 @@ mod test { mod native { use super::*; extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::native::test"] #[doc(hidden)] pub const test: test::TestDescAndFn = test::TestDescAndFn { @@ -578,7 +575,6 @@ mod test { mod wasm { use super::*; extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::wasm::test"] #[doc(hidden)] pub const test: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_alloc_wasm32v1-none.rs b/tests-expanded/test_alloc_wasm32v1-none.rs index 884f99cfe..17e2683ca 100644 --- a/tests-expanded/test_alloc_wasm32v1-none.rs +++ b/tests-expanded/test_alloc_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl, Env}; extern crate alloc; pub struct Contract; diff --git a/tests-expanded/test_auth_tests.rs b/tests-expanded/test_auth_tests.rs index 3c06f0d49..022745827 100644 --- a/tests-expanded/test_auth_tests.rs +++ b/tests-expanded/test_auth_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl, Address, Env, IntoVal}; pub struct ContractA; ///ContractAArgs is a type for building arg lists for functions defined in "ContractA". @@ -304,7 +303,6 @@ static __ContractA__7c3764b58a7ababbe8a6b452f6a400d8ae3704b80f8c5ea1b251eebbc869 } __ContractA__7c3764b58a7ababbe8a6b452f6a400d8ae3704b80f8c5ea1b251eebbc8698020_ctor___rust_ctor___ctor }; -#[cfg(test)] mod test_a { use super::*; use soroban_sdk::{ @@ -321,7 +319,6 @@ mod test_a { }; extern crate std; extern crate test; - #[cfg(test)] #[rustc_test_marker = "test_a::test_with_mock_all_auth"] #[doc(hidden)] pub const test_with_mock_all_auth: test::TestDescAndFn = test::TestDescAndFn { @@ -365,20 +362,17 @@ mod test_a { }; match ( &e.auths(), - &<[_]>::into_vec( - #[rustc_box] - ::alloc::boxed::Box::new([( - a.clone(), - AuthorizedInvocation { - function: AuthorizedFunction::Contract(( - contract_id.clone(), - Symbol::new(&e, "fn1"), - (&a,).into_val(&e), - )), - sub_invocations: ::alloc::vec::Vec::new(), - }, - )]), - ), + &<[_]>::into_vec(::alloc::boxed::box_new([( + a.clone(), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + contract_id.clone(), + Symbol::new(&e, "fn1"), + (&a,).into_val(&e), + )), + sub_invocations: ::alloc::vec::Vec::new(), + }, + )])), ) { (left_val, right_val) => { if !(*left_val == *right_val) { @@ -394,7 +388,6 @@ mod test_a { }; } extern crate test; - #[cfg(test)] #[rustc_test_marker = "test_a::test_with_mock_auth"] #[doc(hidden)] pub const test_with_mock_auth: test::TestDescAndFn = test::TestDescAndFn { @@ -448,20 +441,17 @@ mod test_a { }; match ( &e.auths(), - &<[_]>::into_vec( - #[rustc_box] - ::alloc::boxed::Box::new([( - a.clone(), - AuthorizedInvocation { - function: AuthorizedFunction::Contract(( - contract_id.clone(), - Symbol::new(&e, "fn1"), - (&a,).into_val(&e), - )), - sub_invocations: ::alloc::vec::Vec::new(), - }, - )]), - ), + &<[_]>::into_vec(::alloc::boxed::box_new([( + a.clone(), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + contract_id.clone(), + Symbol::new(&e, "fn1"), + (&a,).into_val(&e), + )), + sub_invocations: ::alloc::vec::Vec::new(), + }, + )])), ) { (left_val, right_val) => { if !(*left_val == *right_val) { @@ -477,7 +467,6 @@ mod test_a { }; } extern crate test; - #[cfg(test)] #[rustc_test_marker = "test_a::test_with_real_contract_auth_approve"] #[doc(hidden)] pub const test_with_real_contract_auth_approve: test::TestDescAndFn = test::TestDescAndFn { @@ -518,10 +507,9 @@ mod test_a { function: SorobanAuthorizedFunction::ContractFn(InvokeContractArgs { contract_address: contract_id.clone().try_into().unwrap(), function_name: StringM::try_from("fn1").unwrap().into(), - args: <[_]>::into_vec( - #[rustc_box] - ::alloc::boxed::Box::new([ScVal::Address(a_xdr.clone())]), - ) + args: <[_]>::into_vec(::alloc::boxed::box_new([ScVal::Address( + a_xdr.clone(), + )])) .try_into() .unwrap(), }), @@ -544,20 +532,17 @@ mod test_a { }; match ( &e.auths(), - &<[_]>::into_vec( - #[rustc_box] - ::alloc::boxed::Box::new([( - a.clone(), - AuthorizedInvocation { - function: AuthorizedFunction::Contract(( - contract_id.clone(), - Symbol::new(&e, "fn1"), - (&a,).into_val(&e), - )), - sub_invocations: ::alloc::vec::Vec::new(), - }, - )]), - ), + &<[_]>::into_vec(::alloc::boxed::box_new([( + a.clone(), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + contract_id.clone(), + Symbol::new(&e, "fn1"), + (&a,).into_val(&e), + )), + sub_invocations: ::alloc::vec::Vec::new(), + }, + )])), ) { (left_val, right_val) => { if !(*left_val == *right_val) { @@ -573,7 +558,6 @@ mod test_a { }; } extern crate test; - #[cfg(test)] #[rustc_test_marker = "test_a::test_with_real_contract_auth_decline"] #[doc(hidden)] pub const test_with_real_contract_auth_decline: test::TestDescAndFn = test::TestDescAndFn { @@ -614,10 +598,9 @@ mod test_a { function: SorobanAuthorizedFunction::ContractFn(InvokeContractArgs { contract_address: contract_id.try_into().unwrap(), function_name: StringM::try_from("fn1").unwrap().into(), - args: <[_]>::into_vec( - #[rustc_box] - ::alloc::boxed::Box::new([ScVal::Address(a_xdr.clone())]), - ) + args: <[_]>::into_vec(::alloc::boxed::box_new([ScVal::Address( + a_xdr.clone(), + )])) .try_into() .unwrap(), }), @@ -1693,7 +1676,6 @@ static __ContractB__389cfcb1cb10680376b4cd5cf632e6b11c3e59494c10e1d42514faf6c4c2 } __ContractB__389cfcb1cb10680376b4cd5cf632e6b11c3e59494c10e1d42514faf6c4c21b84_ctor___rust_ctor___ctor }; -#[cfg(test)] mod test_b { use super::*; use soroban_sdk::{ @@ -1710,7 +1692,6 @@ mod test_b { }; extern crate std; extern crate test; - #[cfg(test)] #[rustc_test_marker = "test_b::test_with_mock_all_auth"] #[doc(hidden)] pub const test_with_mock_all_auth: test::TestDescAndFn = test::TestDescAndFn { @@ -1767,9 +1748,8 @@ mod test_b { }, (1, 2).into_val(&e), )), - sub_invocations: <[_]>::into_vec( - #[rustc_box] - ::alloc::boxed::Box::new([AuthorizedInvocation { + sub_invocations: <[_]>::into_vec(::alloc::boxed::box_new([ + AuthorizedInvocation { function: AuthorizedFunction::Contract(( contract_a_id.clone(), { @@ -1781,8 +1761,8 @@ mod test_b { (&a,).into_val(&e), )), sub_invocations: ::alloc::vec::Vec::new(), - }]), - ), + }, + ])), }, )], ) { @@ -1800,7 +1780,6 @@ mod test_b { }; } extern crate test; - #[cfg(test)] #[rustc_test_marker = "test_b::test_with_mock_auth"] #[doc(hidden)] pub const test_with_mock_auth: test::TestDescAndFn = test::TestDescAndFn { @@ -1872,9 +1851,8 @@ mod test_b { }, (1, 2).into_val(&e), )), - sub_invocations: <[_]>::into_vec( - #[rustc_box] - ::alloc::boxed::Box::new([AuthorizedInvocation { + sub_invocations: <[_]>::into_vec(::alloc::boxed::box_new([ + AuthorizedInvocation { function: AuthorizedFunction::Contract(( contract_a_id.clone(), { @@ -1886,8 +1864,8 @@ mod test_b { (&a,).into_val(&e), )), sub_invocations: ::alloc::vec::Vec::new(), - }]), - ), + }, + ])), }, )], ) { @@ -1905,7 +1883,6 @@ mod test_b { }; } extern crate test; - #[cfg(test)] #[rustc_test_marker = "test_b::test_with_real_contract_auth_approve"] #[doc(hidden)] pub const test_with_real_contract_auth_approve: test::TestDescAndFn = test::TestDescAndFn { @@ -1947,29 +1924,27 @@ mod test_b { function: SorobanAuthorizedFunction::ContractFn(InvokeContractArgs { contract_address: contract_b_id.clone().try_into().unwrap(), function_name: StringM::try_from("fn2").unwrap().into(), - args: <[_]>::into_vec( - #[rustc_box] - ::alloc::boxed::Box::new([ScVal::I32(1), ScVal::I32(2)]), - ) + args: <[_]>::into_vec(::alloc::boxed::box_new([ + ScVal::I32(1), + ScVal::I32(2), + ])) .try_into() .unwrap(), }), - sub_invocations: <[_]>::into_vec( - #[rustc_box] - ::alloc::boxed::Box::new([SorobanAuthorizedInvocation { + sub_invocations: <[_]>::into_vec(::alloc::boxed::box_new([ + SorobanAuthorizedInvocation { function: SorobanAuthorizedFunction::ContractFn(InvokeContractArgs { contract_address: contract_a_id.clone().try_into().unwrap(), function_name: StringM::try_from("fn1").unwrap().into(), - args: <[_]>::into_vec( - #[rustc_box] - ::alloc::boxed::Box::new([ScVal::Address(a_xdr.clone())]), - ) + args: <[_]>::into_vec(::alloc::boxed::box_new([ScVal::Address( + a_xdr.clone(), + )])) .try_into() .unwrap(), }), sub_invocations: Default::default(), - }]), - ) + }, + ])) .try_into() .unwrap(), }, @@ -2002,9 +1977,8 @@ mod test_b { }, (1, 2).into_val(&e), )), - sub_invocations: <[_]>::into_vec( - #[rustc_box] - ::alloc::boxed::Box::new([AuthorizedInvocation { + sub_invocations: <[_]>::into_vec(::alloc::boxed::box_new([ + AuthorizedInvocation { function: AuthorizedFunction::Contract(( contract_a_id.clone(), { @@ -2016,8 +1990,8 @@ mod test_b { (&a,).into_val(&e), )), sub_invocations: ::alloc::vec::Vec::new(), - }]), - ), + }, + ])), }, )], ) { @@ -2035,7 +2009,6 @@ mod test_b { }; } extern crate test; - #[cfg(test)] #[rustc_test_marker = "test_b::test_with_real_contract_auth_decline"] #[doc(hidden)] pub const test_with_real_contract_auth_decline: test::TestDescAndFn = test::TestDescAndFn { @@ -2077,29 +2050,27 @@ mod test_b { function: SorobanAuthorizedFunction::ContractFn(InvokeContractArgs { contract_address: contract_b_id.try_into().unwrap(), function_name: StringM::try_from("fn2").unwrap().into(), - args: <[_]>::into_vec( - #[rustc_box] - ::alloc::boxed::Box::new([ScVal::I32(1), ScVal::I32(2)]), - ) + args: <[_]>::into_vec(::alloc::boxed::box_new([ + ScVal::I32(1), + ScVal::I32(2), + ])) .try_into() .unwrap(), }), - sub_invocations: <[_]>::into_vec( - #[rustc_box] - ::alloc::boxed::Box::new([SorobanAuthorizedInvocation { + sub_invocations: <[_]>::into_vec(::alloc::boxed::box_new([ + SorobanAuthorizedInvocation { function: SorobanAuthorizedFunction::ContractFn(InvokeContractArgs { contract_address: contract_a_id.clone().try_into().unwrap(), function_name: StringM::try_from("fn1").unwrap().into(), - args: <[_]>::into_vec( - #[rustc_box] - ::alloc::boxed::Box::new([ScVal::Address(a_xdr.clone())]), - ) + args: <[_]>::into_vec(::alloc::boxed::box_new([ScVal::Address( + a_xdr.clone(), + )])) .try_into() .unwrap(), }), sub_invocations: Default::default(), - }]), - ) + }, + ])) .try_into() .unwrap(), }, diff --git a/tests-expanded/test_auth_wasm32v1-none.rs b/tests-expanded/test_auth_wasm32v1-none.rs index ef944a979..e58039e37 100644 --- a/tests-expanded/test_auth_wasm32v1-none.rs +++ b/tests-expanded/test_auth_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl, Address, Env, IntoVal}; pub struct ContractA; ///ContractAArgs is a type for building arg lists for functions defined in "ContractA". diff --git a/tests-expanded/test_bls_tests.rs b/tests-expanded/test_bls_tests.rs index d8071fb0f..cb8ead6bb 100644 --- a/tests-expanded/test_bls_tests.rs +++ b/tests-expanded/test_bls_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{ contract, contractimpl, contracttype, crypto::bls12_381::{Fp, Fp2, Fr, G1Affine, G2Affine}, @@ -199,62 +198,59 @@ impl TryFrom<&DummyProof> for soroban_sdk::xdr::ScMap { fn try_from(val: &DummyProof) -> Result { extern crate alloc; use soroban_sdk::TryFromVal; - soroban_sdk::xdr::ScMap::sorted_from(<[_]>::into_vec( - #[rustc_box] - ::alloc::boxed::Box::new([ - soroban_sdk::xdr::ScMapEntry { - key: soroban_sdk::xdr::ScSymbol( - "fp".try_into() - .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - ) - .into(), - val: (&val.fp) - .try_into() + soroban_sdk::xdr::ScMap::sorted_from(<[_]>::into_vec(::alloc::boxed::box_new([ + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "fp".try_into() .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - }, - soroban_sdk::xdr::ScMapEntry { - key: soroban_sdk::xdr::ScSymbol( - "fp2" - .try_into() - .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - ) - .into(), - val: (&val.fp2) + ) + .into(), + val: (&val.fp) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + }, + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "fp2" .try_into() .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - }, - soroban_sdk::xdr::ScMapEntry { - key: soroban_sdk::xdr::ScSymbol( - "fr".try_into() - .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - ) - .into(), - val: (&val.fr) - .try_into() + ) + .into(), + val: (&val.fp2) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + }, + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "fr".try_into() .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - }, - soroban_sdk::xdr::ScMapEntry { - key: soroban_sdk::xdr::ScSymbol( - "g1".try_into() - .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - ) - .into(), - val: (&val.g1) - .try_into() + ) + .into(), + val: (&val.fr) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + }, + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "g1".try_into() .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - }, - soroban_sdk::xdr::ScMapEntry { - key: soroban_sdk::xdr::ScSymbol( - "g2".try_into() - .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - ) - .into(), - val: (&val.g2) - .try_into() + ) + .into(), + val: (&val.g1) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + }, + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "g2".try_into() .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - }, - ]), - )) + ) + .into(), + val: (&val.g2) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + }, + ]))) } } impl TryFrom for soroban_sdk::xdr::ScMap { @@ -1210,13 +1206,11 @@ static __Contract__492d85ed5a5d2cb14995f41e785b3df9c7fcf4af92b6d50ce2c9fa7c9b1e3 } __Contract__492d85ed5a5d2cb14995f41e785b3df9c7fcf4af92b6d50ce2c9fa7c9b1e350d_ctor___rust_ctor___ctor }; -#[cfg(test)] mod test { use super::*; use crate::{Contract, ContractClient}; use soroban_sdk::{bytesn, Env}; extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test_g1_mul"] #[doc(hidden)] pub const test_g1_mul: test::TestDescAndFn = test::TestDescAndFn { @@ -1290,7 +1284,6 @@ mod test { }; } extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test_g2_mul"] #[doc(hidden)] pub const test_g2_mul: test::TestDescAndFn = test::TestDescAndFn { @@ -1378,7 +1371,6 @@ mod test { }; } extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test_dummy_verify"] #[doc(hidden)] pub const test_dummy_verify: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_bls_wasm32v1-none.rs b/tests-expanded/test_bls_wasm32v1-none.rs index 30cb06ea0..7f320f2e1 100644 --- a/tests-expanded/test_bls_wasm32v1-none.rs +++ b/tests-expanded/test_bls_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{ contract, contractimpl, contracttype, crypto::bls12_381::{Fp, Fp2, Fr, G1Affine, G2Affine}, diff --git a/tests-expanded/test_constructor_tests.rs b/tests-expanded/test_constructor_tests.rs index b4a1a9432..e967d9153 100644 --- a/tests-expanded/test_constructor_tests.rs +++ b/tests-expanded/test_constructor_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl, contracttype, Env}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". @@ -948,7 +947,6 @@ static __Contract__99dc7227b32e52c8d11ead5dec3dd80bafdad62d74493e7341c782fd8cb13 __Contract__99dc7227b32e52c8d11ead5dec3dd80bafdad62d74493e7341c782fd8cb13593_ctor___rust_ctor___ctor }; extern crate test; -#[cfg(test)] #[rustc_test_marker = "test_constructor"] #[doc(hidden)] pub const test_constructor: test::TestDescAndFn = test::TestDescAndFn { @@ -1055,7 +1053,6 @@ fn test_constructor() { } } extern crate test; -#[cfg(test)] #[rustc_test_marker = "test_passing_no_constructor_arguments_causes_panic"] #[doc(hidden)] pub const test_passing_no_constructor_arguments_causes_panic: test::TestDescAndFn = @@ -1087,7 +1084,6 @@ fn test_passing_no_constructor_arguments_causes_panic() { let _ = env.register(Contract, ()); } extern crate test; -#[cfg(test)] #[rustc_test_marker = "test_missing_constructor_arguments_causes_panic"] #[doc(hidden)] pub const test_missing_constructor_arguments_causes_panic: test::TestDescAndFn = @@ -1119,7 +1115,6 @@ fn test_missing_constructor_arguments_causes_panic() { let _ = env.register(Contract, (100_u32,)); } extern crate test; -#[cfg(test)] #[rustc_test_marker = "test_passing_extra_constructor_arguments_causes_panic"] #[doc(hidden)] pub const test_passing_extra_constructor_arguments_causes_panic: test::TestDescAndFn = @@ -1151,7 +1146,6 @@ fn test_passing_extra_constructor_arguments_causes_panic() { let _ = env.register(Contract, (100_u32, 1000_i64, 123_u32)); } extern crate test; -#[cfg(test)] #[rustc_test_marker = "test_passing_incorrectly_typed_constructor_arguments_causes_panic"] #[doc(hidden)] pub const test_passing_incorrectly_typed_constructor_arguments_causes_panic: test::TestDescAndFn = diff --git a/tests-expanded/test_constructor_wasm32v1-none.rs b/tests-expanded/test_constructor_wasm32v1-none.rs index 330c69836..8e13a3446 100644 --- a/tests-expanded/test_constructor_wasm32v1-none.rs +++ b/tests-expanded/test_constructor_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl, contracttype, Env}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_contract_data_tests.rs b/tests-expanded/test_contract_data_tests.rs index 9c48c9200..5ec29ef8c 100644 --- a/tests-expanded/test_contract_data_tests.rs +++ b/tests-expanded/test_contract_data_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl, Env, Symbol}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_contract_data_wasm32v1-none.rs b/tests-expanded/test_contract_data_wasm32v1-none.rs index 6a3835fdd..5ca71926d 100644 --- a/tests-expanded/test_contract_data_wasm32v1-none.rs +++ b/tests-expanded/test_contract_data_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl, Env, Symbol}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_empty2_tests.rs b/tests-expanded/test_empty2_tests.rs index 3b874ec59..c1e410399 100644 --- a/tests-expanded/test_empty2_tests.rs +++ b/tests-expanded/test_empty2_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". @@ -156,12 +155,10 @@ static __Contract__e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b } __Contract__e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855_ctor___rust_ctor___ctor }; -#[cfg(test)] mod test { use crate::{Contract, ContractClient}; use soroban_sdk::Env; extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test_hello"] #[doc(hidden)] pub const test_hello: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_empty2_wasm32v1-none.rs b/tests-expanded/test_empty2_wasm32v1-none.rs index 1af6429f4..4edc6a71d 100644 --- a/tests-expanded/test_empty2_wasm32v1-none.rs +++ b/tests-expanded/test_empty2_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_empty_tests.rs b/tests-expanded/test_empty_tests.rs index f8f51d99c..5236a8110 100644 --- a/tests-expanded/test_empty_tests.rs +++ b/tests-expanded/test_empty_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". @@ -293,12 +292,10 @@ static __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f } __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor___rust_ctor___ctor }; -#[cfg(test)] mod test { use crate::{Contract, ContractClient}; use soroban_sdk::Env; extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test_hello"] #[doc(hidden)] pub const test_hello: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_empty_wasm32v1-none.rs b/tests-expanded/test_empty_wasm32v1-none.rs index 1d2f0f150..4f56631dc 100644 --- a/tests-expanded/test_empty_wasm32v1-none.rs +++ b/tests-expanded/test_empty_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_errors_tests.rs b/tests-expanded/test_errors_tests.rs index 3a95468c0..5fa081641 100644 --- a/tests-expanded/test_errors_tests.rs +++ b/tests-expanded/test_errors_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{ contract, contracterror, contractimpl, contracttype, panic_with_error, symbol_short, Env, Symbol, @@ -643,7 +642,6 @@ impl Contract { ::core::panicking::panic("not implemented") } } - #[cfg(test)] pub fn persisted(env: Env) -> bool { env.storage() .persistent() @@ -670,18 +668,15 @@ impl Contract { } } #[doc(hidden)] -#[cfg(test)] #[allow(non_snake_case)] pub mod __Contract__persisted__spec { #[doc(hidden)] #[allow(non_snake_case)] #[allow(non_upper_case_globals)] - #[cfg(test)] pub static __SPEC_XDR_FN_PERSISTED: [u8; 36usize] = super::Contract::spec_xdr_persisted(); } impl Contract { #[allow(non_snake_case)] - #[cfg(test)] pub const fn spec_xdr_persisted() -> [u8; 36usize] { *b"\0\0\0\0\0\0\0\0\0\0\0\tpersisted\0\0\0\0\0\0\0\0\0\0\x01\0\0\0\x01" } @@ -766,7 +761,6 @@ impl<'a> ContractClient<'a> { } res } - #[cfg(test)] pub fn persisted(&self) -> bool { use core::ops::Not; let old_auth_manager = self @@ -804,7 +798,6 @@ impl<'a> ContractClient<'a> { } res } - #[cfg(test)] pub fn try_persisted( &self, ) -> Result< @@ -898,7 +891,6 @@ pub mod __Contract__hello { use super::*; } #[doc(hidden)] -#[cfg(test)] #[allow(non_snake_case)] pub mod __Contract__persisted { use super::*; @@ -958,12 +950,10 @@ static __Contract__dc66cfa30fdb08b17ba29ed3da0a0be599deef8db57bfb9cd9b3dcbf8c3be } __Contract__dc66cfa30fdb08b17ba29ed3da0a0be599deef8db57bfb9cd9b3dcbf8c3be498_ctor___rust_ctor___ctor }; -#[cfg(test)] mod test { use crate::{Contract, ContractClient, Error, Flag}; use soroban_sdk::{symbol_short, xdr, Env, InvokeError}; extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::hello_ok"] #[doc(hidden)] pub const hello_ok: test::TestDescAndFn = test::TestDescAndFn { @@ -1013,7 +1003,6 @@ mod test { } } extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::try_hello_ok"] #[doc(hidden)] pub const try_hello_ok: test::TestDescAndFn = test::TestDescAndFn { @@ -1066,7 +1055,6 @@ mod test { } } extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::try_hello_error"] #[doc(hidden)] pub const try_hello_error: test::TestDescAndFn = test::TestDescAndFn { @@ -1112,7 +1100,6 @@ mod test { } } extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::try_hello_error_panic"] #[doc(hidden)] pub const try_hello_error_panic: test::TestDescAndFn = test::TestDescAndFn { @@ -1158,7 +1145,6 @@ mod test { } } extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::try_hello_error_panic_string"] #[doc(hidden)] pub const try_hello_error_panic_string: test::TestDescAndFn = test::TestDescAndFn { @@ -1204,7 +1190,6 @@ mod test { } } extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::try_hello_error_unexpected_contract_error"] #[doc(hidden)] pub const try_hello_error_unexpected_contract_error: test::TestDescAndFn = @@ -1251,7 +1236,6 @@ mod test { } } extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::type_conversion"] #[doc(hidden)] pub const type_conversion: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_errors_wasm32v1-none.rs b/tests-expanded/test_errors_wasm32v1-none.rs index 6e6da9a29..b321525be 100644 --- a/tests-expanded/test_errors_wasm32v1-none.rs +++ b/tests-expanded/test_errors_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{ contract, contracterror, contractimpl, contracttype, panic_with_error, symbol_short, Env, Symbol, diff --git a/tests-expanded/test_events_tests.rs b/tests-expanded/test_events_tests.rs index 9bde77d9b..38991c925 100644 --- a/tests-expanded/test_events_tests.rs +++ b/tests-expanded/test_events_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractevent, contractimpl, Address, Env, MuxedAddress}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". @@ -585,7 +584,6 @@ static __Contract__a60968eb9ff75bf813738a9007ab5bbea9f174011ab4092819ed57e87eb6b } __Contract__a60968eb9ff75bf813738a9007ab5bbea9f174011ab4092819ed57e87eb6b301_ctor___rust_ctor___ctor }; -#[cfg(test)] mod test { extern crate alloc; use crate::{Contract, ContractClient}; @@ -595,7 +593,6 @@ mod test { vec, Address, Env, IntoVal, MuxedAddress, Symbol, Val, }; extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test_event"] #[doc(hidden)] pub const test_event: test::TestDescAndFn = test::TestDescAndFn { @@ -669,7 +666,6 @@ mod test { }; } extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test_event_with_option_none"] #[doc(hidden)] pub const test_event_with_option_none: test::TestDescAndFn = test::TestDescAndFn { @@ -740,7 +736,6 @@ mod test { }; } extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test_no_events_recorded_for_failed_call"] #[doc(hidden)] pub const test_no_events_recorded_for_failed_call: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_events_wasm32v1-none.rs b/tests-expanded/test_events_wasm32v1-none.rs index 43ae60136..506c67e6e 100644 --- a/tests-expanded/test_events_wasm32v1-none.rs +++ b/tests-expanded/test_events_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractevent, contractimpl, Address, Env, MuxedAddress}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_fuzz_tests.rs b/tests-expanded/test_fuzz_tests.rs index 690827270..1b01a802c 100644 --- a/tests-expanded/test_fuzz_tests.rs +++ b/tests-expanded/test_fuzz_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl, U256}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_fuzz_wasm32v1-none.rs b/tests-expanded/test_fuzz_wasm32v1-none.rs index 7690e8ab7..a818cd3df 100644 --- a/tests-expanded/test_fuzz_wasm32v1-none.rs +++ b/tests-expanded/test_fuzz_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl, U256}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_import_contract_tests.rs b/tests-expanded/test_import_contract_tests.rs index 0c80053ee..796ddabfd 100644 --- a/tests-expanded/test_import_contract_tests.rs +++ b/tests-expanded/test_import_contract_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl, Address, Env}; mod addcontract { pub const WASM: &[u8] = b"\0asm\x01\0\0\0\x01\x14\x04`\x01~\x01~`\x02\x7f~\0`\x02~~\x01~`\0\0\x02\r\x02\x01i\x010\0\0\x01i\x01_\0\0\x03\x05\x04\x01\x02\x03\x03\x05\x03\x01\0\x10\x06!\x04\x7f\x01A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x07/\x05\x06memory\x02\0\x03add\0\x03\x01_\x03\x01\n__data_end\x03\x02\x0b__heap_base\x03\x03\n\x89\x02\x04]\x02\x01\x7f\x01~\x02@\x02@ \x01\xa7A\xff\x01q\"\x02A\xc0\0F\r\0\x02@ \x02A\x06F\r\0B\x01!\x03B\x83\x90\x80\x80\x80\x01!\x01\x0c\x02\x0b \x01B\x08\x88!\x01B\0!\x03\x0c\x01\x0bB\0!\x03 \x01\x10\x80\x80\x80\x80\0!\x01\x0b \0 \x037\x03\0 \0 \x017\x03\x08\x0b\x9a\x01\x01\x01\x7f#\x80\x80\x80\x80\0A\x10k\"\x02$\x80\x80\x80\x80\0 \x02 \0\x10\x82\x80\x80\x80\0\x02@\x02@ \x02(\x02\0A\x01F\r\0 \x02)\x03\x08!\0 \x02 \x01\x10\x82\x80\x80\x80\0 \x02(\x02\0A\x01F\r\0 \0 \x02)\x03\x08|\"\x01 \0T\r\x01\x02@\x02@ \x01B\xff\xff\xff\xff\xff\xff\xff\xff\0V\r\0 \x01B\x08\x86B\x06\x84!\0\x0c\x01\x0b \x01\x10\x81\x80\x80\x80\0!\0\x0b \x02A\x10j$\x80\x80\x80\x80\0 \0\x0f\x0b\0\x0b\x10\x84\x80\x80\x80\0\0\x0b\t\0\x10\x85\x80\x80\x80\0\0\x0b\x03\0\0\x0b\x0b\t\x01\0A\x80\x80\xc0\0\x0b\0\0K\x0econtractspecv0\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x06\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x06\0\0\0\x01\0\0\0\x06\0\x1e\x11contractenvmetav0\0\0\0\0\0\0\0\x17\0\0\0\0\0+\x0econtractmetav0\0\0\0\0\0\0\0\x05rsver\0\0\0\0\0\0\x061.84.0\0\0"; @@ -541,12 +540,10 @@ static __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e85117ee9 } __Contract__70a46203e4054de1ddff57b7a47699d47775f2dc3cd806328562e85117ee9756_ctor___rust_ctor___ctor }; -#[cfg(test)] mod test { use crate::{addcontract, Contract, ContractClient}; use soroban_sdk::Env; extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test_add"] #[doc(hidden)] pub const test_add: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_import_contract_wasm32v1-none.rs b/tests-expanded/test_import_contract_wasm32v1-none.rs index 29bd751da..44b65c8d7 100644 --- a/tests-expanded/test_import_contract_wasm32v1-none.rs +++ b/tests-expanded/test_import_contract_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl, Address, Env}; mod addcontract { pub const WASM: &[u8] = b"\0asm\x01\0\0\0\x01\x14\x04`\x01~\x01~`\x02\x7f~\0`\x02~~\x01~`\0\0\x02\r\x02\x01i\x010\0\0\x01i\x01_\0\0\x03\x05\x04\x01\x02\x03\x03\x05\x03\x01\0\x10\x06!\x04\x7f\x01A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x7f\0A\x80\x80\xc0\0\x0b\x07/\x05\x06memory\x02\0\x03add\0\x03\x01_\x03\x01\n__data_end\x03\x02\x0b__heap_base\x03\x03\n\x89\x02\x04]\x02\x01\x7f\x01~\x02@\x02@ \x01\xa7A\xff\x01q\"\x02A\xc0\0F\r\0\x02@ \x02A\x06F\r\0B\x01!\x03B\x83\x90\x80\x80\x80\x01!\x01\x0c\x02\x0b \x01B\x08\x88!\x01B\0!\x03\x0c\x01\x0bB\0!\x03 \x01\x10\x80\x80\x80\x80\0!\x01\x0b \0 \x037\x03\0 \0 \x017\x03\x08\x0b\x9a\x01\x01\x01\x7f#\x80\x80\x80\x80\0A\x10k\"\x02$\x80\x80\x80\x80\0 \x02 \0\x10\x82\x80\x80\x80\0\x02@\x02@ \x02(\x02\0A\x01F\r\0 \x02)\x03\x08!\0 \x02 \x01\x10\x82\x80\x80\x80\0 \x02(\x02\0A\x01F\r\0 \0 \x02)\x03\x08|\"\x01 \0T\r\x01\x02@\x02@ \x01B\xff\xff\xff\xff\xff\xff\xff\xff\0V\r\0 \x01B\x08\x86B\x06\x84!\0\x0c\x01\x0b \x01\x10\x81\x80\x80\x80\0!\0\x0b \x02A\x10j$\x80\x80\x80\x80\0 \0\x0f\x0b\0\x0b\x10\x84\x80\x80\x80\0\0\x0b\t\0\x10\x85\x80\x80\x80\0\0\x0b\x03\0\0\x0b\x0b\t\x01\0A\x80\x80\xc0\0\x0b\0\0K\x0econtractspecv0\0\0\0\0\0\0\0\0\0\0\0\x03add\0\0\0\0\x02\0\0\0\0\0\0\0\x01a\0\0\0\0\0\0\x06\0\0\0\0\0\0\0\x01b\0\0\0\0\0\0\x06\0\0\0\x01\0\0\0\x06\0\x1e\x11contractenvmetav0\0\0\0\0\0\0\0\x17\0\0\0\0\0+\x0econtractmetav0\0\0\0\0\0\0\0\x05rsver\0\0\0\0\0\0\x061.84.0\0\0"; diff --git a/tests-expanded/test_invoke_contract_tests.rs b/tests-expanded/test_invoke_contract_tests.rs index 25806dcb4..c1c1d8239 100644 --- a/tests-expanded/test_invoke_contract_tests.rs +++ b/tests-expanded/test_invoke_contract_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl, symbol_short, vec, Address, Env, IntoVal}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". @@ -672,12 +671,10 @@ static __AddContract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65 } __AddContract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor }; -#[cfg(test)] mod test { use crate::{AddContract, Contract, ContractClient}; use soroban_sdk::Env; extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test_add"] #[doc(hidden)] pub const test_add: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_invoke_contract_wasm32v1-none.rs b/tests-expanded/test_invoke_contract_wasm32v1-none.rs index 301554712..6127c5008 100644 --- a/tests-expanded/test_invoke_contract_wasm32v1-none.rs +++ b/tests-expanded/test_invoke_contract_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl, symbol_short, vec, Address, Env, IntoVal}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_logging_tests.rs b/tests-expanded/test_logging_tests.rs index 658230ee4..0d91c718c 100644 --- a/tests-expanded/test_logging_tests.rs +++ b/tests-expanded/test_logging_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl, log, symbol_short, Env}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". @@ -376,13 +375,11 @@ static __Contract__2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9 } __Contract__2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824_ctor___rust_ctor___ctor }; -#[cfg(test)] mod test { extern crate std; use crate::{Contract, ContractClient}; use soroban_sdk::{testutils::Logs, Env}; extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test_logging"] #[doc(hidden)] pub const test_logging: test::TestDescAndFn = test::TestDescAndFn { @@ -412,17 +409,14 @@ mod test { client.hello(); env.logs().print(); if true { - let pats = <[_]>::into_vec( - #[rustc_box] - ::alloc::boxed::Box::new([ - "\"none\"", - "\"none\"", - "[\"one:\", one]", - "[\"one:\", one]", - "[\"one and two:\", one, two]", - "[\"one and two:\", one, two]", - ]), - ); + let pats = <[_]>::into_vec(::alloc::boxed::box_new([ + "\"none\"", + "\"none\"", + "[\"one:\", one]", + "[\"one:\", one]", + "[\"one and two:\", one, two]", + "[\"one and two:\", one, two]", + ])); for (msg, pat) in env.logs().all().iter().zip(pats.iter()) { if !msg.contains(pat) { ::core::panicking::panic("assertion failed: msg.contains(pat)") diff --git a/tests-expanded/test_logging_wasm32v1-none.rs b/tests-expanded/test_logging_wasm32v1-none.rs index 9b77acf39..0a9ec0e79 100644 --- a/tests-expanded/test_logging_wasm32v1-none.rs +++ b/tests-expanded/test_logging_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl, log, symbol_short, Env}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_macros_tests.rs b/tests-expanded/test_macros_tests.rs index 152193d35..c7faa9f8c 100644 --- a/tests-expanded/test_macros_tests.rs +++ b/tests-expanded/test_macros_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use proc_macros::parse_item_fn; use soroban_sdk::{contract, contractimpl}; pub struct Contract; @@ -294,12 +293,10 @@ static __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f } __Contract__2e1cfa82b035c26cbbbdae632cea070514eb8b773f616aaeaf668e2f0be8f10d_ctor___rust_ctor___ctor }; -#[cfg(test)] mod test { use crate::{Contract, ContractClient}; use soroban_sdk::Env; extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test_empty"] #[doc(hidden)] pub const test_empty: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_macros_wasm32v1-none.rs b/tests-expanded/test_macros_wasm32v1-none.rs index 74073b0c4..27f0c0f87 100644 --- a/tests-expanded/test_macros_wasm32v1-none.rs +++ b/tests-expanded/test_macros_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use proc_macros::parse_item_fn; use soroban_sdk::{contract, contractimpl}; pub struct Contract; diff --git a/tests-expanded/test_modular_tests.rs b/tests-expanded/test_modular_tests.rs index 112c88726..22a8c2241 100644 --- a/tests-expanded/test_modular_tests.rs +++ b/tests-expanded/test_modular_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl}; mod feat1 { use crate::Contract; @@ -348,11 +347,9 @@ mod feat2 { }; } mod test { - #![cfg(test)] use crate::{Contract, ContractClient}; use soroban_sdk::Env; extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test"] #[doc(hidden)] pub const test: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_modular_wasm32v1-none.rs b/tests-expanded/test_modular_wasm32v1-none.rs index 16b25df27..ffe0d21be 100644 --- a/tests-expanded/test_modular_wasm32v1-none.rs +++ b/tests-expanded/test_modular_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl}; mod feat1 { use crate::Contract; diff --git a/tests-expanded/test_multiimpl_tests.rs b/tests-expanded/test_multiimpl_tests.rs index e0586c95b..6d767e266 100644 --- a/tests-expanded/test_multiimpl_tests.rs +++ b/tests-expanded/test_multiimpl_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". @@ -610,12 +609,10 @@ static __Contract_Trait_2be3aa1100044a64e8135c570a7b382cebaca742493cf17b77052a7a } __Contract_Trait_2be3aa1100044a64e8135c570a7b382cebaca742493cf17b77052a7ae50fa889_ctor___rust_ctor___ctor }; -#[cfg(test)] mod test { use crate::{Contract, ContractClient}; use soroban_sdk::Env; extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test_hello"] #[doc(hidden)] pub const test_hello: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_multiimpl_wasm32v1-none.rs b/tests-expanded/test_multiimpl_wasm32v1-none.rs index 63069fd00..eff397db0 100644 --- a/tests-expanded/test_multiimpl_wasm32v1-none.rs +++ b/tests-expanded/test_multiimpl_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl}; pub struct Contract; ///ContractArgs is a type for building arg lists for functions defined in "Contract". diff --git a/tests-expanded/test_udt_tests.rs b/tests-expanded/test_udt_tests.rs index 13f51f9dd..ff6bbef27 100644 --- a/tests-expanded/test_udt_tests.rs +++ b/tests-expanded/test_udt_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl, contracttype, Vec}; pub enum UdtEnum2 { A = 10, @@ -1104,17 +1103,14 @@ impl TryFrom<&UdtTuple> for soroban_sdk::xdr::ScVec { extern crate alloc; use soroban_sdk::TryFromVal; Ok(soroban_sdk::xdr::ScVec( - <[_]>::into_vec( - #[rustc_box] - ::alloc::boxed::Box::new([ - (&val.0) - .try_into() - .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - (&val.1) - .try_into() - .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - ]), - ) + <[_]>::into_vec(::alloc::boxed::box_new([ + (&val.0) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + (&val.1) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + ])) .try_into()?, )) } @@ -1531,41 +1527,38 @@ impl TryFrom<&UdtStruct> for soroban_sdk::xdr::ScMap { fn try_from(val: &UdtStruct) -> Result { extern crate alloc; use soroban_sdk::TryFromVal; - soroban_sdk::xdr::ScMap::sorted_from(<[_]>::into_vec( - #[rustc_box] - ::alloc::boxed::Box::new([ - soroban_sdk::xdr::ScMapEntry { - key: soroban_sdk::xdr::ScSymbol( - "a".try_into() - .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - ) - .into(), - val: (&val.a) - .try_into() + soroban_sdk::xdr::ScMap::sorted_from(<[_]>::into_vec(::alloc::boxed::box_new([ + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "a".try_into() .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - }, - soroban_sdk::xdr::ScMapEntry { - key: soroban_sdk::xdr::ScSymbol( - "b".try_into() - .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - ) - .into(), - val: (&val.b) - .try_into() + ) + .into(), + val: (&val.a) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + }, + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "b".try_into() .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - }, - soroban_sdk::xdr::ScMapEntry { - key: soroban_sdk::xdr::ScSymbol( - "c".try_into() - .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - ) - .into(), - val: (&val.c) - .try_into() + ) + .into(), + val: (&val.b) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + }, + soroban_sdk::xdr::ScMapEntry { + key: soroban_sdk::xdr::ScSymbol( + "c".try_into() .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - }, - ]), - )) + ) + .into(), + val: (&val.c) + .try_into() + .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, + }, + ]))) } } impl TryFrom for soroban_sdk::xdr::ScMap { @@ -2138,12 +2131,10 @@ static __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4 } __Contract__7e9e5ac30f2216fd0fd6f5faed316f2d5983361a4203c3330cfa46ef65bb4767_ctor___rust_ctor___ctor }; -#[cfg(test)] mod test { use super::*; use soroban_sdk::{vec, xdr::ScVal, Bytes, Env, TryFromVal}; extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test_serializing"] #[doc(hidden)] pub const test_serializing: test::TestDescAndFn = test::TestDescAndFn { @@ -2197,7 +2188,6 @@ mod test { }; } extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test_add"] #[doc(hidden)] pub const test_add: test::TestDescAndFn = test::TestDescAndFn { @@ -2261,7 +2251,6 @@ mod test { }; } extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test_scval_accessibility_from_udt_types"] #[doc(hidden)] pub const test_scval_accessibility_from_udt_types: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_udt_wasm32v1-none.rs b/tests-expanded/test_udt_wasm32v1-none.rs index 3216e3d81..5dd3f78f5 100644 --- a/tests-expanded/test_udt_wasm32v1-none.rs +++ b/tests-expanded/test_udt_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl, contracttype, Vec}; pub enum UdtEnum2 { A = 10, diff --git a/tests-expanded/test_workspace_contract_tests.rs b/tests-expanded/test_workspace_contract_tests.rs index d852f9395..8df3686f7 100644 --- a/tests-expanded/test_workspace_contract_tests.rs +++ b/tests-expanded/test_workspace_contract_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl}; use test_workspace_lib::Value; pub struct Contract; @@ -299,12 +298,10 @@ static __Contract__cd42404d52ad55ccfa9aca4adc828aa5800ad9d385a0671fbcbf724118320 } __Contract__cd42404d52ad55ccfa9aca4adc828aa5800ad9d385a0671fbcbf724118320619_ctor___rust_ctor___ctor }; -#[cfg(test)] mod test { use super::*; use soroban_sdk::Env; extern crate test; - #[cfg(test)] #[rustc_test_marker = "test::test_add"] #[doc(hidden)] pub const test_add: test::TestDescAndFn = test::TestDescAndFn { diff --git a/tests-expanded/test_workspace_contract_wasm32v1-none.rs b/tests-expanded/test_workspace_contract_wasm32v1-none.rs index 32fe1c861..f6df76f7a 100644 --- a/tests-expanded/test_workspace_contract_wasm32v1-none.rs +++ b/tests-expanded/test_workspace_contract_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::{contract, contractimpl}; use test_workspace_lib::Value; pub struct Contract; diff --git a/tests-expanded/test_workspace_lib_tests.rs b/tests-expanded/test_workspace_lib_tests.rs index e019f3ee6..680a0c8c9 100644 --- a/tests-expanded/test_workspace_lib_tests.rs +++ b/tests-expanded/test_workspace_lib_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::contracttype; pub struct Value { pub value: i32, @@ -140,9 +139,8 @@ impl TryFrom<&Value> for soroban_sdk::xdr::ScMap { fn try_from(val: &Value) -> Result { extern crate alloc; use soroban_sdk::TryFromVal; - soroban_sdk::xdr::ScMap::sorted_from(<[_]>::into_vec( - #[rustc_box] - ::alloc::boxed::Box::new([soroban_sdk::xdr::ScMapEntry { + soroban_sdk::xdr::ScMap::sorted_from(<[_]>::into_vec(::alloc::boxed::box_new([ + soroban_sdk::xdr::ScMapEntry { key: soroban_sdk::xdr::ScSymbol( "value" .try_into() @@ -152,8 +150,8 @@ impl TryFrom<&Value> for soroban_sdk::xdr::ScMap { val: (&val.value) .try_into() .map_err(|_| soroban_sdk::xdr::Error::Invalid)?, - }]), - )) + }, + ]))) } } impl TryFrom for soroban_sdk::xdr::ScMap { diff --git a/tests-expanded/test_workspace_lib_wasm32v1-none.rs b/tests-expanded/test_workspace_lib_wasm32v1-none.rs index 9c4e36b5c..ccfff7e61 100644 --- a/tests-expanded/test_workspace_lib_wasm32v1-none.rs +++ b/tests-expanded/test_workspace_lib_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::contracttype; pub struct Value { pub value: i32, diff --git a/tests-expanded/test_zero_tests.rs b/tests-expanded/test_zero_tests.rs index 5dc2a00a9..6c2443a14 100644 --- a/tests-expanded/test_zero_tests.rs +++ b/tests-expanded/test_zero_tests.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::contract; struct _Contract; ///_ContractArgs is a type for building arg lists for functions defined in "_Contract". diff --git a/tests-expanded/test_zero_wasm32v1-none.rs b/tests-expanded/test_zero_wasm32v1-none.rs index 3961de10d..4fdd0f007 100644 --- a/tests-expanded/test_zero_wasm32v1-none.rs +++ b/tests-expanded/test_zero_wasm32v1-none.rs @@ -1,10 +1,9 @@ #![feature(prelude_import)] #![no_std] -#[prelude_import] -use core::prelude::rust_2021::*; #[macro_use] extern crate core; -extern crate compiler_builtins as _; +#[prelude_import] +use core::prelude::rust_2021::*; use soroban_sdk::contract; struct _Contract; ///_ContractArgs is a type for building arg lists for functions defined in "_Contract". From 4103648fe20662bc7c1642f0885ab786a9fc2832 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 30 Sep 2025 20:51:19 +1000 Subject: [PATCH 24/24] remove rustup update step and add rustflags for test expansion --- .github/workflows/rust.yml | 3 --- Makefile | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4e8160cdf..1dccb1326 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -243,9 +243,6 @@ jobs: msrv="$(make msrv)" rustup install $msrv rustup target add --toolchain $msrv wasm32v1-none - - name: Install latest rust version - run: | - rustup update - uses: stellar/binaries@v45 with: name: cargo-hack diff --git a/Makefile b/Makefile index fee743f47..9cb45820a 100644 --- a/Makefile +++ b/Makefile @@ -49,6 +49,8 @@ readme: expand-tests: build-test-wasms rm -fr tests-expanded mkdir -p tests-expanded + RUSTUP_TOOLCHAIN=$(TEST_CRATES_RUSTUP_TOOLCHAIN) ; \ + RUSTFLAGS='--cfg soroban_sdk_internal_no_rssdkver_meta' ; \ for package in $(TEST_CRATES); do \ echo "Expanding $$package for linux target including tests"; \ cargo expand --package $$package --tests --target x86_64-unknown-linux-gnu | rustfmt > tests-expanded/$${package}_tests.rs; \