Web3 testing differs from web2 testing in six main places: environment setup, state, async behavior, security, performance, and authentication. I moved from web2 test automation to web3 projects, and these are the differences that cost me the most time.
Web2 vs web3 in one paragraph
Web2 is the internet most of us test daily: centralized, with servers run by one company. Web3 apps run on a blockchain, so logic and state live in smart contracts that nobody can quietly patch or roll back.
Key differences in web2 vs web3 testing
1. Environment setup
Web2: You set up a local environment, maybe a staging server, and you’re done.
Web3: You need a local blockchain, one or more testnets, and often a fork of mainnet. It’s the difference between microwaving a meal and cooking one from scratch.
Example, a Hardhat config that forks mainnet so tests run against real deployed contracts:
// hardhat.config.js
require('@nomicfoundation/hardhat-toolbox');
module.exports = {
solidity: '0.8.28',
networks: {
hardhat: {
forking: {
url: process.env.MAINNET_RPC_URL, // from your RPC provider
blockNumber: 21000000, // pin a block so runs are repeatable
},
},
},
};
Pinning the block matters. Without it, every run forks the latest state and a test that passed yesterday can fail today. For setup details, see automated testing setup for smart contracts.
2. State management
Web2: State sits on the server or in the browser. Resetting it means clearing a database or local storage.
Web3: State lives on the blockchain. Resetting it means redeploying contracts or restarting your local chain. Possible, but a lot more work.
3. Asynchronous operations
Web2: Async work is mostly API calls and database queries.
Web3: Every transaction has to be mined and confirmed. Sometimes that takes a second, sometimes much longer, and your test has to wait for it. On a local chain blocks are instant, so the same test behaves differently from how it does on a public network.
// Web3 transaction wait (ethers v6)
const tx = await contract.someFunction();
await tx.wait(2); // resolves after 2 block confirmations
4. Security testing
Web2: XSS, CSRF, SQL injection.
Web3: Smart contract vulnerabilities: reentrancy, front-running, and badly optimized gas usage. A bug here can drain funds, and you can’t patch a deployed contract the way you patch a server. Upgradeable contracts add their own failure modes, covered in testing smart contract upgrades.
5. Performance testing
Web2: Load and stress testing.
Web3: Gas optimization. You still care how many users the app can handle, but you also care how much blockchain resource each call uses, because users pay for it. I show how to turn that into a failing test in gas optimization through testing.
6. User authentication
Web2: Username and password, OAuth, maybe 2FA.
Web3: Wallets and signatures. Users prove who they are by signing a message with their private key, and your tests need to do the same.
// Web3 authentication example (ethers v6)
const message = 'Login to MyAwesomeWeb3App';
const signature = await signer.signMessage(message);
// Backend side: recover the address that signed the message
const recovered = ethers.verifyMessage(message, signature);
expect(recovered).to.equal(signer.address);
Production sign-in should use a standard such as Sign-In with Ethereum (EIP-4361), which adds a nonce and domain to prevent replay. Test that a reused nonce is rejected.
Common web3 testing problems and how to solve them
1. Non-deterministic tests
Randomness and changing chain state make tests hard to repeat. Pin the fork block, seed any random inputs, and log the seed so a failure can be replayed.
2. Slow tests
Waiting for confirmations drags tests out on public networks. Run on a local chain and use time travel instead of waiting:
const { time } = require('@nomicfoundation/hardhat-network-helpers');
await time.increase(7 * 24 * 60 * 60); // jump a week ahead instantly
3. Gas costs
Tests get expensive and slow on public testnets. Run most tests on a local chain or a forked mainnet, where gas is free.
4. Complex state
Chain state is interdependent, so tests affect each other. Hardhat’s loadFixture deploys once, takes a snapshot, and reverts to it before every test:
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
async function deployFixture() {
const [owner, user] = await ethers.getSigners();
const token = await ethers.deployContract('Token');
return { token, owner, user };
}
it('starts from a clean state', async () => {
const { token, user } = await loadFixture(deployFixture);
expect(await token.balanceOf(user.address)).to.equal(0n);
});
Each test gets the state right after deployment, no matter what earlier tests did, and you pay the deployment cost once.
Web3 testing takes more setup, not a different job
The core job is the same: find what breaks before users do. What changes is the setup cost, the price of a missed bug, and how much you need to understand the chain underneath. That price is what drives the budget, which I break down in how much web3 testing costs.
More on this in the web3 testing posts.