TransactionFormatterTest.php 2.3 KB

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