Update default networks list and build Wallet config on login (#4592)
This commit: - Updates the default networks list to include the Sepolia test network - Updates the "LoginAccount" method to build and include the wallet config in the node config --------- Signed-off-by: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com>
This commit is contained in:
parent
d5a10a97f1
commit
7816ee186d
|
@ -1419,3 +1419,80 @@ func TestSetFleet(t *testing.T) {
|
|||
|
||||
require.NoError(t, b.Logout())
|
||||
}
|
||||
|
||||
func TestWalletConfigOnLoginAccount(t *testing.T) {
|
||||
utils.Init()
|
||||
password := "some-password2" // nolint: goconst
|
||||
tmpdir := t.TempDir()
|
||||
poktToken := "grove-token" // nolint: goconst
|
||||
infuraToken := "infura-token" // nolint: goconst
|
||||
alchemyEthereumMainnetToken := "alchemy-ethereum-mainnet-token"
|
||||
alchemyEthereumSepoliaToken := "alchemy-ethereum-sepolia-token"
|
||||
alchemyArbitrumMainnetToken := "alchemy-arbitrum-mainnet-token"
|
||||
alchemyArbitrumSepoliaToken := "alchemy-arbitrum-sepolia-token"
|
||||
alchemyOptimismMainnetToken := "alchemy-optimism-mainnet-token"
|
||||
alchemyOptimismSepoliaToken := "alchemy-optimism-sepolia-token"
|
||||
raribleMainnetAPIKey := "rarible-mainnet-api-key" // nolint: gosec
|
||||
raribleTestnetAPIKey := "rarible-testnet-api-key" // nolint: gosec
|
||||
|
||||
b := NewGethStatusBackend()
|
||||
createAccountRequest := &requests.CreateAccount{
|
||||
DisplayName: "some-display-name",
|
||||
CustomizationColor: "#ffffff",
|
||||
Password: password,
|
||||
BackupDisabledDataDir: tmpdir,
|
||||
NetworkID: 1,
|
||||
LogFilePath: tmpdir + "/log",
|
||||
Emoji: "some",
|
||||
}
|
||||
c := make(chan interface{}, 10)
|
||||
signal.SetMobileSignalHandler(func(data []byte) {
|
||||
if strings.Contains(string(data), "node.login") {
|
||||
c <- struct{}{}
|
||||
}
|
||||
})
|
||||
|
||||
newAccount, err := b.CreateAccountAndLogin(createAccountRequest)
|
||||
require.NoError(t, err)
|
||||
statusNode := b.statusNode
|
||||
require.NotNil(t, statusNode)
|
||||
|
||||
require.NoError(t, b.Logout())
|
||||
|
||||
loginAccountRequest := &requests.Login{
|
||||
KeyUID: newAccount.KeyUID,
|
||||
Password: password,
|
||||
WalletSecretsConfig: requests.WalletSecretsConfig{
|
||||
PoktToken: poktToken,
|
||||
InfuraToken: infuraToken,
|
||||
AlchemyEthereumMainnetToken: alchemyEthereumMainnetToken,
|
||||
AlchemyEthereumSepoliaToken: alchemyEthereumSepoliaToken,
|
||||
AlchemyArbitrumMainnetToken: alchemyArbitrumMainnetToken,
|
||||
AlchemyArbitrumSepoliaToken: alchemyArbitrumSepoliaToken,
|
||||
AlchemyOptimismMainnetToken: alchemyOptimismMainnetToken,
|
||||
AlchemyOptimismSepoliaToken: alchemyOptimismSepoliaToken,
|
||||
RaribleMainnetAPIKey: raribleMainnetAPIKey,
|
||||
RaribleTestnetAPIKey: raribleTestnetAPIKey,
|
||||
},
|
||||
}
|
||||
|
||||
require.NoError(t, b.LoginAccount(loginAccountRequest))
|
||||
select {
|
||||
case <-c:
|
||||
break
|
||||
case <-time.After(5 * time.Second):
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
require.Equal(t, b.config.WalletConfig.InfuraAPIKey, infuraToken)
|
||||
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[mainnetChainID], alchemyEthereumMainnetToken)
|
||||
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[sepoliaChainID], alchemyEthereumSepoliaToken)
|
||||
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[arbitrumChainID], alchemyArbitrumMainnetToken)
|
||||
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[arbitrumSepoliaChainID], alchemyArbitrumSepoliaToken)
|
||||
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[optimismChainID], alchemyOptimismMainnetToken)
|
||||
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[optimismSepoliaChainID], alchemyOptimismSepoliaToken)
|
||||
require.Equal(t, b.config.WalletConfig.RaribleMainnetAPIKey, raribleMainnetAPIKey)
|
||||
require.Equal(t, b.config.WalletConfig.RaribleTestnetAPIKey, raribleTestnetAPIKey)
|
||||
|
||||
require.NoError(t, b.Logout())
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ var mainnet = params.Network{
|
|||
|
||||
var goerli = params.Network{
|
||||
ChainID: goerliChainID,
|
||||
ChainName: "Ethereum Mainnet",
|
||||
ChainName: "Ethereum Goerli",
|
||||
RPCURL: "https://goerli-archival.rpc.grove.city/v1/",
|
||||
FallbackURL: "https://goerli.infura.io/v3/",
|
||||
BlockExplorerURL: "https://goerli.etherscan.io/",
|
||||
|
@ -60,6 +60,24 @@ var goerli = params.Network{
|
|||
RelatedChainID: mainnetChainID,
|
||||
}
|
||||
|
||||
var sepolia = params.Network{
|
||||
ChainID: sepoliaChainID,
|
||||
ChainName: "Ethereum Sepolia",
|
||||
RPCURL: "https://sepolia-archival.rpc.grove.city/v1/",
|
||||
FallbackURL: "https://sepolia.infura.io/v3/",
|
||||
BlockExplorerURL: "https://sepolia.etherscan.io/",
|
||||
IconURL: "network/Network=Testnet",
|
||||
ChainColor: "#51D0F0",
|
||||
ShortName: "eth",
|
||||
NativeCurrencyName: "Ether",
|
||||
NativeCurrencySymbol: "ETH",
|
||||
NativeCurrencyDecimals: 18,
|
||||
IsTest: true,
|
||||
Layer: 1,
|
||||
Enabled: true,
|
||||
RelatedChainID: mainnetChainID,
|
||||
}
|
||||
|
||||
var optimism = params.Network{
|
||||
ChainID: optimismChainID,
|
||||
ChainName: "Optimism",
|
||||
|
@ -80,7 +98,7 @@ var optimism = params.Network{
|
|||
|
||||
var optimismGoerli = params.Network{
|
||||
ChainID: optimismGoerliChainID,
|
||||
ChainName: "Optimism Goerli Testnet",
|
||||
ChainName: "Optimism Goerli",
|
||||
RPCURL: "https://optimism-goerli.infura.io/v3/",
|
||||
FallbackURL: "",
|
||||
BlockExplorerURL: "https://goerli-optimism.etherscan.io/",
|
||||
|
@ -95,6 +113,25 @@ var optimismGoerli = params.Network{
|
|||
Enabled: false,
|
||||
RelatedChainID: optimismChainID,
|
||||
}
|
||||
|
||||
var optimismSepolia = params.Network{
|
||||
ChainID: optimismSepoliaChainID,
|
||||
ChainName: "Optimism Sepolia",
|
||||
RPCURL: "https://optimism-sepolia.infura.io/v3/",
|
||||
FallbackURL: "",
|
||||
BlockExplorerURL: "https://sepolia-optimism.etherscan.io/",
|
||||
IconURL: "network/Network=Testnet",
|
||||
ChainColor: "#939BA1",
|
||||
ShortName: "opt",
|
||||
NativeCurrencyName: "Ether",
|
||||
NativeCurrencySymbol: "ETH",
|
||||
NativeCurrencyDecimals: 18,
|
||||
IsTest: true,
|
||||
Layer: 2,
|
||||
Enabled: false,
|
||||
RelatedChainID: optimismChainID,
|
||||
}
|
||||
|
||||
var arbitrum = params.Network{
|
||||
ChainID: arbitrumChainID,
|
||||
ChainName: "Arbitrum",
|
||||
|
@ -131,13 +168,34 @@ var arbitrumGoerli = params.Network{
|
|||
RelatedChainID: arbitrumChainID,
|
||||
}
|
||||
|
||||
var arbitrumSepolia = params.Network{
|
||||
ChainID: arbitrumSepoliaChainID,
|
||||
ChainName: "Arbitrum Sepolia",
|
||||
RPCURL: "https://arbitrum-sepolia.infura.io/v3/",
|
||||
FallbackURL: "",
|
||||
BlockExplorerURL: "https://sepolia-explorer.arbitrum.io/",
|
||||
IconURL: "network/Network=Testnet",
|
||||
ChainColor: "#51D0F0",
|
||||
ShortName: "arb",
|
||||
NativeCurrencyName: "Ether",
|
||||
NativeCurrencySymbol: "ETH",
|
||||
NativeCurrencyDecimals: 18,
|
||||
IsTest: true,
|
||||
Layer: 2,
|
||||
Enabled: false,
|
||||
RelatedChainID: arbitrumChainID,
|
||||
}
|
||||
|
||||
var defaultNetworks = []params.Network{
|
||||
mainnet,
|
||||
goerli,
|
||||
sepolia,
|
||||
optimism,
|
||||
optimismGoerli,
|
||||
optimismSepolia,
|
||||
arbitrum,
|
||||
arbitrumGoerli,
|
||||
arbitrumSepolia,
|
||||
}
|
||||
|
||||
var mainnetGanacheTokenOverrides = params.TokenOverride{
|
||||
|
|
|
@ -21,7 +21,7 @@ func TestBuildDefaultNetworks(t *testing.T) {
|
|||
|
||||
actualNetworks := BuildDefaultNetworks(request)
|
||||
|
||||
require.Len(t, actualNetworks, 6)
|
||||
require.Len(t, actualNetworks, 9)
|
||||
|
||||
require.Equal(t, mainnetChainID, actualNetworks[0].ChainID)
|
||||
|
||||
|
@ -33,25 +33,40 @@ func TestBuildDefaultNetworks(t *testing.T) {
|
|||
require.True(t, strings.Contains(actualNetworks[1].RPCURL, poktToken))
|
||||
require.True(t, strings.Contains(actualNetworks[1].FallbackURL, infuraToken))
|
||||
|
||||
require.Equal(t, optimismChainID, actualNetworks[2].ChainID)
|
||||
require.Equal(t, sepoliaChainID, actualNetworks[2].ChainID)
|
||||
|
||||
require.True(t, strings.Contains(actualNetworks[2].RPCURL, poktToken))
|
||||
require.True(t, strings.Contains(actualNetworks[2].FallbackURL, infuraToken))
|
||||
|
||||
require.Equal(t, optimismGoerliChainID, actualNetworks[3].ChainID)
|
||||
require.Equal(t, optimismChainID, actualNetworks[3].ChainID)
|
||||
|
||||
require.True(t, strings.Contains(actualNetworks[3].RPCURL, infuraToken))
|
||||
require.Equal(t, "", actualNetworks[3].FallbackURL)
|
||||
require.True(t, strings.Contains(actualNetworks[3].RPCURL, poktToken))
|
||||
require.True(t, strings.Contains(actualNetworks[3].FallbackURL, infuraToken))
|
||||
|
||||
require.Equal(t, arbitrumChainID, actualNetworks[4].ChainID)
|
||||
require.Equal(t, optimismGoerliChainID, actualNetworks[4].ChainID)
|
||||
|
||||
require.True(t, strings.Contains(actualNetworks[4].RPCURL, poktToken))
|
||||
require.True(t, strings.Contains(actualNetworks[4].FallbackURL, infuraToken))
|
||||
require.True(t, strings.Contains(actualNetworks[4].RPCURL, infuraToken))
|
||||
require.Equal(t, "", actualNetworks[4].FallbackURL)
|
||||
|
||||
require.Equal(t, arbitrumGoerliChainID, actualNetworks[5].ChainID)
|
||||
require.Equal(t, optimismSepoliaChainID, actualNetworks[5].ChainID)
|
||||
|
||||
require.True(t, strings.Contains(actualNetworks[5].RPCURL, infuraToken))
|
||||
require.Equal(t, "", actualNetworks[5].FallbackURL)
|
||||
|
||||
require.Equal(t, arbitrumChainID, actualNetworks[6].ChainID)
|
||||
|
||||
require.True(t, strings.Contains(actualNetworks[6].RPCURL, poktToken))
|
||||
require.True(t, strings.Contains(actualNetworks[6].FallbackURL, infuraToken))
|
||||
|
||||
require.Equal(t, arbitrumGoerliChainID, actualNetworks[7].ChainID)
|
||||
|
||||
require.True(t, strings.Contains(actualNetworks[7].RPCURL, infuraToken))
|
||||
require.Equal(t, "", actualNetworks[7].FallbackURL)
|
||||
|
||||
require.Equal(t, arbitrumSepoliaChainID, actualNetworks[8].ChainID)
|
||||
|
||||
require.True(t, strings.Contains(actualNetworks[8].RPCURL, infuraToken))
|
||||
require.Equal(t, "", actualNetworks[8].FallbackURL)
|
||||
}
|
||||
|
||||
func TestBuildDefaultNetworksGanache(t *testing.T) {
|
||||
|
@ -64,7 +79,7 @@ func TestBuildDefaultNetworksGanache(t *testing.T) {
|
|||
|
||||
actualNetworks := BuildDefaultNetworks(request)
|
||||
|
||||
require.Len(t, actualNetworks, 6)
|
||||
require.Len(t, actualNetworks, 9)
|
||||
|
||||
for _, n := range actualNetworks {
|
||||
require.True(t, strings.Contains(n.RPCURL, ganacheURL))
|
||||
|
|
110
api/defaults.go
110
api/defaults.go
|
@ -145,6 +145,63 @@ func SetFleet(fleet string, nodeConfig *params.NodeConfig) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func buildWalletConfig(request *requests.WalletSecretsConfig) params.WalletConfig {
|
||||
walletConfig := params.WalletConfig{
|
||||
Enabled: true,
|
||||
AlchemyAPIKeys: make(map[uint64]string),
|
||||
}
|
||||
|
||||
if request.OpenseaAPIKey != "" {
|
||||
walletConfig.OpenseaAPIKey = request.OpenseaAPIKey
|
||||
}
|
||||
|
||||
if request.RaribleMainnetAPIKey != "" {
|
||||
walletConfig.RaribleMainnetAPIKey = request.RaribleMainnetAPIKey
|
||||
}
|
||||
|
||||
if request.RaribleTestnetAPIKey != "" {
|
||||
walletConfig.RaribleTestnetAPIKey = request.RaribleTestnetAPIKey
|
||||
}
|
||||
|
||||
if request.InfuraToken != "" {
|
||||
walletConfig.InfuraAPIKey = request.InfuraToken
|
||||
}
|
||||
|
||||
if request.InfuraSecret != "" {
|
||||
walletConfig.InfuraAPIKeySecret = request.InfuraSecret
|
||||
}
|
||||
|
||||
if request.AlchemyEthereumMainnetToken != "" {
|
||||
walletConfig.AlchemyAPIKeys[mainnetChainID] = request.AlchemyEthereumMainnetToken
|
||||
}
|
||||
if request.AlchemyEthereumGoerliToken != "" {
|
||||
walletConfig.AlchemyAPIKeys[goerliChainID] = request.AlchemyEthereumGoerliToken
|
||||
}
|
||||
if request.AlchemyEthereumSepoliaToken != "" {
|
||||
walletConfig.AlchemyAPIKeys[sepoliaChainID] = request.AlchemyEthereumSepoliaToken
|
||||
}
|
||||
if request.AlchemyArbitrumMainnetToken != "" {
|
||||
walletConfig.AlchemyAPIKeys[arbitrumChainID] = request.AlchemyArbitrumMainnetToken
|
||||
}
|
||||
if request.AlchemyArbitrumGoerliToken != "" {
|
||||
walletConfig.AlchemyAPIKeys[arbitrumGoerliChainID] = request.AlchemyArbitrumGoerliToken
|
||||
}
|
||||
if request.AlchemyArbitrumSepoliaToken != "" {
|
||||
walletConfig.AlchemyAPIKeys[arbitrumSepoliaChainID] = request.AlchemyArbitrumSepoliaToken
|
||||
}
|
||||
if request.AlchemyOptimismMainnetToken != "" {
|
||||
walletConfig.AlchemyAPIKeys[optimismChainID] = request.AlchemyOptimismMainnetToken
|
||||
}
|
||||
if request.AlchemyOptimismGoerliToken != "" {
|
||||
walletConfig.AlchemyAPIKeys[optimismGoerliChainID] = request.AlchemyOptimismGoerliToken
|
||||
}
|
||||
if request.AlchemyOptimismSepoliaToken != "" {
|
||||
walletConfig.AlchemyAPIKeys[optimismSepoliaChainID] = request.AlchemyOptimismSepoliaToken
|
||||
}
|
||||
|
||||
return walletConfig
|
||||
}
|
||||
|
||||
func defaultNodeConfig(installationID string, request *requests.CreateAccount) (*params.NodeConfig, error) {
|
||||
// Set mainnet
|
||||
nodeConfig := ¶ms.NodeConfig{}
|
||||
|
@ -173,58 +230,7 @@ func defaultNodeConfig(installationID string, request *requests.CreateAccount) (
|
|||
nodeConfig.MaxPeers = 20
|
||||
nodeConfig.MaxPendingPeers = 20
|
||||
|
||||
nodeConfig.WalletConfig = params.WalletConfig{
|
||||
Enabled: true,
|
||||
AlchemyAPIKeys: make(map[uint64]string),
|
||||
}
|
||||
|
||||
if request.OpenseaAPIKey != "" {
|
||||
nodeConfig.WalletConfig.OpenseaAPIKey = request.OpenseaAPIKey
|
||||
}
|
||||
|
||||
if request.RaribleMainnetAPIKey != "" {
|
||||
nodeConfig.WalletConfig.RaribleMainnetAPIKey = request.RaribleMainnetAPIKey
|
||||
}
|
||||
|
||||
if request.RaribleTestnetAPIKey != "" {
|
||||
nodeConfig.WalletConfig.RaribleTestnetAPIKey = request.RaribleTestnetAPIKey
|
||||
}
|
||||
|
||||
if request.InfuraToken != "" {
|
||||
nodeConfig.WalletConfig.InfuraAPIKey = request.InfuraToken
|
||||
}
|
||||
|
||||
if request.InfuraSecret != "" {
|
||||
nodeConfig.WalletConfig.InfuraAPIKeySecret = request.InfuraSecret
|
||||
}
|
||||
|
||||
if request.AlchemyEthereumMainnetToken != "" {
|
||||
nodeConfig.WalletConfig.AlchemyAPIKeys[mainnetChainID] = request.AlchemyEthereumMainnetToken
|
||||
}
|
||||
if request.AlchemyEthereumGoerliToken != "" {
|
||||
nodeConfig.WalletConfig.AlchemyAPIKeys[goerliChainID] = request.AlchemyEthereumGoerliToken
|
||||
}
|
||||
if request.AlchemyEthereumSepoliaToken != "" {
|
||||
nodeConfig.WalletConfig.AlchemyAPIKeys[sepoliaChainID] = request.AlchemyEthereumSepoliaToken
|
||||
}
|
||||
if request.AlchemyArbitrumMainnetToken != "" {
|
||||
nodeConfig.WalletConfig.AlchemyAPIKeys[arbitrumChainID] = request.AlchemyArbitrumMainnetToken
|
||||
}
|
||||
if request.AlchemyArbitrumGoerliToken != "" {
|
||||
nodeConfig.WalletConfig.AlchemyAPIKeys[arbitrumGoerliChainID] = request.AlchemyArbitrumGoerliToken
|
||||
}
|
||||
if request.AlchemyArbitrumSepoliaToken != "" {
|
||||
nodeConfig.WalletConfig.AlchemyAPIKeys[arbitrumSepoliaChainID] = request.AlchemyArbitrumSepoliaToken
|
||||
}
|
||||
if request.AlchemyOptimismMainnetToken != "" {
|
||||
nodeConfig.WalletConfig.AlchemyAPIKeys[optimismChainID] = request.AlchemyOptimismMainnetToken
|
||||
}
|
||||
if request.AlchemyOptimismGoerliToken != "" {
|
||||
nodeConfig.WalletConfig.AlchemyAPIKeys[optimismGoerliChainID] = request.AlchemyOptimismGoerliToken
|
||||
}
|
||||
if request.AlchemyOptimismSepoliaToken != "" {
|
||||
nodeConfig.WalletConfig.AlchemyAPIKeys[optimismSepoliaChainID] = request.AlchemyOptimismSepoliaToken
|
||||
}
|
||||
nodeConfig.WalletConfig = buildWalletConfig(&request.WalletSecretsConfig)
|
||||
|
||||
nodeConfig.LocalNotificationsConfig = params.LocalNotificationsConfig{Enabled: true}
|
||||
nodeConfig.BrowsersConfig = params.BrowsersConfig{Enabled: true}
|
||||
|
|
|
@ -622,6 +622,8 @@ func (b *GethStatusBackend) loginAccount(request *requests.Login) error {
|
|||
KeycardPairingDataFile: defaultKeycardPairingDataFile,
|
||||
}
|
||||
|
||||
defaultCfg.WalletConfig = buildWalletConfig(&request.WalletSecretsConfig)
|
||||
|
||||
settings, err := b.GetSettings()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue