-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from marsfoundation/SC-437-fix-coverage
[SC-437] Fixing coverage by adding unit tests
- Loading branch information
Showing
11 changed files
with
409 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// 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 { AMBReceiver } from "src/receivers/AMBReceiver.sol"; | ||
|
||
contract AMBMock { | ||
|
||
bytes32 public messageSourceChainId; | ||
address public messageSender; | ||
|
||
constructor(bytes32 _messageSourceChainId, address _messageSender) { | ||
messageSourceChainId = _messageSourceChainId; | ||
messageSender = _messageSender; | ||
} | ||
|
||
function __setSourceChainId(bytes32 _messageSourceChainId) public { | ||
messageSourceChainId = _messageSourceChainId; | ||
} | ||
|
||
function __setSender(address _messageSender) public { | ||
messageSender = _messageSender; | ||
} | ||
|
||
} | ||
|
||
contract AMBReceiverTest is Test { | ||
|
||
AMBMock amb; | ||
TargetContractMock target; | ||
|
||
AMBReceiver receiver; | ||
|
||
bytes32 sourceChainId = bytes32(uint256(1)); | ||
address sourceAuthority = makeAddr("sourceAuthority"); | ||
address randomAddress = makeAddr("randomAddress"); | ||
|
||
function setUp() public { | ||
amb = new AMBMock(sourceChainId, sourceAuthority); | ||
target = new TargetContractMock(); | ||
|
||
receiver = new AMBReceiver( | ||
address(amb), | ||
sourceChainId, | ||
sourceAuthority, | ||
address(target) | ||
); | ||
} | ||
|
||
function test_constructor() public { | ||
receiver = new AMBReceiver( | ||
address(amb), | ||
sourceChainId, | ||
sourceAuthority, | ||
address(target) | ||
); | ||
|
||
assertEq(receiver.amb(), address(amb)); | ||
assertEq(receiver.sourceChainId(), sourceChainId); | ||
assertEq(receiver.sourceAuthority(), sourceAuthority); | ||
assertEq(receiver.target(), address(target)); | ||
} | ||
|
||
function test_forward_invalidSender() public { | ||
vm.prank(randomAddress); | ||
vm.expectRevert("AMBReceiver/invalid-sender"); | ||
TargetContractMock(address(receiver)).increment(); | ||
} | ||
|
||
function test_forward_invalidSourceChainId() public { | ||
amb.__setSourceChainId(bytes32(uint256(2))); | ||
|
||
vm.prank(address(amb)); | ||
vm.expectRevert("AMBReceiver/invalid-sourceChainId"); | ||
TargetContractMock(address(receiver)).increment(); | ||
} | ||
|
||
function test_forward_invalidSourceAuthority() public { | ||
amb.__setSender(randomAddress); | ||
|
||
vm.prank(address(amb)); | ||
vm.expectRevert("AMBReceiver/invalid-sourceAuthority"); | ||
TargetContractMock(address(receiver)).increment(); | ||
} | ||
|
||
function test_forward_success() public { | ||
assertEq(target.count(), 0); | ||
vm.prank(address(amb)); | ||
TargetContractMock(address(receiver)).increment(); | ||
assertEq(target.count(), 1); | ||
} | ||
|
||
function test_forward_revert() public { | ||
vm.prank(address(amb)); | ||
vm.expectRevert("TargetContract/error"); | ||
TargetContractMock(address(receiver)).revertFunc(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
TargetContractMock(address(receiver)).increment(); | ||
} | ||
|
||
function test_forward_invalidL1AuthoritySourceAuthorityNoOffset() public { | ||
vm.prank(sourceAuthority); | ||
vm.expectRevert("ArbitrumReceiver/invalid-l1Authority"); | ||
TargetContractMock(address(receiver)).increment(); | ||
} | ||
|
||
function test_forward_success() public { | ||
assertEq(target.count(), 0); | ||
vm.prank(sourceAuthorityWithOffset); | ||
TargetContractMock(address(receiver)).increment(); | ||
assertEq(target.count(), 1); | ||
} | ||
|
||
function test_forward_revert() public { | ||
vm.prank(sourceAuthorityWithOffset); | ||
vm.expectRevert("TargetContract/error"); | ||
TargetContractMock(address(receiver)).revertFunc(); | ||
} | ||
|
||
} |
Oops, something went wrong.