web3.php/test/unit/Web3Test.php
sc0Vu eca04e1c91 Web3
Web3 api:
* clientVersion
* sha3

Basic object:
* HttpProvider
* HttpRequestManager
2017-12-12 11:52:52 +08:00

106 lines
2.3 KiB
PHP

<?php
namespace Test\Unit;
use Test\TestCase;
use Web3\Web3;
use Web3\Eth;
use Web3\Providers\HttpProvider;
use Web3\RequestManagers\RequestManager;
class Web3Test extends TestCase
{
/**
* web3
*
* @var \Web3\Web3
*/
protected $web3;
/**
* 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()
{
$web3 = new Web3('https://rinkeby.infura.io/vuethexplore');
$this->web3 = $web3;
}
/**
* testInstance
*
* @return void
*/
public function testInstance()
{
$web3 = $this->web3;
$this->assertTrue($web3->provider instanceof HttpProvider);
$this->assertTrue($web3->provider->requestManager instanceof RequestManager);
$this->assertTrue($web3->eth instanceof Eth);
}
/**
* testSend
*
* @return void
*/
public function testSend()
{
$web3 = $this->web3;
$web3->clientVersion(function ($err, $version) {
if ($err !== null) {
return $this->markTestIncomplete($err->getMessage());
}
$this->assertTrue(is_string($version->result));
});
$web3->sha3($this->testHex, function ($err, $hash) {
if ($err !== null) {
return $this->markTestIncomplete($err->getMessage());
}
$this->assertEquals($hash->result, $this->testHash);
});
}
/**
* 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->markTestIncomplete($err->getMessage());
}
$this->assertTrue(is_string($data[0]->result));
$this->assertEquals($data[1]->result, $this->testHash);
});
}
}