From 0a64eb5d822b5aee364a8230442cfd1de199c2fc Mon Sep 17 00:00:00 2001 From: Lohann Paterno Coutinho Ferreira Date: Fri, 19 Apr 2024 00:51:11 +0100 Subject: [PATCH] Update to latest analog-gmp version (#1) --- .github/workflows/test.yml | 9 +++++- examples/simple/Counter.sol | 4 +-- examples/simple/Counter.t.sol | 58 +++++++++++++++++++++++++++++------ lib/contracts | 2 +- 4 files changed, 60 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9282e82..fc95861 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,13 @@ name: test -on: workflow_dispatch +on: + push: + branches: + - master + - main + - staging + - release-v* + pull_request: env: FOUNDRY_PROFILE: ci diff --git a/examples/simple/Counter.sol b/examples/simple/Counter.sol index 42454f5..5f64d6a 100644 --- a/examples/simple/Counter.sol +++ b/examples/simple/Counter.sol @@ -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; diff --git a/examples/simple/Counter.t.sol b/examples/simple/Counter.t.sol index 8b5bab7..f6484c5 100644 --- a/examples/simple/Counter.t.sol +++ b/examples/simple/Counter.t.sol @@ -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); } diff --git a/lib/contracts b/lib/contracts index 70b5aea..f61efc8 160000 --- a/lib/contracts +++ b/lib/contracts @@ -1 +1 @@ -Subproject commit 70b5aea794eda798299b86da3aef7090a3200e36 +Subproject commit f61efc855faed4de87b39bab442bdc69644ed5bb