Skip to content

Add E2E tests to PSM pallet (Westend AH)#592

Open
rockbmb wants to merge 27 commits intomasterfrom
psm-e2e
Open

Add E2E tests to PSM pallet (Westend AH)#592
rockbmb wants to merge 27 commits intomasterfrom
psm-e2e

Conversation

@rockbmb
Copy link
Copy Markdown
Collaborator

@rockbmb rockbmb commented Apr 14, 2026

Closes #586.

The PSM pallet (polkadot-sdk#11068) is not deployed to any production chain. To run E2E tests against it, a custom PAH runtime was built with the pallet patched in and fed to Chopsticks via the ASSETHUBPOLKADOT_WASM environment variable.

EDIT: the PSM pallet has recently been deployed to WAH; the PR has been changed to use it instead. However, the below instructions are still valid to run PET tests against PAH/KAH (the runtimes branch contains all required changes for PAH; KAH is a matter of replication).

The patched runtime lives in the psm-e2e-runtime branch of the runtimes repository. To reproduce the build:

git clone -b psm-e2e-runtime git@github.com:rockbmb/runtimes.git
cd runtimes
cargo build -p asset-hub-polkadot-runtime --release

Then run:

ASSETHUBPOLKADOT_WASM=target/release/wbuild/asset-hub-polkadot-runtime/asset_hub_polkadot_runtime.compact.compressed.wasm yarn test -t psm
  • Core swaps: mint, redeem, roundtrip, minimum amount enforcement
    • mint USDC to pUSD — pUSD received > 0, debt equals mint amount, fee to insurance fund
    • mint then redeem — USDC returned > 0
    • mint below MIN_SWAP fails
  • Asset lifecycle: add/remove external assets, fee configuration, ceiling weight assignment
    • addExternalAsset with zero ceiling — mint fails
    • addExternalAsset then setCeiling — mint succeeds
    • zero debt then removeExternalAsset — asset is None
    • set custom fee, remove, re-add — fee resets to default
    • mint creates debt, removeExternalAsset blocked — asset still present
    • setMintingFee before adding asset — 3% fee applied on mint
  • Circuit breaker: MintingDisabled, AllDisabled, governance origin checks
    • MintingDisabled — mint fails, redeem succeeds
    • AllDisabled — both mint and redeem fail
    • MintingDisabled — debt unchanged, redeem reduces debt
    • signed setMintingFee without root fails
  • Value conservation: fee distribution to insurance fund, residual debt from fees
    • set 1% fees, mint and redeem all — insurance fund gain > 0
    • set 1% mint fee, mint 1000, redeem all pUSD — residual debt > 0
    • Bob redeems more than reserve — ExtrinsicFailed
    • fee 0% mint vs fee 5% mint — higher fee yields less pUSD
  • Ceiling dynamics: global debt ceiling, per-asset weight normalization, zero-weight blocking
    • mint 500, setMaxPsmDebt(1) blocks mint, restore allows mint
    • setMaxPsmDebt(10_000), fund USDT, mint USDC and USDT — total debt > 0
    • setAssetCeilingWeight(USDT, 0) — mint USDC succeeds, debt equals amount
    • setAssetCeilingWeight(USDC, 0) — mint fails despite AllEnabled circuit breaker
    • both assets at 75% weight — normalized to 50/50, enforced at boundary
    • setMaxPsmDebt(0) after minting both assets — mints blocked, redeems work
    • mint 500, zero maxPsmDebt — debt unchanged, mint blocked, redeem reduces debt
  • Reserve integrity: over-redemption rejection, multi-account behavior, debt accumulation
    • setMaxPsmDebt(5_000), mint 200 — debt > 0
    • mint 500, give Bob 2x debt pUSD, Bob redeems debt plus MIN_SWAP — ExtrinsicFailed
    • mint 500 then mint 200 more — debt > 500 UNIT
    • mint 500, redeem MIN_SWAP — Redeemed event
  • rebase psm-e2e-runtime branch onto main now that polkadot-sdk#11068 has been merged; verify that the extra scaffolding added to the PAH runtime still compiles and is compatible with the latest runtimes release
  • create assetHubWestend.psm.e2e.test.ts, and test PSM on WAH

rockbmb added 17 commits March 23, 2026 00:57
The `apply_authorized_upgrade` call is sensitive to scheduled
runtime upgrades; it's been removed.
When a real runtime upgrade is in progress at the fork block, upgrade tests
fail because the chain state conflicts with the test's own upgrade flow.

Add skipIfRealUpgradePending() helper that detects two conditions:
1. system.authorizedUpgrade is set (covers ALL chains including relay)
2. parachainSystem.pendingValidationCode is non-empty (parachain-specific)

When detected, the test is skipped via ctx.skip() instead of failing.
Wired into the two authorizeUpgradeWithoutChecks* wrapper functions only —
the authorizeUpgrade (with-checks) variants are unaffected since they
expect failure at SpecVersionNeedsToIncrease before reaching the
pending code check.
- Add psmStableAssetId (4242/pUSD), psmUsdcId (1337), psmUsdtId (1984)
- Inject PSM pallet storage via initStorages (Chopsticks dev.setStorage):
  MaxPsmDebtOfTotal=50%, ExternalAssets with AllEnabled for USDC+USDT,
  0.5% fees, 60/40 ceiling weights
- Pre-fund Alice/Bob with USDC and Alice with pUSD for swap tests
Also, fix previously failing tests; data about pUSD needed to exist
in storage for some of the tests to pass; in other cases, incorrect swap
amounts were being used.
@rockbmb rockbmb added this to the Advanced CUI/CUJ Coverage milestone Apr 14, 2026
@rockbmb rockbmb self-assigned this Apr 14, 2026
@rockbmb rockbmb added the e2e tests Related to end-to-end tests label Apr 14, 2026
@rockbmb rockbmb marked this pull request as ready for review April 16, 2026 17:38
@rockbmb rockbmb changed the title Add E2E tests to PSM pallet Add E2E tests to PSM pallet (Westend AH) Apr 16, 2026
@rockbmb
Copy link
Copy Markdown
Collaborator Author

rockbmb commented Apr 16, 2026

Concerning (and unrelated) failure in bifrostKusama.basilisk.xcm (88296838829683); I'll investigate this locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e tests Related to end-to-end tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E2E tests for pallet-psm (PSM / pUSD)

1 participant