Decoding Hardhat Test Output: A Complete Guide to Contract Health and Gas Costs
This article walks through a typical Hardhat test run, explaining each section of the console report—from compilation details and individual test results to gas usage, network configuration, and deployment costs—so developers can assess contract correctness, performance, and optimization opportunities.
Compilation and Test Results
npx hardhat test
Compiled 1 Solidity file successfully (evm target: paris).
Lock
Deployment
✔ Should set the right unlockTime (58ms)
✔ Should set the right owner
✔ Should receive and store the funds to lock
✔ Should fail if the unlockTime is not in the future
Withdrawals
Validations
✔ Should revert with the right error if called too soon
✔ Should revert with the right error if called from another account
✔ Shouldn't fail if the unlockTime has arrived and the owner calls it
Events
✔ Should emit an event on withdrawals
Transfers
✔ Should transfer the funds to the owner
9 passing (121ms)The output shows that Hardhat compiled a single Solidity source targeting the Paris EVM version and then executed a hierarchical test suite for the Lock contract. All nine test cases passed, indicating functional correctness for deployment, owner assignment, fund locking, time‑based withdrawal validation, event emission, and fund transfer.
Gas Reporter Output
Solidity and Network Settings
Solidity: 0.8.28– compiler version used for the build. Optim: false – optimizer disabled; production builds typically enable it ( true) to reduce gas. Runs: 200 – optimizer parameter that assumes each function will be called 200 times (relevant only when Optim is true). viaIR: false – compilation did not use the intermediate‑representation pipeline. Block: 30,000,000 gas – simulated block gas limit for the test environment.
Method Gas Consumption
withdraw – average gas consumption 34,096 gas per call, with 7 total invocations during the test run.
The report also lists minimum, maximum, and average values for each external/public function, as well as the number of calls. The USD column is empty because no gas price was configured.
Deployment Gas Consumption
Average deployment cost for the Lock contract: 326,112 gas .
This represents 1.1 % of the simulated block gas limit, a useful metric for assessing whether the contract size may cause deployment failures on networks with tighter limits.
Key Takeaways
Functional correctness: All nine test cases passed, confirming that the contract behaves as expected under both positive and negative scenarios.
Test coverage: The suite covers deployment state, owner assignment, fund locking, time‑based withdrawal validation, event emission, and fund transfer, providing a solid baseline for contract quality.
Performance and cost insights: The average gas cost of the withdraw function (34 k gas) and the deployment cost (326 k gas) highlight optimization opportunities. High deployment gas may suggest contract splitting or storage layout refinement, while unusually high function gas warrants a deeper code review for inefficiencies.
Regularly running npx hardhat test and reviewing the Hardhat gas reporter output enables developers to iteratively improve smart contract security, reliability, and cost efficiency before main‑net deployment.
Ops Development & AI Practice
DevSecOps engineer sharing experiences and insights on AI, Web3, and Claude code development. Aims to help solve technical challenges, improve development efficiency, and grow through community interaction. Feel free to comment and discuss.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
