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

Commit

Permalink
Filter EVM logs in unit tests to just wormhole publish message logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
scnale committed Feb 7, 2023
1 parent 2055d89 commit 6d1ae8f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
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
14 changes: 10 additions & 4 deletions ethereum/forge-test/WormholeSimulator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,23 @@ 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)
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

0 comments on commit 6d1ae8f

Please sign in to comment.