2021-02-01 18:12:51 +01:00
|
|
|
# standard imports
|
|
|
|
import os
|
|
|
|
|
|
|
|
# third-party imports
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
# local imports
|
|
|
|
from cic_eth.db.models.lock import Lock
|
|
|
|
from cic_eth.db.enum import LockEnum
|
|
|
|
from cic_eth.error import LockedError
|
2021-04-04 14:40:59 +02:00
|
|
|
from cic_eth.queue.tx import queue_create
|
2021-08-28 13:10:18 +02:00
|
|
|
from cic_eth.encode import tx_normalize
|
2021-02-01 18:12:51 +01:00
|
|
|
|
|
|
|
def test_queue_lock(
|
|
|
|
init_database,
|
|
|
|
default_chain_spec,
|
|
|
|
):
|
|
|
|
|
|
|
|
chain_str = str(default_chain_spec)
|
|
|
|
|
|
|
|
address = '0x' + os.urandom(20).hex()
|
|
|
|
tx_hash = '0x' + os.urandom(32).hex()
|
|
|
|
tx_raw = '0x' + os.urandom(128).hex()
|
2021-08-28 13:10:18 +02:00
|
|
|
address_normal = tx_normalize.wallet_address(address)
|
|
|
|
tx_hash_normal = tx_normalize.tx_hash(tx_hash)
|
2021-02-01 18:12:51 +01:00
|
|
|
|
|
|
|
Lock.set(chain_str, LockEnum.QUEUE)
|
|
|
|
with pytest.raises(LockedError):
|
|
|
|
queue_create(
|
2021-04-04 14:40:59 +02:00
|
|
|
default_chain_spec,
|
2021-02-01 18:12:51 +01:00
|
|
|
0,
|
|
|
|
address,
|
|
|
|
tx_hash,
|
|
|
|
tx_raw,
|
|
|
|
)
|
|
|
|
|
2021-08-28 13:10:18 +02:00
|
|
|
Lock.set(chain_str, LockEnum.QUEUE, address=address_normal)
|
2021-02-01 18:12:51 +01:00
|
|
|
with pytest.raises(LockedError):
|
|
|
|
queue_create(
|
2021-04-04 14:40:59 +02:00
|
|
|
default_chain_spec,
|
2021-02-01 18:12:51 +01:00
|
|
|
0,
|
|
|
|
address,
|
|
|
|
tx_hash,
|
|
|
|
tx_raw,
|
|
|
|
)
|
|
|
|
|
|
|
|
Lock.reset(chain_str, LockEnum.QUEUE)
|
|
|
|
with pytest.raises(LockedError):
|
|
|
|
queue_create(
|
2021-04-04 14:40:59 +02:00
|
|
|
default_chain_spec,
|
2021-02-01 18:12:51 +01:00
|
|
|
0,
|
|
|
|
address,
|
|
|
|
tx_hash,
|
|
|
|
tx_raw,
|
|
|
|
)
|
|
|
|
|
2021-08-28 13:10:18 +02:00
|
|
|
Lock.set(chain_str, LockEnum.QUEUE, address=address_normal, tx_hash=tx_hash_normal)
|
2021-02-01 18:12:51 +01:00
|
|
|
with pytest.raises(LockedError):
|
|
|
|
queue_create(
|
2021-04-04 14:40:59 +02:00
|
|
|
default_chain_spec,
|
2021-02-01 18:12:51 +01:00
|
|
|
0,
|
|
|
|
address,
|
|
|
|
tx_hash,
|
|
|
|
tx_raw,
|
|
|
|
)
|