In theory, version exchange for client and server works now.
Test rig isn't there yet, so untested at the moment. Added a simple README
This commit is contained in:
78
spec/em-bitcoin_spec.rb
Normal file
78
spec/em-bitcoin_spec.rb
Normal file
@@ -0,0 +1,78 @@
|
||||
require 'spec_helper'
|
||||
require 'em-bitcoin'
|
||||
|
||||
|
||||
include ::EM::P
|
||||
|
||||
class MockActor
|
||||
attr_accessor :connection
|
||||
|
||||
def network_name ; :main ; end
|
||||
def current_time ; Time.now ; end
|
||||
def sub_version ; nil ; end
|
||||
def current_height ; 0 ; end
|
||||
|
||||
def log(level, msg)
|
||||
STDERR.puts("#{level}: #{msg}") if $DEBUG
|
||||
end
|
||||
|
||||
def ready!
|
||||
@ready = true
|
||||
end
|
||||
|
||||
def ready?
|
||||
@ready == true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class MockSignature
|
||||
attr_reader :lip, :lport, :rip, :rport
|
||||
|
||||
def initialize(lip = "127.0.0.1", lport = 12701, rip="127.0.0.2", rport=12702)
|
||||
@lip, @lport, @rip, @rport = lip, lport, rip, rport
|
||||
end
|
||||
end
|
||||
|
||||
module EMPMocks
|
||||
def get_peername
|
||||
Socket::pack_sockaddr_in(@signature.rport, @signature.rip)
|
||||
end
|
||||
|
||||
def get_sockname
|
||||
Socket::pack_sockaddr_in(@signature.lport, @signature.lip)
|
||||
end
|
||||
|
||||
def send_data(d)
|
||||
nil # TODO: expectations &c...
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for BitcoinPeer do
|
||||
end
|
||||
|
||||
describe BitcoinClient do
|
||||
before(:each) do
|
||||
@reactor = stub("reactor")
|
||||
@sig = MockSignature.new
|
||||
|
||||
@actor = MockActor.new
|
||||
@client = BitcoinClient.new(@sig, @actor)
|
||||
@client.extend(EMPMocks)
|
||||
end
|
||||
describe "connection setup" do
|
||||
context "successful" do
|
||||
it "should accept a valid actor" do
|
||||
@client.actor.should == @actor
|
||||
end
|
||||
|
||||
it "should send a version first, accept a verack + version, then send a verack"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
describe BitcoinServer do
|
||||
end
|
||||
|
Reference in New Issue
Block a user