EthBatchTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Test\Unit;
  3. use RuntimeException;
  4. use Test\TestCase;
  5. use phpseclib\Math\BigInteger as BigNumber;
  6. class EthBatchTest extends TestCase
  7. {
  8. /**
  9. * eth
  10. *
  11. * @var \Web3\Eth
  12. */
  13. protected $eth;
  14. /**
  15. * setUp
  16. *
  17. * @return void
  18. */
  19. public function setUp(): void
  20. {
  21. parent::setUp();
  22. $this->eth = $this->web3->eth;
  23. }
  24. /**
  25. * testBatch
  26. *
  27. * @return void
  28. */
  29. public function testBatch()
  30. {
  31. $eth = $this->eth;
  32. $eth->batch(true);
  33. $eth->protocolVersion();
  34. $eth->syncing();
  35. $eth->provider->execute(function ($err, $data) {
  36. if ($err !== null) {
  37. return $this->fail($err->getMessage());
  38. }
  39. $this->assertTrue($data[0] instanceof BigNumber);
  40. $this->assertTrue($data[1] !== null);
  41. });
  42. }
  43. /**
  44. * testBatchAsync
  45. *
  46. * @return void
  47. */
  48. public function testBatchAsync()
  49. {
  50. $eth = $this->eth;
  51. $eth->provider = $this->asyncHttpProvider;
  52. $eth->batch(true);
  53. $eth->protocolVersion();
  54. $eth->syncing();
  55. // should return reactphp promise
  56. $promise = $eth->provider->execute(function ($err, $data) {
  57. if ($err !== null) {
  58. return $this->fail($err->getMessage());
  59. }
  60. $this->assertTrue($data[0] instanceof BigNumber);
  61. $this->assertTrue($data[1] !== null);
  62. });
  63. $this->assertTrue($promise instanceof \React\Promise\PromiseInterface);
  64. \React\Async\await($promise);
  65. }
  66. }