Skip to content

Commit

Permalink
Use common url
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanTinianov committed Jan 4, 2024
1 parent c0b6d02 commit c5d9272
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 86 deletions.
10 changes: 5 additions & 5 deletions core/cmd/evm_node_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
evmcfg "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/cmd"
"github.com/smartcontractkit/chainlink/v2/core/internal/cltest"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
)

func assertTableRenders(t *testing.T, r *cltest.RendererMock) {
Expand All @@ -31,15 +31,15 @@ func TestShell_IndexEVMNodes(t *testing.T) {
chainID := newRandChainID()
node1 := evmcfg.Node{
Name: ptr("Test node 1"),
WSURL: models.MustParseURL("ws://localhost:8546"),
HTTPURL: models.MustParseURL("http://localhost:8546"),
WSURL: commonconfig.MustParseURL("ws://localhost:8546"),
HTTPURL: commonconfig.MustParseURL("http://localhost:8546"),
SendOnly: ptr(false),
Order: ptr(int32(15)),
}
node2 := evmcfg.Node{
Name: ptr("Test node 2"),
WSURL: models.MustParseURL("ws://localhost:8547"),
HTTPURL: models.MustParseURL("http://localhost:8547"),
WSURL: commonconfig.MustParseURL("ws://localhost:8547"),
HTTPURL: commonconfig.MustParseURL("http://localhost:8547"),
SendOnly: ptr(false),
Order: ptr(int32(36)),
}
Expand Down
9 changes: 5 additions & 4 deletions core/cmd/shell_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"
"time"

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox"

"github.com/smartcontractkit/chainlink/v2/common/client"
Expand Down Expand Up @@ -74,8 +75,8 @@ func TestShell_RunNodeWithPasswords(t *testing.T) {
cfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
s.Password.Keystore = models.NewSecret("dummy")
c.EVM[0].Nodes[0].Name = ptr("fake")
c.EVM[0].Nodes[0].HTTPURL = models.MustParseURL("http://fake.com")
c.EVM[0].Nodes[0].WSURL = models.MustParseURL("WSS://fake.com/ws")
c.EVM[0].Nodes[0].HTTPURL = commonconfig.MustParseURL("http://fake.com")
c.EVM[0].Nodes[0].WSURL = commonconfig.MustParseURL("WSS://fake.com/ws")
// seems to be needed for config validate
c.Insecure.OCRDevelopmentMode = nil
})
Expand Down Expand Up @@ -168,8 +169,8 @@ func TestShell_RunNodeWithAPICredentialsFile(t *testing.T) {
cfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
s.Password.Keystore = models.NewSecret("16charlengthp4SsW0rD1!@#_")
c.EVM[0].Nodes[0].Name = ptr("fake")
c.EVM[0].Nodes[0].WSURL = models.MustParseURL("WSS://fake.com/ws")
c.EVM[0].Nodes[0].HTTPURL = models.MustParseURL("http://fake.com")
c.EVM[0].Nodes[0].WSURL = commonconfig.MustParseURL("WSS://fake.com/ws")
c.EVM[0].Nodes[0].HTTPURL = commonconfig.MustParseURL("http://fake.com")
// seems to be needed for config validate
c.Insecure.OCRDevelopmentMode = nil
})
Expand Down
3 changes: 2 additions & 1 deletion core/config/audit_logger_config.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package config

import (
commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
)

type AuditLogger interface {
Enabled() bool
ForwardToUrl() (models.URL, error)
ForwardToUrl() (commonconfig.URL, error)
Environment() string
JsonWrapperKey() string
Headers() (models.ServiceHeaders, error)
Expand Down
4 changes: 2 additions & 2 deletions core/config/docs/docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (
stkcfg "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/config"

"github.com/smartcontractkit/chainlink-common/pkg/config"
commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
evmcfg "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/config/docs"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink/cfgtest"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
)

func TestDoc(t *testing.T) {
Expand All @@ -42,7 +42,7 @@ func TestDoc(t *testing.T) {
// and its only use is to signal to NOPs that these fields are no longer allowed
emptyString := ""
c.TelemetryIngress.ServerPubKey = &emptyString
c.TelemetryIngress.URL = new(models.URL)
c.TelemetryIngress.URL = new(commonconfig.URL)

cfgtest.AssertFieldsNotNil(t, c)

Expand Down
10 changes: 5 additions & 5 deletions core/config/toml/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,14 +439,14 @@ type TelemetryIngress struct {
UseBatchSend *bool
Endpoints []TelemetryIngressEndpoint `toml:",omitempty"`

URL *models.URL `toml:",omitempty"` // Deprecated: Use TelemetryIngressEndpoint.URL instead, this field will be removed in future versions
ServerPubKey *string `toml:",omitempty"` // Deprecated: Use TelemetryIngressEndpoint.ServerPubKey instead, this field will be removed in future versions
URL *commonconfig.URL `toml:",omitempty"` // Deprecated: Use TelemetryIngressEndpoint.URL instead, this field will be removed in future versions
ServerPubKey *string `toml:",omitempty"` // Deprecated: Use TelemetryIngressEndpoint.ServerPubKey instead, this field will be removed in future versions
}

type TelemetryIngressEndpoint struct {
Network *string
ChainID *string
URL *models.URL
URL *commonconfig.URL
ServerPubKey *string
}

Expand Down Expand Up @@ -499,7 +499,7 @@ func (t *TelemetryIngress) ValidateConfig() (err error) {

type AuditLogger struct {
Enabled *bool
ForwardToUrl *models.URL
ForwardToUrl *commonconfig.URL
JsonWrapperKey *string
Headers *[]models.ServiceHeader
}
Expand Down Expand Up @@ -598,7 +598,7 @@ func (l *LogFile) setFrom(f *LogFile) {
type WebServer struct {
AuthenticationMethod *string
AllowOrigins *string
BridgeResponseURL *models.URL
BridgeResponseURL *commonconfig.URL
BridgeCacheTTL *commonconfig.Duration
HTTPWriteTimeout *commonconfig.Duration
HTTPPort *uint16
Expand Down
7 changes: 4 additions & 3 deletions core/config/toml/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/stretchr/testify/assert"

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink/v2/core/build"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
Expand Down Expand Up @@ -109,13 +110,13 @@ func Test_validateDBURL(t *testing.T) {
}

func TestDatabaseSecrets_ValidateConfig(t *testing.T) {
validUrl := models.URL(url.URL{Scheme: "https", Host: "localhost"})
validUrl := commonconfig.URL(url.URL{Scheme: "https", Host: "localhost"})
validSecretURL := *models.NewSecretURL(&validUrl)

invalidEmptyUrl := models.URL(url.URL{})
invalidEmptyUrl := commonconfig.URL(url.URL{})
invalidEmptySecretURL := *models.NewSecretURL(&invalidEmptyUrl)

invalidBackupURL := models.URL(url.URL{Scheme: "http", Host: "localhost"})
invalidBackupURL := commonconfig.URL(url.URL{Scheme: "http", Host: "localhost"})
invalidBackupSecretURL := *models.NewSecretURL(&invalidBackupURL)

tests := []struct {
Expand Down
10 changes: 5 additions & 5 deletions core/internal/testutils/configtest/general_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func overrides(c *chainlink.Config, s *chainlink.Secrets) {
c.P2P.V2.Enabled = ptr(false)

c.WebServer.SessionTimeout = commonconfig.MustNewDuration(2 * time.Minute)
c.WebServer.BridgeResponseURL = models.MustParseURL("http://localhost:6688")
c.WebServer.BridgeResponseURL = commonconfig.MustParseURL("http://localhost:6688")
testIP := net.ParseIP("127.0.0.1")
c.WebServer.ListenIP = &testIP
c.WebServer.TLS.ListenIP = &testIP
Expand All @@ -72,8 +72,8 @@ func overrides(c *chainlink.Config, s *chainlink.Secrets) {
Nodes: evmcfg.EVMNodes{
&evmcfg.Node{
Name: ptr("test"),
WSURL: &models.URL{},
HTTPURL: &models.URL{},
WSURL: &commonconfig.URL{},
HTTPURL: &commonconfig.URL{},
SendOnly: new(bool),
Order: ptr[int32](100),
},
Expand Down Expand Up @@ -113,8 +113,8 @@ func simulated(c *chainlink.Config, s *chainlink.Secrets) {

var validTestNode = evmcfg.Node{
Name: ptr("simulated-node"),
WSURL: models.MustParseURL("WSS://simulated-wss.com/ws"),
HTTPURL: models.MustParseURL("http://simulated.com"),
WSURL: commonconfig.MustParseURL("WSS://simulated-wss.com/ws"),
HTTPURL: commonconfig.MustParseURL("http://simulated.com"),
SendOnly: nil,
Order: ptr(int32(1)),
}
Expand Down
4 changes: 2 additions & 2 deletions core/logger/audit/audit_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"os"
"time"

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/services"

"github.com/smartcontractkit/chainlink/v2/core/config"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
Expand All @@ -38,7 +38,7 @@ type HTTPAuditLoggerInterface interface {
type AuditLoggerService struct {
logger logger.Logger // The standard logger configured in the node
enabled bool // Whether the audit logger is enabled or not
forwardToUrl models.URL // Location we are going to send logs to
forwardToUrl commonconfig.URL // Location we are going to send logs to
headers []models.ServiceHeader // Headers to be sent along with logs for identification/authentication
jsonWrapperKey string // Wrap audit data as a map under this key if present
environmentName string // Decorate the environment this is coming from
Expand Down
7 changes: 4 additions & 3 deletions core/logger/audit/audit_logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/urfave/cli"

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink/v2/core/internal/cltest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/logger"
Expand Down Expand Up @@ -65,10 +66,10 @@ func (c Config) Environment() string {
return "test"
}

func (c Config) ForwardToUrl() (models.URL, error) {
url, err := models.ParseURL("http://localhost:9898")
func (c Config) ForwardToUrl() (commonconfig.URL, error) {
url, err := commonconfig.ParseURL("http://localhost:9898")
if err != nil {
return models.URL{}, err
return commonconfig.URL{}, err
}
return *url, nil
}
Expand Down
2 changes: 1 addition & 1 deletion core/services/chainlink/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
// - TOML is limited to int64/float64, so fields requiring greater range/precision must use non-standard types
// implementing encoding.TextMarshaler/TextUnmarshaler, like big.Big and decimal.Decimal
// - std lib types that don't implement encoding.TextMarshaler/TextUnmarshaler (time.Duration, url.URL, big.Int) won't
// work as expected, and require wrapper types. See commonconfig.Duration, models.URL, big.Big.
// work as expected, and require wrapper types. See commonconfig.Duration, commonconfig.URL, big.Big.
type Config struct {
toml.Core

Expand Down
3 changes: 2 additions & 1 deletion core/services/chainlink/config_audit_logger.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package chainlink

import (
commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink/v2/core/build"
"github.com/smartcontractkit/chainlink/v2/core/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
Expand All @@ -14,7 +15,7 @@ func (a auditLoggerConfig) Enabled() bool {
return *a.c.Enabled
}

func (a auditLoggerConfig) ForwardToUrl() (models.URL, error) {
func (a auditLoggerConfig) ForwardToUrl() (commonconfig.URL, error) {
return *a.c.ForwardToUrl, nil
}

Expand Down
10 changes: 5 additions & 5 deletions core/services/chainlink/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func TestConfig_Marshal(t *testing.T) {
SendInterval: commonconfig.MustNewDuration(time.Minute),
SendTimeout: commonconfig.MustNewDuration(5 * time.Second),
UseBatchSend: ptr(true),
URL: ptr(models.URL{}),
URL: ptr(commonconfig.URL{}),
ServerPubKey: ptr(""),
Endpoints: []toml.TelemetryIngressEndpoint{{
Network: ptr("EVM"),
Expand Down Expand Up @@ -1124,7 +1124,7 @@ func TestConfig_full(t *testing.T) {
for c := range got.EVM {
for n := range got.EVM[c].Nodes {
if got.EVM[c].Nodes[n].WSURL == nil {
got.EVM[c].Nodes[n].WSURL = new(models.URL)
got.EVM[c].Nodes[n].WSURL = new(commonconfig.URL)
}
if got.EVM[c].Nodes[n].SendOnly == nil {
got.EVM[c].Nodes[n].SendOnly = ptr(true)
Expand All @@ -1143,7 +1143,7 @@ func TestConfig_full(t *testing.T) {
// Except for TelemetryIngress.URL as this will be removed in the future
// and its only use is to signal to NOPs that these fields are no longer allowed
if got.TelemetryIngress.URL == nil {
got.TelemetryIngress.URL = new(models.URL)
got.TelemetryIngress.URL = new(commonconfig.URL)
}

cfgtest.AssertFieldsNotNil(t, got)
Expand Down Expand Up @@ -1256,8 +1256,8 @@ func TestConfig_Validate(t *testing.T) {
}
}

func mustURL(s string) *models.URL {
var u models.URL
func mustURL(s string) *commonconfig.URL {
var u commonconfig.URL
if err := u.UnmarshalText([]byte(s)); err != nil {
panic(err)
}
Expand Down
Loading

0 comments on commit c5d9272

Please sign in to comment.