diff --git a/apps/cli/pisa-cli.py b/apps/cli/pisa-cli.py index dacca68..3dd22f1 100644 --- a/apps/cli/pisa-cli.py +++ b/apps/cli/pisa-cli.py @@ -28,9 +28,8 @@ def generate_dummy_appointment(): current_height = r.json().get("block_count") - dummy_appointment_data = {"tx": hexlify(os.urandom(192)).decode('utf-8'), - "tx_id": hexlify(os.urandom(32)).decode('utf-8'), "start_time": current_height + 5, - "end_time": current_height + 10, "dispute_delta": 20} + dummy_appointment_data = {"tx": os.urandom(192).hex(), "tx_id": os.urandom(32).hex(), + "start_time": current_height + 5, "end_time": current_height + 10, "dispute_delta": 20} print('Generating dummy appointment data:''\n\n' + json.dumps(dummy_appointment_data, indent=4, sort_keys=True)) diff --git a/test/add_appointment_test.py b/test/add_appointment_test.py index 68fea80..35aa1b0 100644 --- a/test/add_appointment_test.py +++ b/test/add_appointment_test.py @@ -18,8 +18,7 @@ def generate_dummy_appointment(dispute_txid): current_height = r.json().get("block_count") - dummy_appointment_data = {"tx": hexlify(os.urandom(32)).decode('utf-8'), - "tx_id": dispute_txid, "start_time": current_height + 5, + dummy_appointment_data = {"tx": os.urandom(32).hex(), "tx_id": dispute_txid, "start_time": current_height + 5, "end_time": current_height + 10, "dispute_delta": 20} cipher = "AES-GCM-128" @@ -40,7 +39,7 @@ def generate_dummy_appointment(dispute_txid): def test_add_appointment(appointment=None): if not appointment: - dispute_txid = hexlify(os.urandom(32)).decode('utf-8') + dispute_txid = os.urandom(32).hex() appointment = generate_dummy_appointment(dispute_txid) print("Sending appointment (locator: {}) to PISA".format(appointment.get("locator"))) @@ -67,7 +66,7 @@ def test_add_appointment(appointment=None): def test_same_locator_multiple_appointments(): - dispute_txid = hexlify(os.urandom(32)).decode('utf-8') + dispute_txid = os.urandom(32).hex() appointment = generate_dummy_appointment(dispute_txid) # Send it once diff --git a/test/simulator/bitcoin_sim_tests.py b/test/simulator/bitcoin_sim_tests.py index dd77baa..bc5f45a 100644 --- a/test/simulator/bitcoin_sim_tests.py +++ b/test/simulator/bitcoin_sim_tests.py @@ -32,7 +32,7 @@ assert(len(block.get('tx')) != 0) assert(isinstance(block.get('height'), int)) # Some fails -values += ["a"*64, binascii.hexlify(os.urandom(32)).decode()] +values += ["a"*64, os.urandom(32).hex()] print("\ngetblock fails ({}):".format(len(values))) for v in values: @@ -50,14 +50,14 @@ assert(isinstance(tx.get('txid'), str)) assert(check_txid_format(tx.get('txid'))) # Therefore should also work for a random formatted 32-byte hex in our simulation -random_tx = binascii.hexlify(os.urandom(32)).decode() +random_tx = os.urandom(32).hex() tx = bitcoin_cli.decoderawtransaction(random_tx) assert(isinstance(tx, dict)) assert(isinstance(tx.get('txid'), str)) assert(check_txid_format(tx.get('txid'))) # But it should fail for not proper formatted one -values = [1, None, '', "a"*63, "b"*65, [], binascii.hexlify(os.urandom(31)).hex()] +values = [1, None, '', "a"*63, "b"*65, [], os.urandom(31).hex()] print("\ndecoderawtransaction fails ({}):".format(len(values))) for v in values: @@ -68,7 +68,7 @@ for v in values: print('\t{}'.format(e)) # sendrawtransaction should only allow txids that the simulator has not mined yet -bitcoin_cli.sendrawtransaction(binascii.hexlify(os.urandom(32)).decode()) +bitcoin_cli.sendrawtransaction(os.urandom(32).hex()) # Any data not matching the txid format or that matches with an already mined transaction should fail values += [coinbase_tx] diff --git a/test/simulator/bitcoind_sim.py b/test/simulator/bitcoind_sim.py index 9ba6089..1512c1f 100644 --- a/test/simulator/bitcoind_sim.py +++ b/test/simulator/bitcoind_sim.py @@ -172,8 +172,8 @@ def simulate_mining(): prev_block_hash = None while True: - block_hash = binascii.hexlify(os.urandom(32)).decode('utf-8') - coinbase_tx_hash = binascii.hexlify(os.urandom(32)).decode('utf-8') + block_hash = os.urandom(32).hex() + coinbase_tx_hash = os.urandom(32).hex() txs_to_mine = [coinbase_tx_hash] if len(mempool) != 0: diff --git a/test/unit/test_cleaner.py b/test/unit/test_cleaner.py index 5a3bbab..de1be8a 100644 --- a/test/unit/test_cleaner.py +++ b/test/unit/test_cleaner.py @@ -20,7 +20,7 @@ def set_up_appointments(total_appointments): for _ in range(total_appointments): uuid = uuid4().hex - locator = hexlify(urandom(64)) + locator = urandom(32).hex() appointments[uuid] = Appointment(locator, None, None, None, None, None, None) locator_uuid_map[locator] = [uuid] @@ -41,7 +41,7 @@ def set_up_jobs(total_jobs): for _ in range(total_jobs): uuid = uuid4().hex - txid = hexlify(urandom(64)) + txid = urandom(32).hex() # Assign both justice_txid and dispute_txid the same id (it shouldn't matter) jobs[uuid] = Job(txid, txid, None, None, None)