Skip to content

Commit

Permalink
[ship-3979] remove ws validation (#1318)
Browse files Browse the repository at this point in the history
* Remove WS validation

* Add forcehttp option

* Updates Seth version to latest tag

* Adjust

* Remove unnecessary check

* Simplify

* Cleanup

* Adjust validation

* Adds changeset

* Add tests

* Fix linting issues
  • Loading branch information
davidcauchi authored Nov 13, 2024
1 parent 7987e78 commit ed6103e
Show file tree
Hide file tree
Showing 9 changed files with 563 additions and 31 deletions.
4 changes: 4 additions & 0 deletions lib/.changeset/v1.50.14.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- Update deps
- Allows Seth to run with only HTTP but defaults to WS when available
- Allows Network to initialize with only HTTP
- Adjust RPC url validation to accept only HTTP or WS + HTTP only.
15 changes: 10 additions & 5 deletions lib/config/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,18 @@ func (n *NetworkConfig) Validate() error {
continue
}
}
// if the network is not forked, we need to validate RPC endpoints and private keys
if _, ok := n.RpcHttpUrls[network]; !ok {
return fmt.Errorf("at least one HTTP RPC endpoint for %s network must be set", network)

// If the network is not forked, we need to validate RPC endpoints and private keys
_, httpOk := n.RpcHttpUrls[network]
_, wsOk := n.RpcWsUrls[network]
// WS can be present but only if HTTP is also available
if wsOk && !httpOk {
return fmt.Errorf("WS RPC endpoint for %s network is set without an HTTP endpoint; only HTTP or both HTTP and WS are allowed", network)
}

if _, ok := n.RpcWsUrls[network]; !ok {
return fmt.Errorf("at least one WS RPC endpoint for %s network must be set", network)
// Validate that there is at least one HTTP endpoint
if !httpOk {
return fmt.Errorf("at least one HTTP RPC endpoint for %s network must be set", network)
}

if _, ok := n.WalletKeys[network]; !ok {
Expand Down
106 changes: 106 additions & 0 deletions lib/config/testconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package config

import (
"errors"
"fmt"
"os"
"reflect"
"testing"

"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/ptr"
)

Expand Down Expand Up @@ -123,3 +126,106 @@ func TestReadConfigValuesFromEnvVars(t *testing.T) {
func newString(s string) *string {
return &s
}

func TestValidateNetworkConfig(t *testing.T) {
testCases := []struct {
name string
networkConfig NetworkConfig
expectedError error
}{
{
name: "Valid configuration with HTTP and WS URLs",
networkConfig: NetworkConfig{
SelectedNetworks: []string{"MAINNET"},
RpcHttpUrls: map[string][]string{
"MAINNET": {"http://localhost:8545"},
},
RpcWsUrls: map[string][]string{
"MAINNET": {"ws://localhost:8546"},
},
WalletKeys: map[string][]string{
"MAINNET": {"0xPrivateKey"},
},
},
expectedError: nil,
},
{
name: "Valid configuration with only HTTP URL",
networkConfig: NetworkConfig{
SelectedNetworks: []string{"MAINNET"},
RpcHttpUrls: map[string][]string{
"MAINNET": {"http://localhost:8545"},
},
WalletKeys: map[string][]string{
"MAINNET": {"0xPrivateKey"},
},
},
expectedError: nil,
},
{
name: "Invalid configuration with only WS URL",
networkConfig: NetworkConfig{
SelectedNetworks: []string{"MAINNET"},
RpcWsUrls: map[string][]string{
"MAINNET": {"ws://localhost:8546"},
},
WalletKeys: map[string][]string{
"MAINNET": {"0xPrivateKey"},
},
},
expectedError: fmt.Errorf("WS RPC endpoint for MAINNET network is set without an HTTP endpoint; only HTTP or both HTTP and WS are allowed"),
},
{
name: "Invalid configuration without HTTP or WS URLs",
networkConfig: NetworkConfig{
SelectedNetworks: []string{"MAINNET"},
WalletKeys: map[string][]string{
"MAINNET": {"0xPrivateKey"},
},
},
expectedError: fmt.Errorf("at least one HTTP RPC endpoint for MAINNET network must be set"),
},
{
name: "Valid simulated network without RPC URLs",
networkConfig: NetworkConfig{
SelectedNetworks: []string{"SIMULATED"},
},
expectedError: nil,
},
{
name: "Valid forked network (Anvil) without RPC URLs",
networkConfig: NetworkConfig{
SelectedNetworks: []string{"MAINNET"},
AnvilConfigs: map[string]*AnvilConfig{
"MAINNET": {URL: ptr.Ptr("http://forked-node-url")},
},
},
expectedError: nil,
},
{
name: "Missing private key",
networkConfig: NetworkConfig{
SelectedNetworks: []string{"MAINNET"},
RpcHttpUrls: map[string][]string{
"MAINNET": {"http://localhost:8545"},
},
RpcWsUrls: map[string][]string{
"MAINNET": {"ws://localhost:8546"},
},
},
expectedError: fmt.Errorf("at least one private key of funding wallet for MAINNET network must be set"),
},
}

for _, tc := range testCases {
tc := tc // capture range variable
t.Run(tc.name, func(t *testing.T) {
err := tc.networkConfig.Validate()
if tc.expectedError != nil {
require.EqualError(t, err, tc.expectedError.Error())
} else {
require.NoError(t, err)
}
})
}
}
6 changes: 3 additions & 3 deletions lib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
github.com/smartcontractkit/chainlink-testing-framework/wasp v1.50.1
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
23 changes: 12 additions & 11 deletions lib/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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 h1:yB1x5UXvpZNka+5h57yo1/GrKfXKCqMzChCISpldZx4=
github.com/smartcontractkit/chainlink-testing-framework/seth v1.50.9/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=
Expand Down Expand Up @@ -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=
Expand All @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
20 changes: 13 additions & 7 deletions lib/networks/known_networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -1101,17 +1101,23 @@ func SetNetworks(networkCfg config.NetworkConfig) ([]blockchain.EVMNetwork, erro
if networkCfg.AnvilConfigs != nil {
_, forked = networkCfg.AnvilConfigs[networkName]
}

// if network is not simulated or forked, use the rpc urls and wallet keys from config
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])
var ok, wsOk, httpOk bool
// Check for WS URLs
wsUrls, wsOk = networkCfg.RpcWsUrls[selectedNetworks[i]]
// Check for HTTP URLs
httpUrls, httpOk = networkCfg.RpcHttpUrls[selectedNetworks[i]]

// WS can be present but only if HTTP is also available, the CL node cannot function only on WS
if wsOk && !httpOk {
return nil, fmt.Errorf("WS RPC endpoint for %s network is set without an HTTP endpoint; only HTTP or both HTTP and WS are allowed", selectedNetworks[i])
}

httpUrls, ok = networkCfg.RpcHttpUrls[selectedNetworks[i]]
if !ok {
return nil, fmt.Errorf("no rpc http urls found in config for '%s' network", selectedNetworks[i])
// Validate that there is at least one HTTP endpoint
if !httpOk {
return nil, fmt.Errorf("at least one HTTP RPC endpoint for %s network must be set", selectedNetworks[i])
}

walletKeys, ok = networkCfg.WalletKeys[selectedNetworks[i]]
Expand Down
Loading

0 comments on commit ed6103e

Please sign in to comment.