difftreelog
Fix all unit test execution
in: master
6 files changed
pallets/inflation/src/lib.rsdiffbeforeafterboth--- a/pallets/inflation/src/lib.rs
+++ b/pallets/inflation/src/lib.rs
@@ -46,7 +46,8 @@
pub type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
-pub const YEAR: u32 = 5_259_600;
+// pub const YEAR: u32 = 5_259_600; // 6-second block
+pub const YEAR: u32 = 2_629_800; // 12-second block
pub const TOTAL_YEARS_UNTIL_FLAT: u32 = 9;
pub const START_INFLATION_PERCENT: u32 = 10;
pub const END_INFLATION_PERCENT: u32 = 4;
pallets/inflation/src/tests.rsdiffbeforeafterboth--- a/pallets/inflation/src/tests.rs
+++ b/pallets/inflation/src/tests.rs
@@ -18,7 +18,7 @@
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
-const YEAR: u64 = 5_259_600;
+const YEAR: u64 = 2_629_800;
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
@@ -112,8 +112,8 @@
// first inflation deposit should be equal to BlockInflation
Inflation::on_initialize(1);
- // SBP M2 review: Verify expected block inflation for year 1
- assert_eq!(Inflation::block_inflation(), 1901);
+ // Expected 100-block inflation for year 1 is 100 * 100_000_000 / YEAR = 3803
+ assert_eq!(Inflation::block_inflation(), 3803);
assert_eq!(
Balances::free_balance(1234) - initial_issuance,
Inflation::block_inflation()
@@ -158,26 +158,21 @@
let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
assert_eq!(Balances::free_balance(1234), initial_issuance);
Inflation::on_initialize(1);
- let block_inflation_year_0 = Inflation::block_inflation();
- // SBP M2 review: go through all the block inflations for year 1,
+ // Go through all the block inflations for year 1,
// total issuance will be updated accordingly
for block in (100..YEAR).step_by(100) {
Inflation::on_initialize(block);
}
assert_eq!(
- initial_issuance + (1901 * (YEAR / 100)),
+ initial_issuance + (3803 * (YEAR / 100)),
<Balances as Currency<_>>::total_issuance()
);
Inflation::on_initialize(YEAR);
let block_inflation_year_1 = Inflation::block_inflation();
- // SBP M2 review: Verify expected block inflation for year 2
- assert_eq!(block_inflation_year_1, 1952);
-
- // SBP M2 review: this is actually not true
- // Assert that year 1 inflation is less than year 0
- // assert!(block_inflation_year_0 > block_inflation_year_1);
+ // Expected 100-block inflation for year 2: 100 * 9.33% * initial issuance * 110% / YEAR = 3904
+ assert_eq!(block_inflation_year_1, 3904);
});
}
pallets/nft/src/mock.rsdiffbeforeafterboth1#![allow(clippy::from_over_into)]23use crate as pallet_template;4use sp_core::H256;5use frame_support::{parameter_types, traits::Everything, weights::IdentityFee};6use sp_runtime::{7 traits::{BlakeTwo256, IdentityLookup},8 testing::Header,9};10use pallet_transaction_payment::{CurrencyAdapter};11use frame_system as system;12use pallet_evm::AddressMapping;13use pallet_common::account::{EvmBackwardsAddressMapping, CrossAccountId};14use codec::{Encode, Decode};15use scale_info::TypeInfo;1617type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;18type Block = frame_system::mocking::MockBlock<Test>;1920// Configure a mock runtime to test the pallet.21frame_support::construct_runtime!(22 pub enum Test where23 Block = Block,24 NodeBlock = Block,25 UncheckedExtrinsic = UncheckedExtrinsic,26 {27 System: frame_system::{Pallet, Call, Config, Storage, Event<T>},28 TemplateModule: pallet_template::{Pallet, Call, Storage},29 Balances: pallet_balances::{Pallet, Call, Storage},30 }31);3233parameter_types! {34 pub const BlockHashCount: u64 = 250;35 pub const SS58Prefix: u8 = 42;36}3738impl system::Config for Test {39 type BaseCallFilter = Everything;40 type BlockWeights = ();41 type BlockLength = ();42 type DbWeight = ();43 type Origin = Origin;44 type Call = Call;45 type Index = u64;46 type BlockNumber = u64;47 type Hash = H256;48 type Hashing = BlakeTwo256;49 type AccountId = u64;50 type Lookup = IdentityLookup<Self::AccountId>;51 type Header = Header;52 type Event = ();53 type BlockHashCount = BlockHashCount;54 type Version = ();55 type PalletInfo = PalletInfo;56 type AccountData = pallet_balances::AccountData<u64>;57 type OnNewAccount = ();58 type OnKilledAccount = ();59 type SystemWeightInfo = ();60 type SS58Prefix = SS58Prefix;61 type OnSetCode = ();62}6364parameter_types! {65 pub const ExistentialDeposit: u64 = 1;66 pub const MaxLocks: u32 = 50;67}68//frame_system::Module<Test>;69impl pallet_balances::Config for Test {70 type AccountStore = System;71 type Balance = u64;72 type DustRemoval = ();73 type Event = ();74 type ExistentialDeposit = ExistentialDeposit;75 type WeightInfo = ();76 type MaxLocks = MaxLocks;77 type MaxReserves = ();78 type ReserveIdentifier = [u8; 8];79}8081parameter_types! {82 pub const TransactionByteFee: u64 = 1;83 pub const OperationalFeeMultiplier: u8 = 5;84}8586impl pallet_transaction_payment::Config for Test {87 type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;88 type TransactionByteFee = TransactionByteFee;89 type WeightToFee = IdentityFee<u64>;90 type FeeMultiplierUpdate = ();91 type OperationalFeeMultiplier = OperationalFeeMultiplier;92}9394parameter_types! {95 pub const MinimumPeriod: u64 = 1;96}97impl pallet_timestamp::Config for Test {98 type Moment = u64;99 type OnTimestampSet = ();100 type MinimumPeriod = MinimumPeriod;101 type WeightInfo = ();102}103104parameter_types! {105 pub const CollectionCreationPrice: u32 = 0;106 pub TreasuryAccountId: u64 = 1234;107 pub EthereumChainId: u32 = 1111;108}109110pub struct TestEvmAddressMapping;111impl AddressMapping<u64> for TestEvmAddressMapping {112 fn into_account_id(_addr: sp_core::H160) -> u64 {113 unimplemented!()114 }115}116117pub struct TestEvmBackwardsAddressMapping;118impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {119 fn from_account_id(_account_id: u64) -> sp_core::H160 {120 unimplemented!()121 }122}123124#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo)]125pub struct TestCrossAccountId(u64, sp_core::H160);126impl CrossAccountId<u64> for TestCrossAccountId {127 fn as_sub(&self) -> &u64 {128 &self.0129 }130 fn as_eth(&self) -> &sp_core::H160 {131 &self.1132 }133 fn from_sub(sub: u64) -> Self {134 let mut eth = [0; 20];135 eth[12..20].copy_from_slice(&sub.to_be_bytes());136 Self(sub, sp_core::H160(eth))137 }138 fn from_eth(eth: sp_core::H160) -> Self {139 let mut sub_raw = [0; 8];140 sub_raw.copy_from_slice(ð.0[0..8]);141 let sub = u64::from_be_bytes(sub_raw);142 Self(sub, eth)143 }144 fn conv_eq(&self, other: &Self) -> bool {145 self.as_sub() == other.as_sub()146 }147}148149impl Default for TestCrossAccountId {150 fn default() -> Self {151 Self::from_sub(0)152 }153}154155156pub struct TestEtheremTransactionSender;157impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {158 fn submit_logs_transaction(159 _tx: pallet_ethereum::Transaction,160 _logs: Vec<pallet_ethereum::Log>,161 ) -> Result<(), sp_runtime::DispatchError> {162 Ok(())163 }164}165166impl pallet_evm_coder_substrate::Config for Test {167 type EthereumTransactionSender = TestEtheremTransactionSender;168}169170impl pallet_common::Config for Test {171 type Event = ();172 type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;173 type EvmAddressMapping = TestEvmAddressMapping;174 type CrossAccountId = TestCrossAccountId;175176 type Currency = Balances;177 type CollectionCreationPrice = CollectionCreationPrice;178 type TreasuryAccountId = TreasuryAccountId;179}180181impl pallet_fungible::Config for Test {182 type WeightInfo = ();183}184impl pallet_refungible::Config for Test {185 type WeightInfo = ();186}187impl pallet_nonfungible::Config for Test {188 type WeightInfo = ();189}190191impl pallet_template::Config for Test {192 type WeightInfo = ();193}194195// Build genesis storage according to the mock runtime.196pub fn new_test_ext() -> sp_io::TestExternalities {197 system::GenesisConfig::default()198 .build_storage::<Test>()199 .unwrap()200 .into()201}1#![allow(clippy::from_over_into)]23use crate as pallet_template;4use sp_core::H256;5use frame_support::{parameter_types, traits::Everything, weights::IdentityFee};6use sp_runtime::{7 traits::{BlakeTwo256, IdentityLookup},8 testing::Header,9};10use pallet_transaction_payment::{CurrencyAdapter};11use frame_system as system;12use pallet_evm::AddressMapping;13use pallet_common::account::{EvmBackwardsAddressMapping, CrossAccountId};14use codec::{Encode, Decode};15use scale_info::TypeInfo;1617type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;18type Block = frame_system::mocking::MockBlock<Test>;1920// Configure a mock runtime to test the pallet.21frame_support::construct_runtime!(22 pub enum Test where23 Block = Block,24 NodeBlock = Block,25 UncheckedExtrinsic = UncheckedExtrinsic,26 {27 System: frame_system::{Pallet, Call, Config, Storage, Event<T>},28 TemplateModule: pallet_template::{Pallet, Call, Storage},29 Balances: pallet_balances::{Pallet, Call, Storage},30 Common: pallet_common::{Pallet, Storage, Event<T>},31 Fungible: pallet_fungible::{Pallet, Storage},32 Refungible: pallet_refungible::{Pallet, Storage},33 Nonfungible: pallet_nonfungible::{Pallet, Storage},34 }35);3637parameter_types! {38 pub const BlockHashCount: u64 = 250;39 pub const SS58Prefix: u8 = 42;40}4142impl system::Config for Test {43 type BaseCallFilter = Everything;44 type BlockWeights = ();45 type BlockLength = ();46 type DbWeight = ();47 type Origin = Origin;48 type Call = Call;49 type Index = u64;50 type BlockNumber = u64;51 type Hash = H256;52 type Hashing = BlakeTwo256;53 type AccountId = u64;54 type Lookup = IdentityLookup<Self::AccountId>;55 type Header = Header;56 type Event = ();57 type BlockHashCount = BlockHashCount;58 type Version = ();59 type PalletInfo = PalletInfo;60 type AccountData = pallet_balances::AccountData<u64>;61 type OnNewAccount = ();62 type OnKilledAccount = ();63 type SystemWeightInfo = ();64 type SS58Prefix = SS58Prefix;65 type OnSetCode = ();66}6768parameter_types! {69 pub const ExistentialDeposit: u64 = 1;70 pub const MaxLocks: u32 = 50;71}72//frame_system::Module<Test>;73impl pallet_balances::Config for Test {74 type AccountStore = System;75 type Balance = u64;76 type DustRemoval = ();77 type Event = ();78 type ExistentialDeposit = ExistentialDeposit;79 type WeightInfo = ();80 type MaxLocks = MaxLocks;81 type MaxReserves = ();82 type ReserveIdentifier = [u8; 8];83}8485parameter_types! {86 pub const TransactionByteFee: u64 = 1;87 pub const OperationalFeeMultiplier: u8 = 5;88}8990impl pallet_transaction_payment::Config for Test {91 type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;92 type TransactionByteFee = TransactionByteFee;93 type WeightToFee = IdentityFee<u64>;94 type FeeMultiplierUpdate = ();95 type OperationalFeeMultiplier = OperationalFeeMultiplier;96}9798parameter_types! {99 pub const MinimumPeriod: u64 = 1;100}101impl pallet_timestamp::Config for Test {102 type Moment = u64;103 type OnTimestampSet = ();104 type MinimumPeriod = MinimumPeriod;105 type WeightInfo = ();106}107108parameter_types! {109 pub const CollectionCreationPrice: u32 = 0;110 pub TreasuryAccountId: u64 = 1234;111 pub EthereumChainId: u32 = 1111;112}113114pub struct TestEvmAddressMapping;115impl AddressMapping<u64> for TestEvmAddressMapping {116 fn into_account_id(_addr: sp_core::H160) -> u64 {117 unimplemented!()118 }119}120121pub struct TestEvmBackwardsAddressMapping;122impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {123 fn from_account_id(_account_id: u64) -> sp_core::H160 {124 unimplemented!()125 }126}127128#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo)]129pub struct TestCrossAccountId(u64, sp_core::H160);130impl CrossAccountId<u64> for TestCrossAccountId {131 fn as_sub(&self) -> &u64 {132 &self.0133 }134 fn as_eth(&self) -> &sp_core::H160 {135 &self.1136 }137 fn from_sub(sub: u64) -> Self {138 let mut eth = [0; 20];139 eth[12..20].copy_from_slice(&sub.to_be_bytes());140 Self(sub, sp_core::H160(eth))141 }142 fn from_eth(eth: sp_core::H160) -> Self {143 let mut sub_raw = [0; 8];144 sub_raw.copy_from_slice(ð.0[0..8]);145 let sub = u64::from_be_bytes(sub_raw);146 Self(sub, eth)147 }148 fn conv_eq(&self, other: &Self) -> bool {149 self.as_sub() == other.as_sub()150 }151}152153impl Default for TestCrossAccountId {154 fn default() -> Self {155 Self::from_sub(0)156 }157}158159pub struct TestEtheremTransactionSender;160impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {161 fn submit_logs_transaction(162 _tx: pallet_ethereum::Transaction,163 _logs: Vec<pallet_ethereum::Log>,164 ) -> Result<(), sp_runtime::DispatchError> {165 Ok(())166 }167}168169impl pallet_evm_coder_substrate::Config for Test {170 type EthereumTransactionSender = TestEtheremTransactionSender;171}172173impl pallet_common::Config for Test {174 type Event = ();175 type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;176 type EvmAddressMapping = TestEvmAddressMapping;177 type CrossAccountId = TestCrossAccountId;178179 type Currency = Balances;180 type CollectionCreationPrice = CollectionCreationPrice;181 type TreasuryAccountId = TreasuryAccountId;182}183184impl pallet_fungible::Config for Test {185 type WeightInfo = ();186}187impl pallet_refungible::Config for Test {188 type WeightInfo = ();189}190impl pallet_nonfungible::Config for Test {191 type WeightInfo = ();192}193194impl pallet_template::Config for Test {195 type WeightInfo = ();196}197198// Build genesis storage according to the mock runtime.199pub fn new_test_ext() -> sp_io::TestExternalities {200 system::GenesisConfig::default()201 .build_storage::<Test>()202 .unwrap()203 .into()204}pallets/nft/src/tests.rsdiffbeforeafterboth--- a/pallets/nft/src/tests.rs
+++ b/pallets/nft/src/tests.rs
@@ -3,10 +3,9 @@
use crate::mock::*;
use crate::{AccessMode, CollectionMode};
use nft_data_structs::{
- COLLECTION_NUMBER_LIMIT, Collection, CollectionId, CreateItemData, CreateFungibleData,
- CreateNftData, CreateReFungibleData, ExistenceRequirement, MAX_COLLECTION_DESCRIPTION_LENGTH,
- MAX_COLLECTION_NAME_LENGTH, MAX_DECIMAL_POINTS, MAX_TOKEN_PREFIX_LENGTH, COLLECTION_ADMINS_LIMIT,
- MetaUpdatePermission, Pays, PostDispatchInfo, TokenId, Weight, WithdrawReasons,
+ COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData,
+ CreateNftData, CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT,
+ MetaUpdatePermission, TokenId,
};
use frame_support::{assert_noop, assert_ok};
@@ -213,7 +212,7 @@
.collect()
));
for (index, data) in items_data.into_iter().enumerate() {
- let item = <pallet_nonfungible::TokenData<Test>>::get((CollectionId(1), TokenId((index + 1) as u32))).unwrap();
+ let item = <pallet_refungible::TokenData<Test>>::get((CollectionId(1), TokenId((index + 1) as u32)));
let balance = <pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));
assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());
assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());
@@ -274,7 +273,7 @@
assert_eq!(<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))), 5);
// change owner scenario
- assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 5));
+ assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(0), 5));
assert_eq!(<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))), 0);
// split item scenario
@@ -282,12 +281,12 @@
origin2.clone(),
account(3),
CollectionId(1),
- TokenId(1),
+ TokenId(0),
3
));
// split item and new owner has account scenario
- assert_ok!(TemplateModule::transfer(origin2, account(3), CollectionId(1), TokenId(1), 1));
+ assert_ok!(TemplateModule::transfer(origin2, account(3), CollectionId(1), TokenId(0), 1));
assert_eq!(<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))), 1);
assert_eq!(<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))), 4);
});
@@ -298,33 +297,27 @@
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
+ // Create RFT 1 in 1023 pieces for account 1
let data = default_re_fungible_data();
create_test_item(collection_id, &data.clone().into());
+ let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));
+ assert_eq!(item.const_data, data.const_data.into_inner());
+ assert_eq!(item.variable_data, data.variable_data.into_inner());
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
+ assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))), 1023);
+ assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
+ // Account 1 transfers all 1023 pieces of RFT 1 to account 2
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
- {
- let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));
- let balance = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));
- assert_eq!(item.const_data, data.const_data.into_inner());
- assert_eq!(item.variable_data, data.variable_data.into_inner());
- assert_eq!(balance, 1023);
- }
-
- assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1023);
- assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
-
- // change owner scenario
assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1023));
-
- let balance2 = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2)));
- assert_eq!(balance2, 1023);
+ assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))), 1023);
assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);
- assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))), 1023);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))), 1);
assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), false);
assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);
- // split item scenario
+ // Account 2 transfers 500 pieces of RFT 1 to account 3
assert_ok!(TemplateModule::transfer(
origin2.clone(),
account(3),
@@ -332,29 +325,19 @@
TokenId(1),
500
));
- {
- let item = <pallet_refungible::TokenData<Test>>::get((CollectionId(1), TokenId(1)));
- let balance2 = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2)));
- let balance3 = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3)));
- assert_eq!(balance2, 523);
- assert_eq!(balance3, 500);
- }
- assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))), 523);
- assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))), 500);
+ assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))), 523);
+ assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))), 500);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))), 1);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))), 1);
assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);
assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))), true);
- // split item and new owner has account scenario
+ // Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance
assert_ok!(TemplateModule::transfer(origin2, account(3), CollectionId(1), TokenId(1), 200));
- {
- let item = <pallet_refungible::TokenData<Test>>::get((CollectionId(1), TokenId(1)));
- let balance2 = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2)));
- let balance3 = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3)));
- assert_eq!(balance2, 323);
- assert_eq!(balance3, 700);
- }
- assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))), 323);
- assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))), 700);
+ assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))), 323);
+ assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))), 700);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))), 1);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))), 1);
assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);
assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))), true);
});
@@ -373,7 +356,7 @@
let origin1 = Origin::signed(1);
// default scenario
- assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1000));
+ assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1));
assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);
assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))), 1);
assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), false);
@@ -382,6 +365,45 @@
}
#[test]
+fn transfer_nft_item_wrong_value() {
+ new_test_ext().execute_with(|| {
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
+
+ let data = default_nft_data();
+ create_test_item(collection_id, &data.into());
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
+ assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
+
+ let origin1 = Origin::signed(1);
+
+ assert_noop!(
+ TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2).map_err(|e| e.error),
+ <pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount
+ );
+ });
+}
+
+#[test]
+fn transfer_nft_item_zero_value() {
+ new_test_ext().execute_with(|| {
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
+
+ let data = default_nft_data();
+ create_test_item(collection_id, &data.into());
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
+ assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
+
+ let origin1 = Origin::signed(1);
+
+ // Transferring 0 amount works on NFT...
+ assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 0));
+ // ... and results in no transfer
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
+ assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
+ });
+}
+
+#[test]
fn nft_approve_and_transfer_from() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
@@ -395,14 +417,14 @@
assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
- // neg transfer
+ // neg transfer_from
assert_noop!(
- TemplateModule::transfer_from(origin2.clone(), account(1), account(2), CollectionId(1), TokenId(1), 1),
- CommonError::<Test>::NoPermission
+ TemplateModule::transfer_from(origin2.clone(), account(1), account(2), CollectionId(1), TokenId(1), 1).map_err(|e| e.error),
+ CommonError::<Test>::TokenValueNotEnough
);
// do approve
- assert_ok!(TemplateModule::approve(origin1, account(2), CollectionId(1), TokenId(1), 5));
+ assert_ok!(TemplateModule::approve(origin1, account(2), CollectionId(1), TokenId(1), 1));
assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(2));
assert_ok!(TemplateModule::transfer_from(
@@ -425,9 +447,9 @@
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
+ // Create NFT 1 for account 1
let data = default_nft_data();
create_test_item(collection_id, &data.clone().into());
-
assert_eq!(
&<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1))).unwrap().const_data,
&data.const_data.into_inner()
@@ -435,6 +457,7 @@
assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
+ // Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list
assert_ok!(TemplateModule::set_mint_permission(
origin1.clone(),
CollectionId(1),
@@ -461,18 +484,17 @@
account(3)
));
- // do approve
+ // Account 1 approves account 2 for NFT 1
assert_ok!(TemplateModule::approve(
origin1.clone(),
account(2),
CollectionId(1),
TokenId(1),
- 5
+ 1
));
assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(2));
- assert_ok!(TemplateModule::approve(origin1, account(3), CollectionId(1), TokenId(1), 5));
- assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(3));
+ // Account 2 transfers NFT 1 from account 1 to account 3
assert_ok!(TemplateModule::transfer_from(
origin2,
account(1),
@@ -493,12 +515,15 @@
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
+ // Create RFT 1 in 1023 pieces for account 1
let data = default_re_fungible_data();
create_test_item(collection_id, &data.into());
- assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1023);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
+ assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))), 1023);
assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
+ // Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list
assert_ok!(TemplateModule::set_mint_permission(
origin1.clone(),
CollectionId(1),
@@ -525,10 +550,11 @@
account(3)
));
- // do approve
+ // Account 1 approves account 2 for 1023 pieces of RFT 1
assert_ok!(TemplateModule::approve(origin1, account(2), CollectionId(1), TokenId(1), 1023));
assert_eq!(<pallet_refungible::Allowance<Test>>::get((CollectionId(1), TokenId(1), account(1), account(2))), 1023);
+ // Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3
assert_ok!(TemplateModule::transfer_from(
origin2,
account(1),
@@ -537,10 +563,12 @@
TokenId(1),
100
));
- assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 923);
- assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))), 100);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))), 1);
+ assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))), 923);
+ assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))), 100);
+ assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
- assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(3))), true);
assert_eq!(<pallet_refungible::Allowance<Test>>::get((CollectionId(1), TokenId(1), account(1), account(2))), 923);
});
}
@@ -587,11 +615,11 @@
origin1.clone(),
account(2),
CollectionId(1),
- TokenId(1),
+ TokenId(0),
5
));
assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))), 5);
- assert_ok!(TemplateModule::approve(origin1, account(3), CollectionId(1), TokenId(1), 5));
+ assert_ok!(TemplateModule::approve(origin1, account(3), CollectionId(1), TokenId(0), 5));
assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))), 5);
assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))), 5);
@@ -600,15 +628,15 @@
account(1),
account(3),
CollectionId(1),
- TokenId(1),
+ TokenId(0),
4
));
assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))), 1);
assert_noop!(
- TemplateModule::transfer_from(origin2, account(1), account(3), CollectionId(1), TokenId(1), 4),
- CommonError::<Test>::NoPermission
+ TemplateModule::transfer_from(origin2, account(1), account(3), CollectionId(1), TokenId(0), 4).map_err(|e| e.error),
+ CommonError::<Test>::TokenValueNotEnough
);
});
}
@@ -647,17 +675,36 @@
let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
- assert_ok!(TemplateModule::add_collection_admin(
+
+ let data = default_nft_data();
+ create_test_item(collection_id, &data.into());
+
+ // check balance (collection with id = 1, user id = 1)
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
+
+ // burn item
+ assert_ok!(TemplateModule::burn_item(
origin1.clone(),
collection_id,
- account(2)
+ TokenId(1),
+ 1
));
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);
+ });
+}
+
+#[test]
+fn burn_same_nft_item_twice() {
+ new_test_ext().execute_with(|| {
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
+
+ let origin1 = Origin::signed(1);
let data = default_nft_data();
create_test_item(collection_id, &data.into());
// check balance (collection with id = 1, user id = 1)
- assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
// burn item
assert_ok!(TemplateModule::burn_item(
@@ -666,12 +713,14 @@
TokenId(1),
1
));
+
+ // burn item again
assert_noop!(
- TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1),
+ TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error),
CommonError::<Test>::TokenNotFound
);
- assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);
});
}
@@ -694,10 +743,10 @@
assert_eq!(<pallet_fungible::Balance<Test>>::get((collection_id, account(1))), 5);
// burn item
- assert_ok!(TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 5));
+ assert_ok!(TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(0), 5));
assert_noop!(
- TemplateModule::burn_item(origin1, CollectionId(1), TokenId(1), 5),
- CommonError::<Test>::TokenValueNotEnough
+ TemplateModule::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error),
+ CommonError::<Test>::TokenValueTooLow
);
assert_eq!(<pallet_fungible::Balance<Test>>::get((collection_id, account(1))), 0);
@@ -705,6 +754,31 @@
}
#[test]
+fn burn_fungible_item_with_token_id() {
+ new_test_ext().execute_with(|| {
+ let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
+
+ let origin1 = Origin::signed(1);
+ assert_ok!(TemplateModule::add_collection_admin(
+ origin1.clone(),
+ collection_id,
+ account(2)
+ ));
+
+ let data = default_fungible_data();
+ create_test_item(collection_id, &data.into());
+
+ // check balance (collection with id = 1, user id = 1)
+ assert_eq!(<pallet_fungible::Balance<Test>>::get((collection_id, account(1))), 5);
+
+ // Try to burn item using Token ID
+ assert_noop!(
+ TemplateModule::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),
+ <pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId
+ );
+ });
+}
+#[test]
fn burn_refungible_item() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
@@ -736,14 +810,14 @@
create_test_item(collection_id, &data.into());
// check balance (collection with id = 1, user id = 2)
- assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1023);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))), 1023);
// burn item
assert_ok!(TemplateModule::burn_item(origin1.clone(), collection_id, TokenId(1), 1023));
assert_noop!(
- TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1023),
- CommonError::<Test>::TokenNotFound
+ TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1023).map_err(|e| e.error),
+ CommonError::<Test>::TokenValueTooLow
);
assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))), 0);
@@ -754,12 +828,9 @@
fn add_collection_admin() {
new_test_ext().execute_with(|| {
let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
- create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(2));
- create_test_collection_for_owner(&CollectionMode::NFT, 3, CollectionId(3));
-
let origin1 = Origin::signed(1);
- // collection admin
+ // Add collection admins
assert_ok!(TemplateModule::add_collection_admin(
origin1.clone(),
collection1_id,
@@ -771,7 +842,8 @@
account(3)
));
- assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))));
+ // Owner is not an admin by default
+ assert_eq!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))), false);
assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(2))));
assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))));
});
@@ -781,13 +853,10 @@
fn remove_collection_admin() {
new_test_ext().execute_with(|| {
let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
- create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(2));
- create_test_collection_for_owner(&CollectionMode::NFT, 3, CollectionId(3));
-
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
- // collection admin
+ // Add collection admins 2 and 3
assert_ok!(TemplateModule::add_collection_admin(
origin1.clone(),
collection1_id,
@@ -802,14 +871,16 @@
assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(2))));
assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))));
- // remove admin
+ // remove admin 3
assert_ok!(TemplateModule::remove_collection_admin(
origin2,
CollectionId(1),
account(3)
));
- assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))));
- assert_eq!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(2))), false);
+
+ // 2 is still admin, 3 is not an admin anymore
+ assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(2))));
+ assert_eq!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))), false);
});
}
@@ -837,10 +908,10 @@
// check balance (collection with id = 1, user id = 1)
assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))), 1);
assert_eq!(<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))), 5);
- assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))), 1023);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))), 1);
assert_eq!(<pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))), true);
- assert_eq!(<pallet_refungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))), true);
+ assert_eq!(<pallet_refungible::Owned<Test>>::get((re_fungible_collection_id, account(1), TokenId(1))), true);
});
}
@@ -1037,7 +1108,7 @@
collection_id,
account(2)
));
- assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));
+ assert_eq!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))), false);
});
}
@@ -1048,23 +1119,27 @@
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
+ // Owner adds admin
assert_ok!(TemplateModule::add_collection_admin(
origin1.clone(),
collection_id,
account(2)
));
+ // Owner adds address 3 to allow list
assert_ok!(TemplateModule::add_to_allow_list(
origin1,
collection_id,
account(3)
));
+
+ // Admin removes address 3 from allow list
assert_ok!(TemplateModule::remove_from_allow_list(
origin2,
collection_id,
account(3)
));
- assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(3))));
+ assert_eq!(<pallet_common::Allowlist<Test>>::get((collection_id, account(3))), false);
});
}
@@ -1107,17 +1182,27 @@
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
+ // Add account 2 to allow list
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
collection_id,
account(2)
));
+
+ // Account 2 is in collection allow-list
+ assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));
+
+ // Destroy collection
assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));
+
+ // Attempt to remove account 2 from collection allow-list => error
assert_noop!(
TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),
CommonError::<Test>::CollectionNotFound
);
- assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));
+
+ // Account 2 is not found in collection allow-list anyway
+ assert_eq!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))), false);
});
}
@@ -1138,12 +1223,13 @@
collection_id,
account(2)
));
+ assert_eq!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))), false);
assert_ok!(TemplateModule::remove_from_allow_list(
origin1,
collection_id,
account(2)
));
- assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));
+ assert_eq!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))), false);
});
}
@@ -1170,7 +1256,7 @@
));
assert_noop!(
- TemplateModule::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1),
+ TemplateModule::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1).map_err(|e| e.error),
CommonError::<Test>::AddressNotInAllowlist
);
});
@@ -1218,7 +1304,7 @@
));
assert_noop!(
- TemplateModule::transfer_from(origin1, account(1), account(3), CollectionId(1), TokenId(1), 1),
+ TemplateModule::transfer_from(origin1, account(1), account(3), CollectionId(1), TokenId(1), 1).map_err(|e| e.error),
CommonError::<Test>::AddressNotInAllowlist
);
});
@@ -1247,7 +1333,7 @@
));
assert_noop!(
- TemplateModule::transfer(origin1, account(3), collection_id, TokenId(1), 1),
+ TemplateModule::transfer(origin1, account(3), collection_id, TokenId(1), 1).map_err(|e| e.error),
CommonError::<Test>::AddressNotInAllowlist
);
});
@@ -1296,7 +1382,7 @@
));
assert_noop!(
- TemplateModule::transfer_from(origin1, account(1), account(3), collection_id, TokenId(1), 1),
+ TemplateModule::transfer_from(origin1, account(1), account(3), collection_id, TokenId(1), 1).map_err(|e| e.error),
CommonError::<Test>::AddressNotInAllowlist
);
});
@@ -1319,7 +1405,7 @@
AccessMode::AllowList
));
assert_noop!(
- TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 5),
+ TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1).map_err(|e| e.error),
CommonError::<Test>::AddressNotInAllowlist
);
});
@@ -1344,7 +1430,7 @@
// do approve
assert_noop!(
- TemplateModule::approve(origin1, account(1), CollectionId(1), TokenId(1), 5),
+ TemplateModule::approve(origin1, account(1), CollectionId(1), TokenId(1), 1).map_err(|e| e.error),
CommonError::<Test>::AddressNotInAllowlist
);
});
@@ -1387,11 +1473,13 @@
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
+ // Create NFT for account 1
let data = default_nft_data();
create_test_item(collection_id, &data.into());
let origin1 = Origin::signed(1);
+ // Toggle Allow List mode and add accounts 1 and 2
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
collection_id,
@@ -1408,16 +1496,17 @@
account(2)
));
- // do approve
+ // Sself-approve account 1 for NFT 1
assert_ok!(TemplateModule::approve(
origin1.clone(),
account(1),
CollectionId(1),
TokenId(1),
- 5
+ 1
));
assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(1));
+ // Transfer from 1 to 2
assert_ok!(TemplateModule::transfer_from(
origin1,
account(1),
@@ -1513,7 +1602,7 @@
));
assert_noop!(
- TemplateModule::create_item(origin2, CollectionId(1), account(2), default_nft_data().into()),
+ TemplateModule::create_item(origin2, CollectionId(1), account(2), default_nft_data().into()).map_err(|e| e.error),
CommonError::<Test>::PublicMintingNotAllowed
);
});
@@ -1540,7 +1629,7 @@
));
assert_noop!(
- TemplateModule::create_item(origin2, CollectionId(1), account(2), default_nft_data().into()),
+ TemplateModule::create_item(origin2, CollectionId(1), account(2), default_nft_data().into()).map_err(|e| e.error),
CommonError::<Test>::PublicMintingNotAllowed
);
});
@@ -1626,7 +1715,7 @@
));
assert_noop!(
- TemplateModule::create_item(origin2, collection_id, account(2), default_nft_data().into()),
+ TemplateModule::create_item(origin2, collection_id, account(2), default_nft_data().into()).map_err(|e| e.error),
CommonError::<Test>::AddressNotInAllowlist
);
});
@@ -1674,14 +1763,23 @@
});
}
-// Total number of collections. Negotive test
#[test]
+fn create_max_collections() {
+ new_test_ext().execute_with(|| {
+ for i in 1..=COLLECTION_NUMBER_LIMIT {
+ create_test_collection(&CollectionMode::NFT, CollectionId(i));
+ }
+ });
+}
+
+// Total number of collections. Negative test
+#[test]
fn total_number_collections_bound_neg() {
new_test_ext().execute_with(|| {
let origin1 = Origin::signed(1);
- for i in 0..COLLECTION_NUMBER_LIMIT {
- create_test_collection(&CollectionMode::NFT, CollectionId(i + 1));
+ for i in 1..=COLLECTION_NUMBER_LIMIT {
+ create_test_collection(&CollectionMode::NFT, CollectionId(i));
}
let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
@@ -1722,14 +1820,14 @@
let origin1 = Origin::signed(1);
- for _ in 0..MAX_TOKEN_OWNERSHIP {
+ for _ in 1..=MAX_TOKEN_OWNERSHIP {
let data = default_nft_data();
create_test_item(collection_id, &data.clone().into());
}
let data = default_nft_data();
assert_noop!(
- TemplateModule::create_item(origin1, CollectionId(1), account(1), data.into()),
+ TemplateModule::create_item(origin1, CollectionId(1), account(1), data.into()).map_err(|e| e.error),
CommonError::<Test>::AccountTokenLimitExceeded
);
});
@@ -1902,13 +2000,31 @@
let variable_data = b"test data".to_vec();
assert_noop!(
- TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(1), variable_data),
+ TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(0), variable_data).map_err(|e| e.error),
<pallet_fungible::Error<Test>>::FungibleItemsDontHaveData
);
});
}
#[test]
+fn set_variable_meta_data_on_fungible_token_with_token_id_fails() {
+ new_test_ext().execute_with(|| {
+ let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
+
+ let origin1 = Origin::signed(1);
+
+ let data = default_fungible_data();
+ create_test_item(collection_id, &data.into());
+
+ let variable_data = b"test data".to_vec();
+ assert_noop!(
+ TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(1), variable_data).map_err(|e| e.error),
+ <pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId
+ );
+ });
+}
+
+#[test]
fn set_variable_meta_data_on_nft_token_fails_for_big_data() {
new_test_ext().execute_with(|| {
let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
@@ -1920,7 +2036,7 @@
let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();
assert_noop!(
- TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(1), variable_data),
+ TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(1), variable_data).map_err(|e| e.error),
CommonError::<Test>::TokenVariableDataLimitExceeded
);
});
@@ -1938,7 +2054,7 @@
let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();
assert_noop!(
- TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(1), variable_data),
+ TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(1), variable_data).map_err(|e| e.error),
CommonError::<Test>::TokenVariableDataLimitExceeded
);
});
@@ -2013,7 +2129,7 @@
collection_id,
TokenId(1),
variable_data.clone()
- ),
+ ).map_err(|e| e.error),
CommonError::<Test>::TokenVariableDataLimitExceeded
);
})
@@ -2035,7 +2151,7 @@
let origin1 = Origin::signed(1);
// default scenario
- assert_ok!(TemplateModule::transfer(origin1, account(2), collection_id, TokenId(1), 1000));
+ assert_ok!(TemplateModule::transfer(origin1, account(2), collection_id, TokenId(1), 1));
assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), false);
assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);
assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);
@@ -2133,7 +2249,7 @@
collection_id,
TokenId(1),
variable_data.clone()
- ),
+ ).map_err(|e| e.error),
CommonError::<Test>::NoPermission
);
});
@@ -2188,7 +2304,7 @@
collection_id,
TokenId(1),
variable_data.clone()
- ),
+ ).map_err(|e| e.error),
CommonError::<Test>::NoPermission
);
});
@@ -2213,7 +2329,7 @@
// default scenario
assert_noop!(
- TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1000),
+ TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1).map_err(|e| e.error),
CommonError::<Test>::TransferNotAllowed
);
assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
pallets/scheduler/src/lib.rsdiffbeforeafterboth--- a/pallets/scheduler/src/lib.rs
+++ b/pallets/scheduler/src/lib.rs
@@ -795,8 +795,8 @@
use super::*;
use frame_support::{
- Hashable, assert_err, assert_noop, assert_ok, ord_parameter_types, parameter_types,
- traits::{Contains, OnFinalize, OnInitialize},
+ ord_parameter_types, parameter_types,
+ traits::Contains,
weights::constants::RocksDbWeight,
};
use sp_core::H256;
@@ -806,7 +806,6 @@
traits::{BlakeTwo256, IdentityLookup},
};
use frame_system::{EnsureOneOf, EnsureRoot, EnsureSignedBy};
- use substrate_test_utils::assert_eq_uvec;
use crate as scheduler;
mod logger {
@@ -815,9 +814,6 @@
thread_local! {
static LOG: RefCell<Vec<(OriginCaller, u32)>> = RefCell::new(Vec::new());
- }
- pub fn log() -> Vec<(OriginCaller, u32)> {
- LOG.with(|log| log.borrow().clone())
}
pub trait Config: system::Config {
type Event: From<Event> + Into<<Self as system::Config>::Event>;
@@ -928,24 +924,5 @@
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type WeightInfo = ();
type SponsorshipHandler = ();
- }
-
- pub fn new_test_ext() -> sp_io::TestExternalities {
- let t = system::GenesisConfig::default()
- .build_storage::<Test>()
- .unwrap();
- t.into()
- }
-
- fn run_to_block(n: u64) {
- while System::block_number() < n {
- Scheduler::on_finalize(System::block_number());
- System::set_block_number(System::block_number() + 1);
- Scheduler::on_initialize(System::block_number());
- }
- }
-
- fn root() -> OriginCaller {
- system::RawOrigin::Root.into()
}
}
primitives/nft/src/lib.rsdiffbeforeafterboth--- a/primitives/nft/src/lib.rs
+++ b/primitives/nft/src/lib.rs
@@ -29,10 +29,14 @@
pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;
pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;
pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;
-pub const MAX_TOKEN_OWNERSHIP: u32 = 10_000_000;
+pub const MAX_TOKEN_OWNERSHIP: u32 = if cfg!(not(feature = "limit-testing")) {
+ 10_000_000
+} else {
+ 10
+};
pub const COLLECTION_NUMBER_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {
- 100000
+ 100_000
} else {
10
};
@@ -44,7 +48,7 @@
pub const COLLECTION_ADMINS_LIMIT: u32 = 5;
pub const COLLECTION_TOKEN_LIMIT: u32 = u32::MAX;
pub const ACCOUNT_TOKEN_OWNERSHIP_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {
- 1000000
+ 1_000_000
} else {
10
};