JC-Fraschetti/[Wallet] Add fixtures to recovered accounts and refactor wallet_getDerivedAddresses test (#19287)
* chore: fix contract test for wallet/create-derived-addresses and add asynchronous operations using Promesa library
This commit is contained in:
parent
3b5afb5d60
commit
01a881523f
|
@ -66,10 +66,18 @@
|
||||||
[]
|
[]
|
||||||
@(rf/subscribe [:messenger/started?]))
|
@(rf/subscribe [:messenger/started?]))
|
||||||
|
|
||||||
|
(defn wallet-loaded?
|
||||||
|
[]
|
||||||
|
(not @(rf/subscribe [:wallet/tokens-loading?])))
|
||||||
|
|
||||||
(defn assert-messenger-started
|
(defn assert-messenger-started
|
||||||
[]
|
[]
|
||||||
(is (messenger-started)))
|
(is (messenger-started)))
|
||||||
|
|
||||||
|
(defn assert-wallet-loaded
|
||||||
|
[]
|
||||||
|
(is (wallet-loaded?)))
|
||||||
|
|
||||||
(defn assert-community-created
|
(defn assert-community-created
|
||||||
[]
|
[]
|
||||||
(is (= @(rf/subscribe [:communities/create]) constants/community)))
|
(is (= @(rf/subscribe [:communities/create]) constants/community)))
|
||||||
|
@ -141,18 +149,49 @@
|
||||||
(test-utils/init!)
|
(test-utils/init!)
|
||||||
(if (app-initialized)
|
(if (app-initialized)
|
||||||
(p/resolved ::app-initialized)
|
(p/resolved ::app-initialized)
|
||||||
(do
|
(p/do!
|
||||||
(rf/dispatch [:app-started])
|
(rf/dispatch [:app-started])
|
||||||
(wait-for [:profile/get-profiles-overview-success]))))
|
(wait-for [:profile/get-profiles-overview-success]))))
|
||||||
|
|
||||||
(defn setup-account
|
(defn setup-account
|
||||||
[]
|
[]
|
||||||
(if (messenger-started)
|
(if (messenger-started)
|
||||||
(p/resolved ::messenger-started)
|
(p/resolved ::messenger-started)
|
||||||
(do
|
(p/do!
|
||||||
(create-multiaccount!)
|
(create-multiaccount!)
|
||||||
(-> (wait-for [:profile.login/messenger-started])
|
(p/then (wait-for [:profile.login/messenger-started]) #(assert-messenger-started)))))
|
||||||
(.then #(assert-messenger-started))))))
|
|
||||||
|
(defn- recover-and-login
|
||||||
|
[seed-phrase]
|
||||||
|
(rf/dispatch [:profile.recover/recover-and-login
|
||||||
|
{:display-name (:name constants/recovery-account)
|
||||||
|
:seed-phrase seed-phrase
|
||||||
|
:password constants/password
|
||||||
|
:color "blue"}]))
|
||||||
|
|
||||||
|
(defn- enable-testnet!
|
||||||
|
[]
|
||||||
|
(rf/dispatch [:profile.settings/profile-update :test-networks-enabled? true {}])
|
||||||
|
(rf/dispatch [:wallet/initialize]))
|
||||||
|
|
||||||
|
(defn- recover-multiaccount!
|
||||||
|
[]
|
||||||
|
(p/let [masked-seed-phrase (security/mask-data (:seed-phrase constants/recovery-account))
|
||||||
|
[mnemonic key-uid] (validate-mnemonic masked-seed-phrase)]
|
||||||
|
(rf/dispatch [:onboarding/seed-phrase-validated (security/mask-data mnemonic) key-uid])
|
||||||
|
(rf/dispatch [:pop-to-root :profiles])
|
||||||
|
(rf/dispatch [:profile/profile-selected key-uid])
|
||||||
|
(recover-and-login mnemonic)))
|
||||||
|
|
||||||
|
(defn setup-recovered-account
|
||||||
|
[]
|
||||||
|
(if (messenger-started)
|
||||||
|
(p/resolved ::messenger-started)
|
||||||
|
(p/do!
|
||||||
|
(recover-multiaccount!)
|
||||||
|
(p/then (wait-for [:profile.login/messenger-started]) #(assert-messenger-started))
|
||||||
|
(enable-testnet!)
|
||||||
|
(p/then (wait-for [:wallet/store-wallet-token]) #(assert-wallet-loaded)))))
|
||||||
|
|
||||||
(defn test-async
|
(defn test-async
|
||||||
"Runs `f` inside `cljs.test/async` macro in a restorable re-frame checkpoint.
|
"Runs `f` inside `cljs.test/async` macro in a restorable re-frame checkpoint.
|
||||||
|
@ -228,17 +267,24 @@
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
(use-fixtures :each (h/fixture-logged))"
|
(use-fixtures :each (h/fixture-logged))"
|
||||||
[]
|
([type]
|
||||||
{:before (fn []
|
{:before (if (= :recovered-account type)
|
||||||
(test/async done
|
(fn []
|
||||||
(p/do (setup-app)
|
(test/async done
|
||||||
(setup-account)
|
(p/do (setup-app)
|
||||||
(done))))
|
(setup-recovered-account)
|
||||||
:after (fn []
|
(done))))
|
||||||
(test/async done
|
(fn []
|
||||||
(p/do (logout)
|
(test/async done
|
||||||
(wait-for [::logout/logout-method])
|
(p/do (setup-app)
|
||||||
(done))))})
|
(setup-account)
|
||||||
|
(done)))))
|
||||||
|
:after (fn []
|
||||||
|
(test/async done
|
||||||
|
(p/do (logout)
|
||||||
|
(wait-for [::logout/logout-method])
|
||||||
|
(done))))})
|
||||||
|
([] (fixture-session [:new-account])))
|
||||||
|
|
||||||
(defn fixture-silence-reframe
|
(defn fixture-silence-reframe
|
||||||
"Fixture to disable most re-frame messages.
|
"Fixture to disable most re-frame messages.
|
||||||
|
@ -260,25 +306,3 @@
|
||||||
(set! rf.interop/debug-enabled? false))
|
(set! rf.interop/debug-enabled? false))
|
||||||
:after (fn []
|
:after (fn []
|
||||||
(set! rf.interop/debug-enabled? true))})
|
(set! rf.interop/debug-enabled? true))})
|
||||||
|
|
||||||
(defn recover-and-login
|
|
||||||
[seed-phrase]
|
|
||||||
(rf/dispatch [:profile.recover/recover-and-login
|
|
||||||
{:display-name (:name constants/recovery-account)
|
|
||||||
:seed-phrase seed-phrase
|
|
||||||
:password constants/password
|
|
||||||
:color "blue"}]))
|
|
||||||
|
|
||||||
(defn enable-testnet!
|
|
||||||
[]
|
|
||||||
(rf/dispatch [:profile.settings/profile-update :test-networks-enabled? true {}])
|
|
||||||
(rf/dispatch [:wallet/initialize]))
|
|
||||||
|
|
||||||
(defn recover-multiaccount!
|
|
||||||
[]
|
|
||||||
(p/let [masked-seed-phrase (security/mask-data (:seed-phrase constants/recovery-account))
|
|
||||||
[mnemonic key-uid] (validate-mnemonic masked-seed-phrase)]
|
|
||||||
(rf/dispatch [:onboarding/seed-phrase-validated (security/mask-data mnemonic) key-uid])
|
|
||||||
(rf/dispatch [:pop-to-root :profiles])
|
|
||||||
(rf/dispatch [:profile/profile-selected key-uid])
|
|
||||||
(recover-and-login mnemonic)))
|
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
(ns tests.contract-test.wallet-recovered-account-test
|
||||||
|
(:require
|
||||||
|
[cljs.test :refer [deftest is use-fixtures]]
|
||||||
|
legacy.status-im.events
|
||||||
|
legacy.status-im.subs.root
|
||||||
|
[native-module.core :as native-module]
|
||||||
|
[promesa.core :as p]
|
||||||
|
status-im.events
|
||||||
|
status-im.navigation.core
|
||||||
|
status-im.subs.root
|
||||||
|
[test-helpers.integration :as h]
|
||||||
|
[tests.contract-test.utils :as contract-utils]
|
||||||
|
[tests.integration-test.constants :as integration-constants]))
|
||||||
|
|
||||||
|
(use-fixtures :each (h/fixture-session :recovered-account))
|
||||||
|
|
||||||
|
(defn get-main-account
|
||||||
|
[accounts]
|
||||||
|
(:address (first accounts)))
|
||||||
|
|
||||||
|
(defn assert-derived-account
|
||||||
|
[response]
|
||||||
|
(let [{:keys [address public-key]} (first response)]
|
||||||
|
(is (= integration-constants/derived-address address))
|
||||||
|
(is (= (:public-key integration-constants/recovery-account) public-key))
|
||||||
|
(is (= integration-constants/derivation-path (:path (first response))))))
|
||||||
|
|
||||||
|
(deftest wallet-get-derived-addressess-contract-test
|
||||||
|
(h/test-async :wallet/create-derived-addresses
|
||||||
|
(fn []
|
||||||
|
(p/let [sha3-pwd (native-module/sha3 integration-constants/password)
|
||||||
|
derivation-path [integration-constants/derivation-path]
|
||||||
|
accounts (contract-utils/call-rpc "accounts_getAccounts")
|
||||||
|
main-account (get-main-account accounts)
|
||||||
|
response (contract-utils/call-rpc
|
||||||
|
"wallet_getDerivedAddresses"
|
||||||
|
sha3-pwd
|
||||||
|
main-account
|
||||||
|
derivation-path)]
|
||||||
|
(assert-derived-account response)))))
|
|
@ -3,7 +3,6 @@
|
||||||
[cljs.test :refer [deftest is use-fixtures]]
|
[cljs.test :refer [deftest is use-fixtures]]
|
||||||
legacy.status-im.events
|
legacy.status-im.events
|
||||||
legacy.status-im.subs.root
|
legacy.status-im.subs.root
|
||||||
[native-module.core :as native-module]
|
|
||||||
[promesa.core :as p]
|
[promesa.core :as p]
|
||||||
[status-im.common.emoji-picker.utils :as emoji-picker.utils]
|
[status-im.common.emoji-picker.utils :as emoji-picker.utils]
|
||||||
[status-im.constants :as constants]
|
[status-im.constants :as constants]
|
||||||
|
@ -12,8 +11,7 @@
|
||||||
status-im.navigation.core
|
status-im.navigation.core
|
||||||
status-im.subs.root
|
status-im.subs.root
|
||||||
[test-helpers.integration :as h]
|
[test-helpers.integration :as h]
|
||||||
[tests.contract-test.utils :as contract-utils]
|
[tests.contract-test.utils :as contract-utils]))
|
||||||
[tests.integration-test.constants :as integration-constants]))
|
|
||||||
|
|
||||||
(use-fixtures :each (h/fixture-session))
|
(use-fixtures :each (h/fixture-session))
|
||||||
|
|
||||||
|
@ -67,31 +65,3 @@
|
||||||
(fn []
|
(fn []
|
||||||
(p/let [response (contract-utils/call-rpc "wallet_getEthereumChains")]
|
(p/let [response (contract-utils/call-rpc "wallet_getEthereumChains")]
|
||||||
(assert-ethereum-chains response)))))
|
(assert-ethereum-chains response)))))
|
||||||
|
|
||||||
(defn get-main-account
|
|
||||||
[accounts]
|
|
||||||
(:address (first accounts)))
|
|
||||||
|
|
||||||
(def test-password integration-constants/password)
|
|
||||||
|
|
||||||
(defn assert-derived-account
|
|
||||||
[response]
|
|
||||||
(is (= (:address response) (:address response)))
|
|
||||||
(is (= (:public-key response) (:public-key response)))
|
|
||||||
(is (= "m/43'/60'/1581'/0'/0" (:path (first response)))))
|
|
||||||
|
|
||||||
(deftest wallet-get-derived-addressess-contract-test
|
|
||||||
(h/test-async :wallet/create-derived-addresses
|
|
||||||
(fn []
|
|
||||||
(p/let [_ (h/enable-testnet!)
|
|
||||||
_ (h/recover-multiaccount!)
|
|
||||||
sha3-pwd (native-module/sha3 test-password)
|
|
||||||
derivation-path ["m/43'/60'/1581'/0'/0"]
|
|
||||||
accounts (contract-utils/call-rpc "accounts_getAccounts")
|
|
||||||
main-account (get-main-account accounts)
|
|
||||||
response (contract-utils/call-rpc
|
|
||||||
"wallet_getDerivedAddresses"
|
|
||||||
sha3-pwd
|
|
||||||
main-account
|
|
||||||
derivation-path)]
|
|
||||||
(assert-derived-account response)))))
|
|
||||||
|
|
|
@ -6,9 +6,13 @@
|
||||||
|
|
||||||
(def account-name "account-abc")
|
(def account-name "account-abc")
|
||||||
|
|
||||||
|
(def derivation-path "m/43'/60'/1581'/0'/0")
|
||||||
|
|
||||||
|
(def derived-address "0x542bf2d18e83ba176c151c949c53eee896fa5a3e")
|
||||||
|
|
||||||
(def recovery-account
|
(def recovery-account
|
||||||
{:name "wallet-abc"
|
{:name "wallet-abc"
|
||||||
:seed-phrase "destroy end torch puzzle develop note wise island disease chaos kind bus"
|
:seed-phrase "destroy end torch puzzle develop note wise island disease chaos kind bus"
|
||||||
:key-uid "0x6827f3d1e21ae723a24e0dcbac1853b5ed4d651c821a2326492ce8f2367ec905"
|
:key-uid "0x6827f3d1e21ae723a24e0dcbac1853b5ed4d651c821a2326492ce8f2367ec905"
|
||||||
:public-key "0x48b8b9e2a8f71e1beae729d83bcd385ffc6af0d5"
|
:public-key
|
||||||
:main-account "0x48b8b9e2a8f71e1beae729d83bcd385ffc6af0d5"})
|
"0x04937b2d8ed320f89a437e3c854213ec56b34c0c5a5a6105fd6f0850574d10af6988f128b4e2b7b7171f4599deda75584c7c75f7cdf0846f8d485a7f593a5f31f6"})
|
||||||
|
|
Loading…
Reference in New Issue