Cyfrin Updraft.

Post

Share your knowledge.

thegreatfeez.
Jan 04, 2025
Expert Q&A

Foundry Solidity Test

What could wrong in my code?

 function testFundUpdatesFundedDataStructure() public {
        fundMe.fund{value: 10e18}();
        
        uint256 amountFunded = fundMe.getAddressToAmountFunded(address(this));
        assertEq(amountFunded, 10e18);
    }```

getting  this error:

 [14658] FundMeTest::testFundUpdatesFundedDataStructure()
    ├─ [2658] FundMe::fund{value: 1000000000000000000}()
    │   ├─ [0] 0x0000000000000000000000000000000000000000::latestRoundData() [staticcall]
    │   │   └─ ← [Stop] 
    │   └─ ← [Revert] EvmError: Revert
    └─ ← [Revert] EvmError: Revert
  • Cyfrin Updraft
  • Foundry
  • Solidity
1
3
Share
Comments
.

Answers

3
The8bitGHOST.
Jan 5 2025, 10:43

instead of this in

uint256 amountFunded = fundMe.getAddressToAmountFunded(address(this));

try using msg.sender

uint256 amountFunded = fundMe.getAddressToAmountFunded(address(msg.sender));
1
Comments
.
thegreatfeez.
Jan 5 2025, 16:05

it's still the same thing, this is the full error:

Ran 1 test for test/FundMeTest.t.sol:FundMeTest
[FAIL: EvmError: Revert] testFundUpdatesFundedDataStructure() (gas: 14658)
Traces:
  [2716771] FundMeTest::setUp()
    ├─ [1364919] → new DeployFundMe@0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f
    │   └─ ← [Return] 6707 bytes of code
    ├─ [1312235] DeployFundMe::run()
    │   ├─ [858779] → new HelperConfig@0x104fBc016F4bb334D775a19E8A6510109AC63E00
    │   │   ├─ [0] VM::startBroadcast()
    │   │   │   └─ ← [Return] 
    │   │   ├─ [367647] → new MockV3Aggregator@0x34A1D3fff3958843C43aD80F30b94c510645C316
    │   │   │   └─ ← [Return] 1059 bytes of code
    │   │   ├─ [0] VM::stopBroadcast()
    │   │   │   └─ ← [Return] 
    │   │   └─ ← [Return] 2153 bytes of code
    │   ├─ [358] HelperConfig::activeNetworkConfig() [staticcall]
    │   │   └─ ← [Return] 0x0000000000000000000000000000000000000000
    │   ├─ [0] VM::startBroadcast()
    │   │   └─ ← [Return] 
    │   ├─ [386177] → new FundMe@0x90193C961A926261B756D1E5bb255e67ff9498A1
    │   │   └─ ← [Return] 1806 bytes of code
    │   ├─ [0] VM::stopBroadcast()
    │   │   └─ ← [Return] 
    │   └─ ← [Return] FundMe: [0x90193C961A926261B756D1E5bb255e67ff9498A1]
    └─ ← [Stop] 

  [14658] FundMeTest::testFundUpdatesFundedDataStructure()
    ├─ [2658] FundMe::fund{value: 10000000000000000000}()
    │   ├─ [0] 0x0000000000000000000000000000000000000000::latestRoundData() [staticcall]
    │   │   └─ ← [Stop] 
    │   └─ ← [Revert] EvmError: Revert
    └─ ← [Revert] EvmError: Revert

Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 3.39ms (474.29µs CPU time)
1
Comments
.
The8bitGHOST.
Jan 5 2025, 17:58

can you share the fund function ?

0xcc0b...e70b.
Jan 10 2025, 05:10

Can you also share the full test suit? (Especially setUp function)

0
Comments
.

Do you know the answer?

Please log in and share it.

Cyfrin Updraft is an education platform specializing on teaching the next generation of smart contract developers

195Posts196Answers
We use cookies to ensure you get the best experience on our website.
More info