def finalize_deposit_claim( subtask_id: str, concent_use_case: ConcentUseCase, ethereum_address: str, ) -> None: deposit_claim: DepositClaim = get_one_or_none( # type: ignore DepositClaim, subtask_id=subtask_id, concent_use_case=concent_use_case, payer_deposit_account__ethereum_address=ethereum_address, ) if deposit_claim is not None: bankster.finalize_payment(deposit_claim)
def test_that_when_there_are_other_deposit_claims_finalize_payment_substract_them_from_currently_processed_claim( self): newest_deposit_claim, newest_task_to_compute = self.create_n_deposits_with_subtasks( 2) (v, r, s) = newest_task_to_compute.promissory_note_sig with mock.patch('core.payments.service.get_deposit_value', return_value=5) as get_deposit_value: with mock.patch('core.payments.service.force_subtask_payment', return_value=MOCK_TRANSACTION_HASH ) as force_subtask_payment: returned_value = finalize_payment(newest_deposit_claim) self.assertEqual(returned_value, MOCK_TRANSACTION_HASH) get_deposit_value.assert_called_with( client_eth_address=newest_deposit_claim.payer_deposit_account. ethereum_address, ) force_subtask_payment.assert_called_once_with( requestor_eth_address=newest_deposit_claim.payer_deposit_account. ethereum_address, provider_eth_address=newest_deposit_claim.payee_ethereum_address, value=newest_task_to_compute.price, subtask_id=newest_deposit_claim.subtask_id, v=v, r=r, s=s, # 5 - (2 + 2) | deposit_value - sum_of_other_claims reimburse_amount=1, )
def test_that_when_deposit_claim_is_for_additional_verification_use_case_finalize_payment_should_call_cover_additional_verification_cost( self): self.deposit_claim.concent_use_case = ConcentUseCase.ADDITIONAL_VERIFICATION self.deposit_claim.clean() self.deposit_claim.save() (v, r, s) = self.task_to_compute.promissory_note_sig with mock.patch('core.payments.service.get_deposit_value', return_value=2) as get_deposit_value: with mock.patch('core.payments.service.force_subtask_payment', return_value=MOCK_TRANSACTION_HASH ) as force_subtask_payment: returned_value = finalize_payment(self.deposit_claim) self.assertEqual(returned_value, MOCK_TRANSACTION_HASH) get_deposit_value.assert_called_with( client_eth_address=self.deposit_claim.payer_deposit_account. ethereum_address, ) force_subtask_payment.assert_called_once_with( requestor_eth_address=self.deposit_claim.payer_deposit_account. ethereum_address, provider_eth_address=self.deposit_claim.payee_ethereum_address, value=self.task_to_compute.price, subtask_id=self.deposit_claim.subtask_id, v=v, r=r, s=s, reimburse_amount=self.deposit_claim.amount)
def test_that_when_there_are_other_deposit_claims_finalize_payment_substract_them_from_currently_processed_claim(self): self.deposit_claim = DepositClaim() self.deposit_claim.subtask_id = self._get_uuid('1') self.deposit_claim.payer_deposit_account = self.deposit_account self.deposit_claim.payee_ethereum_address = self.task_to_compute.provider_ethereum_address self.deposit_claim.concent_use_case = ConcentUseCase.FORCED_ACCEPTANCE self.deposit_claim.amount = 2 self.deposit_claim.clean() # Save twice because we want two claims. self.deposit_claim.save() self.deposit_claim.pk = None self.deposit_claim.subtask_id = generate_uuid() self.deposit_claim.save() with mock.patch('core.payments.service.get_deposit_value', return_value=5) as get_deposit_value: with mock.patch('core.payments.service.force_subtask_payment', return_value=MOCK_TRANSACTION_HASH) as force_subtask_payment: returned_value = finalize_payment(self.deposit_claim) self.assertEqual(returned_value, MOCK_TRANSACTION_HASH) get_deposit_value.assert_called_with( client_eth_address=self.deposit_claim.payer_deposit_account.ethereum_address, ) force_subtask_payment.assert_called_once_with( requestor_eth_address=self.deposit_claim.payer_deposit_account.ethereum_address, provider_eth_address=self.deposit_claim.payee_ethereum_address, # 5 - (2 + 2) | deposit_value - sum_of_other_claims value=1, subtask_id=self.deposit_claim.subtask_id, )
def test_that_when_available_funds_are_zero_finalize_payment_should_delete_deposit_claim_and_return_none(self): with mock.patch('core.payments.service.get_deposit_value', return_value=0) as get_deposit_value: returned_value = finalize_payment(self.deposit_claim) self.assertIsNone(returned_value) self.assertFalse(DepositClaim.objects.filter(pk=self.deposit_claim.pk).exists()) get_deposit_value.assert_called_with( client_eth_address=self.deposit_claim.payer_deposit_account.ethereum_address, )
def test_that_when_deposit_claim_is_for_forced_acceptance_use_case_finalize_payment_should_call_force_subtask_payment(self): with mock.patch('core.payments.service.get_deposit_value', return_value=2) as get_deposit_value: with mock.patch('core.payments.service.force_subtask_payment', return_value=MOCK_TRANSACTION_HASH) as force_subtask_payment: returned_value = finalize_payment(self.deposit_claim) self.assertEqual(returned_value, MOCK_TRANSACTION_HASH) get_deposit_value.assert_called_with( client_eth_address=self.deposit_claim.payer_deposit_account.ethereum_address, ) force_subtask_payment.assert_called_once_with( requestor_eth_address=self.deposit_claim.payer_deposit_account.ethereum_address, provider_eth_address=self.deposit_claim.payee_ethereum_address, value=self.deposit_claim.amount, subtask_id=self.deposit_claim.subtask_id, )