Skip to content

Commit

Permalink
Address: left pad (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
kornrunner committed Mar 25, 2021
1 parent b491319 commit 89197ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(string $privateKey = '') {
}

public function getPrivateKey(): string {
return str_pad(gmp_strval($this->privateKey->getSecret(), 16), 64, '0');
return str_pad(gmp_strval($this->privateKey->getSecret(), 16), 64, '0', STR_PAD_LEFT);
}

public function getPublicKey(): string {
Expand Down
16 changes: 16 additions & 0 deletions test/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ public function testCreateFromPrivateKey(): void {
$this->assertSame('677a637ec8f0bb2c8d33c6ace08054e521bff4b5', $address->get());
$this->assertSame('5f65c9c32a4e38393b79ccf94913c1e5dbe7071d4264aad290d936c4bb2a7c0e3a71ebc855aaadd38f477320d54cd88e5133bfcf97bbf037252db4cd824ab902', $address->getPublicKey());
}
/**
* @dataProvider privateKeyPading
*/
public function testPrivateKeyPadding($key, $public): void {
$address = new Address($key);
$this->assertSame($public, $address->get());
}

public static function privateKeyPading(): array {
return [
['93262d84237f92dc8e4409062dcc9dfc8cdc211ec32b18aa073af15841cd8440', '669d9098736e33b8a0ee0470c10357b66caac548'],
['093262d84237f92dc8e4409062dcc9dfc8cdc211ec32b18aa073af15841cd844', '2c10383ae14f59415979d7c232ca2c85b62c18a9'],
['07a51d7d4445c567c12639ca38e4c9fc4b12f6ec9f0aab82f98c28acaae446a3', 'f81153ba99e401149c6d028eb39fd657e474e7c0'],
['7a51d7d4445c567c12639ca38e4c9fc4b12f6ec9f0aab82f98c28acaae446a30', 'f783c3bccfcc24a3731eb25b9587bf5071aab592'],
];
}

public function testThrowsNotHex(): void {
$this->expectException(InvalidArgumentException::class);
Expand Down

0 comments on commit 89197ed

Please sign in to comment.