Skip to content

chore(fee-processor): add regression tests and improve overall coverage#1410

Open
F3Joule wants to merge 4 commits intofeat/gigahdx-implfrom
f3/fee-processor-chore
Open

chore(fee-processor): add regression tests and improve overall coverage#1410
F3Joule wants to merge 4 commits intofeat/gigahdx-implfrom
f3/fee-processor-chore

Conversation

@F3Joule
Copy link
Copy Markdown
Contributor

@F3Joule F3Joule commented Apr 6, 2026

Overview

This PR improves test coverage for pallet-fee-processor and pallet-referrals following the fee processing refactor. It also aligns the test mock with the production HdxFeeReceivers configuration.

Found issues / follow-up

  • ⚠️ process_trade_fee(amount=0) inserts asset into PendingConversions despite no tokens being transferred, leading to infinite failed conversions in on_idle. Needs a decision: early return on zero amount, or guard in do_convert.
  • ⚠️ No governance extrinsic exists to force-remove an asset from PendingConversions. A permanently failing asset (e.g. no liquidity pool) will consume an on_idle slot every block indefinitely.

Changes

pallet-fee-processor

Mock updated to reflect production HDX receiver shape
Replaced the previous 2-receiver mock (50/50 including a fake referrals receiver) with 3 receivers matching the structural shape of the runtime config:

  • HdxGigaHdxFeeReceiver — 70%
  • HdxGigaRewardFeeReceiver — 20%
  • HdxStakingFeeReceiver — 10%

Referrals is not part of the HDX fee path and has been removed from HdxFeeReceivers in the mock accordingly.

New tests — convert.rs

  • on_idle_retries_failed_conversion_on_next_block - confirms retry behavior (intentional divergence from old referrals pallet which removed failed assets)
  • convert_extrinsic_for_asset_not_in_pending_still_executes - documents permissionless nature of do_convert
  • on_idle_returns_zero_when_weight_below_single_conversion - verifies weight guard early exit
  • on_idle_processes_only_one_when_weight_fits_exactly_one - verifies weight budget precision
  • distribute_to_pots_uses_total_param_not_actual_pot_balance - regression test for suspicious unused _balance read at lib.rs:280; confirms pre-existing HDX on pot is not redistributed

New tests — process_fee.rs

  • process_trade_fee_same_asset_twice_does_not_duplicate_pending_count
  • process_trade_fee_fails_when_source_has_insufficient_balance
  • process_trade_fee_nothing_changes_when_pre_deposit_callback_fails - confirms Substrate transactional rollback, so we are sure no assets stuck on pot because of failing handler.

pallet-referrals

New tests — accumulator.rs (new file)

Covers the new reward-per-share accumulator logic that replaced the old share-based distribution:

  • on_hdx_deposited_bumps_reward_per_share_correctly
  • on_hdx_deposited_does_nothing_when_total_shares_is_zero
  • on_hdx_deposited_accumulates_correctly_over_multiple_calls
  • on_fee_received_calculates_shares_correctly_for_all_parties
  • on_fee_received_skips_referrer_share_when_no_code_linked
  • on_fee_received_external_account_none_shares_dropped
  • checkpoint_user_accumulates_pending_rewards_before_share_change
  • claim_rewards_cannot_double_claim_via_debt_mechanism
  • claim_rewards_combines_accumulated_and_pending_rewards

ExtBuilder extended with with_reward_per_share, with_user_reward_debts, with_user_accumulated_rewards builders to support accumulator state setup in tests.

@F3Joule F3Joule requested a review from enthusiastmartin April 6, 2026 14:08
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 6, 2026

Crate versions that have not been updated:

  • pallet-fee-processor: v0.1.0
  • pallet-referrals: v1.5.0

Runtime version has not been increased.

@F3Joule F3Joule self-assigned this Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant