Split web3 tests
This commit is contained in:
parent
07c394787d
commit
f1aebc65a6
105
test/unit/Web3ApiTest.php
Normal file
105
test/unit/Web3ApiTest.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace Test\Unit;
|
||||
|
||||
use RuntimeException;
|
||||
use Test\TestCase;
|
||||
use Web3\Web3;
|
||||
use Web3\Eth;
|
||||
use Web3\Net;
|
||||
use Web3\Providers\HttpProvider;
|
||||
use Web3\RequestManagers\RequestManager;
|
||||
|
||||
class Web3ApiTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* testHex
|
||||
* 'hello world'
|
||||
* you can check by call pack('H*', $hex)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $testHex = '0x68656c6c6f20776f726c64';
|
||||
|
||||
/**
|
||||
* testHash
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $testHash = '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad';
|
||||
|
||||
/**
|
||||
* setUp
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* testClientVersion
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testClientVersion()
|
||||
{
|
||||
$web3 = $this->web3;
|
||||
|
||||
$web3->clientVersion(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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* testSha3
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSha3()
|
||||
{
|
||||
$web3 = $this->web3;
|
||||
|
||||
$web3->sha3($this->testHex, function ($err, $hash) {
|
||||
if ($err !== null) {
|
||||
return $this->fail($err->getMessage());
|
||||
}
|
||||
if (isset($hash->result)) {
|
||||
$this->assertEquals($hash->result, $this->testHash);
|
||||
} else {
|
||||
$this->fail($hash->error->message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* testWrongParam
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testWrongParam()
|
||||
{
|
||||
$this->expectException(RuntimeException::class);
|
||||
|
||||
$web3 = $this->web3;
|
||||
|
||||
$web3->sha3('hello world', function ($err, $hash) {
|
||||
if ($err !== null) {
|
||||
return $this->fail($err->getMessage());
|
||||
}
|
||||
if (isset($hash->result)) {
|
||||
$this->assertTrue(true);
|
||||
} else {
|
||||
$this->fail($hash->error->message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
62
test/unit/Web3BatchTest.php
Normal file
62
test/unit/Web3BatchTest.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Test\Unit;
|
||||
|
||||
use RuntimeException;
|
||||
use Test\TestCase;
|
||||
use Web3\Web3;
|
||||
use Web3\Eth;
|
||||
use Web3\Net;
|
||||
use Web3\Providers\HttpProvider;
|
||||
use Web3\RequestManagers\RequestManager;
|
||||
|
||||
class Web3BatchTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* testHex
|
||||
* 'hello world'
|
||||
* you can check by call pack('H*', $hex)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $testHex = '0x68656c6c6f20776f726c64';
|
||||
|
||||
/**
|
||||
* testHash
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $testHash = '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad';
|
||||
|
||||
/**
|
||||
* setUp
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* testBatch
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBatch()
|
||||
{
|
||||
$web3 = $this->web3;
|
||||
|
||||
$web3->batch(true);
|
||||
$web3->clientVersion();
|
||||
$web3->sha3($this->testHex);
|
||||
|
||||
$web3->provider->execute(function ($err, $data) {
|
||||
if ($err !== null) {
|
||||
return $this->fail($err->getMessage());
|
||||
}
|
||||
$this->assertTrue(is_string($data[0]->result));
|
||||
$this->assertEquals($data[1]->result, $this->testHash);
|
||||
});
|
||||
}
|
||||
}
|
@ -53,70 +53,6 @@ class Web3Test extends TestCase
|
||||
$this->assertTrue($web3->net instanceof Net);
|
||||
}
|
||||
|
||||
/**
|
||||
* testClientVersion
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testClientVersion()
|
||||
{
|
||||
$web3 = $this->web3;
|
||||
|
||||
$web3->clientVersion(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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* testSha3
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSha3()
|
||||
{
|
||||
$web3 = $this->web3;
|
||||
|
||||
$web3->sha3($this->testHex, function ($err, $hash) {
|
||||
if ($err !== null) {
|
||||
return $this->fail($err->getMessage());
|
||||
}
|
||||
if (isset($hash->result)) {
|
||||
$this->assertEquals($hash->result, $this->testHash);
|
||||
} else {
|
||||
$this->fail($hash->error->message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* testBatch
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBatch()
|
||||
{
|
||||
$web3 = $this->web3;
|
||||
|
||||
$web3->batch(true);
|
||||
$web3->clientVersion();
|
||||
$web3->sha3($this->testHex);
|
||||
|
||||
$web3->provider->execute(function ($err, $data) {
|
||||
if ($err !== null) {
|
||||
return $this->fail($err->getMessage());
|
||||
}
|
||||
$this->assertTrue(is_string($data[0]->result));
|
||||
$this->assertEquals($data[1]->result, $this->testHash);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* testUnallowedMethod
|
||||
*
|
||||
@ -139,27 +75,4 @@ class Web3Test extends TestCase
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* testWrongParam
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testWrongParam()
|
||||
{
|
||||
$this->expectException(RuntimeException::class);
|
||||
|
||||
$web3 = $this->web3;
|
||||
|
||||
$web3->sha3('hello world', function ($err, $hash) {
|
||||
if ($err !== null) {
|
||||
return $this->fail($err->getMessage());
|
||||
}
|
||||
if (isset($hash->result)) {
|
||||
$this->assertTrue(true);
|
||||
} else {
|
||||
$this->fail($hash->error->message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user