<reponame>Bladez1753/lightning
from pyln.proto import Invoice
from decimal import Decimal
from bitstring import ConstBitStream
import binascii


def test_decode():
    i = '<KEY>'
    inv = Invoice.decode(i)

    assert(inv.hexpubkey == '<KEY>')
    assert(inv.hexpaymenthash == '76272b9b95b14eb6bece3cd051006d8aabac63c3a50bd7ea2bb53612b0a9324b')
    assert(inv.min_final_cltv_expiry == 5)
    assert(inv.amount == Decimal('0.000001'))
    assert(inv.featurebits == ConstBitStream('0x28200'))
    print(inv)


def test_encode():
    inv = Invoice(paymenthash=binascii.unhexlify("76272b9b95b14eb6bece3cd051006d8aabac63c3a50bd7ea2bb53612b0a9324b"),
                  amount=Decimal('0.000001'),
                  tags=[('d', 'test_pay_routeboost2'),
                        ('x', 604800)],
                  date=1579298293)
    privkey = 'c28a9f80738f770d527803a566cf6fc3edf6cea586c4fc4a5223a5ad797e1ac3'
    i = inv.encode(privkey)
    assert(i == '<KEY>')
