def test_etherscan_account_no_tx_found_api_call(self, mock_func): """Test no records found during etherscan api call """ mock_func.return_value = Mock(ok=False) params = { 'module': 'account', 'action': 'txlist', 'address': self.account, 'startblock': 0, 'endblock': 6, 'apikey': settings.ETHERSCAN_API_KEY, 'sort': 'asc', } records = call_etherscan_api('mainnet', params) self.assertTrue(len(records) == 0)
def test_etherscan_account_wrong_api_call(self, mock_func): """Test wrong call to etherscan api """ mock_func.return_value = Mock(ok=False) params = { 'module': 'account', 'action': 'transactions', # non-existent action 'address': self.account, 'startblock': 0, 'endblock': 6570004, 'apikey': settings.ETHERSCAN_API_KEY, 'sort': 'asc', } records = call_etherscan_api('mainnet', params) self.assertTrue(len(records) == 0)
def test_etherscan_account_txlist_api_call(self, mock_func): """Test etherscan txlist api call """ mock_func.return_value = Mock(ok=True) mock_func.return_value.json.return_value = { "status": "1", "message": "OK", "result": [{ "blockNumber": "6570004", "timeStamp": "1540317632", "hash": "0x84a4a80b6e70048bf0ee8b937a4931efdb4f30e248e0f15036cf40748aef938e", "nonce": "4", "blockHash": "0x9b9d524c5fb92ed79fac4174c8136b9a11527cf7ba30985a27502c104bb6c574", "transactionIndex": "95", "from": "0xf8ae578d5d4e570de6c31f26d42ef369c320ae0b", "to": "0xdb282cee382244e05dd226c8809d2405b76fbdc9", "value": "50000000000000000", "gas": "21000", "gasPrice": "4000000000", "isError": "0", "txreceipt_status": "1", "input": "0x", "contractAddress": "", "cumulativeGasUsed": "7992355", "gasUsed": "21000", "confirmations": "2546337" }] } params = { 'module': 'account', 'action': 'txlist', 'address': self.account, 'startblock': 0, 'endblock': 6570004, 'apikey': settings.ETHERSCAN_API_KEY, 'sort': 'asc', } records = call_etherscan_api('mainnet', params) self.assertTrue(len(records) == 1) for record in records: self.assertTrue('hash' in record) self.assertTrue('contractAddress' in record) self.assertTrue('value' in record) self.assertTrue('from' in record) self.assertTrue('to' in record) break