LayerZero-Labs / LayerZero-v2

Other
542 stars 327 forks source link

TestHelper incompatability with forking and changing forks #20

Open BlazeWasHere opened 7 months ago

BlazeWasHere commented 7 months ago

When using fork cheatcodes and switching fork, state is not persisted by default. This means contracts already created prior to switching forks are reset and must be explicitly marked with vm.makePersistent.

image

https://github.com/LayerZero-Labs/LayerZero-v2/blob/3fd23fd21a3c7c42473d43bee44cedecbc93569e/oapp/test/OptionsHelper.sol#L18-L19

For the above code it is recommended to instead define the variable in the class (UlnOptionsMock ulnOptions;), and then init the variable in a setup function (ulnOptions = new UlnOptionsMock(). Without doing so, and without using vm.makePersistent, leads to a very opaque error.

ulnOptions.decode(
    hex"0003010021010000000000000000000000000003827100000000000000000000000000000001"
);
├─ [0] UlnOptionsMock::decode(0003010021010000000000000000000000000003827100000000000000000000000000000001) [staticcall]
    │   └─ ← ()
    └─ ← EvmError: Revert