-
-
Notifications
You must be signed in to change notification settings - Fork 16
remove replace #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remove replace #66
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -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." | ||||
| "Bob's balance should be 20 after receiving two transfers." | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
fd 'test_transaction_signing_karun\.py$' | while read -r f; do
echo "== $f =="
nl -ba "$f" | sed -n '132,160p'
doneRepository: StabilityNexus/MiniChain Length of output: 173 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Find the file and display lines around 144 using cat
fd 'test_transaction_signing_karun\.py$' -type f | while read -r f; do
echo "== $f =="
echo "=== File size ==="
wc -l "$f"
echo "=== Lines 130-160 with line numbers ==="
cat -n "$f" | sed -n '130,160p'
doneRepository: StabilityNexus/MiniChain Length of output: 238 🏁 Script executed: #!/bin/bash
# Verify Python syntax by attempting to compile the file
fd 'test_transaction_signing_karun\.py$' -type f | while read -r f; do
echo "== Syntax check for $f =="
python3 -m py_compile "$f" 2>&1 || echo "Syntax error detected"
doneRepository: StabilityNexus/MiniChain Length of output: 238 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Find the file with correct fd syntax
fd 'test_transaction_signing_karun\.py$' | while read -r f; do
echo "== $f =="
echo "=== File line count ==="
wc -l "$f"
echo "=== Lines 130-160 ==="
cat -n "$f" | sed -n '130,160p'
doneRepository: StabilityNexus/MiniChain Length of output: 709 🏁 Script executed: #!/bin/bash
# Verify Python syntax
python3 -c "
import sys
import py_compile
try:
py_compile.compile('tests/test_transaction_signing_karun.py', doraise=True)
print('✓ File syntax is valid')
except py_compile.PyCompileError as e:
print(f'✗ Syntax error detected:')
print(e)
sys.exit(1)
"Repository: StabilityNexus/MiniChain Length of output: 181 Remove the orphaned indented string at EOF — it causes a Python IndentationError and prevents pytest collection. Line 144 is a standalone string literal with unexpected indentation at the end of the file. Python cannot parse it, causing an Fix- "Bob's balance should be 20 after receiving two transfers."📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.15.6)[warning] 144-144: Unexpected indentation (invalid-syntax) 🤖 Prompt for AI Agents |
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-add replay/nonce regression tests removed in this deletion area.
This change drops coverage for duplicate nonce rejection, skipped nonce rejection, and sequential nonce progression. Those behaviors are enforced in
minichain/state.py(Line 37-43 and Line 79-126), so removing these tests meaningfully weakens replay-protection safety.🧰 Tools
🪛 Ruff (0.15.6)
[warning] 144-144: Unexpected indentation
(invalid-syntax)
🤖 Prompt for AI Agents