Skip to content

Commit a9ae8a0

Browse files
add exec2 method to trait and contract implementations
1 parent 4cf6f75 commit a9ae8a0

File tree

2 files changed

+242
-8
lines changed

2 files changed

+242
-8
lines changed

tests-expanded/test_associated_types_tests.rs

Lines changed: 160 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ impl Trait for DefaultImpl {
1111
fn exec(env: &Env) -> String {
1212
String::from_str(env, "default")
1313
}
14+
fn exec2(env: &Env) {
15+
String::from_str(env, "default")
16+
}
1417
}
1518
pub trait Trait {
1619
type Impl: Trait;
1720
fn exec(env: &Env) -> String {
1821
Self::Impl::exec(env)
1922
}
23+
fn exec2();
2024
}
2125
pub struct Contract;
2226
///ContractArgs is a type for building arg lists for functions defined in "Contract".
@@ -151,8 +155,8 @@ impl soroban_sdk::testutils::ContractFunctionSet for Contract {
151155
}
152156
impl Trait for Contract {
153157
type Impl = DefaultImpl;
154-
fn exec(env: &Env) -> String {
155-
Self::Impl::exec(env)
158+
fn exec2(env: &Env) -> String {
159+
String::from_str(env, "impl")
156160
}
157161
}
158162
#[doc(hidden)]
@@ -169,6 +173,20 @@ impl Contract {
169173
*b"\0\0\0\0\0\0\0\0\0\0\0\x04exec\0\0\0\0\0\0\0\x01\0\0\0\x10"
170174
}
171175
}
176+
#[doc(hidden)]
177+
#[allow(non_snake_case)]
178+
pub mod __Contract__exec2__spec {
179+
#[doc(hidden)]
180+
#[allow(non_snake_case)]
181+
#[allow(non_upper_case_globals)]
182+
pub static __SPEC_XDR_FN_EXEC2: [u8; 32usize] = super::Contract::spec_xdr_exec2();
183+
}
184+
impl Contract {
185+
#[allow(non_snake_case)]
186+
pub const fn spec_xdr_exec2() -> [u8; 32usize] {
187+
*b"\0\0\0\0\0\0\0\0\0\0\0\x05exec2\0\0\0\0\0\0\0\0\0\0\x01\0\0\0\x10"
188+
}
189+
}
172190
impl<'a> ContractClient<'a> {
173191
pub fn exec(&self) -> String {
174192
use core::ops::Not;
@@ -248,13 +266,96 @@ impl<'a> ContractClient<'a> {
248266
}
249267
res
250268
}
269+
pub fn exec2(&self) -> String {
270+
use core::ops::Not;
271+
let old_auth_manager = self
272+
.env
273+
.in_contract()
274+
.not()
275+
.then(|| self.env.host().snapshot_auth_manager().unwrap());
276+
{
277+
if let Some(set_auths) = self.set_auths {
278+
self.env.set_auths(set_auths);
279+
}
280+
if let Some(mock_auths) = self.mock_auths {
281+
self.env.mock_auths(mock_auths);
282+
}
283+
if self.mock_all_auths {
284+
if self.allow_non_root_auth {
285+
self.env.mock_all_auths_allowing_non_root_auth();
286+
} else {
287+
self.env.mock_all_auths();
288+
}
289+
}
290+
}
291+
use soroban_sdk::{FromVal, IntoVal};
292+
let res = self.env.invoke_contract(
293+
&self.address,
294+
&{
295+
#[allow(deprecated)]
296+
const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("exec2");
297+
SYMBOL
298+
},
299+
::soroban_sdk::Vec::new(&self.env),
300+
);
301+
if let Some(old_auth_manager) = old_auth_manager {
302+
self.env.host().set_auth_manager(old_auth_manager).unwrap();
303+
}
304+
res
305+
}
306+
pub fn try_exec2(
307+
&self,
308+
) -> Result<
309+
Result<
310+
String,
311+
<String as soroban_sdk::TryFromVal<soroban_sdk::Env, soroban_sdk::Val>>::Error,
312+
>,
313+
Result<soroban_sdk::Error, soroban_sdk::InvokeError>,
314+
> {
315+
use core::ops::Not;
316+
let old_auth_manager = self
317+
.env
318+
.in_contract()
319+
.not()
320+
.then(|| self.env.host().snapshot_auth_manager().unwrap());
321+
{
322+
if let Some(set_auths) = self.set_auths {
323+
self.env.set_auths(set_auths);
324+
}
325+
if let Some(mock_auths) = self.mock_auths {
326+
self.env.mock_auths(mock_auths);
327+
}
328+
if self.mock_all_auths {
329+
self.env.mock_all_auths();
330+
}
331+
}
332+
use soroban_sdk::{FromVal, IntoVal};
333+
let res = self.env.try_invoke_contract(
334+
&self.address,
335+
&{
336+
#[allow(deprecated)]
337+
const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("exec2");
338+
SYMBOL
339+
},
340+
::soroban_sdk::Vec::new(&self.env),
341+
);
342+
if let Some(old_auth_manager) = old_auth_manager {
343+
self.env.host().set_auth_manager(old_auth_manager).unwrap();
344+
}
345+
res
346+
}
251347
}
252348
impl ContractArgs {
253349
#[inline(always)]
254350
#[allow(clippy::unused_unit)]
255351
pub fn exec<'i>() -> () {
256352
()
257353
}
354+
#[inline(always)]
355+
#[allow(clippy::unused_unit)]
356+
pub fn exec2<'i>() -> () {
357+
()
358+
}
258359
}
259360
#[doc(hidden)]
260361
#[allow(non_snake_case)]
@@ -292,8 +393,42 @@ pub mod __Contract__exec {
292393
}
293394
#[doc(hidden)]
294395
#[allow(non_snake_case)]
396+
pub mod __Contract__exec2 {
397+
use super::*;
398+
#[deprecated(note = "use `ContractClient::new(&env, &contract_id).exec2` instead")]
399+
pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val {
400+
use super::Trait;
401+
<_ as soroban_sdk::IntoVal<soroban_sdk::Env, soroban_sdk::Val>>::into_val(
402+
#[allow(deprecated)]
403+
&<super::Contract>::exec2(&env),
404+
&env,
405+
)
406+
}
407+
#[deprecated(note = "use `ContractClient::new(&env, &contract_id).exec2` instead")]
408+
pub fn invoke_raw_slice(env: soroban_sdk::Env, args: &[soroban_sdk::Val]) -> soroban_sdk::Val {
409+
if args.len() != 0usize {
410+
{
411+
::core::panicking::panic_fmt(format_args!(
412+
"invalid number of input arguments: {0} expected, got {1}",
413+
0usize,
414+
args.len(),
415+
));
416+
};
417+
}
418+
#[allow(deprecated)]
419+
invoke_raw(env)
420+
}
421+
#[deprecated(note = "use `ContractClient::new(&env, &contract_id).exec2` instead")]
422+
pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val {
423+
#[allow(deprecated)]
424+
invoke_raw(soroban_sdk::Env::default())
425+
}
426+
use super::*;
427+
}
428+
#[doc(hidden)]
429+
#[allow(non_snake_case)]
295430
#[allow(unused)]
296-
fn __Contract_Trait_2706c619fe73f0cf112473c6ee02e66c04e1c01c110b0c37b88d8eb509630c9f_ctor() {
431+
fn __Contract_Trait_63842da933ab3611b9860480a0bd8b7c0de39e8f6f301c9ed52dd54191e8c014_ctor() {
297432
#[allow(unsafe_code)]
298433
{
299434
#[link_section = ".init_array"]
@@ -305,7 +440,7 @@ fn __Contract_Trait_2706c619fe73f0cf112473c6ee02e66c04e1c01c110b0c37b88d8eb50963
305440
#[allow(non_snake_case)]
306441
extern "C" fn f() -> ::ctor::__support::CtorRetType {
307442
unsafe {
308-
__Contract_Trait_2706c619fe73f0cf112473c6ee02e66c04e1c01c110b0c37b88d8eb509630c9f_ctor();
443+
__Contract_Trait_63842da933ab3611b9860480a0bd8b7c0de39e8f6f301c9ed52dd54191e8c014_ctor();
309444
};
310445
core::default::Default::default()
311446
}
@@ -318,6 +453,11 @@ fn __Contract_Trait_2706c619fe73f0cf112473c6ee02e66c04e1c01c110b0c37b88d8eb50963
318453
#[allow(deprecated)]
319454
&__Contract__exec::invoke_raw_slice,
320455
);
456+
<Contract as soroban_sdk::testutils::ContractFunctionRegister>::register(
457+
"exec2",
458+
#[allow(deprecated)]
459+
&__Contract__exec2::invoke_raw_slice,
460+
);
321461
}
322462
}
323463
mod test {
@@ -332,9 +472,9 @@ mod test {
332472
ignore: false,
333473
ignore_message: ::core::option::Option::None,
334474
source_file: "tests/associated_type/src/lib.rs",
335-
start_line: 42usize,
475+
start_line: 51usize,
336476
start_col: 8usize,
337-
end_line: 42usize,
477+
end_line: 51usize,
338478
end_col: 17usize,
339479
compile_fail: false,
340480
no_run: false,
@@ -364,6 +504,20 @@ mod test {
364504
}
365505
}
366506
};
507+
let res = client.exec2();
508+
match (&res, &String::from_str(&e, "impl")) {
509+
(left_val, right_val) => {
510+
if !(*left_val == *right_val) {
511+
let kind = ::core::panicking::AssertKind::Eq;
512+
::core::panicking::assert_failed(
513+
kind,
514+
&*left_val,
515+
&*right_val,
516+
::core::option::Option::None,
517+
);
518+
}
519+
}
520+
};
367521
}
368522
}
369523
#[rustc_main]

tests-expanded/test_associated_types_wasm32v1-none.rs

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ impl Trait for DefaultImpl {
1111
fn exec(env: &Env) -> String {
1212
String::from_str(env, "default")
1313
}
14+
fn exec2(env: &Env) {
15+
String::from_str(env, "default")
16+
}
1417
}
1518
pub trait Trait {
1619
type Impl: Trait;
1720
fn exec(env: &Env) -> String {
1821
Self::Impl::exec(env)
1922
}
23+
fn exec2();
2024
}
2125
pub struct Contract;
2226
///ContractArgs is a type for building arg lists for functions defined in "Contract".
@@ -39,8 +43,8 @@ impl<'a> ContractClient<'a> {
3943
}
4044
impl Trait for Contract {
4145
type Impl = DefaultImpl;
42-
fn exec(env: &Env) -> String {
43-
Self::Impl::exec(env)
46+
fn exec2(env: &Env) -> String {
47+
String::from_str(env, "impl")
4448
}
4549
}
4650
#[doc(hidden)]
@@ -58,6 +62,21 @@ impl Contract {
5862
*b"\0\0\0\0\0\0\0\0\0\0\0\x04exec\0\0\0\0\0\0\0\x01\0\0\0\x10"
5963
}
6064
}
65+
#[doc(hidden)]
66+
#[allow(non_snake_case)]
67+
pub mod __Contract__exec2__spec {
68+
#[doc(hidden)]
69+
#[allow(non_snake_case)]
70+
#[allow(non_upper_case_globals)]
71+
#[link_section = "contractspecv0"]
72+
pub static __SPEC_XDR_FN_EXEC2: [u8; 32usize] = super::Contract::spec_xdr_exec2();
73+
}
74+
impl Contract {
75+
#[allow(non_snake_case)]
76+
pub const fn spec_xdr_exec2() -> [u8; 32usize] {
77+
*b"\0\0\0\0\0\0\0\0\0\0\0\x05exec2\0\0\0\0\0\0\0\0\0\0\x01\0\0\0\x10"
78+
}
79+
}
6180
impl<'a> ContractClient<'a> {
6281
pub fn exec(&self) -> String {
6382
use core::ops::Not;
@@ -94,13 +113,53 @@ impl<'a> ContractClient<'a> {
94113
);
95114
res
96115
}
116+
pub fn exec2(&self) -> String {
117+
use core::ops::Not;
118+
use soroban_sdk::{FromVal, IntoVal};
119+
let res = self.env.invoke_contract(
120+
&self.address,
121+
&{
122+
#[allow(deprecated)]
123+
const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("exec2");
124+
SYMBOL
125+
},
126+
::soroban_sdk::Vec::new(&self.env),
127+
);
128+
res
129+
}
130+
pub fn try_exec2(
131+
&self,
132+
) -> Result<
133+
Result<
134+
String,
135+
<String as soroban_sdk::TryFromVal<soroban_sdk::Env, soroban_sdk::Val>>::Error,
136+
>,
137+
Result<soroban_sdk::Error, soroban_sdk::InvokeError>,
138+
> {
139+
use soroban_sdk::{FromVal, IntoVal};
140+
let res = self.env.try_invoke_contract(
141+
&self.address,
142+
&{
143+
#[allow(deprecated)]
144+
const SYMBOL: soroban_sdk::Symbol = soroban_sdk::Symbol::short("exec2");
145+
SYMBOL
146+
},
147+
::soroban_sdk::Vec::new(&self.env),
148+
);
149+
res
150+
}
97151
}
98152
impl ContractArgs {
99153
#[inline(always)]
100154
#[allow(clippy::unused_unit)]
101155
pub fn exec<'i>() -> () {
102156
()
103157
}
158+
#[inline(always)]
159+
#[allow(clippy::unused_unit)]
160+
pub fn exec2<'i>() -> () {
161+
()
162+
}
104163
}
105164
#[doc(hidden)]
106165
#[allow(non_snake_case)]
@@ -123,3 +182,24 @@ pub mod __Contract__exec {
123182
}
124183
use super::*;
125184
}
185+
#[doc(hidden)]
186+
#[allow(non_snake_case)]
187+
pub mod __Contract__exec2 {
188+
use super::*;
189+
#[deprecated(note = "use `ContractClient::new(&env, &contract_id).exec2` instead")]
190+
pub fn invoke_raw(env: soroban_sdk::Env) -> soroban_sdk::Val {
191+
use super::Trait;
192+
<_ as soroban_sdk::IntoVal<soroban_sdk::Env, soroban_sdk::Val>>::into_val(
193+
#[allow(deprecated)]
194+
&<super::Contract>::exec2(&env),
195+
&env,
196+
)
197+
}
198+
#[deprecated(note = "use `ContractClient::new(&env, &contract_id).exec2` instead")]
199+
#[export_name = "exec2"]
200+
pub extern "C" fn invoke_raw_extern() -> soroban_sdk::Val {
201+
#[allow(deprecated)]
202+
invoke_raw(soroban_sdk::Env::default())
203+
}
204+
use super::*;
205+
}

0 commit comments

Comments
 (0)