spec/bitcoin/protocol/version_spec.rb in bitcoin-ruby-0.0.4 vs spec/bitcoin/protocol/version_spec.rb in bitcoin-ruby-0.0.5

- old
+ new

@@ -25,11 +25,12 @@ :time => 1329775027, :from => "127.0.0.1:18333", :to => "127.0.0.1:57802", :nonce => 12576309328653329813, :user_agent => "/bitcoin-qt:0.6.0/", - :last_block => 46722 + :last_block => 46722, + :relay => true } pkt = [ "f9 be b4 d9 76 65 72 73 69 6f 6e 00 00 00 00 00 55 00 00 00 a4 c2 08 cb 40 9c 00 00 01 00 00 00 00 00 00 00 10 42 c9 4e 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 7f 00 00 01 04 d2 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 7f 00 00 01 47 9d 4b b8 bb 21 ae d7 f0 71 00 fa 00 00 00" .split(" ").join].pack("H*") @@ -45,11 +46,12 @@ :time => 1321812496, :from => "127.0.0.1:18333", :to => "127.0.0.1:1234", :nonce => 8210299263586646091, :user_agent => '', - :last_block => 250 + :last_block => 250, + :relay => true } end it 'creates version packets' do version = Bitcoin::Protocol::Version.new({ @@ -70,10 +72,39 @@ :time => 1337, :to => "127.0.0.1:8333", :from => "127.0.0.1:1234", :nonce => 123, :user_agent => "/bitcoin-ruby:#{Bitcoin::VERSION}/", - :last_block => 188617 + :last_block => 188617, + :relay => true + } + end + + # check that we support sending and receiving of the BIP0037 fRelay flag + it 'creates spv enabled version packets' do + version = Bitcoin::Protocol::Version.new({ + :time => 1337, + :from => "127.0.0.1:8333", + :to => "127.0.0.1:1234", + :nonce => 123, + :last_block => 188617, + :relay => false + }) + + parser = Bitcoin::Protocol::Parser.new( handler = Version_Handler.new ) + parser.parse( version.to_pkt ) + + pkt = handler.pkt + pkt.fields.should == { + :version => Bitcoin.network[:protocol_version], + :services => Bitcoin::Protocol::Version::NODE_NETWORK, + :time => 1337, + :to => "127.0.0.1:8333", + :from => "127.0.0.1:1234", + :nonce => 123, + :user_agent => "/bitcoin-ruby:#{Bitcoin::VERSION}/", + :last_block => 188617, + :relay => false } end end