@@ -10,6 +10,13 @@ import "../interfaces/IWormholeReceiver.sol";
10
10
11
11
import "forge-std/console.sol " ;
12
12
13
+ interface Structs {
14
+ struct XAddress {
15
+ uint16 chainId;
16
+ bytes32 addr;
17
+ }
18
+ }
19
+
13
20
contract MockRelayerIntegration is IWormholeReceiver {
14
21
using BytesLib for bytes ;
15
22
@@ -28,7 +35,8 @@ contract MockRelayerIntegration is IWormholeReceiver {
28
35
// mapping of other MockRelayerIntegration contracts
29
36
mapping (uint16 => bytes32 ) registeredContracts;
30
37
31
- bytes [] messages;
38
+ // bytes[] messages;
39
+ bytes [][] messageHistory;
32
40
33
41
struct FurtherInstructions {
34
42
bool keepSending;
@@ -139,14 +147,17 @@ contract MockRelayerIntegration is IWormholeReceiver {
139
147
function receiveWormholeMessages (bytes [] memory wormholeObservations , bytes [] memory ) public payable override {
140
148
// loop through the array of wormhole observations from the batch and store each payload
141
149
uint256 numObservations = wormholeObservations.length ;
142
- messages = new bytes [](wormholeObservations.length - 2 );
150
+ bytes [] memory messages = new bytes [](wormholeObservations.length - 2 );
151
+ uint16 emitterChainId;
143
152
for (uint256 i = 0 ; i < numObservations - 2 ; i++ ) {
144
153
(IWormhole.VM memory parsed , bool valid , string memory reason ) =
145
154
wormhole.parseAndVerifyVM (wormholeObservations[i]);
146
155
require (valid, reason);
147
156
require (registeredContracts[parsed.emitterChainId] == parsed.emitterAddress);
157
+ emitterChainId = parsed.emitterChainId;
148
158
messages[i] = parsed.payload;
149
159
}
160
+ messageHistory.push (messages);
150
161
151
162
(IWormhole.VM memory parsed , bool valid , string memory reason ) =
152
163
wormhole.parseAndVerifyVM (wormholeObservations[wormholeObservations.length - 2 ]);
@@ -183,14 +194,21 @@ contract MockRelayerIntegration is IWormholeReceiver {
183
194
}
184
195
185
196
function getMessage () public view returns (bytes memory ) {
186
- if (messages .length == 0 ) {
197
+ if (messageHistory. length == 0 || messageHistory[messageHistory. length - 1 ] .length == 0 ) {
187
198
return new bytes (0 );
188
199
}
189
- return messages [0 ];
200
+ return messageHistory[messageHistory. length - 1 ] [0 ];
190
201
}
191
202
192
203
function getMessages () public view returns (bytes [] memory ) {
193
- return messages;
204
+ if (messageHistory.length == 0 || messageHistory[messageHistory.length - 1 ].length == 0 ) {
205
+ return new bytes [](0 );
206
+ }
207
+ return messageHistory[messageHistory.length - 1 ];
208
+ }
209
+
210
+ function getMessageHistory () public view returns (bytes [][] memory ) {
211
+ return messageHistory;
194
212
}
195
213
196
214
function clearPayload (bytes32 hash ) public {
@@ -210,6 +228,13 @@ contract MockRelayerIntegration is IWormholeReceiver {
210
228
registeredContracts[chainId] = emitterAddress;
211
229
}
212
230
231
+ function registerEmitters (Structs.XAddress[] calldata emitters ) public {
232
+ require (msg .sender == owner);
233
+ for (uint256 i = 0 ; i < emitters.length ; i++ ) {
234
+ registeredContracts[emitters[i].chainId] = emitters[i].addr;
235
+ }
236
+ }
237
+
213
238
function encodeFurtherInstructions (FurtherInstructions memory furtherInstructions )
214
239
public
215
240
view
0 commit comments