Skip to content

Invariant test fuzzed functions always use msg.value == 0 #8449

@Melvillian

Description

@Melvillian

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (ea7817c 2024-07-16T00:18:48.894654000Z)

What command(s) is the bug in?

forge test

Operating System

macOS (Apple Silicon)

Describe the bug

tl;dr: It looks like both from personal testing with console.log on my invariant tested contracts, and from reading the forge Rust code, that for invariant tests the fuzzed function calls always use a value of 0 for msg.value. Is this true? And if so, is there a way to change this via some config value? My code under test needs non-zero values for msg.value, otherwise nothing interesting will happen in my tests.

Context:
I am writing a simple kickstarter clone app here: https://github.com/Melvillian/crowdfund-project. If you clone that repo and run forge test --match-test invariant -vvvvv, you will find in the console.log'ed output that the msg.value parameter of every call to the TestProject.contribute function is equal to 0. This is a problem because for TestProject.contribute to work it needs to have a non-zero value for msg.value.

From perusing the forge code, it looks like passing 0 for msg.value is the intended result, based on this line here. Note, since there are several functions that look like they could be the one that actually calls the function that fuzzes the contract, I'm not sure if that is the correct line for where the msg.value == 0 is set, so correct me if I'm wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions