Skip to content

Commit

Permalink
Add testBatchAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
sc0Vu committed Aug 27, 2023
1 parent 5714103 commit cda20fb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 17 deletions.
28 changes: 28 additions & 0 deletions test/unit/NetBatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,32 @@ public function testBatch()
$this->assertTrue($data[2] instanceof BigNumber);
});
}

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

$net->batch(true);
$net->version();
$net->listening();
$net->peerCount();

// should return reactphp promise
$promise = $net->provider->execute(function ($err, $data) {
if ($err !== null) {
return $this->fail($err->getMessage());
}
$this->assertTrue(is_string($data[0]));
$this->assertTrue(is_bool($data[1]));
$this->assertTrue($data[2] instanceof BigNumber);
});
$this->assertTrue($promise instanceof \React\Promise\PromiseInterface);
\React\Async\await($promise);
}
}
38 changes: 21 additions & 17 deletions test/unit/ShhBatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,34 @@ public function testBatch()
}
$this->assertTrue(is_string($data[0]));
$this->assertTrue(is_string($data[1]));
$this->assertEquals($data[0], $data[1]);
});
}

/**
* testWrongParam
* testBatchAsync
*
* @return void
*/
// public function testWrongParam()
// {
// $this->expectException(RuntimeException::class);

// $shh = $this->shh;
public function testBatchAsync()
{
$shh = $this->shh;
$shh->provider = $this->asyncHttpProvider;

// $shh->batch(true);
// $shh->version();
// $shh->hasIdentity('0');
$shh->batch(true);
$shh->version();
$shh->version();

// $shh->provider->execute(function ($err, $data) {
// if ($err !== null) {
// return $this->fail($err->getMessage());
// }
// $this->assertTrue(is_string($data[0]));
// $this->assertFalse($data[1]);
// });
// }
// should return reactphp promise
$promise = $shh->provider->execute(function ($err, $data) {
if ($err !== null) {
return $this->fail($err->getMessage());
}
$this->assertTrue(is_string($data[0]));
$this->assertTrue(is_string($data[1]));
$this->assertEquals($data[0], $data[1]);
});
$this->assertTrue($promise instanceof \React\Promise\PromiseInterface);
\React\Async\await($promise);
}
}

0 comments on commit cda20fb

Please sign in to comment.