Skip to content

Commit

Permalink
chore(test): add ReplayAttack test
Browse files Browse the repository at this point in the history
  • Loading branch information
gitmp01 committed Aug 15, 2024
1 parent e909c69 commit b7b0289
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions solidity/test/forge/Integration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,44 @@ contract IntegrationTest is Test, Helper {

adapter_B.settle(operation, metadata);
}

function test_settle_e2e_RevertWhen_ReplayAttack() public {
uint256 amount = 10000;

bytes memory data = vm.parseBytes("0x");

vm.recordLogs();
_performERC20Swap(
CHAIN_A,
address(erc20_A),
user,
address(adapter_A),
CHAIN_B,
address(recipient),
amount,
data
);

Vm.Log[] memory logs = vm.getRecordedLogs();
operation = _getOperationFromLogs(logs, SWAP_TOPIC);
metadata = _getMetadataFromLogs(
logs,
SWAP_TOPIC,
operation,
attestatorPrivateKey
);

bytes32 eventId = _getEventId(metadata.preimage);

vm.chainId(CHAIN_B);

vm.expectEmit(address(adapter_B));
emit IAdapter.Settled(eventId);
adapter_B.settle(operation, metadata);

vm.expectRevert(
abi.encodeWithSelector(Adapter.AlreadyProcessed.selector, eventId)
);
adapter_B.settle(operation, metadata);
}
}

0 comments on commit b7b0289

Please sign in to comment.