feat: add basic infrastructure for contract tests (#18665)

This commit is contained in:
Jamie Caprani 2024-02-09 17:10:09 +00:00 committed by GitHub
parent ab73c7e56a
commit 9acf67dd5b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 147 additions and 60 deletions

View File

@ -373,15 +373,20 @@ test-watch-for-repl: ##@test Watch all Clojure tests and support REPL connection
"until [ -f $$SHADOW_OUTPUT_TO ] ; do sleep 1 ; done ; node --require ./test-resources/override.js $$SHADOW_OUTPUT_TO --repl" "until [ -f $$SHADOW_OUTPUT_TO ] ; do sleep 1 ; done ; node --require ./test-resources/override.js $$SHADOW_OUTPUT_TO --repl"
test-unit: export SHADOW_OUTPUT_TO := target/unit_test/test.js test-unit: export SHADOW_OUTPUT_TO := target/unit_test/test.js
test-unit: export SHADOW_NS_REGEXP := ^(?!status-im\.integration-test).*-test$$ test-unit: export SHADOW_NS_REGEXP := ^(?!tests\.integration-test)(?!tests-im\.contract-test).*-test$$
test-unit: ##@test Run unit tests test-unit: ##@test Run unit tests
test-unit: _test-clojure test-unit: _test-clojure
test-integration: export SHADOW_OUTPUT_TO := target/integration_test/test.js test-integration: export SHADOW_OUTPUT_TO := target/integration_test/test.js
test-integration: export SHADOW_NS_REGEXP := ^status-im\.integration-test.*$$ test-integration: export SHADOW_NS_REGEXP := ^tests\.integration-test.*$$
test-integration: ##@test Run integration tests test-integration: ##@test Run integration tests
test-integration: _test-clojure test-integration: _test-clojure
test-contract: export SHADOW_OUTPUT_TO := target/contract_test/test.js
test-contract: export SHADOW_NS_REGEXP := ^tests\.contract-test.*$$
test-contract: ##@test Run contract tests
test-contract: _test-clojure
android-test: jsbundle android-test: jsbundle
android-test: export TARGET := android android-test: export TARGET := android
android-test: android-test:

View File

@ -176,7 +176,6 @@
;; option setupFilesAfterEnv. ;; option setupFilesAfterEnv.
test-helpers.component-tests-preload test-helpers.component-tests-preload
status-im.setup.schema-preload status-im.setup.schema-preload
quo.core-spec quo.core-spec
status-im.core-spec] status-im.core-spec]
:ns-regexp "component-spec$" :ns-regexp "component-spec$"

View File

@ -1,51 +0,0 @@
(ns status-im.integration-test.wallet-test
(:require
[cljs.test :refer [is]]
[clojure.string :as string]
[day8.re-frame.test :as rf-test]
legacy.status-im.events
[legacy.status-im.multiaccounts.logout.core :as logout]
legacy.status-im.subs.root
[re-frame.core :as rf]
status-im.events
status-im.navigation.core
status-im.subs.root
[test-helpers.integration :as h]))
;; Workaround to skip test. Switch to `deftest` when test is fixed.
(defn create-wallet-account-test
[]
(h/log-headline :create-wallet-account-test)
(rf-test/run-test-async
(h/with-app-initialized
(h/with-account
(h/create-new-account!)
(rf-test/wait-for
[:wallet-legacy.accounts/account-stored]
(h/assert-new-account-created)
(h/logout)
(rf-test/wait-for [::logout/logout-method]))))))
;; Workaround to skip test. Switch to `deftest` when test is fixed.
(defn back-up-seed-phrase-test
[]
(h/log-headline :back-up-seed-phrase-test)
(rf-test/run-test-async
(h/with-app-initialized
(h/with-account
(rf/dispatch-sync [:set-in [:my-profile/seed :step] :12-words]) ; display seed phrase to user
(rf/dispatch-sync [:my-profile/enter-two-random-words]) ; begin prompting user for seed words
(let [{:keys [mnemonic]} @(rf/subscribe [:profile/profile])
seed @(rf/subscribe [:my-profile/seed])
word1 (second (:first-word seed))
word2 (second (:second-word seed))]
(is (= 12 (count (string/split mnemonic #" "))))
(rf/dispatch-sync [:set-in [:my-profile/seed :word] word1])
(rf/dispatch-sync [:my-profile/set-step :second-word])
(rf/dispatch-sync [:set-in [:my-profile/seed :word] word2])
(rf/dispatch [:my-profile/finish])
(rf-test/wait-for
[:my-profile/finish-success]
(is (nil? @(rf/subscribe [:mnemonic]))) ; assert seed phrase has been removed
(h/logout)
(rf-test/wait-for [::logout/logout-method])))))))

View File

@ -7,10 +7,10 @@
[native-module.core :as native-module] [native-module.core :as native-module]
[re-frame.core :as rf] [re-frame.core :as rf]
status-im.events status-im.events
[status-im.integration-test.constants :as constants]
status-im.navigation.core status-im.navigation.core
status-im.subs.root status-im.subs.root
[taoensso.timbre :as log])) [taoensso.timbre :as log]
[tests.integration-test.constants :as constants]))
(defn initialize-app! (defn initialize-app!
[] []

View File

@ -1,4 +1,4 @@
(ns status-im.integration-test.core-test (ns tests.contract-test.core-test
(:require (:require
[cljs.test :refer [deftest]] [cljs.test :refer [deftest]]
[day8.re-frame.test :as rf-test] [day8.re-frame.test :as rf-test]

View File

@ -0,0 +1,14 @@
(ns tests.contract-test.utils
(:require
[status-im.common.json-rpc.events :as rpc-events]
[utils.number]))
(defn call-rpc-endpoint
[{:keys [rpc-endpoint
params
action
on-error]}]
(rpc-events/call {:method rpc-endpoint
:params params
:on-success action
:on-error on-error}))

View File

@ -0,0 +1,86 @@
(ns tests.contract-test.wallet-test
(:require
[cljs.test :refer [deftest is]]
[day8.re-frame.test :as rf-test]
legacy.status-im.events
[legacy.status-im.multiaccounts.logout.core :as logout]
legacy.status-im.subs.root
[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]))
(defn assert-accounts-get-accounts
[result]
(is (true? (some :wallet result)))
(is (true? (some :chat result)))
(is (= 2 (count result))))
(deftest accounts-get-accounts-contract
(h/log-headline :contract/accounts-get-accounts)
(rf-test/run-test-async
(h/with-app-initialized
(h/with-account
(contract-utils/call-rpc-endpoint
{:rpc-endpoint "accounts_getAccounts"
:action assert-accounts-get-accounts})
(h/logout)
(rf-test/wait-for
[::logout/logout-method])))))
(defn get-default-account
[accounts]
(first (filter :wallet accounts)))
(defn check-emoji-is-updated
[test-emoji accounts]
(let [default-account (get-default-account accounts)]
(is (= (:emoji default-account) test-emoji))))
(deftest accounts-save-accounts-contract
(h/log-headline :contract/accounts-save-account)
(rf-test/run-test-async
(h/with-app-initialized
(h/with-account
(let [test-emoji (emoji-picker.utils/random-emoji)
account (contract-utils/call-rpc-endpoint
{:rpc-endpoint "accounts_getAccounts"
:action get-default-account})]
(contract-utils/call-rpc-endpoint
{:rpc-endpoint "accounts_saveAccount"
:action identity
:params [(data-store/<-account (merge account {:emoji test-emoji}))]})
(contract-utils/call-rpc-endpoint
{:rpc-endpoint "accounts_getAccounts"
:action #(check-emoji-is-updated test-emoji %)})
(h/logout)
(rf-test/wait-for
[::logout/logout-method]))))))
(def number-of-networks 3)
(defn assert-ethereum-chains
[response]
(is (= number-of-networks (count response)))
(is (some #(= constants/ethereum-chain-id (get-in % [:Prod :chainId])) response))
(is (some #(= constants/optimism-chain-id (get-in % [:Prod :chainId])) response))
(is (some #(= constants/arbitrum-chain-id (get-in % [:Prod :chainId])) response))
(is (some #(= constants/goerli-chain-id (get-in % [:Test :chainId])) response))
(is (some #(= constants/arbitrum-testnet-chain-id (get-in % [:Test :chainId])) response))
(is (some #(= constants/optimism-testnet-chain-id (get-in % [:Test :chainId])) response)))
(deftest accounts-get-chains-contract
(h/log-headline :contract/wallet_get-ethereum-chains)
(rf-test/run-test-async
(h/with-app-initialized
(h/with-account
(contract-utils/call-rpc-endpoint
{:rpc-endpoint "wallet_getEthereumChains"
:action assert-ethereum-chains})
(h/logout)
(rf-test/wait-for
[::logout/logout-method])))))

View File

@ -1,4 +1,4 @@
(ns status-im.integration-test.chat-test (ns tests.integration-test.chat-test
(:require (:require
[cljs.test :refer [deftest is]] [cljs.test :refer [deftest is]]
[day8.re-frame.test :as rf-test] [day8.re-frame.test :as rf-test]

View File

@ -1,4 +1,4 @@
(ns status-im.integration-test.constants) (ns tests.integration-test.constants)
(def password "testabc") (def password "testabc")

View File

@ -0,0 +1,34 @@
(ns tests.integration-test.core-test
(:require
[cljs.test :refer [deftest]]
[day8.re-frame.test :as rf-test]
legacy.status-im.events
[legacy.status-im.multiaccounts.logout.core :as logout]
legacy.status-im.subs.root
[legacy.status-im.utils.test :as utils.test]
[re-frame.core :as rf]
status-im.events
status-im.navigation.core
status-im.subs.root
[test-helpers.integration :as h]))
(deftest initialize-app-test
(h/log-headline :initialize-app-test)
(rf-test/run-test-async
(utils.test/init!)
(rf/dispatch [:app-started])
(rf-test/wait-for
;; use initialize-view because it has the longest avg. time and
;; is dispatched by initialize-multiaccounts (last non-view event)
[:profile/get-profiles-overview-success]
(rf-test/wait-for
[:font/init-font-file-for-initials-avatar]
(h/assert-app-initialized)))))
(deftest create-account-test
(h/log-headline :create-account-test)
(rf-test/run-test-async
(h/with-app-initialized
(h/with-account
(h/logout)
(rf-test/wait-for [::logout/logout-method])))))

View File

@ -1,4 +1,4 @@
(ns status-im.integration-test.profile-test (ns tests.integration-test.profile-test
(:require (:require
[cljs.test :refer [deftest is]] [cljs.test :refer [deftest is]]
[day8.re-frame.test :as rf-test] [day8.re-frame.test :as rf-test]