make slow-clap tests work again based on new functionality, new tests added too
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
parent
ebae9fadbe
commit
decf6665df
@ -665,15 +665,14 @@ fn should_throw_error_if_session_index_is_not_current() {
|
||||
network_id,
|
||||
authority_prev
|
||||
));
|
||||
assert_ok!(do_clap_from_first_authority(
|
||||
session_index_next,
|
||||
network_id,
|
||||
authority_next
|
||||
));
|
||||
assert_err!(
|
||||
do_clap_from_first_authority(session_index_next, network_id, authority_next),
|
||||
DispatchError::Other("Transaction has a bad signature")
|
||||
);
|
||||
|
||||
assert_claps_info_correct(&storage_key_curr, &session_index_curr, 1);
|
||||
assert_claps_info_correct(&storage_key_prev, &session_index_prev, 1);
|
||||
assert_claps_info_correct(&storage_key_next, &session_index_next, 1);
|
||||
assert_claps_info_correct(&storage_key_next, &session_index_next, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -688,22 +687,12 @@ fn should_throw_error_if_signer_has_incorrect_index() {
|
||||
let storage_key = (session_index, transaction_hash, unique_transaction_hash);
|
||||
|
||||
assert_claps_info_correct(&storage_key, &session_index, 0);
|
||||
let clap = Clap {
|
||||
block_number: 420,
|
||||
removed: false,
|
||||
transaction_hash,
|
||||
session_index,
|
||||
authority_index: 1337,
|
||||
network_id,
|
||||
receiver: 69,
|
||||
amount: 420,
|
||||
};
|
||||
let authority = UintAuthorityId::from((1) as u64);
|
||||
let signature = authority.sign(&clap.encode()).unwrap();
|
||||
assert_err!(
|
||||
SlowClap::slow_clap(RuntimeOrigin::none(), clap, signature),
|
||||
Error::<Runtime>::NotAnAuthority
|
||||
);
|
||||
assert_invalid_signing_address(session_index, network_id, 69);
|
||||
assert_transaction_has_bad_signature(session_index, network_id, 69);
|
||||
assert_invalid_signing_address(session_index, network_id, 420);
|
||||
assert_transaction_has_bad_signature(session_index, network_id, 420);
|
||||
assert_invalid_signing_address(session_index, network_id, 1337);
|
||||
assert_transaction_has_bad_signature(session_index, network_id, 1337);
|
||||
assert_claps_info_correct(&storage_key, &session_index, 0);
|
||||
});
|
||||
}
|
||||
@ -956,8 +945,8 @@ fn should_avoid_applause_during_nullification_period() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_self_applause_if_enough_received_claps() {
|
||||
let zero: u64 = 0u64;
|
||||
fn should_self_applause_if_enough_claps() {
|
||||
let zero = 0u64;
|
||||
let (network_id, transaction_hash, unique_transaction_hash) =
|
||||
generate_unique_hash(None, None, None, None);
|
||||
let (_, receiver, amount) = get_mocked_metadata();
|
||||
@ -965,6 +954,7 @@ fn should_self_applause_if_enough_received_claps() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let _ = prepare_evm_network(Some(network_id), Some(0));
|
||||
let session_index = advance_session_and_get_index();
|
||||
let next_session_index = session_index.saturating_add(1);
|
||||
let storage_key = (session_index, transaction_hash, unique_transaction_hash);
|
||||
|
||||
assert_err!(
|
||||
@ -976,7 +966,7 @@ fn should_self_applause_if_enough_received_claps() {
|
||||
receiver,
|
||||
amount,
|
||||
),
|
||||
Error::<Runtime>::NotEnoughClaps
|
||||
Error::<Runtime>::NotEnoughClaps,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
@ -984,59 +974,34 @@ fn should_self_applause_if_enough_received_claps() {
|
||||
false
|
||||
);
|
||||
assert_eq!(Balances::balance(&receiver), zero);
|
||||
assert_eq!(
|
||||
BridgedInflationCurve::<RewardCurve, Runtime>::era_payout(zero, zero, zero),
|
||||
(zero, zero)
|
||||
);
|
||||
|
||||
assert_ok!(do_clap_from(session_index, network_id, 0, false));
|
||||
assert_ok!(do_clap_from(session_index, network_id, 1, false));
|
||||
|
||||
assert_eq!(
|
||||
pallet::ApplausesForTransaction::<Runtime>::get(&storage_key),
|
||||
false
|
||||
);
|
||||
assert_eq!(Balances::balance(&receiver), 0);
|
||||
|
||||
assert_err!(
|
||||
SlowClap::self_applause(
|
||||
RuntimeOrigin::signed(receiver),
|
||||
network_id,
|
||||
session_index,
|
||||
transaction_hash,
|
||||
receiver,
|
||||
amount,
|
||||
),
|
||||
Error::<Runtime>::NotEnoughClaps
|
||||
);
|
||||
assert_eq!(
|
||||
pallet::ApplausesForTransaction::<Runtime>::get(&storage_key),
|
||||
false
|
||||
);
|
||||
assert_eq!(Balances::balance(&receiver), 0);
|
||||
|
||||
Networks::on_finalize(System::block_number());
|
||||
|
||||
advance_session();
|
||||
let next_session_index = Session::session_index();
|
||||
let next_storage_key = (
|
||||
next_session_index,
|
||||
transaction_hash,
|
||||
unique_transaction_hash,
|
||||
);
|
||||
assert_ok!(do_clap_from(next_session_index, network_id, 2, false));
|
||||
|
||||
assert_err!(
|
||||
SlowClap::self_applause(
|
||||
RuntimeOrigin::signed(receiver),
|
||||
network_id,
|
||||
next_session_index,
|
||||
transaction_hash,
|
||||
receiver,
|
||||
amount,
|
||||
),
|
||||
Error::<Runtime>::NotEnoughClaps
|
||||
let mut fake_claps_in_session = sp_std::collections::btree_map::BTreeMap::new();
|
||||
fake_claps_in_session.insert(
|
||||
1,
|
||||
SessionAuthorityInfo {
|
||||
claps: 1,
|
||||
disabled: false,
|
||||
},
|
||||
);
|
||||
fake_claps_in_session.insert(
|
||||
2,
|
||||
SessionAuthorityInfo {
|
||||
claps: 1,
|
||||
disabled: false,
|
||||
},
|
||||
);
|
||||
|
||||
let mut fake_received_clap =
|
||||
BoundedBTreeSet::<AuthIndex, <Runtime as pallet::Config>::MaxAuthorities>::new();
|
||||
assert_eq!(fake_received_clap.try_insert(1).unwrap(), true);
|
||||
assert_eq!(fake_received_clap.try_insert(2).unwrap(), true);
|
||||
|
||||
pallet::ReceivedClaps::<Runtime>::insert(&storage_key, fake_received_clap);
|
||||
pallet::ClapsInSession::<Runtime>::insert(&next_session_index, fake_claps_in_session);
|
||||
|
||||
assert_ok!(SlowClap::self_applause(
|
||||
RuntimeOrigin::signed(receiver),
|
||||
network_id,
|
||||
@ -1049,10 +1014,37 @@ fn should_self_applause_if_enough_received_claps() {
|
||||
pallet::ApplausesForTransaction::<Runtime>::get(&storage_key),
|
||||
true
|
||||
);
|
||||
assert_eq!(Balances::balance(&receiver), amount);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_avoid_session_overlap_on_mended_session_index() {
|
||||
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 _ = prepare_evm_network(Some(network_id), Some(0));
|
||||
let session_index = advance_session_and_get_index();
|
||||
let storage_key = (session_index, transaction_hash, unique_transaction_hash);
|
||||
|
||||
assert_ok!(do_clap_from(session_index, network_id, 0, false));
|
||||
advance_session();
|
||||
|
||||
assert_eq!(
|
||||
pallet::ApplausesForTransaction::<Runtime>::get(&next_storage_key),
|
||||
pallet::ApplausesForTransaction::<Runtime>::get(&storage_key),
|
||||
false
|
||||
);
|
||||
assert_eq!(Balances::balance(&receiver), 0u64);
|
||||
|
||||
assert_ok!(do_clap_from(session_index, network_id, 1, false));
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user