Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input instead of output is shown for functions that uses gas #20

Open
gpersoon opened this issue Sep 17, 2019 · 12 comments
Open

Input instead of output is shown for functions that uses gas #20

gpersoon opened this issue Sep 17, 2019 · 12 comments
Assignees

Comments

@gpersoon
Copy link
Contributor

The results of a function that uses gas aren't shown. Instead the input is shown.
For example if you input "6" in the function "double" you would expect the output to be 12.

pragma solidity ^0.5.3;

contract Test {
    
    function double(uint i) public returns (uint) {
        
        return i*2;
    }

}

However the value of "6" is shown, which is actually the input:

image

It's technically difficult the get the output, so maybe it's better not to shown anything.

@serapath
Copy link
Member

  • actually, we plan to add the given input to all outputs, so the history in what will become a console would be more similar to "chat messages", where you see messages you received, but also messages you sent.
  • and yes - it seems to be difficult to retrieve return value output of "write" functions sadly

I think @ninabreznik know the status quo a bit better than me as she was investigating this already :-)

@ninabreznik
Copy link
Member

That's the good comment @gpersoon! I am also not satisfied with the returns here. I was thinking to always show inputs and outputs, but not sure yet... or maybe just outputs and more details (like in remix). I just working on this, so hopefully I find some nice solution here.

Do you have any preferences or suggestions?

@ninabreznik ninabreznik self-assigned this Sep 18, 2019
@gpersoon
Copy link
Contributor Author

gpersoon commented Sep 19, 2019

From a users point of view, having the result is very useful.
Here are a few suggestions:

  1. indicate that the output can't be shown (short term solution)
  2. Implement showing emitted events and suggest the user to modify the source to emit the result as an event { this would work for me }
  3. perform the call from another contract and capture the results via events (do-able but might have side effects); perhaps have an option to use
  4. Use debug.traceTransaction, but then you need a full node in debugging mode
  5. Calculate the function result with an in browser EVM (ethereumjs-vm) (quite complicated i guess)

Regarding the inputs: they could be stored in a hoover text see you can still find them without cluttering the screen.

@gpersoon
Copy link
Contributor Author

Copied from: https://gitter.im/ethereum/play :

  • Nina: Btw. I am struggling with getting outputs from the transactions. It's not straight forward. Ethers.js guy told me there is a workaround, but I have to figure out how exactly...
    image
  • Gerard: I think the workaround is using the myContract.methods.myMethod(..).call instead of the myContract.methods.myMethod(..).send method (in web3.js terms, i don't know the equivalent in ethers.js); it's basically calling the function in a readonly way without sending any eth/gas. However as he is saying this won't give an accurate result. Perhaps calling via another contract is the most straightforward way to get the results back. { or maybe via a proxy function in the same contract, however that would have to be inserted in the contract }
  • Nina: Hm, good tips, let me see how these things work in etherjs. Thanks

@gpersoon
Copy link
Contributor Author

Ganache has debug_traceTransaction ( trufflesuite/ganache#125 ), so when Ganache is used in combination with the play editor, you can use it.

@ninabreznik
Copy link
Member

The solution was implemented but will be released in the new version of the smartcontact-ui, coming out hopefully in 2 weeks or so.

@ninabreznik
Copy link
Member

@gpersoon finally I made this PR. It was once already don, but I by mistake overrun the changes, so now we have it again.

Currently on my test version, but please check it out once you have time and if it's ok, we can merge it
https://ninabreznik.github.io/editor-solidity/

@gpersoon
Copy link
Contributor Author

@ninabreznik this is a lot better 👍

I've noticed a situation where it doesn't work and narrowed it down to:

pragma solidity ^0.5.12;
contract Testreturn { 
    function getnow() public returns (uint) {
        return now;
    } 
}

Which shows the following error in the developer console:

bundle.js:50510 Uncaught (in promise) TypeError: Cannot read property 'type' of undefined
    at makeContractCallable (bundle.js:50510)
    at sendTx (bundle.js:50472)
``

@gpersoon
Copy link
Contributor Author

@ninabreznik : Fixes pushed to https://ninabreznik.github.io/editor-solidity/

Works a lot better now (previous error is solved).
Another 2 (related) cases:

pragma solidity >=0.5.0 <0.7.0;
contract TestPayable {
    function Test() public payable returns (bool) {  
        return false;
    }
}

This results in the following error:

Error: call cannot override gasLimit
    at bundle.js:24480
    at Array.forEach (<anonymous>)
    at bundle.js:24480
    at async makeContractCallable (bundle.js:50519)
    at async sendTx (bundle.js:50471)

When i changed the type to uint:

pragma solidity >=0.5.0 <0.7.0;
contract TestPayable {
    function Test() public payable returns (uint) {  
        return 1;
    }
}

I saw an additional error:

Error: call cannot override gasLimit
....
bundle.js:49671 Uncaught (in promise) TypeError: Cannot read property 'toString' of undefined
    at decode (bundle.js:49671)
    at decodeReturnData (bundle.js:49664)
    at getReturnData (bundle.js:50058)
    at makeReturn (bundle.js:50050)
    at sendTx (bundle.js:50487)
decode @ bundle.js:49671
decodeReturnData @ bundle.js:49664
getReturnData @ bundle.js:50058
makeReturn @ bundle.js:50050
sendTx @ bundle.js:50487
async function (async)
sendTx @ bundle.js:50460
(anonymous) @ bundle.js:50437
bundle.

@ninabreznik
Copy link
Member

Fixed

@gpersoon
Copy link
Contributor Author

The previous error is fixed now.

Found a situation where the answer isn't correct:

pragma solidity >=0.5.0 <0.7.0;
contract TestPayable {
    function Test() public payable returns (uint) {  
         return msg.value;
    }
}

When I sent 4 wei to this contract, I would expect the return value to be 4. However it is shown as 0.
image

@ninabreznik
Copy link
Member

@gpersoon You're the master of edge cases. Thanks for that. Checking it out now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants