@@ -12,7 +12,7 @@ use crate::data::{
1212use crate :: util:: BcrKeys ;
1313use async_trait:: async_trait;
1414use bcr_ebill_core:: ServiceTraitBounds ;
15- use bcr_ebill_core:: bill:: { BillAction , BillIssueData , PastPaymentResult } ;
15+ use bcr_ebill_core:: bill:: { BillAction , BillHistory , BillIssueData , PastPaymentResult } ;
1616use bcr_ebill_core:: blockchain:: bill:: chain:: BillBlockPlaintextWrapper ;
1717
1818pub use error:: Error ;
@@ -235,6 +235,14 @@ pub trait BillServiceApi: ServiceTraitBounds {
235235 signer_keys : & BcrKeys ,
236236 court_node_id : & NodeId ,
237237 ) -> Result < ( ) > ;
238+
239+ async fn get_bill_history (
240+ & self ,
241+ bill_id : & BillId ,
242+ local_identity : & Identity ,
243+ current_identity_node_id : & NodeId ,
244+ current_timestamp : u64 ,
245+ ) -> Result < BillHistory > ;
238246}
239247
240248#[ cfg( test) ]
@@ -6163,7 +6171,7 @@ pub mod tests {
61636171 }
61646172
61656173 #[ tokio:: test]
6166- async fn recourse_bitcredit_bill_fails_for_anon ( ) {
6174+ async fn recourse_bitcredit_bill_works_for_anon ( ) {
61676175 let mut ctx = get_ctx ( ) ;
61686176 let identity = get_baseline_identity ( ) ;
61696177 let mut bill = get_baseline_bill ( & bill_id_test ( ) ) ;
@@ -6219,6 +6227,9 @@ pub mod tests {
62196227 . expect_send_bill_recourse_paid_event ( )
62206228 . returning ( |_, _| Ok ( ( ) ) ) ;
62216229
6230+ // Populates identity block
6231+ expect_populates_identity_block ( & mut ctx) ;
6232+
62226233 let service = get_service ( ctx) ;
62236234
62246235 let res = service
@@ -6235,11 +6246,9 @@ pub mod tests {
62356246 1731593928 ,
62366247 )
62376248 . await ;
6238- assert ! ( res. is_err( ) ) ;
6239- assert ! ( matches!(
6240- res. as_ref( ) . unwrap_err( ) ,
6241- Error :: Validation ( ValidationError :: SignerCantBeAnon )
6242- ) ) ;
6249+ assert ! ( res. is_ok( ) ) ;
6250+ assert_eq ! ( res. as_ref( ) . unwrap( ) . blocks( ) . len( ) , 3 ) ;
6251+ assert_eq ! ( res. unwrap( ) . blocks( ) [ 2 ] . op_code, BillOpCode :: Recourse ) ;
62436252 }
62446253
62456254 #[ test]
@@ -7360,4 +7369,40 @@ pub mod tests {
73607369 Err ( Error :: Validation ( ValidationError :: InvalidNodeId ) )
73617370 ) ) ;
73627371 }
7372+
7373+ #[ tokio:: test]
7374+ async fn get_bill_history_baseline ( ) {
7375+ let mut ctx = get_ctx ( ) ;
7376+ let identity = get_baseline_identity ( ) ;
7377+ let mut bill = get_baseline_bill ( & bill_id_test ( ) ) ;
7378+ bill. drawee = bill_identified_participant_only_node_id ( identity. identity . node_id . clone ( ) ) ;
7379+ let drawer_node_id = bill. drawer . node_id . clone ( ) ;
7380+ ctx. bill_store . expect_exists ( ) . returning ( |_| Ok ( true ) ) ;
7381+ ctx. bill_blockchain_store
7382+ . expect_get_chain ( )
7383+ . returning ( move |_| Ok ( get_genesis_chain ( Some ( bill. clone ( ) ) ) ) ) ;
7384+ ctx. notification_service
7385+ . expect_get_active_bill_notification ( )
7386+ . with ( eq ( bill_id_test ( ) ) )
7387+ . returning ( |_| None ) ;
7388+
7389+ let res = get_service ( ctx)
7390+ . get_bill_history (
7391+ & bill_id_test ( ) ,
7392+ & identity. identity ,
7393+ & identity. identity . node_id ,
7394+ 1731593928 ,
7395+ )
7396+ . await ;
7397+ assert ! ( res. is_ok( ) ) ;
7398+ assert_eq ! ( res. as_ref( ) . unwrap( ) . blocks. len( ) , 1 ) ;
7399+ assert_eq ! (
7400+ res. as_ref( ) . unwrap( ) . blocks[ 0 ] . block_type,
7401+ BillOpCode :: Issue
7402+ ) ;
7403+ assert_eq ! (
7404+ res. as_ref( ) . unwrap( ) . blocks[ 0 ] . signed. data. node_id( ) ,
7405+ drawer_node_id
7406+ ) ;
7407+ }
73637408}
0 commit comments