Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
add missing lz_compose test case to OmniCounter
Browse files Browse the repository at this point in the history
  • Loading branch information
e00dan committed Jan 9, 2024
1 parent 36e5a65 commit 57e031c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ These are the potential advantages of using this repository instead of official
4. CREATE2 by default for deterministic addresses in multichain deployment
5. Very simple Counter example just to get started without advanced functionality

I still recommend to consult [official repository of LayerZero](https://github.com/LayerZero-Labs/LayerZero-v2) whenever you need to bring more advanced functionality such as composability, nested calls etc. Examples of such aren't part of this repository as of now.
I still recommend consulting [official repository of LayerZero](https://github.com/LayerZero-Labs/LayerZero-v2) whenever you need to bring more advanced functionality or different code examples.

## Quickstart

Expand Down
2 changes: 2 additions & 0 deletions src/OmniCounter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.19;

import {OptionsBuilder} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/libs/OptionsBuilder.sol";
import {
ILayerZeroEndpointV2,
MessagingParams,
MessagingReceipt
} from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
Expand Down Expand Up @@ -70,6 +71,7 @@ contract OmniCounter is ILayerZeroComposer, OAppUpgradeable, UUPSUpgradeable {
function initialize(address _endpoint, address _owner) public initializer {
_initializeOApp(_endpoint, _owner);
admin = _owner;
eid = ILayerZeroEndpointV2(_endpoint).eid();
}

modifier onlyAdmin() {
Expand Down
24 changes: 23 additions & 1 deletion test/OmniCounter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {OmniCounter, MsgCodec} from "../src/OmniCounter.sol";
import {UUPSProxy} from "../src/UUPSProxy.sol";
import {ProxyTestHelper} from "./utils/ProxyTestHelper.sol";

contract CounterTest is ProxyTestHelper {
contract OmniCounterTest is ProxyTestHelper {
using OptionsBuilder for bytes;

uint32 aEid = 1;
Expand Down Expand Up @@ -136,6 +136,28 @@ contract CounterTest is ProxyTestHelper {
assertEq(aCounter.count(), countABefore + 1, "increment A assertion failure");
}

// A -> B1 -> B2 -> A
function test_lzCompose_ABA_increment() public {
uint256 countABefore = aCounter.count();
uint256 countBBefore = bCounter.count();
uint256 composedCountBBefore = bCounter.composedCount();

bytes memory options = OptionsBuilder
.newOptions()
.addExecutorLzReceiveOption(200000, 0)
.addExecutorLzComposeOption(0, 10000000, 10000000);
(uint256 nativeFee, ) = aCounter.quote(bEid, MsgCodec.COMPOSED_ABA_TYPE, options);
console2.log("bEid is", bEid);
aCounter.increment{ value: nativeFee }(bEid, MsgCodec.COMPOSED_ABA_TYPE, options);

verifyPackets(bEid, addressToBytes32(address(bCounter)), 0, address(bCounter));
assertEq(bCounter.count(), countBBefore + 1, "increment B1 assertion failure");
assertEq(bCounter.composedCount(), composedCountBBefore + 1, "increment B2 assertion failure");

verifyPackets(aEid, addressToBytes32(address(aCounter)));
assertEq(aCounter.count(), countABefore + 1, "increment A assertion failure");
}

// required for test helper to know how to initialize the OApp
function _deployOAppProxy(address _endpoint, address _owner, address implementationAddress)
internal
Expand Down

0 comments on commit 57e031c

Please sign in to comment.