Split net tests
This commit is contained in:
parent
f1aebc65a6
commit
841bd56780
114
test/unit/NetApiTest.php
Normal file
114
test/unit/NetApiTest.php
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Test\Unit;
|
||||||
|
|
||||||
|
use RuntimeException;
|
||||||
|
use Test\TestCase;
|
||||||
|
|
||||||
|
class NetApiTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* net
|
||||||
|
*
|
||||||
|
* @var Web3\Net
|
||||||
|
*/
|
||||||
|
protected $net;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setUp
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->net = $this->web3->net;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testVersion
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testVersion()
|
||||||
|
{
|
||||||
|
$net = $this->net;
|
||||||
|
|
||||||
|
$net->version(function ($err, $version) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail($err->getMessage());
|
||||||
|
}
|
||||||
|
if (isset($version->result)) {
|
||||||
|
$this->assertTrue(is_string($version->result));
|
||||||
|
} else {
|
||||||
|
$this->fail($version->error->message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testPeerCount
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testPeerCount()
|
||||||
|
{
|
||||||
|
$net = $this->net;
|
||||||
|
|
||||||
|
$net->peerCount(function ($err, $count) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail($err->getMessage());
|
||||||
|
}
|
||||||
|
if (isset($count->result)) {
|
||||||
|
$this->assertTrue(is_string($count->result));
|
||||||
|
} else {
|
||||||
|
$this->fail($count->error->message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testListening
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testListening()
|
||||||
|
{
|
||||||
|
$net = $this->net;
|
||||||
|
|
||||||
|
$net->listening(function ($err, $net) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail($err->getMessage());
|
||||||
|
}
|
||||||
|
if (isset($net->result)) {
|
||||||
|
$this->assertTrue(is_bool($net->result));
|
||||||
|
} else {
|
||||||
|
$this->fail($net->error->message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testUnallowedMethod
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testUnallowedMethod()
|
||||||
|
{
|
||||||
|
$this->expectException(RuntimeException::class);
|
||||||
|
|
||||||
|
$net = $this->net;
|
||||||
|
|
||||||
|
$net->hello(function ($err, $hello) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail($err->getMessage());
|
||||||
|
}
|
||||||
|
if (isset($hello->result)) {
|
||||||
|
$this->assertTrue(true);
|
||||||
|
} else {
|
||||||
|
$this->fail($hello->error->message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
50
test/unit/NetBatchTest.php
Normal file
50
test/unit/NetBatchTest.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Test\Unit;
|
||||||
|
|
||||||
|
use RuntimeException;
|
||||||
|
use Test\TestCase;
|
||||||
|
|
||||||
|
class NetBatchTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* net
|
||||||
|
*
|
||||||
|
* @var Web3\Net
|
||||||
|
*/
|
||||||
|
protected $net;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setUp
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->net = $this->web3->net;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testBatch
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testBatch()
|
||||||
|
{
|
||||||
|
$net = $this->net;
|
||||||
|
|
||||||
|
$net->batch(true);
|
||||||
|
$net->version();
|
||||||
|
$net->listening();
|
||||||
|
|
||||||
|
$net->provider->execute(function ($err, $data) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail($err->getMessage());
|
||||||
|
}
|
||||||
|
$this->assertTrue(is_string($data[0]->result));
|
||||||
|
$this->assertTrue(is_bool($data[1]->result));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,8 @@ namespace Test\Unit;
|
|||||||
|
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
use Web3\Providers\HttpProvider;
|
||||||
|
use Web3\RequestManagers\RequestManager;
|
||||||
|
|
||||||
class NetTest extends TestCase
|
class NetTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -27,110 +29,15 @@ class NetTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testVersion
|
* testInstance
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testVersion()
|
public function testInstance()
|
||||||
{
|
{
|
||||||
$net = $this->net;
|
$net = $this->net;
|
||||||
|
|
||||||
$net->version(function ($err, $version) {
|
$this->assertTrue($net->provider instanceof HttpProvider);
|
||||||
if ($err !== null) {
|
$this->assertTrue($net->provider->requestManager instanceof RequestManager);
|
||||||
return $this->fail($err->getMessage());
|
|
||||||
}
|
|
||||||
if (isset($version->result)) {
|
|
||||||
$this->assertTrue(is_string($version->result));
|
|
||||||
} else {
|
|
||||||
$this->fail($version->error->message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testPeerCount
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testPeerCount()
|
|
||||||
{
|
|
||||||
$net = $this->net;
|
|
||||||
|
|
||||||
$net->peerCount(function ($err, $count) {
|
|
||||||
if ($err !== null) {
|
|
||||||
return $this->fail($err->getMessage());
|
|
||||||
}
|
|
||||||
if (isset($count->result)) {
|
|
||||||
$this->assertTrue(is_string($count->result));
|
|
||||||
} else {
|
|
||||||
$this->fail($count->error->message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testListening
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testListening()
|
|
||||||
{
|
|
||||||
$net = $this->net;
|
|
||||||
|
|
||||||
$net->listening(function ($err, $net) {
|
|
||||||
if ($err !== null) {
|
|
||||||
return $this->fail($err->getMessage());
|
|
||||||
}
|
|
||||||
if (isset($net->result)) {
|
|
||||||
$this->assertTrue(is_bool($net->result));
|
|
||||||
} else {
|
|
||||||
$this->fail($net->error->message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testBatch
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testBatch()
|
|
||||||
{
|
|
||||||
$net = $this->net;
|
|
||||||
|
|
||||||
$net->batch(true);
|
|
||||||
$net->version();
|
|
||||||
$net->listening();
|
|
||||||
|
|
||||||
$net->provider->execute(function ($err, $data) {
|
|
||||||
if ($err !== null) {
|
|
||||||
return $this->fail($err->getMessage());
|
|
||||||
}
|
|
||||||
$this->assertTrue(is_string($data[0]->result));
|
|
||||||
$this->assertTrue(is_bool($data[1]->result));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testUnallowedMethod
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testUnallowedMethod()
|
|
||||||
{
|
|
||||||
$this->expectException(RuntimeException::class);
|
|
||||||
|
|
||||||
$net = $this->net;
|
|
||||||
|
|
||||||
$net->hello(function ($err, $hello) {
|
|
||||||
if ($err !== null) {
|
|
||||||
return $this->fail($err->getMessage());
|
|
||||||
}
|
|
||||||
if (isset($hello->result)) {
|
|
||||||
$this->assertTrue(true);
|
|
||||||
} else {
|
|
||||||
$this->fail($hello->error->message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,11 +4,6 @@ namespace Test\Unit;
|
|||||||
|
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
use Web3\Web3;
|
|
||||||
use Web3\Eth;
|
|
||||||
use Web3\Net;
|
|
||||||
use Web3\Providers\HttpProvider;
|
|
||||||
use Web3\RequestManagers\RequestManager;
|
|
||||||
|
|
||||||
class Web3ApiTest extends TestCase
|
class Web3ApiTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -4,11 +4,6 @@ namespace Test\Unit;
|
|||||||
|
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
use Web3\Web3;
|
|
||||||
use Web3\Eth;
|
|
||||||
use Web3\Net;
|
|
||||||
use Web3\Providers\HttpProvider;
|
|
||||||
use Web3\RequestManagers\RequestManager;
|
|
||||||
|
|
||||||
class Web3BatchTest extends TestCase
|
class Web3BatchTest extends TestCase
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user