79 lines
1.4 KiB
Ruby
79 lines
1.4 KiB
Ruby
![]() |
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
|
||
|
|