2023-04-25 12:00:17 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2024-10-14 14:39:37 +00:00
|
|
|
"github.com/pkg/errors"
|
2023-04-25 12:00:17 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/protocol/requests"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBuildDefaultNetworks(t *testing.T) {
|
2024-10-14 14:39:37 +00:00
|
|
|
rpcToken := "infura-token"
|
|
|
|
fallbackToken := ""
|
2024-08-14 15:35:48 +00:00
|
|
|
stageName := "fast-n-bulbous"
|
2023-04-25 12:00:17 +00:00
|
|
|
request := &requests.CreateAccount{
|
2023-05-24 15:02:53 +00:00
|
|
|
WalletSecretsConfig: requests.WalletSecretsConfig{
|
2024-10-14 14:39:37 +00:00
|
|
|
InfuraToken: rpcToken,
|
2024-08-14 15:35:48 +00:00
|
|
|
StatusProxyStageName: stageName,
|
2023-05-24 15:02:53 +00:00
|
|
|
},
|
2023-04-25 12:00:17 +00:00
|
|
|
}
|
|
|
|
|
2024-04-22 12:33:23 +00:00
|
|
|
actualNetworks := BuildDefaultNetworks(&request.WalletSecretsConfig)
|
2023-04-25 12:00:17 +00:00
|
|
|
|
2024-10-15 07:29:21 +00:00
|
|
|
require.Len(t, actualNetworks, 6)
|
2024-10-14 14:39:37 +00:00
|
|
|
|
|
|
|
for _, n := range actualNetworks {
|
|
|
|
var err error
|
|
|
|
switch n.ChainID {
|
|
|
|
case mainnetChainID:
|
|
|
|
case sepoliaChainID:
|
|
|
|
case optimismChainID:
|
|
|
|
case optimismSepoliaChainID:
|
|
|
|
case arbitrumChainID:
|
|
|
|
case arbitrumSepoliaChainID:
|
|
|
|
default:
|
|
|
|
err = errors.Errorf("unexpected chain id: %d", n.ChainID)
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check default chains
|
2024-10-15 07:29:21 +00:00
|
|
|
// DefaultRPCURL and DefaultFallbackURL are mandatory
|
|
|
|
require.True(t, strings.Contains(n.DefaultRPCURL, stageName))
|
|
|
|
require.True(t, strings.Contains(n.DefaultFallbackURL, stageName))
|
|
|
|
if n.DefaultFallbackURL2 != "" {
|
|
|
|
require.True(t, strings.Contains(actualNetworks[0].DefaultFallbackURL2, stageName))
|
2024-10-14 14:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// check fallback options
|
|
|
|
require.True(t, strings.Contains(n.RPCURL, rpcToken))
|
|
|
|
require.True(t, strings.Contains(n.FallbackURL, fallbackToken))
|
|
|
|
}
|
2023-04-25 12:00:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestBuildDefaultNetworksGanache(t *testing.T) {
|
|
|
|
ganacheURL := "ganacheurl"
|
|
|
|
request := &requests.CreateAccount{
|
2023-05-24 15:02:53 +00:00
|
|
|
WalletSecretsConfig: requests.WalletSecretsConfig{
|
|
|
|
GanacheURL: ganacheURL,
|
|
|
|
},
|
2023-04-25 12:00:17 +00:00
|
|
|
}
|
|
|
|
|
2024-04-22 12:33:23 +00:00
|
|
|
actualNetworks := BuildDefaultNetworks(&request.WalletSecretsConfig)
|
2023-04-25 12:00:17 +00:00
|
|
|
|
2024-10-15 07:29:21 +00:00
|
|
|
require.Len(t, actualNetworks, 6)
|
2023-04-25 12:00:17 +00:00
|
|
|
|
|
|
|
for _, n := range actualNetworks {
|
|
|
|
require.True(t, strings.Contains(n.RPCURL, ganacheURL))
|
|
|
|
require.True(t, strings.Contains(n.FallbackURL, ganacheURL))
|
|
|
|
}
|
|
|
|
|
|
|
|
require.Equal(t, mainnetChainID, actualNetworks[0].ChainID)
|
|
|
|
|
|
|
|
require.NotNil(t, actualNetworks[0].TokenOverrides)
|
|
|
|
require.Len(t, actualNetworks[0].TokenOverrides, 1)
|
|
|
|
require.Equal(t, sntSymbol, actualNetworks[0].TokenOverrides[0].Symbol)
|
|
|
|
require.Equal(t, ganacheTokenAddress, actualNetworks[0].TokenOverrides[0].Address)
|
|
|
|
}
|