@@ -416,3 +416,73 @@ impl ProgramManager {
416416 cost_in_microcredits_v2 ( & stack, & function_id) . map_err ( |e| e. to_string ( ) )
417417 }
418418}
419+
420+ #[ cfg( test) ]
421+ mod tests {
422+ use js_sys:: Array ;
423+ use snarkvm_console:: prelude:: ConsensusVersion ;
424+ use snarkvm_synthesizer:: process:: execution_cost;
425+ use wasm_bindgen:: JsValue ;
426+ use wasm_bindgen_test:: wasm_bindgen_test;
427+
428+ use crate :: {
429+ PrivateKey ,
430+ ProgramManager ,
431+ types:: native:: { ProcessNative , ProgramNative } ,
432+ } ;
433+
434+ #[ wasm_bindgen_test]
435+ pub async fn test_estimate_execution_fee ( ) {
436+ for ( function, inputs) in [
437+ ( "transfer_public" , vec ! [
438+ JsValue :: from_str( "aleo1q8zc0asncaw9d83ft2dynyqz08fcpq3p40depmrj4wjda28rdvrsvegg45" ) ,
439+ JsValue :: from_str( "1u64" ) ,
440+ ] ) ,
441+ ( "bond_public" , vec ! [
442+ JsValue :: from_str( "aleo1q8zc0asncaw9d83ft2dynyqz08fcpq3p40depmrj4wjda28rdvrsvegg45" ) ,
443+ JsValue :: from_str( "aleo1q8zc0asncaw9d83ft2dynyqz08fcpq3p40depmrj4wjda28rdvrsvegg45" ) ,
444+ JsValue :: from_str( "1u64" ) ,
445+ ] ) ,
446+ ] {
447+ let program = "credits.aleo" ;
448+ let private_key = PrivateKey :: new ( ) ;
449+
450+ let mut process_native = ProcessNative :: load_web ( ) . map_err ( |err| err. to_string ( ) ) ?;
451+ let process = & mut process_native;
452+
453+ let program_native = ProgramNative :: from_str ( program) . map_err ( |e| e. to_string ( ) ) ?;
454+
455+ let resp = ProgramManager :: execute_function_offline (
456+ & private_key,
457+ program,
458+ function,
459+ Array :: from_iter ( inputs. iter ( ) ) ,
460+ false ,
461+ true ,
462+ None ,
463+ None ,
464+ None ,
465+ Some ( "api.explorer.provable.com/v1" . to_string ( ) ) ,
466+ None ,
467+ Some ( 1 ) ,
468+ )
469+ . await
470+ . unwrap ( ) ;
471+
472+ let ( execution_estimate, _) =
473+ execution_cost ( & process, & resp. get_execution ( ) . unwrap ( ) , ConsensusVersion :: V3 ) . unwrap ( ) ;
474+ let authorization_estimate = ProgramManager :: estimate_execution_fee (
475+ program,
476+ function,
477+ Some ( "api.explorer.provable.com/v1" . to_string ( ) ) ,
478+ None ,
479+ None ,
480+ Some ( 1 ) ,
481+ )
482+ . await
483+ . unwrap ( ) ;
484+
485+ assert_eq ! ( execution_estimate, authorization_estimate) ;
486+ }
487+ }
488+ }
0 commit comments