Пример #1
0
 public function testConnectFails()
 {
     $loop = new StreamSelectLoop();
     $deferred = new Deferred();
     $deferred->promise()->then(function () {
         $this->fail('should not have succeeded');
     }, function ($value) use($loop) {
         $this->assertEquals(1, $value);
         $loop->stop();
     });
     $request = new RequestFactory();
     $connector = new TcpConnector($loop);
     $client = new Client($connector, $request);
     $client->connect('127.0.0.1', 54320);
     $loop->run();
 }
Пример #2
0
 /**
  * @param $height
  * @return \React\Promise\Promise
  */
 public function blockGetChunk($height)
 {
     return $this->client->request('blockchain.block.get_chunk', [$height]);
 }
Пример #3
0
 public function testReturnsResponse()
 {
     $loop = new StreamSelectLoop();
     $request = new RequestFactory();
     $server = new Server($loop);
     $server->on('connection', function (SocketConnection $connection) use($server, $request) {
         $connection->on('data', function ($data) use($connection, $request) {
             $req = $request->response($data);
             $response = new Response($req->getId(), ['1.0']);
             $connection->write($response->write());
         });
         $connection->on('close', function () use($server) {
             $server->shutdown();
         });
     });
     $server->listen(54323, '127.0.0.1');
     $tcp = new TcpConnector($loop);
     $client = new Client($tcp, $request);
     $client->connect('127.0.0.1', 54323)->then(function (Connection $connection) use($loop) {
         $deferred = new Deferred();
         $deferred->promise()->then(function ($value) {
             $this->assertEquals(1, $value);
         });
         $electrum = new ElectrumClient($connection);
         $electrum->getServerVersion('1.9.6', ' 0.6')->then(function () use($deferred, $connection) {
             $deferred->resolve(1);
             $connection->close();
         }, function () use($loop) {
             $loop->stop();
             $this->fail();
         });
     });
     $loop->run();
 }