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 12, 2024
1 parent 1c0c81f commit a82659f
Show file tree
Hide file tree
Showing 10 changed files with 1,072 additions and 1,475 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';

57 changes: 53 additions & 4 deletions contracts/test/TestSwap.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,68 @@
// 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 claimAddress,
address refundAddress,
uint timelock
) external {
(bool success, ) = payable(msg.sender).call{value: amount}("");
require(success, "Could not transfer Ether");

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 locked in the contract");
}

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

}
Loading

0 comments on commit a82659f

Please sign in to comment.