Substrate Pallet Test Framework (CC3 Protocol)
๐ญ Overview
A purpose-built test framework for validating Substrate blockchain pallets on the Creditcoin 3 network. Testing a custom blockchain runtime is fundamentally different from testing a REST API โ there's no existing framework, no easy mocking, and bugs can mean irreversible on-chain state changes. This framework was built from first principles to cover the full pallet surface.
๐ ๏ธ What I Built
๐๏ธ Framework Architecture
- โ๏ธ Polkadot.js API integration: connects to live Substrate nodes (testnet, devnet, dryrun) and submits extrinsics programmatically
- ๐ง Dynamic extrinsic calling: generic helpers for calling any pallet extrinsic by name, enabling tests to be written at a high level without hard-coding ABI knowledge
- ๐ Multi-environment support: single test suite runs against testnet, devnet, or dryrun via environment variable configuration
- ๐ Allure integration: structured test reporting with step-level annotations, screenshots on failure, and test history tracking
๐ Staking Lifecycle Coverage
- ๐ Full staking lifecycle:
bondโnominateโunbondโwithdraw_unbondedโpayout_stakers - โ ๏ธ Edge cases: bonding with insufficient funds, nominating non-validators, unbonding during active era
- ๐ฐ Reward payout correctness: validates payout amounts against expected era points and commission rates
๐ Grandpa Migration Tests
- ๐ Validates the Grandpa consensus migration path from the legacy chain to CC3
- โ State correctness assertions: account balances, staking positions, and validator sets post-migration
- ๐งช Run against devnet fork to verify migration scripts before mainnet execution
๐ Precompile Testing
- ๐ BN128 curve precompile: validates elliptic curve operations (add, mul, pairing) at the EVM precompile address
- โ๏ธ Signature verifier precompile: validates ECDSA signature recovery for Ethereum-compatible address derivation
- โ Cross-validates precompile outputs against reference implementations
๐ฆ Test Data Management
- ๐ค Nomination account fixtures for deterministic test environments
- ๐ CSV-based test vector loading for parameterized tests across multiple account states
- ๐งน On-chain state cleanup helpers for test isolation
โญ Key Highlights
- ๐งช Testing a custom blockchain runtime from scratch โ no existing framework to extend
- ๐ง Dynamic extrinsic calling covers any pallet without per-extrinsic boilerplate
- ๐ Allure reporting provides structured observability for QA team and stakeholders
- ๐ Multi-environment: same test suite validates testnet, devnet, and dryrun environments
- ๐ Caught 3 critical staking edge-case bugs before mainnet deployment