Skip to content

Commit

Permalink
Refactoring, tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed Aug 16, 2024
1 parent 2f99eda commit 3786f54
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
8 changes: 8 additions & 0 deletions cmd/rosetta/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import (
"github.com/multiversx/mx-chain-rosetta/server/resources"
)

func decideCustomCurrencies(configFileCustomCurrencies string) ([]resources.Currency, error) {
if len(configFileCustomCurrencies) == 0 {
return make([]resources.Currency, 0), nil
}

return loadConfigOfCustomCurrencies(configFileCustomCurrencies)
}

func loadConfigOfCustomCurrencies(configFile string) ([]resources.Currency, error) {
fileContent, err := os.ReadFile(configFile)
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions cmd/rosetta/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ import (
"github.com/stretchr/testify/require"
)

func TestDecideCustomCurrencies(t *testing.T) {
t.Run("with success (file provided)", func(t *testing.T) {
customCurrencies, err := decideCustomCurrencies("testdata/custom-currencies.json")
require.NoError(t, err)
require.Len(t, customCurrencies, 2)
})

t.Run("with success (file not provided)", func(t *testing.T) {
customCurrencies, err := decideCustomCurrencies("")
require.NoError(t, err)
require.Empty(t, customCurrencies)
})
}

func TestLoadConfigOfCustomCurrencies(t *testing.T) {
t.Run("with success", func(t *testing.T) {
customCurrencies, err := loadConfigOfCustomCurrencies("testdata/custom-currencies.json")
Expand Down
9 changes: 0 additions & 9 deletions cmd/rosetta/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/coinbase/rosetta-sdk-go/server"
"github.com/multiversx/mx-chain-rosetta/server/factory"
"github.com/multiversx/mx-chain-rosetta/server/resources"
"github.com/multiversx/mx-chain-rosetta/version"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -124,14 +123,6 @@ func startRosetta(ctx *cli.Context) error {
return nil
}

func decideCustomCurrencies(configFileCustomCurrencies string) ([]resources.Currency, error) {
if len(configFileCustomCurrencies) == 0 {
return make([]resources.Currency, 0), nil
}

return loadConfigOfCustomCurrencies(configFileCustomCurrencies)
}

func createHttpServer(port int, routers ...server.Router) (*http.Server, error) {
router := server.NewRouter(
routers...,
Expand Down

0 comments on commit 3786f54

Please sign in to comment.