Esempio n. 1
0
    def run_test(self):
        # due to OS-specific network stats queries, this test works only on Linux
        if sum([self.options.run_ipv4, self.options.run_ipv6, self.options.run_nonloopback]) > 1:
            raise AssertionError("Only one of --ipv4, --ipv6 and --nonloopback can be set")

        self.log.info("Check for linux")
        if not sys.platform.startswith('linux'):
            raise SkipTest("This test can only be run on linux.")

        self.log.info("Check for ipv6")
        have_ipv6 = test_ipv6_local()
        if not have_ipv6 and not self.options.run_ipv4:
            raise SkipTest("This test requires ipv6 support.")

        self.log.info("Check for non-loopback interface")
        self.non_loopback_ip = None
        for name,ip in all_interfaces():
            if ip != '127.0.0.1':
                self.non_loopback_ip = ip
                break
        if self.non_loopback_ip is None and self.options.run_nonloopback:
            raise SkipTest("This test requires a non-loopback ip address.")

        self.defaultport = rpc_port(0)

        if not self.options.run_nonloopback:
            self._run_loopback_tests()
        if not self.options.run_ipv4 and not self.options.run_ipv6:
            self._run_nonloopback_tests()
Esempio n. 2
0
    def run_test(self):
        # due to OS-specific network stats queries, this test works only on Linux
        if sum([
                self.options.run_ipv4, self.options.run_ipv6,
                self.options.run_nonloopback
        ]) > 1:
            raise AssertionError(
                "Only one of --ipv4, --ipv6 and --nonloopback can be set")

        self.log.info("Check for linux")
        if not sys.platform.startswith('linux'):
            raise SkipTest("This test can only be run on linux.")

        self.log.info("Check for ipv6")
        have_ipv6 = test_ipv6_local()
        if not have_ipv6 and not self.options.run_ipv4:
            raise SkipTest("This test requires ipv6 support.")

        self.log.info("Check for non-loopback interface")
        self.non_loopback_ip = None
        for name, ip in all_interfaces():
            if ip != '127.0.0.1':
                self.non_loopback_ip = ip
                break
        if self.non_loopback_ip is None and self.options.run_nonloopback:
            raise SkipTest("This test requires a non-loopback ip address.")

        self.defaultport = rpc_port(0)

        if not self.options.run_nonloopback:
            self._run_loopback_tests()
        if not self.options.run_ipv4 and not self.options.run_ipv6:
            self._run_nonloopback_tests()
Esempio n. 3
0
    def run_test(self):
        # due to OS-specific network stats queries, this test works only on Linux
        if not sys.platform.startswith('linux'):
            raise SkipTest("This test can only be run on linux.")
        # find the first non-loopback interface for testing
        non_loopback_ip = None
        for _, ip in all_interfaces():
            if ip != '127.0.0.1':
                non_loopback_ip = ip
                break
        if non_loopback_ip is None:
            raise SkipTest(
                "This test requires at least one non-loopback IPv4 interface.")
        try:
            s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
            s.connect(("::1", 1))
            s.close()
        except OSError:
            raise SkipTest("This test requires IPv6 support.")

        self.log.info("Using interface %s for testing" % non_loopback_ip)

        default_port = rpc_port(0)

        # check default without rpcallowip (IPv4 and IPv6 localhost)
        self.run_bind_test(None, '127.0.0.1', [], [('127.0.0.1', default_port),
                                                   ('::1', default_port)])
        # check default with rpcallowip (IPv6 any)
        self.run_bind_test(['127.0.0.1'], '127.0.0.1', [],
                           [('::0', default_port)])
        # check only IPv4 localhost (explicit)
        self.run_bind_test(['127.0.0.1'], '127.0.0.1', ['127.0.0.1'],
                           [('127.0.0.1', default_port)])
        # check only IPv4 localhost (explicit) with alternative port
        self.run_bind_test(['127.0.0.1'], '127.0.0.1:32171',
                           ['127.0.0.1:32171'], [('127.0.0.1', 32171)])
        # check only IPv4 localhost (explicit) with multiple alternative ports on same host
        self.run_bind_test(['127.0.0.1'], '127.0.0.1:32171',
                           ['127.0.0.1:32171', '127.0.0.1:32172'],
                           [('127.0.0.1', 32171), ('127.0.0.1', 32172)])
        # check only IPv6 localhost (explicit)
        self.run_bind_test(['[::1]'], '[::1]', ['[::1]'],
                           [('::1', default_port)])
        # check both IPv4 and IPv6 localhost (explicit)
        self.run_bind_test(['127.0.0.1'], '127.0.0.1', ['127.0.0.1', '[::1]'],
                           [('127.0.0.1', default_port),
                            ('::1', default_port)])
        # check only non-loopback interface
        self.run_bind_test([non_loopback_ip], non_loopback_ip,
                           [non_loopback_ip],
                           [(non_loopback_ip, default_port)])

        # Check that with invalid rpcallowip, we are denied
        self.run_allowip_test([non_loopback_ip], non_loopback_ip, default_port)
        assert_raises_rpc_error(
            -342, "non-JSON HTTP response with '403 Forbidden' from server",
            self.run_allowip_test, ['1.1.1.1'], non_loopback_ip, default_port)
Esempio n. 4
0
def run_test(tmpdir):
    assert (
        sys.platform == 'linux2'
    )  # due to OS-specific network stats queries, this test works only on Linux
    # find the first non-loopback interface for testing
    non_loopback_ip = None
    for name, ip in all_interfaces():
        if ip != '127.0.0.1':
            non_loopback_ip = ip
            break
    if non_loopback_ip is None:
        assert (
            not 'This test requires at least one non-loopback IPv4 interface')
    print("Using interface %s for testing" % non_loopback_ip)

    defaultport = rpc_port(0)

    # check default without rpcallowip (IPv4 and IPv6 localhost)
    run_bind_test(tmpdir, None, '127.0.0.1', [], [('127.0.0.1', defaultport),
                                                  ('::1', defaultport)])
    # check default with rpcallowip (IPv6 any)
    run_bind_test(tmpdir, ['127.0.0.1'], '127.0.0.1', [],
                  [('::0', defaultport)])
    # check only IPv4 localhost (explicit)
    run_bind_test(tmpdir, ['127.0.0.1'], '127.0.0.1', ['127.0.0.1'],
                  [('127.0.0.1', defaultport)])
    # check only IPv4 localhost (explicit) with alternative port
    run_bind_test(tmpdir, ['127.0.0.1'], '127.0.0.1:32171',
                  ['127.0.0.1:32171'], [('127.0.0.1', 32171)])
    # check only IPv4 localhost (explicit) with multiple alternative ports on same host
    run_bind_test(tmpdir, ['127.0.0.1'], '127.0.0.1:32171',
                  ['127.0.0.1:32171', '127.0.0.1:32172'],
                  [('127.0.0.1', 32171), ('127.0.0.1', 32172)])
    # check only IPv6 localhost (explicit)
    run_bind_test(tmpdir, ['[::1]'], '[::1]', ['[::1]'],
                  [('::1', defaultport)])
    # check both IPv4 and IPv6 localhost (explicit)
    run_bind_test(tmpdir, ['127.0.0.1'], '127.0.0.1', ['127.0.0.1', '[::1]'],
                  [('127.0.0.1', defaultport), ('::1', defaultport)])
    # check only non-loopback interface
    run_bind_test(tmpdir, [non_loopback_ip], non_loopback_ip,
                  [non_loopback_ip], [(non_loopback_ip, defaultport)])

    # Check that with invalid rpcallowip, we are denied
    run_allowip_test(tmpdir, [non_loopback_ip], non_loopback_ip, defaultport)
    try:
        run_allowip_test(tmpdir, ['1.1.1.1'], non_loopback_ip, defaultport)
        assert (not 'Connection not denied by rpcallowip as expected')
    except ValueError:
        pass
Esempio n. 5
0
def run_test(tmpdir):
    assert(sys.platform == 'linux2') # due to OS-specific network stats queries, this test works only on Linux
    # find the first non-loopback interface for testing
    non_loopback_ip = None
    for name,ip in all_interfaces():
        if ip != '127.0.0.1':
            non_loopback_ip = ip
            break
    if non_loopback_ip is None:
        assert(not 'This test requires at least one non-loopback IPv4 interface')
    print("Using interface %s for testing" % non_loopback_ip)

    defaultport = rpc_port(0)

    # check default without rpcallowip (IPv4 and IPv6 localhost)
    run_bind_test(tmpdir, None, '127.0.0.1', [],
        [('127.0.0.1', defaultport), ('::1', defaultport)])
    # check default with rpcallowip (IPv6 any)
    run_bind_test(tmpdir, ['127.0.0.1'], '127.0.0.1', [],
        [('::0', defaultport)])
    # check only IPv4 localhost (explicit)
    run_bind_test(tmpdir, ['127.0.0.1'], '127.0.0.1', ['127.0.0.1'],
        [('127.0.0.1', defaultport)])
    # check only IPv4 localhost (explicit) with alternative port
    run_bind_test(tmpdir, ['127.0.0.1'], '127.0.0.1:32171', ['127.0.0.1:32171'],
        [('127.0.0.1', 32171)])
    # check only IPv4 localhost (explicit) with multiple alternative ports on same host
    run_bind_test(tmpdir, ['127.0.0.1'], '127.0.0.1:32171', ['127.0.0.1:32171', '127.0.0.1:32172'],
        [('127.0.0.1', 32171), ('127.0.0.1', 32172)])
    # check only IPv6 localhost (explicit)
    run_bind_test(tmpdir, ['[::1]'], '[::1]', ['[::1]'],
        [('::1', defaultport)])
    # check both IPv4 and IPv6 localhost (explicit)
    run_bind_test(tmpdir, ['127.0.0.1'], '127.0.0.1', ['127.0.0.1', '[::1]'],
        [('127.0.0.1', defaultport), ('::1', defaultport)])
    # check only non-loopback interface
    run_bind_test(tmpdir, [non_loopback_ip], non_loopback_ip, [non_loopback_ip],
        [(non_loopback_ip, defaultport)])

    # Check that with invalid rpcallowip, we are denied
    run_allowip_test(tmpdir, [non_loopback_ip], non_loopback_ip, defaultport)
    try:
        run_allowip_test(tmpdir, ['1.1.1.1'], non_loopback_ip, defaultport)
        assert(not 'Connection not denied by rpcallowip as expected')
    except ValueError:
        pass
Esempio n. 6
0
 def run_test(self):
     for i in range(len(self.expected)):
         self.log.info(f"Starting node {i} with {self.expected[i][0]}")
         self.start_node(i)
         pid = self.nodes[i].process.pid
         binds = set(get_bind_addrs(pid))
         # Remove IPv6 addresses because on some CI environments "::1" is not configured
         # on the system (so our test_ipv6_local() would return False), but it is
         # possible to bind on "::". This makes it unpredictable whether to expect
         # that syscoind has bound on "::1" (for RPC) and "::" (for P2P).
         ipv6_addr_len_bytes = 32
         binds = set(filter(lambda e: len(e[0]) != ipv6_addr_len_bytes, binds))
         # Remove RPC ports. They are not relevant for this test.
         binds = set(filter(lambda e: e[1] != rpc_port(i), binds))
         assert_equal(binds, set(self.expected[i][1]))
         self.stop_node(i)
         self.log.info(f"Stopped node {i}")
Esempio n. 7
0
    def run_test(self):
        # due to OS-specific network stats queries, this test works only on
        # Linux
        if sum([
                self.options.run_ipv4, self.options.run_ipv6,
                self.options.run_nonloopback
        ]) > 1:
            raise AssertionError(
                "Only one of --ipv4, --ipv6 and --nonloopback can be set")

        self.log.info("Check for linux")
        if not sys.platform.startswith('linux'):
            raise SkipTest("This test can only be run on linux.")

        # WSL in currently not supported (refer to
        # https://reviews.bitcoinabc.org/T400 for details).
        # This condition should be removed once netstat support is provided by
        # Microsoft.
        if "microsoft" in uname().version.lower():
            raise SkipTest(
                "Running this test on WSL is currently not supported")

        self.log.info("Check for ipv6")
        have_ipv6 = test_ipv6_local()
        if not have_ipv6 and not (self.options.run_ipv4
                                  or self.options.run_nonloopback):
            raise SkipTest("This test requires ipv6 support.")

        self.log.info("Check for non-loopback interface")
        self.non_loopback_ip = None

        for name, ip in all_interfaces():
            if ip != '127.0.0.1':
                self.non_loopback_ip = ip
                break
        if self.non_loopback_ip is None and self.options.run_nonloopback:
            raise SkipTest("This test requires a non-loopback ip address.")

        self.defaultport = rpc_port(0)

        if not self.options.run_nonloopback:
            self._run_loopback_tests()
        if not self.options.run_ipv4 and not self.options.run_ipv6:
            self._run_nonloopback_tests()
Esempio n. 8
0
    def run_test(self):
        self.nodes[0].generate(101)

        # sending a transaction without fee estimations must be possible by default on regtest
        self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)

        # test sending a tx with disabled fallback fee (must fail)
        self.restart_node(0, extra_args=["-fallbackfee=0"])
        assert_raises_rpc_error(-6, "Fee estimation failed", lambda: self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1))
        assert_raises_rpc_error(-4, "Fee estimation failed", lambda: self.nodes[0].fundrawtransaction(self.nodes[0].createrawtransaction([], [{self.nodes[0].getnewaddress(): 1}])))
        assert_raises_rpc_error(-6, "Fee estimation failed", lambda: self.nodes[0].sendmany("", {self.nodes[0].getnewaddress(): 1}))

        ## ELEMENTS: test claimpegin with fallback fee set to zero
        # getpeginaddress does not work with descriptor wallets yet
        if not self.options.descriptors:
            extra_args = [
                '-fallbackfee=0',
                '-mainchainrpchost=127.0.0.1',
                '-mainchainrpcport=%s' % rpc_port(0),
                '-parentgenesisblockhash=%s' % self.nodes[0].getblockhash(0),
                '-con_parent_chain_signblockscript=51',
                '-parentscriptprefix=75',
            ]
            self.restart_node(0)
            self.restart_node(1, extra_args)

            addrs = self.nodes[1].getpeginaddress()
            txid = self.nodes[0].sendtoaddress(addrs["mainchain_address"], 5)
            raw = self.nodes[0].getrawtransaction(txid)
            self.nodes[0].generate(12)
            proof = self.nodes[0].gettxoutproof([txid])
            assert_raises_rpc_error(-6, "Fee estimation failed", lambda: self.nodes[1].claimpegin(raw, proof))

            # Try again with fallbackfee below the min relay fee. It should just work
            # (will let the relay fee override the fallbackfee)
            extra_args[0] = '-fallbackfee=0.00000001'
            self.restart_node(1, extra_args)
            self.nodes[1].claimpegin(raw, proof)
Esempio n. 9
0
 def run_bind_test(self, allow_ips, connect_to, addresses, expected):
     '''
     Start a node with requested rpcallowip and rpcbind parameters,
     then try to connect, and check if the set of bound addresses
     matches the expected set.
     '''
     self.log.info("Bind test for {}".format(str(addresses)))
     expected = [(addr_to_hex(addr), port) for (addr, port) in expected]
     base_args = ['-disablewallet', '-nolisten']
     if allow_ips:
         base_args += ['-rpcallowip=' + x for x in allow_ips]
     binds = ['-rpcbind=' + addr for addr in addresses]
     parts = connect_to.split(':')
     if len(parts) == 2:
         self.nodes[0].host = parts[0]
         self.nodes[0].rpc_port = parts[1]
     else:
         self.nodes[0].host = connect_to
         self.nodes[0].rpc_port = rpc_port(self.nodes[0].index)
     self.start_node(0, base_args + binds)
     pid = self.nodes[0].process.pid
     assert_equal(set(get_bind_addrs(pid)), set(expected))
     self.stop_nodes()
Esempio n. 10
0
    def setup_network(self, split=False):
        if self.options.parent_bitcoin and self.options.parent_binpath == "":
            raise Exception(
                "Can't run with --parent_bitcoin without specifying --parent_binpath"
            )

        self.nodes = []
        # Setup parent nodes
        parent_chain = "parent" if not self.options.parent_bitcoin else "regtest"
        parent_binary = [self.options.parent_binpath
                         ] if self.options.parent_binpath != "" else None
        for n in range(2):
            extra_args = [
                "-port=" + str(p2p_port(n)), "-rpcport=" + str(rpc_port(n))
            ]
            if self.options.parent_bitcoin:
                # bitcoind can't read elements.conf config files
                extra_args.extend([
                    "-regtest=1",
                    "-printtoconsole=0",
                    "-server=1",
                    "-discover=0",
                    "-keypool=1",
                    "-listenonion=0",
                    "-addresstype=legacy",  # To make sure bitcoind gives back p2pkh no matter version
                ])
            else:
                extra_args.extend([
                    "-validatepegin=0",
                    "-initialfreecoins=0",
                    "-anyonecanspendaremine",
                    "-signblockscript=51",  # OP_TRUE
                    '-con_blocksubsidy=5000000000',
                ])

            self.add_nodes(1, [extra_args],
                           chain=[parent_chain],
                           binary=parent_binary,
                           chain_in_args=[not self.options.parent_bitcoin])
            self.start_node(n)
            print("Node {} started".format(n))

        connect_nodes_bi(self.nodes, 0, 1)
        self.parentgenesisblockhash = self.nodes[0].getblockhash(0)
        if not self.options.parent_bitcoin:
            parent_pegged_asset = self.nodes[0].getsidechaininfo(
            )['pegged_asset']

        # Setup sidechain nodes
        self.fedpeg_script = "512103dff4923d778550cc13ce0d887d737553b4b58f4e8e886507fc39f5e447b2186451ae"
        for n in range(2):
            extra_args = [
                "-printtoconsole=0",
                "-port=" + str(p2p_port(2 + n)),
                "-rpcport=" + str(rpc_port(2 + n)),
                '-parentgenesisblockhash=%s' % self.parentgenesisblockhash,
                '-validatepegin=1',
                '-fedpegscript=%s' % self.fedpeg_script,
                '-anyonecanspendaremine=0',
                '-minrelaytxfee=0',
                '-blockmintxfee=0',
                '-initialfreecoins=0',
                '-peginconfirmationdepth=10',
                '-mainchainrpchost=127.0.0.1',
                '-mainchainrpcport=%s' % rpc_port(n),
                '-recheckpeginblockinterval=15',  # Long enough to allow failure and repair before timeout
                '-parentpubkeyprefix=111',
                '-parentscriptprefix=196',
            ]
            if not self.options.parent_bitcoin:
                extra_args.extend([
                    '-parentpubkeyprefix=111',
                    '-parentscriptprefix=196',
                    '-con_parent_chain_signblockscript=51',
                    '-con_parent_pegged_asset=%s' % parent_pegged_asset,
                ])

            # Use rpcuser auth only for first parent.
            if n == 0:
                # Extract username and password from cookie file and use directly.
                datadir = get_datadir_path(self.options.tmpdir, n)
                rpc_u, rpc_p = get_auth_cookie(datadir, parent_chain)
                extra_args.extend([
                    '-mainchainrpcuser=%s' % rpc_u,
                    '-mainchainrpcpassword=%s' % rpc_p,
                ])
            else:
                # Need to specify where to find parent cookie file
                datadir = get_datadir_path(self.options.tmpdir, n)
                extra_args.append('-mainchainrpccookiefile=' + datadir + "/" +
                                  parent_chain + "/.cookie")

            self.add_nodes(1, [extra_args], chain=["sidechain"])
            self.start_node(2 + n)
            print("Node {} started".format(2 + n))

        # We only connect the same-chain nodes, so sync_all works correctly
        connect_nodes_bi(self.nodes, 2, 3)
        self.node_groups = [[self.nodes[0], self.nodes[1]],
                            [self.nodes[2], self.nodes[3]]]
        self.sync_all(self.node_groups)
        print("Setting up network done")
Esempio n. 11
0
    def setup_network(self, split=False):
        if self.options.parent_bitcoin and self.options.parent_binpath == "":
            raise Exception(
                "Can't run with --parent_bitcoin without specifying --parent_binpath"
            )

        self.nodes = []
        # Setup parent nodes
        parent_chain = "elementsregtest" if not self.options.parent_bitcoin else "regtest"
        parent_binary = [self.options.parent_binpath
                         ] if self.options.parent_binpath != "" else None
        for n in range(2):
            extra_args = [
                "-port=" + str(p2p_port(n)), "-rpcport=" + str(rpc_port(n))
            ]
            if self.options.parent_bitcoin:
                # bitcoind can't read elements.conf config files
                extra_args.extend([
                    "-regtest=1",
                    "-printtoconsole=0",
                    "-server=1",
                    "-discover=0",
                    "-keypool=1",
                    "-listenonion=0",
                    "-addresstype=legacy",  # To make sure bitcoind gives back p2pkh no matter version
                    "-fallbackfee=0.0002"
                ])
            else:
                extra_args.extend([
                    "-validatepegin=0",
                    "-initialfreecoins=0",
                    "-anyonecanspendaremine=1",
                    "-signblockscript=51",  # OP_TRUE
                ])

            self.add_nodes(1, [extra_args],
                           chain=[parent_chain],
                           binary=parent_binary,
                           chain_in_args=[not self.options.parent_bitcoin])
            self.start_node(n)
            print("Node {} started".format(n))
        # set hard-coded mining keys for non-Elements chains
        if self.options.parent_bitcoin:
            self.nodes[0].set_deterministic_priv_key(
                '2Mysp7FKKe52eoC2JmU46irt1dt58TpCvhQ',
                'cTNbtVJmhx75RXomhYWSZAafuNNNKPd1cr2ZiUcAeukLNGrHWjvJ')
            self.nodes[1].set_deterministic_priv_key(
                '2N19ZHF3nEzBXzkaZ3N5sVBJXQ8jZ7Udpg5',
                'cRnDSw1JsjmYYEN6xxQvf5pqMENsRE584z6MdWfJ7v85c4ciitkk')

        connect_nodes_bi(self.nodes, 0, 1)
        self.parentgenesisblockhash = self.nodes[0].getblockhash(0)
        if not self.options.parent_bitcoin:
            parent_pegged_asset = self.nodes[0].getsidechaininfo(
            )['pegged_asset']

        # Setup sidechain nodes
        self.fedpeg_script = "512103dff4923d778550cc13ce0d887d737553b4b58f4e8e886507fc39f5e447b2186451ae"
        for n in range(2):
            extra_args = [
                "-printtoconsole=0",
                "-port=" + str(p2p_port(2 + n)),
                "-rpcport=" + str(rpc_port(2 + n)),
                '-validatepegin=1',
                '-fedpegscript=%s' % self.fedpeg_script,
                '-minrelaytxfee=0',
                '-blockmintxfee=0',
                '-initialfreecoins=0',
                '-peginconfirmationdepth=10',
                '-mainchainrpchost=127.0.0.1',
                '-mainchainrpcport=%s' % rpc_port(n),
                '-recheckpeginblockinterval=15',  # Long enough to allow failure and repair before timeout
                '-parentgenesisblockhash=%s' % self.parentgenesisblockhash,
                '-parentpubkeyprefix=111',
                '-parentscriptprefix=196',
                '-parent_bech32_hrp=bcrt',
                # Turn of consistency checks that can cause assert when parent node stops
                # and a peg-in transaction fails this belt-and-suspenders check.
                '-checkmempool=0',
            ]
            if not self.options.parent_bitcoin:
                extra_args.extend([
                    '-parentpubkeyprefix=235',
                    '-parentscriptprefix=75',
                    '-parent_bech32_hrp=ert',
                    '-con_parent_chain_signblockscript=51',
                    '-con_parent_pegged_asset=%s' % parent_pegged_asset,
                ])

            # Immediate activation of dynafed when requested versus "never" from conf
            if self.options.pre_transition or self.options.post_transition:
                extra_args.extend(["-con_dyna_deploy_start=-1"])

            # Use rpcuser auth only for first parent.
            if n == 0:
                # Extract username and password from cookie file and use directly.
                datadir = get_datadir_path(self.options.tmpdir, n)
                rpc_u, rpc_p = get_auth_cookie(datadir, parent_chain)
                extra_args.extend([
                    '-mainchainrpcuser=%s' % rpc_u,
                    '-mainchainrpcpassword=%s' % rpc_p,
                ])
            else:
                # Need to specify where to find parent cookie file
                datadir = get_datadir_path(self.options.tmpdir, n)
                extra_args.append('-mainchainrpccookiefile=' + datadir + "/" +
                                  parent_chain + "/.cookie")

            self.add_nodes(1, [extra_args], chain=["elementsregtest"])
            self.start_node(2 + n)
            print("Node {} started".format(2 + n))

        # We only connect the same-chain nodes, so sync_all works correctly
        connect_nodes_bi(self.nodes, 2, 3)
        self.node_groups = [[self.nodes[0], self.nodes[1]],
                            [self.nodes[2], self.nodes[3]]]
        self.sync_all(self.node_groups)
        print("Setting up network done")
Esempio n. 12
0
    def run_test(self):
        # due to OS-specific network stats queries, this test works only on Linux
        if not sys.platform.startswith('linux'):
            raise SkipTest("This test can only be run on Linux.")

        # WSL in currently not supported (refer to
        # https://reviews.bitcoinabc.org/T400 for details).
        # This condition should be removed once netstat support is provided by
        # Microsoft.
        if "microsoft" in uname().version.lower():
            raise SkipTest(
                "Running this test on WSL is currently not supported")

        # find the first non-loopback interface for testing
        non_loopback_ip = None
        for name, ip in all_interfaces():
            if ip != '127.0.0.1':
                non_loopback_ip = ip
                break
        if non_loopback_ip is None:
            raise SkipTest(
                "This test requires at least one non-loopback IPv4 interface.")
        try:
            s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
            s.connect(("::1", 1))
            s.close
        except OSError:
            raise SkipTest("This test requires IPv6 support.")

        self.log.info("Using interface {} for testing".format(non_loopback_ip))

        defaultport = rpc_port(0)

        # check default without rpcallowip (IPv4 and IPv6 localhost)
        self.run_bind_test(None, '127.0.0.1', [], [('127.0.0.1', defaultport),
                                                   ('::1', defaultport)])
        # check default with rpcallowip (IPv6 any)
        self.run_bind_test(['127.0.0.1'], '127.0.0.1', [],
                           [('::0', defaultport)])
        # check only IPv4 localhost (explicit)
        self.run_bind_test(['127.0.0.1'], '127.0.0.1', ['127.0.0.1'],
                           [('127.0.0.1', defaultport)])
        # check only IPv4 localhost (explicit) with alternative port
        self.run_bind_test(['127.0.0.1'], '127.0.0.1:32171',
                           ['127.0.0.1:32171'], [('127.0.0.1', 32171)])
        # check only IPv4 localhost (explicit) with multiple alternative ports
        # on same host
        self.run_bind_test(['127.0.0.1'], '127.0.0.1:32171',
                           ['127.0.0.1:32171', '127.0.0.1:32172'],
                           [('127.0.0.1', 32171), ('127.0.0.1', 32172)])
        # check only IPv6 localhost (explicit)
        self.run_bind_test(['[::1]'], '[::1]', ['[::1]'],
                           [('::1', defaultport)])
        # check both IPv4 and IPv6 localhost (explicit)
        self.run_bind_test(['127.0.0.1'], '127.0.0.1', ['127.0.0.1', '[::1]'],
                           [('127.0.0.1', defaultport), ('::1', defaultport)])
        # check only non-loopback interface
        self.run_bind_test([non_loopback_ip], non_loopback_ip,
                           [non_loopback_ip], [(non_loopback_ip, defaultport)])

        # Check that with invalid rpcallowip, we are denied
        self.run_allowip_test([non_loopback_ip], non_loopback_ip, defaultport)
        assert_raises_rpc_error(
            -342, "non-JSON HTTP response with '403 Forbidden' from server",
            self.run_allowip_test, ['1.1.1.1'], non_loopback_ip, defaultport)
Esempio n. 13
0
 def get_local_peer(self, node_index, is_rpc=False):
     port = self.get_node_setting(node_index,
                                  "rpcport" if is_rpc else "port")
     return "127.0.0.1:" + str(
         rpc_port(node_index) if port is None else port)
Esempio n. 14
0
    def setup_network(self, split=False):
        if self.options.parent_bitcoin and self.options.parent_binpath == "":
            raise Exception("Can't run with --parent_bitcoin without specifying --parent_binpath")

        self.nodes = []
        # Setup parent nodes
        parent_chain = "parent" if not self.options.parent_bitcoin else "regtest"
        parent_binary = [self.options.parent_binpath] if self.options.parent_binpath != "" else None
        for n in range(2):
            extra_args = [
                "-port="+str(p2p_port(n)),
                "-rpcport="+str(rpc_port(n))
            ]
            if self.options.parent_bitcoin:
                # bitcoind can't read elements.conf config files
                extra_args.extend([
                    "-regtest=1",
                    "-printtoconsole=0",
                    "-server=1",
                    "-discover=0",
                    "-keypool=1",
                    "-listenonion=0",
                    "-addresstype=legacy", # To make sure bitcoind gives back p2pkh no matter version
                ])
            else:
                extra_args.extend([
                    "-validatepegin=0",
                    "-initialfreecoins=0",
                    "-anyonecanspendaremine",
                    "-signblockscript=51", # OP_TRUE
                    '-con_blocksubsidy=5000000000',
                    "-pubkeyprefix=111",
                    "-scriptprefix=196",
                ])

            self.add_nodes(1, [extra_args], chain=[parent_chain], binary=parent_binary, chain_in_args=[not self.options.parent_bitcoin])
            self.start_node(n)
            print("Node {} started".format(n))

        connect_nodes_bi(self.nodes, 0, 1)
        self.parentgenesisblockhash = self.nodes[0].getblockhash(0)
        if not self.options.parent_bitcoin:
            parent_pegged_asset = self.nodes[0].getsidechaininfo()['pegged_asset']

        # Setup sidechain nodes
        self.fedpeg_script = "512103dff4923d778550cc13ce0d887d737553b4b58f4e8e886507fc39f5e447b2186451ae"
        for n in range(2):
            extra_args = [
                "-printtoconsole=0",
                "-port="+str(p2p_port(2+n)),
                "-rpcport="+str(rpc_port(2+n)),
                '-parentgenesisblockhash=%s' % self.parentgenesisblockhash,
                '-validatepegin=1',
                '-fedpegscript=%s' % self.fedpeg_script,
                '-anyonecanspendaremine=0',
                '-minrelaytxfee=0',
                '-blockmintxfee=0',
                '-initialfreecoins=0',
                '-peginconfirmationdepth=10',
                '-mainchainrpchost=127.0.0.1',
                '-mainchainrpcport=%s' % rpc_port(n),
                '-recheckpeginblockinterval=15', # Long enough to allow failure and repair before timeout
                '-parentpubkeyprefix=111',
                '-parentscriptprefix=196',
                # Turn of consistency checks that can cause assert when parent node stops
                # and a peg-in transaction fails this belt-and-suspenders check.
                '-checkmempool=0',
            ]
            if not self.options.parent_bitcoin:
                extra_args.extend([
                    '-parentpubkeyprefix=111',
                    '-parentscriptprefix=196',
                    "-parent_bech32_hrp=ert",
                    '-con_parent_chain_signblockscript=51',
                    '-con_parent_pegged_asset=%s' % parent_pegged_asset,
                ])

            # Use rpcuser auth only for first parent.
            if n==0:
                # Extract username and password from cookie file and use directly.
                datadir = get_datadir_path(self.options.tmpdir, n)
                rpc_u, rpc_p = get_auth_cookie(datadir, parent_chain)
                extra_args.extend([
                    '-mainchainrpcuser=%s' % rpc_u,
                    '-mainchainrpcpassword=%s' % rpc_p,
                ])
            else:
                # Need to specify where to find parent cookie file
                datadir = get_datadir_path(self.options.tmpdir, n)
                extra_args.append('-mainchainrpccookiefile='+datadir+"/" + parent_chain + "/.cookie")

            self.add_nodes(1, [extra_args], chain=["sidechain"])
            self.start_node(2+n)
            print("Node {} started".format(2+n))

        # We only connect the same-chain nodes, so sync_all works correctly
        connect_nodes_bi(self.nodes, 2, 3)
        self.node_groups = [[self.nodes[0], self.nodes[1]], [self.nodes[2], self.nodes[3]]]
        self.sync_all(self.node_groups)
        print("Setting up network done")
Esempio n. 15
0
    def setup_network(self, split=False):
        if self.options.parent_bitcoin and self.options.parent_binpath == "":
            raise Exception(
                "Can't run with --parent_bitcoin without specifying --parent_binpath"
            )
        self.nodes = []
        self.extra_args = []
        # Parent chain args
        for n in range(2):
            # We want to test the rpc cookie method so we force the use of a
            # dummy conf file to avoid loading rpcuser/rpcpassword lines
            use_cookie_auth = n == 1
            rpc_u, rpc_p = rpc_auth_pair(n)
            if self.options.parent_bitcoin:
                self.parent_chain = 'regtest'
                self.extra_args.append([
                    "-conf=dummy",
                    "-printtoconsole=0",
                    "-addresstype=legacy",  # To make sure bitcoind gives back p2pkh no matter version
                    "-deprecatedrpc=validateaddress",
                    "-port=" + str(p2p_port(n)),
                    "-rpcport=" + str(rpc_port(n))
                ])
            else:
                self.parent_chain = 'parent'
                self.extra_args.append([
                    "-conf=dummy", "-printtoconsole=0", '-validatepegin=0',
                    '-anyonecanspendaremine',
                    '-initialfreecoins=2100000000000000',
                    "-port=" + str(p2p_port(n)), "-rpcport=" + str(rpc_port(n))
                ])
            # Only first parent uses name/password, the 2nd uses cookie auth
            if not use_cookie_auth:
                self.extra_args[n].extend(
                    ["-rpcuser="******"-rpcpassword="******"" else None
            self.nodes.append(
                start_node(n,
                           self.options.tmpdir,
                           self.extra_args[n],
                           binary=self.binary,
                           chain=self.parent_chain,
                           cookie_auth=use_cookie_auth))

        connect_nodes_bi(self.nodes, 0, 1)
        self.parentgenesisblockhash = self.nodes[0].getblockhash(0)
        print('parentgenesisblockhash', self.parentgenesisblockhash)
        if not self.options.parent_bitcoin:
            parent_pegged_asset = self.nodes[0].getsidechaininfo(
            )['pegged_asset']

        # Sidechain args
        self.fedpeg_script = "512103dff4923d778550cc13ce0d887d737553b4b58f4e8e886507fc39f5e447b2186451ae"
        parent_chain_signblockscript = '51'
        for n in range(2):
            used_cookie_auth = n == 1
            rpc_u, rpc_p = rpc_auth_pair(n)
            args = [
                "-printtoconsole=0",
                '-parentgenesisblockhash=%s' % self.parentgenesisblockhash,
                '-validatepegin=1',
                '-fedpegscript=%s' % self.fedpeg_script,
                '-anyonecanspendaremine=0',
                '-initialfreecoins=0',
                '-peginconfirmationdepth=10',
                '-mainchainrpchost=127.0.0.1',
                '-mainchainrpcport=%s' % rpc_port(n),
                '-recheckpeginblockinterval=15',  # Long enough to allow failure and repair before timeout
            ]
            if not self.options.parent_bitcoin:
                args.extend([
                    '-parentpubkeyprefix=235',
                    '-parentscriptprefix=75',
                    '-con_parent_chain_signblockscript=%s' %
                    parent_chain_signblockscript,
                    '-con_parent_pegged_asset=%s' % parent_pegged_asset,
                ])

            if used_cookie_auth:
                # Need to specify where to find parent cookie file
                datadir = os.path.join(self.options.tmpdir, "node" + str(n))
                args.append('-mainchainrpccookiefile=' + datadir + "/" +
                            self.parent_chain + "/.cookie")
            else:
                args.extend([
                    '-mainchainrpcuser=%s' % rpc_u,
                    '-mainchainrpcpassword=%s' % rpc_p,
                ])

            self.extra_args.append(args)
            self.nodes.append(
                start_node(n + 2,
                           self.options.tmpdir,
                           self.extra_args[n + 2],
                           chain='sidechain'))

        # We only connect the same-chain nodes, so sync_all works correctly
        connect_nodes_bi(self.nodes, 2, 3)
        self.is_network_split = True
        self.sync_all()