diff --git a/pallets/duniter-wot/src/tests.rs b/pallets/duniter-wot/src/tests.rs index c0d091a8cc5c91bb6f745a5b9754e0305020fc9a..3950835ae783efd8ae43fefd0fde03fa7a665163 100644 --- a/pallets/duniter-wot/src/tests.rs +++ b/pallets/duniter-wot/src/tests.rs @@ -584,8 +584,7 @@ fn test_cert_can_not_be_issued() { )); run_to_block(11); - // /!\ COUNTERINTUITIVE BEHAVIOR - // Dave should not be able to receive a smith cert since he did not request smith membership + // Dave should be able to receive a smith cert since assert_ok!(SmithCert::add_cert(RuntimeOrigin::signed(3), 3, 4)); // Bob renews his smith certification towards Alice assert_ok!(SmithCert::add_cert(RuntimeOrigin::signed(2), 2, 1)); @@ -646,3 +645,54 @@ fn test_cert_can_not_be_issued() { // she would have been able to emit a cert without being member }) } + +/// test non smith identity can not emit smith cert +#[test] +fn test_non_smith_can_not_issue_smith_cert() { + new_test_ext(4, 3).execute_with(|| { + assert_noop!( + SmithCert::add_cert(RuntimeOrigin::signed(4), 4, 1), + pallet_certification::Error::<Test, Instance2>::NotEnoughCertReceived + ); + }) +} + +/// FIXME this test should not fail with NotRespectCertPeriod but NotSmith or somthing like that +/// test non smith identity can not emit smith cert +#[test] +fn test_non_smith_with_certs_can_not_issue_smith_cert() { + new_test_ext(4, 3).execute_with(|| { + run_to_block(2); + assert_ok!(SmithCert::add_cert(RuntimeOrigin::signed(1), 1, 4)); + assert_ok!(SmithCert::add_cert(RuntimeOrigin::signed(2), 2, 4)); + assert_ok!(SmithCert::add_cert(RuntimeOrigin::signed(3), 3, 4)); + assert_noop!( + SmithCert::add_cert(RuntimeOrigin::signed(4), 4, 1), + pallet_certification::Error::<Test, Instance2>::NotRespectCertPeriod + ); + }) +} + +/// FIXME this test should not succeed because Dave should not be able to issue cert +/// after revocation of his smith membership +/// test non smith identity can not emit smith cert +#[test] +fn test_revoked_smith_with_certs_can_not_issue_smith_cert() { + new_test_ext(4, 3).execute_with(|| { + run_to_block(2); + assert_ok!(SmithCert::add_cert(RuntimeOrigin::signed(1), 1, 4)); + assert_ok!(SmithCert::add_cert(RuntimeOrigin::signed(2), 2, 4)); + assert_ok!(SmithCert::add_cert(RuntimeOrigin::signed(3), 3, 4)); + assert_ok!(SmithMembership::claim_membership(RuntimeOrigin::signed(4))); + assert_noop!( + SmithCert::add_cert(RuntimeOrigin::signed(4), 4, 1), + pallet_certification::Error::<Test, Instance2>::NotRespectCertPeriod + ); + run_to_block(4); + assert_ok!(SmithCert::add_cert(RuntimeOrigin::signed(4), 4, 1),); + run_to_block(5); + assert_ok!(SmithMembership::revoke_membership(RuntimeOrigin::signed(4))); + run_to_block(6); + assert_ok!(SmithCert::add_cert(RuntimeOrigin::signed(4), 4, 1),); + }) +}