mirror of
https://git.ghostchain.io/proxmio/ghost-node.git
synced 2025-12-27 03:09:56 +00:00
new tests based on new ghost-network functinality
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
@@ -10,6 +10,9 @@ use sp_core::offchain::{
|
||||
};
|
||||
use sp_runtime::testing::UintAuthorityId;
|
||||
|
||||
use ghost_networks::BridgedInflationCurve;
|
||||
use pallet_staking::EraPayout;
|
||||
|
||||
const MAX_DEVIATION_DEPTH: u32 = 10;
|
||||
|
||||
fn prepare_evm_network(
|
||||
@@ -262,18 +265,24 @@ fn should_mark_clapped_transaction_when_clap_received() {
|
||||
fn should_applause_and_take_next_claps() {
|
||||
let (network_id, transaction_hash, unique_transaction_hash) =
|
||||
generate_unique_hash(None, None, None, None);
|
||||
let (_, receiver, amount) = get_mocked_metadata();
|
||||
|
||||
new_test_ext().execute_with(|| {
|
||||
let session_index = advance_session_and_get_index();
|
||||
let storage_key = (session_index, transaction_hash, unique_transaction_hash);
|
||||
|
||||
assert_eq!(pallet::ApplausesForTransaction::<Runtime>::get(&storage_key), false);
|
||||
assert_eq!(Balances::balance(&receiver), 0);
|
||||
assert_ok!(do_clap_from(session_index, network_id, 0, false));
|
||||
assert_eq!(pallet::ApplausesForTransaction::<Runtime>::get(&storage_key), false);
|
||||
assert_eq!(Balances::balance(&receiver), 0);
|
||||
assert_ok!(do_clap_from(session_index, network_id, 1, false));
|
||||
assert_eq!(pallet::ApplausesForTransaction::<Runtime>::get(&storage_key), true);
|
||||
assert_eq!(Balances::balance(&receiver), amount);
|
||||
assert_ok!(do_clap_from(session_index, network_id, 2, false));
|
||||
assert_eq!(pallet::ApplausesForTransaction::<Runtime>::get(&storage_key), true);
|
||||
assert_eq!(Balances::balance(&receiver), amount);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -530,10 +539,74 @@ fn should_throw_error_on_commission_overflow() {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_nullify_commission_on_finalize() {
|
||||
let total_staked = 69_000_000;
|
||||
let total_issuance = 100_000_000;
|
||||
|
||||
let (network_id, _, _) = generate_unique_hash(None, None, None, None);
|
||||
let (_, _, amount) = get_mocked_metadata();
|
||||
|
||||
new_test_ext().execute_with(|| {
|
||||
let _ = prepare_evm_network(Some(network_id), Some(500_000_000));
|
||||
let session_index = advance_session_and_get_index();
|
||||
|
||||
assert_eq!(Networks::accumulated_commission(), 0);
|
||||
assert_ok!(do_clap_from(session_index, network_id, 0, false));
|
||||
assert_ok!(do_clap_from(session_index, network_id, 1, false));
|
||||
assert_eq!(Networks::accumulated_commission(), amount.saturating_div(2));
|
||||
assert_eq!(Networks::is_nullification_period(), false);
|
||||
|
||||
assert_eq!(BridgedInflationCurve::<RewardCurve, Runtime>::era_payout(
|
||||
total_staked,
|
||||
(total_issuance + amount).into(),
|
||||
0), (1260099399952u128, 208739900600048u128)); // precomputed values
|
||||
assert_eq!(Networks::is_nullification_period(), true);
|
||||
Networks::on_finalize(System::block_number());
|
||||
|
||||
assert_eq!(Networks::is_nullification_period(), false);
|
||||
assert_eq!(Networks::accumulated_commission(), 0);
|
||||
assert_ok!(do_clap_from(session_index, network_id, 2, false));
|
||||
assert_eq!(Networks::accumulated_commission(), 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_avoid_applause_during_nullification_period() {
|
||||
let total_staked = 69_000_000;
|
||||
let total_issuance = 100_000_000;
|
||||
|
||||
let (network_id, _, _) = generate_unique_hash(None, None, None, None);
|
||||
let (_, receiver, amount) = get_mocked_metadata();
|
||||
|
||||
new_test_ext().execute_with(|| {
|
||||
let _ = prepare_evm_network(Some(network_id), Some(0));
|
||||
let session_index = advance_session_and_get_index();
|
||||
|
||||
assert_eq!(Networks::is_nullification_period(), false);
|
||||
assert_eq!(BridgedInflationCurve::<RewardCurve, Runtime>::era_payout(
|
||||
total_staked,
|
||||
total_issuance,
|
||||
0), (0, 0));
|
||||
assert_eq!(Networks::is_nullification_period(), true);
|
||||
|
||||
assert_ok!(do_clap_from(session_index, network_id, 0, false));
|
||||
assert_ok!(do_clap_from(session_index, network_id, 1, false));
|
||||
assert_eq!(Balances::balance(&receiver), 0);
|
||||
|
||||
Networks::on_finalize(System::block_number());
|
||||
assert_eq!(Networks::is_nullification_period(), false);
|
||||
|
||||
assert_ok!(do_clap_from(session_index, network_id, 2, false));
|
||||
assert_eq!(Balances::balance(&receiver), amount);
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: check event
|
||||
// TODO: multiple logs will create multiple records
|
||||
// TODO: errors should be checked as much as possible
|
||||
// TODO: offences generated as expected
|
||||
// TODO: deal with below existential amount after commission
|
||||
|
||||
fn advance_session_and_get_index() -> u32 {
|
||||
advance_session();
|
||||
|
||||
Reference in New Issue
Block a user