import pytest
from argparse import Namespace
import validate_address as va




# Notes:
# - "work directory" = directory that contains this file.
# - Running the command {pytest test_validate_address.py} in the work directory should load and run the tests in this file.
# - Run a specific test:
# -- pytest test_validate_address.py::test_valid_address
# - Run quietly:
# -- pytest -q test_validate_address.py
# - Print log data during a single test:
# -- pytest -o log_cli=true --log-cli-level=DEBUG --log-format="%(levelname)s [%(lineno)s: %(funcName)s] %(message)s" test_validate_address.py::test_valid_address
# -- This is very useful when you want to manually check the operation of the functions during the test.




# Rename function for convenience. 
f1 = va.validateBitcoinAddress




### TEST SECTION
# Basic domain checks.


def test_none():
	with pytest.raises(TypeError):
		f1(None)


def test_empty_string():
	with pytest.raises(ValueError):
		f1('')


def test_bad_first_character():
	with pytest.raises(ValueError):
		f1('5QAZz5b4MzqG64Loq3qsvAQiwHqweY7mbT')


def test_valid_address():
	f1('1QAZz5b4MzqG64Loq3qsvAQiwHqweY7mbT')


def test_bad_last_character():
	# this means that the checksum is incorrect.
	with pytest.raises(ValueError):
		f1('1QAZz5b4MzqG64Loq3qsvAQiwHqweY7mbS')




### TEST SECTION
# Test data source:
# http://edgecase.net/articles/bitcoin_address_test_set


# Test the address test set in one go.
addresses = [	
	'19VdGCFG8QH3CmYXjMXd3UQCK2HdC3UodP',
	'1FJdRWN7tAd8rnivBm7yojppwvDmS7F55X',
	'138obEZkdWaWEQ4x8ZAYw4MybHSZtX1Nam',
	'13xPBB175FtPbPQ84iB8KuawaVy3mHrady', 
	'1AGygbyEFYduWkkmZbbvirgS9kuBBMLJCP',
	'1vkb4YyPMFcxyC83Z5m5zuN45xASoHeNK',
	'17rEGTR4ss7xhVVMwL969Y8xszS7FaFsae',
	'16ASCUS3s7D4UQh6J9oHGuT19agPvD3PFj',
	'1KHDLNmqBtiBELUsmTCkNASg79jfEVKrig',
	'1DLg5i1kBjXYXy9f82xZcHokEMC9dtct7P',
	'17pNyD9ur28aBgPhHtAFi6fAyrvgshp5yn',
	'1PFw45xp5JUcLZfDQnMpto6yJpcjRLqrJ8',
	'19u4WSjpp19yoAK9kdRyY9HJ7ad2S8s1E4',
	'17PZ6uyL59vPirNqqpMnB1kjEXkU7ske7s',
	'15BLTZb6uQr24MrxqXJaPpRGz1tKrzq7iC',
]


@pytest.mark.parametrize('address', addresses)
def test_multiple_addresses(address):
	# all addresses should be valid i.e. not cause an error.
	f1(address)