difftreelog
Unit tests repaired
in: master
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.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>;
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>>();