difftreelog
Merge pull request #87 from usetech-llc/feature/upgrade_unit_tests
in: master
Upgrade unit tests to newer substrate
2 files changed
pallets/nft/src/mock.rsdiffbeforeafterboth1// Creating mock runtime here1// Creating mock runtime here223use crate::{Module, Trait};3use crate::{Module, Config};45use pallet_contracts::{6 ContractAddressFor, TrieId, TrieIdGenerator,7};849use frame_support::{5use frame_support::{10 impl_outer_origin, parameter_types,6 impl_outer_origin, parameter_types,11 weights::{7 weights::{Weight, IdentityFee},12 // constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight},13 Weight, IdentityFee,14 },15};8};16use frame_system as system;9use frame_system as system;10use system::limits::{BlockLength, BlockWeights};17use transaction_payment;11use transaction_payment::{self, CurrencyAdapter};18use sp_core::H256;12use sp_core::H256;19use sp_runtime::{13use sp_runtime::{20 testing::Header,14 testing::Header,21 traits::{BlakeTwo256, IdentityLookup, Saturating},15 traits::{BlakeTwo256, IdentityLookup},22 Perbill,16 Perbill,23};17};18use pallet_contracts::WeightInfo;24pub use pallet_balances;19pub use pallet_balances;252026impl_outer_origin! {21impl_outer_origin! {34pub struct Test;29pub struct Test;35parameter_types! {30parameter_types! {36 pub const BlockHashCount: u64 = 250;31 pub const BlockHashCount: u64 = 250;37 pub const MaximumBlockWeight: Weight = 1024;32 pub TestBlockWeights: BlockWeights = BlockWeights::default();38 pub const MaximumBlockLength: u32 = 2 * 1024;33 pub TestBlockLength: BlockLength = BlockLength::default();39 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);40 pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()34 pub SS58Prefix: u8 = 0;41 .saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();42}35}433644impl system::Trait for Test {37impl system::Config for Test {45 type BaseCallFilter = ();38 type BaseCallFilter = ();46 type Origin = Origin;39 type Origin = Origin;47 type Call = ();40 type Call = ();54 type Header = Header;47 type Header = Header;55 type Event = ();48 type Event = ();56 type BlockHashCount = BlockHashCount;49 type BlockHashCount = BlockHashCount;57 type MaximumBlockWeight = MaximumBlockWeight;50 type BlockWeights = TestBlockWeights;58 type DbWeight = ();51 type DbWeight = ();59 type BlockExecutionWeight = ();52 type BlockLength = TestBlockLength;60 type ExtrinsicBaseWeight = ();61 type MaximumExtrinsicWeight = MaximumBlockWeight;62 type MaximumBlockLength = MaximumBlockLength;63 type AvailableBlockRatio = AvailableBlockRatio;64 type Version = ();53 type Version = ();65 type PalletInfo = ();54 type PalletInfo = ();66 type AccountData = pallet_balances::AccountData<u64>;55 type AccountData = pallet_balances::AccountData<u64>;67 type OnNewAccount = ();56 type OnNewAccount = ();68 type OnKilledAccount = ();57 type OnKilledAccount = ();58 type SS58Prefix = SS58Prefix;69 type SystemWeightInfo = ();59 type SystemWeightInfo = ();70}60}716175}65}766677type System = frame_system::Module<Test>;67type System = frame_system::Module<Test>;78impl pallet_balances::Trait for Test {68impl pallet_balances::Config for Test {79 type AccountStore = System;69 type AccountStore = System;80 type Balance = u64;70 type Balance = u64;81 type DustRemoval = ();71 type DustRemoval = ();89 pub const TransactionByteFee: u64 = 1;79 pub const TransactionByteFee: u64 = 1;90}80}8191impl transaction_payment::Trait for Test {82impl transaction_payment::Config for Test {92 type Currency = pallet_balances::Module<Test>;83 type OnChargeTransaction = CurrencyAdapter<pallet_balances::Module<Test>, ()>;93 type OnTransactionPayment = ();94 type TransactionByteFee = TransactionByteFee;84 type TransactionByteFee = TransactionByteFee;95 type WeightToFee = IdentityFee<u64>;85 type WeightToFee = IdentityFee<u64>;96 type FeeMultiplierUpdate = ();86 type FeeMultiplierUpdate = ();100parameter_types! {90parameter_types! {101 pub const MinimumPeriod: u64 = 1;91 pub const MinimumPeriod: u64 = 1;102}92}103impl pallet_timestamp::Trait for Test {93impl pallet_timestamp::Config for Test {104 type Moment = u64;94 type Moment = u64;105 type OnTimestampSet = ();95 type OnTimestampSet = ();106 type MinimumPeriod = MinimumPeriod;96 type MinimumPeriod = MinimumPeriod;110type Timestamp = pallet_timestamp::Module<Test>;100type Timestamp = pallet_timestamp::Module<Test>;111type Randomness = pallet_randomness_collective_flip::Module<Test>;101type Randomness = pallet_randomness_collective_flip::Module<Test>;112102113parameter_types! {103parameter_types! {114 pub const TombstoneDeposit: u64 = 1;104 pub const TombstoneDeposit: u64 = 1;115 pub const RentByteFee: u64 = 1;105 pub const DepositPerContract: u64 = 1;116 pub const RentDepositOffset: u64 = 1;106 pub const DepositPerStorageByte: u64 = 1;117 pub const SurchargeReward: u64 = 1;107 pub const DepositPerStorageItem: u64 = 1;118}119120pub struct DummyTrieIdGenerator;108 pub RentFraction: Perbill = Perbill::from_rational_approximation(1u32, 30 * 24 * 60 * 10);121impl TrieIdGenerator<u64> for DummyTrieIdGenerator {122 fn trie_id(account_id: &u64) -> TrieId {109 pub const SurchargeReward: u64 = 1;123 let new_seed = *account_id + 1;124 let mut res = vec![];110 pub const SignedClaimHandicap: u32 = 2;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;111 pub const MaxDepth: u32 = 32;132impl ContractAddressFor<H256, u64> for DummyContractAddressFor {133 fn contract_address_for(_code_hash: &H256, _data: &[u8], origin: &u64) -> u64 {112 pub const MaxValueSize: u32 = 16 * 1024;134 *origin + 1113 pub DeletionWeightLimit: Weight = Perbill::from_percent(10) *135 }114 TestBlockWeights::get().max_block;136}115 pub DeletionQueueDepth: u32 = ((DeletionWeightLimit::get() / (116 <Test as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(1) -117 <Test as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(0)118 )) / 5) as u32;119}137120138impl pallet_contracts::Trait for Test {121impl pallet_contracts::Config for Test {139 type Time = Timestamp;122 type Time = Timestamp;140 type Randomness = Randomness;123 type Randomness = Randomness;141 type Currency = pallet_balances::Module<Test>;124 type Currency = pallet_balances::Module<Test>;142 type Event = ();125 type Event = ();143 type DetermineContractAddress = DummyContractAddressFor;144 type TrieIdGenerator = DummyTrieIdGenerator;145 type RentPayment = ();126 type RentPayment = ();146 type SignedClaimHandicap = pallet_contracts::DefaultSignedClaimHandicap;127 type SignedClaimHandicap = SignedClaimHandicap;147 type TombstoneDeposit = TombstoneDeposit;128 type TombstoneDeposit = TombstoneDeposit;148 type StorageSizeOffset = pallet_contracts::DefaultStorageSizeOffset;129 type DepositPerContract = DepositPerContract;149 type RentByteFee = RentByteFee;130 type DepositPerStorageByte = DepositPerStorageByte;150 type RentDepositOffset = RentDepositOffset;131 type DepositPerStorageItem = DepositPerStorageItem;132 type RentFraction = RentFraction;151 type SurchargeReward = SurchargeReward;133 type SurchargeReward = SurchargeReward;134 type DeletionWeightLimit = DeletionWeightLimit;152 type MaxDepth = pallet_contracts::DefaultMaxDepth;135 type MaxDepth = MaxDepth;136 type DeletionQueueDepth = DeletionQueueDepth;153 type MaxValueSize = pallet_contracts::DefaultMaxValueSize;137 type MaxValueSize = MaxValueSize;138 type ChainExtension = ();154 type WeightPrice = ();139 type WeightPrice = ();140 type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;155}141}156142157impl Trait for Test {143impl Config for Test {158 type Event = ();144 type Event = ();159 type WeightInfo = ();145 type WeightInfo = ();160146pallets/nft/src/tests.rsdiffbeforeafterboth454 assert_ok!(TemplateModule::transfer_from(454 assert_ok!(TemplateModule::transfer_from(455 origin2.clone(),455 origin2.clone(),456 1,456 1,457 2,457 3,458 1,458 1,459 1,459 1,460 1460 1508 1,508 1,509 1509 1510 ));510 ));511 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 4);511 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);512 });512 });513}513}514514543 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));543 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));544544545 // do approve545 // do approve546 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));546 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 1000));547 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);547 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1000);548 assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1, 1000));549 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 1000);550548551 assert_ok!(TemplateModule::transfer_from(549 assert_ok!(TemplateModule::transfer_from(552 origin2.clone(),550 origin2.clone(),562 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);560 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);563561564 assert_eq!(562 assert_eq!(565 TemplateModule::approved(1, (1, 1, 3)),563 TemplateModule::approved(1, (1, 1, 2)),566 900564 900567 );565 );568 });566 });618 assert_eq!(TemplateModule::balance_count(1, 1), 1);616 assert_eq!(TemplateModule::balance_count(1, 1), 1);619 assert_eq!(TemplateModule::balance_count(1, 3), 4);617 assert_eq!(TemplateModule::balance_count(1, 3), 4);620618621 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);619 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);622 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 1);620623624 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));625 assert_noop!(TemplateModule::transfer_from(621 assert_noop!(TemplateModule::transfer_from(626 origin2.clone(),622 origin2.clone(),627 1,623 1,