Skip to content
Snippets Groups Projects
Commit cb99b8f6 authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

distance pallet unit test stub

parent 72cc4e73
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,8 @@ pub mod benchmarking;
#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;
pub use pallet::*;
pub use traits::*;
......
......@@ -19,7 +19,7 @@ use crate::{self as pallet_distance};
use core::marker::PhantomData;
use frame_support::{
parameter_types,
traits::{Everything, GenesisBuild},
traits::{Everything, GenesisBuild, OnFinalize, OnInitialize},
};
use frame_system as system;
use pallet_balances::AccountData;
......@@ -291,3 +291,14 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
sp_io::TestExternalities::new(t)
}
pub fn run_to_block(n: u64) {
while System::block_number() < n {
Session::on_finalize(System::block_number());
System::on_finalize(System::block_number());
System::reset_events();
System::set_block_number(System::block_number() + 1);
System::on_initialize(System::block_number());
Session::on_initialize(System::block_number());
}
}
// Copyright 2023 Axiom-Team
//
// This file is part of Duniter-v2S.
//
// Duniter-v2S is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Duniter-v2S is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
use crate::mock::*;
use crate::*;
use frame_support::assert_ok;
use frame_support::traits::Currency;
#[test]
fn test_request_distance_evaluation() {
new_test_ext().execute_with(|| {
run_to_block(1);
// give enough for reserve
Balances::make_free_balance_be(&1, 10_000);
// call request
assert_ok!(Distance::request_distance_evaluation(
RuntimeOrigin::signed(1)
));
System::assert_has_event(RuntimeEvent::Distance(Event::EvaluationRequested {
idty_index: 1,
who: 1,
}));
// currency was reserved
assert_eq!(Balances::reserved_balance(1), 1000);
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment