Python 3 library and CLI application for SporeStack
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.1 KiB

  1. from . import utilities
  2. import pytest
  3. def test_payment_to_uri():
  4. address = "1xm4vFerV3pSgvBFkyzLgT1Ew3HQYrS1V"
  5. currency = "btc"
  6. amount = 12345678
  7. output = utilities.payment_to_uri(address=address, currency=currency, amount=amount)
  8. expected = "bitcoin:1xm4vFerV3pSgvBFkyzLgT1Ew3HQYrS1V?amount=0.12345678"
  9. assert output == expected
  10. address = "1xm4vFerV3pSgvBFkyzLgT1Ew3HQYrS1V"
  11. currency = "bsv"
  12. amount = 200000000
  13. output = utilities.payment_to_uri(address=address, currency=currency, amount=amount)
  14. expected = "bitcoin:1xm4vFerV3pSgvBFkyzLgT1Ew3HQYrS1V?amount=2.00000000"
  15. assert output == expected
  16. address = "bitcoincash:qq9gh20y2vur63tpe0xa5dh90zwzsuxagyhp7pfuv3"
  17. currency = "bch"
  18. amount = 1000001
  19. output = utilities.payment_to_uri(address=address, currency=currency, amount=amount)
  20. expected = address + "?amount=0.01000001"
  21. assert output == expected
  22. address = "85rBW1Afx7TSteLwk4xfXcH57v7JzgsnRMi1cJugQatXTNB1gqbf"
  23. address += "vcP47iPXXU1yqgJofrShLzKnBYBmMCTSSw2h1iaQs8h"
  24. currency = "xmr"
  25. amount = 1000001
  26. output = utilities.payment_to_uri(address=address, currency=currency, amount=amount)
  27. # piconeros are smaller than Satoshis.
  28. expected = "monero:" + address + "?tx_amount=0.000001000001"
  29. assert output == expected
  30. # Negative tests.
  31. with pytest.raises(ValueError):
  32. utilities.payment_to_uri(address=address, currency="xxx", amount=amount)
  33. with pytest.raises(TypeError):
  34. utilities.payment_to_uri(address=address, currency=currency, amount="100")
  35. def test_cents_to_usd():
  36. output = utilities.cents_to_usd(1)
  37. assert output == "$0.01"
  38. output = utilities.cents_to_usd(10)
  39. assert output == "$0.10"
  40. output = utilities.cents_to_usd(100)
  41. assert output == "$1.00"
  42. output = utilities.cents_to_usd(123456)
  43. assert output == "$1,234.56"
  44. with pytest.raises(TypeError):
  45. utilities.cents_to_usd(None)
  46. with pytest.raises(TypeError):
  47. utilities.cents_to_usd(-1)
  48. with pytest.raises(TypeError):
  49. utilities.cents_to_usd("10")