Skip to content

Commit

Permalink
Updated readme and tests.
Browse files Browse the repository at this point in the history
preserve_case default value, description and tests.
  • Loading branch information
denpamusic committed Nov 15, 2018
1 parent ed88a50 commit 5d7880e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ or use array to define your bitcoind settings
use Denpa\Bitcoin\Client as BitcoinClient;

$bitcoind = new BitcoinClient([
'scheme' => 'http', // optional, default http
'host' => 'localhost', // optional, default localhost
'port' => 8332, // optional, default 8332
'user' => 'rpcuser', // required
'password' => 'rpcpassword', // required
'ca' => '/etc/ssl/ca-cert.pem' // optional, for use with https scheme
'scheme' => 'http', // optional, default http
'host' => 'localhost', // optional, default localhost
'port' => 8332, // optional, default 8332
'user' => 'rpcuser', // required
'password' => 'rpcpassword', // required
'ca' => '/etc/ssl/ca-cert.pem' // optional, for use with https scheme
'preserve_case' => false, // optional, send method names as defined instead of lowercasing them
]);
```
Then call methods defined in [Bitcoin Core API Documentation](https://bitcoin.org/en/developer-reference#bitcoin-core-apis) with magic:
Expand Down
16 changes: 9 additions & 7 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,13 @@ protected function onError(Exception $exception, callable $callback = null)
protected function getDefaultConfig()
{
return [
'scheme' => 'http',
'host' => '127.0.0.1',
'port' => 8332,
'user' => '',
'password' => '',
'ca' => null,
'scheme' => 'http',
'host' => '127.0.0.1',
'port' => 8332,
'user' => '',
'password' => '',
'ca' => null,
'preserve_case' => false,
];
}

Expand Down Expand Up @@ -389,7 +390,8 @@ protected function makeJson($method, $params = [])
{
return [
'json' => [
'method' => isset($this->config['preserve_case']) ? $method : strtolower($method),
'method' => $this->config['preserve_case'] ?
$method : strtolower($method),
'params' => (array) $params,
'id' => $this->rpcId++,
],
Expand Down
20 changes: 20 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,26 @@ public function testCaOption()
$this->assertEquals(__FILE__, $bitcoind->getConfig('verify'));
}

/**
* Test preserve method name case config option.
*
* @return void
*/
public function testPreserveCase()
{
$bitcoind = new BitcoinClient(['preserve_case' => true]);
$bitcoind->setClient($this->mockGuzzle([$this->getBlockResponse()]));
$bitcoind->getBlockHeader();

$request = $this->getHistoryRequestBody();

$this->assertEquals(false, $bitcoind->getConfig('preserve_case'));
$this->assertEquals($this->makeRequestBody(
'getBlockHeader',
$request['id']
), $request);
}

/**
* Test simple request.
*
Expand Down

0 comments on commit 5d7880e

Please sign in to comment.