Skip to content

Commit

Permalink
fix: loading of custom endpoint address
Browse files Browse the repository at this point in the history
  • Loading branch information
PhearZero committed Nov 5, 2024
1 parent 3c88bbb commit 8ceaebe
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func initConfig() {
// Check for endpoint address
if hasWildcardEndpointUrl(algodConfig.EndpointAddress) {
algodConfig.EndpointAddress = replaceEndpointUrl(algodConfig.EndpointAddress)
} else {
} else if algodConfig.EndpointAddress == "" {
// Assume it is not set, try to discover the port from the network file
networkPath := algorandData + "/algod.net"
networkFile, err := os.Open(networkPath)
Expand Down Expand Up @@ -245,7 +245,7 @@ func initConfig() {
}

// Set the server configuration
viper.Set("server", "http://"+algodConfig.EndpointAddress)
viper.Set("server", "http://"+strings.Replace(algodConfig.EndpointAddress, "\n", "", 1))
viper.Set("data", dataConfigPath)
}

Expand Down
14 changes: 14 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,17 @@ func Test_InitConfigWithoutEndpoint(t *testing.T) {
t.Fatal("Invalid Server")
}
}

func Test_InitConfigWithAddress(t *testing.T) {
cwd, _ := os.Getwd()
t.Setenv("ALGORAND_DATA", cwd+"/testdata/Test_InitConfigWithAddress")

initConfig()
server := viper.Get("server")
if server == "" {
t.Fatal("Invalid Server")
}
if server != "http://255.255.255.255:8080" {
t.Fatal("Invalid Server")
}
}
1 change: 1 addition & 0 deletions cmd/testdata/Test_InitConfigWithAddress/algod.admin.token
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
4 changes: 4 additions & 0 deletions cmd/testdata/Test_InitConfigWithAddress/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"EndpointAddress": "255.255.255.255:8080",
"OtherKey": ""
}

0 comments on commit 8ceaebe

Please sign in to comment.