@@ -51,7 +51,18 @@ async function main() {
5151 let dispatcherAddr ;
5252 let ucHandler ;
5353
54- if ( sanityCheck ) {
54+ // If the sanity check fails, we don't need to continue with the rest of the checks
55+ if ( ! sanityCheck ) {
56+ console . log ( `
57+ ⛔ Sanity check failed for network ${ networkName } ,
58+ check if the values provided in the .env file for the Universal Channel Mw and the dispatcher are correct.
59+ --------------------------------------------------
60+ 🔮 Expected Universal Channel Handler (in IBC contract): ${ ucHandlerAddr } ...
61+ 🗃️ Found Universal Channel Handler (in .env file): ${ envUcHandlerAddr } ...
62+ --------------------------------------------------
63+ ` ) ;
64+ return ;
65+ } else {
5566 try {
5667 ucHandler = await getUcHandler ( networkName ) ;
5768 dispatcherAddr = await ucHandler . dispatcher ( ) ;
@@ -64,53 +75,63 @@ async function main() {
6475 console . log ( `❌ Error getting dispatcher address from Universal Channel Mw or from config: ${ error } ` ) ;
6576 return ;
6677 }
67- } else {
78+ }
79+
80+ // If sanity check is false, log an error and return
81+ if ( ! sanityCheck ) {
6882 console . log ( `
6983⛔ Sanity check failed for network ${ networkName } ,
7084check if the values provided in the .env file for the Universal Channel Mw and the dispatcher are correct.
7185--------------------------------------------------
72- 🔮 Expected Universal Channel Handler (in IBC contract): ${ ucHandlerAddr } ...
73- 🗃️ Found Universal Channel Handler (in .env file): ${ envUcHandlerAddr } ...
86+ 🔮 Expected Dispatcher (in Universal Channel Handler contract): ${ dispatcherAddr } ...
87+ 🗃️ Found Dispatcher (in .env file): ${ envDispatcherAddr } ...
7488--------------------------------------------------
75- ` ) ;
89+ ` ) ;
7690 return ;
77- }
91+ } else {
92+ // If the sanity check passes, we can continue to check the channel ID stored in the Universal Channel Mw
93+ let counter = 0 ;
94+ let channelId , envChannelId ;
95+ let channelBytes ;
96+ let foundChannel = true ;
97+ // We don't know how many channels are connected to the Universal Channel Mw, so we loop until we get an error
98+ do {
99+ // Try to get the channel ID at the index
100+ try {
101+ channelBytes = await ucHandler . connectedChannels ( counter ) ;
102+ } catch ( error ) {
103+ // If we get an error, it means we reached the end of the list, do not return, just log the error and set foundChannel to false
104+ // console.log(`❌ No channel ID at index: ${counter}`);
105+ foundChannel = false ;
106+ }
107+ counter ++ ;
108+ } while ( foundChannel ) ;
78109
79- if ( sanityCheck ) {
80- const channelBytes = await ucHandler . connectedChannels ( 0 ) ;
81- const channelId = hre . ethers . decodeBytes32String ( channelBytes ) ;
82- const envChannelId = config [ 'sendUniversalPacket' ] [ networkName ] [ 'channelId' ] ;
110+ // channelBytes should be the last (populated) index in the connectedChannels array
111+ channelId = hre . ethers . decodeBytes32String ( channelBytes ) ;
112+ console . log ( `Channel ID in UCH contract: ${ channelId } ` ) ;
113+ envChannelId = config [ 'sendUniversalPacket' ] [ networkName ] [ 'channelId' ] ;
83114
84- if ( channelId !== envChannelId ) {
115+ // Compare the channel ID with the one in the .env file and log an error if they don't match
116+ // Run only after we've encountered an error fetching a channel ID at a new index
117+ if ( channelId === undefined && channelId !== envChannelId ) {
85118 sanityCheck = false ;
86119 console . log ( `
87120⛔ Sanity check failed for network ${ networkName } ,
88121check if the channel id value for the Universal channel in the config is correct.
89122--------------------------------------------------
90123🔮 Expected Channel ID (in Universal Channel Handler contract): ${ channelId } ...
91- 🗃️ Found Dispatcher (in .env file): ${ envChannelId } ...
124+ 🗃️ Found Channel ID (in config file): ${ envChannelId } ...
92125--------------------------------------------------
93- ` ) ;
126+ `) ;
94127 return ;
95128 }
96129 }
97130
98131 // 5. Print the result of the sanity check
99132 // If true, it means all values in the contracts check out with those in the .env file and we can continue with the script.
100- if ( sanityCheck ) {
101- console . log ( `✅ Sanity check passed for network ${ networkName } ` ) ;
102- } else {
103- console . log ( `
104- ⛔ Sanity check failed for network ${ networkName } ,
105- check if the values provided in the .env file for the Universal Channel Mw and the dispatcher are correct.
106- --------------------------------------------------
107- 🔮 Expected Dispatcher (in Universal Channel Handler contract): ${ dispatcherAddr } ...
108- 🗃️ Found Dispatcher (in .env file): ${ envDispatcherAddr } ...
109- --------------------------------------------------
110- ` ) ;
111- }
133+ console . log ( `✅ Sanity check passed for network ${ networkName } ` ) ;
112134}
113-
114135// We recommend this pattern to be able to use async/await everywhere
115136// and properly handle errors.
116137main ( ) . catch ( ( error ) => {
0 commit comments