bitcoin-ruby 0.0.18 → 0.0.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (255) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +8 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +46 -0
  5. data/.travis.yml +5 -1
  6. data/Gemfile +11 -9
  7. data/Gemfile.lock +64 -12
  8. data/README.rdoc +17 -4
  9. data/Rakefile +58 -83
  10. data/bitcoin-ruby.gemspec +5 -2
  11. data/lib/bitcoin.rb +31 -14
  12. data/lib/bitcoin/bech32.rb +126 -132
  13. data/lib/bitcoin/bloom_filter.rb +24 -21
  14. data/lib/bitcoin/builder.rb +168 -126
  15. data/lib/bitcoin/connection.rb +21 -24
  16. data/lib/bitcoin/contracthash.rb +20 -24
  17. data/lib/bitcoin/dogecoin.rb +79 -77
  18. data/lib/bitcoin/electrum/mnemonic.rb +28 -25
  19. data/lib/bitcoin/ext_key.rb +3 -3
  20. data/lib/bitcoin/ffi/bitcoinconsensus.rb +17 -13
  21. data/lib/bitcoin/ffi/openssl.rb +355 -338
  22. data/lib/bitcoin/ffi/secp256k1.rb +97 -64
  23. data/lib/bitcoin/protocol.rb +6 -3
  24. data/lib/bitcoin/protocol/address.rb +15 -13
  25. data/lib/bitcoin/protocol/aux_pow.rb +12 -15
  26. data/lib/bitcoin/protocol/block.rb +102 -76
  27. data/lib/bitcoin/protocol/handler.rb +2 -4
  28. data/lib/bitcoin/protocol/parser.rb +108 -92
  29. data/lib/bitcoin/protocol/partial_merkle_tree.rb +59 -47
  30. data/lib/bitcoin/protocol/reject.rb +26 -28
  31. data/lib/bitcoin/protocol/script_witness.rb +3 -8
  32. data/lib/bitcoin/protocol/tx.rb +250 -137
  33. data/lib/bitcoin/protocol/txin.rb +44 -38
  34. data/lib/bitcoin/protocol/txout.rb +27 -20
  35. data/lib/bitcoin/protocol/version.rb +47 -34
  36. data/lib/bitcoin/script.rb +18 -17
  37. data/lib/bitcoin/trezor/mnemonic.rb +113 -98
  38. data/lib/bitcoin/version.rb +1 -1
  39. data/spec/examples.txt +399 -0
  40. data/spec/{bitcoin/fixtures → fixtures}/000000000000056b1a3d84a1e2b33cde8915a4b61c0cae14fca6d3e1490b4f98.json +0 -0
  41. data/spec/{bitcoin/fixtures → fixtures}/03d7e1fa4d5fefa169431f24f7798552861b255cd55d377066fedcd088fb0e99.json +0 -0
  42. data/spec/{bitcoin/fixtures → fixtures}/0961c660358478829505e16a1f028757e54b5bbf9758341a7546573738f31429.json +0 -0
  43. data/spec/{bitcoin/fixtures → fixtures}/0f24294a1d23efbb49c1765cf443fba7930702752aba6d765870082fe4f13cae.json +0 -0
  44. data/spec/{bitcoin/fixtures → fixtures}/156e6e1b84c5c3bd3a0927b25e4119fadce6e6d5186f363317511d1d680fae9a.json +0 -0
  45. data/spec/{bitcoin/fixtures → fixtures}/23b397edccd3740a74adb603c9756370fafcde9bcc4483eb271ecad09a94dd63.json +0 -0
  46. data/spec/{bitcoin/fixtures → fixtures}/315ac7d4c26d69668129cc352851d9389b4a6868f1509c6c8b66bead11e2619f.json +0 -0
  47. data/spec/{bitcoin/fixtures → fixtures}/35e2001b428891fefa0bfb73167c7360669d3cbd7b3aa78e7cad125ddfc51131.json +0 -0
  48. data/spec/{bitcoin/fixtures → fixtures}/3a17dace09ffb919ed627a93f1873220f4c975c1248558b18d16bce25d38c4b7.json +0 -0
  49. data/spec/{bitcoin/fixtures → fixtures}/3e58b7eed0fdb599019af08578effea25c8666bbe8e200845453cacce6314477.json +0 -0
  50. data/spec/{bitcoin/fixtures → fixtures}/514c46f0b61714092f15c8dfcb576c9f79b3f959989b98de3944b19d98832b58.json +0 -0
  51. data/spec/{bitcoin/fixtures → fixtures}/51bf528ecf3c161e7c021224197dbe84f9a8564212f6207baa014c01a1668e1e.json +0 -0
  52. data/spec/{bitcoin/fixtures → fixtures}/60a20bd93aa49ab4b28d514ec10b06e1829ce6818ec06cd3aabd013ebcdc4bb1.json +0 -0
  53. data/spec/{bitcoin/fixtures → fixtures}/69216b8aaa35b76d6613e5f527f4858640d986e1046238583bdad79b35e938dc.json +0 -0
  54. data/spec/{bitcoin/fixtures → fixtures}/7208e5edf525f04e705fb3390194e316205b8f995c8c9fcd8c6093abe04fa27d.json +0 -0
  55. data/spec/{bitcoin/fixtures → fixtures}/761d8c5210fdfd505f6dff38f740ae3728eb93d7d0971fb433f685d40a4c04f6.json +0 -0
  56. data/spec/{bitcoin/fixtures → fixtures}/8d0b238a06b5a70be75d543902d02d7a514d68d3252a949a513865ac3538874c.json +0 -0
  57. data/spec/{bitcoin/fixtures → fixtures}/aea682d68a3ea5e3583e088dcbd699a5d44d4b083f02ad0aaf2598fe1fa4dfd4.json +0 -0
  58. data/spec/{bitcoin/fixtures → fixtures}/base58_keys_invalid.json +0 -0
  59. data/spec/{bitcoin/fixtures → fixtures}/base58_keys_valid.json +0 -0
  60. data/spec/{bitcoin/fixtures → fixtures}/bc179baab547b7d7c1d5d8d6f8b0cc6318eaa4b0dd0a093ad6ac7f5a1cb6b3ba.json +0 -0
  61. data/spec/{bitcoin/fixtures → fixtures}/bd1715f1abfdc62bea3f605bdb461b3ba1f2cca6ec0d73a18a548b7717ca8531.json +0 -0
  62. data/spec/{bitcoin/fixtures → fixtures}/block-testnet-0000000000ac85bb2530a05a4214a387e6be02b22d3348abc5e7a5d9c4ce8dab.bin +0 -0
  63. data/spec/{bitcoin/fixtures → fixtures}/cd874fa8cb0e2ec2d385735d5e1fd482c4fe648533efb4c50ee53bda58e15ae2.json +0 -0
  64. data/spec/{bitcoin/fixtures → fixtures}/ce5fad9b4ef094d8f4937b0707edaf0a6e6ceeaf67d5edbfd51f660eac8f398b.json +0 -0
  65. data/spec/{bitcoin/fixtures → fixtures}/coinbase-toshi.json +0 -0
  66. data/spec/{bitcoin/fixtures → fixtures}/coinbase.json +0 -0
  67. data/spec/{bitcoin/fixtures → fixtures}/dogecoin-block-60323982f9c5ff1b5a954eac9dc1269352835f47c2c5222691d80f0d50dcf053.bin +0 -0
  68. data/spec/{bitcoin/fixtures → fixtures}/f003f0c1193019db2497a675fd05d9f2edddf9b67c59e677c48d3dbd4ed5f00b.json +0 -0
  69. data/spec/{bitcoin/fixtures → fixtures}/filteredblock-0.bin +0 -0
  70. data/spec/{bitcoin/fixtures → fixtures}/litecoin-block-80ca095ed10b02e53d769eb6eaf92cd04e9e0759e5be4a8477b42911ba49c78f.bin +0 -0
  71. data/spec/{bitcoin/fixtures → fixtures}/litecoin-block-80ca095ed10b02e53d769eb6eaf92cd04e9e0759e5be4a8477b42911ba49c78f.json +0 -0
  72. data/spec/{bitcoin/fixtures → fixtures}/litecoin-genesis-block-12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2.bin +0 -0
  73. data/spec/{bitcoin/fixtures → fixtures}/litecoin-genesis-block-12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2.json +0 -0
  74. data/spec/{bitcoin/fixtures → fixtures}/litecoin-tx-f5aa30f574e3b6f1a3d99c07a6356ba812aabb9661e1d5f71edff828cbd5c996.json +0 -0
  75. data/spec/{bitcoin/fixtures → fixtures}/rawblock-0.bin +0 -0
  76. data/spec/{bitcoin/fixtures → fixtures}/rawblock-0.json +0 -0
  77. data/spec/{bitcoin/fixtures → fixtures}/rawblock-1.bin +0 -0
  78. data/spec/{bitcoin/fixtures → fixtures}/rawblock-1.json +0 -0
  79. data/spec/{bitcoin/fixtures → fixtures}/rawblock-131025.bin +0 -0
  80. data/spec/{bitcoin/fixtures → fixtures}/rawblock-131025.json +0 -0
  81. data/spec/{bitcoin/fixtures → fixtures}/rawblock-170.bin +0 -0
  82. data/spec/{bitcoin/fixtures → fixtures}/rawblock-9.bin +0 -0
  83. data/spec/{bitcoin/fixtures → fixtures}/rawblock-auxpow.bin +0 -0
  84. data/spec/{bitcoin/fixtures → fixtures}/rawblock-testnet-1151351.bin +0 -0
  85. data/spec/{bitcoin/fixtures → fixtures}/rawblock-testnet-26478.bin +0 -0
  86. data/spec/{bitcoin/fixtures → fixtures}/rawblock-testnet-26478.json +0 -0
  87. data/spec/{bitcoin/fixtures → fixtures}/rawblock-testnet-265322.bin +0 -0
  88. data/spec/{bitcoin/fixtures → fixtures}/rawtx-01-toshi.json +0 -0
  89. data/spec/{bitcoin/fixtures → fixtures}/rawtx-01.bin +0 -0
  90. data/spec/{bitcoin/fixtures → fixtures}/rawtx-01.json +0 -0
  91. data/spec/{bitcoin/fixtures → fixtures}/rawtx-02-toshi.json +0 -0
  92. data/spec/{bitcoin/fixtures → fixtures}/rawtx-02.bin +0 -0
  93. data/spec/{bitcoin/fixtures → fixtures}/rawtx-02.json +0 -0
  94. data/spec/{bitcoin/fixtures → fixtures}/rawtx-03-toshi.json +0 -0
  95. data/spec/{bitcoin/fixtures → fixtures}/rawtx-03.bin +0 -0
  96. data/spec/{bitcoin/fixtures → fixtures}/rawtx-03.json +0 -0
  97. data/spec/{bitcoin/fixtures → fixtures}/rawtx-04.json +0 -0
  98. data/spec/{bitcoin/fixtures → fixtures}/rawtx-0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9.bin +0 -0
  99. data/spec/{bitcoin/fixtures → fixtures}/rawtx-05.json +0 -0
  100. data/spec/{bitcoin/fixtures → fixtures}/rawtx-14be6fff8c6014f7c9493b4a6e4a741699173f39d74431b6b844fcb41ebb9984.bin +0 -0
  101. data/spec/{bitcoin/fixtures → fixtures}/rawtx-2f4a2717ec8c9f077a87dde6cbe0274d5238793a3f3f492b63c744837285e58a.bin +0 -0
  102. data/spec/{bitcoin/fixtures → fixtures}/rawtx-2f4a2717ec8c9f077a87dde6cbe0274d5238793a3f3f492b63c744837285e58a.json +0 -0
  103. data/spec/{bitcoin/fixtures → fixtures}/rawtx-406b2b06bcd34d3c8733e6b79f7a394c8a431fbf4ff5ac705c93f4076bb77602.json +0 -0
  104. data/spec/{bitcoin/fixtures → fixtures}/rawtx-52250a162c7d03d2e1fbc5ebd1801a88612463314b55102171c5b5d817d2d7b2.bin +0 -0
  105. data/spec/{bitcoin/fixtures → fixtures}/rawtx-b5d4e8883533f99e5903ea2cf001a133a322fa6b1370b18a16c57c946a40823d.bin +0 -0
  106. data/spec/{bitcoin/fixtures → fixtures}/rawtx-ba1ff5cd66713133c062a871a8adab92416f1e38d17786b2bf56ac5f6ffdfdf5.json +0 -0
  107. data/spec/{bitcoin/fixtures → fixtures}/rawtx-c99c49da4c38af669dea436d3e73780dfdb6c1ecf9958baa52960e8baee30e73.json +0 -0
  108. data/spec/{bitcoin/fixtures → fixtures}/rawtx-de35d060663750b3975b7997bde7fb76307cec5b270d12fcd9c4ad98b279c28c.json +0 -0
  109. data/spec/{bitcoin/fixtures → fixtures}/rawtx-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16.bin +0 -0
  110. data/spec/{bitcoin/fixtures → fixtures}/rawtx-p2wpkh.bin +0 -0
  111. data/spec/{bitcoin/fixtures → fixtures}/rawtx-p2wpkh.json +0 -0
  112. data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-04fdc38d6722ab4b12d79113fc4b2896bdcc5169710690ee4e78541b98e467b4.bin +0 -0
  113. data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-0b294c7d11dd21bcccb8393e6744fed7d4d1981a08c00e3e88838cc421f33c9f.bin +0 -0
  114. data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-3bc52ac063291ad92d95ddda5fd776a342083b95607ad32ed8bc6f8f7d30449e.bin +0 -0
  115. data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-6f0bbdd4e71a8af4305018d738184df32dbb6f27284fdebd5b56d16947f7c181.bin +0 -0
  116. data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-a220adf1902c46a39db25a24bc4178b6a88440f977a7e2cabfdd8b5c1dd35cfb.json +0 -0
  117. data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-a7c9b06e275e8674cc19a5f7d3e557c72c6d93576e635b33212dbe08ab7cdb60.bin +0 -0
  118. data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-e232e0055dbdca88bbaa79458683195a0b7c17c5b6c524a8d146721d4d4d652f.bin +0 -0
  119. data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-e232e0055dbdca88bbaa79458683195a0b7c17c5b6c524a8d146721d4d4d652f.json +0 -0
  120. data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-f80acbd2f594d04ddb0e1cacba662132104909157dff526935a3c88abe9201a5.bin +0 -0
  121. data/spec/{bitcoin/fixtures → fixtures}/script_tests.json +0 -0
  122. data/spec/{bitcoin/fixtures → fixtures}/sighash.json +0 -0
  123. data/spec/{bitcoin/fixtures → fixtures}/tx-0295028ef826b2a188409cb905b631faebb9bb3cdf14510571c5f4bd8591338f.json +0 -0
  124. data/spec/{bitcoin/fixtures → fixtures}/tx-03339a725007a279484fb6f5361f522dd1cf4d0923d30e6b973290dba4275f92.json +0 -0
  125. data/spec/{bitcoin/fixtures → fixtures}/tx-0a6a357e2f7796444e02638749d9611c008b253fb55f5dc88b739b230ed0c4c3.json +0 -0
  126. data/spec/{bitcoin/fixtures → fixtures}/tx-0ce7e5238fbdb6c086cf1b384b21b827e91cc23f360417265874a5a0d86ce367.json +0 -0
  127. data/spec/{bitcoin/fixtures → fixtures}/tx-0ef34c49f630aea17df0080728b0fc67bf5f87fbda936934a4b11b4a69d7821e.json +0 -0
  128. data/spec/{bitcoin/fixtures → fixtures}/tx-1129d2a8bd5bb3a81e54dc96a90f1f6b2544575748caa17243470935c5dd91b7.json +0 -0
  129. data/spec/{bitcoin/fixtures → fixtures}/tx-19aa42fee0fa57c45d3b16488198b27caaacc4ff5794510d0c17f173f05587ff.json +0 -0
  130. data/spec/{bitcoin/fixtures → fixtures}/tx-1a4f3b9dc4494aeedeb39f30dd37e60541b2abe3ed4977992017cc0ad4f44956.json +0 -0
  131. data/spec/{bitcoin/fixtures → fixtures}/tx-1f9191dcf2b1844ca28c6ef4b969e1d5fab70a5e3c56b7007949e55851cb0c4f.json +0 -0
  132. data/spec/{bitcoin/fixtures → fixtures}/tx-22cd5fef23684d7b304e119bedffde6f54538d3d54a5bfa237e20dc2d9b4b5ad.json +0 -0
  133. data/spec/{bitcoin/fixtures → fixtures}/tx-28204cad1d7fc1d199e8ef4fa22f182de6258a3eaafe1bbe56ebdcacd3069a5f.json +0 -0
  134. data/spec/{bitcoin/fixtures → fixtures}/tx-2958fb00b4fd6fe0353503b886eb9a193d502f4fd5fc042d5e03216ba918bbd6.json +0 -0
  135. data/spec/{bitcoin/fixtures → fixtures}/tx-29f277145749ad6efbed3ae6ce301f8d33c585ec26b7c044ad93c2f866e9e942.json +0 -0
  136. data/spec/{bitcoin/fixtures → fixtures}/tx-2c5e5376c20e9cc78d0fb771730e5d840cc2096eff0ef045b599fe92475ace1c.json +0 -0
  137. data/spec/{bitcoin/fixtures → fixtures}/tx-2c63aa814701cef5dbd4bbaddab3fea9117028f2434dddcdab8339141e9b14d1.json +0 -0
  138. data/spec/{bitcoin/fixtures → fixtures}/tx-313897799b1e37e9ecae15010e56156dddde4e683c96b0e713af95272c38aee0.json +0 -0
  139. data/spec/{bitcoin/fixtures → fixtures}/tx-326882a7f22b5191f1a0cc9962ca4b878cd969cf3b3a70887aece4d801a0ba5e.json +0 -0
  140. data/spec/{bitcoin/fixtures → fixtures}/tx-345bed8785c3282a264ffb0dbee61cde54854f10e16f1b3e75b7f2d9f62946f2.json +0 -0
  141. data/spec/{bitcoin/fixtures → fixtures}/tx-39ba7440b7103557560cc8ce258009936796485aaf8b478e66ab4cb97c66e31b.json +0 -0
  142. data/spec/{bitcoin/fixtures → fixtures}/tx-3a04d57a833367f1655cc5ec3beb587888ef4977a86caa8c8ad4ba7cc717eae7.json +0 -0
  143. data/spec/{bitcoin/fixtures → fixtures}/tx-3da75972766f0ad13319b0b461fd16823a731e44f6e9de4eb3c52d6a6fb6c8ae.json +0 -0
  144. data/spec/{bitcoin/fixtures → fixtures}/tx-4142ee4877eb116abf955a7ec6ef2dc38133b793df762b76d75e3d7d4d8badc9.json +0 -0
  145. data/spec/{bitcoin/fixtures → fixtures}/tx-44b833074e671120ba33106877b49e86ece510824b9af477a3853972bcd8d06a.json +0 -0
  146. data/spec/{bitcoin/fixtures → fixtures}/tx-46224764c7870f95b58f155bce1e38d4da8e99d42dbb632d0dd7c07e092ee5aa.json +0 -0
  147. data/spec/{bitcoin/fixtures → fixtures}/tx-5df1375ffe61ac35ca178ebb0cab9ea26dedbd0e96005dfcee7e379fa513232f.json +0 -0
  148. data/spec/{bitcoin/fixtures → fixtures}/tx-62d9a565bd7b5344c5352e3e9e5f40fa4bbd467fa19c87357216ec8777ba1cce.json +0 -0
  149. data/spec/{bitcoin/fixtures → fixtures}/tx-6327783a064d4e350c454ad5cd90201aedf65b1fc524e73709c52f0163739190.json +0 -0
  150. data/spec/{bitcoin/fixtures → fixtures}/tx-6606c366a487bff9e412d0b6c09c14916319932db5954bf5d8719f43f828a3ba.json +0 -0
  151. data/spec/{bitcoin/fixtures → fixtures}/tx-6aaf18b9f1283b939d8e5d40ff5f8a435229f4178372659cc3a0bce4e262bf78.json +0 -0
  152. data/spec/{bitcoin/fixtures → fixtures}/tx-6b48bba6f6d2286d7ec0883c0fc3085955090813a4c94980466611c798b868cc.json +0 -0
  153. data/spec/{bitcoin/fixtures → fixtures}/tx-70cfbc6690f9ab46712db44e3079ac227962b2771a9341d4233d898b521619ef.json +0 -0
  154. data/spec/{bitcoin/fixtures → fixtures}/tx-7a1a9db42f065f75110fcdb1bc415549c8ef7670417ba1d35a67f1b8adc562c1.json +0 -0
  155. data/spec/{bitcoin/fixtures → fixtures}/tx-9a768fc7d0c4bdc86e25154357ef7c0063ca21310e5740a2f12f90b7455184a7.json +0 -0
  156. data/spec/{bitcoin/fixtures → fixtures}/tx-9cad8d523a0694f2509d092c39cebc8046adae62b4e4297102d568191d9478d8.json +0 -0
  157. data/spec/{bitcoin/fixtures → fixtures}/tx-9e052eb694bd7e15906433f064dff0161a12fd325c1124537766377004023c6f.json +0 -0
  158. data/spec/{bitcoin/fixtures → fixtures}/tx-9fb65b7304aaa77ac9580823c2c06b259cc42591e5cce66d76a81b6f51cc5c28.json +0 -0
  159. data/spec/{bitcoin/fixtures → fixtures}/tx-a6ce7081addade7676cd2af75c4129eba6bf5e179a19c40c7d4cf6a5fe595954.json +0 -0
  160. data/spec/{bitcoin/fixtures → fixtures}/tx-a955032f4d6b0c9bfe8cad8f00a8933790b9c1dc28c82e0f48e75b35da0e4944.json +0 -0
  161. data/spec/{bitcoin/fixtures → fixtures}/tx-aab7ef280abbb9cc6fbaf524d2645c3daf4fcca2b3f53370e618d9cedf65f1f8.json +0 -0
  162. data/spec/{bitcoin/fixtures → fixtures}/tx-ab9805c6d57d7070d9a42c5176e47bb705023e6b67249fb6760880548298e742.json +0 -0
  163. data/spec/{bitcoin/fixtures → fixtures}/tx-ad4bcf3241e5d2ad140564e20db3567d41594cf4c2012433fe46a2b70e0d87b8.json +0 -0
  164. data/spec/{bitcoin/fixtures → fixtures}/tx-b5b598de91787439afd5938116654e0b16b7a0d0f82742ba37564219c5afcbf9.json +0 -0
  165. data/spec/{bitcoin/fixtures → fixtures}/tx-b8fd633e7713a43d5ac87266adc78444669b987a56b3a65fb92d58c2c4b0e84d.json +0 -0
  166. data/spec/{bitcoin/fixtures → fixtures}/tx-bbca0628c42cb8bf7c3f4b2ad688fa56da5308dd2a10255da89fb1f46e6e413d.json +0 -0
  167. data/spec/{bitcoin/fixtures → fixtures}/tx-bc7fd132fcf817918334822ee6d9bd95c889099c96e07ca2c1eb2cc70db63224.json +0 -0
  168. data/spec/{bitcoin/fixtures → fixtures}/tx-c192b74844e4837a34c4a5a97b438f1c111405b01b99e2d12b7c96d07fc74c04.json +0 -0
  169. data/spec/{bitcoin/fixtures → fixtures}/tx-d3d77d63709e47d9ef58f0b557800115a6b676c6a423012fbb96f45d8fcef830.json +0 -0
  170. data/spec/{bitcoin/fixtures → fixtures}/tx-e335562f7e297aadeed88e5954bc4eeb8dc00b31d829eedb232e39d672b0c009.json +0 -0
  171. data/spec/{bitcoin/fixtures → fixtures}/tx-eb3b82c0884e3efa6d8b0be55b4915eb20be124c9766245bcc7f34fdac32bccb.json +0 -0
  172. data/spec/{bitcoin/fixtures → fixtures}/tx-fee1b9b85531c8fb6cd7831f83490c7f2aa768b6eefe29854ef5e89ce7b9ecb1.json +0 -0
  173. data/spec/{bitcoin/fixtures → fixtures}/txscript-invalid-too-many-sigops-followed-by-invalid-pushdata.bin +0 -0
  174. data/spec/helpers/block_helpers.rb +58 -0
  175. data/spec/helpers/fixture_helpers.rb +20 -0
  176. data/spec/helpers/library_helpers.rb +15 -0
  177. data/spec/spec_helper.rb +109 -0
  178. data/spec/unit/bitcoin/bech32_spec.rb +187 -0
  179. data/spec/unit/bitcoin/bitcoin_spec.rb +1079 -0
  180. data/spec/unit/bitcoin/bloom_filter_spec.rb +33 -0
  181. data/spec/unit/bitcoin/builder_spec.rb +559 -0
  182. data/spec/unit/bitcoin/contracthash_spec.rb +52 -0
  183. data/spec/unit/bitcoin/ext_key_spec.rb +281 -0
  184. data/spec/unit/bitcoin/key_spec.rb +457 -0
  185. data/spec/unit/bitcoin/network_spec.rb +71 -0
  186. data/spec/unit/bitcoin/protocol/addr_spec.rb +90 -0
  187. data/spec/unit/bitcoin/protocol/aux_pow_spec.rb +45 -0
  188. data/spec/unit/bitcoin/protocol/bip143_spec.rb +334 -0
  189. data/spec/unit/bitcoin/protocol/block_spec.rb +280 -0
  190. data/spec/unit/bitcoin/protocol/getblocks_spec.rb +44 -0
  191. data/spec/unit/bitcoin/protocol/inv_spec.rb +166 -0
  192. data/spec/unit/bitcoin/protocol/notfound_spec.rb +44 -0
  193. data/spec/unit/bitcoin/protocol/parser_spec.rb +69 -0
  194. data/spec/unit/bitcoin/protocol/partial_merkle_tree_spec.rb +47 -0
  195. data/spec/unit/bitcoin/protocol/ping_spec.rb +62 -0
  196. data/spec/unit/bitcoin/protocol/tx_spec.rb +1515 -0
  197. data/spec/unit/bitcoin/protocol/txin_spec.rb +47 -0
  198. data/spec/unit/bitcoin/protocol/txout_spec.rb +36 -0
  199. data/spec/unit/bitcoin/protocol/version_spec.rb +121 -0
  200. data/spec/unit/bitcoin/script/opcodes_spec.rb +864 -0
  201. data/spec/unit/bitcoin/script/script_spec.rb +1610 -0
  202. data/spec/unit/bitcoin/secp256k1_spec.rb +138 -0
  203. data/spec/unit/bitcoin/trezor/mnemonic_spec.rb +193 -0
  204. data/spec/unit/integrations/dogecoin_spec.rb +215 -0
  205. metadata +381 -372
  206. data/lib/bitcoin/logger.rb +0 -86
  207. data/lib/bitcoin/protocol/alert.rb +0 -46
  208. data/spec/bitcoin/bech32_spec.rb +0 -160
  209. data/spec/bitcoin/bitcoin_spec.rb +0 -666
  210. data/spec/bitcoin/bloom_filter_spec.rb +0 -23
  211. data/spec/bitcoin/builder_spec.rb +0 -375
  212. data/spec/bitcoin/contracthash_spec.rb +0 -45
  213. data/spec/bitcoin/dogecoin_spec.rb +0 -176
  214. data/spec/bitcoin/ext_key_spec.rb +0 -180
  215. data/spec/bitcoin/ffi_openssl.rb +0 -45
  216. data/spec/bitcoin/fixtures/rawblock-170.json +0 -68
  217. data/spec/bitcoin/fixtures/rawblock-9.json +0 -39
  218. data/spec/bitcoin/fixtures/reorg/blk_0_to_4.dat +0 -0
  219. data/spec/bitcoin/fixtures/reorg/blk_3A.dat +0 -0
  220. data/spec/bitcoin/fixtures/reorg/blk_4A.dat +0 -0
  221. data/spec/bitcoin/fixtures/reorg/blk_5A.dat +0 -0
  222. data/spec/bitcoin/fixtures/testnet/block_0.bin +0 -0
  223. data/spec/bitcoin/fixtures/testnet/block_1.bin +0 -0
  224. data/spec/bitcoin/fixtures/testnet/block_2.bin +0 -0
  225. data/spec/bitcoin/fixtures/testnet/block_3.bin +0 -0
  226. data/spec/bitcoin/fixtures/testnet/block_4.bin +0 -0
  227. data/spec/bitcoin/fixtures/testnet/block_5.bin +0 -0
  228. data/spec/bitcoin/fixtures/txdp-1.txt +0 -32
  229. data/spec/bitcoin/fixtures/txdp-2-signed.txt +0 -19
  230. data/spec/bitcoin/fixtures/txdp-2-unsigned.txt +0 -14
  231. data/spec/bitcoin/helpers/fake_blockchain.rb +0 -183
  232. data/spec/bitcoin/key_spec.rb +0 -326
  233. data/spec/bitcoin/network_spec.rb +0 -50
  234. data/spec/bitcoin/performance/storage_spec.rb +0 -41
  235. data/spec/bitcoin/protocol/addr_spec.rb +0 -82
  236. data/spec/bitcoin/protocol/alert_spec.rb +0 -22
  237. data/spec/bitcoin/protocol/aux_pow_spec.rb +0 -45
  238. data/spec/bitcoin/protocol/bip143_spec.rb +0 -116
  239. data/spec/bitcoin/protocol/block_spec.rb +0 -208
  240. data/spec/bitcoin/protocol/getblocks_spec.rb +0 -32
  241. data/spec/bitcoin/protocol/inv_spec.rb +0 -134
  242. data/spec/bitcoin/protocol/notfound_spec.rb +0 -31
  243. data/spec/bitcoin/protocol/parser_spec.rb +0 -50
  244. data/spec/bitcoin/protocol/partial_merkle_tree_spec.rb +0 -38
  245. data/spec/bitcoin/protocol/ping_spec.rb +0 -51
  246. data/spec/bitcoin/protocol/reject.rb +0 -17
  247. data/spec/bitcoin/protocol/tx_spec.rb +0 -894
  248. data/spec/bitcoin/protocol/txin_spec.rb +0 -45
  249. data/spec/bitcoin/protocol/txout_spec.rb +0 -33
  250. data/spec/bitcoin/protocol/version_spec.rb +0 -110
  251. data/spec/bitcoin/script/opcodes_spec.rb +0 -773
  252. data/spec/bitcoin/script/script_spec.rb +0 -977
  253. data/spec/bitcoin/secp256k1_spec.rb +0 -78
  254. data/spec/bitcoin/spec_helper.rb +0 -108
  255. data/spec/bitcoin/trezor/mnemonic_spec.rb +0 -161
@@ -1,977 +0,0 @@
1
- # encoding: ascii-8bit
2
-
3
- require_relative '../spec_helper.rb'
4
- require 'bitcoin/script'
5
-
6
- include Bitcoin
7
-
8
- describe 'Bitcoin::Script' do
9
- SCRIPT = [
10
- "410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac",
11
- "47304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901",
12
- "76a91417977bca1b6287a5e6559c57ef4b6525e9d7ded688ac",
13
- "524104573b6e9f3a714440048a7b87d606bcbf9e45b8586e70a67a3665ea720c095658471a523e5d923f3f3e015626e7c900bd08560ddffeb17d33c5b52c96edb875954104039c2f4e413a26901e67ad4adbb6a4759af87bc16c7120459ecc9482fed3dd4a4502947f7b4c7782dcadc2bed513ed14d5e770452b97ae246ac2030f13b80a5141048b0f9d04e495c3c754f8c3c109196d713d0778882ef098f785570ee6043f8c192d8f84df43ebafbcc168f5d95a074dc4010b62c003e560abc163c312966b74b653ae", # multisig 2 of 3
14
- "5141040ee607b584b36e995f2e96dec35457dbb40845d0ce0782c84002134e816a6b8cbc65e9eed047ae05e10760e4113f690fd49ad73b86b04a1d7813d843f8690ace4104220a78f5f6741bb0739675c2cc200643516b02cfdfda5cba21edeaa62c0f954936b30dfd956e3e99af0a8e7665cff6ac5b429c54c418184c81fbcd4bde4088f552ae", # multisig 1 of 2
15
- "a9149471864495192e39f5f74574b6c8c513588a820487", # p2sh
16
- "6a04deadbeef", # OP_RETURN deadbeef
17
- "00141e205151c90c16475363d11b7b8c235cf6c7d695", # p2wpkh
18
- "00205d1b56b63d714eebe542309525f484b7e9d6f686b3781b6f61ef925d66d6f6a0" # p2wsh
19
- ].map{|s|[s].pack("H*")}
20
- PUBKEYS = [
21
- "04fb0123fe2c399981bc77d522e2ae3268d2ab15e9a84ae49338a4b1db3886a1ea04cdab955d81e9fa1fcb0c062cb9a5af1ad5dd5064f4afcca322402b07030ec2",
22
- "0423b8161514560bc8638054b6637ab78f400b24e5694ec8061db635d1f28a17902b14dbf4f80780da659ab24f11ded3095c780452a4004c30ab58dffac33d839a",
23
- "04f43e76afac66bf3927638b6c4f7e324513ce56d2d658ac9d24c420d09993a4464eea6141a68a4748c092ad0e8f4ac29c4a2f661ef4d22b21f20110f42fcd6f6d",
24
- ]
25
-
26
- describe "serialization" do
27
- it '#to_string' do
28
- Script.new(SCRIPT[0]).to_string.should ==
29
- "0411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3 OP_CHECKSIG"
30
-
31
- Script.new(SCRIPT[1]).to_string.should ==
32
- "304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901"
33
-
34
- #Script.new([123].pack("C")).to_string.should == "(opcode 123)"
35
- Script.new([176].pack("C")).to_string.should == "OP_NOP1"
36
- Script.from_string("1 OP_DROP 2").to_string.should == "1 OP_DROP 2"
37
-
38
- Script.from_string("4b").to_string.should == "4b"
39
- Script.from_string("4b").to_payload.should == "\x01\x4b"
40
- Script.from_string("ff").to_string.should == "ff"
41
- Script.from_string("ff").to_payload.should == "\x01\xff"
42
- Script.from_string("ffff").to_string.should == "ffff"
43
-
44
- Script.from_string( "ff"*(Script::OP_PUSHDATA1-1) ).to_payload[0] .should == [Script::OP_PUSHDATA1-1].pack("C*")
45
- Script.from_string( "ff"*Script::OP_PUSHDATA1 ).to_payload[0..1].should == [Script::OP_PUSHDATA1, Script::OP_PUSHDATA1].pack("C*")
46
- Script.from_string( "ff"*(Script::OP_PUSHDATA1+1) ).to_payload[0..1].should == [Script::OP_PUSHDATA1, Script::OP_PUSHDATA1+1].pack("C*")
47
- Script.from_string( "ff"*0xff ).to_payload[0..1].should == [Script::OP_PUSHDATA1, 0xff].pack("C*")
48
- Script.from_string( "ff"*(0xff+1) ).to_payload[0..2].should == [Script::OP_PUSHDATA2, 0x00, 0x01].pack("C*")
49
- Script.from_string( "ff"*0xffff ).to_payload[0..2].should == [Script::OP_PUSHDATA2, 0xff, 0xff].pack("C*")
50
- Script.from_string( "ff"*(0xffff+1) ).to_payload[0..4].should == [Script::OP_PUSHDATA4, 0x00, 0x00, 0x01, 0x00].pack("C*")
51
-
52
- Script.from_string("16").to_string.should == "16"
53
- Script::OP_2_16.include?(Script.from_string("16").chunks.first).should == true
54
- Script.from_string("16").to_payload.should == "\x60"
55
- Script.new("\x60").to_string.should == "16"
56
-
57
- Script.from_string("0:1:16").to_string.should == "0:1:16"
58
- Script::OP_2_16.include?(Script.from_string("0:1:16").chunks.first).should == false
59
- Script.from_string("0:1:16").to_payload.should == "\x01\x16"
60
- Script.new("\x01\x16").to_string.should == "0:1:16"
61
-
62
- Script.new("\x4d\x01\x00\x02").to_string.should == "77:1:02"
63
- Script.from_string("77:1:02").to_payload.should == "\x4d\x01\x00\x02"
64
- Script.from_string("77:1:01").to_string.should == "77:1:01"
65
- Script.from_string("77:2:0101").to_string.should == "77:2:0101"
66
- Script.from_string("78:1:01").to_string.should == "78:1:01"
67
- Script.from_string("78:2:0101").to_string.should == "78:2:0101"
68
- Script.new("\x4e\x01\x00\x00\x00\x02").to_string.should == "78:1:02"
69
- Script.from_string("78:1:02").to_payload.should == "\x4e\x01\x00\x00\x00\x02"
70
-
71
- Script.new("\x4d\x01\x00").to_string.should == "77:1:"
72
- Script.from_string("77:1:").to_payload.should == "\x4d\x01\x00"
73
-
74
- [ # mainnet tx: ebc9fa1196a59e192352d76c0f6e73167046b9d37b8302b6bb6968dfd279b767 outputs
75
- ["\x01", "238:1:01", true],
76
- ["\x02\x01", "238:2:0201", true],
77
- ["L", "238:1:4c", true],
78
- ["L\x02\x01", "76:2:01", nil],
79
- ["M", "238:1:4d", true],
80
- ["M\xff\xff\x01", "238:4:4dffff01", true],
81
- ["N", "238:1:4e", true],
82
- ["N\xff\xff\xff\xff\x01", "238:6:4effffffff01", true],
83
- ].each{|payload,string,parse_invalid|
84
- Script.new(payload).to_string.should == string
85
- Script.new(payload).instance_eval{ @parse_invalid }.should == parse_invalid
86
- Script.from_string(string).to_payload == payload
87
- }
88
-
89
- Bitcoin::Script.from_string("(opcode-230) 4 1 2").to_string.should == "(opcode-230) 4 1 2"
90
- Bitcoin::Script.from_string("(opcode 230) 4 1 2").to_string.should == "(opcode-230) 4 1 2"
91
- Bitcoin::Script.from_string("(opcode-65449) 4 1 2").to_string.should == "OP_INVALIDOPCODE OP_HASH160 4 1 2"
92
-
93
- # found in testnet3 block 0000000000ac85bb2530a05a4214a387e6be02b22d3348abc5e7a5d9c4ce8dab transactions
94
- Script.new("\xff\xff\xff\xff").to_string.should == "OP_INVALIDOPCODE OP_INVALIDOPCODE OP_INVALIDOPCODE OP_INVALIDOPCODE"
95
- Script.from_string(Script.new("\xff\xff\xff\xff").to_string).raw.should == "\xFF\xFF\xFF\xFF"
96
- Script.new("\xff\xff\xff").to_string.should == "OP_INVALIDOPCODE OP_INVALIDOPCODE OP_INVALIDOPCODE"
97
- Script.from_string(Script.new("\xff\xff\xff").to_string).raw.should == "\xFF\xFF\xFF"
98
- end
99
-
100
- it 'Script#binary_from_string' do
101
- str = Script.new(SCRIPT[0]).to_string
102
- Script.binary_from_string(str).unpack("H*")[0].should == SCRIPT[0].unpack("H*")[0]
103
- Script.new(Script.binary_from_string(str)).to_string.should == str
104
-
105
- str = Script.new(SCRIPT[1]).to_string
106
- Script.binary_from_string(str).unpack("H*")[0].should == SCRIPT[1].unpack("H*")[0]
107
- Script.new(Script.binary_from_string(str)).to_string.should == str
108
- # TODO make tests for OP_PUSHDATA1, OP_PUSHDATA2, OP_PUSHDATA4 cases
109
-
110
- string = "2 OP_TOALTSTACK 0 OP_TOALTSTACK OP_TUCK OP_CHECKSIG OP_SWAP OP_HASH160 3cd1def404e12a85ead2b4d3f5f9f817fb0d46ef OP_EQUAL OP_BOOLAND OP_FROMALTSTACK OP_ADD"
111
- Script.from_string(string).to_string.should == string
112
-
113
- Script.from_string("0 OP_DROP 2 3 4").to_string.should == "0 OP_DROP 2 3 4"
114
-
115
- Script.from_string("OP_EVAL").to_string.should == "OP_NOP1"
116
- Script.from_string("OP_NOP1").to_string.should == "OP_NOP1" # test opcodes_alias table
117
- Script.from_string("OP_NOP").to_string.should == "OP_NOP"
118
- Script.from_string("1").to_string.should == "1"
119
-
120
- Script.from_string("0 ffff OP_CODESEPARATOR 1 ffff 1 OP_CHECKMULTISIG").to_string.should == "0 ffff OP_CODESEPARATOR 1 ffff 1 OP_CHECKMULTISIG"
121
-
122
- [1,2,4].all?{|n| script = "OP_PUSHDATA#{n} 01 ff"
123
- Bitcoin::Script.binary_from_string(script) == Bitcoin::Script.binary_from_string( Bitcoin::Script.from_string(script).to_string )
124
- }.should == true
125
-
126
- #Script.from_string("-100").to_string.should == "OP_NOP"
127
- #Script.from_string("100").to_string.should == "100"
128
-
129
- proc{ Script.from_string("OP_NOP OP_UNKOWN") }.should.raise(Script::ScriptOpcodeError).message.should == "OP_UNKOWN not defined!"
130
- end
131
- end
132
-
133
- describe "get keys/addresses" do
134
- it '#get_pubkey' do
135
- Script.new(SCRIPT[0]).get_pubkey.should ==
136
- "0411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3"
137
- end
138
-
139
- it '#get_pubkey_address' do
140
- Script.new(SCRIPT[0]).get_pubkey_address.should ==
141
- "12cbQLTFMXRnSzktFkuoG3eHoMeFtpTu3S"
142
- end
143
-
144
- it "#get_hash160" do
145
- Script.new(SCRIPT[2]).get_hash160.should ==
146
- "17977bca1b6287a5e6559c57ef4b6525e9d7ded6"
147
- Script.from_string("OP_DUP OP_HASH160 0 OP_EQUALVERIFY OP_CHECKSIG")
148
- .get_hash160.should == nil
149
- Script.new(SCRIPT[7]).get_hash160.should == "1e205151c90c16475363d11b7b8c235cf6c7d695"
150
- end
151
-
152
- it "#get_hash160_address" do
153
- Script.new(SCRIPT[2]).get_hash160_address.should ==
154
- "139k1g5rtTsL4aGZbcASH3Fv3fUh9yBEdW"
155
- end
156
-
157
- it "#get_multisig_pubkeys" do
158
- Script.new(SCRIPT[3]).get_multisig_pubkeys.should == [
159
- "04573b6e9f3a714440048a7b87d606bcbf9e45b8586e70a67a3665ea720c095658471a523e5d923f3f3e015626e7c900bd08560ddffeb17d33c5b52c96edb87595",
160
- "04039c2f4e413a26901e67ad4adbb6a4759af87bc16c7120459ecc9482fed3dd4a4502947f7b4c7782dcadc2bed513ed14d5e770452b97ae246ac2030f13b80a51",
161
- "048b0f9d04e495c3c754f8c3c109196d713d0778882ef098f785570ee6043f8c192d8f84df43ebafbcc168f5d95a074dc4010b62c003e560abc163c312966b74b6"].map{|pk| [pk].pack("H*")}
162
- Script.from_string("3 #{PUBKEYS[0..2].join(' ')} 3 OP_CHECKMULTISIG")
163
- .get_multisig_pubkeys.should == [
164
- "04fb0123fe2c399981bc77d522e2ae3268d2ab15e9a84ae49338a4b1db3886a1ea04cdab955d81e9fa1fcb0c062cb9a5af1ad5dd5064f4afcca322402b07030ec2",
165
- "0423b8161514560bc8638054b6637ab78f400b24e5694ec8061db635d1f28a17902b14dbf4f80780da659ab24f11ded3095c780452a4004c30ab58dffac33d839a",
166
- "04f43e76afac66bf3927638b6c4f7e324513ce56d2d658ac9d24c420d09993a4464eea6141a68a4748c092ad0e8f4ac29c4a2f661ef4d22b21f20110f42fcd6f6d"].map{|k|[k].pack("H*")}
167
- end
168
-
169
- it "#get_multisig_addresses" do
170
- Script.new(SCRIPT[3]).get_multisig_addresses.should == [
171
- "1JiaVc3N3U3CwwcLtzNX1Q4eYfeYxVjtuj", "19Fm2gY7qDTXriNTEhFY2wjxbHna3Gvenk",
172
- "1B6k6g1d2L975i7beAbiBRxfBWhxomPxvy"]
173
- Script.new(SCRIPT[4]).get_multisig_addresses.should == [
174
- "1F2Nnyn7niMcheiYhkHrkc18aDxEkFowy5", "1EE7JGimkV7QqyHwXDJvk3b1yEN4ZUWeqx"]
175
-
176
- # from tx 274f8be3b7b9b1a220285f5f71f61e2691dd04df9d69bb02a8b3b85f91fb1857, second pubkey has invalid encoding.
177
- output = "1 0351efb6e91a31221652105d032a2508275f374cea63939ad72f1b1e02f477da78 00f2b7816db49d55d24df7bdffdbc1e203b424e8cd39f5651ab938e5e4a193569e 2 OP_CHECKMULTISIG"
178
- Bitcoin::Script.from_string(output).get_multisig_addresses.should == ["1NdB761LmTmrJixxp93nz7pEiCx5cKPW44", nil]
179
- end
180
-
181
- it "#get_p2sh_address" do
182
- Script.new(SCRIPT[5]).get_p2sh_address.should ==
183
- "3FDuvkgzsW7LpzL9RBjtjvL7bFXCEeZ7xi"
184
- end
185
-
186
- it "#get_address" do
187
- Script.new(SCRIPT[0]).get_address.should ==
188
- "12cbQLTFMXRnSzktFkuoG3eHoMeFtpTu3S"
189
- Script.new(SCRIPT[1]).get_address.should == nil
190
- Script.new(SCRIPT[2]).get_address.should ==
191
- "139k1g5rtTsL4aGZbcASH3Fv3fUh9yBEdW"
192
- Script.new(SCRIPT[3]).get_address.should ==
193
- "1JiaVc3N3U3CwwcLtzNX1Q4eYfeYxVjtuj"
194
- Script.new(SCRIPT[4]).get_address.should ==
195
- "1F2Nnyn7niMcheiYhkHrkc18aDxEkFowy5"
196
- Script.new(SCRIPT[5]).get_address.should ==
197
- "3FDuvkgzsW7LpzL9RBjtjvL7bFXCEeZ7xi"
198
- Script.new(SCRIPT[7]).get_address.should ==
199
- "bc1qrcs9z5wfpstyw5mr6ydhhrprtnmv0454y6laym"
200
- Script.new(SCRIPT[8]).get_address.should ==
201
- "bc1qt5d4dd3aw98whe2zxz2jtayykl5ada5xkdupkmmpa7f96ekk76sqvmrunq"
202
- end
203
-
204
- it "#get_addresses" do
205
- Script.new(SCRIPT[0]).get_addresses.
206
- should == ["12cbQLTFMXRnSzktFkuoG3eHoMeFtpTu3S"]
207
- Script.new(SCRIPT[3]).get_addresses
208
- .should == ["1JiaVc3N3U3CwwcLtzNX1Q4eYfeYxVjtuj",
209
- "19Fm2gY7qDTXriNTEhFY2wjxbHna3Gvenk", "1B6k6g1d2L975i7beAbiBRxfBWhxomPxvy"]
210
- Script.new(SCRIPT[7]).get_addresses.
211
- should == ["bc1qrcs9z5wfpstyw5mr6ydhhrprtnmv0454y6laym"]
212
- end
213
-
214
- it "should get op_return data" do
215
- Script.new(SCRIPT[6]).get_op_return_data.should == "deadbeef"
216
- Script.new(SCRIPT[1]).get_op_return_data.should == nil
217
- Script.from_string("OP_RETURN").get_op_return_data.should == nil
218
- Script.from_string("OP_RETURN dead beef").get_op_return_data.should == nil
219
- Script.from_string("OP_RETURN deadbeef").get_op_return_data.should == "deadbeef"
220
- Script.from_string("OP_RETURN OP_CHECKSIG").get_op_return_data.should == "ac00"
221
- end
222
- end
223
-
224
- describe "determine type" do
225
-
226
- it '#is_standard?' do
227
- Script.new(SCRIPT[0]).is_standard?.should == true
228
- Script.new(SCRIPT[1]).is_standard?.should == false
229
- Script.new(SCRIPT[2]).is_standard?.should == true
230
- Script.new(SCRIPT[3]).is_standard?.should == true
231
- Script.new(SCRIPT[4]).is_standard?.should == true
232
- Script.new(SCRIPT[5]).is_standard?.should == true
233
- Script.new(SCRIPT[6]).is_standard?.should == true
234
- Script.new(SCRIPT[7]).is_standard?.should == true
235
- Script.new(SCRIPT[8]).is_standard?.should == true
236
- end
237
-
238
- it '#is_pubkey?' do
239
- Script.new(SCRIPT[0]).is_pubkey?.should == true
240
- Script.new(SCRIPT[1]).is_pubkey?.should == false
241
- Script.new(SCRIPT[2]).is_pubkey?.should == false
242
- Script.new(SCRIPT[3]).is_pubkey?.should == false
243
- Script.new(SCRIPT[4]).is_send_to_ip?.should == false
244
- Script.new(SCRIPT[5]).is_pubkey?.should == false
245
- Script.new(SCRIPT[6]).is_pubkey?.should == false
246
- Script.new(SCRIPT[7]).is_pubkey?.should == false
247
- Script.new(SCRIPT[8]).is_pubkey?.should == false
248
- Script.from_string("0 OP_CHECKSIG").is_pubkey?.should == false # testnet aba0441c4c9933dcd7db789c39053739ec435ab742ed2c23c05f22f1488c0bfd
249
- end
250
-
251
- it "#is_hash160?" do
252
- Script.new(SCRIPT[0]).is_hash160?.should == false
253
- Script.new(SCRIPT[1]).is_pubkey?.should == false
254
- Script.new(SCRIPT[2]).is_hash160?.should == true
255
- Script.from_string("OP_DUP OP_HASH160 0 OP_EQUALVERIFY OP_CHECKSIG")
256
- .is_hash160?.should == false
257
- Script.new(SCRIPT[5]).is_hash160?.should == false
258
- Script.new(SCRIPT[6]).is_hash160?.should == false
259
- Script.new(SCRIPT[7]).is_hash160?.should == false
260
- Script.new(SCRIPT[8]).is_hash160?.should == false
261
- end
262
-
263
- it "#is_multisig?" do
264
- Script.new(SCRIPT[3]).is_multisig?.should == true
265
- Script.new(SCRIPT[4]).is_multisig?.should == true
266
- Script.new(SCRIPT[0]).is_multisig?.should == false
267
- Script.new(SCRIPT[6]).is_multisig?.should == false
268
- Script.new(SCRIPT[7]).is_multisig?.should == false
269
- Script.new(SCRIPT[8]).is_multisig?.should == false
270
- Script.new("OP_DUP OP_DROP 2 #{PUBKEYS[0..2].join(' ')} 3 OP_CHECKMULTISIG")
271
- .is_multisig?.should == false
272
- Script.new("OP_DROP OP_CHECKMULTISIG").is_multisig?.should == false
273
- Script.from_string("d366fb5cbf048801b1bf0742bb0d873f65afb406f41756bd4a31865870f6a928 OP_DROP 2 02aae4b5cd593da83679a9c5cadad4c180c008a40dd3ed240cceb2933b9912da36 03a5aebd8b1b6eec06abc55fb13c72a9ed2143f9eed7d665970e38853d564bf1ab OP_CHECKMULTISIG").is_multisig?.should == false
274
- end
275
-
276
- it '#is_p2sh?' do
277
- Script.new(SCRIPT[0]).is_p2sh?.should == false
278
- Script.new(SCRIPT[1]).is_p2sh?.should == false
279
- Script.new(SCRIPT[2]).is_p2sh?.should == false
280
- Script.new(SCRIPT[3]).is_p2sh?.should == false
281
- Script.new(SCRIPT[4]).is_p2sh?.should == false
282
- Script.new(SCRIPT[5]).is_p2sh?.should == true
283
- Script.new(SCRIPT[6]).is_p2sh?.should == false
284
- Script.new(SCRIPT[7]).is_p2sh?.should == false
285
- Script.new(SCRIPT[8]).is_p2sh?.should == false
286
- Script.from_string("OP_DUP OP_HASH160 b689ebc262f50297139e7d16c4f8909e14ed4322 OP_EQUALVERIFY OP_CHECKSIGVERIFY OP_HASH160 1b6246121883816fc0637e4aa280aca1df219b1a OP_EQUAL")
287
- .is_p2sh?.should == false
288
- end
289
-
290
- it '#is_op_return?' do
291
- Script.new(SCRIPT[0]).is_op_return?.should == false
292
- Script.new(SCRIPT[1]).is_op_return?.should == false
293
- Script.new(SCRIPT[2]).is_op_return?.should == false
294
- Script.new(SCRIPT[3]).is_op_return?.should == false
295
- Script.new(SCRIPT[4]).is_op_return?.should == false
296
- Script.new(SCRIPT[5]).is_op_return?.should == false
297
- Script.new(SCRIPT[6]).is_op_return?.should == true
298
- Script.new(SCRIPT[7]).is_op_return?.should == false
299
- Script.new(SCRIPT[8]).is_op_return?.should == false
300
- Script.from_string("OP_RETURN dead beef").is_op_return?.should == false
301
- Script.from_string("OP_RETURN deadbeef").is_op_return?.should == true
302
- Script.from_string("OP_RETURN OP_CHECKSIG").is_op_return?.should == true
303
- end
304
-
305
- it '#is_witness_v0_keyhash?' do
306
- Script.new(SCRIPT[0]).is_witness_v0_keyhash?.should == false
307
- Script.new(SCRIPT[1]).is_witness_v0_keyhash?.should == false
308
- Script.new(SCRIPT[2]).is_witness_v0_keyhash?.should == false
309
- Script.new(SCRIPT[3]).is_witness_v0_keyhash?.should == false
310
- Script.new(SCRIPT[4]).is_witness_v0_keyhash?.should == false
311
- Script.new(SCRIPT[5]).is_witness_v0_keyhash?.should == false
312
- Script.new(SCRIPT[6]).is_witness_v0_keyhash?.should == false
313
- Script.new(SCRIPT[7]).is_witness_v0_keyhash?.should == true
314
- Script.new(SCRIPT[8]).is_witness_v0_keyhash?.should == false
315
- end
316
-
317
- it '#is_witness_v0_scripthash?' do
318
- Script.new(SCRIPT[0]).is_witness_v0_scripthash?.should == false
319
- Script.new(SCRIPT[1]).is_witness_v0_scripthash?.should == false
320
- Script.new(SCRIPT[2]).is_witness_v0_scripthash?.should == false
321
- Script.new(SCRIPT[3]).is_witness_v0_scripthash?.should == false
322
- Script.new(SCRIPT[4]).is_witness_v0_scripthash?.should == false
323
- Script.new(SCRIPT[5]).is_witness_v0_scripthash?.should == false
324
- Script.new(SCRIPT[6]).is_witness_v0_scripthash?.should == false
325
- Script.new(SCRIPT[7]).is_witness_v0_scripthash?.should == false
326
- Script.new(SCRIPT[8]).is_witness_v0_scripthash?.should == true
327
- end
328
-
329
- it "#type" do
330
- Script.new(SCRIPT[0]).type.should == :pubkey
331
- Script.new(SCRIPT[1]).type.should == :unknown
332
- Script.new(SCRIPT[2]).type.should == :hash160
333
- Script.new(SCRIPT[3]).type.should == :multisig
334
- Script.new(SCRIPT[4]).type.should == :multisig
335
- Script.new(SCRIPT[5]).type.should == :p2sh
336
- Script.new(SCRIPT[6]).type.should == :op_return
337
- Script.new(SCRIPT[7]).type.should == :witness_v0_keyhash
338
- Script.new(SCRIPT[8]).type.should == :witness_v0_scripthash
339
- Script.from_string("OP_RETURN OP_CHECKSIG").type.should == :op_return
340
- Script.from_string("OP_RETURN dead beef").type.should == :unknown
341
- end
342
-
343
- end
344
-
345
- describe "generate scripts" do
346
-
347
- it "should generate pubkey script" do
348
- Script.to_pubkey_script(PUBKEYS[0]).should ==
349
- Script.from_string("#{PUBKEYS[0]} OP_CHECKSIG").raw
350
- Script.to_pubkey_script(PUBKEYS[1]).should ==
351
- Script.from_string("#{PUBKEYS[1]} OP_CHECKSIG").raw
352
- end
353
-
354
- it "should generate hash160 script" do
355
- Script.to_address_script('16Tc7znw2mfpWcqS84vBFfJ7PyoeHaXSz9')
356
- .should == ["76a9143be0c2daaabbf3d53e47352c19d1e8f047e2f94188ac"].pack("H*")
357
- hash160 = Bitcoin.hash160_from_address('16Tc7znw2mfpWcqS84vBFfJ7PyoeHaXSz9')
358
- Script.to_hash160_script(hash160)
359
- .should == Script.from_string("OP_DUP OP_HASH160 #{hash160} OP_EQUALVERIFY OP_CHECKSIG").raw
360
- Script.to_address_script('mr1jU3Adw2pkvxTLvQA4MKpXB9Dynj9cXF')
361
- .should == nil
362
- end
363
-
364
- it "should generate multisig script" do
365
- Script.to_multisig_script(2, *PUBKEYS[0..2]).should ==
366
- Script.from_string("2 #{PUBKEYS[0..2].join(' ')} 3 OP_CHECKMULTISIG").raw
367
- Script.to_multisig_script(1, *PUBKEYS[0..1]).should ==
368
- Script.from_string("1 #{PUBKEYS[0..1].join(' ')} 2 OP_CHECKMULTISIG").raw
369
-
370
- m=n=16; Bitcoin::Script.new(Bitcoin::Script.to_multisig_script(m, *(["a"]*n))).to_string
371
- .should == "16 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 16 OP_CHECKMULTISIG"
372
- m=n=17; Bitcoin::Script.new(Bitcoin::Script.to_multisig_script(m, *(["a"]*n))).to_string
373
- .should == "0:1:11 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 0:1:11 OP_CHECKMULTISIG"
374
- m=n=20; Bitcoin::Script.new(Bitcoin::Script.to_multisig_script(m, *(["a"]*n))).to_string
375
- .should == "0:1:14 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 0:1:14 OP_CHECKMULTISIG"
376
- end
377
-
378
- it "should generate p2sh script" do
379
- address = "3CkxTG25waxsmd13FFgRChPuGYba3ar36B"
380
- hash160 = Bitcoin.hash160_from_address address
381
- Script.to_p2sh_script(hash160).should ==
382
- Script.from_string("OP_HASH160 #{hash160} OP_EQUAL").raw
383
- end
384
-
385
- it "to_witness_hash160_script" do
386
- hash160 = Bitcoin.hash160('025476c2e83188368da1ff3e292e7acafcdb3566bb0ad253f62fc70f07aeee6357')
387
- Script.to_witness_hash160_script(hash160).should == Script.new("00141d0f172a0ecb48aee1be1f2687d2963ae33f71a1".htb).raw
388
- end
389
-
390
- it "should generate p2wsh script" do
391
- witness_script = '21026dccc749adc2a9d0d89497ac511f760f45c47dc5ed9cf352a58ac706453880aeadab210255a9626aebf5e29c0e6538428ba0d1dcf6ca98ffdf086aa8ced5e0d0215ea465ac'
392
- sha256 = Bitcoin.sha256(witness_script)
393
- Script.to_witness_p2sh_script(sha256).should == Script.new("00205d1b56b63d714eebe542309525f484b7e9d6f686b3781b6f61ef925d66d6f6a0".htb).raw
394
- end
395
-
396
- it "should generate op_return script" do
397
- Script.to_op_return_script("deadbeef").should == SCRIPT[6]
398
- Script.to_op_return_script.should == Script.from_string("OP_RETURN").raw
399
- end
400
-
401
- it "should determine type for address script" do
402
- address = '16Tc7znw2mfpWcqS84vBFfJ7PyoeHaXSz9'
403
- hash160 = Bitcoin.hash160_from_address address
404
- Script.to_address_script(address).should ==
405
- Script.from_string("OP_DUP OP_HASH160 #{hash160} OP_EQUALVERIFY OP_CHECKSIG").raw
406
-
407
- address = "3CkxTG25waxsmd13FFgRChPuGYba3ar36B"
408
- hash160 = Bitcoin.hash160_from_address address
409
- Script.to_p2sh_script(hash160).should ==
410
- Script.from_string("OP_HASH160 #{hash160} OP_EQUAL").raw
411
- end
412
-
413
- end
414
-
415
- describe "generate script sigs" do
416
- before do
417
- @sig = '3045022062437a8f60651cd968137355775fa8bdb83d4ca717fdbc08bf9868a051e0542f022100f5cd626c15ef0de0803ddf299e8895743e7ff484d6335874edfe086ee0a08fec'.htb
418
- end
419
-
420
- it "should generate pubkey script sig" do
421
- pub = '04bc3e2b520d4be3e2651f2ba554392ea31edd69d2081186ab98acda3c4bf45e41a5f6e093277b774b5893347e38ffafce2b9e82226e6e0b378cf79b8c2eed983c'.htb
422
- expected_script = '483045022062437a8f60651cd968137355775fa8bdb83d4ca717fdbc08bf9868a051e0542f022100f5cd626c15ef0de0803ddf299e8895743e7ff484d6335874edfe086ee0a08fec014104bc3e2b520d4be3e2651f2ba554392ea31edd69d2081186ab98acda3c4bf45e41a5f6e093277b774b5893347e38ffafce2b9e82226e6e0b378cf79b8c2eed983c'.htb
423
-
424
- Script.to_pubkey_script_sig(@sig, pub).should == expected_script
425
- end
426
-
427
- it "should accept a compressed public key as input" do
428
- pub = '02bc3e2b520d4be3e2651f2ba554392ea31edd69d2081186ab98acda3c4bf45e41'.htb
429
- expected_script = '483045022062437a8f60651cd968137355775fa8bdb83d4ca717fdbc08bf9868a051e0542f022100f5cd626c15ef0de0803ddf299e8895743e7ff484d6335874edfe086ee0a08fec012102bc3e2b520d4be3e2651f2ba554392ea31edd69d2081186ab98acda3c4bf45e41'.htb
430
-
431
- Script.to_pubkey_script_sig(@sig, pub).should == expected_script
432
- end
433
-
434
- it "should reject an improperly encoding public key" do
435
- # Not binary encoded, like it's supposed to be.
436
- pub = '02bc3e2b520d4be3e2651f2ba554392ea31edd69d2081186ab98acda3c4bf45e41'
437
-
438
- lambda {
439
- Script.to_pubkey_script_sig(@sig, pub)
440
- }.should.raise
441
- end
442
-
443
- it "should support different hash types" do
444
- hash_type = Script::SIGHASH_TYPE[:single]
445
- pub = '04bc3e2b520d4be3e2651f2ba554392ea31edd69d2081186ab98acda3c4bf45e41a5f6e093277b774b5893347e38ffafce2b9e82226e6e0b378cf79b8c2eed983c'.htb
446
- expected_script = '483045022062437a8f60651cd968137355775fa8bdb83d4ca717fdbc08bf9868a051e0542f022100f5cd626c15ef0de0803ddf299e8895743e7ff484d6335874edfe086ee0a08fec034104bc3e2b520d4be3e2651f2ba554392ea31edd69d2081186ab98acda3c4bf45e41a5f6e093277b774b5893347e38ffafce2b9e82226e6e0b378cf79b8c2eed983c'.htb
447
-
448
- Script.to_pubkey_script_sig(@sig, pub, hash_type).should == expected_script
449
- end
450
-
451
- it "should generate multisig script sig" do
452
- hash_type = Script::SIGHASH_TYPE[:none]
453
- expected_script = '00483045022062437a8f60651cd968137355775fa8bdb83d4ca717fdbc08bf9868a051e0542f022100f5cd626c15ef0de0803ddf299e8895743e7ff484d6335874edfe086ee0a08fec02483045022062437a8f60651cd968137355775fa8bdb83d4ca717fdbc08bf9868a051e0542f022100f5cd626c15ef0de0803ddf299e8895743e7ff484d6335874edfe086ee0a08fec02'.htb
454
-
455
- Script.to_multisig_script_sig(@sig, @sig, hash_type).should == expected_script
456
- end
457
- end
458
-
459
-
460
- describe "signatures_count" do
461
-
462
- it "should be zero in data-only scripts" do
463
- [false, true].each do |accurate|
464
- Script.from_string("").sigops_count_accurate(accurate).should == 0
465
- Script.from_string("DEADBEEF").sigops_count_accurate(accurate).should == 0
466
- Script.from_string("DEAD BEEF").sigops_count_accurate(accurate).should == 0
467
- Script.from_string("DE AD BE EF").sigops_count_accurate(accurate).should == 0
468
- Script.from_string("OP_NOP").sigops_count_accurate(accurate).should == 0
469
- Script.from_string("0").sigops_count_accurate(accurate).should == 0
470
- Script.from_string("0 1").sigops_count_accurate(accurate).should == 0
471
- Script.from_string("0 1 2 3").sigops_count_accurate(accurate).should == 0
472
- end
473
- end
474
-
475
- it "should count sigops" do
476
- [false, true].each do |accurate|
477
- Script.from_string("OP_CHECKSIG").sigops_count_accurate(accurate).should == 1
478
- Script.from_string("OP_CHECKSIGVERIFY").sigops_count_accurate(accurate).should == 1
479
- Script.from_string("OP_CHECKSIG OP_CHECKSIGVERIFY").sigops_count_accurate(accurate).should == 2
480
- Script.from_string("OP_CHECKSIG OP_CHECKSIG OP_CHECKSIG OP_CHECKSIG").sigops_count_accurate(accurate).should == 4
481
- Script.from_string("1 OP_CHECKSIG 2 OP_CHECKSIG DEADBEEF OP_CHECKSIG 3 OP_CHECKSIG 4").sigops_count_accurate(accurate).should == 4
482
- end
483
- end
484
-
485
- it "should count multisig as 20 sigops in legact inaccurate mode" do
486
- Script.from_string("OP_CHECKMULTISIG").sigops_count_accurate(false).should == 20
487
- Script.from_string("OP_CHECKMULTISIGVERIFY").sigops_count_accurate(false).should == 20
488
- Script.from_string("OP_CHECKMULTISIG OP_CHECKMULTISIGVERIFY").sigops_count_accurate(false).should == 40
489
- Script.from_string("1 OP_CHECKMULTISIG").sigops_count_accurate(false).should == 20
490
- Script.from_string("5 OP_CHECKMULTISIG").sigops_count_accurate(false).should == 20
491
- Script.from_string("40 OP_CHECKMULTISIG").sigops_count_accurate(false).should == 20
492
- end
493
-
494
- it "should count multisig accurately using number of pubkeys" do
495
- Script.from_string("1 OP_CHECKMULTISIG").sigops_count_accurate(true).should == 1
496
- Script.from_string("1 OP_CHECKMULTISIGVERIFY").sigops_count_accurate(true).should == 1
497
- Script.from_string("2 OP_CHECKMULTISIG").sigops_count_accurate(true).should == 2
498
- Script.from_string("2 OP_CHECKMULTISIGVERIFY").sigops_count_accurate(true).should == 2
499
- Script.from_string("15 OP_CHECKMULTISIG").sigops_count_accurate(true).should == 15
500
- Script.from_string("15 OP_CHECKMULTISIGVERIFY").sigops_count_accurate(true).should == 15
501
- Script.from_string("16 OP_CHECKMULTISIG").sigops_count_accurate(true).should == 16
502
- Script.from_string("16 OP_CHECKMULTISIGVERIFY").sigops_count_accurate(true).should == 16
503
- Script.from_string("4 OP_CHECKMULTISIG 7 OP_CHECKMULTISIGVERIFY").sigops_count_accurate(true).should == 11
504
- end
505
-
506
- it "should count multisig as 20 sigops in accurate mode when the pubkey count is missing" do
507
- Script.from_string("OP_CHECKMULTISIG").sigops_count_accurate(true).should == 20
508
- Script.from_string("OP_CHECKMULTISIGVERIFY").sigops_count_accurate(true).should == 20
509
- end
510
-
511
- it "should count multisig as 20 sigops when pubkey count is not OP_{1,...,16}, but bignum as pushdata" do
512
- Script.from_string("#{Script::OP_PUSHDATA1}:1:01 OP_CHECKMULTISIG").sigops_count_accurate(true).should == 20
513
- Script.from_string("#{Script::OP_PUSHDATA1}:1:02 OP_CHECKMULTISIGVERIFY").sigops_count_accurate(true).should == 20
514
- end
515
-
516
- it "should count multisig as 20 sigops in accurate mode when the pubkey count is out of bounds" do
517
- Script.from_string("0 OP_CHECKMULTISIG").sigops_count_accurate(true).should == 20
518
- Script.from_string("0 OP_CHECKMULTISIGVERIFY").sigops_count_accurate(true).should == 20
519
- Script.from_string("0 OP_CHECKMULTISIG 0 OP_CHECKMULTISIGVERIFY").sigops_count_accurate(true).should == 40
520
- Script.from_string("DEADBEEF OP_CHECKMULTISIG").sigops_count_accurate(true).should == 20
521
- Script.from_string("#{Script::OP_PUSHDATA1}:1:11 OP_CHECKMULTISIG").sigops_count_accurate(true).should == 20
522
- end
523
-
524
- it "should extract signature count from P2SH scriptSig" do
525
-
526
- # Given a P2SH input script (the one with the signatures and a serialized script inside)
527
- # This should count as 12 sigops (1 + 4 + 7)
528
- script = Script.from_string("OP_CHECKSIG 4 OP_CHECKMULTISIG 7 OP_CHECKMULTISIGVERIFY")
529
-
530
- # Serialize the script to be used as a plain pushdata (which will be decoded as a script).
531
- serialized_script = Script.new("").append_pushdata(script.to_binary)
532
-
533
- # If empty should return 0.
534
- Script.from_string("").sigops_count_for_p2sh.should == 0
535
-
536
- # If ends with OP_N
537
- Script.from_string("0").sigops_count_for_p2sh.should == 0
538
- Script.from_string("1").sigops_count_for_p2sh.should == 0
539
- Script.from_string("5").sigops_count_for_p2sh.should == 0
540
- Script.from_string("16").sigops_count_for_p2sh.should == 0
541
-
542
- # If ends with opcode
543
- Script.from_string("OP_NOP").sigops_count_for_p2sh.should == 0
544
- Script.from_string("OP_HASH160").sigops_count_for_p2sh.should == 0
545
- Script.from_string("OP_CHECKSIG").sigops_count_for_p2sh.should == 0
546
- Script.from_string("DEADBEEF OP_NOP").sigops_count_for_p2sh.should == 0
547
- Script.from_string("DEADBEEF OP_HASH160").sigops_count_for_p2sh.should == 0
548
- Script.from_string("DEADBEEF OP_CHECKSIG").sigops_count_for_p2sh.should == 0
549
-
550
- # If only has the script, should parse it well
551
- serialized_script.sigops_count_for_p2sh.should == 12
552
-
553
- # If ends with the script, should also parse well.
554
- Script.new(Script.from_string("DEADBEEF CAFEBABE").to_binary + serialized_script.to_binary).sigops_count_for_p2sh.should == 12
555
- Script.new(Script.from_string("DEADBEEF 1").to_binary + serialized_script.to_binary).sigops_count_for_p2sh.should == 12
556
-
557
- # If has the script, but ends with non-script, should return 0
558
- # DEADBEEF is a script with OP_CHECKSIGVERIFY in it, so we wrap it in a serialized script with plain pushdata to have 0 count.
559
- Script.new(serialized_script.to_binary + Script.new("").append_pushdata(Script.from_string("DEADBEEF").to_binary).to_binary).sigops_count_for_p2sh.should == 0
560
- Script.new(serialized_script.to_binary + Script.from_string("1").to_binary).sigops_count_for_p2sh.should == 0
561
- end
562
-
563
- it "should count sigops up until an invalid OP_PUSHDATA" do
564
- script_binary = Bitcoin::Protocol.read_binary_file(fixtures_path("txscript-invalid-too-many-sigops-followed-by-invalid-pushdata.bin"))
565
- Script.new(script_binary).sigops_count_accurate(false).should == 39998
566
- end
567
-
568
- end
569
-
570
- it '#run' do
571
- script = SCRIPT[1] + SCRIPT[0]
572
- Script.new(script).run.should == true
573
-
574
- Script.from_string("1 OP_DUP OP_DROP 1 OP_EQUAL")
575
- .run.should == true
576
- Script.from_string("1 OP_DUP OP_DROP 1 OP_EQUAL")
577
- .run.should == true
578
- Script.from_string("foo OP_DUP OP_DROP foo OP_EQUAL")
579
- .run.should == true
580
- Script.from_string("bar foo OP_DUP OP_DROP bar OP_EQUAL")
581
- .run.should == false
582
-
583
- Script.from_string("1 OP_DROP 2").run.should == true
584
-
585
- # testnet3 tx: 5dea81f9d9d2ea6d06ce23ff225d1e240392519017643f75c96fa2e4316d948a
586
- script = Script.new( ["0063bac0d0e0f0f1f2f3f3f4ff675168"].pack("H*") )
587
- script.to_string.should == "0 OP_IF (opcode-186) (opcode-192) (opcode-208) (opcode-224) (opcode-240) (opcode-241) (opcode-242) (opcode-243) (opcode-243) (opcode-244) OP_INVALIDOPCODE OP_ELSE 1 OP_ENDIF"
588
- script.run.should == true
589
-
590
- # mainnet tx: 61a078472543e9de9247446076320499c108b52307d8d0fafbe53b5c4e32acc4 redeeming output from 5342c96b946ea2c5e497de5dbf7762021f94aba2c8222c17ed28492fdbb4a6d9
591
- script = Bitcoin::Script.from_string("16cfb9bc7654ef1d7723e5c2722fc0c3d505045e OP_SIZE OP_DUP 1 OP_GREATERTHAN OP_VERIFY OP_NEGATE OP_HASH256 OP_HASH160 OP_SHA256 OP_SHA1 OP_RIPEMD160 OP_EQUAL")
592
- script.run.should == true
593
-
594
- # mainnet tx: 340aa9f72206d600b7e89c9137e4d2d77a920723f83e34707ff452121fd48492 redeeming output from f2d72a7bf22e29e3f2dc721afbf0a922860f81db9fc7eb397937f9d7e87cc438
595
- script = Bitcoin::Script.from_string("027ce87f6f41dd4d7d874b40889f7df6b288f77f OP_DEPTH OP_HASH256 OP_HASH160 OP_SHA256 OP_SHA1 OP_RIPEMD160 OP_EQUAL")
596
- script.run.should == true
597
- end
598
-
599
- it "should run op_checkmultisig p2sh script with empty signature" do
600
- # mainnet tx: b78706427923f73b334fd68040f35900503da33c671723c41ca845f6fba6c29c
601
- tx1 = Bitcoin::P::Tx.new("01000000023904cd3644c6d440a6d752c95f07737c46f5e70fb6fbb28f00aa17e281868b7b010000006b483045022100ac455750dc430957942e9766f88aecfe6eb17d4244eb2cb50ca4a25336fd4dd702202640cc943f4fe8f2166b03005bed3bd024f4762767322b60bf471ecf8e3f3ede012102348d4cad0084f88c4c02bdc1bf90cc6c0893a0b97af76ef644daf72e6786b4afffffffffb84057ae61ad22ac17c02635ee1b37d170ef785847ec28efe848a5607331568e020000006b483045022100d7fee595d7a1f9969767098f8582e7a563f08437f461f0a25395f35c1833839302205f565ab12d343478471a78669c4c3476714032f7758a781d7deab19f160784e0012102ea69c47753d8e0228c0c426294a6b4dc926aebbeb8561248d40be37d257d94e0ffffffff01a08601000000000017a91438430c4d1c214bf11d2c0c3dea8e5e9a5d11aab08700000000".htb)
602
- # mainnet tx: 136becd0892fa38c5aca8104db8b90b3a0e6b40912b7d1462aed583c067054cd
603
- tx2 = Bitcoin::P::Tx.new("01000000019cc2a6fbf645a81cc42317673ca33d500059f34080d64f333bf72379420687b70000000008000051005102ae91ffffffff0150c300000000000002ae9100000000".htb)
604
- tx2.verify_input_signature(0, tx1).should == true
605
- end
606
-
607
- it "should debug script branches (OP_IF/NOTIF/ELSE/ENDIF) correctly" do
608
-
609
- script = Bitcoin::Script.from_string("1 OP_NOTIF OP_RETURN OP_ENDIF")
610
- script.run {}
611
- script.debug.should == [
612
- [], "OP_1",
613
- [1], "OP_NOTIF",
614
- [], "OP_ENDIF",
615
- [], "RESULT"
616
- ]
617
-
618
- script = Bitcoin::Script.from_string("1 OP_IF OP_RETURN OP_ENDIF")
619
- script.run {}
620
- script.debug.should == [
621
- [], "OP_1",
622
- [1], "OP_IF",
623
- [], "OP_RETURN",
624
- [], "INVALID TRANSACTION", "RESULT"
625
- ]
626
-
627
- script = Bitcoin::Script.from_string("1 OP_IF OP_2 OP_ELSE OP_3 OP_ENDIF OP_2 OP_EQUAL")
628
- script.run {}
629
- script.debug.should == [
630
- [], "OP_1",
631
- [1], "OP_IF",
632
- [], "OP_2",
633
- [2], "OP_ELSE",
634
- [2], "OP_ENDIF",
635
- [2], "OP_2",
636
- [2, 2], "OP_EQUAL",
637
- [1], "RESULT"]
638
-
639
- script = Bitcoin::Script.from_string("0 OP_IF OP_2 OP_ELSE OP_3 OP_ENDIF OP_2 OP_EQUAL")
640
- script.run {}
641
- script.debug.should == [
642
- [], "OP_0",
643
- [[""]], "OP_IF",
644
- [], "OP_ELSE",
645
- [], "OP_3",
646
- [3], "OP_ENDIF",
647
- [3], "OP_2",
648
- [3, 2], "OP_EQUAL",
649
- [0], "RESULT"]
650
-
651
- script = Bitcoin::Script.from_string("0 OP_IF deadbeef OP_ELSE OP_3 OP_ENDIF OP_2 OP_EQUAL")
652
- script.run {}
653
- script.debug.should == [
654
- [], "OP_0",
655
- [[""]], "OP_IF",
656
- [], "OP_ELSE",
657
- [], "OP_3",
658
- [3], "OP_ENDIF",
659
- [3], "OP_2",
660
- [3, 2], "OP_EQUAL",
661
- [0], "RESULT"]
662
-
663
- script = Bitcoin::Script.from_string("1 OP_IF 2 OP_ELSE 3 OP_ENDIF 2 OP_EQUAL")
664
- script.run {}
665
- script.debug.should == [[], "OP_1", [1], "OP_IF", [], "OP_2", [2], "OP_ELSE", [2], "OP_ENDIF", [2], "OP_2", [2, 2], "OP_EQUAL", [1], "RESULT"]
666
-
667
- script = Bitcoin::Script.from_string("
668
- 0
669
- 3045022041ccefcad804c28fcd843afeb10df3bd09d93e56542cda4ae9bcac18ed69f6c7022100f24d891b69695099a66b81a4ef382ff0ef388ad211505cd32e2ad3adebe5f74501
670
- 304502201124a34c8bcc6a41c9bda088bc28e4274af02872866fa926205b0799e0f3b28a022100d0bbe8382a4e6ff46968bb8c2990bb63ef7f413f5b7c3912b4948b3eb0e72fc301
671
- 1
672
- 635221022d73c0041da9794fcaa7286fcce35e126f84f8b53563be6abb3b213f964bfbfc2102ab2445a289939e49e326dd29ca068cb38d1c9ef7618b7272d14c79c1abdea5cd52ae675221025182b1ca9a1ea9358f61cb363ac80c80b145204d9c4d875c35873d3d578853
673
- OP_IF
674
- 2
675
- 022d73c0041da9794fcaa7286fcce35e126f84f8b53563be6abb3b213f964bfbfc
676
- 02ab2445a289939e49e326dd29ca068cb38d1c9ef7618b7272d14c79c1abdea5cd
677
- 2
678
- OP_CHECKMULTISIG
679
- OP_ELSE
680
- 2
681
- 025182b1ca9a1ea9358f61cb363ac80c80b145204d9c4d875c35873d3d57885348
682
- 02b18808b3e6857e396167890a52f898cbd5215354f027b89fed895058e49a158b
683
- 2
684
- OP_CHECKMULTISIG
685
- OP_ENDIF")
686
- script.run {}
687
- script.debug.should == [
688
- [], "OP_0",
689
- [[""]], "PUSH DATA 3045022041ccefcad804c28fcd843afeb10df3bd09d93e56542cda4ae9bcac18ed69f6c7022100f24d891b69695099a66b81a4ef382ff0ef388ad211505cd32e2ad3adebe5f74501",
690
- [[""], ["3045022041ccefcad804c28fcd843afeb10df3bd09d93e56542cda4ae9bcac18ed69f6c7022100f24d891b69695099a66b81a4ef382ff0ef388ad211505cd32e2ad3adebe5f74501"]], "PUSH DATA 304502201124a34c8bcc6a41c9bda088bc28e4274af02872866fa926205b0799e0f3b28a022100d0bbe8382a4e6ff46968bb8c2990bb63ef7f413f5b7c3912b4948b3eb0e72fc301",
691
- [[""], ["3045022041ccefcad804c28fcd843afeb10df3bd09d93e56542cda4ae9bcac18ed69f6c7022100f24d891b69695099a66b81a4ef382ff0ef388ad211505cd32e2ad3adebe5f74501"], ["304502201124a34c8bcc6a41c9bda088bc28e4274af02872866fa926205b0799e0f3b28a022100d0bbe8382a4e6ff46968bb8c2990bb63ef7f413f5b7c3912b4948b3eb0e72fc301"]], "OP_1",
692
- [[""], ["3045022041ccefcad804c28fcd843afeb10df3bd09d93e56542cda4ae9bcac18ed69f6c7022100f24d891b69695099a66b81a4ef382ff0ef388ad211505cd32e2ad3adebe5f74501"], ["304502201124a34c8bcc6a41c9bda088bc28e4274af02872866fa926205b0799e0f3b28a022100d0bbe8382a4e6ff46968bb8c2990bb63ef7f413f5b7c3912b4948b3eb0e72fc301"], 1], "PUSH DATA 635221022d73c0041da9794fcaa7286fcce35e126f84f8b53563be6abb3b213f964bfbfc2102ab2445a289939e49e326dd29ca068cb38d1c9ef7618b7272d14c79c1abdea5cd52ae675221025182b1ca9a1ea9358f61cb363ac80c80b145204d9c4d875c35873d3d578853",
693
- [[""], ["3045022041ccefcad804c28fcd843afeb10df3bd09d93e56542cda4ae9bcac18ed69f6c7022100f24d891b69695099a66b81a4ef382ff0ef388ad211505cd32e2ad3adebe5f74501"], ["304502201124a34c8bcc6a41c9bda088bc28e4274af02872866fa926205b0799e0f3b28a022100d0bbe8382a4e6ff46968bb8c2990bb63ef7f413f5b7c3912b4948b3eb0e72fc301"], 1, ["635221022d73c0041da9794fcaa7286fcce35e126f84f8b53563be6abb3b213f964bfbfc2102ab2445a289939e49e326dd29ca068cb38d1c9ef7618b7272d14c79c1abdea5cd52ae675221025182b1ca9a1ea9358f61cb363ac80c80b145204d9c4d875c35873d3d578853"]], "OP_IF",
694
-
695
- [[""], ["3045022041ccefcad804c28fcd843afeb10df3bd09d93e56542cda4ae9bcac18ed69f6c7022100f24d891b69695099a66b81a4ef382ff0ef388ad211505cd32e2ad3adebe5f74501"], ["304502201124a34c8bcc6a41c9bda088bc28e4274af02872866fa926205b0799e0f3b28a022100d0bbe8382a4e6ff46968bb8c2990bb63ef7f413f5b7c3912b4948b3eb0e72fc301"], 1], "OP_2",
696
- [[""], ["3045022041ccefcad804c28fcd843afeb10df3bd09d93e56542cda4ae9bcac18ed69f6c7022100f24d891b69695099a66b81a4ef382ff0ef388ad211505cd32e2ad3adebe5f74501"], ["304502201124a34c8bcc6a41c9bda088bc28e4274af02872866fa926205b0799e0f3b28a022100d0bbe8382a4e6ff46968bb8c2990bb63ef7f413f5b7c3912b4948b3eb0e72fc301"], 1, 2], "PUSH DATA 022d73c0041da9794fcaa7286fcce35e126f84f8b53563be6abb3b213f964bfbfc",
697
- [[""], ["3045022041ccefcad804c28fcd843afeb10df3bd09d93e56542cda4ae9bcac18ed69f6c7022100f24d891b69695099a66b81a4ef382ff0ef388ad211505cd32e2ad3adebe5f74501"], ["304502201124a34c8bcc6a41c9bda088bc28e4274af02872866fa926205b0799e0f3b28a022100d0bbe8382a4e6ff46968bb8c2990bb63ef7f413f5b7c3912b4948b3eb0e72fc301"], 1, 2, ["022d73c0041da9794fcaa7286fcce35e126f84f8b53563be6abb3b213f964bfbfc"]], "PUSH DATA 02ab2445a289939e49e326dd29ca068cb38d1c9ef7618b7272d14c79c1abdea5cd",
698
- [[""], ["3045022041ccefcad804c28fcd843afeb10df3bd09d93e56542cda4ae9bcac18ed69f6c7022100f24d891b69695099a66b81a4ef382ff0ef388ad211505cd32e2ad3adebe5f74501"], ["304502201124a34c8bcc6a41c9bda088bc28e4274af02872866fa926205b0799e0f3b28a022100d0bbe8382a4e6ff46968bb8c2990bb63ef7f413f5b7c3912b4948b3eb0e72fc301"], 1, 2, ["022d73c0041da9794fcaa7286fcce35e126f84f8b53563be6abb3b213f964bfbfc"], ["02ab2445a289939e49e326dd29ca068cb38d1c9ef7618b7272d14c79c1abdea5cd"]], "OP_2",
699
- [[""], ["3045022041ccefcad804c28fcd843afeb10df3bd09d93e56542cda4ae9bcac18ed69f6c7022100f24d891b69695099a66b81a4ef382ff0ef388ad211505cd32e2ad3adebe5f74501"], ["304502201124a34c8bcc6a41c9bda088bc28e4274af02872866fa926205b0799e0f3b28a022100d0bbe8382a4e6ff46968bb8c2990bb63ef7f413f5b7c3912b4948b3eb0e72fc301"], 1, 2, ["022d73c0041da9794fcaa7286fcce35e126f84f8b53563be6abb3b213f964bfbfc"], ["02ab2445a289939e49e326dd29ca068cb38d1c9ef7618b7272d14c79c1abdea5cd"], 2], "OP_CHECKMULTISIG",
700
- [[""], 0], "OP_ELSE",
701
- [[""], 0], "OP_ENDIF",
702
- [[""], 0], "RESULT"]
703
- end
704
-
705
- it "should not execute p2sh recursively" do
706
- # this script_sig includes a pattern that matches the p2sh template
707
- script_sig = "0 a914b472a266d0bd89c13706a4132ccfb16f7c3b9fcb87"
708
- pk_script = "OP_HASH160 92a04bc86e23f169691bd6926d11853cc61e1852 OP_EQUAL"
709
- script = Bitcoin::Script.from_string(script_sig + " " + pk_script)
710
- script.run.should == true
711
- end
712
-
713
- def build_p2sh_multisig_tx(m, *keys)
714
- redeem_script = Bitcoin::Script.to_multisig_script(m, *keys.map(&:pub))
715
- p2sh_address = Bitcoin.hash160_to_p2sh_address(Bitcoin.hash160(redeem_script.hth))
716
-
717
- prev_tx = build_tx {|t| t.input {|i| i.coinbase}
718
- t.output {|o| o.to p2sh_address; o.value 50e8 } }
719
- tx = build_tx {|t| t.input {|i| i.prev_out prev_tx, 0 }
720
- t.output {|o| o.to Bitcoin::Key.generate.addr; o.value 50e8 } }
721
-
722
- sig_hash = tx.signature_hash_for_input(0, redeem_script)
723
- return prev_tx, tx, redeem_script, sig_hash
724
- end
725
-
726
- it "#sort_p2sh_multisig_signatures 3-of-3" do
727
- keys = 3.times.map { Bitcoin::Key.generate }
728
-
729
- prev_tx, tx, redeem_script, sig_hash = build_p2sh_multisig_tx(3, *keys)
730
- sigs = keys.map {|k| k.sign(sig_hash) }
731
-
732
- # add sigs in all possible orders, sort them, and see if they are valid
733
- [0, 1, 2].permutation do |order|
734
- script_sig = Script.to_p2sh_multisig_script_sig(redeem_script)
735
- order.each{|i| script_sig = Script.add_sig_to_multisig_script_sig(sigs[i], script_sig)}
736
- script_sig = Script.sort_p2sh_multisig_signatures(script_sig, sig_hash)
737
- tx.in[0].script_sig = script_sig
738
- tx.verify_input_signature(0, prev_tx).should == true
739
- end
740
- end
741
-
742
- it "#sort_p2sh_multisig_signatures 2-of-3" do
743
- keys = 3.times.map { Bitcoin::Key.generate }
744
-
745
- prev_tx, tx, redeem_script, sig_hash = build_p2sh_multisig_tx(2, *keys)
746
- sigs = keys.map {|k| k.sign(sig_hash) }
747
-
748
- # add sigs in all possible orders, sort them, and see if they are valid
749
- [0, 1, 2].permutation(2) do |order|
750
- script_sig = Script.to_p2sh_multisig_script_sig(redeem_script)
751
- order.each{|i| script_sig = Script.add_sig_to_multisig_script_sig(sigs[i], script_sig)}
752
- script_sig = Script.sort_p2sh_multisig_signatures(script_sig, sig_hash)
753
- tx.in[0].script_sig = script_sig
754
- tx.verify_input_signature(0, prev_tx).should == true
755
- end
756
- end
757
-
758
- end
759
-
760
- describe "Implements BIP62" do
761
- it 'tests for incorrectly encoded S-values in signatures' do
762
- # TX 3da75972766f0ad13319b0b461fd16823a731e44f6e9de4eb3c52d6a6fb6c8ae
763
- sig_orig = ["304502210088984573e3e4f33db7df6aea313f1ce67a3ef3532ea89991494c7f018258371802206ceefc9291450dbd40d834f249658e0f64662d52a41cf14e20c9781144f2fe0701"].pack("H*")
764
- Bitcoin::Script::is_low_der_signature?(sig_orig).should == true
765
-
766
- # Set the start of the S-value to 0xff so it's well above the order of the curve divided by two
767
- sig = sig_orig.unpack("C*")
768
- length_r = sig[3]
769
- sig[6 + length_r] = 0xff
770
-
771
- Bitcoin::Script::is_low_der_signature?(sig.pack("C*")).should == false
772
- end
773
- it 'enforces rules 3 and 4' do
774
- Script.new([75].pack("C") + 'A' * 75).pushes_are_canonical?.should == true
775
- Script.new([Bitcoin::Script::OP_PUSHDATA1, 75].pack("CC") + 'A' * 75).pushes_are_canonical?.should == false
776
- Script.new([Bitcoin::Script::OP_PUSHDATA2, 255].pack("Cv") + 'A' * 255).pushes_are_canonical?.should == false
777
- Script.new([Bitcoin::Script::OP_PUSHDATA4, 1645].pack("CV") + 'A' * 1645).pushes_are_canonical?.should == false
778
- end
779
- end
780
-
781
- describe "Implements BIP66" do
782
- def build_crediting_tx(script_pk)
783
- tx = Bitcoin::P::Tx.new
784
- input = Bitcoin::P::TxIn.new(nil, 0xffffffff, 2, "\x00\x00")
785
- output = Bitcoin::P::TxOut.new(0, script_pk)
786
- tx.add_in(input)
787
- tx.add_out(output)
788
- Bitcoin::P::Tx.new(tx.to_payload)
789
- end
790
-
791
- def build_spending_tx(script_sig, tx_credit)
792
- tx = Bitcoin::P::Tx.new
793
- input = Bitcoin::P::TxIn.new(tx_credit.binary_hash, 0, 2, script_sig)
794
- output = Bitcoin::P::TxOut.new(0, '')
795
- tx.add_in(input)
796
- tx.add_out(output)
797
- Bitcoin::P::Tx.new(tx.to_payload)
798
- end
799
-
800
- # essentially DoTest() from script_tests.cpp
801
- def run_script_test(script_sig_str, script_pk_str, opts={})
802
- script_sig = Bitcoin::Script.from_string(script_sig_str)
803
- script_pk = Bitcoin::Script.from_string(script_pk_str)
804
- tx_credit = build_crediting_tx(script_pk.raw)
805
- tx = build_spending_tx(script_sig.raw, tx_credit)
806
- tx.verify_input_signature(0, tx_credit, Time.now.to_i, opts)
807
- end
808
-
809
- it 'overly long signature fails with DERSIG passes without' do
810
- script_sig = "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
811
- script_pk = "0 OP_CHECKSIG OP_NOT"
812
- run_script_test(script_sig, script_pk, {verify_dersig: true}).should == false
813
- run_script_test(script_sig, script_pk).should == true
814
- end
815
-
816
- it 'missing S fails with DERSIG passes without' do
817
- script_sig = "3022022000000000000000000000000000000000000000000000000000000000000000000"
818
- script_pk = "0 OP_CHECKSIG OP_NOT"
819
- run_script_test(script_sig, script_pk, {verify_dersig: true}).should == false
820
- run_script_test(script_sig, script_pk).should == true
821
- end
822
-
823
- it 'S with invalid fails with DERSIG passes without' do
824
- script_sig = "3024021077777777777777777777777777777777020a7777777777777777777777777777777701"
825
- script_pk = "0 OP_CHECKSIG OP_NOT"
826
- run_script_test(script_sig, script_pk, {verify_dersig: true}).should == false
827
- run_script_test(script_sig, script_pk).should == true
828
- end
829
-
830
- it 'non-integer R fails with DERSIG passes without' do
831
- script_sig = "302403107777777777777777777777777777777702107777777777777777777777777777777701"
832
- script_pk = "0 OP_CHECKSIG OP_NOT"
833
- run_script_test(script_sig, script_pk, {verify_dersig: true}).should == false
834
- run_script_test(script_sig, script_pk).should == true
835
- end
836
-
837
- it 'non-integer S fails with DERSIG passes without' do
838
- script_sig = "302402107777777777777777777777777777777703107777777777777777777777777777777701"
839
- script_pk = "0 OP_CHECKSIG OP_NOT"
840
- run_script_test(script_sig, script_pk, {verify_dersig: true}).should == false
841
- run_script_test(script_sig, script_pk).should == true
842
- end
843
-
844
- it 'zero length R fails with DERSIG passes without' do
845
- script_sig = "3014020002107777777777777777777777777777777701"
846
- script_pk = "0 OP_CHECKSIG OP_NOT"
847
- run_script_test(script_sig, script_pk, {verify_dersig: true}).should == false
848
- run_script_test(script_sig, script_pk).should == true
849
- end
850
-
851
- it 'zero length S fails with DERSIG passes without' do
852
- script_sig = "3014021077777777777777777777777777777777020001"
853
- script_pk = "0 OP_CHECKSIG OP_NOT"
854
- run_script_test(script_sig, script_pk, {verify_dersig: true}).should == false
855
- run_script_test(script_sig, script_pk).should == true
856
- end
857
-
858
- it 'negative S fails with DERSIG passes without' do
859
- script_sig = "302402107777777777777777777777777777777702108777777777777777777777777777777701"
860
- script_pk = "0 OP_CHECKSIG OP_NOT"
861
- run_script_test(script_sig, script_pk, {verify_dersig: true}).should == false
862
- run_script_test(script_sig, script_pk).should == true
863
- end
864
-
865
- # see: https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki#examples
866
- # see also: https://github.com/bitcoin/bitcoin/pull/5713/files
867
- P1 = "038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508"
868
- P2 = "03363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640"
869
-
870
- # Example 1: S1' P1 CHECKSIG (fails w/ verify_dersig, passes w/o)
871
- it 'example 1' do
872
- script_sig = "30440220d7a0417c3f6d1a15094d1cf2a3378ca0503eb8a57630953a9e2987e21ddd0a6502207a6266d686c99090920249991d3d42065b6d43eb70187b219c0db82e4f94d1a201"
873
- script_pk = "#{P1} OP_CHECKSIG"
874
- run_script_test(script_sig, script_pk).should == true
875
- run_script_test(script_sig, script_pk, {verify_dersig: true}).should == false
876
- end
877
-
878
- # Example 2: S1' P1 CHECKSIG NOT (fails with either)
879
- it 'example 2' do
880
- script_sig = "304402208e43c0b91f7c1e5bc58e41c8185f8a6086e111b0090187968a86f2822462d3c902200a58f4076b1133b18ff1dc83ee51676e44c60cc608d9534e0df5ace0424fc0be01"
881
- script_pk = "#{P1} OP_CHECKSIG OP_NOT"
882
- run_script_test(script_sig, script_pk).should == false
883
- run_script_test(script_sig, script_pk, {verify_dersig: true}).should == false
884
- end
885
-
886
- # Example 3: F P1 CHECKSIG fails (fails with either)
887
- it 'example 3' do
888
- script_sig = "0"
889
- script_pk = "#{P1} OP_CHECKSIG"
890
- run_script_test(script_sig, script_pk).should == false
891
- run_script_test(script_sig, script_pk, {verify_dersig: true}).should == false
892
- end
893
-
894
- # Example 4: F P1 CHECKSIG NOT (passes with either)
895
- it 'example 4' do
896
- script_sig = "0"
897
- script_pk = "#{P1} OP_CHECKSIG OP_NOT"
898
- run_script_test(script_sig, script_pk).should == true
899
- run_script_test(script_sig, script_pk, {verify_dersig: true}).should == true
900
- end
901
-
902
- # Example 5: F' P1 CHECKSIG (fails with either)
903
- it 'example 5' do
904
- script_sig = "1"
905
- script_pk = "#{P1} OP_CHECKSIG"
906
- run_script_test(script_sig, script_pk).should == false
907
- run_script_test(script_sig, script_pk, {verify_dersig: true}).should == false
908
- end
909
-
910
- # Example 6: F' P1 CHECKSIG NOT (fails w/verify_dersig, passes w/o)
911
- it 'example 6' do
912
- script_sig = "1"
913
- script_pk = "#{P1} OP_CHECKSIG OP_NOT"
914
- run_script_test(script_sig, script_pk).should == true
915
- run_script_test(script_sig, script_pk, {verify_dersig: true}).should == false
916
- end
917
-
918
- # Example 7: 0 S1' S2 2 P1 P2 2 CHECKMULTISIG (fails w/verify_dersig, passes w/o)
919
- it 'example 7' do
920
- s1 = "30440220cae00b1444babfbf6071b0ba8707f6bd373da3df494d6e74119b0430c5db810502205d5231b8c5939c8ff0c82242656d6e06edb073d42af336c99fe8837c36ea39d501"
921
- s2 = "304402200b3d0b0375bb15c14620afa4aa10ae90a0d6a046ce217bc20fe0bc1ced68c1b802204b550acab90ae6d3478057c9ad24f9df743815b799b6449dd7e7f6d3bc6e274c01"
922
- script_sig = "0 #{s1} #{s2}"
923
- script_pk = "2 #{P1} #{P2} 2 OP_CHECKMULTISIG"
924
- run_script_test(script_sig, script_pk).should == true
925
- run_script_test(script_sig, script_pk, {verify_dersig: true}).should == false
926
- end
927
-
928
- # Example 8: 0 S1' S2 2 P1 P2 2 CHECKMULTISIG NOT (fails for either)
929
- it 'example 8' do
930
- s1 = "30440220f00a77260d34ec2f0c59621dc710f58169d0ca06df1a88cd4b1f1b97bd46991b02201ee220c7e04f26aed03f94aa97fb09ca5627163bf4ba07e6979972ec737db22601"
931
- s2 = "3044022079ea80afd538d9ada421b5101febeb6bc874e01dde5bca108c1d0479aec339a4022004576db8f66130d1df686ccf00935703689d69cf539438da1edab208b0d63c4801"
932
- script_sig = "0 #{s1} #{s2}"
933
- script_pk = "2 #{P1} #{P2} 2 OP_CHECKMULTISIG OP_NOT"
934
- run_script_test(script_sig, script_pk).should == false
935
- run_script_test(script_sig, script_pk, {verify_dersig: true}).should == false
936
- end
937
-
938
- # Example 9: 0 F S2' 2 P1 P2 2 CHECKMULTISIG fails (fails for either)
939
- it 'example 9' do
940
- s1 = "0"
941
- s2 = "3044022081aa9d436f2154e8b6d600516db03d78de71df685b585a9807ead4210bd883490220534bb6bdf318a419ac0749660b60e78d17d515558ef369bf872eff405b676b2e01"
942
- script_sig = "0 #{s1} #{s2}"
943
- script_pk = "2 #{P1} #{P2} 2 OP_CHECKMULTISIG"
944
- run_script_test(script_sig, script_pk).should == false
945
- run_script_test(script_sig, script_pk, {verify_dersig: true}).should == false
946
- end
947
-
948
- # Example 10: 0 F S2' 2 P1 P2 2 CHECKMULTISIG NOT (fails w/verify_dersig, passes w/o)
949
- it 'example 10' do
950
- s1 = "0"
951
- s2 = "30440220afa76a8f60622f813b05711f051c6c3407e32d1b1b70b0576c1f01b54e4c05c702200d58e9df044fd1845cabfbeef6e624ba0401daf7d7e084736f9ff601c3783bf501"
952
- script_sig = "0 #{s1} #{s2}"
953
- script_pk = "2 #{P1} #{P2} 2 OP_CHECKMULTISIG OP_NOT"
954
- run_script_test(script_sig, script_pk).should == true
955
- run_script_test(script_sig, script_pk, {verify_dersig: true}).should == false
956
- end
957
-
958
- # Example 11: 0 S1' F 2 P1 P2 2 CHECKMULTISIG (fails for either)
959
- it 'example 11' do
960
- s1 = "30440220cae00b1444babfbf6071b0ba8707f6bd373da3df494d6e74119b0430c5db810502205d5231b8c5939c8ff0c82242656d6e06edb073d42af336c99fe8837c36ea39d501"
961
- s2 = "0"
962
- script_sig = "0 #{s1} #{s2}"
963
- script_pk = "2 #{P1} #{P2} 2 OP_CHECKMULTISIG"
964
- run_script_test(script_sig, script_pk).should == false
965
- run_script_test(script_sig, script_pk, {verify_dersig: true}).should == false
966
- end
967
-
968
- # Example 12: 0 S1' F 2 P1 P2 2 CHECKMULTISIG NOT (passes for either)
969
- it 'example 12' do
970
- s1 = "30440220f00a77260d34ec2f0c59621dc710f58169d0ca06df1a88cd4b1f1b97bd46991b02201ee220c7e04f26aed03f94aa97fb09ca5627163bf4ba07e6979972ec737db22601"
971
- s2 = "0"
972
- script_sig = "0 #{s1} #{s2}"
973
- script_pk = "2 #{P1} #{P2} 2 OP_CHECKMULTISIG OP_NOT"
974
- run_script_test(script_sig, script_pk).should == true
975
- run_script_test(script_sig, script_pk, {verify_dersig: true}).should == true
976
- end
977
- end