CallValidatorTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace Test\Unit;
  3. use Test\TestCase;
  4. use Web3\Validators\CallValidator;
  5. class CallValidatorTest extends TestCase
  6. {
  7. /**
  8. * validator
  9. *
  10. * @var \Web3\Validators\CallValidator
  11. */
  12. protected $validator;
  13. /**
  14. * setUp
  15. *
  16. * @return void
  17. */
  18. public function setUp()
  19. {
  20. parent::setUp();
  21. $this->validator = new CallValidator;
  22. }
  23. /**
  24. * testValidate
  25. *
  26. * @return void
  27. */
  28. public function testValidate()
  29. {
  30. $validator = $this->validator;
  31. $this->assertEquals(false, $validator->validate('hello web3.php'));
  32. $this->assertEquals(false, $validator->validate([]));
  33. $this->assertEquals(false, $validator->validate([
  34. 'from' => '',
  35. 'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
  36. ]));
  37. $this->assertEquals(false, $validator->validate([
  38. 'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
  39. 'gas' => '',
  40. ]));
  41. $this->assertEquals(false, $validator->validate([
  42. 'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
  43. 'gasPrice' => '',
  44. ]));
  45. $this->assertEquals(false, $validator->validate([
  46. 'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
  47. 'value' => '',
  48. ]));
  49. $this->assertEquals(false, $validator->validate([
  50. 'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
  51. 'data' => '',
  52. ]));
  53. $this->assertEquals(false, $validator->validate([
  54. 'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
  55. 'nonce' => '',
  56. ]));
  57. $this->assertEquals(true, $validator->validate([
  58. 'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
  59. ]));
  60. $this->assertEquals(true, $validator->validate([
  61. 'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
  62. 'gas' => '0x76c0',
  63. 'gasPrice' => '0x9184e72a000',
  64. 'value' => '0x9184e72a',
  65. 'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675',
  66. 'nonce' => '0x9184e72a',
  67. ]));
  68. }
  69. }