forked from Bit-Wasp/bitcoin-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Bit-Wasp#805: Incorrect tests of resource type
- Loading branch information
Showing
8 changed files
with
148 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
tests/Crypto/EcAdapter/Impl/Secp256k1/Adapter/EcAdapterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace BitWasp\Bitcoin\Tests\Crypto\EcAdapter\Impl\Secp256k1\Adapter; | ||
|
||
use BitWasp\Bitcoin\Bitcoin; | ||
use BitWasp\Bitcoin\Crypto\EcAdapter\Impl\Secp256k1\Adapter\EcAdapter; | ||
use BitWasp\Bitcoin\Math\Math; | ||
use BitWasp\Bitcoin\Tests\AbstractTestCase; | ||
|
||
class EcAdapterTest extends AbstractTestCase | ||
{ | ||
private function callConstructor($value) | ||
{ | ||
$math = new Math(); | ||
$G = Bitcoin::getGenerator(); | ||
return new EcAdapter($math, $G, $value); | ||
} | ||
public function testContextNotResource() | ||
{ | ||
if (!function_exists('secp256k1_context_create')) { | ||
$this->markTestSkipped("secp256k1 not installed"); | ||
} | ||
$this->expectException(\InvalidArgumentException::class); | ||
$this->expectExceptionMessage("Secp256k1: Must pass a secp256k1_context_t resource"); | ||
$this->callConstructor(""); | ||
} | ||
public function testContextWrongResource() | ||
{ | ||
if (!function_exists('secp256k1_context_create')) { | ||
$this->markTestSkipped("secp256k1 not installed"); | ||
} | ||
$ctx = gmp_init(1); | ||
$this->expectException(\InvalidArgumentException::class); | ||
$this->expectExceptionMessage("Secp256k1: Must pass a secp256k1_context_t resource"); | ||
$this->callConstructor($ctx); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
tests/Crypto/EcAdapter/Impl/Secp256k1/Key/PublicKeyTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace BitWasp\Bitcoin\Tests\Crypto\EcAdapter\Impl\Secp256k1\Key; | ||
|
||
use BitWasp\Bitcoin\Bitcoin; | ||
use BitWasp\Bitcoin\Crypto\EcAdapter\EcAdapterFactory; | ||
use BitWasp\Bitcoin\Crypto\EcAdapter\Impl\Secp256k1\Adapter\EcAdapter; | ||
use BitWasp\Bitcoin\Crypto\EcAdapter\Impl\Secp256k1\Key\PublicKey; | ||
use BitWasp\Bitcoin\Math\Math; | ||
use BitWasp\Bitcoin\Tests\AbstractTestCase; | ||
|
||
class PublicKeyTest extends AbstractTestCase | ||
{ | ||
private function callConstructor($value) | ||
{ | ||
return new PublicKey(EcAdapterFactory::getSecp256k1(new Math(), Bitcoin::getGenerator()), $value, true); | ||
} | ||
public function testNotResource() | ||
{ | ||
if (!function_exists('secp256k1_context_create')) { | ||
$this->markTestSkipped("secp256k1 not installed"); | ||
} | ||
$this->expectException(\InvalidArgumentException::class); | ||
$this->expectExceptionMessage('Secp256k1\Key\PublicKey expects ' . SECP256K1_TYPE_PUBKEY . ' resource'); | ||
$this->callConstructor(""); | ||
} | ||
public function testWrongResourceType() | ||
{ | ||
if (!function_exists('secp256k1_context_create')) { | ||
$this->markTestSkipped("secp256k1 not installed"); | ||
} | ||
$this->expectException(\InvalidArgumentException::class); | ||
$this->expectExceptionMessage('Secp256k1\Key\PublicKey expects ' . SECP256K1_TYPE_PUBKEY . ' resource'); | ||
$this->callConstructor(gmp_init(1)); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
tests/Crypto/EcAdapter/Impl/Secp256k1/Signature/CompactSignatureTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace BitWasp\Bitcoin\Tests\Crypto\EcAdapter\Impl\Secp256k1\Signature; | ||
|
||
use BitWasp\Bitcoin\Bitcoin; | ||
use BitWasp\Bitcoin\Crypto\EcAdapter\EcAdapterFactory; | ||
use BitWasp\Bitcoin\Crypto\EcAdapter\Impl\Secp256k1\Signature\CompactSignature; | ||
use BitWasp\Bitcoin\Crypto\EcAdapter\Impl\Secp256k1\Signature\Signature; | ||
use BitWasp\Bitcoin\Math\Math; | ||
use BitWasp\Bitcoin\Tests\AbstractTestCase; | ||
|
||
class CompactSignatureTest extends AbstractTestCase | ||
{ | ||
private function callConstructor($value) | ||
{ | ||
return new CompactSignature(EcAdapterFactory::getSecp256k1(new Math(), Bitcoin::getGenerator()), $value, 1, true); | ||
} | ||
public function testNotResource() | ||
{ | ||
if (!function_exists('secp256k1_context_create')) { | ||
$this->markTestSkipped("secp256k1 not installed"); | ||
} | ||
$this->expectException(\InvalidArgumentException::class); | ||
$this->expectExceptionMessage('CompactSignature: must pass recoverable signature resource'); | ||
$this->callConstructor(""); | ||
} | ||
public function testWrongResourceType() | ||
{ | ||
if (!function_exists('secp256k1_context_create')) { | ||
$this->markTestSkipped("secp256k1 not installed"); | ||
} | ||
$this->expectException(\InvalidArgumentException::class); | ||
$this->expectExceptionMessage('CompactSignature: must pass recoverable signature resource'); | ||
$this->callConstructor(gmp_init(1)); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/Crypto/EcAdapter/Impl/Secp256k1/Signature/SignatureTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace BitWasp\Bitcoin\Tests\Crypto\EcAdapter\Impl\Secp256k1\Signature; | ||
|
||
use BitWasp\Bitcoin\Bitcoin; | ||
use BitWasp\Bitcoin\Crypto\EcAdapter\EcAdapterFactory; | ||
use BitWasp\Bitcoin\Crypto\EcAdapter\Impl\Secp256k1\Signature\Signature; | ||
use BitWasp\Bitcoin\Math\Math; | ||
use BitWasp\Bitcoin\Tests\AbstractTestCase; | ||
|
||
class SignatureTest extends AbstractTestCase | ||
{ | ||
private function callConstructor($value) | ||
{ | ||
return new Signature(EcAdapterFactory::getSecp256k1(new Math(), Bitcoin::getGenerator()), gmp_init(1), gmp_init(1), $value); | ||
} | ||
public function testNotResource() | ||
{ | ||
if (!function_exists('secp256k1_context_create')) { | ||
$this->markTestSkipped("secp256k1 not installed"); | ||
} | ||
$this->expectException(\InvalidArgumentException::class); | ||
$this->expectExceptionMessage('CompactSignature: must pass recoverable signature resource'); | ||
$this->callConstructor(""); | ||
} | ||
public function testWrongResourceType() | ||
{ | ||
if (!function_exists('secp256k1_context_create')) { | ||
$this->markTestSkipped("secp256k1 not installed"); | ||
} | ||
$this->expectException(\InvalidArgumentException::class); | ||
$this->expectExceptionMessage('CompactSignature: must pass recoverable signature resource'); | ||
$this->callConstructor(gmp_init(1)); | ||
} | ||
} |