web3.php/test/unit/EthTest.php
2017-12-12 18:25:20 +08:00

75 lines
1.5 KiB
PHP

<?php
namespace Test\Unit;
use RuntimeException;
use Test\TestCase;
use Web3\Web3;
use Web3\Eth;
use Web3\Providers\HttpProvider;
use Web3\RequestManagers\RequestManager;
class EthTest extends TestCase
{
/**
* web3
*
* @var \Web3\Web3
*/
protected $web3;
/**
* setUp
*
* @return void
*/
public function setUp()
{
$web3 = new Web3('https://rinkeby.infura.io/vuethexplore');
$this->web3 = $web3;
}
/**
* testSend
*
* @return void
*/
public function testSend()
{
$eth = $this->web3->eth;
$eth->protocolVersion(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);
}
});
}
/**
* testUnallowedMethod
*
* @return void
*/
public function testUnallowedMethod()
{
$this->expectException(RuntimeException::class);
$eth = $this->web3->eth;
$eth->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);
}
});
}
}