Skip to content

Commit

Permalink
fixes setCheckerCreator always throws
Browse files Browse the repository at this point in the history
  • Loading branch information
olegabr authored and afk11 committed Dec 10, 2019
1 parent cbbbf35 commit b213fdc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Transaction/Factory/Signer.php
Expand Up @@ -87,7 +87,7 @@ public function __construct(TransactionInterface $tx, EcAdapterInterface $ecAdap
*/
public function setCheckerCreator(CheckerCreatorBase $checker)
{
if (null === $this->signatureCreator) {
if (count($this->signatureCreator) === 0) {
$this->checkerCreator = $checker;
return $this;
} else {
Expand Down
27 changes: 27 additions & 0 deletions tests/Transaction/Factory/SignerTest.php
Expand Up @@ -331,6 +331,33 @@ public function testRejectsInvalidSigHashType()
$input->getSigHash(20);
}

public function testSetCheckerCreatorNoInputs()
{
$signer = new Signer((new TxBuilder())
->get(), Bitcoin::getEcAdapter());
$ecAdapter = Bitcoin::getEcAdapter();
$checkerCreator = \BitWasp\Bitcoin\Transaction\Factory\Checker\CheckerCreator::fromEcAdapter($ecAdapter);
$signer->setCheckerCreator($checkerCreator);
}

public function testSetCheckerCreator()
{
$outpoint = new OutPoint(new Buffer('', 32), 0xffffffff);
$txOut = new TransactionOutput(5000000000, ScriptFactory::scriptPubKey()->p2pkh((new Random())->bytes(20)));
$signer = new Signer((new TxBuilder())
->inputs([new TransactionInput($outpoint, new Script())])
->outputs([new TransactionOutput(4900000000, new Script)])
->get(), Bitcoin::getEcAdapter());
$input = $signer->input(0, $txOut);
$ecAdapter = Bitcoin::getEcAdapter();
$checkerCreator = \BitWasp\Bitcoin\Transaction\Factory\Checker\CheckerCreator::fromEcAdapter($ecAdapter);

$this->expectException(SignerException::class);
$this->expectExceptionMessage("Cannot change CheckerCreator after inputs have been parsed");

$signer->setCheckerCreator($checkerCreator);
}

public function testDiscouragesInvalidKeysInScripts()
{
$caught = false;
Expand Down

0 comments on commit b213fdc

Please sign in to comment.