Skip to content

Commit 2b762f1

Browse files
committed
WIP - ccipReceive tests
1 parent 8068820 commit 2b762f1

File tree

4 files changed

+599
-50
lines changed

4 files changed

+599
-50
lines changed

src/interfaces/IEnsoCCIPReceiver.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ interface IEnsoCCIPReceiver {
4747
/// @dev errorData encodings:
4848
/// - ALREADY_EXECUTED: (bytes32 messageId)
4949
/// - Others: empty bytes unless specified by the implementation.
50-
event MessageValidationFailed(bytes32 indexed messageId, ErrorCode errorCode, bytes errorData);
50+
event MessageValidationFailed(bytes32 indexed messageId, ErrorCode indexed errorCode, bytes errorData);
5151

5252
/// @notice Funds were quarantined in the receiver instead of delivered to the payload receiver.
5353
/// @param messageId The CCIP message id.
@@ -56,7 +56,7 @@ interface IEnsoCCIPReceiver {
5656
/// @param amount Token amount retained.
5757
/// @param receiver Original payload receiver (informational; may be zero if not decoded).
5858
event MessageQuarantined(
59-
bytes32 indexed messageId, ErrorCode code, address token, uint256 amount, address receiver
59+
bytes32 indexed messageId, ErrorCode indexed code, address token, uint256 amount, address receiver
6060
);
6161

6262
/// @notice Emitted when Enso Shortcuts execution succeeds for a CCIP message.
@@ -69,7 +69,7 @@ interface IEnsoCCIPReceiver {
6969
event ShortcutExecutionFailed(bytes32 indexed messageId, bytes err);
7070

7171
/// @notice Emitted when the owner recovers tokens from the receiver.
72-
event TokensRecovered(address token, address to, uint256 amount);
72+
event TokensRecovered(address indexed token, address indexed to, uint256 amount);
7373

7474
// -------------------------------------------------------------------------
7575
// Errors

test/unit/concrete/bridge/ensoCCIPReceiver/EnsoCCIPReceiver.t.sol

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// SPDX-License-Identifier: GPL-3.0-only
22
pragma solidity ^0.8.28;
33

4+
import { EnsoShortcuts } from "../../../../../src/EnsoShortcuts.sol";
45
import { EnsoCCIPReceiver } from "../../../../../src/bridge/EnsoCCIPReceiver.sol";
56
import { EnsoShortcutsHelpers } from "../../../../../src/helpers/EnsoShortcutsHelpers.sol";
67
import { EnsoRouter } from "../../../../../src/router/EnsoRouter.sol";
8+
import { MockERC20 } from "../../../../mocks/MockERC20.sol";
79
import { WETH9 } from "../../../../mocks/WETH9.sol";
810
import { MockCCIPRouter } from "chainlink-ccip/test/mocks/MockRouter.sol";
911
import { Test } from "forge-std-1.9.7/Test.sol";
@@ -14,10 +16,13 @@ abstract contract EnsoCCIPReceiver_Unit_Concrete_Test is Test {
1416
address payable internal s_account1;
1517
address payable internal s_account2;
1618
EnsoRouter internal s_ensoRouter;
19+
EnsoShortcuts internal s_ensoShortcuts;
1720
EnsoShortcutsHelpers internal s_ensoShortcutsHelpers;
1821
MockCCIPRouter internal s_ccipRouter;
1922
EnsoCCIPReceiver internal s_ensoCcipReceiver;
2023
WETH9 internal s_weth;
24+
MockERC20 internal s_tokenA;
25+
MockERC20 internal s_tokenB;
2126

2227
function setUp() public virtual {
2328
s_deployer = payable(vm.addr(1));
@@ -40,6 +45,9 @@ abstract contract EnsoCCIPReceiver_Unit_Concrete_Test is Test {
4045
s_ensoRouter = new EnsoRouter();
4146
vm.label(address(s_ensoRouter), "EnsoRouter");
4247

48+
s_ensoShortcuts = EnsoShortcuts(payable(s_ensoRouter.shortcuts()));
49+
vm.label(address(s_ensoShortcuts), "EnsoShortcuts");
50+
4351
s_ensoShortcutsHelpers = new EnsoShortcutsHelpers();
4452
vm.label(address(s_ensoShortcutsHelpers), "EnsoShortcutsHelpers");
4553

@@ -51,6 +59,15 @@ abstract contract EnsoCCIPReceiver_Unit_Concrete_Test is Test {
5159

5260
s_weth = new WETH9();
5361
vm.label(address(s_weth), "WETH9");
62+
63+
s_tokenA = new MockERC20("Token A", "TKNA");
64+
vm.label(address(s_tokenA), "TKNA");
65+
s_tokenA.mint(s_deployer, 1000 ether);
66+
67+
s_tokenB = new MockERC20("Token B", "TKNB");
68+
vm.label(address(s_tokenB), "TKNB");
69+
s_tokenB.mint(s_deployer, 1000 ether);
70+
5471
vm.stopPrank();
5572
}
5673
}

test/unit/concrete/bridge/ensoCCIPReceiver/EnsoCCIPReceiver.tree

Lines changed: 107 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,115 @@
44
// └── when caller is pending owner
55
// └── it should transfer ownership
66

7+
// EnsoCCIPReceiver::CcipReceive
8+
// # when caller is not ccipRouter
9+
// ## it should revert
10+
// # when caller is ccipRouter
11+
// ## when message was already executed
12+
// ### it should emit MessageValidationFailed
13+
// ### it should not update executedMessage
14+
// ## when message was not executed
15+
// ### when message has no tokens
16+
// #### it should emit MessageValidationFailed
17+
// #### it should update executedMessage
18+
// #### it should emit MessageQuarantined
19+
// ### when message has tokens
20+
// #### when message has more than one token
21+
// ##### it should emit MessageValidationFailed
22+
// ##### it should update executedMessage
23+
// ##### it should emit MessageQuarantined
24+
// ##### it should escrow message tokens
25+
// #### when message has single token
26+
// ##### when message token amount is zero
27+
// ###### it should emit MessageValidationFailed
28+
// ###### it should update executedMessage
29+
// ###### it should emit MessageQuarantined
30+
// ##### when message token amount is gt zero
31+
// ###### when message data is malformed
32+
// ####### it should emit MessageValidationFailed
33+
// ####### it should update executedMessage
34+
// ####### it should emit MessageQuarantined
35+
// ####### it should escrow message token
36+
// ###### when message data is well formed
37+
// ####### when message data receiver is zero address
38+
// ######## it should emit MessageValidationFailed
39+
// ######## it shoud update executedMessage
40+
// ######## it should escrow message token
41+
// ######## it should emit MessageQuarantined
42+
// ####### when message data receiver is not zero address
43+
// ######## when contract is paused
44+
// ######### it should emit MessageValidationFailed
45+
// ######### it shoud update executedMessage
46+
// ######### it should safe transfer token amount to receiver
47+
// ######## when contract is not paused
48+
// ######### when shortcut execution was successful
49+
// ########## it shoud update executedMessage
50+
// ########## it should emit ShortcutExecutionSuccessful
51+
// ######### when shortcut execution failed
52+
// ########## it shoud update executedMessage
53+
// ########## it should emit ShortcutExecutionFailed
54+
// ########## it should safe transfer token amount to receiver
55+
756
EnsoCCIPReceiver::CcipReceive
8-
# when caller is not ccipRouter
9-
## it should revert
10-
# when caller is ccipRouter
11-
## when message was already executed
12-
### it should emit MessageValidationFailed
13-
## when message was not executed
14-
### when message has no tokens
15-
#### it should emit MessageValidationFailed
16-
### when message has tokens
17-
#### when message has more than one token
18-
##### it should emit MessageValidationFailed
19-
#### when message has single token
20-
##### when message token amount is zero
21-
###### it should emit MessageValidationFailed
22-
##### when message token amount is gt zero
23-
###### when message data is malformed
24-
####### it should emit MessageValidationFailed
25-
###### when message data is well formed
26-
####### when message data receiver is zero address
27-
######## it should emit MessageValidationFailed
28-
######## it shoud set executedMessage to true
29-
######## it should emit MessageQuarantined
30-
######## it should escrow message token amount
31-
####### when message data receiver is not zero address
32-
######## when contract is paused
33-
######### it should emit MessageValidationFailed
34-
######### it shoud set executedMessage to true
35-
######### it should safe transfer token amount to receiver
36-
######## when contract is not paused
37-
######### when shortcut execution was was successful
38-
########## it shoud set executedMessage to true
39-
########## it should emit ShortcutExecutionSuccessful
40-
######### when shortcut execution failed
41-
########## it should emit ShortcutExecutionFailed
42-
########## it should safe transfer token amount to receiver
57+
├── when caller is not ccipRouter
58+
│ └── it should revert
59+
└── when caller is ccipRouter
60+
├── when message was already executed
61+
│ ├── it should emit MessageValidationFailed
62+
│ └── it should update executedMessage
63+
└── when message was not executed
64+
├── when message has no tokens
65+
│ ├── it should emit MessageValidationFailed
66+
│ └── it should not update executedMessage
67+
└── when message has tokens
68+
├── when message has more than one token
69+
│ ├── it should emit MessageValidationFailed
70+
│ ├── it should not update executedMessage
71+
│ ├── it should emit MessageQuarantined
72+
│ └── it should escrow message tokens
73+
└── when message has single token
74+
├── when message token amount is zero
75+
│ ├── it should emit MessageValidationFailed
76+
│ ├── it should not update executedMessage
77+
│ └── it should emit MessageQuarantined
78+
└── when message token amount is gt zero
79+
├── when message data is malformed
80+
│ ├── it should emit MessageValidationFailed
81+
│ ├── it should not update executedMessage
82+
│ ├── it should emit MessageQuarantined
83+
│ └── it should escrow message token
84+
└── when message data is well formed
85+
├── when message data receiver is zero address
86+
│ ├── it should emit MessageValidationFailed
87+
│ ├── it shoud update executedMessage
88+
│ ├── it should escrow message token
89+
│ └── it should emit MessageQuarantined
90+
└── when message data receiver is not zero address
91+
├── when contract is paused
92+
│ ├── it should emit MessageValidationFailed
93+
│ ├── it shoud update executedMessage
94+
│ └── it should safe transfer token amount to receiver
95+
└── when contract is not paused
96+
├── when shortcut execution was successful
97+
│ ├── it shoud update executedMessage
98+
│ └── it should emit ShortcutExecutionSuccessful
99+
└── when shortcut execution failed
100+
├── it shoud update executedMessage
101+
├── it should emit ShortcutExecutionFailed
102+
└── it should safe transfer token amount to receiver
43103

44104
// EnsoCCIPReceiver::Constructor
45105
// └── when deployed
46106
// ├── it should set owner
47107
// ├── it should set ccipRouter
48108
// └── it should set ensoRouter
49109

50-
EnsoCCIPReceiver::RecoverTokens
51-
# when caller is not self
52-
## it should revert
53-
# when caller is self
54-
## it should force approve amount to ensoRouter
55-
## it should call ensoRouter routeSingle
110+
// EnsoCCIPReceiver::RecoverTokens
111+
// # when caller is not self
112+
// ## it should revert
113+
// # when caller is self
114+
// ## it should force approve amount to ensoRouter
115+
// ## it should call ensoRouter routeSingle
56116

57117
// EnsoCCIPReceiver::Pause
58118
// ├── when caller is not owner
@@ -72,12 +132,12 @@ EnsoCCIPReceiver::RecoverTokens
72132
// └── when caller is owner
73133
// └── it should start ownership transfer
74134

75-
EnsoCCIPReceiver::RecoverTokens
76-
# when caller is not owner
77-
## it should revert
78-
# when caller is owner
79-
## it should safe transfer amount to recipient
80-
## it should emit TOkensRecovered
135+
// EnsoCCIPReceiver::RecoverTokens
136+
// # when caller is not owner
137+
// ## it should revert
138+
// # when caller is owner
139+
// ## it should safe transfer amount to recipient
140+
// ## it should emit TOkensRecovered
81141

82142
// EnsoCCIPReceiver::RenounceOwnership
83143
// ├── when caller is not owner

0 commit comments

Comments
 (0)