Skip to content

Commit

Permalink
feat: test
Browse files Browse the repository at this point in the history
  • Loading branch information
wellitongervickas committed Dec 6, 2023
1 parent 5c9ad11 commit e810628
Show file tree
Hide file tree
Showing 17 changed files with 1,023 additions and 579 deletions.
15 changes: 0 additions & 15 deletions contracts/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,6 @@ contract Bridge is IBridge, AccessManaged {
s_chainId = chainId_;
}

modifier checkEvmChainIdAdapterIsValid(IBridge.EvmChainSettings memory evmChainSettings_) {
/// @dev: todo: check by sender when off ramp
if (evmChainSettings_.adapter == address(0)) {
revert IBridge.AdapterNotFound();
}
_;
}

modifier checkEvmChainIdIsEnabled(IBridge.EvmChainSettings memory evmChainSettings_) {
if (!evmChainSettings_.isEnabled) {
revert IBridge.AdapterNotEnabled();
}
_;
}

/// @inheritdoc IBridge
function chainId() public view returns (uint256) {
return s_chainId;
Expand Down
9 changes: 6 additions & 3 deletions contracts/adapters/BaseAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract contract BaseAdapter is IBaseAdapter, AccessManaged {
}

/// @inheritdoc IBaseAdapter
function bridge() public view override returns (address) {
function getBridge() public view override returns (address) {
return s_bridge;
}

Expand All @@ -29,15 +29,18 @@ abstract contract BaseAdapter is IBaseAdapter, AccessManaged {
}

/// @inheritdoc IBaseAdapter
function sendMessageUsingERC20(IBridge.ERC721Send memory payload_, uint256 quotedFee_) external override {
function sendMessageUsingERC20(
IBridge.ERC721Send memory payload_,
uint256 quotedFee_
) external override restricted {
if (quotedFee_ < getFee(payload_)) revert InsufficientFeeTokenAmount();

_sendMessage(payload_, quotedFee_);
emit IBaseAdapter.ERC721Sent(payload_.toChain, payload_.receiver, payload_.data);
}

/// @inheritdoc IBaseAdapter
function sendMessageUsingNative(IBridge.ERC721Send memory payload_) external payable override {
function sendMessageUsingNative(IBridge.ERC721Send memory payload_) external payable override restricted {
if (msg.value < getFee(payload_)) revert InsufficientFeeTokenAmount();

_sendMessage(payload_, msg.value);
Expand Down
15 changes: 8 additions & 7 deletions contracts/adapters/CCIPAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ contract CCIPAdapter is BaseAdapter, CCIPReceiver, AutomationCompatibleInterface
address feeToken_
) BaseAdapter(bridge_, accessManagement_, feeToken_) CCIPReceiver(router_) {}

function setUpdateInterval(uint256 updateInterval_) external {
function setUpdateInterval(uint256 updateInterval_) external restricted {
s_updateInterval = updateInterval_;
}

function updateInterval() public view returns (uint256) {
return s_updateInterval;
}

function setDefaultExecutionLimit(uint256 defaultExecutionLimit_) external {
function setDefaultExecutionLimit(uint256 defaultExecutionLimit_) external restricted {
s_defaultExecutionLimit = defaultExecutionLimit_;
}

Expand All @@ -46,12 +46,13 @@ contract CCIPAdapter is BaseAdapter, CCIPReceiver, AutomationCompatibleInterface
function checkUpkeep(
bytes calldata /* checkData */
) external view override returns (bool upkeepNeeded, bytes memory /* performData */) {
if (s_pendingMessagesToExecute.length == 0) {
if ((block.timestamp - s_lastTimeStamp) > s_updateInterval) {
/// @dev execute messages if there are any message available
upkeepNeeded = s_pendingMessagesToExecute.length > 0;
} else {
upkeepNeeded = false;
return (upkeepNeeded, "");
}

upkeepNeeded = (block.timestamp - s_lastTimeStamp) > s_updateInterval;
return (upkeepNeeded, "");
}

Expand Down Expand Up @@ -95,7 +96,7 @@ contract CCIPAdapter is BaseAdapter, CCIPReceiver, AutomationCompatibleInterface
}

/// @inheritdoc CCIPReceiver
function ccipReceive(Client.Any2EVMMessage memory any2EvmMessage) external override {
function ccipReceive(Client.Any2EVMMessage memory any2EvmMessage) external override restricted {
_ccipReceive(any2EvmMessage);
}

Expand Down Expand Up @@ -132,7 +133,7 @@ contract CCIPAdapter is BaseAdapter, CCIPReceiver, AutomationCompatibleInterface
while (limit > 0) {
IBridge.ERC721Receive memory payload = s_pendingMessagesToExecute[lastIndex];

IBridge(bridge()).receiveERC721(payload);
IBridge(getBridge()).receiveERC721(payload);

if (lastIndex > 0) {
lastIndex--;
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IBaseAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface IBaseAdapter {

event ERC721Received(uint256 fromChain_, address sender_, bytes data_);

function bridge() external view returns (address);
function getBridge() external view returns (address);

function feeToken() external view returns (address);

Expand Down
Loading

0 comments on commit e810628

Please sign in to comment.