Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: constructor() payable {} does not work correctly with code coverage #9270

Closed
StackOverflowExcept1on opened this issue Nov 5, 2024 · 0 comments · Fixed by #9288
Closed
Assignees
Labels
C-forge Command: forge Cmd-forge-coverage Command: forge coverage T-bug Type: bug
Milestone

Comments

@StackOverflowExcept1on
Copy link
Contributor

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

contract Counter {
    constructor() payable {}

    function increment() public {}
}
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

import {Test, console} from "forge-std/Test.sol";
import {Counter} from "../src/Counter.sol";

contract CounterTest is Test {
    Counter public counter;

    function setUp() public {
        counter = new Counter();
    }

    function test_Increment() public {
        counter.increment();
    }
}
$ forge coverage
[⠊] Compiling...
[⠢] Compiling 25 files with Solc 0.8.28
[⠔] Solc 0.8.28 finished in 2.15s
Compiler run successful!
Analysing contracts...
Running tests...

Ran 1 test for test/Counter.t.sol:CounterTest
[PASS] test_Increment() (gas: 5358)
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 2.46ms (88.42µs CPU time)

Ran 1 test suite in 5.14ms (2.46ms CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)
| File            | % Lines       | % Statements  | % Branches    | % Funcs      |
|-----------------|---------------|---------------|---------------|--------------|
| src/Counter.sol | 100.00% (0/0) | 100.00% (0/0) | 100.00% (0/0) | 50.00% (1/2) |
| Total           | 100.00% (0/0) | 100.00% (0/0) | 100.00% (0/0) | 50.00% (1/2) |

when you remove payable the coverage becomes 100%

@DaniPopes DaniPopes transferred this issue from foundry-rs/forge-std Nov 6, 2024
@DaniPopes DaniPopes added C-forge Command: forge Cmd-forge-coverage Command: forge coverage labels Nov 6, 2024
@zerosnacks zerosnacks added the T-bug Type: bug label Nov 6, 2024
@zerosnacks zerosnacks changed the title constructor() payable {} does not work correctly with code coverage bug: constructor() payable {} does not work correctly with code coverage Nov 6, 2024
@zerosnacks zerosnacks added this to the v1.0.0 milestone Nov 6, 2024
@grandizzy grandizzy self-assigned this Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge Cmd-forge-coverage Command: forge coverage T-bug Type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants