예제 #1
0
    def test_get_all_system_limit_txs(self):
        system_pagination = config.MAX_ROWS_IN_API_RESPONSE
        config.MAX_ROWS_IN_API_RESPONSE = 2
        with switch_db(EthTransactions,
                       config.MONGO_TEST_DATABASE_NAME) as TestEthTransactions:
            with switch_db(EthBlocks,
                           config.MONGO_TEST_DATABASE_NAME) as TestEthBlocks:
                self.assertEqual(TestEthTransactions.objects.count(), 4)
                self.assertEqual(TestEthBlocks.objects.count(), 3)

                response = self.client.get(reverse('txs-list'), {
                    'api_key': self.api_key.key,
                    'offset': 1
                })

                self.assertEqual(response.status_code, status.HTTP_200_OK)
                self.assertEqual(len(response.data), 2)
                self.assertEqual(
                    response.data,
                    TxSerializer([
                        TestEthTransactions.objects.all()[1],
                        TestEthTransactions.objects.all()[2]
                    ],
                                 many=True).data)
        config.MAX_ROWS_IN_API_RESPONSE = system_pagination
예제 #2
0
    def test_get_all_txs(self):
        with switch_db(EthTransactions,
                       config.MONGO_TEST_DATABASE_NAME) as TestEthTransactions:
            with switch_db(EthBlocks,
                           config.MONGO_TEST_DATABASE_NAME) as TestEthBlocks:
                self.assertEqual(TestEthTransactions.objects.count(), 4)
                self.assertEqual(TestEthBlocks.objects.count(), 3)

                response = self.client.get(reverse('txs-list'),
                                           {'api_key': self.api_key.key})

                self.assertEqual(response.status_code, status.HTTP_200_OK)
                self.assertEqual(len(response.data), 4)
                self.assertEqual(
                    response.data,
                    TxSerializer(TestEthTransactions.objects.all(),
                                 many=True).data)
예제 #3
0
    def test_get_filter_from_txs(self):
        to_address = '0x42e6723a0c884e922240e56d7b618bec96f35801'
        with switch_db(EthTransactions,
                       config.MONGO_TEST_DATABASE_NAME) as TestEthTransactions:
            with switch_db(EthBlocks,
                           config.MONGO_TEST_DATABASE_NAME) as TestEthBlocks:
                self.assertEqual(TestEthTransactions.objects.count(), 4)
                self.assertEqual(TestEthBlocks.objects.count(), 3)

                response = self.client.get(reverse('txs-list'), {
                    'toAddress': to_address,
                    'api_key': self.api_key.key
                })
                self.assertEqual(response.status_code, status.HTTP_200_OK)

                self.assertEqual(len(response.data), 2)
                self.assertEqual(
                    response.data,
                    TxSerializer(TestEthTransactions.objects.filter(
                        toAddress=to_address),
                                 many=True).data)
예제 #4
0
    def test_get_filter_timestamp_gte(self):
        timestamp = 1442886050
        with switch_db(EthTransactions,
                       config.MONGO_TEST_DATABASE_NAME) as TestEthTransactions:
            with switch_db(EthBlocks,
                           config.MONGO_TEST_DATABASE_NAME) as TestEthBlocks:
                self.assertEqual(TestEthTransactions.objects.count(), 4)
                self.assertEqual(TestEthBlocks.objects.count(), 3)

                response = self.client.get(reverse('txs-list'), {
                    'timestamp__gte': timestamp,
                    'api_key': self.api_key.key
                })
                self.assertEqual(response.status_code, status.HTTP_200_OK)

                self.assertEqual(len(response.data), 3)
                self.assertEqual(
                    response.data,
                    TxSerializer(TestEthTransactions.objects.filter(
                        timestamp__gte=timestamp),
                                 many=True).data)
예제 #5
0
    def test_get_filter_block_num_lt(self):
        block_number = 270678
        with switch_db(EthTransactions,
                       config.MONGO_TEST_DATABASE_NAME) as TestEthTransactions:
            with switch_db(EthBlocks,
                           config.MONGO_TEST_DATABASE_NAME) as TestEthBlocks:
                self.assertEqual(TestEthTransactions.objects.count(), 4)
                self.assertEqual(TestEthBlocks.objects.count(), 3)

                response = self.client.get(reverse('txs-list'), {
                    'blockNumber__lt': block_number,
                    'api_key': self.api_key.key
                })
                self.assertEqual(response.status_code, status.HTTP_200_OK)

                self.assertEqual(len(response.data), 2)
                self.assertEqual(
                    response.data,
                    TxSerializer(TestEthTransactions.objects.filter(
                        blockNumber__lt=block_number),
                                 many=True).data)