@@ -543,6 +543,95 @@ func TestUpdateBidirectionalLanesChangesetWithV2FeeQuoter(t *testing.T) {
543543 }
544544}
545545
546+ func TestFilterOutExistingDestChainConfigs (t * testing.T ) {
547+ t .Parallel ()
548+
549+ deployedEnvironment , _ := testhelpers .NewMemoryEnvironment (t , func (testCfg * testhelpers.TestConfigs ) {
550+ testCfg .Chains = 2
551+ })
552+ e := deployedEnvironment .Env
553+
554+ state , err := stateview .LoadOnchainState (e )
555+ require .NoError (t , err , "must load onchain state" )
556+
557+ selectors := e .BlockChains .ListChainSelectors (cldf_chain .WithFamily (chain_selectors .FamilyEVM ))
558+ require .Len (t , selectors , 2 , "must have 2 chains" )
559+
560+ chainSel := selectors [0 ]
561+ otherChainSel := selectors [1 ]
562+ evmChain := e .BlockChains .EVMChains ()[chainSel ]
563+
564+ parsedABI , err := abi .JSON (strings .NewReader (fqv2ops .FeeQuoterABI ))
565+ require .NoError (t , err , "must parse v2 FeeQuoter ABI" )
566+
567+ // Deploy a v2 FeeQuoter with one destination already configured (otherChainSel)
568+ preConfiguredDest := fqv2ops.DestChainConfigArgs {
569+ DestChainSelector : otherChainSel ,
570+ DestChainConfig : fqv2ops.DestChainConfig {
571+ IsEnabled : true ,
572+ MaxDataBytes : 30_000 ,
573+ },
574+ }
575+ fqV2Addr , tx , _ , err := bind .DeployContract (
576+ evmChain .DeployerKey ,
577+ parsedABI ,
578+ common .FromHex (fqv2ops .FeeQuoterBin ),
579+ evmChain .Client ,
580+ fqv2ops.StaticConfig {
581+ MaxFeeJuelsPerMsg : big .NewInt (1e18 ),
582+ LinkToken : state .Chains [chainSel ].LinkToken .Address (),
583+ },
584+ []common.Address {evmChain .DeployerKey .From },
585+ []fqv2ops.TokenTransferFeeConfigArgs {},
586+ []fqv2ops.DestChainConfigArgs {preConfiguredDest },
587+ )
588+ require .NoError (t , err , "must deploy v2 FeeQuoter" )
589+
590+ _ , err = evmChain .Confirm (tx )
591+ require .NoError (t , err , "must confirm v2 FeeQuoter deployment" )
592+
593+ // Verify the pre-configured dest is enabled on-chain
594+ fqV2 , err := fqv2ops .NewFeeQuoterContract (fqV2Addr , evmChain .Client )
595+ require .NoError (t , err , "must bind v2 FeeQuoter" )
596+
597+ existingCfg , err := fqV2 .GetDestChainConfig (nil , otherChainSel )
598+ require .NoError (t , err , "must get pre-configured dest config" )
599+ require .True (t , existingCfg .IsEnabled , "pre-configured dest must be enabled" )
600+
601+ unconfiguredChainSel := uint64 (999 )
602+ unconfiguredCfg , err := fqV2 .GetDestChainConfig (nil , unconfiguredChainSel )
603+ require .NoError (t , err , "must get unconfigured dest config" )
604+ require .False (t , unconfiguredCfg .IsEnabled , "unconfigured dest must not be enabled" )
605+
606+ // Call FilterOutExistingDestChainConfigs with both destinations
607+ input := []fqv2ops.DestChainConfigArgs {
608+ {
609+ DestChainSelector : otherChainSel ,
610+ DestChainConfig : fqv2ops.DestChainConfig {IsEnabled : true , MaxDataBytes : 50_000 },
611+ },
612+ {
613+ DestChainSelector : unconfiguredChainSel ,
614+ DestChainConfig : fqv2ops.DestChainConfig {IsEnabled : true , MaxDataBytes : 60_000 },
615+ },
616+ }
617+
618+ filtered , err := v1_6 .FilterOutExistingDestChainConfigs (e , fqV2Addr , chainSel , input )
619+ require .NoError (t , err , "FilterOutExistingDestChainConfigs must not error" )
620+
621+ // Only the unconfigured chain should remain
622+ require .Len (t , filtered , 1 , "must filter out the already-enabled destination" )
623+ assert .Equal (t , unconfiguredChainSel , filtered [0 ].DestChainSelector ,
624+ "remaining entry must be the unconfigured chain" )
625+ assert .Equal (t , uint32 (60_000 ), filtered [0 ].DestChainConfig .MaxDataBytes ,
626+ "remaining entry must preserve original config" )
627+
628+ // Verify the pre-existing config was NOT overwritten
629+ unchangedCfg , err := fqV2 .GetDestChainConfig (nil , otherChainSel )
630+ require .NoError (t , err , "must re-read pre-configured dest config" )
631+ assert .Equal (t , uint32 (30_000 ), unchangedCfg .MaxDataBytes ,
632+ "pre-existing config must remain unchanged" )
633+ }
634+
546635func TestUpdateBidirectionalLanesChangesetWithV2FeeQuoterWithMCMS (t * testing.T ) {
547636 t .Parallel ()
548637
0 commit comments