Exemplo n.º 1
0
 def get_operation(self, obj):
     """
     Filters confirmations queryset
     :param obj: MultisigConfirmation instance
     :return: serialized queryset
     """
     return SafeOperation(obj.operation).name
Exemplo n.º 2
0
    def test_safe_multisig_tx_get(self):
        safe = SafeContractFactory()
        my_safe_address = safe.address
        response = self.client.get(
            reverse('v1:safe-multisig-txs', args=(my_safe_address, )))
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

        safe_multisig_tx = SafeMultisigTxFactory(safe=safe)
        response = self.client.get(
            reverse('v1:safe-multisig-txs', args=(my_safe_address, )))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        response_json = response.json()
        self.assertEqual(response_json['count'], 1)
        self.assertEqual(len(response_json['results']), 1)
        response_tx = response_json['results'][0]
        self.assertIsNone(response_tx['gasToken'])
        self.assertEqual(response_tx['data'], safe_multisig_tx.data.hex())
        self.assertEqual(response_tx['dataGas'], safe_multisig_tx.data_gas)
        self.assertIsInstance(response_tx['ethereumTx']['gas'], str)
        self.assertEqual(int(response_tx['ethereumTx']['gas']),
                         safe_multisig_tx.ethereum_tx.gas)
        self.assertEqual(response_tx['nonce'], safe_multisig_tx.nonce)
        self.assertEqual(response_tx['operation'],
                         SafeOperation(safe_multisig_tx.operation).name)
        self.assertEqual(response_tx['refundReceiver'],
                         safe_multisig_tx.refund_receiver)
        self.assertEqual(response_tx['safeTxGas'],
                         safe_multisig_tx.safe_tx_gas)
        self.assertEqual(response_tx['safeTxHash'],
                         safe_multisig_tx.safe_tx_hash.hex())
        self.assertEqual(response_tx['to'], safe_multisig_tx.to)
        self.assertEqual(response_tx['txHash'],
                         safe_multisig_tx.ethereum_tx.tx_hash.hex())
        self.assertEqual(response_tx['value'], safe_multisig_tx.value)

        safe_multisig_tx2 = SafeMultisigTxFactory(safe=safe)
        safe_multisig_tx3 = SafeMultisigTxFactory(safe=safe)
        response = self.client.get(
            reverse('v1:safe-multisig-txs', args=(my_safe_address, )))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.json()['count'], 3)

        # Test filter by `to`
        response = self.client.get(
            reverse('v1:safe-multisig-txs', args=(my_safe_address, )),
            {'to': safe_multisig_tx3.to})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.json()['count'], 1)

        value = safe_multisig_tx.value + safe_multisig_tx2.value + safe_multisig_tx3.value
        safe_multisig_tx4 = SafeMultisigTxFactory(safe=safe, value=value)

        # Test filter by `value >`
        response = self.client.get(
            reverse('v1:safe-multisig-txs', args=(my_safe_address, )),
            {'value__gt': value - 1})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.json()['count'], 1)
        self.assertEqual(response.json()['results'][0]['to'],
                         safe_multisig_tx4.to)

        # Test sorting
        response = self.client.get(
            reverse('v1:safe-multisig-txs', args=(my_safe_address, )))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.json()['count'], 4)
        self.assertEqual(response.json()['results'][0]['to'],
                         safe_multisig_tx4.to)

        # Test reverse sorting
        response = self.client.get(
            reverse('v1:safe-multisig-txs', args=(my_safe_address, )),
            {'ordering': 'created'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.json()['count'], 4)
        self.assertEqual(response.json()['results'][0]['to'],
                         safe_multisig_tx.to)
Exemplo n.º 3
0
 def __str__(self):
     return '{} - {} - Safe {}'.format(self.ethereum_tx.tx_hash,
                                       SafeOperation(self.operation).name,
                                       self.safe.address)
Exemplo n.º 4
0
    def test_safe_multisig_tx_get(self):
        safe = SafeContractFactory()
        my_safe_address = safe.address
        response = self.client.get(
            reverse("v1:safe-multisig-txs", args=(my_safe_address, )))
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

        safe_multisig_tx = SafeMultisigTxFactory(safe=safe)
        response = self.client.get(
            reverse("v1:safe-multisig-txs", args=(my_safe_address, )))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        response_json = response.json()
        self.assertEqual(response_json["count"], 1)
        self.assertEqual(len(response_json["results"]), 1)
        response_tx = response_json["results"][0]
        self.assertIsNone(response_tx["gasToken"])
        self.assertEqual(response_tx["data"], safe_multisig_tx.data.hex())
        self.assertEqual(response_tx["dataGas"], safe_multisig_tx.data_gas)
        self.assertIsInstance(response_tx["ethereumTx"]["gas"], str)
        self.assertEqual(int(response_tx["ethereumTx"]["gas"]),
                         safe_multisig_tx.ethereum_tx.gas)
        self.assertEqual(response_tx["nonce"], safe_multisig_tx.nonce)
        self.assertEqual(response_tx["operation"],
                         SafeOperation(safe_multisig_tx.operation).name)
        self.assertEqual(response_tx["refundReceiver"],
                         safe_multisig_tx.refund_receiver)
        self.assertEqual(response_tx["safeTxGas"],
                         safe_multisig_tx.safe_tx_gas)
        self.assertEqual(response_tx["safeTxHash"],
                         safe_multisig_tx.safe_tx_hash.hex())
        self.assertEqual(response_tx["to"], safe_multisig_tx.to)
        self.assertEqual(response_tx["txHash"],
                         safe_multisig_tx.ethereum_tx.tx_hash.hex())
        self.assertEqual(response_tx["value"], safe_multisig_tx.value)

        safe_multisig_tx2 = SafeMultisigTxFactory(safe=safe)
        safe_multisig_tx3 = SafeMultisigTxFactory(safe=safe)
        response = self.client.get(
            reverse("v1:safe-multisig-txs", args=(my_safe_address, )))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.json()["count"], 3)

        # Test filter by `to`
        response = self.client.get(
            reverse("v1:safe-multisig-txs", args=(my_safe_address, )),
            {"to": safe_multisig_tx3.to},
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.json()["count"], 1)

        value = (safe_multisig_tx.value + safe_multisig_tx2.value +
                 safe_multisig_tx3.value)
        safe_multisig_tx4 = SafeMultisigTxFactory(safe=safe, value=value)

        # Test filter by `value >`
        response = self.client.get(
            reverse("v1:safe-multisig-txs", args=(my_safe_address, )),
            {"value__gt": value - 1},
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.json()["count"], 1)
        self.assertEqual(response.json()["results"][0]["to"],
                         safe_multisig_tx4.to)

        # Test sorting
        response = self.client.get(
            reverse("v1:safe-multisig-txs", args=(my_safe_address, )))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.json()["count"], 4)
        self.assertEqual(response.json()["results"][0]["to"],
                         safe_multisig_tx4.to)

        # Test reverse sorting
        response = self.client.get(
            reverse("v1:safe-multisig-txs", args=(my_safe_address, )),
            {"ordering": "created"},
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.json()["count"], 4)
        self.assertEqual(response.json()["results"][0]["to"],
                         safe_multisig_tx.to)