Skip to content

Commit

Permalink
Add test cases for code coverage (#719)
Browse files Browse the repository at this point in the history
* Add test cases
* More test cases
* One more simple test case
* Remove removed staking pallet
* Update CI script
* Auto format
  • Loading branch information
simonsso authored Mar 17, 2023
1 parent aaf9e00 commit 0334905
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 10,723 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Test and gather coverage
run: cargo llvm-cov --lcov --output-path lcov.info --all-features --workspace --exclude runtimes-eden --exclude nodle-parachain
run: cargo llvm-cov --lcov --output-path lcov.info --all-features --workspace --exclude nodle-parachain
- name: Upload to Codecov
uses: codecov/[email protected]
with:
Expand Down
78 changes: 16 additions & 62 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions pallets/allocations/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,3 +704,30 @@ fn no_issuance() {
fn test_releases_default() {
assert_eq!(Releases::default(), Releases::V0);
}

#[test]
fn check_weight_info() {
use crate::weights::SubstrateWeight;
use frame_support::pallet_prelude::Weight;

assert_ne!(<()>::set_curve_starting_block(), Weight::from_ref_time(0));
assert_ne!(
SubstrateWeight::<Test>::set_curve_starting_block(),
Weight::from_ref_time(0)
);

assert_ne!(<()>::checked_update_session_quota(), Weight::from_ref_time(0));
assert_ne!(
SubstrateWeight::<Test>::checked_update_session_quota(),
Weight::from_ref_time(0)
);

assert_ne!(<()>::allocate(100), Weight::from_ref_time(0));
assert_ne!(SubstrateWeight::<Test>::allocate(100), Weight::from_ref_time(0));

assert_ne!(<()>::calc_quota(), Weight::from_ref_time(0));
assert_ne!(SubstrateWeight::<Test>::calc_quota(), Weight::from_ref_time(0));

assert_ne!(<()>::renew_quota(), Weight::from_ref_time(0));
assert_ne!(SubstrateWeight::<Test>::renew_quota(), Weight::from_ref_time(0));
}
17 changes: 0 additions & 17 deletions pallets/grants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,23 +307,6 @@ pub mod pallet {
}
}

#[cfg(feature = "std")]
impl<T: Config> GenesisConfig<T> {
/// Direct implementation of `GenesisBuild::build_storage`.
///
/// Kept in order not to break dependency.
pub fn build_storage(&self) -> Result<sp_runtime::Storage, String> {
<Self as GenesisBuild<T>>::build_storage(self)
}

/// Direct implementation of `GenesisBuild::assimilate_storage`.
///
/// Kept in order not to break dependency.
pub fn assimilate_storage(&self, storage: &mut sp_runtime::Storage) -> Result<(), String> {
<Self as GenesisBuild<T>>::assimilate_storage(self, storage)
}
}

pub const VESTING_LOCK_ID: LockIdentifier = *b"nvesting";

impl<T: Config> Pallet<T> {
Expand Down
17 changes: 0 additions & 17 deletions pallets/reserve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,6 @@ pub mod pallet {
}
}

#[cfg(feature = "std")]
impl<T: Config<I>, I: 'static> GenesisConfig<T, I> {
/// Direct implementation of `GenesisBuild::build_storage`.
///
/// Kept in order not to break dependency.
pub fn build_storage(&self) -> Result<sp_runtime::Storage, String> {
<Self as GenesisBuild<T, I>>::build_storage(self)
}

/// Direct implementation of `GenesisBuild::assimilate_storage`.
///
/// Kept in order not to break dependency.
pub fn assimilate_storage(&self, storage: &mut sp_runtime::Storage) -> Result<(), String> {
<Self as GenesisBuild<T, I>>::assimilate_storage(self, storage)
}
}

impl<T: Config<I>, I: 'static> WithAccountId<T::AccountId> for Pallet<T, I> {
fn account_id() -> T::AccountId {
T::PalletId::get().into_account_truncating()
Expand Down
11 changes: 11 additions & 0 deletions pallets/reserve/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ fn spend_error_if_bad_origin() {
})
}

#[test]
fn check_weight_info() {
use crate::weights::SubstrateWeight;
use frame_support::pallet_prelude::Weight;

assert_ne!(<()>::tip(), Weight::from_ref_time(0));
assert_ne!(<()>::spend(), Weight::from_ref_time(0));
assert_ne!(SubstrateWeight::<Test>::tip(), Weight::from_ref_time(0));
assert_ne!(SubstrateWeight::<Test>::spend(), Weight::from_ref_time(0));
}

#[test]
fn spend_funds_to_target() {
new_test_ext().execute_with(|| {
Expand Down
59 changes: 0 additions & 59 deletions pallets/staking/Cargo.toml

This file was deleted.

Loading

0 comments on commit 0334905

Please sign in to comment.