@@ -267,7 +267,7 @@ mod tests {
267267 IMPRESSION ,
268268 } ,
269269 spender:: Spender ,
270- test_util:: { ADVERTISER , DUMMY_AD_UNITS , DUMMY_IPFS , GUARDIAN , GUARDIAN_2 , PUBLISHER } ,
270+ test_util:: { ADVERTISER , DUMMY_AD_UNITS , DUMMY_IPFS , GUARDIAN , GUARDIAN_2 , IDS , PUBLISHER } ,
271271 util:: { logging:: new_logger, ApiUrl } ,
272272 validator:: { Heartbeat , NewState } ,
273273 Balances , BigNum , Campaign , CampaignId , Channel , ChannelId , UnifiedNum ,
@@ -1142,7 +1142,7 @@ mod tests {
11421142 // Check ApproveState of the Follower
11431143 // Assert that it exists in both validators
11441144 {
1145- let newstate_leader = leader_sentry
1145+ let latest_new_state_leader = leader_sentry
11461146 . get_our_latest_msg ( CAMPAIGN_1 . channel . id ( ) , & [ "NewState" ] )
11471147 . await
11481148 . expect ( "Should fetch NewState from Leader (Who am I) in Leader sentry" )
@@ -1174,7 +1174,7 @@ mod tests {
11741174 . expect ( "Should spend" ) ;
11751175
11761176 pretty_assertions:: assert_eq!(
1177- newstate_leader . balances,
1177+ latest_new_state_leader . balances,
11781178 expected_balances,
11791179 "Balances are as expected"
11801180 ) ;
@@ -1190,9 +1190,23 @@ mod tests {
11901190 . await
11911191 . expect ( "Should fetch Approve state from Leader" ) ;
11921192
1193+ // Due to timestamp differences in the `received` field
1194+ // we can only `assert_eq!` the messages themselves
11931195 pretty_assertions:: assert_eq!(
1194- last_approved_response_leader,
1195- last_approved_response_follower,
1196+ last_approved_response_leader
1197+ . heartbeats
1198+ . expect( "Leader response should have heartbeats" )
1199+ . clone( )
1200+ . into_iter( )
1201+ . map( |message| message. msg)
1202+ . collect:: <Vec <_>>( ) ,
1203+ last_approved_response_follower
1204+ . heartbeats
1205+ . expect( "Follower response should have heartbeats" )
1206+ . clone( )
1207+ . into_iter( )
1208+ . map( |message| message. msg)
1209+ . collect:: <Vec <_>>( ) ,
11961210 "Leader and Follower should both have the same last Approved response"
11971211 ) ;
11981212
@@ -1204,18 +1218,70 @@ mod tests {
12041218 . last_approved
12051219 . expect ( "Should have last approved messages for the events we've submitted" ) ;
12061220
1207- pretty_assertions:: assert_eq!(
1208- last_approved_leader,
1209- last_approved_follower,
1210- "Last Approved responses should be the same for both Leader & Follower"
1211- ) ;
1221+ // Due to the received time that can be different in messages
1222+ // we must check the actual ValidatorMessage without the timestamps
1223+ {
1224+ let msg_new_state_leader = last_approved_leader
1225+ . new_state
1226+ . expect ( "Leader should have last approved NewState" ) ;
12121227
1213- pretty_assertions:: assert_eq!(
1214- newstate_leader,
1215- last_approved_follower. new_state. map( |new_state| new_state. msg. 0 . clone( ) . try_checked( ) . expect( "Should have CheckedState Balances" ) )
1216- . expect( "Should have last approved NewState from submitted events" ) ,
1217- "Last approved NewState in Follower should be the same as the last NewState from Leader"
1218- ) ;
1228+ assert_eq ! (
1229+ msg_new_state_leader. from, IDS [ & LEADER ] ,
1230+ "NewState should be received from Leader"
1231+ ) ;
1232+
1233+ let msg_approve_state_leader = last_approved_leader
1234+ . approve_state
1235+ . expect ( "Leader should have last approved ApproveState" ) ;
1236+
1237+ assert_eq ! (
1238+ msg_approve_state_leader. from, IDS [ & FOLLOWER ] ,
1239+ "ApproveState should be received from Follower"
1240+ ) ;
1241+
1242+ let msg_new_state_follower = last_approved_follower
1243+ . new_state
1244+ . expect ( "Follower should have last approved NewState" ) ;
1245+
1246+ assert_eq ! (
1247+ msg_new_state_follower. from, IDS [ & LEADER ] ,
1248+ "NewState should be received from Leader"
1249+ ) ;
1250+
1251+ let msg_approve_state_follower = last_approved_follower
1252+ . approve_state
1253+ . expect ( "Follower should have last approved ApproveState" ) ;
1254+
1255+ assert_eq ! (
1256+ msg_approve_state_follower. from, IDS [ & FOLLOWER ] ,
1257+ "ApproveState should be received from Follower"
1258+ ) ;
1259+
1260+ let new_state_leader = msg_new_state_leader
1261+ . msg
1262+ . clone ( )
1263+ . into_inner ( )
1264+ . try_checked ( )
1265+ . expect ( "NewState should have valid CheckedState Balances" ) ;
1266+
1267+ let new_state_follower = msg_new_state_follower
1268+ . msg
1269+ . clone ( )
1270+ . into_inner ( )
1271+ . try_checked ( )
1272+ . expect ( "NewState should have valid CheckedState Balances" ) ;
1273+
1274+ assert_eq ! (
1275+ new_state_leader, new_state_follower,
1276+ "Last approved NewState in Leader & Follower should be the same"
1277+ ) ;
1278+
1279+ pretty_assertions:: assert_eq!(
1280+ latest_new_state_leader,
1281+ new_state_leader,
1282+ "Latest NewState from Leader should be the same as last approved NewState from Leader & Follower"
1283+ ) ;
1284+ }
12191285 }
12201286 }
12211287
0 commit comments