mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 04:21:01 +00:00
BREAKING: Rename Origin (#12258)
* BREAKING: Rename Origin * more renaming * a bit more renaming * fix * more fixing * fix in frame_support * even more fixes * fix * small fix * ... * update .stderr * docs * update docs * update docs * docs
This commit is contained in:
@@ -27,7 +27,7 @@ impl system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
|
||||
@@ -5,7 +5,7 @@ use frame_support::{assert_noop, assert_ok};
|
||||
fn it_works_for_default_value() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// Dispatch a signed extrinsic.
|
||||
assert_ok!(TemplateModule::do_something(Origin::signed(1), 42));
|
||||
assert_ok!(TemplateModule::do_something(RuntimeOrigin::signed(1), 42));
|
||||
// Read pallet storage and assert an expected result.
|
||||
assert_eq!(TemplateModule::something(), Some(42));
|
||||
});
|
||||
@@ -15,6 +15,9 @@ fn it_works_for_default_value() {
|
||||
fn correct_error_for_none_value() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// Ensure the expected error is thrown when no value is present.
|
||||
assert_noop!(TemplateModule::cause_error(Origin::signed(1)), Error::<Test>::NoneValue);
|
||||
assert_noop!(
|
||||
TemplateModule::cause_error(RuntimeOrigin::signed(1)),
|
||||
Error::<Test>::NoneValue
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ impl frame_system::Config for Runtime {
|
||||
/// The ubiquitous event type.
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
/// The ubiquitous origin type.
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
|
||||
type BlockHashCount = BlockHashCount;
|
||||
/// The weight of database operations that the runtime can invoke.
|
||||
|
||||
@@ -205,7 +205,7 @@ impl frame_system::Config for Runtime {
|
||||
type BlockWeights = RuntimeBlockWeights;
|
||||
type BlockLength = RuntimeBlockLength;
|
||||
type DbWeight = RocksDbWeight;
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type Index = Index;
|
||||
type BlockNumber = BlockNumber;
|
||||
@@ -346,7 +346,7 @@ parameter_types! {
|
||||
|
||||
impl pallet_scheduler::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type PalletsOrigin = OriginCaller;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type MaximumWeight = MaximumSchedulerWeight;
|
||||
@@ -796,7 +796,7 @@ parameter_types! {
|
||||
pub struct TracksInfo;
|
||||
impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
|
||||
type Id = u16;
|
||||
type Origin = <Origin as frame_support::traits::OriginTrait>::PalletsOrigin;
|
||||
type RuntimeOrigin = <RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;
|
||||
fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo<Balance, BlockNumber>)] {
|
||||
static DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 1] = [(
|
||||
0u16,
|
||||
@@ -822,7 +822,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
|
||||
)];
|
||||
&DATA[..]
|
||||
}
|
||||
fn track_for(id: &Self::Origin) -> Result<Self::Id, ()> {
|
||||
fn track_for(id: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {
|
||||
if let Ok(system_origin) = frame_system::RawOrigin::try_from(id.clone()) {
|
||||
match system_origin {
|
||||
frame_system::RawOrigin::Root => Ok(0),
|
||||
@@ -957,7 +957,7 @@ parameter_types! {
|
||||
|
||||
type CouncilCollective = pallet_collective::Instance1;
|
||||
impl pallet_collective::Config<CouncilCollective> for Runtime {
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Proposal = RuntimeCall;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type MotionDuration = CouncilMotionDuration;
|
||||
@@ -1014,7 +1014,7 @@ parameter_types! {
|
||||
|
||||
type TechnicalCollective = pallet_collective::Instance2;
|
||||
impl pallet_collective::Config<TechnicalCollective> for Runtime {
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Proposal = RuntimeCall;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type MotionDuration = TechnicalMotionDuration;
|
||||
@@ -1536,7 +1536,7 @@ parameter_types! {
|
||||
|
||||
type AllianceCollective = pallet_collective::Instance3;
|
||||
impl pallet_collective::Config<AllianceCollective> for Runtime {
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Proposal = RuntimeCall;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type MotionDuration = AllianceMotionDuration;
|
||||
|
||||
@@ -62,8 +62,8 @@ pub type BoxBlockImport<B, Transaction> =
|
||||
pub type BoxJustificationImport<B> =
|
||||
Box<dyn JustificationImport<B, Error = ConsensusError> + Send + Sync>;
|
||||
|
||||
/// Maps to the Origin used by the network.
|
||||
pub type Origin = libp2p::PeerId;
|
||||
/// Maps to the RuntimeOrigin used by the network.
|
||||
pub type RuntimeOrigin = libp2p::PeerId;
|
||||
|
||||
/// Block data used by the queue.
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
@@ -79,7 +79,7 @@ pub struct IncomingBlock<B: BlockT> {
|
||||
/// Justification(s) if requested.
|
||||
pub justifications: Option<Justifications>,
|
||||
/// The peer, we received this from
|
||||
pub origin: Option<Origin>,
|
||||
pub origin: Option<RuntimeOrigin>,
|
||||
/// Allow importing the block skipping state verification if parent state is missing.
|
||||
pub allow_missing_state: bool,
|
||||
/// Skip block execution and state verification.
|
||||
@@ -112,7 +112,7 @@ pub trait ImportQueue<B: BlockT>: Send {
|
||||
/// Import block justifications.
|
||||
fn import_justifications(
|
||||
&mut self,
|
||||
who: Origin,
|
||||
who: RuntimeOrigin,
|
||||
hash: B::Hash,
|
||||
number: NumberFor<B>,
|
||||
justifications: Justifications,
|
||||
@@ -140,7 +140,7 @@ pub trait Link<B: BlockT>: Send {
|
||||
/// Justification import result.
|
||||
fn justification_imported(
|
||||
&mut self,
|
||||
_who: Origin,
|
||||
_who: RuntimeOrigin,
|
||||
_hash: &B::Hash,
|
||||
_number: NumberFor<B>,
|
||||
_success: bool,
|
||||
@@ -155,9 +155,9 @@ pub trait Link<B: BlockT>: Send {
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum BlockImportStatus<N: std::fmt::Debug + PartialEq> {
|
||||
/// Imported known block.
|
||||
ImportedKnown(N, Option<Origin>),
|
||||
ImportedKnown(N, Option<RuntimeOrigin>),
|
||||
/// Imported unknown block.
|
||||
ImportedUnknown(N, ImportedAux, Option<Origin>),
|
||||
ImportedUnknown(N, ImportedAux, Option<RuntimeOrigin>),
|
||||
}
|
||||
|
||||
impl<N: std::fmt::Debug + PartialEq> BlockImportStatus<N> {
|
||||
@@ -175,15 +175,15 @@ impl<N: std::fmt::Debug + PartialEq> BlockImportStatus<N> {
|
||||
pub enum BlockImportError {
|
||||
/// Block missed header, can't be imported
|
||||
#[error("block is missing a header (origin = {0:?})")]
|
||||
IncompleteHeader(Option<Origin>),
|
||||
IncompleteHeader(Option<RuntimeOrigin>),
|
||||
|
||||
/// Block verification failed, can't be imported
|
||||
#[error("block verification failed (origin = {0:?}): {1}")]
|
||||
VerificationFailed(Option<Origin>, String),
|
||||
VerificationFailed(Option<RuntimeOrigin>, String),
|
||||
|
||||
/// Block is known to be Bad
|
||||
#[error("bad block (origin = {0:?})")]
|
||||
BadBlock(Option<Origin>),
|
||||
BadBlock(Option<RuntimeOrigin>),
|
||||
|
||||
/// Parent state is missing.
|
||||
#[error("block is missing parent state")]
|
||||
|
||||
@@ -34,7 +34,7 @@ use crate::{
|
||||
import_queue::{
|
||||
buffered_link::{self, BufferedLinkReceiver, BufferedLinkSender},
|
||||
import_single_block_metered, BlockImportError, BlockImportStatus, BoxBlockImport,
|
||||
BoxJustificationImport, ImportQueue, IncomingBlock, Link, Origin, Verifier,
|
||||
BoxJustificationImport, ImportQueue, IncomingBlock, Link, RuntimeOrigin, Verifier,
|
||||
},
|
||||
metrics::Metrics,
|
||||
};
|
||||
@@ -120,7 +120,7 @@ impl<B: BlockT, Transaction: Send> ImportQueue<B> for BasicQueue<B, Transaction>
|
||||
|
||||
fn import_justifications(
|
||||
&mut self,
|
||||
who: Origin,
|
||||
who: RuntimeOrigin,
|
||||
hash: B::Hash,
|
||||
number: NumberFor<B>,
|
||||
justifications: Justifications,
|
||||
@@ -152,7 +152,7 @@ mod worker_messages {
|
||||
|
||||
pub struct ImportBlocks<B: BlockT>(pub BlockOrigin, pub Vec<IncomingBlock<B>>);
|
||||
pub struct ImportJustification<B: BlockT>(
|
||||
pub Origin,
|
||||
pub RuntimeOrigin,
|
||||
pub B::Hash,
|
||||
pub NumberFor<B>,
|
||||
pub Justification,
|
||||
@@ -289,7 +289,7 @@ impl<B: BlockT> BlockImportWorker<B> {
|
||||
|
||||
async fn import_justification(
|
||||
&mut self,
|
||||
who: Origin,
|
||||
who: RuntimeOrigin,
|
||||
hash: B::Hash,
|
||||
number: NumberFor<B>,
|
||||
justification: Justification,
|
||||
@@ -530,7 +530,7 @@ mod tests {
|
||||
|
||||
fn justification_imported(
|
||||
&mut self,
|
||||
_who: Origin,
|
||||
_who: RuntimeOrigin,
|
||||
hash: &Hash,
|
||||
_number: BlockNumber,
|
||||
_success: bool,
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
//! });
|
||||
//! ```
|
||||
|
||||
use crate::import_queue::{Link, Origin};
|
||||
use crate::import_queue::{Link, RuntimeOrigin};
|
||||
use futures::prelude::*;
|
||||
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
|
||||
use sp_runtime::traits::{Block as BlockT, NumberFor};
|
||||
@@ -82,7 +82,7 @@ impl<B: BlockT> Clone for BufferedLinkSender<B> {
|
||||
/// Internal buffered message.
|
||||
enum BlockImportWorkerMsg<B: BlockT> {
|
||||
BlocksProcessed(usize, usize, Vec<(BlockImportResult<B>, B::Hash)>),
|
||||
JustificationImported(Origin, B::Hash, NumberFor<B>, bool),
|
||||
JustificationImported(RuntimeOrigin, B::Hash, NumberFor<B>, bool),
|
||||
RequestJustification(B::Hash, NumberFor<B>),
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ impl<B: BlockT> Link<B> for BufferedLinkSender<B> {
|
||||
|
||||
fn justification_imported(
|
||||
&mut self,
|
||||
who: Origin,
|
||||
who: RuntimeOrigin,
|
||||
hash: &B::Hash,
|
||||
number: NumberFor<B>,
|
||||
success: bool,
|
||||
|
||||
@@ -37,7 +37,7 @@ use libp2p::{
|
||||
};
|
||||
use log::debug;
|
||||
|
||||
use sc_consensus::import_queue::{IncomingBlock, Origin};
|
||||
use sc_consensus::import_queue::{IncomingBlock, RuntimeOrigin};
|
||||
use sc_network_common::{
|
||||
config::ProtocolId,
|
||||
protocol::{
|
||||
@@ -103,7 +103,7 @@ where
|
||||
/// Event generated by `Behaviour`.
|
||||
pub enum BehaviourOut<B: BlockT> {
|
||||
BlockImport(BlockOrigin, Vec<IncomingBlock<B>>),
|
||||
JustificationImport(Origin, B::Hash, NumberFor<B>, Justifications),
|
||||
JustificationImport(RuntimeOrigin, B::Hash, NumberFor<B>, Justifications),
|
||||
|
||||
/// Started a random iterative Kademlia discovery query.
|
||||
RandomKademliaStarted(ProtocolId),
|
||||
|
||||
@@ -41,7 +41,9 @@ use message::{
|
||||
use notifications::{Notifications, NotificationsOut};
|
||||
use prometheus_endpoint::{register, Gauge, GaugeVec, Opts, PrometheusError, Registry, U64};
|
||||
use sc_client_api::HeaderBackend;
|
||||
use sc_consensus::import_queue::{BlockImportError, BlockImportStatus, IncomingBlock, Origin};
|
||||
use sc_consensus::import_queue::{
|
||||
BlockImportError, BlockImportStatus, IncomingBlock, RuntimeOrigin,
|
||||
};
|
||||
use sc_network_common::{
|
||||
config::ProtocolId,
|
||||
protocol::ProtocolName,
|
||||
@@ -1257,7 +1259,7 @@ fn prepare_warp_sync_request<B: BlockT>(
|
||||
#[must_use]
|
||||
pub enum CustomMessageOutcome<B: BlockT> {
|
||||
BlockImport(BlockOrigin, Vec<IncomingBlock<B>>),
|
||||
JustificationImport(Origin, B::Hash, NumberFor<B>, Justifications),
|
||||
JustificationImport(RuntimeOrigin, B::Hash, NumberFor<B>, Justifications),
|
||||
/// Notification protocols have been opened with a remote.
|
||||
NotificationStreamOpened {
|
||||
remote: PeerId,
|
||||
|
||||
@@ -147,7 +147,7 @@ And update the overall definition for weights on frame and a few related types a
|
||||
+ type BlockWeights = RuntimeBlockWeights;
|
||||
+ type BlockLength = RuntimeBlockLength;
|
||||
+ type DbWeight = RocksDbWeight;
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type Index = Index;
|
||||
@@ -171,25 +198,19 @@ impl frame_system::Trait for Runtime {
|
||||
|
||||
@@ -245,7 +245,7 @@ pub mod pallet {
|
||||
|
||||
/// The outer call dispatch type.
|
||||
type Proposal: Parameter
|
||||
+ Dispatchable<Origin = Self::Origin, PostInfo = PostDispatchInfo>
|
||||
+ Dispatchable<RuntimeOrigin = Self::RuntimeOrigin, PostInfo = PostDispatchInfo>
|
||||
+ From<frame_system::Call<Self>>
|
||||
+ From<Call<Self, I>>
|
||||
+ GetDispatchInfo
|
||||
@@ -253,13 +253,13 @@ pub mod pallet {
|
||||
+ IsType<<Self as frame_system::Config>::RuntimeCall>;
|
||||
|
||||
/// Origin for admin-level operations, like setting the Alliance's rules.
|
||||
type AdminOrigin: EnsureOrigin<Self::Origin>;
|
||||
type AdminOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// Origin that manages entry and forcible discharge from the Alliance.
|
||||
type MembershipManager: EnsureOrigin<Self::Origin>;
|
||||
type MembershipManager: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// Origin for making announcements and adding/removing unscrupulous items.
|
||||
type AnnouncementOrigin: EnsureOrigin<Self::Origin>;
|
||||
type AnnouncementOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// The currency used for deposits.
|
||||
type Currency: ReservableCurrency<Self::AccountId>;
|
||||
|
||||
@@ -47,7 +47,7 @@ impl frame_system::Config for Test {
|
||||
type BaseCallFilter = frame_support::traits::Everything;
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type Index = u64;
|
||||
type BlockNumber = BlockNumber;
|
||||
@@ -95,7 +95,7 @@ parameter_types! {
|
||||
}
|
||||
type AllianceCollective = pallet_collective::Instance1;
|
||||
impl pallet_collective::Config<AllianceCollective> for Test {
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Proposal = RuntimeCall;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type MotionDuration = MotionDuration;
|
||||
@@ -283,7 +283,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
|
||||
let mut ext = sp_io::TestExternalities::new(t);
|
||||
ext.execute_with(|| {
|
||||
assert_ok!(Identity::add_registrar(Origin::signed(1), 1));
|
||||
assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 1));
|
||||
|
||||
let info = IdentityInfo {
|
||||
additional: BoundedVec::default(),
|
||||
@@ -296,58 +296,58 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
image: Data::default(),
|
||||
twitter: Data::default(),
|
||||
};
|
||||
assert_ok!(Identity::set_identity(Origin::signed(1), Box::new(info.clone())));
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(1), Box::new(info.clone())));
|
||||
assert_ok!(Identity::provide_judgement(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
0,
|
||||
1,
|
||||
Judgement::KnownGood,
|
||||
BlakeTwo256::hash_of(&info)
|
||||
));
|
||||
assert_ok!(Identity::set_identity(Origin::signed(2), Box::new(info.clone())));
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(2), Box::new(info.clone())));
|
||||
assert_ok!(Identity::provide_judgement(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
0,
|
||||
2,
|
||||
Judgement::KnownGood,
|
||||
BlakeTwo256::hash_of(&info)
|
||||
));
|
||||
assert_ok!(Identity::set_identity(Origin::signed(3), Box::new(info.clone())));
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(3), Box::new(info.clone())));
|
||||
assert_ok!(Identity::provide_judgement(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
0,
|
||||
3,
|
||||
Judgement::KnownGood,
|
||||
BlakeTwo256::hash_of(&info)
|
||||
));
|
||||
assert_ok!(Identity::set_identity(Origin::signed(4), Box::new(info.clone())));
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(4), Box::new(info.clone())));
|
||||
assert_ok!(Identity::provide_judgement(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
0,
|
||||
4,
|
||||
Judgement::KnownGood,
|
||||
BlakeTwo256::hash_of(&info)
|
||||
));
|
||||
assert_ok!(Identity::set_identity(Origin::signed(5), Box::new(info.clone())));
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(5), Box::new(info.clone())));
|
||||
assert_ok!(Identity::provide_judgement(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
0,
|
||||
5,
|
||||
Judgement::KnownGood,
|
||||
BlakeTwo256::hash_of(&info)
|
||||
));
|
||||
assert_ok!(Identity::set_identity(Origin::signed(6), Box::new(info.clone())));
|
||||
assert_ok!(Identity::set_identity(Origin::signed(8), Box::new(info.clone())));
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(6), Box::new(info.clone())));
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(8), Box::new(info.clone())));
|
||||
assert_ok!(Identity::provide_judgement(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
0,
|
||||
8,
|
||||
Judgement::KnownGood,
|
||||
BlakeTwo256::hash_of(&info)
|
||||
));
|
||||
assert_ok!(Identity::set_identity(Origin::signed(9), Box::new(info.clone())));
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(9), Box::new(info.clone())));
|
||||
assert_ok!(Identity::provide_judgement(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
0,
|
||||
9,
|
||||
Judgement::KnownGood,
|
||||
@@ -356,11 +356,11 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
|
||||
// Joining before init should fail.
|
||||
assert_noop!(
|
||||
Alliance::join_alliance(Origin::signed(1)),
|
||||
Alliance::join_alliance(RuntimeOrigin::signed(1)),
|
||||
Error::<Test, ()>::AllianceNotYetInitialized
|
||||
);
|
||||
|
||||
assert_ok!(Alliance::init_members(Origin::root(), vec![1, 2], vec![3], vec![]));
|
||||
assert_ok!(Alliance::init_members(RuntimeOrigin::root(), vec![1, 2], vec![3], vec![]));
|
||||
|
||||
System::set_block_number(1);
|
||||
});
|
||||
|
||||
@@ -30,28 +30,31 @@ fn init_members_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// alliance must be reset first, no witness data
|
||||
assert_noop!(
|
||||
Alliance::init_members(Origin::root(), vec![8], vec![], vec![],),
|
||||
Alliance::init_members(RuntimeOrigin::root(), vec![8], vec![], vec![],),
|
||||
Error::<Test, ()>::AllianceAlreadyInitialized,
|
||||
);
|
||||
|
||||
// give a retirement notice to check later a retiring member not removed
|
||||
assert_ok!(Alliance::give_retirement_notice(Origin::signed(2)));
|
||||
assert_ok!(Alliance::give_retirement_notice(RuntimeOrigin::signed(2)));
|
||||
assert!(Alliance::is_member_of(&2, MemberRole::Retiring));
|
||||
|
||||
// disband the Alliance to init new
|
||||
assert_ok!(Alliance::disband(Origin::root(), DisbandWitness::new(2, 0)));
|
||||
assert_ok!(Alliance::disband(RuntimeOrigin::root(), DisbandWitness::new(2, 0)));
|
||||
|
||||
// fails without root
|
||||
assert_noop!(Alliance::init_members(Origin::signed(1), vec![], vec![], vec![]), BadOrigin);
|
||||
assert_noop!(
|
||||
Alliance::init_members(RuntimeOrigin::signed(1), vec![], vec![], vec![]),
|
||||
BadOrigin
|
||||
);
|
||||
|
||||
// founders missing, other members given
|
||||
assert_noop!(
|
||||
Alliance::init_members(Origin::root(), vec![], vec![4], vec![2],),
|
||||
Alliance::init_members(RuntimeOrigin::root(), vec![], vec![4], vec![2],),
|
||||
Error::<Test, ()>::FoundersMissing,
|
||||
);
|
||||
|
||||
// success call
|
||||
assert_ok!(Alliance::init_members(Origin::root(), vec![8, 5], vec![4], vec![2],));
|
||||
assert_ok!(Alliance::init_members(RuntimeOrigin::root(), vec![8, 5], vec![4], vec![2],));
|
||||
|
||||
// assert new set of voting members
|
||||
assert_eq!(Alliance::voting_members_sorted(), vec![4, 5, 8]);
|
||||
@@ -78,36 +81,36 @@ fn disband_works() {
|
||||
assert_eq!(Alliance::voting_members_sorted(), vec![1, 2, 3]);
|
||||
|
||||
// give a retirement notice to check later a retiring member not removed
|
||||
assert_ok!(Alliance::give_retirement_notice(Origin::signed(2)));
|
||||
assert_ok!(Alliance::give_retirement_notice(RuntimeOrigin::signed(2)));
|
||||
assert!(Alliance::is_member_of(&2, MemberRole::Retiring));
|
||||
|
||||
// join alliance and reserve funds
|
||||
assert_eq!(Balances::free_balance(9), 40);
|
||||
assert_ok!(Alliance::join_alliance(Origin::signed(9)));
|
||||
assert_ok!(Alliance::join_alliance(RuntimeOrigin::signed(9)));
|
||||
assert_eq!(Alliance::deposit_of(9), Some(25));
|
||||
assert_eq!(Balances::free_balance(9), 15);
|
||||
assert!(Alliance::is_member_of(&9, MemberRole::Ally));
|
||||
|
||||
// fails without root
|
||||
assert_noop!(Alliance::disband(Origin::signed(1), Default::default()), BadOrigin);
|
||||
assert_noop!(Alliance::disband(RuntimeOrigin::signed(1), Default::default()), BadOrigin);
|
||||
|
||||
// bad witness data checks
|
||||
assert_noop!(
|
||||
Alliance::disband(Origin::root(), Default::default(),),
|
||||
Alliance::disband(RuntimeOrigin::root(), Default::default(),),
|
||||
Error::<Test, ()>::BadWitness
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
Alliance::disband(Origin::root(), DisbandWitness::new(1, 1)),
|
||||
Alliance::disband(RuntimeOrigin::root(), DisbandWitness::new(1, 1)),
|
||||
Error::<Test, ()>::BadWitness,
|
||||
);
|
||||
assert_noop!(
|
||||
Alliance::disband(Origin::root(), DisbandWitness::new(2, 0)),
|
||||
Alliance::disband(RuntimeOrigin::root(), DisbandWitness::new(2, 0)),
|
||||
Error::<Test, ()>::BadWitness,
|
||||
);
|
||||
|
||||
// success call
|
||||
assert_ok!(Alliance::disband(Origin::root(), DisbandWitness::new(2, 1)));
|
||||
assert_ok!(Alliance::disband(RuntimeOrigin::root(), DisbandWitness::new(2, 1)));
|
||||
|
||||
// assert members disband
|
||||
assert!(!Alliance::is_member(&1));
|
||||
@@ -125,7 +128,7 @@ fn disband_works() {
|
||||
|
||||
// the Alliance must be set first
|
||||
assert_noop!(
|
||||
Alliance::disband(Origin::root(), DisbandWitness::new(100, 100)),
|
||||
Alliance::disband(RuntimeOrigin::root(), DisbandWitness::new(100, 100)),
|
||||
Error::<Test, ()>::AllianceNotYetInitialized,
|
||||
);
|
||||
})
|
||||
@@ -138,12 +141,17 @@ fn propose_works() {
|
||||
|
||||
// only voting member can propose proposal, 4 is ally not have vote rights
|
||||
assert_noop!(
|
||||
Alliance::propose(Origin::signed(4), 3, Box::new(proposal.clone()), proposal_len),
|
||||
Alliance::propose(
|
||||
RuntimeOrigin::signed(4),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
),
|
||||
Error::<Test, ()>::NoVotingRights
|
||||
);
|
||||
|
||||
assert_ok!(Alliance::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
@@ -171,12 +179,12 @@ fn vote_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let (proposal, proposal_len, hash) = make_remark_proposal(42);
|
||||
assert_ok!(Alliance::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_ok!(Alliance::vote(Origin::signed(2), hash, 0, true));
|
||||
assert_ok!(Alliance::vote(RuntimeOrigin::signed(2), hash, 0, true));
|
||||
|
||||
let record = |event| EventRecord { phase: Phase::Initialization, event, topics: vec![] };
|
||||
assert_eq!(
|
||||
@@ -205,21 +213,21 @@ fn veto_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let (proposal, proposal_len, hash) = make_remark_proposal(42);
|
||||
assert_ok!(Alliance::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
// only set_rule/elevate_ally can be veto
|
||||
assert_noop!(
|
||||
Alliance::veto(Origin::signed(1), hash),
|
||||
Alliance::veto(RuntimeOrigin::signed(1), hash),
|
||||
Error::<Test, ()>::NotVetoableProposal
|
||||
);
|
||||
|
||||
let cid = test_cid();
|
||||
let (vetoable_proposal, vetoable_proposal_len, vetoable_hash) = make_set_rule_proposal(cid);
|
||||
assert_ok!(Alliance::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(vetoable_proposal.clone()),
|
||||
vetoable_proposal_len
|
||||
@@ -227,11 +235,11 @@ fn veto_works() {
|
||||
|
||||
// only founder have veto rights, 3 is fellow
|
||||
assert_noop!(
|
||||
Alliance::veto(Origin::signed(3), vetoable_hash),
|
||||
Alliance::veto(RuntimeOrigin::signed(3), vetoable_hash),
|
||||
Error::<Test, ()>::NotFounder
|
||||
);
|
||||
|
||||
assert_ok!(Alliance::veto(Origin::signed(2), vetoable_hash));
|
||||
assert_ok!(Alliance::veto(RuntimeOrigin::signed(2), vetoable_hash));
|
||||
let record = |event| EventRecord { phase: Phase::Initialization, event, topics: vec![] };
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
@@ -262,15 +270,21 @@ fn close_works() {
|
||||
let (proposal, proposal_len, hash) = make_remark_proposal(42);
|
||||
let proposal_weight = proposal.get_dispatch_info().weight;
|
||||
assert_ok!(Alliance::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_ok!(Alliance::vote(Origin::signed(1), hash, 0, true));
|
||||
assert_ok!(Alliance::vote(Origin::signed(2), hash, 0, true));
|
||||
assert_ok!(Alliance::vote(Origin::signed(3), hash, 0, true));
|
||||
assert_ok!(Alliance::close(Origin::signed(1), hash, 0, proposal_weight, proposal_len));
|
||||
assert_ok!(Alliance::vote(RuntimeOrigin::signed(1), hash, 0, true));
|
||||
assert_ok!(Alliance::vote(RuntimeOrigin::signed(2), hash, 0, true));
|
||||
assert_ok!(Alliance::vote(RuntimeOrigin::signed(3), hash, 0, true));
|
||||
assert_ok!(Alliance::close(
|
||||
RuntimeOrigin::signed(1),
|
||||
hash,
|
||||
0,
|
||||
proposal_weight,
|
||||
proposal_len
|
||||
));
|
||||
|
||||
let record = |event| EventRecord { phase: Phase::Initialization, event, topics: vec![] };
|
||||
assert_eq!(
|
||||
@@ -324,7 +338,7 @@ fn close_works() {
|
||||
fn set_rule_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let cid = test_cid();
|
||||
assert_ok!(Alliance::set_rule(Origin::signed(1), cid.clone()));
|
||||
assert_ok!(Alliance::set_rule(RuntimeOrigin::signed(1), cid.clone()));
|
||||
assert_eq!(Alliance::rule(), Some(cid.clone()));
|
||||
|
||||
System::assert_last_event(mock::RuntimeEvent::Alliance(crate::Event::NewRuleSet {
|
||||
@@ -338,9 +352,9 @@ fn announce_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let cid = test_cid();
|
||||
|
||||
assert_noop!(Alliance::announce(Origin::signed(2), cid.clone()), BadOrigin);
|
||||
assert_noop!(Alliance::announce(RuntimeOrigin::signed(2), cid.clone()), BadOrigin);
|
||||
|
||||
assert_ok!(Alliance::announce(Origin::signed(3), cid.clone()));
|
||||
assert_ok!(Alliance::announce(RuntimeOrigin::signed(3), cid.clone()));
|
||||
assert_eq!(Alliance::announcements(), vec![cid.clone()]);
|
||||
|
||||
System::assert_last_event(mock::RuntimeEvent::Alliance(crate::Event::Announced {
|
||||
@@ -353,7 +367,7 @@ fn announce_works() {
|
||||
fn remove_announcement_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let cid = test_cid();
|
||||
assert_ok!(Alliance::announce(Origin::signed(3), cid.clone()));
|
||||
assert_ok!(Alliance::announce(RuntimeOrigin::signed(3), cid.clone()));
|
||||
assert_eq!(Alliance::announcements(), vec![cid.clone()]);
|
||||
System::assert_last_event(mock::RuntimeEvent::Alliance(crate::Event::Announced {
|
||||
announcement: cid.clone(),
|
||||
@@ -361,7 +375,7 @@ fn remove_announcement_works() {
|
||||
|
||||
System::set_block_number(2);
|
||||
|
||||
assert_ok!(Alliance::remove_announcement(Origin::signed(3), cid.clone()));
|
||||
assert_ok!(Alliance::remove_announcement(RuntimeOrigin::signed(3), cid.clone()));
|
||||
assert_eq!(Alliance::announcements(), vec![]);
|
||||
System::assert_last_event(mock::RuntimeEvent::Alliance(
|
||||
crate::Event::AnnouncementRemoved { announcement: cid },
|
||||
@@ -373,46 +387,52 @@ fn remove_announcement_works() {
|
||||
fn join_alliance_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// check already member
|
||||
assert_noop!(Alliance::join_alliance(Origin::signed(1)), Error::<Test, ()>::AlreadyMember);
|
||||
assert_noop!(
|
||||
Alliance::join_alliance(RuntimeOrigin::signed(1)),
|
||||
Error::<Test, ()>::AlreadyMember
|
||||
);
|
||||
|
||||
// check already listed as unscrupulous
|
||||
assert_ok!(Alliance::add_unscrupulous_items(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
vec![UnscrupulousItem::AccountId(4)]
|
||||
));
|
||||
assert_noop!(
|
||||
Alliance::join_alliance(Origin::signed(4)),
|
||||
Alliance::join_alliance(RuntimeOrigin::signed(4)),
|
||||
Error::<Test, ()>::AccountNonGrata
|
||||
);
|
||||
assert_ok!(Alliance::remove_unscrupulous_items(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
vec![UnscrupulousItem::AccountId(4)]
|
||||
));
|
||||
|
||||
// check deposit funds
|
||||
assert_noop!(
|
||||
Alliance::join_alliance(Origin::signed(5)),
|
||||
Alliance::join_alliance(RuntimeOrigin::signed(5)),
|
||||
Error::<Test, ()>::InsufficientFunds
|
||||
);
|
||||
|
||||
// success to submit
|
||||
assert_ok!(Alliance::join_alliance(Origin::signed(4)));
|
||||
assert_ok!(Alliance::join_alliance(RuntimeOrigin::signed(4)));
|
||||
assert_eq!(Alliance::deposit_of(4), Some(25));
|
||||
assert_eq!(Alliance::members(MemberRole::Ally), vec![4]);
|
||||
|
||||
// check already member
|
||||
assert_noop!(Alliance::join_alliance(Origin::signed(4)), Error::<Test, ()>::AlreadyMember);
|
||||
assert_noop!(
|
||||
Alliance::join_alliance(RuntimeOrigin::signed(4)),
|
||||
Error::<Test, ()>::AlreadyMember
|
||||
);
|
||||
|
||||
// check missing identity judgement
|
||||
#[cfg(not(feature = "runtime-benchmarks"))]
|
||||
assert_noop!(
|
||||
Alliance::join_alliance(Origin::signed(6)),
|
||||
Alliance::join_alliance(RuntimeOrigin::signed(6)),
|
||||
Error::<Test, ()>::WithoutGoodIdentityJudgement
|
||||
);
|
||||
// check missing identity info
|
||||
#[cfg(not(feature = "runtime-benchmarks"))]
|
||||
assert_noop!(
|
||||
Alliance::join_alliance(Origin::signed(7)),
|
||||
Alliance::join_alliance(RuntimeOrigin::signed(7)),
|
||||
Error::<Test, ()>::WithoutIdentityDisplayAndWebsite
|
||||
);
|
||||
});
|
||||
@@ -423,51 +443,51 @@ fn nominate_ally_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// check already member
|
||||
assert_noop!(
|
||||
Alliance::nominate_ally(Origin::signed(1), 2),
|
||||
Alliance::nominate_ally(RuntimeOrigin::signed(1), 2),
|
||||
Error::<Test, ()>::AlreadyMember
|
||||
);
|
||||
|
||||
// only voting member(founder/fellow) have nominate right
|
||||
assert_noop!(
|
||||
Alliance::nominate_ally(Origin::signed(5), 4),
|
||||
Alliance::nominate_ally(RuntimeOrigin::signed(5), 4),
|
||||
Error::<Test, ()>::NoVotingRights
|
||||
);
|
||||
|
||||
// check already listed as unscrupulous
|
||||
assert_ok!(Alliance::add_unscrupulous_items(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
vec![UnscrupulousItem::AccountId(4)]
|
||||
));
|
||||
assert_noop!(
|
||||
Alliance::nominate_ally(Origin::signed(1), 4),
|
||||
Alliance::nominate_ally(RuntimeOrigin::signed(1), 4),
|
||||
Error::<Test, ()>::AccountNonGrata
|
||||
);
|
||||
assert_ok!(Alliance::remove_unscrupulous_items(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
vec![UnscrupulousItem::AccountId(4)]
|
||||
));
|
||||
|
||||
// success to nominate
|
||||
assert_ok!(Alliance::nominate_ally(Origin::signed(1), 4));
|
||||
assert_ok!(Alliance::nominate_ally(RuntimeOrigin::signed(1), 4));
|
||||
assert_eq!(Alliance::deposit_of(4), None);
|
||||
assert_eq!(Alliance::members(MemberRole::Ally), vec![4]);
|
||||
|
||||
// check already member
|
||||
assert_noop!(
|
||||
Alliance::nominate_ally(Origin::signed(1), 4),
|
||||
Alliance::nominate_ally(RuntimeOrigin::signed(1), 4),
|
||||
Error::<Test, ()>::AlreadyMember
|
||||
);
|
||||
|
||||
// check missing identity judgement
|
||||
#[cfg(not(feature = "runtime-benchmarks"))]
|
||||
assert_noop!(
|
||||
Alliance::join_alliance(Origin::signed(6)),
|
||||
Alliance::join_alliance(RuntimeOrigin::signed(6)),
|
||||
Error::<Test, ()>::WithoutGoodIdentityJudgement
|
||||
);
|
||||
// check missing identity info
|
||||
#[cfg(not(feature = "runtime-benchmarks"))]
|
||||
assert_noop!(
|
||||
Alliance::join_alliance(Origin::signed(7)),
|
||||
Alliance::join_alliance(RuntimeOrigin::signed(7)),
|
||||
Error::<Test, ()>::WithoutIdentityDisplayAndWebsite
|
||||
);
|
||||
});
|
||||
@@ -476,13 +496,16 @@ fn nominate_ally_works() {
|
||||
#[test]
|
||||
fn elevate_ally_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(Alliance::elevate_ally(Origin::signed(2), 4), Error::<Test, ()>::NotAlly);
|
||||
assert_noop!(
|
||||
Alliance::elevate_ally(RuntimeOrigin::signed(2), 4),
|
||||
Error::<Test, ()>::NotAlly
|
||||
);
|
||||
|
||||
assert_ok!(Alliance::join_alliance(Origin::signed(4)));
|
||||
assert_ok!(Alliance::join_alliance(RuntimeOrigin::signed(4)));
|
||||
assert_eq!(Alliance::members(MemberRole::Ally), vec![4]);
|
||||
assert_eq!(Alliance::members(MemberRole::Fellow), vec![3]);
|
||||
|
||||
assert_ok!(Alliance::elevate_ally(Origin::signed(2), 4));
|
||||
assert_ok!(Alliance::elevate_ally(RuntimeOrigin::signed(2), 4));
|
||||
assert_eq!(Alliance::members(MemberRole::Ally), Vec::<u64>::new());
|
||||
assert_eq!(Alliance::members(MemberRole::Fellow), vec![3, 4]);
|
||||
});
|
||||
@@ -492,12 +515,12 @@ fn elevate_ally_works() {
|
||||
fn give_retirement_notice_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
Alliance::give_retirement_notice(Origin::signed(4)),
|
||||
Alliance::give_retirement_notice(RuntimeOrigin::signed(4)),
|
||||
Error::<Test, ()>::NotMember
|
||||
);
|
||||
|
||||
assert_eq!(Alliance::members(MemberRole::Fellow), vec![3]);
|
||||
assert_ok!(Alliance::give_retirement_notice(Origin::signed(3)));
|
||||
assert_ok!(Alliance::give_retirement_notice(RuntimeOrigin::signed(3)));
|
||||
assert_eq!(Alliance::members(MemberRole::Fellow), Vec::<u64>::new());
|
||||
assert_eq!(Alliance::members(MemberRole::Retiring), vec![3]);
|
||||
System::assert_last_event(mock::RuntimeEvent::Alliance(
|
||||
@@ -505,7 +528,7 @@ fn give_retirement_notice_work() {
|
||||
));
|
||||
|
||||
assert_noop!(
|
||||
Alliance::give_retirement_notice(Origin::signed(3)),
|
||||
Alliance::give_retirement_notice(RuntimeOrigin::signed(3)),
|
||||
Error::<Test, ()>::AlreadyRetiring
|
||||
);
|
||||
});
|
||||
@@ -515,23 +538,23 @@ fn give_retirement_notice_work() {
|
||||
fn retire_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
Alliance::retire(Origin::signed(2)),
|
||||
Alliance::retire(RuntimeOrigin::signed(2)),
|
||||
Error::<Test, ()>::RetirementNoticeNotGiven
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
Alliance::retire(Origin::signed(4)),
|
||||
Alliance::retire(RuntimeOrigin::signed(4)),
|
||||
Error::<Test, ()>::RetirementNoticeNotGiven
|
||||
);
|
||||
|
||||
assert_eq!(Alliance::members(MemberRole::Fellow), vec![3]);
|
||||
assert_ok!(Alliance::give_retirement_notice(Origin::signed(3)));
|
||||
assert_ok!(Alliance::give_retirement_notice(RuntimeOrigin::signed(3)));
|
||||
assert_noop!(
|
||||
Alliance::retire(Origin::signed(3)),
|
||||
Alliance::retire(RuntimeOrigin::signed(3)),
|
||||
Error::<Test, ()>::RetirementPeriodNotPassed
|
||||
);
|
||||
System::set_block_number(System::block_number() + RetirementPeriod::get());
|
||||
assert_ok!(Alliance::retire(Origin::signed(3)));
|
||||
assert_ok!(Alliance::retire(RuntimeOrigin::signed(3)));
|
||||
assert_eq!(Alliance::members(MemberRole::Fellow), Vec::<u64>::new());
|
||||
System::assert_last_event(mock::RuntimeEvent::Alliance(crate::Event::MemberRetired {
|
||||
member: (3),
|
||||
@@ -541,11 +564,11 @@ fn retire_works() {
|
||||
// Move time on:
|
||||
System::set_block_number(System::block_number() + RetirementPeriod::get());
|
||||
|
||||
assert_powerless(Origin::signed(3));
|
||||
assert_powerless(RuntimeOrigin::signed(3));
|
||||
});
|
||||
}
|
||||
|
||||
fn assert_powerless(user: Origin) {
|
||||
fn assert_powerless(user: RuntimeOrigin) {
|
||||
//vote / veto with a valid propsal
|
||||
let cid = test_cid();
|
||||
let (proposal, _, _) = make_kick_member_proposal(42);
|
||||
@@ -578,13 +601,16 @@ fn assert_powerless(user: Origin) {
|
||||
#[test]
|
||||
fn kick_member_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(Alliance::kick_member(Origin::signed(4), 4), BadOrigin);
|
||||
assert_noop!(Alliance::kick_member(RuntimeOrigin::signed(4), 4), BadOrigin);
|
||||
|
||||
assert_noop!(Alliance::kick_member(Origin::signed(2), 4), Error::<Test, ()>::NotMember);
|
||||
assert_noop!(
|
||||
Alliance::kick_member(RuntimeOrigin::signed(2), 4),
|
||||
Error::<Test, ()>::NotMember
|
||||
);
|
||||
|
||||
<DepositOf<Test, ()>>::insert(2, 25);
|
||||
assert_eq!(Alliance::members(MemberRole::Founder), vec![1, 2]);
|
||||
assert_ok!(Alliance::kick_member(Origin::signed(2), 2));
|
||||
assert_ok!(Alliance::kick_member(RuntimeOrigin::signed(2), 2));
|
||||
assert_eq!(Alliance::members(MemberRole::Founder), vec![1]);
|
||||
assert_eq!(<DepositOf<Test, ()>>::get(2), None);
|
||||
System::assert_last_event(mock::RuntimeEvent::Alliance(crate::Event::MemberKicked {
|
||||
@@ -597,10 +623,10 @@ fn kick_member_works() {
|
||||
#[test]
|
||||
fn add_unscrupulous_items_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(Alliance::add_unscrupulous_items(Origin::signed(2), vec![]), BadOrigin);
|
||||
assert_noop!(Alliance::add_unscrupulous_items(RuntimeOrigin::signed(2), vec![]), BadOrigin);
|
||||
|
||||
assert_ok!(Alliance::add_unscrupulous_items(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
vec![
|
||||
UnscrupulousItem::AccountId(3),
|
||||
UnscrupulousItem::Website("abc".as_bytes().to_vec().try_into().unwrap())
|
||||
@@ -611,7 +637,7 @@ fn add_unscrupulous_items_works() {
|
||||
|
||||
assert_noop!(
|
||||
Alliance::add_unscrupulous_items(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
vec![UnscrupulousItem::AccountId(3)]
|
||||
),
|
||||
Error::<Test, ()>::AlreadyUnscrupulous
|
||||
@@ -622,23 +648,26 @@ fn add_unscrupulous_items_works() {
|
||||
#[test]
|
||||
fn remove_unscrupulous_items_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(Alliance::remove_unscrupulous_items(Origin::signed(2), vec![]), BadOrigin);
|
||||
assert_noop!(
|
||||
Alliance::remove_unscrupulous_items(RuntimeOrigin::signed(2), vec![]),
|
||||
BadOrigin
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
Alliance::remove_unscrupulous_items(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
vec![UnscrupulousItem::AccountId(3)]
|
||||
),
|
||||
Error::<Test, ()>::NotListedAsUnscrupulous
|
||||
);
|
||||
|
||||
assert_ok!(Alliance::add_unscrupulous_items(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
vec![UnscrupulousItem::AccountId(3)]
|
||||
));
|
||||
assert_eq!(Alliance::unscrupulous_accounts(), vec![3]);
|
||||
assert_ok!(Alliance::remove_unscrupulous_items(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
vec![UnscrupulousItem::AccountId(3)]
|
||||
));
|
||||
assert_eq!(Alliance::unscrupulous_accounts(), Vec::<u64>::new());
|
||||
|
||||
@@ -208,7 +208,7 @@ pub mod pallet {
|
||||
|
||||
/// The origin which may forcibly create or destroy an asset or otherwise alter privileged
|
||||
/// attributes.
|
||||
type ForceOrigin: EnsureOrigin<Self::Origin>;
|
||||
type ForceOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// The basic amount of funds that must be reserved for an asset.
|
||||
#[pallet::constant]
|
||||
|
||||
@@ -49,7 +49,7 @@ impl frame_system::Config for Test {
|
||||
type BaseCallFilter = frame_support::traits::Everything;
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
|
||||
+360
-252
File diff suppressed because it is too large
Load Diff
@@ -37,7 +37,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
@@ -100,7 +100,7 @@ fn two_party_successful_swap() {
|
||||
// A creates the swap on chain1.
|
||||
chain1.execute_with(|| {
|
||||
AtomicSwap::create_swap(
|
||||
Origin::signed(A),
|
||||
RuntimeOrigin::signed(A),
|
||||
B,
|
||||
hashed_proof,
|
||||
BalanceSwapAction::new(50),
|
||||
@@ -115,7 +115,7 @@ fn two_party_successful_swap() {
|
||||
// B creates the swap on chain2.
|
||||
chain2.execute_with(|| {
|
||||
AtomicSwap::create_swap(
|
||||
Origin::signed(B),
|
||||
RuntimeOrigin::signed(B),
|
||||
A,
|
||||
hashed_proof,
|
||||
BalanceSwapAction::new(75),
|
||||
@@ -129,8 +129,12 @@ fn two_party_successful_swap() {
|
||||
|
||||
// A reveals the proof and claims the swap on chain2.
|
||||
chain2.execute_with(|| {
|
||||
AtomicSwap::claim_swap(Origin::signed(A), proof.to_vec(), BalanceSwapAction::new(75))
|
||||
.unwrap();
|
||||
AtomicSwap::claim_swap(
|
||||
RuntimeOrigin::signed(A),
|
||||
proof.to_vec(),
|
||||
BalanceSwapAction::new(75),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(Balances::free_balance(A), 100 + 75);
|
||||
assert_eq!(Balances::free_balance(B), 200 - 75);
|
||||
@@ -138,8 +142,12 @@ fn two_party_successful_swap() {
|
||||
|
||||
// B use the revealed proof to claim the swap on chain1.
|
||||
chain1.execute_with(|| {
|
||||
AtomicSwap::claim_swap(Origin::signed(B), proof.to_vec(), BalanceSwapAction::new(50))
|
||||
.unwrap();
|
||||
AtomicSwap::claim_swap(
|
||||
RuntimeOrigin::signed(B),
|
||||
proof.to_vec(),
|
||||
BalanceSwapAction::new(50),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(Balances::free_balance(A), 100 - 50);
|
||||
assert_eq!(Balances::free_balance(B), 200 + 50);
|
||||
|
||||
@@ -56,7 +56,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
|
||||
@@ -235,7 +235,7 @@ mod tests {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = BlockNumber;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
|
||||
@@ -468,7 +468,7 @@ mod tests {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
@@ -738,7 +738,7 @@ mod tests {
|
||||
System::reset_events();
|
||||
System::initialize(¤t_depth, &parent_hash, &Default::default());
|
||||
Authorship::on_initialize(current_depth);
|
||||
Authorship::set_uncles(Origin::none(), uncles).unwrap();
|
||||
Authorship::set_uncles(RuntimeOrigin::none(), uncles).unwrap();
|
||||
Authorship::on_finalize(current_depth);
|
||||
max_item_count =
|
||||
std::cmp::max(max_item_count, <Authorship as Store>::Uncles::get().len());
|
||||
|
||||
@@ -74,7 +74,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
|
||||
@@ -289,7 +289,7 @@ fn can_enact_next_config() {
|
||||
assert_eq!(NextEpochConfig::<Test>::get(), Some(next_config.clone()));
|
||||
|
||||
Babe::plan_config_change(
|
||||
Origin::root(),
|
||||
RuntimeOrigin::root(),
|
||||
NextConfigDescriptor::V1 {
|
||||
c: next_next_config.c,
|
||||
allowed_slots: next_next_config.allowed_slots,
|
||||
@@ -323,15 +323,15 @@ fn only_root_can_enact_config_change() {
|
||||
let next_config =
|
||||
NextConfigDescriptor::V1 { c: (1, 4), allowed_slots: AllowedSlots::PrimarySlots };
|
||||
|
||||
let res = Babe::plan_config_change(Origin::none(), next_config.clone());
|
||||
let res = Babe::plan_config_change(RuntimeOrigin::none(), next_config.clone());
|
||||
|
||||
assert_noop!(res, DispatchError::BadOrigin);
|
||||
|
||||
let res = Babe::plan_config_change(Origin::signed(1), next_config.clone());
|
||||
let res = Babe::plan_config_change(RuntimeOrigin::signed(1), next_config.clone());
|
||||
|
||||
assert_noop!(res, DispatchError::BadOrigin);
|
||||
|
||||
let res = Babe::plan_config_change(Origin::root(), next_config);
|
||||
let res = Babe::plan_config_change(RuntimeOrigin::root(), next_config);
|
||||
|
||||
assert!(res.is_ok());
|
||||
});
|
||||
@@ -464,7 +464,7 @@ fn report_equivocation_current_session_works() {
|
||||
|
||||
// report the equivocation
|
||||
Babe::report_equivocation_unsigned(
|
||||
Origin::none(),
|
||||
RuntimeOrigin::none(),
|
||||
Box::new(equivocation_proof),
|
||||
key_owner_proof,
|
||||
)
|
||||
@@ -536,7 +536,7 @@ fn report_equivocation_old_session_works() {
|
||||
|
||||
// report the equivocation
|
||||
Babe::report_equivocation_unsigned(
|
||||
Origin::none(),
|
||||
RuntimeOrigin::none(),
|
||||
Box::new(equivocation_proof),
|
||||
key_owner_proof,
|
||||
)
|
||||
@@ -588,7 +588,7 @@ fn report_equivocation_invalid_key_owner_proof() {
|
||||
key_owner_proof.session = 0;
|
||||
assert_err!(
|
||||
Babe::report_equivocation_unsigned(
|
||||
Origin::none(),
|
||||
RuntimeOrigin::none(),
|
||||
Box::new(equivocation_proof.clone()),
|
||||
key_owner_proof
|
||||
),
|
||||
@@ -608,7 +608,7 @@ fn report_equivocation_invalid_key_owner_proof() {
|
||||
|
||||
assert_err!(
|
||||
Babe::report_equivocation_unsigned(
|
||||
Origin::none(),
|
||||
RuntimeOrigin::none(),
|
||||
Box::new(equivocation_proof),
|
||||
key_owner_proof,
|
||||
),
|
||||
@@ -642,7 +642,7 @@ fn report_equivocation_invalid_equivocation_proof() {
|
||||
let assert_invalid_equivocation = |equivocation_proof| {
|
||||
assert_err!(
|
||||
Babe::report_equivocation_unsigned(
|
||||
Origin::none(),
|
||||
RuntimeOrigin::none(),
|
||||
Box::new(equivocation_proof),
|
||||
key_owner_proof.clone(),
|
||||
),
|
||||
@@ -784,7 +784,7 @@ fn report_equivocation_validate_unsigned_prevents_duplicates() {
|
||||
|
||||
// we submit the report
|
||||
Babe::report_equivocation_unsigned(
|
||||
Origin::none(),
|
||||
RuntimeOrigin::none(),
|
||||
Box::new(equivocation_proof),
|
||||
key_owner_proof,
|
||||
)
|
||||
@@ -857,7 +857,7 @@ fn valid_equivocation_reports_dont_pay_fees() {
|
||||
|
||||
// report the equivocation.
|
||||
let post_info = Babe::report_equivocation_unsigned(
|
||||
Origin::none(),
|
||||
RuntimeOrigin::none(),
|
||||
Box::new(equivocation_proof.clone()),
|
||||
key_owner_proof.clone(),
|
||||
)
|
||||
@@ -871,7 +871,7 @@ fn valid_equivocation_reports_dont_pay_fees() {
|
||||
// report the equivocation again which is invalid now since it is
|
||||
// duplicate.
|
||||
let post_info = Babe::report_equivocation_unsigned(
|
||||
Origin::none(),
|
||||
RuntimeOrigin::none(),
|
||||
Box::new(equivocation_proof),
|
||||
key_owner_proof,
|
||||
)
|
||||
|
||||
@@ -49,7 +49,7 @@ impl frame_election_provider_support::ScoreProvider<AccountId> for StakingMock {
|
||||
impl frame_system::Config for Runtime {
|
||||
type SS58Prefix = ();
|
||||
type BaseCallFilter = frame_support::traits::Everything;
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
|
||||
@@ -37,7 +37,7 @@ mod pallet {
|
||||
// when increasing score to the level of non-existent bag
|
||||
assert_eq!(List::<Runtime>::get_score(&42).unwrap(), 20);
|
||||
StakingMock::set_score_of(&42, 2_000);
|
||||
assert_ok!(BagsList::rebag(Origin::signed(0), 42));
|
||||
assert_ok!(BagsList::rebag(RuntimeOrigin::signed(0), 42));
|
||||
assert_eq!(List::<Runtime>::get_score(&42).unwrap(), 2_000);
|
||||
|
||||
// then a new bag is created and the id moves into it
|
||||
@@ -48,7 +48,7 @@ mod pallet {
|
||||
|
||||
// when decreasing score within the range of the current bag
|
||||
StakingMock::set_score_of(&42, 1_001);
|
||||
assert_ok!(BagsList::rebag(Origin::signed(0), 42));
|
||||
assert_ok!(BagsList::rebag(RuntimeOrigin::signed(0), 42));
|
||||
|
||||
// then the id does not move
|
||||
assert_eq!(
|
||||
@@ -60,7 +60,7 @@ mod pallet {
|
||||
|
||||
// when reducing score to the level of a non-existent bag
|
||||
StakingMock::set_score_of(&42, 30);
|
||||
assert_ok!(BagsList::rebag(Origin::signed(0), 42));
|
||||
assert_ok!(BagsList::rebag(RuntimeOrigin::signed(0), 42));
|
||||
|
||||
// then a new bag is created and the id moves into it
|
||||
assert_eq!(
|
||||
@@ -71,7 +71,7 @@ mod pallet {
|
||||
|
||||
// when increasing score to the level of a pre-existing bag
|
||||
StakingMock::set_score_of(&42, 500);
|
||||
assert_ok!(BagsList::rebag(Origin::signed(0), 42));
|
||||
assert_ok!(BagsList::rebag(RuntimeOrigin::signed(0), 42));
|
||||
|
||||
// then the id moves into that bag
|
||||
assert_eq!(
|
||||
@@ -92,7 +92,7 @@ mod pallet {
|
||||
|
||||
// when
|
||||
StakingMock::set_score_of(&4, 10);
|
||||
assert_ok!(BagsList::rebag(Origin::signed(0), 4));
|
||||
assert_ok!(BagsList::rebag(RuntimeOrigin::signed(0), 4));
|
||||
|
||||
// then
|
||||
assert_eq!(List::<Runtime>::get_bags(), vec![(10, vec![1, 4]), (1_000, vec![2, 3])]);
|
||||
@@ -100,7 +100,7 @@ mod pallet {
|
||||
|
||||
// when
|
||||
StakingMock::set_score_of(&3, 10);
|
||||
assert_ok!(BagsList::rebag(Origin::signed(0), 3));
|
||||
assert_ok!(BagsList::rebag(RuntimeOrigin::signed(0), 3));
|
||||
|
||||
// then
|
||||
assert_eq!(List::<Runtime>::get_bags(), vec![(10, vec![1, 4, 3]), (1_000, vec![2])]);
|
||||
@@ -111,7 +111,7 @@ mod pallet {
|
||||
|
||||
// when
|
||||
StakingMock::set_score_of(&2, 10);
|
||||
assert_ok!(BagsList::rebag(Origin::signed(0), 2));
|
||||
assert_ok!(BagsList::rebag(RuntimeOrigin::signed(0), 2));
|
||||
|
||||
// then
|
||||
assert_eq!(List::<Runtime>::get_bags(), vec![(10, vec![1, 4, 3, 2])]);
|
||||
@@ -126,7 +126,7 @@ mod pallet {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
// when
|
||||
StakingMock::set_score_of(&2, 10);
|
||||
assert_ok!(BagsList::rebag(Origin::signed(0), 2));
|
||||
assert_ok!(BagsList::rebag(RuntimeOrigin::signed(0), 2));
|
||||
|
||||
// then
|
||||
assert_eq!(List::<Runtime>::get_bags(), vec![(10, vec![1, 2]), (1_000, vec![3, 4])]);
|
||||
@@ -134,7 +134,7 @@ mod pallet {
|
||||
|
||||
// when
|
||||
StakingMock::set_score_of(&3, 10);
|
||||
assert_ok!(BagsList::rebag(Origin::signed(0), 3));
|
||||
assert_ok!(BagsList::rebag(RuntimeOrigin::signed(0), 3));
|
||||
|
||||
// then
|
||||
assert_eq!(List::<Runtime>::get_bags(), vec![(10, vec![1, 2, 3]), (1_000, vec![4])]);
|
||||
@@ -142,7 +142,7 @@ mod pallet {
|
||||
|
||||
// when
|
||||
StakingMock::set_score_of(&4, 10);
|
||||
assert_ok!(BagsList::rebag(Origin::signed(0), 4));
|
||||
assert_ok!(BagsList::rebag(RuntimeOrigin::signed(0), 4));
|
||||
|
||||
// then
|
||||
assert_eq!(List::<Runtime>::get_bags(), vec![(10, vec![1, 2, 3, 4])]);
|
||||
@@ -159,12 +159,15 @@ mod pallet {
|
||||
assert!(!node_3.is_misplaced(500));
|
||||
|
||||
// then calling rebag on account 3 with score 500 is a noop
|
||||
assert_storage_noop!(assert_eq!(BagsList::rebag(Origin::signed(0), 3), Ok(())));
|
||||
assert_storage_noop!(assert_eq!(BagsList::rebag(RuntimeOrigin::signed(0), 3), Ok(())));
|
||||
|
||||
// when account 42 is not in the list
|
||||
assert!(!BagsList::contains(&42));
|
||||
// then rebag-ing account 42 is an error
|
||||
assert_storage_noop!(assert!(matches!(BagsList::rebag(Origin::signed(0), 42), Err(_))));
|
||||
assert_storage_noop!(assert!(matches!(
|
||||
BagsList::rebag(RuntimeOrigin::signed(0), 42),
|
||||
Err(_)
|
||||
)));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -200,7 +203,7 @@ mod pallet {
|
||||
);
|
||||
|
||||
// any rebag is noop.
|
||||
assert_storage_noop!(assert_eq!(BagsList::rebag(Origin::signed(0), 1), Ok(())));
|
||||
assert_storage_noop!(assert_eq!(BagsList::rebag(RuntimeOrigin::signed(0), 1), Ok(())));
|
||||
})
|
||||
}
|
||||
|
||||
@@ -214,7 +217,7 @@ mod pallet {
|
||||
assert_eq!(List::<Runtime>::get_bags(), vec![(20, vec![10, 11])]);
|
||||
|
||||
// when
|
||||
assert_ok!(BagsList::put_in_front_of(Origin::signed(11), 10));
|
||||
assert_ok!(BagsList::put_in_front_of(RuntimeOrigin::signed(11), 10));
|
||||
|
||||
// then
|
||||
assert_eq!(List::<Runtime>::get_bags(), vec![(20, vec![11, 10])]);
|
||||
@@ -231,7 +234,7 @@ mod pallet {
|
||||
assert_eq!(List::<Runtime>::get_bags(), vec![(20, vec![11, 10])]);
|
||||
|
||||
// when
|
||||
assert_ok!(BagsList::put_in_front_of(Origin::signed(11), 10));
|
||||
assert_ok!(BagsList::put_in_front_of(RuntimeOrigin::signed(11), 10));
|
||||
|
||||
// then
|
||||
assert_eq!(List::<Runtime>::get_bags(), vec![(20, vec![11, 10])]);
|
||||
@@ -247,7 +250,7 @@ mod pallet {
|
||||
StakingMock::set_score_of(&3, 999);
|
||||
|
||||
// when
|
||||
assert_ok!(BagsList::put_in_front_of(Origin::signed(4), 3));
|
||||
assert_ok!(BagsList::put_in_front_of(RuntimeOrigin::signed(4), 3));
|
||||
|
||||
// then
|
||||
assert_eq!(List::<Runtime>::get_bags(), vec![(10, vec![1]), (1_000, vec![2, 4, 3, 5])]);
|
||||
@@ -268,7 +271,7 @@ mod pallet {
|
||||
StakingMock::set_score_of(&5, 999);
|
||||
|
||||
// when
|
||||
assert_ok!(BagsList::put_in_front_of(Origin::signed(3), 5));
|
||||
assert_ok!(BagsList::put_in_front_of(RuntimeOrigin::signed(3), 5));
|
||||
|
||||
// then
|
||||
assert_eq!(
|
||||
@@ -287,7 +290,7 @@ mod pallet {
|
||||
StakingMock::set_score_of(&2, 999);
|
||||
|
||||
// when
|
||||
assert_ok!(BagsList::put_in_front_of(Origin::signed(3), 2));
|
||||
assert_ok!(BagsList::put_in_front_of(RuntimeOrigin::signed(3), 2));
|
||||
|
||||
// then
|
||||
assert_eq!(List::<Runtime>::get_bags(), vec![(10, vec![1]), (1_000, vec![3, 2, 4])]);
|
||||
@@ -303,7 +306,7 @@ mod pallet {
|
||||
StakingMock::set_score_of(&3, 999);
|
||||
|
||||
// when
|
||||
assert_ok!(BagsList::put_in_front_of(Origin::signed(4), 3));
|
||||
assert_ok!(BagsList::put_in_front_of(RuntimeOrigin::signed(4), 3));
|
||||
|
||||
// then
|
||||
assert_eq!(List::<Runtime>::get_bags(), vec![(10, vec![1]), (1_000, vec![2, 4, 3])]);
|
||||
@@ -319,7 +322,7 @@ mod pallet {
|
||||
StakingMock::set_score_of(&2, 999);
|
||||
|
||||
// when
|
||||
assert_ok!(BagsList::put_in_front_of(Origin::signed(5), 2));
|
||||
assert_ok!(BagsList::put_in_front_of(RuntimeOrigin::signed(5), 2));
|
||||
|
||||
// then
|
||||
assert_eq!(List::<Runtime>::get_bags(), vec![(10, vec![1]), (1_000, vec![5, 2, 3, 4])]);
|
||||
@@ -335,7 +338,7 @@ mod pallet {
|
||||
StakingMock::set_score_of(&4, 999);
|
||||
|
||||
// when
|
||||
BagsList::put_in_front_of(Origin::signed(2), 4).unwrap();
|
||||
BagsList::put_in_front_of(RuntimeOrigin::signed(2), 4).unwrap();
|
||||
|
||||
// then
|
||||
assert_eq!(List::<Runtime>::get_bags(), vec![(10, vec![1]), (1_000, vec![3, 2, 4, 5])]);
|
||||
@@ -349,7 +352,7 @@ mod pallet {
|
||||
assert_eq!(List::<Runtime>::get_bags(), vec![(10, vec![1]), (1_000, vec![2, 3, 4, 5])]);
|
||||
|
||||
// when
|
||||
BagsList::put_in_front_of(Origin::signed(3), 5).unwrap();
|
||||
BagsList::put_in_front_of(RuntimeOrigin::signed(3), 5).unwrap();
|
||||
|
||||
// then
|
||||
assert_eq!(List::<Runtime>::get_bags(), vec![(10, vec![1]), (1_000, vec![2, 4, 3, 5])]);
|
||||
@@ -365,7 +368,7 @@ mod pallet {
|
||||
StakingMock::set_score_of(&4, 999);
|
||||
|
||||
// when
|
||||
BagsList::put_in_front_of(Origin::signed(2), 4).unwrap();
|
||||
BagsList::put_in_front_of(RuntimeOrigin::signed(2), 4).unwrap();
|
||||
|
||||
// then
|
||||
assert_eq!(List::<Runtime>::get_bags(), vec![(10, vec![1]), (1_000, vec![3, 2, 4])]);
|
||||
@@ -382,7 +385,7 @@ mod pallet {
|
||||
|
||||
// then
|
||||
assert_noop!(
|
||||
BagsList::put_in_front_of(Origin::signed(3), 2),
|
||||
BagsList::put_in_front_of(RuntimeOrigin::signed(3), 2),
|
||||
crate::pallet::Error::<Runtime>::List(ListError::NotHeavier)
|
||||
);
|
||||
});
|
||||
@@ -396,7 +399,7 @@ mod pallet {
|
||||
|
||||
// then
|
||||
assert_noop!(
|
||||
BagsList::put_in_front_of(Origin::signed(3), 4),
|
||||
BagsList::put_in_front_of(RuntimeOrigin::signed(3), 4),
|
||||
crate::pallet::Error::<Runtime>::List(ListError::NotHeavier)
|
||||
);
|
||||
});
|
||||
@@ -413,7 +416,7 @@ mod pallet {
|
||||
|
||||
// then
|
||||
assert_noop!(
|
||||
BagsList::put_in_front_of(Origin::signed(5), 4),
|
||||
BagsList::put_in_front_of(RuntimeOrigin::signed(5), 4),
|
||||
crate::pallet::Error::<Runtime>::List(ListError::NodeNotFound)
|
||||
);
|
||||
});
|
||||
@@ -427,7 +430,7 @@ mod pallet {
|
||||
|
||||
// then
|
||||
assert_noop!(
|
||||
BagsList::put_in_front_of(Origin::signed(4), 5),
|
||||
BagsList::put_in_front_of(RuntimeOrigin::signed(4), 5),
|
||||
crate::pallet::Error::<Runtime>::List(ListError::NodeNotFound)
|
||||
);
|
||||
});
|
||||
@@ -441,7 +444,7 @@ mod pallet {
|
||||
|
||||
// then
|
||||
assert_noop!(
|
||||
BagsList::put_in_front_of(Origin::signed(4), 1),
|
||||
BagsList::put_in_front_of(RuntimeOrigin::signed(4), 1),
|
||||
crate::pallet::Error::<Runtime>::List(ListError::NotInSameBag)
|
||||
);
|
||||
});
|
||||
|
||||
@@ -825,7 +825,7 @@ macro_rules! decl_tests {
|
||||
/* User has no reference counter, so they can die in these scenarios */
|
||||
|
||||
// SCENARIO: Slash would not kill account.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 1_000, 0));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 1_000, 0));
|
||||
// Slashed completed in full
|
||||
assert_eq!(Balances::slash(&1, 900), (NegativeImbalance::new(900), 0));
|
||||
// Account is still alive
|
||||
@@ -833,35 +833,35 @@ macro_rules! decl_tests {
|
||||
System::assert_last_event(RuntimeEvent::Balances(crate::Event::Slashed { who: 1, amount: 900 }));
|
||||
|
||||
// SCENARIO: Slash will kill account because not enough balance left.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 1_000, 0));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 1_000, 0));
|
||||
// Slashed completed in full
|
||||
assert_eq!(Balances::slash(&1, 950), (NegativeImbalance::new(950), 0));
|
||||
// Account is killed
|
||||
assert!(!System::account_exists(&1));
|
||||
|
||||
// SCENARIO: Over-slash will kill account, and report missing slash amount.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 1_000, 0));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 1_000, 0));
|
||||
// Slashed full free_balance, and reports 300 not slashed
|
||||
assert_eq!(Balances::slash(&1, 1_300), (NegativeImbalance::new(1000), 300));
|
||||
// Account is dead
|
||||
assert!(!System::account_exists(&1));
|
||||
|
||||
// SCENARIO: Over-slash can take from reserved, but keep alive.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 1_000, 400));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 1_000, 400));
|
||||
// Slashed full free_balance and 300 of reserved balance
|
||||
assert_eq!(Balances::slash(&1, 1_300), (NegativeImbalance::new(1300), 0));
|
||||
// Account is still alive
|
||||
assert!(System::account_exists(&1));
|
||||
|
||||
// SCENARIO: Over-slash can take from reserved, and kill.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 1_000, 350));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 1_000, 350));
|
||||
// Slashed full free_balance and 300 of reserved balance
|
||||
assert_eq!(Balances::slash(&1, 1_300), (NegativeImbalance::new(1300), 0));
|
||||
// Account is dead because 50 reserved balance is not enough to keep alive
|
||||
assert!(!System::account_exists(&1));
|
||||
|
||||
// SCENARIO: Over-slash can take as much as possible from reserved, kill, and report missing amount.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 1_000, 250));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 1_000, 250));
|
||||
// Slashed full free_balance and 300 of reserved balance
|
||||
assert_eq!(Balances::slash(&1, 1_300), (NegativeImbalance::new(1250), 50));
|
||||
// Account is super dead
|
||||
@@ -870,7 +870,7 @@ macro_rules! decl_tests {
|
||||
/* User will now have a reference counter on them, keeping them alive in these scenarios */
|
||||
|
||||
// SCENARIO: Slash would not kill account.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 1_000, 0));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 1_000, 0));
|
||||
assert_ok!(System::inc_consumers(&1)); // <-- Reference counter added here is enough for all tests
|
||||
// Slashed completed in full
|
||||
assert_eq!(Balances::slash(&1, 900), (NegativeImbalance::new(900), 0));
|
||||
@@ -878,35 +878,35 @@ macro_rules! decl_tests {
|
||||
assert!(System::account_exists(&1));
|
||||
|
||||
// SCENARIO: Slash will take as much as possible without killing account.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 1_000, 0));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 1_000, 0));
|
||||
// Slashed completed in full
|
||||
assert_eq!(Balances::slash(&1, 950), (NegativeImbalance::new(900), 50));
|
||||
// Account is still alive
|
||||
assert!(System::account_exists(&1));
|
||||
|
||||
// SCENARIO: Over-slash will not kill account, and report missing slash amount.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 1_000, 0));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 1_000, 0));
|
||||
// Slashed full free_balance minus ED, and reports 400 not slashed
|
||||
assert_eq!(Balances::slash(&1, 1_300), (NegativeImbalance::new(900), 400));
|
||||
// Account is still alive
|
||||
assert!(System::account_exists(&1));
|
||||
|
||||
// SCENARIO: Over-slash can take from reserved, but keep alive.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 1_000, 400));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 1_000, 400));
|
||||
// Slashed full free_balance and 300 of reserved balance
|
||||
assert_eq!(Balances::slash(&1, 1_300), (NegativeImbalance::new(1300), 0));
|
||||
// Account is still alive
|
||||
assert!(System::account_exists(&1));
|
||||
|
||||
// SCENARIO: Over-slash can take from reserved, but keep alive.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 1_000, 350));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 1_000, 350));
|
||||
// Slashed full free_balance and 250 of reserved balance to leave ED
|
||||
assert_eq!(Balances::slash(&1, 1_300), (NegativeImbalance::new(1250), 50));
|
||||
// Account is still alive
|
||||
assert!(System::account_exists(&1));
|
||||
|
||||
// SCENARIO: Over-slash can take as much as possible from reserved and report missing amount.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 1_000, 250));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 1_000, 250));
|
||||
// Slashed full free_balance and 300 of reserved balance
|
||||
assert_eq!(Balances::slash(&1, 1_300), (NegativeImbalance::new(1150), 150));
|
||||
// Account is still alive
|
||||
@@ -926,28 +926,28 @@ macro_rules! decl_tests {
|
||||
/* User has no reference counter, so they can die in these scenarios */
|
||||
|
||||
// SCENARIO: Slash would not kill account.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 50, 1_000));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 50, 1_000));
|
||||
// Slashed completed in full
|
||||
assert_eq!(Balances::slash_reserved(&1, 900), (NegativeImbalance::new(900), 0));
|
||||
// Account is still alive
|
||||
assert!(System::account_exists(&1));
|
||||
|
||||
// SCENARIO: Slash would kill account.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 50, 1_000));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 50, 1_000));
|
||||
// Slashed completed in full
|
||||
assert_eq!(Balances::slash_reserved(&1, 1_000), (NegativeImbalance::new(1_000), 0));
|
||||
// Account is dead
|
||||
assert!(!System::account_exists(&1));
|
||||
|
||||
// SCENARIO: Over-slash would kill account, and reports left over slash.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 50, 1_000));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 50, 1_000));
|
||||
// Slashed completed in full
|
||||
assert_eq!(Balances::slash_reserved(&1, 1_300), (NegativeImbalance::new(1_000), 300));
|
||||
// Account is dead
|
||||
assert!(!System::account_exists(&1));
|
||||
|
||||
// SCENARIO: Over-slash does not take from free balance.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 300, 1_000));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 300, 1_000));
|
||||
// Slashed completed in full
|
||||
assert_eq!(Balances::slash_reserved(&1, 1_300), (NegativeImbalance::new(1_000), 300));
|
||||
// Account is alive because of free balance
|
||||
@@ -956,7 +956,7 @@ macro_rules! decl_tests {
|
||||
/* User has a reference counter, so they cannot die */
|
||||
|
||||
// SCENARIO: Slash would not kill account.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 50, 1_000));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 50, 1_000));
|
||||
assert_ok!(System::inc_consumers(&1)); // <-- Reference counter added here is enough for all tests
|
||||
// Slashed completed in full
|
||||
assert_eq!(Balances::slash_reserved(&1, 900), (NegativeImbalance::new(900), 0));
|
||||
@@ -964,21 +964,21 @@ macro_rules! decl_tests {
|
||||
assert!(System::account_exists(&1));
|
||||
|
||||
// SCENARIO: Slash as much as possible without killing.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 50, 1_000));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 50, 1_000));
|
||||
// Slashed as much as possible
|
||||
assert_eq!(Balances::slash_reserved(&1, 1_000), (NegativeImbalance::new(950), 50));
|
||||
// Account is still alive
|
||||
assert!(System::account_exists(&1));
|
||||
|
||||
// SCENARIO: Over-slash reports correctly, where reserved is needed to keep alive.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 50, 1_000));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 50, 1_000));
|
||||
// Slashed as much as possible
|
||||
assert_eq!(Balances::slash_reserved(&1, 1_300), (NegativeImbalance::new(950), 350));
|
||||
// Account is still alive
|
||||
assert!(System::account_exists(&1));
|
||||
|
||||
// SCENARIO: Over-slash reports correctly, where full reserved is removed.
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 200, 1_000));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 200, 1_000));
|
||||
// Slashed as much as possible
|
||||
assert_eq!(Balances::slash_reserved(&1, 1_300), (NegativeImbalance::new(1_000), 300));
|
||||
// Account is still alive
|
||||
@@ -1018,7 +1018,7 @@ macro_rules! decl_tests {
|
||||
.existential_deposit(100)
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 100, 100));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 100, 100));
|
||||
assert_ok!(Balances::transfer_keep_alive(Some(1).into(), 2, 100));
|
||||
assert_eq!(Balances::total_balance(&1), 100);
|
||||
assert_eq!(Balances::total_balance(&2), 100);
|
||||
@@ -1032,32 +1032,32 @@ macro_rules! decl_tests {
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
// setup
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 200, 0));
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 2, 0, 0));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 200, 0));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 2, 0, 0));
|
||||
// transfer all and allow death
|
||||
assert_ok!(Balances::transfer_all(Some(1).into(), 2, false));
|
||||
assert_eq!(Balances::total_balance(&1), 0);
|
||||
assert_eq!(Balances::total_balance(&2), 200);
|
||||
|
||||
// setup
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 200, 0));
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 2, 0, 0));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 200, 0));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 2, 0, 0));
|
||||
// transfer all and keep alive
|
||||
assert_ok!(Balances::transfer_all(Some(1).into(), 2, true));
|
||||
assert_eq!(Balances::total_balance(&1), 100);
|
||||
assert_eq!(Balances::total_balance(&2), 100);
|
||||
|
||||
// setup
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 200, 10));
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 2, 0, 0));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 200, 10));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 2, 0, 0));
|
||||
// transfer all and allow death w/ reserved
|
||||
assert_ok!(Balances::transfer_all(Some(1).into(), 2, false));
|
||||
assert_eq!(Balances::total_balance(&1), 0);
|
||||
assert_eq!(Balances::total_balance(&2), 200);
|
||||
|
||||
// setup
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1, 200, 10));
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 2, 0, 0));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 200, 10));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 2, 0, 0));
|
||||
// transfer all and keep alive w/ reserved
|
||||
assert_ok!(Balances::transfer_all(Some(1).into(), 2, true));
|
||||
assert_eq!(Balances::total_balance(&1), 100);
|
||||
@@ -1281,7 +1281,7 @@ macro_rules! decl_tests {
|
||||
let _ = Balances::deposit_creating(&1, 111);
|
||||
assert_ok!(frame_system::Pallet::<Test>::inc_consumers(&1));
|
||||
assert_noop!(
|
||||
Balances::set_balance(Origin::root(), 1, 0, 0),
|
||||
Balances::set_balance(RuntimeOrigin::root(), 1, 0, 0),
|
||||
DispatchError::ConsumerRemaining,
|
||||
);
|
||||
});
|
||||
@@ -1291,7 +1291,7 @@ macro_rules! decl_tests {
|
||||
fn set_balance_handles_total_issuance() {
|
||||
<$ext_builder>::default().build().execute_with(|| {
|
||||
let old_total_issuance = Balances::total_issuance();
|
||||
assert_ok!(Balances::set_balance(Origin::root(), 1337, 69, 42));
|
||||
assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1337, 69, 42));
|
||||
assert_eq!(Balances::total_issuance(), old_total_issuance + 69 + 42);
|
||||
assert_eq!(Balances::total_balance(&1337), 69 + 42);
|
||||
assert_eq!(Balances::free_balance(&1337), 69);
|
||||
|
||||
@@ -55,7 +55,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = BlockWeights;
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
|
||||
@@ -56,7 +56,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = BlockWeights;
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
|
||||
@@ -59,7 +59,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = BlockWeights;
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
|
||||
@@ -67,7 +67,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
|
||||
@@ -62,7 +62,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
|
||||
@@ -176,7 +176,7 @@ pub mod mock {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = AccountIndex;
|
||||
type BlockNumber = BlockNumber;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
|
||||
@@ -112,14 +112,14 @@ macro_rules! whitelist {
|
||||
/// foo {
|
||||
/// let caller = account::<T>(b"caller", 0, benchmarks_seed);
|
||||
/// let l in 1 .. MAX_LENGTH => initialize_l(l);
|
||||
/// }: _(Origin::Signed(caller), vec![0u8; l])
|
||||
/// }: _(RuntimeOrigin::Signed(caller), vec![0u8; l])
|
||||
///
|
||||
/// // second dispatchable: bar; this is a root dispatchable and accepts a `u8` vector of size
|
||||
/// // `l`.
|
||||
/// // In this case, we explicitly name the call using `bar` instead of `_`.
|
||||
/// bar {
|
||||
/// let l in 1 .. MAX_LENGTH => initialize_l(l);
|
||||
/// }: bar(Origin::Root, vec![0u8; l])
|
||||
/// }: bar(RuntimeOrigin::Root, vec![0u8; l])
|
||||
///
|
||||
/// // third dispatchable: baz; this is a user dispatchable. It isn't dependent on length like the
|
||||
/// // other two but has its own complexity `c` that needs setting up. It uses `caller` (in the
|
||||
@@ -128,20 +128,20 @@ macro_rules! whitelist {
|
||||
/// baz1 {
|
||||
/// let caller = account::<T>(b"caller", 0, benchmarks_seed);
|
||||
/// let c = 0 .. 10 => setup_c(&caller, c);
|
||||
/// }: baz(Origin::Signed(caller))
|
||||
/// }: baz(RuntimeOrigin::Signed(caller))
|
||||
///
|
||||
/// // this is a second benchmark of the baz dispatchable with a different setup.
|
||||
/// baz2 {
|
||||
/// let caller = account::<T>(b"caller", 0, benchmarks_seed);
|
||||
/// let c = 0 .. 10 => setup_c_in_some_other_way(&caller, c);
|
||||
/// }: baz(Origin::Signed(caller))
|
||||
/// }: baz(RuntimeOrigin::Signed(caller))
|
||||
///
|
||||
/// // You may optionally specify the origin type if it can't be determined automatically like
|
||||
/// // this.
|
||||
/// baz3 {
|
||||
/// let caller = account::<T>(b"caller", 0, benchmarks_seed);
|
||||
/// let l in 1 .. MAX_LENGTH => initialize_l(l);
|
||||
/// }: baz<T::Origin>(Origin::Signed(caller), vec![0u8; l])
|
||||
/// }: baz<T::RuntimeOrigin>(RuntimeOrigin::Signed(caller), vec![0u8; l])
|
||||
///
|
||||
/// // this is benchmarking some code that is not a dispatchable.
|
||||
/// populate_a_set {
|
||||
@@ -617,7 +617,7 @@ macro_rules! to_origin {
|
||||
$origin.into()
|
||||
};
|
||||
($origin:expr, $origin_type:ty) => {
|
||||
<<T as frame_system::Config>::Origin as From<$origin_type>>::from($origin)
|
||||
<<T as frame_system::Config>::RuntimeOrigin as From<$origin_type>>::from($origin)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
@@ -148,7 +148,7 @@ mod benchmarks {
|
||||
crate::benchmarks! {
|
||||
where_clause {
|
||||
where
|
||||
crate::tests::Origin: From<RawOrigin<<T as frame_system::Config>::AccountId>>,
|
||||
crate::tests::RuntimeOrigin: From<RawOrigin<<T as frame_system::Config>::AccountId>>,
|
||||
}
|
||||
|
||||
set_value {
|
||||
|
||||
@@ -41,7 +41,7 @@ mod pallet_test {
|
||||
|
||||
frame_support::decl_module! {
|
||||
pub struct Module<T: Config<I>, I: Instance = DefaultInstance> for enum Call where
|
||||
origin: T::Origin, <T as OtherConfig>::OtherEvent: Into<<T as Config<I>>::RuntimeEvent>
|
||||
origin: T::RuntimeOrigin, <T as OtherConfig>::OtherEvent: Into<<T as Config<I>>::RuntimeEvent>
|
||||
{
|
||||
#[weight = 0]
|
||||
fn set_value(origin, n: u32) -> frame_support::dispatch::DispatchResult {
|
||||
@@ -91,7 +91,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
|
||||
@@ -98,7 +98,7 @@ benchmarks_instance_pallet! {
|
||||
Bounties::<T, I>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
|
||||
let bounty_id = BountyCount::<T, I>::get() - 1;
|
||||
let approve_origin = T::ApproveOrigin::successful_origin();
|
||||
}: _<T::Origin>(approve_origin, bounty_id)
|
||||
}: _<T::RuntimeOrigin>(approve_origin, bounty_id)
|
||||
|
||||
propose_curator {
|
||||
setup_pot_account::<T, I>();
|
||||
@@ -110,7 +110,7 @@ benchmarks_instance_pallet! {
|
||||
Bounties::<T, I>::approve_bounty(approve_origin, bounty_id)?;
|
||||
Treasury::<T, I>::on_initialize(T::BlockNumber::zero());
|
||||
let approve_origin = T::ApproveOrigin::successful_origin();
|
||||
}: _<T::Origin>(approve_origin, bounty_id, curator_lookup, fee)
|
||||
}: _<T::RuntimeOrigin>(approve_origin, bounty_id, curator_lookup, fee)
|
||||
|
||||
// Worst case when curator is inactive and any sender unassigns the curator.
|
||||
unassign_curator {
|
||||
@@ -171,7 +171,7 @@ benchmarks_instance_pallet! {
|
||||
Bounties::<T, I>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
|
||||
let bounty_id = BountyCount::<T, I>::get() - 1;
|
||||
let approve_origin = T::ApproveOrigin::successful_origin();
|
||||
}: close_bounty<T::Origin>(approve_origin, bounty_id)
|
||||
}: close_bounty<T::RuntimeOrigin>(approve_origin, bounty_id)
|
||||
|
||||
close_bounty_active {
|
||||
setup_pot_account::<T, I>();
|
||||
@@ -179,7 +179,7 @@ benchmarks_instance_pallet! {
|
||||
Treasury::<T, I>::on_initialize(T::BlockNumber::zero());
|
||||
let bounty_id = BountyCount::<T, I>::get() - 1;
|
||||
let approve_origin = T::ApproveOrigin::successful_origin();
|
||||
}: close_bounty<T::Origin>(approve_origin, bounty_id)
|
||||
}: close_bounty<T::RuntimeOrigin>(approve_origin, bounty_id)
|
||||
verify {
|
||||
assert_last_event::<T, I>(Event::BountyCanceled { index: bounty_id }.into())
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
@@ -229,7 +229,7 @@ fn minting_works() {
|
||||
#[test]
|
||||
fn spend_proposal_takes_min_deposit() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 1, 3));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 1, 3));
|
||||
assert_eq!(Balances::free_balance(0), 99);
|
||||
assert_eq!(Balances::reserved_balance(0), 1);
|
||||
});
|
||||
@@ -238,7 +238,7 @@ fn spend_proposal_takes_min_deposit() {
|
||||
#[test]
|
||||
fn spend_proposal_takes_proportional_deposit() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 100, 3));
|
||||
assert_eq!(Balances::free_balance(0), 95);
|
||||
assert_eq!(Balances::reserved_balance(0), 5);
|
||||
});
|
||||
@@ -248,7 +248,7 @@ fn spend_proposal_takes_proportional_deposit() {
|
||||
fn spend_proposal_fails_when_proposer_poor() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
Treasury::propose_spend(Origin::signed(2), 100, 3),
|
||||
Treasury::propose_spend(RuntimeOrigin::signed(2), 100, 3),
|
||||
TreasuryError::InsufficientProposersBalance,
|
||||
);
|
||||
});
|
||||
@@ -259,8 +259,8 @@ fn accepted_spend_proposal_ignored_outside_spend_period() {
|
||||
new_test_ext().execute_with(|| {
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::approve_proposal(Origin::root(), 0));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::approve_proposal(RuntimeOrigin::root(), 0));
|
||||
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(1);
|
||||
assert_eq!(Balances::free_balance(3), 0);
|
||||
@@ -286,8 +286,8 @@ fn rejected_spend_proposal_ignored_on_spend_period() {
|
||||
new_test_ext().execute_with(|| {
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::reject_proposal(Origin::root(), 0));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::reject_proposal(RuntimeOrigin::root(), 0));
|
||||
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
assert_eq!(Balances::free_balance(3), 0);
|
||||
@@ -300,9 +300,12 @@ fn reject_already_rejected_spend_proposal_fails() {
|
||||
new_test_ext().execute_with(|| {
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::reject_proposal(Origin::root(), 0));
|
||||
assert_noop!(Treasury::reject_proposal(Origin::root(), 0), TreasuryError::InvalidIndex);
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::reject_proposal(RuntimeOrigin::root(), 0));
|
||||
assert_noop!(
|
||||
Treasury::reject_proposal(RuntimeOrigin::root(), 0),
|
||||
TreasuryError::InvalidIndex
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -310,7 +313,7 @@ fn reject_already_rejected_spend_proposal_fails() {
|
||||
fn reject_non_existent_spend_proposal_fails() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
Treasury::reject_proposal(Origin::root(), 0),
|
||||
Treasury::reject_proposal(RuntimeOrigin::root(), 0),
|
||||
pallet_treasury::Error::<Test>::InvalidIndex
|
||||
);
|
||||
});
|
||||
@@ -319,7 +322,10 @@ fn reject_non_existent_spend_proposal_fails() {
|
||||
#[test]
|
||||
fn accept_non_existent_spend_proposal_fails() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(Treasury::approve_proposal(Origin::root(), 0), TreasuryError::InvalidIndex);
|
||||
assert_noop!(
|
||||
Treasury::approve_proposal(RuntimeOrigin::root(), 0),
|
||||
TreasuryError::InvalidIndex
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -328,9 +334,12 @@ fn accept_already_rejected_spend_proposal_fails() {
|
||||
new_test_ext().execute_with(|| {
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::reject_proposal(Origin::root(), 0));
|
||||
assert_noop!(Treasury::approve_proposal(Origin::root(), 0), TreasuryError::InvalidIndex);
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::reject_proposal(RuntimeOrigin::root(), 0));
|
||||
assert_noop!(
|
||||
Treasury::approve_proposal(RuntimeOrigin::root(), 0),
|
||||
TreasuryError::InvalidIndex
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -340,8 +349,8 @@ fn accepted_spend_proposal_enacted_on_spend_period() {
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
assert_eq!(Treasury::pot(), 100);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::approve_proposal(Origin::root(), 0));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::approve_proposal(RuntimeOrigin::root(), 0));
|
||||
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
assert_eq!(Balances::free_balance(3), 100);
|
||||
@@ -355,8 +364,8 @@ fn pot_underflow_should_not_diminish() {
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
assert_eq!(Treasury::pot(), 100);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 150, 3));
|
||||
assert_ok!(Treasury::approve_proposal(Origin::root(), 0));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 150, 3));
|
||||
assert_ok!(Treasury::approve_proposal(RuntimeOrigin::root(), 0));
|
||||
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
assert_eq!(Treasury::pot(), 100); // Pot hasn't changed
|
||||
@@ -377,14 +386,14 @@ fn treasury_account_doesnt_get_deleted() {
|
||||
assert_eq!(Treasury::pot(), 100);
|
||||
let treasury_balance = Balances::free_balance(&Treasury::account_id());
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), treasury_balance, 3));
|
||||
assert_ok!(Treasury::approve_proposal(Origin::root(), 0));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), treasury_balance, 3));
|
||||
assert_ok!(Treasury::approve_proposal(RuntimeOrigin::root(), 0));
|
||||
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
assert_eq!(Treasury::pot(), 100); // Pot hasn't changed
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), Treasury::pot(), 3));
|
||||
assert_ok!(Treasury::approve_proposal(Origin::root(), 1));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), Treasury::pot(), 3));
|
||||
assert_ok!(Treasury::approve_proposal(RuntimeOrigin::root(), 1));
|
||||
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(4);
|
||||
assert_eq!(Treasury::pot(), 0); // Pot is emptied
|
||||
@@ -407,10 +416,10 @@ fn inexistent_account_works() {
|
||||
assert_eq!(Balances::free_balance(Treasury::account_id()), 0); // Account does not exist
|
||||
assert_eq!(Treasury::pot(), 0); // Pot is empty
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 99, 3));
|
||||
assert_ok!(Treasury::approve_proposal(Origin::root(), 0));
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 1, 3));
|
||||
assert_ok!(Treasury::approve_proposal(Origin::root(), 1));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 99, 3));
|
||||
assert_ok!(Treasury::approve_proposal(RuntimeOrigin::root(), 0));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 1, 3));
|
||||
assert_ok!(Treasury::approve_proposal(RuntimeOrigin::root(), 1));
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
assert_eq!(Treasury::pot(), 0); // Pot hasn't changed
|
||||
assert_eq!(Balances::free_balance(3), 0); // Balance of `3` hasn't changed
|
||||
@@ -434,7 +443,7 @@ fn propose_bounty_works() {
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
assert_eq!(Treasury::pot(), 100);
|
||||
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 10, b"1234567890".to_vec()));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 10, b"1234567890".to_vec()));
|
||||
|
||||
assert_eq!(last_event(), BountiesEvent::BountyProposed { index: 0 });
|
||||
|
||||
@@ -469,17 +478,21 @@ fn propose_bounty_validation_works() {
|
||||
assert_eq!(Treasury::pot(), 100);
|
||||
|
||||
assert_noop!(
|
||||
Bounties::propose_bounty(Origin::signed(1), 0, [0; 17_000].to_vec()),
|
||||
Bounties::propose_bounty(RuntimeOrigin::signed(1), 0, [0; 17_000].to_vec()),
|
||||
Error::<Test>::ReasonTooBig
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
Bounties::propose_bounty(Origin::signed(1), 10, b"12345678901234567890".to_vec()),
|
||||
Bounties::propose_bounty(
|
||||
RuntimeOrigin::signed(1),
|
||||
10,
|
||||
b"12345678901234567890".to_vec()
|
||||
),
|
||||
Error::<Test>::InsufficientProposersBalance
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
Bounties::propose_bounty(Origin::signed(1), 0, b"12345678901234567890".to_vec()),
|
||||
Bounties::propose_bounty(RuntimeOrigin::signed(1), 0, b"12345678901234567890".to_vec()),
|
||||
Error::<Test>::InvalidValue
|
||||
);
|
||||
});
|
||||
@@ -490,11 +503,11 @@ fn close_bounty_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
assert_noop!(Bounties::close_bounty(Origin::root(), 0), Error::<Test>::InvalidIndex);
|
||||
assert_noop!(Bounties::close_bounty(RuntimeOrigin::root(), 0), Error::<Test>::InvalidIndex);
|
||||
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 10, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 10, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Bounties::close_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::close_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
let deposit: u64 = 80 + 5;
|
||||
|
||||
@@ -515,11 +528,14 @@ fn approve_bounty_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
assert_noop!(Bounties::approve_bounty(Origin::root(), 0), Error::<Test>::InvalidIndex);
|
||||
assert_noop!(
|
||||
Bounties::approve_bounty(RuntimeOrigin::root(), 0),
|
||||
Error::<Test>::InvalidIndex
|
||||
);
|
||||
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
let deposit: u64 = 80 + 5;
|
||||
|
||||
@@ -536,7 +552,10 @@ fn approve_bounty_works() {
|
||||
);
|
||||
assert_eq!(Bounties::bounty_approvals(), vec![0]);
|
||||
|
||||
assert_noop!(Bounties::close_bounty(Origin::root(), 0), Error::<Test>::UnexpectedStatus);
|
||||
assert_noop!(
|
||||
Bounties::close_bounty(RuntimeOrigin::root(), 0),
|
||||
Error::<Test>::UnexpectedStatus
|
||||
);
|
||||
|
||||
// deposit not returned yet
|
||||
assert_eq!(Balances::reserved_balance(0), deposit);
|
||||
@@ -572,24 +591,24 @@ fn assign_curator_works() {
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
|
||||
assert_noop!(
|
||||
Bounties::propose_curator(Origin::root(), 0, 4, 4),
|
||||
Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 4),
|
||||
Error::<Test>::InvalidIndex
|
||||
);
|
||||
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_noop!(
|
||||
Bounties::propose_curator(Origin::root(), 0, 4, 50),
|
||||
Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 50),
|
||||
Error::<Test>::InvalidFee
|
||||
);
|
||||
|
||||
let fee = 4;
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 4, fee));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, fee));
|
||||
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
@@ -603,15 +622,18 @@ fn assign_curator_works() {
|
||||
}
|
||||
);
|
||||
|
||||
assert_noop!(Bounties::accept_curator(Origin::signed(1), 0), Error::<Test>::RequireCurator);
|
||||
assert_noop!(
|
||||
Bounties::accept_curator(Origin::signed(4), 0),
|
||||
Bounties::accept_curator(RuntimeOrigin::signed(1), 0),
|
||||
Error::<Test>::RequireCurator
|
||||
);
|
||||
assert_noop!(
|
||||
Bounties::accept_curator(RuntimeOrigin::signed(4), 0),
|
||||
pallet_balances::Error::<Test, _>::InsufficientBalance
|
||||
);
|
||||
|
||||
Balances::make_free_balance_be(&4, 10);
|
||||
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(4), 0));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0));
|
||||
|
||||
let expected_deposit = Bounties::calculate_curator_deposit(&fee);
|
||||
|
||||
@@ -637,18 +659,18 @@ fn unassign_curator_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
let fee = 4;
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 4, fee));
|
||||
assert_noop!(Bounties::unassign_curator(Origin::signed(1), 0), BadOrigin);
|
||||
assert_ok!(Bounties::unassign_curator(Origin::signed(4), 0));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, fee));
|
||||
assert_noop!(Bounties::unassign_curator(RuntimeOrigin::signed(1), 0), BadOrigin);
|
||||
assert_ok!(Bounties::unassign_curator(RuntimeOrigin::signed(4), 0));
|
||||
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
@@ -662,11 +684,11 @@ fn unassign_curator_works() {
|
||||
}
|
||||
);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 4, fee));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, fee));
|
||||
Balances::make_free_balance_be(&4, 10);
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(4), 0));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0));
|
||||
let expected_deposit = Bounties::calculate_curator_deposit(&fee);
|
||||
assert_ok!(Bounties::unassign_curator(Origin::root(), 0));
|
||||
assert_ok!(Bounties::unassign_curator(RuntimeOrigin::root(), 0));
|
||||
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
@@ -691,26 +713,26 @@ fn award_and_claim_bounty_works() {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
Balances::make_free_balance_be(&4, 10);
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
let fee = 4;
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 4, fee));
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(4), 0));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, fee));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0));
|
||||
|
||||
let expected_deposit = Bounties::calculate_curator_deposit(&fee);
|
||||
assert_eq!(Balances::free_balance(4), 10 - expected_deposit);
|
||||
|
||||
assert_noop!(
|
||||
Bounties::award_bounty(Origin::signed(1), 0, 3),
|
||||
Bounties::award_bounty(RuntimeOrigin::signed(1), 0, 3),
|
||||
Error::<Test>::RequireCurator
|
||||
);
|
||||
|
||||
assert_ok!(Bounties::award_bounty(Origin::signed(4), 0, 3));
|
||||
assert_ok!(Bounties::award_bounty(RuntimeOrigin::signed(4), 0, 3));
|
||||
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
@@ -724,14 +746,18 @@ fn award_and_claim_bounty_works() {
|
||||
}
|
||||
);
|
||||
|
||||
assert_noop!(Bounties::claim_bounty(Origin::signed(1), 0), Error::<Test>::Premature);
|
||||
assert_noop!(Bounties::claim_bounty(RuntimeOrigin::signed(1), 0), Error::<Test>::Premature);
|
||||
|
||||
System::set_block_number(5);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(5);
|
||||
|
||||
assert_ok!(Balances::transfer(Origin::signed(0), Bounties::bounty_account_id(0), 10));
|
||||
assert_ok!(Balances::transfer(
|
||||
RuntimeOrigin::signed(0),
|
||||
Bounties::bounty_account_id(0),
|
||||
10
|
||||
));
|
||||
|
||||
assert_ok!(Bounties::claim_bounty(Origin::signed(1), 0));
|
||||
assert_ok!(Bounties::claim_bounty(RuntimeOrigin::signed(1), 0));
|
||||
|
||||
assert_eq!(
|
||||
last_event(),
|
||||
@@ -754,17 +780,17 @@ fn claim_handles_high_fee() {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
Balances::make_free_balance_be(&4, 30);
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 4, 49));
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(4), 0));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 49));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0));
|
||||
|
||||
assert_ok!(Bounties::award_bounty(Origin::signed(4), 0, 3));
|
||||
assert_ok!(Bounties::award_bounty(RuntimeOrigin::signed(4), 0, 3));
|
||||
|
||||
System::set_block_number(5);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(5);
|
||||
@@ -773,7 +799,7 @@ fn claim_handles_high_fee() {
|
||||
let res = Balances::slash(&Bounties::bounty_account_id(0), 10);
|
||||
assert_eq!(res.0.peek(), 10);
|
||||
|
||||
assert_ok!(Bounties::claim_bounty(Origin::signed(1), 0));
|
||||
assert_ok!(Bounties::claim_bounty(RuntimeOrigin::signed(1), 0));
|
||||
|
||||
assert_eq!(
|
||||
last_event(),
|
||||
@@ -796,14 +822,18 @@ fn cancel_and_refund() {
|
||||
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Balances::transfer(Origin::signed(0), Bounties::bounty_account_id(0), 10));
|
||||
assert_ok!(Balances::transfer(
|
||||
RuntimeOrigin::signed(0),
|
||||
Bounties::bounty_account_id(0),
|
||||
10
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
@@ -819,9 +849,9 @@ fn cancel_and_refund() {
|
||||
|
||||
assert_eq!(Balances::free_balance(Bounties::bounty_account_id(0)), 60);
|
||||
|
||||
assert_noop!(Bounties::close_bounty(Origin::signed(0), 0), BadOrigin);
|
||||
assert_noop!(Bounties::close_bounty(RuntimeOrigin::signed(0), 0), BadOrigin);
|
||||
|
||||
assert_ok!(Bounties::close_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::close_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
// `- 25 + 10`
|
||||
assert_eq!(Treasury::pot(), 85);
|
||||
@@ -833,27 +863,30 @@ fn award_and_cancel() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 0, 10));
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(0), 0));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 0, 10));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(0), 0));
|
||||
|
||||
assert_eq!(Balances::free_balance(0), 95);
|
||||
assert_eq!(Balances::reserved_balance(0), 5);
|
||||
|
||||
assert_ok!(Bounties::award_bounty(Origin::signed(0), 0, 3));
|
||||
assert_ok!(Bounties::award_bounty(RuntimeOrigin::signed(0), 0, 3));
|
||||
|
||||
// Cannot close bounty directly when payout is happening...
|
||||
assert_noop!(Bounties::close_bounty(Origin::root(), 0), Error::<Test>::PendingPayout);
|
||||
assert_noop!(
|
||||
Bounties::close_bounty(RuntimeOrigin::root(), 0),
|
||||
Error::<Test>::PendingPayout
|
||||
);
|
||||
|
||||
// Instead unassign the curator to slash them and then close.
|
||||
assert_ok!(Bounties::unassign_curator(Origin::root(), 0));
|
||||
assert_ok!(Bounties::close_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::unassign_curator(RuntimeOrigin::root(), 0));
|
||||
assert_ok!(Bounties::close_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
assert_eq!(last_event(), BountiesEvent::BountyCanceled { index: 0 });
|
||||
|
||||
@@ -873,15 +906,15 @@ fn expire_and_unassign() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 1, 10));
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(1), 0));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 1, 10));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(1), 0));
|
||||
|
||||
assert_eq!(Balances::free_balance(1), 93);
|
||||
assert_eq!(Balances::reserved_balance(1), 5);
|
||||
@@ -889,12 +922,15 @@ fn expire_and_unassign() {
|
||||
System::set_block_number(22);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(22);
|
||||
|
||||
assert_noop!(Bounties::unassign_curator(Origin::signed(0), 0), Error::<Test>::Premature);
|
||||
assert_noop!(
|
||||
Bounties::unassign_curator(RuntimeOrigin::signed(0), 0),
|
||||
Error::<Test>::Premature
|
||||
);
|
||||
|
||||
System::set_block_number(23);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(23);
|
||||
|
||||
assert_ok!(Bounties::unassign_curator(Origin::signed(0), 0));
|
||||
assert_ok!(Bounties::unassign_curator(RuntimeOrigin::signed(0), 0));
|
||||
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
@@ -919,20 +955,20 @@ fn extend_expiry() {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
Balances::make_free_balance_be(&4, 10);
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
assert_noop!(
|
||||
Bounties::extend_bounty_expiry(Origin::signed(1), 0, Vec::new()),
|
||||
Bounties::extend_bounty_expiry(RuntimeOrigin::signed(1), 0, Vec::new()),
|
||||
Error::<Test>::UnexpectedStatus
|
||||
);
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 4, 10));
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(4), 0));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 10));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0));
|
||||
|
||||
assert_eq!(Balances::free_balance(4), 5);
|
||||
assert_eq!(Balances::reserved_balance(4), 5);
|
||||
@@ -941,10 +977,10 @@ fn extend_expiry() {
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(10);
|
||||
|
||||
assert_noop!(
|
||||
Bounties::extend_bounty_expiry(Origin::signed(0), 0, Vec::new()),
|
||||
Bounties::extend_bounty_expiry(RuntimeOrigin::signed(0), 0, Vec::new()),
|
||||
Error::<Test>::RequireCurator
|
||||
);
|
||||
assert_ok!(Bounties::extend_bounty_expiry(Origin::signed(4), 0, Vec::new()));
|
||||
assert_ok!(Bounties::extend_bounty_expiry(RuntimeOrigin::signed(4), 0, Vec::new()));
|
||||
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
@@ -958,7 +994,7 @@ fn extend_expiry() {
|
||||
}
|
||||
);
|
||||
|
||||
assert_ok!(Bounties::extend_bounty_expiry(Origin::signed(4), 0, Vec::new()));
|
||||
assert_ok!(Bounties::extend_bounty_expiry(RuntimeOrigin::signed(4), 0, Vec::new()));
|
||||
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
@@ -975,8 +1011,11 @@ fn extend_expiry() {
|
||||
System::set_block_number(25);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(25);
|
||||
|
||||
assert_noop!(Bounties::unassign_curator(Origin::signed(0), 0), Error::<Test>::Premature);
|
||||
assert_ok!(Bounties::unassign_curator(Origin::signed(4), 0));
|
||||
assert_noop!(
|
||||
Bounties::unassign_curator(RuntimeOrigin::signed(0), 0),
|
||||
Error::<Test>::Premature
|
||||
);
|
||||
assert_ok!(Bounties::unassign_curator(RuntimeOrigin::signed(4), 0));
|
||||
|
||||
assert_eq!(Balances::free_balance(4), 10); // not slashed
|
||||
assert_eq!(Balances::reserved_balance(4), 0);
|
||||
@@ -1049,14 +1088,14 @@ fn unassign_curator_self() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 1, 10));
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(1), 0));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 1, 10));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(1), 0));
|
||||
|
||||
assert_eq!(Balances::free_balance(1), 93);
|
||||
assert_eq!(Balances::reserved_balance(1), 5);
|
||||
@@ -1064,7 +1103,7 @@ fn unassign_curator_self() {
|
||||
System::set_block_number(8);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(8);
|
||||
|
||||
assert_ok!(Bounties::unassign_curator(Origin::signed(1), 0));
|
||||
assert_ok!(Bounties::unassign_curator(RuntimeOrigin::signed(1), 0));
|
||||
|
||||
assert_eq!(
|
||||
Bounties::bounties(0).unwrap(),
|
||||
@@ -1097,14 +1136,14 @@ fn accept_curator_handles_different_deposit_calculations() {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
Balances::make_free_balance_be(&user, 100);
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), value, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), bounty_index));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), value, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), bounty_index));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), bounty_index, user, fee));
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(user), bounty_index));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), bounty_index, user, fee));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(user), bounty_index));
|
||||
|
||||
let expected_deposit = CuratorDepositMultiplier::get() * fee;
|
||||
assert_eq!(Balances::free_balance(&user), 100 - expected_deposit);
|
||||
@@ -1119,14 +1158,14 @@ fn accept_curator_handles_different_deposit_calculations() {
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
Balances::make_free_balance_be(&user, 100);
|
||||
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), value, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), bounty_index));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), value, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), bounty_index));
|
||||
|
||||
System::set_block_number(4);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(4);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), bounty_index, user, fee));
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(user), bounty_index));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), bounty_index, user, fee));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(user), bounty_index));
|
||||
|
||||
let expected_deposit = CuratorDepositMin::get();
|
||||
assert_eq!(Balances::free_balance(&user), 100 - expected_deposit);
|
||||
@@ -1143,14 +1182,14 @@ fn accept_curator_handles_different_deposit_calculations() {
|
||||
Balances::make_free_balance_be(&user, starting_balance);
|
||||
Balances::make_free_balance_be(&0, starting_balance);
|
||||
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), value, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), bounty_index));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), value, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), bounty_index));
|
||||
|
||||
System::set_block_number(6);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(6);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), bounty_index, user, fee));
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(user), bounty_index));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), bounty_index, user, fee));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(user), bounty_index));
|
||||
|
||||
let expected_deposit = CuratorDepositMax::get();
|
||||
assert_eq!(Balances::free_balance(&user), starting_balance - expected_deposit);
|
||||
@@ -1170,8 +1209,8 @@ fn approve_bounty_works_second_instance() {
|
||||
assert_eq!(Balances::free_balance(&Treasury::account_id()), 101);
|
||||
assert_eq!(Balances::free_balance(&Treasury1::account_id()), 201);
|
||||
|
||||
assert_ok!(Bounties1::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties1::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties1::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties1::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
<Treasury1 as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
@@ -211,19 +211,19 @@ fn add_child_bounty() {
|
||||
System::set_block_number(1);
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
let fee = 8;
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 4, fee));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, fee));
|
||||
|
||||
Balances::make_free_balance_be(&4, 10);
|
||||
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(4), 0));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0));
|
||||
|
||||
// This verifies that the accept curator logic took a deposit.
|
||||
let expected_deposit = CuratorDepositMultiplier::get() * fee;
|
||||
@@ -234,7 +234,7 @@ fn add_child_bounty() {
|
||||
// Acc-4 is the parent curator.
|
||||
// Call from invalid origin & check for error "RequireCurator".
|
||||
assert_noop!(
|
||||
ChildBounties::add_child_bounty(Origin::signed(0), 0, 10, b"12345-p1".to_vec()),
|
||||
ChildBounties::add_child_bounty(RuntimeOrigin::signed(0), 0, 10, b"12345-p1".to_vec()),
|
||||
BountiesError::RequireCurator,
|
||||
);
|
||||
|
||||
@@ -246,17 +246,22 @@ fn add_child_bounty() {
|
||||
assert_eq!(Balances::reserved_balance(Bounties::bounty_account_id(0)), 0);
|
||||
|
||||
assert_noop!(
|
||||
ChildBounties::add_child_bounty(Origin::signed(4), 0, 50, b"12345-p1".to_vec()),
|
||||
ChildBounties::add_child_bounty(RuntimeOrigin::signed(4), 0, 50, b"12345-p1".to_vec()),
|
||||
pallet_balances::Error::<Test>::KeepAlive,
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
ChildBounties::add_child_bounty(Origin::signed(4), 0, 100, b"12345-p1".to_vec()),
|
||||
ChildBounties::add_child_bounty(RuntimeOrigin::signed(4), 0, 100, b"12345-p1".to_vec()),
|
||||
Error::<Test>::InsufficientBountyBalance,
|
||||
);
|
||||
|
||||
// Add child-bounty with valid value, which can be funded by parent bounty.
|
||||
assert_ok!(ChildBounties::add_child_bounty(Origin::signed(4), 0, 10, b"12345-p1".to_vec()));
|
||||
assert_ok!(ChildBounties::add_child_bounty(
|
||||
RuntimeOrigin::signed(4),
|
||||
0,
|
||||
10,
|
||||
b"12345-p1".to_vec()
|
||||
));
|
||||
|
||||
// Check for the event child-bounty added.
|
||||
assert_eq!(last_event(), ChildBountiesEvent::Added { index: 0, child_index: 0 });
|
||||
@@ -299,16 +304,16 @@ fn child_bounty_assign_curator() {
|
||||
Balances::make_free_balance_be(&4, 101);
|
||||
Balances::make_free_balance_be(&8, 101);
|
||||
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
let fee = 4;
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 4, fee));
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(4), 0));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, fee));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0));
|
||||
|
||||
// Bounty account status before adding child-bounty.
|
||||
assert_eq!(Balances::free_balance(Bounties::bounty_account_id(0)), 50);
|
||||
@@ -322,7 +327,12 @@ fn child_bounty_assign_curator() {
|
||||
|
||||
// Add child-bounty.
|
||||
// Acc-4 is the parent curator & make sure enough deposit.
|
||||
assert_ok!(ChildBounties::add_child_bounty(Origin::signed(4), 0, 10, b"12345-p1".to_vec()));
|
||||
assert_ok!(ChildBounties::add_child_bounty(
|
||||
RuntimeOrigin::signed(4),
|
||||
0,
|
||||
10,
|
||||
b"12345-p1".to_vec()
|
||||
));
|
||||
|
||||
assert_eq!(last_event(), ChildBountiesEvent::Added { index: 0, child_index: 0 });
|
||||
|
||||
@@ -335,7 +345,7 @@ fn child_bounty_assign_curator() {
|
||||
assert_eq!(Balances::reserved_balance(ChildBounties::child_bounty_account_id(0)), 0);
|
||||
|
||||
let fee = 6u64;
|
||||
assert_ok!(ChildBounties::propose_curator(Origin::signed(4), 0, 0, 8, fee));
|
||||
assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 8, fee));
|
||||
|
||||
assert_eq!(
|
||||
ChildBounties::child_bounties(0, 0).unwrap(),
|
||||
@@ -353,11 +363,11 @@ fn child_bounty_assign_curator() {
|
||||
assert_eq!(Balances::reserved_balance(4), expected_deposit);
|
||||
|
||||
assert_noop!(
|
||||
ChildBounties::accept_curator(Origin::signed(3), 0, 0),
|
||||
ChildBounties::accept_curator(RuntimeOrigin::signed(3), 0, 0),
|
||||
BountiesError::RequireCurator,
|
||||
);
|
||||
|
||||
assert_ok!(ChildBounties::accept_curator(Origin::signed(8), 0, 0));
|
||||
assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(8), 0, 0));
|
||||
|
||||
let expected_child_deposit = CuratorDepositMultiplier::get() * fee;
|
||||
|
||||
@@ -403,34 +413,39 @@ fn award_claim_child_bounty() {
|
||||
Balances::make_free_balance_be(&4, 101); // Parent-bounty curator.
|
||||
Balances::make_free_balance_be(&8, 101); // Child-bounty curator.
|
||||
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 4, 6));
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(4), 0));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 6));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0));
|
||||
|
||||
// Child-bounty.
|
||||
assert_ok!(ChildBounties::add_child_bounty(Origin::signed(4), 0, 10, b"12345-p1".to_vec()));
|
||||
assert_ok!(ChildBounties::add_child_bounty(
|
||||
RuntimeOrigin::signed(4),
|
||||
0,
|
||||
10,
|
||||
b"12345-p1".to_vec()
|
||||
));
|
||||
|
||||
assert_eq!(last_event(), ChildBountiesEvent::Added { index: 0, child_index: 0 });
|
||||
|
||||
// Propose and accept curator for child-bounty.
|
||||
let fee = 8;
|
||||
assert_ok!(ChildBounties::propose_curator(Origin::signed(4), 0, 0, 8, fee));
|
||||
assert_ok!(ChildBounties::accept_curator(Origin::signed(8), 0, 0));
|
||||
assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 8, fee));
|
||||
assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(8), 0, 0));
|
||||
|
||||
// Award child-bounty.
|
||||
// Test for non child-bounty curator.
|
||||
assert_noop!(
|
||||
ChildBounties::award_child_bounty(Origin::signed(3), 0, 0, 7),
|
||||
ChildBounties::award_child_bounty(RuntimeOrigin::signed(3), 0, 0, 7),
|
||||
BountiesError::RequireCurator,
|
||||
);
|
||||
|
||||
assert_ok!(ChildBounties::award_child_bounty(Origin::signed(8), 0, 0, 7));
|
||||
assert_ok!(ChildBounties::award_child_bounty(RuntimeOrigin::signed(8), 0, 0, 7));
|
||||
|
||||
let expected_deposit = CuratorDepositMultiplier::get() * fee;
|
||||
assert_eq!(
|
||||
@@ -451,13 +466,13 @@ fn award_claim_child_bounty() {
|
||||
// Claim child-bounty.
|
||||
// Test for Premature condition.
|
||||
assert_noop!(
|
||||
ChildBounties::claim_child_bounty(Origin::signed(7), 0, 0),
|
||||
ChildBounties::claim_child_bounty(RuntimeOrigin::signed(7), 0, 0),
|
||||
BountiesError::Premature
|
||||
);
|
||||
|
||||
System::set_block_number(9);
|
||||
|
||||
assert_ok!(ChildBounties::claim_child_bounty(Origin::signed(7), 0, 0));
|
||||
assert_ok!(ChildBounties::claim_child_bounty(RuntimeOrigin::signed(7), 0, 0));
|
||||
|
||||
// Ensure child-bounty curator is paid with curator fee & deposit refund.
|
||||
assert_eq!(Balances::free_balance(8), 101 + fee);
|
||||
@@ -489,19 +504,24 @@ fn close_child_bounty_added() {
|
||||
Balances::make_free_balance_be(&4, 101); // Parent-bounty curator.
|
||||
Balances::make_free_balance_be(&8, 101); // Child-bounty curator.
|
||||
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 4, 6));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 6));
|
||||
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(4), 0));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0));
|
||||
|
||||
// Child-bounty.
|
||||
assert_ok!(ChildBounties::add_child_bounty(Origin::signed(4), 0, 10, b"12345-p1".to_vec()));
|
||||
assert_ok!(ChildBounties::add_child_bounty(
|
||||
RuntimeOrigin::signed(4),
|
||||
0,
|
||||
10,
|
||||
b"12345-p1".to_vec()
|
||||
));
|
||||
|
||||
assert_eq!(last_event(), ChildBountiesEvent::Added { index: 0, child_index: 0 });
|
||||
|
||||
@@ -509,11 +529,11 @@ fn close_child_bounty_added() {
|
||||
|
||||
// Close child-bounty.
|
||||
// Wrong origin.
|
||||
assert_noop!(ChildBounties::close_child_bounty(Origin::signed(7), 0, 0), BadOrigin);
|
||||
assert_noop!(ChildBounties::close_child_bounty(Origin::signed(8), 0, 0), BadOrigin);
|
||||
assert_noop!(ChildBounties::close_child_bounty(RuntimeOrigin::signed(7), 0, 0), BadOrigin);
|
||||
assert_noop!(ChildBounties::close_child_bounty(RuntimeOrigin::signed(8), 0, 0), BadOrigin);
|
||||
|
||||
// Correct origin - parent curator.
|
||||
assert_ok!(ChildBounties::close_child_bounty(Origin::signed(4), 0, 0));
|
||||
assert_ok!(ChildBounties::close_child_bounty(RuntimeOrigin::signed(4), 0, 0));
|
||||
|
||||
// Check the child-bounty count.
|
||||
assert_eq!(ChildBounties::parent_child_bounties(0), 0);
|
||||
@@ -541,28 +561,33 @@ fn close_child_bounty_active() {
|
||||
Balances::make_free_balance_be(&4, 101); // Parent-bounty curator.
|
||||
Balances::make_free_balance_be(&8, 101); // Child-bounty curator.
|
||||
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 4, 6));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 6));
|
||||
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(4), 0));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0));
|
||||
|
||||
// Child-bounty.
|
||||
assert_ok!(ChildBounties::add_child_bounty(Origin::signed(4), 0, 10, b"12345-p1".to_vec()));
|
||||
assert_ok!(ChildBounties::add_child_bounty(
|
||||
RuntimeOrigin::signed(4),
|
||||
0,
|
||||
10,
|
||||
b"12345-p1".to_vec()
|
||||
));
|
||||
|
||||
assert_eq!(last_event(), ChildBountiesEvent::Added { index: 0, child_index: 0 });
|
||||
|
||||
// Propose and accept curator for child-bounty.
|
||||
assert_ok!(ChildBounties::propose_curator(Origin::signed(4), 0, 0, 8, 2));
|
||||
assert_ok!(ChildBounties::accept_curator(Origin::signed(8), 0, 0));
|
||||
assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 8, 2));
|
||||
assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(8), 0, 0));
|
||||
|
||||
// Close child-bounty in active state.
|
||||
assert_ok!(ChildBounties::close_child_bounty(Origin::signed(4), 0, 0));
|
||||
assert_ok!(ChildBounties::close_child_bounty(RuntimeOrigin::signed(4), 0, 0));
|
||||
|
||||
// Check the child-bounty count.
|
||||
assert_eq!(ChildBounties::parent_child_bounties(0), 0);
|
||||
@@ -594,33 +619,38 @@ fn close_child_bounty_pending() {
|
||||
Balances::make_free_balance_be(&4, 101); // Parent-bounty curator.
|
||||
Balances::make_free_balance_be(&8, 101); // Child-bounty curator.
|
||||
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
let parent_fee = 6;
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 4, parent_fee));
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(4), 0));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, parent_fee));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0));
|
||||
|
||||
// Child-bounty.
|
||||
assert_ok!(ChildBounties::add_child_bounty(Origin::signed(4), 0, 10, b"12345-p1".to_vec()));
|
||||
assert_ok!(ChildBounties::add_child_bounty(
|
||||
RuntimeOrigin::signed(4),
|
||||
0,
|
||||
10,
|
||||
b"12345-p1".to_vec()
|
||||
));
|
||||
|
||||
assert_eq!(last_event(), ChildBountiesEvent::Added { index: 0, child_index: 0 });
|
||||
|
||||
// Propose and accept curator for child-bounty.
|
||||
let child_fee = 4;
|
||||
assert_ok!(ChildBounties::propose_curator(Origin::signed(4), 0, 0, 8, child_fee));
|
||||
assert_ok!(ChildBounties::accept_curator(Origin::signed(8), 0, 0));
|
||||
assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 8, child_fee));
|
||||
assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(8), 0, 0));
|
||||
let expected_child_deposit = CuratorDepositMin::get();
|
||||
|
||||
assert_ok!(ChildBounties::award_child_bounty(Origin::signed(8), 0, 0, 7));
|
||||
assert_ok!(ChildBounties::award_child_bounty(RuntimeOrigin::signed(8), 0, 0, 7));
|
||||
|
||||
// Close child-bounty in pending_payout state.
|
||||
assert_noop!(
|
||||
ChildBounties::close_child_bounty(Origin::signed(4), 0, 0),
|
||||
ChildBounties::close_child_bounty(RuntimeOrigin::signed(4), 0, 0),
|
||||
BountiesError::PendingPayout
|
||||
);
|
||||
|
||||
@@ -650,25 +680,30 @@ fn child_bounty_added_unassign_curator() {
|
||||
Balances::make_free_balance_be(&4, 101); // Parent-bounty curator.
|
||||
Balances::make_free_balance_be(&8, 101); // Child-bounty curator.
|
||||
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 4, 6));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 6));
|
||||
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(4), 0));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0));
|
||||
|
||||
// Child-bounty.
|
||||
assert_ok!(ChildBounties::add_child_bounty(Origin::signed(4), 0, 10, b"12345-p1".to_vec()));
|
||||
assert_ok!(ChildBounties::add_child_bounty(
|
||||
RuntimeOrigin::signed(4),
|
||||
0,
|
||||
10,
|
||||
b"12345-p1".to_vec()
|
||||
));
|
||||
|
||||
assert_eq!(last_event(), ChildBountiesEvent::Added { index: 0, child_index: 0 });
|
||||
|
||||
// Unassign curator in added state.
|
||||
assert_noop!(
|
||||
ChildBounties::unassign_curator(Origin::signed(4), 0, 0),
|
||||
ChildBounties::unassign_curator(RuntimeOrigin::signed(4), 0, 0),
|
||||
BountiesError::UnexpectedStatus
|
||||
);
|
||||
});
|
||||
@@ -687,24 +722,29 @@ fn child_bounty_curator_proposed_unassign_curator() {
|
||||
Balances::make_free_balance_be(&4, 101); // Parent-bounty curator.
|
||||
Balances::make_free_balance_be(&8, 101); // Child-bounty curator.
|
||||
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 4, 6));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 6));
|
||||
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(4), 0));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0));
|
||||
|
||||
// Child-bounty.
|
||||
assert_ok!(ChildBounties::add_child_bounty(Origin::signed(4), 0, 10, b"12345-p1".to_vec()));
|
||||
assert_ok!(ChildBounties::add_child_bounty(
|
||||
RuntimeOrigin::signed(4),
|
||||
0,
|
||||
10,
|
||||
b"12345-p1".to_vec()
|
||||
));
|
||||
|
||||
assert_eq!(last_event(), ChildBountiesEvent::Added { index: 0, child_index: 0 });
|
||||
|
||||
// Propose curator for child-bounty.
|
||||
assert_ok!(ChildBounties::propose_curator(Origin::signed(4), 0, 0, 8, 2));
|
||||
assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 8, 2));
|
||||
|
||||
assert_eq!(
|
||||
ChildBounties::child_bounties(0, 0).unwrap(),
|
||||
@@ -718,10 +758,10 @@ fn child_bounty_curator_proposed_unassign_curator() {
|
||||
);
|
||||
|
||||
// Random account cannot unassign the curator when in proposed state.
|
||||
assert_noop!(ChildBounties::unassign_curator(Origin::signed(99), 0, 0), BadOrigin);
|
||||
assert_noop!(ChildBounties::unassign_curator(RuntimeOrigin::signed(99), 0, 0), BadOrigin);
|
||||
|
||||
// Unassign curator.
|
||||
assert_ok!(ChildBounties::unassign_curator(Origin::signed(4), 0, 0));
|
||||
assert_ok!(ChildBounties::unassign_curator(RuntimeOrigin::signed(4), 0, 0));
|
||||
|
||||
// Verify updated child-bounty status.
|
||||
assert_eq!(
|
||||
@@ -759,18 +799,23 @@ fn child_bounty_active_unassign_curator() {
|
||||
Balances::make_free_balance_be(&7, 101); // Child-bounty curator 2.
|
||||
Balances::make_free_balance_be(&8, 101); // Child-bounty curator 3.
|
||||
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 4, 6));
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(4), 0));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 6));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0));
|
||||
|
||||
// Create Child-bounty.
|
||||
assert_ok!(ChildBounties::add_child_bounty(Origin::signed(4), 0, 10, b"12345-p1".to_vec()));
|
||||
assert_ok!(ChildBounties::add_child_bounty(
|
||||
RuntimeOrigin::signed(4),
|
||||
0,
|
||||
10,
|
||||
b"12345-p1".to_vec()
|
||||
));
|
||||
assert_eq!(last_event(), ChildBountiesEvent::Added { index: 0, child_index: 0 });
|
||||
|
||||
System::set_block_number(3);
|
||||
@@ -778,8 +823,8 @@ fn child_bounty_active_unassign_curator() {
|
||||
|
||||
// Propose and accept curator for child-bounty.
|
||||
let fee = 6;
|
||||
assert_ok!(ChildBounties::propose_curator(Origin::signed(4), 0, 0, 8, fee));
|
||||
assert_ok!(ChildBounties::accept_curator(Origin::signed(8), 0, 0));
|
||||
assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 8, fee));
|
||||
assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(8), 0, 0));
|
||||
let expected_child_deposit = CuratorDepositMultiplier::get() * fee;
|
||||
|
||||
assert_eq!(
|
||||
@@ -797,7 +842,7 @@ fn child_bounty_active_unassign_curator() {
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(4);
|
||||
|
||||
// Unassign curator - from reject origin.
|
||||
assert_ok!(ChildBounties::unassign_curator(Origin::root(), 0, 0));
|
||||
assert_ok!(ChildBounties::unassign_curator(RuntimeOrigin::root(), 0, 0));
|
||||
|
||||
// Verify updated child-bounty status.
|
||||
assert_eq!(
|
||||
@@ -817,8 +862,8 @@ fn child_bounty_active_unassign_curator() {
|
||||
|
||||
// Propose and accept curator for child-bounty again.
|
||||
let fee = 2;
|
||||
assert_ok!(ChildBounties::propose_curator(Origin::signed(4), 0, 0, 7, fee));
|
||||
assert_ok!(ChildBounties::accept_curator(Origin::signed(7), 0, 0));
|
||||
assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 7, fee));
|
||||
assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(7), 0, 0));
|
||||
let expected_child_deposit = CuratorDepositMin::get();
|
||||
|
||||
assert_eq!(
|
||||
@@ -836,7 +881,7 @@ fn child_bounty_active_unassign_curator() {
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(5);
|
||||
|
||||
// Unassign curator again - from parent curator.
|
||||
assert_ok!(ChildBounties::unassign_curator(Origin::signed(4), 0, 0));
|
||||
assert_ok!(ChildBounties::unassign_curator(RuntimeOrigin::signed(4), 0, 0));
|
||||
|
||||
// Verify updated child-bounty status.
|
||||
assert_eq!(
|
||||
@@ -855,8 +900,8 @@ fn child_bounty_active_unassign_curator() {
|
||||
assert_eq!(Balances::reserved_balance(7), 0); // slashed
|
||||
|
||||
// Propose and accept curator for child-bounty again.
|
||||
assert_ok!(ChildBounties::propose_curator(Origin::signed(4), 0, 0, 6, 2));
|
||||
assert_ok!(ChildBounties::accept_curator(Origin::signed(6), 0, 0));
|
||||
assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 6, 2));
|
||||
assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(6), 0, 0));
|
||||
|
||||
assert_eq!(
|
||||
ChildBounties::child_bounties(0, 0).unwrap(),
|
||||
@@ -873,7 +918,7 @@ fn child_bounty_active_unassign_curator() {
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(6);
|
||||
|
||||
// Unassign curator again - from child-bounty curator.
|
||||
assert_ok!(ChildBounties::unassign_curator(Origin::signed(6), 0, 0));
|
||||
assert_ok!(ChildBounties::unassign_curator(RuntimeOrigin::signed(6), 0, 0));
|
||||
|
||||
// Verify updated child-bounty status.
|
||||
assert_eq!(
|
||||
@@ -893,8 +938,8 @@ fn child_bounty_active_unassign_curator() {
|
||||
|
||||
// Propose and accept curator for child-bounty one last time.
|
||||
let fee = 2;
|
||||
assert_ok!(ChildBounties::propose_curator(Origin::signed(4), 0, 0, 6, fee));
|
||||
assert_ok!(ChildBounties::accept_curator(Origin::signed(6), 0, 0));
|
||||
assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 6, fee));
|
||||
assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(6), 0, 0));
|
||||
let expected_child_deposit = CuratorDepositMin::get();
|
||||
|
||||
assert_eq!(
|
||||
@@ -914,7 +959,7 @@ fn child_bounty_active_unassign_curator() {
|
||||
// Unassign curator again - from non curator; non reject origin; some random guy.
|
||||
// Bounty update period is not yet complete.
|
||||
assert_noop!(
|
||||
ChildBounties::unassign_curator(Origin::signed(3), 0, 0),
|
||||
ChildBounties::unassign_curator(RuntimeOrigin::signed(3), 0, 0),
|
||||
BountiesError::Premature
|
||||
);
|
||||
|
||||
@@ -922,7 +967,7 @@ fn child_bounty_active_unassign_curator() {
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(20);
|
||||
|
||||
// Unassign child curator from random account after inactivity.
|
||||
assert_ok!(ChildBounties::unassign_curator(Origin::signed(3), 0, 0));
|
||||
assert_ok!(ChildBounties::unassign_curator(RuntimeOrigin::signed(3), 0, 0));
|
||||
|
||||
// Verify updated child-bounty status.
|
||||
assert_eq!(
|
||||
@@ -960,17 +1005,22 @@ fn parent_bounty_inactive_unassign_curator_child_bounty() {
|
||||
Balances::make_free_balance_be(&7, 101); // Child-bounty curator 2.
|
||||
Balances::make_free_balance_be(&8, 101); // Child-bounty curator 3.
|
||||
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 4, 6));
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(4), 0));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 6));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0));
|
||||
|
||||
// Create Child-bounty.
|
||||
assert_ok!(ChildBounties::add_child_bounty(Origin::signed(4), 0, 10, b"12345-p1".to_vec()));
|
||||
assert_ok!(ChildBounties::add_child_bounty(
|
||||
RuntimeOrigin::signed(4),
|
||||
0,
|
||||
10,
|
||||
b"12345-p1".to_vec()
|
||||
));
|
||||
assert_eq!(last_event(), ChildBountiesEvent::Added { index: 0, child_index: 0 });
|
||||
|
||||
System::set_block_number(3);
|
||||
@@ -978,8 +1028,8 @@ fn parent_bounty_inactive_unassign_curator_child_bounty() {
|
||||
|
||||
// Propose and accept curator for child-bounty.
|
||||
let fee = 8;
|
||||
assert_ok!(ChildBounties::propose_curator(Origin::signed(4), 0, 0, 8, fee));
|
||||
assert_ok!(ChildBounties::accept_curator(Origin::signed(8), 0, 0));
|
||||
assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 8, fee));
|
||||
assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(8), 0, 0));
|
||||
let expected_child_deposit = CuratorDepositMultiplier::get() * fee;
|
||||
|
||||
assert_eq!(
|
||||
@@ -997,7 +1047,7 @@ fn parent_bounty_inactive_unassign_curator_child_bounty() {
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(4);
|
||||
|
||||
// Unassign parent bounty curator.
|
||||
assert_ok!(Bounties::unassign_curator(Origin::root(), 0));
|
||||
assert_ok!(Bounties::unassign_curator(RuntimeOrigin::root(), 0));
|
||||
|
||||
System::set_block_number(5);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(5);
|
||||
@@ -1005,12 +1055,12 @@ fn parent_bounty_inactive_unassign_curator_child_bounty() {
|
||||
// Try unassign child-bounty curator - from non curator; non reject
|
||||
// origin; some random guy. Bounty update period is not yet complete.
|
||||
assert_noop!(
|
||||
ChildBounties::unassign_curator(Origin::signed(3), 0, 0),
|
||||
ChildBounties::unassign_curator(RuntimeOrigin::signed(3), 0, 0),
|
||||
Error::<Test>::ParentBountyNotActive
|
||||
);
|
||||
|
||||
// Unassign curator - from reject origin.
|
||||
assert_ok!(ChildBounties::unassign_curator(Origin::root(), 0, 0));
|
||||
assert_ok!(ChildBounties::unassign_curator(RuntimeOrigin::root(), 0, 0));
|
||||
|
||||
// Verify updated child-bounty status.
|
||||
assert_eq!(
|
||||
@@ -1032,16 +1082,16 @@ fn parent_bounty_inactive_unassign_curator_child_bounty() {
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(6);
|
||||
|
||||
// Propose and accept curator for parent-bounty again.
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 5, 6));
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(5), 0));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 5, 6));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(5), 0));
|
||||
|
||||
System::set_block_number(7);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(7);
|
||||
|
||||
// Propose and accept curator for child-bounty again.
|
||||
let fee = 2;
|
||||
assert_ok!(ChildBounties::propose_curator(Origin::signed(5), 0, 0, 7, fee));
|
||||
assert_ok!(ChildBounties::accept_curator(Origin::signed(7), 0, 0));
|
||||
assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(5), 0, 0, 7, fee));
|
||||
assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(7), 0, 0));
|
||||
let expected_deposit = CuratorDepositMin::get();
|
||||
|
||||
assert_eq!(
|
||||
@@ -1059,18 +1109,18 @@ fn parent_bounty_inactive_unassign_curator_child_bounty() {
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(8);
|
||||
|
||||
assert_noop!(
|
||||
ChildBounties::unassign_curator(Origin::signed(3), 0, 0),
|
||||
ChildBounties::unassign_curator(RuntimeOrigin::signed(3), 0, 0),
|
||||
BountiesError::Premature
|
||||
);
|
||||
|
||||
// Unassign parent bounty curator again.
|
||||
assert_ok!(Bounties::unassign_curator(Origin::signed(5), 0));
|
||||
assert_ok!(Bounties::unassign_curator(RuntimeOrigin::signed(5), 0));
|
||||
|
||||
System::set_block_number(9);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(9);
|
||||
|
||||
// Unassign curator again - from parent curator.
|
||||
assert_ok!(ChildBounties::unassign_curator(Origin::signed(7), 0, 0));
|
||||
assert_ok!(ChildBounties::unassign_curator(RuntimeOrigin::signed(7), 0, 0));
|
||||
|
||||
// Verify updated child-bounty status.
|
||||
assert_eq!(
|
||||
@@ -1103,24 +1153,29 @@ fn close_parent_with_child_bounty() {
|
||||
Balances::make_free_balance_be(&4, 101); // Parent-bounty curator.
|
||||
Balances::make_free_balance_be(&8, 101); // Child-bounty curator.
|
||||
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
// Try add child-bounty.
|
||||
// Should fail, parent bounty not active yet.
|
||||
assert_noop!(
|
||||
ChildBounties::add_child_bounty(Origin::signed(4), 0, 10, b"12345-p1".to_vec()),
|
||||
ChildBounties::add_child_bounty(RuntimeOrigin::signed(4), 0, 10, b"12345-p1".to_vec()),
|
||||
Error::<Test>::ParentBountyNotActive
|
||||
);
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 4, 6));
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(4), 0));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 6));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0));
|
||||
|
||||
// Child-bounty.
|
||||
assert_ok!(ChildBounties::add_child_bounty(Origin::signed(4), 0, 10, b"12345-p1".to_vec()));
|
||||
assert_ok!(ChildBounties::add_child_bounty(
|
||||
RuntimeOrigin::signed(4),
|
||||
0,
|
||||
10,
|
||||
b"12345-p1".to_vec()
|
||||
));
|
||||
assert_eq!(last_event(), ChildBountiesEvent::Added { index: 0, child_index: 0 });
|
||||
|
||||
System::set_block_number(4);
|
||||
@@ -1129,21 +1184,21 @@ fn close_parent_with_child_bounty() {
|
||||
// Try close parent-bounty.
|
||||
// Child bounty active, can't close parent.
|
||||
assert_noop!(
|
||||
Bounties::close_bounty(Origin::root(), 0),
|
||||
Bounties::close_bounty(RuntimeOrigin::root(), 0),
|
||||
BountiesError::HasActiveChildBounty
|
||||
);
|
||||
|
||||
System::set_block_number(2);
|
||||
|
||||
// Close child-bounty.
|
||||
assert_ok!(ChildBounties::close_child_bounty(Origin::root(), 0, 0));
|
||||
assert_ok!(ChildBounties::close_child_bounty(RuntimeOrigin::root(), 0, 0));
|
||||
|
||||
// Check the child-bounty count.
|
||||
assert_eq!(ChildBounties::parent_child_bounties(0), 0);
|
||||
|
||||
// Try close parent-bounty again.
|
||||
// Should pass this time.
|
||||
assert_ok!(Bounties::close_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::close_bounty(RuntimeOrigin::root(), 0));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1162,17 +1217,22 @@ fn children_curator_fee_calculation_test() {
|
||||
Balances::make_free_balance_be(&4, 101); // Parent-bounty curator.
|
||||
Balances::make_free_balance_be(&8, 101); // Child-bounty curator.
|
||||
|
||||
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), 0));
|
||||
assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec()));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(Origin::root(), 0, 4, 6));
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(4), 0));
|
||||
assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 6));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0));
|
||||
|
||||
// Child-bounty.
|
||||
assert_ok!(ChildBounties::add_child_bounty(Origin::signed(4), 0, 10, b"12345-p1".to_vec()));
|
||||
assert_ok!(ChildBounties::add_child_bounty(
|
||||
RuntimeOrigin::signed(4),
|
||||
0,
|
||||
10,
|
||||
b"12345-p1".to_vec()
|
||||
));
|
||||
assert_eq!(last_event(), ChildBountiesEvent::Added { index: 0, child_index: 0 });
|
||||
|
||||
System::set_block_number(4);
|
||||
@@ -1181,13 +1241,13 @@ fn children_curator_fee_calculation_test() {
|
||||
let fee = 6;
|
||||
|
||||
// Propose curator for child-bounty.
|
||||
assert_ok!(ChildBounties::propose_curator(Origin::signed(4), 0, 0, 8, fee));
|
||||
assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 8, fee));
|
||||
// Check curator fee added to the sum.
|
||||
assert_eq!(ChildBounties::children_curator_fees(0), fee);
|
||||
// Accept curator for child-bounty.
|
||||
assert_ok!(ChildBounties::accept_curator(Origin::signed(8), 0, 0));
|
||||
assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(8), 0, 0));
|
||||
// Award child-bounty.
|
||||
assert_ok!(ChildBounties::award_child_bounty(Origin::signed(8), 0, 0, 7));
|
||||
assert_ok!(ChildBounties::award_child_bounty(RuntimeOrigin::signed(8), 0, 0, 7));
|
||||
|
||||
let expected_child_deposit = CuratorDepositMultiplier::get() * fee;
|
||||
|
||||
@@ -1209,18 +1269,18 @@ fn children_curator_fee_calculation_test() {
|
||||
System::set_block_number(9);
|
||||
|
||||
// Claim child-bounty.
|
||||
assert_ok!(ChildBounties::claim_child_bounty(Origin::signed(7), 0, 0));
|
||||
assert_ok!(ChildBounties::claim_child_bounty(RuntimeOrigin::signed(7), 0, 0));
|
||||
|
||||
// Check the child-bounty count.
|
||||
assert_eq!(ChildBounties::parent_child_bounties(0), 0);
|
||||
|
||||
// Award the parent bounty.
|
||||
assert_ok!(Bounties::award_bounty(Origin::signed(4), 0, 9));
|
||||
assert_ok!(Bounties::award_bounty(RuntimeOrigin::signed(4), 0, 9));
|
||||
|
||||
System::set_block_number(15);
|
||||
|
||||
// Claim the parent bounty.
|
||||
assert_ok!(Bounties::claim_bounty(Origin::signed(9), 0));
|
||||
assert_ok!(Bounties::claim_bounty(RuntimeOrigin::signed(9), 0));
|
||||
|
||||
// Ensure parent-bounty curator received correctly reduced fee.
|
||||
assert_eq!(Balances::free_balance(4), 101 + 6 - fee); // 101 + 6 - 2
|
||||
@@ -1247,22 +1307,22 @@ fn accept_curator_handles_different_deposit_calculations() {
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), parent_value * 3);
|
||||
Balances::make_free_balance_be(&parent_curator, parent_fee * 100);
|
||||
assert_ok!(Bounties::propose_bounty(
|
||||
Origin::signed(parent_curator),
|
||||
RuntimeOrigin::signed(parent_curator),
|
||||
parent_value,
|
||||
b"12345".to_vec()
|
||||
));
|
||||
assert_ok!(Bounties::approve_bounty(Origin::root(), parent_index));
|
||||
assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), parent_index));
|
||||
|
||||
System::set_block_number(2);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
|
||||
assert_ok!(Bounties::propose_curator(
|
||||
Origin::root(),
|
||||
RuntimeOrigin::root(),
|
||||
parent_index,
|
||||
parent_curator,
|
||||
parent_fee
|
||||
));
|
||||
assert_ok!(Bounties::accept_curator(Origin::signed(parent_curator), parent_index));
|
||||
assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(parent_curator), parent_index));
|
||||
|
||||
// Now we can start creating some child bounties.
|
||||
// Case 1: Parent and child curator are not the same.
|
||||
@@ -1275,7 +1335,7 @@ fn accept_curator_handles_different_deposit_calculations() {
|
||||
|
||||
Balances::make_free_balance_be(&child_curator, starting_balance);
|
||||
assert_ok!(ChildBounties::add_child_bounty(
|
||||
Origin::signed(parent_curator),
|
||||
RuntimeOrigin::signed(parent_curator),
|
||||
parent_index,
|
||||
child_value,
|
||||
b"12345-p1".to_vec()
|
||||
@@ -1283,14 +1343,14 @@ fn accept_curator_handles_different_deposit_calculations() {
|
||||
System::set_block_number(3);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(3);
|
||||
assert_ok!(ChildBounties::propose_curator(
|
||||
Origin::signed(parent_curator),
|
||||
RuntimeOrigin::signed(parent_curator),
|
||||
parent_index,
|
||||
child_index,
|
||||
child_curator,
|
||||
child_fee
|
||||
));
|
||||
assert_ok!(ChildBounties::accept_curator(
|
||||
Origin::signed(child_curator),
|
||||
RuntimeOrigin::signed(child_curator),
|
||||
parent_index,
|
||||
child_index
|
||||
));
|
||||
@@ -1310,7 +1370,7 @@ fn accept_curator_handles_different_deposit_calculations() {
|
||||
let reserved_before = Balances::reserved_balance(&parent_curator);
|
||||
|
||||
assert_ok!(ChildBounties::add_child_bounty(
|
||||
Origin::signed(parent_curator),
|
||||
RuntimeOrigin::signed(parent_curator),
|
||||
parent_index,
|
||||
child_value,
|
||||
b"12345-p1".to_vec()
|
||||
@@ -1318,14 +1378,14 @@ fn accept_curator_handles_different_deposit_calculations() {
|
||||
System::set_block_number(4);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(4);
|
||||
assert_ok!(ChildBounties::propose_curator(
|
||||
Origin::signed(parent_curator),
|
||||
RuntimeOrigin::signed(parent_curator),
|
||||
parent_index,
|
||||
child_index,
|
||||
child_curator,
|
||||
child_fee
|
||||
));
|
||||
assert_ok!(ChildBounties::accept_curator(
|
||||
Origin::signed(child_curator),
|
||||
RuntimeOrigin::signed(child_curator),
|
||||
parent_index,
|
||||
child_index
|
||||
));
|
||||
@@ -1343,7 +1403,7 @@ fn accept_curator_handles_different_deposit_calculations() {
|
||||
|
||||
Balances::make_free_balance_be(&child_curator, starting_balance);
|
||||
assert_ok!(ChildBounties::add_child_bounty(
|
||||
Origin::signed(parent_curator),
|
||||
RuntimeOrigin::signed(parent_curator),
|
||||
parent_index,
|
||||
child_value,
|
||||
b"12345-p1".to_vec()
|
||||
@@ -1351,14 +1411,14 @@ fn accept_curator_handles_different_deposit_calculations() {
|
||||
System::set_block_number(5);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(5);
|
||||
assert_ok!(ChildBounties::propose_curator(
|
||||
Origin::signed(parent_curator),
|
||||
RuntimeOrigin::signed(parent_curator),
|
||||
parent_index,
|
||||
child_index,
|
||||
child_curator,
|
||||
child_fee
|
||||
));
|
||||
assert_ok!(ChildBounties::accept_curator(
|
||||
Origin::signed(child_curator),
|
||||
RuntimeOrigin::signed(child_curator),
|
||||
parent_index,
|
||||
child_index
|
||||
));
|
||||
@@ -1379,7 +1439,7 @@ fn accept_curator_handles_different_deposit_calculations() {
|
||||
|
||||
Balances::make_free_balance_be(&child_curator, starting_balance);
|
||||
assert_ok!(ChildBounties::add_child_bounty(
|
||||
Origin::signed(parent_curator),
|
||||
RuntimeOrigin::signed(parent_curator),
|
||||
parent_index,
|
||||
child_value,
|
||||
b"12345-p1".to_vec()
|
||||
@@ -1387,14 +1447,14 @@ fn accept_curator_handles_different_deposit_calculations() {
|
||||
System::set_block_number(5);
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(5);
|
||||
assert_ok!(ChildBounties::propose_curator(
|
||||
Origin::signed(parent_curator),
|
||||
RuntimeOrigin::signed(parent_curator),
|
||||
parent_index,
|
||||
child_index,
|
||||
child_curator,
|
||||
child_fee
|
||||
));
|
||||
assert_ok!(ChildBounties::accept_curator(
|
||||
Origin::signed(child_curator),
|
||||
RuntimeOrigin::signed(child_curator),
|
||||
parent_index,
|
||||
child_index
|
||||
));
|
||||
|
||||
@@ -181,12 +181,14 @@ pub mod pallet {
|
||||
#[pallet::config]
|
||||
pub trait Config<I: 'static = ()>: frame_system::Config {
|
||||
/// The outer origin type.
|
||||
type Origin: From<RawOrigin<Self::AccountId, I>>;
|
||||
type RuntimeOrigin: From<RawOrigin<Self::AccountId, I>>;
|
||||
|
||||
/// The outer call dispatch type.
|
||||
type Proposal: Parameter
|
||||
+ Dispatchable<Origin = <Self as Config<I>>::Origin, PostInfo = PostDispatchInfo>
|
||||
+ From<frame_system::Call<Self>>
|
||||
+ Dispatchable<
|
||||
RuntimeOrigin = <Self as Config<I>>::RuntimeOrigin,
|
||||
PostInfo = PostDispatchInfo,
|
||||
> + From<frame_system::Call<Self>>
|
||||
+ GetDispatchInfo;
|
||||
|
||||
/// The outer event type.
|
||||
|
||||
@@ -64,7 +64,7 @@ mod mock_democracy {
|
||||
pub trait Config: frame_system::Config + Sized {
|
||||
type RuntimeEvent: From<Event<Self>>
|
||||
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
||||
type ExternalMajorityOrigin: EnsureOrigin<Self::Origin>;
|
||||
type ExternalMajorityOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
}
|
||||
|
||||
#[pallet::call]
|
||||
@@ -98,7 +98,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
@@ -120,7 +120,7 @@ impl frame_system::Config for Test {
|
||||
type MaxConsumers = ConstU32<16>;
|
||||
}
|
||||
impl Config<Instance1> for Test {
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Proposal = RuntimeCall;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type MotionDuration = ConstU64<3>;
|
||||
@@ -130,7 +130,7 @@ impl Config<Instance1> for Test {
|
||||
type WeightInfo = ();
|
||||
}
|
||||
impl Config<Instance2> for Test {
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Proposal = RuntimeCall;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type MotionDuration = ConstU64<3>;
|
||||
@@ -144,7 +144,7 @@ impl mock_democracy::Config for Test {
|
||||
type ExternalMajorityOrigin = EnsureProportionAtLeast<u64, Instance1, 3, 4>;
|
||||
}
|
||||
impl Config for Test {
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Proposal = RuntimeCall;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type MotionDuration = ConstU64<3>;
|
||||
@@ -200,22 +200,28 @@ fn close_works() {
|
||||
let hash = BlakeTwo256::hash_of(&proposal);
|
||||
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_ok!(Collective::vote(Origin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(Origin::signed(2), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, true));
|
||||
|
||||
System::set_block_number(3);
|
||||
assert_noop!(
|
||||
Collective::close(Origin::signed(4), hash, 0, proposal_weight, proposal_len),
|
||||
Collective::close(RuntimeOrigin::signed(4), hash, 0, proposal_weight, proposal_len),
|
||||
Error::<Test, Instance1>::TooEarly
|
||||
);
|
||||
|
||||
System::set_block_number(4);
|
||||
assert_ok!(Collective::close(Origin::signed(4), hash, 0, proposal_weight, proposal_len));
|
||||
assert_ok!(Collective::close(
|
||||
RuntimeOrigin::signed(4),
|
||||
hash,
|
||||
0,
|
||||
proposal_weight,
|
||||
proposal_len
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
@@ -267,17 +273,17 @@ fn proposal_weight_limit_works_on_approve() {
|
||||
// Set 1 as prime voter
|
||||
Prime::<Test, Instance1>::set(Some(1));
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_ok!(Collective::vote(Origin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true));
|
||||
// With 1's prime vote, this should pass
|
||||
System::set_block_number(4);
|
||||
assert_noop!(
|
||||
Collective::close(
|
||||
Origin::signed(4),
|
||||
RuntimeOrigin::signed(4),
|
||||
hash,
|
||||
0,
|
||||
proposal_weight - Weight::from_ref_time(100),
|
||||
@@ -285,7 +291,13 @@ fn proposal_weight_limit_works_on_approve() {
|
||||
),
|
||||
Error::<Test, Instance1>::WrongProposalWeight
|
||||
);
|
||||
assert_ok!(Collective::close(Origin::signed(4), hash, 0, proposal_weight, proposal_len));
|
||||
assert_ok!(Collective::close(
|
||||
RuntimeOrigin::signed(4),
|
||||
hash,
|
||||
0,
|
||||
proposal_weight,
|
||||
proposal_len
|
||||
));
|
||||
})
|
||||
}
|
||||
|
||||
@@ -302,7 +314,7 @@ fn proposal_weight_limit_ignored_on_disapprove() {
|
||||
let hash = BlakeTwo256::hash_of(&proposal);
|
||||
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
@@ -310,7 +322,7 @@ fn proposal_weight_limit_ignored_on_disapprove() {
|
||||
// No votes, this proposal wont pass
|
||||
System::set_block_number(4);
|
||||
assert_ok!(Collective::close(
|
||||
Origin::signed(4),
|
||||
RuntimeOrigin::signed(4),
|
||||
hash,
|
||||
0,
|
||||
proposal_weight - Weight::from_ref_time(100),
|
||||
@@ -327,23 +339,29 @@ fn close_with_prime_works() {
|
||||
let proposal_weight = proposal.get_dispatch_info().weight;
|
||||
let hash = BlakeTwo256::hash_of(&proposal);
|
||||
assert_ok!(Collective::set_members(
|
||||
Origin::root(),
|
||||
RuntimeOrigin::root(),
|
||||
vec![1, 2, 3],
|
||||
Some(3),
|
||||
MaxMembers::get()
|
||||
));
|
||||
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_ok!(Collective::vote(Origin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(Origin::signed(2), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, true));
|
||||
|
||||
System::set_block_number(4);
|
||||
assert_ok!(Collective::close(Origin::signed(4), hash, 0, proposal_weight, proposal_len));
|
||||
assert_ok!(Collective::close(
|
||||
RuntimeOrigin::signed(4),
|
||||
hash,
|
||||
0,
|
||||
proposal_weight,
|
||||
proposal_len
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
@@ -389,23 +407,29 @@ fn close_with_voting_prime_works() {
|
||||
let proposal_weight = proposal.get_dispatch_info().weight;
|
||||
let hash = BlakeTwo256::hash_of(&proposal);
|
||||
assert_ok!(Collective::set_members(
|
||||
Origin::root(),
|
||||
RuntimeOrigin::root(),
|
||||
vec![1, 2, 3],
|
||||
Some(1),
|
||||
MaxMembers::get()
|
||||
));
|
||||
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_ok!(Collective::vote(Origin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(Origin::signed(2), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, true));
|
||||
|
||||
System::set_block_number(4);
|
||||
assert_ok!(Collective::close(Origin::signed(4), hash, 0, proposal_weight, proposal_len));
|
||||
assert_ok!(Collective::close(
|
||||
RuntimeOrigin::signed(4),
|
||||
hash,
|
||||
0,
|
||||
proposal_weight,
|
||||
proposal_len
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
@@ -453,25 +477,25 @@ fn close_with_no_prime_but_majority_works() {
|
||||
let proposal_weight = proposal.get_dispatch_info().weight;
|
||||
let hash = BlakeTwo256::hash_of(&proposal);
|
||||
assert_ok!(CollectiveMajority::set_members(
|
||||
Origin::root(),
|
||||
RuntimeOrigin::root(),
|
||||
vec![1, 2, 3, 4, 5],
|
||||
Some(5),
|
||||
MaxMembers::get()
|
||||
));
|
||||
|
||||
assert_ok!(CollectiveMajority::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
5,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_ok!(CollectiveMajority::vote(Origin::signed(1), hash, 0, true));
|
||||
assert_ok!(CollectiveMajority::vote(Origin::signed(2), hash, 0, true));
|
||||
assert_ok!(CollectiveMajority::vote(Origin::signed(3), hash, 0, true));
|
||||
assert_ok!(CollectiveMajority::vote(RuntimeOrigin::signed(1), hash, 0, true));
|
||||
assert_ok!(CollectiveMajority::vote(RuntimeOrigin::signed(2), hash, 0, true));
|
||||
assert_ok!(CollectiveMajority::vote(RuntimeOrigin::signed(3), hash, 0, true));
|
||||
|
||||
System::set_block_number(4);
|
||||
assert_ok!(CollectiveMajority::close(
|
||||
Origin::signed(4),
|
||||
RuntimeOrigin::signed(4),
|
||||
hash,
|
||||
0,
|
||||
proposal_weight,
|
||||
@@ -533,13 +557,13 @@ fn removal_of_old_voters_votes_works() {
|
||||
let hash = BlakeTwo256::hash_of(&proposal);
|
||||
let end = 4;
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_ok!(Collective::vote(Origin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(Origin::signed(2), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, true));
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Some(Votes { index: 0, threshold: 3, ayes: vec![1, 2], nays: vec![], end })
|
||||
@@ -554,13 +578,13 @@ fn removal_of_old_voters_votes_works() {
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let hash = BlakeTwo256::hash_of(&proposal);
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
2,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_ok!(Collective::vote(Origin::signed(2), hash, 1, true));
|
||||
assert_ok!(Collective::vote(Origin::signed(3), hash, 1, false));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 1, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(3), hash, 1, false));
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Some(Votes { index: 1, threshold: 2, ayes: vec![2], nays: vec![3], end })
|
||||
@@ -581,18 +605,23 @@ fn removal_of_old_voters_votes_works_with_set_members() {
|
||||
let hash = BlakeTwo256::hash_of(&proposal);
|
||||
let end = 4;
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_ok!(Collective::vote(Origin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(Origin::signed(2), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, true));
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Some(Votes { index: 0, threshold: 3, ayes: vec![1, 2], nays: vec![], end })
|
||||
);
|
||||
assert_ok!(Collective::set_members(Origin::root(), vec![2, 3, 4], None, MaxMembers::get()));
|
||||
assert_ok!(Collective::set_members(
|
||||
RuntimeOrigin::root(),
|
||||
vec![2, 3, 4],
|
||||
None,
|
||||
MaxMembers::get()
|
||||
));
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Some(Votes { index: 0, threshold: 3, ayes: vec![2], nays: vec![], end })
|
||||
@@ -602,18 +631,23 @@ fn removal_of_old_voters_votes_works_with_set_members() {
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let hash = BlakeTwo256::hash_of(&proposal);
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
2,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_ok!(Collective::vote(Origin::signed(2), hash, 1, true));
|
||||
assert_ok!(Collective::vote(Origin::signed(3), hash, 1, false));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 1, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(3), hash, 1, false));
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Some(Votes { index: 1, threshold: 2, ayes: vec![2], nays: vec![3], end })
|
||||
);
|
||||
assert_ok!(Collective::set_members(Origin::root(), vec![2, 4], None, MaxMembers::get()));
|
||||
assert_ok!(Collective::set_members(
|
||||
RuntimeOrigin::root(),
|
||||
vec![2, 4],
|
||||
None,
|
||||
MaxMembers::get()
|
||||
));
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Some(Votes { index: 1, threshold: 2, ayes: vec![2], nays: vec![], end })
|
||||
@@ -629,7 +663,7 @@ fn propose_works() {
|
||||
let hash = proposal.blake2_256().into();
|
||||
let end = 4;
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
@@ -660,7 +694,7 @@ fn limit_active_proposals() {
|
||||
let proposal = make_proposal(i as u64);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
@@ -669,7 +703,12 @@ fn limit_active_proposals() {
|
||||
let proposal = make_proposal(MaxProposals::get() as u64 + 1);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
assert_noop!(
|
||||
Collective::propose(Origin::signed(1), 3, Box::new(proposal.clone()), proposal_len),
|
||||
Collective::propose(
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
),
|
||||
Error::<Test, Instance1>::TooManyProposals
|
||||
);
|
||||
})
|
||||
@@ -684,7 +723,12 @@ fn correct_validate_and_get_proposal() {
|
||||
old_count: MaxMembers::get(),
|
||||
});
|
||||
let length = proposal.encode().len() as u32;
|
||||
assert_ok!(Collective::propose(Origin::signed(1), 3, Box::new(proposal.clone()), length));
|
||||
assert_ok!(Collective::propose(
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
length
|
||||
));
|
||||
|
||||
let hash = BlakeTwo256::hash_of(&proposal);
|
||||
let weight = proposal.get_dispatch_info().weight;
|
||||
@@ -722,7 +766,12 @@ fn motions_ignoring_non_collective_proposals_works() {
|
||||
let proposal = make_proposal(42);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
assert_noop!(
|
||||
Collective::propose(Origin::signed(42), 3, Box::new(proposal.clone()), proposal_len),
|
||||
Collective::propose(
|
||||
RuntimeOrigin::signed(42),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
),
|
||||
Error::<Test, Instance1>::NotMember
|
||||
);
|
||||
});
|
||||
@@ -735,13 +784,13 @@ fn motions_ignoring_non_collective_votes_works() {
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_noop!(
|
||||
Collective::vote(Origin::signed(42), hash, 0, true),
|
||||
Collective::vote(RuntimeOrigin::signed(42), hash, 0, true),
|
||||
Error::<Test, Instance1>::NotMember,
|
||||
);
|
||||
});
|
||||
@@ -755,13 +804,13 @@ fn motions_ignoring_bad_index_collective_vote_works() {
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_noop!(
|
||||
Collective::vote(Origin::signed(2), hash, 1, true),
|
||||
Collective::vote(RuntimeOrigin::signed(2), hash, 1, true),
|
||||
Error::<Test, Instance1>::WrongIndex,
|
||||
);
|
||||
});
|
||||
@@ -775,7 +824,7 @@ fn motions_vote_after_works() {
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
let end = 4;
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
@@ -786,25 +835,25 @@ fn motions_vote_after_works() {
|
||||
Some(Votes { index: 0, threshold: 2, ayes: vec![], nays: vec![], end })
|
||||
);
|
||||
// Cast first aye vote.
|
||||
assert_ok!(Collective::vote(Origin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true));
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Some(Votes { index: 0, threshold: 2, ayes: vec![1], nays: vec![], end })
|
||||
);
|
||||
// Try to cast a duplicate aye vote.
|
||||
assert_noop!(
|
||||
Collective::vote(Origin::signed(1), hash, 0, true),
|
||||
Collective::vote(RuntimeOrigin::signed(1), hash, 0, true),
|
||||
Error::<Test, Instance1>::DuplicateVote,
|
||||
);
|
||||
// Cast a nay vote.
|
||||
assert_ok!(Collective::vote(Origin::signed(1), hash, 0, false));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, false));
|
||||
assert_eq!(
|
||||
Collective::voting(&hash),
|
||||
Some(Votes { index: 0, threshold: 2, ayes: vec![], nays: vec![1], end })
|
||||
);
|
||||
// Try to cast a duplicate nay vote.
|
||||
assert_noop!(
|
||||
Collective::vote(Origin::signed(1), hash, 0, false),
|
||||
Collective::vote(RuntimeOrigin::signed(1), hash, 0, false),
|
||||
Error::<Test, Instance1>::DuplicateVote,
|
||||
);
|
||||
|
||||
@@ -844,7 +893,7 @@ fn motions_all_first_vote_free_works() {
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
let end = 4;
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len,
|
||||
@@ -856,40 +905,40 @@ fn motions_all_first_vote_free_works() {
|
||||
|
||||
// For the motion, acc 2's first vote, expecting Ok with Pays::No.
|
||||
let vote_rval: DispatchResultWithPostInfo =
|
||||
Collective::vote(Origin::signed(2), hash, 0, true);
|
||||
Collective::vote(RuntimeOrigin::signed(2), hash, 0, true);
|
||||
assert_eq!(vote_rval.unwrap().pays_fee, Pays::No);
|
||||
|
||||
// Duplicate vote, expecting error with Pays::Yes.
|
||||
let vote_rval: DispatchResultWithPostInfo =
|
||||
Collective::vote(Origin::signed(2), hash, 0, true);
|
||||
Collective::vote(RuntimeOrigin::signed(2), hash, 0, true);
|
||||
assert_eq!(vote_rval.unwrap_err().post_info.pays_fee, Pays::Yes);
|
||||
|
||||
// Modifying vote, expecting ok with Pays::Yes.
|
||||
let vote_rval: DispatchResultWithPostInfo =
|
||||
Collective::vote(Origin::signed(2), hash, 0, false);
|
||||
Collective::vote(RuntimeOrigin::signed(2), hash, 0, false);
|
||||
assert_eq!(vote_rval.unwrap().pays_fee, Pays::Yes);
|
||||
|
||||
// For the motion, acc 3's first vote, expecting Ok with Pays::No.
|
||||
let vote_rval: DispatchResultWithPostInfo =
|
||||
Collective::vote(Origin::signed(3), hash, 0, true);
|
||||
Collective::vote(RuntimeOrigin::signed(3), hash, 0, true);
|
||||
assert_eq!(vote_rval.unwrap().pays_fee, Pays::No);
|
||||
|
||||
// acc 3 modify the vote, expecting Ok with Pays::Yes.
|
||||
let vote_rval: DispatchResultWithPostInfo =
|
||||
Collective::vote(Origin::signed(3), hash, 0, false);
|
||||
Collective::vote(RuntimeOrigin::signed(3), hash, 0, false);
|
||||
assert_eq!(vote_rval.unwrap().pays_fee, Pays::Yes);
|
||||
|
||||
// Test close() Extrincis | Check DispatchResultWithPostInfo with Pay Info
|
||||
|
||||
let proposal_weight = proposal.get_dispatch_info().weight;
|
||||
let close_rval: DispatchResultWithPostInfo =
|
||||
Collective::close(Origin::signed(2), hash, 0, proposal_weight, proposal_len);
|
||||
Collective::close(RuntimeOrigin::signed(2), hash, 0, proposal_weight, proposal_len);
|
||||
assert_eq!(close_rval.unwrap().pays_fee, Pays::No);
|
||||
|
||||
// trying to close the proposal, which is already closed.
|
||||
// Expecting error "ProposalMissing" with Pays::Yes
|
||||
let close_rval: DispatchResultWithPostInfo =
|
||||
Collective::close(Origin::signed(2), hash, 0, proposal_weight, proposal_len);
|
||||
Collective::close(RuntimeOrigin::signed(2), hash, 0, proposal_weight, proposal_len);
|
||||
assert_eq!(close_rval.unwrap_err().post_info.pays_fee, Pays::Yes);
|
||||
});
|
||||
}
|
||||
@@ -902,16 +951,22 @@ fn motions_reproposing_disapproved_works() {
|
||||
let proposal_weight = proposal.get_dispatch_info().weight;
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_ok!(Collective::vote(Origin::signed(2), hash, 0, false));
|
||||
assert_ok!(Collective::close(Origin::signed(2), hash, 0, proposal_weight, proposal_len));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, false));
|
||||
assert_ok!(Collective::close(
|
||||
RuntimeOrigin::signed(2),
|
||||
hash,
|
||||
0,
|
||||
proposal_weight,
|
||||
proposal_len
|
||||
));
|
||||
assert_eq!(*Collective::proposals(), vec![]);
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
@@ -933,14 +988,20 @@ fn motions_approval_with_enough_votes_and_lower_voting_threshold_works() {
|
||||
//
|
||||
// Failed to execute with only 2 yes votes.
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_ok!(Collective::vote(Origin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(Origin::signed(2), hash, 0, true));
|
||||
assert_ok!(Collective::close(Origin::signed(2), hash, 0, proposal_weight, proposal_len));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, true));
|
||||
assert_ok!(Collective::close(
|
||||
RuntimeOrigin::signed(2),
|
||||
hash,
|
||||
0,
|
||||
proposal_weight,
|
||||
proposal_len
|
||||
));
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
vec![
|
||||
@@ -981,15 +1042,21 @@ fn motions_approval_with_enough_votes_and_lower_voting_threshold_works() {
|
||||
|
||||
// Executed with 3 yes votes.
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_ok!(Collective::vote(Origin::signed(1), hash, 1, true));
|
||||
assert_ok!(Collective::vote(Origin::signed(2), hash, 1, true));
|
||||
assert_ok!(Collective::vote(Origin::signed(3), hash, 1, true));
|
||||
assert_ok!(Collective::close(Origin::signed(2), hash, 1, proposal_weight, proposal_len));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 1, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 1, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(3), hash, 1, true));
|
||||
assert_ok!(Collective::close(
|
||||
RuntimeOrigin::signed(2),
|
||||
hash,
|
||||
1,
|
||||
proposal_weight,
|
||||
proposal_len
|
||||
));
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
vec![
|
||||
@@ -1046,14 +1113,20 @@ fn motions_disapproval_works() {
|
||||
let proposal_weight = proposal.get_dispatch_info().weight;
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_ok!(Collective::vote(Origin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(Origin::signed(2), hash, 0, false));
|
||||
assert_ok!(Collective::close(Origin::signed(2), hash, 0, proposal_weight, proposal_len));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, false));
|
||||
assert_ok!(Collective::close(
|
||||
RuntimeOrigin::signed(2),
|
||||
hash,
|
||||
0,
|
||||
proposal_weight,
|
||||
proposal_len
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
@@ -1099,14 +1172,20 @@ fn motions_approval_works() {
|
||||
let proposal_weight = proposal.get_dispatch_info().weight;
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
assert_ok!(Collective::vote(Origin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(Origin::signed(2), hash, 0, true));
|
||||
assert_ok!(Collective::close(Origin::signed(2), hash, 0, proposal_weight, proposal_len));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, true));
|
||||
assert_ok!(Collective::close(
|
||||
RuntimeOrigin::signed(2),
|
||||
hash,
|
||||
0,
|
||||
proposal_weight,
|
||||
proposal_len
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
@@ -1154,7 +1233,7 @@ fn motion_with_no_votes_closes_with_disapproval() {
|
||||
let proposal_weight = proposal.get_dispatch_info().weight;
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
@@ -1172,7 +1251,7 @@ fn motion_with_no_votes_closes_with_disapproval() {
|
||||
// Closing the motion too early is not possible because it has neither
|
||||
// an approving or disapproving simple majority due to the lack of votes.
|
||||
assert_noop!(
|
||||
Collective::close(Origin::signed(2), hash, 0, proposal_weight, proposal_len),
|
||||
Collective::close(RuntimeOrigin::signed(2), hash, 0, proposal_weight, proposal_len),
|
||||
Error::<Test, Instance1>::TooEarly
|
||||
);
|
||||
|
||||
@@ -1180,7 +1259,13 @@ fn motion_with_no_votes_closes_with_disapproval() {
|
||||
let closing_block = System::block_number() + MotionDuration::get();
|
||||
System::set_block_number(closing_block);
|
||||
// we can successfully close the motion.
|
||||
assert_ok!(Collective::close(Origin::signed(2), hash, 0, proposal_weight, proposal_len));
|
||||
assert_ok!(Collective::close(
|
||||
RuntimeOrigin::signed(2),
|
||||
hash,
|
||||
0,
|
||||
proposal_weight,
|
||||
proposal_len
|
||||
));
|
||||
|
||||
// Events show that the close ended in a disapproval.
|
||||
assert_eq!(
|
||||
@@ -1208,28 +1293,28 @@ fn close_disapprove_does_not_care_about_weight_or_len() {
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
// First we make the proposal succeed
|
||||
assert_ok!(Collective::vote(Origin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(Origin::signed(2), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, true));
|
||||
// It will not close with bad weight/len information
|
||||
assert_noop!(
|
||||
Collective::close(Origin::signed(2), hash, 0, Weight::zero(), 0),
|
||||
Collective::close(RuntimeOrigin::signed(2), hash, 0, Weight::zero(), 0),
|
||||
Error::<Test, Instance1>::WrongProposalLength,
|
||||
);
|
||||
assert_noop!(
|
||||
Collective::close(Origin::signed(2), hash, 0, Weight::zero(), proposal_len),
|
||||
Collective::close(RuntimeOrigin::signed(2), hash, 0, Weight::zero(), proposal_len),
|
||||
Error::<Test, Instance1>::WrongProposalWeight,
|
||||
);
|
||||
// Now we make the proposal fail
|
||||
assert_ok!(Collective::vote(Origin::signed(1), hash, 0, false));
|
||||
assert_ok!(Collective::vote(Origin::signed(2), hash, 0, false));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, false));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, false));
|
||||
// It can close even if the weight/len information is bad
|
||||
assert_ok!(Collective::close(Origin::signed(2), hash, 0, Weight::zero(), 0));
|
||||
assert_ok!(Collective::close(RuntimeOrigin::signed(2), hash, 0, Weight::zero(), 0));
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1240,16 +1325,16 @@ fn disapprove_proposal_works() {
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
assert_ok!(Collective::propose(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
Box::new(proposal.clone()),
|
||||
proposal_len
|
||||
));
|
||||
// Proposal would normally succeed
|
||||
assert_ok!(Collective::vote(Origin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(Origin::signed(2), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true));
|
||||
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, true));
|
||||
// But Root can disapprove and remove it anyway
|
||||
assert_ok!(Collective::disapprove_proposal(Origin::root(), hash));
|
||||
assert_ok!(Collective::disapprove_proposal(RuntimeOrigin::root(), hash));
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
vec![
|
||||
|
||||
@@ -1306,7 +1306,7 @@ where
|
||||
}
|
||||
|
||||
fn call_runtime(&self, call: <Self::T as Config>::RuntimeCall) -> DispatchResultWithPostInfo {
|
||||
let mut origin: T::Origin = RawOrigin::Signed(self.address().clone()).into();
|
||||
let mut origin: T::RuntimeOrigin = RawOrigin::Signed(self.address().clone()).into();
|
||||
origin.add_filter(T::CallFilter::contains);
|
||||
call.dispatch(origin)
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ pub mod pallet {
|
||||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
||||
|
||||
/// The overarching call type.
|
||||
type RuntimeCall: Dispatchable<Origin = Self::Origin, PostInfo = PostDispatchInfo>
|
||||
type RuntimeCall: Dispatchable<RuntimeOrigin = Self::RuntimeOrigin, PostInfo = PostDispatchInfo>
|
||||
+ GetDispatchInfo
|
||||
+ codec::Decode
|
||||
+ IsType<<Self as frame_system::Config>::RuntimeCall>;
|
||||
|
||||
@@ -277,7 +277,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = BlockWeights;
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
@@ -489,7 +489,7 @@ fn calling_plain_account_fails() {
|
||||
let base_cost = <<Test as Config>::WeightInfo as WeightInfo>::call();
|
||||
|
||||
assert_eq!(
|
||||
Contracts::call(Origin::signed(ALICE), BOB, 0, GAS_LIMIT, None, Vec::new()),
|
||||
Contracts::call(RuntimeOrigin::signed(ALICE), BOB, 0, GAS_LIMIT, None, Vec::new()),
|
||||
Err(DispatchErrorWithPostInfo {
|
||||
error: Error::<Test>::ContractNotFound.into(),
|
||||
post_info: PostDispatchInfo {
|
||||
@@ -512,14 +512,14 @@ fn instantiate_and_call_and_deposit_event() {
|
||||
|
||||
// We determine the storage deposit limit after uploading because it depends on ALICEs free
|
||||
// balance which is changed by uploading a module.
|
||||
assert_ok!(Contracts::upload_code(Origin::signed(ALICE), wasm, None));
|
||||
assert_ok!(Contracts::upload_code(RuntimeOrigin::signed(ALICE), wasm, None));
|
||||
|
||||
// Drop previous events
|
||||
initialize_block(2);
|
||||
|
||||
// Check at the end to get hash on error easily
|
||||
assert_ok!(Contracts::instantiate(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
value,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -603,7 +603,7 @@ fn deposit_event_max_value_limit() {
|
||||
// Create
|
||||
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
30_000,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -615,7 +615,7 @@ fn deposit_event_max_value_limit() {
|
||||
|
||||
// Call contract with allowed storage value.
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT * 2, // we are copying a huge buffer,
|
||||
@@ -626,7 +626,7 @@ fn deposit_event_max_value_limit() {
|
||||
// Call contract with too large a storage value.
|
||||
assert_err_ignore_postinfo!(
|
||||
Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr,
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
@@ -646,7 +646,7 @@ fn run_out_of_gas() {
|
||||
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
100 * min_balance,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -660,7 +660,7 @@ fn run_out_of_gas() {
|
||||
// loops forever.
|
||||
assert_err_ignore_postinfo!(
|
||||
Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr, // newly created account
|
||||
0,
|
||||
Weight::from_ref_time(1_000_000_000_000),
|
||||
@@ -680,12 +680,12 @@ fn instantiate_unique_trie_id() {
|
||||
|
||||
ExtBuilder::default().existential_deposit(500).build().execute_with(|| {
|
||||
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
|
||||
Contracts::upload_code(Origin::signed(ALICE), wasm, None).unwrap();
|
||||
Contracts::upload_code(RuntimeOrigin::signed(ALICE), wasm, None).unwrap();
|
||||
let addr = Contracts::contract_address(&ALICE, &code_hash, &[]);
|
||||
|
||||
// Instantiate the contract and store its trie id for later comparison.
|
||||
assert_ok!(Contracts::instantiate(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -698,7 +698,7 @@ fn instantiate_unique_trie_id() {
|
||||
// Try to instantiate it again without termination should yield an error.
|
||||
assert_err_ignore_postinfo!(
|
||||
Contracts::instantiate(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -711,7 +711,7 @@ fn instantiate_unique_trie_id() {
|
||||
|
||||
// Terminate the contract.
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
@@ -721,7 +721,7 @@ fn instantiate_unique_trie_id() {
|
||||
|
||||
// Re-Instantiate after termination.
|
||||
assert_ok!(Contracts::instantiate(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -743,7 +743,7 @@ fn storage_max_value_limit() {
|
||||
// Create
|
||||
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
30_000,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -756,7 +756,7 @@ fn storage_max_value_limit() {
|
||||
|
||||
// Call contract with allowed storage value.
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT * 2, // we are copying a huge buffer
|
||||
@@ -767,7 +767,7 @@ fn storage_max_value_limit() {
|
||||
// Call contract with too large a storage value.
|
||||
assert_err_ignore_postinfo!(
|
||||
Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr,
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
@@ -792,7 +792,7 @@ fn deploy_and_call_other_contract() {
|
||||
// Create
|
||||
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
100_000,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -801,7 +801,7 @@ fn deploy_and_call_other_contract() {
|
||||
vec![],
|
||||
));
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
100_000,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -816,7 +816,7 @@ fn deploy_and_call_other_contract() {
|
||||
// Call BOB contract, which attempts to instantiate and call the callee contract and
|
||||
// makes various assertions on the results from those calls.
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
caller_addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
@@ -917,7 +917,7 @@ fn delegate_call() {
|
||||
|
||||
// Instantiate the 'caller'
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
300_000,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -927,13 +927,13 @@ fn delegate_call() {
|
||||
));
|
||||
// Only upload 'callee' code
|
||||
assert_ok!(Contracts::upload_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
callee_wasm,
|
||||
Some(codec::Compact(100_000)),
|
||||
));
|
||||
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
caller_addr.clone(),
|
||||
1337,
|
||||
GAS_LIMIT,
|
||||
@@ -951,7 +951,7 @@ fn cannot_self_destruct_through_draning() {
|
||||
|
||||
// Instantiate the BOB contract.
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
1_000,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -967,7 +967,7 @@ fn cannot_self_destruct_through_draning() {
|
||||
// Call BOB which makes it send all funds to the zero address
|
||||
// The contract code asserts that the transfer was successful
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
@@ -992,7 +992,7 @@ fn cannot_self_destruct_through_storage_refund_after_price_change() {
|
||||
|
||||
// Instantiate the BOB contract.
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -1009,7 +1009,7 @@ fn cannot_self_destruct_through_storage_refund_after_price_change() {
|
||||
|
||||
// Create 100 bytes of storage with a price of per byte
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
@@ -1021,7 +1021,7 @@ fn cannot_self_destruct_through_storage_refund_after_price_change() {
|
||||
// because the refund removes the reserved existential deposit. This should not happen.
|
||||
DEPOSIT_PER_BYTE.with(|c| *c.borrow_mut() = 500);
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
@@ -1045,7 +1045,7 @@ fn cannot_self_destruct_by_refund_after_slash() {
|
||||
let min_balance = <Test as Config>::Currency::minimum_balance();
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -1057,7 +1057,7 @@ fn cannot_self_destruct_by_refund_after_slash() {
|
||||
|
||||
// create 100 more reserved balance
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
@@ -1075,7 +1075,7 @@ fn cannot_self_destruct_by_refund_after_slash() {
|
||||
|
||||
// trigger a refund of 50 which would bring the contract below min when actually refunded
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
@@ -1131,7 +1131,7 @@ fn cannot_self_destruct_while_live() {
|
||||
|
||||
// Instantiate the BOB contract.
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
100_000,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -1147,7 +1147,14 @@ fn cannot_self_destruct_while_live() {
|
||||
// Call BOB with input data, forcing it make a recursive call to itself to
|
||||
// self-destruct, resulting in a trap.
|
||||
assert_err_ignore_postinfo!(
|
||||
Contracts::call(Origin::signed(ALICE), addr.clone(), 0, GAS_LIMIT, None, vec![0],),
|
||||
Contracts::call(
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
vec![0],
|
||||
),
|
||||
Error::<Test>::ContractTrapped,
|
||||
);
|
||||
|
||||
@@ -1165,7 +1172,7 @@ fn self_destruct_works() {
|
||||
|
||||
// Instantiate the BOB contract.
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
100_000,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -1183,7 +1190,7 @@ fn self_destruct_works() {
|
||||
|
||||
// Call BOB without input data which triggers termination.
|
||||
assert_matches!(
|
||||
Contracts::call(Origin::signed(ALICE), addr.clone(), 0, GAS_LIMIT, None, vec![],),
|
||||
Contracts::call(RuntimeOrigin::signed(ALICE), addr.clone(), 0, GAS_LIMIT, None, vec![],),
|
||||
Ok(_)
|
||||
);
|
||||
|
||||
@@ -1258,7 +1265,7 @@ fn destroy_contract_and_transfer_funds() {
|
||||
// Create
|
||||
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
200_000,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -1270,7 +1277,7 @@ fn destroy_contract_and_transfer_funds() {
|
||||
// This deploys the BOB contract, which in turn deploys the CHARLIE contract during
|
||||
// construction.
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
200_000,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -1286,7 +1293,7 @@ fn destroy_contract_and_transfer_funds() {
|
||||
|
||||
// Call BOB, which calls CHARLIE, forcing CHARLIE to self-destruct.
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr_bob,
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
@@ -1308,7 +1315,7 @@ fn cannot_self_destruct_in_constructor() {
|
||||
// Fail to instantiate the BOB because the contructor calls seal_terminate.
|
||||
assert_err_ignore_postinfo!(
|
||||
Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
100_000,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -1330,7 +1337,7 @@ fn crypto_hashes() {
|
||||
|
||||
// Instantiate the CRYPTO_HASHES contract.
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
100_000,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -1379,7 +1386,7 @@ fn transfer_return_code() {
|
||||
let _ = Balances::deposit_creating(&ALICE, 1000 * min_balance);
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -1418,7 +1425,7 @@ fn call_return_code() {
|
||||
let _ = Balances::deposit_creating(&CHARLIE, 1000 * min_balance);
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -1444,7 +1451,7 @@ fn call_return_code() {
|
||||
assert_return_code!(result, RuntimeReturnCode::NotCallable);
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(CHARLIE),
|
||||
RuntimeOrigin::signed(CHARLIE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -1545,7 +1552,7 @@ fn instantiate_return_code() {
|
||||
let callee_hash = callee_hash.as_ref().to_vec();
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -1555,7 +1562,7 @@ fn instantiate_return_code() {
|
||||
),);
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -1645,7 +1652,7 @@ fn disabled_chain_extension_wont_deploy() {
|
||||
TestExtension::disable();
|
||||
assert_err_ignore_postinfo!(
|
||||
Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
3 * min_balance,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -1665,7 +1672,7 @@ fn disabled_chain_extension_errors_on_call() {
|
||||
let min_balance = <Test as Config>::Currency::minimum_balance();
|
||||
let _ = Balances::deposit_creating(&ALICE, 1000 * min_balance);
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -1676,7 +1683,7 @@ fn disabled_chain_extension_errors_on_call() {
|
||||
let addr = Contracts::contract_address(&ALICE, &hash, &[]);
|
||||
TestExtension::disable();
|
||||
assert_err_ignore_postinfo!(
|
||||
Contracts::call(Origin::signed(ALICE), addr.clone(), 0, GAS_LIMIT, None, vec![],),
|
||||
Contracts::call(RuntimeOrigin::signed(ALICE), addr.clone(), 0, GAS_LIMIT, None, vec![],),
|
||||
Error::<Test>::NoChainExtension,
|
||||
);
|
||||
});
|
||||
@@ -1689,7 +1696,7 @@ fn chain_extension_works() {
|
||||
let min_balance = <Test as Config>::Currency::minimum_balance();
|
||||
let _ = Balances::deposit_creating(&ALICE, 1000 * min_balance);
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -1792,7 +1799,7 @@ fn chain_extension_works() {
|
||||
// We set the MSB part to 2 (instead of 0) which routes the request into the third extension
|
||||
assert_err_ignore_postinfo!(
|
||||
Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
@@ -1811,7 +1818,7 @@ fn chain_extension_temp_storage_works() {
|
||||
let min_balance = <Test as Config>::Currency::minimum_balance();
|
||||
let _ = Balances::deposit_creating(&ALICE, 1000 * min_balance);
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -1845,7 +1852,7 @@ fn lazy_removal_works() {
|
||||
let _ = Balances::deposit_creating(&ALICE, 1000 * min_balance);
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -1863,7 +1870,7 @@ fn lazy_removal_works() {
|
||||
|
||||
// Terminate the contract
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
@@ -1914,7 +1921,7 @@ fn lazy_batch_removal_works() {
|
||||
|
||||
for i in 0..3u8 {
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -1933,7 +1940,7 @@ fn lazy_batch_removal_works() {
|
||||
// Terminate the contract. Contract info should be gone, but value should be still there
|
||||
// as the lazy removal did not run, yet.
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
@@ -1976,7 +1983,7 @@ fn lazy_removal_partial_remove_works() {
|
||||
let _ = Balances::deposit_creating(&ALICE, 1000 * min_balance);
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -2003,7 +2010,7 @@ fn lazy_removal_partial_remove_works() {
|
||||
|
||||
// Terminate the contract
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
@@ -2088,7 +2095,7 @@ fn lazy_removal_does_no_run_on_low_remaining_weight() {
|
||||
let _ = Balances::deposit_creating(&ALICE, 1000 * min_balance);
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -2106,7 +2113,7 @@ fn lazy_removal_does_no_run_on_low_remaining_weight() {
|
||||
|
||||
// Terminate the contract
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
@@ -2156,7 +2163,7 @@ fn lazy_removal_does_not_use_all_weight() {
|
||||
let _ = Balances::deposit_creating(&ALICE, 1000 * min_balance);
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -2189,7 +2196,7 @@ fn lazy_removal_does_not_use_all_weight() {
|
||||
|
||||
// Terminate the contract
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
@@ -2236,7 +2243,7 @@ fn deletion_queue_full() {
|
||||
let _ = Balances::deposit_creating(&ALICE, 1000 * min_balance);
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -2252,7 +2259,7 @@ fn deletion_queue_full() {
|
||||
|
||||
// Terminate the contract should fail
|
||||
assert_err_ignore_postinfo!(
|
||||
Contracts::call(Origin::signed(ALICE), addr.clone(), 0, GAS_LIMIT, None, vec![],),
|
||||
Contracts::call(RuntimeOrigin::signed(ALICE), addr.clone(), 0, GAS_LIMIT, None, vec![],),
|
||||
Error::<Test>::DeletionQueueFull,
|
||||
);
|
||||
|
||||
@@ -2270,7 +2277,7 @@ fn refcounter() {
|
||||
|
||||
// Create two contracts with the same code and check that they do in fact share it.
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -2279,7 +2286,7 @@ fn refcounter() {
|
||||
vec![0],
|
||||
));
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -2291,7 +2298,7 @@ fn refcounter() {
|
||||
|
||||
// Sharing should also work with the usual instantiate call
|
||||
assert_ok!(Contracts::instantiate(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -2307,18 +2314,39 @@ fn refcounter() {
|
||||
let addr2 = Contracts::contract_address(&ALICE, &code_hash, &[2]);
|
||||
|
||||
// Terminating one contract should decrement the refcount
|
||||
assert_ok!(Contracts::call(Origin::signed(ALICE), addr0, 0, GAS_LIMIT, None, vec![]));
|
||||
assert_ok!(Contracts::call(
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr0,
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
vec![]
|
||||
));
|
||||
assert_refcount!(code_hash, 2);
|
||||
|
||||
// remove another one
|
||||
assert_ok!(Contracts::call(Origin::signed(ALICE), addr1, 0, GAS_LIMIT, None, vec![]));
|
||||
assert_ok!(Contracts::call(
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr1,
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
vec![]
|
||||
));
|
||||
assert_refcount!(code_hash, 1);
|
||||
|
||||
// Pristine code should still be there
|
||||
crate::PristineCode::<Test>::get(code_hash).unwrap();
|
||||
|
||||
// remove the last contract
|
||||
assert_ok!(Contracts::call(Origin::signed(ALICE), addr2, 0, GAS_LIMIT, None, vec![]));
|
||||
assert_ok!(Contracts::call(
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr2,
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
vec![]
|
||||
));
|
||||
assert_refcount!(code_hash, 0);
|
||||
|
||||
// refcount is `0` but code should still exists because it needs to be removed manually
|
||||
@@ -2337,7 +2365,7 @@ fn reinstrument_does_charge() {
|
||||
let code_len = wasm.len() as u32;
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -2386,7 +2414,7 @@ fn debug_message_works() {
|
||||
ExtBuilder::default().existential_deposit(50).build().execute_with(|| {
|
||||
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
30_000,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -2409,7 +2437,7 @@ fn debug_message_logging_disabled() {
|
||||
ExtBuilder::default().existential_deposit(50).build().execute_with(|| {
|
||||
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
30_000,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -2422,7 +2450,7 @@ fn debug_message_logging_disabled() {
|
||||
let result = Contracts::bare_call(ALICE, addr.clone(), 0, GAS_LIMIT, None, vec![], false);
|
||||
assert_matches!(result.result, Ok(_));
|
||||
// the dispatchables always run without debugging
|
||||
assert_ok!(Contracts::call(Origin::signed(ALICE), addr, 0, GAS_LIMIT, None, vec![]));
|
||||
assert_ok!(Contracts::call(RuntimeOrigin::signed(ALICE), addr, 0, GAS_LIMIT, None, vec![]));
|
||||
assert!(result.debug_message.is_empty());
|
||||
});
|
||||
}
|
||||
@@ -2434,7 +2462,7 @@ fn debug_message_invalid_utf8() {
|
||||
ExtBuilder::default().existential_deposit(50).build().execute_with(|| {
|
||||
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
30_000,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -2458,7 +2486,7 @@ fn gas_estimation_nested_call_fixed_limit() {
|
||||
let _ = Balances::deposit_creating(&CHARLIE, 1000 * min_balance);
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -2469,7 +2497,7 @@ fn gas_estimation_nested_call_fixed_limit() {
|
||||
let addr_caller = Contracts::contract_address(&ALICE, &caller_hash, &[0]);
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -2527,7 +2555,7 @@ fn gas_estimation_call_runtime() {
|
||||
let _ = Balances::deposit_creating(&CHARLIE, 1000 * min_balance);
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -2538,7 +2566,7 @@ fn gas_estimation_call_runtime() {
|
||||
let addr_caller = Contracts::contract_address(&ALICE, &caller_hash, &[0]);
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
min_balance * 100,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -2595,7 +2623,7 @@ fn ecdsa_recover() {
|
||||
|
||||
// Instantiate the ecdsa_recover contract.
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
100_000,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -2649,7 +2677,7 @@ fn upload_code_works() {
|
||||
|
||||
assert!(!<CodeStorage<Test>>::contains_key(code_hash));
|
||||
assert_ok!(Contracts::upload_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
wasm,
|
||||
Some(codec::Compact(1_000))
|
||||
));
|
||||
@@ -2687,7 +2715,7 @@ fn upload_code_limit_too_low() {
|
||||
initialize_block(2);
|
||||
|
||||
assert_noop!(
|
||||
Contracts::upload_code(Origin::signed(ALICE), wasm, Some(codec::Compact(100))),
|
||||
Contracts::upload_code(RuntimeOrigin::signed(ALICE), wasm, Some(codec::Compact(100))),
|
||||
<Error<Test>>::StorageDepositLimitExhausted,
|
||||
);
|
||||
|
||||
@@ -2706,7 +2734,7 @@ fn upload_code_not_enough_balance() {
|
||||
initialize_block(2);
|
||||
|
||||
assert_noop!(
|
||||
Contracts::upload_code(Origin::signed(ALICE), wasm, Some(codec::Compact(1_000))),
|
||||
Contracts::upload_code(RuntimeOrigin::signed(ALICE), wasm, Some(codec::Compact(1_000))),
|
||||
<Error<Test>>::StorageDepositNotEnoughFunds,
|
||||
);
|
||||
|
||||
@@ -2725,13 +2753,13 @@ fn remove_code_works() {
|
||||
initialize_block(2);
|
||||
|
||||
assert_ok!(Contracts::upload_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
wasm,
|
||||
Some(codec::Compact(1_000))
|
||||
));
|
||||
|
||||
assert!(<CodeStorage<Test>>::contains_key(code_hash));
|
||||
assert_ok!(Contracts::remove_code(Origin::signed(ALICE), code_hash));
|
||||
assert_ok!(Contracts::remove_code(RuntimeOrigin::signed(ALICE), code_hash));
|
||||
assert!(!<CodeStorage<Test>>::contains_key(code_hash));
|
||||
|
||||
assert_eq!(
|
||||
@@ -2779,13 +2807,13 @@ fn remove_code_wrong_origin() {
|
||||
initialize_block(2);
|
||||
|
||||
assert_ok!(Contracts::upload_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
wasm,
|
||||
Some(codec::Compact(1_000))
|
||||
));
|
||||
|
||||
assert_noop!(
|
||||
Contracts::remove_code(Origin::signed(BOB), code_hash),
|
||||
Contracts::remove_code(RuntimeOrigin::signed(BOB), code_hash),
|
||||
sp_runtime::traits::BadOrigin,
|
||||
);
|
||||
|
||||
@@ -2818,7 +2846,7 @@ fn remove_code_in_use() {
|
||||
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -2831,7 +2859,7 @@ fn remove_code_in_use() {
|
||||
initialize_block(2);
|
||||
|
||||
assert_noop!(
|
||||
Contracts::remove_code(Origin::signed(ALICE), code_hash),
|
||||
Contracts::remove_code(RuntimeOrigin::signed(ALICE), code_hash),
|
||||
<Error<Test>>::CodeInUse,
|
||||
);
|
||||
|
||||
@@ -2850,7 +2878,7 @@ fn remove_code_not_found() {
|
||||
initialize_block(2);
|
||||
|
||||
assert_noop!(
|
||||
Contracts::remove_code(Origin::signed(ALICE), code_hash),
|
||||
Contracts::remove_code(RuntimeOrigin::signed(ALICE), code_hash),
|
||||
<Error<Test>>::CodeNotFound,
|
||||
);
|
||||
|
||||
@@ -2870,7 +2898,7 @@ fn instantiate_with_zero_balance_works() {
|
||||
|
||||
// Instantiate the BOB contract.
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -2963,7 +2991,7 @@ fn instantiate_with_below_existential_deposit_works() {
|
||||
|
||||
// Instantiate the BOB contract.
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
50,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -3061,7 +3089,7 @@ fn storage_deposit_works() {
|
||||
let mut deposit = <Test as Config>::Currency::minimum_balance();
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -3076,7 +3104,7 @@ fn storage_deposit_works() {
|
||||
|
||||
// Create storage
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
42,
|
||||
GAS_LIMIT,
|
||||
@@ -3090,7 +3118,7 @@ fn storage_deposit_works() {
|
||||
|
||||
// Add more storage (but also remove some)
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
@@ -3103,7 +3131,7 @@ fn storage_deposit_works() {
|
||||
|
||||
// Remove more storage (but also add some)
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
@@ -3210,7 +3238,7 @@ fn set_code_extrinsic() {
|
||||
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -3220,7 +3248,7 @@ fn set_code_extrinsic() {
|
||||
));
|
||||
let addr = Contracts::contract_address(&ALICE, &code_hash, &[]);
|
||||
|
||||
assert_ok!(Contracts::upload_code(Origin::signed(ALICE), new_wasm, None,));
|
||||
assert_ok!(Contracts::upload_code(RuntimeOrigin::signed(ALICE), new_wasm, None,));
|
||||
|
||||
// Drop previous events
|
||||
initialize_block(2);
|
||||
@@ -3231,7 +3259,7 @@ fn set_code_extrinsic() {
|
||||
|
||||
// only root can execute this extrinsic
|
||||
assert_noop!(
|
||||
Contracts::set_code(Origin::signed(ALICE), addr.clone(), new_code_hash),
|
||||
Contracts::set_code(RuntimeOrigin::signed(ALICE), addr.clone(), new_code_hash),
|
||||
sp_runtime::traits::BadOrigin,
|
||||
);
|
||||
assert_eq!(<ContractInfoOf<Test>>::get(&addr).unwrap().code_hash, code_hash);
|
||||
@@ -3241,7 +3269,7 @@ fn set_code_extrinsic() {
|
||||
|
||||
// contract must exist
|
||||
assert_noop!(
|
||||
Contracts::set_code(Origin::root(), BOB, new_code_hash),
|
||||
Contracts::set_code(RuntimeOrigin::root(), BOB, new_code_hash),
|
||||
<Error<Test>>::ContractNotFound,
|
||||
);
|
||||
assert_eq!(<ContractInfoOf<Test>>::get(&addr).unwrap().code_hash, code_hash);
|
||||
@@ -3251,7 +3279,7 @@ fn set_code_extrinsic() {
|
||||
|
||||
// new code hash must exist
|
||||
assert_noop!(
|
||||
Contracts::set_code(Origin::root(), addr.clone(), Default::default()),
|
||||
Contracts::set_code(RuntimeOrigin::root(), addr.clone(), Default::default()),
|
||||
<Error<Test>>::CodeNotFound,
|
||||
);
|
||||
assert_eq!(<ContractInfoOf<Test>>::get(&addr).unwrap().code_hash, code_hash);
|
||||
@@ -3260,7 +3288,7 @@ fn set_code_extrinsic() {
|
||||
assert_eq!(System::events(), vec![],);
|
||||
|
||||
// successful call
|
||||
assert_ok!(Contracts::set_code(Origin::root(), addr.clone(), new_code_hash));
|
||||
assert_ok!(Contracts::set_code(RuntimeOrigin::root(), addr.clone(), new_code_hash));
|
||||
assert_eq!(<ContractInfoOf<Test>>::get(&addr).unwrap().code_hash, new_code_hash);
|
||||
assert_refcount!(&code_hash, 0);
|
||||
assert_refcount!(&new_code_hash, 1);
|
||||
@@ -3287,7 +3315,7 @@ fn call_after_killed_account_needs_funding() {
|
||||
let min_balance = <Test as Config>::Currency::minimum_balance();
|
||||
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
700,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -3312,7 +3340,7 @@ fn call_after_killed_account_needs_funding() {
|
||||
// account in order to send balance there.
|
||||
assert_err_ignore_postinfo!(
|
||||
Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
min_balance - 1,
|
||||
GAS_LIMIT,
|
||||
@@ -3324,7 +3352,7 @@ fn call_after_killed_account_needs_funding() {
|
||||
|
||||
// Sending zero should work as it does not do a transfer
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
@@ -3334,7 +3362,7 @@ fn call_after_killed_account_needs_funding() {
|
||||
|
||||
// Sending minimum balance should work
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
min_balance,
|
||||
GAS_LIMIT,
|
||||
@@ -3416,12 +3444,12 @@ fn contract_reverted() {
|
||||
let input = (flags.bits(), buffer).encode();
|
||||
|
||||
// We just upload the code for later use
|
||||
assert_ok!(Contracts::upload_code(Origin::signed(ALICE), wasm.clone(), None));
|
||||
assert_ok!(Contracts::upload_code(RuntimeOrigin::signed(ALICE), wasm.clone(), None));
|
||||
|
||||
// Calling extrinsic: revert leads to an error
|
||||
assert_err_ignore_postinfo!(
|
||||
Contracts::instantiate(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -3435,7 +3463,7 @@ fn contract_reverted() {
|
||||
// Calling extrinsic: revert leads to an error
|
||||
assert_err_ignore_postinfo!(
|
||||
Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -3483,7 +3511,14 @@ fn contract_reverted() {
|
||||
|
||||
// Calling extrinsic: revert leads to an error
|
||||
assert_err_ignore_postinfo!(
|
||||
Contracts::call(Origin::signed(ALICE), addr.clone(), 0, GAS_LIMIT, None, input.clone()),
|
||||
Contracts::call(
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
input.clone()
|
||||
),
|
||||
<Error<Test>>::ContractReverted,
|
||||
);
|
||||
|
||||
@@ -3503,7 +3538,7 @@ fn code_rejected_error_works() {
|
||||
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
|
||||
|
||||
assert_noop!(
|
||||
Contracts::upload_code(Origin::signed(ALICE), wasm.clone(), None),
|
||||
Contracts::upload_code(RuntimeOrigin::signed(ALICE), wasm.clone(), None),
|
||||
<Error<Test>>::CodeRejected,
|
||||
);
|
||||
|
||||
@@ -3537,7 +3572,7 @@ fn set_code_hash() {
|
||||
|
||||
// Instantiate the 'caller'
|
||||
assert_ok!(Contracts::instantiate_with_code(
|
||||
Origin::signed(ALICE),
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
300_000,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
@@ -3546,7 +3581,7 @@ fn set_code_hash() {
|
||||
vec![],
|
||||
));
|
||||
// upload new code
|
||||
assert_ok!(Contracts::upload_code(Origin::signed(ALICE), new_wasm.clone(), None));
|
||||
assert_ok!(Contracts::upload_code(RuntimeOrigin::signed(ALICE), new_wasm.clone(), None));
|
||||
|
||||
System::reset_events();
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
@@ -269,28 +269,28 @@ fn basic_stuff() {
|
||||
#[test]
|
||||
fn basic_voting_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(2, 5)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(2, 5)));
|
||||
assert_eq!(tally(3), Tally::from_parts(10, 0, 2));
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(2, 5)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, nay(2, 5)));
|
||||
assert_eq!(tally(3), Tally::from_parts(0, 10, 0));
|
||||
assert_eq!(Balances::usable_balance(1), 8);
|
||||
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(5, 1)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(5, 1)));
|
||||
assert_eq!(tally(3), Tally::from_parts(5, 0, 5));
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(5, 1)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, nay(5, 1)));
|
||||
assert_eq!(tally(3), Tally::from_parts(0, 5, 0));
|
||||
assert_eq!(Balances::usable_balance(1), 5);
|
||||
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(10, 0)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(10, 0)));
|
||||
assert_eq!(tally(3), Tally::from_parts(1, 0, 10));
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(10, 0)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, nay(10, 0)));
|
||||
assert_eq!(tally(3), Tally::from_parts(0, 1, 0));
|
||||
assert_eq!(Balances::usable_balance(1), 0);
|
||||
|
||||
assert_ok!(Voting::remove_vote(Origin::signed(1), None, 3));
|
||||
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), None, 3));
|
||||
assert_eq!(tally(3), Tally::from_parts(0, 0, 0));
|
||||
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), class(3), 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), class(3), 1));
|
||||
assert_eq!(Balances::usable_balance(1), 10);
|
||||
});
|
||||
}
|
||||
@@ -298,28 +298,28 @@ fn basic_voting_works() {
|
||||
#[test]
|
||||
fn voting_balance_gets_locked() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(2, 5)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(2, 5)));
|
||||
assert_eq!(tally(3), Tally::from_parts(10, 0, 2));
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(2, 5)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, nay(2, 5)));
|
||||
assert_eq!(tally(3), Tally::from_parts(0, 10, 0));
|
||||
assert_eq!(Balances::usable_balance(1), 8);
|
||||
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(5, 1)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(5, 1)));
|
||||
assert_eq!(tally(3), Tally::from_parts(5, 0, 5));
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(5, 1)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, nay(5, 1)));
|
||||
assert_eq!(tally(3), Tally::from_parts(0, 5, 0));
|
||||
assert_eq!(Balances::usable_balance(1), 5);
|
||||
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(10, 0)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(10, 0)));
|
||||
assert_eq!(tally(3), Tally::from_parts(1, 0, 10));
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(10, 0)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, nay(10, 0)));
|
||||
assert_eq!(tally(3), Tally::from_parts(0, 1, 0));
|
||||
assert_eq!(Balances::usable_balance(1), 0);
|
||||
|
||||
assert_ok!(Voting::remove_vote(Origin::signed(1), None, 3));
|
||||
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), None, 3));
|
||||
assert_eq!(tally(3), Tally::from_parts(0, 0, 0));
|
||||
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), class(3), 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), class(3), 1));
|
||||
assert_eq!(Balances::usable_balance(1), 10);
|
||||
});
|
||||
}
|
||||
@@ -327,12 +327,12 @@ fn voting_balance_gets_locked() {
|
||||
#[test]
|
||||
fn successful_but_zero_conviction_vote_balance_can_be_unlocked() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(1, 1)));
|
||||
assert_ok!(Voting::vote(Origin::signed(2), 3, nay(20, 0)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(1, 1)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(2), 3, nay(20, 0)));
|
||||
let c = class(3);
|
||||
Polls::set(vec![(3, Completed(3, false))].into_iter().collect());
|
||||
assert_ok!(Voting::remove_vote(Origin::signed(2), Some(c), 3));
|
||||
assert_ok!(Voting::unlock(Origin::signed(2), c, 2));
|
||||
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(2), Some(c), 3));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(2), c, 2));
|
||||
assert_eq!(Balances::usable_balance(2), 20);
|
||||
});
|
||||
}
|
||||
@@ -340,12 +340,12 @@ fn successful_but_zero_conviction_vote_balance_can_be_unlocked() {
|
||||
#[test]
|
||||
fn unsuccessful_conviction_vote_balance_can_be_unlocked() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(1, 1)));
|
||||
assert_ok!(Voting::vote(Origin::signed(2), 3, nay(20, 0)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(1, 1)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(2), 3, nay(20, 0)));
|
||||
let c = class(3);
|
||||
Polls::set(vec![(3, Completed(3, false))].into_iter().collect());
|
||||
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(c), 3));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), c, 1));
|
||||
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), Some(c), 3));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), c, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 10);
|
||||
});
|
||||
}
|
||||
@@ -354,17 +354,17 @@ fn unsuccessful_conviction_vote_balance_can_be_unlocked() {
|
||||
fn successful_conviction_vote_balance_stays_locked_for_correct_time() {
|
||||
new_test_ext().execute_with(|| {
|
||||
for i in 1..=5 {
|
||||
assert_ok!(Voting::vote(Origin::signed(i), 3, aye(10, i as u8)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(i), 3, aye(10, i as u8)));
|
||||
}
|
||||
let c = class(3);
|
||||
Polls::set(vec![(3, Completed(3, true))].into_iter().collect());
|
||||
for i in 1..=5 {
|
||||
assert_ok!(Voting::remove_vote(Origin::signed(i), Some(c), 3));
|
||||
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(i), Some(c), 3));
|
||||
}
|
||||
for block in 1..=(3 + 5 * 3) {
|
||||
run_to(block);
|
||||
for i in 1..=5 {
|
||||
assert_ok!(Voting::unlock(Origin::signed(i), c, i));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(i), c, i));
|
||||
let expired = block >= (3 << (i - 1)) + 3;
|
||||
assert_eq!(Balances::usable_balance(i), i * 10 - if expired { 0 } else { 10 });
|
||||
}
|
||||
@@ -385,20 +385,20 @@ fn classwise_delegation_works() {
|
||||
.into_iter()
|
||||
.collect(),
|
||||
);
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked1x, 5));
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 1, 3, Conviction::Locked1x, 5));
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 2, 4, Conviction::Locked1x, 5));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked1x, 5));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 1, 3, Conviction::Locked1x, 5));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 2, 4, Conviction::Locked1x, 5));
|
||||
assert_eq!(Balances::usable_balance(1), 5);
|
||||
|
||||
assert_ok!(Voting::vote(Origin::signed(2), 0, aye(10, 0)));
|
||||
assert_ok!(Voting::vote(Origin::signed(2), 1, nay(10, 0)));
|
||||
assert_ok!(Voting::vote(Origin::signed(2), 2, nay(10, 0)));
|
||||
assert_ok!(Voting::vote(Origin::signed(3), 0, nay(10, 0)));
|
||||
assert_ok!(Voting::vote(Origin::signed(3), 1, aye(10, 0)));
|
||||
assert_ok!(Voting::vote(Origin::signed(3), 2, nay(10, 0)));
|
||||
assert_ok!(Voting::vote(Origin::signed(4), 0, nay(10, 0)));
|
||||
assert_ok!(Voting::vote(Origin::signed(4), 1, nay(10, 0)));
|
||||
assert_ok!(Voting::vote(Origin::signed(4), 2, aye(10, 0)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(2), 0, aye(10, 0)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(2), 1, nay(10, 0)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(2), 2, nay(10, 0)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(3), 0, nay(10, 0)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(3), 1, aye(10, 0)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(3), 2, nay(10, 0)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(4), 0, nay(10, 0)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(4), 1, nay(10, 0)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(4), 2, aye(10, 0)));
|
||||
// 4 hasn't voted yet
|
||||
|
||||
assert_eq!(
|
||||
@@ -414,7 +414,7 @@ fn classwise_delegation_works() {
|
||||
);
|
||||
|
||||
// 4 votes nay to 3.
|
||||
assert_ok!(Voting::vote(Origin::signed(4), 3, nay(10, 0)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(4), 3, nay(10, 0)));
|
||||
assert_eq!(
|
||||
Polls::get(),
|
||||
vec![
|
||||
@@ -428,8 +428,8 @@ fn classwise_delegation_works() {
|
||||
);
|
||||
|
||||
// Redelegate for class 2 to account 3.
|
||||
assert_ok!(Voting::undelegate(Origin::signed(1), 2));
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 2, 3, Conviction::Locked1x, 5));
|
||||
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 2));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 2, 3, Conviction::Locked1x, 5));
|
||||
assert_eq!(
|
||||
Polls::get(),
|
||||
vec![
|
||||
@@ -443,12 +443,12 @@ fn classwise_delegation_works() {
|
||||
);
|
||||
|
||||
// Redelegating with a lower lock does not forget previous lock and updates correctly.
|
||||
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
|
||||
assert_ok!(Voting::undelegate(Origin::signed(1), 1));
|
||||
assert_ok!(Voting::undelegate(Origin::signed(1), 2));
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked1x, 3));
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 1, 3, Conviction::Locked1x, 3));
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 2, 4, Conviction::Locked1x, 3));
|
||||
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
|
||||
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 1));
|
||||
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 2));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked1x, 3));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 1, 3, Conviction::Locked1x, 3));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 2, 4, Conviction::Locked1x, 3));
|
||||
assert_eq!(
|
||||
Polls::get(),
|
||||
vec![
|
||||
@@ -462,24 +462,24 @@ fn classwise_delegation_works() {
|
||||
);
|
||||
assert_eq!(Balances::usable_balance(1), 5);
|
||||
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 1, 1));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 2, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 1, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 2, 1));
|
||||
// unlock does nothing since the delegation already took place.
|
||||
assert_eq!(Balances::usable_balance(1), 5);
|
||||
|
||||
// Redelegating with higher amount extends previous lock.
|
||||
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked1x, 6));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked1x, 6));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 4);
|
||||
assert_ok!(Voting::undelegate(Origin::signed(1), 1));
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 1, 3, Conviction::Locked1x, 7));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 1, 1));
|
||||
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 1));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 1, 3, Conviction::Locked1x, 7));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 1, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 3);
|
||||
assert_ok!(Voting::undelegate(Origin::signed(1), 2));
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 2, 4, Conviction::Locked1x, 8));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 2, 1));
|
||||
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 2));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 2, 4, Conviction::Locked1x, 8));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 2, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 2);
|
||||
assert_eq!(
|
||||
Polls::get(),
|
||||
@@ -499,14 +499,14 @@ fn classwise_delegation_works() {
|
||||
fn redelegation_after_vote_ending_should_keep_lock() {
|
||||
new_test_ext().execute_with(|| {
|
||||
Polls::set(vec![(0, Ongoing(Tally::new(0), 0))].into_iter().collect());
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked1x, 5));
|
||||
assert_ok!(Voting::vote(Origin::signed(2), 0, aye(10, 1)));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked1x, 5));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(2), 0, aye(10, 1)));
|
||||
Polls::set(vec![(0, Completed(1, true))].into_iter().collect());
|
||||
assert_eq!(Balances::usable_balance(1), 5);
|
||||
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 0, 3, Conviction::Locked1x, 3));
|
||||
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 3, Conviction::Locked1x, 3));
|
||||
assert_eq!(Balances::usable_balance(1), 5);
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 5);
|
||||
});
|
||||
}
|
||||
@@ -523,9 +523,9 @@ fn lock_amalgamation_valid_with_multiple_removed_votes() {
|
||||
.into_iter()
|
||||
.collect(),
|
||||
);
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 0, aye(5, 1)));
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 1, aye(10, 1)));
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 2, aye(5, 2)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 0, aye(5, 1)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 1, aye(10, 1)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 2, aye(5, 2)));
|
||||
assert_eq!(Balances::usable_balance(1), 0);
|
||||
|
||||
Polls::set(
|
||||
@@ -533,28 +533,28 @@ fn lock_amalgamation_valid_with_multiple_removed_votes() {
|
||||
.into_iter()
|
||||
.collect(),
|
||||
);
|
||||
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(0), 0));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), Some(0), 0));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 0);
|
||||
|
||||
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(0), 1));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), Some(0), 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 0);
|
||||
|
||||
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(0), 2));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), Some(0), 2));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 0);
|
||||
|
||||
run_to(3);
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 0);
|
||||
|
||||
run_to(6);
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert!(Balances::usable_balance(1) <= 5);
|
||||
|
||||
run_to(7);
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 10);
|
||||
});
|
||||
}
|
||||
@@ -562,25 +562,25 @@ fn lock_amalgamation_valid_with_multiple_removed_votes() {
|
||||
#[test]
|
||||
fn lock_amalgamation_valid_with_multiple_delegations() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked1x, 5));
|
||||
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked1x, 10));
|
||||
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked2x, 5));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked1x, 5));
|
||||
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked1x, 10));
|
||||
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked2x, 5));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 0);
|
||||
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
|
||||
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
|
||||
|
||||
run_to(3);
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 0);
|
||||
|
||||
run_to(6);
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert!(Balances::usable_balance(1) <= 5);
|
||||
|
||||
run_to(7);
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 10);
|
||||
});
|
||||
}
|
||||
@@ -589,32 +589,32 @@ fn lock_amalgamation_valid_with_multiple_delegations() {
|
||||
fn lock_amalgamation_valid_with_move_roundtrip_to_delegation() {
|
||||
new_test_ext().execute_with(|| {
|
||||
Polls::set(vec![(0, Ongoing(Tally::new(0), 0))].into_iter().collect());
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 0, aye(5, 1)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 0, aye(5, 1)));
|
||||
Polls::set(vec![(0, Completed(1, true))].into_iter().collect());
|
||||
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(0), 0));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), Some(0), 0));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 5);
|
||||
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked1x, 10));
|
||||
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked1x, 10));
|
||||
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 0);
|
||||
|
||||
Polls::set(vec![(1, Ongoing(Tally::new(0), 0))].into_iter().collect());
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 1, aye(5, 2)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 1, aye(5, 2)));
|
||||
Polls::set(vec![(1, Completed(1, true))].into_iter().collect());
|
||||
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(0), 1));
|
||||
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), Some(0), 1));
|
||||
|
||||
run_to(3);
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 0);
|
||||
|
||||
run_to(6);
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert!(Balances::usable_balance(1) <= 5);
|
||||
|
||||
run_to(7);
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 10);
|
||||
});
|
||||
}
|
||||
@@ -622,33 +622,33 @@ fn lock_amalgamation_valid_with_move_roundtrip_to_delegation() {
|
||||
#[test]
|
||||
fn lock_amalgamation_valid_with_move_roundtrip_to_casting() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked1x, 5));
|
||||
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked1x, 5));
|
||||
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
|
||||
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 5);
|
||||
|
||||
Polls::set(vec![(0, Ongoing(Tally::new(0), 0))].into_iter().collect());
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 0, aye(10, 1)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 0, aye(10, 1)));
|
||||
Polls::set(vec![(0, Completed(1, true))].into_iter().collect());
|
||||
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(0), 0));
|
||||
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), Some(0), 0));
|
||||
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 0);
|
||||
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked2x, 10));
|
||||
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked2x, 10));
|
||||
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
|
||||
|
||||
run_to(3);
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 0);
|
||||
|
||||
run_to(6);
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert!(Balances::usable_balance(1) <= 5);
|
||||
|
||||
run_to(7);
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 10);
|
||||
});
|
||||
}
|
||||
@@ -656,30 +656,30 @@ fn lock_amalgamation_valid_with_move_roundtrip_to_casting() {
|
||||
#[test]
|
||||
fn lock_aggregation_over_different_classes_with_delegation_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked1x, 5));
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 1, 2, Conviction::Locked2x, 5));
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 2, 2, Conviction::Locked1x, 10));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::Locked1x, 5));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 1, 2, Conviction::Locked2x, 5));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 2, 2, Conviction::Locked1x, 10));
|
||||
|
||||
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
|
||||
assert_ok!(Voting::undelegate(Origin::signed(1), 1));
|
||||
assert_ok!(Voting::undelegate(Origin::signed(1), 2));
|
||||
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
|
||||
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 1));
|
||||
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 2));
|
||||
|
||||
run_to(3);
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 1, 1));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 2, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 1, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 2, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 0);
|
||||
|
||||
run_to(6);
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 1, 1));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 2, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 1, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 2, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 5);
|
||||
|
||||
run_to(7);
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 1, 1));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 2, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 1, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 2, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 10);
|
||||
});
|
||||
}
|
||||
@@ -696,34 +696,34 @@ fn lock_aggregation_over_different_classes_with_casting_works() {
|
||||
.into_iter()
|
||||
.collect(),
|
||||
);
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 0, aye(5, 1)));
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 1, aye(10, 1)));
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 2, aye(5, 2)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 0, aye(5, 1)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 1, aye(10, 1)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 2, aye(5, 2)));
|
||||
Polls::set(
|
||||
vec![(0, Completed(1, true)), (1, Completed(1, true)), (2, Completed(1, true))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
);
|
||||
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(0), 0));
|
||||
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(1), 1));
|
||||
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(2), 2));
|
||||
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), Some(0), 0));
|
||||
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), Some(1), 1));
|
||||
assert_ok!(Voting::remove_vote(RuntimeOrigin::signed(1), Some(2), 2));
|
||||
|
||||
run_to(3);
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 1, 1));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 2, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 1, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 2, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 0);
|
||||
|
||||
run_to(6);
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 1, 1));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 2, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 1, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 2, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 5);
|
||||
|
||||
run_to(7);
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 1, 1));
|
||||
assert_ok!(Voting::unlock(Origin::signed(1), 2, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 0, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 1, 1));
|
||||
assert_ok!(Voting::unlock(RuntimeOrigin::signed(1), 2, 1));
|
||||
assert_eq!(Balances::usable_balance(1), 10);
|
||||
});
|
||||
}
|
||||
@@ -731,21 +731,30 @@ fn lock_aggregation_over_different_classes_with_casting_works() {
|
||||
#[test]
|
||||
fn errors_with_vote_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(Voting::vote(Origin::signed(1), 0, aye(10, 0)), Error::<Test>::NotOngoing);
|
||||
assert_noop!(Voting::vote(Origin::signed(1), 1, aye(10, 0)), Error::<Test>::NotOngoing);
|
||||
assert_noop!(Voting::vote(Origin::signed(1), 2, aye(10, 0)), Error::<Test>::NotOngoing);
|
||||
assert_noop!(
|
||||
Voting::vote(Origin::signed(1), 3, aye(11, 0)),
|
||||
Voting::vote(RuntimeOrigin::signed(1), 0, aye(10, 0)),
|
||||
Error::<Test>::NotOngoing
|
||||
);
|
||||
assert_noop!(
|
||||
Voting::vote(RuntimeOrigin::signed(1), 1, aye(10, 0)),
|
||||
Error::<Test>::NotOngoing
|
||||
);
|
||||
assert_noop!(
|
||||
Voting::vote(RuntimeOrigin::signed(1), 2, aye(10, 0)),
|
||||
Error::<Test>::NotOngoing
|
||||
);
|
||||
assert_noop!(
|
||||
Voting::vote(RuntimeOrigin::signed(1), 3, aye(11, 0)),
|
||||
Error::<Test>::InsufficientFunds
|
||||
);
|
||||
|
||||
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::None, 10));
|
||||
assert_ok!(Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::None, 10));
|
||||
assert_noop!(
|
||||
Voting::vote(Origin::signed(1), 3, aye(10, 0)),
|
||||
Voting::vote(RuntimeOrigin::signed(1), 3, aye(10, 0)),
|
||||
Error::<Test>::AlreadyDelegating
|
||||
);
|
||||
|
||||
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
|
||||
assert_ok!(Voting::undelegate(RuntimeOrigin::signed(1), 0));
|
||||
Polls::set(
|
||||
vec![
|
||||
(0, Ongoing(Tally::new(0), 0)),
|
||||
@@ -756,11 +765,11 @@ fn errors_with_vote_work() {
|
||||
.into_iter()
|
||||
.collect(),
|
||||
);
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 0, aye(10, 0)));
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 1, aye(10, 0)));
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 2, aye(10, 0)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 0, aye(10, 0)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 1, aye(10, 0)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 2, aye(10, 0)));
|
||||
assert_noop!(
|
||||
Voting::vote(Origin::signed(1), 3, aye(10, 0)),
|
||||
Voting::vote(RuntimeOrigin::signed(1), 3, aye(10, 0)),
|
||||
Error::<Test>::MaxVotesReached
|
||||
);
|
||||
});
|
||||
@@ -770,21 +779,21 @@ fn errors_with_vote_work() {
|
||||
fn errors_with_delegating_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
Voting::delegate(Origin::signed(1), 0, 2, Conviction::None, 11),
|
||||
Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::None, 11),
|
||||
Error::<Test>::InsufficientFunds
|
||||
);
|
||||
assert_noop!(
|
||||
Voting::delegate(Origin::signed(1), 3, 2, Conviction::None, 10),
|
||||
Voting::delegate(RuntimeOrigin::signed(1), 3, 2, Conviction::None, 10),
|
||||
Error::<Test>::BadClass
|
||||
);
|
||||
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(10, 0)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(10, 0)));
|
||||
assert_noop!(
|
||||
Voting::delegate(Origin::signed(1), 0, 2, Conviction::None, 10),
|
||||
Voting::delegate(RuntimeOrigin::signed(1), 0, 2, Conviction::None, 10),
|
||||
Error::<Test>::AlreadyVoting
|
||||
);
|
||||
|
||||
assert_noop!(Voting::undelegate(Origin::signed(1), 0), Error::<Test>::NotDelegating);
|
||||
assert_noop!(Voting::undelegate(RuntimeOrigin::signed(1), 0), Error::<Test>::NotDelegating);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -792,31 +801,37 @@ fn errors_with_delegating_work() {
|
||||
fn remove_other_vote_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
Voting::remove_other_vote(Origin::signed(2), 1, 0, 3),
|
||||
Voting::remove_other_vote(RuntimeOrigin::signed(2), 1, 0, 3),
|
||||
Error::<Test>::NotVoter
|
||||
);
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(10, 2)));
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(10, 2)));
|
||||
assert_noop!(
|
||||
Voting::remove_other_vote(Origin::signed(2), 1, 0, 3),
|
||||
Voting::remove_other_vote(RuntimeOrigin::signed(2), 1, 0, 3),
|
||||
Error::<Test>::NoPermission
|
||||
);
|
||||
Polls::set(vec![(3, Completed(1, true))].into_iter().collect());
|
||||
run_to(6);
|
||||
assert_noop!(
|
||||
Voting::remove_other_vote(Origin::signed(2), 1, 0, 3),
|
||||
Voting::remove_other_vote(RuntimeOrigin::signed(2), 1, 0, 3),
|
||||
Error::<Test>::NoPermissionYet
|
||||
);
|
||||
run_to(7);
|
||||
assert_ok!(Voting::remove_other_vote(Origin::signed(2), 1, 0, 3));
|
||||
assert_ok!(Voting::remove_other_vote(RuntimeOrigin::signed(2), 1, 0, 3));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_with_remove_vote_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(Voting::remove_vote(Origin::signed(1), Some(0), 3), Error::<Test>::NotVoter);
|
||||
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(10, 2)));
|
||||
assert_noop!(
|
||||
Voting::remove_vote(RuntimeOrigin::signed(1), Some(0), 3),
|
||||
Error::<Test>::NotVoter
|
||||
);
|
||||
assert_ok!(Voting::vote(RuntimeOrigin::signed(1), 3, aye(10, 2)));
|
||||
Polls::set(vec![(3, Completed(1, true))].into_iter().collect());
|
||||
assert_noop!(Voting::remove_vote(Origin::signed(1), None, 3), Error::<Test>::ClassNeeded);
|
||||
assert_noop!(
|
||||
Voting::remove_vote(RuntimeOrigin::signed(1), None, 3),
|
||||
Error::<Test>::ClassNeeded
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ benchmarks! {
|
||||
let origin = T::CancellationOrigin::successful_origin();
|
||||
let referendum_index = add_referendum::<T>(0)?;
|
||||
assert_ok!(Democracy::<T>::referendum_status(referendum_index));
|
||||
}: _<T::Origin>(origin, referendum_index)
|
||||
}: _<T::RuntimeOrigin>(origin, referendum_index)
|
||||
verify {
|
||||
// Referendum has been canceled
|
||||
assert_noop!(
|
||||
@@ -225,7 +225,7 @@ benchmarks! {
|
||||
// Add a referendum of our proposal.
|
||||
let referendum_index = add_referendum::<T>(0)?;
|
||||
assert_ok!(Democracy::<T>::referendum_status(referendum_index));
|
||||
}: _<T::Origin>(origin, hash, Some(referendum_index))
|
||||
}: _<T::RuntimeOrigin>(origin, hash, Some(referendum_index))
|
||||
verify {
|
||||
// Referendum has been canceled
|
||||
assert_noop!(
|
||||
@@ -250,7 +250,7 @@ benchmarks! {
|
||||
proposal_hash,
|
||||
(T::BlockNumber::zero(), addresses),
|
||||
);
|
||||
}: _<T::Origin>(origin, proposal_hash)
|
||||
}: _<T::RuntimeOrigin>(origin, proposal_hash)
|
||||
verify {
|
||||
// External proposal created
|
||||
ensure!(<NextExternal<T>>::exists(), "External proposal didn't work");
|
||||
@@ -259,7 +259,7 @@ benchmarks! {
|
||||
external_propose_majority {
|
||||
let origin = T::ExternalMajorityOrigin::successful_origin();
|
||||
let proposal_hash = T::Hashing::hash_of(&0);
|
||||
}: _<T::Origin>(origin, proposal_hash)
|
||||
}: _<T::RuntimeOrigin>(origin, proposal_hash)
|
||||
verify {
|
||||
// External proposal created
|
||||
ensure!(<NextExternal<T>>::exists(), "External proposal didn't work");
|
||||
@@ -268,7 +268,7 @@ benchmarks! {
|
||||
external_propose_default {
|
||||
let origin = T::ExternalDefaultOrigin::successful_origin();
|
||||
let proposal_hash = T::Hashing::hash_of(&0);
|
||||
}: _<T::Origin>(origin, proposal_hash)
|
||||
}: _<T::RuntimeOrigin>(origin, proposal_hash)
|
||||
verify {
|
||||
// External proposal created
|
||||
ensure!(<NextExternal<T>>::exists(), "External proposal didn't work");
|
||||
@@ -283,7 +283,7 @@ benchmarks! {
|
||||
let origin_fast_track = T::FastTrackOrigin::successful_origin();
|
||||
let voting_period = T::FastTrackVotingPeriod::get();
|
||||
let delay = 0u32;
|
||||
}: _<T::Origin>(origin_fast_track, proposal_hash, voting_period, delay.into())
|
||||
}: _<T::RuntimeOrigin>(origin_fast_track, proposal_hash, voting_period, delay.into())
|
||||
verify {
|
||||
assert_eq!(Democracy::<T>::referendum_count(), 1, "referendum not created")
|
||||
}
|
||||
@@ -306,7 +306,7 @@ benchmarks! {
|
||||
|
||||
let origin = T::VetoOrigin::successful_origin();
|
||||
ensure!(NextExternal::<T>::get().is_some(), "no external proposal");
|
||||
}: _<T::Origin>(origin, proposal_hash)
|
||||
}: _<T::RuntimeOrigin>(origin, proposal_hash)
|
||||
verify {
|
||||
assert!(NextExternal::<T>::get().is_none());
|
||||
let (_, new_vetoers) = <Blacklist<T>>::get(&proposal_hash).ok_or("no blacklist")?;
|
||||
@@ -322,7 +322,7 @@ benchmarks! {
|
||||
}
|
||||
|
||||
let cancel_origin = T::CancelProposalOrigin::successful_origin();
|
||||
}: _<T::Origin>(cancel_origin, 0)
|
||||
}: _<T::RuntimeOrigin>(cancel_origin, 0)
|
||||
|
||||
cancel_referendum {
|
||||
let referendum_index = add_referendum::<T>(0)?;
|
||||
|
||||
@@ -253,7 +253,9 @@ pub mod pallet {
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config + Sized {
|
||||
type Proposal: Parameter + Dispatchable<Origin = Self::Origin> + From<Call<Self>>;
|
||||
type Proposal: Parameter
|
||||
+ Dispatchable<RuntimeOrigin = Self::RuntimeOrigin>
|
||||
+ From<Call<Self>>;
|
||||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
||||
|
||||
/// Currency type for this pallet.
|
||||
@@ -289,25 +291,25 @@ pub mod pallet {
|
||||
|
||||
/// Origin from which the next tabled referendum may be forced. This is a normal
|
||||
/// "super-majority-required" referendum.
|
||||
type ExternalOrigin: EnsureOrigin<Self::Origin>;
|
||||
type ExternalOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// Origin from which the next tabled referendum may be forced; this allows for the tabling
|
||||
/// of a majority-carries referendum.
|
||||
type ExternalMajorityOrigin: EnsureOrigin<Self::Origin>;
|
||||
type ExternalMajorityOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// Origin from which the next tabled referendum may be forced; this allows for the tabling
|
||||
/// of a negative-turnout-bias (default-carries) referendum.
|
||||
type ExternalDefaultOrigin: EnsureOrigin<Self::Origin>;
|
||||
type ExternalDefaultOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// Origin from which the next majority-carries (or more permissive) referendum may be
|
||||
/// tabled to vote according to the `FastTrackVotingPeriod` asynchronously in a similar
|
||||
/// manner to the emergency origin. It retains its threshold method.
|
||||
type FastTrackOrigin: EnsureOrigin<Self::Origin>;
|
||||
type FastTrackOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// Origin from which the next majority-carries (or more permissive) referendum may be
|
||||
/// tabled to vote immediately and asynchronously in a similar manner to the emergency
|
||||
/// origin. It retains its threshold method.
|
||||
type InstantOrigin: EnsureOrigin<Self::Origin>;
|
||||
type InstantOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// Indicator for whether an emergency origin is even allowed to happen. Some chains may
|
||||
/// want to set this permanently to `false`, others may want to condition it on things such
|
||||
@@ -320,13 +322,13 @@ pub mod pallet {
|
||||
type FastTrackVotingPeriod: Get<Self::BlockNumber>;
|
||||
|
||||
/// Origin from which any referendum may be cancelled in an emergency.
|
||||
type CancellationOrigin: EnsureOrigin<Self::Origin>;
|
||||
type CancellationOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// Origin from which proposals may be blacklisted.
|
||||
type BlacklistOrigin: EnsureOrigin<Self::Origin>;
|
||||
type BlacklistOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// Origin from which a proposal may be cancelled and its backers slashed.
|
||||
type CancelProposalOrigin: EnsureOrigin<Self::Origin>;
|
||||
type CancelProposalOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// Origin for anyone able to veto proposals.
|
||||
///
|
||||
@@ -334,7 +336,7 @@ pub mod pallet {
|
||||
///
|
||||
/// The number of Vetoers for a proposal must be small, extrinsics are weighted according to
|
||||
/// [MAX_VETOERS](./const.MAX_VETOERS.html)
|
||||
type VetoOrigin: EnsureOrigin<Self::Origin, Success = Self::AccountId>;
|
||||
type VetoOrigin: EnsureOrigin<Self::RuntimeOrigin, Success = Self::AccountId>;
|
||||
|
||||
/// Period in blocks where an external proposal may not be re-submitted after being vetoed.
|
||||
#[pallet::constant]
|
||||
@@ -345,7 +347,7 @@ pub mod pallet {
|
||||
type PreimageByteDeposit: Get<BalanceOf<Self>>;
|
||||
|
||||
/// An origin that can provide a preimage using operational extrinsics.
|
||||
type OperationalPreimageOrigin: EnsureOrigin<Self::Origin, Success = Self::AccountId>;
|
||||
type OperationalPreimageOrigin: EnsureOrigin<Self::RuntimeOrigin, Success = Self::AccountId>;
|
||||
|
||||
/// Handler for the unbalanced reduction when slashing a preimage deposit.
|
||||
type Slash: OnUnbalanced<NegativeImbalanceOf<Self>>;
|
||||
|
||||
@@ -85,7 +85,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
@@ -111,7 +111,7 @@ parameter_types! {
|
||||
}
|
||||
impl pallet_scheduler::Config for Test {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type PalletsOrigin = OriginCaller;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type MaximumWeight = MaximumSchedulerWeight;
|
||||
@@ -240,7 +240,7 @@ fn set_balance_proposal_hash(value: u64) -> H256 {
|
||||
fn set_balance_proposal_hash_and_note(value: u64) -> H256 {
|
||||
let p = set_balance_proposal(value);
|
||||
let h = BlakeTwo256::hash(&p[..]);
|
||||
match Democracy::note_preimage(Origin::signed(6), p) {
|
||||
match Democracy::note_preimage(RuntimeOrigin::signed(6), p) {
|
||||
Ok(_) => (),
|
||||
Err(x) if x == Error::<Test>::DuplicatePreimage.into() => (),
|
||||
Err(x) => panic!("{:?}", x),
|
||||
@@ -249,11 +249,11 @@ fn set_balance_proposal_hash_and_note(value: u64) -> H256 {
|
||||
}
|
||||
|
||||
fn propose_set_balance(who: u64, value: u64, delay: u64) -> DispatchResult {
|
||||
Democracy::propose(Origin::signed(who), set_balance_proposal_hash(value), delay)
|
||||
Democracy::propose(RuntimeOrigin::signed(who), set_balance_proposal_hash(value), delay)
|
||||
}
|
||||
|
||||
fn propose_set_balance_and_note(who: u64, value: u64, delay: u64) -> DispatchResult {
|
||||
Democracy::propose(Origin::signed(who), set_balance_proposal_hash_and_note(value), delay)
|
||||
Democracy::propose(RuntimeOrigin::signed(who), set_balance_proposal_hash_and_note(value), delay)
|
||||
}
|
||||
|
||||
fn next_block() {
|
||||
|
||||
@@ -28,8 +28,8 @@ fn cancel_referendum_should_work() {
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
|
||||
assert_ok!(Democracy::cancel_referendum(Origin::root(), r.into()));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
assert_ok!(Democracy::cancel_referendum(RuntimeOrigin::root(), r.into()));
|
||||
assert_eq!(Democracy::lowest_unbaked(), 0);
|
||||
|
||||
next_block();
|
||||
@@ -51,14 +51,17 @@ fn cancel_queued_should_work() {
|
||||
// start of 2 => next referendum scheduled.
|
||||
fast_forward_to(2);
|
||||
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), 0, aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), 0, aye(1)));
|
||||
|
||||
fast_forward_to(4);
|
||||
|
||||
assert!(pallet_scheduler::Agenda::<Test>::get(6)[0].is_some());
|
||||
|
||||
assert_noop!(Democracy::cancel_queued(Origin::root(), 1), Error::<Test>::ProposalMissing);
|
||||
assert_ok!(Democracy::cancel_queued(Origin::root(), 0));
|
||||
assert_noop!(
|
||||
Democracy::cancel_queued(RuntimeOrigin::root(), 1),
|
||||
Error::<Test>::ProposalMissing
|
||||
);
|
||||
assert_ok!(Democracy::cancel_queued(RuntimeOrigin::root(), 0));
|
||||
assert!(pallet_scheduler::Agenda::<Test>::get(6)[0].is_none());
|
||||
});
|
||||
}
|
||||
@@ -75,8 +78,8 @@ fn emergency_cancel_should_work() {
|
||||
);
|
||||
assert!(Democracy::referendum_status(r).is_ok());
|
||||
|
||||
assert_noop!(Democracy::emergency_cancel(Origin::signed(3), r), BadOrigin);
|
||||
assert_ok!(Democracy::emergency_cancel(Origin::signed(4), r));
|
||||
assert_noop!(Democracy::emergency_cancel(RuntimeOrigin::signed(3), r), BadOrigin);
|
||||
assert_ok!(Democracy::emergency_cancel(RuntimeOrigin::signed(4), r));
|
||||
assert!(Democracy::referendum_info(r).is_none());
|
||||
|
||||
// some time later...
|
||||
@@ -89,7 +92,7 @@ fn emergency_cancel_should_work() {
|
||||
);
|
||||
assert!(Democracy::referendum_status(r).is_ok());
|
||||
assert_noop!(
|
||||
Democracy::emergency_cancel(Origin::signed(4), r),
|
||||
Democracy::emergency_cancel(RuntimeOrigin::signed(4), r),
|
||||
Error::<Test>::AlreadyCanceled,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -29,33 +29,33 @@ fn single_proposal_should_work_with_delegation() {
|
||||
fast_forward_to(2);
|
||||
|
||||
// Delegate first vote.
|
||||
assert_ok!(Democracy::delegate(Origin::signed(2), 1, Conviction::None, 20));
|
||||
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::None, 20));
|
||||
let r = 0;
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
assert_eq!(tally(r), Tally { ayes: 3, nays: 0, turnout: 30 });
|
||||
|
||||
// Delegate a second vote.
|
||||
assert_ok!(Democracy::delegate(Origin::signed(3), 1, Conviction::None, 30));
|
||||
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(3), 1, Conviction::None, 30));
|
||||
assert_eq!(tally(r), Tally { ayes: 6, nays: 0, turnout: 60 });
|
||||
|
||||
// Reduce first vote.
|
||||
assert_ok!(Democracy::delegate(Origin::signed(2), 1, Conviction::None, 10));
|
||||
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::None, 10));
|
||||
assert_eq!(tally(r), Tally { ayes: 5, nays: 0, turnout: 50 });
|
||||
|
||||
// Second vote delegates to first; we don't do tiered delegation, so it doesn't get used.
|
||||
assert_ok!(Democracy::delegate(Origin::signed(3), 2, Conviction::None, 30));
|
||||
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(3), 2, Conviction::None, 30));
|
||||
assert_eq!(tally(r), Tally { ayes: 2, nays: 0, turnout: 20 });
|
||||
|
||||
// Main voter cancels their vote
|
||||
assert_ok!(Democracy::remove_vote(Origin::signed(1), r));
|
||||
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(1), r));
|
||||
assert_eq!(tally(r), Tally { ayes: 0, nays: 0, turnout: 0 });
|
||||
|
||||
// First delegator delegates half funds with conviction; nothing changes yet.
|
||||
assert_ok!(Democracy::delegate(Origin::signed(2), 1, Conviction::Locked1x, 10));
|
||||
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::Locked1x, 10));
|
||||
assert_eq!(tally(r), Tally { ayes: 0, nays: 0, turnout: 0 });
|
||||
|
||||
// Main voter reinstates their vote
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
assert_eq!(tally(r), Tally { ayes: 11, nays: 0, turnout: 20 });
|
||||
});
|
||||
}
|
||||
@@ -64,7 +64,7 @@ fn single_proposal_should_work_with_delegation() {
|
||||
fn self_delegation_not_allowed() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
Democracy::delegate(Origin::signed(1), 1, Conviction::None, 10),
|
||||
Democracy::delegate(RuntimeOrigin::signed(1), 1, Conviction::None, 10),
|
||||
Error::<Test>::Nonsense,
|
||||
);
|
||||
});
|
||||
@@ -80,14 +80,14 @@ fn cyclic_delegation_should_unwind() {
|
||||
fast_forward_to(2);
|
||||
|
||||
// Check behavior with cycle.
|
||||
assert_ok!(Democracy::delegate(Origin::signed(2), 1, Conviction::None, 20));
|
||||
assert_ok!(Democracy::delegate(Origin::signed(3), 2, Conviction::None, 30));
|
||||
assert_ok!(Democracy::delegate(Origin::signed(1), 3, Conviction::None, 10));
|
||||
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::None, 20));
|
||||
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(3), 2, Conviction::None, 30));
|
||||
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(1), 3, Conviction::None, 10));
|
||||
let r = 0;
|
||||
assert_ok!(Democracy::undelegate(Origin::signed(3)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(3), r, aye(3)));
|
||||
assert_ok!(Democracy::undelegate(Origin::signed(1)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, nay(1)));
|
||||
assert_ok!(Democracy::undelegate(RuntimeOrigin::signed(3)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(3), r, aye(3)));
|
||||
assert_ok!(Democracy::undelegate(RuntimeOrigin::signed(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, nay(1)));
|
||||
|
||||
// Delegated vote is counted.
|
||||
assert_eq!(tally(r), Tally { ayes: 3, nays: 3, turnout: 60 });
|
||||
@@ -105,13 +105,13 @@ fn single_proposal_should_work_with_vote_and_delegation() {
|
||||
fast_forward_to(2);
|
||||
|
||||
let r = 0;
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(2), r, nay(2)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(2), r, nay(2)));
|
||||
assert_eq!(tally(r), Tally { ayes: 1, nays: 2, turnout: 30 });
|
||||
|
||||
// Delegate vote.
|
||||
assert_ok!(Democracy::remove_vote(Origin::signed(2), r));
|
||||
assert_ok!(Democracy::delegate(Origin::signed(2), 1, Conviction::None, 20));
|
||||
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(2), r));
|
||||
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::None, 20));
|
||||
// Delegated vote replaces the explicit vote.
|
||||
assert_eq!(tally(r), Tally { ayes: 3, nays: 0, turnout: 30 });
|
||||
});
|
||||
@@ -125,12 +125,12 @@ fn single_proposal_should_work_with_undelegation() {
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 1));
|
||||
|
||||
// Delegate and undelegate vote.
|
||||
assert_ok!(Democracy::delegate(Origin::signed(2), 1, Conviction::None, 20));
|
||||
assert_ok!(Democracy::undelegate(Origin::signed(2)));
|
||||
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::None, 20));
|
||||
assert_ok!(Democracy::undelegate(RuntimeOrigin::signed(2)));
|
||||
|
||||
fast_forward_to(2);
|
||||
let r = 0;
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
|
||||
// Delegated vote is not counted.
|
||||
assert_eq!(tally(r), Tally { ayes: 1, nays: 0, turnout: 10 });
|
||||
@@ -143,11 +143,11 @@ fn single_proposal_should_work_with_delegation_and_vote() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let r = begin_referendum();
|
||||
// Delegate, undelegate and vote.
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
|
||||
assert_ok!(Democracy::delegate(Origin::signed(2), 1, Conviction::None, 20));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::None, 20));
|
||||
assert_eq!(tally(r), Tally { ayes: 3, nays: 0, turnout: 30 });
|
||||
assert_ok!(Democracy::undelegate(Origin::signed(2)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(2), r, aye(2)));
|
||||
assert_ok!(Democracy::undelegate(RuntimeOrigin::signed(2)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(2), r, aye(2)));
|
||||
// Delegated vote is not counted.
|
||||
assert_eq!(tally(r), Tally { ayes: 3, nays: 0, turnout: 30 });
|
||||
});
|
||||
@@ -159,8 +159,8 @@ fn conviction_should_be_honored_in_delegation() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let r = begin_referendum();
|
||||
// Delegate and vote.
|
||||
assert_ok!(Democracy::delegate(Origin::signed(2), 1, Conviction::Locked6x, 20));
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
|
||||
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::Locked6x, 20));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
// Delegated vote is huge.
|
||||
assert_eq!(tally(r), Tally { ayes: 121, nays: 0, turnout: 30 });
|
||||
});
|
||||
@@ -171,8 +171,12 @@ fn split_vote_delegation_should_be_ignored() {
|
||||
// If transactor voted, delegated vote is overwritten.
|
||||
new_test_ext().execute_with(|| {
|
||||
let r = begin_referendum();
|
||||
assert_ok!(Democracy::delegate(Origin::signed(2), 1, Conviction::Locked6x, 20));
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, AccountVote::Split { aye: 10, nay: 0 }));
|
||||
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::Locked6x, 20));
|
||||
assert_ok!(Democracy::vote(
|
||||
RuntimeOrigin::signed(1),
|
||||
r,
|
||||
AccountVote::Split { aye: 10, nay: 0 }
|
||||
));
|
||||
// Delegated vote is huge.
|
||||
assert_eq!(tally(r), Tally { ayes: 1, nays: 0, turnout: 10 });
|
||||
});
|
||||
@@ -184,8 +188,8 @@ fn redelegation_keeps_lock() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let r = begin_referendum();
|
||||
// Delegate and vote.
|
||||
assert_ok!(Democracy::delegate(Origin::signed(2), 1, Conviction::Locked6x, 20));
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
|
||||
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::Locked6x, 20));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
// Delegated vote is huge.
|
||||
assert_eq!(tally(r), Tally { ayes: 121, nays: 0, turnout: 30 });
|
||||
|
||||
@@ -196,14 +200,14 @@ fn redelegation_keeps_lock() {
|
||||
assert_eq!(VotingOf::<Test>::get(2).prior(), &prior_lock);
|
||||
|
||||
// Delegate someone else at a lower conviction and amount
|
||||
assert_ok!(Democracy::delegate(Origin::signed(2), 3, Conviction::None, 10));
|
||||
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 3, Conviction::None, 10));
|
||||
|
||||
// 6x prior should appear w/ locked balance.
|
||||
prior_lock.accumulate(98, 20);
|
||||
assert_eq!(VotingOf::<Test>::get(2).prior(), &prior_lock);
|
||||
assert_eq!(VotingOf::<Test>::get(2).locked_balance(), 20);
|
||||
// Unlock shouldn't work
|
||||
assert_ok!(Democracy::unlock(Origin::signed(2), 2));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(2), 2));
|
||||
assert_eq!(VotingOf::<Test>::get(2).prior(), &prior_lock);
|
||||
assert_eq!(VotingOf::<Test>::get(2).locked_balance(), 20);
|
||||
|
||||
@@ -211,7 +215,7 @@ fn redelegation_keeps_lock() {
|
||||
|
||||
// Now unlock can remove the prior lock and reduce the locked amount.
|
||||
assert_eq!(VotingOf::<Test>::get(2).prior(), &prior_lock);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(2), 2));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(2), 2));
|
||||
assert_eq!(VotingOf::<Test>::get(2).prior(), &vote::PriorLock::default());
|
||||
assert_eq!(VotingOf::<Test>::get(2).locked_balance(), 10);
|
||||
});
|
||||
|
||||
@@ -24,53 +24,56 @@ fn veto_external_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
assert_ok!(Democracy::external_propose(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
));
|
||||
assert!(<NextExternal<Test>>::exists());
|
||||
|
||||
let h = set_balance_proposal_hash_and_note(2);
|
||||
assert_ok!(Democracy::veto_external(Origin::signed(3), h));
|
||||
assert_ok!(Democracy::veto_external(RuntimeOrigin::signed(3), h));
|
||||
// cancelled.
|
||||
assert!(!<NextExternal<Test>>::exists());
|
||||
// fails - same proposal can't be resubmitted.
|
||||
assert_noop!(
|
||||
Democracy::external_propose(Origin::signed(2), set_balance_proposal_hash(2),),
|
||||
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal_hash(2),),
|
||||
Error::<Test>::ProposalBlacklisted
|
||||
);
|
||||
|
||||
fast_forward_to(1);
|
||||
// fails as we're still in cooloff period.
|
||||
assert_noop!(
|
||||
Democracy::external_propose(Origin::signed(2), set_balance_proposal_hash(2),),
|
||||
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal_hash(2),),
|
||||
Error::<Test>::ProposalBlacklisted
|
||||
);
|
||||
|
||||
fast_forward_to(2);
|
||||
// works; as we're out of the cooloff period.
|
||||
assert_ok!(Democracy::external_propose(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
));
|
||||
assert!(<NextExternal<Test>>::exists());
|
||||
|
||||
// 3 can't veto the same thing twice.
|
||||
assert_noop!(Democracy::veto_external(Origin::signed(3), h), Error::<Test>::AlreadyVetoed);
|
||||
assert_noop!(
|
||||
Democracy::veto_external(RuntimeOrigin::signed(3), h),
|
||||
Error::<Test>::AlreadyVetoed
|
||||
);
|
||||
|
||||
// 4 vetoes.
|
||||
assert_ok!(Democracy::veto_external(Origin::signed(4), h));
|
||||
assert_ok!(Democracy::veto_external(RuntimeOrigin::signed(4), h));
|
||||
// cancelled again.
|
||||
assert!(!<NextExternal<Test>>::exists());
|
||||
|
||||
fast_forward_to(3);
|
||||
// same proposal fails as we're still in cooloff
|
||||
assert_noop!(
|
||||
Democracy::external_propose(Origin::signed(2), set_balance_proposal_hash(2),),
|
||||
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal_hash(2),),
|
||||
Error::<Test>::ProposalBlacklisted
|
||||
);
|
||||
// different proposal works fine.
|
||||
assert_ok!(Democracy::external_propose(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(3),
|
||||
));
|
||||
});
|
||||
@@ -82,18 +85,21 @@ fn external_blacklisting_should_work() {
|
||||
System::set_block_number(0);
|
||||
|
||||
assert_ok!(Democracy::external_propose(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
));
|
||||
|
||||
let hash = set_balance_proposal_hash(2);
|
||||
assert_ok!(Democracy::blacklist(Origin::root(), hash, None));
|
||||
assert_ok!(Democracy::blacklist(RuntimeOrigin::root(), hash, None));
|
||||
|
||||
fast_forward_to(2);
|
||||
assert_noop!(Democracy::referendum_status(0), Error::<Test>::ReferendumInvalid);
|
||||
|
||||
assert_noop!(
|
||||
Democracy::external_propose(Origin::signed(2), set_balance_proposal_hash_and_note(2),),
|
||||
Democracy::external_propose(
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
),
|
||||
Error::<Test>::ProposalBlacklisted,
|
||||
);
|
||||
});
|
||||
@@ -104,15 +110,15 @@ fn external_referendum_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
assert_noop!(
|
||||
Democracy::external_propose(Origin::signed(1), set_balance_proposal_hash(2),),
|
||||
Democracy::external_propose(RuntimeOrigin::signed(1), set_balance_proposal_hash(2),),
|
||||
BadOrigin,
|
||||
);
|
||||
assert_ok!(Democracy::external_propose(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
));
|
||||
assert_noop!(
|
||||
Democracy::external_propose(Origin::signed(2), set_balance_proposal_hash(1),),
|
||||
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal_hash(1),),
|
||||
Error::<Test>::DuplicateProposal
|
||||
);
|
||||
fast_forward_to(2);
|
||||
@@ -134,11 +140,14 @@ fn external_majority_referendum_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
assert_noop!(
|
||||
Democracy::external_propose_majority(Origin::signed(1), set_balance_proposal_hash(2)),
|
||||
Democracy::external_propose_majority(
|
||||
RuntimeOrigin::signed(1),
|
||||
set_balance_proposal_hash(2)
|
||||
),
|
||||
BadOrigin,
|
||||
);
|
||||
assert_ok!(Democracy::external_propose_majority(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
set_balance_proposal_hash_and_note(2)
|
||||
));
|
||||
fast_forward_to(2);
|
||||
@@ -160,11 +169,14 @@ fn external_default_referendum_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
assert_noop!(
|
||||
Democracy::external_propose_default(Origin::signed(3), set_balance_proposal_hash(2)),
|
||||
Democracy::external_propose_default(
|
||||
RuntimeOrigin::signed(3),
|
||||
set_balance_proposal_hash(2)
|
||||
),
|
||||
BadOrigin,
|
||||
);
|
||||
assert_ok!(Democracy::external_propose_default(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
set_balance_proposal_hash_and_note(2)
|
||||
));
|
||||
fast_forward_to(2);
|
||||
@@ -186,7 +198,7 @@ fn external_and_public_interleaving_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
assert_ok!(Democracy::external_propose(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(1),
|
||||
));
|
||||
assert_ok!(propose_set_balance_and_note(6, 2, 2));
|
||||
@@ -206,7 +218,7 @@ fn external_and_public_interleaving_works() {
|
||||
);
|
||||
// replenish external
|
||||
assert_ok!(Democracy::external_propose(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(3),
|
||||
));
|
||||
|
||||
@@ -240,7 +252,7 @@ fn external_and_public_interleaving_works() {
|
||||
);
|
||||
// replenish external
|
||||
assert_ok!(Democracy::external_propose(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(5),
|
||||
));
|
||||
|
||||
@@ -259,7 +271,7 @@ fn external_and_public_interleaving_works() {
|
||||
);
|
||||
// replenish both
|
||||
assert_ok!(Democracy::external_propose(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(7),
|
||||
));
|
||||
assert_ok!(propose_set_balance_and_note(6, 4, 2));
|
||||
@@ -281,7 +293,7 @@ fn external_and_public_interleaving_works() {
|
||||
assert_ok!(propose_set_balance_and_note(6, 6, 2));
|
||||
// cancel external
|
||||
let h = set_balance_proposal_hash_and_note(7);
|
||||
assert_ok!(Democracy::veto_external(Origin::signed(3), h));
|
||||
assert_ok!(Democracy::veto_external(RuntimeOrigin::signed(3), h));
|
||||
|
||||
fast_forward_to(12);
|
||||
|
||||
|
||||
@@ -25,15 +25,15 @@ fn fast_track_referendum_works() {
|
||||
System::set_block_number(0);
|
||||
let h = set_balance_proposal_hash_and_note(2);
|
||||
assert_noop!(
|
||||
Democracy::fast_track(Origin::signed(5), h, 3, 2),
|
||||
Democracy::fast_track(RuntimeOrigin::signed(5), h, 3, 2),
|
||||
Error::<Test>::ProposalMissing
|
||||
);
|
||||
assert_ok!(Democracy::external_propose_majority(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
set_balance_proposal_hash_and_note(2)
|
||||
));
|
||||
assert_noop!(Democracy::fast_track(Origin::signed(1), h, 3, 2), BadOrigin);
|
||||
assert_ok!(Democracy::fast_track(Origin::signed(5), h, 2, 0));
|
||||
assert_noop!(Democracy::fast_track(RuntimeOrigin::signed(1), h, 3, 2), BadOrigin);
|
||||
assert_ok!(Democracy::fast_track(RuntimeOrigin::signed(5), h, 2, 0));
|
||||
assert_eq!(
|
||||
Democracy::referendum_status(0),
|
||||
Ok(ReferendumStatus {
|
||||
@@ -53,25 +53,25 @@ fn instant_referendum_works() {
|
||||
System::set_block_number(0);
|
||||
let h = set_balance_proposal_hash_and_note(2);
|
||||
assert_noop!(
|
||||
Democracy::fast_track(Origin::signed(5), h, 3, 2),
|
||||
Democracy::fast_track(RuntimeOrigin::signed(5), h, 3, 2),
|
||||
Error::<Test>::ProposalMissing
|
||||
);
|
||||
assert_ok!(Democracy::external_propose_majority(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
set_balance_proposal_hash_and_note(2)
|
||||
));
|
||||
assert_noop!(Democracy::fast_track(Origin::signed(1), h, 3, 2), BadOrigin);
|
||||
assert_noop!(Democracy::fast_track(Origin::signed(5), h, 1, 0), BadOrigin);
|
||||
assert_noop!(Democracy::fast_track(RuntimeOrigin::signed(1), h, 3, 2), BadOrigin);
|
||||
assert_noop!(Democracy::fast_track(RuntimeOrigin::signed(5), h, 1, 0), BadOrigin);
|
||||
assert_noop!(
|
||||
Democracy::fast_track(Origin::signed(6), h, 1, 0),
|
||||
Democracy::fast_track(RuntimeOrigin::signed(6), h, 1, 0),
|
||||
Error::<Test>::InstantNotAllowed
|
||||
);
|
||||
INSTANT_ALLOWED.with(|v| *v.borrow_mut() = true);
|
||||
assert_noop!(
|
||||
Democracy::fast_track(Origin::signed(6), h, 0, 0),
|
||||
Democracy::fast_track(RuntimeOrigin::signed(6), h, 0, 0),
|
||||
Error::<Test>::VotingPeriodLow
|
||||
);
|
||||
assert_ok!(Democracy::fast_track(Origin::signed(6), h, 1, 0));
|
||||
assert_ok!(Democracy::fast_track(RuntimeOrigin::signed(6), h, 1, 0));
|
||||
assert_eq!(
|
||||
Democracy::referendum_status(0),
|
||||
Ok(ReferendumStatus {
|
||||
@@ -102,13 +102,13 @@ fn instant_next_block_referendum_backed() {
|
||||
|
||||
// propose with majority origin
|
||||
assert_ok!(Democracy::external_propose_majority(
|
||||
Origin::signed(majority_origin_id),
|
||||
RuntimeOrigin::signed(majority_origin_id),
|
||||
proposal_hash
|
||||
));
|
||||
|
||||
// fast track with instant origin and voting period pointing to the next block
|
||||
assert_ok!(Democracy::fast_track(
|
||||
Origin::signed(instant_origin_id),
|
||||
RuntimeOrigin::signed(instant_origin_id),
|
||||
proposal_hash,
|
||||
voting_period,
|
||||
delay
|
||||
@@ -145,11 +145,11 @@ fn fast_track_referendum_fails_when_no_simple_majority() {
|
||||
System::set_block_number(0);
|
||||
let h = set_balance_proposal_hash_and_note(2);
|
||||
assert_ok!(Democracy::external_propose(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(2)
|
||||
));
|
||||
assert_noop!(
|
||||
Democracy::fast_track(Origin::signed(5), h, 3, 2),
|
||||
Democracy::fast_track(RuntimeOrigin::signed(5), h, 3, 2),
|
||||
Error::<Test>::NotSimpleMajority
|
||||
);
|
||||
});
|
||||
|
||||
@@ -47,11 +47,11 @@ fn lock_voting_should_work() {
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, nay(5, 10)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(2), r, aye(4, 20)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(3), r, aye(3, 30)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(4), r, aye(2, 40)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(5), r, nay(1, 50)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, nay(5, 10)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(2), r, aye(4, 20)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(3), r, aye(3, 30)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(4), r, aye(2, 40)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r, nay(1, 50)));
|
||||
assert_eq!(tally(r), Tally { ayes: 250, nays: 100, turnout: 150 });
|
||||
|
||||
// All balances are currently locked.
|
||||
@@ -62,20 +62,20 @@ fn lock_voting_should_work() {
|
||||
fast_forward_to(2);
|
||||
|
||||
// Referendum passed; 1 and 5 didn't get their way and can now reap and unlock.
|
||||
assert_ok!(Democracy::remove_vote(Origin::signed(1), r));
|
||||
assert_ok!(Democracy::unlock(Origin::signed(1), 1));
|
||||
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(1), r));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(1), 1));
|
||||
// Anyone can reap and unlock anyone else's in this context.
|
||||
assert_ok!(Democracy::remove_other_vote(Origin::signed(2), 5, r));
|
||||
assert_ok!(Democracy::unlock(Origin::signed(2), 5));
|
||||
assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(2), 5, r));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(2), 5));
|
||||
|
||||
// 2, 3, 4 got their way with the vote, so they cannot be reaped by others.
|
||||
assert_noop!(
|
||||
Democracy::remove_other_vote(Origin::signed(1), 2, r),
|
||||
Democracy::remove_other_vote(RuntimeOrigin::signed(1), 2, r),
|
||||
Error::<Test>::NoPermission
|
||||
);
|
||||
// However, they can be unvoted by the owner, though it will make no difference to the lock.
|
||||
assert_ok!(Democracy::remove_vote(Origin::signed(2), r));
|
||||
assert_ok!(Democracy::unlock(Origin::signed(2), 2));
|
||||
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(2), r));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(2), 2));
|
||||
|
||||
assert_eq!(Balances::locks(1), vec![]);
|
||||
assert_eq!(Balances::locks(2), vec![the_lock(20)]);
|
||||
@@ -87,35 +87,35 @@ fn lock_voting_should_work() {
|
||||
fast_forward_to(7);
|
||||
// No change yet...
|
||||
assert_noop!(
|
||||
Democracy::remove_other_vote(Origin::signed(1), 4, r),
|
||||
Democracy::remove_other_vote(RuntimeOrigin::signed(1), 4, r),
|
||||
Error::<Test>::NoPermission
|
||||
);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(1), 4));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(1), 4));
|
||||
assert_eq!(Balances::locks(4), vec![the_lock(40)]);
|
||||
fast_forward_to(8);
|
||||
// 4 should now be able to reap and unlock
|
||||
assert_ok!(Democracy::remove_other_vote(Origin::signed(1), 4, r));
|
||||
assert_ok!(Democracy::unlock(Origin::signed(1), 4));
|
||||
assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(1), 4, r));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(1), 4));
|
||||
assert_eq!(Balances::locks(4), vec![]);
|
||||
|
||||
fast_forward_to(13);
|
||||
assert_noop!(
|
||||
Democracy::remove_other_vote(Origin::signed(1), 3, r),
|
||||
Democracy::remove_other_vote(RuntimeOrigin::signed(1), 3, r),
|
||||
Error::<Test>::NoPermission
|
||||
);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(1), 3));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(1), 3));
|
||||
assert_eq!(Balances::locks(3), vec![the_lock(30)]);
|
||||
fast_forward_to(14);
|
||||
assert_ok!(Democracy::remove_other_vote(Origin::signed(1), 3, r));
|
||||
assert_ok!(Democracy::unlock(Origin::signed(1), 3));
|
||||
assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(1), 3, r));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(1), 3));
|
||||
assert_eq!(Balances::locks(3), vec![]);
|
||||
|
||||
// 2 doesn't need to reap_vote here because it was already done before.
|
||||
fast_forward_to(25);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(1), 2));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(1), 2));
|
||||
assert_eq!(Balances::locks(2), vec![the_lock(20)]);
|
||||
fast_forward_to(26);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(1), 2));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(1), 2));
|
||||
assert_eq!(Balances::locks(2), vec![]);
|
||||
});
|
||||
}
|
||||
@@ -130,13 +130,13 @@ fn no_locks_without_conviction_should_work() {
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(0, 10)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(0, 10)));
|
||||
|
||||
fast_forward_to(2);
|
||||
|
||||
assert_eq!(Balances::free_balance(42), 2);
|
||||
assert_ok!(Democracy::remove_other_vote(Origin::signed(2), 1, r));
|
||||
assert_ok!(Democracy::unlock(Origin::signed(2), 1));
|
||||
assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(2), 1, r));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(2), 1));
|
||||
assert_eq!(Balances::locks(1), vec![]);
|
||||
});
|
||||
}
|
||||
@@ -150,11 +150,11 @@ fn lock_voting_should_work_with_delegation() {
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, nay(5, 10)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(2), r, aye(4, 20)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(3), r, aye(3, 30)));
|
||||
assert_ok!(Democracy::delegate(Origin::signed(4), 2, Conviction::Locked2x, 40));
|
||||
assert_ok!(Democracy::vote(Origin::signed(5), r, nay(1, 50)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, nay(5, 10)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(2), r, aye(4, 20)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(3), r, aye(3, 30)));
|
||||
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(4), 2, Conviction::Locked2x, 40));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r, nay(1, 50)));
|
||||
|
||||
assert_eq!(tally(r), Tally { ayes: 250, nays: 100, turnout: 150 });
|
||||
|
||||
@@ -173,7 +173,7 @@ fn setup_three_referenda() -> (u32, u32, u32) {
|
||||
VoteThreshold::SimpleMajority,
|
||||
0,
|
||||
);
|
||||
assert_ok!(Democracy::vote(Origin::signed(5), r1, aye(4, 10)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r1, aye(4, 10)));
|
||||
|
||||
let r2 = Democracy::inject_referendum(
|
||||
2,
|
||||
@@ -181,7 +181,7 @@ fn setup_three_referenda() -> (u32, u32, u32) {
|
||||
VoteThreshold::SimpleMajority,
|
||||
0,
|
||||
);
|
||||
assert_ok!(Democracy::vote(Origin::signed(5), r2, aye(3, 20)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r2, aye(3, 20)));
|
||||
|
||||
let r3 = Democracy::inject_referendum(
|
||||
2,
|
||||
@@ -189,7 +189,7 @@ fn setup_three_referenda() -> (u32, u32, u32) {
|
||||
VoteThreshold::SimpleMajority,
|
||||
0,
|
||||
);
|
||||
assert_ok!(Democracy::vote(Origin::signed(5), r3, aye(2, 50)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r3, aye(2, 50)));
|
||||
|
||||
fast_forward_to(2);
|
||||
|
||||
@@ -206,36 +206,36 @@ fn prior_lockvotes_should_be_enforced() {
|
||||
|
||||
fast_forward_to(7);
|
||||
assert_noop!(
|
||||
Democracy::remove_other_vote(Origin::signed(1), 5, r.2),
|
||||
Democracy::remove_other_vote(RuntimeOrigin::signed(1), 5, r.2),
|
||||
Error::<Test>::NoPermission
|
||||
);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert_eq!(Balances::locks(5), vec![the_lock(50)]);
|
||||
fast_forward_to(8);
|
||||
assert_ok!(Democracy::remove_other_vote(Origin::signed(1), 5, r.2));
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(1), 5, r.2));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert_eq!(Balances::locks(5), vec![the_lock(20)]);
|
||||
fast_forward_to(13);
|
||||
assert_noop!(
|
||||
Democracy::remove_other_vote(Origin::signed(1), 5, r.1),
|
||||
Democracy::remove_other_vote(RuntimeOrigin::signed(1), 5, r.1),
|
||||
Error::<Test>::NoPermission
|
||||
);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert_eq!(Balances::locks(5), vec![the_lock(20)]);
|
||||
fast_forward_to(14);
|
||||
assert_ok!(Democracy::remove_other_vote(Origin::signed(1), 5, r.1));
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(1), 5, r.1));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert_eq!(Balances::locks(5), vec![the_lock(10)]);
|
||||
fast_forward_to(25);
|
||||
assert_noop!(
|
||||
Democracy::remove_other_vote(Origin::signed(1), 5, r.0),
|
||||
Democracy::remove_other_vote(RuntimeOrigin::signed(1), 5, r.0),
|
||||
Error::<Test>::NoPermission
|
||||
);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert_eq!(Balances::locks(5), vec![the_lock(10)]);
|
||||
fast_forward_to(26);
|
||||
assert_ok!(Democracy::remove_other_vote(Origin::signed(1), 5, r.0));
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(1), 5, r.0));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert_eq!(Balances::locks(5), vec![]);
|
||||
});
|
||||
}
|
||||
@@ -249,27 +249,27 @@ fn single_consolidation_of_lockvotes_should_work_as_before() {
|
||||
// r.2 locked 50 until 2 + 2 * 3 = #8
|
||||
|
||||
fast_forward_to(7);
|
||||
assert_ok!(Democracy::remove_vote(Origin::signed(5), r.2));
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.2));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert_eq!(Balances::locks(5), vec![the_lock(50)]);
|
||||
fast_forward_to(8);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert_eq!(Balances::locks(5), vec![the_lock(20)]);
|
||||
|
||||
fast_forward_to(13);
|
||||
assert_ok!(Democracy::remove_vote(Origin::signed(5), r.1));
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.1));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert_eq!(Balances::locks(5), vec![the_lock(20)]);
|
||||
fast_forward_to(14);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert_eq!(Balances::locks(5), vec![the_lock(10)]);
|
||||
|
||||
fast_forward_to(25);
|
||||
assert_ok!(Democracy::remove_vote(Origin::signed(5), r.0));
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.0));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert_eq!(Balances::locks(5), vec![the_lock(10)]);
|
||||
fast_forward_to(26);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert_eq!(Balances::locks(5), vec![]);
|
||||
});
|
||||
}
|
||||
@@ -282,20 +282,20 @@ fn multi_consolidation_of_lockvotes_should_be_conservative() {
|
||||
// r.1 locked 20 until 2 + 4 * 3 = #14
|
||||
// r.2 locked 50 until 2 + 2 * 3 = #8
|
||||
|
||||
assert_ok!(Democracy::remove_vote(Origin::signed(5), r.2));
|
||||
assert_ok!(Democracy::remove_vote(Origin::signed(5), r.1));
|
||||
assert_ok!(Democracy::remove_vote(Origin::signed(5), r.0));
|
||||
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.2));
|
||||
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.1));
|
||||
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.0));
|
||||
|
||||
fast_forward_to(8);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert!(Balances::locks(5)[0].amount >= 20);
|
||||
|
||||
fast_forward_to(14);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert!(Balances::locks(5)[0].amount >= 10);
|
||||
|
||||
fast_forward_to(26);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert_eq!(Balances::locks(5), vec![]);
|
||||
});
|
||||
}
|
||||
@@ -310,32 +310,32 @@ fn locks_should_persist_from_voting_to_delegation() {
|
||||
VoteThreshold::SimpleMajority,
|
||||
0,
|
||||
);
|
||||
assert_ok!(Democracy::vote(Origin::signed(5), r, aye(4, 10)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r, aye(4, 10)));
|
||||
fast_forward_to(2);
|
||||
assert_ok!(Democracy::remove_vote(Origin::signed(5), r));
|
||||
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r));
|
||||
// locked 10 until #26.
|
||||
|
||||
assert_ok!(Democracy::delegate(Origin::signed(5), 1, Conviction::Locked3x, 20));
|
||||
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(5), 1, Conviction::Locked3x, 20));
|
||||
// locked 20.
|
||||
assert!(Balances::locks(5)[0].amount == 20);
|
||||
|
||||
assert_ok!(Democracy::undelegate(Origin::signed(5)));
|
||||
assert_ok!(Democracy::undelegate(RuntimeOrigin::signed(5)));
|
||||
// locked 20 until #14
|
||||
|
||||
fast_forward_to(13);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert!(Balances::locks(5)[0].amount == 20);
|
||||
|
||||
fast_forward_to(14);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert!(Balances::locks(5)[0].amount >= 10);
|
||||
|
||||
fast_forward_to(25);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert!(Balances::locks(5)[0].amount >= 10);
|
||||
|
||||
fast_forward_to(26);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert_eq!(Balances::locks(5), vec![]);
|
||||
});
|
||||
}
|
||||
@@ -344,8 +344,8 @@ fn locks_should_persist_from_voting_to_delegation() {
|
||||
fn locks_should_persist_from_delegation_to_voting() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
assert_ok!(Democracy::delegate(Origin::signed(5), 1, Conviction::Locked5x, 5));
|
||||
assert_ok!(Democracy::undelegate(Origin::signed(5)));
|
||||
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(5), 1, Conviction::Locked5x, 5));
|
||||
assert_ok!(Democracy::undelegate(RuntimeOrigin::signed(5)));
|
||||
// locked 5 until 16 * 3 = #48
|
||||
|
||||
let r = setup_three_referenda();
|
||||
@@ -353,24 +353,24 @@ fn locks_should_persist_from_delegation_to_voting() {
|
||||
// r.1 locked 20 until 2 + 4 * 3 = #14
|
||||
// r.2 locked 50 until 2 + 2 * 3 = #8
|
||||
|
||||
assert_ok!(Democracy::remove_vote(Origin::signed(5), r.2));
|
||||
assert_ok!(Democracy::remove_vote(Origin::signed(5), r.1));
|
||||
assert_ok!(Democracy::remove_vote(Origin::signed(5), r.0));
|
||||
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.2));
|
||||
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.1));
|
||||
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.0));
|
||||
|
||||
fast_forward_to(8);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert!(Balances::locks(5)[0].amount >= 20);
|
||||
|
||||
fast_forward_to(14);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert!(Balances::locks(5)[0].amount >= 10);
|
||||
|
||||
fast_forward_to(26);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert!(Balances::locks(5)[0].amount >= 5);
|
||||
|
||||
fast_forward_to(48);
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert_eq!(Balances::locks(5), vec![]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ fn missing_preimage_should_fail() {
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
|
||||
next_block();
|
||||
next_block();
|
||||
@@ -44,9 +44,9 @@ fn preimage_deposit_should_be_required_and_returned() {
|
||||
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 100);
|
||||
assert_noop!(
|
||||
if operational {
|
||||
Democracy::note_preimage_operational(Origin::signed(6), vec![0; 500])
|
||||
Democracy::note_preimage_operational(RuntimeOrigin::signed(6), vec![0; 500])
|
||||
} else {
|
||||
Democracy::note_preimage(Origin::signed(6), vec![0; 500])
|
||||
Democracy::note_preimage(RuntimeOrigin::signed(6), vec![0; 500])
|
||||
},
|
||||
BalancesError::<Test, _>::InsufficientBalance,
|
||||
);
|
||||
@@ -58,7 +58,7 @@ fn preimage_deposit_should_be_required_and_returned() {
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
|
||||
assert_eq!(Balances::reserved_balance(6), 12);
|
||||
|
||||
@@ -76,21 +76,25 @@ fn preimage_deposit_should_be_reapable_earlier_by_owner() {
|
||||
new_test_ext_execute_with_cond(|operational| {
|
||||
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 1);
|
||||
assert_ok!(if operational {
|
||||
Democracy::note_preimage_operational(Origin::signed(6), set_balance_proposal(2))
|
||||
Democracy::note_preimage_operational(RuntimeOrigin::signed(6), set_balance_proposal(2))
|
||||
} else {
|
||||
Democracy::note_preimage(Origin::signed(6), set_balance_proposal(2))
|
||||
Democracy::note_preimage(RuntimeOrigin::signed(6), set_balance_proposal(2))
|
||||
});
|
||||
|
||||
assert_eq!(Balances::reserved_balance(6), 12);
|
||||
|
||||
next_block();
|
||||
assert_noop!(
|
||||
Democracy::reap_preimage(Origin::signed(6), set_balance_proposal_hash(2), u32::MAX),
|
||||
Democracy::reap_preimage(
|
||||
RuntimeOrigin::signed(6),
|
||||
set_balance_proposal_hash(2),
|
||||
u32::MAX
|
||||
),
|
||||
Error::<Test>::TooEarly
|
||||
);
|
||||
next_block();
|
||||
assert_ok!(Democracy::reap_preimage(
|
||||
Origin::signed(6),
|
||||
RuntimeOrigin::signed(6),
|
||||
set_balance_proposal_hash(2),
|
||||
u32::MAX
|
||||
));
|
||||
@@ -104,15 +108,19 @@ fn preimage_deposit_should_be_reapable_earlier_by_owner() {
|
||||
fn preimage_deposit_should_be_reapable() {
|
||||
new_test_ext_execute_with_cond(|operational| {
|
||||
assert_noop!(
|
||||
Democracy::reap_preimage(Origin::signed(5), set_balance_proposal_hash(2), u32::MAX),
|
||||
Democracy::reap_preimage(
|
||||
RuntimeOrigin::signed(5),
|
||||
set_balance_proposal_hash(2),
|
||||
u32::MAX
|
||||
),
|
||||
Error::<Test>::PreimageMissing
|
||||
);
|
||||
|
||||
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 1);
|
||||
assert_ok!(if operational {
|
||||
Democracy::note_preimage_operational(Origin::signed(6), set_balance_proposal(2))
|
||||
Democracy::note_preimage_operational(RuntimeOrigin::signed(6), set_balance_proposal(2))
|
||||
} else {
|
||||
Democracy::note_preimage(Origin::signed(6), set_balance_proposal(2))
|
||||
Democracy::note_preimage(RuntimeOrigin::signed(6), set_balance_proposal(2))
|
||||
});
|
||||
assert_eq!(Balances::reserved_balance(6), 12);
|
||||
|
||||
@@ -120,13 +128,17 @@ fn preimage_deposit_should_be_reapable() {
|
||||
next_block();
|
||||
next_block();
|
||||
assert_noop!(
|
||||
Democracy::reap_preimage(Origin::signed(5), set_balance_proposal_hash(2), u32::MAX),
|
||||
Democracy::reap_preimage(
|
||||
RuntimeOrigin::signed(5),
|
||||
set_balance_proposal_hash(2),
|
||||
u32::MAX
|
||||
),
|
||||
Error::<Test>::TooEarly
|
||||
);
|
||||
|
||||
next_block();
|
||||
assert_ok!(Democracy::reap_preimage(
|
||||
Origin::signed(5),
|
||||
RuntimeOrigin::signed(5),
|
||||
set_balance_proposal_hash(2),
|
||||
u32::MAX
|
||||
));
|
||||
@@ -147,16 +159,16 @@ fn noting_imminent_preimage_for_free_should_work() {
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
1,
|
||||
);
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
|
||||
assert_noop!(
|
||||
if operational {
|
||||
Democracy::note_imminent_preimage_operational(
|
||||
Origin::signed(6),
|
||||
RuntimeOrigin::signed(6),
|
||||
set_balance_proposal(2),
|
||||
)
|
||||
} else {
|
||||
Democracy::note_imminent_preimage(Origin::signed(6), set_balance_proposal(2))
|
||||
Democracy::note_imminent_preimage(RuntimeOrigin::signed(6), set_balance_proposal(2))
|
||||
},
|
||||
Error::<Test>::NotImminent
|
||||
);
|
||||
@@ -164,7 +176,10 @@ fn noting_imminent_preimage_for_free_should_work() {
|
||||
next_block();
|
||||
|
||||
// Now we're in the dispatch queue it's all good.
|
||||
assert_ok!(Democracy::note_imminent_preimage(Origin::signed(6), set_balance_proposal(2)));
|
||||
assert_ok!(Democracy::note_imminent_preimage(
|
||||
RuntimeOrigin::signed(6),
|
||||
set_balance_proposal(2)
|
||||
));
|
||||
|
||||
next_block();
|
||||
|
||||
@@ -177,11 +192,11 @@ fn reaping_imminent_preimage_should_fail() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let h = set_balance_proposal_hash_and_note(2);
|
||||
let r = Democracy::inject_referendum(3, h, VoteThreshold::SuperMajorityApprove, 1);
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
next_block();
|
||||
next_block();
|
||||
assert_noop!(
|
||||
Democracy::reap_preimage(Origin::signed(6), h, u32::MAX),
|
||||
Democracy::reap_preimage(RuntimeOrigin::signed(6), h, u32::MAX),
|
||||
Error::<Test>::Imminent
|
||||
);
|
||||
});
|
||||
@@ -198,21 +213,24 @@ fn note_imminent_preimage_can_only_be_successful_once() {
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
1,
|
||||
);
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
next_block();
|
||||
|
||||
// First time works
|
||||
assert_ok!(Democracy::note_imminent_preimage(Origin::signed(6), set_balance_proposal(2)));
|
||||
assert_ok!(Democracy::note_imminent_preimage(
|
||||
RuntimeOrigin::signed(6),
|
||||
set_balance_proposal(2)
|
||||
));
|
||||
|
||||
// Second time fails
|
||||
assert_noop!(
|
||||
Democracy::note_imminent_preimage(Origin::signed(6), set_balance_proposal(2)),
|
||||
Democracy::note_imminent_preimage(RuntimeOrigin::signed(6), set_balance_proposal(2)),
|
||||
Error::<Test>::DuplicatePreimage
|
||||
);
|
||||
|
||||
// Fails from any user
|
||||
assert_noop!(
|
||||
Democracy::note_imminent_preimage(Origin::signed(5), set_balance_proposal(2)),
|
||||
Democracy::note_imminent_preimage(RuntimeOrigin::signed(5), set_balance_proposal(2)),
|
||||
Error::<Test>::DuplicatePreimage
|
||||
);
|
||||
});
|
||||
|
||||
@@ -35,10 +35,10 @@ fn backing_for_should_work() {
|
||||
fn deposit_for_proposals_should_be_taken() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 5));
|
||||
assert_ok!(Democracy::second(Origin::signed(2), 0, u32::MAX));
|
||||
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::MAX));
|
||||
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::MAX));
|
||||
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::MAX));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(2), 0, u32::MAX));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0, u32::MAX));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0, u32::MAX));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0, u32::MAX));
|
||||
assert_eq!(Balances::free_balance(1), 5);
|
||||
assert_eq!(Balances::free_balance(2), 15);
|
||||
assert_eq!(Balances::free_balance(5), 35);
|
||||
@@ -49,10 +49,10 @@ fn deposit_for_proposals_should_be_taken() {
|
||||
fn deposit_for_proposals_should_be_returned() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 5));
|
||||
assert_ok!(Democracy::second(Origin::signed(2), 0, u32::MAX));
|
||||
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::MAX));
|
||||
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::MAX));
|
||||
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::MAX));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(2), 0, u32::MAX));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0, u32::MAX));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0, u32::MAX));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0, u32::MAX));
|
||||
fast_forward_to(3);
|
||||
assert_eq!(Balances::free_balance(1), 10);
|
||||
assert_eq!(Balances::free_balance(2), 20);
|
||||
@@ -79,7 +79,7 @@ fn poor_seconder_should_not_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(propose_set_balance_and_note(2, 2, 11));
|
||||
assert_noop!(
|
||||
Democracy::second(Origin::signed(1), 0, u32::MAX),
|
||||
Democracy::second(RuntimeOrigin::signed(1), 0, u32::MAX),
|
||||
BalancesError::<Test, _>::InsufficientBalance
|
||||
);
|
||||
});
|
||||
@@ -89,7 +89,10 @@ fn poor_seconder_should_not_work() {
|
||||
fn invalid_seconds_upper_bound_should_not_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 5));
|
||||
assert_noop!(Democracy::second(Origin::signed(2), 0, 0), Error::<Test>::WrongUpperBound);
|
||||
assert_noop!(
|
||||
Democracy::second(RuntimeOrigin::signed(2), 0, 0),
|
||||
Error::<Test>::WrongUpperBound
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -98,8 +101,8 @@ fn cancel_proposal_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 2));
|
||||
assert_ok!(propose_set_balance_and_note(1, 4, 4));
|
||||
assert_noop!(Democracy::cancel_proposal(Origin::signed(1), 0), BadOrigin);
|
||||
assert_ok!(Democracy::cancel_proposal(Origin::root(), 0));
|
||||
assert_noop!(Democracy::cancel_proposal(RuntimeOrigin::signed(1), 0), BadOrigin);
|
||||
assert_ok!(Democracy::cancel_proposal(RuntimeOrigin::root(), 0));
|
||||
System::assert_last_event(crate::Event::ProposalCanceled { prop_index: 0 }.into());
|
||||
assert_eq!(Democracy::backing_for(0), None);
|
||||
assert_eq!(Democracy::backing_for(1), Some(4));
|
||||
@@ -115,8 +118,8 @@ fn blacklisting_should_work() {
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 2));
|
||||
assert_ok!(propose_set_balance_and_note(1, 4, 4));
|
||||
|
||||
assert_noop!(Democracy::blacklist(Origin::signed(1), hash, None), BadOrigin);
|
||||
assert_ok!(Democracy::blacklist(Origin::root(), hash, None));
|
||||
assert_noop!(Democracy::blacklist(RuntimeOrigin::signed(1), hash, None), BadOrigin);
|
||||
assert_ok!(Democracy::blacklist(RuntimeOrigin::root(), hash, None));
|
||||
|
||||
assert_eq!(Democracy::backing_for(0), None);
|
||||
assert_eq!(Democracy::backing_for(1), Some(4));
|
||||
@@ -127,7 +130,7 @@ fn blacklisting_should_work() {
|
||||
|
||||
let hash = set_balance_proposal_hash(4);
|
||||
assert_ok!(Democracy::referendum_status(0));
|
||||
assert_ok!(Democracy::blacklist(Origin::root(), hash, Some(0)));
|
||||
assert_ok!(Democracy::blacklist(RuntimeOrigin::root(), hash, Some(0)));
|
||||
assert_noop!(Democracy::referendum_status(0), Error::<Test>::ReferendumInvalid);
|
||||
});
|
||||
}
|
||||
@@ -140,10 +143,10 @@ fn runners_up_should_come_after() {
|
||||
assert_ok!(propose_set_balance_and_note(1, 4, 4));
|
||||
assert_ok!(propose_set_balance_and_note(1, 3, 3));
|
||||
fast_forward_to(2);
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), 0, aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), 0, aye(1)));
|
||||
fast_forward_to(4);
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), 1, aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), 1, aye(1)));
|
||||
fast_forward_to(6);
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), 2, aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), 2, aye(1)));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ fn simple_passing_should_work() {
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
assert_eq!(tally(r), Tally { ayes: 1, nays: 0, turnout: 10 });
|
||||
assert_eq!(Democracy::lowest_unbaked(), 0);
|
||||
next_block();
|
||||
@@ -47,7 +47,7 @@ fn simple_failing_should_work() {
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, nay(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, nay(1)));
|
||||
assert_eq!(tally(r), Tally { ayes: 0, nays: 1, turnout: 10 });
|
||||
|
||||
next_block();
|
||||
@@ -73,13 +73,13 @@ fn ooo_inject_referendums_should_work() {
|
||||
0,
|
||||
);
|
||||
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r2, aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r2, aye(1)));
|
||||
assert_eq!(tally(r2), Tally { ayes: 1, nays: 0, turnout: 10 });
|
||||
|
||||
next_block();
|
||||
assert_eq!(Balances::free_balance(42), 2);
|
||||
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r1, aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r1, aye(1)));
|
||||
assert_eq!(tally(r1), Tally { ayes: 1, nays: 0, turnout: 10 });
|
||||
|
||||
next_block();
|
||||
@@ -96,12 +96,12 @@ fn delayed_enactment_should_work() {
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
1,
|
||||
);
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(2), r, aye(2)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(3), r, aye(3)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(4), r, aye(4)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(5), r, aye(5)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(6), r, aye(6)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(2), r, aye(2)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(3), r, aye(3)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(4), r, aye(4)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r, aye(5)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(6), r, aye(6)));
|
||||
|
||||
assert_eq!(tally(r), Tally { ayes: 21, nays: 0, turnout: 210 });
|
||||
|
||||
@@ -134,10 +134,10 @@ fn lowest_unbaked_should_be_sensible() {
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r1, aye(1)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r2, aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r1, aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r2, aye(1)));
|
||||
// r3 is canceled
|
||||
assert_ok!(Democracy::cancel_referendum(Origin::root(), r3.into()));
|
||||
assert_ok!(Democracy::cancel_referendum(RuntimeOrigin::root(), r3.into()));
|
||||
assert_eq!(Democracy::lowest_unbaked(), 0);
|
||||
|
||||
next_block();
|
||||
|
||||
@@ -24,7 +24,7 @@ fn overvoting_should_fail() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let r = begin_referendum();
|
||||
assert_noop!(
|
||||
Democracy::vote(Origin::signed(1), r, aye(2)),
|
||||
Democracy::vote(RuntimeOrigin::signed(1), r, aye(2)),
|
||||
Error::<Test>::InsufficientFunds
|
||||
);
|
||||
});
|
||||
@@ -35,9 +35,12 @@ fn split_voting_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let r = begin_referendum();
|
||||
let v = AccountVote::Split { aye: 40, nay: 20 };
|
||||
assert_noop!(Democracy::vote(Origin::signed(5), r, v), Error::<Test>::InsufficientFunds);
|
||||
assert_noop!(
|
||||
Democracy::vote(RuntimeOrigin::signed(5), r, v),
|
||||
Error::<Test>::InsufficientFunds
|
||||
);
|
||||
let v = AccountVote::Split { aye: 30, nay: 20 };
|
||||
assert_ok!(Democracy::vote(Origin::signed(5), r, v));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r, v));
|
||||
|
||||
assert_eq!(tally(r), Tally { ayes: 3, nays: 2, turnout: 50 });
|
||||
});
|
||||
@@ -48,10 +51,10 @@ fn split_vote_cancellation_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let r = begin_referendum();
|
||||
let v = AccountVote::Split { aye: 30, nay: 20 };
|
||||
assert_ok!(Democracy::vote(Origin::signed(5), r, v));
|
||||
assert_ok!(Democracy::remove_vote(Origin::signed(5), r));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r, v));
|
||||
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r));
|
||||
assert_eq!(tally(r), Tally { ayes: 0, nays: 0, turnout: 0 });
|
||||
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
|
||||
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
|
||||
assert_eq!(Balances::locks(5), vec![]);
|
||||
});
|
||||
}
|
||||
@@ -66,7 +69,7 @@ fn single_proposal_should_work() {
|
||||
|
||||
// start of 2 => next referendum scheduled.
|
||||
fast_forward_to(2);
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
|
||||
assert_eq!(Democracy::referendum_count(), 1);
|
||||
assert_eq!(
|
||||
@@ -108,12 +111,12 @@ fn controversial_voting_should_work() {
|
||||
0,
|
||||
);
|
||||
|
||||
assert_ok!(Democracy::vote(Origin::signed(1), r, big_aye(1)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(2), r, big_nay(2)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(3), r, big_nay(3)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(4), r, big_aye(4)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(5), r, big_nay(5)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(6), r, big_aye(6)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, big_aye(1)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(2), r, big_nay(2)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(3), r, big_nay(3)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(4), r, big_aye(4)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r, big_nay(5)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(6), r, big_aye(6)));
|
||||
|
||||
assert_eq!(tally(r), Tally { ayes: 110, nays: 100, turnout: 210 });
|
||||
|
||||
@@ -133,8 +136,8 @@ fn controversial_low_turnout_voting_should_work() {
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
assert_ok!(Democracy::vote(Origin::signed(5), r, big_nay(5)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(6), r, big_aye(6)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r, big_nay(5)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(6), r, big_aye(6)));
|
||||
|
||||
assert_eq!(tally(r), Tally { ayes: 60, nays: 50, turnout: 110 });
|
||||
|
||||
@@ -157,9 +160,9 @@ fn passing_low_turnout_voting_should_work() {
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
assert_ok!(Democracy::vote(Origin::signed(4), r, big_aye(4)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(5), r, big_nay(5)));
|
||||
assert_ok!(Democracy::vote(Origin::signed(6), r, big_aye(6)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(4), r, big_aye(4)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r, big_nay(5)));
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(6), r, big_aye(6)));
|
||||
assert_eq!(tally(r), Tally { ayes: 100, nays: 50, turnout: 150 });
|
||||
|
||||
next_block();
|
||||
|
||||
@@ -700,7 +700,7 @@ pub mod pallet {
|
||||
|
||||
/// Origin that can control this pallet. Note that any action taken by this origin (such)
|
||||
/// as providing an emergency solution is not checked. Thus, it must be a trusted origin.
|
||||
type ForceOrigin: EnsureOrigin<Self::Origin>;
|
||||
type ForceOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// The configuration of benchmarking.
|
||||
type BenchmarkingConfig: BenchmarkingConfig;
|
||||
@@ -1828,7 +1828,7 @@ mod tests {
|
||||
use crate::{
|
||||
mock::{
|
||||
multi_phase_events, raw_solution, roll_to, AccountId, ExtBuilder, MockWeightInfo,
|
||||
MockedWeightInfo, MultiPhase, Origin, Runtime, SignedMaxSubmissions, System,
|
||||
MockedWeightInfo, MultiPhase, Runtime, RuntimeOrigin, SignedMaxSubmissions, System,
|
||||
TargetIndex, Targets,
|
||||
},
|
||||
Phase,
|
||||
@@ -2030,7 +2030,10 @@ mod tests {
|
||||
score: ElectionScore { minimal_stake: (5 + s).into(), ..Default::default() },
|
||||
..Default::default()
|
||||
};
|
||||
assert_ok!(MultiPhase::submit(crate::mock::Origin::signed(99), Box::new(solution)));
|
||||
assert_ok!(MultiPhase::submit(
|
||||
crate::mock::RuntimeOrigin::signed(99),
|
||||
Box::new(solution)
|
||||
));
|
||||
}
|
||||
|
||||
// an unexpected call to elect.
|
||||
@@ -2057,7 +2060,10 @@ mod tests {
|
||||
assert!(MultiPhase::current_phase().is_signed());
|
||||
|
||||
let solution = raw_solution();
|
||||
assert_ok!(MultiPhase::submit(crate::mock::Origin::signed(99), Box::new(solution)));
|
||||
assert_ok!(MultiPhase::submit(
|
||||
crate::mock::RuntimeOrigin::signed(99),
|
||||
Box::new(solution)
|
||||
));
|
||||
|
||||
roll_to(30);
|
||||
assert_ok!(MultiPhase::elect());
|
||||
@@ -2098,7 +2104,7 @@ mod tests {
|
||||
// ensure this solution is valid.
|
||||
assert!(MultiPhase::queued_solution().is_none());
|
||||
assert_ok!(MultiPhase::submit_unsigned(
|
||||
crate::mock::Origin::none(),
|
||||
crate::mock::RuntimeOrigin::none(),
|
||||
Box::new(solution),
|
||||
witness
|
||||
));
|
||||
@@ -2176,12 +2182,12 @@ mod tests {
|
||||
|
||||
// no single account can trigger this
|
||||
assert_noop!(
|
||||
MultiPhase::governance_fallback(Origin::signed(99), None, None),
|
||||
MultiPhase::governance_fallback(RuntimeOrigin::signed(99), None, None),
|
||||
DispatchError::BadOrigin
|
||||
);
|
||||
|
||||
// only root can
|
||||
assert_ok!(MultiPhase::governance_fallback(Origin::root(), None, None));
|
||||
assert_ok!(MultiPhase::governance_fallback(RuntimeOrigin::root(), None, None));
|
||||
// something is queued now
|
||||
assert!(MultiPhase::queued_solution().is_some());
|
||||
// next election call with fix everything.;
|
||||
|
||||
@@ -199,7 +199,7 @@ pub fn witness() -> SolutionOrSnapshotSize {
|
||||
impl frame_system::Config for Runtime {
|
||||
type SS58Prefix = ();
|
||||
type BaseCallFilter = frame_support::traits::Everything;
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = BlockNumber;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
|
||||
@@ -529,7 +529,7 @@ mod tests {
|
||||
use crate::{
|
||||
mock::{
|
||||
balances, raw_solution, roll_to, Balances, ExtBuilder, MockedWeightInfo, MultiPhase,
|
||||
Origin, Runtime, SignedMaxRefunds, SignedMaxSubmissions, SignedMaxWeight,
|
||||
Runtime, RuntimeOrigin, SignedMaxRefunds, SignedMaxSubmissions, SignedMaxWeight,
|
||||
},
|
||||
Error, Perbill, Phase,
|
||||
};
|
||||
@@ -546,7 +546,7 @@ mod tests {
|
||||
let solution = raw_solution();
|
||||
|
||||
assert_noop!(
|
||||
MultiPhase::submit(Origin::signed(10), Box::new(solution)),
|
||||
MultiPhase::submit(RuntimeOrigin::signed(10), Box::new(solution)),
|
||||
Error::<Runtime>::PreDispatchEarlySubmission,
|
||||
);
|
||||
})
|
||||
@@ -561,7 +561,7 @@ mod tests {
|
||||
let solution = raw_solution();
|
||||
assert_eq!(balances(&99), (100, 0));
|
||||
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(99), Box::new(solution)));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(solution)));
|
||||
|
||||
assert_eq!(balances(&99), (95, 5));
|
||||
assert_eq!(MultiPhase::signed_submissions().iter().next().unwrap().deposit, 5);
|
||||
@@ -577,7 +577,7 @@ mod tests {
|
||||
let solution = raw_solution();
|
||||
assert_eq!(balances(&99), (100, 0));
|
||||
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(99), Box::new(solution)));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(solution)));
|
||||
assert_eq!(balances(&99), (95, 5));
|
||||
|
||||
assert!(MultiPhase::finalize_signed_phase());
|
||||
@@ -597,7 +597,7 @@ mod tests {
|
||||
// make the solution invalid.
|
||||
solution.score.minimal_stake += 1;
|
||||
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(99), Box::new(solution)));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(solution)));
|
||||
assert_eq!(balances(&99), (95, 5));
|
||||
|
||||
// no good solution was stored.
|
||||
@@ -618,11 +618,11 @@ mod tests {
|
||||
assert_eq!(balances(&999), (100, 0));
|
||||
|
||||
// submit as correct.
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(99), Box::new(solution.clone())));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(solution.clone())));
|
||||
|
||||
// make the solution invalid and weaker.
|
||||
solution.score.minimal_stake -= 1;
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(999), Box::new(solution)));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(999), Box::new(solution)));
|
||||
assert_eq!(balances(&99), (95, 5));
|
||||
assert_eq!(balances(&999), (95, 5));
|
||||
|
||||
@@ -648,7 +648,7 @@ mod tests {
|
||||
score: ElectionScore { minimal_stake: (5 + s).into(), ..Default::default() },
|
||||
..Default::default()
|
||||
};
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(99), Box::new(solution)));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(solution)));
|
||||
}
|
||||
|
||||
// weaker.
|
||||
@@ -658,7 +658,7 @@ mod tests {
|
||||
};
|
||||
|
||||
assert_noop!(
|
||||
MultiPhase::submit(Origin::signed(99), Box::new(solution)),
|
||||
MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(solution)),
|
||||
Error::<Runtime>::SignedQueueFull,
|
||||
);
|
||||
})
|
||||
@@ -679,7 +679,7 @@ mod tests {
|
||||
let mut solution = raw_solution();
|
||||
solution.score.minimal_stake -= s as u128;
|
||||
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(account), Box::new(solution)));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(account), Box::new(solution)));
|
||||
assert_eq!(balances(&account), (95, 5));
|
||||
}
|
||||
|
||||
@@ -719,7 +719,7 @@ mod tests {
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(99), Box::new(solution)));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(solution)));
|
||||
|
||||
// This is 10% better, so does not meet the 20% threshold and is therefore rejected.
|
||||
solution = RawSolution {
|
||||
@@ -732,7 +732,7 @@ mod tests {
|
||||
};
|
||||
|
||||
assert_noop!(
|
||||
MultiPhase::submit(Origin::signed(99), Box::new(solution)),
|
||||
MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(solution)),
|
||||
Error::<Runtime>::SignedQueueFull,
|
||||
);
|
||||
|
||||
@@ -746,7 +746,7 @@ mod tests {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(99), Box::new(solution)));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(solution)));
|
||||
})
|
||||
}
|
||||
|
||||
@@ -764,7 +764,7 @@ mod tests {
|
||||
score: ElectionScore { minimal_stake: (5 + s).into(), ..Default::default() },
|
||||
..Default::default()
|
||||
};
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(account), Box::new(solution)));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(account), Box::new(solution)));
|
||||
assert_eq!(balances(&account), (95, 5));
|
||||
}
|
||||
|
||||
@@ -781,7 +781,7 @@ mod tests {
|
||||
score: ElectionScore { minimal_stake: 20, ..Default::default() },
|
||||
..Default::default()
|
||||
};
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(999), Box::new(solution)));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(999), Box::new(solution)));
|
||||
|
||||
// the one with score 5 was rejected, the new one inserted.
|
||||
assert_eq!(
|
||||
@@ -809,14 +809,14 @@ mod tests {
|
||||
score: ElectionScore { minimal_stake: (5 + s).into(), ..Default::default() },
|
||||
..Default::default()
|
||||
};
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(99), Box::new(solution)));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(solution)));
|
||||
}
|
||||
|
||||
let solution = RawSolution {
|
||||
score: ElectionScore { minimal_stake: 4, ..Default::default() },
|
||||
..Default::default()
|
||||
};
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(99), Box::new(solution)));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(solution)));
|
||||
|
||||
assert_eq!(
|
||||
MultiPhase::signed_submissions()
|
||||
@@ -831,7 +831,7 @@ mod tests {
|
||||
score: ElectionScore { minimal_stake: 5, ..Default::default() },
|
||||
..Default::default()
|
||||
};
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(99), Box::new(solution)));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(solution)));
|
||||
|
||||
// the one with score 5 was rejected, the new one inserted.
|
||||
assert_eq!(
|
||||
@@ -856,7 +856,7 @@ mod tests {
|
||||
score: ElectionScore { minimal_stake: (5 + s).into(), ..Default::default() },
|
||||
..Default::default()
|
||||
};
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(99), Box::new(solution)));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(solution)));
|
||||
}
|
||||
|
||||
assert_eq!(balances(&99).1, 2 * 5);
|
||||
@@ -867,7 +867,7 @@ mod tests {
|
||||
score: ElectionScore { minimal_stake: 20, ..Default::default() },
|
||||
..Default::default()
|
||||
};
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(999), Box::new(solution)));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(999), Box::new(solution)));
|
||||
|
||||
// got one bond back.
|
||||
assert_eq!(balances(&99).1, 2 * 4);
|
||||
@@ -886,7 +886,7 @@ mod tests {
|
||||
score: ElectionScore { minimal_stake: (5 + i).into(), ..Default::default() },
|
||||
..Default::default()
|
||||
};
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(99), Box::new(solution)));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(solution)));
|
||||
}
|
||||
assert_eq!(
|
||||
MultiPhase::signed_submissions()
|
||||
@@ -902,7 +902,7 @@ mod tests {
|
||||
..Default::default()
|
||||
};
|
||||
assert_noop!(
|
||||
MultiPhase::submit(Origin::signed(99), Box::new(solution)),
|
||||
MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(solution)),
|
||||
Error::<Runtime>::SignedQueueFull,
|
||||
);
|
||||
})
|
||||
@@ -924,18 +924,18 @@ mod tests {
|
||||
let solution = raw_solution();
|
||||
|
||||
// submit a correct one.
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(99), Box::new(solution.clone())));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(solution.clone())));
|
||||
|
||||
// make the solution invalidly better and submit. This ought to be slashed.
|
||||
let mut solution_999 = solution.clone();
|
||||
solution_999.score.minimal_stake += 1;
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(999), Box::new(solution_999)));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(999), Box::new(solution_999)));
|
||||
|
||||
// make the solution invalidly worse and submit. This ought to be suppressed and
|
||||
// returned.
|
||||
let mut solution_9999 = solution.clone();
|
||||
solution_9999.score.minimal_stake -= 1;
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(9999), Box::new(solution_9999)));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(9999), Box::new(solution_9999)));
|
||||
|
||||
assert_eq!(
|
||||
MultiPhase::signed_submissions().iter().map(|x| x.who).collect::<Vec<_>>(),
|
||||
@@ -975,14 +975,14 @@ mod tests {
|
||||
assert_eq!(raw.solution.voter_count(), 5);
|
||||
assert_eq!(<Runtime as Config>::SignedMaxWeight::get(), Weight::from_ref_time(40));
|
||||
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(99), Box::new(raw.clone())));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(raw.clone())));
|
||||
|
||||
<SignedMaxWeight>::set(Weight::from_ref_time(30));
|
||||
|
||||
// note: resubmitting the same solution is technically okay as long as the queue has
|
||||
// space.
|
||||
assert_noop!(
|
||||
MultiPhase::submit(Origin::signed(99), Box::new(raw)),
|
||||
MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(raw)),
|
||||
Error::<Runtime>::SignedTooMuchWeight,
|
||||
);
|
||||
})
|
||||
@@ -998,7 +998,7 @@ mod tests {
|
||||
|
||||
assert_eq!(balances(&123), (0, 0));
|
||||
assert_noop!(
|
||||
MultiPhase::submit(Origin::signed(123), Box::new(solution)),
|
||||
MultiPhase::submit(RuntimeOrigin::signed(123), Box::new(solution)),
|
||||
Error::<Runtime>::SignedCannotPayDeposit,
|
||||
);
|
||||
|
||||
@@ -1020,7 +1020,7 @@ mod tests {
|
||||
score: ElectionScore { minimal_stake: (5 + s).into(), ..Default::default() },
|
||||
..Default::default()
|
||||
};
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(99), Box::new(solution)));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(solution)));
|
||||
}
|
||||
|
||||
// this solution has a higher score than any in the queue
|
||||
@@ -1034,7 +1034,7 @@ mod tests {
|
||||
|
||||
assert_eq!(balances(&123), (0, 0));
|
||||
assert_noop!(
|
||||
MultiPhase::submit(Origin::signed(123), Box::new(solution)),
|
||||
MultiPhase::submit(RuntimeOrigin::signed(123), Box::new(solution)),
|
||||
Error::<Runtime>::SignedCannotPayDeposit,
|
||||
);
|
||||
|
||||
@@ -1063,7 +1063,7 @@ mod tests {
|
||||
let solution = raw_solution();
|
||||
|
||||
// submit a correct one.
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(99), Box::new(solution)));
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(solution)));
|
||||
|
||||
// _some_ good solution was stored.
|
||||
assert!(MultiPhase::finalize_signed_phase());
|
||||
|
||||
@@ -856,7 +856,7 @@ mod tests {
|
||||
use crate::{
|
||||
mock::{
|
||||
roll_to, roll_to_with_ocw, trim_helpers, witness, BlockNumber, ExtBuilder, Extrinsic,
|
||||
MinerMaxWeight, MultiPhase, Origin, Runtime, RuntimeCall as OuterCall, System,
|
||||
MinerMaxWeight, MultiPhase, Runtime, RuntimeCall as OuterCall, RuntimeOrigin, System,
|
||||
TestNposSolution, TrimHelpers, UnsignedPhase,
|
||||
},
|
||||
CurrentPhase, InvalidTransaction, Phase, QueuedSolution, TransactionSource,
|
||||
@@ -1071,7 +1071,7 @@ mod tests {
|
||||
witness: witness(),
|
||||
};
|
||||
let outer_call: OuterCall = call.into();
|
||||
let _ = outer_call.dispatch(Origin::none());
|
||||
let _ = outer_call.dispatch(RuntimeOrigin::none());
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1097,7 +1097,7 @@ mod tests {
|
||||
witness: correct_witness,
|
||||
};
|
||||
let outer_call: OuterCall = call.into();
|
||||
let _ = outer_call.dispatch(Origin::none());
|
||||
let _ = outer_call.dispatch(RuntimeOrigin::none());
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1116,7 +1116,11 @@ mod tests {
|
||||
|
||||
// ensure this solution is valid.
|
||||
assert!(MultiPhase::queued_solution().is_none());
|
||||
assert_ok!(MultiPhase::submit_unsigned(Origin::none(), Box::new(solution), witness));
|
||||
assert_ok!(MultiPhase::submit_unsigned(
|
||||
RuntimeOrigin::none(),
|
||||
Box::new(solution),
|
||||
witness
|
||||
));
|
||||
assert!(MultiPhase::queued_solution().is_some());
|
||||
})
|
||||
}
|
||||
@@ -1215,7 +1219,7 @@ mod tests {
|
||||
let solution = RawSolution { solution: raw, score, round: MultiPhase::round() };
|
||||
assert_ok!(MultiPhase::unsigned_pre_dispatch_checks(&solution));
|
||||
assert_ok!(MultiPhase::submit_unsigned(
|
||||
Origin::none(),
|
||||
RuntimeOrigin::none(),
|
||||
Box::new(solution),
|
||||
witness
|
||||
));
|
||||
@@ -1276,7 +1280,7 @@ mod tests {
|
||||
// and it is fine
|
||||
assert_ok!(MultiPhase::unsigned_pre_dispatch_checks(&solution));
|
||||
assert_ok!(MultiPhase::submit_unsigned(
|
||||
Origin::none(),
|
||||
RuntimeOrigin::none(),
|
||||
Box::new(solution),
|
||||
witness
|
||||
));
|
||||
|
||||
@@ -211,7 +211,7 @@ mod tests {
|
||||
impl frame_system::Config for Runtime {
|
||||
type SS58Prefix = ();
|
||||
type BaseCallFilter = frame_support::traits::Everything;
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = AccountId;
|
||||
type BlockNumber = BlockNumber;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -655,7 +655,7 @@ pub mod pallet {
|
||||
impl<T: Config> Pallet<T> {
|
||||
// Add public immutables and private mutables.
|
||||
#[allow(dead_code)]
|
||||
fn accumulate_foo(origin: T::Origin, increase_by: T::Balance) -> DispatchResult {
|
||||
fn accumulate_foo(origin: T::RuntimeOrigin, increase_by: T::Balance) -> DispatchResult {
|
||||
let _sender = ensure_signed(origin)?;
|
||||
|
||||
let prev = <Foo<T>>::get();
|
||||
|
||||
@@ -60,7 +60,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
@@ -128,12 +128,12 @@ fn it_works_for_optional_value() {
|
||||
assert_eq!(Example::dummy(), Some(val1));
|
||||
|
||||
// Check that accumulate works when we have Some value in Dummy already.
|
||||
assert_ok!(Example::accumulate_dummy(Origin::signed(1), val2));
|
||||
assert_ok!(Example::accumulate_dummy(RuntimeOrigin::signed(1), val2));
|
||||
assert_eq!(Example::dummy(), Some(val1 + val2));
|
||||
|
||||
// Check that accumulate works when we Dummy has None in it.
|
||||
<Example as OnInitialize<u64>>::on_initialize(2);
|
||||
assert_ok!(Example::accumulate_dummy(Origin::signed(1), val1));
|
||||
assert_ok!(Example::accumulate_dummy(RuntimeOrigin::signed(1), val1));
|
||||
assert_eq!(Example::dummy(), Some(val1 + val2 + val1));
|
||||
});
|
||||
}
|
||||
@@ -142,7 +142,7 @@ fn it_works_for_optional_value() {
|
||||
fn it_works_for_default_value() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_eq!(Example::foo(), 24);
|
||||
assert_ok!(Example::accumulate_foo(Origin::signed(1), 1));
|
||||
assert_ok!(Example::accumulate_foo(RuntimeOrigin::signed(1), 1));
|
||||
assert_eq!(Example::foo(), 25);
|
||||
});
|
||||
}
|
||||
@@ -151,7 +151,7 @@ fn it_works_for_default_value() {
|
||||
fn set_dummy_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let test_val = 133;
|
||||
assert_ok!(Example::set_dummy(Origin::root(), test_val.into()));
|
||||
assert_ok!(Example::set_dummy(RuntimeOrigin::root(), test_val.into()));
|
||||
assert_eq!(Example::dummy(), Some(test_val));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
@@ -134,10 +134,10 @@ fn it_aggregates_the_price() {
|
||||
sp_io::TestExternalities::default().execute_with(|| {
|
||||
assert_eq!(Example::average_price(), None);
|
||||
|
||||
assert_ok!(Example::submit_price(Origin::signed(test_pub()), 27));
|
||||
assert_ok!(Example::submit_price(RuntimeOrigin::signed(test_pub()), 27));
|
||||
assert_eq!(Example::average_price(), Some(27));
|
||||
|
||||
assert_ok!(Example::submit_price(Origin::signed(test_pub()), 43));
|
||||
assert_ok!(Example::submit_price(RuntimeOrigin::signed(test_pub()), 43));
|
||||
assert_eq!(Example::average_price(), Some(35));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ parameter_types! {
|
||||
|
||||
impl frame_system::Config for Test {
|
||||
type BaseCallFilter = frame_support::traits::Everything;
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type PalletInfo = PalletInfo;
|
||||
type Index = u64;
|
||||
@@ -76,8 +76,8 @@ fn test_pub(n: u8) -> sp_core::sr25519::Public {
|
||||
sp_core::sr25519::Public::from_raw([n; 32])
|
||||
}
|
||||
|
||||
fn test_origin(n: u8) -> Origin {
|
||||
Origin::signed(test_pub(n))
|
||||
fn test_origin(n: u8) -> RuntimeOrigin {
|
||||
RuntimeOrigin::signed(test_pub(n))
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -103,7 +103,7 @@ fn it_can_enlist() {
|
||||
},
|
||||
];
|
||||
|
||||
Example::enlist_participants(Origin::signed(test_pub(1)), participants)
|
||||
Example::enlist_participants(RuntimeOrigin::signed(test_pub(1)), participants)
|
||||
.expect("Failed to enlist");
|
||||
|
||||
assert_eq!(Example::participants().len(), 2);
|
||||
|
||||
@@ -138,7 +138,7 @@ use sp_std::{marker::PhantomData, prelude::*};
|
||||
|
||||
pub type CheckedOf<E, C> = <E as Checkable<C>>::Checked;
|
||||
pub type CallOf<E, C> = <CheckedOf<E, C> as Applyable>::Call;
|
||||
pub type OriginOf<E, C> = <CallOf<E, C> as Dispatchable>::Origin;
|
||||
pub type OriginOf<E, C> = <CallOf<E, C> as Dispatchable>::RuntimeOrigin;
|
||||
|
||||
/// Main entry point for certain runtime actions as e.g. `execute_block`.
|
||||
///
|
||||
@@ -789,7 +789,7 @@ mod tests {
|
||||
type BlockWeights = BlockWeights;
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type BlockNumber = u64;
|
||||
|
||||
@@ -77,7 +77,7 @@ benchmarks! {
|
||||
|
||||
set_target {
|
||||
let origin = T::AdminOrigin::successful_origin();
|
||||
}: _<T::Origin>(origin, Default::default())
|
||||
}: _<T::RuntimeOrigin>(origin, Default::default())
|
||||
verify {}
|
||||
|
||||
thaw {
|
||||
|
||||
@@ -116,7 +116,7 @@ pub mod pallet {
|
||||
+ MaxEncodedLen;
|
||||
|
||||
/// Origin required for setting the target proportion to be under gilt.
|
||||
type AdminOrigin: EnsureOrigin<Self::Origin>;
|
||||
type AdminOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// Unbalanced handler to account for funds created (in case of a higher total issuance over
|
||||
/// freezing period).
|
||||
|
||||
@@ -49,7 +49,7 @@ impl frame_system::Config for Test {
|
||||
type BaseCallFilter = frame_support::traits::Everything;
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
|
||||
@@ -49,8 +49,8 @@ fn set_target_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(1);
|
||||
let e = DispatchError::BadOrigin;
|
||||
assert_noop!(Gilt::set_target(Origin::signed(2), Perquintill::from_percent(50)), e);
|
||||
assert_ok!(Gilt::set_target(Origin::signed(1), Perquintill::from_percent(50)));
|
||||
assert_noop!(Gilt::set_target(RuntimeOrigin::signed(2), Perquintill::from_percent(50)), e);
|
||||
assert_ok!(Gilt::set_target(RuntimeOrigin::signed(1), Perquintill::from_percent(50)));
|
||||
|
||||
assert_eq!(
|
||||
ActiveTotal::<Test>::get(),
|
||||
@@ -68,13 +68,19 @@ fn set_target_works() {
|
||||
fn place_bid_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(1);
|
||||
assert_noop!(Gilt::place_bid(Origin::signed(1), 1, 2), Error::<Test>::AmountTooSmall);
|
||||
assert_noop!(
|
||||
Gilt::place_bid(Origin::signed(1), 101, 2),
|
||||
Gilt::place_bid(RuntimeOrigin::signed(1), 1, 2),
|
||||
Error::<Test>::AmountTooSmall
|
||||
);
|
||||
assert_noop!(
|
||||
Gilt::place_bid(RuntimeOrigin::signed(1), 101, 2),
|
||||
BalancesError::<Test>::InsufficientBalance
|
||||
);
|
||||
assert_noop!(Gilt::place_bid(Origin::signed(1), 10, 4), Error::<Test>::DurationTooBig);
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 10, 2));
|
||||
assert_noop!(
|
||||
Gilt::place_bid(RuntimeOrigin::signed(1), 10, 4),
|
||||
Error::<Test>::DurationTooBig
|
||||
);
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 10, 2));
|
||||
assert_eq!(Balances::reserved_balance(1), 10);
|
||||
assert_eq!(Queues::<Test>::get(2), vec![GiltBid { amount: 10, who: 1 }]);
|
||||
assert_eq!(QueueTotals::<Test>::get(), vec![(0, 0), (1, 10), (0, 0)]);
|
||||
@@ -85,16 +91,16 @@ fn place_bid_works() {
|
||||
fn place_bid_queuing_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(1);
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 20, 2));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 10, 2));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 5, 2));
|
||||
assert_noop!(Gilt::place_bid(Origin::signed(1), 5, 2), Error::<Test>::BidTooLow);
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 15, 2));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 20, 2));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 10, 2));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 5, 2));
|
||||
assert_noop!(Gilt::place_bid(RuntimeOrigin::signed(1), 5, 2), Error::<Test>::BidTooLow);
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 15, 2));
|
||||
assert_eq!(Balances::reserved_balance(1), 45);
|
||||
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 25, 2));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 25, 2));
|
||||
assert_eq!(Balances::reserved_balance(1), 60);
|
||||
assert_noop!(Gilt::place_bid(Origin::signed(1), 10, 2), Error::<Test>::BidTooLow);
|
||||
assert_noop!(Gilt::place_bid(RuntimeOrigin::signed(1), 10, 2), Error::<Test>::BidTooLow);
|
||||
assert_eq!(
|
||||
Queues::<Test>::get(2),
|
||||
vec![
|
||||
@@ -111,11 +117,11 @@ fn place_bid_queuing_works() {
|
||||
fn place_bid_fails_when_queue_full() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(1);
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 10, 2));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(2), 10, 2));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(3), 10, 2));
|
||||
assert_noop!(Gilt::place_bid(Origin::signed(4), 10, 2), Error::<Test>::BidTooLow);
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(4), 10, 3));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 10, 2));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(2), 10, 2));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(3), 10, 2));
|
||||
assert_noop!(Gilt::place_bid(RuntimeOrigin::signed(4), 10, 2), Error::<Test>::BidTooLow);
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(4), 10, 3));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -123,11 +129,11 @@ fn place_bid_fails_when_queue_full() {
|
||||
fn multiple_place_bids_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(1);
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 10, 1));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 10, 2));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 10, 2));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 10, 3));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(2), 10, 2));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 10, 1));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 10, 2));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 10, 2));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 10, 3));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(2), 10, 2));
|
||||
|
||||
assert_eq!(Balances::reserved_balance(1), 40);
|
||||
assert_eq!(Balances::reserved_balance(2), 10);
|
||||
@@ -149,9 +155,9 @@ fn multiple_place_bids_works() {
|
||||
fn retract_single_item_queue_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(1);
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 10, 1));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 10, 2));
|
||||
assert_ok!(Gilt::retract_bid(Origin::signed(1), 10, 1));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 10, 1));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 10, 2));
|
||||
assert_ok!(Gilt::retract_bid(RuntimeOrigin::signed(1), 10, 1));
|
||||
|
||||
assert_eq!(Balances::reserved_balance(1), 10);
|
||||
assert_eq!(Queues::<Test>::get(1), vec![]);
|
||||
@@ -164,12 +170,12 @@ fn retract_single_item_queue_works() {
|
||||
fn retract_with_other_and_duplicate_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(1);
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 10, 1));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 10, 2));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 10, 2));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(2), 10, 2));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 10, 1));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 10, 2));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 10, 2));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(2), 10, 2));
|
||||
|
||||
assert_ok!(Gilt::retract_bid(Origin::signed(1), 10, 2));
|
||||
assert_ok!(Gilt::retract_bid(RuntimeOrigin::signed(1), 10, 2));
|
||||
assert_eq!(Balances::reserved_balance(1), 20);
|
||||
assert_eq!(Balances::reserved_balance(2), 10);
|
||||
assert_eq!(Queues::<Test>::get(1), vec![GiltBid { amount: 10, who: 1 },]);
|
||||
@@ -185,11 +191,11 @@ fn retract_with_other_and_duplicate_works() {
|
||||
fn retract_non_existent_item_fails() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(1);
|
||||
assert_noop!(Gilt::retract_bid(Origin::signed(1), 10, 1), Error::<Test>::NotFound);
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 10, 1));
|
||||
assert_noop!(Gilt::retract_bid(Origin::signed(1), 20, 1), Error::<Test>::NotFound);
|
||||
assert_noop!(Gilt::retract_bid(Origin::signed(1), 10, 2), Error::<Test>::NotFound);
|
||||
assert_noop!(Gilt::retract_bid(Origin::signed(2), 10, 1), Error::<Test>::NotFound);
|
||||
assert_noop!(Gilt::retract_bid(RuntimeOrigin::signed(1), 10, 1), Error::<Test>::NotFound);
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 10, 1));
|
||||
assert_noop!(Gilt::retract_bid(RuntimeOrigin::signed(1), 20, 1), Error::<Test>::NotFound);
|
||||
assert_noop!(Gilt::retract_bid(RuntimeOrigin::signed(1), 10, 2), Error::<Test>::NotFound);
|
||||
assert_noop!(Gilt::retract_bid(RuntimeOrigin::signed(2), 10, 1), Error::<Test>::NotFound);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -197,8 +203,8 @@ fn retract_non_existent_item_fails() {
|
||||
fn basic_enlarge_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(1);
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 40, 1));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(2), 40, 2));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 40, 1));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(2), 40, 2));
|
||||
Gilt::enlarge(40, 2);
|
||||
|
||||
// Takes 2/2, then stopped because it reaches its max amount
|
||||
@@ -228,10 +234,10 @@ fn basic_enlarge_works() {
|
||||
fn enlarge_respects_bids_limit() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(1);
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 40, 1));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(2), 40, 2));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(3), 40, 2));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(4), 40, 3));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 40, 1));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(2), 40, 2));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(3), 40, 2));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(4), 40, 3));
|
||||
Gilt::enlarge(100, 2);
|
||||
|
||||
// Should have taken 4/3 and 2/2, then stopped because it's only allowed 2.
|
||||
@@ -269,7 +275,7 @@ fn enlarge_respects_bids_limit() {
|
||||
fn enlarge_respects_amount_limit_and_will_split() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(1);
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 80, 1));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 80, 1));
|
||||
Gilt::enlarge(40, 2);
|
||||
|
||||
// Takes 2/2, then stopped because it reaches its max amount
|
||||
@@ -296,14 +302,14 @@ fn enlarge_respects_amount_limit_and_will_split() {
|
||||
fn basic_thaw_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(1);
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 40, 1));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 40, 1));
|
||||
Gilt::enlarge(40, 1);
|
||||
run_to_block(3);
|
||||
assert_noop!(Gilt::thaw(Origin::signed(1), 0), Error::<Test>::NotExpired);
|
||||
assert_noop!(Gilt::thaw(RuntimeOrigin::signed(1), 0), Error::<Test>::NotExpired);
|
||||
run_to_block(4);
|
||||
assert_noop!(Gilt::thaw(Origin::signed(1), 1), Error::<Test>::Unknown);
|
||||
assert_noop!(Gilt::thaw(Origin::signed(2), 0), Error::<Test>::NotOwner);
|
||||
assert_ok!(Gilt::thaw(Origin::signed(1), 0));
|
||||
assert_noop!(Gilt::thaw(RuntimeOrigin::signed(1), 1), Error::<Test>::Unknown);
|
||||
assert_noop!(Gilt::thaw(RuntimeOrigin::signed(2), 0), Error::<Test>::NotOwner);
|
||||
assert_ok!(Gilt::thaw(RuntimeOrigin::signed(1), 0));
|
||||
|
||||
assert_eq!(
|
||||
ActiveTotal::<Test>::get(),
|
||||
@@ -324,7 +330,7 @@ fn basic_thaw_works() {
|
||||
fn thaw_when_issuance_higher_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(1);
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 100, 1));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 100, 1));
|
||||
Gilt::enlarge(100, 1);
|
||||
|
||||
// Everybody else's balances goes up by 50%
|
||||
@@ -333,7 +339,7 @@ fn thaw_when_issuance_higher_works() {
|
||||
Balances::make_free_balance_be(&4, 150);
|
||||
|
||||
run_to_block(4);
|
||||
assert_ok!(Gilt::thaw(Origin::signed(1), 0));
|
||||
assert_ok!(Gilt::thaw(RuntimeOrigin::signed(1), 0));
|
||||
|
||||
assert_eq!(Balances::free_balance(1), 150);
|
||||
assert_eq!(Balances::reserved_balance(1), 0);
|
||||
@@ -347,16 +353,16 @@ fn thaw_with_ignored_issuance_works() {
|
||||
// Give account zero some balance.
|
||||
Balances::make_free_balance_be(&0, 200);
|
||||
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 100, 1));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 100, 1));
|
||||
Gilt::enlarge(100, 1);
|
||||
|
||||
// Account zero transfers 50 into everyone else's accounts.
|
||||
assert_ok!(Balances::transfer(Origin::signed(0), 2, 50));
|
||||
assert_ok!(Balances::transfer(Origin::signed(0), 3, 50));
|
||||
assert_ok!(Balances::transfer(Origin::signed(0), 4, 50));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(0), 2, 50));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(0), 3, 50));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(0), 4, 50));
|
||||
|
||||
run_to_block(4);
|
||||
assert_ok!(Gilt::thaw(Origin::signed(1), 0));
|
||||
assert_ok!(Gilt::thaw(RuntimeOrigin::signed(1), 0));
|
||||
|
||||
// Account zero changes have been ignored.
|
||||
assert_eq!(Balances::free_balance(1), 150);
|
||||
@@ -368,7 +374,7 @@ fn thaw_with_ignored_issuance_works() {
|
||||
fn thaw_when_issuance_lower_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(1);
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 100, 1));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 100, 1));
|
||||
Gilt::enlarge(100, 1);
|
||||
|
||||
// Everybody else's balances goes down by 25%
|
||||
@@ -377,7 +383,7 @@ fn thaw_when_issuance_lower_works() {
|
||||
Balances::make_free_balance_be(&4, 75);
|
||||
|
||||
run_to_block(4);
|
||||
assert_ok!(Gilt::thaw(Origin::signed(1), 0));
|
||||
assert_ok!(Gilt::thaw(RuntimeOrigin::signed(1), 0));
|
||||
|
||||
assert_eq!(Balances::free_balance(1), 75);
|
||||
assert_eq!(Balances::reserved_balance(1), 0);
|
||||
@@ -388,9 +394,9 @@ fn thaw_when_issuance_lower_works() {
|
||||
fn multiple_thaws_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(1);
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 40, 1));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 60, 1));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(2), 50, 1));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 40, 1));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 60, 1));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(2), 50, 1));
|
||||
Gilt::enlarge(200, 3);
|
||||
|
||||
// Double everyone's free balances.
|
||||
@@ -399,9 +405,9 @@ fn multiple_thaws_works() {
|
||||
Balances::make_free_balance_be(&4, 200);
|
||||
|
||||
run_to_block(4);
|
||||
assert_ok!(Gilt::thaw(Origin::signed(1), 0));
|
||||
assert_ok!(Gilt::thaw(Origin::signed(1), 1));
|
||||
assert_ok!(Gilt::thaw(Origin::signed(2), 2));
|
||||
assert_ok!(Gilt::thaw(RuntimeOrigin::signed(1), 0));
|
||||
assert_ok!(Gilt::thaw(RuntimeOrigin::signed(1), 1));
|
||||
assert_ok!(Gilt::thaw(RuntimeOrigin::signed(2), 2));
|
||||
|
||||
assert_eq!(Balances::free_balance(1), 200);
|
||||
assert_eq!(Balances::free_balance(2), 200);
|
||||
@@ -412,9 +418,9 @@ fn multiple_thaws_works() {
|
||||
fn multiple_thaws_works_in_alternative_thaw_order() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(1);
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 40, 1));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 60, 1));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(2), 50, 1));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 40, 1));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 60, 1));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(2), 50, 1));
|
||||
Gilt::enlarge(200, 3);
|
||||
|
||||
// Double everyone's free balances.
|
||||
@@ -423,9 +429,9 @@ fn multiple_thaws_works_in_alternative_thaw_order() {
|
||||
Balances::make_free_balance_be(&4, 200);
|
||||
|
||||
run_to_block(4);
|
||||
assert_ok!(Gilt::thaw(Origin::signed(2), 2));
|
||||
assert_ok!(Gilt::thaw(Origin::signed(1), 1));
|
||||
assert_ok!(Gilt::thaw(Origin::signed(1), 0));
|
||||
assert_ok!(Gilt::thaw(RuntimeOrigin::signed(2), 2));
|
||||
assert_ok!(Gilt::thaw(RuntimeOrigin::signed(1), 1));
|
||||
assert_ok!(Gilt::thaw(RuntimeOrigin::signed(1), 0));
|
||||
|
||||
assert_eq!(Balances::free_balance(1), 200);
|
||||
assert_eq!(Balances::free_balance(2), 200);
|
||||
@@ -436,12 +442,12 @@ fn multiple_thaws_works_in_alternative_thaw_order() {
|
||||
fn enlargement_to_target_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(2);
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 40, 1));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 40, 2));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(2), 40, 2));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(2), 40, 3));
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(3), 40, 3));
|
||||
assert_ok!(Gilt::set_target(Origin::signed(1), Perquintill::from_percent(40)));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 40, 1));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(1), 40, 2));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(2), 40, 2));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(2), 40, 3));
|
||||
assert_ok!(Gilt::place_bid(RuntimeOrigin::signed(3), 40, 3));
|
||||
assert_ok!(Gilt::set_target(RuntimeOrigin::signed(1), Perquintill::from_percent(40)));
|
||||
|
||||
run_to_block(3);
|
||||
assert_eq!(Queues::<Test>::get(1), vec![GiltBid { amount: 40, who: 1 },]);
|
||||
@@ -540,7 +546,7 @@ fn enlargement_to_target_works() {
|
||||
);
|
||||
|
||||
// Set target a bit higher to use up the remaining bid.
|
||||
assert_ok!(Gilt::set_target(Origin::signed(1), Perquintill::from_percent(60)));
|
||||
assert_ok!(Gilt::set_target(RuntimeOrigin::signed(1), Perquintill::from_percent(60)));
|
||||
run_to_block(10);
|
||||
|
||||
// Two new gilts should have been issued to 1 & 2 for 40 each & duration of 2.
|
||||
|
||||
@@ -79,7 +79,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
|
||||
@@ -359,7 +359,7 @@ fn report_equivocation_current_set_works() {
|
||||
|
||||
// report the equivocation and the tx should be dispatched successfully
|
||||
assert_ok!(Grandpa::report_equivocation_unsigned(
|
||||
Origin::none(),
|
||||
RuntimeOrigin::none(),
|
||||
Box::new(equivocation_proof),
|
||||
key_owner_proof,
|
||||
),);
|
||||
@@ -437,7 +437,7 @@ fn report_equivocation_old_set_works() {
|
||||
// report the equivocation using the key ownership proof generated on
|
||||
// the old set, the tx should be dispatched successfully
|
||||
assert_ok!(Grandpa::report_equivocation_unsigned(
|
||||
Origin::none(),
|
||||
RuntimeOrigin::none(),
|
||||
Box::new(equivocation_proof),
|
||||
key_owner_proof,
|
||||
),);
|
||||
@@ -500,7 +500,7 @@ fn report_equivocation_invalid_set_id() {
|
||||
// the call for reporting the equivocation should error
|
||||
assert_err!(
|
||||
Grandpa::report_equivocation_unsigned(
|
||||
Origin::none(),
|
||||
RuntimeOrigin::none(),
|
||||
Box::new(equivocation_proof),
|
||||
key_owner_proof,
|
||||
),
|
||||
@@ -541,7 +541,7 @@ fn report_equivocation_invalid_session() {
|
||||
// proof from the previous set, the session should be invalid.
|
||||
assert_err!(
|
||||
Grandpa::report_equivocation_unsigned(
|
||||
Origin::none(),
|
||||
RuntimeOrigin::none(),
|
||||
Box::new(equivocation_proof),
|
||||
key_owner_proof,
|
||||
),
|
||||
@@ -586,7 +586,7 @@ fn report_equivocation_invalid_key_owner_proof() {
|
||||
// proof for a different key than the one in the equivocation proof.
|
||||
assert_err!(
|
||||
Grandpa::report_equivocation_unsigned(
|
||||
Origin::none(),
|
||||
RuntimeOrigin::none(),
|
||||
Box::new(equivocation_proof),
|
||||
invalid_key_owner_proof,
|
||||
),
|
||||
@@ -617,7 +617,7 @@ fn report_equivocation_invalid_equivocation_proof() {
|
||||
let assert_invalid_equivocation_proof = |equivocation_proof| {
|
||||
assert_err!(
|
||||
Grandpa::report_equivocation_unsigned(
|
||||
Origin::none(),
|
||||
RuntimeOrigin::none(),
|
||||
Box::new(equivocation_proof),
|
||||
key_owner_proof.clone(),
|
||||
),
|
||||
@@ -723,7 +723,7 @@ fn report_equivocation_validate_unsigned_prevents_duplicates() {
|
||||
|
||||
// we submit the report
|
||||
Grandpa::report_equivocation_unsigned(
|
||||
Origin::none(),
|
||||
RuntimeOrigin::none(),
|
||||
Box::new(equivocation_proof),
|
||||
key_owner_proof,
|
||||
)
|
||||
@@ -861,7 +861,7 @@ fn valid_equivocation_reports_dont_pay_fees() {
|
||||
|
||||
// report the equivocation.
|
||||
let post_info = Grandpa::report_equivocation_unsigned(
|
||||
Origin::none(),
|
||||
RuntimeOrigin::none(),
|
||||
Box::new(equivocation_proof.clone()),
|
||||
key_owner_proof.clone(),
|
||||
)
|
||||
@@ -875,7 +875,7 @@ fn valid_equivocation_reports_dont_pay_fees() {
|
||||
// report the equivocation again which is invalid now since it is
|
||||
// duplicate.
|
||||
let post_info = Grandpa::report_equivocation_unsigned(
|
||||
Origin::none(),
|
||||
RuntimeOrigin::none(),
|
||||
Box::new(equivocation_proof),
|
||||
key_owner_proof,
|
||||
)
|
||||
|
||||
@@ -123,7 +123,7 @@ benchmarks! {
|
||||
ensure!(Registrars::<T>::get().len() as u32 == r, "Registrars not set up correctly.");
|
||||
let origin = T::RegistrarOrigin::successful_origin();
|
||||
let account = T::Lookup::unlookup(account("registrar", r + 1, SEED));
|
||||
}: _<T::Origin>(origin, account)
|
||||
}: _<T::RuntimeOrigin>(origin, account)
|
||||
verify {
|
||||
ensure!(Registrars::<T>::get().len() as u32 == r + 1, "Registrars not added.");
|
||||
}
|
||||
@@ -135,7 +135,7 @@ benchmarks! {
|
||||
// The target user
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let caller_lookup = T::Lookup::unlookup(caller.clone());
|
||||
let caller_origin: <T as frame_system::Config>::Origin = RawOrigin::Signed(caller.clone()).into();
|
||||
let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into();
|
||||
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
|
||||
// Add an initial identity
|
||||
@@ -193,7 +193,7 @@ benchmarks! {
|
||||
|
||||
clear_identity {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let caller_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(caller.clone()));
|
||||
let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));
|
||||
let caller_lookup = <T::Lookup as StaticLookup>::unlookup(caller.clone());
|
||||
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
|
||||
@@ -208,7 +208,7 @@ benchmarks! {
|
||||
// Create their main identity with x additional fields
|
||||
let info = create_identity_info::<T>(x);
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let caller_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(caller.clone()));
|
||||
let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));
|
||||
Identity::<T>::set_identity(caller_origin.clone(), Box::new(info.clone()))?;
|
||||
|
||||
// User requests judgement from all the registrars, and they approve
|
||||
@@ -237,7 +237,7 @@ benchmarks! {
|
||||
// Create their main identity with x additional fields
|
||||
let info = create_identity_info::<T>(x);
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let caller_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(caller));
|
||||
let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller));
|
||||
Identity::<T>::set_identity(caller_origin, Box::new(info))?;
|
||||
};
|
||||
}: _(RawOrigin::Signed(caller.clone()), r - 1, 10u32.into())
|
||||
@@ -247,7 +247,7 @@ benchmarks! {
|
||||
|
||||
cancel_request {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let caller_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(caller.clone()));
|
||||
let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));
|
||||
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
|
||||
let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
|
||||
@@ -255,7 +255,7 @@ benchmarks! {
|
||||
// Create their main identity with x additional fields
|
||||
let info = create_identity_info::<T>(x);
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let caller_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(caller));
|
||||
let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller));
|
||||
Identity::<T>::set_identity(caller_origin, Box::new(info))?;
|
||||
};
|
||||
|
||||
@@ -323,7 +323,7 @@ benchmarks! {
|
||||
provide_judgement {
|
||||
// The user
|
||||
let user: T::AccountId = account("user", r, SEED);
|
||||
let user_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(user.clone()));
|
||||
let user_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(user.clone()));
|
||||
let user_lookup = <T::Lookup as StaticLookup>::unlookup(user.clone());
|
||||
let _ = T::Currency::make_free_balance_be(&user, BalanceOf::<T>::max_value());
|
||||
|
||||
@@ -352,7 +352,7 @@ benchmarks! {
|
||||
let x in 1 .. T::MaxAdditionalFields::get();
|
||||
|
||||
let target: T::AccountId = account("target", 0, SEED);
|
||||
let target_origin: <T as frame_system::Config>::Origin = RawOrigin::Signed(target.clone()).into();
|
||||
let target_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(target.clone()).into();
|
||||
let target_lookup = T::Lookup::unlookup(target.clone());
|
||||
let _ = T::Currency::make_free_balance_be(&target, BalanceOf::<T>::max_value());
|
||||
|
||||
@@ -373,7 +373,7 @@ benchmarks! {
|
||||
}
|
||||
ensure!(IdentityOf::<T>::contains_key(&target), "Identity not set");
|
||||
let origin = T::ForceOrigin::successful_origin();
|
||||
}: _<T::Origin>(origin, target_lookup)
|
||||
}: _<T::RuntimeOrigin>(origin, target_lookup)
|
||||
verify {
|
||||
ensure!(!IdentityOf::<T>::contains_key(&target), "Identity not removed");
|
||||
}
|
||||
|
||||
@@ -142,10 +142,10 @@ pub mod pallet {
|
||||
type Slashed: OnUnbalanced<NegativeImbalanceOf<Self>>;
|
||||
|
||||
/// The origin which may forcibly set or remove a name. Root can always do this.
|
||||
type ForceOrigin: EnsureOrigin<Self::Origin>;
|
||||
type ForceOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// The origin which may add or remove registrars. Root can always do this.
|
||||
type RegistrarOrigin: EnsureOrigin<Self::Origin>;
|
||||
type RegistrarOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// Weight information for extrinsics in this pallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
|
||||
@@ -56,7 +56,7 @@ impl frame_system::Config for Test {
|
||||
type BaseCallFilter = frame_support::traits::Everything;
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
@@ -148,41 +148,44 @@ fn editing_subaccounts_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let data = |x| Data::Raw(vec![x; 1].try_into().unwrap());
|
||||
|
||||
assert_noop!(Identity::add_sub(Origin::signed(10), 20, data(1)), Error::<Test>::NoIdentity);
|
||||
assert_noop!(
|
||||
Identity::add_sub(RuntimeOrigin::signed(10), 20, data(1)),
|
||||
Error::<Test>::NoIdentity
|
||||
);
|
||||
|
||||
assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten())));
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
|
||||
|
||||
// first sub account
|
||||
assert_ok!(Identity::add_sub(Origin::signed(10), 1, data(1)));
|
||||
assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 1, data(1)));
|
||||
assert_eq!(SuperOf::<Test>::get(1), Some((10, data(1))));
|
||||
assert_eq!(Balances::free_balance(10), 80);
|
||||
|
||||
// second sub account
|
||||
assert_ok!(Identity::add_sub(Origin::signed(10), 2, data(2)));
|
||||
assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 2, data(2)));
|
||||
assert_eq!(SuperOf::<Test>::get(1), Some((10, data(1))));
|
||||
assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));
|
||||
assert_eq!(Balances::free_balance(10), 70);
|
||||
|
||||
// third sub account is too many
|
||||
assert_noop!(
|
||||
Identity::add_sub(Origin::signed(10), 3, data(3)),
|
||||
Identity::add_sub(RuntimeOrigin::signed(10), 3, data(3)),
|
||||
Error::<Test>::TooManySubAccounts
|
||||
);
|
||||
|
||||
// rename first sub account
|
||||
assert_ok!(Identity::rename_sub(Origin::signed(10), 1, data(11)));
|
||||
assert_ok!(Identity::rename_sub(RuntimeOrigin::signed(10), 1, data(11)));
|
||||
assert_eq!(SuperOf::<Test>::get(1), Some((10, data(11))));
|
||||
assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));
|
||||
assert_eq!(Balances::free_balance(10), 70);
|
||||
|
||||
// remove first sub account
|
||||
assert_ok!(Identity::remove_sub(Origin::signed(10), 1));
|
||||
assert_ok!(Identity::remove_sub(RuntimeOrigin::signed(10), 1));
|
||||
assert_eq!(SuperOf::<Test>::get(1), None);
|
||||
assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));
|
||||
assert_eq!(Balances::free_balance(10), 80);
|
||||
|
||||
// add third sub account
|
||||
assert_ok!(Identity::add_sub(Origin::signed(10), 3, data(3)));
|
||||
assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 3, data(3)));
|
||||
assert_eq!(SuperOf::<Test>::get(1), None);
|
||||
assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));
|
||||
assert_eq!(SuperOf::<Test>::get(3), Some((10, data(3))));
|
||||
@@ -195,27 +198,27 @@ fn resolving_subaccount_ownership_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let data = |x| Data::Raw(vec![x; 1].try_into().unwrap());
|
||||
|
||||
assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten())));
|
||||
assert_ok!(Identity::set_identity(Origin::signed(20), Box::new(twenty())));
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(20), Box::new(twenty())));
|
||||
|
||||
// 10 claims 1 as a subaccount
|
||||
assert_ok!(Identity::add_sub(Origin::signed(10), 1, data(1)));
|
||||
assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 1, data(1)));
|
||||
assert_eq!(Balances::free_balance(1), 10);
|
||||
assert_eq!(Balances::free_balance(10), 80);
|
||||
assert_eq!(Balances::reserved_balance(10), 20);
|
||||
// 20 cannot claim 1 now
|
||||
assert_noop!(
|
||||
Identity::add_sub(Origin::signed(20), 1, data(1)),
|
||||
Identity::add_sub(RuntimeOrigin::signed(20), 1, data(1)),
|
||||
Error::<Test>::AlreadyClaimed
|
||||
);
|
||||
// 1 wants to be with 20 so it quits from 10
|
||||
assert_ok!(Identity::quit_sub(Origin::signed(1)));
|
||||
assert_ok!(Identity::quit_sub(RuntimeOrigin::signed(1)));
|
||||
// 1 gets the 10 that 10 paid.
|
||||
assert_eq!(Balances::free_balance(1), 20);
|
||||
assert_eq!(Balances::free_balance(10), 80);
|
||||
assert_eq!(Balances::reserved_balance(10), 10);
|
||||
// 20 can claim 1 now
|
||||
assert_ok!(Identity::add_sub(Origin::signed(20), 1, data(1)));
|
||||
assert_ok!(Identity::add_sub(RuntimeOrigin::signed(20), 1, data(1)));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -232,10 +235,10 @@ fn trailing_zeros_decodes_into_default_data() {
|
||||
#[test]
|
||||
fn adding_registrar_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Identity::add_registrar(Origin::signed(1), 3));
|
||||
assert_ok!(Identity::set_fee(Origin::signed(3), 0, 10));
|
||||
assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
|
||||
assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));
|
||||
let fields = IdentityFields(IdentityField::Display | IdentityField::Legal);
|
||||
assert_ok!(Identity::set_fields(Origin::signed(3), 0, fields));
|
||||
assert_ok!(Identity::set_fields(RuntimeOrigin::signed(3), 0, fields));
|
||||
assert_eq!(
|
||||
Identity::registrars(),
|
||||
vec![Some(RegistrarInfo { account: 3, fee: 10, fields })]
|
||||
@@ -247,11 +250,11 @@ fn adding_registrar_should_work() {
|
||||
fn amount_of_registrars_is_limited() {
|
||||
new_test_ext().execute_with(|| {
|
||||
for i in 1..MaxRegistrars::get() + 1 {
|
||||
assert_ok!(Identity::add_registrar(Origin::signed(1), i as u64));
|
||||
assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), i as u64));
|
||||
}
|
||||
let last_registrar = MaxRegistrars::get() as u64 + 1;
|
||||
assert_noop!(
|
||||
Identity::add_registrar(Origin::signed(1), last_registrar),
|
||||
Identity::add_registrar(RuntimeOrigin::signed(1), last_registrar),
|
||||
Error::<Test>::TooManyRegistrars
|
||||
);
|
||||
});
|
||||
@@ -260,18 +263,18 @@ fn amount_of_registrars_is_limited() {
|
||||
#[test]
|
||||
fn registration_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Identity::add_registrar(Origin::signed(1), 3));
|
||||
assert_ok!(Identity::set_fee(Origin::signed(3), 0, 10));
|
||||
assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
|
||||
assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));
|
||||
let mut three_fields = ten();
|
||||
three_fields.additional.try_push(Default::default()).unwrap();
|
||||
three_fields.additional.try_push(Default::default()).unwrap();
|
||||
assert_eq!(three_fields.additional.try_push(Default::default()), Err(()));
|
||||
assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten())));
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
|
||||
assert_eq!(Identity::identity(10).unwrap().info, ten());
|
||||
assert_eq!(Balances::free_balance(10), 90);
|
||||
assert_ok!(Identity::clear_identity(Origin::signed(10)));
|
||||
assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10)));
|
||||
assert_eq!(Balances::free_balance(10), 100);
|
||||
assert_noop!(Identity::clear_identity(Origin::signed(10)), Error::<Test>::NotNamed);
|
||||
assert_noop!(Identity::clear_identity(RuntimeOrigin::signed(10)), Error::<Test>::NotNamed);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -280,7 +283,7 @@ fn uninvited_judgement_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
Identity::provide_judgement(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
0,
|
||||
10,
|
||||
Judgement::Reasonable,
|
||||
@@ -289,10 +292,10 @@ fn uninvited_judgement_should_work() {
|
||||
Error::<Test>::InvalidIndex
|
||||
);
|
||||
|
||||
assert_ok!(Identity::add_registrar(Origin::signed(1), 3));
|
||||
assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
|
||||
assert_noop!(
|
||||
Identity::provide_judgement(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
0,
|
||||
10,
|
||||
Judgement::Reasonable,
|
||||
@@ -301,10 +304,10 @@ fn uninvited_judgement_should_work() {
|
||||
Error::<Test>::InvalidTarget
|
||||
);
|
||||
|
||||
assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten())));
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
|
||||
assert_noop!(
|
||||
Identity::provide_judgement(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
0,
|
||||
10,
|
||||
Judgement::Reasonable,
|
||||
@@ -317,7 +320,7 @@ fn uninvited_judgement_should_work() {
|
||||
|
||||
assert_noop!(
|
||||
Identity::provide_judgement(
|
||||
Origin::signed(10),
|
||||
RuntimeOrigin::signed(10),
|
||||
0,
|
||||
10,
|
||||
Judgement::Reasonable,
|
||||
@@ -327,7 +330,7 @@ fn uninvited_judgement_should_work() {
|
||||
);
|
||||
assert_noop!(
|
||||
Identity::provide_judgement(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
0,
|
||||
10,
|
||||
Judgement::FeePaid(1),
|
||||
@@ -337,7 +340,7 @@ fn uninvited_judgement_should_work() {
|
||||
);
|
||||
|
||||
assert_ok!(Identity::provide_judgement(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
0,
|
||||
10,
|
||||
Judgement::Reasonable,
|
||||
@@ -350,16 +353,16 @@ fn uninvited_judgement_should_work() {
|
||||
#[test]
|
||||
fn clearing_judgement_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Identity::add_registrar(Origin::signed(1), 3));
|
||||
assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten())));
|
||||
assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
|
||||
assert_ok!(Identity::provide_judgement(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
0,
|
||||
10,
|
||||
Judgement::Reasonable,
|
||||
BlakeTwo256::hash_of(&ten())
|
||||
));
|
||||
assert_ok!(Identity::clear_identity(Origin::signed(10)));
|
||||
assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10)));
|
||||
assert_eq!(Identity::identity(10), None);
|
||||
});
|
||||
}
|
||||
@@ -367,12 +370,15 @@ fn clearing_judgement_should_work() {
|
||||
#[test]
|
||||
fn killing_slashing_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten())));
|
||||
assert_noop!(Identity::kill_identity(Origin::signed(1), 10), BadOrigin);
|
||||
assert_ok!(Identity::kill_identity(Origin::signed(2), 10));
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
|
||||
assert_noop!(Identity::kill_identity(RuntimeOrigin::signed(1), 10), BadOrigin);
|
||||
assert_ok!(Identity::kill_identity(RuntimeOrigin::signed(2), 10));
|
||||
assert_eq!(Identity::identity(10), None);
|
||||
assert_eq!(Balances::free_balance(10), 90);
|
||||
assert_noop!(Identity::kill_identity(Origin::signed(2), 10), Error::<Test>::NotNamed);
|
||||
assert_noop!(
|
||||
Identity::kill_identity(RuntimeOrigin::signed(2), 10),
|
||||
Error::<Test>::NotNamed
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -380,17 +386,20 @@ fn killing_slashing_should_work() {
|
||||
fn setting_subaccounts_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let mut subs = vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))];
|
||||
assert_noop!(Identity::set_subs(Origin::signed(10), subs.clone()), Error::<Test>::NotFound);
|
||||
assert_noop!(
|
||||
Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()),
|
||||
Error::<Test>::NotFound
|
||||
);
|
||||
|
||||
assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten())));
|
||||
assert_ok!(Identity::set_subs(Origin::signed(10), subs.clone()));
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
|
||||
assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));
|
||||
assert_eq!(Balances::free_balance(10), 80);
|
||||
assert_eq!(Identity::subs_of(10), (10, vec![20].try_into().unwrap()));
|
||||
assert_eq!(Identity::super_of(20), Some((10, Data::Raw(vec![40; 1].try_into().unwrap()))));
|
||||
|
||||
// push another item and re-set it.
|
||||
subs.push((30, Data::Raw(vec![50; 1].try_into().unwrap())));
|
||||
assert_ok!(Identity::set_subs(Origin::signed(10), subs.clone()));
|
||||
assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));
|
||||
assert_eq!(Balances::free_balance(10), 70);
|
||||
assert_eq!(Identity::subs_of(10), (20, vec![20, 30].try_into().unwrap()));
|
||||
assert_eq!(Identity::super_of(20), Some((10, Data::Raw(vec![40; 1].try_into().unwrap()))));
|
||||
@@ -398,7 +407,7 @@ fn setting_subaccounts_should_work() {
|
||||
|
||||
// switch out one of the items and re-set.
|
||||
subs[0] = (40, Data::Raw(vec![60; 1].try_into().unwrap()));
|
||||
assert_ok!(Identity::set_subs(Origin::signed(10), subs.clone()));
|
||||
assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));
|
||||
assert_eq!(Balances::free_balance(10), 70); // no change in the balance
|
||||
assert_eq!(Identity::subs_of(10), (20, vec![40, 30].try_into().unwrap()));
|
||||
assert_eq!(Identity::super_of(20), None);
|
||||
@@ -406,7 +415,7 @@ fn setting_subaccounts_should_work() {
|
||||
assert_eq!(Identity::super_of(40), Some((10, Data::Raw(vec![60; 1].try_into().unwrap()))));
|
||||
|
||||
// clear
|
||||
assert_ok!(Identity::set_subs(Origin::signed(10), vec![]));
|
||||
assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), vec![]));
|
||||
assert_eq!(Balances::free_balance(10), 90);
|
||||
assert_eq!(Identity::subs_of(10), (0, BoundedVec::default()));
|
||||
assert_eq!(Identity::super_of(30), None);
|
||||
@@ -414,7 +423,7 @@ fn setting_subaccounts_should_work() {
|
||||
|
||||
subs.push((20, Data::Raw(vec![40; 1].try_into().unwrap())));
|
||||
assert_noop!(
|
||||
Identity::set_subs(Origin::signed(10), subs.clone()),
|
||||
Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()),
|
||||
Error::<Test>::TooManySubAccounts
|
||||
);
|
||||
});
|
||||
@@ -423,12 +432,12 @@ fn setting_subaccounts_should_work() {
|
||||
#[test]
|
||||
fn clearing_account_should_remove_subaccounts_and_refund() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten())));
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
|
||||
assert_ok!(Identity::set_subs(
|
||||
Origin::signed(10),
|
||||
RuntimeOrigin::signed(10),
|
||||
vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))]
|
||||
));
|
||||
assert_ok!(Identity::clear_identity(Origin::signed(10)));
|
||||
assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10)));
|
||||
assert_eq!(Balances::free_balance(10), 100);
|
||||
assert!(Identity::super_of(20).is_none());
|
||||
});
|
||||
@@ -437,12 +446,12 @@ fn clearing_account_should_remove_subaccounts_and_refund() {
|
||||
#[test]
|
||||
fn killing_account_should_remove_subaccounts_and_not_refund() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten())));
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
|
||||
assert_ok!(Identity::set_subs(
|
||||
Origin::signed(10),
|
||||
RuntimeOrigin::signed(10),
|
||||
vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))]
|
||||
));
|
||||
assert_ok!(Identity::kill_identity(Origin::signed(2), 10));
|
||||
assert_ok!(Identity::kill_identity(RuntimeOrigin::signed(2), 10));
|
||||
assert_eq!(Balances::free_balance(10), 80);
|
||||
assert!(Identity::super_of(20).is_none());
|
||||
});
|
||||
@@ -451,24 +460,30 @@ fn killing_account_should_remove_subaccounts_and_not_refund() {
|
||||
#[test]
|
||||
fn cancelling_requested_judgement_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Identity::add_registrar(Origin::signed(1), 3));
|
||||
assert_ok!(Identity::set_fee(Origin::signed(3), 0, 10));
|
||||
assert_noop!(Identity::cancel_request(Origin::signed(10), 0), Error::<Test>::NoIdentity);
|
||||
assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten())));
|
||||
assert_ok!(Identity::request_judgement(Origin::signed(10), 0, 10));
|
||||
assert_ok!(Identity::cancel_request(Origin::signed(10), 0));
|
||||
assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
|
||||
assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));
|
||||
assert_noop!(
|
||||
Identity::cancel_request(RuntimeOrigin::signed(10), 0),
|
||||
Error::<Test>::NoIdentity
|
||||
);
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
|
||||
assert_ok!(Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10));
|
||||
assert_ok!(Identity::cancel_request(RuntimeOrigin::signed(10), 0));
|
||||
assert_eq!(Balances::free_balance(10), 90);
|
||||
assert_noop!(Identity::cancel_request(Origin::signed(10), 0), Error::<Test>::NotFound);
|
||||
assert_noop!(
|
||||
Identity::cancel_request(RuntimeOrigin::signed(10), 0),
|
||||
Error::<Test>::NotFound
|
||||
);
|
||||
|
||||
assert_ok!(Identity::provide_judgement(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
0,
|
||||
10,
|
||||
Judgement::Reasonable,
|
||||
BlakeTwo256::hash_of(&ten())
|
||||
));
|
||||
assert_noop!(
|
||||
Identity::cancel_request(Origin::signed(10), 0),
|
||||
Identity::cancel_request(RuntimeOrigin::signed(10), 0),
|
||||
Error::<Test>::JudgementGiven
|
||||
);
|
||||
});
|
||||
@@ -477,24 +492,24 @@ fn cancelling_requested_judgement_should_work() {
|
||||
#[test]
|
||||
fn requesting_judgement_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Identity::add_registrar(Origin::signed(1), 3));
|
||||
assert_ok!(Identity::set_fee(Origin::signed(3), 0, 10));
|
||||
assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten())));
|
||||
assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
|
||||
assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
|
||||
assert_noop!(
|
||||
Identity::request_judgement(Origin::signed(10), 0, 9),
|
||||
Identity::request_judgement(RuntimeOrigin::signed(10), 0, 9),
|
||||
Error::<Test>::FeeChanged
|
||||
);
|
||||
assert_ok!(Identity::request_judgement(Origin::signed(10), 0, 10));
|
||||
assert_ok!(Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10));
|
||||
// 10 for the judgement request, 10 for the identity.
|
||||
assert_eq!(Balances::free_balance(10), 80);
|
||||
|
||||
// Re-requesting won't work as we already paid.
|
||||
assert_noop!(
|
||||
Identity::request_judgement(Origin::signed(10), 0, 10),
|
||||
Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10),
|
||||
Error::<Test>::StickyJudgement
|
||||
);
|
||||
assert_ok!(Identity::provide_judgement(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
0,
|
||||
10,
|
||||
Judgement::Erroneous,
|
||||
@@ -505,33 +520,33 @@ fn requesting_judgement_should_work() {
|
||||
|
||||
// Re-requesting still won't work as it's erroneous.
|
||||
assert_noop!(
|
||||
Identity::request_judgement(Origin::signed(10), 0, 10),
|
||||
Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10),
|
||||
Error::<Test>::StickyJudgement
|
||||
);
|
||||
|
||||
// Requesting from a second registrar still works.
|
||||
assert_ok!(Identity::add_registrar(Origin::signed(1), 4));
|
||||
assert_ok!(Identity::request_judgement(Origin::signed(10), 1, 10));
|
||||
assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 4));
|
||||
assert_ok!(Identity::request_judgement(RuntimeOrigin::signed(10), 1, 10));
|
||||
|
||||
// Re-requesting after the judgement has been reduced works.
|
||||
assert_ok!(Identity::provide_judgement(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
0,
|
||||
10,
|
||||
Judgement::OutOfDate,
|
||||
BlakeTwo256::hash_of(&ten())
|
||||
));
|
||||
assert_ok!(Identity::request_judgement(Origin::signed(10), 0, 10));
|
||||
assert_ok!(Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn field_deposit_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Identity::add_registrar(Origin::signed(1), 3));
|
||||
assert_ok!(Identity::set_fee(Origin::signed(3), 0, 10));
|
||||
assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
|
||||
assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));
|
||||
assert_ok!(Identity::set_identity(
|
||||
Origin::signed(10),
|
||||
RuntimeOrigin::signed(10),
|
||||
Box::new(IdentityInfo {
|
||||
additional: vec![
|
||||
(
|
||||
@@ -555,23 +570,23 @@ fn field_deposit_should_work() {
|
||||
#[test]
|
||||
fn setting_account_id_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Identity::add_registrar(Origin::signed(1), 3));
|
||||
assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
|
||||
// account 4 cannot change the first registrar's identity since it's owned by 3.
|
||||
assert_noop!(
|
||||
Identity::set_account_id(Origin::signed(4), 0, 3),
|
||||
Identity::set_account_id(RuntimeOrigin::signed(4), 0, 3),
|
||||
Error::<Test>::InvalidIndex
|
||||
);
|
||||
// account 3 can, because that's the registrar's current account.
|
||||
assert_ok!(Identity::set_account_id(Origin::signed(3), 0, 4));
|
||||
assert_ok!(Identity::set_account_id(RuntimeOrigin::signed(3), 0, 4));
|
||||
// account 4 can now, because that's their new ID.
|
||||
assert_ok!(Identity::set_account_id(Origin::signed(4), 0, 3));
|
||||
assert_ok!(Identity::set_account_id(RuntimeOrigin::signed(4), 0, 3));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_has_identity() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten())));
|
||||
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
|
||||
assert!(Identity::has_identity(&10, IdentityField::Display as u64));
|
||||
assert!(Identity::has_identity(&10, IdentityField::Legal as u64));
|
||||
assert!(Identity::has_identity(
|
||||
|
||||
@@ -111,7 +111,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
result.execute_with(|| {
|
||||
for i in 1..=6 {
|
||||
System::inc_providers(&i);
|
||||
assert_eq!(Session::set_keys(Origin::signed(i), (i - 1).into(), vec![]), Ok(()));
|
||||
assert_eq!(Session::set_keys(RuntimeOrigin::signed(i), (i - 1).into(), vec![]), Ok(()));
|
||||
}
|
||||
});
|
||||
result
|
||||
@@ -127,7 +127,7 @@ impl frame_system::Config for Runtime {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
|
||||
@@ -141,7 +141,7 @@ fn heartbeat(
|
||||
"invalid validators len",
|
||||
e @ _ => <&'static str>::from(e),
|
||||
})?;
|
||||
ImOnline::heartbeat(Origin::none(), heartbeat, signature)
|
||||
ImOnline::heartbeat(RuntimeOrigin::none(), heartbeat, signature)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -52,7 +52,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
|
||||
@@ -104,7 +104,7 @@ fn transfer_index_on_accounts_should_work() {
|
||||
fn force_transfer_index_on_preowned_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Indices::claim(Some(1).into(), 0));
|
||||
assert_ok!(Indices::force_transfer(Origin::root(), Id(3), 0, false));
|
||||
assert_ok!(Indices::force_transfer(RuntimeOrigin::root(), Id(3), 0, false));
|
||||
assert_eq!(Balances::reserved_balance(1), 0);
|
||||
assert_eq!(Balances::reserved_balance(3), 0);
|
||||
assert_eq!(Indices::lookup_index(0), Some(3));
|
||||
@@ -114,7 +114,7 @@ fn force_transfer_index_on_preowned_should_work() {
|
||||
#[test]
|
||||
fn force_transfer_index_on_free_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Indices::force_transfer(Origin::root(), Id(3), 0, false));
|
||||
assert_ok!(Indices::force_transfer(RuntimeOrigin::root(), Id(3), 0, false));
|
||||
assert_eq!(Balances::reserved_balance(3), 0);
|
||||
assert_eq!(Indices::lookup_index(0), Some(3));
|
||||
});
|
||||
|
||||
@@ -78,7 +78,7 @@ benchmarks! {
|
||||
let calls = vec![frame_system::Call::<T>::remark { remark: vec![] }.into(); n as usize];
|
||||
let origin = T::ManagerOrigin::successful_origin();
|
||||
assert!(CallIndices::<T>::get().is_empty());
|
||||
}: _<T::Origin>(origin, calls)
|
||||
}: _<T::RuntimeOrigin>(origin, calls)
|
||||
verify {
|
||||
if !n.is_zero() {
|
||||
assert!(!CallIndices::<T>::get().is_empty());
|
||||
@@ -90,7 +90,7 @@ benchmarks! {
|
||||
let end = 10u32.into();
|
||||
let payout = 5u32.into();
|
||||
let origin = T::ManagerOrigin::successful_origin();
|
||||
}: _<T::Origin>(origin, price, end, payout, true)
|
||||
}: _<T::RuntimeOrigin>(origin, price, end, payout, true)
|
||||
verify {
|
||||
assert!(crate::Lottery::<T>::get().is_some());
|
||||
}
|
||||
@@ -99,7 +99,7 @@ benchmarks! {
|
||||
setup_lottery::<T>(true)?;
|
||||
assert_eq!(crate::Lottery::<T>::get().unwrap().repeat, true);
|
||||
let origin = T::ManagerOrigin::successful_origin();
|
||||
}: _<T::Origin>(origin)
|
||||
}: _<T::RuntimeOrigin>(origin)
|
||||
verify {
|
||||
assert_eq!(crate::Lottery::<T>::get().unwrap().repeat, false);
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ pub mod pallet {
|
||||
|
||||
/// A dispatchable call.
|
||||
type RuntimeCall: Parameter
|
||||
+ Dispatchable<Origin = Self::Origin>
|
||||
+ Dispatchable<RuntimeOrigin = Self::RuntimeOrigin>
|
||||
+ GetDispatchInfo
|
||||
+ From<frame_system::Call<Self>>;
|
||||
|
||||
@@ -149,7 +149,7 @@ pub mod pallet {
|
||||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
||||
|
||||
/// The manager origin.
|
||||
type ManagerOrigin: EnsureOrigin<Self::Origin>;
|
||||
type ManagerOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// The max number of calls available in a single lottery.
|
||||
#[pallet::constant]
|
||||
|
||||
@@ -57,7 +57,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type BlockNumber = u64;
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
use super::*;
|
||||
use frame_support::{assert_noop, assert_ok, assert_storage_noop};
|
||||
use mock::{
|
||||
new_test_ext, run_to_block, Balances, BalancesCall, Lottery, Origin, RuntimeCall, SystemCall,
|
||||
Test,
|
||||
new_test_ext, run_to_block, Balances, BalancesCall, Lottery, RuntimeCall, RuntimeOrigin,
|
||||
SystemCall, Test,
|
||||
};
|
||||
use pallet_balances::Error as BalancesError;
|
||||
use sp_runtime::traits::BadOrigin;
|
||||
@@ -49,15 +49,15 @@ fn basic_end_to_end_works() {
|
||||
];
|
||||
|
||||
// Set calls for the lottery
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), calls));
|
||||
assert_ok!(Lottery::set_calls(RuntimeOrigin::root(), calls));
|
||||
|
||||
// Start lottery, it repeats
|
||||
assert_ok!(Lottery::start_lottery(Origin::root(), price, length, delay, true));
|
||||
assert_ok!(Lottery::start_lottery(RuntimeOrigin::root(), price, length, delay, true));
|
||||
assert!(crate::Lottery::<Test>::get().is_some());
|
||||
|
||||
assert_eq!(Balances::free_balance(&1), 100);
|
||||
let call = Box::new(RuntimeCall::Balances(BalancesCall::transfer { dest: 2, value: 20 }));
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(1), call.clone()));
|
||||
assert_ok!(Lottery::buy_ticket(RuntimeOrigin::signed(1), call.clone()));
|
||||
// 20 from the transfer, 10 from buying a ticket
|
||||
assert_eq!(Balances::free_balance(&1), 100 - 20 - 10);
|
||||
assert_eq!(Participants::<Test>::get(&1).1.len(), 1);
|
||||
@@ -66,14 +66,14 @@ fn basic_end_to_end_works() {
|
||||
assert_eq!(Tickets::<Test>::get(0), Some(1));
|
||||
|
||||
// More ticket purchases
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(2), call.clone()));
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(3), call.clone()));
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(4), call.clone()));
|
||||
assert_ok!(Lottery::buy_ticket(RuntimeOrigin::signed(2), call.clone()));
|
||||
assert_ok!(Lottery::buy_ticket(RuntimeOrigin::signed(3), call.clone()));
|
||||
assert_ok!(Lottery::buy_ticket(RuntimeOrigin::signed(4), call.clone()));
|
||||
assert_eq!(TicketsCount::<Test>::get(), 4);
|
||||
|
||||
// Go to end
|
||||
run_to_block(20);
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(5), call.clone()));
|
||||
assert_ok!(Lottery::buy_ticket(RuntimeOrigin::signed(5), call.clone()));
|
||||
// Ticket isn't bought
|
||||
assert_eq!(TicketsCount::<Test>::get(), 4);
|
||||
|
||||
@@ -100,15 +100,15 @@ fn stop_repeat_works() {
|
||||
let delay = 5;
|
||||
|
||||
// Set no calls for the lottery.
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), vec![]));
|
||||
assert_ok!(Lottery::set_calls(RuntimeOrigin::root(), vec![]));
|
||||
// Start lottery, it repeats.
|
||||
assert_ok!(Lottery::start_lottery(Origin::root(), price, length, delay, true));
|
||||
assert_ok!(Lottery::start_lottery(RuntimeOrigin::root(), price, length, delay, true));
|
||||
|
||||
// Non-manager fails to `stop_repeat`.
|
||||
assert_noop!(Lottery::stop_repeat(Origin::signed(1)), DispatchError::BadOrigin);
|
||||
assert_noop!(Lottery::stop_repeat(RuntimeOrigin::signed(1)), DispatchError::BadOrigin);
|
||||
// Manager can `stop_repeat`, even twice.
|
||||
assert_ok!(Lottery::stop_repeat(Origin::root()));
|
||||
assert_ok!(Lottery::stop_repeat(Origin::root()));
|
||||
assert_ok!(Lottery::stop_repeat(RuntimeOrigin::root()));
|
||||
assert_ok!(Lottery::stop_repeat(RuntimeOrigin::root()));
|
||||
|
||||
// Lottery still exists.
|
||||
assert!(crate::Lottery::<Test>::get().is_some());
|
||||
@@ -132,7 +132,7 @@ fn set_calls_works() {
|
||||
RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 }),
|
||||
];
|
||||
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), calls));
|
||||
assert_ok!(Lottery::set_calls(RuntimeOrigin::root(), calls));
|
||||
assert!(CallIndices::<Test>::exists());
|
||||
|
||||
let too_many_calls = vec![
|
||||
@@ -142,12 +142,12 @@ fn set_calls_works() {
|
||||
];
|
||||
|
||||
assert_noop!(
|
||||
Lottery::set_calls(Origin::root(), too_many_calls),
|
||||
Lottery::set_calls(RuntimeOrigin::root(), too_many_calls),
|
||||
Error::<Test>::TooManyCalls,
|
||||
);
|
||||
|
||||
// Clear calls
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), vec![]));
|
||||
assert_ok!(Lottery::set_calls(RuntimeOrigin::root(), vec![]));
|
||||
assert!(CallIndices::<Test>::get().is_empty());
|
||||
});
|
||||
}
|
||||
@@ -182,16 +182,16 @@ fn start_lottery_works() {
|
||||
|
||||
// Setup ignores bad origin
|
||||
assert_noop!(
|
||||
Lottery::start_lottery(Origin::signed(1), price, length, delay, false),
|
||||
Lottery::start_lottery(RuntimeOrigin::signed(1), price, length, delay, false),
|
||||
BadOrigin,
|
||||
);
|
||||
|
||||
// All good
|
||||
assert_ok!(Lottery::start_lottery(Origin::root(), price, length, delay, false));
|
||||
assert_ok!(Lottery::start_lottery(RuntimeOrigin::root(), price, length, delay, false));
|
||||
|
||||
// Can't open another one if lottery is already present
|
||||
assert_noop!(
|
||||
Lottery::start_lottery(Origin::root(), price, length, delay, false),
|
||||
Lottery::start_lottery(RuntimeOrigin::root(), price, length, delay, false),
|
||||
Error::<Test>::InProgress,
|
||||
);
|
||||
});
|
||||
@@ -205,7 +205,7 @@ fn buy_ticket_works_as_simple_passthrough() {
|
||||
// No lottery set up
|
||||
let call = Box::new(RuntimeCall::Balances(BalancesCall::transfer { dest: 2, value: 20 }));
|
||||
// This is just a basic transfer then
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(1), call.clone()));
|
||||
assert_ok!(Lottery::buy_ticket(RuntimeOrigin::signed(1), call.clone()));
|
||||
assert_eq!(Balances::free_balance(&1), 100 - 20);
|
||||
assert_eq!(TicketsCount::<Test>::get(), 0);
|
||||
|
||||
@@ -214,11 +214,11 @@ fn buy_ticket_works_as_simple_passthrough() {
|
||||
RuntimeCall::Balances(BalancesCall::force_transfer { source: 0, dest: 0, value: 0 }),
|
||||
RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 }),
|
||||
];
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), calls));
|
||||
assert_ok!(Lottery::set_calls(RuntimeOrigin::root(), calls));
|
||||
|
||||
// Ticket price of 60 would kill the user's account
|
||||
assert_ok!(Lottery::start_lottery(Origin::root(), 60, 10, 5, false));
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(1), call.clone()));
|
||||
assert_ok!(Lottery::start_lottery(RuntimeOrigin::root(), 60, 10, 5, false));
|
||||
assert_ok!(Lottery::buy_ticket(RuntimeOrigin::signed(1), call.clone()));
|
||||
assert_eq!(Balances::free_balance(&1), 100 - 20 - 20);
|
||||
assert_eq!(TicketsCount::<Test>::get(), 0);
|
||||
|
||||
@@ -226,7 +226,7 @@ fn buy_ticket_works_as_simple_passthrough() {
|
||||
let fail_call =
|
||||
Box::new(RuntimeCall::Balances(BalancesCall::transfer { dest: 2, value: 1000 }));
|
||||
assert_noop!(
|
||||
Lottery::buy_ticket(Origin::signed(1), fail_call),
|
||||
Lottery::buy_ticket(RuntimeOrigin::signed(1), fail_call),
|
||||
BalancesError::<Test, _>::InsufficientBalance,
|
||||
);
|
||||
|
||||
@@ -235,17 +235,17 @@ fn buy_ticket_works_as_simple_passthrough() {
|
||||
dest: 0,
|
||||
value: 0,
|
||||
}));
|
||||
assert_noop!(Lottery::buy_ticket(Origin::signed(1), bad_origin_call), BadOrigin,);
|
||||
assert_noop!(Lottery::buy_ticket(RuntimeOrigin::signed(1), bad_origin_call), BadOrigin,);
|
||||
|
||||
// User can call other txs, but doesn't get a ticket
|
||||
let remark_call =
|
||||
Box::new(RuntimeCall::System(SystemCall::remark { remark: b"hello, world!".to_vec() }));
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(2), remark_call));
|
||||
assert_ok!(Lottery::buy_ticket(RuntimeOrigin::signed(2), remark_call));
|
||||
assert_eq!(TicketsCount::<Test>::get(), 0);
|
||||
|
||||
let successful_call =
|
||||
Box::new(RuntimeCall::Balances(BalancesCall::transfer { dest: 2, value: 1 }));
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(2), successful_call));
|
||||
assert_ok!(Lottery::buy_ticket(RuntimeOrigin::signed(2), successful_call));
|
||||
assert_eq!(TicketsCount::<Test>::get(), 1);
|
||||
});
|
||||
}
|
||||
@@ -258,40 +258,40 @@ fn buy_ticket_works() {
|
||||
RuntimeCall::System(SystemCall::remark { remark: vec![] }),
|
||||
RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 }),
|
||||
];
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), calls));
|
||||
assert_ok!(Lottery::set_calls(RuntimeOrigin::root(), calls));
|
||||
|
||||
// Can't buy ticket before start
|
||||
let call = Box::new(RuntimeCall::Balances(BalancesCall::transfer { dest: 2, value: 1 }));
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(1), call.clone()));
|
||||
assert_ok!(Lottery::buy_ticket(RuntimeOrigin::signed(1), call.clone()));
|
||||
assert_eq!(TicketsCount::<Test>::get(), 0);
|
||||
|
||||
// Start lottery
|
||||
assert_ok!(Lottery::start_lottery(Origin::root(), 1, 20, 5, false));
|
||||
assert_ok!(Lottery::start_lottery(RuntimeOrigin::root(), 1, 20, 5, false));
|
||||
|
||||
// Go to start, buy ticket for transfer
|
||||
run_to_block(5);
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(1), call));
|
||||
assert_ok!(Lottery::buy_ticket(RuntimeOrigin::signed(1), call));
|
||||
assert_eq!(TicketsCount::<Test>::get(), 1);
|
||||
|
||||
// Can't buy another of the same ticket (even if call is slightly changed)
|
||||
let call = Box::new(RuntimeCall::Balances(BalancesCall::transfer { dest: 3, value: 30 }));
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(1), call));
|
||||
assert_ok!(Lottery::buy_ticket(RuntimeOrigin::signed(1), call));
|
||||
assert_eq!(TicketsCount::<Test>::get(), 1);
|
||||
|
||||
// Buy ticket for remark
|
||||
let call =
|
||||
Box::new(RuntimeCall::System(SystemCall::remark { remark: b"hello, world!".to_vec() }));
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(1), call.clone()));
|
||||
assert_ok!(Lottery::buy_ticket(RuntimeOrigin::signed(1), call.clone()));
|
||||
assert_eq!(TicketsCount::<Test>::get(), 2);
|
||||
|
||||
// Go to end, can't buy tickets anymore
|
||||
run_to_block(20);
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(2), call.clone()));
|
||||
assert_ok!(Lottery::buy_ticket(RuntimeOrigin::signed(2), call.clone()));
|
||||
assert_eq!(TicketsCount::<Test>::get(), 2);
|
||||
|
||||
// Go to payout, can't buy tickets when there is no lottery open
|
||||
run_to_block(25);
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(2), call.clone()));
|
||||
assert_ok!(Lottery::buy_ticket(RuntimeOrigin::signed(2), call.clone()));
|
||||
assert_eq!(TicketsCount::<Test>::get(), 0);
|
||||
assert_eq!(LotteryIndex::<Test>::get(), 1);
|
||||
});
|
||||
@@ -303,8 +303,8 @@ fn buy_ticket_works() {
|
||||
fn do_buy_ticket_already_participating() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let calls = vec![RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 })];
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), calls.clone()));
|
||||
assert_ok!(Lottery::start_lottery(Origin::root(), 1, 10, 10, false));
|
||||
assert_ok!(Lottery::set_calls(RuntimeOrigin::root(), calls.clone()));
|
||||
assert_ok!(Lottery::start_lottery(RuntimeOrigin::root(), 1, 10, 10, false));
|
||||
|
||||
// Buying once works.
|
||||
assert_ok!(Lottery::do_buy_ticket(&1, &calls[0]));
|
||||
@@ -318,15 +318,15 @@ fn do_buy_ticket_already_participating() {
|
||||
fn buy_ticket_already_participating() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let calls = vec![RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 })];
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), calls.clone()));
|
||||
assert_ok!(Lottery::start_lottery(Origin::root(), 1, 10, 10, false));
|
||||
assert_ok!(Lottery::set_calls(RuntimeOrigin::root(), calls.clone()));
|
||||
assert_ok!(Lottery::start_lottery(RuntimeOrigin::root(), 1, 10, 10, false));
|
||||
|
||||
// Buying once works.
|
||||
let call = Box::new(calls[0].clone());
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(1), call.clone()));
|
||||
assert_ok!(Lottery::buy_ticket(RuntimeOrigin::signed(1), call.clone()));
|
||||
|
||||
// Buying the same ticket again returns Ok, but changes nothing.
|
||||
assert_storage_noop!(Lottery::buy_ticket(Origin::signed(1), call).unwrap());
|
||||
assert_storage_noop!(Lottery::buy_ticket(RuntimeOrigin::signed(1), call).unwrap());
|
||||
|
||||
// Exactly one ticket exists.
|
||||
assert_eq!(TicketsCount::<Test>::get(), 1);
|
||||
@@ -338,13 +338,13 @@ fn buy_ticket_already_participating() {
|
||||
fn buy_ticket_insufficient_balance() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let calls = vec![RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 })];
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), calls.clone()));
|
||||
assert_ok!(Lottery::set_calls(RuntimeOrigin::root(), calls.clone()));
|
||||
// Price set to 100.
|
||||
assert_ok!(Lottery::start_lottery(Origin::root(), 100, 10, 10, false));
|
||||
assert_ok!(Lottery::start_lottery(RuntimeOrigin::root(), 100, 10, 10, false));
|
||||
let call = Box::new(calls[0].clone());
|
||||
|
||||
// Buying a ticket returns Ok, but changes nothing.
|
||||
assert_storage_noop!(Lottery::buy_ticket(Origin::signed(1), call).unwrap());
|
||||
assert_storage_noop!(Lottery::buy_ticket(RuntimeOrigin::signed(1), call).unwrap());
|
||||
assert!(TicketsCount::<Test>::get().is_zero());
|
||||
});
|
||||
}
|
||||
@@ -353,9 +353,9 @@ fn buy_ticket_insufficient_balance() {
|
||||
fn do_buy_ticket_insufficient_balance() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let calls = vec![RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 })];
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), calls.clone()));
|
||||
assert_ok!(Lottery::set_calls(RuntimeOrigin::root(), calls.clone()));
|
||||
// Price set to 101.
|
||||
assert_ok!(Lottery::start_lottery(Origin::root(), 101, 10, 10, false));
|
||||
assert_ok!(Lottery::start_lottery(RuntimeOrigin::root(), 101, 10, 10, false));
|
||||
|
||||
// Buying fails with InsufficientBalance.
|
||||
assert_noop!(
|
||||
@@ -370,9 +370,9 @@ fn do_buy_ticket_insufficient_balance() {
|
||||
fn do_buy_ticket_keep_alive() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let calls = vec![RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 })];
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), calls.clone()));
|
||||
assert_ok!(Lottery::set_calls(RuntimeOrigin::root(), calls.clone()));
|
||||
// Price set to 100.
|
||||
assert_ok!(Lottery::start_lottery(Origin::root(), 100, 10, 10, false));
|
||||
assert_ok!(Lottery::start_lottery(RuntimeOrigin::root(), 100, 10, 10, false));
|
||||
|
||||
// Buying fails with KeepAlive.
|
||||
assert_noop!(Lottery::do_buy_ticket(&1, &calls[0]), BalancesError::<Test, _>::KeepAlive);
|
||||
@@ -388,9 +388,9 @@ fn no_participants_works() {
|
||||
let delay = 5;
|
||||
|
||||
// Set no calls for the lottery.
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), vec![]));
|
||||
assert_ok!(Lottery::set_calls(RuntimeOrigin::root(), vec![]));
|
||||
// Start lottery.
|
||||
assert_ok!(Lottery::start_lottery(Origin::root(), 10, length, delay, false));
|
||||
assert_ok!(Lottery::start_lottery(RuntimeOrigin::root(), 10, length, delay, false));
|
||||
|
||||
// End the lottery, no one wins.
|
||||
run_to_block(length + delay);
|
||||
@@ -405,7 +405,7 @@ fn start_lottery_will_create_account() {
|
||||
let delay = 5;
|
||||
|
||||
assert_eq!(Balances::total_balance(&Lottery::account_id()), 0);
|
||||
assert_ok!(Lottery::start_lottery(Origin::root(), price, length, delay, false));
|
||||
assert_ok!(Lottery::start_lottery(RuntimeOrigin::root(), price, length, delay, false));
|
||||
assert_eq!(Balances::total_balance(&Lottery::account_id()), 1);
|
||||
});
|
||||
}
|
||||
@@ -422,12 +422,12 @@ fn choose_ticket_trivial_cases() {
|
||||
fn choose_account_one_participant() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let calls = vec![RuntimeCall::Balances(BalancesCall::transfer { dest: 0, value: 0 })];
|
||||
assert_ok!(Lottery::set_calls(Origin::root(), calls.clone()));
|
||||
assert_ok!(Lottery::start_lottery(Origin::root(), 10, 10, 10, false));
|
||||
assert_ok!(Lottery::set_calls(RuntimeOrigin::root(), calls.clone()));
|
||||
assert_ok!(Lottery::start_lottery(RuntimeOrigin::root(), 10, 10, 10, false));
|
||||
let call = Box::new(calls[0].clone());
|
||||
|
||||
// Buy one ticket with account 1.
|
||||
assert_ok!(Lottery::buy_ticket(Origin::signed(1), call));
|
||||
assert_ok!(Lottery::buy_ticket(RuntimeOrigin::signed(1), call));
|
||||
// Account 1 is always the winner.
|
||||
assert_eq!(Lottery::choose_account().unwrap(), 1);
|
||||
});
|
||||
|
||||
@@ -59,19 +59,19 @@ pub mod pallet {
|
||||
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
||||
|
||||
/// Required origin for adding a member (though can always be Root).
|
||||
type AddOrigin: EnsureOrigin<Self::Origin>;
|
||||
type AddOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// Required origin for removing a member (though can always be Root).
|
||||
type RemoveOrigin: EnsureOrigin<Self::Origin>;
|
||||
type RemoveOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// Required origin for adding and removing a member in a single action.
|
||||
type SwapOrigin: EnsureOrigin<Self::Origin>;
|
||||
type SwapOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// Required origin for resetting membership.
|
||||
type ResetOrigin: EnsureOrigin<Self::Origin>;
|
||||
type ResetOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// Required origin for setting or resetting the prime member.
|
||||
type PrimeOrigin: EnsureOrigin<Self::Origin>;
|
||||
type PrimeOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// The receiver of the signal for when the membership has been initialized. This happens
|
||||
/// pre-genesis and will usually be the same as `MembershipChanged`. If you need to do
|
||||
@@ -543,7 +543,7 @@ mod tests {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
@@ -647,13 +647,16 @@ mod tests {
|
||||
#[test]
|
||||
fn prime_member_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(Membership::set_prime(Origin::signed(4), 20), BadOrigin);
|
||||
assert_noop!(Membership::set_prime(Origin::signed(5), 15), Error::<Test, _>::NotMember);
|
||||
assert_ok!(Membership::set_prime(Origin::signed(5), 20));
|
||||
assert_noop!(Membership::set_prime(RuntimeOrigin::signed(4), 20), BadOrigin);
|
||||
assert_noop!(
|
||||
Membership::set_prime(RuntimeOrigin::signed(5), 15),
|
||||
Error::<Test, _>::NotMember
|
||||
);
|
||||
assert_ok!(Membership::set_prime(RuntimeOrigin::signed(5), 20));
|
||||
assert_eq!(Membership::prime(), Some(20));
|
||||
assert_eq!(PRIME.with(|m| *m.borrow()), Membership::prime());
|
||||
|
||||
assert_ok!(Membership::clear_prime(Origin::signed(5)));
|
||||
assert_ok!(Membership::clear_prime(RuntimeOrigin::signed(5)));
|
||||
assert_eq!(Membership::prime(), None);
|
||||
assert_eq!(PRIME.with(|m| *m.borrow()), Membership::prime());
|
||||
});
|
||||
@@ -662,12 +665,12 @@ mod tests {
|
||||
#[test]
|
||||
fn add_member_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(Membership::add_member(Origin::signed(5), 15), BadOrigin);
|
||||
assert_noop!(Membership::add_member(RuntimeOrigin::signed(5), 15), BadOrigin);
|
||||
assert_noop!(
|
||||
Membership::add_member(Origin::signed(1), 10),
|
||||
Membership::add_member(RuntimeOrigin::signed(1), 10),
|
||||
Error::<Test, _>::AlreadyMember
|
||||
);
|
||||
assert_ok!(Membership::add_member(Origin::signed(1), 15));
|
||||
assert_ok!(Membership::add_member(RuntimeOrigin::signed(1), 15));
|
||||
assert_eq!(Membership::members(), vec![10, 15, 20, 30]);
|
||||
assert_eq!(MEMBERS.with(|m| m.borrow().clone()), Membership::members().to_vec());
|
||||
});
|
||||
@@ -676,13 +679,13 @@ mod tests {
|
||||
#[test]
|
||||
fn remove_member_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(Membership::remove_member(Origin::signed(5), 20), BadOrigin);
|
||||
assert_noop!(Membership::remove_member(RuntimeOrigin::signed(5), 20), BadOrigin);
|
||||
assert_noop!(
|
||||
Membership::remove_member(Origin::signed(2), 15),
|
||||
Membership::remove_member(RuntimeOrigin::signed(2), 15),
|
||||
Error::<Test, _>::NotMember
|
||||
);
|
||||
assert_ok!(Membership::set_prime(Origin::signed(5), 20));
|
||||
assert_ok!(Membership::remove_member(Origin::signed(2), 20));
|
||||
assert_ok!(Membership::set_prime(RuntimeOrigin::signed(5), 20));
|
||||
assert_ok!(Membership::remove_member(RuntimeOrigin::signed(2), 20));
|
||||
assert_eq!(Membership::members(), vec![10, 30]);
|
||||
assert_eq!(MEMBERS.with(|m| m.borrow().clone()), Membership::members().to_vec());
|
||||
assert_eq!(Membership::prime(), None);
|
||||
@@ -693,24 +696,24 @@ mod tests {
|
||||
#[test]
|
||||
fn swap_member_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(Membership::swap_member(Origin::signed(5), 10, 25), BadOrigin);
|
||||
assert_noop!(Membership::swap_member(RuntimeOrigin::signed(5), 10, 25), BadOrigin);
|
||||
assert_noop!(
|
||||
Membership::swap_member(Origin::signed(3), 15, 25),
|
||||
Membership::swap_member(RuntimeOrigin::signed(3), 15, 25),
|
||||
Error::<Test, _>::NotMember
|
||||
);
|
||||
assert_noop!(
|
||||
Membership::swap_member(Origin::signed(3), 10, 30),
|
||||
Membership::swap_member(RuntimeOrigin::signed(3), 10, 30),
|
||||
Error::<Test, _>::AlreadyMember
|
||||
);
|
||||
|
||||
assert_ok!(Membership::set_prime(Origin::signed(5), 20));
|
||||
assert_ok!(Membership::swap_member(Origin::signed(3), 20, 20));
|
||||
assert_ok!(Membership::set_prime(RuntimeOrigin::signed(5), 20));
|
||||
assert_ok!(Membership::swap_member(RuntimeOrigin::signed(3), 20, 20));
|
||||
assert_eq!(Membership::members(), vec![10, 20, 30]);
|
||||
assert_eq!(Membership::prime(), Some(20));
|
||||
assert_eq!(PRIME.with(|m| *m.borrow()), Membership::prime());
|
||||
|
||||
assert_ok!(Membership::set_prime(Origin::signed(5), 10));
|
||||
assert_ok!(Membership::swap_member(Origin::signed(3), 10, 25));
|
||||
assert_ok!(Membership::set_prime(RuntimeOrigin::signed(5), 10));
|
||||
assert_ok!(Membership::swap_member(RuntimeOrigin::signed(3), 10, 25));
|
||||
assert_eq!(Membership::members(), vec![20, 25, 30]);
|
||||
assert_eq!(MEMBERS.with(|m| m.borrow().clone()), Membership::members().to_vec());
|
||||
assert_eq!(Membership::prime(), None);
|
||||
@@ -721,7 +724,7 @@ mod tests {
|
||||
#[test]
|
||||
fn swap_member_works_that_does_not_change_order() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Membership::swap_member(Origin::signed(3), 10, 5));
|
||||
assert_ok!(Membership::swap_member(RuntimeOrigin::signed(3), 10, 5));
|
||||
assert_eq!(Membership::members(), vec![5, 20, 30]);
|
||||
assert_eq!(MEMBERS.with(|m| m.borrow().clone()), Membership::members().to_vec());
|
||||
});
|
||||
@@ -730,16 +733,16 @@ mod tests {
|
||||
#[test]
|
||||
fn change_key_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Membership::set_prime(Origin::signed(5), 10));
|
||||
assert_ok!(Membership::set_prime(RuntimeOrigin::signed(5), 10));
|
||||
assert_noop!(
|
||||
Membership::change_key(Origin::signed(3), 25),
|
||||
Membership::change_key(RuntimeOrigin::signed(3), 25),
|
||||
Error::<Test, _>::NotMember
|
||||
);
|
||||
assert_noop!(
|
||||
Membership::change_key(Origin::signed(10), 20),
|
||||
Membership::change_key(RuntimeOrigin::signed(10), 20),
|
||||
Error::<Test, _>::AlreadyMember
|
||||
);
|
||||
assert_ok!(Membership::change_key(Origin::signed(10), 40));
|
||||
assert_ok!(Membership::change_key(RuntimeOrigin::signed(10), 40));
|
||||
assert_eq!(Membership::members(), vec![20, 30, 40]);
|
||||
assert_eq!(MEMBERS.with(|m| m.borrow().clone()), Membership::members().to_vec());
|
||||
assert_eq!(Membership::prime(), Some(40));
|
||||
@@ -750,7 +753,7 @@ mod tests {
|
||||
#[test]
|
||||
fn change_key_works_that_does_not_change_order() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Membership::change_key(Origin::signed(10), 5));
|
||||
assert_ok!(Membership::change_key(RuntimeOrigin::signed(10), 5));
|
||||
assert_eq!(Membership::members(), vec![5, 20, 30]);
|
||||
assert_eq!(MEMBERS.with(|m| m.borrow().clone()), Membership::members().to_vec());
|
||||
});
|
||||
@@ -759,19 +762,19 @@ mod tests {
|
||||
#[test]
|
||||
fn reset_members_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Membership::set_prime(Origin::signed(5), 20));
|
||||
assert_ok!(Membership::set_prime(RuntimeOrigin::signed(5), 20));
|
||||
assert_noop!(
|
||||
Membership::reset_members(Origin::signed(1), bounded_vec![20, 40, 30]),
|
||||
Membership::reset_members(RuntimeOrigin::signed(1), bounded_vec![20, 40, 30]),
|
||||
BadOrigin
|
||||
);
|
||||
|
||||
assert_ok!(Membership::reset_members(Origin::signed(4), vec![20, 40, 30]));
|
||||
assert_ok!(Membership::reset_members(RuntimeOrigin::signed(4), vec![20, 40, 30]));
|
||||
assert_eq!(Membership::members(), vec![20, 30, 40]);
|
||||
assert_eq!(MEMBERS.with(|m| m.borrow().clone()), Membership::members().to_vec());
|
||||
assert_eq!(Membership::prime(), Some(20));
|
||||
assert_eq!(PRIME.with(|m| *m.borrow()), Membership::prime());
|
||||
|
||||
assert_ok!(Membership::reset_members(Origin::signed(4), vec![10, 40, 30]));
|
||||
assert_ok!(Membership::reset_members(RuntimeOrigin::signed(4), vec![10, 40, 30]));
|
||||
assert_eq!(Membership::members(), vec![10, 30, 40]);
|
||||
assert_eq!(MEMBERS.with(|m| m.borrow().clone()), Membership::members().to_vec());
|
||||
assert_eq!(Membership::prime(), None);
|
||||
|
||||
@@ -47,7 +47,7 @@ frame_support::construct_runtime!(
|
||||
|
||||
impl frame_system::Config for Test {
|
||||
type BaseCallFilter = frame_support::traits::Everything;
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
|
||||
@@ -122,7 +122,7 @@ pub mod pallet {
|
||||
|
||||
/// The overarching call type.
|
||||
type RuntimeCall: Parameter
|
||||
+ Dispatchable<Origin = Self::Origin, PostInfo = PostDispatchInfo>
|
||||
+ Dispatchable<RuntimeOrigin = Self::RuntimeOrigin, PostInfo = PostDispatchInfo>
|
||||
+ GetDispatchInfo
|
||||
+ From<frame_system::Call<Self>>;
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
@@ -138,15 +138,15 @@ fn call_transfer(dest: u64, value: u64) -> RuntimeCall {
|
||||
fn multisig_deposit_is_taken_and_returned() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let multi = Multisig::multi_account_id(&[1, 2, 3][..], 2);
|
||||
assert_ok!(Balances::transfer(Origin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(3), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(3), multi, 5));
|
||||
|
||||
let call = call_transfer(6, 15);
|
||||
let call_weight = call.get_dispatch_info().weight;
|
||||
let data = call.encode();
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
vec![2, 3],
|
||||
None,
|
||||
@@ -158,7 +158,7 @@ fn multisig_deposit_is_taken_and_returned() {
|
||||
assert_eq!(Balances::reserved_balance(1), 3);
|
||||
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
2,
|
||||
vec![1, 3],
|
||||
Some(now()),
|
||||
@@ -175,16 +175,16 @@ fn multisig_deposit_is_taken_and_returned() {
|
||||
fn multisig_deposit_is_taken_and_returned_with_call_storage() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let multi = Multisig::multi_account_id(&[1, 2, 3][..], 2);
|
||||
assert_ok!(Balances::transfer(Origin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(3), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(3), multi, 5));
|
||||
|
||||
let call = call_transfer(6, 15);
|
||||
let call_weight = call.get_dispatch_info().weight;
|
||||
let data = call.encode();
|
||||
let hash = blake2_256(&data);
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
vec![2, 3],
|
||||
None,
|
||||
@@ -196,7 +196,7 @@ fn multisig_deposit_is_taken_and_returned_with_call_storage() {
|
||||
assert_eq!(Balances::reserved_balance(1), 5);
|
||||
|
||||
assert_ok!(Multisig::approve_as_multi(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
2,
|
||||
vec![1, 3],
|
||||
Some(now()),
|
||||
@@ -212,9 +212,9 @@ fn multisig_deposit_is_taken_and_returned_with_call_storage() {
|
||||
fn multisig_deposit_is_taken_and_returned_with_alt_call_storage() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let multi = Multisig::multi_account_id(&[1, 2, 3][..], 3);
|
||||
assert_ok!(Balances::transfer(Origin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(3), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(3), multi, 5));
|
||||
|
||||
let call = call_transfer(6, 15);
|
||||
let call_weight = call.get_dispatch_info().weight;
|
||||
@@ -222,7 +222,7 @@ fn multisig_deposit_is_taken_and_returned_with_alt_call_storage() {
|
||||
let hash = blake2_256(&data);
|
||||
|
||||
assert_ok!(Multisig::approve_as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
vec![2, 3],
|
||||
None,
|
||||
@@ -233,7 +233,7 @@ fn multisig_deposit_is_taken_and_returned_with_alt_call_storage() {
|
||||
assert_eq!(Balances::reserved_balance(1), 4);
|
||||
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
3,
|
||||
vec![1, 3],
|
||||
Some(now()),
|
||||
@@ -247,7 +247,7 @@ fn multisig_deposit_is_taken_and_returned_with_alt_call_storage() {
|
||||
assert_eq!(Balances::reserved_balance(1), 4);
|
||||
|
||||
assert_ok!(Multisig::approve_as_multi(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
3,
|
||||
vec![1, 2],
|
||||
Some(now()),
|
||||
@@ -267,7 +267,7 @@ fn cancel_multisig_returns_deposit() {
|
||||
let call = call_transfer(6, 15).encode();
|
||||
let hash = blake2_256(&call);
|
||||
assert_ok!(Multisig::approve_as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
vec![2, 3],
|
||||
None,
|
||||
@@ -275,7 +275,7 @@ fn cancel_multisig_returns_deposit() {
|
||||
Weight::zero()
|
||||
));
|
||||
assert_ok!(Multisig::approve_as_multi(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
3,
|
||||
vec![1, 3],
|
||||
Some(now()),
|
||||
@@ -284,7 +284,7 @@ fn cancel_multisig_returns_deposit() {
|
||||
));
|
||||
assert_eq!(Balances::free_balance(1), 6);
|
||||
assert_eq!(Balances::reserved_balance(1), 4);
|
||||
assert_ok!(Multisig::cancel_as_multi(Origin::signed(1), 3, vec![2, 3], now(), hash));
|
||||
assert_ok!(Multisig::cancel_as_multi(RuntimeOrigin::signed(1), 3, vec![2, 3], now(), hash));
|
||||
assert_eq!(Balances::free_balance(1), 10);
|
||||
assert_eq!(Balances::reserved_balance(1), 0);
|
||||
});
|
||||
@@ -294,16 +294,16 @@ fn cancel_multisig_returns_deposit() {
|
||||
fn timepoint_checking_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let multi = Multisig::multi_account_id(&[1, 2, 3][..], 2);
|
||||
assert_ok!(Balances::transfer(Origin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(3), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(3), multi, 5));
|
||||
|
||||
let call = call_transfer(6, 15).encode();
|
||||
let hash = blake2_256(&call);
|
||||
|
||||
assert_noop!(
|
||||
Multisig::approve_as_multi(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
2,
|
||||
vec![1, 3],
|
||||
Some(now()),
|
||||
@@ -314,7 +314,7 @@ fn timepoint_checking_works() {
|
||||
);
|
||||
|
||||
assert_ok!(Multisig::approve_as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
vec![2, 3],
|
||||
None,
|
||||
@@ -324,7 +324,7 @@ fn timepoint_checking_works() {
|
||||
|
||||
assert_noop!(
|
||||
Multisig::as_multi(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
2,
|
||||
vec![1, 3],
|
||||
None,
|
||||
@@ -337,7 +337,7 @@ fn timepoint_checking_works() {
|
||||
let later = Timepoint { index: 1, ..now() };
|
||||
assert_noop!(
|
||||
Multisig::as_multi(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
2,
|
||||
vec![1, 3],
|
||||
Some(later),
|
||||
@@ -354,16 +354,16 @@ fn timepoint_checking_works() {
|
||||
fn multisig_2_of_3_works_with_call_storing() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let multi = Multisig::multi_account_id(&[1, 2, 3][..], 2);
|
||||
assert_ok!(Balances::transfer(Origin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(3), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(3), multi, 5));
|
||||
|
||||
let call = call_transfer(6, 15);
|
||||
let call_weight = call.get_dispatch_info().weight;
|
||||
let data = call.encode();
|
||||
let hash = blake2_256(&data);
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
vec![2, 3],
|
||||
None,
|
||||
@@ -374,7 +374,7 @@ fn multisig_2_of_3_works_with_call_storing() {
|
||||
assert_eq!(Balances::free_balance(6), 0);
|
||||
|
||||
assert_ok!(Multisig::approve_as_multi(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
2,
|
||||
vec![1, 3],
|
||||
Some(now()),
|
||||
@@ -389,16 +389,16 @@ fn multisig_2_of_3_works_with_call_storing() {
|
||||
fn multisig_2_of_3_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let multi = Multisig::multi_account_id(&[1, 2, 3][..], 2);
|
||||
assert_ok!(Balances::transfer(Origin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(3), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(3), multi, 5));
|
||||
|
||||
let call = call_transfer(6, 15);
|
||||
let call_weight = call.get_dispatch_info().weight;
|
||||
let data = call.encode();
|
||||
let hash = blake2_256(&data);
|
||||
assert_ok!(Multisig::approve_as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
vec![2, 3],
|
||||
None,
|
||||
@@ -408,7 +408,7 @@ fn multisig_2_of_3_works() {
|
||||
assert_eq!(Balances::free_balance(6), 0);
|
||||
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
2,
|
||||
vec![1, 3],
|
||||
Some(now()),
|
||||
@@ -424,16 +424,16 @@ fn multisig_2_of_3_works() {
|
||||
fn multisig_3_of_3_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let multi = Multisig::multi_account_id(&[1, 2, 3][..], 3);
|
||||
assert_ok!(Balances::transfer(Origin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(3), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(3), multi, 5));
|
||||
|
||||
let call = call_transfer(6, 15);
|
||||
let call_weight = call.get_dispatch_info().weight;
|
||||
let data = call.encode();
|
||||
let hash = blake2_256(&data);
|
||||
assert_ok!(Multisig::approve_as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
vec![2, 3],
|
||||
None,
|
||||
@@ -441,7 +441,7 @@ fn multisig_3_of_3_works() {
|
||||
Weight::zero()
|
||||
));
|
||||
assert_ok!(Multisig::approve_as_multi(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
3,
|
||||
vec![1, 3],
|
||||
Some(now()),
|
||||
@@ -451,7 +451,7 @@ fn multisig_3_of_3_works() {
|
||||
assert_eq!(Balances::free_balance(6), 0);
|
||||
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
3,
|
||||
vec![1, 2],
|
||||
Some(now()),
|
||||
@@ -469,7 +469,7 @@ fn cancel_multisig_works() {
|
||||
let call = call_transfer(6, 15).encode();
|
||||
let hash = blake2_256(&call);
|
||||
assert_ok!(Multisig::approve_as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
vec![2, 3],
|
||||
None,
|
||||
@@ -477,7 +477,7 @@ fn cancel_multisig_works() {
|
||||
Weight::zero()
|
||||
));
|
||||
assert_ok!(Multisig::approve_as_multi(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
3,
|
||||
vec![1, 3],
|
||||
Some(now()),
|
||||
@@ -485,10 +485,10 @@ fn cancel_multisig_works() {
|
||||
Weight::zero()
|
||||
));
|
||||
assert_noop!(
|
||||
Multisig::cancel_as_multi(Origin::signed(2), 3, vec![1, 3], now(), hash),
|
||||
Multisig::cancel_as_multi(RuntimeOrigin::signed(2), 3, vec![1, 3], now(), hash),
|
||||
Error::<Test>::NotOwner,
|
||||
);
|
||||
assert_ok!(Multisig::cancel_as_multi(Origin::signed(1), 3, vec![2, 3], now(), hash),);
|
||||
assert_ok!(Multisig::cancel_as_multi(RuntimeOrigin::signed(1), 3, vec![2, 3], now(), hash),);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -498,7 +498,7 @@ fn cancel_multisig_with_call_storage_works() {
|
||||
let call = call_transfer(6, 15).encode();
|
||||
let hash = blake2_256(&call);
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
vec![2, 3],
|
||||
None,
|
||||
@@ -508,7 +508,7 @@ fn cancel_multisig_with_call_storage_works() {
|
||||
));
|
||||
assert_eq!(Balances::free_balance(1), 4);
|
||||
assert_ok!(Multisig::approve_as_multi(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
3,
|
||||
vec![1, 3],
|
||||
Some(now()),
|
||||
@@ -516,10 +516,10 @@ fn cancel_multisig_with_call_storage_works() {
|
||||
Weight::zero()
|
||||
));
|
||||
assert_noop!(
|
||||
Multisig::cancel_as_multi(Origin::signed(2), 3, vec![1, 3], now(), hash),
|
||||
Multisig::cancel_as_multi(RuntimeOrigin::signed(2), 3, vec![1, 3], now(), hash),
|
||||
Error::<Test>::NotOwner,
|
||||
);
|
||||
assert_ok!(Multisig::cancel_as_multi(Origin::signed(1), 3, vec![2, 3], now(), hash),);
|
||||
assert_ok!(Multisig::cancel_as_multi(RuntimeOrigin::signed(1), 3, vec![2, 3], now(), hash),);
|
||||
assert_eq!(Balances::free_balance(1), 10);
|
||||
});
|
||||
}
|
||||
@@ -530,7 +530,7 @@ fn cancel_multisig_with_alt_call_storage_works() {
|
||||
let call = call_transfer(6, 15).encode();
|
||||
let hash = blake2_256(&call);
|
||||
assert_ok!(Multisig::approve_as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
vec![2, 3],
|
||||
None,
|
||||
@@ -539,7 +539,7 @@ fn cancel_multisig_with_alt_call_storage_works() {
|
||||
));
|
||||
assert_eq!(Balances::free_balance(1), 6);
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
3,
|
||||
vec![1, 3],
|
||||
Some(now()),
|
||||
@@ -548,7 +548,7 @@ fn cancel_multisig_with_alt_call_storage_works() {
|
||||
Weight::zero()
|
||||
));
|
||||
assert_eq!(Balances::free_balance(2), 8);
|
||||
assert_ok!(Multisig::cancel_as_multi(Origin::signed(1), 3, vec![2, 3], now(), hash));
|
||||
assert_ok!(Multisig::cancel_as_multi(RuntimeOrigin::signed(1), 3, vec![2, 3], now(), hash));
|
||||
assert_eq!(Balances::free_balance(1), 10);
|
||||
assert_eq!(Balances::free_balance(2), 10);
|
||||
});
|
||||
@@ -558,15 +558,15 @@ fn cancel_multisig_with_alt_call_storage_works() {
|
||||
fn multisig_2_of_3_as_multi_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let multi = Multisig::multi_account_id(&[1, 2, 3][..], 2);
|
||||
assert_ok!(Balances::transfer(Origin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(3), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(3), multi, 5));
|
||||
|
||||
let call = call_transfer(6, 15);
|
||||
let call_weight = call.get_dispatch_info().weight;
|
||||
let data = call.encode();
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
vec![2, 3],
|
||||
None,
|
||||
@@ -577,7 +577,7 @@ fn multisig_2_of_3_as_multi_works() {
|
||||
assert_eq!(Balances::free_balance(6), 0);
|
||||
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
2,
|
||||
vec![1, 3],
|
||||
Some(now()),
|
||||
@@ -593,9 +593,9 @@ fn multisig_2_of_3_as_multi_works() {
|
||||
fn multisig_2_of_3_as_multi_with_many_calls_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let multi = Multisig::multi_account_id(&[1, 2, 3][..], 2);
|
||||
assert_ok!(Balances::transfer(Origin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(3), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(3), multi, 5));
|
||||
|
||||
let call1 = call_transfer(6, 10);
|
||||
let call1_weight = call1.get_dispatch_info().weight;
|
||||
@@ -605,7 +605,7 @@ fn multisig_2_of_3_as_multi_with_many_calls_works() {
|
||||
let data2 = call2.encode();
|
||||
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
vec![2, 3],
|
||||
None,
|
||||
@@ -614,7 +614,7 @@ fn multisig_2_of_3_as_multi_with_many_calls_works() {
|
||||
Weight::zero()
|
||||
));
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
2,
|
||||
vec![1, 3],
|
||||
None,
|
||||
@@ -623,7 +623,7 @@ fn multisig_2_of_3_as_multi_with_many_calls_works() {
|
||||
Weight::zero()
|
||||
));
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
2,
|
||||
vec![1, 2],
|
||||
Some(now()),
|
||||
@@ -632,7 +632,7 @@ fn multisig_2_of_3_as_multi_with_many_calls_works() {
|
||||
call1_weight
|
||||
));
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
2,
|
||||
vec![1, 2],
|
||||
Some(now()),
|
||||
@@ -650,16 +650,16 @@ fn multisig_2_of_3_as_multi_with_many_calls_works() {
|
||||
fn multisig_2_of_3_cannot_reissue_same_call() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let multi = Multisig::multi_account_id(&[1, 2, 3][..], 2);
|
||||
assert_ok!(Balances::transfer(Origin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(3), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(3), multi, 5));
|
||||
|
||||
let call = call_transfer(6, 10);
|
||||
let call_weight = call.get_dispatch_info().weight;
|
||||
let data = call.encode();
|
||||
let hash = blake2_256(&data);
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
vec![2, 3],
|
||||
None,
|
||||
@@ -668,7 +668,7 @@ fn multisig_2_of_3_cannot_reissue_same_call() {
|
||||
Weight::zero()
|
||||
));
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
2,
|
||||
vec![1, 3],
|
||||
Some(now()),
|
||||
@@ -679,7 +679,7 @@ fn multisig_2_of_3_cannot_reissue_same_call() {
|
||||
assert_eq!(Balances::free_balance(multi), 5);
|
||||
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
vec![2, 3],
|
||||
None,
|
||||
@@ -688,7 +688,7 @@ fn multisig_2_of_3_cannot_reissue_same_call() {
|
||||
Weight::zero()
|
||||
));
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
2,
|
||||
vec![1, 2],
|
||||
Some(now()),
|
||||
@@ -717,7 +717,7 @@ fn minimum_threshold_check_works() {
|
||||
let call = call_transfer(6, 15).encode();
|
||||
assert_noop!(
|
||||
Multisig::as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
0,
|
||||
vec![2],
|
||||
None,
|
||||
@@ -729,7 +729,7 @@ fn minimum_threshold_check_works() {
|
||||
);
|
||||
assert_noop!(
|
||||
Multisig::as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
1,
|
||||
vec![2],
|
||||
None,
|
||||
@@ -748,7 +748,7 @@ fn too_many_signatories_fails() {
|
||||
let call = call_transfer(6, 15).encode();
|
||||
assert_noop!(
|
||||
Multisig::as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
vec![2, 3, 4],
|
||||
None,
|
||||
@@ -767,7 +767,7 @@ fn duplicate_approvals_are_ignored() {
|
||||
let call = call_transfer(6, 15).encode();
|
||||
let hash = blake2_256(&call);
|
||||
assert_ok!(Multisig::approve_as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
vec![2, 3],
|
||||
None,
|
||||
@@ -776,7 +776,7 @@ fn duplicate_approvals_are_ignored() {
|
||||
));
|
||||
assert_noop!(
|
||||
Multisig::approve_as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
vec![2, 3],
|
||||
Some(now()),
|
||||
@@ -786,7 +786,7 @@ fn duplicate_approvals_are_ignored() {
|
||||
Error::<Test>::AlreadyApproved,
|
||||
);
|
||||
assert_ok!(Multisig::approve_as_multi(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
2,
|
||||
vec![1, 3],
|
||||
Some(now()),
|
||||
@@ -795,7 +795,7 @@ fn duplicate_approvals_are_ignored() {
|
||||
));
|
||||
assert_noop!(
|
||||
Multisig::approve_as_multi(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
2,
|
||||
vec![1, 2],
|
||||
Some(now()),
|
||||
@@ -811,15 +811,15 @@ fn duplicate_approvals_are_ignored() {
|
||||
fn multisig_1_of_3_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let multi = Multisig::multi_account_id(&[1, 2, 3][..], 1);
|
||||
assert_ok!(Balances::transfer(Origin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(3), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(3), multi, 5));
|
||||
|
||||
let call = call_transfer(6, 15).encode();
|
||||
let hash = blake2_256(&call);
|
||||
assert_noop!(
|
||||
Multisig::approve_as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
1,
|
||||
vec![2, 3],
|
||||
None,
|
||||
@@ -830,7 +830,7 @@ fn multisig_1_of_3_works() {
|
||||
);
|
||||
assert_noop!(
|
||||
Multisig::as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
1,
|
||||
vec![2, 3],
|
||||
None,
|
||||
@@ -841,7 +841,11 @@ fn multisig_1_of_3_works() {
|
||||
Error::<Test>::MinimumThreshold,
|
||||
);
|
||||
let boxed_call = Box::new(call_transfer(6, 15));
|
||||
assert_ok!(Multisig::as_multi_threshold_1(Origin::signed(1), vec![2, 3], boxed_call));
|
||||
assert_ok!(Multisig::as_multi_threshold_1(
|
||||
RuntimeOrigin::signed(1),
|
||||
vec![2, 3],
|
||||
boxed_call
|
||||
));
|
||||
|
||||
assert_eq!(Balances::free_balance(6), 15);
|
||||
});
|
||||
@@ -852,7 +856,7 @@ fn multisig_filters() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let call = Box::new(RuntimeCall::System(frame_system::Call::set_code { code: vec![] }));
|
||||
assert_noop!(
|
||||
Multisig::as_multi_threshold_1(Origin::signed(1), vec![2], call.clone()),
|
||||
Multisig::as_multi_threshold_1(RuntimeOrigin::signed(1), vec![2], call.clone()),
|
||||
DispatchError::from(frame_system::Error::<Test>::CallFiltered),
|
||||
);
|
||||
});
|
||||
@@ -862,14 +866,14 @@ fn multisig_filters() {
|
||||
fn weight_check_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let multi = Multisig::multi_account_id(&[1, 2, 3][..], 2);
|
||||
assert_ok!(Balances::transfer(Origin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(3), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(3), multi, 5));
|
||||
|
||||
let call = call_transfer(6, 15);
|
||||
let data = call.encode();
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
vec![2, 3],
|
||||
None,
|
||||
@@ -881,7 +885,7 @@ fn weight_check_works() {
|
||||
|
||||
assert_noop!(
|
||||
Multisig::as_multi(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
2,
|
||||
vec![1, 3],
|
||||
Some(now()),
|
||||
@@ -901,16 +905,16 @@ fn multisig_handles_no_preimage_after_all_approve() {
|
||||
// the call will go through.
|
||||
new_test_ext().execute_with(|| {
|
||||
let multi = Multisig::multi_account_id(&[1, 2, 3][..], 3);
|
||||
assert_ok!(Balances::transfer(Origin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(Origin::signed(3), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(1), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(2), multi, 5));
|
||||
assert_ok!(Balances::transfer(RuntimeOrigin::signed(3), multi, 5));
|
||||
|
||||
let call = call_transfer(6, 15);
|
||||
let call_weight = call.get_dispatch_info().weight;
|
||||
let data = call.encode();
|
||||
let hash = blake2_256(&data);
|
||||
assert_ok!(Multisig::approve_as_multi(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
3,
|
||||
vec![2, 3],
|
||||
None,
|
||||
@@ -918,7 +922,7 @@ fn multisig_handles_no_preimage_after_all_approve() {
|
||||
Weight::zero()
|
||||
));
|
||||
assert_ok!(Multisig::approve_as_multi(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
3,
|
||||
vec![1, 3],
|
||||
Some(now()),
|
||||
@@ -926,7 +930,7 @@ fn multisig_handles_no_preimage_after_all_approve() {
|
||||
Weight::zero()
|
||||
));
|
||||
assert_ok!(Multisig::approve_as_multi(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
3,
|
||||
vec![1, 2],
|
||||
Some(now()),
|
||||
@@ -936,7 +940,7 @@ fn multisig_handles_no_preimage_after_all_approve() {
|
||||
assert_eq!(Balances::free_balance(6), 0);
|
||||
|
||||
assert_ok!(Multisig::as_multi(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
3,
|
||||
vec![1, 2],
|
||||
Some(now()),
|
||||
|
||||
@@ -71,7 +71,7 @@ pub mod pallet {
|
||||
type Slashed: OnUnbalanced<NegativeImbalanceOf<Self>>;
|
||||
|
||||
/// The origin which may forcibly set or remove a name. Root can always do this.
|
||||
type ForceOrigin: EnsureOrigin<Self::Origin>;
|
||||
type ForceOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// The minimum length a name may be.
|
||||
#[pallet::constant]
|
||||
@@ -280,7 +280,7 @@ mod tests {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
@@ -338,9 +338,9 @@ mod tests {
|
||||
#[test]
|
||||
fn kill_name_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Nicks::set_name(Origin::signed(2), b"Dave".to_vec()));
|
||||
assert_ok!(Nicks::set_name(RuntimeOrigin::signed(2), b"Dave".to_vec()));
|
||||
assert_eq!(Balances::total_balance(&2), 10);
|
||||
assert_ok!(Nicks::kill_name(Origin::signed(1), 2));
|
||||
assert_ok!(Nicks::kill_name(RuntimeOrigin::signed(1), 2));
|
||||
assert_eq!(Balances::total_balance(&2), 8);
|
||||
assert_eq!(<NameOf<Test>>::get(2), None);
|
||||
});
|
||||
@@ -350,17 +350,21 @@ mod tests {
|
||||
fn force_name_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
Nicks::set_name(Origin::signed(2), b"Dr. David Brubeck, III".to_vec()),
|
||||
Nicks::set_name(RuntimeOrigin::signed(2), b"Dr. David Brubeck, III".to_vec()),
|
||||
Error::<Test>::TooLong,
|
||||
);
|
||||
|
||||
assert_ok!(Nicks::set_name(Origin::signed(2), b"Dave".to_vec()));
|
||||
assert_ok!(Nicks::set_name(RuntimeOrigin::signed(2), b"Dave".to_vec()));
|
||||
assert_eq!(Balances::reserved_balance(2), 2);
|
||||
assert_noop!(
|
||||
Nicks::force_name(Origin::signed(1), 2, b"Dr. David Brubeck, III".to_vec()),
|
||||
Nicks::force_name(RuntimeOrigin::signed(1), 2, b"Dr. David Brubeck, III".to_vec()),
|
||||
Error::<Test>::TooLong,
|
||||
);
|
||||
assert_ok!(Nicks::force_name(Origin::signed(1), 2, b"Dr. Brubeck, III".to_vec()));
|
||||
assert_ok!(Nicks::force_name(
|
||||
RuntimeOrigin::signed(1),
|
||||
2,
|
||||
b"Dr. Brubeck, III".to_vec()
|
||||
));
|
||||
assert_eq!(Balances::reserved_balance(2), 2);
|
||||
let (name, amount) = <NameOf<Test>>::get(2).unwrap();
|
||||
assert_eq!(name, b"Dr. Brubeck, III".to_vec());
|
||||
@@ -371,17 +375,17 @@ mod tests {
|
||||
#[test]
|
||||
fn normal_operation_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Nicks::set_name(Origin::signed(1), b"Gav".to_vec()));
|
||||
assert_ok!(Nicks::set_name(RuntimeOrigin::signed(1), b"Gav".to_vec()));
|
||||
assert_eq!(Balances::reserved_balance(1), 2);
|
||||
assert_eq!(Balances::free_balance(1), 8);
|
||||
assert_eq!(<NameOf<Test>>::get(1).unwrap().0, b"Gav".to_vec());
|
||||
|
||||
assert_ok!(Nicks::set_name(Origin::signed(1), b"Gavin".to_vec()));
|
||||
assert_ok!(Nicks::set_name(RuntimeOrigin::signed(1), b"Gavin".to_vec()));
|
||||
assert_eq!(Balances::reserved_balance(1), 2);
|
||||
assert_eq!(Balances::free_balance(1), 8);
|
||||
assert_eq!(<NameOf<Test>>::get(1).unwrap().0, b"Gavin".to_vec());
|
||||
|
||||
assert_ok!(Nicks::clear_name(Origin::signed(1)));
|
||||
assert_ok!(Nicks::clear_name(RuntimeOrigin::signed(1)));
|
||||
assert_eq!(Balances::reserved_balance(1), 0);
|
||||
assert_eq!(Balances::free_balance(1), 10);
|
||||
});
|
||||
@@ -390,24 +394,27 @@ mod tests {
|
||||
#[test]
|
||||
fn error_catching_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(Nicks::clear_name(Origin::signed(1)), Error::<Test>::Unnamed);
|
||||
assert_noop!(Nicks::clear_name(RuntimeOrigin::signed(1)), Error::<Test>::Unnamed);
|
||||
|
||||
assert_noop!(
|
||||
Nicks::set_name(Origin::signed(3), b"Dave".to_vec()),
|
||||
Nicks::set_name(RuntimeOrigin::signed(3), b"Dave".to_vec()),
|
||||
pallet_balances::Error::<Test, _>::InsufficientBalance
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
Nicks::set_name(Origin::signed(1), b"Ga".to_vec()),
|
||||
Nicks::set_name(RuntimeOrigin::signed(1), b"Ga".to_vec()),
|
||||
Error::<Test>::TooShort
|
||||
);
|
||||
assert_noop!(
|
||||
Nicks::set_name(Origin::signed(1), b"Gavin James Wood, Esquire".to_vec()),
|
||||
Nicks::set_name(RuntimeOrigin::signed(1), b"Gavin James Wood, Esquire".to_vec()),
|
||||
Error::<Test>::TooLong
|
||||
);
|
||||
assert_ok!(Nicks::set_name(Origin::signed(1), b"Dave".to_vec()));
|
||||
assert_noop!(Nicks::kill_name(Origin::signed(2), 1), BadOrigin);
|
||||
assert_noop!(Nicks::force_name(Origin::signed(2), 1, b"Whatever".to_vec()), BadOrigin);
|
||||
assert_ok!(Nicks::set_name(RuntimeOrigin::signed(1), b"Dave".to_vec()));
|
||||
assert_noop!(Nicks::kill_name(RuntimeOrigin::signed(2), 1), BadOrigin);
|
||||
assert_noop!(
|
||||
Nicks::force_name(RuntimeOrigin::signed(2), 1, b"Whatever".to_vec()),
|
||||
BadOrigin
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,16 +78,16 @@ pub mod pallet {
|
||||
type MaxPeerIdLength: Get<u32>;
|
||||
|
||||
/// The origin which can add a well known node.
|
||||
type AddOrigin: EnsureOrigin<Self::Origin>;
|
||||
type AddOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// The origin which can remove a well known node.
|
||||
type RemoveOrigin: EnsureOrigin<Self::Origin>;
|
||||
type RemoveOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// The origin which can swap the well known nodes.
|
||||
type SwapOrigin: EnsureOrigin<Self::Origin>;
|
||||
type SwapOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// The origin which can reset the well known nodes.
|
||||
type ResetOrigin: EnsureOrigin<Self::Origin>;
|
||||
type ResetOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// Weight information for extrinsics in this pallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
|
||||
@@ -52,7 +52,7 @@ impl frame_system::Config for Test {
|
||||
type DbWeight = ();
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
|
||||
@@ -26,19 +26,27 @@ use sp_runtime::traits::BadOrigin;
|
||||
fn add_well_known_node_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
NodeAuthorization::add_well_known_node(Origin::signed(2), test_node(15), 15),
|
||||
NodeAuthorization::add_well_known_node(RuntimeOrigin::signed(2), test_node(15), 15),
|
||||
BadOrigin
|
||||
);
|
||||
assert_noop!(
|
||||
NodeAuthorization::add_well_known_node(Origin::signed(1), PeerId(vec![1, 2, 3]), 15),
|
||||
NodeAuthorization::add_well_known_node(
|
||||
RuntimeOrigin::signed(1),
|
||||
PeerId(vec![1, 2, 3]),
|
||||
15
|
||||
),
|
||||
Error::<Test>::PeerIdTooLong
|
||||
);
|
||||
assert_noop!(
|
||||
NodeAuthorization::add_well_known_node(Origin::signed(1), test_node(20), 20),
|
||||
NodeAuthorization::add_well_known_node(RuntimeOrigin::signed(1), test_node(20), 20),
|
||||
Error::<Test>::AlreadyJoined
|
||||
);
|
||||
|
||||
assert_ok!(NodeAuthorization::add_well_known_node(Origin::signed(1), test_node(15), 15));
|
||||
assert_ok!(NodeAuthorization::add_well_known_node(
|
||||
RuntimeOrigin::signed(1),
|
||||
test_node(15),
|
||||
15
|
||||
));
|
||||
assert_eq!(
|
||||
WellKnownNodes::<Test>::get(),
|
||||
BTreeSet::from_iter(vec![test_node(10), test_node(15), test_node(20), test_node(30)])
|
||||
@@ -49,7 +57,7 @@ fn add_well_known_node_works() {
|
||||
assert_eq!(Owners::<Test>::get(test_node(15)), Some(15));
|
||||
|
||||
assert_noop!(
|
||||
NodeAuthorization::add_well_known_node(Origin::signed(1), test_node(25), 25),
|
||||
NodeAuthorization::add_well_known_node(RuntimeOrigin::signed(1), test_node(25), 25),
|
||||
Error::<Test>::TooManyNodes
|
||||
);
|
||||
});
|
||||
@@ -59,15 +67,18 @@ fn add_well_known_node_works() {
|
||||
fn remove_well_known_node_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
NodeAuthorization::remove_well_known_node(Origin::signed(3), test_node(20)),
|
||||
NodeAuthorization::remove_well_known_node(RuntimeOrigin::signed(3), test_node(20)),
|
||||
BadOrigin
|
||||
);
|
||||
assert_noop!(
|
||||
NodeAuthorization::remove_well_known_node(Origin::signed(2), PeerId(vec![1, 2, 3])),
|
||||
NodeAuthorization::remove_well_known_node(
|
||||
RuntimeOrigin::signed(2),
|
||||
PeerId(vec![1, 2, 3])
|
||||
),
|
||||
Error::<Test>::PeerIdTooLong
|
||||
);
|
||||
assert_noop!(
|
||||
NodeAuthorization::remove_well_known_node(Origin::signed(2), test_node(40)),
|
||||
NodeAuthorization::remove_well_known_node(RuntimeOrigin::signed(2), test_node(40)),
|
||||
Error::<Test>::NotExist
|
||||
);
|
||||
|
||||
@@ -77,7 +88,10 @@ fn remove_well_known_node_works() {
|
||||
);
|
||||
assert!(AdditionalConnections::<Test>::contains_key(test_node(20)));
|
||||
|
||||
assert_ok!(NodeAuthorization::remove_well_known_node(Origin::signed(2), test_node(20)));
|
||||
assert_ok!(NodeAuthorization::remove_well_known_node(
|
||||
RuntimeOrigin::signed(2),
|
||||
test_node(20)
|
||||
));
|
||||
assert_eq!(
|
||||
WellKnownNodes::<Test>::get(),
|
||||
BTreeSet::from_iter(vec![test_node(10), test_node(30)])
|
||||
@@ -91,12 +105,16 @@ fn remove_well_known_node_works() {
|
||||
fn swap_well_known_node_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
NodeAuthorization::swap_well_known_node(Origin::signed(4), test_node(20), test_node(5)),
|
||||
NodeAuthorization::swap_well_known_node(
|
||||
RuntimeOrigin::signed(4),
|
||||
test_node(20),
|
||||
test_node(5)
|
||||
),
|
||||
BadOrigin
|
||||
);
|
||||
assert_noop!(
|
||||
NodeAuthorization::swap_well_known_node(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
PeerId(vec![1, 2, 3]),
|
||||
test_node(20)
|
||||
),
|
||||
@@ -104,7 +122,7 @@ fn swap_well_known_node_works() {
|
||||
);
|
||||
assert_noop!(
|
||||
NodeAuthorization::swap_well_known_node(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
test_node(20),
|
||||
PeerId(vec![1, 2, 3])
|
||||
),
|
||||
@@ -112,7 +130,7 @@ fn swap_well_known_node_works() {
|
||||
);
|
||||
|
||||
assert_ok!(NodeAuthorization::swap_well_known_node(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
test_node(20),
|
||||
test_node(20)
|
||||
));
|
||||
@@ -122,12 +140,16 @@ fn swap_well_known_node_works() {
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
NodeAuthorization::swap_well_known_node(Origin::signed(3), test_node(15), test_node(5)),
|
||||
NodeAuthorization::swap_well_known_node(
|
||||
RuntimeOrigin::signed(3),
|
||||
test_node(15),
|
||||
test_node(5)
|
||||
),
|
||||
Error::<Test>::NotExist
|
||||
);
|
||||
assert_noop!(
|
||||
NodeAuthorization::swap_well_known_node(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
test_node(20),
|
||||
test_node(30)
|
||||
),
|
||||
@@ -139,7 +161,7 @@ fn swap_well_known_node_works() {
|
||||
BTreeSet::from_iter(vec![test_node(15)]),
|
||||
);
|
||||
assert_ok!(NodeAuthorization::swap_well_known_node(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
test_node(20),
|
||||
test_node(5)
|
||||
));
|
||||
@@ -162,14 +184,14 @@ fn reset_well_known_nodes_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
NodeAuthorization::reset_well_known_nodes(
|
||||
Origin::signed(3),
|
||||
RuntimeOrigin::signed(3),
|
||||
vec![(test_node(15), 15), (test_node(5), 5), (test_node(20), 20)]
|
||||
),
|
||||
BadOrigin
|
||||
);
|
||||
assert_noop!(
|
||||
NodeAuthorization::reset_well_known_nodes(
|
||||
Origin::signed(4),
|
||||
RuntimeOrigin::signed(4),
|
||||
vec![
|
||||
(test_node(15), 15),
|
||||
(test_node(5), 5),
|
||||
@@ -181,7 +203,7 @@ fn reset_well_known_nodes_works() {
|
||||
);
|
||||
|
||||
assert_ok!(NodeAuthorization::reset_well_known_nodes(
|
||||
Origin::signed(4),
|
||||
RuntimeOrigin::signed(4),
|
||||
vec![(test_node(15), 15), (test_node(5), 5), (test_node(20), 20)]
|
||||
));
|
||||
assert_eq!(
|
||||
@@ -198,15 +220,15 @@ fn reset_well_known_nodes_works() {
|
||||
fn claim_node_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
NodeAuthorization::claim_node(Origin::signed(1), PeerId(vec![1, 2, 3])),
|
||||
NodeAuthorization::claim_node(RuntimeOrigin::signed(1), PeerId(vec![1, 2, 3])),
|
||||
Error::<Test>::PeerIdTooLong
|
||||
);
|
||||
assert_noop!(
|
||||
NodeAuthorization::claim_node(Origin::signed(1), test_node(20)),
|
||||
NodeAuthorization::claim_node(RuntimeOrigin::signed(1), test_node(20)),
|
||||
Error::<Test>::AlreadyClaimed
|
||||
);
|
||||
|
||||
assert_ok!(NodeAuthorization::claim_node(Origin::signed(15), test_node(15)));
|
||||
assert_ok!(NodeAuthorization::claim_node(RuntimeOrigin::signed(15), test_node(15)));
|
||||
assert_eq!(Owners::<Test>::get(test_node(15)), Some(15));
|
||||
});
|
||||
}
|
||||
@@ -215,21 +237,21 @@ fn claim_node_works() {
|
||||
fn remove_claim_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
NodeAuthorization::remove_claim(Origin::signed(15), PeerId(vec![1, 2, 3])),
|
||||
NodeAuthorization::remove_claim(RuntimeOrigin::signed(15), PeerId(vec![1, 2, 3])),
|
||||
Error::<Test>::PeerIdTooLong
|
||||
);
|
||||
assert_noop!(
|
||||
NodeAuthorization::remove_claim(Origin::signed(15), test_node(15)),
|
||||
NodeAuthorization::remove_claim(RuntimeOrigin::signed(15), test_node(15)),
|
||||
Error::<Test>::NotClaimed
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
NodeAuthorization::remove_claim(Origin::signed(15), test_node(20)),
|
||||
NodeAuthorization::remove_claim(RuntimeOrigin::signed(15), test_node(20)),
|
||||
Error::<Test>::NotOwner
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
NodeAuthorization::remove_claim(Origin::signed(20), test_node(20)),
|
||||
NodeAuthorization::remove_claim(RuntimeOrigin::signed(20), test_node(20)),
|
||||
Error::<Test>::PermissionDenied
|
||||
);
|
||||
|
||||
@@ -238,7 +260,7 @@ fn remove_claim_works() {
|
||||
test_node(15),
|
||||
BTreeSet::from_iter(vec![test_node(20)]),
|
||||
);
|
||||
assert_ok!(NodeAuthorization::remove_claim(Origin::signed(15), test_node(15)));
|
||||
assert_ok!(NodeAuthorization::remove_claim(RuntimeOrigin::signed(15), test_node(15)));
|
||||
assert!(!Owners::<Test>::contains_key(test_node(15)));
|
||||
assert!(!AdditionalConnections::<Test>::contains_key(test_node(15)));
|
||||
});
|
||||
@@ -248,20 +270,20 @@ fn remove_claim_works() {
|
||||
fn transfer_node_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
NodeAuthorization::transfer_node(Origin::signed(15), PeerId(vec![1, 2, 3]), 10),
|
||||
NodeAuthorization::transfer_node(RuntimeOrigin::signed(15), PeerId(vec![1, 2, 3]), 10),
|
||||
Error::<Test>::PeerIdTooLong
|
||||
);
|
||||
assert_noop!(
|
||||
NodeAuthorization::transfer_node(Origin::signed(15), test_node(15), 10),
|
||||
NodeAuthorization::transfer_node(RuntimeOrigin::signed(15), test_node(15), 10),
|
||||
Error::<Test>::NotClaimed
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
NodeAuthorization::transfer_node(Origin::signed(15), test_node(20), 10),
|
||||
NodeAuthorization::transfer_node(RuntimeOrigin::signed(15), test_node(20), 10),
|
||||
Error::<Test>::NotOwner
|
||||
);
|
||||
|
||||
assert_ok!(NodeAuthorization::transfer_node(Origin::signed(20), test_node(20), 15));
|
||||
assert_ok!(NodeAuthorization::transfer_node(RuntimeOrigin::signed(20), test_node(20), 15));
|
||||
assert_eq!(Owners::<Test>::get(test_node(20)), Some(15));
|
||||
});
|
||||
}
|
||||
@@ -271,7 +293,7 @@ fn add_connections_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
NodeAuthorization::add_connections(
|
||||
Origin::signed(15),
|
||||
RuntimeOrigin::signed(15),
|
||||
PeerId(vec![1, 2, 3]),
|
||||
vec![test_node(5)]
|
||||
),
|
||||
@@ -279,7 +301,7 @@ fn add_connections_works() {
|
||||
);
|
||||
assert_noop!(
|
||||
NodeAuthorization::add_connections(
|
||||
Origin::signed(15),
|
||||
RuntimeOrigin::signed(15),
|
||||
test_node(15),
|
||||
vec![test_node(5)]
|
||||
),
|
||||
@@ -288,7 +310,7 @@ fn add_connections_works() {
|
||||
|
||||
assert_noop!(
|
||||
NodeAuthorization::add_connections(
|
||||
Origin::signed(15),
|
||||
RuntimeOrigin::signed(15),
|
||||
test_node(20),
|
||||
vec![test_node(5)]
|
||||
),
|
||||
@@ -296,7 +318,7 @@ fn add_connections_works() {
|
||||
);
|
||||
|
||||
assert_ok!(NodeAuthorization::add_connections(
|
||||
Origin::signed(20),
|
||||
RuntimeOrigin::signed(20),
|
||||
test_node(20),
|
||||
vec![test_node(15), test_node(5), test_node(25), test_node(20)]
|
||||
));
|
||||
@@ -312,7 +334,7 @@ fn remove_connections_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
NodeAuthorization::remove_connections(
|
||||
Origin::signed(15),
|
||||
RuntimeOrigin::signed(15),
|
||||
PeerId(vec![1, 2, 3]),
|
||||
vec![test_node(5)]
|
||||
),
|
||||
@@ -320,7 +342,7 @@ fn remove_connections_works() {
|
||||
);
|
||||
assert_noop!(
|
||||
NodeAuthorization::remove_connections(
|
||||
Origin::signed(15),
|
||||
RuntimeOrigin::signed(15),
|
||||
test_node(15),
|
||||
vec![test_node(5)]
|
||||
),
|
||||
@@ -329,7 +351,7 @@ fn remove_connections_works() {
|
||||
|
||||
assert_noop!(
|
||||
NodeAuthorization::remove_connections(
|
||||
Origin::signed(15),
|
||||
RuntimeOrigin::signed(15),
|
||||
test_node(20),
|
||||
vec![test_node(5)]
|
||||
),
|
||||
@@ -341,7 +363,7 @@ fn remove_connections_works() {
|
||||
BTreeSet::from_iter(vec![test_node(5), test_node(15), test_node(25)]),
|
||||
);
|
||||
assert_ok!(NodeAuthorization::remove_connections(
|
||||
Origin::signed(20),
|
||||
RuntimeOrigin::signed(20),
|
||||
test_node(20),
|
||||
vec![test_node(15), test_node(5)]
|
||||
));
|
||||
|
||||
@@ -26,7 +26,7 @@ mod mock;
|
||||
use frame_benchmarking::{account, frame_support::traits::Currency, vec, whitelist_account, Vec};
|
||||
use frame_election_provider_support::SortedListProvider;
|
||||
use frame_support::{assert_ok, ensure, traits::Get};
|
||||
use frame_system::RawOrigin as Origin;
|
||||
use frame_system::RawOrigin as RuntimeOrigin;
|
||||
use pallet_nomination_pools::{
|
||||
BalanceOf, BondExtra, BondedPoolInner, BondedPools, ConfigOp, MaxPoolMembers,
|
||||
MaxPoolMembersPerPool, MaxPools, Metadata, MinCreateBond, MinJoinBond, Pallet as Pools,
|
||||
@@ -80,7 +80,7 @@ fn create_pool_account<T: pallet_nomination_pools::Config>(
|
||||
let pool_creator_lookup = T::Lookup::unlookup(pool_creator.clone());
|
||||
|
||||
Pools::<T>::create(
|
||||
Origin::Signed(pool_creator.clone()).into(),
|
||||
RuntimeOrigin::Signed(pool_creator.clone()).into(),
|
||||
balance,
|
||||
pool_creator_lookup.clone(),
|
||||
pool_creator_lookup.clone(),
|
||||
@@ -203,7 +203,7 @@ impl<T: Config> ListScenario<T> {
|
||||
maybe_pool.as_mut().map(|pool| pool.points -= amount)
|
||||
});
|
||||
|
||||
Pools::<T>::join(Origin::Signed(joiner.clone()).into(), amount, 1).unwrap();
|
||||
Pools::<T>::join(RuntimeOrigin::Signed(joiner.clone()).into(), amount, 1).unwrap();
|
||||
|
||||
// check that the vote weight is still the same as the original bonded
|
||||
let weight_of = pallet_staking::Pallet::<T>::weight_of_fn();
|
||||
@@ -236,7 +236,7 @@ frame_benchmarking::benchmarks! {
|
||||
= create_funded_user_with_balance::<T>("joiner", 0, joiner_free);
|
||||
|
||||
whitelist_account!(joiner);
|
||||
}: _(Origin::Signed(joiner.clone()), max_additional, 1)
|
||||
}: _(RuntimeOrigin::Signed(joiner.clone()), max_additional, 1)
|
||||
verify {
|
||||
assert_eq!(CurrencyOf::<T>::free_balance(&joiner), joiner_free - max_additional);
|
||||
assert_eq!(
|
||||
@@ -252,7 +252,7 @@ frame_benchmarking::benchmarks! {
|
||||
|
||||
// creator of the src pool will bond-extra, bumping itself to dest bag.
|
||||
|
||||
}: bond_extra(Origin::Signed(scenario.creator1.clone()), BondExtra::FreeBalance(extra))
|
||||
}: bond_extra(RuntimeOrigin::Signed(scenario.creator1.clone()), BondExtra::FreeBalance(extra))
|
||||
verify {
|
||||
assert!(
|
||||
T::StakingInterface::active_stake(&scenario.origin1).unwrap() >=
|
||||
@@ -270,7 +270,7 @@ frame_benchmarking::benchmarks! {
|
||||
assert!(extra >= CurrencyOf::<T>::minimum_balance());
|
||||
CurrencyOf::<T>::deposit_creating(&reward_account1, extra);
|
||||
|
||||
}: bond_extra(Origin::Signed(scenario.creator1.clone()), BondExtra::Rewards)
|
||||
}: bond_extra(RuntimeOrigin::Signed(scenario.creator1.clone()), BondExtra::Rewards)
|
||||
verify {
|
||||
assert!(
|
||||
T::StakingInterface::active_stake(&scenario.origin1).unwrap() >=
|
||||
@@ -294,7 +294,7 @@ frame_benchmarking::benchmarks! {
|
||||
);
|
||||
|
||||
whitelist_account!(depositor);
|
||||
}:_(Origin::Signed(depositor.clone()))
|
||||
}:_(RuntimeOrigin::Signed(depositor.clone()))
|
||||
verify {
|
||||
assert_eq!(
|
||||
CurrencyOf::<T>::free_balance(&depositor),
|
||||
@@ -318,7 +318,7 @@ frame_benchmarking::benchmarks! {
|
||||
let member_id_lookup = T::Lookup::unlookup(member_id.clone());
|
||||
let all_points = PoolMembers::<T>::get(&member_id).unwrap().points;
|
||||
whitelist_account!(member_id);
|
||||
}: _(Origin::Signed(member_id.clone()), member_id_lookup, all_points)
|
||||
}: _(RuntimeOrigin::Signed(member_id.clone()), member_id_lookup, all_points)
|
||||
verify {
|
||||
let bonded_after = T::StakingInterface::active_stake(&scenario.origin1).unwrap();
|
||||
// We at least went down to the destination bag
|
||||
@@ -346,7 +346,7 @@ frame_benchmarking::benchmarks! {
|
||||
// Add a new member
|
||||
let min_join_bond = MinJoinBond::<T>::get().max(CurrencyOf::<T>::minimum_balance());
|
||||
let joiner = create_funded_user_with_balance::<T>("joiner", 0, min_join_bond * 2u32.into());
|
||||
Pools::<T>::join(Origin::Signed(joiner.clone()).into(), min_join_bond, 1)
|
||||
Pools::<T>::join(RuntimeOrigin::Signed(joiner.clone()).into(), min_join_bond, 1)
|
||||
.unwrap();
|
||||
|
||||
// Sanity check join worked
|
||||
@@ -357,7 +357,7 @@ frame_benchmarking::benchmarks! {
|
||||
assert_eq!(CurrencyOf::<T>::free_balance(&joiner), min_join_bond);
|
||||
|
||||
// Unbond the new member
|
||||
Pools::<T>::fully_unbond(Origin::Signed(joiner.clone()).into(), joiner.clone()).unwrap();
|
||||
Pools::<T>::fully_unbond(RuntimeOrigin::Signed(joiner.clone()).into(), joiner.clone()).unwrap();
|
||||
|
||||
// Sanity check that unbond worked
|
||||
assert_eq!(
|
||||
@@ -371,7 +371,7 @@ frame_benchmarking::benchmarks! {
|
||||
// Add `s` count of slashing spans to storage.
|
||||
pallet_staking::benchmarking::add_slashing_spans::<T>(&pool_account, s);
|
||||
whitelist_account!(pool_account);
|
||||
}: _(Origin::Signed(pool_account.clone()), 1, s)
|
||||
}: _(RuntimeOrigin::Signed(pool_account.clone()), 1, s)
|
||||
verify {
|
||||
// The joiners funds didn't change
|
||||
assert_eq!(CurrencyOf::<T>::free_balance(&joiner), min_join_bond);
|
||||
@@ -389,7 +389,7 @@ frame_benchmarking::benchmarks! {
|
||||
let min_join_bond = MinJoinBond::<T>::get().max(CurrencyOf::<T>::minimum_balance());
|
||||
let joiner = create_funded_user_with_balance::<T>("joiner", 0, min_join_bond * 2u32.into());
|
||||
let joiner_lookup = T::Lookup::unlookup(joiner.clone());
|
||||
Pools::<T>::join(Origin::Signed(joiner.clone()).into(), min_join_bond, 1)
|
||||
Pools::<T>::join(RuntimeOrigin::Signed(joiner.clone()).into(), min_join_bond, 1)
|
||||
.unwrap();
|
||||
|
||||
// Sanity check join worked
|
||||
@@ -401,7 +401,7 @@ frame_benchmarking::benchmarks! {
|
||||
|
||||
// Unbond the new member
|
||||
pallet_staking::CurrentEra::<T>::put(0);
|
||||
Pools::<T>::fully_unbond(Origin::Signed(joiner.clone()).into(), joiner.clone()).unwrap();
|
||||
Pools::<T>::fully_unbond(RuntimeOrigin::Signed(joiner.clone()).into(), joiner.clone()).unwrap();
|
||||
|
||||
// Sanity check that unbond worked
|
||||
assert_eq!(
|
||||
@@ -415,7 +415,7 @@ frame_benchmarking::benchmarks! {
|
||||
|
||||
pallet_staking::benchmarking::add_slashing_spans::<T>(&pool_account, s);
|
||||
whitelist_account!(joiner);
|
||||
}: withdraw_unbonded(Origin::Signed(joiner.clone()), joiner_lookup, s)
|
||||
}: withdraw_unbonded(RuntimeOrigin::Signed(joiner.clone()), joiner_lookup, s)
|
||||
verify {
|
||||
assert_eq!(
|
||||
CurrencyOf::<T>::free_balance(&joiner),
|
||||
@@ -448,7 +448,7 @@ frame_benchmarking::benchmarks! {
|
||||
// up when unbonding.
|
||||
let reward_account = Pools::<T>::create_reward_account(1);
|
||||
assert!(frame_system::Account::<T>::contains_key(&reward_account));
|
||||
Pools::<T>::fully_unbond(Origin::Signed(depositor.clone()).into(), depositor.clone()).unwrap();
|
||||
Pools::<T>::fully_unbond(RuntimeOrigin::Signed(depositor.clone()).into(), depositor.clone()).unwrap();
|
||||
|
||||
// Sanity check that unbond worked
|
||||
assert_eq!(
|
||||
@@ -473,7 +473,7 @@ frame_benchmarking::benchmarks! {
|
||||
assert!(frame_system::Account::<T>::contains_key(&reward_account));
|
||||
|
||||
whitelist_account!(depositor);
|
||||
}: withdraw_unbonded(Origin::Signed(depositor.clone()), depositor_lookup, s)
|
||||
}: withdraw_unbonded(RuntimeOrigin::Signed(depositor.clone()), depositor_lookup, s)
|
||||
verify {
|
||||
// Pool removal worked
|
||||
assert!(!pallet_staking::Ledger::<T>::contains_key(&pool_account));
|
||||
@@ -506,7 +506,7 @@ frame_benchmarking::benchmarks! {
|
||||
|
||||
whitelist_account!(depositor);
|
||||
}: _(
|
||||
Origin::Signed(depositor.clone()),
|
||||
RuntimeOrigin::Signed(depositor.clone()),
|
||||
min_create_bond,
|
||||
depositor_lookup.clone(),
|
||||
depositor_lookup.clone(),
|
||||
@@ -550,7 +550,7 @@ frame_benchmarking::benchmarks! {
|
||||
.collect();
|
||||
|
||||
whitelist_account!(depositor);
|
||||
}:_(Origin::Signed(depositor.clone()), 1, validators)
|
||||
}:_(RuntimeOrigin::Signed(depositor.clone()), 1, validators)
|
||||
verify {
|
||||
assert_eq!(RewardPools::<T>::count(), 1);
|
||||
assert_eq!(BondedPools::<T>::count(), 1);
|
||||
@@ -586,7 +586,7 @@ frame_benchmarking::benchmarks! {
|
||||
|
||||
let caller = account("caller", 0, USER_SEED);
|
||||
whitelist_account!(caller);
|
||||
}:_(Origin::Signed(caller), 1, PoolState::Destroying)
|
||||
}:_(RuntimeOrigin::Signed(caller), 1, PoolState::Destroying)
|
||||
verify {
|
||||
assert_eq!(BondedPools::<T>::get(1).unwrap().state, PoolState::Destroying);
|
||||
}
|
||||
@@ -601,14 +601,14 @@ frame_benchmarking::benchmarks! {
|
||||
let metadata: Vec<u8> = (0..n).map(|_| 42).collect();
|
||||
|
||||
whitelist_account!(depositor);
|
||||
}:_(Origin::Signed(depositor), 1, metadata.clone())
|
||||
}:_(RuntimeOrigin::Signed(depositor), 1, metadata.clone())
|
||||
verify {
|
||||
assert_eq!(Metadata::<T>::get(&1), metadata);
|
||||
}
|
||||
|
||||
set_configs {
|
||||
}:_(
|
||||
Origin::Root,
|
||||
RuntimeOrigin::Root,
|
||||
ConfigOp::Set(BalanceOf::<T>::max_value()),
|
||||
ConfigOp::Set(BalanceOf::<T>::max_value()),
|
||||
ConfigOp::Set(u32::MAX),
|
||||
@@ -627,7 +627,7 @@ frame_benchmarking::benchmarks! {
|
||||
let (root, _) = create_pool_account::<T>(0, min_create_bond::<T>() * 2u32.into());
|
||||
let random: T::AccountId = account("but is anything really random in computers..?", 0, USER_SEED);
|
||||
}:_(
|
||||
Origin::Signed(root.clone()),
|
||||
RuntimeOrigin::Signed(root.clone()),
|
||||
first_id,
|
||||
ConfigOp::Set(random.clone()),
|
||||
ConfigOp::Set(random.clone()),
|
||||
@@ -653,11 +653,11 @@ frame_benchmarking::benchmarks! {
|
||||
.map(|i| account("stash", USER_SEED, i))
|
||||
.collect();
|
||||
|
||||
assert_ok!(Pools::<T>::nominate(Origin::Signed(depositor.clone()).into(), 1, validators));
|
||||
assert_ok!(Pools::<T>::nominate(RuntimeOrigin::Signed(depositor.clone()).into(), 1, validators));
|
||||
assert!(T::StakingInterface::nominations(Pools::<T>::create_bonded_account(1)).is_some());
|
||||
|
||||
whitelist_account!(depositor);
|
||||
}:_(Origin::Signed(depositor.clone()), 1)
|
||||
}:_(RuntimeOrigin::Signed(depositor.clone()), 1)
|
||||
verify {
|
||||
assert!(T::StakingInterface::nominations(Pools::<T>::create_bonded_account(1)).is_none());
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ impl frame_system::Config for Runtime {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = AccountIndex;
|
||||
type BlockNumber = BlockNumber;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
|
||||
@@ -119,7 +119,7 @@ pub mod v2 {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let join = |x| {
|
||||
Balances::make_free_balance_be(&x, Balances::minimum_balance() + 10);
|
||||
frame_support::assert_ok!(Pools::join(Origin::signed(x), 10, 1));
|
||||
frame_support::assert_ok!(Pools::join(RuntimeOrigin::signed(x), 10, 1));
|
||||
};
|
||||
|
||||
assert_eq!(BondedPool::<Runtime>::get(1).unwrap().points, 10);
|
||||
|
||||
@@ -128,7 +128,7 @@ impl sp_staking::StakingInterface for StakingMock {
|
||||
impl frame_system::Config for Runtime {
|
||||
type SS58Prefix = ();
|
||||
type BaseCallFilter = frame_support::traits::Everything;
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = BlockNumber;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
@@ -291,7 +291,7 @@ impl ExtBuilder {
|
||||
let amount_to_bond = Pools::depositor_min_bond();
|
||||
Balances::make_free_balance_be(&10, amount_to_bond * 5);
|
||||
assert_ok!(Pools::create(RawOrigin::Signed(10).into(), amount_to_bond, 900, 901, 902));
|
||||
assert_ok!(Pools::set_metadata(Origin::signed(900), 1, vec![1, 1]));
|
||||
assert_ok!(Pools::set_metadata(RuntimeOrigin::signed(900), 1, vec![1, 1]));
|
||||
let last_pool = LastPoolId::<Runtime>::get();
|
||||
for (account_id, bonded) in self.members {
|
||||
Balances::make_free_balance_be(&account_id, bonded * 2);
|
||||
@@ -353,7 +353,7 @@ pub fn fully_unbond_permissioned(member: AccountId) -> DispatchResult {
|
||||
let points = PoolMembers::<Runtime>::get(&member)
|
||||
.map(|d| d.active_points())
|
||||
.unwrap_or_default();
|
||||
Pools::unbond(Origin::signed(member), member, points)
|
||||
Pools::unbond(RuntimeOrigin::signed(member), member, points)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -35,11 +35,11 @@ fn pool_lifecycle_e2e() {
|
||||
assert_eq!(Staking::current_era(), None);
|
||||
|
||||
// create the pool, we know this has id 1.
|
||||
assert_ok!(Pools::create(Origin::signed(10), 50, 10, 10, 10));
|
||||
assert_ok!(Pools::create(RuntimeOrigin::signed(10), 50, 10, 10, 10));
|
||||
assert_eq!(LastPoolId::<Runtime>::get(), 1);
|
||||
|
||||
// have the pool nominate.
|
||||
assert_ok!(Pools::nominate(Origin::signed(10), 1, vec![1, 2, 3]));
|
||||
assert_ok!(Pools::nominate(RuntimeOrigin::signed(10), 1, vec![1, 2, 3]));
|
||||
|
||||
assert_eq!(staking_events_since_last_call(), vec![StakingEvent::Bonded(POOL1_BONDED, 50),]);
|
||||
assert_eq!(
|
||||
@@ -51,8 +51,8 @@ fn pool_lifecycle_e2e() {
|
||||
);
|
||||
|
||||
// have two members join
|
||||
assert_ok!(Pools::join(Origin::signed(20), 10, 1));
|
||||
assert_ok!(Pools::join(Origin::signed(21), 10, 1));
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(20), 10, 1));
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(21), 10, 1));
|
||||
|
||||
assert_eq!(
|
||||
staking_events_since_last_call(),
|
||||
@@ -67,17 +67,17 @@ fn pool_lifecycle_e2e() {
|
||||
);
|
||||
|
||||
// pool goes into destroying
|
||||
assert_ok!(Pools::set_state(Origin::signed(10), 1, PoolState::Destroying));
|
||||
assert_ok!(Pools::set_state(RuntimeOrigin::signed(10), 1, PoolState::Destroying));
|
||||
|
||||
// depositor cannot unbond yet.
|
||||
assert_noop!(
|
||||
Pools::unbond(Origin::signed(10), 10, 50),
|
||||
Pools::unbond(RuntimeOrigin::signed(10), 10, 50),
|
||||
PoolsError::<Runtime>::MinimumBondNotMet,
|
||||
);
|
||||
|
||||
// now the members want to unbond.
|
||||
assert_ok!(Pools::unbond(Origin::signed(20), 20, 10));
|
||||
assert_ok!(Pools::unbond(Origin::signed(21), 21, 10));
|
||||
assert_ok!(Pools::unbond(RuntimeOrigin::signed(20), 20, 10));
|
||||
assert_ok!(Pools::unbond(RuntimeOrigin::signed(21), 21, 10));
|
||||
|
||||
assert_eq!(PoolMembers::<Runtime>::get(20).unwrap().unbonding_eras.len(), 1);
|
||||
assert_eq!(PoolMembers::<Runtime>::get(20).unwrap().points, 0);
|
||||
@@ -102,14 +102,14 @@ fn pool_lifecycle_e2e() {
|
||||
|
||||
// depositor cannot still unbond
|
||||
assert_noop!(
|
||||
Pools::unbond(Origin::signed(10), 10, 50),
|
||||
Pools::unbond(RuntimeOrigin::signed(10), 10, 50),
|
||||
PoolsError::<Runtime>::MinimumBondNotMet,
|
||||
);
|
||||
|
||||
for e in 1..BondingDuration::get() {
|
||||
CurrentEra::<Runtime>::set(Some(e));
|
||||
assert_noop!(
|
||||
Pools::withdraw_unbonded(Origin::signed(20), 20, 0),
|
||||
Pools::withdraw_unbonded(RuntimeOrigin::signed(20), 20, 0),
|
||||
PoolsError::<Runtime>::CannotWithdrawAny
|
||||
);
|
||||
}
|
||||
@@ -119,13 +119,13 @@ fn pool_lifecycle_e2e() {
|
||||
|
||||
// depositor cannot still unbond
|
||||
assert_noop!(
|
||||
Pools::unbond(Origin::signed(10), 10, 50),
|
||||
Pools::unbond(RuntimeOrigin::signed(10), 10, 50),
|
||||
PoolsError::<Runtime>::MinimumBondNotMet,
|
||||
);
|
||||
|
||||
// but members can now withdraw.
|
||||
assert_ok!(Pools::withdraw_unbonded(Origin::signed(20), 20, 0));
|
||||
assert_ok!(Pools::withdraw_unbonded(Origin::signed(21), 21, 0));
|
||||
assert_ok!(Pools::withdraw_unbonded(RuntimeOrigin::signed(20), 20, 0));
|
||||
assert_ok!(Pools::withdraw_unbonded(RuntimeOrigin::signed(21), 21, 0));
|
||||
assert!(PoolMembers::<Runtime>::get(20).is_none());
|
||||
assert!(PoolMembers::<Runtime>::get(21).is_none());
|
||||
|
||||
@@ -146,12 +146,12 @@ fn pool_lifecycle_e2e() {
|
||||
// as soon as all members have left, the depositor can try to unbond, but since the
|
||||
// min-nominator intention is set, they must chill first.
|
||||
assert_noop!(
|
||||
Pools::unbond(Origin::signed(10), 10, 50),
|
||||
Pools::unbond(RuntimeOrigin::signed(10), 10, 50),
|
||||
pallet_staking::Error::<Runtime>::InsufficientBond
|
||||
);
|
||||
|
||||
assert_ok!(Pools::chill(Origin::signed(10), 1));
|
||||
assert_ok!(Pools::unbond(Origin::signed(10), 10, 50));
|
||||
assert_ok!(Pools::chill(RuntimeOrigin::signed(10), 1));
|
||||
assert_ok!(Pools::unbond(RuntimeOrigin::signed(10), 10, 50));
|
||||
|
||||
assert_eq!(
|
||||
staking_events_since_last_call(),
|
||||
@@ -164,7 +164,7 @@ fn pool_lifecycle_e2e() {
|
||||
|
||||
// waiting another bonding duration:
|
||||
CurrentEra::<Runtime>::set(Some(BondingDuration::get() * 2));
|
||||
assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 1));
|
||||
assert_ok!(Pools::withdraw_unbonded(RuntimeOrigin::signed(10), 10, 1));
|
||||
|
||||
// pools is fully destroyed now.
|
||||
assert_eq!(
|
||||
@@ -190,7 +190,7 @@ fn pool_slash_e2e() {
|
||||
assert_eq!(Staking::current_era(), None);
|
||||
|
||||
// create the pool, we know this has id 1.
|
||||
assert_ok!(Pools::create(Origin::signed(10), 40, 10, 10, 10));
|
||||
assert_ok!(Pools::create(RuntimeOrigin::signed(10), 40, 10, 10, 10));
|
||||
assert_eq!(LastPoolId::<Runtime>::get(), 1);
|
||||
|
||||
assert_eq!(staking_events_since_last_call(), vec![StakingEvent::Bonded(POOL1_BONDED, 40)]);
|
||||
@@ -205,8 +205,8 @@ fn pool_slash_e2e() {
|
||||
assert_eq!(Payee::<Runtime>::get(POOL1_BONDED), RewardDestination::Account(POOL1_REWARD));
|
||||
|
||||
// have two members join
|
||||
assert_ok!(Pools::join(Origin::signed(20), 20, 1));
|
||||
assert_ok!(Pools::join(Origin::signed(21), 20, 1));
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(20), 20, 1));
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(21), 20, 1));
|
||||
|
||||
assert_eq!(
|
||||
staking_events_since_last_call(),
|
||||
@@ -224,8 +224,8 @@ fn pool_slash_e2e() {
|
||||
CurrentEra::<Runtime>::set(Some(1));
|
||||
|
||||
// 20 / 80 of the total funds are unlocked, and safe from any further slash.
|
||||
assert_ok!(Pools::unbond(Origin::signed(10), 10, 10));
|
||||
assert_ok!(Pools::unbond(Origin::signed(20), 20, 10));
|
||||
assert_ok!(Pools::unbond(RuntimeOrigin::signed(10), 10, 10));
|
||||
assert_ok!(Pools::unbond(RuntimeOrigin::signed(20), 20, 10));
|
||||
|
||||
assert_eq!(
|
||||
staking_events_since_last_call(),
|
||||
@@ -246,9 +246,9 @@ fn pool_slash_e2e() {
|
||||
|
||||
// note: depositor cannot fully unbond at this point.
|
||||
// these funds will still get slashed.
|
||||
assert_ok!(Pools::unbond(Origin::signed(10), 10, 10));
|
||||
assert_ok!(Pools::unbond(Origin::signed(20), 20, 10));
|
||||
assert_ok!(Pools::unbond(Origin::signed(21), 21, 10));
|
||||
assert_ok!(Pools::unbond(RuntimeOrigin::signed(10), 10, 10));
|
||||
assert_ok!(Pools::unbond(RuntimeOrigin::signed(20), 20, 10));
|
||||
assert_ok!(Pools::unbond(RuntimeOrigin::signed(21), 21, 10));
|
||||
|
||||
assert_eq!(
|
||||
staking_events_since_last_call(),
|
||||
@@ -290,7 +290,7 @@ fn pool_slash_e2e() {
|
||||
);
|
||||
|
||||
CurrentEra::<Runtime>::set(Some(3));
|
||||
assert_ok!(Pools::unbond(Origin::signed(21), 21, 10));
|
||||
assert_ok!(Pools::unbond(RuntimeOrigin::signed(21), 21, 10));
|
||||
|
||||
assert_eq!(
|
||||
PoolMembers::<Runtime>::get(21).unwrap(),
|
||||
@@ -310,8 +310,8 @@ fn pool_slash_e2e() {
|
||||
|
||||
// now we start withdrawing. we do it all at once, at era 6 where 20 and 21 are fully free.
|
||||
CurrentEra::<Runtime>::set(Some(6));
|
||||
assert_ok!(Pools::withdraw_unbonded(Origin::signed(20), 20, 0));
|
||||
assert_ok!(Pools::withdraw_unbonded(Origin::signed(21), 21, 0));
|
||||
assert_ok!(Pools::withdraw_unbonded(RuntimeOrigin::signed(20), 20, 0));
|
||||
assert_ok!(Pools::withdraw_unbonded(RuntimeOrigin::signed(21), 21, 0));
|
||||
|
||||
assert_eq!(
|
||||
pool_events_since_last_call(),
|
||||
@@ -331,8 +331,8 @@ fn pool_slash_e2e() {
|
||||
);
|
||||
|
||||
// now, finally, we can unbond the depositor further than their current limit.
|
||||
assert_ok!(Pools::set_state(Origin::signed(10), 1, PoolState::Destroying));
|
||||
assert_ok!(Pools::unbond(Origin::signed(10), 10, 20));
|
||||
assert_ok!(Pools::set_state(RuntimeOrigin::signed(10), 1, PoolState::Destroying));
|
||||
assert_ok!(Pools::unbond(RuntimeOrigin::signed(10), 10, 20));
|
||||
|
||||
assert_eq!(
|
||||
staking_events_since_last_call(),
|
||||
@@ -357,7 +357,7 @@ fn pool_slash_e2e() {
|
||||
}
|
||||
);
|
||||
// withdraw the depositor, they should lose 12 balance in total due to slash.
|
||||
assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0));
|
||||
assert_ok!(Pools::withdraw_unbonded(RuntimeOrigin::signed(10), 10, 0));
|
||||
|
||||
assert_eq!(
|
||||
staking_events_since_last_call(),
|
||||
@@ -385,7 +385,7 @@ fn pool_slash_proportional() {
|
||||
assert_eq!(Staking::current_era(), None);
|
||||
|
||||
// create the pool, we know this has id 1.
|
||||
assert_ok!(Pools::create(Origin::signed(10), 40, 10, 10, 10));
|
||||
assert_ok!(Pools::create(RuntimeOrigin::signed(10), 40, 10, 10, 10));
|
||||
assert_eq!(LastPoolId::<T>::get(), 1);
|
||||
|
||||
assert_eq!(staking_events_since_last_call(), vec![StakingEvent::Bonded(POOL1_BONDED, 40)]);
|
||||
@@ -399,9 +399,9 @@ fn pool_slash_proportional() {
|
||||
|
||||
// have two members join
|
||||
let bond = 20;
|
||||
assert_ok!(Pools::join(Origin::signed(20), bond, 1));
|
||||
assert_ok!(Pools::join(Origin::signed(21), bond, 1));
|
||||
assert_ok!(Pools::join(Origin::signed(22), bond, 1));
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(20), bond, 1));
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(21), bond, 1));
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(22), bond, 1));
|
||||
|
||||
assert_eq!(
|
||||
staking_events_since_last_call(),
|
||||
@@ -424,7 +424,7 @@ fn pool_slash_proportional() {
|
||||
CurrentEra::<T>::set(Some(99));
|
||||
|
||||
// and unbond
|
||||
assert_ok!(Pools::unbond(Origin::signed(20), 20, bond));
|
||||
assert_ok!(Pools::unbond(RuntimeOrigin::signed(20), 20, bond));
|
||||
|
||||
assert_eq!(
|
||||
staking_events_since_last_call(),
|
||||
@@ -442,7 +442,7 @@ fn pool_slash_proportional() {
|
||||
);
|
||||
|
||||
CurrentEra::<T>::set(Some(100));
|
||||
assert_ok!(Pools::unbond(Origin::signed(21), 21, bond));
|
||||
assert_ok!(Pools::unbond(RuntimeOrigin::signed(21), 21, bond));
|
||||
assert_eq!(
|
||||
staking_events_since_last_call(),
|
||||
vec![StakingEvent::Unbonded(POOL1_BONDED, bond),]
|
||||
@@ -459,7 +459,7 @@ fn pool_slash_proportional() {
|
||||
);
|
||||
|
||||
CurrentEra::<T>::set(Some(101));
|
||||
assert_ok!(Pools::unbond(Origin::signed(22), 22, bond));
|
||||
assert_ok!(Pools::unbond(RuntimeOrigin::signed(22), 22, bond));
|
||||
assert_eq!(
|
||||
staking_events_since_last_call(),
|
||||
vec![StakingEvent::Unbonded(POOL1_BONDED, bond),]
|
||||
@@ -516,7 +516,7 @@ fn pool_slash_non_proportional_only_bonded_pool() {
|
||||
assert_eq!(Staking::current_era(), None);
|
||||
|
||||
// create the pool, we know this has id 1.
|
||||
assert_ok!(Pools::create(Origin::signed(10), 40, 10, 10, 10));
|
||||
assert_ok!(Pools::create(RuntimeOrigin::signed(10), 40, 10, 10, 10));
|
||||
assert_eq!(staking_events_since_last_call(), vec![StakingEvent::Bonded(POOL1_BONDED, 40)]);
|
||||
assert_eq!(
|
||||
pool_events_since_last_call(),
|
||||
@@ -528,7 +528,7 @@ fn pool_slash_non_proportional_only_bonded_pool() {
|
||||
|
||||
// have two members join
|
||||
let bond = 20;
|
||||
assert_ok!(Pools::join(Origin::signed(20), bond, 1));
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(20), bond, 1));
|
||||
assert_eq!(
|
||||
staking_events_since_last_call(),
|
||||
vec![StakingEvent::Bonded(POOL1_BONDED, bond)]
|
||||
@@ -540,7 +540,7 @@ fn pool_slash_non_proportional_only_bonded_pool() {
|
||||
|
||||
// progress and unbond.
|
||||
CurrentEra::<T>::set(Some(99));
|
||||
assert_ok!(Pools::unbond(Origin::signed(20), 20, bond));
|
||||
assert_ok!(Pools::unbond(RuntimeOrigin::signed(20), 20, bond));
|
||||
assert_eq!(
|
||||
staking_events_since_last_call(),
|
||||
vec![StakingEvent::Unbonded(POOL1_BONDED, bond)]
|
||||
@@ -589,7 +589,7 @@ fn pool_slash_non_proportional_bonded_pool_and_chunks() {
|
||||
assert_eq!(Staking::current_era(), None);
|
||||
|
||||
// create the pool, we know this has id 1.
|
||||
assert_ok!(Pools::create(Origin::signed(10), 40, 10, 10, 10));
|
||||
assert_ok!(Pools::create(RuntimeOrigin::signed(10), 40, 10, 10, 10));
|
||||
assert_eq!(staking_events_since_last_call(), vec![StakingEvent::Bonded(POOL1_BONDED, 40)]);
|
||||
assert_eq!(
|
||||
pool_events_since_last_call(),
|
||||
@@ -601,7 +601,7 @@ fn pool_slash_non_proportional_bonded_pool_and_chunks() {
|
||||
|
||||
// have two members join
|
||||
let bond = 20;
|
||||
assert_ok!(Pools::join(Origin::signed(20), bond, 1));
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(20), bond, 1));
|
||||
assert_eq!(
|
||||
staking_events_since_last_call(),
|
||||
vec![StakingEvent::Bonded(POOL1_BONDED, bond)]
|
||||
@@ -613,7 +613,7 @@ fn pool_slash_non_proportional_bonded_pool_and_chunks() {
|
||||
|
||||
// progress and unbond.
|
||||
CurrentEra::<T>::set(Some(99));
|
||||
assert_ok!(Pools::unbond(Origin::signed(20), 20, bond));
|
||||
assert_ok!(Pools::unbond(RuntimeOrigin::signed(20), 20, bond));
|
||||
assert_eq!(
|
||||
staking_events_since_last_call(),
|
||||
vec![StakingEvent::Unbonded(POOL1_BONDED, bond)]
|
||||
|
||||
@@ -43,7 +43,7 @@ impl frame_system::Config for Runtime {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = AccountIndex;
|
||||
type BlockNumber = BlockNumber;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
@@ -227,7 +227,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
|
||||
// set some limit for nominations.
|
||||
assert_ok!(Staking::set_staking_configs(
|
||||
Origin::root(),
|
||||
RuntimeOrigin::root(),
|
||||
pallet_staking::ConfigOp::Set(10), // minimum nominator bond
|
||||
pallet_staking::ConfigOp::Noop,
|
||||
pallet_staking::ConfigOp::Noop,
|
||||
|
||||
@@ -50,7 +50,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = AccountIndex;
|
||||
type BlockNumber = BlockNumber;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
|
||||
@@ -92,7 +92,7 @@ impl frame_system::Config for Runtime {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = RocksDbWeight;
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user