Web3BatchTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace Test\Unit;
  3. use RuntimeException;
  4. use Test\TestCase;
  5. class Web3BatchTest extends TestCase
  6. {
  7. /**
  8. * testHex
  9. * 'hello world'
  10. * you can check by call pack('H*', $hex)
  11. *
  12. * @var string
  13. */
  14. protected $testHex = '0x68656c6c6f20776f726c64';
  15. /**
  16. * testHash
  17. *
  18. * @var string
  19. */
  20. protected $testHash = '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad';
  21. /**
  22. * setUp
  23. *
  24. * @return void
  25. */
  26. public function setUp()
  27. {
  28. parent::setUp();
  29. }
  30. /**
  31. * testBatch
  32. *
  33. * @return void
  34. */
  35. public function testBatch()
  36. {
  37. $web3 = $this->web3;
  38. $web3->batch(true);
  39. $web3->clientVersion();
  40. $web3->sha3($this->testHex);
  41. $web3->provider->execute(function ($err, $data) {
  42. if ($err !== null) {
  43. return $this->fail('Got error!');
  44. }
  45. $this->assertTrue(is_string($data[0]));
  46. $this->assertEquals($data[1], $this->testHash);
  47. });
  48. }
  49. /**
  50. * testWrongParam
  51. *
  52. * @return void
  53. */
  54. public function testWrongParam()
  55. {
  56. $this->expectException(RuntimeException::class);
  57. $web3 = $this->web3;
  58. $web3->batch(true);
  59. $web3->clientVersion();
  60. $web3->sha3($web3);
  61. $web3->provider->execute(function ($err, $data) {
  62. if ($err !== null) {
  63. return $this->fail('Got error!');
  64. }
  65. $this->assertTrue(is_string($data[0]));
  66. $this->assertEquals($data[1], $this->testHash);
  67. });
  68. }
  69. }