@@ -2,36 +2,49 @@ use predicates::prelude::predicate;
22use soroban_cli:: tx:: ONE_XLM ;
33use soroban_test:: { AssertExt , TestEnv } ;
44
5- fn secure_store_key ( sandbox : & TestEnv , name : & str ) -> String {
5+ // All secure store tests are run within one test to avoid issues with multiple
6+ // tests trying to access the dbus at the same time which can lead to intermittent failures.
7+ #[ tokio:: test]
8+ async fn secure_store_key_management ( ) {
9+ let sandbox = & TestEnv :: new ( ) ;
10+
11+ let secure_key_name = "secure-store-test" ;
12+
13+ // generate a new secret key in secure store
614 sandbox
715 . new_assert_cmd ( "keys" )
8- . args ( [ "generate" , "--fund" , "--secure-store" , name ] )
16+ . args ( [ "generate" , secure_key_name , "--secure-store" , "--fund" ] )
917 . assert ( )
10- . success ( )
11- . stdout_as_str ( ) ;
18+ . success ( ) ;
1219
20+ // validate that we cannot get the secret key back
1321 sandbox
1422 . new_assert_cmd ( "keys" )
15- . args ( [ "address" , name] )
23+ . arg ( "secret" )
24+ . arg ( secure_key_name)
1625 . assert ( )
17- . success ( )
18- . stdout_as_str ( )
19- }
26+ . stderr ( predicate:: str:: contains ( "does not reveal secret key" ) )
27+ . failure ( ) ;
2028
21- // test that we can create a create-account tx and sign it with a secure-store key
22- #[ tokio:: test]
23- async fn create_account ( ) {
24- let sandbox = & TestEnv :: new ( ) ;
25- let secure_store_address = secure_store_key ( sandbox, "secure-store" ) ;
29+ // validate that we can get the public key
30+ let secure_store_address = sandbox
31+ . new_assert_cmd ( "keys" )
32+ . args ( [ "address" , secure_key_name] )
33+ . assert ( )
34+ . success ( )
35+ . stdout_as_str ( ) ;
36+ assert ! ( secure_store_address. starts_with( 'G' ) ) ;
2637
38+ // use the secure store key to fund a new account
39+ let new_key_name = "new" ;
2740 sandbox
2841 . new_assert_cmd ( "keys" )
29- . args ( [ "generate" , "new" ] )
42+ . args ( [ "generate" , new_key_name ] )
3043 . assert ( )
3144 . success ( ) ;
3245 let new_address = sandbox
3346 . new_assert_cmd ( "keys" )
34- . args ( [ "address" , "new" ] )
47+ . args ( [ "address" , new_key_name ] )
3548 . assert ( )
3649 . success ( )
3750 . stdout_as_str ( ) ;
@@ -50,7 +63,7 @@ async fn create_account() {
5063 "--starting-balance" ,
5164 starting_balance. to_string ( ) . as_str ( ) ,
5265 "--source" ,
53- "secure-store" ,
66+ secure_key_name ,
5467 ] )
5568 . assert ( )
5669 . success ( )
@@ -61,38 +74,4 @@ async fn create_account() {
6174
6275 let new_account = client. get_account ( & new_address) . await . unwrap ( ) ;
6376 assert_eq ! ( new_account. balance, starting_balance) ;
64- }
65-
66- #[ tokio:: test]
67- async fn get_secret_key ( ) {
68- let sandbox = & TestEnv :: new ( ) ;
69- sandbox
70- . new_assert_cmd ( "keys" )
71- . args ( [ "generate" , "secret-key-test" , "--secure-store" , "--fund" ] )
72- . assert ( )
73- . success ( ) ;
74- sandbox
75- . new_assert_cmd ( "keys" )
76- . arg ( "secret" )
77- . arg ( "secret-key-test" )
78- . assert ( )
79- . stderr ( predicate:: str:: contains ( "does not reveal secret key" ) )
80- . failure ( ) ;
81- }
82-
83- #[ tokio:: test]
84- async fn public_key_with_secure_store ( ) {
85- let sandbox = & TestEnv :: new ( ) ;
86- sandbox
87- . new_assert_cmd ( "keys" )
88- . args ( [ "generate" , "public-key-test" , "--secure-store" , "--fund" ] )
89- . assert ( )
90- . success ( ) ;
91- sandbox
92- . new_assert_cmd ( "keys" )
93- . arg ( "public-key" )
94- . arg ( "public-key-test" )
95- . assert ( )
96- . stdout ( predicate:: str:: contains ( "G" ) )
97- . success ( ) ;
98- }
77+ }
0 commit comments