33#![ cfg( test) ]
44
55use crate :: accountant:: db_access_objects:: banned_dao:: { BannedDao , BannedDaoFactory } ;
6+ use crate :: accountant:: db_access_objects:: failed_payable_dao:: {
7+ FailedPayableDao , FailedPayableDaoError , FailedPayableDaoFactory , FailedTx ,
8+ FailureRetrieveCondition , FailureStatus ,
9+ } ;
610use crate :: accountant:: db_access_objects:: payable_dao:: {
711 PayableAccount , PayableDao , PayableDaoError , PayableDaoFactory ,
812} ;
@@ -13,7 +17,7 @@ use crate::accountant::db_access_objects::receivable_dao::{
1317 ReceivableAccount , ReceivableDao , ReceivableDaoError , ReceivableDaoFactory ,
1418} ;
1519use crate :: accountant:: db_access_objects:: utils:: {
16- from_unix_timestamp, to_unix_timestamp, CustomQuery ,
20+ from_unix_timestamp, to_unix_timestamp, CustomQuery , TxHash , TxIdentifiers ,
1721} ;
1822use crate :: accountant:: payment_adjuster:: { Adjustment , AnalysisError , PaymentAdjuster } ;
1923use crate :: accountant:: scanners:: payable_scanner_extension:: msgs:: {
@@ -45,6 +49,7 @@ use masq_lib::logger::Logger;
4549use rusqlite:: { Connection , OpenFlags , Row } ;
4650use std:: any:: type_name;
4751use std:: cell:: RefCell ;
52+ use std:: collections:: { HashMap , HashSet } ;
4853use std:: fmt:: Debug ;
4954use std:: path:: Path ;
5055use std:: rc:: Rc ;
@@ -1077,6 +1082,158 @@ impl PendingPayableDaoFactoryMock {
10771082 }
10781083}
10791084
1085+ #[ derive( Default ) ]
1086+ pub struct FailedPayableDaoMock {
1087+ get_tx_identifiers_params : Arc < Mutex < Vec < HashSet < TxHash > > > > ,
1088+ get_tx_identifiers_results : RefCell < Vec < TxIdentifiers > > ,
1089+ insert_new_records_params : Arc < Mutex < Vec < Vec < FailedTx > > > > ,
1090+ insert_new_records_results : RefCell < Vec < Result < ( ) , FailedPayableDaoError > > > ,
1091+ retrieve_txs_params : Arc < Mutex < Vec < Option < FailureRetrieveCondition > > > > ,
1092+ retrieve_txs_results : RefCell < Vec < Vec < FailedTx > > > ,
1093+ update_statuses_params : Arc < Mutex < Vec < HashMap < TxHash , FailureStatus > > > > ,
1094+ update_statuses_results : RefCell < Vec < Result < ( ) , FailedPayableDaoError > > > ,
1095+ delete_records_params : Arc < Mutex < Vec < HashSet < TxHash > > > > ,
1096+ delete_records_results : RefCell < Vec < Result < ( ) , FailedPayableDaoError > > > ,
1097+ }
1098+
1099+ impl FailedPayableDao for FailedPayableDaoMock {
1100+ fn get_tx_identifiers ( & self , hashes : & HashSet < TxHash > ) -> TxIdentifiers {
1101+ self . get_tx_identifiers_params
1102+ . lock ( )
1103+ . unwrap ( )
1104+ . push ( hashes. clone ( ) ) ;
1105+ self . get_tx_identifiers_results . borrow_mut ( ) . remove ( 0 )
1106+ }
1107+
1108+ fn insert_new_records ( & self , txs : & [ FailedTx ] ) -> Result < ( ) , FailedPayableDaoError > {
1109+ self . insert_new_records_params
1110+ . lock ( )
1111+ . unwrap ( )
1112+ . push ( txs. to_vec ( ) ) ;
1113+ self . insert_new_records_results . borrow_mut ( ) . remove ( 0 )
1114+ }
1115+
1116+ fn retrieve_txs ( & self , condition : Option < FailureRetrieveCondition > ) -> Vec < FailedTx > {
1117+ self . retrieve_txs_params . lock ( ) . unwrap ( ) . push ( condition) ;
1118+ self . retrieve_txs_results . borrow_mut ( ) . remove ( 0 )
1119+ }
1120+
1121+ fn update_statuses (
1122+ & self ,
1123+ status_updates : HashMap < TxHash , FailureStatus > ,
1124+ ) -> Result < ( ) , FailedPayableDaoError > {
1125+ self . update_statuses_params
1126+ . lock ( )
1127+ . unwrap ( )
1128+ . push ( status_updates) ;
1129+ self . update_statuses_results . borrow_mut ( ) . remove ( 0 )
1130+ }
1131+
1132+ fn delete_records ( & self , hashes : & HashSet < TxHash > ) -> Result < ( ) , FailedPayableDaoError > {
1133+ self . delete_records_params
1134+ . lock ( )
1135+ . unwrap ( )
1136+ . push ( hashes. clone ( ) ) ;
1137+ self . delete_records_results . borrow_mut ( ) . remove ( 0 )
1138+ }
1139+ }
1140+
1141+ impl FailedPayableDaoMock {
1142+ pub fn new ( ) -> Self {
1143+ Self :: default ( )
1144+ }
1145+
1146+ pub fn get_tx_identifiers_params ( mut self , params : & Arc < Mutex < Vec < HashSet < TxHash > > > > ) -> Self {
1147+ self . get_tx_identifiers_params = params. clone ( ) ;
1148+ self
1149+ }
1150+
1151+ pub fn get_tx_identifiers_result ( self , result : TxIdentifiers ) -> Self {
1152+ self . get_tx_identifiers_results . borrow_mut ( ) . push ( result) ;
1153+ self
1154+ }
1155+
1156+ pub fn insert_new_records_params ( mut self , params : & Arc < Mutex < Vec < Vec < FailedTx > > > > ) -> Self {
1157+ self . insert_new_records_params = params. clone ( ) ;
1158+ self
1159+ }
1160+
1161+ pub fn insert_new_records_result ( self , result : Result < ( ) , FailedPayableDaoError > ) -> Self {
1162+ self . insert_new_records_results . borrow_mut ( ) . push ( result) ;
1163+ self
1164+ }
1165+
1166+ pub fn retrieve_txs_params (
1167+ mut self ,
1168+ params : & Arc < Mutex < Vec < Option < FailureRetrieveCondition > > > > ,
1169+ ) -> Self {
1170+ self . retrieve_txs_params = params. clone ( ) ;
1171+ self
1172+ }
1173+
1174+ pub fn retrieve_txs_result ( self , result : Vec < FailedTx > ) -> Self {
1175+ self . retrieve_txs_results . borrow_mut ( ) . push ( result) ;
1176+ self
1177+ }
1178+
1179+ pub fn update_statuses_params (
1180+ mut self ,
1181+ params : & Arc < Mutex < Vec < HashMap < TxHash , FailureStatus > > > > ,
1182+ ) -> Self {
1183+ self . update_statuses_params = params. clone ( ) ;
1184+ self
1185+ }
1186+
1187+ pub fn update_statuses_result ( self , result : Result < ( ) , FailedPayableDaoError > ) -> Self {
1188+ self . update_statuses_results . borrow_mut ( ) . push ( result) ;
1189+ self
1190+ }
1191+
1192+ pub fn delete_records_params ( mut self , params : & Arc < Mutex < Vec < HashSet < TxHash > > > > ) -> Self {
1193+ self . delete_records_params = params. clone ( ) ;
1194+ self
1195+ }
1196+
1197+ pub fn delete_records_result ( self , result : Result < ( ) , FailedPayableDaoError > ) -> Self {
1198+ self . delete_records_results . borrow_mut ( ) . push ( result) ;
1199+ self
1200+ }
1201+ }
1202+
1203+ pub struct FailedPayableDaoFactoryMock {
1204+ make_params : Arc < Mutex < Vec < ( ) > > > ,
1205+ make_results : RefCell < Vec < Box < dyn FailedPayableDao > > > ,
1206+ }
1207+
1208+ impl FailedPayableDaoFactory for FailedPayableDaoFactoryMock {
1209+ fn make ( & self ) -> Box < dyn FailedPayableDao > {
1210+ if self . make_results . borrow ( ) . len ( ) == 0 {
1211+ panic ! ( "FailedPayableDao Missing." )
1212+ } ;
1213+ self . make_params . lock ( ) . unwrap ( ) . push ( ( ) ) ;
1214+ self . make_results . borrow_mut ( ) . remove ( 0 )
1215+ }
1216+ }
1217+
1218+ impl FailedPayableDaoFactoryMock {
1219+ pub fn new ( ) -> Self {
1220+ Self {
1221+ make_params : Arc :: new ( Mutex :: new ( vec ! [ ] ) ) ,
1222+ make_results : RefCell :: new ( vec ! [ ] ) ,
1223+ }
1224+ }
1225+
1226+ pub fn make_params ( mut self , params : & Arc < Mutex < Vec < ( ) > > > ) -> Self {
1227+ self . make_params = params. clone ( ) ;
1228+ self
1229+ }
1230+
1231+ pub fn make_result ( self , result : FailedPayableDaoMock ) -> Self {
1232+ self . make_results . borrow_mut ( ) . push ( Box :: new ( result) ) ;
1233+ self
1234+ }
1235+ }
1236+
10801237pub struct PayableScannerBuilder {
10811238 payable_dao : PayableDaoMock ,
10821239 pending_payable_dao : PendingPayableDaoMock ,
0 commit comments