Issue with writing test for hardhat-simplestorage #1432
-
Hey guys, I am facing an issue while writing test for SimpleStorage.sol. const { assert } = require("chai")
const { ethers } = require("hardhat")
describe("SimpleStorage", function (params) {
let simpleStorageFactory
let simpleStorage
beforeEach(async function () {
simpleStorageFactory = await ethers.getContractFactory("SimpleStorage")
simpleStorage = await simpleStorageFactory.deploy()
})
it("Person should be added when calling addPerson", async function () {
const expectedPersonName = "deept"
const expectedFavoriteNumber = "12"
const transactionResponse = await simpleStorage.addPerson(
expectedPersonName,
expectedFavoriteNumber
)
await transactionResponse.wait(1)
const { favoriteNumber, name } = await simpleStorage.people(0)
assert.equal(name, expectedPersonName)
assert.equal(favoriteNumber, expectedFavoriteNumber)
const lengthOfPeople = await simpleStorage.people.length
console.log(lengthOfPeople)
assert.equal(lengthOfPeople, 1)
})
}) When runnning
Update the test file with the content provided above |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Make a repo, I will look into it |
Beta Was this translation helpful? Give feedback.
-
Hii, The length of a public array is not exposed by default in solidity. You can add a function in your contract which returns the length of people array function getNumberOfpeoples() public view returns(uint256){
return people.length
} |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick response @krakxn and @technophile-04. |
Beta Was this translation helpful? Give feedback.
Hii, The length of a public array is not exposed by default in solidity. You can add a function in your contract which returns the length of people array