aboutsummaryrefslogtreecommitdiff
path: root/test/functional/feature_backwards_compatibility.py
blob: 452b55337467332a5c9b2347116cb38a0123069d (plain)
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
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
# Copyright (c) 2018-2019 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Backwards compatibility functional test

Test various backwards compatibility scenarios. Download the previous node binaries:

contrib/devtools/previous_release.sh -b v0.18.1 v0.17.1

Due to RPC changes introduced in various versions the below tests
won't work for older versions without some patches or workarounds.

Use only the latest patch version of each release, unless a test specifically
needs an older patch version.
"""

import os

from test_framework.test_framework import BitcoinTestFramework, SkipTest

from test_framework.util import (
    assert_equal,
    sync_blocks
)

class BackwardsCompatibilityTest(BitcoinTestFramework):
    def set_test_params(self):
        self.setup_clean_chain = True
        self.num_nodes = 4
        # Add new version after each release:
        self.extra_args = [
            [], # Pre-release: use to mine blocks
            [], # Pre-release: use to receive coins, swap wallets, etc
            [], # v0.18.1
            [] # v0.17.1
        ]

    def setup_nodes(self):
        if os.getenv("TEST_PREVIOUS_RELEASES") == "false":
            raise SkipTest("backwards compatibility tests")

        releases_path = os.getenv("PREVIOUS_RELEASES_DIR") or os.getcwd() + "/releases"
        if not os.path.isdir(releases_path):
            if os.getenv("TEST_PREVIOUS_RELEASES") == "true":
                raise AssertionError("TEST_PREVIOUS_RELEASES=1 but releases missing: " + releases_path)
            raise SkipTest("This test requires binaries for previous releases")

        self.add_nodes(self.num_nodes, extra_args=self.extra_args, versions=[
            None,
            None,
            180100,
            170100
        ], binary=[
            self.options.bitcoind,
            self.options.bitcoind,
            releases_path + "/v0.18.1/bin/bitcoind",
            releases_path + "/v0.17.1/bin/bitcoind"
        ], binary_cli=[
            self.options.bitcoincli,
            self.options.bitcoincli,
            releases_path + "/v0.18.1/bin/bitcoin-cli",
            releases_path + "/v0.17.1/bin/bitcoin-cli"
        ])

        self.start_nodes()

    def run_test(self):
        self.nodes[0].generate(101)

        sync_blocks(self.nodes)

        # Sanity check the test framework:
        res = self.nodes[self.num_nodes - 1].getblockchaininfo()
        assert_equal(res['blocks'], 101)

if __name__ == '__main__':
    BackwardsCompatibilityTest().main()