Skip to content

Commit

Permalink
set admin in OmniCounter
Browse files Browse the repository at this point in the history
  • Loading branch information
e00dan committed Jan 9, 2024
1 parent 1839dd1 commit 36e5a65
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/OmniCounter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ contract OmniCounter is ILayerZeroComposer, OAppUpgradeable, UUPSUpgradeable {
*/
function initialize(address _endpoint, address _owner) public initializer {
_initializeOApp(_endpoint, _owner);
admin = _owner;
}

modifier onlyAdmin() {
Expand Down
33 changes: 33 additions & 0 deletions test/OmniCounter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,39 @@ contract CounterTest is ProxyTestHelper {
assertEq(bCounter.count(), counterBefore + batchSize, "batchIncrement assertion failure");
}

function test_nativeDrop_increment() public {
uint256 balanceBefore = address(bCounter).balance;

bytes memory options = OptionsBuilder
.newOptions()
.addExecutorLzReceiveOption(200000, 0)
.addExecutorNativeDropOption(1 gwei, addressToBytes32(address(bCounter)));
(uint256 nativeFee, ) = aCounter.quote(bEid, MsgCodec.VANILLA_TYPE, options);
aCounter.increment{ value: nativeFee }(bEid, MsgCodec.VANILLA_TYPE, options);

// verify packet to bCounter manually
verifyPackets(bEid, addressToBytes32(address(bCounter)));

assertEq(address(bCounter).balance, balanceBefore + 1 gwei, "nativeDrop assertion failure");

// transfer funds out
address payable receiver = payable(address(0xABCD));
address payable admin = payable(address(this));

// withdraw with non admin
vm.startPrank(receiver);
vm.expectRevert("only admin");
bCounter.withdraw(receiver, 1 gwei);
vm.stopPrank();

// withdraw with admin
vm.startPrank(admin);
bCounter.withdraw(receiver, 1 gwei);
assertEq(address(bCounter).balance, 0, "withdraw assertion failure");
assertEq(receiver.balance, 1 gwei, "withdraw assertion failure");
vm.stopPrank();
}

// classic message passing A -> B1 -> B2
function test_lzCompose_increment() public {
uint256 countBefore = bCounter.count();
Expand Down

0 comments on commit 36e5a65

Please sign in to comment.