I am trying to write test for a function addPerson() that takes stirng name and uint256 favNumber and creates a People object and add it to the people list, this addPerson() is defined in Solidity and I am trying to access it in my "test-deploy.js", here's the test I have written -

  it("It should add People object to people list and nameToFavNum", async function () {
    const expectedValue = ["name", "87"]
    const transactionResponse = await simpleStorage.addPerson("name", 87)
    await transactionResponse.wait(1)
    const actualValue = await simpleStorage.people[0]
    assert.equal(expectedValue, actualValue)

Now here actualValue returns undefined it works well on other functions that return something, I need to grab that value which I store on calling addPerson() the code for addPerson() -

    function addPerson (string memory _name, uint256 _favNum) public {
        People memory newPerson = People({name: _name, favNum: _favNum});
        nameToFavNum[_name] = _favNum;

I tried my best to explain my problem and if anyone could help me with this it would be great. Thanks.

  • 2
    So there is an array called people which is of type struct. If that's the case, then you should be able to access it almost as you do, just one small change: await simpleStorage.people(0). Make sure the variable is public. Jun 26, 2022 at 8:40

1 Answer 1


Try changing the const actualValue = await simpleStorage.people[0] to const actualValue = await simpleStorage.people(0)

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.