Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fraschetti - Add tests for wallet_getWalletToken #19210

8 changes: 8 additions & 0 deletions src/tests/contract_test/utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@
:params args
:on-success p-resolve
:on-error p-reject}))))

(defn get-default-account
[accounts]
(first (filter :wallet accounts)))

(defn get-default-address
[accounts]
(:address (get-default-account accounts)))
12 changes: 4 additions & 8 deletions src/tests/contract_test/wallet_recovered_account_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@

(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)]
Expand All @@ -28,13 +24,13 @@
(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)
(p/let [sha3-pwd-hash (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)
default-address (contract-utils/get-default-address accounts)
response (contract-utils/call-rpc
"wallet_getDerivedAddresses"
sha3-pwd
main-account
sha3-pwd-hash
default-address
derivation-path)]
(assert-derived-account response)))))
38 changes: 30 additions & 8 deletions src/tests/contract_test/wallet_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

(use-fixtures :each (h/fixture-session))

(def number-of-networks 3)

(defn assert-accounts-get-accounts
[result]
(is (true? (some :wallet result)))
Expand All @@ -27,29 +29,23 @@
(p/let [result (contract-utils/call-rpc "accounts_getAccounts")]
(assert-accounts-get-accounts result)))))

(defn get-default-account
[accounts]
(first (filter :wallet accounts)))

(defn check-emoji-is-updated
[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))))

(deftest accounts-save-accounts-contract
(h/test-async :contract/accounts-save-account
(fn []
(p/let [test-emoji (emoji-picker.utils/random-emoji)
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
"accounts_saveAccount"
(data-store/<-account (merge default-account {:emoji test-emoji})))
accounts (contract-utils/call-rpc "accounts_getAccounts")]
(check-emoji-is-updated test-emoji accounts)))))

(def number-of-networks 3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo this is better defined in the test file. Do really need this defined as a global constant? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yah, I can roll back because this might change in future tests


(defn assert-ethereum-chains
[response]
(is (= number-of-networks (count response)))
Expand All @@ -65,3 +61,29 @@
(fn []
(p/let [response (contract-utils/call-rpc "wallet_getEthereumChains")]
(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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simple one up the top of my mind:

Suggested change
(is (contains? token :balancesPerChain))
(is (contains? token :balancesPerChain))
(is (contains? token :marketValuesPerCurrency))
(is (contains? (:marketValuesPerCurrency token) :usd))

Copy link
Contributor Author

@FFFra FFFra Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why :marketValuesPerCurrency is important to the tests? (not against include it, just curious)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. It's just that we calculate the fiat balance in the client app (Mobile/Desktop) using the market values we get from status-go. Users love to see the fiat balance for the tokens they are holding. We don't want to disappoint the users 😄 .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense. Thank you! I;'ve included

(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))))))))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cc @smohamedjavid looks good here in the assertion? ^^

(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)))))
4 changes: 2 additions & 2 deletions src/tests/integration_test/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

(def derivation-path "m/43'/60'/1581'/0'/0")

(def derived-address "0x542bf2d18e83ba176c151c949c53eee896fa5a3e")
(def derived-address "0x64829fa755b9fda0c7ece27434970807aecc8c79")

(def recovery-account
{:name "wallet-abc"
:seed-phrase "destroy end torch puzzle develop note wise island disease chaos kind bus"
:key-uid "0x6827f3d1e21ae723a24e0dcbac1853b5ed4d651c821a2326492ce8f2367ec905"
:public-key
"0x04937b2d8ed320f89a437e3c854213ec56b34c0c5a5a6105fd6f0850574d10af6988f128b4e2b7b7171f4599deda75584c7c75f7cdf0846f8d485a7f593a5f31f6"})
"0x04ca1446090fa458f42a54307fb191daf132d295bd364a691a5434e1b5717e4cf3116e66b1f5188dd18f1b74fe70fe77cff02e5d6c279f3834f47176563393be1c"})