From 1886dc336041b41623187be57f43ac0d855615d3 Mon Sep 17 00:00:00 2001 From: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com> Date: Tue, 26 Mar 2024 17:08:16 +0530 Subject: [PATCH] [Feature] Allow setting TestNetworksEnabled in Create/Restore Account (#4971) This commit adds the ability to set the "TestNetworksEnabled" flag while creating an account. Function affected: "generateOrImportAccount" This helps Dev/E2E/PR builds to enable Test Networks by default and disable them on release/nightly builds. Signed-off-by: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com> --- VERSION | 2 +- api/backend_test.go | 50 +++++++++++++++++++++++++++++ api/defaults.go | 2 ++ api/geth_backend.go | 1 + cmd/ping-community/main.go | 2 ++ cmd/populate-db/main.go | 2 ++ cmd/spiff-workflow/main.go | 2 ++ multiaccounts/settings/database.go | 6 ++-- protocol/requests/create_account.go | 2 ++ 9 files changed, 66 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index eca6fc9b2..4ef231165 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.177.0 +0.177.1 diff --git a/api/backend_test.go b/api/backend_test.go index adb0f7584..f8aad85c4 100644 --- a/api/backend_test.go +++ b/api/backend_test.go @@ -1572,3 +1572,53 @@ func TestWalletConfigOnLoginAccount(t *testing.T) { require.NoError(t, b.Logout()) } + +func TestTestnetEnabledSettingOnCreateAccount(t *testing.T) { + utils.Init() + tmpdir := t.TempDir() + + b := NewGethStatusBackend() + + // Creating an account with test networks enabled + createAccountRequest1 := &requests.CreateAccount{ + DisplayName: "User-1", + CustomizationColor: "#ffffff", + Emoji: "some", + Password: "password123", + BackupDisabledDataDir: tmpdir, + NetworkID: 1, + LogFilePath: tmpdir + "/log", + TestNetworksEnabled: true, + } + _, err := b.CreateAccountAndLogin(createAccountRequest1) + require.NoError(t, err) + statusNode := b.statusNode + require.NotNil(t, statusNode) + + settings, err := b.GetSettings() + require.NoError(t, err) + require.True(t, settings.TestNetworksEnabled) + + require.NoError(t, b.Logout()) + + // Creating an account with test networks disabled + createAccountRequest2 := &requests.CreateAccount{ + DisplayName: "User-2", + CustomizationColor: "#ffffff", + Emoji: "some", + Password: "password", + BackupDisabledDataDir: tmpdir, + NetworkID: 1, + LogFilePath: tmpdir + "/log", + } + _, err = b.CreateAccountAndLogin(createAccountRequest2) + require.NoError(t, err) + statusNode = b.statusNode + require.NotNil(t, statusNode) + + settings, err = b.GetSettings() + require.NoError(t, err) + require.False(t, settings.TestNetworksEnabled) + + require.NoError(t, b.Logout()) +} diff --git a/api/defaults.go b/api/defaults.go index 26ab03018..b69a0c9f4 100644 --- a/api/defaults.go +++ b/api/defaults.go @@ -94,6 +94,8 @@ func defaultSettings(generatedAccountInfo generator.GeneratedAccountInfo, derive s.ShowCommunityAssetWhenSendingTokens = true s.DisplayAssetsBelowBalance = false + s.TestNetworksEnabled = false + return s, nil } diff --git a/api/geth_backend.go b/api/geth_backend.go index 994515986..fe48d54fa 100644 --- a/api/geth_backend.go +++ b/api/geth_backend.go @@ -1372,6 +1372,7 @@ func (b *GethStatusBackend) generateOrImportAccount(mnemonic string, customizati settings.DisplayName = request.DisplayName settings.PreviewPrivacy = request.PreviewPrivacy settings.CurrentNetwork = request.CurrentNetwork + settings.TestNetworksEnabled = request.TestNetworksEnabled // If restoring an account, we don't set the mnemonic if mnemonic == "" { diff --git a/cmd/ping-community/main.go b/cmd/ping-community/main.go index 889924b38..4e9b46300 100644 --- a/cmd/ping-community/main.go +++ b/cmd/ping-community/main.go @@ -315,6 +315,8 @@ func defaultSettings(generatedAccountInfo generator.GeneratedAccountInfo, derive defaultSettings.ProfilePicturesVisibility = settings.ProfilePicturesVisibilityEveryone defaultSettings.LinkPreviewRequestEnabled = true + defaultSettings.TestNetworksEnabled = false + visibleTokens := make(map[string][]string) visibleTokens["mainnet"] = []string{"SNT"} visibleTokensJSON, err := json.Marshal(visibleTokens) diff --git a/cmd/populate-db/main.go b/cmd/populate-db/main.go index aae78af0b..01b41bf4e 100644 --- a/cmd/populate-db/main.go +++ b/cmd/populate-db/main.go @@ -363,6 +363,8 @@ func defaultSettings(generatedAccountInfo generator.GeneratedAccountInfo, derive defaultSettings.ProfilePicturesVisibility = settings.ProfilePicturesVisibilityEveryone defaultSettings.LinkPreviewRequestEnabled = true + defaultSettings.TestNetworksEnabled = false + visibleTokens := make(map[string][]string) visibleTokens["mainnet"] = []string{"SNT"} visibleTokensJSON, err := json.Marshal(visibleTokens) diff --git a/cmd/spiff-workflow/main.go b/cmd/spiff-workflow/main.go index 9a63df604..16cee2a10 100644 --- a/cmd/spiff-workflow/main.go +++ b/cmd/spiff-workflow/main.go @@ -240,6 +240,8 @@ func defaultSettings(generatedAccountInfo generator.GeneratedAccountInfo, derive defaultSettings.ProfilePicturesVisibility = settings.ProfilePicturesVisibilityEveryone defaultSettings.LinkPreviewRequestEnabled = true + defaultSettings.TestNetworksEnabled = false + visibleTokens := make(map[string][]string) visibleTokens["mainnet"] = []string{"SNT"} visibleTokensJSON, err := json.Marshal(visibleTokens) diff --git a/multiaccounts/settings/database.go b/multiaccounts/settings/database.go index 879288a76..4ba65dd05 100644 --- a/multiaccounts/settings/database.go +++ b/multiaccounts/settings/database.go @@ -146,10 +146,11 @@ INSERT INTO settings ( mnemonic_was_not_shown, wallet_token_preferences_group_by_community, wallet_collectible_preferences_group_by_collection, - wallet_collectible_preferences_group_by_community + wallet_collectible_preferences_group_by_community, + test_networks_enabled ) VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?,?,?, -?,?,?,?,?,?,?,?,?,'id',?,?,?,?,?,?,?,?,?)`, +?,?,?,?,?,?,?,?,?,'id',?,?,?,?,?,?,?,?,?,?)`, s.Address, s.Currency, s.CurrentNetwork, @@ -182,6 +183,7 @@ INSERT INTO settings ( s.TokenGroupByCommunity, s.CollectibleGroupByCollection, s.CollectibleGroupByCommunity, + s.TestNetworksEnabled, ) if err != nil { return err diff --git a/protocol/requests/create_account.go b/protocol/requests/create_account.go index b01ab399a..fa2fe5dfc 100644 --- a/protocol/requests/create_account.go +++ b/protocol/requests/create_account.go @@ -40,6 +40,8 @@ type CreateAccount struct { CurrentNetwork string `json:"currentNetwork"` NetworkID uint64 `json:"networkId"` + TestNetworksEnabled bool `json:"testNetworksEnabled"` + WalletSecretsConfig }