Web3Test.php 2.2 KB

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