mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 14:14:22 +01:00
Updates os.urandom to python3
All string generated with urandom(x) were using binascii + os.urandom + encode. In python3 os.urandom has a hex method.
This commit is contained in:
@@ -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))
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user