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
before · pallets/nft/Cargo.toml
1[package]2authors = ['Substrate DevHub <https://github.com/substrate-developer-hub>']3description = 'FRAME pallet nft'4edition = '2018'5homepage = 'https://substrate.io'6license = 'Unlicense'7name = 'pallet-nft'8repository = 'https://github.com/substrate-developer-hub/nft/'9version = '2.0.0'1011[package.metadata.docs.rs]12targets = ['x86_64-unknown-linux-gnu']1314# alias "parity-scale-code" to "codec"15[dependencies.codec]16default-features = false17features = ['derive']18package = 'parity-scale-codec'19version = '1.3.4'2021[dependencies.frame-support]22default-features = false23git = 'https://github.com/usetech-llc/substrate.git'24branch = 'v2.0.0_release'25version = '2.0.0'2627[dependencies.frame-system]28default-features = false29git = 'https://github.com/usetech-llc/substrate.git'30branch = 'v2.0.0_release'31version = '2.0.0'3233[dev-dependencies.sp-core]34default-features = false35git = 'https://github.com/usetech-llc/substrate.git'36branch = 'v2.0.0_release'37version = '2.0.0'3839[dev-dependencies.sp-io]40default-features = false41git = 'https://github.com/usetech-llc/substrate.git'42branch = 'v2.0.0_release'43version = '2.0.0'4445[dependencies.sp-runtime]46default-features = false47git = 'https://github.com/usetech-llc/substrate.git'48branch = 'v2.0.0_release'49version = '2.0.0'50	51[dependencies]52# third-party dependencies53serde = { version = "1.0.102", features = ["derive"] }54log = "0.4.8"5556[dependencies.sp-std]57default-features = false58git = 'https://github.com/usetech-llc/substrate.git'59branch = 'v2.0.0_release'60version = '2.0.0'6162[dependencies.transaction-payment]63default-features = false64git = 'https://github.com/usetech-llc/substrate.git'65package = 'pallet-transaction-payment'66branch = 'v2.0.0_release'67version = '2.0.0'6869[dependencies.frame-benchmarking]70version = "2.0.0"71default-features = false72git = 'https://github.com/usetech-llc/substrate.git'73branch = 'v2.0.0_release'74optional = true7576[dependencies.pallet-contracts]77default-features = false78git = 'https://github.com/usetech-llc/substrate.git'79package = 'pallet-contracts'80branch = 'v2.0.0_release'81version = '2.0.0'8283[features]84default = ['std']85std = [86    'codec/std',87    "serde/std",88    'frame-support/std',89    'frame-system/std',90    'sp-std/std',91    'sp-runtime/std',92    'frame-benchmarking/std',93]94runtime-benchmarks = ["frame-benchmarking"]
after · pallets/nft/Cargo.toml
1[package]2authors = ['Substrate DevHub <https://github.com/substrate-developer-hub>']3description = 'FRAME pallet nft'4edition = '2018'5homepage = 'https://substrate.io'6license = 'Unlicense'7name = 'pallet-nft'8repository = 'https://github.com/substrate-developer-hub/nft/'9version = '2.0.0'1011[package.metadata.docs.rs]12targets = ['x86_64-unknown-linux-gnu']1314# alias "parity-scale-code" to "codec"15[dependencies.codec]16default-features = false17features = ['derive']18package = 'parity-scale-codec'19version = '1.3.4'2021[dependencies.frame-support]22default-features = false23git = 'https://github.com/usetech-llc/substrate.git'24branch = 'v2.0.0_release'25version = '2.0.0'2627[dependencies.frame-system]28default-features = false29git = 'https://github.com/usetech-llc/substrate.git'30branch = 'v2.0.0_release'31version = '2.0.0'3233[dev-dependencies.sp-core]34default-features = false35git = 'https://github.com/usetech-llc/substrate.git'36branch = 'v2.0.0_release'37version = '2.0.0'3839[dev-dependencies.sp-io]40default-features = false41git = 'https://github.com/usetech-llc/substrate.git'42branch = 'v2.0.0_release'43version = '2.0.0'4445[dependencies.sp-runtime]46default-features = false47git = 'https://github.com/usetech-llc/substrate.git'48branch = 'v2.0.0_release'49version = '2.0.0'50	51[dependencies]52# third-party dependencies53serde = { version = "1.0.102", features = ["derive"] }54log = "0.4.8"5556[dependencies.sp-std]57default-features = false58git = 'https://github.com/usetech-llc/substrate.git'59branch = 'v2.0.0_release'60version = '2.0.0'6162[dependencies.transaction-payment]63default-features = false64git = 'https://github.com/usetech-llc/substrate.git'65package = 'pallet-transaction-payment'66branch = 'v2.0.0_release'67version = '2.0.0'6869[dependencies.frame-benchmarking]70version = "2.0.0"71default-features = false72git = 'https://github.com/usetech-llc/substrate.git'73branch = 'v2.0.0_release'74optional = true7576[dependencies.pallet-contracts]77default-features = false78git = 'https://github.com/usetech-llc/substrate.git'79package = 'pallet-contracts'80branch = 'v2.0.0_release'81version = '2.0.0'8283[dependencies.pallet-balances]84default-features = false85git = 'https://github.com/usetech-llc/substrate.git'86package = 'pallet-balances'87branch = 'v2.0.0_release'88version = '2.0.0'8990[dependencies.pallet-timestamp]91default-features = false92git = 'https://github.com/usetech-llc/substrate.git'93package = 'pallet-timestamp'94branch = 'v2.0.0_release'95version = '2.0.0'9697[dependencies.pallet-randomness-collective-flip]98default-features = false99git = 'https://github.com/usetech-llc/substrate.git'100package = 'pallet-randomness-collective-flip'101branch = 'v2.0.0_release'102version = '2.0.0'103104[features]105default = ['std']106std = [107    'codec/std',108    "serde/std",109    'frame-support/std',110    'frame-system/std',111    'pallet-balances/std',112    'pallet-timestamp/std',113    'pallet-randomness-collective-flip/std',114    'sp-std/std',115    'sp-runtime/std',116    'frame-benchmarking/std',117]118runtime-benchmarks = ["frame-benchmarking"]
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,