generated from open-ibc/ibc-app-solidity-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_sanity-check-universal.js
90 lines (78 loc) · 3.95 KB
/
_sanity-check-universal.js
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
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// You can also run a script with `npx hardhat run <script>`. If you do that, Hardhat
// will compile your contracts, add the Hardhat Runtime Environment's members to the
// global scope, and execute the script.
const hre = require("hardhat");
const path = require('path');
const configRelativePath = process.env.CONFIG_PATH || 'config.json';
const configPath = path.join(__dirname, '..' , configRelativePath);
const { areAddressesEqual } = require('./_helpers.js');
const { getIbcApp, getUcHandler } = require("./_vibc-helpers.js");
async function main() {
const config = require(configPath);
const accounts = await hre.ethers.getSigners();
const networkName = hre.network.name;
// Get the Universal Channel Mw from your IBC enabled contract and comare it with the values in the .env file
// 1. Get the contract type from the config and get the contract
const ibcApp = await getIbcApp(networkName, true);
// 2. Query your app for the Universal Channel Mw address stored
const ucHandlerAddr = await ibcApp.mw();
// 3. Compare with the value expected in the .env config file
let sanityCheck = false;
let envUcHandlerAddr;
if (networkName === "optimism") {
envUcHandlerAddr = config.proofsEnabled === true ? process.env.OP_UC_MW : process.env.OP_UC_MW_SIM;
sanityCheck = areAddressesEqual(ucHandlerAddr, envUcHandlerAddr);
} else if (networkName === "base") {
envUcHandlerAddr = config.proofsEnabled === true ? process.env.BASE_UC_MW : process.env.BASE_UC_MW_SIM;
sanityCheck = areAddressesEqual(ucHandlerAddr, envUcHandlerAddr);
}
// 4. If true, we continue to check the dispatcher stored in the Universal Channel Mw
let envDispatcherAddr;
let dispatcherAddr;
if (sanityCheck) {
const ucHandler = await getUcHandler(networkName);
dispatcherAddr = await ucHandler.dispatcher();
if (networkName === "optimism") {
envDispatcherAddr = config.proofsEnabled === true ? process.env.OP_DISPATCHER : process.env.OP_DISPATCHER_SIM;
sanityCheck = areAddressesEqual(dispatcherAddr, envDispatcherAddr);
} else if (networkName === "base") {
envDispatcherAddr = config.proofsEnabled === true ? process.env.BASE_DISPATCHER : process.env.BASE_DISPATCHER_SIM;
sanityCheck = areAddressesEqual(dispatcherAddr, envDispatcherAddr);
} else {
sanityCheck = false;
}
} else {
console.log(`
⛔ Sanity check failed for network ${networkName},
check if the values provided in the .env file for the Universal Channel Mw and the dispatcher are correct.
--------------------------------------------------
🔮 Expected Universal Channel Handler (in IBC contract): ${ucHandlerAddr}...
🗃️ Found Universal Channel Handler (in .env file): ${envUcHandlerAddr}...
--------------------------------------------------
`);
return;
}
// 5. Print the result of the sanity check
// If true, it means all values in the contracts check out with those in the .env file and we can continue with the script.
if (sanityCheck) {
console.log(`✅ Sanity check passed for network ${networkName}`);
} else {
console.log(`
⛔ Sanity check failed for network ${networkName},
check if the values provided in the .env file for the Universal Channel Mw and the dispatcher are correct.
--------------------------------------------------
🔮 Expected Dispatcher (in Universal Channel Handler contract): ${dispatcherAddr}...
🗃️ Found Dispatcher (in .env file): ${envDispatcherAddr}...
--------------------------------------------------
`);
}
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});