예제 #1
0
 async def test_no_transaction_to_commit(self):
     request = await self.client.post(
         '/transactions/commit',
         data=bank_pb2.CommitTransactionRequest(
             transaction_id=666).SerializeToString())
     await self.check_error(
         request, error='bank.commit_transaction.no_transacton_to_commit')
예제 #2
0
    async def apply_operations(self, test_operations):
        request = await self.client.post('/transactions/start',
                                         data=bank_pb2.StartTransactionRequest(
                                             operations=test_operations,
                                             lifetime=0).SerializeToString())
        answer = await self.check_success(request,
                                          bank_pb2.StartTransactionResponse)

        await self.client.post(
            '/transactions/commit',
            data=bank_pb2.CommitTransactionRequest(
                transaction_id=answer.transaction_id).SerializeToString())
예제 #3
0
    async def test_commit(self):
        await helpers.call_change_balance(account_id=666,
                                          currency=1,
                                          amount=1000)
        await helpers.call_change_balance(account_id=667,
                                          currency=1,
                                          amount=1000)

        lifetime = datetime.timedelta(seconds=100)

        request = await self.client.post('/transactions/start',
                                         data=bank_pb2.StartTransactionRequest(
                                             operations=TEST_OPERATIONS,
                                             lifetime=100).SerializeToString())
        answer = await self.check_success(request,
                                          bank_pb2.StartTransactionResponse)

        request = await self.client.post(
            '/transactions/commit',
            data=bank_pb2.CommitTransactionRequest(
                transaction_id=answer.transaction_id).SerializeToString())
        answer = await self.check_success(request,
                                          bank_pb2.CommitTransactionResponse)

        results = await db.sql('SELECT * FROM transactions')

        self.assertEqual(results[0]['state'],
                         relations.TRANSACTION_STATE.COMMITED.value)
        self.assertEqual(results[0]['lifetime'], lifetime)

        loaded_operations = await load_operations()
        self.assertEqual(TEST_OPERATIONS, loaded_operations)

        # only withdraws applied on transaction start
        await self.check_balance(account_id=666, expected_balance={1: 500})
        await self.check_balance(account_id=667, expected_balance={1: 1200})
예제 #4
0
def commit_transaction(transaction_id):
    tt_api.async_request(url=conf.game_settings.TT_ENERGY_COMMIT_TRANSACTION,
                         data=bank_pb2.CommitTransactionRequest(transaction_id=transaction_id))