diff --git a/project.clj b/project.clj index 4bc7598fea..fc4b3f6e8c 100644 --- a/project.clj +++ b/project.clj @@ -69,12 +69,13 @@ :preamble ["js/hook-require.js"] :target :nodejs}} {:id "protocol" - :source-paths ["src" "test/cljs"] - :compiler {:main status-im.test.protocol.runner - :output-to "target/test/test.js" - :output-dir "target/test" - :optimizations :none - :target :nodejs}} + :source-paths ["components/src" "src" "test/cljs"] + :compiler {:main status-im.test.protocol.runner + :output-to "target/test/test.js" + :output-dir "target/test" + :optimizations :none + :preamble ["js/hook-require.js"] + :target :nodejs}} {:id "env-dev-utils" :source-paths ["env/dev/env/utils.cljs" "test/env/dev"] :compiler {:main env.test.runner diff --git a/src/status_im/chat/models/message.cljs b/src/status_im/chat/models/message.cljs index 8000630545..55e988768e 100644 --- a/src/status_im/chat/models/message.cljs +++ b/src/status_im/chat/models/message.cljs @@ -219,8 +219,8 @@ (and group-chat (not public?)) (assoc :message-type :group-user-message))) -(defn- prepare-plain-message [{:keys [identity message-text]} - {:keys [chat-id last-to-clock-value last-from-clock-value] :as chat} now] +(defn- prepare-plain-message [chat-id {:keys [identity message-text]} + {:keys [last-to-clock-value last-from-clock-value] :as chat} now] (add-message-type {:chat-id chat-id :content message-text :from identity @@ -243,7 +243,7 @@ (send chat-id send-record)))) (defn send-message [{:keys [db now random-id] :as cofx} {:keys [chat-id] :as params}] - (upsert-and-send (prepare-plain-message params (get-in db [:chats chat-id]) now) cofx)) + (upsert-and-send (prepare-plain-message chat-id params (get-in db [:chats chat-id]) now) cofx)) (defn- prepare-command-message [identity diff --git a/test/cljs/status_im/test/protocol/core.cljs b/test/cljs/status_im/test/protocol/core.cljs index 2f2aa88b37..ac3e96524c 100644 --- a/test/cljs/status_im/test/protocol/core.cljs +++ b/test/cljs/status_im/test/protocol/core.cljs @@ -1,102 +1,59 @@ (ns status-im.test.protocol.core - (:require [cljs.test :refer-macros [deftest is testing run-tests - async use-fixtures]] + (:require [cljs.test :refer-macros [deftest is testing async ]] [cljs.nodejs :as nodejs] + re-frame.db + status-im.ui.screens.events + [re-frame.core :as rf] [cljs.core.async :as async] - ;;[status-im.protocol.web3.utils :as web3.utils] + [status-im.transport.utils :as transport.utils] + [day8.re-frame.test :refer-macros [run-test-async run-test-sync] :as rf-test] [status-im.test.protocol.node :as node] - [status-im.test.protocol.utils :as utils] - ;;[status-im.protocol.core :as protocol] - )) + [status-im.transport.message.v1.contact :as transport.contact] + [status-im.test.protocol.utils :as utils])) ;; NOTE(oskarth): All these tests are evaluated in NodeJS -;; (nodejs/enable-util-print!) +(nodejs/enable-util-print!) -;; (def rpc-url "http://localhost:8645") -;; (def Web3 (js/require "web3")) -;; (defn make-web3 [] -;; (Web3. (Web3.providers.HttpProvider. rpc-url))) +(def contact-whisper-identity "0x048f7d5d4bda298447bbb5b021a34832509bd1a8dbe4e06f9b7223d00a59b6dc14f6e142b21d3220ceb3155a6d8f40ec115cd96394d3cc7c55055b433a1758dc74") +(def rpc-url (aget nodejs/process.env "WNODE_ADDRESS")) -;; (defn setup [] -;; (println "Setup...") +(def Web3 (js/require "web3")) +(defn make-web3 [] + (Web3. (Web3.providers.HttpProvider. rpc-url))) -;; ;; NOTE(oskarth): If status-go has already been built correctly, comment this out -;; (println "Preparing environment...") -;; (node/prepare-env!) +(defn create-keys [shh] + (let [keypair-promise (.newKeyPair shh)] + (.getPublicKey shh keypair-promise))) -;; (println "Start node...") -;; (node/start!) +(deftest test-send-message! + (testing "send contact request & message" + (run-test-async + (let [web3 (make-web3) + shh (transport.utils/shh web3) + from (create-keys shh)] + (reset! re-frame.db/app-db {:web3 web3 + :current-public-key from}) -;; (println "Setup done")) + (rf/reg-fx :data-store/save-chat (constantly nil)) + (rf/reg-fx :data-store/save-message (constantly nil)) + (rf/reg-fx :data-store/save-contact (constantly nil)) + (rf/reg-fx :data-store.transport/save (constantly nil)) + (rf/reg-fx :data-store/update-message (constantly nil)) -;; (defn teardown [] -;; (println "Teardown done")) + (rf/dispatch [:open-chat-with-contact {:whisper-identity contact-whisper-identity}]) + (rf-test/wait-for [::transport.contact/send-new-sym-key] + (rf/dispatch [:set-chat-input-text "test message"]) + (rf/dispatch [:send-current-message]) + (rf-test/wait-for [:update-message-status :protocol/send-status-message-error] + (is true))))))) -;; (use-fixtures :once {:before setup :after teardown}) - -;; (defn make-callback [identity done] -;; (fn [& args] -;; (is (contains? #{:sent :pending} (first args))) -;; (when (= (first args) :sent) -;; (protocol/reset-all-pending-messages!) -;; (protocol/stop-watching-all!) -;; (node/stop!) -;; (done) -;; (utils/exit!)))) - -;; (defn post-error-callback [identity] -;; (fn [& args] -;; (.log js/console (str :post-error " " identity "\n" args)))) - -;; (defn id-specific-config -;; [id contacts done] -;; {:identity id -;; :callback (make-callback id done) -;; :contacts contacts -;; :post-error-callback (post-error-callback id)}) - -;; (defn ensure-test-terminates! [timeout done] -;; (async/go (async/ It may be required to make your node a swarm manager first. If you see an appropriate error, follow the instructions. + +This command will start a bootnode and build a Whisper node running the latest `status-go`. + +For more information about bootnodes see https://github.com/ethereum/go-ethereum/wiki/Setting-up-private-network-or-local-cluster diff --git a/test/docker/bootnode/static/bootnode.key b/test/docker/bootnode/static/bootnode.key new file mode 100644 index 0000000000..e369fe902e --- /dev/null +++ b/test/docker/bootnode/static/bootnode.key @@ -0,0 +1 @@ +5f84f2ab5bc629b1cf83b5b9a100b00c4cf2b8970a317cc7f6b6b4dce5462352 diff --git a/test/docker/clojure/Dockerfile b/test/docker/clojure/Dockerfile new file mode 100644 index 0000000000..c114317705 --- /dev/null +++ b/test/docker/clojure/Dockerfile @@ -0,0 +1,6 @@ +FROM clojure + +RUN apt-get update +RUN apt-get install make curl -y +RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - +RUN apt-get install -y nodejs diff --git a/test/docker/docker-compose.yml b/test/docker/docker-compose.yml new file mode 100644 index 0000000000..0581d8d8d8 --- /dev/null +++ b/test/docker/docker-compose.yml @@ -0,0 +1,54 @@ +version: "3" +services: + tests: + build: ./clojure + volumes: + - "../../:/srv" + command: lein test-protocol + working_dir: "/srv" + environment: + WNODE_ADDRESS: "http://172.16.238.11:8545" + links: + - wnode + networks: + cluster: + ipv4_address: 172.16.238.12 + bootnode: + image: ethereum/client-go:alltools-latest + entrypoint: bootnode + command: -addr=:30303 -nodekey /static/keys/bootnode.key + volumes: + - ./bootnode/static:/static/keys + ports: + - 30303 + networks: + cluster: + ipv4_address: 172.16.238.10 + wnode: + build: ./status-go + command: + - "-shh" + - "-listenaddr=:30303" + - "-discovery=true" + - "-standalone=false" + - "-bootnodes=enode://3f04db09bedc8d85a198de94c84da73aa7782fafc61b28c525ec5cca5a6cc16be7ebbb5cd001780f71d8408d35a2f6326faa1e524d9d8875294172ebec988743@172.16.238.10:30303" + - "-http" + - "-httpport=8545" + - "-httphost=0.0.0.0" + - "-log=DEBUG" + ports: + - 8080 + - 8545 + - 30303 + depends_on: + - bootnode + networks: + cluster: + ipv4_address: 172.16.238.11 +networks: + cluster: + driver: overlay + ipam: + driver: default + config: + - subnet: 172.16.238.0/24 diff --git a/test/docker/status-go/Dockerfile b/test/docker/status-go/Dockerfile new file mode 100644 index 0000000000..62df127447 --- /dev/null +++ b/test/docker/status-go/Dockerfile @@ -0,0 +1,28 @@ +# Build status-go in a Go builder container +FROM golang:1.9-alpine as builder + +RUN apk add git --update + +ARG build_tags + +RUN apk add --no-cache make gcc musl-dev linux-headers + +RUN mkdir -p /go/src/github.com/status-im/status-go +RUN git clone http://github.com/status-im/status-go /go/src/github.com/status-im/status-go + +RUN cd /go/src/github.com/status-im/status-go && make statusgo BUILD_TAGS="$build_tags" + +# Copy the binary to the second image +FROM alpine:latest + +RUN apk add --no-cache ca-certificates bash + +COPY --from=builder /go/src/github.com/status-im/status-go/build/bin/* /usr/local/bin/ + +RUN mkdir -p /static/keys +COPY --from=builder /go/src/github.com/status-im/status-go/static/keys/* /static/keys/ + +# 30304 is used for Discovery v5 +EXPOSE 8080 8545 30303 30303/udp 30304/udp + +ENTRYPOINT ["/usr/local/bin/statusd"]