Lesson 6 Testing addPerson function [Uncovered lines(31,32) Challenge] #1543
-
I was trying to test the addPerson function. I'm not sure how to pass an array. Can anyone please check the code and let me know where I'm being wrong? Patrick asks us to do it by ourselves at 9:46:30 This is the test-deploy.js program it("Should add person when called and attach favourite number to person name", async function () {
const expectedValue = ("Chad", 69)
const transactionResponse = await simpleStorage.addPerson(expectedValue)
await transactionResponse.wait(1)
assert.equal(transactionResponse, expectedValue)
}) This is the error I'm getting: 1) SimpleStorage
Should add person when called and attach favourite number to person name:
Error: missing argument: passed to contract (count=1, expectedCount=2, code=MISSING_ARGUMENT, version=contracts/5.6.2)
at Logger.makeError (node_modules/@ethersproject/logger/src.ts/index.ts:261:28)
at Logger.throwError (node_modules/@ethersproject/logger/src.ts/index.ts:273:20)
at Logger.checkArgumentCount (node_modules/@ethersproject/logger/src.ts/index.ts:332:18)
at /home/anirbanweb3/Anirban/hh-fcc/hardhat-simple-storage-fcc/node_modules/@ethersproject/contracts/src.ts/index.ts:187:12
at step (node_modules/@ethersproject/contracts/lib/index.js:48:23)
at Object.next (node_modules/@ethersproject/contracts/lib/index.js:29:53)
at /home/anirbanweb3/Anirban/hh-fcc/hardhat-simple-storage-fcc/node_modules/@ethersproject/contracts/lib/index.js:23:71
at new Promise (<anonymous>)
at __awaiter (node_modules/@ethersproject/contracts/lib/index.js:19:12)
at populateTransaction (node_modules/@ethersproject/contracts/lib/index.js:152:12)
error Command failed with exit code 1. I know my code is fundamentally wrong somewhere but since I'm new I can't seem to figure out. Any help would be awesome.Thanks :) |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 12 replies
-
you should pass the values directly into const transactionResponse = await simpleStorage.addPerson("Chad",69) The way you did it is wrong because when the value are passed into function they will have a double brackets: const transactionResponse = await simpleStorage.addPerson(("Chad",69)) In your |
Beta Was this translation helpful? Give feedback.
-
@oneyellowpeacock 1 issue that @IANGECHUKI176 mentioned above and 2 issues you are comparing with transactionResponse that is to equivalent. You need the get the added person from person array and then compare with that. Here is my example of that test: it("Should add a person with favorite number", async function () {
const personName = "Ali Murtaza";
const personFavoriteNumber = "40";
const transactionResponse = await simpleStorage.addPerson(
personName,
personFavoriteNumber
);
await transactionResponse.wait(1);
const person = await simpleStorage.people(0);
assert.equal(person.name, personName);
assert.equal(person.favoriteNumber.toString(), personFavoriteNumber);
}); |
Beta Was this translation helpful? Give feedback.
-
Hey guys, I tried doing the addPerson mini challenge, and this is the code I wrote. I'm not sure if I did it right, although it did pass the test. it("Should add a person and a number to the array", async function () {
const expectedValue = "0"
const currentValue = await simpleStorage.retrieve()
await simpleStorage.addPerson(expectedValue, currentValue)
assert.equal(currentValue.toString(), expectedValue)
})
Could anyone please verify that this is a right way of doing it? |
Beta Was this translation helpful? Give feedback.
-
This is what I wrote maybe It will help with the console.log.... so you can see whats inside and how to show you. ''' |
Beta Was this translation helpful? Give feedback.
@oneyellowpeacock 1 issue that @IANGECHUKI176 mentioned above and 2 issues you are comparing with transactionResponse that is to equivalent. You need the get the added person from person array and then compare with that.
Here is my example of that test: