0

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?

1 Answer 1

0

With hardhat, deploy your contract, then check that people[] is emply (i.e. people[0].name == '' or something like that), then call the addPerson() function, then checks that people[] is not empty anymore (i.e. people[0].name == 'Tusher Bharti').

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.