Completed
Pull Request — master (#546)
by thomas
113:48 queued 41:22
created

ServerTest::testStartStop()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

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