From 5669f7db781c83cc1782a474cc68493febcd19f8 Mon Sep 17 00:00:00 2001 From: Sam MacPherson Date: Wed, 5 Jun 2024 19:24:50 +0900 Subject: [PATCH] add arbitrum receiever unit tests --- test/ArbitrumReceiver.t.sol | 67 +++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 test/ArbitrumReceiver.t.sol diff --git a/test/ArbitrumReceiver.t.sol b/test/ArbitrumReceiver.t.sol new file mode 100644 index 0000000..02d57c6 --- /dev/null +++ b/test/ArbitrumReceiver.t.sol @@ -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, ())); + } + +}