|
1 | 1 | (ns status-im.test.protocol.core |
2 | | - (:require [cljs.test :refer-macros [deftest is testing run-tests async]] |
| 2 | + (:require-macros [cljs.core.async.macros :as async]) |
| 3 | + (:require [cljs.test :refer-macros [deftest is testing run-tests |
| 4 | + async use-fixtures]] |
3 | 5 | [cljs.nodejs :as nodejs] |
| 6 | + [cljs.core.async :as async] |
4 | 7 | [status-im.protocol.web3.utils :as web3.utils] |
5 | 8 | [status-im.test.protocol.node :as node] |
6 | 9 | [status-im.test.protocol.utils :as utils] |
|
10 | 13 |
|
11 | 14 | (nodejs/enable-util-print!) |
12 | 15 |
|
13 | | -;; NOTE(oskarth): If status-go has already been built correctly, comment this out |
14 | | -(node/prepare-env!) |
15 | | - |
16 | 16 | (def rpc-url "http://localhost:8645") |
17 | 17 | (def Web3 (js/require "web3")) |
18 | 18 | (defn make-web3 [] |
19 | 19 | (Web3. (Web3.providers.HttpProvider. rpc-url))) |
20 | 20 |
|
| 21 | +(defn setup [] |
| 22 | + (println "Setup...") |
| 23 | + |
| 24 | + ;; NOTE(oskarth): If status-go has already been built correctly, comment this out |
| 25 | + (println "Preparing environment...") |
| 26 | + (node/prepare-env!) |
| 27 | + |
| 28 | + (println "Start node...") |
| 29 | + (node/start!) |
| 30 | + |
| 31 | + (println "Setup done")) |
| 32 | + |
| 33 | +(defn teardown [] |
| 34 | + (println "Teardown done")) |
| 35 | + |
| 36 | +(use-fixtures :once {:before setup :after teardown}) |
| 37 | + |
21 | 38 | (defn make-callback [identity done] |
22 | 39 | (fn [& args] |
23 | 40 | (is (contains? #{:sent :pending} (first args))) |
|
41 | 58 | :contacts contacts |
42 | 59 | :post-error-callback (post-error-callback id)}) |
43 | 60 |
|
44 | | -;; NOTE(oskarth): Test assumes callback is always called, otherwise it won't terminate |
45 | | -;; TODO(oskarth): Add a timeout async function where we fail test if it takes too long to finish |
| 61 | +(defn ensure-test-terminates! [timeout done] |
| 62 | + (async/go (async/<! (async/timeout (* timeout 1000))) |
| 63 | + (println "ERROR: Timeout of" timeout "seconds reached - failing test.") |
| 64 | + (is (= :terminate :indeterminate)) |
| 65 | + (done))) |
| 66 | + |
46 | 67 | ;; TODO(oskarth): Fix this test, issue with private key not being persisted |
47 | | -#_(deftest test-send-message! |
| 68 | +(deftest test-send-message! |
48 | 69 | (async done |
49 | | - (node/start!) |
50 | | - (let [web3 (make-web3) |
| 70 | + (let [timeout 30 |
| 71 | + web3 (make-web3) |
51 | 72 | id1-keypair (protocol/new-keypair!) |
52 | 73 | common-config {:web3 web3 |
53 | 74 | :groups [] |
|
60 | 81 | :hashtags [] |
61 | 82 | :pending-messages []} |
62 | 83 | id1-config (id-specific-config node/identity-1 id1-keypair [] done)] |
| 84 | + (ensure-test-terminates! timeout done) |
63 | 85 | (protocol/init-whisper! (merge common-config id1-config)) |
64 | 86 | (protocol/send-message! |
65 | 87 | {:web3 web3 |
|
71 | 93 | :content "123" |
72 | 94 | :timestamp 1498723691404}}})))) |
73 | 95 |
|
74 | | -;; TODO(oskarth): Add fixtures to start node before running tests against node |
75 | 96 | (deftest test-whisper-version! |
76 | 97 | (testing "Whisper version supported" |
77 | 98 | (async done |
|
0 commit comments