Skip to content

Commit

Permalink
Adding mocks to verify that the sdk is actually importable
Browse files Browse the repository at this point in the history
  • Loading branch information
sullof committed Nov 4, 2024
1 parent fdee3b4 commit 3bf3eff
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
63 changes: 63 additions & 0 deletions scripts/mocks/HelloWormhole.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {IWormholeRelayer} from "../interfaces/IWormholeRelayer.sol";
import {IWormholeReceiver} from "../interfaces/IWormholeReceiver.sol";

contract HelloWormhole is IWormholeReceiver {
event GreetingReceived(string greeting, uint16 senderChain, address sender);

uint256 constant GAS_LIMIT = 50_000;

IWormholeRelayer public immutable wormholeRelayer;

string public latestGreeting;

constructor(address _wormholeRelayer) {
wormholeRelayer = IWormholeRelayer(_wormholeRelayer);
}

function quoteCrossChainGreeting(
uint16 targetChain
) public view returns (uint256 cost) {
(cost, ) = wormholeRelayer.quoteEVMDeliveryPrice(
targetChain,
0,
GAS_LIMIT
);
}

function sendCrossChainGreeting(
uint16 targetChain,
address targetAddress,
string memory greeting
) public payable {
uint256 cost = quoteCrossChainGreeting(targetChain);
require(msg.value == cost);
wormholeRelayer.sendPayloadToEvm{value: cost}(
targetChain,
targetAddress,
abi.encode(greeting, msg.sender), // payload
0, // no receiver value needed since we're just passing a message
GAS_LIMIT
);
}

function receiveWormholeMessages(
bytes memory payload,
bytes[] memory, // additionalVaas
bytes32, // address that called 'sendPayloadToEvm' (HelloWormhole contract address)
uint16 sourceChain,
bytes32 // unique identifier of delivery
) public payable override {
require(msg.sender == address(wormholeRelayer), "Only relayer allowed");

// Parse the payload and do the corresponding actions!
(string memory greeting, address sender) = abi.decode(
payload,
(string, address)
);
latestGreeting = greeting;
emit GreetingReceived(latestGreeting, sourceChain, sender);
}
}
5 changes: 4 additions & 1 deletion scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ if [[ -d "contracts" ]]; then
rm -rf contracts
fi

mkdir contracts
mkdir -p contracts

cp -r src/* contracts/.
cp -r scripts/mocks contracts/.
rm -rf contracts/testing
node scripts/clean-remapping.js

Expand All @@ -40,6 +41,8 @@ npx hardhat compile
if [ $? -ne 0 ]; then
echo "Compilation failed. Exiting."
exit 1
elif
rm -rf contracts/mocks
fi

# Continue with the rest of your script
Expand Down

0 comments on commit 3bf3eff

Please sign in to comment.