Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DisabledGlobalNetwork - allow disabling global network (with errors) #716

Open
wants to merge 1 commit into
base: 0.0.35
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Exceptions/DisabledGlobalNetworkException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace BitWasp\Bitcoin\Exceptions;

class DisabledGlobalNetworkException extends \Exception
{

}
41 changes: 41 additions & 0 deletions src/Network/DisabledGlobalNetwork.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace BitWasp\Bitcoin\Network;

use BitWasp\Bitcoin\Exceptions\DisabledGlobalNetworkException;

class DisabledGlobalNetwork implements NetworkInterface
{
public function getAddressByte()
{
throw new DisabledGlobalNetworkException();
}
public function getHDPrivByte()
{
throw new DisabledGlobalNetworkException();
}
public function getHDPubByte()
{
throw new DisabledGlobalNetworkException();
}
public function getNetMagicBytes()
{
throw new DisabledGlobalNetworkException();
}
public function getP2shByte()
{
throw new DisabledGlobalNetworkException();
}
public function getPrivByte()
{
throw new DisabledGlobalNetworkException();
}
public function getSegwitBech32Prefix()
{
throw new DisabledGlobalNetworkException();
}
public function getSignedMessageMagic()
{
throw new DisabledGlobalNetworkException();
}
}
30 changes: 30 additions & 0 deletions tests/Network/DisabledGlobalNetworkTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace BitWasp\Bitcoin\Tests\Network;

use BitWasp\Bitcoin\Network\DisabledGlobalNetwork;
use BitWasp\Bitcoin\Network\NetworkInterface;
use BitWasp\Bitcoin\Tests\AbstractTestCase;

class DisabledGlobalNetworkTest extends AbstractTestCase
{
public function getMethods()
{
$methods = [];
foreach (get_class_methods(NetworkInterface::class) as $method) {
$methods[] = [$method];
}
return $methods;
}

/**
* @expectedException \BitWasp\Bitcoin\Exceptions\DisabledGlobalNetworkException
* @dataProvider getMethods
* @param string $method
*/
public function testThrows($method)
{
$network = new DisabledGlobalNetwork();
$network->{$method}();
}
}