@@ -267,7 +267,7 @@ mod tests {
267
267
IMPRESSION ,
268
268
} ,
269
269
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 } ,
271
271
util:: { logging:: new_logger, ApiUrl } ,
272
272
validator:: { Heartbeat , NewState } ,
273
273
Balances , BigNum , Campaign , CampaignId , Channel , ChannelId , UnifiedNum ,
@@ -1142,7 +1142,7 @@ mod tests {
1142
1142
// Check ApproveState of the Follower
1143
1143
// Assert that it exists in both validators
1144
1144
{
1145
- let newstate_leader = leader_sentry
1145
+ let latest_new_state_leader = leader_sentry
1146
1146
. get_our_latest_msg ( CAMPAIGN_1 . channel . id ( ) , & [ "NewState" ] )
1147
1147
. await
1148
1148
. expect ( "Should fetch NewState from Leader (Who am I) in Leader sentry" )
@@ -1174,7 +1174,7 @@ mod tests {
1174
1174
. expect ( "Should spend" ) ;
1175
1175
1176
1176
pretty_assertions:: assert_eq!(
1177
- newstate_leader . balances,
1177
+ latest_new_state_leader . balances,
1178
1178
expected_balances,
1179
1179
"Balances are as expected"
1180
1180
) ;
@@ -1190,9 +1190,23 @@ mod tests {
1190
1190
. await
1191
1191
. expect ( "Should fetch Approve state from Leader" ) ;
1192
1192
1193
+ // Due to timestamp differences in the `received` field
1194
+ // we can only `assert_eq!` the messages themselves
1193
1195
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 <_>>( ) ,
1196
1210
"Leader and Follower should both have the same last Approved response"
1197
1211
) ;
1198
1212
@@ -1204,18 +1218,70 @@ mod tests {
1204
1218
. last_approved
1205
1219
. expect ( "Should have last approved messages for the events we've submitted" ) ;
1206
1220
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" ) ;
1212
1227
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
+ }
1219
1285
}
1220
1286
}
1221
1287
0 commit comments