spec/bitcoin/protocol/inv_spec.rb in bitcoin-ruby-0.0.1 vs spec/bitcoin/protocol/inv_spec.rb in bitcoin-ruby-0.0.2
- old
+ new
@@ -1,16 +1,18 @@
+# encoding: ascii-8bit
+
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
- def on_inv_transaction(hash); (@tx_inv ||= []) << hth(hash); end
- def on_get_transaction(hash); (@tx_inv ||= []) << hth(hash); end
- def on_inv_block(hash); (@block_inv ||= []) << hth(hash); end
- def on_get_block(hash); (@block_inv ||= []) << hth(hash); end
+ 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
end
it 'parses inv (transaction)' do
pkt = [
@@ -87,17 +89,17 @@
def on_getblocks(version, hashes, stop_hash); @pkt = { :version => version, :locator_hashes => hashes, :stop_hash => stop_hash }; end
end
locator_hashes = ["00000000068866924696f410b778911316f92035e9b69b62afa03573974fd750", "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"]
stop_hash = "0000000000000000000000000000000000000000000000000000000000000000"
- pkt = Bitcoin::Protocol.getblocks_pkt( locator_hashes )
+ pkt = Bitcoin::Protocol.getblocks_pkt( Bitcoin.network[:protocol_version], locator_hashes )
parser = Bitcoin::Protocol::Parser.new( handler = Test_Handler.new )
parser.parse(pkt + "AAAA").should == "AAAA"
handler.pkt.should == {
- :version => Bitcoin.network[:magic_head],
+ :version => Bitcoin.network[:protocol_version],
:locator_hashes => locator_hashes,
:stop_hash => "0000000000000000000000000000000000000000000000000000000000000000"
}
end
@@ -107,16 +109,16 @@
def on_getheaders(version, hashes, stop_hash); @pkt = { :version => version, :locator_hashes => hashes, :stop_hash => stop_hash }; end
end
locator_hashes = ["00000000068866924696f410b778911316f92035e9b69b62afa03573974fd750", "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"]
stop_hash = "0000000000000000000000000000000000000000000000000000000000007e57"
- pkt = Bitcoin::Protocol.getblocks_pkt( locator_hashes, stop_hash )
+ pkt = Bitcoin::Protocol.getblocks_pkt( Bitcoin.network[:protocol_version], locator_hashes, stop_hash )
parser = Bitcoin::Protocol::Parser.new( handler = Test_Handler.new )
parser.parse(pkt + "AAAA").should == "AAAA"
handler.pkt.should == {
- :version => Bitcoin.network[:magic_head],
+ :version => Bitcoin.network[:protocol_version],
:locator_hashes => locator_hashes,
:stop_hash => "0000000000000000000000000000000000000000000000000000000000007e57"
}
end