Exemple #1
0
class TestDepositAccountValidation(ConcentIntegrationTestCase):
    def setUp(self):
        super().setUp()
        task_to_compute = self._get_deserialized_task_to_compute()
        self.payer_ethereum_address = task_to_compute.requestor_ethereum_address

        self.client = Client(public_key_bytes=self.REQUESTOR_PUBLIC_KEY)
        self.client.clean()
        self.client.save()

    def test_that_exception_is_raised_when_ethereum_address_has_wrong_length(self):
        with pytest.raises(ValidationError) as exception_info:
            deposit_account = DepositAccount(
                client=self.client,
                ethereum_address=self.payer_ethereum_address + '1'
            )
            deposit_account.clean()
        self.assertIn('ethereum_address', exception_info.value.error_dict)

    def test_that_exception_is_raised_when_ethereum_address_has_wrong_type(self):
        with pytest.raises(ValidationError) as exception_info:
            deposit_account = DepositAccount(
                client=self.client,
                ethereum_address=b'x' * ETHEREUM_ADDRESS_LENGTH
            )
            deposit_account.clean()
        self.assertIn('ethereum_address', exception_info.value.error_dict)

    def test_that_exception_is_not_raised_when_ethereum_address_has_valid_length(self):
        deposit_account = DepositAccount(
            client=self.client,
            ethereum_address=self.payer_ethereum_address
        )
        deposit_account.clean()
        deposit_account.save()
class TestDepositAccountValidation(ConcentIntegrationTestCase):
    def setUp(self):
        super().setUp()
        task_to_compute = self._get_deserialized_task_to_compute()
        self.payer_ethereum_address = task_to_compute.requestor_ethereum_address

        self.client = Client(public_key_bytes=self.REQUESTOR_PUBLIC_KEY)
        self.client.clean()
        self.client.save()

    def test_that_exception_is_not_raised_when_ethereum_address_has_valid_length(
            self):
        deposit_account = DepositAccount(
            client=self.client, ethereum_address=self.payer_ethereum_address)
        deposit_account.clean()
        deposit_account.save()
Exemple #3
0
class DiscardClaimBanksterTest(ConcentIntegrationTestCase):
    def setUp(self):
        super().setUp()
        self.task_to_compute = self._get_deserialized_task_to_compute()

        self.client = Client(public_key_bytes=self.PROVIDER_PUBLIC_KEY)
        self.client.clean()
        self.client.save()

        self.deposit_account = DepositAccount()
        self.deposit_account.client = self.client
        self.deposit_account.ethereum_address = self.task_to_compute.requestor_ethereum_address
        self.deposit_account.clean()
        self.deposit_account.save()

        self.deposit_claim = DepositClaim()
        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_PAYMENT
        self.deposit_claim.amount = 1
        self.deposit_claim.closure_time = parse_timestamp_to_utc_datetime(
            get_current_utc_timestamp())
        self.deposit_claim.full_clean()
        self.deposit_claim.save()

    def test_that_discard_claim_should_return_false_and_not_remove_deposit_claim_if_tx_hash_is_none(
            self):
        claim_removed = discard_claim(self.deposit_claim)

        self.assertFalse(claim_removed)
        self.assertTrue(
            DepositClaim.objects.filter(pk=self.deposit_claim.pk).exists())

    def test_that_discard_claim_should_return_true_and_remove_deposit_claim_if_tx_hash_is_set(
            self):
        self.deposit_claim.tx_hash = 64 * '0'
        self.deposit_claim.clean()
        self.deposit_claim.save()

        claim_removed = discard_claim(self.deposit_claim)

        self.assertTrue(claim_removed)
        self.assertFalse(
            DepositClaim.objects.filter(pk=self.deposit_claim.pk).exists())
Exemple #4
0
    def setUp(self):
        super().setUp()
        task_to_compute = self._get_deserialized_task_to_compute()
        self.payer_ethereum_address = task_to_compute.requestor_ethereum_address
        self.payee_ethereum_address = task_to_compute.provider_ethereum_address

        client = Client(public_key_bytes=self.REQUESTOR_PUBLIC_KEY)
        client.clean()
        client.save()

        self.payer_deposit_account = DepositAccount()
        self.payer_deposit_account.client = client
        self.payer_deposit_account.ethereum_address = task_to_compute.requestor_ethereum_address
        self.payer_deposit_account.clean()
        self.payer_deposit_account.save()

        self.deposit_claim = DepositClaim()
        self.deposit_claim.payer_deposit_account = self.payer_deposit_account
        self.deposit_claim.subtask_id = task_to_compute.subtask_id
        self.deposit_claim.payee_ethereum_address = self.payee_ethereum_address
        self.deposit_claim.concent_use_case = ConcentUseCase.FORCED_TASK_RESULT.value
        self.deposit_claim.amount = 1
        self.deposit_claim.tx_hash = encode_hex(MOCK_TRANSACTION.hash)