@@ -102,6 +102,7 @@ type Balance = U256;
102102
103103/// Information for Ravs that are abstracted away from the SignedRav itself
104104#[ derive( Debug , Default , PartialEq , Eq ) ]
105+ #[ cfg_attr( test, derive( Clone ) ) ]
105106pub struct RavInformation {
106107 /// Allocation Id of a Rav
107108 pub allocation_id : Address ,
@@ -140,6 +141,8 @@ impl From<&tap_graph::v2::SignedRav> for RavInformation {
140141///
141142/// It has different logic depending on the variant
142143#[ derive( Debug ) ]
144+ #[ cfg_attr( test, derive( educe:: Educe ) ) ]
145+ #[ cfg_attr( test, educe( PartialEq , Eq , Clone ) ) ]
143146pub enum ReceiptFees {
144147 /// Adds the receipt value to the fee tracker
145148 ///
@@ -153,7 +156,11 @@ pub enum ReceiptFees {
153156 ///
154157 /// If the rav response was successful, update the rav tracker
155158 /// If not, signalize the fee_tracker to apply proper backoff
156- RavRequestResponse ( ( UnaggregatedReceipts , anyhow:: Result < Option < RavInformation > > ) ) ,
159+ RavRequestResponse (
160+ UnaggregatedReceipts ,
161+ #[ cfg_attr( test, educe( PartialEq ( ignore) , Clone ( method( clone_rav_result) ) ) ) ]
162+ anyhow:: Result < Option < RavInformation > > ,
163+ ) ,
157164 /// Ignores all logic and simply retry Allow/Deny and Rav Request logic
158165 ///
159166 /// This is used inside a scheduler to trigger a Rav request in case the
@@ -162,8 +169,20 @@ pub enum ReceiptFees {
162169 Retry ,
163170}
164171
172+ #[ cfg( test) ]
173+ fn clone_rav_result (
174+ res : & anyhow:: Result < Option < RavInformation > > ,
175+ ) -> anyhow:: Result < Option < RavInformation > > {
176+ match res {
177+ Ok ( val) => Ok ( val. clone ( ) ) ,
178+ Err ( _) => Err ( anyhow:: anyhow!( "Some error" ) ) ,
179+ }
180+ }
181+
165182/// Enum containing all types of messages that a [SenderAccount] can receive
166183#[ derive( Debug ) ]
184+ #[ cfg_attr( test, derive( educe:: Educe ) ) ]
185+ #[ cfg_attr( test, educe( PartialEq , Eq , Clone ) ) ]
167186pub enum SenderAccountMessage {
168187 /// Updates the sender balance and
169188 UpdateBalanceAndLastRavs ( Balance , RavMap ) ,
@@ -185,13 +204,22 @@ pub enum SenderAccountMessage {
185204 UpdateRav ( RavInformation ) ,
186205 #[ cfg( test) ]
187206 /// Returns the sender fee tracker, used for tests
188- GetSenderFeeTracker ( ractor:: RpcReplyPort < SenderFeeTracker > ) ,
207+ GetSenderFeeTracker (
208+ #[ educe( PartialEq ( ignore) , Clone ( method( crate :: test:: actors:: clone_rpc_reply) ) ) ]
209+ ractor:: RpcReplyPort < SenderFeeTracker > ,
210+ ) ,
189211 #[ cfg( test) ]
190212 /// Returns the Deny status, used for tests
191- GetDeny ( ractor:: RpcReplyPort < bool > ) ,
213+ GetDeny (
214+ #[ educe( PartialEq ( ignore) , Clone ( method( crate :: test:: actors:: clone_rpc_reply) ) ) ]
215+ ractor:: RpcReplyPort < bool > ,
216+ ) ,
192217 #[ cfg( test) ]
193218 /// Returns if the scheduler is enabled, used for tests
194- IsSchedulerEnabled ( ractor:: RpcReplyPort < bool > ) ,
219+ IsSchedulerEnabled (
220+ #[ educe( PartialEq ( ignore) , Clone ( method( crate :: test:: actors:: clone_rpc_reply) ) ) ]
221+ ractor:: RpcReplyPort < bool > ,
222+ ) ,
195223}
196224
197225/// A SenderAccount manages the receipts accounting between the indexer and the sender across
@@ -1040,8 +1068,8 @@ impl Actor for SenderAccount {
10401068 . unwrap_or_default ( ) as f64 ,
10411069 ) ;
10421070 }
1043- ReceiptFees :: RavRequestResponse ( rav_result) => {
1044- state. finalize_rav_request ( allocation_id, rav_result) ;
1071+ ReceiptFees :: RavRequestResponse ( fees , rav_result) => {
1072+ state. finalize_rav_request ( allocation_id, ( fees , rav_result) ) ;
10451073 }
10461074 ReceiptFees :: UpdateValue ( unaggregated_fees) => {
10471075 state. update_sender_fee ( allocation_id, unaggregated_fees) ;
@@ -1415,50 +1443,6 @@ pub mod tests {
14151443 } ,
14161444 } ;
14171445
1418- // we implement the PartialEq and Eq traits for SenderAccountMessage to be able to compare
1419- impl Eq for SenderAccountMessage { }
1420-
1421- impl PartialEq for SenderAccountMessage {
1422- fn eq ( & self , other : & Self ) -> bool {
1423- match ( self , other) {
1424- ( Self :: UpdateAllocationIds ( l0) , Self :: UpdateAllocationIds ( r0) ) => l0 == r0,
1425- ( Self :: UpdateReceiptFees ( l0, l1) , Self :: UpdateReceiptFees ( r0, r1) ) => {
1426- l0 == r0
1427- && match ( l1, r1) {
1428- ( ReceiptFees :: NewReceipt ( l1, l2) , ReceiptFees :: NewReceipt ( r1, r2) ) => {
1429- r1 == l1 && r2 == l2
1430- }
1431- ( ReceiptFees :: UpdateValue ( l) , ReceiptFees :: UpdateValue ( r) ) => r == l,
1432- (
1433- ReceiptFees :: RavRequestResponse ( l) ,
1434- ReceiptFees :: RavRequestResponse ( r) ,
1435- ) => match ( l, r) {
1436- ( ( fee, Ok ( rav) ) , ( fee1, Ok ( rav1) ) ) => fee == fee1 && rav == rav1,
1437- ( ( fee, Err ( error) ) , ( fee1, Err ( error1) ) ) => {
1438- fee == fee1 && error. to_string ( ) == error1. to_string ( )
1439- }
1440- _ => false ,
1441- } ,
1442- ( ReceiptFees :: Retry , ReceiptFees :: Retry ) => true ,
1443- _ => false ,
1444- }
1445- }
1446- (
1447- Self :: UpdateInvalidReceiptFees ( l0, l1) ,
1448- Self :: UpdateInvalidReceiptFees ( r0, r1) ,
1449- ) => l0 == r0 && l1 == r1,
1450- ( Self :: NewAllocationId ( l0) , Self :: NewAllocationId ( r0) ) => l0 == r0,
1451- ( a, b) => match (
1452- core:: mem:: discriminant ( self ) ,
1453- core:: mem:: discriminant ( other) ,
1454- ) {
1455- ( a, b) if a != b => false ,
1456- _ => unimplemented ! ( "PartialEq not implementated for {a:?} and {b:?}" ) ,
1457- } ,
1458- }
1459- }
1460- }
1461-
14621446 /// Prefix shared between tests so we don't have conflicts in the global registry
14631447 const BUFFER_DURATION : Duration = Duration :: from_millis ( 100 ) ;
14641448 const RETRY_DURATION : Duration = Duration :: from_millis ( 1000 ) ;
0 commit comments