11use stellar_ledger:: Blob ;
22
3- use soroban_test:: { AssertExt , TestEnv } ;
3+ use soroban_test:: { AssertExt , TestEnv , Wasm } ;
44use std:: sync:: Arc ;
55
66use stellar_ledger:: emulator_test_support:: * ;
@@ -12,6 +12,8 @@ use soroban_cli::{
1212
1313use test_case:: test_case;
1414
15+ const HELLO_WORLD : & Wasm = & Wasm :: Custom ( "test-wasms" , "test_hello_world" ) ;
16+
1517#[ test_case( "nanos" , 0 ; "when the device is NanoS" ) ]
1618#[ test_case( "nanox" , 1 ; "when the device is NanoX" ) ]
1719#[ test_case( "nanosp" , 2 ; "when the device is NanoS Plus" ) ]
@@ -88,3 +90,90 @@ async fn test_signer(ledger_device_model: &str, hd_path: u32) {
8890 )
8991 . unwrap ( ) ;
9092}
93+
94+ // Mirrors `invoke_auth_with_non_source_identity` from the integration tests:
95+ // invoke a contract whose `auth(addr, world)` calls `addr.require_auth()`,
96+ // where the auth identity (`testone`) is a Ledger-backed alias and the
97+ // transaction source (`test`) is a regular keypair. Exercises the Soroban
98+ // auth-entry signing path through the Ledger device.
99+ #[ test_case( "nanos" , 0 ; "when the device is NanoS" ) ]
100+ #[ test_case( "nanox" , 1 ; "when the device is NanoX" ) ]
101+ #[ test_case( "nanosp" , 2 ; "when the device is NanoS Plus" ) ]
102+ #[ tokio:: test]
103+ async fn invoke_auth_with_ledger_identity ( ledger_device_model : & str , hd_path : u32 ) {
104+ let sandbox = Arc :: new ( TestEnv :: new ( ) ) ;
105+ let container = TestEnv :: speculos_container ( ledger_device_model) . await ;
106+ let host_port = container. get_host_port_ipv4 ( 9998 ) . await . unwrap ( ) ;
107+ let ui_host_port = container. get_host_port_ipv4 ( 5000 ) . await . unwrap ( ) ;
108+
109+ sandbox
110+ . new_assert_cmd ( "keys" )
111+ . arg ( "fund" )
112+ . arg ( "test" )
113+ . assert ( )
114+ . success ( ) ;
115+
116+ sandbox
117+ . new_assert_cmd ( "keys" )
118+ . arg ( "add" )
119+ . arg ( "testone" )
120+ . arg ( "--ledger" )
121+ . arg ( "--hd-path" )
122+ . arg ( hd_path. to_string ( ) )
123+ . env ( "SPECULOS_PORT" , host_port. to_string ( ) )
124+ . assert ( )
125+ . success ( ) ;
126+
127+ let addr = sandbox
128+ . new_assert_cmd ( "keys" )
129+ . arg ( "address" )
130+ . arg ( "testone" )
131+ . assert ( )
132+ . success ( )
133+ . stdout_as_str ( ) ;
134+
135+ let id = sandbox
136+ . new_assert_cmd ( "contract" )
137+ . arg ( "deploy" )
138+ . arg ( "--source" )
139+ . arg ( "test" )
140+ . arg ( "--wasm" )
141+ . arg ( HELLO_WORLD . path ( ) )
142+ . arg ( "--ignore-checks" )
143+ . assert ( )
144+ . success ( )
145+ . stdout_as_str ( ) ;
146+
147+ let invoke = tokio:: task:: spawn_blocking ( {
148+ let sandbox = Arc :: clone ( & sandbox) ;
149+ let id = id. clone ( ) ;
150+ let addr = addr. clone ( ) ;
151+ move || {
152+ let stdout = sandbox
153+ . new_assert_cmd ( "contract" )
154+ . arg ( "invoke" )
155+ . arg ( "--source" )
156+ . arg ( "test" )
157+ . arg ( "--id" )
158+ . arg ( & id)
159+ . arg ( "--" )
160+ . arg ( "auth" )
161+ . arg ( "--addr" )
162+ . arg ( "testone" )
163+ . arg ( "--world=world" )
164+ . env ( "SPECULOS_PORT" , host_port. to_string ( ) )
165+ . assert ( )
166+ . success ( )
167+ . stdout_as_str ( ) ;
168+ assert_eq ! ( stdout, format!( "\" {addr}\" " ) ) ;
169+ }
170+ } ) ;
171+
172+ let approve = tokio:: task:: spawn ( approve_tx_hash_signature (
173+ ui_host_port,
174+ ledger_device_model. to_string ( ) ,
175+ ) ) ;
176+
177+ invoke. await . unwrap ( ) ;
178+ approve. await . unwrap ( ) ;
179+ }
0 commit comments