Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#13804] Extend integration tests to back up seed phrase #13853

Merged
merged 1 commit into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 54 additions & 11 deletions src/status_im/integration_test.cljs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
(ns status-im.integration-test
(:require [cljs.test :refer [deftest is run-tests]]
[day8.re-frame.test :as rf-test]
[clojure.string :as string]
[re-frame.core :as rf]
status-im.events
[status-im.multiaccounts.logout.core :as logout]
[status-im.transport.core :as transport]
status-im.subs ;;so integration tests can run independently
[status-im.ethereum.core :as ethereum]
[status-im.utils.test :as utils.test]))
[status-im.utils.test :as utils.test]
[taoensso.timbre :as log]))

(def password "testabc")

Expand All @@ -18,7 +20,7 @@
(utils.test/init!)

(defn initialize-app! []
(rf/dispatch-sync [:init/app-started]))
(rf/dispatch [:init/app-started]))

(defn generate-and-derive-addresses! []
(rf/dispatch [:generate-and-derive-addresses]))
Expand Down Expand Up @@ -46,11 +48,6 @@
(defn assert-messenger-started []
(is (messenger-started)))

(deftest initialize-app-test
(rf-test/run-test-sync
(rf/dispatch [:init/app-started])
(assert-app-initialized)))

(defn assert-multiaccount-loaded []
(is (false? @(rf/subscribe [:multiaccounts/loading]))))

Expand All @@ -69,11 +66,22 @@
(defn logout! []
(rf/dispatch [:logout]))

(deftest initialize-app-test
(log/info "========= initialize-app-test ==================")
(rf-test/run-test-async
(rf/dispatch [:init/app-started])
(rf-test/wait-for
;; use initialize-view because it has the longest avg. time and
;; is dispatched by initialize-multiaccounts (last non-view event)
[:status-im.init.core/initialize-view]
(assert-app-initialized))))

(deftest create-account-test
(log/info "====== create-account-test ==================")
(rf-test/run-test-async
(initialize-app!) ; initialize app
(rf-test/wait-for
[:status-im.init.core/initialize-multiaccounts] ; wait so we load accounts.db
[:status-im.init.core/initialize-view]
(generate-and-derive-addresses!) ; generate 5 new keys
(rf-test/wait-for
[:multiaccount-generate-and-derive-addresses-success] ; wait for the keys
Expand All @@ -87,10 +95,11 @@
(assert-logout)))))))

(deftest create-community-test
(log/info "====== create-community-test ==================")
(rf-test/run-test-async
(initialize-app!) ; initialize app
(rf-test/wait-for
[:status-im.init.core/initialize-multiaccounts]
[:status-im.init.core/initialize-view]
(generate-and-derive-addresses!) ; generate 5 new keys
(rf-test/wait-for
[:multiaccount-generate-and-derive-addresses-success]
Expand All @@ -111,10 +120,11 @@
(assert-logout))))))))

(deftest create-wallet-account-test
(log/info "====== create-wallet-account-test ==================")
(rf-test/run-test-async
(initialize-app!) ; initialize app
(initialize-app!)
(rf-test/wait-for
[:status-im.init.core/initialize-multiaccounts]
[:status-im.init.core/initialize-view]
(generate-and-derive-addresses!) ; generate 5 new keys
(rf-test/wait-for
[:multiaccount-generate-and-derive-addresses-success]
Expand All @@ -131,5 +141,38 @@
(rf-test/wait-for [::logout/logout-method] ; we need to logout to make sure the node is not in an inconsistent state between tests
(assert-logout))))))))

(deftest back-up-seed-phrase-test
(log/info "========= back-up-seed-phrase-test ==================")
(rf-test/run-test-async
(initialize-app!)
(rf-test/wait-for
[:status-im.init.core/initialize-view]
(generate-and-derive-addresses!)
(rf-test/wait-for
[:multiaccount-generate-and-derive-addresses-success]
(assert-multiaccount-loaded)
(create-multiaccount!)
(rf-test/wait-for
[::transport/messenger-started]
(assert-messenger-started)
(rf/dispatch-sync [:set-in [:my-profile/seed :step] :12-words]) ; display seed phrase to user
(rf/dispatch-sync [:my-profile/enter-two-random-words]) ; begin prompting user for seed words
(let [ma @(rf/subscribe [:multiaccount])
seed @(rf/subscribe [:my-profile/seed])
word1 (second (:first-word seed))
word2 (second (:second-word seed))]
(is (= 12 (count (string/split (:mnemonic ma) #" ")))) ; assert 12-word seed phrase
(rf/dispatch-sync [:set-in [:my-profile/seed :word] word1])
(rf/dispatch-sync [:my-profile/set-step :second-word])
(rf/dispatch-sync [:set-in [:my-profile/seed :word] word2])
;; TODO: refactor (defn next-handler) & (defn enter-word) to improve test coverage?
(rf/dispatch [:my-profile/finish])
(rf-test/wait-for
[:my-profile/finish-success]
(is (nil? @(rf/subscribe [:mnemonic]))) ; assert seed phrase has been removed
(logout!)
(rf-test/wait-for [::logout/logout-method] ; we need to logout to make sure the node is not in an inconsistent state between tests
(assert-logout)))))))))

(comment
(run-tests))
6 changes: 2 additions & 4 deletions src/status_im/multiaccounts/update/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@

(fx/defn clean-seed-phrase
"A helper function that removes seed phrase from storage."
[cofx]
(multiaccount-update cofx
:mnemonic nil
{}))
[cofx on-success]
(multiaccount-update cofx :mnemonic nil on-success))

(defn augment-synchronized-recent-stickers
"Add 'url' parameter to stickers that are synchronized from other devices.
Expand Down
3 changes: 2 additions & 1 deletion src/status_im/multiaccounts/update/core_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
(is (= (get-in efx [:db :multiaccount]) {:not-empty "would throw an error if was empty"}))))

(deftest test-clean-seed-phrase
(let [efx (multiaccounts.update/clean-seed-phrase {:db {:multiaccount {:mnemonic "lalalala"}}})
(let [efx (multiaccounts.update/clean-seed-phrase
{:db {:multiaccount {:mnemonic "lalalala"}}} {})
json-rpc (into #{} (map :method (::json-rpc/call efx)))]
(is (json-rpc "settings_saveSetting"))
(is (nil? (get-in efx [:db :multiaccount :mnemonic])))))
13 changes: 9 additions & 4 deletions src/status_im/profile/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,17 @@
(let [link (universal-links/generate-link :user :external contact-code)]
(list-selection/open-share {:message link}))))

(fx/defn finish-success
{:events [:my-profile/finish-success]}
[{:keys [db] :as cofx}]
{:db (update db :my-profile/seed assoc :step :finish :error nil :word nil)})

(fx/defn finish
{:events [:my-profile/finish]}
[{:keys [db] :as cofx}]
(fx/merge cofx
{:db (update db :my-profile/seed assoc :step :finish :error nil :word nil)}
(multiaccounts.update/clean-seed-phrase)))
[cofx]
(multiaccounts.update/clean-seed-phrase
cofx
{:on-success #(re-frame/dispatch [:my-profile/finish-success])}))

(fx/defn enter-two-random-words
{:events [:my-profile/enter-two-random-words]}
Expand Down