Skip to content

Commit

Permalink
add arbitrum receiever unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hexonaut committed Jun 5, 2024
1 parent 3fcbcce commit 5669f7d
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions test/ArbitrumReceiver.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity >=0.8.0;

import "forge-std/Test.sol";

import { TargetContractMock } from "test/mocks/TargetContractMock.sol";

import { ArbitrumReceiver } from "src/receivers/ArbitrumReceiver.sol";

contract ArbitrumReceiverTest is Test {

TargetContractMock target;

ArbitrumReceiver receiver;

address sourceAuthority = makeAddr("sourceAuthority");
address sourceAuthorityWithOffset;
address randomAddress = makeAddr("randomAddress");

function setUp() public {
target = new TargetContractMock();

receiver = new ArbitrumReceiver(
sourceAuthority,
address(target)
);
unchecked {
sourceAuthorityWithOffset = address(uint160(sourceAuthority) + uint160(0x1111000000000000000000000000000000001111));
}
}

function test_constructor() public {
receiver = new ArbitrumReceiver(
sourceAuthority,
address(target)
);

assertEq(receiver.l1Authority(), sourceAuthority);
assertEq(receiver.target(), address(target));
}

function test_forward_invalidL1Authority() public {
vm.prank(randomAddress);
vm.expectRevert("ArbitrumReceiver/invalid-l1Authority");
receiver.forward(abi.encodeCall(TargetContractMock.someFunc, ()));
}

function test_forward_invalidL1AuthoritySourceAuthorityNoOffset() public {
vm.prank(sourceAuthority);
vm.expectRevert("ArbitrumReceiver/invalid-l1Authority");
receiver.forward(abi.encodeCall(TargetContractMock.someFunc, ()));
}

function test_forward_success() public {
assertEq(target.data(), 0);
vm.prank(sourceAuthorityWithOffset);
receiver.forward(abi.encodeCall(TargetContractMock.someFunc, ()));
assertEq(target.data(), 1);
}

function test_forward_revert() public {
vm.prank(sourceAuthorityWithOffset);
vm.expectRevert("error");
receiver.forward(abi.encodeCall(TargetContractMock.revertFunc, ()));
}

}

0 comments on commit 5669f7d

Please sign in to comment.