Skip to content

Commit

Permalink
fix_: address PR feedback part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
friofry committed Jan 10, 2025
1 parent a368ae1 commit 30d653a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 13 additions & 4 deletions params/networkhelper/provider_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,19 @@ func OverrideEmbeddedProxyProviders(networks []params.Network, enabled bool, use
return updatedNetworks
}

func OverrideDirectProvidersAuth(networks []params.Network, authTokens map[string]string) []params.Network {
func deepCopyNetworks(networks []params.Network) []params.Network {
updatedNetworks := make([]params.Network, len(networks))
copy(updatedNetworks, networks)
for i, network := range networks {
updatedNetwork := network
updatedNetwork.RpcProviders = make([]params.RpcProvider, len(network.RpcProviders))
copy(updatedNetwork.RpcProviders, network.RpcProviders)
updatedNetworks[i] = updatedNetwork
}
return updatedNetworks
}

func OverrideDirectProvidersAuth(networks []params.Network, authTokens map[string]string) []params.Network {
updatedNetworks := deepCopyNetworks(networks)

for i := range updatedNetworks {
network := &updatedNetworks[i]
Expand Down Expand Up @@ -149,8 +159,7 @@ func OverrideDirectProvidersAuth(networks []params.Network, authTokens map[strin
}

func OverrideGanacheToken(networks []params.Network, ganacheURL string, chainID uint64, tokenOverride params.TokenOverride) []params.Network {
updatedNetworks := make([]params.Network, len(networks))
copy(updatedNetworks, networks)
updatedNetworks := deepCopyNetworks(networks)

for i := range updatedNetworks {
network := &updatedNetworks[i]
Expand Down
4 changes: 3 additions & 1 deletion params/networkhelper/provider_utils_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package networkhelper_test

import (
"github.com/ethereum/go-ethereum/common"
"reflect"
"strings"
"testing"
Expand All @@ -9,7 +10,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ethereum/go-ethereum/common"
"github.com/status-im/status-go/api"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/params/networkhelper"
Expand Down Expand Up @@ -127,9 +127,11 @@ func TestOverrideDirectProvidersAuth(t *testing.T) {
case strings.Contains(provider.URL, "infura.io"):
assert.Equal(t, params.TokenAuth, provider.AuthType)
assert.Equal(t, authTokens["infura.io"], provider.AuthToken)
assert.NotEqual(t, expectedProvider.AuthToken, provider.AuthToken)
case strings.Contains(provider.URL, "grove.city"):
assert.Equal(t, params.TokenAuth, provider.AuthType)
assert.Equal(t, authTokens["grove.city"], provider.AuthToken)
assert.NotEqual(t, expectedProvider.AuthToken, provider.AuthToken)
case strings.Contains(provider.URL, "example.com"):
assert.Equal(t, params.NoAuth, provider.AuthType) // should not update user providers
default:
Expand Down

0 comments on commit 30d653a

Please sign in to comment.