difftreelog
Unit tests repaired
in: master
3 files changed
pallets/nft/Cargo.tomldiffbeforeafterboth80branch = 'v2.0.0_release'80branch = 'v2.0.0_release'81version = '2.0.0'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'8210383[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',pallets/nft/src/mock.rsdiffbeforeafterboth223use crate::{Module, Trait};3use crate::{Module, Trait};45use pallet_contracts::{6 ContractAddressFor, TrieId, TrieIdGenerator,7};84use frame_support::{9use frame_support::{5 impl_outer_origin, parameter_types,10 impl_outer_origin, parameter_types,6 weights::{11 weights::{7 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight},12 // constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight},8 Weight,13 Weight, IdentityFee,9 },14 },10};15};11use frame_system as system;16use frame_system as system;17use transaction_payment;12use sp_core::H256;18use sp_core::H256;13use sp_runtime::{19use sp_runtime::{14 testing::Header,20 testing::Header,15 traits::{BlakeTwo256, IdentityLookup, Saturating},21 traits::{BlakeTwo256, IdentityLookup, Saturating},16 Perbill,22 Perbill,17};23};24pub use pallet_balances;182519impl_outer_origin! {26impl_outer_origin! {20 pub enum Origin for Test {}27 pub enum Origin for Test {}56 type AvailableBlockRatio = AvailableBlockRatio;63 type AvailableBlockRatio = AvailableBlockRatio;57 type Version = ();64 type Version = ();58 type PalletInfo = ();65 type PalletInfo = ();59 type AccountData = ();66 type AccountData = pallet_balances::AccountData<u64>;60 type OnNewAccount = ();67 type OnNewAccount = ();61 type OnKilledAccount = ();68 type OnKilledAccount = ();62 type SystemWeightInfo = ();69 type SystemWeightInfo = ();63}70}7172parameter_types! {73 pub const ExistentialDeposit: u64 = 1;74 pub const MaxLocks: u32 = 50;75}7677type System = frame_system::Module<Test>;78impl pallet_balances::Trait for Test {79 type AccountStore = System;80 type Balance = u64;81 type DustRemoval = ();82 type Event = ();83 type ExistentialDeposit = ExistentialDeposit;84 type WeightInfo = ();85 type MaxLocks = MaxLocks;86}8788parameter_types! {89 pub const TransactionByteFee: u64 = 1;90}91impl transaction_payment::Trait for Test {92 type Currency = pallet_balances::Module<Test>;93 type OnTransactionPayment = ();94 type TransactionByteFee = TransactionByteFee;95 type WeightToFee = IdentityFee<u64>;96 type FeeMultiplierUpdate = ();97}9899100parameter_types! {101 pub const MinimumPeriod: u64 = 1;102}103impl pallet_timestamp::Trait for Test {104 type Moment = u64;105 type OnTimestampSet = ();106 type MinimumPeriod = MinimumPeriod;107 type WeightInfo = ();108}109110type Timestamp = pallet_timestamp::Module<Test>;111type Randomness = pallet_randomness_collective_flip::Module<Test>;112113parameter_types! {114 pub const TombstoneDeposit: u64 = 1;115 pub const RentByteFee: u64 = 1;116 pub const RentDepositOffset: u64 = 1;117 pub const SurchargeReward: u64 = 1;118}119120pub struct DummyTrieIdGenerator;121impl TrieIdGenerator<u64> for DummyTrieIdGenerator {122 fn trie_id(account_id: &u64) -> TrieId {123 let new_seed = *account_id + 1;124 let mut res = vec![];125 res.extend_from_slice(&new_seed.to_le_bytes());126 res.extend_from_slice(&account_id.to_le_bytes());127 res128 }129}130131pub struct DummyContractAddressFor;132impl ContractAddressFor<H256, u64> for DummyContractAddressFor {133 fn contract_address_for(_code_hash: &H256, _data: &[u8], origin: &u64) -> u64 {134 *origin + 1135 }136}137138impl pallet_contracts::Trait for Test {139 type Time = Timestamp;140 type Randomness = Randomness;141 type Currency = pallet_balances::Module<Test>;142 type Event = ();143 type DetermineContractAddress = DummyContractAddressFor;144 type TrieIdGenerator = DummyTrieIdGenerator;145 type RentPayment = ();146 type SignedClaimHandicap = pallet_contracts::DefaultSignedClaimHandicap;147 type TombstoneDeposit = TombstoneDeposit;148 type StorageSizeOffset = pallet_contracts::DefaultStorageSizeOffset;149 type RentByteFee = RentByteFee;150 type RentDepositOffset = RentDepositOffset;151 type SurchargeReward = SurchargeReward;152 type MaxDepth = pallet_contracts::DefaultMaxDepth;153 type MaxValueSize = pallet_contracts::DefaultMaxValueSize;154 type WeightPrice = ();155}15664impl Trait for Test {157impl Trait for Test {65 type Event = ();158 type Event = ();159 type WeightInfo = ();16066}161}67pub type TemplateModule = Module<Test>;162pub type TemplateModule = Module<Test>;pallets/nft/src/tests.rsdiffbeforeafterboth356}356}357357358#[test]358#[test]359fn nft_approve_and_transfer_from() {359fn nft_approve_and_transfer_from() {360 new_test_ext().execute_with(|| {361 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();362 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();363 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();364 let mode: CollectionMode = CollectionMode::NFT(2000);365366 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 367 collection_numbers_limit: 10,368 account_token_ownership_limit: 10,369 collections_admins_limit: 5,370 custom_data_limit: 2048,371 nft_sponsor_transfer_timeout: 15,372 fungible_sponsor_transfer_timeout: 15,373 refungible_sponsor_transfer_timeout: 15, 374 }));375376 let origin1 = Origin::signed(1);377 let origin2 = Origin::signed(2);378 assert_ok!(TemplateModule::create_collection(379 origin1.clone(),380 col_name1.clone(),381 col_desc1.clone(),382 token_prefix1.clone(),383 mode384 ));385 assert_eq!(TemplateModule::collection(1).owner, 1);386387 assert_ok!(TemplateModule::create_item(388 origin1.clone(),389 1,390 [1, 2, 3].to_vec(),391 1392 ));393 assert_eq!(TemplateModule::nft_item_id(1, 1).data, [1, 2, 3].to_vec());394 assert_eq!(TemplateModule::balance_count(1, 1), 1);395 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);396397 // neg transfer398 assert_noop!(TemplateModule::transfer_from(399 origin2.clone(),400 1,401 2,402 1,403 1,404 1), "Only item owner, collection owner and admins can modify items");405406 // do approve407 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));408 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 1);409 assert_eq!(410 TemplateModule::approved(1, (1, 1))[0],411 ApprovePermissions {412 approved: 2,413 amount: 100000000414 }415 );416417 assert_ok!(TemplateModule::transfer_from(418 origin2.clone(),419 1,420 2,421 1,422 1,423 1424 ));425 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 0);426 });427}428429#[test]430fn nft_approve_and_transfer_from_white_list() {360 new_test_ext().execute_with(|| {431 new_test_ext().execute_with(|| {361 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();432 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();362 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();433 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();