def test_get_pending_nonce_if_strict_invalid(self): with self.assertRaises(transaction.TransactionNonceInvalid): transaction.get_new_pending_nonce( tx_nonce=3, nonce=1, pending_nonce=2 )
def test_get_pending_nonce_too_many_tx_per_block_raise_error_pending(self): with self.assertRaises(transaction.TransactionTooManyPendingException): transaction.get_new_pending_nonce( tx_nonce=17, nonce=0, pending_nonce=1 )
def test_get_pending_nonce_if_not_strict_is_highest_nonce(self): new_pending_nonce = transaction.get_new_pending_nonce(tx_nonce=3, nonce=1, pending_nonce=2, strict=False) self.assertEqual(new_pending_nonce, 4)
async def submit_transaction(self, request): log.debug(f'New request: {request}') # Reject TX if the queue is too large if len(self.queue) >= self.max_queue_len: return response.json({'error': "Queue full. Resubmit shortly."}, status=503, headers={'Access-Control-Allow-Origin': '*'}) tx_raw = _json.loads(request.body) log.error(tx_raw) # Check that the payload is valid JSON tx = decode(request.body) if tx is None: return response.json({'error': 'Malformed request body.'}, headers={'Access-Control-Allow-Origin': '*'}) # Check that the TX is correctly formatted try: transaction.check_tx_formatting(tx, self.wallet.verifying_key) transaction.transaction_is_valid( transaction=tx, expected_processor=self.wallet.verifying_key, client=self.client, nonces=self.nonces) nonce, pending_nonce = transaction.get_nonces( sender=tx['payload']['sender'], processor=tx['payload']['processor'], driver=self.nonces) pending_nonce = transaction.get_new_pending_nonce( tx_nonce=tx['payload']['nonce'], nonce=nonce, pending_nonce=pending_nonce) self.nonces.set_pending_nonce(sender=tx['payload']['sender'], processor=tx['payload']['processor'], value=pending_nonce) except TransactionException as e: log.error(f'Tx has error: {type(e)}') log.error(tx) return response.json(transaction.EXCEPTION_MAP[type(e)], headers={'Access-Control-Allow-Origin': '*'}) # Add TX to the processing queue self.queue.append(request.body) log.error('Added to q') # Return the TX hash to the user so they can track it tx_hash = tx_hash_from_tx(tx) return response.json( { 'success': 'Transaction successfully submitted to the network.', 'hash': tx_hash }, headers={'Access-Control-Allow-Origin': '*'})
def test_get_pending_nonce_if_strict_increments(self): new_pending_nonce = transaction.get_new_pending_nonce( tx_nonce=2, nonce=1, pending_nonce=2 ) self.assertEqual(new_pending_nonce, 3)