LayerZero-Labs / devtools

LayerZero Developer Utilities
https://docs.layerzero.network/
92 stars 150 forks source link

Guidance on testing OFT contracts locally (LZ endpoint mock/local deploy) #408

Open actuallymentor opened 8 months ago

actuallymentor commented 8 months ago

Thanks @kushdave95 for your support in DM, as requested an issue with details on my testing questions.

Is your feature request related to a problem? Please describe.

When building an LZ OFT contract and wanting to test it locally with hardhat/foundry, the OFT contract requires an LZ endpoint to be deployed (or perhaps mocked).

I would appreciate guidance on how to best do this. Note that this example in this repository does NOT show how to do this. It only tests a mock OFT contract.

Describe the solution you'd like

A clear example (or docs) on how to test an OFT contract locally in hardhat. I assume this means having a clear mock of an LZ endpoint (and how to implement it in a testing context).

Describe alternatives you've considered

I tried this repo's examples but as #399 indicates, this did not actually show how to test the contract, only the mock.

Additional context

From a DX perspective this would be very appreciated, as testing only on live testnets is suboptimal at best.

janjakubnanista commented 8 months ago

Hey @actuallymentor! Thanks for reaching out!

At the moment there indeed is no easy, out-of-the-box solution for a local E2E test. It's something we are considering exposing to external developers since it's something that we have available in this repo - we deploy our own EndpointV2 contracts to test the wiring scripts.

The bad news is that I can't give you a timeline for this. We will keep you in the loop once we get a rough estimate of how and when this should be available.

actuallymentor commented 8 months ago

Thanks for the context @janjakubnanista!

What would it take to convince you to prioritise this?

Local testing is not a luxury for many devs. Even if you don't subscribe to test-driven development, it's an integral part of writing good contracts (as evidenced by your own doing of this).

I understand that there is always unlimited work and limited people to do the work, but I'd like to strongly advocate for this. Both to help your devs, and to signal to the dev community that you care about testing.

janjakubnanista commented 7 months ago

Hey @actuallymentor!

Not sure if this will completely solve your problem, but it should at least be a step forward. We merged #442 which contains a TestHelper contract for testing contracts using foundry.

We'll see how much work it takes to provide functionality that emulates a LayerZero environment completely, with the off-chain bits as well. As always, will keep you updated!

actuallymentor commented 7 months ago

Thanks for keeping me posted @janjakubnanista! Do you know whether this has hardhat compatibility, and are there docs available for it?