difftreelog
CORE-36 Enable/Disable Transfers + Unit tests fix
in: master
8 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5850,34 +5850,34 @@
[[package]]
name = "pallet-scheduler"
version = "3.0.0"
+source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.7#9c572625f6557dfdb19f47474369a0327d51dfbc"
dependencies = [
"frame-benchmarking",
"frame-support",
"frame-system",
"log",
"parity-scale-codec 2.1.3",
- "serde",
- "sp-core",
"sp-io",
"sp-runtime",
"sp-std",
- "substrate-test-utils",
- "up-sponsorship",
]
[[package]]
name = "pallet-scheduler"
version = "3.0.0"
-source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.7#9c572625f6557dfdb19f47474369a0327d51dfbc"
dependencies = [
"frame-benchmarking",
"frame-support",
"frame-system",
"log",
"parity-scale-codec 2.1.3",
+ "serde",
+ "sp-core",
"sp-io",
"sp-runtime",
"sp-std",
+ "substrate-test-utils",
+ "up-sponsorship",
]
[[package]]
node/cli/src/chain_spec.rsdiffbeforeafterboth--- a/node/cli/src/chain_spec.rs
+++ b/node/cli/src/chain_spec.rs
@@ -196,6 +196,7 @@
const_on_chain_schema: vec![],
variable_on_chain_schema: vec![],
limits: CollectionLimits::default(),
+ transfers_enabled: true,
},
)],
nft_item_id: vec![],
pallets/inflation/src/tests.rsdiffbeforeafterboth1#![cfg(test)]2#![allow(clippy::from_over_into)]3use crate as pallet_inflation;45use frame_support::{6 traits::{Currency},7 parameter_types,8};9use frame_support::{traits::OnInitialize};10use sp_core::H256;11use sp_runtime::{12 traits::{BlakeTwo256, IdentityLookup},13 testing::Header,14};1516type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;17type Block = frame_system::mocking::MockBlock<Test>;1819const YEAR: u64 = 5_259_600;2021parameter_types! {22 pub const ExistentialDeposit: u64 = 1;23 pub const MaxLocks: u32 = 50;24}2526impl pallet_balances::Config for Test {27 type AccountStore = System;28 type Balance = u64;29 type DustRemoval = ();30 type Event = ();31 type ExistentialDeposit = ExistentialDeposit;32 type WeightInfo = ();33 type MaxLocks = MaxLocks;34}3536frame_support::construct_runtime!(37 pub enum Test where38 Block = Block,39 NodeBlock = Block,40 UncheckedExtrinsic = UncheckedExtrinsic,41 {42 Balances: pallet_balances::{Pallet, Call, Storage},43 System: frame_system::{Pallet, Call, Config, Storage, Event<T>},44 Inflation: pallet_inflation::{Pallet, Call, Storage},45 }46);4748parameter_types! {49 pub const BlockHashCount: u64 = 250;50 pub BlockWeights: frame_system::limits::BlockWeights =51 frame_system::limits::BlockWeights::simple_max(1024);52 pub const SS58Prefix: u8 = 42;53}5455impl frame_system::Config for Test {56 type BaseCallFilter = ();57 type BlockWeights = ();58 type BlockLength = ();59 type DbWeight = ();60 type Origin = Origin;61 type Call = Call;62 type Index = u64;63 type BlockNumber = u64;64 type Hash = H256;65 type Hashing = BlakeTwo256;66 type AccountId = u64;67 type Lookup = IdentityLookup<Self::AccountId>;68 type Header = Header;69 type Event = ();70 type BlockHashCount = BlockHashCount;71 type Version = ();72 type PalletInfo = PalletInfo;73 type AccountData = pallet_balances::AccountData<u64>;74 type OnNewAccount = ();75 type OnKilledAccount = ();76 type SystemWeightInfo = ();77 type SS58Prefix = SS58Prefix;78 type OnSetCode = ();79}8081parameter_types! {82 pub TreasuryAccountId: u64 = 1234;83 pub const InflationBlockInterval: u32 = 100; // every time per how many blocks inflation is applied84}8586impl pallet_inflation::Config for Test {87 type Currency = Balances;88 type TreasuryAccountId = TreasuryAccountId;89 type InflationBlockInterval = InflationBlockInterval;90}9192// Build genesis storage according to the mock runtime.93pub fn new_test_ext() -> sp_io::TestExternalities {94 frame_system::GenesisConfig::default()95 .build_storage::<Test>()96 .unwrap()97 .into()98}99100#[test]101fn inflation_works() {102 new_test_ext().execute_with(|| {103 // Total issuance = 1_000_000_000104 let initial_issuance: u64 = 1_000_000_000;105 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);106 assert_eq!(Balances::free_balance(1234), initial_issuance);107108 // BlockInflation should be set after 1st block and109 // first inflation deposit should be equal to BlockInflation110 Inflation::on_initialize(1);111 assert!(Inflation::block_inflation() > 0);112 assert_eq!(113 Balances::free_balance(1234) - initial_issuance,114 Inflation::block_inflation()115 );116 });117}118119#[test]120fn inflation_second_deposit() {121 new_test_ext().execute_with(|| {122 // Total issuance = 1_000_000_000123 let initial_issuance: u64 = 1_000_000_000;124 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);125 assert_eq!(Balances::free_balance(1234), initial_issuance);126 Inflation::on_initialize(1);127128 // Next inflation deposit happens when block is multiple of InflationBlockInterval129 let mut block: u32 = 2;130 let balance_before: u64 = Balances::free_balance(1234);131 while block % InflationBlockInterval::get() != 0 {132 Inflation::on_initialize(block as u64);133 block += 1;134 }135 let balance_just_before: u64 = Balances::free_balance(1234);136 assert_eq!(balance_before, balance_just_before);137138 // The block with inflation139 Inflation::on_initialize(block as u64);140 let balance_after: u64 = Balances::free_balance(1234);141 assert_eq!(142 balance_after - balance_just_before,143 Inflation::block_inflation()144 );145 });146}147148#[test]149fn inflation_in_1_year() {150 new_test_ext().execute_with(|| {151 // Total issuance = 1_000_000_000152 let initial_issuance: u64 = 1_000_000_000;153 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);154 assert_eq!(Balances::free_balance(1234), initial_issuance);155 Inflation::on_initialize(1);156 let block_inflation_year_0 = Inflation::block_inflation();157158 Inflation::on_initialize(YEAR);159 let block_inflation_year_1 = Inflation::block_inflation();160161 // Assert that year 1 inflation is less than year 0162 assert!(block_inflation_year_0 > block_inflation_year_1);163 });164}165166#[test]167fn inflation_in_1_to_9_years() {168 new_test_ext().execute_with(|| {169 // Total issuance = 1_000_000_000170 let initial_issuance: u64 = 1_000_000_000;171 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);172 assert_eq!(Balances::free_balance(1234), initial_issuance);173 Inflation::on_initialize(1);174175 for year in 1..=9 {176 let block_inflation_year_before = Inflation::block_inflation();177 Inflation::on_initialize(YEAR * year);178 let block_inflation_year_after = Inflation::block_inflation();179180 // Assert that next year inflation is less than previous year inflation181 assert!(block_inflation_year_before > block_inflation_year_after);182 }183 });184}185186#[test]187fn inflation_after_year_10_is_flat() {188 new_test_ext().execute_with(|| {189 // Total issuance = 1_000_000_000190 let initial_issuance: u64 = 1_000_000_000;191 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);192 assert_eq!(Balances::free_balance(1234), initial_issuance);193 Inflation::on_initialize(YEAR * 9);194195 for year in 10..=20 {196 let block_inflation_year_before = Inflation::block_inflation();197 Inflation::on_initialize(YEAR * year);198 let block_inflation_year_after = Inflation::block_inflation();199200 // Assert that next year inflation is equal to previous year inflation201 assert_eq!(block_inflation_year_before, block_inflation_year_after);202 }203 });204}205206#[test]207fn inflation_rate_by_year() {208 new_test_ext().execute_with(|| {209 let payouts: u64 = YEAR / InflationBlockInterval::get() as u64;210211 // Inflation starts at 10% and does down by 2/3% every year until year 9 (included),212 // then it is flat.213 let payout_by_year: [u64; 11] = [1000, 933, 867, 800, 733, 667, 600, 533, 467, 400, 400];214215 // For accuracy total issuance = payout0 * payouts * 10;216 let initial_issuance: u64 = payout_by_year[0] * payouts * 10;217 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);218 assert_eq!(Balances::free_balance(1234), initial_issuance);219220 for year in 0..=10 {221 // Year first block222 Inflation::on_initialize(year * YEAR);223 let mut actual_payout = Inflation::block_inflation();224 assert_eq!(actual_payout, payout_by_year[year as usize]);225226 // Year second block227 Inflation::on_initialize(year * YEAR + 1);228 actual_payout = Inflation::block_inflation();229 assert_eq!(actual_payout, payout_by_year[year as usize]);230231 // Year middle block232 Inflation::on_initialize(year * YEAR + YEAR / 2);233 actual_payout = Inflation::block_inflation();234 assert_eq!(actual_payout, payout_by_year[year as usize]);235236 // Year last block237 Inflation::on_initialize((year + 1) * YEAR - 1);238 actual_payout = Inflation::block_inflation();239 assert_eq!(actual_payout, payout_by_year[year as usize]);240 }241 });242}1#![cfg(test)]2#![allow(clippy::from_over_into)]3use crate as pallet_inflation;45use frame_support::{6 traits::{Currency},7 parameter_types,8};9use frame_support::{traits::OnInitialize};10use sp_core::H256;11use sp_runtime::{12 traits::{BlakeTwo256, IdentityLookup},13 testing::Header,14};1516type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;17type Block = frame_system::mocking::MockBlock<Test>;1819const YEAR: u64 = 5_259_600;2021parameter_types! {22 pub const ExistentialDeposit: u64 = 1;23 pub const MaxLocks: u32 = 50;24}2526impl pallet_balances::Config for Test {27 type AccountStore = System;28 type Balance = u64;29 type DustRemoval = ();30 type Event = ();31 type ExistentialDeposit = ExistentialDeposit;32 type WeightInfo = ();33 type MaxLocks = MaxLocks;34 type MaxReserves = ();35 type ReserveIdentifier = ();36}3738frame_support::construct_runtime!(39 pub enum Test where40 Block = Block,41 NodeBlock = Block,42 UncheckedExtrinsic = UncheckedExtrinsic,43 {44 Balances: pallet_balances::{Pallet, Call, Storage},45 System: frame_system::{Pallet, Call, Config, Storage, Event<T>},46 Inflation: pallet_inflation::{Pallet, Call, Storage},47 }48);4950parameter_types! {51 pub const BlockHashCount: u64 = 250;52 pub BlockWeights: frame_system::limits::BlockWeights =53 frame_system::limits::BlockWeights::simple_max(1024);54 pub const SS58Prefix: u8 = 42;55}5657impl frame_system::Config for Test {58 type BaseCallFilter = ();59 type BlockWeights = ();60 type BlockLength = ();61 type DbWeight = ();62 type Origin = Origin;63 type Call = Call;64 type Index = u64;65 type BlockNumber = u64;66 type Hash = H256;67 type Hashing = BlakeTwo256;68 type AccountId = u64;69 type Lookup = IdentityLookup<Self::AccountId>;70 type Header = Header;71 type Event = ();72 type BlockHashCount = BlockHashCount;73 type Version = ();74 type PalletInfo = PalletInfo;75 type AccountData = pallet_balances::AccountData<u64>;76 type OnNewAccount = ();77 type OnKilledAccount = ();78 type SystemWeightInfo = ();79 type SS58Prefix = SS58Prefix;80 type OnSetCode = ();81}8283parameter_types! {84 pub TreasuryAccountId: u64 = 1234;85 pub const InflationBlockInterval: u32 = 100; // every time per how many blocks inflation is applied86}8788impl pallet_inflation::Config for Test {89 type Currency = Balances;90 type TreasuryAccountId = TreasuryAccountId;91 type InflationBlockInterval = InflationBlockInterval;92}9394// Build genesis storage according to the mock runtime.95pub fn new_test_ext() -> sp_io::TestExternalities {96 frame_system::GenesisConfig::default()97 .build_storage::<Test>()98 .unwrap()99 .into()100}101102#[test]103fn inflation_works() {104 new_test_ext().execute_with(|| {105 // Total issuance = 1_000_000_000106 let initial_issuance: u64 = 1_000_000_000;107 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);108 assert_eq!(Balances::free_balance(1234), initial_issuance);109110 // BlockInflation should be set after 1st block and111 // first inflation deposit should be equal to BlockInflation112 Inflation::on_initialize(1);113 assert!(Inflation::block_inflation() > 0);114 assert_eq!(115 Balances::free_balance(1234) - initial_issuance,116 Inflation::block_inflation()117 );118 });119}120121#[test]122fn inflation_second_deposit() {123 new_test_ext().execute_with(|| {124 // Total issuance = 1_000_000_000125 let initial_issuance: u64 = 1_000_000_000;126 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);127 assert_eq!(Balances::free_balance(1234), initial_issuance);128 Inflation::on_initialize(1);129130 // Next inflation deposit happens when block is multiple of InflationBlockInterval131 let mut block: u32 = 2;132 let balance_before: u64 = Balances::free_balance(1234);133 while block % InflationBlockInterval::get() != 0 {134 Inflation::on_initialize(block as u64);135 block += 1;136 }137 let balance_just_before: u64 = Balances::free_balance(1234);138 assert_eq!(balance_before, balance_just_before);139140 // The block with inflation141 Inflation::on_initialize(block as u64);142 let balance_after: u64 = Balances::free_balance(1234);143 assert_eq!(144 balance_after - balance_just_before,145 Inflation::block_inflation()146 );147 });148}149150#[test]151fn inflation_in_1_year() {152 new_test_ext().execute_with(|| {153 // Total issuance = 1_000_000_000154 let initial_issuance: u64 = 1_000_000_000;155 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);156 assert_eq!(Balances::free_balance(1234), initial_issuance);157 Inflation::on_initialize(1);158 let block_inflation_year_0 = Inflation::block_inflation();159160 Inflation::on_initialize(YEAR);161 let block_inflation_year_1 = Inflation::block_inflation();162163 // Assert that year 1 inflation is less than year 0164 assert!(block_inflation_year_0 > block_inflation_year_1);165 });166}167168#[test]169fn inflation_in_1_to_9_years() {170 new_test_ext().execute_with(|| {171 // Total issuance = 1_000_000_000172 let initial_issuance: u64 = 1_000_000_000;173 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);174 assert_eq!(Balances::free_balance(1234), initial_issuance);175 Inflation::on_initialize(1);176177 for year in 1..=9 {178 let block_inflation_year_before = Inflation::block_inflation();179 Inflation::on_initialize(YEAR * year);180 let block_inflation_year_after = Inflation::block_inflation();181182 // Assert that next year inflation is less than previous year inflation183 assert!(block_inflation_year_before > block_inflation_year_after);184 }185 });186}187188#[test]189fn inflation_after_year_10_is_flat() {190 new_test_ext().execute_with(|| {191 // Total issuance = 1_000_000_000192 let initial_issuance: u64 = 1_000_000_000;193 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);194 assert_eq!(Balances::free_balance(1234), initial_issuance);195 Inflation::on_initialize(YEAR * 9);196197 for year in 10..=20 {198 let block_inflation_year_before = Inflation::block_inflation();199 Inflation::on_initialize(YEAR * year);200 let block_inflation_year_after = Inflation::block_inflation();201202 // Assert that next year inflation is equal to previous year inflation203 assert_eq!(block_inflation_year_before, block_inflation_year_after);204 }205 });206}207208#[test]209fn inflation_rate_by_year() {210 new_test_ext().execute_with(|| {211 let payouts: u64 = YEAR / InflationBlockInterval::get() as u64;212213 // Inflation starts at 10% and does down by 2/3% every year until year 9 (included),214 // then it is flat.215 let payout_by_year: [u64; 11] = [1000, 933, 867, 800, 733, 667, 600, 533, 467, 400, 400];216217 // For accuracy total issuance = payout0 * payouts * 10;218 let initial_issuance: u64 = payout_by_year[0] * payouts * 10;219 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);220 assert_eq!(Balances::free_balance(1234), initial_issuance);221222 for year in 0..=10 {223 // Year first block224 Inflation::on_initialize(year * YEAR);225 let mut actual_payout = Inflation::block_inflation();226 assert_eq!(actual_payout, payout_by_year[year as usize]);227228 // Year second block229 Inflation::on_initialize(year * YEAR + 1);230 actual_payout = Inflation::block_inflation();231 assert_eq!(actual_payout, payout_by_year[year as usize]);232233 // Year middle block234 Inflation::on_initialize(year * YEAR + YEAR / 2);235 actual_payout = Inflation::block_inflation();236 assert_eq!(actual_payout, payout_by_year[year as usize]);237238 // Year last block239 Inflation::on_initialize((year + 1) * YEAR - 1);240 actual_payout = Inflation::block_inflation();241 assert_eq!(actual_payout, payout_by_year[year as usize]);242 }243 });244}pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -175,6 +175,8 @@
BadCreateRefungibleCall,
/// Gas limit exceeded
OutOfGas,
+ /// Collection settings not allowing items transferring
+ TransferNotAllowed,
}
}
@@ -533,6 +535,7 @@
variable_on_chain_schema: Vec::new(),
const_on_chain_schema: Vec::new(),
limits,
+ transfers_enabled: true,
};
// Add new collection to map
@@ -922,6 +925,34 @@
Ok(())
}
+ // TODO! transaction weight
+
+ /// Set transfers_enabled value for particular collection
+ ///
+ /// # Permissions
+ ///
+ /// * Collection Owner.
+ ///
+ /// # Arguments
+ ///
+ /// * collection_id: ID of the collection.
+ ///
+ /// * value: New flag value.
+ #[weight = <T as Config>::WeightInfo::burn_item()]
+ #[transactional]
+ pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {
+
+ let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+ let mut target_collection = Self::get_collection(collection_id)?;
+
+ Self::check_owner_permissions(&target_collection, sender.as_sub())?;
+
+ target_collection.transfers_enabled = value;
+ Self::save_collection(target_collection);
+
+ Ok(())
+ }
+
/// Destroys a concrete instance of NFT.
///
/// # Permissions
@@ -1575,6 +1606,12 @@
Error::<T>::AccountTokenLimitExceeded
);
+ // preliminary transfer check
+ ensure!(
+ collection.transfers_enabled,
+ Error::<T>::TransferNotAllowed
+ );
+
Ok(())
}
pallets/nft/src/mock.rsdiffbeforeafterboth--- a/pallets/nft/src/mock.rs
+++ b/pallets/nft/src/mock.rs
@@ -74,6 +74,8 @@
type ExistentialDeposit = ExistentialDeposit;
type WeightInfo = ();
type MaxLocks = MaxLocks;
+ type MaxReserves = ();
+ type ReserveIdentifier = [u8; 8];
}
parameter_types! {
@@ -100,40 +102,40 @@
type Timestamp = pallet_timestamp::Pallet<Test>;
type Randomness = pallet_randomness_collective_flip::Pallet<Test>;
-parameter_types! {
- pub const TombstoneDeposit: u64 = 1;
- pub const DepositPerContract: u64 = 1;
- pub const DepositPerStorageByte: u64 = 1;
- pub const DepositPerStorageItem: u64 = 1;
- pub RentFraction: Perbill = Perbill::from_rational(1u32, 30 * 24 * 60 * 10);
- pub const SurchargeReward: u64 = 1;
- pub const SignedClaimHandicap: u32 = 2;
- pub DeletionWeightLimit: u64 = u64::MAX;//Perbill::from_percent(10);
- pub DeletionQueueDepth: u32 = 10;
- pub Schedule: pallet_contracts::Schedule<Test> = Default::default();
-}
+// parameter_types! {
+// pub const TombstoneDeposit: u64 = 1;
+// pub const DepositPerContract: u64 = 1;
+// pub const DepositPerStorageByte: u64 = 1;
+// pub const DepositPerStorageItem: u64 = 1;
+// pub RentFraction: Perbill = Perbill::from_rational(1u32, 30 * 24 * 60 * 10);
+// pub const SurchargeReward: u64 = 1;
+// pub const SignedClaimHandicap: u32 = 2;
+// pub DeletionWeightLimit: u64 = u64::MAX;//Perbill::from_percent(10);
+// pub DeletionQueueDepth: u32 = 10;
+// pub Schedule: pallet_contracts::Schedule<Test> = Default::default();
+// }
-impl pallet_contracts::Config for Test {
- type Time = Timestamp;
- type Randomness = Randomness;
- type Currency = pallet_balances::Pallet<Test>;
- type Event = ();
- type RentPayment = ();
- type SignedClaimHandicap = SignedClaimHandicap;
- type TombstoneDeposit = TombstoneDeposit;
- type DepositPerContract = DepositPerContract;
- type DepositPerStorageByte = DepositPerStorageByte;
- type DepositPerStorageItem = DepositPerStorageItem;
- type RentFraction = RentFraction;
- type SurchargeReward = SurchargeReward;
- type DeletionWeightLimit = DeletionWeightLimit;
- type DeletionQueueDepth = DeletionQueueDepth;
- type ChainExtension = ();
- type WeightPrice = ();
- type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
- type Schedule = Schedule;
- type CallStack = [pallet_contracts::Frame<Self>; 31];
-}
+// impl pallet_contracts::Config for Test {
+// type Time = Timestamp;
+// type Randomness = Randomness;
+// type Currency = pallet_balances::Pallet<Test>;
+// type Event = ();
+// type RentPayment = ();
+// type SignedClaimHandicap = SignedClaimHandicap;
+// type TombstoneDeposit = TombstoneDeposit;
+// type DepositPerContract = DepositPerContract;
+// type DepositPerStorageByte = DepositPerStorageByte;
+// type DepositPerStorageItem = DepositPerStorageItem;
+// type RentFraction = RentFraction;
+// type SurchargeReward = SurchargeReward;
+// type DeletionWeightLimit = DeletionWeightLimit;
+// type DeletionQueueDepth = DeletionQueueDepth;
+// type ChainExtension = ();
+// type WeightPrice = ();
+// type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
+// type Schedule = Schedule;
+// type CallStack = [pallet_contracts::Frame<Self>; 31];
+// }
parameter_types! {
pub const CollectionCreationPrice: u32 = 0;
pallets/nft/src/tests.rsdiffbeforeafterboth--- a/pallets/nft/src/tests.rs
+++ b/pallets/nft/src/tests.rs
@@ -2351,3 +2351,60 @@
);
});
}
+
+#[test]
+fn collection_transfer_flag_works() {
+ new_test_ext().execute_with(|| {
+ default_limits();
+
+ let origin1 = Origin::signed(1);
+
+ let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ assert_ok!(TemplateModule::set_transfers_enabled_flag(origin1, 1, true));
+
+ let data = default_nft_data();
+ create_test_item(collection_id, &data.into());
+ assert_eq!(TemplateModule::balance_count(1, 1), 1);
+ assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+
+ let origin1 = Origin::signed(1);
+
+ // default scenario
+ assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1000));
+ assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));
+ assert_eq!(TemplateModule::balance_count(1, 1), 0);
+ assert_eq!(TemplateModule::balance_count(1, 2), 1);
+
+ assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
+ });
+}
+
+#[test]
+fn collection_transfer_flag_works_neg() {
+ new_test_ext().execute_with(|| {
+ default_limits();
+
+ let origin1 = Origin::signed(1);
+
+ let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ assert_ok!(TemplateModule::set_transfers_enabled_flag(origin1, 1, false));
+
+ let data = default_nft_data();
+ create_test_item(collection_id, &data.into());
+ assert_eq!(TemplateModule::balance_count(1, 1), 1);
+ assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+
+ let origin1 = Origin::signed(1);
+
+ // default scenario
+ assert_noop!(
+ TemplateModule::transfer(origin1, account(2), 1, 1, 1000),
+ Error::<Test>::TransferNotAllowed
+ );
+ assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(1));
+ assert_eq!(TemplateModule::balance_count(1, 1), 1);
+ assert_eq!(TemplateModule::balance_count(1, 2), 0);
+
+ assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ });
+}
pallets/scheduler/src/lib.rsdiffbeforeafterboth--- a/pallets/scheduler/src/lib.rs
+++ b/pallets/scheduler/src/lib.rs
@@ -947,900 +947,4 @@
fn root() -> OriginCaller {
system::RawOrigin::Root.into()
}
-
- #[test]
- fn basic_scheduling_works() {
- new_test_ext().execute_with(|| {
- let call = Call::Logger(logger::Call::log(42, 1000));
- assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(
- &call
- ));
- assert_ok!(Scheduler::do_schedule(
- DispatchTime::At(4),
- None,
- 127,
- root(),
- call
- ));
- run_to_block(3);
- assert!(logger::log().is_empty());
- run_to_block(4);
- assert_eq!(logger::log(), vec![(root(), 42u32)]);
- run_to_block(100);
- assert_eq!(logger::log(), vec![(root(), 42u32)]);
- });
- }
-
- #[test]
- fn schedule_after_works() {
- new_test_ext().execute_with(|| {
- run_to_block(2);
- let call = Call::Logger(logger::Call::log(42, 1000));
- assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(
- &call
- ));
- // This will schedule the call 3 blocks after the next block... so block 3 + 3 = 6
- assert_ok!(Scheduler::do_schedule(
- DispatchTime::After(3),
- None,
- 127,
- root(),
- call
- ));
- run_to_block(5);
- assert!(logger::log().is_empty());
- run_to_block(6);
- assert_eq!(logger::log(), vec![(root(), 42u32)]);
- run_to_block(100);
- assert_eq!(logger::log(), vec![(root(), 42u32)]);
- });
- }
-
- #[test]
- fn schedule_after_zero_works() {
- new_test_ext().execute_with(|| {
- run_to_block(2);
- let call = Call::Logger(logger::Call::log(42, 1000));
- assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(
- &call
- ));
- assert_ok!(Scheduler::do_schedule(
- DispatchTime::After(0),
- None,
- 127,
- root(),
- call
- ));
- // Will trigger on the next block.
- run_to_block(3);
- assert_eq!(logger::log(), vec![(root(), 42u32)]);
- run_to_block(100);
- assert_eq!(logger::log(), vec![(root(), 42u32)]);
- });
- }
-
- #[test]
- fn periodic_scheduling_works() {
- new_test_ext().execute_with(|| {
- // at #4, every 3 blocks, 3 times.
- assert_ok!(Scheduler::do_schedule(
- DispatchTime::At(4),
- Some((3, 3)),
- 127,
- root(),
- Call::Logger(logger::Call::log(42, 1000))
- ));
- run_to_block(3);
- assert!(logger::log().is_empty());
- run_to_block(4);
- assert_eq!(logger::log(), vec![(root(), 42u32)]);
- run_to_block(6);
- assert_eq!(logger::log(), vec![(root(), 42u32)]);
- run_to_block(7);
- assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 42u32)]);
- run_to_block(9);
- assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 42u32)]);
- run_to_block(10);
- assert_eq!(
- logger::log(),
- vec![(root(), 42u32), (root(), 42u32), (root(), 42u32)]
- );
- run_to_block(100);
- assert_eq!(
- logger::log(),
- vec![(root(), 42u32), (root(), 42u32), (root(), 42u32)]
- );
- });
- }
-
- #[test]
- fn reschedule_works() {
- new_test_ext().execute_with(|| {
- let call = Call::Logger(logger::Call::log(42, 1000));
- assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(
- &call
- ));
- assert_eq!(
- Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call).unwrap(),
- (4, 0)
- );
-
- run_to_block(3);
- assert!(logger::log().is_empty());
-
- assert_eq!(
- Scheduler::do_reschedule((4, 0), DispatchTime::At(6)).unwrap(),
- (6, 0)
- );
-
- assert_noop!(
- Scheduler::do_reschedule((6, 0), DispatchTime::At(6)),
- Error::<Test>::RescheduleNoChange
- );
-
- run_to_block(4);
- assert!(logger::log().is_empty());
-
- run_to_block(6);
- assert_eq!(logger::log(), vec![(root(), 42u32)]);
-
- run_to_block(100);
- assert_eq!(logger::log(), vec![(root(), 42u32)]);
- });
- }
-
- #[test]
- fn reschedule_named_works() {
- new_test_ext().execute_with(|| {
- let call = Call::Logger(logger::Call::log(42, 1000));
- assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(
- &call
- ));
- assert_eq!(
- Scheduler::do_schedule_named(
- 1u32.encode(),
- DispatchTime::At(4),
- None,
- 127,
- root(),
- call
- )
- .unwrap(),
- (4, 0)
- );
-
- run_to_block(3);
- assert!(logger::log().is_empty());
-
- assert_eq!(
- Scheduler::do_reschedule_named(1u32.encode(), DispatchTime::At(6)).unwrap(),
- (6, 0)
- );
-
- assert_noop!(
- Scheduler::do_reschedule_named(1u32.encode(), DispatchTime::At(6)),
- Error::<Test>::RescheduleNoChange
- );
-
- run_to_block(4);
- assert!(logger::log().is_empty());
-
- run_to_block(6);
- assert_eq!(logger::log(), vec![(root(), 42u32)]);
-
- run_to_block(100);
- assert_eq!(logger::log(), vec![(root(), 42u32)]);
- });
- }
-
- #[test]
- fn reschedule_named_perodic_works() {
- new_test_ext().execute_with(|| {
- let call = Call::Logger(logger::Call::log(42, 1000));
- assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(
- &call
- ));
- assert_eq!(
- Scheduler::do_schedule_named(
- 1u32.encode(),
- DispatchTime::At(4),
- Some((3, 3)),
- 127,
- root(),
- call
- )
- .unwrap(),
- (4, 0)
- );
-
- run_to_block(3);
- assert!(logger::log().is_empty());
-
- assert_eq!(
- Scheduler::do_reschedule_named(1u32.encode(), DispatchTime::At(5)).unwrap(),
- (5, 0)
- );
- assert_eq!(
- Scheduler::do_reschedule_named(1u32.encode(), DispatchTime::At(6)).unwrap(),
- (6, 0)
- );
-
- run_to_block(5);
- assert!(logger::log().is_empty());
-
- run_to_block(6);
- assert_eq!(logger::log(), vec![(root(), 42u32)]);
-
- assert_eq!(
- Scheduler::do_reschedule_named(1u32.encode(), DispatchTime::At(10)).unwrap(),
- (10, 0)
- );
-
- run_to_block(9);
- assert_eq!(logger::log(), vec![(root(), 42u32)]);
-
- run_to_block(10);
- assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 42u32)]);
-
- run_to_block(13);
- assert_eq!(
- logger::log(),
- vec![(root(), 42u32), (root(), 42u32), (root(), 42u32)]
- );
-
- run_to_block(100);
- assert_eq!(
- logger::log(),
- vec![(root(), 42u32), (root(), 42u32), (root(), 42u32)]
- );
- });
- }
-
- #[test]
- fn cancel_named_scheduling_works_with_normal_cancel() {
- new_test_ext().execute_with(|| {
- // at #4.
- Scheduler::do_schedule_named(
- 1u32.encode(),
- DispatchTime::At(4),
- None,
- 127,
- root(),
- Call::Logger(logger::Call::log(69, 1000)),
- )
- .unwrap();
- let i = Scheduler::do_schedule(
- DispatchTime::At(4),
- None,
- 127,
- root(),
- Call::Logger(logger::Call::log(42, 1000)),
- )
- .unwrap();
- run_to_block(3);
- assert!(logger::log().is_empty());
- assert_ok!(Scheduler::do_cancel_named(None, 1u32.encode()));
- assert_ok!(Scheduler::do_cancel(None, i));
- run_to_block(100);
- assert!(logger::log().is_empty());
- });
- }
-
- #[test]
- fn cancel_named_periodic_scheduling_works() {
- new_test_ext().execute_with(|| {
- // at #4, every 3 blocks, 3 times.
- Scheduler::do_schedule_named(
- 1u32.encode(),
- DispatchTime::At(4),
- Some((3, 3)),
- 127,
- root(),
- Call::Logger(logger::Call::log(42, 1000)),
- )
- .unwrap();
- // same id results in error.
- assert!(Scheduler::do_schedule_named(
- 1u32.encode(),
- DispatchTime::At(4),
- None,
- 127,
- root(),
- Call::Logger(logger::Call::log(69, 1000))
- )
- .is_err());
- // different id is ok.
- Scheduler::do_schedule_named(
- 2u32.encode(),
- DispatchTime::At(8),
- None,
- 127,
- root(),
- Call::Logger(logger::Call::log(69, 1000)),
- )
- .unwrap();
- run_to_block(3);
- assert!(logger::log().is_empty());
- run_to_block(4);
- assert_eq!(logger::log(), vec![(root(), 42u32)]);
- run_to_block(6);
- assert_ok!(Scheduler::do_cancel_named(None, 1u32.encode()));
- run_to_block(100);
- assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 69u32)]);
- });
- }
-
- #[test]
- fn scheduler_respects_weight_limits() {
- new_test_ext().execute_with(|| {
- assert_ok!(Scheduler::do_schedule(
- DispatchTime::At(4),
- None,
- 127,
- root(),
- Call::Logger(logger::Call::log(42, MaximumSchedulerWeight::get() / 2))
- ));
- assert_ok!(Scheduler::do_schedule(
- DispatchTime::At(4),
- None,
- 127,
- root(),
- Call::Logger(logger::Call::log(69, MaximumSchedulerWeight::get() / 2))
- ));
- // 69 and 42 do not fit together
- run_to_block(4);
- assert_eq!(logger::log(), vec![(root(), 42u32)]);
- run_to_block(5);
- assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 69u32)]);
- });
- }
-
- #[test]
- fn scheduler_respects_hard_deadlines_more() {
- new_test_ext().execute_with(|| {
- assert_ok!(Scheduler::do_schedule(
- DispatchTime::At(4),
- None,
- 0,
- root(),
- Call::Logger(logger::Call::log(42, MaximumSchedulerWeight::get() / 2))
- ));
- assert_ok!(Scheduler::do_schedule(
- DispatchTime::At(4),
- None,
- 0,
- root(),
- Call::Logger(logger::Call::log(69, MaximumSchedulerWeight::get() / 2))
- ));
- // With base weights, 69 and 42 should not fit together, but do because of hard deadlines
- run_to_block(4);
- assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 69u32)]);
- });
- }
-
- #[test]
- fn scheduler_respects_priority_ordering() {
- new_test_ext().execute_with(|| {
- assert_ok!(Scheduler::do_schedule(
- DispatchTime::At(4),
- None,
- 1,
- root(),
- Call::Logger(logger::Call::log(42, MaximumSchedulerWeight::get() / 2))
- ));
- assert_ok!(Scheduler::do_schedule(
- DispatchTime::At(4),
- None,
- 0,
- root(),
- Call::Logger(logger::Call::log(69, MaximumSchedulerWeight::get() / 2))
- ));
- run_to_block(4);
- assert_eq!(logger::log(), vec![(root(), 69u32), (root(), 42u32)]);
- });
- }
-
- #[test]
- fn scheduler_respects_priority_ordering_with_soft_deadlines() {
- new_test_ext().execute_with(|| {
- assert_ok!(Scheduler::do_schedule(
- DispatchTime::At(4),
- None,
- 255,
- root(),
- Call::Logger(logger::Call::log(42, MaximumSchedulerWeight::get() / 3))
- ));
- assert_ok!(Scheduler::do_schedule(
- DispatchTime::At(4),
- None,
- 127,
- root(),
- Call::Logger(logger::Call::log(69, MaximumSchedulerWeight::get() / 2))
- ));
- assert_ok!(Scheduler::do_schedule(
- DispatchTime::At(4),
- None,
- 126,
- root(),
- Call::Logger(logger::Call::log(2600, MaximumSchedulerWeight::get() / 2))
- ));
-
- // 2600 does not fit with 69 or 42, but has higher priority, so will go through
- run_to_block(4);
- assert_eq!(logger::log(), vec![(root(), 2600u32)]);
- // 69 and 42 fit together
- run_to_block(5);
- assert_eq!(
- logger::log(),
- vec![(root(), 2600u32), (root(), 69u32), (root(), 42u32)]
- );
- });
- }
-
- #[test]
- fn on_initialize_weight_is_correct() {
- new_test_ext().execute_with(|| {
- let base_weight: Weight =
- <Test as frame_system::Config>::DbWeight::get().reads_writes(1, 2);
- let base_multiplier = 0;
- let named_multiplier = <Test as frame_system::Config>::DbWeight::get().writes(1);
- let periodic_multiplier =
- <Test as frame_system::Config>::DbWeight::get().reads_writes(1, 1);
-
- // Named
- assert_ok!(Scheduler::do_schedule_named(
- 1u32.encode(),
- DispatchTime::At(1),
- None,
- 255,
- root(),
- Call::Logger(logger::Call::log(3, MaximumSchedulerWeight::get() / 3))
- ));
- // Anon Periodic
- assert_ok!(Scheduler::do_schedule(
- DispatchTime::At(1),
- Some((1000, 3)),
- 128,
- root(),
- Call::Logger(logger::Call::log(42, MaximumSchedulerWeight::get() / 3))
- ));
- // Anon
- assert_ok!(Scheduler::do_schedule(
- DispatchTime::At(1),
- None,
- 127,
- root(),
- Call::Logger(logger::Call::log(69, MaximumSchedulerWeight::get() / 2))
- ));
- // Named Periodic
- assert_ok!(Scheduler::do_schedule_named(
- 2u32.encode(),
- DispatchTime::At(1),
- Some((1000, 3)),
- 126,
- root(),
- Call::Logger(logger::Call::log(2600, MaximumSchedulerWeight::get() / 2))
- ));
-
- // Will include the named periodic only
- let actual_weight = Scheduler::on_initialize(1);
- let call_weight = MaximumSchedulerWeight::get() / 2;
- assert_eq!(
- actual_weight,
- call_weight
- + base_weight + base_multiplier
- + named_multiplier + periodic_multiplier
- );
- assert_eq!(logger::log(), vec![(root(), 2600u32)]);
-
- // Will include anon and anon periodic
- let actual_weight = Scheduler::on_initialize(2);
- let call_weight = MaximumSchedulerWeight::get() / 2 + MaximumSchedulerWeight::get() / 3;
- assert_eq!(
- actual_weight,
- call_weight + base_weight + base_multiplier * 2 + periodic_multiplier
- );
- assert_eq!(
- logger::log(),
- vec![(root(), 2600u32), (root(), 69u32), (root(), 42u32)]
- );
-
- // Will include named only
- let actual_weight = Scheduler::on_initialize(3);
- let call_weight = MaximumSchedulerWeight::get() / 3;
- assert_eq!(
- actual_weight,
- call_weight + base_weight + base_multiplier + named_multiplier
- );
- assert_eq!(
- logger::log(),
- vec![
- (root(), 2600u32),
- (root(), 69u32),
- (root(), 42u32),
- (root(), 3u32)
- ]
- );
-
- // Will contain none
- let actual_weight = Scheduler::on_initialize(4);
- assert_eq!(actual_weight, 0);
- });
- }
-
- #[test]
- fn root_calls_works() {
- new_test_ext().execute_with(|| {
- let call = Box::new(Call::Logger(logger::Call::log(69, 1000)));
- let call2 = Box::new(Call::Logger(logger::Call::log(42, 1000)));
- assert_ok!(Scheduler::schedule_named(
- Origin::root(),
- 1u32.encode(),
- 4,
- None,
- 127,
- call
- ));
- assert_ok!(Scheduler::schedule(Origin::root(), 4, None, 127, call2));
- run_to_block(3);
- // Scheduled calls are in the agenda.
- assert_eq!(Agenda::<Test>::get(4).len(), 2);
- assert!(logger::log().is_empty());
- assert_ok!(Scheduler::cancel_named(Origin::root(), 1u32.encode()));
- assert_ok!(Scheduler::cancel(Origin::root(), 4, 1));
- // Scheduled calls are made NONE, so should not effect state
- run_to_block(100);
- assert!(logger::log().is_empty());
- });
- }
-
- #[test]
- fn fails_to_schedule_task_in_the_past() {
- new_test_ext().execute_with(|| {
- run_to_block(3);
-
- let call = Box::new(Call::Logger(logger::Call::log(69, 1000)));
- let call2 = Box::new(Call::Logger(logger::Call::log(42, 1000)));
-
- assert_err!(
- Scheduler::schedule_named(Origin::root(), 1u32.encode(), 2, None, 127, call),
- Error::<Test>::TargetBlockNumberInPast,
- );
-
- assert_err!(
- Scheduler::schedule(Origin::root(), 2, None, 127, call2.clone()),
- Error::<Test>::TargetBlockNumberInPast,
- );
-
- assert_err!(
- Scheduler::schedule(Origin::root(), 3, None, 127, call2),
- Error::<Test>::TargetBlockNumberInPast,
- );
- });
- }
-
- #[test]
- fn should_use_orign() {
- new_test_ext().execute_with(|| {
- let call = Box::new(Call::Logger(logger::Call::log(69, 1000)));
- let call2 = Box::new(Call::Logger(logger::Call::log(42, 1000)));
- assert_ok!(Scheduler::schedule_named(
- system::RawOrigin::Signed(1).into(),
- 1u32.encode(),
- 4,
- None,
- 127,
- call
- ));
- assert_ok!(Scheduler::schedule(
- system::RawOrigin::Signed(1).into(),
- 4,
- None,
- 127,
- call2
- ));
- run_to_block(3);
- // Scheduled calls are in the agenda.
- assert_eq!(Agenda::<Test>::get(4).len(), 2);
- assert!(logger::log().is_empty());
- assert_ok!(Scheduler::cancel_named(
- system::RawOrigin::Signed(1).into(),
- 1u32.encode()
- ));
- assert_ok!(Scheduler::cancel(system::RawOrigin::Signed(1).into(), 4, 1));
- // Scheduled calls are made NONE, so should not effect state
- run_to_block(100);
- assert!(logger::log().is_empty());
- });
- }
-
- #[test]
- fn should_check_orign() {
- new_test_ext().execute_with(|| {
- let call = Box::new(Call::Logger(logger::Call::log(69, 1000)));
- let call2 = Box::new(Call::Logger(logger::Call::log(42, 1000)));
- assert_noop!(
- Scheduler::schedule_named(
- system::RawOrigin::Signed(2).into(),
- 1u32.encode(),
- 4,
- None,
- 127,
- call
- ),
- BadOrigin
- );
- assert_noop!(
- Scheduler::schedule(system::RawOrigin::Signed(2).into(), 4, None, 127, call2),
- BadOrigin
- );
- });
- }
-
- #[test]
- fn should_check_orign_for_cancel() {
- new_test_ext().execute_with(|| {
- let call = Box::new(Call::Logger(logger::Call::log_without_filter(69, 1000)));
- let call2 = Box::new(Call::Logger(logger::Call::log_without_filter(42, 1000)));
- assert_ok!(Scheduler::schedule_named(
- system::RawOrigin::Signed(1).into(),
- 1u32.encode(),
- 4,
- None,
- 127,
- call
- ));
- assert_ok!(Scheduler::schedule(
- system::RawOrigin::Signed(1).into(),
- 4,
- None,
- 127,
- call2
- ));
- run_to_block(3);
- // Scheduled calls are in the agenda.
- assert_eq!(Agenda::<Test>::get(4).len(), 2);
- assert!(logger::log().is_empty());
- assert_noop!(
- Scheduler::cancel_named(system::RawOrigin::Signed(2).into(), 1u32.encode()),
- BadOrigin
- );
- assert_noop!(
- Scheduler::cancel(system::RawOrigin::Signed(2).into(), 4, 1),
- BadOrigin
- );
- assert_noop!(
- Scheduler::cancel_named(system::RawOrigin::Root.into(), 1u32.encode()),
- BadOrigin
- );
- assert_noop!(
- Scheduler::cancel(system::RawOrigin::Root.into(), 4, 1),
- BadOrigin
- );
- run_to_block(5);
- assert_eq!(
- logger::log(),
- vec![
- (system::RawOrigin::Signed(1).into(), 69u32),
- (system::RawOrigin::Signed(1).into(), 42u32)
- ]
- );
- });
- }
-
- #[test]
- fn migration_to_v2_works() {
- new_test_ext().execute_with(|| {
- for i in 0..3u64 {
- let k = i.twox_64_concat();
- let old = vec![
- Some(ScheduledV1 {
- maybe_id: None,
- priority: i as u8 + 10,
- call: Call::Logger(logger::Call::log(96, 100)),
- maybe_periodic: None,
- }),
- None,
- Some(ScheduledV1 {
- maybe_id: Some(b"test".to_vec()),
- priority: 123,
- call: Call::Logger(logger::Call::log(69, 1000)),
- maybe_periodic: Some((456u64, 10)),
- }),
- ];
- frame_support::migration::put_storage_value(b"Scheduler", b"Agenda", &k, old);
- }
-
- assert_eq!(StorageVersion::get(), Releases::V1);
-
- assert!(Scheduler::migrate_v1_to_t2());
-
- assert_eq_uvec!(
- Agenda::<Test>::iter().collect::<Vec<_>>(),
- vec![
- (
- 0,
- vec![
- Some(ScheduledV2 {
- maybe_id: None,
- priority: 10,
- call: Call::Logger(logger::Call::log(96, 100)),
- maybe_periodic: None,
- origin: root(),
- _phantom: PhantomData::<u64>::default(),
- }),
- None,
- Some(ScheduledV2 {
- maybe_id: Some(b"test".to_vec()),
- priority: 123,
- call: Call::Logger(logger::Call::log(69, 1000)),
- maybe_periodic: Some((456u64, 10)),
- origin: root(),
- _phantom: PhantomData::<u64>::default(),
- }),
- ]
- ),
- (
- 1,
- vec![
- Some(ScheduledV2 {
- maybe_id: None,
- priority: 11,
- call: Call::Logger(logger::Call::log(96, 100)),
- maybe_periodic: None,
- origin: root(),
- _phantom: PhantomData::<u64>::default(),
- }),
- None,
- Some(ScheduledV2 {
- maybe_id: Some(b"test".to_vec()),
- priority: 123,
- call: Call::Logger(logger::Call::log(69, 1000)),
- maybe_periodic: Some((456u64, 10)),
- origin: root(),
- _phantom: PhantomData::<u64>::default(),
- }),
- ]
- ),
- (
- 2,
- vec![
- Some(ScheduledV2 {
- maybe_id: None,
- priority: 12,
- call: Call::Logger(logger::Call::log(96, 100)),
- maybe_periodic: None,
- origin: root(),
- _phantom: PhantomData::<u64>::default(),
- }),
- None,
- Some(ScheduledV2 {
- maybe_id: Some(b"test".to_vec()),
- priority: 123,
- call: Call::Logger(logger::Call::log(69, 1000)),
- maybe_periodic: Some((456u64, 10)),
- origin: root(),
- _phantom: PhantomData::<u64>::default(),
- }),
- ]
- )
- ]
- );
-
- assert_eq!(StorageVersion::get(), Releases::V2);
- });
- }
-
- #[test]
- fn test_migrate_origin() {
- new_test_ext().execute_with(|| {
- for i in 0..3u64 {
- let k = i.twox_64_concat();
- let old: Vec<Option<Scheduled<_, _, u32, u64>>> = vec![
- Some(Scheduled {
- maybe_id: None,
- priority: i as u8 + 10,
- call: Call::Logger(logger::Call::log(96, 100)),
- origin: 3u32,
- maybe_periodic: None,
- _phantom: Default::default(),
- }),
- None,
- Some(Scheduled {
- maybe_id: Some(b"test".to_vec()),
- priority: 123,
- origin: 2u32,
- call: Call::Logger(logger::Call::log(69, 1000)),
- maybe_periodic: Some((456u64, 10)),
- _phantom: Default::default(),
- }),
- ];
- frame_support::migration::put_storage_value(b"Scheduler", b"Agenda", &k, old);
- }
-
- impl From<u32> for OriginCaller {
- fn from(value: u32) -> Self {
- match value {
- 3 => system::RawOrigin::Root.into(),
- 2 => system::RawOrigin::None.into(),
- _ => unimplemented!(),
- }
- }
- }
-
- Scheduler::migrate_origin::<u32>();
-
- assert_eq_uvec!(
- Agenda::<Test>::iter().collect::<Vec<_>>(),
- vec![
- (
- 0,
- vec![
- Some(ScheduledV2::<_, _, OriginCaller, u64> {
- maybe_id: None,
- priority: 10,
- call: Call::Logger(logger::Call::log(96, 100)),
- maybe_periodic: None,
- origin: system::RawOrigin::Root.into(),
- _phantom: PhantomData::<u64>::default(),
- }),
- None,
- Some(ScheduledV2 {
- maybe_id: Some(b"test".to_vec()),
- priority: 123,
- call: Call::Logger(logger::Call::log(69, 1000)),
- maybe_periodic: Some((456u64, 10)),
- origin: system::RawOrigin::None.into(),
- _phantom: PhantomData::<u64>::default(),
- }),
- ]
- ),
- (
- 1,
- vec![
- Some(ScheduledV2 {
- maybe_id: None,
- priority: 11,
- call: Call::Logger(logger::Call::log(96, 100)),
- maybe_periodic: None,
- origin: system::RawOrigin::Root.into(),
- _phantom: PhantomData::<u64>::default(),
- }),
- None,
- Some(ScheduledV2 {
- maybe_id: Some(b"test".to_vec()),
- priority: 123,
- call: Call::Logger(logger::Call::log(69, 1000)),
- maybe_periodic: Some((456u64, 10)),
- origin: system::RawOrigin::None.into(),
- _phantom: PhantomData::<u64>::default(),
- }),
- ]
- ),
- (
- 2,
- vec![
- Some(ScheduledV2 {
- maybe_id: None,
- priority: 12,
- call: Call::Logger(logger::Call::log(96, 100)),
- maybe_periodic: None,
- origin: system::RawOrigin::Root.into(),
- _phantom: PhantomData::<u64>::default(),
- }),
- None,
- Some(ScheduledV2 {
- maybe_id: Some(b"test".to_vec()),
- priority: 123,
- call: Call::Logger(logger::Call::log(69, 1000)),
- maybe_periodic: Some((456u64, 10)),
- origin: system::RawOrigin::None.into(),
- _phantom: PhantomData::<u64>::default(),
- }),
- ]
- )
- ]
- );
- });
- }
}
primitives/nft/src/lib.rsdiffbeforeafterboth--- a/primitives/nft/src/lib.rs
+++ b/primitives/nft/src/lib.rs
@@ -144,6 +144,7 @@
pub limits: CollectionLimits<T::BlockNumber>, // Collection private restrictions
pub variable_on_chain_schema: Vec<u8>, //
pub const_on_chain_schema: Vec<u8>, //
+ pub transfers_enabled: bool,
}
#[derive(Encode, Decode, Debug, Clone, PartialEq)]