-
Hi i am having trouble figuring out why this test passes when it doesn't in the video, function testFailsWithoutEnoughETH() public {
vm.expectRevert(); // hey, the next line, should revert.
// assert(this tx Fail/reverts)
uint256 cat = 1;
}
```
and i get this pass output: foundry-fund-me$ forge test --mt testFailsWithoutEnoughETH Ran 1 test for test/FundMeTest.t.sol:FundMeTest Ran 1 test suite in 20.89ms (893.68µs CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)
function testFailsWithoutEnoughETH() public {
tried looking for an answer unsuccessfully would really appreciate a hand with this, please, thanks.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hello @Hamobcdev, Foundry now has a feature where if you name a test function with the So, let's understand why your test function seems to be behaving abnormally. ** TEST 1 ** function testFailsWithoutEnoughETH() public {
vm.expectRevert(); // hey, the next line should revert.
// assert(this tx Fail/reverts)
uint256 cat = 1;
} So the main point is that if you already name a test function with a TEST CODE function testFailsWithoutEnoughETH1() public {
// vm.expectRevert(); // hey, the next line, should revert.
// assert(this tx Fail/reverts)
uint256 cat = 1;
} TEST OUTPUT Ran 1 test for test/unit/FundMeTest.t.sol:FundMeTest
[FAIL. Reason: assertion failed] testFailsWithoutEnoughETH1() (gas: 143)
Traces:
[2440785] FundMeTest::setUp()
├─ [1057798] → new DeployFundMe@0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f
│ └─ ← [Return] 5173 bytes of code
├─ [1300315] DeployFundMe::run()
│ ├─ [427567] → new HelperConfig@0x104fBc016F4bb334D775a19E8A6510109AC63E00
│ │ └─ ← [Return] 2025 bytes of code
│ ├─ [413423] HelperConfig::getAnvilNetworkConfig()
│ │ ├─ [0] VM::startBroadcast()
│ │ │ └─ ← [Return]
│ │ ├─ [377461] → new MockV3Aggregator@0x90193C961A926261B756D1E5bb255e67ff9498A1
│ │ │ └─ ← [Return] 1108 bytes of code
│ │ ├─ [0] VM::stopBroadcast()
│ │ │ └─ ← [Return]
│ │ └─ ← [Return] MockV3Aggregator: [0x90193C961A926261B756D1E5bb255e67ff9498A1]
│ ├─ [0] VM::startBroadcast()
│ │ └─ ← [Return]
│ ├─ [370298] → new FundMe@0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496
│ │ └─ ← [Return] 1848 bytes of code
│ ├─ [0] VM::stopBroadcast()
│ │ └─ ← [Return]
│ └─ ← [Return] FundMe: [0xA8452Ec99ce0C64f20701dB7dD3abDb607c00496]
├─ [0] VM::deal(Owner: [0x93B07479cC807d037A98B6bB122CE8201958a595], 100000000000000000000 [1e20])
│ └─ ← [Return]
└─ ← [Stop]
[143] FundMeTest::testFailsWithoutEnoughETH1()
└─ ← [Stop]
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 13.19ms (135.46µs CPU time)
Ran 1 test suite in 1.75s (13.19ms CPU time): 0 tests passed, 1 failed, 0 skipped (1 total tests)
Failing tests:
Encountered 1 failing test in test/unit/FundMeTest.t.sol:FundMeTest
[FAIL. Reason: assertion failed] testFailsWithoutEnoughETH1() (gas: 143) TEST 2 function testFailsWithoutEnoughETH() public {
vm.expectRevert(); // hey, the next line should revert.
// assert(this tx Fail/reverts)
fundMe.fund(); //send 0 value
} I ran the test excluding the TEST CODE function testFailsWithoutEnoughETH() public {
// vm.expectRevert(); // hey, the next line, should revert.
// // assert(this tx Fail/reverts)
fundMe.fund(); //send 0 value
} TEST OUTPUT Ran 1 test for test/unit/FundMeTest.t.sol:FundMeTest
[PASS] testFailsWithoutEnoughETH() (gas: 17952)
Traces:
[17952] FundMeTest::testFailsWithoutEnoughETH()
├─ [12710] FundMe::fund()
│ ├─ [8993] MockV3Aggregator::latestRoundData() [staticcall]
│ │ └─ ← [Return] 1, 100000000000 [1e11], 1, 1, 1
│ └─ ← [Revert] revert: You didn't send enough ether
└─ ← [Revert] revert: You didn't send enough ether
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 15.72ms (444.61µs CPU time) Please let us know if you still need clarification. |
Beta Was this translation helpful? Give feedback.
-
You guys saved me, too! Thank you so much!! |
Beta Was this translation helpful? Give feedback.
Anytime, Friend. I am glad I could help. You can mark the discussion as answered.