Testing smart contracts properly
We start with unit tests in Foundry or Hardhat covering every function, access rule and revert condition, then add fork tests that run your contracts against real mainnet state. Coverage reports guide gaps, but coverage alone proves little, so tests are written around invariants such as total supply never exceeding a cap. We also test the failure paths on purpose: out-of-gas conditions, failed external calls, paused states and malicious token behavior, since users meet these far more often than the happy path.
Property-based testing and fuzzing with Foundry's fuzzer, Echidna or Medusa generate thousands of unexpected inputs and call sequences. Static analysis with Slither and symbolic tools find reentrancy, arithmetic and authorization flaws. For Solana programs we test with Anchor, Mollusk and Trident-style fuzzing. Gas usage is measured per function and compared across changes, so an innocent refactor cannot quietly make a core operation too costly for ordinary users when the network becomes busy.