difftreelog
Merge pull request #15 from usetech-llc/fix/nftpar-150
in: master
Unit tests repaired
3 files changed
pallets/nft/Cargo.tomldiffbeforeafterboth--- a/pallets/nft/Cargo.toml
+++ b/pallets/nft/Cargo.toml
@@ -80,6 +80,27 @@
branch = 'v2.0.0_release'
version = '2.0.0'
+[dependencies.pallet-balances]
+default-features = false
+git = 'https://github.com/usetech-llc/substrate.git'
+package = 'pallet-balances'
+branch = 'v2.0.0_release'
+version = '2.0.0'
+
+[dependencies.pallet-timestamp]
+default-features = false
+git = 'https://github.com/usetech-llc/substrate.git'
+package = 'pallet-timestamp'
+branch = 'v2.0.0_release'
+version = '2.0.0'
+
+[dependencies.pallet-randomness-collective-flip]
+default-features = false
+git = 'https://github.com/usetech-llc/substrate.git'
+package = 'pallet-randomness-collective-flip'
+branch = 'v2.0.0_release'
+version = '2.0.0'
+
[features]
default = ['std']
std = [
@@ -87,6 +108,9 @@
"serde/std",
'frame-support/std',
'frame-system/std',
+ 'pallet-balances/std',
+ 'pallet-timestamp/std',
+ 'pallet-randomness-collective-flip/std',
'sp-std/std',
'sp-runtime/std',
'frame-benchmarking/std',
pallets/nft/src/mock.rsdiffbeforeafterboth1// Creating mock runtime here23use crate::{Module, Trait};4use frame_support::{5 impl_outer_origin, parameter_types,6 weights::{7 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight},8 Weight,9 },10};11use frame_system as system;12use sp_core::H256;13use sp_runtime::{14 testing::Header,15 traits::{BlakeTwo256, IdentityLookup, Saturating},16 Perbill,17};1819impl_outer_origin! {20 pub enum Origin for Test {}21}2223// For testing the pallet, we construct most of a mock runtime. This means24// first constructing a configuration type (`Test`) which `impl`s each of the25// configuration traits of pallets we want to use.26#[derive(Clone, Eq, PartialEq)]27pub struct Test;28parameter_types! {29 pub const BlockHashCount: u64 = 250;30 pub const MaximumBlockWeight: Weight = 1024;31 pub const MaximumBlockLength: u32 = 2 * 1024;32 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);33 pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()34 .saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();35}3637impl system::Trait for Test {38 type BaseCallFilter = ();39 type Origin = Origin;40 type Call = ();41 type Index = u64;42 type BlockNumber = u64;43 type Hash = H256;44 type Hashing = BlakeTwo256;45 type AccountId = u64;46 type Lookup = IdentityLookup<Self::AccountId>;47 type Header = Header;48 type Event = ();49 type BlockHashCount = BlockHashCount;50 type MaximumBlockWeight = MaximumBlockWeight;51 type DbWeight = ();52 type BlockExecutionWeight = ();53 type ExtrinsicBaseWeight = ();54 type MaximumExtrinsicWeight = MaximumBlockWeight;55 type MaximumBlockLength = MaximumBlockLength;56 type AvailableBlockRatio = AvailableBlockRatio;57 type Version = ();58 type PalletInfo = ();59 type AccountData = ();60 type OnNewAccount = ();61 type OnKilledAccount = ();62 type SystemWeightInfo = ();63}64impl Trait for Test {65 type Event = ();66}67pub type TemplateModule = Module<Test>;686970// This function basically just builds a genesis storage key/value store according to71// our desired mockup.72pub fn new_test_ext() -> sp_io::TestExternalities {73 system::GenesisConfig::default()74 .build_storage::<Test>()75 .unwrap()76 .into()77}pallets/nft/src/tests.rsdiffbeforeafterboth--- a/pallets/nft/src/tests.rs
+++ b/pallets/nft/src/tests.rs
@@ -394,6 +394,77 @@
assert_eq!(TemplateModule::balance_count(1, 1), 1);
assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ // neg transfer
+ assert_noop!(TemplateModule::transfer_from(
+ origin2.clone(),
+ 1,
+ 2,
+ 1,
+ 1,
+ 1), "Only item owner, collection owner and admins can modify items");
+
+ // do approve
+ assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));
+ assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 1);
+ assert_eq!(
+ TemplateModule::approved(1, (1, 1))[0],
+ ApprovePermissions {
+ approved: 2,
+ amount: 100000000
+ }
+ );
+
+ assert_ok!(TemplateModule::transfer_from(
+ origin2.clone(),
+ 1,
+ 2,
+ 1,
+ 1,
+ 1
+ ));
+ assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 0);
+ });
+}
+
+#[test]
+fn nft_approve_and_transfer_from_white_list() {
+ new_test_ext().execute_with(|| {
+ let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
+ let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
+ let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
+ let mode: CollectionMode = CollectionMode::NFT(2000);
+
+ assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits {
+ collection_numbers_limit: 10,
+ account_token_ownership_limit: 10,
+ collections_admins_limit: 5,
+ custom_data_limit: 2048,
+ nft_sponsor_transfer_timeout: 15,
+ fungible_sponsor_transfer_timeout: 15,
+ refungible_sponsor_transfer_timeout: 15,
+ }));
+
+ let origin1 = Origin::signed(1);
+ let origin2 = Origin::signed(2);
+ assert_ok!(TemplateModule::create_collection(
+ origin1.clone(),
+ col_name1.clone(),
+ col_desc1.clone(),
+ token_prefix1.clone(),
+ mode
+ ));
+ assert_eq!(TemplateModule::collection(1).owner, 1);
+
+ assert_ok!(TemplateModule::create_item(
+ origin1.clone(),
+ 1,
+ [1, 2, 3].to_vec(),
+ 1
+ ));
+ assert_eq!(TemplateModule::nft_item_id(1, 1).data, [1, 2, 3].to_vec());
+ assert_eq!(TemplateModule::balance_count(1, 1), 1);
+ assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+
assert_ok!(TemplateModule::set_mint_permission(
origin1.clone(),
1,