Skip to content

Commit 10b14a5

Browse files
fix(mcms): select public rpc for fork tests
1 parent 1b9e949 commit 10b14a5

3 files changed

Lines changed: 62 additions & 2 deletions

File tree

.changeset/fine-cups-battle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"chainlink-deployments-framework": patch
3+
---
4+
5+
fix(mcms): select public rpc for fork tests

engine/cld/legacy/cli/mcmsv2/mcms_v2.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"math/big"
1010
"os"
11+
"regexp"
1112
"slices"
1213
"strings"
1314
"time"
@@ -620,8 +621,10 @@ func buildExecuteForkCommand(lggr logger.Logger, domain cldf_domain.Domain, prop
620621
return fmt.Errorf("error creating config: %w", err)
621622
}
622623

623-
// get the chain URL, chain ID and MCM contract address
624-
url := cfg.forkedEnv.ChainConfigs[cfg.chainSelector].HTTPRPCs[0].External
624+
url, err := selectPublicRPC(cfg.forkedEnv, cfg.chainSelector)
625+
if err != nil {
626+
return fmt.Errorf("failed to select RPC for fork test: %w", err)
627+
}
625628
anvilClient := rpc.New(url, nil)
626629
chainID := cfg.forkedEnv.ChainConfigs[cfg.chainSelector].ChainID
627630
mcmsAddr := cfg.proposal.ChainMetadata[types.ChainSelector(cfg.chainSelector)].MCMAddress
@@ -1627,3 +1630,19 @@ func createRendererFromFormat(format string) (analyzer.Renderer, error) {
16271630
return nil, fmt.Errorf("unknown format '%s'", format)
16281631
}
16291632
}
1633+
1634+
func selectPublicRPC(env cldfenvironment.ForkedEnvironment, chainSelector uint64) (string, error) {
1635+
for _, rpc := range env.ChainConfigs[chainSelector].HTTPRPCs {
1636+
if !isPrivateRPC(rpc.External) {
1637+
return rpc.External, nil
1638+
}
1639+
}
1640+
1641+
return "", fmt.Errorf("no public RPCs found for chain %d", chainSelector)
1642+
}
1643+
1644+
var privateRpcRegexp = regexp.MustCompile(`^https?://(rpcs|gap\-.*\.(prod|stage))\.cldev\.sh/`)
1645+
1646+
func isPrivateRPC(url string) bool {
1647+
return privateRpcRegexp.MatchString(url)
1648+
}

engine/cld/legacy/cli/mcmsv2/mcms_v2_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,3 +524,39 @@ func Test_timelockExecuteOptions(t *testing.T) {
524524
})
525525
}
526526
}
527+
528+
func Test_isPrivateRPC(t *testing.T) {
529+
t.Parallel()
530+
tests := []struct {
531+
url string
532+
want bool
533+
}{
534+
{"http://rpcs.cldev.sh/", true},
535+
{"https://rpcs.cldev.sh/", true},
536+
{"https://rpcs.cldev.sh/anything", true},
537+
{"https://gap-rpcs.stage.cldev.sh/anything", true},
538+
{"https://gap-rpcs.prod.cldev.sh/anything", true},
539+
{"https://gap-other.prod.cldev.sh/anything", true},
540+
{"https://gap-other.stage.cldev.sh/anything", true},
541+
{"https://gap-other.stage.cldev.sh/anything", true},
542+
{"https://gap-grpc-job-distributor.public.main.prod.cldev.sh/", true},
543+
{"https://gap-ws-job-distributor.public.main.prod.cldev.sh/", true},
544+
{"https://gap-rpc-proxy.public.main.prod.cldev.sh/", true},
545+
{"https://gap-grpc-job-distributor.public.main.stage.cldev.sh/", true},
546+
{"https://gap-ws-job-distributor.public.main.stage.cldev.sh/", true},
547+
{"https://gap-grpc-chainlink-catalog.public.main.stage.cldev.sh/", true},
548+
{"", false},
549+
{"http://", false},
550+
{"https://", false},
551+
{"https://rpcs.cldev.sh", false},
552+
{"https://rpcs.prod.cldev.sh/anything", false},
553+
{"https://rpcs.stage.cldev.sh/anything", false},
554+
{"https://gap.stage.cldev.sh/anything", false},
555+
}
556+
for _, tt := range tests {
557+
t.Run(tt.url, func(t *testing.T) {
558+
t.Parallel()
559+
require.Equal(t, tt.want, isPrivateRPC(tt.url))
560+
})
561+
}
562+
}

0 commit comments

Comments
 (0)