def test_poll_pending_deposits_bad_integration( client, acc1_usd_deposit_transaction_factory, acc1_usd_withdrawal_transaction_factory, ): # execute_deposits() queries for pending deposits acc1_usd_deposit_transaction_factory() # integration returns withdraw transaction withdrawal_transaction = acc1_usd_withdrawal_transaction_factory() rdi.poll_pending_deposits = Mock(return_value=[withdrawal_transaction]) # error message is logged logger.error = Mock() Command.execute_deposits() logger.error.assert_called_with("Transaction not a deposit") # Change kind, add bad status withdrawal_transaction.kind = Transaction.KIND.deposit withdrawal_transaction.status = Transaction.STATUS.completed logger.error.reset_mock() Command.execute_deposits() logger.error.assert_called_with( f"Unexpected transaction status: {withdrawal_transaction.status}, expecting " f"{Transaction.STATUS.pending_user_transfer_start}")
def test_poll_pending_deposits_success(client, acc1_usd_deposit_transaction_factory): transaction = acc1_usd_deposit_transaction_factory() rdi.poll_pending_deposits = Mock(return_value=[transaction]) Command.execute_deposits() transaction.refresh_from_db() assert transaction.status == Transaction.STATUS.pending_anchor assert transaction.status_eta == 5
def test_poll_pending_deposits_bad_integration( client, acc1_usd_deposit_transaction_factory, acc1_usd_withdrawal_transaction_factory, ): # execute_deposits() queries for pending deposits acc1_usd_deposit_transaction_factory() # integration returns withdraw transaction withdrawal_transaction = acc1_usd_withdrawal_transaction_factory() rri.poll_pending_deposits = Mock(return_value=[withdrawal_transaction]) logger.error = Mock() with pytest.raises(CommandError): Command.execute_deposits()
def test_poll_pending_deposits_success(client, acc1_usd_deposit_transaction_factory): transaction_user = acc1_usd_deposit_transaction_factory() transaction_external = acc1_usd_deposit_transaction_factory() transaction_external.status = Transaction.STATUS.pending_external transaction_external.save() og_pending_deposits = rri.poll_pending_deposits rri.poll_pending_deposits = mock_poll_pending_deposits_success rdi.after_deposit = Mock() Command.execute_deposits() transaction_user.refresh_from_db() rdi.after_deposit.assert_called_once_with(transaction_user) rri.poll_pending_deposits = og_pending_deposits
def test_poll_pending_deposits_success(client, acc1_usd_deposit_transaction_factory): transaction_user = acc1_usd_deposit_transaction_factory() transaction_external = acc1_usd_deposit_transaction_factory() transaction_external.status = Transaction.STATUS.pending_external transaction_external.save() og_pending_deposits = rri.poll_pending_deposits rri.poll_pending_deposits = mock_poll_pending_deposits_success rdi.after_deposit = Mock() Command.execute_deposits() transaction_user.refresh_from_db() assert transaction_user.status == Transaction.STATUS.pending_anchor assert transaction_user.status_eta == 5 assert rdi.after_deposit.was_called transaction_external.refresh_from_db() assert transaction_external.status == Transaction.STATUS.pending_external rri.poll_pending_deposits = og_pending_deposits
def test_poll_pending_deposits_bad_integration( client, acc1_usd_deposit_transaction_factory, acc1_usd_withdrawal_transaction_factory, ): # execute_deposits() queries for pending deposits acc1_usd_deposit_transaction_factory() # integration returns withdraw transaction withdrawal_transaction = acc1_usd_withdrawal_transaction_factory() withdrawal_transaction.asset.distribution_account_signers = json.dumps( mock_account.signers) withdrawal_transaction.asset.distribution_account_thresholds = json.dumps({ "low_threshold": mock_account.thresholds.low_threshold, "med_threshold": mock_account.thresholds.med_threshold, "high_threshold": mock_account.thresholds.high_threshold, }) withdrawal_transaction.asset.distribution_account_master_signer = json.dumps( mock_account.signers[0]) withdrawal_transaction.asset.save() rri.poll_pending_deposits = Mock(return_value=[withdrawal_transaction]) logger.error = Mock() Command.execute_deposits() # Change kind, add bad status withdrawal_transaction.kind = Transaction.KIND.deposit withdrawal_transaction.status = Transaction.STATUS.completed Command.execute_deposits() logger.error.assert_called_with( f"Unexpected transaction status: {withdrawal_transaction.status}, expecting " f"{Transaction.STATUS.pending_user_transfer_start} or {Transaction.STATUS.pending_anchor}." )
def test_poll_pending_deposits_success(client, acc1_usd_deposit_transaction_factory): transaction = acc1_usd_deposit_transaction_factory() transaction.asset.distribution_account_signers = json.dumps( mock_account.signers) transaction.asset.distribution_account_thresholds = json.dumps({ "low_threshold": mock_account.thresholds.low_threshold, "med_threshold": mock_account.thresholds.med_threshold, "high_threshold": mock_account.thresholds.high_threshold, }) transaction.asset.distribution_account_master_signer = json.dumps( mock_account.signers[0]) transaction.asset.save() rri.poll_pending_deposits = Mock(return_value=[transaction]) rdi.after_deposit = Mock() Command.execute_deposits() transaction.refresh_from_db() assert transaction.status == Transaction.STATUS.pending_anchor assert transaction.status_eta == 5 assert rdi.after_deposit.was_called assert rri.poll_pending_deposits.was_called