Cyfrin Updraft.

帖子

分享您的知识。

thegreatfeez.
Jan 04, 2025
专家问答

铸造厂坚固性测试

我的代码可能出什么问题?

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

出现这个错误:

 [14658] FundMeTest:: testfundUpdatesFundedDatesFundedDatesFundedD
 ├─ [2658] FundMe:: fund {价值:100000000000000000} ()
 │ ├─ [0] 0x000000000000000000000000000000000000000000:: latestRoundData () [静态调用]
 │ │ └─ ← [停止] 
 │ └─ ← [还原] evmError:还原
 └─ ← [还原] evmError:还原
  • Cyfrin Updraft
  • Foundry
  • Solidity
1
3
分享
评论
.

答案

3
The8bitGHOST.
Jan 5 2025, 10:43

而不是this

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

尝试使用 msg.sender

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

还是一回事,这是完整的错误:

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
评论
.
The8bitGHOST.
Jan 5 2025, 17:58

你能分享基金功能吗?

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

你还能分享完整的测试服吗?(特别是设置功能)

0
评论
.

你知道答案吗?

请登录并分享。

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

195帖子196答案
我们使用 cookie 确保您在我们的网站上获得最佳体验。
更多信息