Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Filter EVM logs in unit tests read by generic relayer to just wormhole publish message logs. #82

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions ethereum/forge-test/CoreRelayer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1219,12 +1219,16 @@ contract TestCoreRelayer is Test {
mapping(bytes32 => ICoreRelayer.TargetDeliveryParametersSingle) pastDeliveries;

function genericRelayer(uint16 chainId, uint8 num) internal {
Vm.Log[] memory entries = vm.getRecordedLogs();
bytes[] memory encodedVMs = new bytes[](num);
for (uint256 i = 0; i < num; i++) {
encodedVMs[i] = relayerWormholeSimulator.fetchSignedMessageFromLogs(
entries[i], chainId, address(uint160(uint256(bytes32(entries[i].topics[1]))))
);
{
// Filters all events to just the wormhole messages.
Vm.Log[] memory entries = relayerWormholeSimulator.fetchWormholeMessageFromLog(vm.getRecordedLogs());
assertTrue(entries.length >= num);
for (uint256 i = 0; i < num; i++) {
encodedVMs[i] = relayerWormholeSimulator.fetchSignedMessageFromLogs(
entries[i], chainId, address(uint160(uint256(bytes32(entries[i].topics[1]))))
);
}
}

IWormhole.VM[] memory parsed = new IWormhole.VM[](encodedVMs.length);
Expand Down
18 changes: 10 additions & 8 deletions ethereum/forge-test/WormholeSimulator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,19 @@ contract WormholeSimulator {
/**
* @notice Finds published Wormhole events in forge logs
* @param logs The forge Vm.log captured when recording events during test execution
* @param numMessages The expected number of Wormhole events in the forge logs
*/
function fetchWormholeMessageFromLog(Vm.Log[] memory logs, uint8 numMessages)
public
pure
returns (Vm.Log[] memory)
{
function fetchWormholeMessageFromLog(Vm.Log[] memory logs) public pure returns (Vm.Log[] memory) {
uint256 count = 0;
for (uint256 i = 0; i < logs.length; i++) {
if (logs[i].topics[0] == keccak256("LogMessagePublished(address,uint64,uint32,bytes,uint8)")) {
count += 1;
}
}

// create log array to save published messages
Vm.Log[] memory published = new Vm.Log[](numMessages);
Vm.Log[] memory published = new Vm.Log[](count);

uint8 publishedIndex = 0;
uint256 publishedIndex = 0;
for (uint256 i = 0; i < logs.length; i++) {
if (logs[i].topics[0] == keccak256("LogMessagePublished(address,uint64,uint32,bytes,uint8)")) {
published[publishedIndex] = logs[i];
Expand Down