Cyfrin Updraft.

Bài viết

Chia sẻ kiến thức của bạn.

Cyfrin Moderator Pst.
Mar 29, 2024
Hỏi đáp Chuyên Gia

Error: Undeclared identifier 'assert' when written in the test file

I followed a tutorial for writing tests in Solidity and imported Test from forge-std, but I encountered an error stating 'Undeclared identifier. Did you mean 'assert'?' Here is a snippet of my code:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import {Test, console} from 'forge-std/Test.sol';
import {FundMe} from '../src/FundMe.sol';

contract FundMeTest {
    FundMe fundme;

    function setup() external {
        fundme = new FundMe();
    }

    function checkMminimumDollar() public {
        assertEq(fundme.MINIMUM_USD(), 5e18);
    }
}

I'm unsure why the error is occurring despite importing Test. Any insights on resolving this issue would be appreciated.

  • Solidity
0
1
Chia sẻ
Bình luận
.

Câu trả lời

1
Cyfrin Moderator Ans.
Mar 29 2024, 08:17

It appears that you have overlooked inheriting the 'Test' contract in the declaration of the 'FundMeTest' contract. To rectify this, please ensure that the declaration is as follows:

contract FundMeTest is Test {

}

By including the inheritance of the 'Test' contract in the declaration of the 'FundMeTest' contract, you establish the relationship between the two contracts and enable the functionality provided by the 'Test' contract to be utilized within the 'FundMeTest' contract.

0
Câu trả lời chính thức
Bình luận
.

Bạn có biết câu trả lời không?

Hãy đăng nhập và chia sẻ nó.

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

200Bài viết201Câu trả lời
Sui.X.Peera.

Kiếm phần của bạn từ 1000 Sui

Tích lũy điểm danh tiếng và nhận phần thưởng khi giúp cộng đồng Sui phát triển.