Sha256: d69d54e5dae105353a33c40a2c245ed8da53804d5083b66b37fcee52e1e855c8

Contents?: true

Size: 1.22 KB

Versions: 19

Compression:

Stored size: 1.22 KB

Contents

# encoding: ascii-8bit

require_relative '../spec_helper.rb'

describe 'Bitcoin::Protocol::Parser (ping/pong)' do

  class Ping_Handler < Bitcoin::Protocol::Handler
    attr_reader :nonce
    def on_ping(nonce)
      @nonce = nonce
    end
    def on_pong(nonce)
      @nonce = nonce
    end
  end

  before do
    @parser = Bitcoin::Protocol::Parser.new( @handler = Ping_Handler.new )
  end

  it 'parses ping without nonce' do
    @parser.parse(Bitcoin::Protocol.pkt("ping", "") + "AAAA").should == "AAAA"
    @handler.nonce.should == nil
  end

  it 'parses ping with nonce' do
    @parser.parse(Bitcoin::Protocol.pkt("ping", [12345].pack("Q")) + "AAAA").should == "AAAA"
    @handler.nonce.should == 12345
  end

  it 'builds ping without nonce' do
    @parser.parse(Bitcoin::Protocol::ping_pkt)
    @handler.nonce.should != nil
  end

  it 'builds ping with nonce' do
    @parser.parse(Bitcoin::Protocol::ping_pkt(12345))
    @handler.nonce.should == 12345
  end

  it 'parses pong' do
    @parser.parse(Bitcoin::Protocol.pkt("pong", [12345].pack("Q")) + "AAAA").should == "AAAA"
    @handler.nonce.should == 12345
  end

  it 'builds pong' do
    @parser.parse(Bitcoin::Protocol::pong_pkt(12345))
    @handler.nonce.should == 12345
  end

end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
bitcoin-ruby-0.0.18 spec/bitcoin/protocol/ping_spec.rb
bitcoin-ruby-0.0.17 spec/bitcoin/protocol/ping_spec.rb
bitcoin-ruby-0.0.16 spec/bitcoin/protocol/ping_spec.rb
bitcoin-ruby-0.0.15 spec/bitcoin/protocol/ping_spec.rb
monacoin-ruby-0.1.3 spec/bitcoin/protocol/ping_spec.rb
monacoin-ruby-0.1.2 spec/bitcoin/protocol/ping_spec.rb
bitcoin-ruby-0.0.14 spec/bitcoin/protocol/ping_spec.rb
bitcoin-ruby-0.0.13 spec/bitcoin/protocol/ping_spec.rb
bitcoin-ruby-0.0.12 spec/bitcoin/protocol/ping_spec.rb
bitcoin-ruby-0.0.11 spec/bitcoin/protocol/ping_spec.rb
bitcoin-ruby-0.0.10 spec/bitcoin/protocol/ping_spec.rb
bitcoin-ruby-0.0.9 spec/bitcoin/protocol/ping_spec.rb
bitcoin-ruby-0.0.8 spec/bitcoin/protocol/ping_spec.rb
bitcoin-ruby-0.0.7 spec/bitcoin/protocol/ping_spec.rb
bitcoin-ruby-0.0.6 spec/bitcoin/protocol/ping_spec.rb
bitcoin-ruby-0.0.5 spec/bitcoin/protocol/ping_spec.rb
bitcoin-ruby-0.0.4 spec/bitcoin/protocol/ping_spec.rb
bitcoin-ruby-0.0.3 spec/bitcoin/protocol/ping_spec.rb
bitcoin-ruby-0.0.2 spec/bitcoin/protocol/ping_spec.rb