Transition into monorepo (#180)

* evm template integrated

* workflows modified per template

* workflow fixes
This commit is contained in:
Özgün Özerk
2024-05-17 12:00:25 +03:00
committed by GitHub
parent 9cd76d29f0
commit 1bb2e96501
103 changed files with 20153 additions and 581 deletions
@@ -0,0 +1,12 @@
// ExtBuilder impl for all runtime integration tests
use frame_support::weights::Weight;
use parachain_template_runtime::{BuildStorage, Runtime, System};
pub fn run_with_system_weight<F: FnMut()>(w: Weight, mut assertions: F) {
let mut t: sp_io::TestExternalities =
frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap().into();
t.execute_with(|| {
System::set_block_consumed_resources(w, 0);
assertions()
});
}
@@ -0,0 +1,217 @@
mod constant_tests {
use parachain_template_runtime::constants::currency::*;
#[test]
fn test_constants() {
assert_eq!(MICROCENTS, 1_000_000);
assert_eq!(MILLICENTS, 1_000_000_000);
assert_eq!(CENTS, 1_000 * MILLICENTS);
assert_eq!(DOLLARS, 100 * CENTS);
assert_eq!(EXISTENTIAL_DEPOSIT, MILLICENTS);
// Ensure deposit function behavior remains constant
assert_eq!(deposit(2, 3), 2 * 15 * CENTS + 3 * 6 * CENTS);
}
}
mod runtime_tests {
use frame_support::{pallet_prelude::Weight, traits::TypedGet, PalletId};
use parachain_template_runtime::{constants::currency::*, *};
use xcm::latest::prelude::BodyId;
#[test]
fn weight_to_fee_constants() {
assert_eq!(P_FACTOR, 10);
assert_eq!(Q_FACTOR, 100);
assert_eq!(POLY_DEGREE, 1);
}
#[test]
fn frame_system_constants() {
#[cfg(not(feature = "async-backing"))]
assert_eq!(
MAXIMUM_BLOCK_WEIGHT,
Weight::from_parts(
frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND.saturating_div(2),
cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64
)
);
#[cfg(feature = "async-backing")]
assert_eq!(
MAXIMUM_BLOCK_WEIGHT,
Weight::from_parts(
frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2),
cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64
)
);
assert_eq!(AVERAGE_ON_INITIALIZE_RATIO, Perbill::from_percent(5));
assert_eq!(NORMAL_DISPATCH_RATIO, Perbill::from_percent(75));
#[cfg(not(feature = "async-backing"))]
assert_eq!(UNINCLUDED_SEGMENT_CAPACITY, 1);
#[cfg(feature = "async-backing")]
assert_eq!(UNINCLUDED_SEGMENT_CAPACITY, 3);
assert_eq!(BLOCK_PROCESSING_VELOCITY, 1);
assert_eq!(RELAY_CHAIN_SLOT_DURATION_MILLIS, 6000);
#[cfg(not(feature = "async-backing"))]
assert_eq!(MILLISECS_PER_BLOCK, 12000);
#[cfg(feature = "async-backing")]
assert_eq!(MILLISECS_PER_BLOCK, 6000);
assert_eq!(SLOT_DURATION, MILLISECS_PER_BLOCK);
assert_eq!(MINUTES, 60_000 / (MILLISECS_PER_BLOCK as BlockNumber));
assert_eq!(HOURS, MINUTES * 60);
assert_eq!(DAYS, HOURS * 24);
assert_eq!(MAX_BLOCK_LENGTH, 5 * 1024 * 1024);
assert_eq!(SS58Prefix::get(), 42);
assert_eq!(<Runtime as frame_system::Config>::MaxConsumers::get(), 16);
}
#[test]
fn proxy_constants() {
assert_eq!(MaxProxies::get(), 32);
assert_eq!(MaxPending::get(), 32);
assert_eq!(ProxyDepositBase::get(), deposit(1, 40));
assert_eq!(AnnouncementDepositBase::get(), deposit(1, 48));
assert_eq!(ProxyDepositFactor::get(), deposit(0, 33));
assert_eq!(AnnouncementDepositFactor::get(), deposit(0, 66));
}
#[test]
fn balances_constants() {
assert_eq!(MaxFreezes::get(), 0);
assert_eq!(MaxLocks::get(), 50);
assert_eq!(MaxReserves::get(), 50);
}
#[test]
fn assets_constants() {
assert_eq!(AssetDeposit::get(), 10 * CENTS);
assert_eq!(AssetAccountDeposit::get(), deposit(1, 16));
assert_eq!(ApprovalDeposit::get(), EXISTENTIAL_DEPOSIT);
assert_eq!(StringLimit::get(), 50);
assert_eq!(MetadataDepositBase::get(), deposit(1, 68));
assert_eq!(MetadataDepositPerByte::get(), deposit(0, 1));
assert_eq!(RemoveItemsLimit::get(), 1000);
}
#[test]
fn transaction_payment_constants() {
assert_eq!(TransactionByteFee::get(), 10 * MICROCENTS);
assert_eq!(OperationalFeeMultiplier::get(), 5);
}
#[test]
fn cumulus_pallet_parachain_system_constants() {
assert_eq!(ReservedXcmpWeight::get(), MAXIMUM_BLOCK_WEIGHT.saturating_div(4));
assert_eq!(ReservedDmpWeight::get(), MAXIMUM_BLOCK_WEIGHT.saturating_div(4));
}
#[test]
fn message_queue_constants() {
assert_eq!(HeapSize::get(), 64 * 1024);
assert_eq!(MaxStale::get(), 8);
}
#[test]
fn cumulus_pallet_xcmp_queue_constants() {
assert_eq!(MaxInboundSuspended::get(), 1000);
}
#[test]
fn multisig_constants() {
assert_eq!(DepositBase::get(), deposit(1, 88));
assert_eq!(DepositFactor::get(), deposit(0, 32));
assert_eq!(MaxSignatories::get(), 100);
}
#[test]
fn session_constants() {
assert_eq!(Period::get(), 6 * HOURS);
assert_eq!(Offset::get(), 0);
}
#[test]
#[allow(clippy::assertions_on_constants)]
fn aura_constants() {
#[cfg(not(feature = "async-backing"))]
assert!(!AllowMultipleBlocksPerSlot::get());
#[cfg(feature = "async-backing")]
assert!(AllowMultipleBlocksPerSlot::get());
assert_eq!(MaxAuthorities::get(), 100_000);
}
#[test]
fn collator_selection_constants() {
let pallet_id_to_string = |id: PalletId| -> String {
core::str::from_utf8(&id.0).unwrap_or_default().to_string()
};
assert_eq!(pallet_id_to_string(PotId::get()), pallet_id_to_string(PalletId(*b"PotStake")));
assert_eq!(SessionLength::get(), 6 * HOURS);
assert_eq!(StakingAdminBodyId::get(), BodyId::Defense);
assert_eq!(MaxCandidates::get(), 100);
assert_eq!(MaxInvulnerables::get(), 20);
assert_eq!(MinEligibleCollators::get(), 4);
}
}
mod xcm_tests {
use frame_support::weights::Weight;
use parachain_template_runtime::xcm_config::*;
#[test]
fn xcm_executor_constants() {
assert_eq!(UnitWeightCost::get(), Weight::from_parts(1_000_000_000, 64 * 1024));
assert_eq!(MaxInstructions::get(), 100);
assert_eq!(MaxAssetsIntoHolding::get(), 64);
}
#[test]
fn pallet_xcm_constants() {
assert_eq!(MaxLockers::get(), 8);
assert_eq!(MaxRemoteLockConsumers::get(), 0);
assert_eq!(<parachain_template_runtime::Runtime as pallet_xcm::Config>::VERSION_DISCOVERY_QUEUE_SIZE, 100);
}
}
@@ -0,0 +1,46 @@
// Integration transaction weight-fee tests
mod common;
use common::*;
use frame_support::pallet_prelude::*;
use pallet_transaction_payment::Multiplier;
use parachain_template_runtime::{Runtime, RuntimeBlockWeights};
use polkadot_runtime_common::MinimumMultiplier;
use sp_runtime::{traits::Convert, Perquintill};
fn min_multiplier() -> Multiplier {
MinimumMultiplier::get()
}
fn target() -> Weight {
Perquintill::from_percent(25)
* RuntimeBlockWeights::get().get(DispatchClass::Normal).max_total.unwrap()
}
fn runtime_multiplier_update(fm: Multiplier) -> Multiplier {
<Runtime as pallet_transaction_payment::Config>::FeeMultiplierUpdate::convert(fm)
}
#[test]
fn multiplier_can_grow_from_zero() {
// if the min is too small, then this will not change, and we are doomed forever.
// the block ref time is 1/100th bigger than target.
run_with_system_weight(target().set_ref_time(target().ref_time() * 101 / 100), || {
let next = runtime_multiplier_update(min_multiplier());
assert!(next > min_multiplier(), "{:?} !> {:?}", next, min_multiplier());
});
// the block proof size is 1/100th bigger than target.
run_with_system_weight(target().set_proof_size((target().proof_size() / 100) * 101), || {
let next = runtime_multiplier_update(min_multiplier());
assert!(next > min_multiplier(), "{:?} !> {:?}", next, min_multiplier());
})
}
#[test]
fn multiplier_cannot_go_below_limit() {
// will not go any further below even if block is empty.
run_with_system_weight(Weight::zero(), || {
let next = runtime_multiplier_update(min_multiplier());
assert_eq!(next, min_multiplier());
})
}
+33
View File
@@ -0,0 +1,33 @@
// Storage indices integration checks
use frame_support::traits::PalletInfo;
use parachain_template_runtime::{
Aura, AuraExt, Authorship, Balances, CollatorSelection, CumulusXcm, MessageQueue, Multisig,
ParachainInfo, ParachainSystem, PolkadotXcm, Proxy, Runtime, Session, Sudo, System, Timestamp,
TransactionPayment, XcmpQueue,
};
fn assert_pallet_prefix<P: 'static>(name: &str) {
assert_eq!(<Runtime as frame_system::Config>::PalletInfo::name::<P>(), Some(name));
}
#[test]
fn verify_pallet_prefixes() {
assert_pallet_prefix::<System>("System");
assert_pallet_prefix::<ParachainSystem>("ParachainSystem");
assert_pallet_prefix::<Timestamp>("Timestamp");
assert_pallet_prefix::<ParachainInfo>("ParachainInfo");
assert_pallet_prefix::<Proxy>("Proxy");
assert_pallet_prefix::<Balances>("Balances");
assert_pallet_prefix::<TransactionPayment>("TransactionPayment");
assert_pallet_prefix::<Sudo>("Sudo");
assert_pallet_prefix::<Multisig>("Multisig");
assert_pallet_prefix::<Authorship>("Authorship");
assert_pallet_prefix::<CollatorSelection>("CollatorSelection");
assert_pallet_prefix::<Session>("Session");
assert_pallet_prefix::<Aura>("Aura");
assert_pallet_prefix::<AuraExt>("AuraExt");
assert_pallet_prefix::<XcmpQueue>("XcmpQueue");
assert_pallet_prefix::<PolkadotXcm>("PolkadotXcm");
assert_pallet_prefix::<CumulusXcm>("CumulusXcm");
assert_pallet_prefix::<MessageQueue>("MessageQueue");
}