Truffle test throws error when specify web3 options on overloaded function #2868
Comments
Ah, thanks for reporting this! Congrats, you've successfully confused Truffle! :) Sounds like your hunch is correct: because you define more than one (You had me for a second there with that error message... I thought you were making a joke, saying Anyway, Truffle provides a way for you to get around this incorrect method discernment... and it's that await c.methods["write(uint256,string)"]("One", { from: account }); Hope this helps! |
Btw, I want to pop in here that better overload resolution is planned for the future to make resorting to |
Hahaha, thanks @gnidan! It works indeed, but the correct method is: await c.methods["write(string)"]("One", { from: account }); Since is the method with signature "write(string)" that looks to be hidden for truffle, but can be accessed explicitly as you recommended, and not the most derived method write(uint256,string). |
Oh of course; I wrote the wrong one, oops :) Anyway, glad I could help! Besides the docs change, anything else actionable here? Is this a case where Truffle can error better? Can we feasibly detect the ambiguity here / is it worth it to add this before @haltman-at's teased changes? Feel free to close if you're satisfied, or I'll follow-up after some team discussion in our weekly ticket processing on Wednesday. Thanks again! |
@haltman-at brings up a good point that we should be able to detect when the last argument is an options and thus not conformant to one of the overloads. Calling this a bug, then! |
Can an object ever be a useable parameter? The solidity ABI can only accept strings and number types? |
@Epict33tus No, the Solidity ABI is considerably broader than that; it includes both structs and arrays, for instance. You can read more about it here. |
Issue
I don't know if this is a bug of Truffle or web3, or if I'm doing something wrong. But when I try to specify some options parameter (e.g. {from: some_address}) on an overloaded function the truffle test throws the following error:
If I remove the option parameter (e.g. {from: some_address}) the test works. So it seems that truffle or web3 are getting the wrong function signature. Or I'm declaring it in the wrong way.
The code is:
Steps to Reproduce
I created a repository to test this code and reproduce the problem. Just clone this repo and run "npm install" to install the dependencies, and run the ethereum client in one terminal:
Then, to see the test passing without the options parameter, run in another terminal:
To see the error when the options parameter is informed, run:
Expected Behavior
The test should succeed passing the web3 options parameter.
Actual Results
Truffle test throws the error: "invalid number value (arg="number", coderType="uint256", valu e="One")"
Environment
truffle version
): 5.1.15node --version
): v11.15.0npm --version
): 6.14.1Am I missing something? Even though if I make the "write" function virtual on the A contract and override it on the B contract, like the following:
I still get the same error.
And if I inspect the contract C abi the two method signatures are there:
Also in the contract object:
The text was updated successfully, but these errors were encountered: