Skip to content

Commit

Permalink
Fix local adapter (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
hieronx authored Jul 17, 2024
1 parent 6d7f242 commit 4d1d6f7
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions test/integration/LocalAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity 0.8.26;

import {Auth} from "./../../src/Auth.sol";
import {IAdapter} from "src/interfaces/gateway/IAdapter.sol";

interface PrecompileLike {
function execute(
Expand All @@ -19,7 +20,7 @@ interface GatewayLike {
/// @title Local Adapter
/// @notice Routing contract that routes from Substrate to EVM and back.
/// I.e. for testing LP in a local Centrifuge Chain deployment.
contract LocalAdapter is Auth {
contract LocalAdapter is Auth, IAdapter {
address internal constant PRECOMPILE = 0x0000000000000000000000000000000000000800;
bytes32 internal constant FAKE_COMMAND_ID = keccak256("FAKE_COMMAND_ID");

Expand All @@ -33,6 +34,7 @@ contract LocalAdapter is Auth {
event File(bytes32 indexed what, address addr);
event File(bytes32 indexed what, string data);

// --- Administrative ---
function file(bytes32 what, address data) external {
if (what == "gateway") {
gateway = GatewayLike(data);
Expand All @@ -55,6 +57,7 @@ contract LocalAdapter is Auth {
emit File(what, data);
}

// --- Incoming ---
// From Centrifuge to LP on Centrifuge (faking other domain)
function callContract(
string calldata destinationChain,
Expand All @@ -65,14 +68,23 @@ contract LocalAdapter is Auth {
emit RouteToDomain(destinationChain, destinationContractAddress, payload);
}

// From LP on Centrifuge (faking other domain) to Centrifuge
// --- Outgoing ---
/// @inheritdoc IAdapter
/// @dev From LP on Centrifuge (faking other domain) to Centrifuge
function send(bytes calldata message) public {
PrecompileLike precompile = PrecompileLike(PRECOMPILE);
precompile.execute(FAKE_COMMAND_ID, sourceChain, sourceAddress, message);

emit RouteToCentrifuge(FAKE_COMMAND_ID, sourceChain, sourceAddress, message);
}

// Added to be ignored in coverage report
function test() public {}
/// @inheritdoc IAdapter
function estimate(bytes calldata payload, uint256 baseCost) external view returns (uint256) {
return 0;
}

/// @inheritdoc IAdapter
function pay(bytes calldata payload, address refund) public payable {
return;
}
}

0 comments on commit 4d1d6f7

Please sign in to comment.