Skip to content

Lesson 6: test gives unexpected result #497

Discussion options

You must be logged in to vote

The length of a public array is not exposed by default in solidity.

First way(easy to implement) :
Define a specific solidity function for it :

And call that function in your test :

You can refer to this :
contract : SimpleStorage.sol
test : test-deploy.js
both the function and required test are written at end of the file respectively.

The second way(complex) :
From ethers.js, read the storage slot of your array. About which you will learn in the further module. The first way is easy and recommended because in the second way when you update your contract you have to update the test again.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@Olaleye-Blessing
Comment options

Answer selected by Olaleye-Blessing
Comment options

You must be logged in to vote
1 reply
@Olaleye-Blessing
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants