HexSignatureSerializerTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace kornrunner;
  3. use InvalidArgumentException;
  4. class HexSignatureSerializerTest extends TestCase
  5. {
  6. /**
  7. * @dataProvider data
  8. */
  9. public function testParse(string $input, string $expect) {
  10. $sig = $this->sigSerializer->parse($input);
  11. $this->assertEquals($expect, gmp_strval($sig->getR(), 16) . gmp_strval($sig->getS(), 16));
  12. }
  13. public function testParseException() {
  14. $this->expectException(InvalidArgumentException::class);
  15. $this->sigSerializer->parse($this->signed . random_bytes(3));
  16. }
  17. /**
  18. * @dataProvider data
  19. */
  20. public function testSerialize(string $input, string $expect) {
  21. $parsed = $this->sigSerializer->parse($input);
  22. $signed = $this->sigSerializer->serialize($parsed);
  23. $this->assertEquals($expect, $signed);
  24. }
  25. public static function data(): array {
  26. return [
  27. ['f67118680df5993e8efca4d3ecc4172ca4ac5e3e007ea774293e37386480970347427f3633371c1a30abbb2b717dbd78ef63d5b19b5a951f9d681cccdd520320', 'f67118680df5993e8efca4d3ecc4172ca4ac5e3e007ea774293e37386480970347427f3633371c1a30abbb2b717dbd78ef63d5b19b5a951f9d681cccdd520320'],
  28. ['0xf67118680df5993e8efca4d3ecc4172ca4ac5e3e007ea774293e37386480970347427f3633371c1a30abbb2b717dbd78ef63d5b19b5a951f9d681cccdd520320', 'f67118680df5993e8efca4d3ecc4172ca4ac5e3e007ea774293e37386480970347427f3633371c1a30abbb2b717dbd78ef63d5b19b5a951f9d681cccdd520320'],
  29. ];
  30. }
  31. }