forked from sc0Vu/web3.php
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Test\Unit; | ||
|
||
use RuntimeException; | ||
use Test\TestCase; | ||
use Web3\RequestManagers\HttpRequestManager; | ||
use Web3\Providers\HttpProvider; | ||
use Web3\Methods\Web3\ClientVersion; | ||
|
||
class HttpProviderTest extends TestCase | ||
{ | ||
/** | ||
* testSend | ||
* | ||
* @return void | ||
*/ | ||
public function testSend() | ||
{ | ||
$requestManager = new HttpRequestManager('http://localhost:8545'); | ||
$provider = new HttpProvider($requestManager); | ||
$method = new ClientVersion('web3_clientVersion', []); | ||
|
||
$provider->send($method, function ($err, $version) { | ||
if ($err !== null) { | ||
$this->fail($err->getMessage()); | ||
} | ||
$this->assertTrue(is_string($version)); | ||
}); | ||
} | ||
|
||
/** | ||
* testBatch | ||
* | ||
* @return void | ||
*/ | ||
public function testBatch() | ||
{ | ||
$requestManager = new HttpRequestManager('http://localhost:8545'); | ||
$provider = new HttpProvider($requestManager); | ||
$method = new ClientVersion('web3_clientVersion', []); | ||
$callback = function ($err, $data) { | ||
if ($err !== null) { | ||
$this->fail($err->getMessage()); | ||
} | ||
$this->assertEquals($data[0], $data[1]); | ||
}; | ||
|
||
try { | ||
$provider->execute($callback); | ||
} catch (RuntimeException $err) { | ||
$this->assertTrue($err->getMessage() !== true); | ||
} | ||
|
||
$provider->batch(true); | ||
$provider->send($method, null); | ||
$provider->send($method, null); | ||
$provider->execute($callback); | ||
} | ||
} |