示例#1
0
    def test_graph_communication_error(self):
        #          -------PEER IDS------
        #   NUM    0    1    2    3    4
        good_chains_info = [
            (8, ['d', 'd', 'i', 'i', 'p']),
            (7, ['c', 'c', 'c', 'c', 'o']),
        ]
        bad_chains_info = [
            (6, ['b', 'b', '', 'b', 'n']),
            (5, ['a', 'a', '', 'a', '']),
            (4, ['0', '0', '', '0', '']),
        ]
        good_chains = make_chains(good_chains_info)
        bad_chains = make_chains(bad_chains_info)

        tails, _ = get_tails(good_chains)
        graph, errors = build_fork_graph(bad_chains, tails)
        self.assertEqual(errors, [2, 4])

        node_id_map = get_node_id_map(errors, len(good_chains))
        tails = list(map(
            lambda item: item[1],
            filter(
                lambda item: item[0] not in errors,
                sorted(tails.items()))))
        print_summary(graph, tails, node_id_map)
 def do_test_compare_print_summary():
     chains = NetworkCommandUtils.make_chains(CHAIN_INFO)
     tails, _ = get_tails(chains)
     graph, _ = build_fork_graph(chains, tails)
     node_id_map = get_node_id_map([], len(tails))
     tails = list(map(lambda item: item[1], sorted(tails.items())))
     print_summary(graph=graph, tails=tails, node_id_map=node_id_map)
示例#3
0
    def test_graph_communication_error(self):
        #          -------PEER IDS------
        #   NUM    0    1    2    3    4
        good_chains_info = [
            (8, ['d', 'd', 'i', 'i', 'p']),
            (7, ['c', 'c', 'c', 'c', 'o']),
        ]
        bad_chains_info = [
            (6, ['b', 'b', '', 'b', 'n']),
            (5, ['a', 'a', '', 'a', '']),
            (4, ['0', '0', '', '0', '']),
        ]
        good_chains = make_chains(good_chains_info)
        bad_chains = make_chains(bad_chains_info)

        tails, _ = get_tails(good_chains)
        graph, errors = build_fork_graph(bad_chains, tails)
        self.assertEqual(errors, [2, 4])

        node_id_map = get_node_id_map(errors, len(good_chains))
        tails = list(
            map(
                lambda item: item[1],
                filter(lambda item: item[0] not in errors,
                       sorted(tails.items()))))
        print_summary(graph, tails, node_id_map)
示例#4
0
    def test_tails_communication_error(self):
        #          -------PEER IDS------
        #   NUM    0    1    2    3    4
        chains_info = [
            (15, ['z', '', '', '', '']),
            (14, ['y', '', '', '', '']),
            (13, ['w', '', 'x', '', '']),
            (12, ['t', '', 'u', '', 'v']),
            (11, ['g', '', 'l', '', 's']),
        ]
        chains = make_chains(chains_info)

        tails, errors = get_tails(chains)
        for _, tail in tails.items():
            self.assertEqual(tail[0].num, 12)
        self.assertEqual(errors, [1, 3])
示例#5
0
    def test_tails_communication_error(self):
        #          -------PEER IDS------
        #   NUM    0    1    2    3    4
        chains_info = [
            (15, ['z', '', '', '', '']),
            (14, ['y', '', '', '', '']),
            (13, ['w', '', 'x', '', '']),
            (12, ['t', '', 'u', '', 'v']),
            (11, ['g', '', 'l', '', 's']),
        ]
        chains = make_chains(chains_info)

        tails, errors = get_tails(chains)
        for _, tail in tails.items():
            self.assertEqual(tail[0].num, 12)
        self.assertEqual(errors, [1, 3])
示例#6
0
    def test_simple_graph(self):
        """Test that building the fork graph works correctly for a simple
        network state."""

        chains = [
            make_generator(chain) for chain in (
                [SimpleBlock(19, '19', '18')],
                [SimpleBlock(19, '19', '18')],
                [SimpleBlock(19, '19', '18')],
            )
        ]

        tails = get_tails(chains)
        graph = build_fork_graph(chains, tails)

        self.assertEqual(graph.root.previous, '18')
        self.assertEqual(graph.root.ident, '19')
示例#7
0
    def test_simple_graph(self):
        """Test that building the fork graph works correctly for a simple
        network state."""

        chains = {
            i: make_generator(chain)
            for i, chain in enumerate((
                [SimpleBlock(19, '19', '18')],
                [SimpleBlock(19, '19', '18')],
                [SimpleBlock(19, '19', '18')],
            ))
        }

        tails, _ = get_tails(chains)
        graph, _ = build_fork_graph(chains, tails)

        self.assertEqual(graph.root.previous, '18')
        self.assertEqual(graph.root.ident, '19')
    def do_test_compare_build_fork_graph():
        good_chains_info = [
            (8, ['d', 'd', 'i', 'i', 'p']),
            (7, ['c', 'c', 'c', 'c', 'o']),
        ]

        bad_chains_info = [
            (6, ['b', 'b', '', 'b', 'n']),
            (5, ['a', 'a', '', 'a', '']),
            (4, ['0', '0', '', '0', '']),
        ]

        good_chains = NetworkCommandUtils.make_chains(good_chains_info)
        bad_chains = NetworkCommandUtils.make_chains(bad_chains_info)
        tails, _ = get_tails(good_chains)
        try:
            build_fork_graph(chains=bad_chains, tails=tails)
        except Exception as e:
            print("type error: " + str(e))
示例#9
0
    def test_complex_graph(self):
        """Test that building the fork graph works correctly for a complex
        network state."""

        #          -------PEER IDS------
        #   NUM    0    1    2    3    4
        chains_info = [
            (15, ['z', '', '', '', '']),
            (14, ['y', '', '', '', '']),
            (13, ['w', '', 'x', '', '']),
            (12, ['t', '', 'u', '', 'v']),
            (11, ['g', 'h', 'l', 'm', 's']),
            (10, ['f', 'f', 'k', 'k', 'r']),
            (9, ['e', 'e', 'j', 'j', 'q']),
            (8, ['d', 'd', 'i', 'i', 'p']),
            (7, ['c', 'c', 'c', 'c', 'o']),
            (6, ['b', 'b', 'b', 'b', 'n']),
            (5, ['a', 'a', 'a', 'a', 'a']),
            (4, ['0', '0', '0', '0', '0']),
        ]

        chains = make_chains(chains_info)

        tails, _ = get_tails(chains)
        for tail in tails.values():
            self.assertEqual(tail[0].num, 11)

        graph, _ = build_fork_graph(chains, tails)
        self.assertEqual(graph.root.previous, '0')
        self.assertEqual(graph.root.ident, 'a')

        # How many checks should happen
        expected_checks = sum(map(
            lambda ci: sum(map(
                lambda bi: 0 if bi in ('', '0') else 1, ci[1]
            )),
            chains_info))

        checks = []

        for block_num, _, siblings in graph.walk():
            expected = chains_info[-(block_num - 3)]
            # Make sure we did the math right in this test
            assert expected[0] == block_num
            expected = expected[1]

            # `expected` contains a list of block ids, where the index is the
            # peer and the at that index is the block that peer should have
            for block_id, nodes in siblings.items():
                # Make sure none of the null strings were added
                self.assertNotEqual(block_id, '')

                for node in nodes:
                    self.assertEqual(block_id, expected[node])
                    checks.append(block_id)

        self.assertEqual(len(checks), expected_checks)

        node_id_map = get_node_id_map([], len(tails))
        tails = list(map(lambda item: item[1], sorted(tails.items())))

        print_table(graph, tails, node_id_map)
        print()

        print_tree(graph, tails, node_id_map)
        print()
示例#10
0
    def test_complex_graph(self):
        """Test that building the fork graph works correctly for a complex
        network state."""

        #          -------PEER IDS------
        #   NUM    0    1    2    3    4
        chains_info = [
            (15, ['z', '', '', '', '']),
            (14, ['y', '', '', '', '']),
            (13, ['w', '', 'x', '', '']),
            (12, ['t', '', 'u', '', 'v']),
            (11, ['g', 'h', 'l', 'm', 's']),
            (10, ['f', 'f', 'k', 'k', 'r']),
            (9, ['e', 'e', 'j', 'j', 'q']),
            (8, ['d', 'd', 'i', 'i', 'p']),
            (7, ['c', 'c', 'c', 'c', 'o']),
            (6, ['b', 'b', 'b', 'b', 'n']),
            (5, ['a', 'a', 'a', 'a', 'a']),
            (4, ['0', '0', '0', '0', '0']),
        ]

        chains = make_chains(chains_info)

        tails, _ = get_tails(chains)
        for tail in tails.values():
            self.assertEqual(tail[0].num, 11)

        graph, _ = build_fork_graph(chains, tails)
        self.assertEqual(graph.root.previous, '0')
        self.assertEqual(graph.root.ident, 'a')

        # How many checks should happen
        expected_checks = sum(
            map(
                lambda ci: sum(
                    map(lambda bi: 0
                        if bi in ('', '0') else 1, ci[1])), chains_info))

        checks = []

        for block_num, _, siblings in graph.walk():
            expected = chains_info[-(block_num - 3)]
            # Make sure we did the math right in this test
            assert expected[0] == block_num
            expected = expected[1]

            # `expected` contains a list of block ids, where the index is the
            # peer and the at that index is the block that peer should have
            for block_id, nodes in siblings.items():
                # Make sure none of the null strings were added
                self.assertNotEqual(block_id, '')

                for node in nodes:
                    self.assertEqual(block_id, expected[node])
                    checks.append(block_id)

        self.assertEqual(len(checks), expected_checks)

        node_id_map = get_node_id_map([], len(tails))
        tails = list(map(lambda item: item[1], sorted(tails.items())))

        print_table(graph, tails, node_id_map)
        print()

        print_tree(graph, tails, node_id_map)
        print()
 def do_test_compare_get_tails():
     chains = NetworkCommandUtils.make_chains(CHAIN_INFO)
     try:
         get_tails(chains=chains)
     except Exception as e:
         print("type error: " + str(e))
示例#12
0
    def test_complex_graph(self):
        """Test that building the fork graph works correctly for a complex
        network state."""

        #          -------PEER IDS------
        #   NUM    0    1    2    3    4
        chains_info = [
            (15, ['z', '', '', '', '']),
            (14, ['y', '', '', '', '']),
            (13, ['w', '', 'x', '', '']),
            (12, ['t', '', 'u', '', 'v']),
            (11, ['g', 'h', 'l', 'm', 's']),
            (10, ['f', 'f', 'k', 'k', 'r']),
            (9, ['e', 'e', 'j', 'j', 'q']),
            (8, ['d', 'd', 'i', 'i', 'p']),
            (7, ['c', 'c', 'c', 'c', 'o']),
            (6, ['b', 'b', 'b', 'b', 'n']),
            (5, ['a', 'a', 'a', 'a', 'a']),
            (4, ['0', '0', '0', '0', '0']),
        ]

        # Build chain generators
        chains = [[] for _ in chains_info[0][1]]
        for i, num_ids in enumerate(chains_info[:-1]):
            num, ids = num_ids
            for j, ident in enumerate(ids):
                if ident != '':
                    next_chain_info = chains_info[i + 1]
                    previous = next_chain_info[1][j]
                    block = SimpleBlock(num, ident, previous)
                    chains[j].append(block)

        chains = [make_generator(chain) for chain in chains]

        tails = get_tails(chains)
        for tail in tails:
            self.assertEqual(tail[0].num, 11)

        graph = build_fork_graph(chains, tails)
        self.assertEqual(graph.root.previous, '0')
        self.assertEqual(graph.root.ident, 'a')

        # How many checks should happen
        expected_checks = sum(
            map(
                lambda ci: sum(
                    map(lambda bi: 0 if
                        (bi == '' or bi == '0') else 1, ci[1])), chains_info))

        checks = []

        for block_num, _, siblings in graph.walk():
            expected = chains_info[-(block_num - 3)]
            # Make sure we did the math right in this test
            assert expected[0] == block_num
            expected = expected[1]

            # `expected` contains a list of block ids, where the index is the
            # peer and the at that index is the block that peer should have
            for block_id, nodes in siblings.items():
                # Make sure none of the null strings were added
                self.assertNotEqual(block_id, '')

                for node in nodes:
                    self.assertEqual(block_id, expected[node])
                    checks.append(block_id)

        self.assertEqual(len(checks), expected_checks)

        node_id_map = get_node_id_map([], len(tails))

        print_table(graph, tails, node_id_map)
        print()

        print_tree(graph, tails, node_id_map)
        print()