git.delta.rocks / unique-network / refs/commits / d59a8e7ab6ce

difftreelog

Merge pull request #87 from usetech-llc/feature/upgrade_unit_tests

Greg Zaitsev2021-02-05parents: #e182b08 #3c66d75.patch.diff
in: master
Upgrade unit tests to newer substrate

2 files changed

modifiedpallets/nft/src/mock.rsdiffbeforeafterboth
before · pallets/nft/src/mock.rs
1// Creating mock runtime here23use crate::{Module, Trait};45use pallet_contracts::{6	ContractAddressFor, TrieId, TrieIdGenerator,7};89use frame_support::{10    impl_outer_origin, parameter_types,11    weights::{12      //  constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight},13        Weight, IdentityFee,14    },15};16use frame_system as system;17use transaction_payment;18use sp_core::H256;19use sp_runtime::{20    testing::Header,21    traits::{BlakeTwo256, IdentityLookup, Saturating},22    Perbill,23};24pub use pallet_balances;2526impl_outer_origin! {27    pub enum Origin for Test {}28}2930// For testing the pallet, we construct most of a mock runtime. This means31// first constructing a configuration type (`Test`) which `impl`s each of the32// configuration traits of pallets we want to use.33#[derive(Clone, Eq, PartialEq)]34pub struct Test;35parameter_types! {36    pub const BlockHashCount: u64 = 250;37    pub const MaximumBlockWeight: Weight = 1024;38    pub const MaximumBlockLength: u32 = 2 * 1024;39    pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);40    pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()41    .saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();42}4344impl system::Trait for Test {45	type BaseCallFilter = ();46	type Origin = Origin;47	type Call = ();48	type Index = u64;49	type BlockNumber = u64;50	type Hash = H256;51	type Hashing = BlakeTwo256;52	type AccountId = u64;53	type Lookup = IdentityLookup<Self::AccountId>;54	type Header = Header;55	type Event = ();56	type BlockHashCount = BlockHashCount;57	type MaximumBlockWeight = MaximumBlockWeight;58	type DbWeight = ();59	type BlockExecutionWeight = ();60	type ExtrinsicBaseWeight = ();61	type MaximumExtrinsicWeight = MaximumBlockWeight;62	type MaximumBlockLength = MaximumBlockLength;63	type AvailableBlockRatio = AvailableBlockRatio;64	type Version = ();65	type PalletInfo = ();66	type AccountData = pallet_balances::AccountData<u64>;67	type OnNewAccount = ();68	type OnKilledAccount = ();69	type SystemWeightInfo = ();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}156157impl Trait for Test {158	type Event = ();159	type WeightInfo = ();160161}162pub type TemplateModule = Module<Test>;163164165// This function basically just builds a genesis storage key/value store according to166// our desired mockup.167pub fn new_test_ext() -> sp_io::TestExternalities {168    system::GenesisConfig::default()169        .build_storage::<Test>()170        .unwrap()171        .into()172}
after · pallets/nft/src/mock.rs
1// Creating mock runtime here23use crate::{Module, Config};45use frame_support::{6    impl_outer_origin, parameter_types,7    weights::{Weight, IdentityFee},8};9use frame_system as system;10use system::limits::{BlockLength, BlockWeights};11use transaction_payment::{self, CurrencyAdapter};12use sp_core::H256;13use sp_runtime::{14    testing::Header,15    traits::{BlakeTwo256, IdentityLookup},16    Perbill,17};18use pallet_contracts::WeightInfo;19pub use pallet_balances;2021impl_outer_origin! {22    pub enum Origin for Test {}23}2425// For testing the pallet, we construct most of a mock runtime. This means26// first constructing a configuration type (`Test`) which `impl`s each of the27// configuration traits of pallets we want to use.28#[derive(Clone, Eq, PartialEq)]29pub struct Test;30parameter_types! {31    pub const BlockHashCount: u64 = 250;32	pub TestBlockWeights: BlockWeights = BlockWeights::default();33	pub TestBlockLength: BlockLength = BlockLength::default();34	pub SS58Prefix: u8 = 0;35}3637impl system::Config for Test {38	type BaseCallFilter = ();39	type Origin = Origin;40	type Call = ();41	type Index = u64;42	type BlockNumber = u64;43	type Hash = H256;44	type Hashing = BlakeTwo256;45	type AccountId = u64;46	type Lookup = IdentityLookup<Self::AccountId>;47	type Header = Header;48	type Event = ();49	type BlockHashCount = BlockHashCount;50	type BlockWeights = TestBlockWeights;51	type DbWeight = ();52	type BlockLength = TestBlockLength;53	type Version = ();54	type PalletInfo = ();55	type AccountData = pallet_balances::AccountData<u64>;56	type OnNewAccount = ();57	type OnKilledAccount = ();58	type SS58Prefix = SS58Prefix;59	type SystemWeightInfo = ();60}6162parameter_types! {63	pub const ExistentialDeposit: u64 = 1;64	pub const MaxLocks: u32 = 50;65}6667type System = frame_system::Module<Test>;68impl pallet_balances::Config for Test {69    type AccountStore = System;70    type Balance = u64;71    type DustRemoval = ();72    type Event = ();73	type ExistentialDeposit = ExistentialDeposit;74	type WeightInfo = ();75	type MaxLocks = MaxLocks;76}7778parameter_types! {79	pub const TransactionByteFee: u64 = 1;80}8182impl transaction_payment::Config for Test {83	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Module<Test>, ()>;84	type TransactionByteFee = TransactionByteFee;85	type WeightToFee = IdentityFee<u64>;86	type FeeMultiplierUpdate = ();87}888990parameter_types! {91	pub const MinimumPeriod: u64 = 1;92}93impl pallet_timestamp::Config for Test {94	type Moment = u64;95	type OnTimestampSet = ();96	type MinimumPeriod = MinimumPeriod;97	type WeightInfo = ();98}99100type Timestamp = pallet_timestamp::Module<Test>;101type Randomness = pallet_randomness_collective_flip::Module<Test>;102103parameter_types! {104	pub const TombstoneDeposit: u64 = 1;105	pub const DepositPerContract: u64 = 1;106	pub const DepositPerStorageByte: u64 = 1;107	pub const DepositPerStorageItem: u64 = 1;108	pub RentFraction: Perbill = Perbill::from_rational_approximation(1u32, 30 * 24 * 60 * 10);109	pub const SurchargeReward: u64 = 1;110	pub const SignedClaimHandicap: u32 = 2;111	pub const MaxDepth: u32 = 32;112	pub const MaxValueSize: u32 = 16 * 1024;113	pub DeletionWeightLimit: Weight = Perbill::from_percent(10) *114		TestBlockWeights::get().max_block;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}120121impl pallet_contracts::Config for Test {122	type Time = Timestamp;123	type Randomness = Randomness;124	type Currency = pallet_balances::Module<Test>;125	type Event = ();126	type RentPayment = ();127	type SignedClaimHandicap = SignedClaimHandicap;128	type TombstoneDeposit = TombstoneDeposit;129	type DepositPerContract = DepositPerContract;130	type DepositPerStorageByte = DepositPerStorageByte;131	type DepositPerStorageItem = DepositPerStorageItem;132	type RentFraction = RentFraction;133	type SurchargeReward = SurchargeReward;134	type DeletionWeightLimit = DeletionWeightLimit;135	type MaxDepth = MaxDepth;136	type DeletionQueueDepth = DeletionQueueDepth;137	type MaxValueSize = MaxValueSize;138	type ChainExtension = ();139	type WeightPrice = ();140	type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;141}142143impl Config for Test {144	type Event = ();145	type WeightInfo = ();146147}148pub type TemplateModule = Module<Test>;149150151// This function basically just builds a genesis storage key/value store according to152// our desired mockup.153pub fn new_test_ext() -> sp_io::TestExternalities {154    system::GenesisConfig::default()155        .build_storage::<Test>()156        .unwrap()157        .into()158}
modifiedpallets/nft/src/tests.rsdiffbeforeafterboth
--- a/pallets/nft/src/tests.rs
+++ b/pallets/nft/src/tests.rs
@@ -454,7 +454,7 @@
         assert_ok!(TemplateModule::transfer_from(
             origin2.clone(),
             1,
-            2,
+            3,
             1,
             1,
             1
@@ -508,7 +508,7 @@
             1,
             1
         ));
-        assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 4);
+        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);
     });
 }
 
@@ -543,10 +543,8 @@
         assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));
 
         // do approve
-        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));
-        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
-        assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1, 1000));
-        assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 1000);
+        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 1000));
+        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1000);
 
         assert_ok!(TemplateModule::transfer_from(
             origin2.clone(),
@@ -562,7 +560,7 @@
         assert_eq!(TemplateModule::address_tokens(1, 3), [1]);
 
         assert_eq!(
-            TemplateModule::approved(1, (1, 1, 3)),
+            TemplateModule::approved(1, (1, 1, 2)),
             900
         );
     });
@@ -618,10 +616,8 @@
         assert_eq!(TemplateModule::balance_count(1, 1), 1);
         assert_eq!(TemplateModule::balance_count(1, 3), 4);
 
-        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
-        assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 1);
+        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);
 
-        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));
         assert_noop!(TemplateModule::transfer_from(
             origin2.clone(),
             1,