Exemplo n.º 1
0
 def test_get_nonce_no_out_transaction(self):
     """
     Makes sure get_nonce() doesn't crash on no out transaction,
     but just returns 0.
     """
     # the VOID_ADDRESS has a lot of in transactions,
     # but no out ones, so the nonce should be 0
     address = VOID_ADDRESS
     # truncated for readability
     transactions = [{
         'blockHash': ('0x7e5a9336dd82efff0bfe8c25ccb0e8c'
                       'f44b4c6f781b25b3fc3578f004f60b872'),
         'from':
         '0x22f2dcff5ad78c3eb6850b5cb951127b659522e6',
         'timeStamp':
         '1438922865',
         'to':
         '0x0000000000000000000000000000000000000000',
         'value':
         '0'
     }]
     with patch_requests_get() as m_get:
         m_get.return_value.status_code = http.HTTPStatus.OK
         m_get.return_value.json.return_value = {
             'status': '1',
             'message': 'OK',
             'result': transactions,
         }
         nonce = PyWalib.get_nonce(address)
     url = mock.ANY
     headers = REQUESTS_HEADERS
     self.assertEqual(m_get.call_args_list,
                      [mock.call(url, headers=headers)])
     self.assertEqual(nonce, 0)
Exemplo n.º 2
0
 def test_get_nonce_no_transaction(self):
     """
     Makes sure get_nonce() doesn't crash on no transaction,
     but just returns 0.
     """
     # the newly created address has no in or out transaction history
     account = self.helper_new_account()
     address = account.address
     nonce = PyWalib.get_nonce(address)
     self.assertEqual(nonce, 0)
Exemplo n.º 3
0
 def test_get_nonce_no_out_transaction(self):
     """
     Makes sure get_nonce() doesn't crash on no out transaction,
     but just returns 0.
     """
     # the VOID_ADDRESS has a lot of in transactions,
     # but no out ones, so the nonce should be 0
     address = VOID_ADDRESS
     nonce = PyWalib.get_nonce(address)
     self.assertEqual(nonce, 0)
Exemplo n.º 4
0
 def test_get_nonce(self):
     """
     Checks get_nonce() returns the next nonce, i.e. transaction count.
     """
     address = ADDRESS
     nonce = PyWalib.get_nonce(address)
     transactions = PyWalib.get_out_transaction_history(address)
     last_transaction = transactions[-1]
     last_nonce = int(last_transaction['nonce'])
     self.assertEqual(nonce, last_nonce + 1)
Exemplo n.º 5
0
 def test_get_nonce_no_transaction(self):
     """
     Makes sure get_nonce() doesn't crash on no transaction,
     but just returns 0.
     """
     # the newly created address has no in or out transaction history
     account = self.helper_new_account()
     address = account.address
     with patch_requests_get() as m_get:
         m_get.return_value.status_code = http.HTTPStatus.OK
         m_get.return_value.json.return_value = {
             'status': '0',
             'message': 'No transactions found',
             'result': [],
         }
         nonce = PyWalib.get_nonce(address)
     url = mock.ANY
     headers = REQUESTS_HEADERS
     self.assertEqual(m_get.call_args_list,
                      [mock.call(url, headers=headers)])
     self.assertEqual(nonce, 0)
Exemplo n.º 6
0
 def test_get_nonce(self):
     """
     Checks get_nonce() returns the next nonce, i.e. transaction count.
     """
     address = ADDRESS
     m_transactions = M_TRANSACTIONS
     with patch_requests_get() as m_get:
         m_get.return_value.status_code = http.HTTPStatus.OK
         m_get.return_value.json.return_value = {
             'status': '1',
             'message': 'OK',
             'result': m_transactions,
         }
         nonce = PyWalib.get_nonce(address)
         transactions = PyWalib.get_out_transaction_history(address)
     url = mock.ANY
     headers = REQUESTS_HEADERS
     self.assertEqual(m_get.call_args_list,
                      2 * [mock.call(url, headers=headers)])
     last_transaction = transactions[-1]
     last_nonce = int(last_transaction['nonce'])
     self.assertEqual(nonce, last_nonce + 1)