Skip to content

Commit

Permalink
Update to latest analog-gmp version (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lohann authored Apr 18, 2024
1 parent 9a1baad commit 0a64eb5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 13 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
name: test

on: workflow_dispatch
on:
push:
branches:
- master
- main
- staging
- release-v*
pull_request:

env:
FOUNDRY_PROFILE: ci
Expand Down
4 changes: 2 additions & 2 deletions examples/simple/Counter.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

contract Counter is IGmpRecipient {
contract Counter is IGmpReceiver {
address private immutable _gateway;
uint256 public number;

Expand Down
58 changes: 49 additions & 9 deletions examples/simple/Counter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,71 @@
pragma solidity ^0.8.0;

import {Test, console} from "forge-std/Test.sol";
import {IGateway} from "@analog-gmp/interfaces/IGateway.sol";
import {GmpTestTools} from "@analog-gmp-testing/GmpTestTools.sol";
import {Counter} from "./Counter.sol";

contract CounterTest is Test {
Counter public counter;

/**
* @dev The address of Alice
*/
address private constant alice = address(bytes20(keccak256("Alice")));

/**
* @dev Sepolia network ID and gateway
*/
uint16 private constant sepoliaId = GmpTestTools.SEPOLIA_NETWORK_ID;
IGateway private constant sepoliaGateway = GmpTestTools.SEPOLIA_GATEWAY;

/**
* @dev Shibuya network ID and gateway
*/
uint16 private constant shibuyaId = GmpTestTools.SHIBUYA_NETWORK_ID;
IGateway private constant shibuyaGateway = GmpTestTools.SHIBUYA_GATEWAY;

/**
* @dev Test setup, deploys the gateways contracts and creates shibuya and sepolia forks respectively.
* The `Counter.sol` contract is deployed on the Sepolia fork.
*/
function setUp() external {
// Setup test environment, deploy gateways and create forks
GmpTestTools.setup();
GmpTestTools.switchNetwork(GmpTestTools.SEPOLIA_NETWORK_ID);
counter = new Counter(address(GmpTestTools.SEPOLIA_GATEWAY));

// Deploy Counter contract on Sepolia
GmpTestTools.switchNetwork(sepoliaId);
counter = new Counter(address(sepoliaGateway));
}

/**
* @dev Example incrementing the counter by sending a message from Shibuya to Sepolia
*/
function test_Increment() external {
GmpTestTools.switchNetwork(GmpTestTools.SEPOLIA_NETWORK_ID);
// Fund `alice` account with 100 ether in all networks
GmpTestTools.deal(alice, 100 ether);

// Set alice as `msg.sender` and `tx.origin` of all subsequent calls
vm.startPrank(alice, alice);

// Switch to Sepolia Fork
GmpTestTools.switchNetwork(sepoliaId);
assertEq(counter.number(), 0);

// Deposit funds to pay for the execution cost from Shibuya to Sepolia
bytes32 source = bytes32(uint256(uint160(alice)));
sepoliaGateway.deposit{value: 1 ether}(source, shibuyaId);
assertEq(counter.number(), 0);
// Deposit
bytes32 source = bytes32(uint256(uint160(msg.sender)));
GmpTestTools.SEPOLIA_GATEWAY.deposit{value: 100 ether}(source, GmpTestTools.SEPOLIA_NETWORK_ID);

GmpTestTools.switchNetwork(GmpTestTools.SHIBUYA_NETWORK_ID);
GmpTestTools.SHIBUYA_GATEWAY.submitMessage(address(counter), GmpTestTools.SEPOLIA_NETWORK_ID, 100_000, "");
// Submit a new GMP from Shibuya to Sepolia
GmpTestTools.switchNetwork(shibuyaId);
shibuyaGateway.submitMessage(address(counter), sepoliaId, 100_000, "");

GmpTestTools.switchNetwork(GmpTestTools.SEPOLIA_NETWORK_ID);
// Check the counter before relaying the GMP message
GmpTestTools.switchNetwork(sepoliaId);
assertEq(counter.number(), 0);

// Relay all pending GMP messages and check the counter again
GmpTestTools.relayMessages();
assertEq(counter.number(), 1);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/contracts

0 comments on commit 0a64eb5

Please sign in to comment.