Completed
Pull Request — master (#546)
by thomas
75:01 queued 05:00
created

ServerTest::testIfRegtest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 15
rs 9.4285
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
        echo "startBitcoind\n";
30
        $server = $this->rpcFactory->startBitcoind();
31
32
        echo "getblockchaininfo\n";
33
        $result = $server->makeRpcRequest("getblockchaininfo");
34
        $this->assertInternalType('array', $result);
35
        $this->assertArrayHasKey('result', $result);
36
        $this->assertArrayHasKey('chain', $result['result']);
37
        $this->assertEquals('regtest', $result['result']['chain']);
38
39
        echo "stop\n";
40
        $server->destroy();
41
    }
42
43
    public function testStartStop() {
44
        $bitcoind = $this->rpcFactory->startBitcoind();
45
46
        // First bitcoind, generate block
47
        $result = $bitcoind->request("generate", [1]);
48
        $this->assertInternalType("array", $result['result']);
49
        $this->assertEquals(64, strlen($result['result'][0]));
50
51
        // First bitcoind, get block height - 1
52
        $info = $bitcoind->request("getblockchaininfo");
53
        $this->assertInternalType("array", $info['result']);
54
        $this->assertEquals(1, $info['result']['blocks']);
55
56
        // Destroy that instance
57
        $bitcoind->destroy();
58
        $this->assertFalse($bitcoind->isRunning());
59
60
        // new bitcoind, 0 blocks
61
        $bitcoind = $this->rpcFactory->startBitcoind();
62
63
        $info = $bitcoind->request("getblockchaininfo");
64
        $this->assertInternalType("array", $info['result']);
65
        $this->assertEquals(0, $info['result']['blocks']);
66
67
        $bitcoind->destroy();
68
    }
69
}
70