Skip to content

Commit

Permalink
fix tests for raw transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
aviad committed Nov 9, 2014
1 parent 54d3d59 commit 4a45a03
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions test/clj_btc/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
;;;; any other, from this software.

(ns clj-btc.core-test
(:require [clojure.test :refer :all]
(:require [clojure.set :refer (superset?)]
[clojure.test :refer :all]
[clj-btc.core :refer :all]
[clj-btc.config :refer :all]))

Expand All @@ -19,6 +20,7 @@
;;; local configuration file.

(def cfg (atom {}))

(def addr-with-bitcoins
{:public "mqWiQRdS6MePCtALRg2smULFvqf8Ru1usj",
:private "cVGghpMADPnrX6YNnS7X8nSEnULR6epfJFHLyw9dvKi6n17tUkDg"})
Expand Down Expand Up @@ -46,6 +48,11 @@
(str ~rpc-method " should return a result of type "
~(str expected-type)))))

(defn- supermap?
"Does m1 cointain all of m2? (inspired by https://stackoverflow.com/questions/20421405/how-to-check-if-a-map-is-a-subset-of-another-in-clojure)"
[m1 m2]
(superset? (set m1) (set m2)))

(deftest return-types
(is-type integer? getblockcount)
(is-type integer? getconnectioncount)
Expand Down Expand Up @@ -106,32 +113,33 @@
"raw transaction creation correct")

(let [random-vout (rand-int 10000)
random-amount (bigdec (rand))
random-amount (bigdec (format "%.8f" (rand)))
raw-transaction (createrawtransaction
:txids-map
[{"txid" "7acb74b4ad7f982eed3dabf93c8f474451b0a60f3f7950cd12a2bbe721290cb8"
"vout" random-vout}]
:addrs-amounts-map
{"mqWiQRdS6MePCtALRg2smULFvqf8Ru1usj" random-amount})
decoded-raw-transaction (decoderawtransaction :hex-string raw-transaction)]
(is (= decoded-raw-transaction
{"txid" "6316b2abcc2d957ecb1304f63725ea70841b1feae94c6f017e114556d8c60537",
"version" 1, "locktime" 0,
"vin" [{"txid" "7acb74b4ad7f982eed3dabf93c8f474451b0a60f3f7950cd12a2bbe721290cb8",
"vout" random-vout, "scriptSig" {"asm" "", "hex" ""},
"sequence" 4294967295}],
"vout" [{"value" random-amount, "n" 0,
"scriptPubKey"
{"asm" "OP_DUP OP_HASH160 6da5a9b587c385c1a6002bf77f71e4333e0ceb1a OP_EQUALVERIFY OP_CHECKSIG",
"hex" "76a9146da5a9b587c385c1a6002bf77f71e4333e0ceb1a88ac",
"reqSigs" 1, "type" "pubkeyhash", "addresses" ["mqWiQRdS6MePCtALRg2smULFvqf8Ru1usj"]}}]})
(is (supermap?
decoded-raw-transaction
{;; "txid" "6316b2abcc2d957ecb1304f63725ea70841b1feae94c6f017e114556d8c60537",
"version" 1, "locktime" 0,
"vin" [{"txid" "7acb74b4ad7f982eed3dabf93c8f474451b0a60f3f7950cd12a2bbe721290cb8",
"vout" random-vout, "scriptSig" {"asm" "", "hex" ""},
"sequence" 4294967295}],
"vout" [{"value" random-amount, "n" 0,
"scriptPubKey"
{"asm" "OP_DUP OP_HASH160 6da5a9b587c385c1a6002bf77f71e4333e0ceb1a OP_EQUALVERIFY OP_CHECKSIG",
"hex" "76a9146da5a9b587c385c1a6002bf77f71e4333e0ceb1a88ac",
"reqSigs" 1, "type" "pubkeyhash", "addresses" ["mqWiQRdS6MePCtALRg2smULFvqf8Ru1usj"]}}]})
"decoding encoded raw transaction correct"))
(is (= (getrawtransaction :txid "7acb74b4ad7f982eed3dabf93c8f474451b0a60f3f7950cd12a2bbe721290cb8")
"01000000019c19404b3cd4aa272cdc45fd6362f33151181d6ea6f26bda8d6311664e8a2248000000006b483045022065939207fde542fd6f38da9c651537f3e36621e9a447f2877ff0e8a807137367022100c7935881cd3af35502eb12a7ea12d7a2952ac5e1ada1dd52bef1b9449fca36240121024d1a5f75a170eebebe25df71a87e3ef012cc07754db4c87feeee65f1aeed84bfffffffff0210270000000000001976a914fac7cf4845a26094ff9571a27db6268950a3b70e88ac3214ac3a000000001976a914560b13a3ac034489c8bc9488d749174a2fb198e988ac00000000")
"get raw transaction")

(is (= (signrawtransaction
:txid "010000000189957b01aed596d3b361b576234eaeed3249246f14562d6bc6085166cd247d5a0000000000ffffffff0180969800000000001976a9140dfc8bafc8419853b34d5e072ad37d1a5159f58488ac00000000"
:hexstring "010000000189957b01aed596d3b361b576234eaeed3249246f14562d6bc6085166cd247d5a0000000000ffffffff0180969800000000001976a9140dfc8bafc8419853b34d5e072ad37d1a5159f58488ac00000000"
:txinfo [{:txid "7acb74b4ad7f982eed3dabf93c8f474451b0a60f3f7950cd12a2bbe721290cb8" :vout 2 :scriptPubKey "123d"}])
{"hex" "010000000189957b01aed596d3b361b576234eaeed3249246f14562d6bc6085166cd247d5a0000000000ffffffff0180969800000000001976a9140dfc8bafc8419853b34d5e072ad37d1a5159f58488ac00000000",
"complete" false})
Expand Down

0 comments on commit 4a45a03

Please sign in to comment.