forked from Bit-Wasp/bitcoin-php
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathServerTest.php
68 lines (53 loc) · 1.94 KB
/
ServerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
declare(strict_types=1);
namespace BitWasp\Bitcoin\RpcTest;
class ServerTest extends AbstractTestCase
{
/**
* @var RegtestBitcoinFactory
*/
private $rpcFactory;
public function __construct($name = null, array $data = [], $dataName = '')
{
parent::__construct($name, $data, $dataName);
static $rpcFactory = null;
if (null === $rpcFactory) {
$rpcFactory = new RegtestBitcoinFactory();
}
$this->rpcFactory = $rpcFactory;
}
/**
* Check tests are being run against regtest
*/
public function testIfRegtest()
{
$server = $this->rpcFactory->startBitcoind();
$result = $server->makeRpcRequest("getblockchaininfo");
$this->assertInternalType('array', $result);
$this->assertArrayHasKey('result', $result);
$this->assertArrayHasKey('chain', $result['result']);
$this->assertEquals('regtest', $result['result']['chain']);
$server->destroy();
}
public function testStartStop()
{
$bitcoind = $this->rpcFactory->startBitcoind();
// First bitcoind, generate block
$result = $bitcoind->request("generate", [1]);
$this->assertInternalType("array", $result['result']);
$this->assertEquals(64, strlen($result['result'][0]));
// First bitcoind, get block height - 1
$info = $bitcoind->request("getblockchaininfo");
$this->assertInternalType("array", $info['result']);
$this->assertEquals(1, $info['result']['blocks']);
// Destroy that instance
$bitcoind->destroy();
$this->assertFalse($bitcoind->isRunning());
// new bitcoind, 0 blocks
$bitcoind = $this->rpcFactory->startBitcoind();
$info = $bitcoind->request("getblockchaininfo");
$this->assertInternalType("array", $info['result']);
$this->assertEquals(0, $info['result']['blocks']);
$bitcoind->destroy();
}
}