def test_handle_get_minor_block_list_request_with_total_diff(self):
    id1 = Identity.create_random_identity()
    acc1 = Address.create_from_identity(id1, full_shard_key=0)
    with ClusterContext(2, acc1) as clusters:
        cluster0_root_state = clusters[0].master.root_state
        cluster1_root_state = clusters[1].master.root_state
        coinbase = cluster1_root_state._calculate_root_block_coinbase([], 0)
        rb0 = cluster0_root_state.get_tip_block()
        rb1 = rb0.create_block_to_append(difficulty=int(1000000.0)).finalize(coinbase)
        call_async(clusters[1].network.connect('127.0.0.1', clusters[0].master.env.cluster_config.SIMPLE_NETWORK.BOOTSTRAP_PORT))
        call_async(clusters[0].master.add_root_block(rb1))
        self.assertEqual(cluster0_root_state.tip.get_hash(), rb1.header.get_hash())
        assert_true_with_timeout((lambda : (cluster1_root_state.tip == rb1.header)), 2)
        shard_state = clusters[1].get_shard_state(2)
        b1 = _tip_gen(shard_state)
        add_result = call_async(clusters[1].master.add_raw_minor_block(b1.header.branch, b1.serialize()))
        self.assertTrue(add_result)
        assert_true_with_timeout((lambda : clusters[1].get_shard_state(2).contain_block_by_hash(b1.header.get_hash())))
        assert_true_with_timeout((lambda : clusters[0].master.root_state.db.contain_minor_block_by_hash(b1.header.get_hash())))
        rb2 = rb0.create_block_to_append(difficulty=int(3000000.0)).finalize(coinbase)
        call_async(clusters[1].master.add_root_block(rb2))
        self.assertEqual(cluster1_root_state.tip.get_hash(), rb2.header.get_hash())
        b2 = _tip_gen(shard_state)
        add_result = call_async(clusters[1].master.add_raw_minor_block(b2.header.branch, b2.serialize()))
        self.assertTrue(add_result)
        assert_true_with_timeout((lambda : clusters[1].get_shard_state(2).contain_block_by_hash(b2.header.get_hash())))
        assert_true_with_timeout((lambda : clusters[0].master.root_state.db.contain_minor_block_by_hash(b2.header.get_hash())))
def test_handle_get_minor_block_list_request_with_total_diff(self):
    id1 = Identity.create_random_identity()
    acc1 = Address.create_from_identity(id1, full_shard_key=0)
    with ClusterContext(2, acc1) as clusters:
        cluster0_root_state = clusters[0].master.root_state
        cluster1_root_state = clusters[1].master.root_state
        coinbase = cluster1_root_state._calculate_root_block_coinbase([], 0)
        rb0 = cluster0_root_state.get_tip_block()
        rb1 = rb0.create_block_to_append(difficulty=int(1000000.0)).finalize(coinbase)
        call_async(clusters[1].network.connect('127.0.0.1', clusters[0].master.env.cluster_config.SIMPLE_NETWORK.BOOTSTRAP_PORT))
        call_async(clusters[0].master.add_root_block(rb1))
        self.assertEqual(cluster0_root_state.tip.get_hash(), rb1.header.get_hash())
        assert_true_with_timeout((lambda : (cluster1_root_state.tip == rb1.header)), 2)
        shard_state = clusters[1].get_shard_state(2)
        b1 = _tip_gen(shard_state)
        add_result = call_async(clusters[1].master.add_raw_minor_block(b1.header.branch, b1.serialize()))
        self.assertTrue(add_result)
        assert_true_with_timeout((lambda : clusters[1].get_shard_state(2).contain_block_by_hash(b1.header.get_hash())))
        assert_true_with_timeout((lambda : clusters[0].master.root_state.db.contain_minor_block_by_hash(b1.header.get_hash())))
        rb2 = rb0.create_block_to_append(difficulty=int(3000000.0)).finalize(coinbase)
        call_async(clusters[1].master.add_root_block(rb2))
        self.assertEqual(cluster1_root_state.tip.get_hash(), rb2.header.get_hash())
        b2 = _tip_gen(shard_state)
        add_result = call_async(clusters[1].master.add_raw_minor_block(b2.header.branch, b2.serialize()))
        self.assertTrue(add_result)
        assert_true_with_timeout((lambda : clusters[1].get_shard_state(2).contain_block_by_hash(b2.header.get_hash())))
        assert_true_with_timeout((lambda : clusters[0].master.root_state.db.contain_minor_block_by_hash(b2.header.get_hash())))