@@ -117,12 +117,30 @@ mod tests {
117117 } ,
118118 } ;
119119 use alloy:: {
120- primitives:: { U256 , Uint , address, bytes, fixed_bytes, keccak256} ,
120+ primitives:: { Address , Bytes , U256 , Uint , address, bytes, fixed_bytes, keccak256} ,
121121 signers:: { SignerSync , local:: PrivateKeySigner } ,
122122 sol_types:: SolValue ,
123123 } ;
124124 use std:: str:: FromStr ;
125125
126+ fn generate_session_proof (
127+ session_spec : & SessionSpec ,
128+ account_address : Address ,
129+ signer_private_key : & str ,
130+ ) -> eyre:: Result < Bytes > {
131+ let session_lib_spec: crate :: erc4337:: account:: modular_smart_account:: session:: contract:: SessionLib :: SessionSpec =
132+ session_spec. clone ( ) . into ( ) ;
133+ let session_hash = keccak256 ( session_lib_spec. abi_encode ( ) ) ;
134+ let digest = keccak256 ( ( session_hash, account_address) . abi_encode ( ) ) ;
135+
136+ let session_signer_instance =
137+ PrivateKeySigner :: from_str ( signer_private_key) ?;
138+ Ok ( session_signer_instance
139+ . sign_hash_sync ( & digest) ?
140+ . as_bytes ( )
141+ . into ( ) )
142+ }
143+
126144 #[ tokio:: test]
127145 async fn test_create_session ( ) -> eyre:: Result < ( ) > {
128146 let (
@@ -250,16 +268,11 @@ mod tests {
250268 } ;
251269
252270 // Calculate proof
253- let session_lib_spec: crate :: erc4337:: account:: modular_smart_account:: session:: contract:: SessionLib :: SessionSpec = session_spec. clone ( ) . into ( ) ;
254- let session_hash = keccak256 ( session_lib_spec. abi_encode ( ) ) ;
255- let digest = keccak256 ( ( session_hash, address) . abi_encode ( ) ) ;
256-
257- let session_signer_instance =
258- PrivateKeySigner :: from_str ( & signer_private_key) ?;
259- let proof = session_signer_instance
260- . sign_hash_sync ( & digest) ?
261- . as_bytes ( )
262- . into ( ) ;
271+ let proof = generate_session_proof (
272+ & session_spec,
273+ address,
274+ & signer_private_key,
275+ ) ?;
263276
264277 create_session ( CreateSessionParams {
265278 account_address : address,
@@ -410,16 +423,11 @@ mod tests {
410423 } ;
411424
412425 // Calculate proof
413- let session_lib_spec: crate :: erc4337:: account:: modular_smart_account:: session:: contract:: SessionLib :: SessionSpec = session_spec. clone ( ) . into ( ) ;
414- let session_hash = keccak256 ( session_lib_spec. abi_encode ( ) ) ;
415- let digest = keccak256 ( ( session_hash, address) . abi_encode ( ) ) ;
416-
417- let session_signer_instance =
418- PrivateKeySigner :: from_str ( & signer_private_key) ?;
419- let proof = session_signer_instance
420- . sign_hash_sync ( & digest) ?
421- . as_bytes ( )
422- . into ( ) ;
426+ let proof = generate_session_proof (
427+ & session_spec,
428+ address,
429+ & signer_private_key,
430+ ) ?;
423431
424432 create_session ( CreateSessionParams {
425433 account_address : address,
0 commit comments