Replies: 3 comments 1 reply
-
@pyromaus Yes, when you do |
Beta Was this translation helpful? Give feedback.
-
so that's how you do it! I didn't know how to get it to work so I cheated and modified the smart contract
and then finally got 100% wit this monster of a code
|
Beta Was this translation helpful? Give feedback.
-
Thanks for sharing your experience @pyromaus! I was unable to get it right without the parenthesis. This is my final result using typescript. I also wanted to know what would happen if you cover two Conclusion: if all the it("Should add a new person with a favorite number to the people array", async () => {
const transactionResponse: ContractTransactionResponse = await simpleStorage.addPerson("satoshi", "21000000")
await transactionResponse.wait(1)
const expectedValue: string = "21000000"
const nameToFavoriteNumberValue: string = (await simpleStorage.nameToFavoriteNumber("satoshi")).toString()
const firstPersonPeopleArrFavoriteNumber: string = ((await simpleStorage.people(0)).favoriteNumber).toString()
// const testValue = 8
assert.equal(nameToFavoriteNumberValue, expectedValue)
assert.equal(firstPersonPeopleArrFavoriteNumber, expectedValue)
// assert.equal(testValue.toString(), "1")
}) |
Beta Was this translation helpful? Give feedback.
-
Here I share how I wrote the coverage test for the 3rd Simple Storage function (.addPerson)
Tests all went through, and coverage shows 100%
@RevanthGundala's way of coding this was more concise and clean.
What I found interesting that may be helpful for other noobs like myself is the difference parentheses () around
await simpleStorage.people(0)
made. From Revanth's thread, @TilakMaddy suggested parentheses that saves you lines of code.. Hardhat console:If I'm not mistaken I imagine it like this;
Without parenthesis, the
await
is awaiting this entire statement:simpleStorage.people(0).name
including the name, which will not compute.With parenthesis, you're waiting for this phrase
await simpleStorage.people(0)
to go through before fetchingname
. It's like those unnamed/"anonymous" functions Patrick mentioned. The parentheses let you make an anonymous variable that's used right then and there and never stored.Thanks for listening to my rant, lemme know if this ain't it
Beta Was this translation helpful? Give feedback.
All reactions