How to write tests for Proxy (Truffle)

I have created tests that work directly with the main contract code, verifying that it works.

But now when I try to run the same tests through the proxy, it fails with “TypeError: Cannot read property ‘function call’ of undefined”.

I assume this is due to the method in question does not exist in the Proxy.sol and that the default way of running javascript tests with Truffle and Ganache need the knowledge of what your calling to work.

Just as when calling the Proxy in the wild, you use the ABI of the contract your proxying to.

Is there any way to create automated tests to verify if a proxy works as intended? I.e. by running tests through it towards the contract you want to verify work?

1 Like

Hi @sven,

Welcome to the community :wave:

To test our upgradeable contract, we use the ABI of the implementation contract with the address of the proxy contract.

Please see OpenZeppelin Upgrades: Step by Step Tutorial for Truffle for an example of testing via the proxy contract using OpenZeppelin Upgrades Plugins (see documentation for test usage:

Let me know if you have any questions.

1 Like

Thanks for the information @abcoathup

I am not utilizing the upgradable proxy by the plugin this time, but will for sure look into that next time!

1 Like

Hi @sven,

For testing upgradeable contracts, once you have deployed the implementation contract, the proxy contract, and initialized the upgradeable contract you can then interact with the upgradeable contract using the ABI of the implementation contract and the proxy contract address.
You won’t be able to interact from the admin address.

I recommend using Upgrades Plugins as this will check upgrade safety when you deploy and upgrade, and make it easy to deploy and test using Truffle and Buidler.

1 Like