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

- old
+ new

@@ -8,12 +8,13 @@ pkt = [ "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" .split(" ").join].pack("H*") class Addr_Handler < Bitcoin::Protocol::Handler - attr_reader :addr + attr_reader :addr, :err def on_addr(addr); (@addr ||= []) << addr; end + def on_error(*err); (@err ||= []) << err; end end parser = Bitcoin::Protocol::Parser.new( handler = Addr_Handler.new ) parser.parse(pkt + "AAAA").should == "AAAA" @@ -22,10 +23,18 @@ handler.addr.map{|i| i.values }.should == [ [1305992491, 1, "82.83.222.4", 8333] ] end + it "parses broken address packet" do + pkt = ["01 00 00 00 00".split(" ").join].pack("H*") + parser = Bitcoin::Protocol::Parser.new( handler = Addr_Handler.new ) + parser.parse_addr(pkt).should == nil + handler.addr.should == nil + handler.err.should == [[:addr, pkt[1..-1]]] + end + end describe 'Bitcoin::Protocol::Addr' do before do @@ -67,6 +76,7 @@ addr[:ip] = "82.83.222.4" addr[:port] = 8333 Bitcoin::Protocol::Addr.pkt(addr).should == Bitcoin::Protocol.pkt("addr", "\x01" + addr.to_payload) end + end