Skip to content

Commit

Permalink
Check tribute if contact was added (but not otherwise)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy Vlasov committed Jun 18, 2019
1 parent 26bbac8 commit d86fd29
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/status_im/tribute_to_talk/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
(when (and (not (get-in db [:chats public-key :group-chat]))
(not (get-in db [:contacts/contacts public-key :tribute-to-talk
:transaction-hash]))
(not (whitelist/whitelisted?
(not (whitelist/whitelisted-by?
(get-in db [:contacts/contacts public-key]))))
(if-let [contract (contracts/get-address db :status/tribute-to-talk)]
(let [address (ethereum/public-key->address public-key)]
Expand Down
59 changes: 59 additions & 0 deletions test/cljs/status_im/test/tribute_to_talk/core.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns status-im.test.tribute-to-talk.core
(:require [cljs.test :refer-macros [deftest testing is]]
[status-im.tribute-to-talk.core :as tribute-to-talk]
[taoensso.timbre :as log]
[status-im.utils.money :as money]))

(deftest get-new-snt-amount
Expand Down Expand Up @@ -75,3 +76,61 @@
(is (not (tribute-to-talk/tribute-transaction-trigger
{:ethereum/current-block 5}
{:block "5"})))))

(def public-key "0xabcdef")
(def my-public-key "0x000001")
(def test-db
{:chats
{public-key {:group-chat false}}
:contacts/contacts
{public-key {:tribute-to-talk {}
:system-tags #{}}}
:account/account
{:public-key my-public-key
:network "mainnet_rpc"
:networks {"mainnet_rpc" {:id "mainnet_rpc"
:config {:NetworkId 1}}
"testnet_rpc" {:id "testnet_rpc"
:config {:NetworkId 3}}}}})

(deftest check-tribute
(testing "No contract in network, own public key"
(let [result (tribute-to-talk/check-tribute {:db test-db} my-public-key)]
(is (= (-> test-db
(assoc :navigation/screen-params {:tribute-to-talk {:unavailable? true}})
(assoc-in [:account/account :settings] {:tribute-to-talk {:mainnet nil}}))
(:db result)))))

(testing "No contract in network, another public key"
(let [result (tribute-to-talk/check-tribute {:db test-db} public-key)]
(is (= {:disabled? true}
(get-in result [:db :contacts/contacts public-key :tribute-to-talk])))))

(testing "Contract in network, another public key"
(let [result (tribute-to-talk/check-tribute {:db
(assoc-in test-db [:account/account :network] "testnet_rpc")} public-key)]
(is (= "0xC61aa0287247a0398589a66fCD6146EC0F295432"
(get-in result [:tribute-to-talk/get-tribute :contract])))))

(testing "Added by other user"
(let [result (tribute-to-talk/check-tribute
{:db (update-in test-db
[:contacts/contacts public-key :system-tags]
conj :contact/request-received)}
public-key)]
(is (= result nil))))

(testing "Group chat"
(let [result (tribute-to-talk/check-tribute
{:db (assoc-in test-db [:chats public-key :group-chat] true)}
public-key)]
(is (= result nil))))

(testing "Added by this user"
(let [result (tribute-to-talk/check-tribute
{:db (update-in test-db
[:contacts/contacts public-key :system-tags]
conj :contact/added)}
public-key)]
(is (= {:disabled? true}
(get-in result [:db :contacts/contacts public-key :tribute-to-talk]))))))

0 comments on commit d86fd29

Please sign in to comment.