1 | <?php |
||
6 | |||
7 | class ServerTest extends AbstractTestCase |
||
8 | { |
||
9 | /** |
||
10 | * @var RegtestBitcoinFactory |
||
11 | */ |
||
12 | private $rpcFactory; |
||
13 | |||
14 | public function __construct($name = null, array $data = [], $dataName = '') |
||
15 | { |
||
16 | parent::__construct($name, $data, $dataName); |
||
17 | |||
18 | static $rpcFactory = null; |
||
19 | if (null === $rpcFactory) { |
||
20 | $rpcFactory = new RegtestBitcoinFactory(); |
||
21 | } |
||
22 | $this->rpcFactory = $rpcFactory; |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * Check tests are being run against regtest |
||
27 | */ |
||
28 | public function testIfRegtest() |
||
29 | { |
||
30 | $server = $this->rpcFactory->startBitcoind(); |
||
31 | |||
32 | $result = $server->makeRpcRequest("getblockchaininfo"); |
||
33 | $this->assertInternalType('array', $result); |
||
34 | $this->assertArrayHasKey('result', $result); |
||
35 | $this->assertArrayHasKey('chain', $result['result']); |
||
36 | $this->assertEquals('regtest', $result['result']['chain']); |
||
37 | |||
38 | $server->destroy(); |
||
39 | } |
||
40 | |||
41 | public function testStartStop() |
||
42 | { |
||
43 | $bitcoind = $this->rpcFactory->startBitcoind(); |
||
44 | |||
45 | // First bitcoind, generate block |
||
46 | $result = $bitcoind->request("generate", [1]); |
||
47 | $this->assertInternalType("array", $result['result']); |
||
48 | $this->assertEquals(64, strlen($result['result'][0])); |
||
49 | |||
50 | // First bitcoind, get block height - 1 |
||
51 | $info = $bitcoind->request("getblockchaininfo"); |
||
52 | $this->assertInternalType("array", $info['result']); |
||
53 | $this->assertEquals(1, $info['result']['blocks']); |
||
54 | |||
55 | // Destroy that instance |
||
56 | $bitcoind->destroy(); |
||
57 | $this->assertFalse($bitcoind->isRunning()); |
||
58 | |||
59 | // new bitcoind, 0 blocks |
||
60 | $bitcoind = $this->rpcFactory->startBitcoind(); |
||
61 | |||
62 | $info = $bitcoind->request("getblockchaininfo"); |
||
63 | $this->assertInternalType("array", $info['result']); |
||
64 | $this->assertEquals(0, $info['result']['blocks']); |
||
65 | |||
66 | $bitcoind->destroy(); |
||
67 | } |
||
69 |