git.delta.rocks / unique-network / refs/commits / 6d406a445076

difftreelog

Merge pull request #15 from usetech-llc/fix/nftpar-150

usetech-llc2020-11-09parents: #c8be66f #5f252d9.patch.diff
in: master
Unit tests repaired

3 files changed

modifiedpallets/nft/Cargo.tomldiffbeforeafterboth
80branch = 'v2.0.0_release'80branch = 'v2.0.0_release'
81version = '2.0.0'81version = '2.0.0'
82
83[dependencies.pallet-balances]
84default-features = false
85git = 'https://github.com/usetech-llc/substrate.git'
86package = 'pallet-balances'
87branch = 'v2.0.0_release'
88version = '2.0.0'
89
90[dependencies.pallet-timestamp]
91default-features = false
92git = 'https://github.com/usetech-llc/substrate.git'
93package = 'pallet-timestamp'
94branch = 'v2.0.0_release'
95version = '2.0.0'
96
97[dependencies.pallet-randomness-collective-flip]
98default-features = false
99git = 'https://github.com/usetech-llc/substrate.git'
100package = 'pallet-randomness-collective-flip'
101branch = 'v2.0.0_release'
102version = '2.0.0'
82103
83[features]104[features]
84default = ['std']105default = ['std']
87 "serde/std",108 "serde/std",
88 'frame-support/std',109 'frame-support/std',
89 'frame-system/std',110 'frame-system/std',
111 'pallet-balances/std',
112 'pallet-timestamp/std',
113 'pallet-randomness-collective-flip/std',
90 'sp-std/std',114 'sp-std/std',
91 'sp-runtime/std',115 'sp-runtime/std',
92 'frame-benchmarking/std',116 'frame-benchmarking/std',
modifiedpallets/nft/src/mock.rsdiffbeforeafterboth
--- a/pallets/nft/src/mock.rs
+++ b/pallets/nft/src/mock.rs
@@ -1,20 +1,27 @@
 // Creating mock runtime here
 
 use crate::{Module, Trait};
+
+use pallet_contracts::{
+	ContractAddressFor, TrieId, TrieIdGenerator,
+};
+
 use frame_support::{
     impl_outer_origin, parameter_types,
     weights::{
-        constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight},
-        Weight,
+      //  constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight},
+        Weight, IdentityFee,
     },
 };
 use frame_system as system;
+use transaction_payment;
 use sp_core::H256;
 use sp_runtime::{
     testing::Header,
     traits::{BlakeTwo256, IdentityLookup, Saturating},
     Perbill,
 };
+pub use pallet_balances;
 
 impl_outer_origin! {
     pub enum Origin for Test {}
@@ -56,13 +63,101 @@
 	type AvailableBlockRatio = AvailableBlockRatio;
 	type Version = ();
 	type PalletInfo = ();
-	type AccountData = ();
+	type AccountData = pallet_balances::AccountData<u64>;
 	type OnNewAccount = ();
 	type OnKilledAccount = ();
 	type SystemWeightInfo = ();
 }
-impl Trait for Test {
+
+parameter_types! {
+	pub const ExistentialDeposit: u64 = 1;
+	pub const MaxLocks: u32 = 50;
+}
+
+type System = frame_system::Module<Test>;
+impl pallet_balances::Trait for Test {
+    type AccountStore = System;
+    type Balance = u64;
+    type DustRemoval = ();
     type Event = ();
+	type ExistentialDeposit = ExistentialDeposit;
+	type WeightInfo = ();
+	type MaxLocks = MaxLocks;
+}
+
+parameter_types! {
+	pub const TransactionByteFee: u64 = 1;
+}
+impl transaction_payment::Trait for Test {
+	type Currency = pallet_balances::Module<Test>;
+	type OnTransactionPayment = ();
+	type TransactionByteFee = TransactionByteFee;
+	type WeightToFee = IdentityFee<u64>;
+	type FeeMultiplierUpdate = ();
+}
+
+
+parameter_types! {
+	pub const MinimumPeriod: u64 = 1;
+}
+impl pallet_timestamp::Trait for Test {
+	type Moment = u64;
+	type OnTimestampSet = ();
+	type MinimumPeriod = MinimumPeriod;
+	type WeightInfo = ();
+}
+
+type Timestamp = pallet_timestamp::Module<Test>;
+type Randomness = pallet_randomness_collective_flip::Module<Test>;
+
+parameter_types! {
+	pub const TombstoneDeposit: u64 = 1;
+	pub const RentByteFee: u64 = 1;
+	pub const RentDepositOffset: u64 = 1;
+	pub const SurchargeReward: u64 = 1;
+}
+
+pub struct DummyTrieIdGenerator;
+impl TrieIdGenerator<u64> for DummyTrieIdGenerator {
+	fn trie_id(account_id: &u64) -> TrieId {
+		let new_seed = *account_id + 1;
+		let mut res = vec![];
+		res.extend_from_slice(&new_seed.to_le_bytes());
+		res.extend_from_slice(&account_id.to_le_bytes());
+		res
+	}
+}
+
+pub struct DummyContractAddressFor;
+impl ContractAddressFor<H256, u64> for DummyContractAddressFor {
+	fn contract_address_for(_code_hash: &H256, _data: &[u8], origin: &u64) -> u64 {
+		*origin + 1
+	}
+}
+
+impl pallet_contracts::Trait for Test {
+	type Time = Timestamp;
+	type Randomness = Randomness;
+	type Currency = pallet_balances::Module<Test>;
+	type Event = ();
+	type DetermineContractAddress = DummyContractAddressFor;
+	type TrieIdGenerator = DummyTrieIdGenerator;
+	type RentPayment = ();
+	type SignedClaimHandicap = pallet_contracts::DefaultSignedClaimHandicap;
+	type TombstoneDeposit = TombstoneDeposit;
+	type StorageSizeOffset = pallet_contracts::DefaultStorageSizeOffset;
+	type RentByteFee = RentByteFee;
+	type RentDepositOffset = RentDepositOffset;
+	type SurchargeReward = SurchargeReward;
+	type MaxDepth = pallet_contracts::DefaultMaxDepth;
+	type MaxValueSize = pallet_contracts::DefaultMaxValueSize;
+	type WeightPrice = ();
+}
+
+impl Trait for Test {
+	type Event = ();
+	type WeightInfo = ();
+
 }
 pub type TemplateModule = Module<Test>;
 
modifiedpallets/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,