From 6f8b8825b602986bde307ff5b9bc37377a7e7e2d Mon Sep 17 00:00:00 2001 From: Hugo Trentesaux <hugo@trentesaux.fr> Date: Tue, 2 May 2023 16:01:02 +0200 Subject: [PATCH] test(#109): reveal certification renewal issue --- pallets/certification/src/tests.rs | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/pallets/certification/src/tests.rs b/pallets/certification/src/tests.rs index c22880e8f..01d1b064f 100644 --- a/pallets/certification/src/tests.rs +++ b/pallets/certification/src/tests.rs @@ -176,6 +176,7 @@ fn test_cert_period() { }); } +// after given validity period, a certification should expire #[test] fn test_cert_expiry() { new_test_ext(DefaultCertificationConfig { @@ -215,3 +216,48 @@ fn test_cert_expiry() { })); }); } + +// when renewing a certification, it should not expire now, but later +#[test] +fn test_cert_renewal() { + new_test_ext(DefaultCertificationConfig { + apply_cert_period_at_genesis: false, + certs_by_receiver: btreemap![ + 0 => btreemap![ + 1 => Some(5), + 2 => Some(20), + ], + 1 => btreemap![ + 0 => Some(20), + 2 => Some(20), + ], + 2 => btreemap![ + 0 => Some(20), + 1 => Some(20), + ], + ], + }) + .execute_with(|| { + run_to_block(2); + // renew certification from bob to alice + // this certification should expire 10 blocks later (at block 12) + assert_eq!( + DefaultCertification::add_cert(RuntimeOrigin::signed(1), 1, 0), + Ok(().into()) + ); + System::assert_last_event(RuntimeEvent::DefaultCertification(Event::RenewedCert { + issuer: 1, + receiver: 0, + })); + + run_to_block(12); + // expiry of previously renewed cert + System::assert_last_event(RuntimeEvent::DefaultCertification(Event::RemovedCert { + issuer: 1, + issuer_issued_count: 1, + receiver: 0, + receiver_received_count: 1, + expiration: true, + })); + }); +} -- GitLab