def test_add_transaction(self):
    id1 = Identity.create_random_identity()
    acc1 = Address.create_from_identity(id1, full_shard_key=0)
    acc2 = Address.create_from_identity(id1, full_shard_key=1)
    with ClusterContext(2, acc1) as clusters:
        master = clusters[0].master
        root = call_async(master.get_next_block_to_mine(acc1, branch_value=None))
        call_async(master.add_root_block(root))
        tx1 = create_transfer_transaction(shard_state=clusters[0].get_shard_state(2), key=id1.get_key(), from_address=acc1, to_address=acc1, value=12345)
        self.assertTrue(call_async(master.add_transaction(tx1)))
        self.assertEqual(len(clusters[0].get_shard_state(2).tx_queue), 1)
        tx2 = create_transfer_transaction(shard_state=clusters[0].get_shard_state(3), key=id1.get_key(), from_address=acc2, to_address=acc1, value=12345, gas=30000)
        self.assertTrue(call_async(master.add_transaction(tx2)))
        self.assertEqual(len(clusters[0].get_shard_state(3).tx_queue), 1)
        tx_queue = clusters[1].get_shard_state(2).tx_queue
        assert_true_with_timeout((lambda : (len(tx_queue) == 1)))
        self.assertEqual(tx_queue.pop_transaction(), tx1.tx.to_evm_tx())
        tx_queue = clusters[1].get_shard_state(3).tx_queue
        assert_true_with_timeout((lambda : (len(tx_queue) == 1)))
        self.assertEqual(tx_queue.pop_transaction(), tx2.tx.to_evm_tx())
def test_add_transaction(self):
    id1 = Identity.create_random_identity()
    acc1 = Address.create_from_identity(id1, full_shard_key=0)
    acc2 = Address.create_from_identity(id1, full_shard_key=1)
    with ClusterContext(2, acc1) as clusters:
        master = clusters[0].master
        root = call_async(master.get_next_block_to_mine(acc1, branch_value=None))
        call_async(master.add_root_block(root))
        tx1 = create_transfer_transaction(shard_state=clusters[0].get_shard_state(2), key=id1.get_key(), from_address=acc1, to_address=acc1, value=12345)
        self.assertTrue(call_async(master.add_transaction(tx1)))
        self.assertEqual(len(clusters[0].get_shard_state(2).tx_queue), 1)
        tx2 = create_transfer_transaction(shard_state=clusters[0].get_shard_state(3), key=id1.get_key(), from_address=acc2, to_address=acc1, value=12345, gas=30000)
        self.assertTrue(call_async(master.add_transaction(tx2)))
        self.assertEqual(len(clusters[0].get_shard_state(3).tx_queue), 1)
        tx_queue = clusters[1].get_shard_state(2).tx_queue
        assert_true_with_timeout((lambda : (len(tx_queue) == 1)))
        self.assertEqual(tx_queue.pop_transaction(), tx1.tx.to_evm_tx())
        tx_queue = clusters[1].get_shard_state(3).tx_queue
        assert_true_with_timeout((lambda : (len(tx_queue) == 1)))
        self.assertEqual(tx_queue.pop_transaction(), tx2.tx.to_evm_tx())