Skip to content

Commit

Permalink
Add testGetBlockByNumberAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
sc0Vu committed Aug 27, 2023
1 parent 6c9a0d4 commit f46f781
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use \PHPUnit\Framework\TestCase as BaseTestCase;
use Web3\Web3;
use Web3\RequestManagers\HttpAsyncRequestManager;
use Web3\Providers\HttpProvider;

class TestCase extends BaseTestCase
{
Expand Down Expand Up @@ -35,6 +37,13 @@ class TestCase extends BaseTestCase
*/
protected $coinbase;

/**
* asyncHttpProvider
*
* @var \Web3\Providers\HttpProvider
*/
protected $asyncHttpProvider;

/**
* setUp
*/
Expand All @@ -43,6 +52,10 @@ public function setUp(): void
$web3 = new Web3($this->testHost);
$this->web3 = $web3;

$asyncRequestManager = new HttpAsyncRequestManager($this->testHost);
$asyncHttpProvider = new HttpProvider($asyncRequestManager);
$this->asyncHttpProvider = $asyncHttpProvider;

$web3->eth->coinbase(function ($err, $coinbase) {
if ($err !== null) {
return $this->fail($err->getMessage());
Expand Down
22 changes: 22 additions & 0 deletions test/unit/EthApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,28 @@ public function testSubmitHashrate()
});
}

/**
* testGetBlockByNumberAsync
*
* @return void
*/
public function testGetBlockByNumberAsync()
{
$eth = $this->eth;
$eth->provider = $this->asyncHttpProvider;

// should return reactphp promise
$promise = $eth->getBlockByNumber('latest', false, function ($err, $block) {
if ($err !== null) {
return $this->assertTrue($err !== null);
}
// weird behavior, see https://github.com/web3p/web3.php/issues/16
$this->assertTrue($block !== null);
});
$this->assertTrue($promise instanceof \React\Promise\PromiseInterface);
\React\Async\await($promise);
}

/**
* testUnallowedMethod
*
Expand Down

0 comments on commit f46f781

Please sign in to comment.