def test_shard_genesis_fork_fork(self):
    ' Test shard forks at genesis blocks due to root chain fork at GENESIS.ROOT_HEIGHT'
    acc1 = Address.create_random_account(0)
    acc2 = Address.create_random_account(1)
    genesis_root_heights = {2: 0, 3: 1}
    with ClusterContext(2, acc1, chain_size=1, shard_size=2, genesis_root_heights=genesis_root_heights) as clusters:
        clusters[1].peer.close()
        master0 = clusters[0].master
        root0 = call_async(master0.get_next_block_to_mine(acc1, branch_value=None))
        call_async(master0.add_root_block(root0))
        genesis0 = clusters[0].get_shard_state((2 | 1)).db.get_minor_block_by_height(0)
        self.assertEqual(genesis0.header.hash_prev_root_block, root0.header.get_hash())
        master1 = clusters[1].master
        root1 = call_async(master1.get_next_block_to_mine(acc2, branch_value=None))
        self.assertNotEqual(root0.header.get_hash(), root1.header.get_hash())
        call_async(master1.add_root_block(root1))
        genesis1 = clusters[1].get_shard_state((2 | 1)).db.get_minor_block_by_height(0)
        self.assertEqual(genesis1.header.hash_prev_root_block, root1.header.get_hash())
        self.assertNotEqual(genesis0.header.get_hash(), genesis1.header.get_hash())
        root2 = call_async(master1.get_next_block_to_mine(acc2, branch_value=None))
        call_async(master1.add_root_block(root2))
        self.assertEqual(master1.root_state.tip.height, 2)
        call_async(clusters[1].network.connect('127.0.0.1', clusters[0].master.env.cluster_config.SIMPLE_NETWORK.BOOTSTRAP_PORT))
        assert_true_with_timeout((lambda : (clusters[0].get_shard_state((2 | 1)).db.get_minor_block_by_height(0).header.get_hash() == genesis1.header.get_hash())))
        self.assertTrue((clusters[0].get_shard_state((2 | 1)).root_tip == root2.header))
Test shard forks at genesis blocks due to root chain fork at GENESIS.ROOT_HEIGHT
def test_shard_genesis_fork_fork(self):
    ' '
    acc1 = Address.create_random_account(0)
    acc2 = Address.create_random_account(1)
    genesis_root_heights = {2: 0, 3: 1}
    with ClusterContext(2, acc1, chain_size=1, shard_size=2, genesis_root_heights=genesis_root_heights) as clusters:
        clusters[1].peer.close()
        master0 = clusters[0].master
        root0 = call_async(master0.get_next_block_to_mine(acc1, branch_value=None))
        call_async(master0.add_root_block(root0))
        genesis0 = clusters[0].get_shard_state((2 | 1)).db.get_minor_block_by_height(0)
        self.assertEqual(genesis0.header.hash_prev_root_block, root0.header.get_hash())
        master1 = clusters[1].master
        root1 = call_async(master1.get_next_block_to_mine(acc2, branch_value=None))
        self.assertNotEqual(root0.header.get_hash(), root1.header.get_hash())
        call_async(master1.add_root_block(root1))
        genesis1 = clusters[1].get_shard_state((2 | 1)).db.get_minor_block_by_height(0)
        self.assertEqual(genesis1.header.hash_prev_root_block, root1.header.get_hash())
        self.assertNotEqual(genesis0.header.get_hash(), genesis1.header.get_hash())
        root2 = call_async(master1.get_next_block_to_mine(acc2, branch_value=None))
        call_async(master1.add_root_block(root2))
        self.assertEqual(master1.root_state.tip.height, 2)
        call_async(clusters[1].network.connect('127.0.0.1', clusters[0].master.env.cluster_config.SIMPLE_NETWORK.BOOTSTRAP_PORT))
        assert_true_with_timeout((lambda : (clusters[0].get_shard_state((2 | 1)).db.get_minor_block_by_height(0).header.get_hash() == genesis1.header.get_hash())))
        self.assertTrue((clusters[0].get_shard_state((2 | 1)).root_tip == root2.header))