Skip to content

Commit

Permalink
Update test docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Lohann committed Apr 18, 2024
1 parent f851917 commit 9c10360
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 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
45 changes: 31 additions & 14 deletions examples/simple/Counter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,64 @@ 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 {
////////////////////////////////////
// Step 1: Setup test environment //
////////////////////////////////////
// Setup test environment, deploy gateways and create forks
GmpTestTools.setup();

////////////////////////////////////////
// Step 2: Deploy contract on Sepolia //
////////////////////////////////////////
// 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 {
// Fund the msg.sender
GmpTestTools.deal(msg.sender, 100 ether);
vm.startPrank(msg.sender, msg.sender);
// 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
// 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(msg.sender)));
bytes32 source = bytes32(uint256(uint160(alice)));
sepoliaGateway.deposit{value: 1 ether}(source, shibuyaId);
assertEq(counter.number(), 0);

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

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

// Check the counter in sepolia before relaying the messages
// Relay all pending GMP messages and check the counter again
GmpTestTools.relayMessages();
assertEq(counter.number(), 1);
}
Expand Down

0 comments on commit 9c10360

Please sign in to comment.