Skip to content

Commit

Permalink
[WIP] debug RPC call
Browse files Browse the repository at this point in the history
  • Loading branch information
FFFra committed Mar 11, 2024
1 parent fb1013c commit 31af697
Showing 1 changed file with 82 additions and 10 deletions.
92 changes: 82 additions & 10 deletions src/tests/contract_test/wallet_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
legacy.status-im.events
[legacy.status-im.multiaccounts.logout.core :as logout]
legacy.status-im.subs.root
[re-frame.core :as re-frame]
[re-frame.db :as rf-db]
[status-im.common.emoji-picker.utils :as emoji-picker.utils]
[status-im.constants :as constants]
[status-im.contexts.wallet.data-store :as data-store]
status-im.events
status-im.navigation.core
status-im.subs.root
[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]
[utils.security.core :as security]
))

(defn assert-accounts-get-accounts
[result]
Expand All @@ -34,6 +39,7 @@

(defn get-default-account
[accounts]
(println "DEFAULT ACCOUNT" accounts)
(first (filter :wallet accounts)))

(defn check-emoji-is-updated
Expand Down Expand Up @@ -85,22 +91,88 @@
(rf-test/wait-for
[::logout/logout-method])))))

(defn get-derived-account


;; (deftest wallet-create-derived-addresses-success
;; (h/log-headline :wallet/create-derived-addresses)
;; (rf-test/run-test-async
;; (h/with-app-initialized
;; (h/with-account
;; (contract-utils/call-rpc-endpoint
;; {:rpc-endpoint "wallet_getDerivedAddresses"
;; :params [(security/safe-unmask-data "some-password")
;; [:account :address]
;; ["m/44'/60'/0'/0/7"]]
;; :action get-derived-account})))))


;; (deftest wallet-create-derived-addresses-success
;; (h/log-headline :wallet/create-derived-addresses)
;; (rf-test/run-test-async
;; (h/with-app-initialized
;; (h/with-account
;; (let [sha3-pwd nil
;; derivation-path ["m/44'/60'/0'/0/0"]
;; address "0xf949b04e6fbb3668c8022ba37c0f5c0f5ff47a9e"
;; addresses (contract-utils/call-rpc-endpoint
;; {:rpc-endpoint "wallet_getDerivedAddresses"
;; :params [sha3-pwd address derivation-path]
;; :action get-derived-account})]
;; (println "PASSED" addresses))))))

(defn assert-derived-account
[response]
(is (= "0x1" (:sha3-pwd response)))
(is (= (security/safe-unmask-data "some-password") (:sha3-pwd response)))
(is (= "🍌" (:emoji response)))
(is (= :army (:color response)))
(is (= "m/44'/60'/0'/0/7" (:path response)))
(is (= "Test 3" (:account-name response))))
(is (= "Test 4" (:account-name response))))

(defn get-main-account
[accounts]
(println "ALL ACCOUNTS" accounts)
(println "MAIN ADDRESS" (:address (first accounts)))
(:address (first accounts)))

(deftype MaskedData [data]
Object
(toString [_] "******"))


(def test-password integration-constants/password)

(defn mask-data
[data]
(MaskedData. data))

(def masked-password (mask-data test-password))

(deftest wallet-create-derived-addresses-success
(h/log-headline :wallet/create-derived-addresses)
(rf-test/run-test-async
(h/with-app-initialized
(h/with-account
(contract-utils/call-rpc-endpoint
{:rpc-endpoint "wallet_getDerivedAccount"
:params ["0x1"
"some-account-address"
["m/44'/60'/0'/0/7"]]
:action get-derived-account})))))
(let [sha3-pwd (security/safe-unmask-data masked-password)
derivation-path ["m/43'/60'/1581'/0'/0"]
db-address (get-in @rf-db/app-db [:profile/profile :address])
derived (contract-utils/call-rpc-endpoint
{:rpc-endpoint "accounts_getAccounts"
:action get-main-account})
]

(println "PROFILE DB" (get-in @rf-db/app-db [:profile/profile :address]))
(println "RE-FRAME PROFILE SUBSCRIPTION" @(re-frame/subscribe [:profile/profile :address]))

(println "DERIVED" derived)

(println "CONSTANT MAIN ADDRESS" (:main-address integration-constants/recovery-account))
(println "PASSWORD" integration-constants/password)
(println "SHA3-PWD" sha3-pwd)

(contract-utils/call-rpc-endpoint
{:rpc-endpoint "wallet_getDerivedAddresses"
:params [sha3-pwd derived derivation-path]
:action assert-derived-account
:on-error (fn [error] (println "RPC Call Failed:" error))}))
(println "FINISHED")))))

0 comments on commit 31af697

Please sign in to comment.