Skip to content

Commit

Permalink
refactor: integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscotobar committed Apr 15, 2024
1 parent 1c0c81f commit e440f3c
Show file tree
Hide file tree
Showing 12 changed files with 1,291 additions and 1,516 deletions.
1 change: 1 addition & 0 deletions contracts/import.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ import '@rsksmart/rif-relay-contracts/contracts/verifier/MinimalBoltzDeployVerif
import '@rsksmart/rif-relay-contracts/contracts/Penalizer.sol';
import '@rsksmart/rif-relay-contracts/contracts/utils/UtilToken.sol';
import '@rsksmart/rif-relay-contracts/contracts/interfaces/IForwarder.sol';
import '@rsksmart/rif-relay-contracts/contracts/interfaces/BoltzVerifier.sol';

66 changes: 62 additions & 4 deletions contracts/test/TestSwap.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,77 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.12;

contract TestSwap {
import "@rsksmart/rif-relay-contracts/contracts/interfaces/BoltzVerifier.sol";

contract TestSwap is NativeSwap {

uint8 constant public version = 3;

bytes32 public DOMAIN_SEPARATOR;
bytes32 public TYPEHASH_REFUND;

mapping (bytes32 => bool) public override swaps;

function addSwap(bytes32 hash) public {
swaps[hash] = true;
}

function claim(
bytes32 preimage,
uint amount,
address refundAddress,
uint timelock
) external {
(bool success, ) = payable(msg.sender).call{value: amount}("");
require(success, "Could not transfer Ether");
claim(preimage, amount, msg.sender, refundAddress, timelock);
}

function claim(
bytes32 preimage,
uint amount,
address claimAddress,
address refundAddress,
uint timelock
) public {

bytes32 preimageHash = sha256(abi.encodePacked(preimage));

bytes32 hash = hashValues(
preimageHash,
amount,
claimAddress,
refundAddress,
timelock
);

checkSwapIsLocked(hash);

delete swaps[hash];

(bool success, ) = payable(claimAddress).call{value: amount}("");
require(success, "Could not transfer RBTC");
}

function hashValues(
bytes32 preimageHash,
uint amount,
address claimAddress,
address refundAddress,
uint timelock
) public override pure returns (bytes32) {
return keccak256(abi.encodePacked(
preimageHash,
amount,
claimAddress,
refundAddress,
timelock
));
}

function checkSwapIsLocked(bytes32 hash) private view {
require(swaps[hash] == true, "NativeSwap: swap has no RBTC");
}

// solhint-disable-next-line no-empty-blocks
receive() external payable {}
receive() external payable {}

}
Loading

0 comments on commit e440f3c

Please sign in to comment.