Skip to content

Commit

Permalink
migrate cancel.py tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Jan 22, 2025
1 parent 9008617 commit cd9c3a1
Showing 1 changed file with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
from counterpartycore.lib.messages import cancel


def test_compose(ledger_db, defaults):
open_order = ledger_db.execute(
def get_open_order(ledger_db):
return ledger_db.execute(
"""
SELECT * FROM
(SELECT tx_hash, status, source, MAX(rowid) FROM orders GROUP BY tx_hash)
WHERE status='open' ORDER BY tx_hash DESC LIMIT 1
"""
).fetchone()


def test_compose(ledger_db, defaults):
open_order = get_open_order(ledger_db)

assert cancel.compose(ledger_db, open_order["source"], open_order["tx_hash"]) == (
open_order["source"],
[],
Expand All @@ -31,3 +35,35 @@ def test_compose(ledger_db, defaults):

with pytest.raises(exceptions.ComposeError, match="offer not open"):
cancel.compose(ledger_db, closed_bet["source"], closed_bet["tx_hash"])


def test_parse_cancel_order(ledger_db, blockchain_mock, test_helpers, current_block_index):
open_order = get_open_order(ledger_db)
tx = blockchain_mock.dummy_tx(ledger_db, open_order["source"])
message = b"\xe1\xba\xf7\xedl\x87\xc1\x99\xd3\xff\x8e\xb9\x00@\x03\xf0\xf6H\x1a\x1ePV+\x16<P\x08\xa4\xd7]7}"

cancel.parse(ledger_db, tx, message)
test_helpers.check_records(
ledger_db,
[
{
"table": "cancels",
"values": {
"block_index": tx["block_index"],
"offer_hash": open_order["tx_hash"],
"source": open_order["source"],
"status": "valid",
"tx_hash": tx["tx_hash"],
"tx_index": tx["tx_index"],
},
},
{
"table": "orders",
"values": {
"status": "cancelled",
"tx_hash": open_order["tx_hash"],
"block_index": current_block_index,
},
},
],
)

0 comments on commit cd9c3a1

Please sign in to comment.