From 39d19ec6b6e09b9a7f14f1aafc09411ee405965d Mon Sep 17 00:00:00 2001 From: davidcauchi Date: Sun, 10 Nov 2024 21:46:51 +0100 Subject: [PATCH] Add forcehttp option --- lib/config/network.go | 11 ++++++++--- lib/config/testconfig.go | 18 ++++++++++-------- lib/go.mod | 6 +++--- lib/go.sum | 23 ++++++++++++----------- lib/networks/known_networks.go | 22 +++++++++++++--------- lib/networks/known_networks_test.go | 6 ++++-- lib/utils/seth/seth.go | 5 ++++- 7 files changed, 54 insertions(+), 37 deletions(-) diff --git a/lib/config/network.go b/lib/config/network.go index 0b0878844..ee21e2014 100644 --- a/lib/config/network.go +++ b/lib/config/network.go @@ -44,6 +44,8 @@ type NetworkConfig struct { // RpcWsUrls is the RPC WS endpoints for each network, // key is the network name as declared in selected_networks slice RpcWsUrls map[string][]string `toml:"RpcWsUrls,omitempty"` + // ForceHttp, if true, skips validation of WS endpoints, requiring only HTTP endpoints + ForceHttp bool `toml:"force_http,omitempty"` // WalletKeys is the private keys for the funding wallets for each network, // key is the network name as declared in selected_networks slice WalletKeys map[string][]string `toml:"WalletKeys,omitempty"` @@ -146,9 +148,12 @@ func (n *NetworkConfig) Validate() error { return fmt.Errorf("at least one HTTP RPC endpoint for %s network must be set", network) } - // if _, ok := n.RpcWsUrls[network]; !ok { - // return fmt.Errorf("at least one WS RPC endpoint for %s network must be set", network) - // } + // Conditionally skip the WebSocket URL check if forceHttp is set to true + if !n.ForceHttp { + if _, ok := n.RpcWsUrls[network]; !ok { + return fmt.Errorf("at least one WS RPC endpoint for %s network must be set", network) + } + } if _, ok := n.WalletKeys[network]; !ok { return fmt.Errorf("at least one private key of funding wallet for %s network must be set", network) diff --git a/lib/config/testconfig.go b/lib/config/testconfig.go index 567764d88..7575e310d 100644 --- a/lib/config/testconfig.go +++ b/lib/config/testconfig.go @@ -231,14 +231,16 @@ func (c *TestConfig) ReadFromEnvVar() error { c.Network.RpcHttpUrls = rpcHttpUrls } - // rpcWsUrls := ReadEnvVarGroupedMap(E2E_TEST_RPC_WS_URL_ENV, E2E_TEST_RPC_WS_URLS_ENV) - // if len(rpcWsUrls) > 0 { - // if c.Network == nil { - // c.Network = &NetworkConfig{} - // } - // logger.Info().Msgf("Using %s and/or %s env vars to override Network.RpcWsUrls", E2E_TEST_RPC_WS_URL_ENV, E2E_TEST_RPC_WS_URLS_ENV) - // c.Network.RpcWsUrls = rpcWsUrls - // } + if !c.Network.ForceHttp { + rpcWsUrls := ReadEnvVarGroupedMap(E2E_TEST_RPC_WS_URL_ENV, E2E_TEST_RPC_WS_URLS_ENV) + if len(rpcWsUrls) > 0 { + if c.Network == nil { + c.Network = &NetworkConfig{} + } + logger.Info().Msgf("Using %s and/or %s env vars to override Network.RpcWsUrls", E2E_TEST_RPC_WS_URL_ENV, E2E_TEST_RPC_WS_URLS_ENV) + c.Network.RpcWsUrls = rpcWsUrls + } + } chainlinkImage := MustReadEnvVar_String(E2E_TEST_CHAINLINK_IMAGE_ENV) if chainlinkImage != "" { diff --git a/lib/go.mod b/lib/go.mod index 56bc9196f..97679d417 100644 --- a/lib/go.mod +++ b/lib/go.mod @@ -32,7 +32,7 @@ require ( github.com/prometheus/common v0.60.0 github.com/rs/zerolog v1.33.0 github.com/slack-go/slack v0.15.0 - github.com/smartcontractkit/chainlink-testing-framework/seth v1.50.4 + github.com/smartcontractkit/chainlink-testing-framework/seth v1.50.9-0.20241110203450-1ec78c4ad500 github.com/smartcontractkit/chainlink-testing-framework/wasp v1.50.1 github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 @@ -191,7 +191,7 @@ require ( github.com/hashicorp/memberlist v0.5.0 // indirect github.com/hashicorp/serf v0.10.1 // indirect github.com/holiman/bloomfilter/v2 v2.0.3 // indirect - github.com/holiman/uint256 v1.2.4 // indirect + github.com/holiman/uint256 v1.3.1 // indirect github.com/huandu/xstrings v1.3.3 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect @@ -292,7 +292,7 @@ require ( go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect go.uber.org/goleak v1.3.0 // indirect go.uber.org/multierr v1.11.0 // indirect - go.uber.org/ratelimit v0.3.0 // indirect + go.uber.org/ratelimit v0.3.1 // indirect go4.org/netipx v0.0.0-20230125063823-8449b0a6169f // indirect golang.org/x/arch v0.4.0 // indirect golang.org/x/crypto v0.28.0 // indirect diff --git a/lib/go.sum b/lib/go.sum index d8d336487..85c984392 100644 --- a/lib/go.sum +++ b/lib/go.sum @@ -256,8 +256,9 @@ github.com/cpuguy83/dockercfg v0.3.2 h1:DlJTyZGBDlXqUZ2Dk2Q3xHs/FtnooJJVaad2S9GK github.com/cpuguy83/dockercfg v0.3.2/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc= github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= -github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc= +github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 h1:d28BXYi+wUpz1KBmiF9bWrjEMacUEREV6MBi2ODnrfQ= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= github.com/crate-crypto/go-kzg-4844 v0.7.0 h1:C0vgZRk4q4EZ/JgPfzuSoxdCq3C3mOZMBShovmncxvA= @@ -678,8 +679,8 @@ github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7 h1:3JQNjnMRil1yD0IfZ github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7/go.mod h1:5GuXa7vkL8u9FkFuWdVvfR5ix8hRB7DbOAaYULamFpc= github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= -github.com/holiman/uint256 v1.2.4 h1:jUc4Nk8fm9jZabQuqr2JzednajVmBpC+oiTiXZJEApU= -github.com/holiman/uint256 v1.2.4/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= +github.com/holiman/uint256 v1.3.1 h1:JfTzmih28bittyHM8z360dCjIA9dbPIBlcTI6lmctQs= +github.com/holiman/uint256 v1.3.1/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4= github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= @@ -1051,8 +1052,8 @@ github.com/slack-go/slack v0.15.0 h1:LE2lj2y9vqqiOf+qIIy0GvEoxgF1N5yLGZffmEZykt0 github.com/slack-go/slack v0.15.0/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw= github.com/smartcontractkit/chainlink-testing-framework/lib/grafana v1.50.0 h1:VIxK8u0Jd0Q/VuhmsNm6Bls6Tb31H/sA3A/rbc5hnhg= github.com/smartcontractkit/chainlink-testing-framework/lib/grafana v1.50.0/go.mod h1:lyAu+oMXdNUzEDScj2DXB2IueY+SDXPPfyl/kb63tMM= -github.com/smartcontractkit/chainlink-testing-framework/seth v1.50.4 h1:hPI9GhHE1RmIG1oyPeFjED0AhWnNb9JzD74Oq2bO+IQ= -github.com/smartcontractkit/chainlink-testing-framework/seth v1.50.4/go.mod h1:afY3QmNgeR/VI1pRbGH8g3YXGy7C2RrFOwUzEFvL3L8= +github.com/smartcontractkit/chainlink-testing-framework/seth v1.50.9-0.20241110203450-1ec78c4ad500 h1:tkQ4IE1gPiI/OSbR46mRZpzcKcYiU9DyK4R0hnX7G14= +github.com/smartcontractkit/chainlink-testing-framework/seth v1.50.9-0.20241110203450-1ec78c4ad500/go.mod h1:lJk0atEJ5Zyo3Tqrmf1Pl9jUEe79EgDb9bD3K5OTUBI= github.com/smartcontractkit/chainlink-testing-framework/wasp v1.50.1 h1:hbapxD2wjGJNkP9Re2LqzPDbejzRP25Yk5vKfuaHs6U= github.com/smartcontractkit/chainlink-testing-framework/wasp v1.50.1/go.mod h1:tMdjHVfgp1QBLfVieSTGNR0kem8cOnH2bOXXXiaTwZ0= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= @@ -1125,8 +1126,8 @@ github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljT github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= -github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= -github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= +github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w= +github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ= github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.6.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w= @@ -1150,8 +1151,8 @@ github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQ github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ= github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4= +github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM= github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmvncFJFHJ7Gvn9wZArjbV5/FppcK2fKk/tI= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= @@ -1211,8 +1212,8 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/ratelimit v0.3.0 h1:IdZd9wqvFXnvLvSEBo0KPcGfkoBGNkpTHlrE3Rcjkjw= -go.uber.org/ratelimit v0.3.0/go.mod h1:So5LG7CV1zWpY1sHe+DXTJqQvOx+FFPFaAs2SnoyBaI= +go.uber.org/ratelimit v0.3.1 h1:K4qVE+byfv/B3tC+4nYWP7v/6SimcO7HzHekoMNBma0= +go.uber.org/ratelimit v0.3.1/go.mod h1:6euWsTB6U/Nb3X++xEUXA8ciPJvr19Q/0h1+oDcJhRk= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= go4.org/netipx v0.0.0-20230125063823-8449b0a6169f h1:ketMxHg+vWm3yccyYiq+uK8D3fRmna2Fcj+awpQp84s= diff --git a/lib/networks/known_networks.go b/lib/networks/known_networks.go index 27d36e0e1..558c67488 100644 --- a/lib/networks/known_networks.go +++ b/lib/networks/known_networks.go @@ -1105,10 +1105,12 @@ func SetNetworks(networkCfg config.NetworkConfig) ([]blockchain.EVMNetwork, erro if !strings.Contains(networkName, "SIMULATED") && !forked { var ok bool - // wsUrls, ok = networkCfg.RpcWsUrls[selectedNetworks[i]] - // if !ok { - // return nil, fmt.Errorf("no rpc ws urls found in config for '%s' network", selectedNetworks[i]) - // } + if !networkCfg.ForceHttp { + wsUrls, ok = networkCfg.RpcWsUrls[selectedNetworks[i]] + if !ok { + return nil, fmt.Errorf("no rpc ws urls found in config for '%s' network", selectedNetworks[i]) + } + } httpUrls, ok = networkCfg.RpcHttpUrls[selectedNetworks[i]] if !ok { @@ -1123,7 +1125,7 @@ func SetNetworks(networkCfg config.NetworkConfig) ([]blockchain.EVMNetwork, erro // if evm_network config is found, use it if networkCfg.EVMNetworks != nil { if network, ok := networkCfg.EVMNetworks[networkName]; ok && network != nil { - if err := NewEVMNetwork(network, walletKeys, httpUrls, wsUrls); err != nil { + if err := NewEVMNetwork(network, walletKeys, httpUrls, wsUrls, networkCfg.ForceHttp); err != nil { return nil, err } networks = append(networks, *network) @@ -1132,7 +1134,7 @@ func SetNetworks(networkCfg config.NetworkConfig) ([]blockchain.EVMNetwork, erro } // if there is no evm_network config, use the known networks to find the network config from the map if knownNetwork, valid := MappedNetworks[networkName]; valid { - err := NewEVMNetwork(&knownNetwork, walletKeys, httpUrls, wsUrls) + err := NewEVMNetwork(&knownNetwork, walletKeys, httpUrls, wsUrls, networkCfg.ForceHttp) if err != nil { return nil, err } @@ -1150,12 +1152,14 @@ func SetNetworks(networkCfg config.NetworkConfig) ([]blockchain.EVMNetwork, erro } // NewEVMNetwork sets the network's private key(s) and rpc urls -func NewEVMNetwork(network *blockchain.EVMNetwork, walletKeys, httpUrls, wsUrls []string) error { +func NewEVMNetwork(network *blockchain.EVMNetwork, walletKeys, httpUrls, wsUrls []string, forceHttp bool) error { if len(httpUrls) > 0 { network.HTTPURLs = httpUrls } - if len(wsUrls) > 0 { - network.URLs = wsUrls + if !forceHttp { + if len(wsUrls) > 0 { + network.URLs = wsUrls + } } if len(walletKeys) > 0 { if err := setKeys(network, walletKeys); err != nil { diff --git a/lib/networks/known_networks_test.go b/lib/networks/known_networks_test.go index b39fe4cf1..f87e5db82 100644 --- a/lib/networks/known_networks_test.go +++ b/lib/networks/known_networks_test.go @@ -39,7 +39,7 @@ func TestNewEVMNetwork(t *testing.T) { t.Run("valid networkKey", func(t *testing.T) { network := MappedNetworks["VALID_KEY"] - err := NewEVMNetwork(&network, nil, nil, nil) + err := NewEVMNetwork(&network, nil, nil, nil, false) require.NoError(t, err) require.Equal(t, MappedNetworks["VALID_KEY"].HTTPURLs, network.HTTPURLs) require.Equal(t, MappedNetworks["VALID_KEY"].URLs, network.URLs) @@ -50,11 +50,13 @@ func TestNewEVMNetwork(t *testing.T) { httpUrls := []string{"http://newurl.com"} wsUrls := []string{"ws://newwsurl.com"} network := MappedNetworks["VALID_KEY"] - err := NewEVMNetwork(&network, walletKeys, httpUrls, wsUrls) + forceHttp := true + err := NewEVMNetwork(&network, walletKeys, httpUrls, wsUrls, forceHttp) require.NoError(t, err) require.Equal(t, httpUrls, network.HTTPURLs) require.Equal(t, wsUrls, network.URLs) require.Equal(t, walletKeys, network.PrivateKeys) + require.Equal(t, walletKeys, network.PrivateKeys) }) } diff --git a/lib/utils/seth/seth.go b/lib/utils/seth/seth.go index 747f6c1f2..f8f88925d 100644 --- a/lib/utils/seth/seth.go +++ b/lib/utils/seth/seth.go @@ -174,7 +174,10 @@ func MergeSethAndEvmNetworkConfigs(evmNetwork blockchain.EVMNetwork, sethConfig break } else if isSameNetwork(conf, evmNetwork) { conf.PrivateKeys = evmNetwork.PrivateKeys - if len(conf.URLs) == 0 { + // forceHttp should override urlssecret + if sethConfig.ForceHTTP { + conf.URLs = evmNetwork.HTTPURLs + } else if len(conf.URLs) == 0 { conf.URLs = evmNetwork.URLs }