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
--- a/pallets/nft/src/mock.rs
+++ b/pallets/nft/src/mock.rs
@@ -1,26 +1,21 @@
 // Creating mock runtime here
 
-use crate::{Module, Trait};
-
-use pallet_contracts::{
-	ContractAddressFor, TrieId, TrieIdGenerator,
-};
+use crate::{Module, Config};
 
 use frame_support::{
     impl_outer_origin, parameter_types,
-    weights::{
-      //  constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight},
-        Weight, IdentityFee,
-    },
+    weights::{Weight, IdentityFee},
 };
 use frame_system as system;
-use transaction_payment;
+use system::limits::{BlockLength, BlockWeights};
+use transaction_payment::{self, CurrencyAdapter};
 use sp_core::H256;
 use sp_runtime::{
     testing::Header,
-    traits::{BlakeTwo256, IdentityLookup, Saturating},
+    traits::{BlakeTwo256, IdentityLookup},
     Perbill,
 };
+use pallet_contracts::WeightInfo;
 pub use pallet_balances;
 
 impl_outer_origin! {
@@ -34,14 +29,12 @@
 pub struct Test;
 parameter_types! {
     pub const BlockHashCount: u64 = 250;
-    pub const MaximumBlockWeight: Weight = 1024;
-    pub const MaximumBlockLength: u32 = 2 * 1024;
-    pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
-    pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()
-    .saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();
+	pub TestBlockWeights: BlockWeights = BlockWeights::default();
+	pub TestBlockLength: BlockLength = BlockLength::default();
+	pub SS58Prefix: u8 = 0;
 }
 
-impl system::Trait for Test {
+impl system::Config for Test {
 	type BaseCallFilter = ();
 	type Origin = Origin;
 	type Call = ();
@@ -54,18 +47,15 @@
 	type Header = Header;
 	type Event = ();
 	type BlockHashCount = BlockHashCount;
-	type MaximumBlockWeight = MaximumBlockWeight;
+	type BlockWeights = TestBlockWeights;
 	type DbWeight = ();
-	type BlockExecutionWeight = ();
-	type ExtrinsicBaseWeight = ();
-	type MaximumExtrinsicWeight = MaximumBlockWeight;
-	type MaximumBlockLength = MaximumBlockLength;
-	type AvailableBlockRatio = AvailableBlockRatio;
+	type BlockLength = TestBlockLength;
 	type Version = ();
 	type PalletInfo = ();
 	type AccountData = pallet_balances::AccountData<u64>;
 	type OnNewAccount = ();
 	type OnKilledAccount = ();
+	type SS58Prefix = SS58Prefix;
 	type SystemWeightInfo = ();
 }
 
@@ -75,7 +65,7 @@
 }
 
 type System = frame_system::Module<Test>;
-impl pallet_balances::Trait for Test {
+impl pallet_balances::Config for Test {
     type AccountStore = System;
     type Balance = u64;
     type DustRemoval = ();
@@ -88,9 +78,9 @@
 parameter_types! {
 	pub const TransactionByteFee: u64 = 1;
 }
-impl transaction_payment::Trait for Test {
-	type Currency = pallet_balances::Module<Test>;
-	type OnTransactionPayment = ();
+
+impl transaction_payment::Config for Test {
+	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Module<Test>, ()>;
 	type TransactionByteFee = TransactionByteFee;
 	type WeightToFee = IdentityFee<u64>;
 	type FeeMultiplierUpdate = ();
@@ -100,7 +90,7 @@
 parameter_types! {
 	pub const MinimumPeriod: u64 = 1;
 }
-impl pallet_timestamp::Trait for Test {
+impl pallet_timestamp::Config for Test {
 	type Moment = u64;
 	type OnTimestampSet = ();
 	type MinimumPeriod = MinimumPeriod;
@@ -112,49 +102,45 @@
 
 parameter_types! {
 	pub const TombstoneDeposit: u64 = 1;
-	pub const RentByteFee: u64 = 1;
-	pub const RentDepositOffset: u64 = 1;
+	pub const DepositPerContract: u64 = 1;
+	pub const DepositPerStorageByte: u64 = 1;
+	pub const DepositPerStorageItem: u64 = 1;
+	pub RentFraction: Perbill = Perbill::from_rational_approximation(1u32, 30 * 24 * 60 * 10);
 	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
-	}
+	pub const SignedClaimHandicap: u32 = 2;
+	pub const MaxDepth: u32 = 32;
+	pub const MaxValueSize: u32 = 16 * 1024;
+	pub DeletionWeightLimit: Weight = Perbill::from_percent(10) *
+		TestBlockWeights::get().max_block;
+	pub DeletionQueueDepth: u32 = ((DeletionWeightLimit::get() / (
+		<Test as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(1) -
+		<Test as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(0)
+	)) / 5) as u32;
 }
 
-impl pallet_contracts::Trait for Test {
+impl pallet_contracts::Config 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 SignedClaimHandicap = SignedClaimHandicap;
 	type TombstoneDeposit = TombstoneDeposit;
-	type StorageSizeOffset = pallet_contracts::DefaultStorageSizeOffset;
-	type RentByteFee = RentByteFee;
-	type RentDepositOffset = RentDepositOffset;
+	type DepositPerContract = DepositPerContract;
+	type DepositPerStorageByte = DepositPerStorageByte;
+	type DepositPerStorageItem = DepositPerStorageItem;
+	type RentFraction = RentFraction;
 	type SurchargeReward = SurchargeReward;
-	type MaxDepth = pallet_contracts::DefaultMaxDepth;
-	type MaxValueSize = pallet_contracts::DefaultMaxValueSize;
+	type DeletionWeightLimit = DeletionWeightLimit;
+	type MaxDepth = MaxDepth;
+	type DeletionQueueDepth = DeletionQueueDepth;
+	type MaxValueSize = MaxValueSize;
+	type ChainExtension = ();
 	type WeightPrice = ();
+	type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
 }
 
-impl Trait for Test {
+impl Config for Test {
 	type Event = ();
 	type WeightInfo = ();
 
modifiedpallets/nft/src/tests.rsdiffbeforeafterboth
454 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 1
508 1,508 1,
509 1509 1
510 ));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}
514514
543 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));543 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));
544544
545 // do approve545 // do approve
546 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);
550548
551 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]);
563561
564 assert_eq!(562 assert_eq!(
565 TemplateModule::approved(1, (1, 1, 3)),563 TemplateModule::approved(1, (1, 1, 2)),
566 900564 900
567 );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);
620618
621 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);620
623
624 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,