Sha256: 92d286068029479ac5f62388a30620397747c5573b82efcd5d7e8037cb2480ce
Contents?: true
Size: 1.96 KB
Versions: 1
Compression:
Stored size: 1.96 KB
Contents
require_relative '../spec_helper.rb' describe 'Bitcoin::Protocol::Parser (addr)' do it 'parses address packet' do 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 def on_addr(addr); (@addr ||= []) << addr; end end parser = Bitcoin::Protocol::Parser.new( handler = Addr_Handler.new ) parser.parse(pkt + "AAAA").should == "AAAA" handler.addr.size .should == 1 handler.addr.first.alive? .should == false handler.addr.map{|i| i.values }.should == [ [1305992491, 1, "82.83.222.4", 8333] ] end end describe 'Bitcoin::Protocol::Addr' do before do @pkt = [ "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*") end it 'parse addr payload' do addr = Bitcoin::Protocol::Addr.new(@pkt) addr.values.should == [1305992491, 1, "82.83.222.4", 8333] end it 'initalize time, service and port' do addr = Bitcoin::Protocol::Addr.new(nil) t = Time.now.to_i; (t-10..t+10).include?(addr[:time]).should == true addr[:service] .should == 1 addr[:port] .should == Bitcoin.network[:default_port] addr[:ip] .should == "127.0.0.1" end it 'addr payload' do addr = Bitcoin::Protocol::Addr.new addr[:time] = 1305992491 addr[:service] = 1 addr[:ip] = "82.83.222.4" addr[:port] = 8333 addr.to_payload.should == @pkt addr.to_payload.bytesize.should == 30 end it 'pack addr packet' do addr = Bitcoin::Protocol::Addr.new addr[:time] = 1305992491 addr[:service] = 1 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
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bitcoin-ruby-0.0.1 | spec/bitcoin/protocol/addr_spec.rb |