
import pytest

from electrumpersonalserver.server import parse_electrum_master_public_key


@pytest.mark.parametrize(
    "bad_master_public_key",
    [
    "<KEY>" +
    "<KEY>", #bad checksum
    "<KEY>" +
    "<KEY>" +
    "<KEY>" +
    "T74sszGaxaf64o5s", #unparsable m number
    "<KEY>" +
    "<KEY>" +
    "<KEY>" +
    "ADjmcCs3arSoxN3F3r", #inconsistent magic
    "e9d4b7866dd1e91c862aebf62a49548c7dbf7bcc6e4b7b8c9da820c7737968df9c09d" +
    "<KEY>", #wrong length
    "e9d4b7866dd1e91c862aebf62a49548c7dbf7bcc6e4b7b8c9da820c7737968df9c09d" +
    "<KEY>" #not hex
    ]
)

def test_parse_bad_mpk(bad_master_public_key):
    try:
        parse_electrum_master_public_key(bad_master_public_key, 5)
        raised_error = False
    except (ValueError, Exception):
        raised_error = True
    assert raised_error


import pytest

from electrumpersonalserver.server import parse_electrum_master_public_key


@pytest.mark.parametrize(
    "bad_master_public_key",
    [
    "<KEY>" +
    "<KEY>", #bad checksum
    "<KEY>" +
    "<KEY>" +
    "<KEY>" +
    "T74sszGaxaf64o5s", #unparsable m number
    "<KEY>" +
    "<KEY>" +
    "<KEY>" +
    "ADjmcCs3arSoxN3F3r", #inconsistent magic
    "e9d4b7866dd1e91c862aebf62a49548c7dbf7bcc6e4b7b8c9da820c7737968df9c09d" +
    "<KEY>", #wrong length
    "e9d4b7866dd1e91c862aebf62a49548c7dbf7bcc6e4b7b8c9da820c7737968df9c09d" +
    "<KEY>" #not hex
    ]
)

def test_parse_bad_mpk(bad_master_public_key):
    try:
        parse_electrum_master_public_key(bad_master_public_key, 5)
        raised_error = False
    except (ValueError, Exception):
        raised_error = True
    assert raised_error

#bad checksum #unparsable m number #inconsistent magic #wrong length #not hex