Interview Questions

Get ready for your next interview with our comprehensive question library

Foundry Interview Questions

Filter by Difficulty

1.

How do you initialize a new Foundry project?

beginner

You initialize a new Foundry project using the forge init command:

forge init my-project
cd my-project

This creates a standard project structure with:

  • src/ - Smart contract source files
  • test/ - Test files
  • script/ - Deployment and interaction scripts
  • foundry.toml - Configuration file
  • lib/ - Dependencies/libraries
2.

Explain the basic structure of a Foundry test and how to run tests.

beginner

Foundry tests are written in Solidity and follow a specific naming convention. Test functions must start with test and test contracts should inherit from Test:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
import "../src/Counter.sol";
contract CounterTest is Test {
    Counter public counter;
    function setUp() public {
        counter = new Counter();
    }
    function testIncrement() public {
        counter.increment();
        assertEq(counter.number(), 1);
    }
}

Run tests using:

forge test                    # Run all tests
forge test --match-test testIncrement  # Run specific test
forge test -vvv              # Verbose output
3.

What are the different verbosity levels in Forge testing?

beginner

Forge provides multiple verbosity levels controlled by the number of v flags:

  • Default: Shows test results only
  • -v: Shows logs for failing tests
  • -vv: Shows logs for all tests and gas usage
  • -vvv: Shows execution traces for failing tests
  • -vvvv: Shows execution traces for all tests and setup
  • -vvvvv: Shows execution and setup traces, plus internal steps
    Higher verbosity levels are crucial for debugging failed tests and understanding gas consumption patterns.
4.

Explain how to manage dependencies in Foundry.

beginner

Upgrade to Premium to see the answer

Upgrade to Premium
5.

What is the difference between `forge build` and `forge compile`?

beginner

Upgrade to Premium to see the answer

Upgrade to Premium
6.

How do you handle testing of view functions and state queries?

beginner

Upgrade to Premium to see the answer

Upgrade to Premium
7.

How do you handle test fixtures and setup in Foundry?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
8.

Explain fuzzing in Foundry and provide an example.

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
9.

What are cheatcodes in Foundry and give examples of commonly used ones?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
10.

How do you test events in Foundry?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
11.

How do you deploy contracts using Foundry scripts?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
12.

How do you handle different network configurations in Foundry?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
13.

How do you perform fork testing in Foundry?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
14.

How do you debug failing tests in Foundry?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
15.

What are some best practices for organizing Foundry test suites?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
16.

How do you configure and use Foundry with continuous integration (CI)?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
17.

How do you perform invariant testing (stateful fuzzing) in Foundry?

expert

Upgrade to Premium to see the answer

Upgrade to Premium
18.

How do you optimize gas usage when testing with Foundry?

expert

Upgrade to Premium to see the answer

Upgrade to Premium
19.

How do you handle upgradeable contracts testing in Foundry?

expert

Upgrade to Premium to see the answer

Upgrade to Premium
20.

How do you interact with external APIs or oracles in Foundry tests?

expert

Upgrade to Premium to see the answer

Upgrade to Premium
Showing 1 to 20 of 21 results

Premium Plan

$10.00 /monthly
  • Access all premium content - interview questions, and other learning resources

  • We regularly update our features and content, to ensure you get the most relevant and updated premium content.

  • 1000 monthly credits

  • Cancel anytime