def test_add_root_block_request_list(self):
    id1 = Identity.create_random_identity()
    acc1 = Address.create_from_identity(id1, full_shard_key=0)
    with ClusterContext(2, acc1) as clusters:
        clusters[1].peer.close()
        block_header_list = [clusters[0].get_shard_state((2 | 0)).header_tip]
        shard_state0 = clusters[0].get_shard_state(2)
        for i in range(7):
            b1 = _tip_gen(shard_state0)
            add_result = call_async(clusters[0].master.add_raw_minor_block(b1.header.branch, b1.serialize()))
            self.assertTrue(add_result)
            block_header_list.append(b1.header)
        block_header_list.append(clusters[0].get_shard_state((2 | 1)).header_tip)
        shard_state0 = clusters[0].get_shard_state(3)
        b2 = _tip_gen(shard_state0)
        add_result = call_async(clusters[0].master.add_raw_minor_block(b2.header.branch, b2.serialize()))
        self.assertTrue(add_result)
        block_header_list.append(b2.header)
        shard_state1 = clusters[1].get_shard_state(3)
        b3 = _tip_gen(shard_state1)
        add_result = call_async(clusters[1].master.add_raw_minor_block(b3.header.branch, b3.serialize()))
        self.assertTrue(add_result)
        self.assertEqual(clusters[1].get_shard_state(3).header_tip, b3.header)
        call_async(clusters[1].network.connect('127.0.0.1', clusters[0].master.env.cluster_config.SIMPLE_NETWORK.BOOTSTRAP_PORT))
        root_block1 = clusters[0].master.root_state.create_block_to_mine(block_header_list, acc1)
        call_async(clusters[0].master.add_root_block(root_block1))
        self.assertEqual(clusters[0].master.root_state.tip, root_block1.header)
        assert_true_with_timeout((lambda : (clusters[1].master.root_state.tip == root_block1.header)), 2)
        self.assertEqual(b1.header.height, 7)
        assert_true_with_timeout((lambda : (clusters[1].get_shard_state(2).header_tip == b1.header)))
        assert_true_with_timeout((lambda : (clusters[1].get_shard_state(3).header_tip == b2.header)))
def test_add_root_block_request_list(self):
    id1 = Identity.create_random_identity()
    acc1 = Address.create_from_identity(id1, full_shard_key=0)
    with ClusterContext(2, acc1) as clusters:
        clusters[1].peer.close()
        block_header_list = [clusters[0].get_shard_state((2 | 0)).header_tip]
        shard_state0 = clusters[0].get_shard_state(2)
        for i in range(7):
            b1 = _tip_gen(shard_state0)
            add_result = call_async(clusters[0].master.add_raw_minor_block(b1.header.branch, b1.serialize()))
            self.assertTrue(add_result)
            block_header_list.append(b1.header)
        block_header_list.append(clusters[0].get_shard_state((2 | 1)).header_tip)
        shard_state0 = clusters[0].get_shard_state(3)
        b2 = _tip_gen(shard_state0)
        add_result = call_async(clusters[0].master.add_raw_minor_block(b2.header.branch, b2.serialize()))
        self.assertTrue(add_result)
        block_header_list.append(b2.header)
        shard_state1 = clusters[1].get_shard_state(3)
        b3 = _tip_gen(shard_state1)
        add_result = call_async(clusters[1].master.add_raw_minor_block(b3.header.branch, b3.serialize()))
        self.assertTrue(add_result)
        self.assertEqual(clusters[1].get_shard_state(3).header_tip, b3.header)
        call_async(clusters[1].network.connect('127.0.0.1', clusters[0].master.env.cluster_config.SIMPLE_NETWORK.BOOTSTRAP_PORT))
        root_block1 = clusters[0].master.root_state.create_block_to_mine(block_header_list, acc1)
        call_async(clusters[0].master.add_root_block(root_block1))
        self.assertEqual(clusters[0].master.root_state.tip, root_block1.header)
        assert_true_with_timeout((lambda : (clusters[1].master.root_state.tip == root_block1.header)), 2)
        self.assertEqual(b1.header.height, 7)
        assert_true_with_timeout((lambda : (clusters[1].get_shard_state(2).header_tip == b1.header)))
        assert_true_with_timeout((lambda : (clusters[1].get_shard_state(3).header_tip == b2.header)))