@@ -9,7 +9,6 @@ use soroban_sdk::{
99 Address , Env , IntoVal , Val , Vec ,
1010} ;
1111
12-
1312fn init_test < ' a > ( env : & ' a Env ) -> ( Address , StellarAssetClient < ' a > , GuessTheNumberClient < ' a > ) {
1413 let admin = Address :: generate ( env) ;
1514 let client = generate_client ( env, & admin) ;
@@ -27,7 +26,10 @@ fn constructed_correctly() {
2726 assert_eq ! ( client. admin( ) , Some ( admin. clone( ) ) ) ;
2827 // Check that the contract has a balance of 1 XLM
2928 assert_eq ! ( sac. balance( & client. address) , xlm:: to_stroops( 1 ) ) ;
30-
29+ // Need to use `as_contract` to call a function in the context of the contract
30+ // Since the method `number` is not in the client, but is visibile in the crate
31+ let number = env. as_contract ( & client. address , || GuessTheNumber :: number ( env) ) ;
32+ assert_eq ! ( number, 4 ) ;
3133}
3234
3335#[ test]
@@ -117,11 +119,10 @@ fn reset_and_guess() {
117119 let alice = Address :: generate ( env) ;
118120 // Mint tokens to the user. On testnet you use friendbot to fund the account.
119121 sac. mint ( & alice, & xlm:: to_stroops ( 2 ) ) ;
120-
121-
122+
122123 // Reset the number
123124 client. reset ( ) ;
124-
125+
125126 // Guess again, this should be correct now
126127 assert ! ( client. guess( & 10 , & alice) ) ;
127128}
@@ -134,7 +135,6 @@ fn generate_client<'a>(env: &Env, admin: &Address) -> GuessTheNumberClient<'a> {
134135 GuessTheNumberClient :: new ( env, & contract_id)
135136}
136137
137-
138138// This lets you mock the auth context for a function call
139139fn set_caller < T > ( client : & GuessTheNumberClient , fn_name : & str , caller : & Address , args : T )
140140where
0 commit comments