def test_valid_transaction_sig(self): """ testing crypto valid_transaction_sig """ transaction = TRANSACTION.copy() # sign transaction (tested prior to this call) test_transaction = crypto.sign_transaction(SIGNATORY, PRIVATE_KEY, PUBLIC_KEY, transaction) # testing signature validation sig_validation = crypto.valid_transaction_sig(test_transaction) # check if valid_transaction_sig returned true self.assertTrue(sig_validation, True)
def test_sign_transaction(self): """ testing crypto sign_transaction """ transaction = TRANSACTION.copy() test_transaction = crypto.sign_transaction(SIGNATORY, PRIVATE_KEY, PUBLIC_KEY, transaction) # checking if signature made it into transaction self.assertEqual('signature' in test_transaction, True) # testing that KeyError is appropriately raised for key in test_transaction.keys(): test_transaction.pop(key) self.assertRaises(KeyError, crypto.sign_transaction, SIGNATORY, PRIVATE_KEY, PUBLIC_KEY, test_transaction)
def test_sign_transaction(self): transaction = TRANSACTION.copy() test_transaction = crypto.sign_transaction(SIGNATORY, PRIVATE_KEY, PUBLIC_KEY, transaction) # checking if signature made it into transaction self.assertEqual('signature' in test_transaction, True) # testing that KeyError is appropriately raised for key in test_transaction.keys(): test_transaction.pop(key) self.assertRaises(KeyError, crypto.sign_transaction, SIGNATORY, PRIVATE_KEY, PUBLIC_KEY, test_transaction)
def post(self): txn = self.request.body log = self.application.log log.debug("Parsing JSON") try: txn = tornado.escape.json_decode(txn) txn["header"]["transaction_id"] = str(uuid.uuid4()) txn["header"]["transaction_ts"] = int(time.time()) except: log.error("Failed to parse JSON. Details: " + str(sys.exc_info()[1])) self.clear() self.set_txn_status(log, 400) self.write( format_error("invalid input", "ERROR: Failed to parse JSON\n")) return try: log.info("Validating the transaction") if not valid_vestal_transaction(txn): return False if valid_transaction_sig(txn): log.info("Signing the transaction") txn = sign_transaction("transaction-service", self.application.private_key, self.application.public_key, txn) tx_dao.insert_transaction(txn) self.set_header("Content-Type", "application/json") self.set_txn_status(log, 201) self.write( json.dumps( {"transaction_id": txn["header"]["transaction_id"]})) return else: # TODO: add status function accepts status code number and status string self.set_txn_status(log, 400) return except: log.error(str(sys.exc_info())) self.clear() self.set_txn_status(log, 500) self.write(format_error("validation", str(sys.exc_info()[1])))
def post(self): txn = self.request.body log = self.application.log log.debug("Parsing JSON") try: txn = tornado.escape.json_decode(txn) txn["header"]["transaction_id"] = str(uuid.uuid4()) txn["header"]["transaction_ts"] = int(time.time()) except: log.error("Failed to parse JSON. Details: " + str(sys.exc_info()[1])) self.clear() self.set_txn_status(log, 400) self.write(format_error("invalid input", "ERROR: malformed json\nDocumentation for transaction format can be found at \nhttps://github.com/dragonchain/dragonchain/blob/master/docs/transaction.md")) return try: log.info("Validating the transaction") if not valid_vestal_transaction(txn): return False if valid_transaction_sig(txn): log.info("Signing the transaction") txn = sign_transaction("transaction-service", self.application.private_key, self.application.public_key, txn) tx_dao.insert_transaction(txn) self.set_header("Content-Type", "application/json") self.set_txn_status(log, 201) self.write(json.dumps({ "transaction_id": txn["header"]["transaction_id"] })) return else: # TODO: add status function accepts status code number and status string self.set_txn_status(log, 400) return except: log.error(str(sys.exc_info())) self.clear() self.set_txn_status(log, 500) self.write(format_error("validation", str(sys.exc_info()[1])))