Skip to content

Commit

Permalink
test(protocol): Token vault foundry tests (#13627)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey authored Apr 20, 2023
1 parent 6095326 commit 4f15527
Show file tree
Hide file tree
Showing 5 changed files with 372 additions and 445 deletions.
52 changes: 0 additions & 52 deletions packages/protocol/contracts/bridge/TokenVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -137,58 +137,6 @@ contract TokenVault is EssentialContract {
EssentialContract._init(addressManager);
}

/**
* Receives Ether and constructs a Bridge message. Sends the Ether and
* message along to the Bridge.
*
* @dev This function doesn't' seem to belong here as it has nothing to
* do with ERC20 tokens. It's added here only for convenience.
*
* @param destChainId @custom:see IBridge.Message
* @param to @custom:see IBridge.Message
* @param gasLimit @custom:see IBridge.Message
* @param processingFee @custom:see IBridge.Message
* @param refundAddress @custom:see IBridge.Message
* @param memo @custom:see IBridge.Message
*/
function sendEther(
uint256 destChainId,
address to,
uint256 gasLimit,
uint256 processingFee,
address refundAddress,
string memory memo
) external payable nonReentrant {
if (
to == address(0) || to == resolve(destChainId, "token_vault", false)
) revert TOKENVAULT_INVALID_TO();

if (msg.value <= processingFee) revert TOKENVAULT_INVALID_VALUE();

IBridge.Message memory message;
message.destChainId = destChainId;
message.owner = msg.sender;
message.to = to;
message.gasLimit = gasLimit;
message.processingFee = processingFee;
message.callValue = msg.value - processingFee;
message.refundAddress = refundAddress;
message.memo = memo;
// message.depositValue = 0;

bytes32 msgHash = IBridge(resolve("bridge", false)).sendMessage{
value: msg.value
}(message);

emit EtherSent({
msgHash: msgHash,
from: message.owner,
to: message.to,
destChainId: destChainId,
amount: message.callValue
});
}

/**
* Transfers ERC20 tokens to this vault and sends a message to the
* destination chain so the user can receive the same amount of tokens
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/contracts/test/erc20/FreeMintERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ contract FreeMintERC20 is ERC20 {
constructor(string memory name, string memory symbol) ERC20(name, symbol) {}

function mint(address to) public {
if (minters[msg.sender]) {
if (minters[to]) {
revert HasMinted();
}

minters[msg.sender] = true;
minters[to] = true;
_mint(to, 50 * (10 ** decimals()));
}
}
Loading

0 comments on commit 4f15527

Please sign in to comment.