TransactionValidatorTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Test\Unit;
  3. use Test\TestCase;
  4. use Web3\Validators\TransactionValidator;
  5. class TransactionValidatorTest extends TestCase
  6. {
  7. /**
  8. * validator
  9. *
  10. * @var \Web3\Validators\TransactionValidator
  11. */
  12. protected $validator;
  13. /**
  14. * setUp
  15. *
  16. * @return void
  17. */
  18. public function setUp()
  19. {
  20. parent::setUp();
  21. $this->validator = new TransactionValidator;
  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. ]));
  36. $this->assertEquals(false, $validator->validate([
  37. 'from' => '0xb60e8dd61c5d32be8058bb8eb970870f07233155',
  38. 'data' => ''
  39. ]));
  40. $this->assertEquals(true, $validator->validate([
  41. 'from' => '0xb60e8dd61c5d32be8058bb8eb970870f07233155',
  42. 'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675'
  43. ]));
  44. $this->assertEquals(true, $validator->validate([
  45. 'from' => '0xb60e8dd61c5d32be8058bb8eb970870f07233155',
  46. 'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
  47. 'gas' => '0x76c0',
  48. 'gasPrice' => '0x9184e72a000',
  49. 'value' => '0x9184e72a',
  50. 'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675'
  51. ]));
  52. }
  53. }