Fraschetti - Add tests for wallet_getWalletToken (#19210)

- Add tests for wallet_getWalletToken 
- Remove get-main-account 
- Add get-default-address function
- Adapt constants/fixtures for recovered account
This commit is contained in:
Flavio Fraschetti 2024-03-21 09:29:12 -03:00 committed by GitHub
parent 6d74d0396e
commit 90913500b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 44 additions and 18 deletions

View File

@ -12,3 +12,11 @@
:params args :params args
:on-success p-resolve :on-success p-resolve
:on-error p-reject})))) :on-error p-reject}))))
(defn get-default-account
[accounts]
(first (filter :wallet accounts)))
(defn get-default-address
[accounts]
(:address (get-default-account accounts)))

View File

@ -14,10 +14,6 @@
(use-fixtures :each (h/fixture-session :recovered-account)) (use-fixtures :each (h/fixture-session :recovered-account))
(defn get-main-account
[accounts]
(:address (first accounts)))
(defn assert-derived-account (defn assert-derived-account
[response] [response]
(let [{:keys [address public-key]} (first response)] (let [{:keys [address public-key]} (first response)]
@ -28,13 +24,13 @@
(deftest wallet-get-derived-addressess-contract-test (deftest wallet-get-derived-addressess-contract-test
(h/test-async :wallet/create-derived-addresses (h/test-async :wallet/create-derived-addresses
(fn [] (fn []
(p/let [sha3-pwd (native-module/sha3 integration-constants/password) (p/let [sha3-pwd-hash (native-module/sha3 integration-constants/password)
derivation-path [integration-constants/derivation-path] derivation-path [integration-constants/derivation-path]
accounts (contract-utils/call-rpc "accounts_getAccounts") accounts (contract-utils/call-rpc "accounts_getAccounts")
main-account (get-main-account accounts) default-address (contract-utils/get-default-address accounts)
response (contract-utils/call-rpc response (contract-utils/call-rpc
"wallet_getDerivedAddresses" "wallet_getDerivedAddresses"
sha3-pwd sha3-pwd-hash
main-account default-address
derivation-path)] derivation-path)]
(assert-derived-account response))))) (assert-derived-account response)))))

View File

@ -15,6 +15,8 @@
(use-fixtures :each (h/fixture-session)) (use-fixtures :each (h/fixture-session))
(def number-of-networks 3)
(defn assert-accounts-get-accounts (defn assert-accounts-get-accounts
[result] [result]
(is (true? (some :wallet result))) (is (true? (some :wallet result)))
@ -27,13 +29,9 @@
(p/let [result (contract-utils/call-rpc "accounts_getAccounts")] (p/let [result (contract-utils/call-rpc "accounts_getAccounts")]
(assert-accounts-get-accounts result))))) (assert-accounts-get-accounts result)))))
(defn get-default-account
[accounts]
(first (filter :wallet accounts)))
(defn check-emoji-is-updated (defn check-emoji-is-updated
[test-emoji accounts] [test-emoji accounts]
(let [default-account (get-default-account accounts)] (let [default-account (contract-utils/get-default-account accounts)]
(is (= (:emoji default-account) test-emoji)))) (is (= (:emoji default-account) test-emoji))))
(deftest accounts-save-accounts-contract (deftest accounts-save-accounts-contract
@ -41,15 +39,13 @@
(fn [] (fn []
(p/let [test-emoji (emoji-picker.utils/random-emoji) (p/let [test-emoji (emoji-picker.utils/random-emoji)
account (contract-utils/call-rpc "accounts_getAccounts") account (contract-utils/call-rpc "accounts_getAccounts")
default-account (get-default-account account) default-account (contract-utils/get-default-account account)
_ (contract-utils/call-rpc _ (contract-utils/call-rpc
"accounts_saveAccount" "accounts_saveAccount"
(data-store/<-account (merge default-account {:emoji test-emoji}))) (data-store/<-account (merge default-account {:emoji test-emoji})))
accounts (contract-utils/call-rpc "accounts_getAccounts")] accounts (contract-utils/call-rpc "accounts_getAccounts")]
(check-emoji-is-updated test-emoji accounts))))) (check-emoji-is-updated test-emoji accounts)))))
(def number-of-networks 3)
(defn assert-ethereum-chains (defn assert-ethereum-chains
[response] [response]
(is (= number-of-networks (count response))) (is (= number-of-networks (count response)))
@ -65,3 +61,29 @@
(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 assert-wallet-tokens
[tokens]
(let [flattened-tokens (mapcat val tokens)]
(doseq [token flattened-tokens]
(is (not-empty (:symbol token)))
(is (:decimals token))
(is (contains? token :balancesPerChain))
(is (contains? token :marketValuesPerCurrency))
(is (contains? (:marketValuesPerCurrency token) :usd))
(let [balances-per-chain (:balancesPerChain token)]
(doseq [[_ balance] balances-per-chain]
(is (contains? balance :rawBalance))
(let [raw-balance (:rawBalance balance)]
(is (not-empty raw-balance))
(is (re-matches #"\d+" raw-balance))))))))
(deftest wallet-get-walet-token-test
(h/test-async :wallet/get-wallet-token
(fn []
(p/let [accounts (contract-utils/call-rpc "accounts_getAccounts")
default-address (contract-utils/get-default-address accounts)
response (contract-utils/call-rpc
"wallet_getWalletToken"
[default-address])]
(assert-wallet-tokens response)))))

View File

@ -8,11 +8,11 @@
(def derivation-path "m/43'/60'/1581'/0'/0") (def derivation-path "m/43'/60'/1581'/0'/0")
(def derived-address "0x542bf2d18e83ba176c151c949c53eee896fa5a3e") (def derived-address "0x64829fa755b9fda0c7ece27434970807aecc8c79")
(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 :public-key
"0x04937b2d8ed320f89a437e3c854213ec56b34c0c5a5a6105fd6f0850574d10af6988f128b4e2b7b7171f4599deda75584c7c75f7cdf0846f8d485a7f593a5f31f6"}) "0x04ca1446090fa458f42a54307fb191daf132d295bd364a691a5434e1b5717e4cf3116e66b1f5188dd18f1b74fe70fe77cff02e5d6c279f3834f47176563393be1c"})