Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/adapters/AxelarAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ contract AxelarAdapter is Auth, IAxelarAdapter {
/// @inheritdoc IAdapter
function estimate(uint16 centrifugeId, bytes calldata payload, uint256 gasLimit) external view returns (uint256) {
AxelarDestination memory destination = destinations[centrifugeId];
require(bytes(destination.axelarId).length != 0, UnknownChainId());

return axelarGasService.estimateGasFee(
destination.axelarId, destination.addr, payload, gasLimit + RECEIVE_COST, bytes("")
);
Expand Down
2 changes: 2 additions & 0 deletions src/adapters/LayerZeroAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ contract LayerZeroAdapter is Auth, ILayerZeroAdapter {
/// @inheritdoc IAdapter
function estimate(uint16 centrifugeId, bytes calldata payload, uint256 gasLimit) external view returns (uint256) {
LayerZeroDestination memory destination = destinations[centrifugeId];
require(destination.layerZeroEid != 0, UnknownChainId());

MessagingFee memory fee = endpoint.quote(_params(destination, payload, gasLimit + RECEIVE_COST), address(this));
return fee.nativeFee;
}
Expand Down
6 changes: 4 additions & 2 deletions src/adapters/WormholeAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ contract WormholeAdapter is Auth, IWormholeAdapter {
view
returns (uint256 nativePriceQuote)
{
(nativePriceQuote,) =
relayer.quoteEVMDeliveryPrice(destinations[centrifugeId].wormholeId, 0, gasLimit + RECEIVE_COST);
WormholeDestination memory destination = destinations[centrifugeId];
require(destination.wormholeId != 0, UnknownChainId());

(nativePriceQuote,) = relayer.quoteEVMDeliveryPrice(destination.wormholeId, 0, gasLimit + RECEIVE_COST);
}
}
2 changes: 2 additions & 0 deletions test/adapters/unit/AxelarAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ contract AxelarAdapterTest is AxelarAdapterTestBase {
vm.assume(gasLimit > 0);
vm.assume(gasLimit < adapter.RECEIVE_COST());

adapter.wire(CENTRIFUGE_CHAIN_ID, abi.encode(AXELAR_CHAIN_ID, REMOTE_AXELAR_ADDR));

bytes memory payload = "irrelevant";

axelarGasService.setReturn("estimateGasFee", gasLimit - 1);
Expand Down
4 changes: 3 additions & 1 deletion test/adapters/unit/LayerZeroAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ contract LayerZeroAdapterTest is LayerZeroAdapterTestBase {
assertEq(adapter.wards(address(this)), 1);
}

function testEstimate(uint64 gasLimit) public view {
function testEstimate(uint64 gasLimit) public {
adapter.wire(CENTRIFUGE_ID, abi.encode(LAYERZERO_ID, REMOTE_LAYERZERO_ADDR));

bytes memory payload = "irrelevant";
assertEq(adapter.estimate(CENTRIFUGE_ID, payload, gasLimit), 200_000);
}
Expand Down
4 changes: 3 additions & 1 deletion test/adapters/unit/WormholeAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ contract WormholeAdapterTest is WormholeAdapterTestBase {
assertEq(adapter.wards(address(this)), 1);
}

function testEstimate(uint64 gasLimit) public view {
function testEstimate(uint64 gasLimit) public {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT, could we add testErrUnknownChainId cases?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do in followup PR, I think in general the adapter tests can be improved a bit.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that maybe we can build some generic adapter test that acts over IAdapter and IAdapterWiring. So you only need to mock your specific adapter calls to some generic expected behavior and run this generic adapter tests for your new adapter implementation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting idea, makes sense to me yes!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adapter.wire(CENTRIFUGE_CHAIN_ID, abi.encode(WORMHOLE_CHAIN_ID, REMOTE_WORMHOLE_ADDR));

bytes memory payload = "irrelevant";
assertEq(
adapter.estimate(CENTRIFUGE_CHAIN_ID, payload, gasLimit), uint128(gasLimit + adapter.RECEIVE_COST()) * 2
Expand Down
Loading