From 0d64ba4268106fffe430d41b541c1aeedd4f8da5 Mon Sep 17 00:00:00 2001 From: Adrian Catangiu Date: Mon, 31 Oct 2022 17:41:01 +0200 Subject: [PATCH] client/beefy: fix incorrect BEEFY justifications import test (#12593) Signed-off-by: Adrian Catangiu --- client/beefy/src/tests.rs | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/client/beefy/src/tests.rs b/client/beefy/src/tests.rs index f0647d7b142e6..b0a1433fafec6 100644 --- a/client/beefy/src/tests.rs +++ b/client/beefy/src/tests.rs @@ -755,10 +755,16 @@ fn beefy_importing_blocks() { block_on(block_import.import_block(params(block, None), HashMap::new())).unwrap(), ImportResult::AlreadyInChain ); - // Verify no justifications present: + // Verify no BEEFY justifications present: { // none in backend, - assert!(full_client.justifications(&block_id).unwrap().is_none()); + assert_eq!( + full_client + .justifications(&block_id) + .unwrap() + .and_then(|j| j.get(BEEFY_ENGINE_ID).cloned()), + None + ); // and none sent to BEEFY worker. block_on(poll_fn(move |cx| { assert_eq!(justif_recv.poll_next_unpin(cx), Poll::Pending); @@ -787,11 +793,18 @@ fn beefy_importing_blocks() { ..Default::default() }), ); - // Verify justification successfully imported: + // Verify BEEFY justification successfully imported: { - // available in backend, - assert!(full_client.justifications(&BlockId::Number(block_num)).unwrap().is_some()); - // and also sent to BEEFY worker. + // still not in backend (worker is responsible for appending to backend), + assert_eq!( + full_client + .justifications(&block_id) + .unwrap() + .and_then(|j| j.get(BEEFY_ENGINE_ID).cloned()), + None + ); + // but sent to BEEFY worker + // (worker will append it to backend when all previous mandatory justifs are there as well). block_on(poll_fn(move |cx| { match justif_recv.poll_next_unpin(cx) { Poll::Ready(Some(_justification)) => (), @@ -823,10 +836,16 @@ fn beefy_importing_blocks() { ..Default::default() }), ); - // Verify bad justifications was not imported: + // Verify bad BEEFY justifications was not imported: { // none in backend, - assert!(full_client.justifications(&block_id).unwrap().is_none()); + assert_eq!( + full_client + .justifications(&BlockId::Number(block_num)) + .unwrap() + .and_then(|j| j.get(BEEFY_ENGINE_ID).cloned()), + None + ); // and none sent to BEEFY worker. block_on(poll_fn(move |cx| { assert_eq!(justif_recv.poll_next_unpin(cx), Poll::Pending);