Web3Test.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace Test\Unit;
  3. use RuntimeException;
  4. use Test\TestCase;
  5. use Web3\Web3;
  6. use Web3\Eth;
  7. use Web3\Net;
  8. use Web3\Personal;
  9. use Web3\Shh;
  10. use Web3\Utils;
  11. use Web3\Providers\HttpProvider;
  12. class Web3Test extends TestCase
  13. {
  14. /**
  15. * testHex
  16. * 'hello world'
  17. * you can check by call pack('H*', $hex)
  18. *
  19. * @var string
  20. */
  21. protected $testHex = '0x68656c6c6f20776f726c64';
  22. /**
  23. * testHash
  24. *
  25. * @var string
  26. */
  27. protected $testHash = '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad';
  28. /**
  29. * setUp
  30. *
  31. * @return void
  32. */
  33. public function setUp(): void
  34. {
  35. parent::setUp();
  36. }
  37. /**
  38. * testInstance
  39. *
  40. * @return void
  41. */
  42. public function testInstance()
  43. {
  44. $web3 = new Web3(new HttpProvider('http://localhost:8545'));
  45. $this->assertTrue($web3->provider instanceof HttpProvider);
  46. $this->assertTrue($web3->eth instanceof Eth);
  47. $this->assertTrue($web3->net instanceof Net);
  48. $this->assertTrue($web3->personal instanceof Personal);
  49. $this->assertTrue($web3->shh instanceof Shh);
  50. $this->assertTrue($web3->utils instanceof Utils);
  51. }
  52. /**
  53. * testSetProvider
  54. *
  55. * @return void
  56. */
  57. public function testSetProvider()
  58. {
  59. $web3 = $this->web3;
  60. $web3->provider = new HttpProvider('http://localhost:8545');
  61. $this->assertEquals($web3->provider->host, 'http://localhost:8545');
  62. $web3->provider = null;
  63. $this->assertEquals($web3->provider->host, 'http://localhost:8545');
  64. }
  65. /**
  66. * testCallThrowRuntimeException
  67. *
  68. * @return void
  69. */
  70. public function testCallThrowRuntimeException()
  71. {
  72. $this->expectException(RuntimeException::class);
  73. $web3 = new Web3(null);
  74. $web3->sha3('hello world');
  75. }
  76. }