monacoin-ruby 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.travis.yml +5 -0
- data/COPYING +18 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +33 -0
- data/README.rdoc +210 -0
- data/Rakefile +112 -0
- data/bin/monacoin_shell +12 -0
- data/bitcoin-ruby.gemspec +23 -0
- data/examples/bbe_verify_tx.rb +60 -0
- data/examples/concept-blockchain-pow.rb +151 -0
- data/examples/connect.rb +36 -0
- data/examples/generate_tx.rb +34 -0
- data/examples/simple_network_monitor_and_util.rb +195 -0
- data/spec/bitcoin/bitcoin_spec.rb +598 -0
- data/spec/bitcoin/bloom_filter_spec.rb +23 -0
- data/spec/bitcoin/builder_spec.rb +342 -0
- data/spec/bitcoin/contracthash_spec.rb +45 -0
- data/spec/bitcoin/dogecoin_spec.rb +176 -0
- data/spec/bitcoin/ext_key_spec.rb +180 -0
- data/spec/bitcoin/ffi_openssl.rb +45 -0
- data/spec/bitcoin/fixtures/000000000000056b1a3d84a1e2b33cde8915a4b61c0cae14fca6d3e1490b4f98.json +3697 -0
- data/spec/bitcoin/fixtures/03d7e1fa4d5fefa169431f24f7798552861b255cd55d377066fedcd088fb0e99.json +23 -0
- data/spec/bitcoin/fixtures/0961c660358478829505e16a1f028757e54b5bbf9758341a7546573738f31429.json +24 -0
- data/spec/bitcoin/fixtures/0f24294a1d23efbb49c1765cf443fba7930702752aba6d765870082fe4f13cae.json +37 -0
- data/spec/bitcoin/fixtures/156e6e1b84c5c3bd3a0927b25e4119fadce6e6d5186f363317511d1d680fae9a.json +24 -0
- data/spec/bitcoin/fixtures/23b397edccd3740a74adb603c9756370fafcde9bcc4483eb271ecad09a94dd63.json +23 -0
- data/spec/bitcoin/fixtures/315ac7d4c26d69668129cc352851d9389b4a6868f1509c6c8b66bead11e2619f.json +31 -0
- data/spec/bitcoin/fixtures/35e2001b428891fefa0bfb73167c7360669d3cbd7b3aa78e7cad125ddfc51131.json +27 -0
- data/spec/bitcoin/fixtures/3a17dace09ffb919ed627a93f1873220f4c975c1248558b18d16bce25d38c4b7.json +72 -0
- data/spec/bitcoin/fixtures/3e58b7eed0fdb599019af08578effea25c8666bbe8e200845453cacce6314477.json +27 -0
- data/spec/bitcoin/fixtures/514c46f0b61714092f15c8dfcb576c9f79b3f959989b98de3944b19d98832b58.json +24 -0
- data/spec/bitcoin/fixtures/51bf528ecf3c161e7c021224197dbe84f9a8564212f6207baa014c01a1668e1e.json +30 -0
- data/spec/bitcoin/fixtures/60a20bd93aa49ab4b28d514ec10b06e1829ce6818ec06cd3aabd013ebcdc4bb1.json +45 -0
- data/spec/bitcoin/fixtures/69216b8aaa35b76d6613e5f527f4858640d986e1046238583bdad79b35e938dc.json +28 -0
- data/spec/bitcoin/fixtures/7208e5edf525f04e705fb3390194e316205b8f995c8c9fcd8c6093abe04fa27d.json +27 -0
- data/spec/bitcoin/fixtures/761d8c5210fdfd505f6dff38f740ae3728eb93d7d0971fb433f685d40a4c04f6.json +27 -0
- data/spec/bitcoin/fixtures/8d0b238a06b5a70be75d543902d02d7a514d68d3252a949a513865ac3538874c.json +24 -0
- data/spec/bitcoin/fixtures/aea682d68a3ea5e3583e088dcbd699a5d44d4b083f02ad0aaf2598fe1fa4dfd4.json +27 -0
- data/spec/bitcoin/fixtures/bc179baab547b7d7c1d5d8d6f8b0cc6318eaa4b0dd0a093ad6ac7f5a1cb6b3ba.json +34 -0
- data/spec/bitcoin/fixtures/bd1715f1abfdc62bea3f605bdb461b3ba1f2cca6ec0d73a18a548b7717ca8531.json +34 -0
- data/spec/bitcoin/fixtures/block-testnet-0000000000ac85bb2530a05a4214a387e6be02b22d3348abc5e7a5d9c4ce8dab.bin +0 -0
- data/spec/bitcoin/fixtures/cd874fa8cb0e2ec2d385735d5e1fd482c4fe648533efb4c50ee53bda58e15ae2.json +24 -0
- data/spec/bitcoin/fixtures/ce5fad9b4ef094d8f4937b0707edaf0a6e6ceeaf67d5edbfd51f660eac8f398b.json +41 -0
- data/spec/bitcoin/fixtures/coinbase-toshi.json +33 -0
- data/spec/bitcoin/fixtures/coinbase.json +24 -0
- data/spec/bitcoin/fixtures/dogecoin-block-60323982f9c5ff1b5a954eac9dc1269352835f47c2c5222691d80f0d50dcf053.bin +0 -0
- data/spec/bitcoin/fixtures/f003f0c1193019db2497a675fd05d9f2edddf9b67c59e677c48d3dbd4ed5f00b.json +23 -0
- data/spec/bitcoin/fixtures/filteredblock-0.bin +0 -0
- data/spec/bitcoin/fixtures/litecoin-block-80ca095ed10b02e53d769eb6eaf92cd04e9e0759e5be4a8477b42911ba49c78f.bin +0 -0
- data/spec/bitcoin/fixtures/litecoin-block-80ca095ed10b02e53d769eb6eaf92cd04e9e0759e5be4a8477b42911ba49c78f.json +39 -0
- data/spec/bitcoin/fixtures/litecoin-genesis-block-12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2.bin +0 -0
- data/spec/bitcoin/fixtures/litecoin-genesis-block-12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2.json +39 -0
- data/spec/bitcoin/fixtures/litecoin-tx-f5aa30f574e3b6f1a3d99c07a6356ba812aabb9661e1d5f71edff828cbd5c996.json +259 -0
- data/spec/bitcoin/fixtures/rawblock-0.bin +0 -0
- data/spec/bitcoin/fixtures/rawblock-0.json +39 -0
- data/spec/bitcoin/fixtures/rawblock-1.bin +0 -0
- data/spec/bitcoin/fixtures/rawblock-1.json +39 -0
- data/spec/bitcoin/fixtures/rawblock-131025.bin +0 -0
- data/spec/bitcoin/fixtures/rawblock-131025.json +5063 -0
- data/spec/bitcoin/fixtures/rawblock-170.bin +0 -0
- data/spec/bitcoin/fixtures/rawblock-170.json +68 -0
- data/spec/bitcoin/fixtures/rawblock-9.bin +0 -0
- data/spec/bitcoin/fixtures/rawblock-9.json +39 -0
- data/spec/bitcoin/fixtures/rawblock-auxpow.bin +0 -0
- data/spec/bitcoin/fixtures/rawblock-testnet-1151351.bin +0 -0
- data/spec/bitcoin/fixtures/rawblock-testnet-26478.bin +0 -0
- data/spec/bitcoin/fixtures/rawblock-testnet-26478.json +64 -0
- data/spec/bitcoin/fixtures/rawblock-testnet-265322.bin +0 -0
- data/spec/bitcoin/fixtures/rawtx-01-toshi.json +46 -0
- data/spec/bitcoin/fixtures/rawtx-01.bin +0 -0
- data/spec/bitcoin/fixtures/rawtx-01.json +27 -0
- data/spec/bitcoin/fixtures/rawtx-02-toshi.json +46 -0
- data/spec/bitcoin/fixtures/rawtx-02.bin +0 -0
- data/spec/bitcoin/fixtures/rawtx-02.json +27 -0
- data/spec/bitcoin/fixtures/rawtx-03-toshi.json +73 -0
- data/spec/bitcoin/fixtures/rawtx-03.bin +0 -0
- data/spec/bitcoin/fixtures/rawtx-03.json +48 -0
- data/spec/bitcoin/fixtures/rawtx-04.json +27 -0
- data/spec/bitcoin/fixtures/rawtx-0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9.bin +0 -0
- data/spec/bitcoin/fixtures/rawtx-05.json +23 -0
- data/spec/bitcoin/fixtures/rawtx-14be6fff8c6014f7c9493b4a6e4a741699173f39d74431b6b844fcb41ebb9984.bin +0 -0
- data/spec/bitcoin/fixtures/rawtx-2f4a2717ec8c9f077a87dde6cbe0274d5238793a3f3f492b63c744837285e58a.bin +0 -0
- data/spec/bitcoin/fixtures/rawtx-2f4a2717ec8c9f077a87dde6cbe0274d5238793a3f3f492b63c744837285e58a.json +27 -0
- data/spec/bitcoin/fixtures/rawtx-406b2b06bcd34d3c8733e6b79f7a394c8a431fbf4ff5ac705c93f4076bb77602.json +23 -0
- data/spec/bitcoin/fixtures/rawtx-52250a162c7d03d2e1fbc5ebd1801a88612463314b55102171c5b5d817d2d7b2.bin +0 -0
- data/spec/bitcoin/fixtures/rawtx-b5d4e8883533f99e5903ea2cf001a133a322fa6b1370b18a16c57c946a40823d.bin +0 -0
- data/spec/bitcoin/fixtures/rawtx-ba1ff5cd66713133c062a871a8adab92416f1e38d17786b2bf56ac5f6ffdfdf5.json +37 -0
- data/spec/bitcoin/fixtures/rawtx-c99c49da4c38af669dea436d3e73780dfdb6c1ecf9958baa52960e8baee30e73.json +24 -0
- data/spec/bitcoin/fixtures/rawtx-de35d060663750b3975b7997bde7fb76307cec5b270d12fcd9c4ad98b279c28c.json +23 -0
- data/spec/bitcoin/fixtures/rawtx-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16.bin +0 -0
- data/spec/bitcoin/fixtures/rawtx-p2wpkh.bin +0 -0
- data/spec/bitcoin/fixtures/rawtx-p2wpkh.json +67 -0
- data/spec/bitcoin/fixtures/rawtx-testnet-04fdc38d6722ab4b12d79113fc4b2896bdcc5169710690ee4e78541b98e467b4.bin +0 -0
- data/spec/bitcoin/fixtures/rawtx-testnet-0b294c7d11dd21bcccb8393e6744fed7d4d1981a08c00e3e88838cc421f33c9f.bin +0 -0
- data/spec/bitcoin/fixtures/rawtx-testnet-3bc52ac063291ad92d95ddda5fd776a342083b95607ad32ed8bc6f8f7d30449e.bin +0 -0
- data/spec/bitcoin/fixtures/rawtx-testnet-6f0bbdd4e71a8af4305018d738184df32dbb6f27284fdebd5b56d16947f7c181.bin +0 -0
- data/spec/bitcoin/fixtures/rawtx-testnet-a220adf1902c46a39db25a24bc4178b6a88440f977a7e2cabfdd8b5c1dd35cfb.json +27 -0
- data/spec/bitcoin/fixtures/rawtx-testnet-a7c9b06e275e8674cc19a5f7d3e557c72c6d93576e635b33212dbe08ab7cdb60.bin +0 -0
- data/spec/bitcoin/fixtures/rawtx-testnet-e232e0055dbdca88bbaa79458683195a0b7c17c5b6c524a8d146721d4d4d652f.bin +0 -0
- data/spec/bitcoin/fixtures/rawtx-testnet-e232e0055dbdca88bbaa79458683195a0b7c17c5b6c524a8d146721d4d4d652f.json +41 -0
- data/spec/bitcoin/fixtures/rawtx-testnet-f80acbd2f594d04ddb0e1cacba662132104909157dff526935a3c88abe9201a5.bin +0 -0
- data/spec/bitcoin/fixtures/reorg/blk_0_to_4.dat +0 -0
- data/spec/bitcoin/fixtures/reorg/blk_3A.dat +0 -0
- data/spec/bitcoin/fixtures/reorg/blk_4A.dat +0 -0
- data/spec/bitcoin/fixtures/reorg/blk_5A.dat +0 -0
- data/spec/bitcoin/fixtures/script_tests.json +1947 -0
- data/spec/bitcoin/fixtures/sighash.json +1004 -0
- data/spec/bitcoin/fixtures/testnet/block_0.bin +0 -0
- data/spec/bitcoin/fixtures/testnet/block_1.bin +0 -0
- data/spec/bitcoin/fixtures/testnet/block_2.bin +0 -0
- data/spec/bitcoin/fixtures/testnet/block_3.bin +0 -0
- data/spec/bitcoin/fixtures/testnet/block_4.bin +0 -0
- data/spec/bitcoin/fixtures/testnet/block_5.bin +0 -0
- data/spec/bitcoin/fixtures/tx-0295028ef826b2a188409cb905b631faebb9bb3cdf14510571c5f4bd8591338f.json +64 -0
- data/spec/bitcoin/fixtures/tx-03339a725007a279484fb6f5361f522dd1cf4d0923d30e6b973290dba4275f92.json +64 -0
- data/spec/bitcoin/fixtures/tx-0a6a357e2f7796444e02638749d9611c008b253fb55f5dc88b739b230ed0c4c3.json +139 -0
- data/spec/bitcoin/fixtures/tx-0ce7e5238fbdb6c086cf1b384b21b827e91cc23f360417265874a5a0d86ce367.json +64 -0
- data/spec/bitcoin/fixtures/tx-0ef34c49f630aea17df0080728b0fc67bf5f87fbda936934a4b11b4a69d7821e.json +64 -0
- data/spec/bitcoin/fixtures/tx-1129d2a8bd5bb3a81e54dc96a90f1f6b2544575748caa17243470935c5dd91b7.json +28 -0
- data/spec/bitcoin/fixtures/tx-19aa42fee0fa57c45d3b16488198b27caaacc4ff5794510d0c17f173f05587ff.json +23 -0
- data/spec/bitcoin/fixtures/tx-1a4f3b9dc4494aeedeb39f30dd37e60541b2abe3ed4977992017cc0ad4f44956.json +64 -0
- data/spec/bitcoin/fixtures/tx-1f9191dcf2b1844ca28c6ef4b969e1d5fab70a5e3c56b7007949e55851cb0c4f.json +64 -0
- data/spec/bitcoin/fixtures/tx-22cd5fef23684d7b304e119bedffde6f54538d3d54a5bfa237e20dc2d9b4b5ad.json +64 -0
- data/spec/bitcoin/fixtures/tx-28204cad1d7fc1d199e8ef4fa22f182de6258a3eaafe1bbe56ebdcacd3069a5f.json +34 -0
- data/spec/bitcoin/fixtures/tx-2958fb00b4fd6fe0353503b886eb9a193d502f4fd5fc042d5e03216ba918bbd6.json +64 -0
- data/spec/bitcoin/fixtures/tx-29f277145749ad6efbed3ae6ce301f8d33c585ec26b7c044ad93c2f866e9e942.json +64 -0
- data/spec/bitcoin/fixtures/tx-2c5e5376c20e9cc78d0fb771730e5d840cc2096eff0ef045b599fe92475ace1c.json +28 -0
- data/spec/bitcoin/fixtures/tx-2c63aa814701cef5dbd4bbaddab3fea9117028f2434dddcdab8339141e9b14d1.json +30 -0
- data/spec/bitcoin/fixtures/tx-313897799b1e37e9ecae15010e56156dddde4e683c96b0e713af95272c38aee0.json +30 -0
- data/spec/bitcoin/fixtures/tx-326882a7f22b5191f1a0cc9962ca4b878cd969cf3b3a70887aece4d801a0ba5e.json +23 -0
- data/spec/bitcoin/fixtures/tx-345bed8785c3282a264ffb0dbee61cde54854f10e16f1b3e75b7f2d9f62946f2.json +64 -0
- data/spec/bitcoin/fixtures/tx-39ba7440b7103557560cc8ce258009936796485aaf8b478e66ab4cb97c66e31b.json +32 -0
- data/spec/bitcoin/fixtures/tx-3a04d57a833367f1655cc5ec3beb587888ef4977a86caa8c8ad4ba7cc717eae7.json +64 -0
- data/spec/bitcoin/fixtures/tx-3da75972766f0ad13319b0b461fd16823a731e44f6e9de4eb3c52d6a6fb6c8ae.json +23 -0
- data/spec/bitcoin/fixtures/tx-4142ee4877eb116abf955a7ec6ef2dc38133b793df762b76d75e3d7d4d8badc9.json +38 -0
- data/spec/bitcoin/fixtures/tx-44b833074e671120ba33106877b49e86ece510824b9af477a3853972bcd8d06a.json +30 -0
- data/spec/bitcoin/fixtures/tx-46224764c7870f95b58f155bce1e38d4da8e99d42dbb632d0dd7c07e092ee5aa.json +23 -0
- data/spec/bitcoin/fixtures/tx-5df1375ffe61ac35ca178ebb0cab9ea26dedbd0e96005dfcee7e379fa513232f.json +30 -0
- data/spec/bitcoin/fixtures/tx-62d9a565bd7b5344c5352e3e9e5f40fa4bbd467fa19c87357216ec8777ba1cce.json +64 -0
- data/spec/bitcoin/fixtures/tx-6327783a064d4e350c454ad5cd90201aedf65b1fc524e73709c52f0163739190.json +23 -0
- data/spec/bitcoin/fixtures/tx-6606c366a487bff9e412d0b6c09c14916319932db5954bf5d8719f43f828a3ba.json +27 -0
- data/spec/bitcoin/fixtures/tx-6aaf18b9f1283b939d8e5d40ff5f8a435229f4178372659cc3a0bce4e262bf78.json +28 -0
- data/spec/bitcoin/fixtures/tx-6b48bba6f6d2286d7ec0883c0fc3085955090813a4c94980466611c798b868cc.json +64 -0
- data/spec/bitcoin/fixtures/tx-70cfbc6690f9ab46712db44e3079ac227962b2771a9341d4233d898b521619ef.json +40 -0
- data/spec/bitcoin/fixtures/tx-7a1a9db42f065f75110fcdb1bc415549c8ef7670417ba1d35a67f1b8adc562c1.json +64 -0
- data/spec/bitcoin/fixtures/tx-9a768fc7d0c4bdc86e25154357ef7c0063ca21310e5740a2f12f90b7455184a7.json +64 -0
- data/spec/bitcoin/fixtures/tx-9cad8d523a0694f2509d092c39cebc8046adae62b4e4297102d568191d9478d8.json +64 -0
- data/spec/bitcoin/fixtures/tx-9e052eb694bd7e15906433f064dff0161a12fd325c1124537766377004023c6f.json +64 -0
- data/spec/bitcoin/fixtures/tx-9fb65b7304aaa77ac9580823c2c06b259cc42591e5cce66d76a81b6f51cc5c28.json +23 -0
- data/spec/bitcoin/fixtures/tx-a6ce7081addade7676cd2af75c4129eba6bf5e179a19c40c7d4cf6a5fe595954.json +30 -0
- data/spec/bitcoin/fixtures/tx-a955032f4d6b0c9bfe8cad8f00a8933790b9c1dc28c82e0f48e75b35da0e4944.json +23 -0
- data/spec/bitcoin/fixtures/tx-aab7ef280abbb9cc6fbaf524d2645c3daf4fcca2b3f53370e618d9cedf65f1f8.json +23 -0
- data/spec/bitcoin/fixtures/tx-ab9805c6d57d7070d9a42c5176e47bb705023e6b67249fb6760880548298e742.json +27 -0
- data/spec/bitcoin/fixtures/tx-ad4bcf3241e5d2ad140564e20db3567d41594cf4c2012433fe46a2b70e0d87b8.json +64 -0
- data/spec/bitcoin/fixtures/tx-b5b598de91787439afd5938116654e0b16b7a0d0f82742ba37564219c5afcbf9.json +27 -0
- data/spec/bitcoin/fixtures/tx-b8fd633e7713a43d5ac87266adc78444669b987a56b3a65fb92d58c2c4b0e84d.json +28 -0
- data/spec/bitcoin/fixtures/tx-bbca0628c42cb8bf7c3f4b2ad688fa56da5308dd2a10255da89fb1f46e6e413d.json +36 -0
- data/spec/bitcoin/fixtures/tx-bc7fd132fcf817918334822ee6d9bd95c889099c96e07ca2c1eb2cc70db63224.json +23 -0
- data/spec/bitcoin/fixtures/tx-c192b74844e4837a34c4a5a97b438f1c111405b01b99e2d12b7c96d07fc74c04.json +28 -0
- data/spec/bitcoin/fixtures/tx-d3d77d63709e47d9ef58f0b557800115a6b676c6a423012fbb96f45d8fcef830.json +28 -0
- data/spec/bitcoin/fixtures/tx-e335562f7e297aadeed88e5954bc4eeb8dc00b31d829eedb232e39d672b0c009.json +406 -0
- data/spec/bitcoin/fixtures/tx-eb3b82c0884e3efa6d8b0be55b4915eb20be124c9766245bcc7f34fdac32bccb.json +35 -0
- data/spec/bitcoin/fixtures/tx-fee1b9b85531c8fb6cd7831f83490c7f2aa768b6eefe29854ef5e89ce7b9ecb1.json +64 -0
- data/spec/bitcoin/fixtures/txdp-1.txt +32 -0
- data/spec/bitcoin/fixtures/txdp-2-signed.txt +19 -0
- data/spec/bitcoin/fixtures/txdp-2-unsigned.txt +14 -0
- data/spec/bitcoin/fixtures/txscript-invalid-too-many-sigops-followed-by-invalid-pushdata.bin +1 -0
- data/spec/bitcoin/helpers/fake_blockchain.rb +183 -0
- data/spec/bitcoin/key_spec.rb +326 -0
- data/spec/bitcoin/network_spec.rb +50 -0
- data/spec/bitcoin/performance/storage_spec.rb +41 -0
- data/spec/bitcoin/protocol/addr_spec.rb +82 -0
- data/spec/bitcoin/protocol/alert_spec.rb +22 -0
- data/spec/bitcoin/protocol/aux_pow_spec.rb +45 -0
- data/spec/bitcoin/protocol/bip143_spec.rb +116 -0
- data/spec/bitcoin/protocol/block_spec.rb +208 -0
- data/spec/bitcoin/protocol/getblocks_spec.rb +32 -0
- data/spec/bitcoin/protocol/inv_spec.rb +134 -0
- data/spec/bitcoin/protocol/notfound_spec.rb +31 -0
- data/spec/bitcoin/protocol/parser_spec.rb +50 -0
- data/spec/bitcoin/protocol/partial_merkle_tree_spec.rb +38 -0
- data/spec/bitcoin/protocol/ping_spec.rb +51 -0
- data/spec/bitcoin/protocol/reject.rb +17 -0
- data/spec/bitcoin/protocol/tx_spec.rb +894 -0
- data/spec/bitcoin/protocol/txin_spec.rb +45 -0
- data/spec/bitcoin/protocol/txout_spec.rb +27 -0
- data/spec/bitcoin/protocol/version_spec.rb +110 -0
- data/spec/bitcoin/script/opcodes_spec.rb +773 -0
- data/spec/bitcoin/script/script_spec.rb +971 -0
- data/spec/bitcoin/secp256k1_spec.rb +78 -0
- data/spec/bitcoin/spec_helper.rb +108 -0
- data/spec/bitcoin/trezor/mnemonic_spec.rb +161 -0
- metadata +237 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
|
3
|
+
require_relative 'spec_helper.rb'
|
4
|
+
|
5
|
+
describe 'Bitcoin::network' do
|
6
|
+
|
7
|
+
it 'returns network descriptor' do
|
8
|
+
Bitcoin.network = :bitcoin
|
9
|
+
net = Bitcoin::network
|
10
|
+
net[:magic_head].should == "\xF9\xBE\xB4\xD9"
|
11
|
+
net[:address_version].should == "00"
|
12
|
+
net[:genesis_hash].should == "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'can be set to main net' do
|
16
|
+
Bitcoin::network = :bitcoin
|
17
|
+
Bitcoin::network.should == Bitcoin::NETWORKS[:bitcoin]
|
18
|
+
end
|
19
|
+
|
20
|
+
class Test_Handler
|
21
|
+
attr_reader :inv
|
22
|
+
def on_inv_transaction inv
|
23
|
+
@inv = inv
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'uses correct magic_head when parsing a message' do
|
28
|
+
pkt = ["f9 be b4 d9 69 6e 76 00 00 00 00 00 00 00 00 00 49 00 00 00 11 ea 1c 91 02 01 00 00 00 e0 41 c2 38 f7 32 1a 68 0a 34 06 bf fd 72 12 e3 d1 2c b5 12 2a 8c 0b 52 76 de 82 30 b1 00 7a 42 01 00 00 00 33 00 09 71 a9 70 7b 6c 6d 6e 77 aa 2e ac 43 f3 e5 67 84 cb 61 b2 35 fb 8d fe e0 86 8b 40 7c f3".split(" ").join].pack("H*")
|
29
|
+
|
30
|
+
parser1 = Bitcoin::Protocol::Parser.new(handler1 = Test_Handler.new)
|
31
|
+
parser2 = Bitcoin::Protocol::Parser.new(handler2 = Test_Handler.new)
|
32
|
+
|
33
|
+
Bitcoin::network = :testnet
|
34
|
+
parser2.parse(pkt).should == ""
|
35
|
+
handler2.inv.should == nil
|
36
|
+
|
37
|
+
Bitcoin::network = :bitcoin
|
38
|
+
parser1.parse(pkt).should == ''
|
39
|
+
handler1.inv.should == ["f37c408b86e0fe8dfb35b261cb8467e5f343ac2eaa776e6d6c7b70a971090033"].pack("H*")
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'uses correct magic head when creating a message' do
|
43
|
+
Bitcoin::network = :testnet
|
44
|
+
Bitcoin::Protocol.pkt('foo', "bar")[0...4].should == "\xFA\xBF\xB5\xDA"
|
45
|
+
|
46
|
+
Bitcoin::network = :bitcoin
|
47
|
+
Bitcoin::Protocol.pkt('foo', "bar")[0...4].should == "\xF9\xBE\xB4\xD9"
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
|
3
|
+
require_relative '../spec_helper'
|
4
|
+
require_relative '../helpers/fake_blockchain'
|
5
|
+
require 'benchmark'
|
6
|
+
|
7
|
+
[
|
8
|
+
[:sequel, :postgres]
|
9
|
+
].compact.each do |options|
|
10
|
+
|
11
|
+
next unless storage = setup_db(*options)
|
12
|
+
|
13
|
+
describe "#{storage.backend_name} block storage" do
|
14
|
+
|
15
|
+
before do
|
16
|
+
@store = storage
|
17
|
+
@store.reset
|
18
|
+
@store.log.level = :error
|
19
|
+
@fake_chain = FakeBlockchain.new 10
|
20
|
+
end
|
21
|
+
|
22
|
+
it "block storage" do
|
23
|
+
blocks = (0..10).to_a.map{|i| @fake_chain.block(i) }
|
24
|
+
|
25
|
+
bm = Benchmark.measure do
|
26
|
+
bm = Benchmark.bm do |b|
|
27
|
+
blocks.each.with_index do |blk,i|
|
28
|
+
b.report("storing fake block ##{i}") do
|
29
|
+
depth, chain = @store.new_block blk
|
30
|
+
chain.should == 0
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
puts '-'*80
|
36
|
+
puts "TOTAL #{bm.format}"
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
|
3
|
+
require_relative '../spec_helper.rb'
|
4
|
+
|
5
|
+
describe 'Bitcoin::Protocol::Parser (addr)' do
|
6
|
+
|
7
|
+
it 'parses address packet' do
|
8
|
+
pkt = [
|
9
|
+
"f9 be b4 d9 61 64 64 72 00 00 00 00 00 00 00 00 1f 00 00 00 e8 b4 c9 ba 01 2b dd d7 4d 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 52 53 de 04 20 8d"
|
10
|
+
.split(" ").join].pack("H*")
|
11
|
+
|
12
|
+
class Addr_Handler < Bitcoin::Protocol::Handler
|
13
|
+
attr_reader :addr, :err
|
14
|
+
def on_addr(addr); (@addr ||= []) << addr; end
|
15
|
+
def on_error(*err); (@err ||= []) << err; end
|
16
|
+
end
|
17
|
+
|
18
|
+
parser = Bitcoin::Protocol::Parser.new( handler = Addr_Handler.new )
|
19
|
+
parser.parse(pkt + "AAAA").should == "AAAA"
|
20
|
+
|
21
|
+
handler.addr.size .should == 1
|
22
|
+
handler.addr.first.alive? .should == false
|
23
|
+
handler.addr.map{|i| i.values }.should == [
|
24
|
+
[1305992491, 1, "82.83.222.4", 8333]
|
25
|
+
]
|
26
|
+
end
|
27
|
+
|
28
|
+
it "parses broken address packet" do
|
29
|
+
pkt = ["01 00 00 00 00".split(" ").join].pack("H*")
|
30
|
+
parser = Bitcoin::Protocol::Parser.new( handler = Addr_Handler.new )
|
31
|
+
parser.parse_addr(pkt).should == nil
|
32
|
+
handler.addr.should == nil
|
33
|
+
handler.err.should == [[:addr, pkt[1..-1]]]
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'Bitcoin::Protocol::Addr' do
|
39
|
+
|
40
|
+
before do
|
41
|
+
@pkt = [
|
42
|
+
"2b dd d7 4d 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 52 53 de 04 20 8d"
|
43
|
+
.split(" ").join].pack("H*")
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'parse addr payload' do
|
47
|
+
addr = Bitcoin::Protocol::Addr.new(@pkt)
|
48
|
+
addr.values.should == [1305992491, 1, "82.83.222.4", 8333]
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'initalize time, service and port' do
|
52
|
+
Time.freeze do
|
53
|
+
addr = Bitcoin::Protocol::Addr.new(nil)
|
54
|
+
addr[:time].should == Time.now.to_i
|
55
|
+
addr[:service] .should == 1
|
56
|
+
addr[:port] .should == Bitcoin.network[:default_port]
|
57
|
+
addr[:ip] .should == "127.0.0.1"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'addr payload' do
|
62
|
+
addr = Bitcoin::Protocol::Addr.new
|
63
|
+
addr[:time] = 1305992491
|
64
|
+
addr[:service] = 1
|
65
|
+
addr[:ip] = "82.83.222.4"
|
66
|
+
addr[:port] = 8333
|
67
|
+
addr.to_payload.should == @pkt
|
68
|
+
addr.to_payload.bytesize.should == 30
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
it 'pack addr packet' do
|
73
|
+
addr = Bitcoin::Protocol::Addr.new
|
74
|
+
addr[:time] = 1305992491
|
75
|
+
addr[:service] = 1
|
76
|
+
addr[:ip] = "82.83.222.4"
|
77
|
+
addr[:port] = 8333
|
78
|
+
Bitcoin::Protocol::Addr.pkt(addr).should ==
|
79
|
+
Bitcoin::Protocol.pkt("addr", "\x01" + addr.to_payload)
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
|
3
|
+
require_relative '../spec_helper.rb'
|
4
|
+
|
5
|
+
describe 'Bitcoin::Protocol::Parser (alert)' do
|
6
|
+
|
7
|
+
it 'parses alert' do
|
8
|
+
payload = "s\x01\x00\x00\x007f@O\x00\x00\x00\x00\xB3\x05CO\x00\x00\x00\x00\xF2\x03\x00\x00\xF1\x03\x00\x00\x00\x10'\x00\x00H\xEE\x00\x00\x00d\x00\x00\x00\x00FSee bitcoin.org/feb20 if you have trouble connecting after 20 February\x00G0E\x02!\x00\x83\x89\xDFE\xF0p?9\xEC\x8C\x1C\xC4,\x13\x81\x0F\xFC\xAE\x14\x99[\xB6H4\x02\x19\xE3S\xB6;S\xEB\x02 \t\xECe\xE1\xC1\xAA\xEE\xC1\xFD3LkhK\xDE+?W0`\xD5\xB7\f:Fr3&\xE4\xE8\xA4\xF1"
|
9
|
+
|
10
|
+
alert = Bitcoin::Protocol::Alert.parse(payload)
|
11
|
+
alert.values.should == [1, 1329620535, 1329792435, 1010, 1009, nil, 10000, 61000, nil, 100, nil, "See bitcoin.org/feb20 if you have trouble connecting after 20 February", nil]
|
12
|
+
alert.valid_signature?.should == true
|
13
|
+
|
14
|
+
|
15
|
+
payload = "\xAC\x01\x00\x00\x00o\xF2cO\x00\x00\x00\x00k\"EQ\x00\x00\x00\x00\xF4\x03\x00\x00\xF2\x03\x00\x00\x00`\xEA\x00\x00`\xEA\x00\x00\x03\x11/Satoshi:0.6.0.3/\x0F/Satoshi:0.6.0/\x12/bitcoin-qt:0.6.0/\x88\x13\x00\x00\x00JURGENT: security fix for Bitcoin-Qt on Windows: http://bitcoin.org/critfix\x00H0F\x02!\x00\xB7\xB1o\x86\x0F\x9EZ\x87bt\xAE\xB7$u\xD2\xDE\xC3\x86j\xA7\xAF\x82\xAD\x97\\\x83Qd\xA9\x97\xA7\x16\x02!\x00\x86\xB4\x18)\xCB\x84\xBE\xD2\x86\x10\x82G\xBE\xBF;\xE9{\xD9\xB3\x1E\xB4/g\xB4\xD33\xCE\x8B\x1D}\xF8^"
|
16
|
+
|
17
|
+
alert = Bitcoin::Protocol::Alert.parse(payload)
|
18
|
+
alert.values.should == [1, 1331950191, 1363485291, 1012, 1010, nil, 60000, 60000, ["/Satoshi:0.6.0.3/", "/Satoshi:0.6.0/", "/bitcoin-qt:0.6.0/"], 5000, nil, "URGENT: security fix for Bitcoin-Qt on Windows: http://bitcoin.org/critfix", nil]
|
19
|
+
alert.valid_signature?.should == true
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
|
3
|
+
require_relative '../spec_helper.rb'
|
4
|
+
|
5
|
+
include Bitcoin
|
6
|
+
|
7
|
+
describe Bitcoin::Protocol::AuxPow do
|
8
|
+
|
9
|
+
before do
|
10
|
+
Bitcoin.network = :namecoin
|
11
|
+
@data = fixtures_file("rawblock-auxpow.bin")
|
12
|
+
@blk = P::Block.new(@data)
|
13
|
+
@aux_pow = @blk.aux_pow
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should parse AuxPow" do
|
17
|
+
@aux_pow.should != nil
|
18
|
+
@aux_pow.block_hash.hth.should ==
|
19
|
+
"b42124fd99e67ddabe52ebbfcb30a82b8c74268a320b3c5e2311000000000000"
|
20
|
+
@aux_pow.coinbase_branch.should == [
|
21
|
+
"c22f79ba86968a5285225008b2740f074f44f44ef27b8efb61ecff09e9eb4f6d",
|
22
|
+
"99696473beb0caa79d4209dbaa6e18fdc23ebdc67210f86fec0c4559847252d0",
|
23
|
+
"20cbcff309ec8c267892a476c1b22d23d9e5d7a6fdfd025658de6c2ae4e7c564",
|
24
|
+
"e4317593d6ad8d735ded56c336376b7409207c3ea6b92b2451f79eced606944e" ]
|
25
|
+
@aux_pow.coinbase_index.should == 0
|
26
|
+
@aux_pow.chain_branch.should == []
|
27
|
+
@aux_pow.chain_index.should == 0
|
28
|
+
@aux_pow.parent_block.hash.should ==
|
29
|
+
"00000000000011235e3c0b328a26748c2ba830cbbfeb52beda7de699fd2421b4"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "#to_payload" do
|
33
|
+
@blk.to_payload.should == @data
|
34
|
+
P::Block.new(@blk.to_payload).to_payload.should == @data
|
35
|
+
end
|
36
|
+
|
37
|
+
it "#to_hash" do
|
38
|
+
P::Block.from_hash(@blk.to_hash).to_payload.should == @data
|
39
|
+
end
|
40
|
+
|
41
|
+
it "#to_json" do
|
42
|
+
P::Block.from_json(@blk.to_json).to_payload.should == @data
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
|
3
|
+
require_relative '../spec_helper.rb'
|
4
|
+
|
5
|
+
include Bitcoin::Protocol
|
6
|
+
|
7
|
+
# this spec requires secp256k1 library
|
8
|
+
describe 'BIP143 spec' do
|
9
|
+
|
10
|
+
# https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki#Example
|
11
|
+
|
12
|
+
it 'Native P2WPKH' do
|
13
|
+
tx = Tx.new('0100000002fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f0000000000eeffffffef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a0100000000ffffffff02202cb206000000001976a9148280b37df378db99f66f85c95a783a76ac7a6d5988ac9093510d000000001976a9143bde42dbee7e4dbe6a21b2d50ce2f0167faa815988ac11000000'.htb)
|
14
|
+
|
15
|
+
sig_hash0 = tx.signature_hash_for_input(0, '2103c9f4836b9a4f77fc0d81f7bcb01b7f1b35916864b9476c241ce9fc198bd25432ac'.htb)
|
16
|
+
sig0 = Bitcoin::Secp256k1.sign(sig_hash0, 'bbc27228ddcb9209d7fd6f36b02f7dfa6252af40bb2f1cbc7a557da8027ff866'.htb) + [Tx::SIGHASH_TYPE[:all]].pack("C")
|
17
|
+
|
18
|
+
tx.in[0].script_sig = Bitcoin::Script.new(Bitcoin::Script.pack_pushdata(sig0)).to_payload
|
19
|
+
|
20
|
+
sig_hash1 = tx.signature_hash_for_witness_input(1, '00141d0f172a0ecb48aee1be1f2687d2963ae33f71a1'.htb, 600000000)
|
21
|
+
sig1 = Bitcoin::Secp256k1.sign(sig_hash1, '619c335025c7f4012e556c2a58b2506e30b8511b53ade95ea316fd8c3286feb9'.htb) + [Tx::SIGHASH_TYPE[:all]].pack("C")
|
22
|
+
|
23
|
+
tx.in[1].script_witness.stack << sig1
|
24
|
+
tx.in[1].script_witness.stack << '025476c2e83188368da1ff3e292e7acafcdb3566bb0ad253f62fc70f07aeee6357'.htb
|
25
|
+
|
26
|
+
tx.to_witness_payload.bth.should == '01000000000102fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f00000000494830450221008b9d1dc26ba6a9cb62127b02742fa9d754cd3bebf337f7a55d114c8e5cdd30be022040529b194ba3f9281a99f2b1c0a19c0489bc22ede944ccf4ecbab4cc618ef3ed01eeffffffef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a0100000000ffffffff02202cb206000000001976a9148280b37df378db99f66f85c95a783a76ac7a6d5988ac9093510d000000001976a9143bde42dbee7e4dbe6a21b2d50ce2f0167faa815988ac000247304402203609e17b84f6a7d30c80bfa610b5b4542f32a8a0d5447a12fb1366d7f01cc44a0220573a954c4518331561406f90300e8f3358f51928d43c212a8caed02de67eebee0121025476c2e83188368da1ff3e292e7acafcdb3566bb0ad253f62fc70f07aeee635711000000'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'P2SH-P2WPKH' do
|
30
|
+
redeem_script = '001479091972186c449eb1ded22b78e40d009bdf0089'
|
31
|
+
tx = Tx.new('0100000001db6b1b20aa0fd7b23880be2ecbd4a98130974cf4748fb66092ac4d3ceb1a54770100000000feffffff02b8b4eb0b000000001976a914a457b684d7f0d539a46a45bbc043f35b59d0d96388ac0008af2f000000001976a914fd270b1ee6abcaea97fea7ad0402e8bd8ad6d77c88ac92040000'.htb)
|
32
|
+
|
33
|
+
tx.in[0].script_sig = Bitcoin::Script.new(Bitcoin::Script.pack_pushdata(redeem_script.htb)).to_payload
|
34
|
+
|
35
|
+
sig_hash = tx.signature_hash_for_witness_input(0, redeem_script.htb, 1000000000)
|
36
|
+
sig = Bitcoin::Secp256k1.sign(sig_hash, 'eb696a065ef48a2192da5b28b694f87544b30fae8327c4510137a922f32c6dcf'.htb) + [Tx::SIGHASH_TYPE[:all]].pack("C")
|
37
|
+
|
38
|
+
tx.in[0].script_witness.stack << sig
|
39
|
+
tx.in[0].script_witness.stack << '03ad1d8e89212f0b92c74d23bb710c00662ad1470198ac48c43f7d6f93a2a26873'.htb
|
40
|
+
|
41
|
+
tx.to_witness_payload.bth.should == '01000000000101db6b1b20aa0fd7b23880be2ecbd4a98130974cf4748fb66092ac4d3ceb1a5477010000001716001479091972186c449eb1ded22b78e40d009bdf0089feffffff02b8b4eb0b000000001976a914a457b684d7f0d539a46a45bbc043f35b59d0d96388ac0008af2f000000001976a914fd270b1ee6abcaea97fea7ad0402e8bd8ad6d77c88ac02473044022047ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f0220217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb012103ad1d8e89212f0b92c74d23bb710c00662ad1470198ac48c43f7d6f93a2a2687392040000'
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'Native P2WSH' do
|
45
|
+
# <026dccc749adc2a9d0d89497ac511f760f45c47dc5ed9cf352a58ac706453880ae> CHECKSIGVERIFY CODESEPERATOR <0255a9626aebf5e29c0e6538428ba0d1dcf6ca98ffdf086aa8ced5e0d0215ea465> CHECKSIG
|
46
|
+
# this script needs two privkey signature
|
47
|
+
witness_script = Bitcoin::Script.new('21026dccc749adc2a9d0d89497ac511f760f45c47dc5ed9cf352a58ac706453880aeadab210255a9626aebf5e29c0e6538428ba0d1dcf6ca98ffdf086aa8ced5e0d0215ea465ac'.htb)
|
48
|
+
script_pubkey = '00205d1b56b63d714eebe542309525f484b7e9d6f686b3781b6f61ef925d66d6f6a0'
|
49
|
+
|
50
|
+
tx = Tx.new('0100000002fe3dc9208094f3ffd12645477b3dc56f60ec4fa8e6f5d67c565d1c6b9216b36e0000000000ffffffff0815cf020f013ed6cf91d29f4202e8a58726b1ac6c79da47c23d1bee0a6925f80000000000ffffffff0100f2052a010000001976a914a30741f8145e5acadf23f751864167f32e0963f788ac00000000'.htb)
|
51
|
+
|
52
|
+
sig_hash0 = tx.signature_hash_for_input(0, '21036d5c20fa14fb2f635474c1dc4ef5909d4568e5569b79fc94d3448486e14685f8ac'.htb)
|
53
|
+
sig0 = Bitcoin::Secp256k1.sign(sig_hash0, 'b8f28a772fccbf9b4f58a4f027e07dc2e35e7cd80529975e292ea34f84c4580c'.htb) + [Tx::SIGHASH_TYPE[:all]].pack("C")
|
54
|
+
tx.in[0].script_sig = Bitcoin::Script.new(Bitcoin::Script.pack_pushdata(sig0)).to_payload
|
55
|
+
|
56
|
+
sig_hash1 = tx.signature_hash_for_witness_input(1, script_pubkey.htb, 4900000000, witness_script.to_payload, Tx::SIGHASH_TYPE[:single])
|
57
|
+
sig1 = Bitcoin::Secp256k1.sign(sig_hash1, '8e02b539b1500aa7c81cf3fed177448a546f19d2be416c0c61ff28e577d8d0cd'.htb) + [Tx::SIGHASH_TYPE[:single]].pack("C")
|
58
|
+
|
59
|
+
sig_hash2 = tx.signature_hash_for_witness_input(1, script_pubkey.htb, 4900000000, witness_script.to_payload, Tx::SIGHASH_TYPE[:single], 1)
|
60
|
+
sig2 = Bitcoin::Secp256k1.sign(sig_hash2, '86bf2ed75935a0cbef03b89d72034bb4c189d381037a5ac121a70016db8896ec'.htb) + [Tx::SIGHASH_TYPE[:single]].pack("C")
|
61
|
+
|
62
|
+
tx.in[1].script_witness.stack << sig2
|
63
|
+
tx.in[1].script_witness.stack << sig1
|
64
|
+
tx.in[1].script_witness.stack << witness_script.to_payload
|
65
|
+
|
66
|
+
tx.to_witness_payload.bth.should == '01000000000102fe3dc9208094f3ffd12645477b3dc56f60ec4fa8e6f5d67c565d1c6b9216b36e000000004847304402200af4e47c9b9629dbecc21f73af989bdaa911f7e6f6c2e9394588a3aa68f81e9902204f3fcf6ade7e5abb1295b6774c8e0abd94ae62217367096bc02ee5e435b67da201ffffffff0815cf020f013ed6cf91d29f4202e8a58726b1ac6c79da47c23d1bee0a6925f80000000000ffffffff0100f2052a010000001976a914a30741f8145e5acadf23f751864167f32e0963f788ac000347304402200de66acf4527789bfda55fc5459e214fa6083f936b430a762c629656216805ac0220396f550692cd347171cbc1ef1f51e15282e837bb2b30860dc77c8f78bc8501e503473044022027dc95ad6b740fe5129e7e62a75dd00f291a2aeb1200b84b09d9e3789406b6c002201a9ecd315dd6a0e632ab20bbb98948bc0c6fb204f2c286963bb48517a7058e27034721026dccc749adc2a9d0d89497ac511f760f45c47dc5ed9cf352a58ac706453880aeadab210255a9626aebf5e29c0e6538428ba0d1dcf6ca98ffdf086aa8ced5e0d0215ea465ac00000000'
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
it 'P2SH-P2WSH' do
|
71
|
+
redeem_script = '0020a16b5755f7f6f96dbd65f5f0d6ab9418b89af4b1f14a1bb8a09062c35f0dcb54'
|
72
|
+
# 6-of-6 multisig
|
73
|
+
witness_script = Bitcoin::Script.new('56210307b8ae49ac90a048e9b53357a2354b3334e9c8bee813ecb98e99a7e07e8c3ba32103b28f0c28bfab54554ae8c658ac5c3e0ce6e79ad336331f78c428dd43eea8449b21034b8113d703413d57761b8b9781957b8c0ac1dfe69f492580ca4195f50376ba4a21033400f6afecb833092a9a21cfdf1ed1376e58c5d1f47de74683123987e967a8f42103a6d48b1131e94ba04d9737d61acdaa1322008af9602b3b14862c07a1789aac162102d8b661b0b3302ee2f162b09e07a55ad5dfbe673a9f01d9f0c19617681024306b56ae'.htb)
|
74
|
+
|
75
|
+
tx = Tx.new('010000000136641869ca081e70f394c6948e8af409e18b619df2ed74aa106c1ca29787b96e0100000000ffffffff0200e9a435000000001976a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe2688acc0832f05000000001976a9147480a33f950689af511e6e84c138dbbd3c3ee41588ac00000000'.htb)
|
76
|
+
tx.in[0].script_sig = Bitcoin::Script.new(Bitcoin::Script.pack_pushdata(redeem_script.htb)).to_payload
|
77
|
+
|
78
|
+
|
79
|
+
tx.in[0].script_witness.stack << ''
|
80
|
+
|
81
|
+
sig_hash0 = tx.signature_hash_for_witness_input(0, redeem_script.htb, 987654321, witness_script.to_payload)
|
82
|
+
sig0 = Bitcoin::Secp256k1.sign(sig_hash0, '730fff80e1413068a05b57d6a58261f07551163369787f349438ea38ca80fac6'.htb) + [Tx::SIGHASH_TYPE[:all]].pack("C")
|
83
|
+
sig0.bth.should == '304402206ac44d672dac41f9b00e28f4df20c52eeb087207e8d758d76d92c6fab3b73e2b0220367750dbbe19290069cba53d096f44530e4f98acaa594810388cf7409a1870ce01'
|
84
|
+
tx.in[0].script_witness.stack << sig0
|
85
|
+
|
86
|
+
sig_hash1 = tx.signature_hash_for_witness_input(0, redeem_script.htb, 987654321, witness_script.to_payload, Tx::SIGHASH_TYPE[:none])
|
87
|
+
sig1 = Bitcoin::Secp256k1.sign(sig_hash1, '11fa3d25a17cbc22b29c44a484ba552b5a53149d106d3d853e22fdd05a2d8bb3'.htb) + [Tx::SIGHASH_TYPE[:none]].pack("C")
|
88
|
+
sig1.bth.should == '3044022068c7946a43232757cbdf9176f009a928e1cd9a1a8c212f15c1e11ac9f2925d9002205b75f937ff2f9f3c1246e547e54f62e027f64eefa2695578cc6432cdabce271502'
|
89
|
+
tx.in[0].script_witness.stack << sig1
|
90
|
+
|
91
|
+
sig_hash2 = tx.signature_hash_for_witness_input(0, redeem_script.htb, 987654321, witness_script.to_payload, Tx::SIGHASH_TYPE[:single])
|
92
|
+
sig2 = Bitcoin::Secp256k1.sign(sig_hash2, '77bf4141a87d55bdd7f3cd0bdccf6e9e642935fec45f2f30047be7b799120661'.htb) + [Tx::SIGHASH_TYPE[:single]].pack("C")
|
93
|
+
sig2.bth.should == '3044022059ebf56d98010a932cf8ecfec54c48e6139ed6adb0728c09cbe1e4fa0915302e022007cd986c8fa870ff5d2b3a89139c9fe7e499259875357e20fcbb15571c76795403'
|
94
|
+
tx.in[0].script_witness.stack << sig2
|
95
|
+
|
96
|
+
sig_hash3 = tx.signature_hash_for_witness_input(0, redeem_script.htb, 987654321, witness_script.to_payload, Tx::SIGHASH_TYPE[:all] | Tx::SIGHASH_TYPE[:anyonecanpay])
|
97
|
+
sig3 = Bitcoin::Secp256k1.sign(sig_hash3, '14af36970f5025ea3e8b5542c0f8ebe7763e674838d08808896b63c3351ffe49'.htb) + [Tx::SIGHASH_TYPE[:all] | Tx::SIGHASH_TYPE[:anyonecanpay]].pack("C")
|
98
|
+
sig3.bth.should == '3045022100fbefd94bd0a488d50b79102b5dad4ab6ced30c4069f1eaa69a4b5a763414067e02203156c6a5c9cf88f91265f5a942e96213afae16d83321c8b31bb342142a14d16381'
|
99
|
+
tx.in[0].script_witness.stack << sig3
|
100
|
+
|
101
|
+
sig_hash4 = tx.signature_hash_for_witness_input(0, redeem_script.htb, 987654321, witness_script.to_payload, Tx::SIGHASH_TYPE[:none] | Tx::SIGHASH_TYPE[:anyonecanpay])
|
102
|
+
sig4 = Bitcoin::Secp256k1.sign(sig_hash4, 'fe9a95c19eef81dde2b95c1284ef39be497d128e2aa46916fb02d552485e0323'.htb) + [Tx::SIGHASH_TYPE[:none] | Tx::SIGHASH_TYPE[:anyonecanpay]].pack("C")
|
103
|
+
sig4.bth.should == '3045022100a5263ea0553ba89221984bd7f0b13613db16e7a70c549a86de0cc0444141a407022005c360ef0ae5a5d4f9f2f87a56c1546cc8268cab08c73501d6b3be2e1e1a8a0882'
|
104
|
+
tx.in[0].script_witness.stack << sig4
|
105
|
+
|
106
|
+
sig_hash5 = tx.signature_hash_for_witness_input(0, redeem_script.htb, 987654321, witness_script.to_payload, Tx::SIGHASH_TYPE[:single] | Tx::SIGHASH_TYPE[:anyonecanpay])
|
107
|
+
sig5 = Bitcoin::Secp256k1.sign(sig_hash5, '428a7aee9f0c2af0cd19af3cf1c78149951ea528726989b2e83e4778d2c3f890'.htb) + [Tx::SIGHASH_TYPE[:single] | Tx::SIGHASH_TYPE[:anyonecanpay]].pack("C")
|
108
|
+
sig5.bth.should == '30440220525406a1482936d5a21888260dc165497a90a15669636d8edca6b9fe490d309c022032af0c646a34a44d1f4576bf6a4a74b67940f8faa84c7df9abe12a01a11e2b4783'
|
109
|
+
tx.in[0].script_witness.stack << sig5
|
110
|
+
|
111
|
+
tx.in[0].script_witness.stack << witness_script.to_payload
|
112
|
+
|
113
|
+
tx.to_witness_payload.bth.should == '0100000000010136641869ca081e70f394c6948e8af409e18b619df2ed74aa106c1ca29787b96e0100000023220020a16b5755f7f6f96dbd65f5f0d6ab9418b89af4b1f14a1bb8a09062c35f0dcb54ffffffff0200e9a435000000001976a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe2688acc0832f05000000001976a9147480a33f950689af511e6e84c138dbbd3c3ee41588ac080047304402206ac44d672dac41f9b00e28f4df20c52eeb087207e8d758d76d92c6fab3b73e2b0220367750dbbe19290069cba53d096f44530e4f98acaa594810388cf7409a1870ce01473044022068c7946a43232757cbdf9176f009a928e1cd9a1a8c212f15c1e11ac9f2925d9002205b75f937ff2f9f3c1246e547e54f62e027f64eefa2695578cc6432cdabce271502473044022059ebf56d98010a932cf8ecfec54c48e6139ed6adb0728c09cbe1e4fa0915302e022007cd986c8fa870ff5d2b3a89139c9fe7e499259875357e20fcbb15571c76795403483045022100fbefd94bd0a488d50b79102b5dad4ab6ced30c4069f1eaa69a4b5a763414067e02203156c6a5c9cf88f91265f5a942e96213afae16d83321c8b31bb342142a14d16381483045022100a5263ea0553ba89221984bd7f0b13613db16e7a70c549a86de0cc0444141a407022005c360ef0ae5a5d4f9f2f87a56c1546cc8268cab08c73501d6b3be2e1e1a8a08824730440220525406a1482936d5a21888260dc165497a90a15669636d8edca6b9fe490d309c022032af0c646a34a44d1f4576bf6a4a74b67940f8faa84c7df9abe12a01a11e2b4783cf56210307b8ae49ac90a048e9b53357a2354b3334e9c8bee813ecb98e99a7e07e8c3ba32103b28f0c28bfab54554ae8c658ac5c3e0ce6e79ad336331f78c428dd43eea8449b21034b8113d703413d57761b8b9781957b8c0ac1dfe69f492580ca4195f50376ba4a21033400f6afecb833092a9a21cfdf1ed1376e58c5d1f47de74683123987e967a8f42103a6d48b1131e94ba04d9737d61acdaa1322008af9602b3b14862c07a1789aac162102d8b661b0b3302ee2f162b09e07a55ad5dfbe673a9f01d9f0c19617681024306b56ae00000000'
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
@@ -0,0 +1,208 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
|
3
|
+
require_relative '../spec_helper.rb'
|
4
|
+
include Bitcoin::Protocol
|
5
|
+
|
6
|
+
describe 'Bitcoin::Protocol::Block' do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@blocks = {
|
10
|
+
# block 0: 00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048
|
11
|
+
'0' => fixtures_file('rawblock-0.bin'),
|
12
|
+
# block 1: 000000006a625f06636b8bb6ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd
|
13
|
+
'1' => fixtures_file('rawblock-1.bin'),
|
14
|
+
# block 9: 000000008d9dc510f23c2657fc4f67bea30078cc05a90eb89e84cc475c080805
|
15
|
+
'9' => fixtures_file('rawblock-9.bin'),
|
16
|
+
# block 170: 00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee
|
17
|
+
'170' => fixtures_file('rawblock-170.bin'),
|
18
|
+
# block 131025: 00000000000007d938dbdd433c5ae12a782de74abf7f566518bc2b2d0a1df145
|
19
|
+
'131025' => fixtures_file('rawblock-131025.bin'),
|
20
|
+
# block 26478: 000000000214a3f06ee99a033a7f2252762d6a18d27c3cd8c8fe2278190da9f3
|
21
|
+
'testnet-26478' => fixtures_file('rawblock-testnet-26478.bin'),
|
22
|
+
'testnet-265322' => fixtures_file('rawblock-testnet-265322.bin'),
|
23
|
+
# block 1151351: 000000000000031525003c4e061fd2e5ce5f4fda6121a836e66f70ec2df621de
|
24
|
+
'testnet-1151351' => fixtures_file('rawblock-testnet-1151351.bin'),
|
25
|
+
# block 100005: 000000000000dab0130bbcc991d3d7ae6b81aa6f50a798888dfe62337458dc45
|
26
|
+
'filtered-0' => fixtures_file('filteredblock-0.bin'),
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
it '#new' do
|
31
|
+
proc{
|
32
|
+
Block.new( nil )
|
33
|
+
@block = Block.new( @blocks['0'] )
|
34
|
+
}.should.not.raise Exception
|
35
|
+
|
36
|
+
proc{
|
37
|
+
Block.new( @blocks['0'][0..20] )
|
38
|
+
}.should.raise Exception
|
39
|
+
|
40
|
+
block = Block.new(nil)
|
41
|
+
block.parse_data(@blocks['0']).should == true
|
42
|
+
block.header_info[7].should == 215
|
43
|
+
block.to_payload.should == @blocks['0']
|
44
|
+
|
45
|
+
block = Block.new(nil)
|
46
|
+
block.parse_data(@blocks['0'] + "AAAA").should == "AAAA"
|
47
|
+
block.header_info[7].should == 215
|
48
|
+
block.to_payload.should == @blocks['0']
|
49
|
+
|
50
|
+
# parse block which includes segwit tx
|
51
|
+
block = Block.new(@blocks['testnet-1151351'])
|
52
|
+
block.mrkl_root.should == 'e4bbfc681f2bf0ed5fe13a01f5f82bd1844d406fe793a7ec590151f4ea4060d5'.htb.reverse
|
53
|
+
end
|
54
|
+
|
55
|
+
it '#hash' do
|
56
|
+
@block.hash.should == "00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048"
|
57
|
+
end
|
58
|
+
|
59
|
+
it '#tx' do
|
60
|
+
@block.tx.size.should == 1
|
61
|
+
@block.tx[0].is_a?(Tx).should == true
|
62
|
+
@block.tx[0].hash.should == "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "#tx_hashes" do
|
66
|
+
@block.tx_hashes.should == ["0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"]
|
67
|
+
end
|
68
|
+
|
69
|
+
it '#to_hash' do
|
70
|
+
@block.to_hash.keys.should == ["hash", "ver", "prev_block", "mrkl_root", "time", "bits", "nonce", "n_tx", "size", "tx", "mrkl_tree"]
|
71
|
+
end
|
72
|
+
|
73
|
+
it '#to_json' do
|
74
|
+
@block.to_json.should == fixtures_file('rawblock-0.json')
|
75
|
+
Block.new( @blocks['1'] ).to_json.should == fixtures_file('rawblock-1.json')
|
76
|
+
Block.new( @blocks['131025'] ).to_json.should == fixtures_file('rawblock-131025.json')
|
77
|
+
Block.new( @blocks['testnet-26478'] ).to_json.should == fixtures_file('rawblock-testnet-26478.json')
|
78
|
+
Block.from_json(@block.to_json).tx[0].in[0].sequence.should == "\xff\xff\xff\xff"
|
79
|
+
end
|
80
|
+
|
81
|
+
it '#to_payload' do
|
82
|
+
@block.to_payload.should == @block.payload
|
83
|
+
Block.new( @block.to_payload ).to_payload.should == @block.payload
|
84
|
+
Block.new( @blocks['1'] ).to_payload.should == @blocks['1']
|
85
|
+
Block.new( @blocks['131025'] ).to_payload.should == @blocks['131025']
|
86
|
+
Block.new( @blocks['testnet-26478'] ).to_payload.should == @blocks['testnet-26478']
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "Block.from_json" do
|
90
|
+
|
91
|
+
it 'should load blocks from json' do
|
92
|
+
block = Block.from_json(fixtures_file('rawblock-0.json'))
|
93
|
+
block.to_payload.should == @blocks['0']
|
94
|
+
block.tx[0].in[0].sequence.should == "\xff\xff\xff\xff"
|
95
|
+
Block.from_json(fixtures_file('rawblock-1.json')).to_payload.should == @blocks['1']
|
96
|
+
|
97
|
+
Block.from_json(fixtures_file('rawblock-131025.json'))
|
98
|
+
.to_payload.should == @blocks['131025']
|
99
|
+
|
100
|
+
Block.from_json(fixtures_file('rawblock-testnet-26478.json'))
|
101
|
+
.to_payload.should == @blocks['testnet-26478']
|
102
|
+
|
103
|
+
# testnet3 block 0000000000ac85bb2530a05a4214a387e6be02b22d3348abc5e7a5d9c4ce8dab
|
104
|
+
block_raw = fixtures_file('block-testnet-0000000000ac85bb2530a05a4214a387e6be02b22d3348abc5e7a5d9c4ce8dab.bin')
|
105
|
+
Block.new(block_raw).to_payload.should == block_raw
|
106
|
+
# Block.from_json(Block.new(block_raw).to_json).to_payload.should == block_raw # slow test
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should work with litecoin blocks" do
|
110
|
+
Bitcoin.network = :litecoin # change to litecoin
|
111
|
+
litecoin_block = "litecoin-genesis-block-12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2"
|
112
|
+
Block.from_json(fixtures_file(litecoin_block + '.json'))
|
113
|
+
.to_payload.should == fixtures_file(litecoin_block + '.bin')
|
114
|
+
|
115
|
+
json = Block.new(fixtures_file(litecoin_block + '.bin')).to_json
|
116
|
+
Block.from_json(json)
|
117
|
+
.to_payload.should == fixtures_file(litecoin_block + '.bin')
|
118
|
+
Block.from_json(json).hash == litecoin_block.split("-").last
|
119
|
+
|
120
|
+
litecoin_block = "litecoin-block-80ca095ed10b02e53d769eb6eaf92cd04e9e0759e5be4a8477b42911ba49c78f"
|
121
|
+
Block.from_json(fixtures_file(litecoin_block + '.json'))
|
122
|
+
.to_payload.should == fixtures_file(litecoin_block + '.bin')
|
123
|
+
|
124
|
+
json = Block.new(fixtures_file(litecoin_block + '.bin')).to_json
|
125
|
+
Block.from_json(json)
|
126
|
+
.to_payload.should == fixtures_file(litecoin_block + '.bin')
|
127
|
+
Block.from_json(json).hash == litecoin_block.split("-").last
|
128
|
+
Bitcoin.network = :bitcoin
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should check block hash' do
|
132
|
+
block = Block.from_json(fixtures_file('rawblock-0.json'))
|
133
|
+
h = block.to_hash
|
134
|
+
h['hash'][0] = "1"
|
135
|
+
-> { Block.from_hash(h) }.should.raise(Exception)
|
136
|
+
.message.should == "Block hash mismatch! Claimed: 10000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048, Actual: 00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048"
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should check merkle tree" do
|
140
|
+
block = Block.from_json(fixtures_file('rawblock-0.json'))
|
141
|
+
h = block.to_hash
|
142
|
+
h['tx'][0]['ver'] = 2
|
143
|
+
h['tx'][0]['hash'] = "5ea04451af738d113f0ae8559225b7f893f186f099d88c72230a5e19c0bb830d"
|
144
|
+
-> { Block.from_hash(h) }.should.raise(Exception)
|
145
|
+
.message.should.include?("Block merkle root mismatch!")
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
#
|
151
|
+
# following test cases are borrowed from
|
152
|
+
# https://github.com/bitcoinj/bitcoinj/blob/master/core/src/test/java/org/bitcoinj/core/FilteredBlockAndPartialMerkleTreeTests.java
|
153
|
+
#
|
154
|
+
it "filtered block parsing" do
|
155
|
+
block = Block.new
|
156
|
+
proc {
|
157
|
+
block.parse_data_from_io(@blocks['filtered-0'], :filtered)
|
158
|
+
}.should.not.raise Exception
|
159
|
+
|
160
|
+
block.verify_mrkl_root.should == true
|
161
|
+
block.hash.should == '000000000000dab0130bbcc991d3d7ae6b81aa6f50a798888dfe62337458dc45'
|
162
|
+
block.tx_hashes.should == ['63194f18be0af63f2c6bc9dc0f777cbefed3d9415c4af83f3ee3a3d669c00cb5']
|
163
|
+
end
|
164
|
+
|
165
|
+
it '#header_to_json' do
|
166
|
+
@block.header_to_json.should == (<<-JSON).chomp
|
167
|
+
{
|
168
|
+
"hash":"00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048",
|
169
|
+
"ver":1,
|
170
|
+
"prev_block":"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
|
171
|
+
"mrkl_root":"0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098",
|
172
|
+
"time":1231469665,
|
173
|
+
"bits":486604799,
|
174
|
+
"nonce":2573394689,
|
175
|
+
"n_tx":1,
|
176
|
+
"size":215
|
177
|
+
}
|
178
|
+
JSON
|
179
|
+
end
|
180
|
+
|
181
|
+
it '#verify_mrkl_root' do
|
182
|
+
block0 = Block.from_json(fixtures_file('rawblock-0.json'))
|
183
|
+
block1 = Block.from_json(fixtures_file('rawblock-1.json'))
|
184
|
+
block0.tx.size.should == 1
|
185
|
+
block0.verify_mrkl_root.should == true
|
186
|
+
block0.tx << block.tx.last # test against CVE-2012-2459
|
187
|
+
block0.verify_mrkl_root.should == false
|
188
|
+
block0.tx = block1.tx
|
189
|
+
block0.verify_mrkl_root.should == false
|
190
|
+
end
|
191
|
+
|
192
|
+
it '#bip34_block_height' do
|
193
|
+
# block version 1
|
194
|
+
block = Block.from_json(fixtures_file('rawblock-131025.json'))
|
195
|
+
block.ver.should == 1
|
196
|
+
block.bip34_block_height.should == nil
|
197
|
+
# block version 2 (introduced by BIP_0034)
|
198
|
+
block = Block.from_json(fixtures_file('000000000000056b1a3d84a1e2b33cde8915a4b61c0cae14fca6d3e1490b4f98.json'))
|
199
|
+
block.ver.should == 2
|
200
|
+
block.bip34_block_height.should == 197657
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'should work with huge block version' do
|
204
|
+
Bitcoin::P::Block.new(@blocks['testnet-265322']).hash.should ==
|
205
|
+
"0000000000014b351588a177be099e39afd4962cd3d58e9ab5cbe45a9cf83c8a"
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|