spec/bitcoin/protocol/block_spec.rb in bitcoin-ruby-0.0.10 vs spec/bitcoin/protocol/block_spec.rb in bitcoin-ruby-0.0.11
- old
+ new
@@ -18,10 +18,14 @@
# block 131025: 00000000000007d938dbdd433c5ae12a782de74abf7f566518bc2b2d0a1df145
'131025' => fixtures_file('rawblock-131025.bin'),
# block 26478: 000000000214a3f06ee99a033a7f2252762d6a18d27c3cd8c8fe2278190da9f3
'testnet-26478' => fixtures_file('rawblock-testnet-26478.bin'),
'testnet-265322' => fixtures_file('rawblock-testnet-265322.bin'),
+ # block 1151351: 000000000000031525003c4e061fd2e5ce5f4fda6121a836e66f70ec2df621de
+ 'testnet-1151351' => fixtures_file('rawblock-testnet-1151351.bin'),
+ # block 100005: 000000000000dab0130bbcc991d3d7ae6b81aa6f50a798888dfe62337458dc45
+ 'filtered-0' => fixtures_file('filteredblock-0.bin'),
}
end
it '#new' do
proc{
@@ -40,10 +44,14 @@
block = Block.new(nil)
block.parse_data(@blocks['0'] + "AAAA").should == "AAAA"
block.header_info[7].should == 215
block.to_payload.should == @blocks['0']
+
+ # parse block which includes segwit tx
+ block = Block.new(@blocks['testnet-1151351'])
+ block.mrkl_root.should == 'e4bbfc681f2bf0ed5fe13a01f5f82bd1844d406fe793a7ec590151f4ea4060d5'.htb.reverse
end
it '#hash' do
@block.hash.should == "00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048"
end
@@ -52,10 +60,14 @@
@block.tx.size.should == 1
@block.tx[0].is_a?(Tx).should == true
@block.tx[0].hash.should == "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"
end
+ it "#tx_hashes" do
+ @block.tx_hashes.should == ["0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"]
+ end
+
it '#to_hash' do
@block.to_hash.keys.should == ["hash", "ver", "prev_block", "mrkl_root", "time", "bits", "nonce", "n_tx", "size", "tx", "mrkl_tree"]
end
it '#to_json' do
@@ -131,9 +143,24 @@
h['tx'][0]['hash'] = "5ea04451af738d113f0ae8559225b7f893f186f099d88c72230a5e19c0bb830d"
-> { Block.from_hash(h) }.should.raise(Exception)
.message.should.include?("Block merkle root mismatch!")
end
+ end
+
+ #
+ # following test cases are borrowed from
+ # https://github.com/bitcoinj/bitcoinj/blob/master/core/src/test/java/org/bitcoinj/core/FilteredBlockAndPartialMerkleTreeTests.java
+ #
+ it "filtered block parsing" do
+ block = Block.new
+ proc {
+ block.parse_data_from_io(@blocks['filtered-0'], :filtered)
+ }.should.not.raise Exception
+
+ block.verify_mrkl_root.should == true
+ block.hash.should == '000000000000dab0130bbcc991d3d7ae6b81aa6f50a798888dfe62337458dc45'
+ block.tx_hashes.should == ['63194f18be0af63f2c6bc9dc0f777cbefed3d9415c4af83f3ee3a3d669c00cb5']
end
it '#header_to_json' do
@block.header_to_json.should == (<<-JSON).chomp
{