Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: democracy enact_proposal shouldn't use max weight
Signed-off-by: Gregory Hill <[email protected]>
  • Loading branch information
gregdhill committed Nov 14, 2022
commit 8e85415a499af83d7012b1cc6de9365938c3d290
3 changes: 2 additions & 1 deletion crates/democracy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ codec = { package = "parity-scale-codec", version = "3.1.5", default-features =
scale-info = { version = "2.2.0", default-features = false, features = ["derive"] }

sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31", default-features = false }
Expand All @@ -26,7 +27,6 @@ frame-support = { git = "https://github.com/paritytech/substrate", branch = "pol
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31", default-features = false }

[dev-dependencies]
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
pallet-scheduler = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }

Expand All @@ -36,6 +36,7 @@ std = [
"serde",
"codec/std",
"scale-info/std",
"sp-core/std",
"sp-std/std",
"sp-io/std",
"frame-benchmarking/std",
Expand Down
2 changes: 1 addition & 1 deletion crates/democracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ pub mod pallet {
}

/// Enact a proposal from a referendum. For now we just make the weight be the maximum.
#[pallet::weight(T::BlockWeights::get().max_block)]
#[pallet::weight(1000)]
pub fn enact_proposal(origin: OriginFor<T>, proposal_hash: T::Hash, index: ReferendumIndex) -> DispatchResult {
ensure_root(origin)?;
Self::do_enact_proposal(proposal_hash, index)
Expand Down
12 changes: 7 additions & 5 deletions crates/democracy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate as pallet_democracy;
use codec::Encode;
use frame_support::{
assert_noop, assert_ok, ord_parameter_types, parameter_types,
traits::{Contains, EqualPrivilegeOnly, GenesisBuild, OnInitialize, SortedMembers},
traits::{ConstU32, Contains, EqualPrivilegeOnly, GenesisBuild, OnInitialize, SortedMembers},
weights::Weight,
};
use frame_system::{EnsureRoot, EnsureSignedBy};
Expand Down Expand Up @@ -42,7 +42,7 @@ frame_support::construct_runtime!(
}
);

// Test that a fitlered call can be dispatched.
// Test that a filtered call can be dispatched.
pub struct BaseFilter;
impl Contains<RuntimeCall> for BaseFilter {
fn contains(call: &RuntimeCall) -> bool {
Expand All @@ -53,11 +53,12 @@ impl Contains<RuntimeCall> for BaseFilter {
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(1_000_000 as u64));
frame_system::limits::BlockWeights::simple_max(frame_support::weights::constants::WEIGHT_PER_SECOND.set_proof_size(u64::MAX));
}

impl frame_system::Config for Test {
type BaseCallFilter = BaseFilter;
type BlockWeights = ();
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
Expand All @@ -81,6 +82,7 @@ impl frame_system::Config for Test {
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block;
}
Expand All @@ -92,7 +94,7 @@ impl pallet_scheduler::Config for Test {
type RuntimeCall = RuntimeCall;
type MaximumWeight = MaximumSchedulerWeight;
type ScheduleOrigin = EnsureRoot<u64>;
type MaxScheduledPerBlock = ();
type MaxScheduledPerBlock = ConstU32<100>;
type OriginPrivilegeCmp = EqualPrivilegeOnly;
type WeightInfo = ();
type Preimages = ();
Expand Down
1 change: 1 addition & 0 deletions parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,5 @@ rococo-native = [ "polkadot-cli/rococo-native" ]
runtime-benchmarks = [
"interlay-runtime/runtime-benchmarks",
"polkadot-service/runtime-benchmarks",
"polkadot-cli/runtime-benchmarks",
]
52 changes: 26 additions & 26 deletions standalone/runtime/tests/test_annuity.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mod mock;

use codec::Encode;
use frame_support::traits::{schedule::MaybeHashed, Currency, OnInitialize};
use frame_support::traits::{Currency, OnInitialize};
use mock::{assert_eq, *};
use sp_runtime::Permill;
use sp_io::hashing::blake2_256;

type EscrowAnnuityPallet = annuity::Pallet<Runtime, EscrowAnnuityInstance>;

Expand Down Expand Up @@ -130,52 +130,52 @@ fn should_distribute_vault_rewards_from_supply() {
assert_ok!(RuntimeCall::Utility(UtilityCall::batch {
calls: vec![
RuntimeCall::Scheduler(SchedulerCall::schedule_named {
id: "Year 1".encode(),
id: blake2_256(&b"Year 1"[..]),
when: start_height + YEARS * 0,
maybe_periodic: None,
priority: 63,
call: Box::new(MaybeHashed::Value(RuntimeCall::Tokens(TokensCall::force_transfer {
call: Box::new(RuntimeCall::Tokens(TokensCall::force_transfer {
source: SupplyPallet::account_id(),
dest: VaultAnnuityPallet::account_id(),
currency_id: DEFAULT_NATIVE_CURRENCY,
amount: Permill::from_percent(40) * total_rewards,
}))),
})),
}),
RuntimeCall::Scheduler(SchedulerCall::schedule_named {
id: "Year 2".encode(),
id: blake2_256(&b"Year 2"[..]),
when: start_height + YEARS * 1,
maybe_periodic: None,
priority: 63,
call: Box::new(MaybeHashed::Value(RuntimeCall::Tokens(TokensCall::force_transfer {
call: Box::new(RuntimeCall::Tokens(TokensCall::force_transfer {
source: SupplyPallet::account_id(),
dest: VaultAnnuityPallet::account_id(),
currency_id: DEFAULT_NATIVE_CURRENCY,
amount: Permill::from_percent(30) * total_rewards,
}))),
})),
}),
RuntimeCall::Scheduler(SchedulerCall::schedule_named {
id: "Year 3".encode(),
id: blake2_256(&b"Year 3"[..]),
when: start_height + YEARS * 2,
maybe_periodic: None,
priority: 63,
call: Box::new(MaybeHashed::Value(RuntimeCall::Tokens(TokensCall::force_transfer {
call: Box::new(RuntimeCall::Tokens(TokensCall::force_transfer {
source: SupplyPallet::account_id(),
dest: VaultAnnuityPallet::account_id(),
currency_id: DEFAULT_NATIVE_CURRENCY,
amount: Permill::from_percent(20) * total_rewards,
}))),
})),
}),
RuntimeCall::Scheduler(SchedulerCall::schedule_named {
id: "Year 4".encode(),
id: blake2_256(&b"Year 4"[..]),
when: start_height + YEARS * 3,
maybe_periodic: None,
priority: 63,
call: Box::new(MaybeHashed::Value(RuntimeCall::Tokens(TokensCall::force_transfer {
call: Box::new(RuntimeCall::Tokens(TokensCall::force_transfer {
source: SupplyPallet::account_id(),
dest: VaultAnnuityPallet::account_id(),
currency_id: DEFAULT_NATIVE_CURRENCY,
amount: Permill::from_percent(10) * total_rewards,
}))),
})),
})
],
})
Expand Down Expand Up @@ -227,52 +227,52 @@ fn should_distribute_escrow_rewards_from_supply() {
assert_ok!(RuntimeCall::Utility(UtilityCall::batch {
calls: vec![
RuntimeCall::Scheduler(SchedulerCall::schedule_named {
id: "Year 1".encode(),
id: blake2_256(&b"Year 1"[..]),
when: start_height + YEARS * 0,
maybe_periodic: None,
priority: 63,
call: Box::new(MaybeHashed::Value(RuntimeCall::Tokens(TokensCall::force_transfer {
call: Box::new(RuntimeCall::Tokens(TokensCall::force_transfer {
source: SupplyPallet::account_id(),
dest: EscrowAnnuityPallet::account_id(),
currency_id: DEFAULT_NATIVE_CURRENCY,
amount: Permill::from_percent(25) * total_rewards,
}))),
})),
}),
RuntimeCall::Scheduler(SchedulerCall::schedule_named {
id: "Year 2".encode(),
id: blake2_256(&b"Year 2"[..]),
when: start_height + YEARS * 1,
maybe_periodic: None,
priority: 63,
call: Box::new(MaybeHashed::Value(RuntimeCall::Tokens(TokensCall::force_transfer {
call: Box::new(RuntimeCall::Tokens(TokensCall::force_transfer {
source: SupplyPallet::account_id(),
dest: EscrowAnnuityPallet::account_id(),
currency_id: DEFAULT_NATIVE_CURRENCY,
amount: Permill::from_percent(25) * total_rewards,
}))),
})),
}),
RuntimeCall::Scheduler(SchedulerCall::schedule_named {
id: "Year 3".encode(),
id: blake2_256(&b"Year 3"[..]),
when: start_height + YEARS * 2,
maybe_periodic: None,
priority: 63,
call: Box::new(MaybeHashed::Value(RuntimeCall::Tokens(TokensCall::force_transfer {
call: Box::new(RuntimeCall::Tokens(TokensCall::force_transfer {
source: SupplyPallet::account_id(),
dest: EscrowAnnuityPallet::account_id(),
currency_id: DEFAULT_NATIVE_CURRENCY,
amount: Permill::from_percent(25) * total_rewards,
}))),
})),
}),
RuntimeCall::Scheduler(SchedulerCall::schedule_named {
id: "Year 4".encode(),
id: blake2_256(&b"Year 4"[..]),
when: start_height + YEARS * 3,
maybe_periodic: None,
priority: 63,
call: Box::new(MaybeHashed::Value(RuntimeCall::Tokens(TokensCall::force_transfer {
call: Box::new(RuntimeCall::Tokens(TokensCall::force_transfer {
source: SupplyPallet::account_id(),
dest: EscrowAnnuityPallet::account_id(),
currency_id: DEFAULT_NATIVE_CURRENCY,
amount: Permill::from_percent(25) * total_rewards,
}))),
})),
})
],
})
Expand Down
25 changes: 10 additions & 15 deletions standalone/runtime/tests/test_multisig.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod mock;

use frame_support::{traits::WrapperKeepOpaque, weights::Weight};
use frame_support::weights::Weight;
use mock::{assert_eq, *};
use orml_tokens::AccountData;
use orml_vesting::VestingSchedule;
Expand Down Expand Up @@ -41,14 +41,12 @@ fn integration_test_transfer_from_multisig_to_vested() {
dest: account_of(EVE),
currency_id: Token(INTR),
amount: 20_000_000_000_001,
})
.encode();
});
assert_ok!(RuntimeCall::Multisig(MultisigCall::as_multi {
threshold: 2,
other_signatories: vec![account_of(BOB)],
maybe_timepoint: None,
call: WrapperKeepOpaque::from_encoded(call.clone()),
store_call: true,
call: Box::new(call.clone()),
max_weight: Weight::from_ref_time(1000000000000 as u64),
})
.dispatch(origin_of(account_of(ALICE))));
Expand All @@ -72,7 +70,7 @@ fn integration_test_transfer_from_multisig_to_vested() {
threshold: 2,
other_signatories: vec![account_of(ALICE)],
maybe_timepoint: Some(timepoint),
call_hash: sp_core::blake2_256(&call),
call_hash: sp_core::blake2_256(&call.encode()),
max_weight: Weight::from_ref_time(1000000000000 as u64),
})
.dispatch(origin_of(account_of(BOB))));
Expand Down Expand Up @@ -109,15 +107,13 @@ fn integration_test_transfer_from_multisig_to_unvested() {
period_count: 100,
per_period: vesting_amount / 100,
},
})
.encode();
});

assert_ok!(RuntimeCall::Multisig(MultisigCall::as_multi {
threshold: 2,
other_signatories: vec![account_of(BOB)],
maybe_timepoint: None,
call: WrapperKeepOpaque::from_encoded(call.clone()),
store_call: true,
call: Box::new(call.clone()),
max_weight: Weight::from_ref_time(1000000000000 as u64),
})
.dispatch(origin_of(account_of(ALICE))));
Expand All @@ -126,7 +122,7 @@ fn integration_test_transfer_from_multisig_to_unvested() {
threshold: 2,
other_signatories: vec![account_of(ALICE)],
maybe_timepoint: Some(MultisigPallet::timepoint()),
call_hash: sp_core::blake2_256(&call),
call_hash: sp_core::blake2_256(&call.encode()),
max_weight: Weight::from_ref_time(1000000000000 as u64),
})
.dispatch(origin_of(account_of(BOB))));
Expand Down Expand Up @@ -265,14 +261,13 @@ fn integration_test_batched_multisig_vesting() {
})
.collect();

let batch = RuntimeCall::Utility(UtilityCall::batch { calls }).encode();
let batch = RuntimeCall::Utility(UtilityCall::batch { calls });

assert_ok!(RuntimeCall::Multisig(MultisigCall::as_multi {
threshold: 2,
other_signatories: vec![account_of(BOB)],
maybe_timepoint: None,
call: WrapperKeepOpaque::from_encoded(batch.clone()),
store_call: true,
call: Box::new(batch.clone()),
max_weight: Weight::from_ref_time(1000000000000 as u64),
})
.dispatch(origin_of(account_of(ALICE))));
Expand All @@ -281,7 +276,7 @@ fn integration_test_batched_multisig_vesting() {
threshold: 2,
other_signatories: vec![account_of(ALICE)],
maybe_timepoint: Some(MultisigPallet::timepoint()),
call_hash: sp_core::blake2_256(&batch),
call_hash: sp_core::blake2_256(&batch.encode()),
max_weight: Weight::from_ref_time(1000000000000 as u64),
})
.dispatch(origin_of(account_of(BOB))));
Expand Down