@@ -417,6 +417,155 @@ fn map_query_params(uri: &Uri<&str>) -> Result<IndexMap<String, String>, Invoice
417
417
#[ cfg( test) ]
418
418
mod test {
419
419
use super :: * ;
420
+ use crate :: RgbInvoiceBuilder ;
421
+
422
+ #[ test]
423
+ fn display_chain ( ) {
424
+ let seal =
425
+ SecretSeal :: from_str ( "utxob:egXsFnw-5Eud7WKYn-7DVQvcPbc-rR69YmgmG-veacwmUFo-uMFKFb" )
426
+ . unwrap ( ) ;
427
+
428
+ // seal-based default
429
+ let invoice = RgbInvoiceBuilder :: rgb20_anything ( seal. clone ( ) ) . finish ( ) ;
430
+ assert_eq ! (
431
+ invoice. to_string( ) ,
432
+ "rgb:~/RGB20/utxob:egXsFnw-5Eud7WKYn-7DVQvcPbc-rR69YmgmG-veacwmUFo-uMFKFb"
433
+ ) ;
434
+
435
+ // seal-based bitcoin
436
+ let invoice = RgbInvoiceBuilder :: rgb20_anything ( seal. clone ( ) )
437
+ . set_chain ( Chain :: Bitcoin )
438
+ . unwrap ( )
439
+ . finish ( ) ;
440
+ assert_eq ! (
441
+ invoice. to_string( ) ,
442
+ "rgb:~/RGB20/utxob:egXsFnw-5Eud7WKYn-7DVQvcPbc-rR69YmgmG-veacwmUFo-uMFKFb"
443
+ ) ;
444
+
445
+ // seal-based testnet
446
+ let invoice = RgbInvoiceBuilder :: rgb20_anything ( seal. clone ( ) )
447
+ . set_chain ( Chain :: Testnet3 )
448
+ . unwrap ( )
449
+ . finish ( ) ;
450
+ assert_eq ! (
451
+ invoice. to_string( ) ,
452
+ "rgb:~/RGB20/utxob:egXsFnw-5Eud7WKYn-7DVQvcPbc-rR69YmgmG-veacwmUFo-uMFKFb?\
453
+ chain=testnet"
454
+ ) ;
455
+
456
+ let addr_bc = Address :: from_str ( "bc1qpws79r3ea4yy2ujsahwrmy2gutdj8w5whnhket" )
457
+ . unwrap ( )
458
+ . assume_checked ( ) ;
459
+ let addr_tc = Address :: from_str ( "mxVFsFW5N4mu1HPkxPttorvocvzeZ7KZyk" )
460
+ . unwrap ( )
461
+ . assume_checked ( ) ;
462
+
463
+ // address-based default
464
+ let invoice = RgbInvoiceBuilder :: rgb20_anything ( addr_bc. clone ( ) ) . finish ( ) ;
465
+ assert_eq ! ( invoice. to_string( ) , "rgb:~/RGB20/bc1qpws79r3ea4yy2ujsahwrmy2gutdj8w5whnhket" ) ;
466
+
467
+ // address-based bitcoin
468
+ let invoice = RgbInvoiceBuilder :: rgb20_anything ( addr_bc. clone ( ) )
469
+ . set_chain ( Chain :: Bitcoin )
470
+ . unwrap ( )
471
+ . finish ( ) ;
472
+ assert_eq ! ( invoice. to_string( ) , "rgb:~/RGB20/bc1qpws79r3ea4yy2ujsahwrmy2gutdj8w5whnhket" ) ;
473
+
474
+ // address-based testnet - mismatching
475
+ assert ! (
476
+ RgbInvoiceBuilder :: rgb20_anything( addr_bc. clone( ) )
477
+ . set_chain( Chain :: Testnet3 )
478
+ . is_err( )
479
+ ) ;
480
+
481
+ // address-based testnet
482
+ let invoice = RgbInvoiceBuilder :: rgb20_anything ( addr_tc. clone ( ) )
483
+ . set_chain ( Chain :: Testnet3 )
484
+ . unwrap ( )
485
+ . finish ( ) ;
486
+ assert_eq ! ( invoice. to_string( ) , "rgb:~/RGB20/mxVFsFW5N4mu1HPkxPttorvocvzeZ7KZyk" ) ;
487
+
488
+ // address-based regtest - mismatching
489
+ assert ! (
490
+ RgbInvoiceBuilder :: rgb20_anything( addr_tc. clone( ) )
491
+ . set_chain( Chain :: Regtest )
492
+ . is_err( )
493
+ ) ;
494
+ }
495
+
496
+ #[ test]
497
+ fn from_str_chain ( ) {
498
+ let invoice = RgbInvoice :: from_str (
499
+ "rgb:~/RGB20/utxob:egXsFnw-5Eud7WKYn-7DVQvcPbc-rR69YmgmG-veacwmUFo-uMFKFb" ,
500
+ )
501
+ . unwrap ( ) ;
502
+ assert_eq ! ( invoice. chain, None ) ;
503
+
504
+ let invoice = RgbInvoice :: from_str (
505
+ "rgb:~/RGB20/utxob:egXsFnw-5Eud7WKYn-7DVQvcPbc-rR69YmgmG-veacwmUFo-uMFKFb?\
506
+ chain=testnet",
507
+ )
508
+ . unwrap ( ) ;
509
+ assert_eq ! ( invoice. chain, Some ( Chain :: Testnet3 ) ) ;
510
+
511
+ let invoice = RgbInvoice :: from_str (
512
+ "rgb:~/RGB20/utxob:egXsFnw-5Eud7WKYn-7DVQvcPbc-rR69YmgmG-veacwmUFo-uMFKFb?\
513
+ chain=testnet3",
514
+ )
515
+ . unwrap ( ) ;
516
+ assert_eq ! ( invoice. chain, Some ( Chain :: Testnet3 ) ) ;
517
+
518
+ let invoice = RgbInvoice :: from_str (
519
+ "rgb:~/RGB20/utxob:egXsFnw-5Eud7WKYn-7DVQvcPbc-rR69YmgmG-veacwmUFo-uMFKFb?chain=signet" ,
520
+ )
521
+ . unwrap ( ) ;
522
+ assert_eq ! ( invoice. chain, Some ( Chain :: Signet ) ) ;
523
+
524
+ let invoice = RgbInvoice :: from_str (
525
+ "rgb:~/RGB20/utxob:egXsFnw-5Eud7WKYn-7DVQvcPbc-rR69YmgmG-veacwmUFo-uMFKFb?\
526
+ chain=regtest",
527
+ )
528
+ . unwrap ( ) ;
529
+ assert_eq ! ( invoice. chain, Some ( Chain :: Regtest ) ) ;
530
+
531
+ let invoice =
532
+ RgbInvoice :: from_str ( "rgb:~/RGB20/bc1qpws79r3ea4yy2ujsahwrmy2gutdj8w5whnhket" ) . unwrap ( ) ;
533
+ assert_eq ! ( invoice. chain, None ) ;
534
+
535
+ let invoice = RgbInvoice :: from_str (
536
+ "rgb:~/RGB20/bc1qpws79r3ea4yy2ujsahwrmy2gutdj8w5whnhket?chain=bitcoin" ,
537
+ )
538
+ . unwrap ( ) ;
539
+ assert_eq ! ( invoice. chain, Some ( Chain :: Bitcoin ) ) ;
540
+
541
+ assert_eq ! (
542
+ RgbInvoice :: from_str(
543
+ "rgb:~/RGB20/bc1qpws79r3ea4yy2ujsahwrmy2gutdj8w5whnhket?chain=testnet" ,
544
+ ) ,
545
+ Err ( InvoiceParseError :: ChainMismatch {
546
+ chain: Chain :: Testnet3 ,
547
+ addr_chain: Chain :: Bitcoin
548
+ } )
549
+ ) ;
550
+
551
+ let invoice =
552
+ RgbInvoice :: from_str ( "rgb:~/RGB20/mxVFsFW5N4mu1HPkxPttorvocvzeZ7KZyk?chain=testnet" )
553
+ . unwrap ( ) ;
554
+ assert_eq ! ( invoice. chain, Some ( Chain :: Testnet3 ) ) ;
555
+
556
+ let invoice =
557
+ RgbInvoice :: from_str ( "rgb:~/RGB20/mxVFsFW5N4mu1HPkxPttorvocvzeZ7KZyk?chain=signet" )
558
+ . unwrap ( ) ;
559
+ assert_eq ! ( invoice. chain, Some ( Chain :: Signet ) ) ;
560
+
561
+ assert_eq ! (
562
+ RgbInvoice :: from_str( "rgb:~/RGB20/mxVFsFW5N4mu1HPkxPttorvocvzeZ7KZyk?chain=regtest" , ) ,
563
+ Err ( InvoiceParseError :: ChainMismatch {
564
+ chain: Chain :: Regtest ,
565
+ addr_chain: Chain :: Testnet3
566
+ } )
567
+ ) ;
568
+ }
420
569
421
570
#[ test]
422
571
fn parse ( ) {
0 commit comments