@@ -90,8 +90,8 @@ fn generate_payment_addresses(wallet: &Wallet) -> (Vec<String>, Vec<String>) {
9090}
9191
9292fn get_resp_for_payment_req ( pool_handle : i32 , wallet_handle : i32 , did : & str ,
93- inputs : & str , outputs : & str ) -> Result < String , ErrorCode > {
94- let req = build_payment_req ( wallet_handle, did, inputs, outputs, None ) . unwrap ( ) ;
93+ inputs : & str , outputs : & str , extra : Option < String > ) -> Result < String , ErrorCode > {
94+ let req = build_payment_req ( wallet_handle, did, inputs, outputs, extra ) . unwrap ( ) ;
9595 let res = indy:: ledger:: submit_request ( pool_handle, & req) . wait ( ) . unwrap ( ) ;
9696 parse_payment_response ( & res)
9797}
@@ -316,7 +316,7 @@ pub fn build_and_submit_payment_req() {
316316 "amount" : 10
317317 }
318318 ] ) . to_string ( ) ;
319- let res = get_resp_for_payment_req ( pool_handle, wallet. handle , dids[ 0 ] , & inputs, & outputs) . unwrap ( ) ;
319+ let res = get_resp_for_payment_req ( pool_handle, wallet. handle , dids[ 0 ] , & inputs, & outputs, None ) . unwrap ( ) ;
320320
321321 let res_parsed: serde_json:: Value = serde_json:: from_str ( & res) . unwrap ( ) ;
322322 let utxos = res_parsed. as_array ( ) . unwrap ( ) ;
@@ -373,7 +373,7 @@ pub fn build_and_submit_payment_req_incorrect_funds() {
373373 }
374374 ] ) . to_string ( ) ;
375375 let res = get_resp_for_payment_req ( pool_handle, wallet. handle , dids[ 0 ] ,
376- & inputs, & outputs_1) . unwrap_err ( ) ;
376+ & inputs, & outputs_1, None ) . unwrap_err ( ) ;
377377 assert_eq ! ( res, ErrorCode :: PaymentInsufficientFundsError ) ;
378378
379379 let outputs_2 = json ! ( [
@@ -387,7 +387,7 @@ pub fn build_and_submit_payment_req_incorrect_funds() {
387387 }
388388 ] ) . to_string ( ) ;
389389 let res = get_resp_for_payment_req ( pool_handle, wallet. handle , dids[ 0 ] ,
390- & inputs, & outputs_2) . unwrap_err ( ) ;
390+ & inputs, & outputs_2, None ) . unwrap_err ( ) ;
391391 assert_eq ! ( res, ErrorCode :: PaymentExtraFundsError ) ;
392392}
393393
@@ -415,15 +415,15 @@ pub fn build_and_submit_payment_req_with_spent_utxo() {
415415 "amount" : 10
416416 }
417417 ] ) . to_string ( ) ;
418- get_resp_for_payment_req ( pool_handle, wallet. handle , dids[ 0 ] , & inputs, & outputs) . unwrap ( ) ;
418+ get_resp_for_payment_req ( pool_handle, wallet. handle , dids[ 0 ] , & inputs, & outputs, None ) . unwrap ( ) ;
419419
420420 //lets try to spend spent utxo while there are enough funds on the unspent one
421421 let inputs = json ! ( [ utxo_2, utxo] ) . to_string ( ) ;
422422 let outputs = json ! ( [ {
423423 "recipient" : addresses[ 2 ] ,
424424 "amount" : 20
425425 } ] ) . to_string ( ) ;
426- let err = get_resp_for_payment_req ( pool_handle, wallet. handle , dids[ 0 ] , & inputs, & outputs) . unwrap_err ( ) ;
426+ let err = get_resp_for_payment_req ( pool_handle, wallet. handle , dids[ 0 ] , & inputs, & outputs, None ) . unwrap_err ( ) ;
427427 assert_eq ! ( err, ErrorCode :: PaymentSourceDoesNotExistError ) ;
428428
429429 //utxo should stay unspent!
@@ -614,4 +614,48 @@ pub fn build_payment_req_with_taa_acceptance_and_additional_extra() {
614614 assert_eq ! ( req_parsed[ "taaAcceptance" ] , taa_acceptance) ;
615615
616616 assert_eq ! ( expected_operation, req_parsed[ "operation" ] ) ;
617+ }
618+
619+ #[ test]
620+ pub fn build_and_submit_payment_req_for_extra ( ) {
621+ let wallet = Wallet :: new ( ) ;
622+ let setup = Setup :: new ( & wallet, SetupConfig {
623+ num_addresses : 1 ,
624+ num_trustees : 4 ,
625+ num_users : 0 ,
626+ mint_tokens : Some ( vec ! [ 20 ] ) ,
627+ fees : None ,
628+ } ) ;
629+ let payment_addresses = & setup. addresses ;
630+ let pool_handle = setup. pool_handle ;
631+ let dids = setup. trustees . dids ( ) ;
632+
633+ for extra in [ "some extra_json data as string" , r#"{"data":"some extra data as string"}"# ] . iter ( )
634+ {
635+ let utxo = utils:: payment:: get_utxo:: get_first_utxo_txo_for_payment_address ( & wallet, pool_handle, dids[ 0 ] , & payment_addresses[ 0 ] ) ;
636+
637+ let inputs = json ! ( [ utxo] ) . to_string ( ) ;
638+ let outputs = json ! ( [
639+ {
640+ "recipient" : payment_addresses[ 0 ] ,
641+ "amount" : 20
642+ }
643+ ] ) . to_string ( ) ;
644+
645+ let res = get_resp_for_payment_req ( pool_handle, wallet. handle , dids[ 0 ] , & inputs, & outputs, Some ( extra. to_string ( ) ) ) . unwrap ( ) ;
646+ let res_parsed: serde_json:: Value = serde_json:: from_str ( & res) . unwrap ( ) ;
647+ let utxos = res_parsed. as_array ( ) . unwrap ( ) ;
648+ assert_eq ! ( utxos. len( ) , 1 ) ;
649+ assert_eq ! ( * extra, utxos[ 0 ] . clone( ) [ "extra" ] . as_str( ) . unwrap( ) ) ;
650+
651+ let value = utxos. get ( 0 ) . unwrap ( ) . as_object ( ) . unwrap ( ) ;
652+ let r_1 = value. get ( "receipt" ) . unwrap ( ) . as_str ( ) . unwrap ( ) ;
653+ assert_eq ! ( value. get( "amount" ) . unwrap( ) . as_i64( ) . unwrap( ) , 20 ) ;
654+
655+ let ( req, _) = indy:: payments:: build_verify_payment_req ( wallet. handle , None , & r_1) . wait ( ) . unwrap ( ) ;
656+ let res = indy:: ledger:: submit_request ( pool_handle, & req) . wait ( ) . unwrap ( ) ;
657+ let res = indy:: payments:: parse_verify_payment_response ( "sov" , & res) . wait ( ) . unwrap ( ) ;
658+ let res_parsed: serde_json:: Value = serde_json:: from_str ( & res) . unwrap ( ) ;
659+ assert_eq ! ( * extra, res_parsed[ "extra" ] . as_str( ) . unwrap( ) ) ;
660+ }
617661}
0 commit comments