From 45b911920de2c8f588f7067b0b3f3ad615e52175 Mon Sep 17 00:00:00 2001 From: Polkaverse Date: Thu, 17 Aug 2023 14:45:39 +0530 Subject: [PATCH 1/4] updated initial vale to 1 and tagline limit --- pallets/community/src/benchmarking.rs | 28 +++--- pallets/community/src/tests.rs | 132 +++++++++++++------------- pallets/passport/src/benchmarking.rs | 4 +- pallets/passport/src/tests.rs | 26 ++--- pallets/proposal/src/benchmarking.rs | 2 +- pallets/proposal/src/tests.rs | 66 ++++++------- primitives/src/macros.rs | 2 +- runtime/src/lib.rs | 2 +- 8 files changed, 131 insertions(+), 131 deletions(-) diff --git a/pallets/community/src/benchmarking.rs b/pallets/community/src/benchmarking.rs index a3c089ce..1b794162 100644 --- a/pallets/community/src/benchmarking.rs +++ b/pallets/community/src/benchmarking.rs @@ -53,7 +53,7 @@ benchmarks! { Some("#E76080".into()) ) verify { - assert!(Communities::::get(T::Helper::community(0)).is_some()); + assert!(Communities::::get(T::Helper::community(1)).is_some()); } update_community { @@ -80,10 +80,10 @@ benchmarks! { let description = "Jur is the core community of the Jur ecosystem"; }: _( - RawOrigin::Signed(caller), T::Helper::community(0), Some(logo.into()), Some(description.into()) + RawOrigin::Signed(caller), T::Helper::community(1), Some(logo.into()), Some(description.into()) ) verify { - assert_last_event::(Event::::UpdatedCommunity(T::Helper::community(0)).into()); + assert_last_event::(Event::::UpdatedCommunity(T::Helper::community(1)).into()); } update_metadata { @@ -125,10 +125,10 @@ benchmarks! { }; }: _( - RawOrigin::Signed(caller), T::Helper::community(0), community_metadata + RawOrigin::Signed(caller), T::Helper::community(1), community_metadata ) verify { - assert_last_event::(Event::::UpdatedMetadata(T::Helper::community(0)).into()); + assert_last_event::(Event::::UpdatedMetadata(T::Helper::community(1)).into()); } accept_members { @@ -154,10 +154,10 @@ benchmarks! { let members = vec![account("sub", 2, SEED), account("sub", 3, SEED)]; }: _( - RawOrigin::Signed(caller), T::Helper::community(0), members + RawOrigin::Signed(caller), T::Helper::community(1), members ) verify { - assert_last_event::(Event::::AddedMembers(T::Helper::community(0)).into()); + assert_last_event::(Event::::AddedMembers(T::Helper::community(1)).into()); } join_community { @@ -183,10 +183,10 @@ benchmarks! { let member: T::AccountId = whitelisted_caller(); }: _( - RawOrigin::Signed(member), T::Helper::community(0) + RawOrigin::Signed(member), T::Helper::community(1) ) verify { - assert_last_event::(Event::::JoinedCommunity(T::Helper::community(0)).into()); + assert_last_event::(Event::::JoinedCommunity(T::Helper::community(1)).into()); } leave_community { @@ -210,10 +210,10 @@ benchmarks! { ).unwrap(); }: _( - RawOrigin::Signed(member), T::Helper::community(0) + RawOrigin::Signed(member), T::Helper::community(1) ) verify { - assert_last_event::(Event::::LeavedCommunity(T::Helper::community(0)).into()); + assert_last_event::(Event::::LeavedCommunity(T::Helper::community(1)).into()); } remove_member { @@ -238,7 +238,7 @@ benchmarks! { ).unwrap(); }: _( - RawOrigin::Signed(caller), member.clone(), T::Helper::community(0) + RawOrigin::Signed(caller), member.clone(), T::Helper::community(1) ) verify { assert_last_event::(Event::::RemovedMember(member).into()); @@ -269,10 +269,10 @@ benchmarks! { let s_color = "#222308"; }: _( - RawOrigin::Signed(caller), T::Helper::community(0), Some(tag.into()), Some(p_color.into()), Some(s_color.into()) + RawOrigin::Signed(caller), T::Helper::community(1), Some(tag.into()), Some(p_color.into()), Some(s_color.into()) ) verify { - assert_last_event::(Event::::UpdatedTagAndColors(T::Helper::community(0)).into()); + assert_last_event::(Event::::UpdatedTagAndColors(T::Helper::community(1)).into()); } impl_benchmark_test_suite!(Community, crate::mock::new_test_ext(), crate::mock::Test); diff --git a/pallets/community/src/tests.rs b/pallets/community/src/tests.rs index e7967f8b..311d8edf 100644 --- a/pallets/community/src/tests.rs +++ b/pallets/community/src/tests.rs @@ -9,15 +9,15 @@ use crate::types::Category; #[test] fn create_community_works() { new_test_ext().execute_with(|| { - assert!(!Communities::::contains_key(0)); + assert!(!Communities::::contains_key(1)); add_founder(); create_community(); - assert!(Communities::::contains_key(0)); + assert!(Communities::::contains_key(1)); setup_blocks(5); create_community(); assert_ne!( - Some(Communities::::get(1).unwrap().reference_id), - Some(Communities::::get(0).unwrap().reference_id) + Some(Communities::::get(2).unwrap().reference_id), + Some(Communities::::get(1).unwrap().reference_id) ); }); } @@ -41,8 +41,8 @@ fn create_community_works_only_with_name() { Some("#E76080".into()) ) .unwrap(); - assert!(Communities::::contains_key(0)); - assert_eq!(Communities::::get(0).unwrap().name.to_vec(), "Jur".as_bytes().to_vec()); + assert!(Communities::::contains_key(1)); + assert_eq!(Communities::::get(1).unwrap().name.to_vec(), "Jur".as_bytes().to_vec()); }); } @@ -103,12 +103,12 @@ fn update_community_not_works_for_invalid_input() { ); add_founder(); create_community(); - assert!(Communities::::contains_key(0)); + assert!(Communities::::contains_key(1)); assert_noop!( Community::update_community( RuntimeOrigin::signed(2), - 0, + 1, Some(logo.into()), Some(description.into()) ), @@ -122,10 +122,10 @@ fn update_community_works() { new_test_ext().execute_with(|| { add_founder(); create_community(); - assert!(Communities::::contains_key(0)); + assert!(Communities::::contains_key(1)); assert_eq!( - Communities::::get(0).unwrap().logo.unwrap(), + Communities::::get(1).unwrap().logo.unwrap(), "bafkreifec54rzopwm6mvqm3fknmdlsw2yefpdr7xrgtsron62on2nynegq" .as_bytes() .to_vec() @@ -136,12 +136,12 @@ fn update_community_works() { assert_ok!(Community::update_community( RuntimeOrigin::signed(1), - 0, + 1, Some(logo.into()), Some(description.into()) )); - assert_eq!(Communities::::get(0).unwrap().logo.unwrap(), logo.as_bytes().to_vec()); + assert_eq!(Communities::::get(1).unwrap().logo.unwrap(), logo.as_bytes().to_vec()); }); } @@ -153,10 +153,10 @@ fn accept_members_works() { create_community(); let new_members = vec![3, 4]; - assert_eq!(Communities::::get(0).unwrap().members, vec![1, 2]); + assert_eq!(Communities::::get(1).unwrap().members, vec![1, 2]); - assert_ok!(Community::accept_members(RuntimeOrigin::signed(1), 0, new_members)); - assert_eq!(Communities::::get(0).unwrap().members, vec![1, 2, 3, 4]); + assert_ok!(Community::accept_members(RuntimeOrigin::signed(1), 1, new_members)); + assert_eq!(Communities::::get(1).unwrap().members, vec![1, 2, 3, 4]); }); } @@ -174,10 +174,10 @@ fn accept_members_not_works_for_invalid_input() { add_founder(); create_community(); - assert_eq!(Communities::::get(0).unwrap().members, vec![1, 2]); + assert_eq!(Communities::::get(1).unwrap().members, vec![1, 2]); assert_noop!( - Community::accept_members(RuntimeOrigin::signed(2), 0, new_members), + Community::accept_members(RuntimeOrigin::signed(2), 1, new_members), Error::::NoPermission ); }); @@ -188,10 +188,10 @@ fn update_metadata_works() { new_test_ext().execute_with(|| { add_founder(); create_community(); - assert!(Communities::::contains_key(0)); + assert!(Communities::::contains_key(1)); assert_eq!( - Communities::::get(0) + Communities::::get(1) .unwrap() .metadata .unwrap() @@ -217,10 +217,10 @@ fn update_metadata_works() { values: Some(vec!["Peace".into(), "No gender discrimination".into()]), }; - assert_ok!(Community::update_metadata(RuntimeOrigin::signed(1), 0, community_metadata)); + assert_ok!(Community::update_metadata(RuntimeOrigin::signed(1), 1, community_metadata)); assert_eq!( - Communities::::get(0) + Communities::::get(1) .unwrap() .metadata .unwrap() @@ -229,7 +229,7 @@ fn update_metadata_works() { ); assert_eq!( - Communities::::get(0) + Communities::::get(1) .unwrap() .metadata .unwrap() @@ -237,7 +237,7 @@ fn update_metadata_works() { None ); - assert_eq!(Communities::::get(0).unwrap().metadata.unwrap().norms, None); + assert_eq!(Communities::::get(1).unwrap().metadata.unwrap().norms, None); }); } @@ -246,10 +246,10 @@ fn update_metadata_not_works_for_invalid_community_id() { new_test_ext().execute_with(|| { add_founder(); create_community(); - assert!(Communities::::contains_key(0)); + assert!(Communities::::contains_key(1)); assert_eq!( - Communities::::get(0) + Communities::::get(1) .unwrap() .metadata .unwrap() @@ -258,7 +258,7 @@ fn update_metadata_not_works_for_invalid_community_id() { ); assert_noop!( - Community::update_metadata(RuntimeOrigin::signed(1), 1, get_metadata()), + Community::update_metadata(RuntimeOrigin::signed(1), 2, get_metadata()), Error::::CommunityNotExist ); }); @@ -269,10 +269,10 @@ fn update_metadata_not_works_for_invalid_caller() { new_test_ext().execute_with(|| { add_founder(); create_community(); - assert!(Communities::::contains_key(0)); + assert!(Communities::::contains_key(1)); assert_eq!( - Communities::::get(0) + Communities::::get(1) .unwrap() .metadata .unwrap() @@ -281,7 +281,7 @@ fn update_metadata_not_works_for_invalid_caller() { ); assert_noop!( - Community::update_metadata(RuntimeOrigin::signed(2), 0, get_metadata()), + Community::update_metadata(RuntimeOrigin::signed(2), 1, get_metadata()), Error::::NoPermission ); }); @@ -294,23 +294,23 @@ fn join_community_works() { add_founder(); create_community(); - assert_eq!(Communities::::get(0).unwrap().members, vec![1, 2]); + assert_eq!(Communities::::get(1).unwrap().members, vec![1, 2]); - assert_ok!(Community::join_community(RuntimeOrigin::signed(3), 0)); - assert_eq!(Communities::::get(0).unwrap().members, vec![1, 2, 3]); + assert_ok!(Community::join_community(RuntimeOrigin::signed(3), 1)); + assert_eq!(Communities::::get(1).unwrap().members, vec![1, 2, 3]); }); } #[test] fn join_community_not_works_for_already_joined() { new_test_ext().execute_with(|| { - assert!(!Communities::::contains_key(0)); + assert!(!Communities::::contains_key(1)); add_founder(); create_community(); - assert_eq!(Communities::::get(0).unwrap().members, vec![1, 2]); + assert_eq!(Communities::::get(1).unwrap().members, vec![1, 2]); assert_noop!( - Community::join_community(RuntimeOrigin::signed(2), 0), + Community::join_community(RuntimeOrigin::signed(2), 1), Error::::AlreadyMember ); }); @@ -319,13 +319,13 @@ fn join_community_not_works_for_already_joined() { #[test] fn join_community_not_works_for_invalid_community() { new_test_ext().execute_with(|| { - assert!(!Communities::::contains_key(0)); + assert!(!Communities::::contains_key(1)); add_founder(); create_community(); - assert_eq!(Communities::::get(0).unwrap().members, vec![1, 2]); + assert_eq!(Communities::::get(1).unwrap().members, vec![1, 2]); assert_noop!( - Community::join_community(RuntimeOrigin::signed(2), 1), + Community::join_community(RuntimeOrigin::signed(2), 2), Error::::CommunityNotExist ); }); @@ -334,28 +334,28 @@ fn join_community_not_works_for_invalid_community() { #[test] fn leave_community_works() { new_test_ext().execute_with(|| { - assert!(!Communities::::contains_key(0)); + assert!(!Communities::::contains_key(1)); add_founder(); create_community(); - assert_eq!(Communities::::get(0).unwrap().members, vec![1, 2]); + assert_eq!(Communities::::get(1).unwrap().members, vec![1, 2]); - assert_ok!(Community::leave_community(RuntimeOrigin::signed(2), 0)); - assert_eq!(Communities::::get(0).unwrap().members, vec![1]); + assert_ok!(Community::leave_community(RuntimeOrigin::signed(2), 1)); + assert_eq!(Communities::::get(1).unwrap().members, vec![1]); }); } #[test] fn leave_community_not_work_for_member_not_part_of_community() { new_test_ext().execute_with(|| { - assert!(!Communities::::contains_key(0)); + assert!(!Communities::::contains_key(1)); add_founder(); create_community(); - assert_eq!(Communities::::get(0).unwrap().members, vec![1, 2]); + assert_eq!(Communities::::get(1).unwrap().members, vec![1, 2]); assert_noop!( - Community::leave_community(RuntimeOrigin::signed(3), 0), + Community::leave_community(RuntimeOrigin::signed(3), 1), Error::::NotMember ); }); @@ -364,14 +364,14 @@ fn leave_community_not_work_for_member_not_part_of_community() { #[test] fn leave_community_not_work_for_invalid_community() { new_test_ext().execute_with(|| { - assert!(!Communities::::contains_key(0)); + assert!(!Communities::::contains_key(1)); add_founder(); create_community(); - assert_eq!(Communities::::get(0).unwrap().members, vec![1, 2]); + assert_eq!(Communities::::get(1).unwrap().members, vec![1, 2]); assert_noop!( - Community::leave_community(RuntimeOrigin::signed(2), 1), + Community::leave_community(RuntimeOrigin::signed(2), 2), Error::::CommunityNotExist ); }); @@ -380,28 +380,28 @@ fn leave_community_not_work_for_invalid_community() { #[test] fn remove_member_works() { new_test_ext().execute_with(|| { - assert!(!Communities::::contains_key(0)); + assert!(!Communities::::contains_key(1)); add_founder(); create_community(); - assert_eq!(Communities::::get(0).unwrap().members, vec![1, 2]); + assert_eq!(Communities::::get(1).unwrap().members, vec![1, 2]); - assert_ok!(Community::remove_member(RuntimeOrigin::signed(1), 2, 0)); - assert_eq!(Communities::::get(0).unwrap().members, vec![1]); + assert_ok!(Community::remove_member(RuntimeOrigin::signed(1), 2, 1)); + assert_eq!(Communities::::get(1).unwrap().members, vec![1]); }); } #[test] fn remove_member_not_work_for_member_not_part_of_community() { new_test_ext().execute_with(|| { - assert!(!Communities::::contains_key(0)); + assert!(!Communities::::contains_key(1)); add_founder(); create_community(); - assert_eq!(Communities::::get(0).unwrap().members, vec![1, 2]); + assert_eq!(Communities::::get(1).unwrap().members, vec![1, 2]); assert_noop!( - Community::remove_member(RuntimeOrigin::signed(1), 3, 0), + Community::remove_member(RuntimeOrigin::signed(1), 3, 1), Error::::NotMember ); }); @@ -410,14 +410,14 @@ fn remove_member_not_work_for_member_not_part_of_community() { #[test] fn remove_member_not_work_for_invalid_community() { new_test_ext().execute_with(|| { - assert!(!Communities::::contains_key(0)); + assert!(!Communities::::contains_key(1)); add_founder(); create_community(); - assert_eq!(Communities::::get(0).unwrap().members, vec![1, 2]); + assert_eq!(Communities::::get(1).unwrap().members, vec![1, 2]); assert_noop!( - Community::remove_member(RuntimeOrigin::signed(1), 2, 1), + Community::remove_member(RuntimeOrigin::signed(1), 2, 2), Error::::CommunityNotExist ); }); @@ -428,24 +428,24 @@ fn update_community_tag_and_colors_works() { new_test_ext().execute_with(|| { add_founder(); create_community(); - assert!(Communities::::contains_key(0)); + assert!(Communities::::contains_key(1)); assert_eq!( - Communities::::get(0).unwrap().tag, + Communities::::get(1).unwrap().tag, "tag" .as_bytes() .to_vec() ); assert_eq!( - Communities::::get(0).unwrap().primary_color, + Communities::::get(1).unwrap().primary_color, "#222307" .as_bytes() .to_vec() ); assert_eq!( - Communities::::get(0).unwrap().secondary_color, + Communities::::get(1).unwrap().secondary_color, "#E76080" .as_bytes() .to_vec() @@ -457,14 +457,14 @@ fn update_community_tag_and_colors_works() { assert_ok!(Community::update_passport_metadata( RuntimeOrigin::signed(1), - 0, + 1, Some(tag.into()), Some(p_color.into()), Some(s_color.into()) )); - assert_eq!(Communities::::get(0).unwrap().tag, tag.as_bytes().to_vec()); - assert_eq!(Communities::::get(0).unwrap().primary_color, p_color.as_bytes().to_vec()); - assert_eq!(Communities::::get(0).unwrap().secondary_color, s_color.as_bytes().to_vec()); + assert_eq!(Communities::::get(1).unwrap().tag, tag.as_bytes().to_vec()); + assert_eq!(Communities::::get(1).unwrap().primary_color, p_color.as_bytes().to_vec()); + assert_eq!(Communities::::get(1).unwrap().secondary_color, s_color.as_bytes().to_vec()); }); } diff --git a/pallets/passport/src/benchmarking.rs b/pallets/passport/src/benchmarking.rs index 992195a9..50b8a433 100644 --- a/pallets/passport/src/benchmarking.rs +++ b/pallets/passport/src/benchmarking.rs @@ -81,7 +81,7 @@ benchmarks! { ) verify { assert_last_event::(Event::::MintedPassport( - ::Helper::passport(0) + ::Helper::passport(1) ).into()); } @@ -104,7 +104,7 @@ benchmarks! { }: _(RawOrigin::Signed(member), community_id, bounded_passport_address) verify { assert_last_event::(Event::::UpdatedPassport( - ::Helper::passport(0) + ::Helper::passport(1) ).into()); } diff --git a/pallets/passport/src/tests.rs b/pallets/passport/src/tests.rs index 19021769..3b736c54 100644 --- a/pallets/passport/src/tests.rs +++ b/pallets/passport/src/tests.rs @@ -54,7 +54,7 @@ fn create_community() { fn mint_passport() { add_founder(); create_community(); - Passport::mint(RuntimeOrigin::signed(2), 0).unwrap(); + Passport::mint(RuntimeOrigin::signed(2), 1).unwrap(); } #[test] @@ -62,11 +62,11 @@ fn mint_passport_works_for_founder() { new_test_ext().execute_with(|| { add_founder(); create_community(); - assert_ok!(Passport::mint(RuntimeOrigin::signed(1), 0)); - assert_eq!(Passports::::get(0, 1).unwrap().id, 0); - create_community(); assert_ok!(Passport::mint(RuntimeOrigin::signed(1), 1)); - assert_eq!(Passports::::get(1, 1).unwrap().id, 0); + assert_eq!(Passports::::get(1, 1).unwrap().id, 1); + create_community(); + assert_ok!(Passport::mint(RuntimeOrigin::signed(1), 2)); + assert_eq!(Passports::::get(2, 1).unwrap().id, 1); }); } @@ -75,9 +75,9 @@ fn mint_passport_works_for_member() { new_test_ext().execute_with(|| { add_founder(); create_community(); - assert_ok!(Passport::mint(RuntimeOrigin::signed(2), 0)); + assert_ok!(Passport::mint(RuntimeOrigin::signed(2), 1)); - assert!(Passports::::get(0, 2).is_some()); + assert!(Passports::::get(1, 2).is_some()); }); } @@ -87,7 +87,7 @@ fn mint_passport_not_works_for_invalid_community() { add_founder(); create_community(); assert_noop!( - Passport::mint(RuntimeOrigin::signed(2), 1), + Passport::mint(RuntimeOrigin::signed(2), 2), Error::::CommunityDoesNotExist ); }); @@ -99,7 +99,7 @@ fn mint_passport_not_works_when_member_not_part_of_community() { add_founder(); create_community(); assert_noop!( - Passport::mint(RuntimeOrigin::signed(12), 0), + Passport::mint(RuntimeOrigin::signed(12), 1), Error::::MemberDoesNotExist ); }); @@ -110,7 +110,7 @@ fn mint_passport_not_works_when_passport_already_minted() { new_test_ext().execute_with(|| { mint_passport(); assert_noop!( - Passport::mint(RuntimeOrigin::signed(2), 0), + Passport::mint(RuntimeOrigin::signed(2), 1), Error::::PassportAlreadyMinted ); }); @@ -128,12 +128,12 @@ fn update_passport_works() { assert_ok!(Passport::update_passport( RuntimeOrigin::signed(2), - 0, + 1, bounded_passport_address.clone() )); assert_eq!( - Passports::::get(0, 2).unwrap().address.unwrap(), + Passports::::get(1, 2).unwrap().address.unwrap(), bounded_passport_address ); }); @@ -184,7 +184,7 @@ fn update_passport_not_works_for_unminted_passport() { passport_address.try_into().unwrap(); assert_noop!( - Passport::update_passport(RuntimeOrigin::signed(1), 0, bounded_passport_address), + Passport::update_passport(RuntimeOrigin::signed(1), 1, bounded_passport_address), Error::::PassportNotAvailable ); }); diff --git a/pallets/proposal/src/benchmarking.rs b/pallets/proposal/src/benchmarking.rs index f7c5817d..3a87c17d 100644 --- a/pallets/proposal/src/benchmarking.rs +++ b/pallets/proposal/src/benchmarking.rs @@ -132,7 +132,7 @@ benchmarks! { 5 ) verify { - assert_last_event::(Event::::CreatedProposal(::Helper::proposal(0)).into()); + assert_last_event::(Event::::CreatedProposal(::Helper::proposal(1)).into()); } cast_vote { diff --git a/pallets/proposal/src/tests.rs b/pallets/proposal/src/tests.rs index db155d92..59951cb6 100644 --- a/pallets/proposal/src/tests.rs +++ b/pallets/proposal/src/tests.rs @@ -66,7 +66,7 @@ fn create_proposal() { create_community(); Proposal::create_proposal( RuntimeOrigin::signed(1), - 0, + 1, bounded_proposal_name, bounded_proposal_description, vec![ @@ -93,7 +93,7 @@ fn create_proposal_works() { create_community(); assert_ok!(Proposal::create_proposal( RuntimeOrigin::signed(1), - 0, + 1, bounded_proposal_name, bounded_proposal_description, vec![ @@ -105,7 +105,7 @@ fn create_proposal_works() { 5 )); - assert!(Choices::::contains_key(0)); + assert!(Choices::::contains_key(1)); }); } @@ -122,7 +122,7 @@ fn create_proposal_does_not_work_when_no_community_id() { assert_noop!( Proposal::create_proposal( RuntimeOrigin::signed(1), - 0, + 1, bounded_proposal_name, bounded_proposal_description, vec![ @@ -144,9 +144,9 @@ fn cast_vote_works() { create_proposal(); let choice: Vec = "Yes".into(); let bounded_choice: BoundedVec> = choice.try_into().unwrap(); - assert_ok!(Proposal::cast_vote(RuntimeOrigin::signed(1), 0, 0, bounded_choice)); + assert_ok!(Proposal::cast_vote(RuntimeOrigin::signed(1), 1, 1, bounded_choice)); - assert_eq!(Votes::::get(0).unwrap().vote_count, 1); + assert_eq!(Votes::::get(1).unwrap().vote_count, 1); }); } @@ -157,7 +157,7 @@ fn cast_vote_not_work_for_invalid_input() { let choice: Vec = "No".into(); let bounded_choice: BoundedVec> = choice.try_into().unwrap(); assert_noop!( - Proposal::cast_vote(RuntimeOrigin::signed(1), 0, 11, bounded_choice), + Proposal::cast_vote(RuntimeOrigin::signed(1), 1, 11, bounded_choice), Error::::ProposalDoesNotExist ); }); @@ -177,7 +177,7 @@ fn cast_votes_not_work_for_invalid_input() { create_community(); assert_ok!(Proposal::create_proposal( RuntimeOrigin::signed(1), - 0, + 1, bounded_proposal_name.clone(), bounded_proposal_description.clone(), vec!["Yes".into(), "No".into()], @@ -189,13 +189,13 @@ fn cast_votes_not_work_for_invalid_input() { let bounded_choice: BoundedVec> = choice.try_into().unwrap(); assert_noop!( - Proposal::cast_vote(RuntimeOrigin::signed(1), 0, 0, bounded_choice), + Proposal::cast_vote(RuntimeOrigin::signed(1), 1, 1, bounded_choice), Error::::ChoiceDoesNotExist ); assert_ok!(Proposal::create_proposal( RuntimeOrigin::signed(1), - 0, + 1, bounded_proposal_name, bounded_proposal_description, vec!["English".into(), "German".into()], @@ -207,7 +207,7 @@ fn cast_votes_not_work_for_invalid_input() { let bounded_choice: BoundedVec> = choice.try_into().unwrap(); assert_noop!( - Proposal::cast_vote(RuntimeOrigin::signed(1), 0, 1, bounded_choice), + Proposal::cast_vote(RuntimeOrigin::signed(1), 1, 2, bounded_choice), Error::::ChoiceDoesNotExist ); }); @@ -227,7 +227,7 @@ fn cast_vote_not_work_for_after_proposal_deadline() { create_community(); assert_ok!(Proposal::create_proposal( RuntimeOrigin::signed(1), - 0, + 1, bounded_proposal_name, bounded_proposal_description, vec![ @@ -245,7 +245,7 @@ fn cast_vote_not_work_for_after_proposal_deadline() { let bounded_choice: BoundedVec> = choice.try_into().unwrap(); assert_noop!( - Proposal::cast_vote(RuntimeOrigin::signed(1), 0, 0, bounded_choice), + Proposal::cast_vote(RuntimeOrigin::signed(1), 1, 1, bounded_choice), Error::::ProposalNotActive ); }); @@ -258,12 +258,12 @@ fn cast_vote_not_works_for_duplicate_vote() { let choice: Vec = "Yes".into(); let bounded_choice: BoundedVec> = choice.try_into().unwrap(); - assert_ok!(Proposal::cast_vote(RuntimeOrigin::signed(1), 0, 0, bounded_choice.clone())); + assert_ok!(Proposal::cast_vote(RuntimeOrigin::signed(1), 1, 1, bounded_choice.clone())); - assert_eq!(Votes::::get(0).unwrap().vote_count, 1); + assert_eq!(Votes::::get(1).unwrap().vote_count, 1); assert_noop!( - Proposal::cast_vote(RuntimeOrigin::signed(1), 0, 0, bounded_choice), + Proposal::cast_vote(RuntimeOrigin::signed(1), 1, 1, bounded_choice), Error::::DuplicateVote ); }); @@ -275,14 +275,14 @@ fn cast_vote_not_works_for_account_limit_exceeds() { create_proposal(); let choice: Vec = "Yes".into(); let bounded_choice: BoundedVec> = choice.try_into().unwrap(); - assert_ok!(Proposal::cast_vote(RuntimeOrigin::signed(1), 0, 0, bounded_choice.clone())); - assert_ok!(Proposal::cast_vote(RuntimeOrigin::signed(2), 0, 0, bounded_choice.clone())); - assert_ok!(Proposal::cast_vote(RuntimeOrigin::signed(7), 0, 0, bounded_choice.clone())); + assert_ok!(Proposal::cast_vote(RuntimeOrigin::signed(1), 1, 1, bounded_choice.clone())); + assert_ok!(Proposal::cast_vote(RuntimeOrigin::signed(2), 1, 1, bounded_choice.clone())); + assert_ok!(Proposal::cast_vote(RuntimeOrigin::signed(7), 1, 1, bounded_choice.clone())); - assert_eq!(Votes::::get(0).unwrap().vote_count, 3); + assert_eq!(Votes::::get(1).unwrap().vote_count, 3); assert_noop!( - Proposal::cast_vote(RuntimeOrigin::signed(8), 0, 0, bounded_choice), + Proposal::cast_vote(RuntimeOrigin::signed(8), 1, 1, bounded_choice), Error::::AccountLimitReached ); }); @@ -303,7 +303,7 @@ fn create_proposal_not_working_invalid_choice() { assert_noop!( Proposal::create_proposal( RuntimeOrigin::signed(1), - 0, + 1, bounded_proposal_name, bounded_proposal_description, vec![], @@ -329,7 +329,7 @@ fn cast_vote_works_with_proposal_result_accepted() { create_community(); assert_ok!(Proposal::create_proposal( RuntimeOrigin::signed(1), - 0, + 1, bounded_proposal_name, bounded_proposal_description, vec![ @@ -343,13 +343,13 @@ fn cast_vote_works_with_proposal_result_accepted() { let choice: Vec = "Yes".into(); let bounded_choice: BoundedVec> = choice.try_into().unwrap(); - assert_ok!(Proposal::cast_vote(RuntimeOrigin::signed(1), 0, 0, bounded_choice.clone())); - assert_ok!(Proposal::cast_vote(RuntimeOrigin::signed(2), 0, 0, bounded_choice.clone())); + assert_ok!(Proposal::cast_vote(RuntimeOrigin::signed(1), 1, 1, bounded_choice.clone())); + assert_ok!(Proposal::cast_vote(RuntimeOrigin::signed(2), 1, 1, bounded_choice.clone())); run_to_block(15_000); - assert_eq!(Votes::::get(0).unwrap().vote_count, 2); - assert_eq!(ProposalResult::::get(0).unwrap().0, ProposalResultStatus::Accepted); + assert_eq!(Votes::::get(1).unwrap().vote_count, 2); + assert_eq!(ProposalResult::::get(1).unwrap().0, ProposalResultStatus::Accepted); }); } @@ -367,7 +367,7 @@ fn cast_vote_works_with_proposal_result_rejected() { create_community(); assert_ok!(Proposal::create_proposal( RuntimeOrigin::signed(1), - 0, + 1, bounded_proposal_name, bounded_proposal_description, vec![ @@ -384,13 +384,13 @@ fn cast_vote_works_with_proposal_result_rejected() { let choice: Vec = "No".into(); let bounded_choice2: BoundedVec> = choice.try_into().unwrap(); - assert_ok!(Proposal::cast_vote(RuntimeOrigin::signed(1), 0, 0, bounded_choice)); - assert_ok!(Proposal::cast_vote(RuntimeOrigin::signed(2), 0, 0, bounded_choice2.clone())); - assert_ok!(Proposal::cast_vote(RuntimeOrigin::signed(7), 0, 0, bounded_choice2)); + assert_ok!(Proposal::cast_vote(RuntimeOrigin::signed(1), 1, 1, bounded_choice)); + assert_ok!(Proposal::cast_vote(RuntimeOrigin::signed(2), 1, 1, bounded_choice2.clone())); + assert_ok!(Proposal::cast_vote(RuntimeOrigin::signed(7), 1, 1, bounded_choice2)); run_to_block(15_000); - assert_eq!(Votes::::get(1).unwrap().vote_count, 2); - assert_eq!(ProposalResult::::get(0).unwrap().0, ProposalResultStatus::Rejected); + assert_eq!(Votes::::get(2).unwrap().vote_count, 2); + assert_eq!(ProposalResult::::get(1).unwrap().0, ProposalResultStatus::Rejected); }); } diff --git a/primitives/src/macros.rs b/primitives/src/macros.rs index 8aa79c37..2f3c2bea 100644 --- a/primitives/src/macros.rs +++ b/primitives/src/macros.rs @@ -10,7 +10,7 @@ macro_rules! impl_incrementable { } fn initial_value() -> Self { - 0 + 1 } } )+ diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index a507f24f..0ccade68 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -410,7 +410,7 @@ impl pallet_community::Config for Runtime { type Helper = (); type WeightInfo = pallet_community::weights::SubstrateWeight; type MyRandomness = RandomnessCollectiveFlip; - type TagLimit = ConstU32<50>; + type TagLimit = ConstU32<40>; type ColorLimit = ConstU32<7>; } From 5b16bafbd6b1d167c5521e74a4dd958f8262358e Mon Sep 17 00:00:00 2001 From: Polkaverse Date: Thu, 17 Aug 2023 17:18:36 +0530 Subject: [PATCH 2/4] fixed username bugs --- pallets/user/src/lib.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/pallets/user/src/lib.rs b/pallets/user/src/lib.rs index 161888dd..e450541f 100644 --- a/pallets/user/src/lib.rs +++ b/pallets/user/src/lib.rs @@ -17,9 +17,9 @@ pub use pallet::*; use sp_runtime::RuntimeDebug; pub use weights::WeightInfo; -pub mod types; #[cfg(test)] mod mock; +pub mod types; #[cfg(test)] mod tests; @@ -33,6 +33,7 @@ pub mod pallet { use crate::types::User; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; + use scale_info::prelude::string::String; use super::*; @@ -77,6 +78,8 @@ pub mod pallet { pub enum Error { /// Username not available. UsernameNotAvailable, + /// Username is not valid. + UsernameInvalid, } #[pallet::hooks] @@ -101,8 +104,24 @@ pub mod pallet { ) -> DispatchResult { let user = ensure_signed(origin.clone())?; + // Validating the username/avatar. They should not have the blank spaces + if name.is_some() { + let username: String = + String::from_utf8(name.clone().unwrap().to_vec()).expect("Invalid username"); + ensure!(!username.contains(" "), Error::::UsernameInvalid); + } + if avatar.is_some() { + let profile: String = + String::from_utf8(avatar.clone().unwrap().to_vec()).expect("Invalid username"); + ensure!(!profile.contains(" "), Error::::UsernameInvalid); + } + + // Validating the duplicate username for (_, userdata) in Users::::iter() { - ensure!(userdata.name != name, Error::::UsernameNotAvailable); + ensure!( + userdata.name != name || userdata.name == None, + Error::::UsernameNotAvailable + ); } // creating the user data structure as per given inputs From 1b7d65074e362f3cde336ef0ce0ee5ff09ac36b1 Mon Sep 17 00:00:00 2001 From: Polkaverse Date: Fri, 18 Aug 2023 13:54:16 +0530 Subject: [PATCH 3/4] added proposal max duration --- pallets/proposal/src/lib.rs | 4 ++-- primitives/src/lib.rs | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pallets/proposal/src/lib.rs b/pallets/proposal/src/lib.rs index 0674ba7a..80ad02e8 100644 --- a/pallets/proposal/src/lib.rs +++ b/pallets/proposal/src/lib.rs @@ -30,7 +30,7 @@ pub use pallet::*; mod types; use crate::types::{Choice, Proposal, ProposalResultStatus, Vote}; use frame_support::{dispatch::DispatchResultWithPostInfo, BoundedVec}; -use primitives::{Incrementable, BLOCKS_PER_DAY}; +use primitives::{Incrementable, BLOCKS_PER_DAY, PROPOSAL_DURATION_LIMIT}; use sp_std::vec::Vec; #[cfg(test)] @@ -305,7 +305,7 @@ pub mod pallet { ensure!(origin == community.founder, Error::::NotAllowed); ensure!(choices.len() >= 2, Error::::InvalidChoicesGiven); - ensure!(proposal_duration >= 1, Error::::InvalidProposalDuration); + ensure!(proposal_duration >= 1 && proposal_duration <= PROPOSAL_DURATION_LIMIT, Error::::InvalidProposalDuration); Self::do_create_proposal( origin, diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index d694befd..2945fe11 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -32,6 +32,8 @@ pub const JUR: CurrencyId = 0; /// Number Constants +pub const PROPOSAL_DURATION_LIMIT: u32 = 30; + pub const INITIAL_INDEX: usize = 0; pub const INITIAL_NODE_INDEX: u8 = 0; From 9de4c90d27e28167f8f08dfcea5a37e6fa3415e7 Mon Sep 17 00:00:00 2001 From: Polkaverse Date: Fri, 18 Aug 2023 16:32:26 +0530 Subject: [PATCH 4/4] updraded spec version --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 0ccade68..b42f94c4 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -120,7 +120,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 111, + spec_version: 112, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1,