Skip to content

Commit

Permalink
finish to migrate messagetype.py tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Jan 27, 2025
1 parent 91a7da0 commit ed36e39
Showing 1 changed file with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import binascii

from counterpartycore.lib import config
from counterpartycore.lib.parser import messagetype
from counterpartycore.pytest.mocks.counterpartydbs import ProtocolChangesDisabled

Expand Down Expand Up @@ -33,3 +34,57 @@ def test_pack():

assert messagetype.pack(1, 310502) == binascii.unhexlify("01")
assert messagetype.pack(2, 310502) == binascii.unhexlify("02")


def test_get_transaction_type(monkeypatch, current_block_index):
assert messagetype.get_transaction_type(b"CNTRPRTY00", "", [], current_block_index) == "unknown"
assert (
messagetype.get_transaction_type(b"[A95428957753448833|1", "", [], current_block_index)
== "fairmint"
)
assert messagetype.get_transaction_type(None, "", ["txid:0"], current_block_index) == "utxomove"
assert messagetype.get_transaction_type(None, "", [""], current_block_index) == "unknown"
assert (
messagetype.get_transaction_type(b"eXCPMEME|25000000000|", "", [], current_block_index)
== "attach"
)
assert (
messagetype.get_transaction_type(
b"fbc1qcxlwq8x9fnhyhgywlnja35l7znt58tud9duqay", "", [], current_block_index
)
== "detach"
)
assert (
messagetype.get_transaction_type(
b"\x02\x00>\xc7\xd9>|n\x19\x00\x00\x00\x00\x00\x00\x00P\x00%?\x9e\x96I\xb3\xf9u\x15$\xb2\x90\xf93Pra\x0c\xcc\x01",
"",
[],
current_block_index,
)
== "enhanced_send"
)
assert (
messagetype.get_transaction_type(
None, config.UNSPENDABLE_TESTNET, [""], config.BURN_END - 1
)
== "burn"
)
assert (
messagetype.get_transaction_type(
None, config.UNSPENDABLE_TESTNET, [""], config.BURN_END + 1
)
== "unknown"
)

def mock_get_change_block_index(change_name):
if change_name == "dispensers":
return current_block_index - 1
if change_name == "disable_vanilla_btc_dispense":
return current_block_index + 1
return 0

monkeypatch.setattr(
"counterpartycore.lib.parser.protocol.get_change_block_index", mock_get_change_block_index
)
with ProtocolChangesDisabled(["utx_support"]):
assert messagetype.get_transaction_type(None, "", [""], current_block_index) == "dispense"

0 comments on commit ed36e39

Please sign in to comment.