forked from ghostchain/ghost-node
		
	tests for clap and applause events added
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
		
							parent
							
								
									2c2df5a607
								
							
						
					
					
						commit
						a00eec9bb9
					
				@ -1,6 +1,6 @@
 | 
			
		||||
[package]
 | 
			
		||||
name = "ghost-slow-clap"
 | 
			
		||||
version = "0.3.20"
 | 
			
		||||
version = "0.3.21"
 | 
			
		||||
description = "Applause protocol for the EVM bridge"
 | 
			
		||||
license.workspace = true
 | 
			
		||||
authors.workspace = true
 | 
			
		||||
 | 
			
		||||
@ -573,11 +573,11 @@ impl<T: Config> Pallet<T> {
 | 
			
		||||
                return Ok(())
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            let incoming_fee = T::NetworkDataHandler::get(&clap.network_id)
 | 
			
		||||
            let commission = T::NetworkDataHandler::get(&clap.network_id)
 | 
			
		||||
                .map(|network_data| Perbill::from_parts(network_data.incoming_fee))
 | 
			
		||||
                .unwrap_or_default();
 | 
			
		||||
                .unwrap_or_default()
 | 
			
		||||
                .mul_ceil(clap.amount);
 | 
			
		||||
 | 
			
		||||
            let commission = incoming_fee.mul_ceil(clap.amount);
 | 
			
		||||
            let final_amount = clap.amount
 | 
			
		||||
                .checked_sub(&commission)
 | 
			
		||||
                .map(|value| T::Currency::minimum_balance()
 | 
			
		||||
 | 
			
		||||
@ -660,7 +660,70 @@ fn should_self_applause_if_enough_received_claps() {
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TODO: check event
 | 
			
		||||
#[test]
 | 
			
		||||
fn should_emit_event_on_each_clap_and_on_applause() {
 | 
			
		||||
    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 commission = Perbill::from_parts(100_000_000); // 10%
 | 
			
		||||
        let commission_amount = commission.mul_ceil(amount);
 | 
			
		||||
        let amount_after_commission = amount.saturating_sub(commission_amount);
 | 
			
		||||
        let _ = prepare_evm_network(Some(network_id), Some(100_000_000));
 | 
			
		||||
        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_claps_info_correct(&storage_key, &session_index, 0);
 | 
			
		||||
        assert_ok!(do_clap_from(session_index, network_id, 0, false));
 | 
			
		||||
        System::assert_last_event(RuntimeEvent::SlowClap(
 | 
			
		||||
                crate::Event::Clapped {
 | 
			
		||||
                    receiver: receiver.clone(),
 | 
			
		||||
                    authority_id: 0,
 | 
			
		||||
                    network_id,
 | 
			
		||||
                    transaction_hash,
 | 
			
		||||
                    amount,
 | 
			
		||||
                }));
 | 
			
		||||
 | 
			
		||||
        assert_eq!(pallet::ApplausesForTransaction::<Runtime>::get(&storage_key), false);
 | 
			
		||||
        assert_claps_info_correct(&storage_key, &session_index, 1);
 | 
			
		||||
        assert_ok!(do_clap_from(session_index, network_id, 1, false));
 | 
			
		||||
        let binding = System::events();
 | 
			
		||||
        let last_two_events = binding
 | 
			
		||||
            .iter()
 | 
			
		||||
            .rev()
 | 
			
		||||
            .take(5)
 | 
			
		||||
            .collect::<Vec<_>>();
 | 
			
		||||
        assert_eq!(last_two_events[0].event, RuntimeEvent::SlowClap(
 | 
			
		||||
                crate::Event::Applaused {
 | 
			
		||||
                    network_id,
 | 
			
		||||
                    receiver: receiver.clone(),
 | 
			
		||||
                    received_amount: amount_after_commission,
 | 
			
		||||
                }));
 | 
			
		||||
        assert_eq!(last_two_events[4].event, RuntimeEvent::SlowClap(
 | 
			
		||||
                crate::Event::Clapped {
 | 
			
		||||
                    receiver: receiver.clone(),
 | 
			
		||||
                    authority_id: 1,
 | 
			
		||||
                    network_id,
 | 
			
		||||
                    transaction_hash,
 | 
			
		||||
                    amount,
 | 
			
		||||
                }));
 | 
			
		||||
 | 
			
		||||
        assert_eq!(pallet::ApplausesForTransaction::<Runtime>::get(&storage_key), true);
 | 
			
		||||
        assert_claps_info_correct(&storage_key, &session_index, 2);
 | 
			
		||||
        assert_ok!(do_clap_from(session_index, network_id, 2, false));
 | 
			
		||||
        System::assert_last_event(RuntimeEvent::SlowClap(
 | 
			
		||||
                crate::Event::Clapped {
 | 
			
		||||
                    receiver: receiver.clone(),
 | 
			
		||||
                    authority_id: 2,
 | 
			
		||||
                    network_id,
 | 
			
		||||
                    transaction_hash,
 | 
			
		||||
                    amount,
 | 
			
		||||
                }));
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TODO: multiple logs will create multiple records
 | 
			
		||||
// TODO: errors should be checked as much as possible
 | 
			
		||||
// TODO: offences generated as expected
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user