Skip to main content
added 7 characters in body
Source Link

Inside my smart contract I'm having this function:

function addPerson(string memory _name, uint256 _favoriteNumber) public {
        people.push(People(_favoriteNumber, _name));
        nameToFavoriteNumber[_name] = _favoriteNumber;
    }

I want to test itwrite a test in hardhat to get my coverage 100%.

people[] array and nameToFavoriteNumber mapping are public.

 uint256 favoriteNumber;

    struct People {
        uint256 favoriteNumber;
        string name;
    }

    People[] public people;

How can I achieve this without making any changes in smart contract?

Inside my smart contract I'm having this function:

function addPerson(string memory _name, uint256 _favoriteNumber) public {
        people.push(People(_favoriteNumber, _name));
        nameToFavoriteNumber[_name] = _favoriteNumber;
    }

I want to test it in hardhat to get my coverage 100%.

people[] array and nameToFavoriteNumber mapping are public.

 uint256 favoriteNumber;

    struct People {
        uint256 favoriteNumber;
        string name;
    }

    People[] public people;

How can I achieve this without making any changes in smart contract?

Inside my smart contract I'm having this function:

function addPerson(string memory _name, uint256 _favoriteNumber) public {
        people.push(People(_favoriteNumber, _name));
        nameToFavoriteNumber[_name] = _favoriteNumber;
    }

I want to write a test in hardhat to get my coverage 100%.

people[] array and nameToFavoriteNumber mapping are public.

 uint256 favoriteNumber;

    struct People {
        uint256 favoriteNumber;
        string name;
    }

    People[] public people;

How can I achieve this without making any changes in smart contract?

Source Link

How to test a non-payable function which doesn't return anything in hardhat

Inside my smart contract I'm having this function:

function addPerson(string memory _name, uint256 _favoriteNumber) public {
        people.push(People(_favoriteNumber, _name));
        nameToFavoriteNumber[_name] = _favoriteNumber;
    }

I want to test it in hardhat to get my coverage 100%.

people[] array and nameToFavoriteNumber mapping are public.

 uint256 favoriteNumber;

    struct People {
        uint256 favoriteNumber;
        string name;
    }

    People[] public people;

How can I achieve this without making any changes in smart contract?