From 31af697f2327e2258901bb256b5bd87080110c02 Mon Sep 17 00:00:00 2001 From: Flavio Fraschetti Date: Fri, 1 Mar 2024 14:56:32 +0000 Subject: [PATCH] [WIP] debug RPC call --- src/tests/contract_test/wallet_test.cljs | 92 +++++++++++++++++++++--- 1 file changed, 82 insertions(+), 10 deletions(-) diff --git a/src/tests/contract_test/wallet_test.cljs b/src/tests/contract_test/wallet_test.cljs index 93e62d0a04e5..94b2521b1491 100644 --- a/src/tests/contract_test/wallet_test.cljs +++ b/src/tests/contract_test/wallet_test.cljs @@ -5,6 +5,8 @@ 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] @@ -12,7 +14,10 @@ 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] @@ -34,6 +39,7 @@ (defn get-default-account [accounts] + (println "DEFAULT ACCOUNT" accounts) (first (filter :wallet accounts))) (defn check-emoji-is-updated @@ -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"))))) +