Skip to content

Commit

Permalink
tests: added unit test for single tx per deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
Janislav committed Feb 22, 2025
1 parent 5ada13a commit 241b8bf
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 6 deletions.
7 changes: 1 addition & 6 deletions state-chain/pallets/cf-ingress-egress/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1788,17 +1788,12 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
.ok_or(Error::<T, I>::InvalidDepositAddress)?;

if let Some(tx_ids) = deposit_details.deposit_ids() {
// log_or_panic!(
// "number of tx_ids isnt 1 for a prewitnessed deposit",
// tx_ids.len() == 1
// );

// TODO: Handle this without a potential panic.
let tx_id = tx_ids
.first()
.expect("there must be exactly one tx_id for a prewitnessed deposit.");

if TransactionsMarkedForRejection::<T, I>::mutate(&owner, &tx_id, |opt| {
if TransactionsMarkedForRejection::<T, I>::mutate(&owner, tx_id, |opt| {
match opt.as_mut() {
// Transaction has been reported, mark it as pre-witnessed.
Some(status @ TransactionPrewitnessedStatus::Unseen) => {
Expand Down
63 changes: 63 additions & 0 deletions state-chain/pallets/cf-ingress-egress/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2059,3 +2059,66 @@ fn failed_ccm_deposit_can_deposit_event() {
);
});
}

#[cfg(test)]
mod ethereum_screener {
use super::*;
use cf_chains::evm::H256;
use std::str::FromStr;

use crate::TransactionsMarkedForRejection;
use cf_traits::{
mocks::account_role_registry::MockAccountRoleRegistry, AccountRoleRegistry, DepositApi,
};

#[test]
fn process_marked_transaction_and_expect_refund_with_single_tx() {
new_test_ext().execute_with(|| {
let tx_id = H256::from_str(
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
)
.unwrap();
assert_ok!(<MockAccountRoleRegistry as AccountRoleRegistry<Test>>::register_as_broker(
&BROKER,
));
let (_, deposit_address, block, _) = IngressEgress::request_liquidity_deposit_address(
BROKER,
eth::Asset::Eth,
0,
ForeignChainAddress::Eth(Default::default()),
)
.unwrap();
let deposit_address: <Ethereum as Chain>::ChainAccount =
deposit_address.try_into().unwrap();
let deposit_details = DepositDetails { tx_hashes: Some(vec![tx_id]) };
// Report the tx as marked for rejection
assert_ok!(IngressEgress::mark_transaction_for_rejection(
OriginTrait::signed(BROKER),
tx_id,
));

assert!(TransactionsMarkedForRejection::<Test, ()>::get(BROKER, tx_id).is_some());
// Process the deposit
assert_ok!(IngressEgress::process_single_deposit(
deposit_address,
eth::Asset::Eth,
DEFAULT_DEPOSIT_AMOUNT,
deposit_details,
block,
));

assert_has_matching_event!(
Test,
RuntimeEvent::IngressEgress(crate::Event::<Test, ()>::DepositIgnored {
deposit_address: _,
asset: eth::Asset::Eth,
amount: DEFAULT_DEPOSIT_AMOUNT,
deposit_details: _,
reason: DepositIgnoredReason::TransactionRejectedByBroker,
})
);

assert!(MockSwapRequestHandler::<Test>::get_swap_requests().is_empty());
});
}
}

0 comments on commit 241b8bf

Please sign in to comment.