@ -68,37 +68,47 @@ def test_bip21_encode():
} ) ==
} ) ==
' bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?label=Luke-Jr '
' bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?label=Luke-Jr '
)
)
# Both dictionary and list of tuples should work
assert (
assert (
btc . encode_bip21_uri ( ' 175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W ' , {
btc . encode_bip21_uri ( ' 175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W ' , [
' amount ' : 20.3 ,
( ' label ' , ' Luke-Jr ' )
' label ' : ' Luke-Jr '
] ) ==
} ) ==
' bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?label=Luke-Jr '
)
# Use list of tuples version for multiple parameter tests, as dicts don't
# have guaranteed ordering.
assert (
btc . encode_bip21_uri ( ' 175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W ' , [
( ' amount ' , 20.3 ) ,
( ' label ' , ' Luke-Jr ' )
] ) ==
' bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=20.3&label=Luke-Jr '
' bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=20.3&label=Luke-Jr '
)
)
assert (
assert (
btc . encode_bip21_uri ( ' 175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W ' , {
btc . encode_bip21_uri ( ' 175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W ' , [
' amount ' : 50 ,
( ' amount ' , 50 ) ,
' label ' : ' Luke-Jr ' ,
( ' label ' , ' Luke-Jr ' ) ,
' message ' : ' Donation for project xyz '
( ' message ' , ' Donation for project xyz ' )
} ) ==
] ) ==
' bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=50&label=Luke-Jr&message=Donation %20f or % 20project %20x yz '
' bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=50&label=Luke-Jr&message=Donation %20f or % 20project %20x yz '
)
)
assert (
assert (
btc . encode_bip21_uri ( ' 175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W ' , {
btc . encode_bip21_uri ( ' 175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W ' , [
' req-somethingyoudontunderstand ' : 50 ,
( ' req-somethingyoudontunderstand ' , 50 ) ,
' req-somethingelseyoudontget ' : 999
( ' req-somethingelseyoudontget ' , 999 )
} ) ==
] ) ==
' bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-somethingyoudontunderstand=50&req-somethingelseyoudontget=999 '
' bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-somethingyoudontunderstand=50&req-somethingelseyoudontget=999 '
)
)
assert (
assert (
btc . encode_bip21_uri ( ' 175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W ' , {
btc . encode_bip21_uri ( ' 175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W ' , [
' somethingyoudontunderstand ' : 50 ,
( ' somethingyoudontunderstand ' , 50 ) ,
' somethingelseyoudontget ' : 999
( ' somethingelseyoudontget ' , 999 )
} ) ==
] ) ==
' bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?somethingyoudontunderstand=50&somethingelseyoudontget=999 '
' bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?somethingyoudontunderstand=50&somethingelseyoudontget=999 '
)
)
# Invalid amounts must raise ValueError
# Invalid amounts must raise ValueError
with pytest . raises ( ValueError ) :
with pytest . raises ( ValueError ) :
# test dicts
btc . encode_bip21_uri ( ' 175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W ' , {
btc . encode_bip21_uri ( ' 175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W ' , {
' amount ' : ' '
' amount ' : ' '
} )
} )
@ -114,3 +124,20 @@ def test_bip21_encode():
btc . encode_bip21_uri ( ' 175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W ' , {
btc . encode_bip21_uri ( ' 175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W ' , {
' amount ' : ' 100000000 '
' amount ' : ' 100000000 '
} )
} )
# test list of tuples
btc . encode_bip21_uri ( ' 175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W ' , [
( ' amount ' , ' ' )
] )
btc . encode_bip21_uri ( ' 175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W ' , [
( ' amount ' , ' XYZ ' )
] )
btc . encode_bip21_uri ( ' 175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W ' , [
( ' amount ' , ' 100 \' 000 ' )
] )
btc . encode_bip21_uri ( ' 175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W ' , [
( ' amount ' , ' 100,000 ' )
] )
btc . encode_bip21_uri ( ' 175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W ' , [
( ' amount ' , ' 100000000 ' )
] )