Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Services/horizon: Integration tests for NETWORK parameter #4974

Merged
merged 13 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions services/horizon/internal/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ const (
// CaptiveCoreConfigUseDB is the command line flag for enabling captive core runtime to use an external db url
// connection rather than RAM for ledger states
CaptiveCoreConfigUseDB = "captive-core-use-db"
// CaptiveCoreHTTPPortFlagName is the commandline flag for specifying captive core HTTP port
CaptiveCoreHTTPPortFlagName = "captive-core-http-port"
// EnableCaptiveCoreIngestionFlagName is the commandline flag for enabling captive core ingestion
EnableCaptiveCoreIngestionFlagName = "enable-captive-core-ingestion"
// NetworkPassphraseFlagName is the command line flag for specifying the network passphrase
NetworkPassphraseFlagName = "network-passphrase"
// HistoryArchiveURLsFlagName is the command line flag for specifying the history archive URLs
Expand Down Expand Up @@ -643,8 +647,8 @@ type ApplyOptions struct {

type networkConfig struct {
defaultConfig []byte
historyArchiveURLs []string
networkPassphrase string
HistoryArchiveURLs []string
NetworkPassphrase string
}

var (
Expand All @@ -654,16 +658,16 @@ var (
//go:embed configs/captive-core-testnet.cfg
TestnetDefaultConfig []byte

pubnetConf = networkConfig{
PubnetConf = networkConfig{
defaultConfig: PubnetDefaultConfig,
historyArchiveURLs: network.PublicNetworkhistoryArchiveURLs,
networkPassphrase: network.PublicNetworkPassphrase,
HistoryArchiveURLs: network.PublicNetworkhistoryArchiveURLs,
NetworkPassphrase: network.PublicNetworkPassphrase,
}

testnetConf = networkConfig{
TestnetConf = networkConfig{
defaultConfig: TestnetDefaultConfig,
historyArchiveURLs: network.TestNetworkhistoryArchiveURLs,
networkPassphrase: network.TestNetworkPassphrase,
HistoryArchiveURLs: network.TestNetworkhistoryArchiveURLs,
NetworkPassphrase: network.TestNetworkPassphrase,
}
)

Expand Down Expand Up @@ -712,24 +716,24 @@ func loadCaptiveCoreTomlFromFile(config *Config) error {
func createCaptiveCoreConfigFromNetwork(config *Config) error {

if config.NetworkPassphrase != "" {
return fmt.Errorf("invalid config: %s not allowed with %s network", NetworkPassphraseFlagName, config.Network)
return fmt.Errorf("invalid config: %s parameter not allowed with the %s parameter", NetworkPassphraseFlagName, NetworkFlagName)
}

if len(config.HistoryArchiveURLs) > 0 {
return fmt.Errorf("invalid config: %s not allowed with %s network", HistoryArchiveURLsFlagName, config.Network)
return fmt.Errorf("invalid config: %s parameter not allowed with the %s parameter", HistoryArchiveURLsFlagName, NetworkFlagName)
}

var defaultNetworkConfig networkConfig
switch config.Network {
case StellarPubnet:
defaultNetworkConfig = pubnetConf
defaultNetworkConfig = PubnetConf
case StellarTestnet:
defaultNetworkConfig = testnetConf
defaultNetworkConfig = TestnetConf
default:
return fmt.Errorf("no default configuration found for network %s", config.Network)
}
config.NetworkPassphrase = defaultNetworkConfig.networkPassphrase
config.HistoryArchiveURLs = defaultNetworkConfig.historyArchiveURLs
config.NetworkPassphrase = defaultNetworkConfig.NetworkPassphrase
config.HistoryArchiveURLs = defaultNetworkConfig.HistoryArchiveURLs

if config.CaptiveCoreConfigPath == "" {
return loadDefaultCaptiveCoreToml(config, defaultNetworkConfig.defaultConfig)
Expand Down Expand Up @@ -779,12 +783,12 @@ func setCaptiveCoreConfiguration(config *Config) error {
if config.Network != "" {
err := createCaptiveCoreConfigFromNetwork(config)
if err != nil {
return errors.Wrap(err, "error generating default captive core config.")
return err
}
} else {
err := createCaptiveCoreConfigFromParameters(config)
if err != nil {
return errors.Wrap(err, "error generating captive core config.")
return err
}
}

Expand Down
18 changes: 9 additions & 9 deletions services/horizon/internal/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func Test_createCaptiveCoreDefaultConfig(t *testing.T) {

var errorMsgDefaultConfig = "invalid config: %s not allowed with %s network"
var errorMsgDefaultConfig = "invalid config: %s parameter not allowed with the network parameter"
tests := []struct {
name string
config Config
Expand All @@ -21,44 +21,44 @@ func Test_createCaptiveCoreDefaultConfig(t *testing.T) {
{
name: "testnet default config",
config: Config{Network: StellarTestnet},
networkPassphrase: testnetConf.networkPassphrase,
historyArchiveURLs: testnetConf.historyArchiveURLs,
networkPassphrase: TestnetConf.NetworkPassphrase,
historyArchiveURLs: TestnetConf.HistoryArchiveURLs,
},
{
name: "pubnet default config",
config: Config{Network: StellarPubnet},
networkPassphrase: pubnetConf.networkPassphrase,
historyArchiveURLs: pubnetConf.historyArchiveURLs,
networkPassphrase: PubnetConf.NetworkPassphrase,
historyArchiveURLs: PubnetConf.HistoryArchiveURLs,
},
{
name: "testnet validation; history archive urls supplied",
config: Config{Network: StellarTestnet,
HistoryArchiveURLs: []string{"network history archive urls supplied"},
},
errStr: fmt.Sprintf(errorMsgDefaultConfig, HistoryArchiveURLsFlagName, StellarTestnet),
errStr: fmt.Sprintf(errorMsgDefaultConfig, HistoryArchiveURLsFlagName),
},
{
name: "pubnet validation; history archive urls supplied",
config: Config{Network: StellarPubnet,
HistoryArchiveURLs: []string{"network history archive urls supplied"},
},
errStr: fmt.Sprintf(errorMsgDefaultConfig, HistoryArchiveURLsFlagName, StellarPubnet),
errStr: fmt.Sprintf(errorMsgDefaultConfig, HistoryArchiveURLsFlagName),
},
{
name: "testnet validation; network passphrase supplied",
config: Config{Network: StellarTestnet,
NetworkPassphrase: "network passphrase supplied",
HistoryArchiveURLs: []string{},
},
errStr: fmt.Sprintf(errorMsgDefaultConfig, NetworkPassphraseFlagName, StellarTestnet),
errStr: fmt.Sprintf(errorMsgDefaultConfig, NetworkPassphraseFlagName),
},
{
name: "pubnet validation; network passphrase supplied",
config: Config{Network: StellarPubnet,
NetworkPassphrase: "pubnet network passphrase supplied",
HistoryArchiveURLs: []string{},
},
errStr: fmt.Sprintf(errorMsgDefaultConfig, NetworkPassphraseFlagName, StellarPubnet),
errStr: fmt.Sprintf(errorMsgDefaultConfig, NetworkPassphraseFlagName),
},
{
name: "unknown network specified",
Expand Down
Loading
Loading