Skip to content

Commit

Permalink
fix: reanme + no default proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
dandanlen committed Sep 11, 2023
1 parent 148fe57 commit 832d866
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 33 deletions.
2 changes: 1 addition & 1 deletion api/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ pub trait GovernanceApi: SignedExtrinsicApi {
println!("Submitting governance proposal for rotation.");
self.submit_signed_extrinsic(pallet_cf_governance::Call::propose_governance_extrinsic {
call: Box::new(pallet_cf_validator::Call::force_rotation {}.into()),
execution: ExecutionMode::Scheduled,
execution: ExecutionMode::Automatic,
})
.await
.until_finalized()
Expand Down
8 changes: 4 additions & 4 deletions state-chain/pallets/cf-governance/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ benchmarks! {
let caller: T::AccountId = whitelisted_caller();
let call = Box::new(frame_system::Call::remark{remark: vec![]}.into());
<Members<T>>::put(BTreeSet::from([caller.clone()]));
}: _(RawOrigin::Signed(caller.clone()), call, ExecutionMode::Scheduled)
}: _(RawOrigin::Signed(caller.clone()), call, ExecutionMode::Automatic)
verify {
assert_eq!(ProposalIdCounter::<T>::get(), 1);
}
approve {
let call: <T as Config>::RuntimeCall = frame_system::Call::remark{remark: vec![]}.into();
let caller: T::AccountId = whitelisted_caller();
<Members<T>>::put(BTreeSet::from([caller.clone()]));
Pallet::<T>::push_proposal(Box::new(call), ExecutionMode::Scheduled);
Pallet::<T>::push_proposal(Box::new(call), ExecutionMode::Automatic);
}: _(RawOrigin::Signed(caller.clone()), 1)
verify {
assert_eq!(ProposalIdCounter::<T>::get(), 1);
Expand All @@ -48,7 +48,7 @@ benchmarks! {
let b in 1 .. 100u32;
for _n in 1 .. b {
let call = Box::new(frame_system::Call::remark{remark: vec![]}.into());
Pallet::<T>::push_proposal(call, ExecutionMode::Scheduled);
Pallet::<T>::push_proposal(call, ExecutionMode::Automatic);
}
}: {
Pallet::<T>::on_initialize(2u32.into());
Expand All @@ -61,7 +61,7 @@ benchmarks! {
let b in 1 .. 100u32;
for _n in 1 .. b {
let call = Box::new(frame_system::Call::remark{remark: vec![]}.into());
Pallet::<T>::push_proposal(call, ExecutionMode::Scheduled);
Pallet::<T>::push_proposal(call, ExecutionMode::Automatic);
}
} : {
Pallet::<T>::expire_proposals(<ActiveProposals<T>>::get());
Expand Down
27 changes: 7 additions & 20 deletions state-chain/pallets/cf-governance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,13 @@ pub mod pallet {

use super::{GovCallHash, WeightInfo};

#[derive(Encode, Decode, TypeInfo, Clone, RuntimeDebug, PartialEq, Eq)]
#[derive(Default, Encode, Decode, TypeInfo, Clone, RuntimeDebug, PartialEq, Eq)]
pub enum ExecutionMode {
Scheduled,
#[default]
Automatic,
Manual,
}

impl Default for ExecutionMode {
fn default() -> Self {
Self::Scheduled
}
}

#[derive(Encode, Decode, TypeInfo, Clone, Copy, RuntimeDebug, PartialEq, Eq)]
pub struct ActiveProposal {
pub proposal_id: ProposalId,
Expand All @@ -81,16 +76,6 @@ pub mod pallet {
pub execution: ExecutionMode,
}

impl<T> Default for Proposal<T> {
fn default() -> Self {
Self {
call: Default::default(),
approved: Default::default(),
execution: Default::default(),
}
}
}

type AccountId<T> = <T as frame_system::Config>::AccountId;
type OpaqueCall = Vec<u8>;
type Timestamp = u64;
Expand Down Expand Up @@ -133,7 +118,7 @@ pub mod pallet {
#[pallet::storage]
#[pallet::getter(fn proposals)]
pub(super) type Proposals<T: Config> =
StorageMap<_, Blake2_128Concat, ProposalId, Proposal<T::AccountId>, ValueQuery>;
StorageMap<_, Blake2_128Concat, ProposalId, Proposal<T::AccountId>>;

/// Active proposals.
#[pallet::storage]
Expand Down Expand Up @@ -538,7 +523,9 @@ impl<T: Config> Pallet<T> {
ensure!(Proposals::<T>::contains_key(approved_id), Error::<T>::ProposalNotFound);

// Try to approve the proposal
let proposal = Proposals::<T>::mutate(approved_id, |proposal| {
let proposal = Proposals::<T>::try_mutate(approved_id, |proposal| {
let proposal = proposal.as_mut().ok_or(Error::<T>::ProposalNotFound)?;

if !proposal.approved.insert(who) {
return Err(Error::<T>::AlreadyApproved)
}
Expand Down
16 changes: 8 additions & 8 deletions state-chain/pallets/cf-governance/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn not_a_member() {
Governance::propose_governance_extrinsic(
RuntimeOrigin::signed(EVE),
mock_extrinsic(),
ExecutionMode::Scheduled,
ExecutionMode::Automatic,
),
<Error<Test>>::NotMember
);
Expand All @@ -52,7 +52,7 @@ fn propose_a_governance_extrinsic_and_expect_execution() {
assert_ok!(Governance::propose_governance_extrinsic(
RuntimeOrigin::signed(ALICE),
mock_extrinsic(),
ExecutionMode::Scheduled,
ExecutionMode::Automatic,
));
assert_eq!(
last_event::<Test>(),
Expand Down Expand Up @@ -84,7 +84,7 @@ fn already_executed() {
assert_ok!(Governance::propose_governance_extrinsic(
RuntimeOrigin::signed(ALICE),
mock_extrinsic(),
ExecutionMode::Scheduled,
ExecutionMode::Automatic,
));
// Assert the proposed event was fired
assert_eq!(
Expand Down Expand Up @@ -127,7 +127,7 @@ fn propose_a_governance_extrinsic_and_expect_it_to_expire() {
assert_ok!(Governance::propose_governance_extrinsic(
RuntimeOrigin::signed(ALICE),
mock_extrinsic(),
ExecutionMode::Scheduled,
ExecutionMode::Automatic,
));
})
.then_execute_at_next_block(|_| {
Expand All @@ -151,7 +151,7 @@ fn can_not_vote_twice() {
assert_ok!(Governance::propose_governance_extrinsic(
RuntimeOrigin::signed(ALICE),
mock_extrinsic(),
ExecutionMode::Scheduled,
ExecutionMode::Automatic,
));
// Try to approve it again. Proposing implies approving.
assert_noop!(
Expand All @@ -167,7 +167,7 @@ fn several_open_proposals() {
assert_ok!(Governance::propose_governance_extrinsic(
RuntimeOrigin::signed(ALICE),
mock_extrinsic(),
ExecutionMode::Scheduled,
ExecutionMode::Automatic,
));
assert_eq!(
last_event::<Test>(),
Expand All @@ -176,7 +176,7 @@ fn several_open_proposals() {
assert_ok!(Governance::propose_governance_extrinsic(
RuntimeOrigin::signed(BOB),
mock_extrinsic(),
ExecutionMode::Scheduled,
ExecutionMode::Automatic,
));
assert_eq!(
last_event::<Test>(),
Expand All @@ -202,7 +202,7 @@ fn sudo_extrinsic() {
assert_ok!(Governance::propose_governance_extrinsic(
RuntimeOrigin::signed(ALICE),
governance_extrinsic,
ExecutionMode::Scheduled,
ExecutionMode::Automatic,
));
assert_eq!(
last_event::<Test>(),
Expand Down

0 comments on commit 832d866

Please sign in to comment.