-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Testing assert/required using ThrowProxy #1001
Comments
I have tried also with another functions that returns other types and the problem is the same, it only works for void functions any ideas? thanks |
@marcosmartinez7 This is super interesting - the ThrowProxy article was written a while ago and I wonder if recent changes at solidity have added that constraint. Will ask around this morning and see if anyone knows the answer to this question. Out of curiosity - do your transactional methods need return signatures? If they're used within Solidity they will automatically return |
Hi @cgewecke , thanks for the answer. There is a couple of recent (aprox 5 months ago) articles and github repos using this aproach so thats an option, i dont know if it is a constraint or the proxy aproach just doesnt work now. I really apreciate if you can research about this! About the methods, the code that i have posted here is just an example, but the Smart contract that i am working on is from a third party and i cannot change it, but it has the return signatures. I will ask them about that because i didnt know that they automatically return true. Thanks! |
@cgewecke any news? The aproach that i have taken is to wrap all the functions that arent void functions in a test contract that expose that functions in a void way.. it is not something im proud of but works :/ |
@marcosmartinez7 I asked the @gnidan (another engineer here - he's recently written a solidity debugger and is intimately familiar with Solidity internals :) He was surprised by this behavior. Below is all the information I can find about
There's nothing in the release notes at Solidity that makes this clearer. The only other thing I can think of that might be related is this thread at Solidity which addresses recent changes in the way return call values are handled. If you find anything out, please report. Will leave this issue open in the interim and thanks for the work-around, that's very helpful. |
Just wanted to chime in and say that I have the same problem and am also using wrapper contracts now. It appears the problem is that the fallback function does not have a return value, right? |
Thank you for raising this issue! It has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you would like to keep this issue open, please respond with information about the current state of this problem. |
There has been no new activity on this issue since it was marked as stale 7 days ago, so it is being automatically closed. If you'd like help with this or a different problem, please open a new issue. Thanks! |
Sorry for bumping up this. I have been struggling with this issue for a couple of days now. It looks like as long as any modifier is used the ThrowProxy will fail as described. Using Solidity v0.5. |
Thanks for your response! This issue is no longer considered stale and someone from the Truffle team will try to respond as soon as they can. |
I'm having the exact same issue in a JavaScript test, using truffle 5.0.9. function I'm testing:
My test:
Expected behavior: The test passes. Actual behavior: The test fails with an error thrown: |
@sleepingevil So that is currently the correct behavior when a require fails. So if you want to test it, you could put in a try/catch and test against the error that is thrown. So it would be something like this...
I hope that helps! |
@eggplantzzz No, thats not the correct behaviour in Solidity. Also, there is no try-catch block in Solidity. The code that youre posting here is a js test. |
@eggplantzzz: @marcosmartinez7 is right. This is not the expected behaviour. ERC20 specification requires the transfer method of a token to:
I'm trying to test the return value in this case, not the exception thrown. According to the throw testing documentation, you can do this in Solidity with ThrowProxy. You can also test it with Both in Solidity and JavaScript this behavior is not as described, as the method throws a VM exception (revert). I posted JS code here, because the expected and actual behavior are the same in both programming languages, which makes me believe that the root cause is the same. Please advise me if I should create a separate issue for the JS one (I'm just trying to avoid having duplicate issues in github). |
@marcosmartinez7 Sorry, I was answering @sleepingevil. From the Solidity docs it states that an exception occurs when the value in a require statement evaluates to I guess regardless of the specs, just from looking at the Solidity code it seems like it is behaving as I would expect Solidity to behave. |
@eggplantzzz Actually, I think I'm missing something. :) Normally, if a function throws an exception, I'd expect it to stop executing, and don't return anything. However, I was under the assumption that in Solidity, if a function has a boolean return value, it will still return I assumed, because that's exactly what happens in this tutorial that I was watching. Apparently that was the incorrect behavior in the version of truffle used in the video, and what we have in truffle 5 today is correct. Thanks for the help clearing the confusion! |
Hi, im trying to test the requires of a Smart Contract using just solidity according to this article:
http://truffleframework.com/tutorials/testing-for-throws-in-solidity-tests
This is the contract, the throw proxy contract and the test:
If i run the tests i get this error:
If i chang the storeNum function to void from
to
the tests works..
Any ideas?
Im using Truffle v4.1.11
The text was updated successfully, but these errors were encountered: