Add docker integration tests

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Andrea Maria Piana 2018-03-27 18:56:02 +01:00
parent 66bcf6562a
commit f8e73f8538
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
10 changed files with 159 additions and 133 deletions

View File

@ -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

View File

@ -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

View File

@ -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/<! (async/timeout (* timeout 1000)))
;; (println "ERROR: Timeout of" timeout "seconds reached - failing test.")
;; (is (= :terminate :indeterminate))
;; (done)))
;; ;; TODO(oskarth): Fix this test, issue with private key not being persisted
;; (deftest test-send-message!
;; (async done
;; (let [timeout 30
;; web3 (make-web3)
;; common-config {:web3 web3
;; :groups []
;; :ack-not-received-s-interval 125
;; :default-ttl 120
;; :send-online-s-interval 180
;; :ttl-config {:public-group-message 2400}
;; :max-attempts-number 3
;; :delivery-loop-ms-interval 500
;; :hashtags []
;; :pending-messages []}
;; id1-config (id-specific-config node/identity-1 [] done)]
;; (ensure-test-terminates! timeout done)
;; (protocol/init-whisper! (merge common-config id1-config))
;; (protocol/send-message!
;; {:web3 web3
;; :message {:message-id "123"
;; :from node/identity-1
;; :to node/identity-2
;; :payload {:type :message
;; :content-type "text/plain"
;; :content "123"
;; :timestamp 1498723691404}}}))))
;; #_(deftest test-whisper-version!
;; (testing "Whisper version supported"
;; (async done
;; (node/start!)
;; (let [web3 (make-web3)
;; shh (web3.utils/shh web3)]
;; (.version shh
;; (fn [& args]
;; (is (= "5.0" (second args)))
;; (done)))))))
(deftest test-whisper-version!
(testing "Whisper version supported"
(async done
(let [web3 (make-web3)
shh (transport.utils/shh web3)]
(.version shh
(fn [& args]
(is (= "6.0" (second args)))
(done)))))))

View File

@ -2,41 +2,6 @@
(:require [clojure.string :as s]
[status-im.test.protocol.utils :as utils]))
(def build-dir "target")
(defonce node-process (atom nil))
(defn prepare-env! []
(when-not (utils/exist? build-dir)
(println "mkdir " build-dir)
(utils/mkdir-sync build-dir))
(let [dir (s/join "/" [build-dir "status-go"])
opts #js {:cwd dir}]
(if-not (utils/exist? dir)
(utils/exec-sync "git clone https://github.com/status-im/status-go.git -b develop" #js {:cwd build-dir})
(utils/exec-sync "git pull origin develop" opts))
(println "Compile statusgo...")
(utils/exec-sync "make statusgo" opts)
(println "Done.")))
(defn start! []
(when-not @node-process
(println "Start statusd...")
(let [dir (s/join "/" [build-dir "status-go" "build" "bin"])]
(let [proc (utils/spawn "./statusd"
["--http" "--httpport" "8645" "-shh" "-logfile" "statusd.log"]
{:cwd dir})]
(reset! node-process proc)
(utils/sleep 5)
(println "Done.")))))
(defn stop! []
(println "Stop statusd...")
(.kill @node-process)
(println "Done.")
(reset! node-process nil))
(def identity-1 "0x04eedbaafd6adf4a9233a13e7b1c3c14461fffeba2e9054b8d456ce5f6ebeafadcbf3dce3716253fbc391277fa5a086b60b283daf61fb5b1f26895f456c2f31ae3")
(def identity-2 "0x0490161b00f2c47542d28c2e8908e77159b1720dccceb6393d7c001850122efc3b1709bcea490fd8f5634ba1a145aa0722d86b9330b0e39a8d493cb981fd459da2")
(def topic-1 "0xdeadbeef")

View File

@ -3,7 +3,6 @@
(def fs (js/require "fs"))
(def child-process (js/require "child_process"))
(def process (js/require "process"))
(def sleep (.-sleep (js/require "sleep")))
(def exist? (.-existsSync fs))

15
test/docker/README.md Normal file
View File

@ -0,0 +1,15 @@
Status react protocol tests
=====================
## Run the tests
To run the tests with `docker-compose`, execute:
```
docker-compose run tests
```
> 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

View File

@ -0,0 +1 @@
5f84f2ab5bc629b1cf83b5b9a100b00c4cf2b8970a317cc7f6b6b4dce5462352

View File

@ -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

View File

@ -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

View File

@ -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"]