Skip to content

Commit 1302167

Browse files
committed
fix: check of evm chain being available
1 parent 379c824 commit 1302167

1 file changed

Lines changed: 36 additions & 13 deletions

File tree

experimental/proposalutils/testhelpers/test_helpers.go

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -157,20 +157,26 @@ func ExecuteMCMSProposalV2(t *testing.T, env cldf.Environment, proposal *mcmslib
157157
}
158158

159159
if family == chainsel.FamilyEVM {
160-
chain := env.BlockChains.EVMChains()[uint64(chainSelector)]
160+
evmChain, ok := env.BlockChains.EVMChains()[uint64(chainSelector)]
161+
if !ok {
162+
return fmt.Errorf("[ExecuteMCMSProposalV2] EVM chain not found for selector %d", chainSelector)
163+
}
161164
evmTransaction, ok := root.RawData.(*gethtypes.Transaction)
162165
if !ok {
163166
return fmt.Errorf("[ExecuteMCMSProposalV2] unexpected RawData type %T", root.RawData)
164167
}
165168
t.Logf("[ExecuteMCMSProposalV2] SetRoot EVM tx hash: %s", evmTransaction.Hash().String())
166-
if _, err = chain.Confirm(evmTransaction); err != nil {
169+
if _, err = evmChain.Confirm(evmTransaction); err != nil {
167170
return fmt.Errorf("[ExecuteMCMSProposalV2] Confirm failed: %w", err)
168171
}
169172
}
170173
if family == chainsel.FamilyAptos {
171-
chain := env.BlockChains.AptosChains()[uint64(chainSelector)]
174+
aptosChain, ok := env.BlockChains.AptosChains()[uint64(chainSelector)]
175+
if !ok {
176+
return fmt.Errorf("[ExecuteMCMSProposalV2] Aptos chain not found for selector %d", chainSelector)
177+
}
172178
t.Logf("[ExecuteMCMSProposalV2] SetRoot Aptos tx hash: %s", root.Hash)
173-
if err = chain.Confirm(root.Hash); err != nil {
179+
if err = aptosChain.Confirm(root.Hash); err != nil {
174180
return fmt.Errorf("[ExecuteMCMSProposalV2] Confirm failed: %w", err)
175181
}
176182
}
@@ -189,20 +195,26 @@ func ExecuteMCMSProposalV2(t *testing.T, env cldf.Environment, proposal *mcmslib
189195
}
190196

191197
if family == chainsel.FamilyEVM {
192-
chain := env.BlockChains.EVMChains()[uint64(op.ChainSelector)]
198+
evmChain, ok := env.BlockChains.EVMChains()[uint64(op.ChainSelector)]
199+
if !ok {
200+
return fmt.Errorf("[ExecuteMCMSProposalV2] EVM chain not found for selector %d", op.ChainSelector)
201+
}
193202
evmTransaction, ok := result.RawData.(*gethtypes.Transaction)
194203
if !ok {
195204
return fmt.Errorf("[ExecuteMCMSProposalV2] unexpected RawData type %T", result.RawData)
196205
}
197206
t.Logf("[ExecuteMCMSProposalV2] Operation %d EVM tx hash: %s", i, evmTransaction.Hash().String())
198-
if _, err = chain.Confirm(evmTransaction); err != nil {
207+
if _, err = evmChain.Confirm(evmTransaction); err != nil {
199208
return fmt.Errorf("[ExecuteMCMSProposalV2] Confirm failed: %w", err)
200209
}
201210
}
202211
if family == chainsel.FamilyAptos {
203-
chain := env.BlockChains.AptosChains()[uint64(op.ChainSelector)]
212+
aptosChain, ok := env.BlockChains.AptosChains()[uint64(op.ChainSelector)]
213+
if !ok {
214+
return fmt.Errorf("[ExecuteMCMSProposalV2] Aptos chain not found for selector %d", op.ChainSelector)
215+
}
204216
t.Logf("[ExecuteMCMSProposalV2] Operation %d Aptos tx hash: %s", i, result.Hash)
205-
if err = chain.Confirm(result.Hash); err != nil {
217+
if err = aptosChain.Confirm(result.Hash); err != nil {
206218
return fmt.Errorf("[ExecuteMCMSProposalV2] Confirm failed: %w", err)
207219
}
208220
}
@@ -267,18 +279,24 @@ func ExecuteMCMSTimelockProposalV2(t *testing.T, env cldf.Environment, timelockP
267279
t.Logf("[ExecuteMCMSTimelockProposalV2] Executed timelock operation index=%d on chain %d (tx %v)", i, uint64(op.ChainSelector), tx.Hash)
268280

269281
if family == chainsel.FamilyEVM {
270-
chain := env.BlockChains.EVMChains()[uint64(op.ChainSelector)]
282+
evmChain, ok := env.BlockChains.EVMChains()[uint64(op.ChainSelector)]
283+
if !ok {
284+
return fmt.Errorf("[ExecuteMCMSTimelockProposalV2] EVM chain not found for selector %d", op.ChainSelector)
285+
}
271286
evmTransaction, ok := tx.RawData.(*gethtypes.Transaction)
272287
if !ok {
273288
return fmt.Errorf("[ExecuteMCMSTimelockProposalV2] unexpected RawData type %T", tx.RawData)
274289
}
275-
if _, err = chain.Confirm(evmTransaction); err != nil {
290+
if _, err = evmChain.Confirm(evmTransaction); err != nil {
276291
return fmt.Errorf("[ExecuteMCMSTimelockProposalV2] Confirm on EVM failed: %w", err)
277292
}
278293
}
279294
if family == chainsel.FamilyAptos {
280-
chain := env.BlockChains.AptosChains()[uint64(op.ChainSelector)]
281-
if err = chain.Confirm(tx.Hash); err != nil {
295+
aptosChain, ok := env.BlockChains.AptosChains()[uint64(op.ChainSelector)]
296+
if !ok {
297+
return fmt.Errorf("[ExecuteMCMSTimelockProposalV2] Aptos chain not found for selector %d", op.ChainSelector)
298+
}
299+
if err = aptosChain.Confirm(tx.Hash); err != nil {
282300
return fmt.Errorf("[ExecuteMCMSTimelockProposalV2] Confirm on Aptos failed: %w", err)
283301
}
284302
}
@@ -310,7 +328,12 @@ func SingleGroupTimelockConfigV2(t *testing.T) proposalutils.MCMSWithTimelockCon
310328
}
311329

312330
func findCallProxyAddress(env cldf.Environment, chainSelector uint64, timelockAddr string) (string, error) {
313-
timelock, err := bindings.NewRBACTimelock(common.HexToAddress(timelockAddr), env.BlockChains.EVMChains()[chainSelector].Client)
331+
evmChain, ok := env.BlockChains.EVMChains()[chainSelector]
332+
if !ok {
333+
return "", fmt.Errorf("EVM chain not found for selector %d", chainSelector)
334+
}
335+
336+
timelock, err := bindings.NewRBACTimelock(common.HexToAddress(timelockAddr), evmChain.Client)
314337
if err != nil {
315338
return "", fmt.Errorf("failed to create timelock binding: %w", err)
316339
}

0 commit comments

Comments
 (0)