I have a js truffle test:
it("should add an exam to the exams list", async () => {
// This should test the complete functionality
let hash_test = "fB03aA5E2E71De1470ae2";
let instance = await Exam.deployed();
let hash = instance.addExam.call({from: accounts[0], hash: hash_test});
assert.equal(hash.valueOf(), hash_test, "Not returning the correct address")
})
And I have an addExam function in the contract:
function addExam(string memory hash) public returns (string memory examProfessorHash) {
// save the exam hash and link it with the professors address
professorsExam[msg.sender] = hash;
return hash;
}
When I run the tests, I get this error:
Error: invalid string value (arg="hash", coderType="string", value={"from":"0x67F4CfB03aA5E2E71De1470ae26adB7e33B7892E","hash":"fB03aA5E2E71De1470ae2"}) at PromiEvent
I am not sure how to debug this. Is it the .call() method?
instance.addExam(hash_test).send({from: accounts[0]})doesn't work.TypeError: instance.addExam(...).send is not a function– Alejandro Veintimilla Nov 21 '19 at 21:19send. While testing, you need to provide the function name, like:let hash = await instance.addExam(hash_test, { from: accounts[0] });. On the other hand, when you dohash.valueOf()you get the transaction info, not the value of the hash. You can use agetExam(...)method to get the hash of a exam andcallit. – alberto Nov 21 '19 at 21:45