-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
228 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
# The Licensed Work is (c) 2023 Sygma | ||
# SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
on: [pull_request] | ||
name: License check | ||
env: | ||
GO111MODULE: on | ||
|
||
jobs: | ||
license-check: | ||
runs-on: ubuntu-latest | ||
container: golang:1.19 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- run: make license | ||
- run: go install github.com/google/addlicense@latest | ||
|
||
- name: license updated check | ||
run: git diff --exit-code | ||
- run: make license-check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// The Licensed Work is (c) 2023 Sygma | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
package config | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/kelseyhightower/envconfig" | ||
"github.com/sygmaprotocol/spectre-node/config" | ||
) | ||
|
||
type EVMConfig struct { | ||
config.BaseNetworkConfig | ||
Router string `required:"true"` | ||
Executor string `required:"true"` | ||
BlockConfirmations uint8 `default:"5"` | ||
} | ||
|
||
// LoadEVMConfig loads EVM config from the environment and validates the fields | ||
func LoadEVMConfig(domainID uint8) (*EVMConfig, error) { | ||
var c EVMConfig | ||
err := envconfig.Process(fmt.Sprintf("%s_DOMAINS_%d", config.PREFIX, domainID), &c) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &c, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// The Licensed Work is (c) 2023 Sygma | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
package config_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
"github.com/sygmaprotocol/spectre-node/chains/evm/config" | ||
baseConfig "github.com/sygmaprotocol/spectre-node/config" | ||
) | ||
|
||
type EVMConfigTestSuite struct { | ||
suite.Suite | ||
} | ||
|
||
func TestRunEVMConfigTestSuite(t *testing.T) { | ||
suite.Run(t, new(EVMConfigTestSuite)) | ||
} | ||
|
||
func (s *EVMConfigTestSuite) Test_LoadEVMConfig_MissingField() { | ||
os.Setenv("SPECTRE_DOMAINS_1_ID", "1") | ||
os.Setenv("SPECTRE_DOMAINS_1_ENDPOINT", "http://endpoint.com") | ||
os.Setenv("SPECTRE_DOMAINS_1_KEY", "key") | ||
os.Setenv("SPECTRE_DOMAINS_1_EXECUTOR", "executor") | ||
os.Setenv("SPECTRE_DOMAINS_2_ROUTER", "invalid") | ||
|
||
_, err := config.LoadEVMConfig(1) | ||
|
||
s.NotNil(err) | ||
} | ||
|
||
func (s *EVMConfigTestSuite) Test_LoadEVMConfig_SuccessfulLoad() { | ||
os.Setenv("SPECTRE_DOMAINS_1_ID", "1") | ||
os.Setenv("SPECTRE_DOMAINS_1_ENDPOINT", "http://endpoint.com") | ||
os.Setenv("SPECTRE_DOMAINS_1_KEY", "key") | ||
os.Setenv("SPECTRE_DOMAINS_1_EXECUTOR", "executor") | ||
os.Setenv("SPECTRE_DOMAINS_1_ROUTER", "router") | ||
os.Setenv("SPECTRE_DOMAINS_2_ROUTER", "invalid") | ||
|
||
c, err := config.LoadEVMConfig(1) | ||
|
||
s.Nil(err) | ||
s.Equal(c, &config.EVMConfig{ | ||
BaseNetworkConfig: baseConfig.BaseNetworkConfig{ | ||
ID: 1, | ||
Key: "key", | ||
Endpoint: "http://endpoint.com", | ||
}, | ||
Router: "router", | ||
Executor: "executor", | ||
BlockConfirmations: 5, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// The Licensed Work is (c) 2023 Sygma | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
package config | ||
|
||
import "github.com/kelseyhightower/envconfig" | ||
|
||
const PREFIX = "SPECTRE" | ||
|
||
type Config struct { | ||
Observability *Observability `env_config:"observability"` | ||
Prover *Prover `env_config:"prover"` | ||
} | ||
|
||
type Observability struct { | ||
LogLevel string `default:"debug" split_words:"true"` | ||
LogFile string `default:"out.log" split_words:"true"` | ||
} | ||
|
||
type Prover struct { | ||
URL string `required:"true"` | ||
} | ||
|
||
// LoadConfig loads config from the environment and validates the fields | ||
func LoadConfig() (*Config, error) { | ||
var c Config | ||
err := envconfig.Process(PREFIX, &c) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &c, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// The Licensed Work is (c) 2023 Sygma | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
package config_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
"github.com/sygmaprotocol/spectre-node/config" | ||
) | ||
|
||
type ConfigTestSuite struct { | ||
suite.Suite | ||
} | ||
|
||
func TestRunConfigTestSuite(t *testing.T) { | ||
suite.Run(t, new(ConfigTestSuite)) | ||
} | ||
|
||
func (c *ConfigTestSuite) TearDownTest() { | ||
os.Clearenv() | ||
} | ||
|
||
func (s *ConfigTestSuite) Test_LoadConfig_MissingField() { | ||
_, err := config.LoadConfig() | ||
|
||
s.NotNil(err) | ||
} | ||
|
||
func (s *ConfigTestSuite) Test_LoadConfig_DefaultValues() { | ||
os.Setenv("SPECTRE_PROVER_URL", "http://prover.com") | ||
|
||
c, err := config.LoadConfig() | ||
|
||
s.Nil(err) | ||
s.Equal(c, &config.Config{ | ||
Observability: &config.Observability{ | ||
LogLevel: "debug", | ||
LogFile: "out.log", | ||
}, | ||
Prover: &config.Prover{ | ||
URL: "http://prover.com", | ||
}, | ||
}) | ||
} | ||
|
||
func (s *ConfigTestSuite) Test_LoadEVMConfig_SuccessfulLoad() { | ||
os.Setenv("SPECTRE_OBSERVABILITY_LOG_LEVEL", "info") | ||
os.Setenv("SPECTRE_OBSERVABILITY_LOG_FILE", "out2.log") | ||
os.Setenv("SPECTRE_PROVER_URL", "http://prover.com") | ||
|
||
c, err := config.LoadConfig() | ||
|
||
s.Nil(err) | ||
s.Equal(c, &config.Config{ | ||
Observability: &config.Observability{ | ||
LogLevel: "info", | ||
LogFile: "out2.log", | ||
}, | ||
Prover: &config.Prover{ | ||
URL: "http://prover.com", | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// The Licensed Work is (c) 2023 Sygma | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
package config | ||
|
||
type BaseNetworkConfig struct { | ||
ID uint8 `required:"true"` | ||
Endpoint string `required:"true"` | ||
Key string `required:"true"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= | ||
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= | ||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |