0
0
Blockchain / Solidityprogramming~20 mins

Fork testing (mainnet fork) in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Fork Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Hardhat fork setup code?
Consider this Hardhat config snippet for mainnet forking. What will be the output when running a script that fetches the balance of an address on the forked network?
Blockchain / Solidity
import { ethers } from "hardhat";

async function main() {
  const provider = ethers.provider;
  const balance = await provider.getBalance("0x742d35Cc6634C0532925a3b844Bc454e4438f44e");
  console.log(ethers.formatEther(balance));
}

main();
ADisplays the ETH balance of the address on mainnet at the fork block
BThrows an error because the provider is not connected
CDisplays zero because the forked network is empty
DDisplays the balance in wei without formatting
Attempts:
2 left
💡 Hint
Remember that mainnet fork replicates the state at a specific block.
🧠 Conceptual
intermediate
1:30remaining
Which statement best describes mainnet fork testing?
Choose the correct description of mainnet fork testing in blockchain development.
AIt forks the mainnet to create a new public blockchain network.
BIt deploys contracts directly on the mainnet for live testing.
CIt simulates transactions without any real blockchain state.
DIt creates a local blockchain that replicates the mainnet state at a specific block for testing.
Attempts:
2 left
💡 Hint
Think about how developers test with real mainnet data safely.
🔧 Debug
advanced
2:00remaining
Why does this fork test script fail with 'invalid JSON RPC response'?
Given this Hardhat fork config and script, why does the script fail with 'invalid JSON RPC response' error? Config snippet: { forking: { url: "https://mainnet.infura.io/v3/INVALID_KEY", blockNumber: 15000000 } } Script tries to get block number from provider.
Blockchain / Solidity
const blockNumber = await ethers.provider.getBlockNumber();
console.log(blockNumber);
AThe script is missing await keyword causing a promise error.
BThe blockNumber is set to a future block that does not exist yet.
CThe Infura URL contains an invalid API key causing connection failure.
DThe provider is not initialized before calling getBlockNumber.
Attempts:
2 left
💡 Hint
Check the RPC URL and credentials.
📝 Syntax
advanced
1:30remaining
Which option correctly sets up a mainnet fork in Hardhat config?
Select the correct Hardhat config snippet to enable mainnet forking at block 16000000 using Alchemy RPC.
A{ forking: { url: "https://eth-mainnet.alchemyapi.io/v2/your-api-key", blockNumber: 16000000 } }
B{ forking: { url: "https://eth-mainnet.alchemyapi.io/v2/your-api-key", blockNumber: "16000000" } }
C{ forking: { endpoint: "https://eth-mainnet.alchemyapi.io/v2/your-api-key", block: 16000000 } }
D{ fork: { url: "https://eth-mainnet.alchemyapi.io/v2/your-api-key", block: 16000000 } }
Attempts:
2 left
💡 Hint
Check property names and syntax carefully.
🚀 Application
expert
2:30remaining
How many transactions are recorded after this fork test script runs?
You run a script on a mainnet fork that sends 3 transactions: 1. Transfer 1 ETH from account A to B 2. Deploy a contract 3. Call a function that reverts intentionally After the script finishes, how many transactions remain on the forked chain?
ANo transactions are recorded because it's a fork
BAll 3 transactions are recorded regardless of revert
COnly the deploy contract transaction is recorded
D2 transactions are recorded; the reverted one is discarded
Attempts:
2 left
💡 Hint
Think about how reverted transactions affect blockchain state.