Extend integration tests to back up seed phrase (#13804)

This commit is contained in:
Erik Seppanen 2022-08-24 16:40:48 -04:00
parent 05219bd721
commit 45e47ad3d9
No known key found for this signature in database
GPG Key ID: E466704B2D98E17D
4 changed files with 67 additions and 20 deletions

View File

@ -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")
@ -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]))
@ -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]))))
@ -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
@ -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]
@ -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]
@ -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))

View File

@ -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.

View File

@ -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])))))

View File

@ -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]}