diff --git a/tests/test_transaction_signing.py b/tests/test_transaction_signing_karun.py similarity index 64% rename from tests/test_transaction_signing.py rename to tests/test_transaction_signing_karun.py index 05b79d0..05cc5fd 100644 --- a/tests/test_transaction_signing.py +++ b/tests/test_transaction_signing_karun.py @@ -140,59 +140,5 @@ def test_unsigned_transaction_fails_verification(alice, bob): assert not tx.verify(), "An unsigned transaction must not verify." -# ------------------------------------------------------------------ -# 4. Replay protection -# ------------------------------------------------------------------ - -def test_replay_attack_same_nonce_rejected(alice, bob, funded_state): - """Replaying the same transaction must be rejected the second time.""" - alice_sk, alice_pk = alice - _, bob_pk = bob - - tx = Transaction(alice_pk, bob_pk, 10, nonce=0) - tx.sign(alice_sk) - - assert funded_state.apply_transaction(tx), "First submission must succeed." - assert not funded_state.apply_transaction(tx), "Replayed transaction must be rejected." - # Ensure the rejected replay did not mutate the ledger - assert funded_state.get_account(alice_pk)["balance"] == 90, \ - "Alice's balance must not change after a rejected replay." - assert funded_state.get_account(alice_pk)["nonce"] == 1, \ - "Alice's nonce must not advance after a rejected replay." - - -def test_out_of_order_nonce_rejected(alice, bob, funded_state): - """A transaction with a skipped nonce must be rejected.""" - alice_sk, alice_pk = alice - _, bob_pk = bob - - tx = Transaction(alice_pk, bob_pk, 10, nonce=5) - tx.sign(alice_sk) - - assert not funded_state.apply_transaction(tx), "A transaction with a skipped nonce must be rejected." - # Ensure the rejected transaction did not mutate the ledger - assert funded_state.get_account(alice_pk)["balance"] == 100, \ - "Alice's balance must remain unchanged after a rejected transaction." - assert funded_state.get_account(alice_pk)["nonce"] == 0, \ - "Alice's nonce must remain unchanged after a rejected transaction." - - -def test_sequential_nonces_accepted(alice, bob, funded_state): - """Two transactions with consecutive nonces must both succeed.""" - alice_sk, alice_pk = alice - _, bob_pk = bob - - tx0 = Transaction(alice_pk, bob_pk, 10, nonce=0) - tx0.sign(alice_sk) - assert funded_state.apply_transaction(tx0) - - tx1 = Transaction(alice_pk, bob_pk, 10, nonce=1) - tx1.sign(alice_sk) - assert funded_state.apply_transaction(tx1) - assert funded_state.get_account(alice_pk)["nonce"] == 2, \ - "Alice's nonce should advance to 2 after two accepted transactions." - assert funded_state.get_account(alice_pk)["balance"] == 80, \ - "Alice's balance should be 80 after two 10-coin transfers." - assert funded_state.get_account(bob_pk)["balance"] == 20, \ - "Bob's balance should be 20 after receiving two transfers." \ No newline at end of file + "Bob's balance should be 20 after receiving two transfers."