ApeWorX / ape-ganache

Ganache network provider plugin for the Ape Framework
https://www.apeworx.io/
Apache License 2.0
4 stars 6 forks source link

Contract calling another contract is not working #16

Open bilbeyt opened 1 year ago

bilbeyt commented 1 year ago

Environment information

$ ape --version
0.5.7

$ ape plugins list
Installed Plugins:
  solidity    0.5.2
  ganache     0.5.0

What went wrong?

I used ape test command, and i used the code like this:

request_manager.invalidateFill(request_id, FILL_ID, chain_id, sender=contracts.l1_messenger)

In which, contracts.l1_messenger and request_manager are contracts.

The output looks like this:

====================================================================================== FAILURES ======================================================================================
___________________________________________________________________ test_invalidation_before_and_after_resolution ____________________________________________________________________

self = [0xC225b4aC8C7Dd7397F4EEe919874614ECE5fE0E6, 0x5ea28528Ff26a13f0f18a9C4e554bbE54189D188, 0x83bf2F23f1A500212a78950A4a7...f28FB7a3FBF3669d64D1C1334eDf65, 0x965663E1bd56f473Efec10d5ebAF15c024101045, 0xAC3812bF4f0FbD26323b2D9e74C494421550e2d9]
account_str = '0xc9D78CD032abC6630B4845583c98eBe104e66b08'

    @__getitem__.register
    def __getitem_str(self, account_str: str):
        account_id = self.conversion_manager.convert(account_str, AddressType)

        for account in self.accounts:
            if account.address == account_id:
                return account

        can_impersonate = False
        err_message = f"No account with address '{account_id}'."
        try:
            if self.network_manager.active_provider:
>               can_impersonate = self.provider.unlock_account(account_id)

../../.virtualenvs/beamer/lib/python3.10/site-packages/ape/managers/accounts.py:92:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

args = (<ganache chain_id=1337>, '0xc9D78CD032abC6630B4845583c98eBe104e66b08'), kwargs = {}

    def inner(*args, **kwargs):
>       raise APINotImplementedError(
            f"Attempted to call method '{fn.__qualname__}', method not supported."
        )
E       ape.exceptions.APINotImplementedError: Attempted to call method 'ProviderAPI.unlock_account', method not supported.

../../.virtualenvs/beamer/lib/python3.10/site-packages/ape/utils/misc.py:255: APINotImplementedError

The above exception was the direct cause of the following exception:

contracts = Contracts(resolver=<Resolver 0x885C51DE25326436479A56CaFA9D14c57f969e8A>, fill_manager=<FillManager 0x08AfdD6a8AbA653F...0xc9D78CD032abC6630B4845583c98eBe104e66b08>, l2_messenger=<TestL2Messenger 0xd8912d0E27222d504Fc904d81e478a2be70Cd56C>)
request_manager = <RequestManager 0x268BdedEA20DeF5Cfe835B9332d2d1DF0803EBE1>

    def test_invalidation_before_and_after_resolution(contracts, request_manager):
        contracts.l1_messenger.setLastSender(contracts.resolver.address)

        address = make_address()
        request_id = RequestId(31 * b"0" + b"1")
        chain_id = ape.chain.chain_id

        assert not request_manager.isInvalidFill(request_id, FILL_ID)
>       request_manager.invalidateFill(request_id, FILL_ID, chain_id, sender=contracts.l1_messenger)

beamer/tests/contracts/test_l1_resolution.py:68:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../.virtualenvs/beamer/lib/python3.10/site-packages/ape/contracts/base.py:286: in __call__
    return contract_transaction(*function_arguments, **kwargs)
beamer/tests/conftest.py:42: in wrapper
    return func(*args, **kwargs)
../../.virtualenvs/beamer/lib/python3.10/site-packages/ape/contracts/base.py:212: in __call__
    txn = self.serialize_transaction(*args, **kwargs)
../../.virtualenvs/beamer/lib/python3.10/site-packages/ape/contracts/base.py:204: in serialize_transaction
    kwargs["sender"] = self.account_manager.test_accounts[kwargs["sender"].address]
../../.pyenv/versions/3.10.8/lib/python3.10/functools.py:926: in _method
    return method.__get__(obj, cls)(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = [0xC225b4aC8C7Dd7397F4EEe919874614ECE5fE0E6, 0x5ea28528Ff26a13f0f18a9C4e554bbE54189D188, 0x83bf2F23f1A500212a78950A4a7...f28FB7a3FBF3669d64D1C1334eDf65, 0x965663E1bd56f473Efec10d5ebAF15c024101045, 0xAC3812bF4f0FbD26323b2D9e74C494421550e2d9]
account_str = '0xc9D78CD032abC6630B4845583c98eBe104e66b08'

    @__getitem__.register
    def __getitem_str(self, account_str: str):
        account_id = self.conversion_manager.convert(account_str, AddressType)

        for account in self.accounts:
            if account.address == account_id:
                return account

        can_impersonate = False
        err_message = f"No account with address '{account_id}'."
        try:
            if self.network_manager.active_provider:
                can_impersonate = self.provider.unlock_account(account_id)
            # else: fall through to `IndexError`
        except NotImplementedError as err:
>           raise IndexError(
                f"Your provider does not support impersonating accounts:\n{err_message}"
            ) from err
E           IndexError: Your provider does not support impersonating accounts:
E           No account with address '0xc9D78CD032abC6630B4845583c98eBe104e66b08'.

../../.virtualenvs/beamer/lib/python3.10/site-packages/ape/managers/accounts.py:95: IndexError

How can it be fixed?

Fill this in if you have ideas on how the bug could be fixed.

fubuloubu commented 1 year ago

See https://github.com/trufflesuite/ganache/discussions/4079:

https://github.com/trufflesuite/ganache/blob/develop/src/chains/ethereum/ethereum/RPC-METHODS.md#evm_addaccount