Analog-Labs / analog-gmp-examples

Gateway smart contract and GMP testing suites
MIT License
21 stars 28 forks source link
analog evm gateway gmp

Analog's cross-chain dApp examples

This repo provides the code for several example of dApps utilizing Analog's General Message Passing protocol.

Dependencies

This project uses Forge Ethereum testing framework (like Truffle, Hardhat and DappTools). Install instructions: https://book.getfoundry.sh/

Examples

Starting a New Project

To start a new project with Foundry, use forge init

forge init hello_gmp

This creates a new directory hello_gmp from the default Foundry template. This also initializes a new git repository.

Install analog-gmp dependencies.

cd hello_gmp
forge install Analog-Labs/analog-gmp

All setup! now just need to import gmp dependencies from @analog-gmp:

import {IGmpReceiver} from "@analog-gmp/interfaces/IGmpReceiver.sol";
import {IGateway} from "@analog-gmp/interfaces/IGateway.sol";

Writing Tests

You can easily write cross-chain unit tests using analog's testing tools at @analog-gmp-testing.

import {GmpTestTools} from "@analog-gmp-testing/GmpTestTools.sol";

// Deploy gateway contracts and create forks for all supported networks
GmpTestTools.setup();

// Set `account` balance in all networks
GmpTestTools.deal(address(account), 100 ether);

// Switch to Sepolia network
GmpTestTools.switchNetwork(5);

// Switch to Shibuya network and set `account` as `msg.sender` and `tx.origin`
GmpTestTools.switchNetwork(7, address(account));

// Relay all pending GMP messages.
GmpTestTools.relayMessages();

Build

$ forge build

Test

$ forge test -vvv

Format

$ forge fmt

License

Analog's Contracts is released under the MIT License.