spec/bitcoin/protocol/inv_spec.rb in bitcoin-ruby-0.0.7 vs spec/bitcoin/protocol/inv_spec.rb in bitcoin-ruby-0.0.8

- old
+ new

@@ -3,16 +3,16 @@ require_relative '../spec_helper.rb' describe 'Bitcoin::Protocol::Parser - Inventory Vectors' do class Test_Handler < Bitcoin::Protocol::Handler - attr_reader :tx_inv - attr_reader :block_inv + attr_reader :tx_inv, :block_inv, :err def on_inv_transaction(hash); (@tx_inv ||= []) << hash.hth; end def on_get_transaction(hash); (@tx_inv ||= []) << hash.hth; end def on_inv_block(hash); (@block_inv ||= []) << hash.hth; end def on_get_block(hash); (@block_inv ||= []) << hash.hth; end + def on_error(*err); (@err ||= []) << err; end end it 'parses inv (transaction)' do pkt = [ @@ -119,8 +119,16 @@ handler.pkt.should == { :version => Bitcoin.network[:protocol_version], :locator_hashes => locator_hashes, :stop_hash => "0000000000000000000000000000000000000000000000000000000000007e57" } + end + + it 'parses broken inv packet' do + pkt = [("01 00 00 00 00" + " 00"*32).split(" ").join].pack("H*") + parser = Bitcoin::Protocol::Parser.new( handler = Test_Handler.new ) + parser.parse_inv(pkt).should == nil + handler.tx_inv.should == nil + handler.err.should == [[:parse_inv, pkt[1..-1]]] end end