def test_broadcast_cross_shard_transactions(self):
    ' Test the cross shard transactions are broadcasted to the destination shards '
    id1 = Identity.create_random_identity()
    acc1 = Address.create_from_identity(id1, full_shard_key=0)
    acc3 = Address.create_random_account(full_shard_key=1)
    with ClusterContext(1, acc1) as clusters:
        master = clusters[0].master
        slaves = clusters[0].slave_list
        genesis_token = clusters[0].get_shard_state((2 | 0)).env.quark_chain_config.genesis_token
        root_block = call_async(master.get_next_block_to_mine(Address.create_empty_account(), branch_value=None))
        call_async(master.add_root_block(root_block))
        tx1 = create_transfer_transaction(shard_state=clusters[0].get_shard_state((2 | 0)), key=id1.get_key(), from_address=acc1, to_address=acc3, value=54321, gas=(opcodes.GTXXSHARDCOST + opcodes.GTXCOST))
        self.assertTrue(slaves[0].add_tx(tx1))
        b1 = clusters[0].get_shard_state((2 | 0)).create_block_to_mine(address=acc1)
        b2 = clusters[0].get_shard_state((2 | 0)).create_block_to_mine(address=acc1)
        b2.header.create_time += 1
        self.assertNotEqual(b1.header.get_hash(), b2.header.get_hash())
        call_async(clusters[0].get_shard((2 | 0)).add_block(b1))
        xshard_tx_list = clusters[0].get_shard_state((2 | 1)).db.get_minor_block_xshard_tx_list(b1.header.get_hash())
        self.assertEqual(len(xshard_tx_list.tx_list), 1)
        self.assertEqual(xshard_tx_list.tx_list[0].tx_hash, tx1.get_hash())
        self.assertEqual(xshard_tx_list.tx_list[0].from_address, acc1)
        self.assertEqual(xshard_tx_list.tx_list[0].to_address, acc3)
        self.assertEqual(xshard_tx_list.tx_list[0].value, 54321)
        call_async(clusters[0].get_shard((2 | 0)).add_block(b2))
        self.assertEqual(clusters[0].get_shard_state((2 | 0)).header_tip, b1.header)
        xshard_tx_list = clusters[0].get_shard_state((2 | 1)).db.get_minor_block_xshard_tx_list(b2.header.get_hash())
        self.assertEqual(len(xshard_tx_list.tx_list), 1)
        self.assertEqual(xshard_tx_list.tx_list[0].tx_hash, tx1.get_hash())
        self.assertEqual(xshard_tx_list.tx_list[0].from_address, acc1)
        self.assertEqual(xshard_tx_list.tx_list[0].to_address, acc3)
        self.assertEqual(xshard_tx_list.tx_list[0].value, 54321)
        b3 = clusters[0].get_shard_state((2 | 1)).create_block_to_mine(address=acc1.address_in_shard(1))
        call_async(master.add_raw_minor_block(b3.header.branch, b3.serialize()))
        root_block = call_async(master.get_next_block_to_mine(address=acc1, branch_value=None))
        call_async(master.add_root_block(root_block))
        b4 = clusters[0].get_shard_state((2 | 1)).create_block_to_mine(address=acc1.address_in_shard(1))
        self.assertTrue(call_async(master.add_raw_minor_block(b1.header.branch, b1.serialize())))
        self.assertTrue(call_async(master.add_raw_minor_block(b2.header.branch, b2.serialize())))
        self.assertTrue(call_async(master.add_raw_minor_block(b3.header.branch, b3.serialize())))
        self.assertTrue(call_async(master.add_raw_minor_block(b4.header.branch, b4.serialize())))
        self.assertEqual(call_async(master.get_primary_account_data(acc3)).token_balances.balance_map, {genesis_token: 54321})
Test the cross shard transactions are broadcasted to the destination shards
def test_broadcast_cross_shard_transactions(self):
    '  '
    id1 = Identity.create_random_identity()
    acc1 = Address.create_from_identity(id1, full_shard_key=0)
    acc3 = Address.create_random_account(full_shard_key=1)
    with ClusterContext(1, acc1) as clusters:
        master = clusters[0].master
        slaves = clusters[0].slave_list
        genesis_token = clusters[0].get_shard_state((2 | 0)).env.quark_chain_config.genesis_token
        root_block = call_async(master.get_next_block_to_mine(Address.create_empty_account(), branch_value=None))
        call_async(master.add_root_block(root_block))
        tx1 = create_transfer_transaction(shard_state=clusters[0].get_shard_state((2 | 0)), key=id1.get_key(), from_address=acc1, to_address=acc3, value=54321, gas=(opcodes.GTXXSHARDCOST + opcodes.GTXCOST))
        self.assertTrue(slaves[0].add_tx(tx1))
        b1 = clusters[0].get_shard_state((2 | 0)).create_block_to_mine(address=acc1)
        b2 = clusters[0].get_shard_state((2 | 0)).create_block_to_mine(address=acc1)
        b2.header.create_time += 1
        self.assertNotEqual(b1.header.get_hash(), b2.header.get_hash())
        call_async(clusters[0].get_shard((2 | 0)).add_block(b1))
        xshard_tx_list = clusters[0].get_shard_state((2 | 1)).db.get_minor_block_xshard_tx_list(b1.header.get_hash())
        self.assertEqual(len(xshard_tx_list.tx_list), 1)
        self.assertEqual(xshard_tx_list.tx_list[0].tx_hash, tx1.get_hash())
        self.assertEqual(xshard_tx_list.tx_list[0].from_address, acc1)
        self.assertEqual(xshard_tx_list.tx_list[0].to_address, acc3)
        self.assertEqual(xshard_tx_list.tx_list[0].value, 54321)
        call_async(clusters[0].get_shard((2 | 0)).add_block(b2))
        self.assertEqual(clusters[0].get_shard_state((2 | 0)).header_tip, b1.header)
        xshard_tx_list = clusters[0].get_shard_state((2 | 1)).db.get_minor_block_xshard_tx_list(b2.header.get_hash())
        self.assertEqual(len(xshard_tx_list.tx_list), 1)
        self.assertEqual(xshard_tx_list.tx_list[0].tx_hash, tx1.get_hash())
        self.assertEqual(xshard_tx_list.tx_list[0].from_address, acc1)
        self.assertEqual(xshard_tx_list.tx_list[0].to_address, acc3)
        self.assertEqual(xshard_tx_list.tx_list[0].value, 54321)
        b3 = clusters[0].get_shard_state((2 | 1)).create_block_to_mine(address=acc1.address_in_shard(1))
        call_async(master.add_raw_minor_block(b3.header.branch, b3.serialize()))
        root_block = call_async(master.get_next_block_to_mine(address=acc1, branch_value=None))
        call_async(master.add_root_block(root_block))
        b4 = clusters[0].get_shard_state((2 | 1)).create_block_to_mine(address=acc1.address_in_shard(1))
        self.assertTrue(call_async(master.add_raw_minor_block(b1.header.branch, b1.serialize())))
        self.assertTrue(call_async(master.add_raw_minor_block(b2.header.branch, b2.serialize())))
        self.assertTrue(call_async(master.add_raw_minor_block(b3.header.branch, b3.serialize())))
        self.assertTrue(call_async(master.add_raw_minor_block(b4.header.branch, b4.serialize())))
        self.assertEqual(call_async(master.get_primary_account_data(acc3)).token_balances.balance_map, {genesis_token: 54321})