ape icon indicating copy to clipboard operation
ape copied to clipboard

feat: add return value for transactions

Open Ninjagod1251 opened this issue 2 years ago • 6 comments

Overview

Provide a simple overview of what you wish to see added. Please include:

Upon making a test for ERC20 Smart contract. We should add a return value for accounts.

tx = contract.myMutableMethod(...)
assert tx.return_value == ...  # .return_value doesn't exist

  • What you are trying to do
  • Why Ape's current functionality is inadequate to address your goal

Specification

Describe the syntax and semantics of how you would like to see this feature implemented. The more detailed the better!

Remember, your feature is much more likely to be included if it does not involve any breaking changes.

Dependencies

Include links to any open issues that must be resolved before this feature can be implemented.

Ninjagod1251 avatar May 13 '22 20:05 Ninjagod1251

You have to use events for transactions I believe.

https://ethereum.stackexchange.com/questions/73787/solidity-return-value-of-smart-contract-transact

I showed @Ninjagod1251 how to get the events from a receipt!

antazoey avatar May 13 '22 21:05 antazoey

You have to use events for transactions I believe.

https://ethereum.stackexchange.com/questions/73787/solidity-return-value-of-smart-contract-transact

I showed @Ninjagod1251 how to get the events from a receipt!

Not sure if this is event related, might require traces actually... I think the trick is to decode the debug_traceTransaction one level and obtain the last structLog item which should contain the return value. Can also use evm-trace to return

https://github.com/eth-brownie/brownie/blob/3aecd87f47c9c316c85b0b0c6252ff7d900cca74/brownie/network/transaction.py#L274-L275

fubuloubu avatar May 13 '22 21:05 fubuloubu

Look like we should research more and I think I might be in over my head. I would love to listen in and test the feature

Ninjagod1251 avatar May 16 '22 18:05 Ninjagod1251

Look like we should research more and I think I might be in over my head. I would love to listen in and test the feature

Yeah, please hold off on this for now

fubuloubu avatar May 16 '22 18:05 fubuloubu

this can be quite easily done now

def get_return_value(tx):
    call_tree = chain.provider.get_call_tree(tx)
    method_abi = Contract(call_tree.address).contract_type.mutable_methods[call_tree.calldata]
    output = chain.provider.network.ecosystem.decode_returndata(method_abi, call_tree.returndata)
    if isinstance(output, tuple) and len(output) < 2:
        output = output[0] if len(output) == 1 else None
    return output

banteg avatar Jul 10 '22 17:07 banteg

@helloibis might be able to take a stab at adding this to the ReceiptAPI class as a .return_value property, and let it raise if the current provider does not implement .get_call_tree

fubuloubu avatar Jul 12 '22 14:07 fubuloubu