diff --git a/tests/plugins/test_pairlocks.py b/tests/plugins/test_pairlocks.py index 678355f1c..f55c6ad88 100644 --- a/tests/plugins/test_pairlocks.py +++ b/tests/plugins/test_pairlocks.py @@ -158,3 +158,32 @@ def test_PairLocks_reason(use_db): PairLocks.reset_locks() PairLocks.use_db = True + + +@pytest.mark.parametrize("use_db", (False, True)) +@pytest.mark.usefixtures("init_persistence") +def test_PairLocks_no_duplicates(use_db, time_machine): + PairLocks.timeframe = "5m" + PairLocks.use_db = use_db + # No lock should be present + assert len(PairLocks.get_all_locks()) == 0 + time_machine.move_to("2026-01-05 20:00:05 +00:00", tick=False) + + assert PairLocks.use_db == use_db + PairLocks.lock_pair("XRP/USDT", dt_now() + timedelta(minutes=4), "TestLock1") + assert len(PairLocks.get_all_locks()) == 1 + + PairLocks.lock_pair("XRP/USDT", dt_now() + timedelta(minutes=4), "TestLock1") + assert len(PairLocks.get_all_locks()) == 1 + + # Different Reason - should create a new lock + PairLocks.lock_pair("XRP/USDT", dt_now() + timedelta(minutes=4), "TestLock2") + assert len(PairLocks.get_all_locks()) == 2 + + # Different end-time - should create a new lock + PairLocks.lock_pair("XRP/USDT", dt_now() + timedelta(minutes=5), "TestLock1") + assert len(PairLocks.get_all_locks()) == 3 + + # Different side - should create a new lock + PairLocks.lock_pair("XRP/USDT", dt_now() + timedelta(minutes=4), "TestLock1", side="long") + assert len(PairLocks.get_all_locks()) == 4 diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index fe82e9904..86084ad5f 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -1434,8 +1434,8 @@ def test_rpc_add_and_delete_lock(mocker, default_conf): pair = "ETH/BTC" rpc._rpc_add_lock(pair, datetime.now(UTC) + timedelta(minutes=4), "", "*") - rpc._rpc_add_lock(pair, datetime.now(UTC) + timedelta(minutes=5), "", "*") - rpc._rpc_add_lock(pair, datetime.now(UTC) + timedelta(minutes=10), "", "*") + rpc._rpc_add_lock(pair, datetime.now(UTC) + timedelta(minutes=20), "", "*") + rpc._rpc_add_lock(pair, datetime.now(UTC) + timedelta(minutes=50), "", "*") locks = rpc._rpc_locks() assert locks["lock_count"] == 3