-
Notifications
You must be signed in to change notification settings - Fork 32
/
DeployClients003.s.sol
99 lines (84 loc) · 4.42 KB
/
DeployClients003.s.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
// ═════════════════════════════ CONTRACT IMPORTS ══════════════════════════════
import {PingPongClient} from "../contracts/client/PingPongClient.sol";
import {TestClient} from "../contracts/client/TestClient.sol";
import {IStateHub} from "../contracts/interfaces/IStateHub.sol";
// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════
import {DeployerUtils} from "./utils/DeployerUtils.sol";
// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════
import {console, stdJson} from "forge-std/Script.sol";
// solhint-disable no-console
// solhint-disable ordering
contract DeployClients003Script is DeployerUtils {
using stdJson for string;
string public constant PING_PONG_CLIENT_NAME = "PingPongClient";
string public constant TEST_CLIENT_NAME = "TestClient";
address internal origin;
address internal destination;
address public pingPongClient;
address public testClient;
constructor() {
setupPK("MESSAGING_DEPLOYER_PRIVATE_KEY");
setupDevnetIfEnabled();
}
/// @dev Function to exclude script from coverage report
function testScript() external {}
/// @notice Main function with the deploy logic.
function run() external {
_deploy(true);
}
/// @notice Function to simulate the deployment procedure.
function runDry() external {
_deploy(false);
}
/// @dev Deploys PingPongClient and TestClient
function _deploy(bool _isBroadcasted) internal {
startBroadcast(_isBroadcasted);
// Load Origin/Destination deployments
origin = loadDeployment("Origin");
destination = loadDeployment("Destination");
// Predict deployments
pingPongClient = predictFactoryDeployment(PING_PONG_CLIENT_NAME);
testClient = predictFactoryDeployment(TEST_CLIENT_NAME);
// Deploy clients
_deployAndCheckAddress(PING_PONG_CLIENT_NAME, _deployPingPongClient, _initNoop, pingPongClient);
_deployAndCheckAddress(TEST_CLIENT_NAME, _deployTestClient, _initNoop, testClient);
stopBroadcast();
// Check clients without broadcasting
_checkClients();
}
function _deployAndCheckAddress(
string memory contractName,
function() internal returns (address, bytes memory) deployFunc,
function(address) internal initFunc,
address predictedDeployment
) internal {
(address deployment,) = deployContract(contractName, deployFunc, initFunc);
require(deployment == predictedDeployment, string.concat(contractName, ": wrong address"));
}
function _deployPingPongClient() internal returns (address deployment, bytes memory constructorArgs) {
// new PingPongClient(origin, destination)
constructorArgs = abi.encode(origin, destination);
deployment = factoryDeploy(PING_PONG_CLIENT_NAME, type(PingPongClient).creationCode, constructorArgs);
}
function _deployTestClient() internal returns (address deployment, bytes memory constructorArgs) {
// new TestClient(origin, destination)
constructorArgs = abi.encode(origin, destination);
deployment = factoryDeploy(TEST_CLIENT_NAME, type(TestClient).creationCode, constructorArgs);
}
function _initNoop(address _deployment) internal {}
function _checkClients() internal {
console.log("Checking Clients");
uint256 initialStates = IStateHub(origin).statesAmount();
uint32 remoteDomain = block.chainid == 10 ? 137 : 10;
// Check Test Client
TestClient(testClient).sendMessage(remoteDomain, address(testClient), 0, 100_000, 0, "test message");
require(IStateHub(origin).statesAmount() == initialStates + 1, "TestClient didn't send");
console.log(unicode" TestClient: ✅");
// Check Ping Pong Client
PingPongClient(pingPongClient).doPing(remoteDomain, address(pingPongClient), 0);
require(IStateHub(origin).statesAmount() == initialStates + 2, "PingPongClient didn't send");
console.log(unicode" PingPongClient: ✅");
}
}