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

Conversation

FFFra
Copy link
Contributor

@FFFra FFFra commented Mar 12, 2024

fixes #18342
follows #19208

Summary
This pull request introduces comprehensive tests for the wallet_getWalletToken endpoint, ensuring its robustness and reliability in our wallet functionality.

Steps to test
run make test-contracts

status: ready!

@FFFra FFFra self-assigned this Mar 12, 2024
@FFFra FFFra linked an issue Mar 12, 2024 that may be closed by this pull request
@FFFra FFFra requested a review from J-Son89 March 12, 2024 16:40
@FFFra FFFra requested a review from ilmotta March 12, 2024 16:40
@status-im-auto
Copy link
Member

status-im-auto commented Mar 12, 2024

Jenkins Builds

Click to see older builds (49)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ bb95d7f #1 2024-03-12 16:47:23 ~6 min android 🤖apk 📲
✔️ bb95d7f #1 2024-03-12 16:47:55 ~7 min android-e2e 🤖apk 📲
✔️ bb95d7f #1 2024-03-12 16:49:03 ~8 min ios 📱ipa 📲
f82da8d #2 2024-03-13 09:30:39 ~7 min ios 📄log
✔️ f82da8d #2 2024-03-13 09:30:44 ~8 min android-e2e 🤖apk 📲
✔️ f82da8d #2 2024-03-13 09:30:46 ~8 min android 🤖apk 📲
✔️ 1e174a8 #3 2024-03-13 11:36:51 ~7 min ios 📱ipa 📲
✔️ 1e174a8 #3 2024-03-13 11:37:01 ~7 min android-e2e 🤖apk 📲
✔️ 1e174a8 #3 2024-03-13 11:37:07 ~7 min android 🤖apk 📲
✔️ 36748c8 #4 2024-03-13 12:00:48 ~6 min tests 📄log
✔️ 36748c8 #4 2024-03-13 12:02:21 ~7 min android-e2e 🤖apk 📲
✔️ 36748c8 #4 2024-03-13 12:02:48 ~8 min android 🤖apk 📲
✔️ 36748c8 #4 2024-03-13 12:02:54 ~8 min ios 📱ipa 📲
✔️ 2a2cd01 #5 2024-03-13 15:15:34 ~7 min android 🤖apk 📲
✔️ 2a2cd01 #5 2024-03-13 15:15:34 ~7 min android-e2e 🤖apk 📲
✔️ 2a2cd01 #5 2024-03-13 15:16:49 ~8 min ios 📱ipa 📲
✔️ b04605b #6 2024-03-13 15:34:30 ~6 min android 🤖apk 📲
✔️ b04605b #6 2024-03-13 15:36:09 ~8 min android-e2e 🤖apk 📲
✔️ b04605b #6 2024-03-13 15:36:17 ~8 min ios 📱ipa 📲
✔️ 09d30bf #7 2024-03-15 13:26:21 ~7 min android-e2e 🤖apk 📲
✔️ 09d30bf #7 2024-03-15 13:26:39 ~7 min android 🤖apk 📲
✔️ 09d30bf #7 2024-03-15 13:26:52 ~7 min ios 📱ipa 📲
✔️ 6e69aad #8 2024-03-19 10:55:15 ~7 min android 🤖apk 📲
✔️ 6e69aad #8 2024-03-19 10:55:25 ~7 min android-e2e 🤖apk 📲
✔️ 6e69aad #8 2024-03-19 10:57:32 ~9 min ios 📱ipa 📲
✔️ 7da7788 #9 2024-03-19 11:10:35 ~7 min android 🤖apk 📲
✔️ 7da7788 #9 2024-03-19 11:11:17 ~7 min android-e2e 🤖apk 📲
✔️ 7da7788 #9 2024-03-19 11:14:28 ~11 min ios 📱ipa 📲
✔️ 0c3f6f2 #10 2024-03-19 14:03:00 ~6 min tests 📄log
✔️ 0c3f6f2 #10 2024-03-19 14:03:27 ~6 min android-e2e 🤖apk 📲
✔️ 0c3f6f2 #10 2024-03-19 14:03:35 ~6 min android 🤖apk 📲
✔️ 0c3f6f2 #10 2024-03-19 14:05:28 ~8 min ios 📱ipa 📲
✔️ 265fd03 #11 2024-03-19 14:17:34 ~7 min android-e2e 🤖apk 📲
✔️ 265fd03 #11 2024-03-19 14:18:14 ~8 min tests 📄log
✔️ 265fd03 #11 2024-03-19 14:18:49 ~9 min android 🤖apk 📲
✔️ 265fd03 #11 2024-03-19 14:29:52 ~20 min ios 📱ipa 📲
✔️ 8f83a97 #12 2024-03-19 14:41:59 ~7 min android-e2e 🤖apk 📲
✔️ 8f83a97 #12 2024-03-19 14:42:07 ~7 min android 🤖apk 📲
✔️ 8f83a97 #12 2024-03-19 14:44:05 ~9 min ios 📱ipa 📲
✔️ 793c3a5 #13 2024-03-19 15:07:41 ~6 min android 🤖apk 📲
✔️ 793c3a5 #13 2024-03-19 15:07:46 ~7 min android-e2e 🤖apk 📲
✔️ 793c3a5 #13 2024-03-19 15:09:37 ~8 min ios 📱ipa 📲
✔️ c29fe89 #14 2024-03-20 16:33:21 ~6 min tests 📄log
✔️ c29fe89 #14 2024-03-20 16:33:58 ~7 min android-e2e 🤖apk 📲
✔️ c29fe89 #14 2024-03-20 16:34:01 ~7 min android 🤖apk 📲
✔️ c29fe89 #14 2024-03-20 16:47:10 ~20 min ios 📱ipa 📲
✔️ 9bf0fca #15 2024-03-20 17:44:37 ~8 min android 🤖apk 📲
✔️ 9bf0fca #15 2024-03-20 17:47:54 ~12 min android-e2e 🤖apk 📲
✔️ 9bf0fca #15 2024-03-20 18:06:46 ~30 min ios 📱ipa 📲
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 4d19720 #16 2024-03-21 12:02:04 ~7 min android-e2e 🤖apk 📲
✔️ 4d19720 #16 2024-03-21 12:02:12 ~7 min android 🤖apk 📲
✔️ 4d19720 #16 2024-03-21 12:04:25 ~9 min ios 📱ipa 📲
✔️ 595acaa #17 2024-03-21 12:22:46 ~6 min tests 📄log
✔️ 595acaa #17 2024-03-21 12:22:50 ~6 min android 🤖apk 📲
✔️ 595acaa #17 2024-03-21 12:23:40 ~7 min android-e2e 🤖apk 📲
✔️ 595acaa #17 2024-03-21 12:25:52 ~9 min ios 📱ipa 📲

(defn assert-wallet-tokens
[tokens]
(let [flattened-tokens (mapcat val tokens)]
(is (true? (some #(= (:symbol %) "SNT") flattened-tokens)))
Copy link
Contributor

Choose a reason for hiding this comment

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

The true? call is unnecessary because some will return a boolean already.

@FFFra FFFra force-pushed the 18342-wallet-add-integration-test-for-rpc-endpoint-wallet_getwallettoken branch from bb95d7f to f82da8d Compare March 13, 2024 09:22
@FFFra FFFra force-pushed the 18342-wallet-add-integration-test-for-rpc-endpoint-wallet_getwallettoken branch 2 times, most recently from 1e174a8 to 36748c8 Compare March 13, 2024 11:54
@ilmotta
Copy link
Contributor

ilmotta commented Mar 13, 2024

@FFFra: Just a heads up that I have merged PR #19208. You'll need to adapt the contract test to use the new and now only available API built on top of promises and without macros and no dependency on day8.re-frame/test. Let me know if you need any help with adapting the test.

@FFFra
Copy link
Contributor Author

FFFra commented Mar 13, 2024

@FFFra: Just a heads up that I have merged PR #19208. You'll need to adapt the contract test to use the new and now only available API built on top of promises and without macros and no dependency on day8.re-frame/test. Let me know if you need any help with adapting the test.

Thank you, I will take a look!

@FFFra FFFra force-pushed the 18342-wallet-add-integration-test-for-rpc-endpoint-wallet_getwallettoken branch from 36748c8 to 2a2cd01 Compare March 13, 2024 15:07
@FFFra FFFra requested a review from ilmotta March 13, 2024 15:08
(defn assert-wallet-tokens
[tokens]
(let [flattened-tokens (mapcat val tokens)]
(is (some #(= (:symbol %) "SNT") flattened-tokens))
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder is there anything else of importance to check in the tokens that we are dependent on.
i.e that there is some particular keys that we need

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 had the same feeling and now refactoring was also thinking about it. Maybe we just check if the tokens have been returned? Something like "response is not empty"
Opened to opinions

Copy link
Contributor

@J-Son89 J-Son89 Mar 13, 2024

Choose a reason for hiding this comment

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

oh no, I think being vague is less helpful. checking that symbol exists is a good thing, because that is part of the contract we are dependent on.
The best thing to do here would be too look at how we are using this rpc request and then check what parts of the data we need, then we know what we need to check in these contracts so that Status Go avoids making breaking changes (that will affect mobile) for this endpoint 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ilmotta any toughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nothing to add really to Jamie's comment above. I think that's a good description of the goal of all contract tests.

@FFFra FFFra force-pushed the 18342-wallet-add-integration-test-for-rpc-endpoint-wallet_getwallettoken branch from 2a2cd01 to b04605b Compare March 13, 2024 15:27
main-account (get-main-account accounts)
response (contract-utils/call-rpc
"wallet_getWalletToken"
[main-account])]
Copy link
Contributor

Choose a reason for hiding this comment

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

The RPC call is now like "any" function call, so it accepts a variable number of args. In other words, we don't need to wrap the args in a vector.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's strange because for me it crashes if I remove it. But will investigate

@FFFra FFFra force-pushed the 18342-wallet-add-integration-test-for-rpc-endpoint-wallet_getwallettoken branch 5 times, most recently from 0c3f6f2 to 265fd03 Compare March 19, 2024 14:09
@FFFra
Copy link
Contributor Author

FFFra commented Mar 19, 2024

@J-Son89 can you please take another look? Made some changes.
Also included @shivekkhurana and @briansztamfater

Thank you!

@FFFra FFFra force-pushed the 18342-wallet-add-integration-test-for-rpc-endpoint-wallet_getwallettoken branch from 265fd03 to 8f83a97 Compare March 19, 2024 14:34
_ (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-wallet-tokens
[tokens]
(let [flattened-tokens (mapcat val tokens)]
(is (some :symbol flattened-tokens))))
Copy link
Contributor

Choose a reason for hiding this comment

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

I really think we should be testing more than this here.
Can you take a look through the code and see what properties of the tokens are being used and then ensure these are captured??
cc @ulisesmac, @smohamedjavid perhaps you could point to some uses of the data we are dependent on that we get from this rpc endpoint ("wallet_getWalletToken")

Copy link
Contributor

@ulisesmac ulisesmac Mar 19, 2024

Choose a reason for hiding this comment

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

Ideally, we should always receive the :symbol not being an empty string, but I remember we received some tokens named "" 😞

other important stuff is the Wei amount and :decimals, since we derive info from them

Copy link
Member

Choose a reason for hiding this comment

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

The whole token data depends on it 😅.
Keys of a token that we use from wallet_getWalletToken RPC.

{:symbol "ETH"
 :name "Ether"
 :decimals 18
 :balances-per-chain {1 {:raw-balance "193823235482934892"}
                      10 {:raw-balance "000004934800028760"}
                      ...}
 :market-values-per-currency {:usd {:price 3305.35 :change-pct-24hour -6.053133328320746}}}
                                            
;; NOTE: 1 and 10 are the chain ids of Ethereum mainnet and Optimism respectively. This would change if the user has enabled testnet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Im pushing a new version. Do we need the :market-values-per-currency? Its the only one Im not testing

Copy link
Contributor

Choose a reason for hiding this comment

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

@FFFra Yeah, we need it. we use it to calculate the fiat balance.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we need to test it, as it is one of the essential keys used to calculate and display the fiat balance.
Just a check whether the keys market-values-per-currency and :usd (default currency) are present should suffice. (Because for some tokens (e.g. a bridged token), we receive 0 as value. Not needed to go deep)

@FFFra FFFra force-pushed the 18342-wallet-add-integration-test-for-rpc-endpoint-wallet_getwallettoken branch from 793c3a5 to c29fe89 Compare March 20, 2024 16:26
@@ -12,3 +12,11 @@
:params args
:on-success p-resolve
:on-error p-reject}))))

(defn get-main-account
Copy link
Contributor

Choose a reason for hiding this comment

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

Btw main account is not good to use because it could actually be the 'chat' account. You should just use that method use default account to guarantee it's related to wallet

(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? ^^

(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

@FFFra FFFra force-pushed the 18342-wallet-add-integration-test-for-rpc-endpoint-wallet_getwallettoken branch from c29fe89 to 9bf0fca Compare March 20, 2024 17:35
@FFFra
Copy link
Contributor Author

FFFra commented Mar 20, 2024

Changes addressed! 🚀

@FFFra FFFra requested a review from smohamedjavid March 20, 2024 17:49
@FFFra FFFra force-pushed the 18342-wallet-add-integration-test-for-rpc-endpoint-wallet_getwallettoken branch from 9bf0fca to 4d19720 Compare March 21, 2024 11:54
@FFFra
Copy link
Contributor Author

FFFra commented Mar 21, 2024

@smohamedjavid I Made some last refactors and will merge soon. Please let me know if there's something else. Thanks!

@FFFra FFFra force-pushed the 18342-wallet-add-integration-test-for-rpc-endpoint-wallet_getwallettoken branch from 4d19720 to 595acaa Compare March 21, 2024 12:15
@FFFra FFFra merged commit 9091350 into develop Mar 21, 2024
6 checks passed
@FFFra FFFra deleted the 18342-wallet-add-integration-test-for-rpc-endpoint-wallet_getwallettoken branch March 21, 2024 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Archived in project
Development

Successfully merging this pull request may close these issues.

Wallet - Add Integration test for RPC endpoint - wallet_getWalletToken
6 participants