@@ -427,27 +427,18 @@ mod tests {
427
427
use ln:: features:: OfferFeatures ;
428
428
use onion_message:: { BlindedHop , BlindedPath } ;
429
429
430
- fn pubkey ( ) -> PublicKey {
430
+ fn pubkey ( byte : u8 ) -> PublicKey {
431
431
let secp_ctx = Secp256k1 :: new ( ) ;
432
- PublicKey :: from_secret_key ( & secp_ctx, & privkey ( ) )
432
+ PublicKey :: from_secret_key ( & secp_ctx, & privkey ( byte ) )
433
433
}
434
434
435
- fn privkey ( ) -> SecretKey {
436
- SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( )
437
- }
438
-
439
- fn blinded_pubkey ( byte : u8 ) -> PublicKey {
440
- let secp_ctx = Secp256k1 :: new ( ) ;
441
- PublicKey :: from_secret_key ( & secp_ctx, & blinded_privkey ( byte) )
442
- }
443
-
444
- fn blinded_privkey ( byte : u8 ) -> SecretKey {
435
+ fn privkey ( byte : u8 ) -> SecretKey {
445
436
SecretKey :: from_slice ( & [ byte; 32 ] ) . unwrap ( )
446
437
}
447
438
448
439
#[ test]
449
440
fn builds_offer_with_defaults ( ) {
450
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) ) . build ( ) ;
441
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) ) . build ( ) ;
451
442
let tlv_stream = offer. as_tlv_stream ( ) ;
452
443
453
444
assert_eq ! ( offer. as_bytes( ) , & offer. to_bytes( ) [ ..] ) ;
@@ -463,7 +454,7 @@ mod tests {
463
454
assert_eq ! ( offer. issuer( ) , None ) ;
464
455
assert_eq ! ( offer. quantity_min( ) , 1 ) ;
465
456
assert_eq ! ( offer. quantity_max( ) , 1 ) ;
466
- assert_eq ! ( offer. node_id( ) , pubkey( ) ) ;
457
+ assert_eq ! ( offer. node_id( ) , pubkey( 42 ) ) ;
467
458
468
459
assert_eq ! ( tlv_stream. chains, None ) ;
469
460
assert_eq ! ( tlv_stream. metadata, None ) ;
@@ -476,7 +467,7 @@ mod tests {
476
467
assert_eq ! ( tlv_stream. issuer, None ) ;
477
468
assert_eq ! ( tlv_stream. quantity_min, None ) ;
478
469
assert_eq ! ( tlv_stream. quantity_max, None ) ;
479
- assert_eq ! ( tlv_stream. node_id, Some ( & pubkey( ) ) ) ;
470
+ assert_eq ! ( tlv_stream. node_id, Some ( & pubkey( 42 ) ) ) ;
480
471
}
481
472
482
473
#[ test]
@@ -487,20 +478,20 @@ mod tests {
487
478
ChainHash :: using_genesis_block( Network :: Testnet ) ,
488
479
] ;
489
480
490
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
481
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
491
482
. chain ( Network :: Bitcoin )
492
483
. build ( ) ;
493
484
assert_eq ! ( offer. chains( ) , vec![ chain] ) ;
494
485
assert_eq ! ( offer. as_tlv_stream( ) . chains, Some ( & vec![ chain] ) ) ;
495
486
496
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
487
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
497
488
. chain ( Network :: Bitcoin )
498
489
. chain ( Network :: Bitcoin )
499
490
. build ( ) ;
500
491
assert_eq ! ( offer. chains( ) , vec![ chain] ) ;
501
492
assert_eq ! ( offer. as_tlv_stream( ) . chains, Some ( & vec![ chain] ) ) ;
502
493
503
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
494
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
504
495
. chain ( Network :: Bitcoin )
505
496
. chain ( Network :: Testnet )
506
497
. build ( ) ;
@@ -510,13 +501,13 @@ mod tests {
510
501
511
502
#[ test]
512
503
fn builds_offer_with_metadata ( ) {
513
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
504
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
514
505
. metadata ( vec ! [ 42 ; 32 ] )
515
506
. build ( ) ;
516
507
assert_eq ! ( offer. metadata( ) , Some ( & vec![ 42 ; 32 ] ) ) ;
517
508
assert_eq ! ( offer. as_tlv_stream( ) . metadata, Some ( & vec![ 42 ; 32 ] ) ) ;
518
509
519
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
510
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
520
511
. metadata ( vec ! [ 42 ; 32 ] )
521
512
. metadata ( vec ! [ 43 ; 32 ] )
522
513
. build ( ) ;
@@ -529,23 +520,23 @@ mod tests {
529
520
let bitcoin_amount = Amount :: Bitcoin { amount_msats : 1000 } ;
530
521
let currency_amount = Amount :: Currency { iso4217_code : * b"USD" , amount : 10 } ;
531
522
532
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
523
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
533
524
. amount ( bitcoin_amount. clone ( ) )
534
525
. build ( ) ;
535
526
let tlv_stream = offer. as_tlv_stream ( ) ;
536
527
assert_eq ! ( offer. amount( ) , Some ( & bitcoin_amount) ) ;
537
528
assert_eq ! ( tlv_stream. amount, Some ( 1000 ) ) ;
538
529
assert_eq ! ( tlv_stream. currency, None ) ;
539
530
540
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
531
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
541
532
. amount ( currency_amount. clone ( ) )
542
533
. build ( ) ;
543
534
let tlv_stream = offer. as_tlv_stream ( ) ;
544
535
assert_eq ! ( offer. amount( ) , Some ( & currency_amount) ) ;
545
536
assert_eq ! ( tlv_stream. amount, Some ( 10 ) ) ;
546
537
assert_eq ! ( tlv_stream. currency, Some ( b"USD" ) ) ;
547
538
548
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
539
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
549
540
. amount ( currency_amount. clone ( ) )
550
541
. amount ( bitcoin_amount. clone ( ) )
551
542
. build ( ) ;
@@ -556,13 +547,13 @@ mod tests {
556
547
557
548
#[ test]
558
549
fn builds_offer_with_features ( ) {
559
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
550
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
560
551
. features ( OfferFeatures :: empty ( ) )
561
552
. build ( ) ;
562
553
assert_eq ! ( offer. features( ) , Some ( & OfferFeatures :: empty( ) ) ) ;
563
554
assert_eq ! ( offer. as_tlv_stream( ) . features, Some ( & OfferFeatures :: empty( ) ) ) ;
564
555
565
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
556
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
566
557
. features ( OfferFeatures :: unknown ( ) )
567
558
. features ( OfferFeatures :: empty ( ) )
568
559
. build ( ) ;
@@ -575,15 +566,15 @@ mod tests {
575
566
let future_expiry = Duration :: from_secs ( u64:: max_value ( ) ) ;
576
567
let past_expiry = Duration :: from_secs ( 0 ) ;
577
568
578
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
569
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
579
570
. absolute_expiry ( future_expiry)
580
571
. build ( ) ;
581
572
#[ cfg( feature = "std" ) ]
582
573
assert ! ( !offer. is_expired( ) ) ;
583
574
assert_eq ! ( offer. absolute_expiry( ) , Some ( future_expiry) ) ;
584
575
assert_eq ! ( offer. as_tlv_stream( ) . absolute_expiry, Some ( future_expiry. as_secs( ) ) ) ;
585
576
586
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
577
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
587
578
. absolute_expiry ( future_expiry)
588
579
. absolute_expiry ( past_expiry)
589
580
. build ( ) ;
@@ -595,55 +586,46 @@ mod tests {
595
586
596
587
#[ test]
597
588
fn builds_offer_with_paths ( ) {
598
- // TODO: Use more realistic data
599
589
let paths = vec ! [
600
590
BlindedPath {
601
- introduction_node_id: pubkey( ) ,
602
- blinding_point: pubkey( ) ,
591
+ introduction_node_id: pubkey( 40 ) ,
592
+ blinding_point: pubkey( 41 ) ,
603
593
blinded_hops: vec![
604
- BlindedHop {
605
- blinded_node_id: blinded_pubkey( 43 ) , encrypted_payload: vec![ 0 ; 43 ] ,
606
- } ,
607
- BlindedHop {
608
- blinded_node_id: blinded_pubkey( 44 ) , encrypted_payload: vec![ 0 ; 44 ] ,
609
- } ,
594
+ BlindedHop { blinded_node_id: pubkey( 43 ) , encrypted_payload: vec![ 0 ; 43 ] } ,
595
+ BlindedHop { blinded_node_id: pubkey( 44 ) , encrypted_payload: vec![ 0 ; 44 ] } ,
610
596
] ,
611
597
} ,
612
598
BlindedPath {
613
- introduction_node_id: pubkey( ) ,
614
- blinding_point: pubkey( ) ,
599
+ introduction_node_id: pubkey( 40 ) ,
600
+ blinding_point: pubkey( 41 ) ,
615
601
blinded_hops: vec![
616
- BlindedHop {
617
- blinded_node_id: blinded_pubkey( 45 ) , encrypted_payload: vec![ 0 ; 45 ] ,
618
- } ,
619
- BlindedHop {
620
- blinded_node_id: blinded_pubkey( 46 ) , encrypted_payload: vec![ 0 ; 46 ] ,
621
- } ,
602
+ BlindedHop { blinded_node_id: pubkey( 45 ) , encrypted_payload: vec![ 0 ; 45 ] } ,
603
+ BlindedHop { blinded_node_id: pubkey( 46 ) , encrypted_payload: vec![ 0 ; 46 ] } ,
622
604
] ,
623
605
} ,
624
606
] ;
625
607
626
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
608
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
627
609
. path ( paths[ 0 ] . clone ( ) )
628
610
. path ( paths[ 1 ] . clone ( ) )
629
611
. build ( ) ;
630
612
let tlv_stream = offer. as_tlv_stream ( ) ;
631
613
assert_eq ! ( offer. paths( ) , Some ( & paths) ) ;
632
- assert_eq ! ( offer. node_id( ) , pubkey( ) ) ;
633
- assert_ne ! ( pubkey( ) , blinded_pubkey ( 44 ) ) ;
614
+ assert_eq ! ( offer. node_id( ) , pubkey( 42 ) ) ;
615
+ assert_ne ! ( pubkey( 42 ) , pubkey ( 44 ) ) ;
634
616
assert_eq ! ( tlv_stream. paths, Some ( & paths) ) ;
635
- assert_eq ! ( tlv_stream. node_id, Some ( & pubkey( ) ) ) ;
617
+ assert_eq ! ( tlv_stream. node_id, Some ( & pubkey( 42 ) ) ) ;
636
618
}
637
619
638
620
#[ test]
639
621
fn builds_offer_with_issuer ( ) {
640
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
622
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
641
623
. issuer ( "bar" . into ( ) )
642
624
. build ( ) ;
643
625
assert_eq ! ( offer. issuer( ) , Some ( & String :: from( "bar" ) ) ) ;
644
626
assert_eq ! ( offer. as_tlv_stream( ) . issuer, Some ( & String :: from( "bar" ) ) ) ;
645
627
646
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
628
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
647
629
. issuer ( "bar" . into ( ) )
648
630
. issuer ( "baz" . into ( ) )
649
631
. build ( ) ;
@@ -657,7 +639,7 @@ mod tests {
657
639
let five = NonZeroU64 :: new ( 5 ) . unwrap ( ) ;
658
640
let ten = NonZeroU64 :: new ( 10 ) . unwrap ( ) ;
659
641
660
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
642
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
661
643
. quantity_fixed ( one)
662
644
. build ( ) ;
663
645
let tlv_stream = offer. as_tlv_stream ( ) ;
@@ -666,7 +648,7 @@ mod tests {
666
648
assert_eq ! ( tlv_stream. quantity_min, None ) ;
667
649
assert_eq ! ( tlv_stream. quantity_max, None ) ;
668
650
669
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
651
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
670
652
. quantity_fixed ( ten)
671
653
. build ( ) ;
672
654
let tlv_stream = offer. as_tlv_stream ( ) ;
@@ -675,7 +657,7 @@ mod tests {
675
657
assert_eq ! ( tlv_stream. quantity_min, Some ( 10 ) ) ;
676
658
assert_eq ! ( tlv_stream. quantity_max, Some ( 10 ) ) ;
677
659
678
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
660
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
679
661
. quantity_fixed ( ten)
680
662
. quantity_fixed ( five)
681
663
. build ( ) ;
@@ -685,7 +667,7 @@ mod tests {
685
667
assert_eq ! ( tlv_stream. quantity_min, Some ( 5 ) ) ;
686
668
assert_eq ! ( tlv_stream. quantity_max, Some ( 5 ) ) ;
687
669
688
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
670
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
689
671
. quantity_range ( ..ten)
690
672
. quantity_fixed ( five)
691
673
. build ( ) ;
@@ -702,7 +684,7 @@ mod tests {
702
684
let five = NonZeroU64 :: new ( 5 ) . unwrap ( ) ;
703
685
let ten = NonZeroU64 :: new ( 10 ) . unwrap ( ) ;
704
686
705
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
687
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
706
688
. quantity_range ( ..)
707
689
. build ( ) ;
708
690
let tlv_stream = offer. as_tlv_stream ( ) ;
@@ -711,7 +693,7 @@ mod tests {
711
693
assert_eq ! ( tlv_stream. quantity_min, Some ( 1 ) ) ;
712
694
assert_eq ! ( tlv_stream. quantity_max, None ) ;
713
695
714
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
696
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
715
697
. quantity_range ( ..ten)
716
698
. build ( ) ;
717
699
let tlv_stream = offer. as_tlv_stream ( ) ;
@@ -720,7 +702,7 @@ mod tests {
720
702
assert_eq ! ( tlv_stream. quantity_min, None ) ;
721
703
assert_eq ! ( tlv_stream. quantity_max, Some ( 9 ) ) ;
722
704
723
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
705
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
724
706
. quantity_range ( one..ten)
725
707
. build ( ) ;
726
708
let tlv_stream = offer. as_tlv_stream ( ) ;
@@ -729,7 +711,7 @@ mod tests {
729
711
assert_eq ! ( tlv_stream. quantity_min, None ) ;
730
712
assert_eq ! ( tlv_stream. quantity_max, Some ( 9 ) ) ;
731
713
732
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
714
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
733
715
. quantity_range ( five..=ten)
734
716
. build ( ) ;
735
717
let tlv_stream = offer. as_tlv_stream ( ) ;
@@ -739,7 +721,7 @@ mod tests {
739
721
assert_eq ! ( tlv_stream. quantity_max, Some ( 10 ) ) ;
740
722
741
723
let one = NonZeroU64 :: new ( 1 ) . unwrap ( ) ;
742
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
724
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
743
725
. quantity_range ( one..=one)
744
726
. build ( ) ;
745
727
let tlv_stream = offer. as_tlv_stream ( ) ;
@@ -748,7 +730,7 @@ mod tests {
748
730
assert_eq ! ( tlv_stream. quantity_min, None ) ;
749
731
assert_eq ! ( tlv_stream. quantity_max, None ) ;
750
732
751
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
733
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
752
734
. quantity_range ( five..=five)
753
735
. build ( ) ;
754
736
let tlv_stream = offer. as_tlv_stream ( ) ;
@@ -757,7 +739,7 @@ mod tests {
757
739
assert_eq ! ( tlv_stream. quantity_min, Some ( 5 ) ) ;
758
740
assert_eq ! ( tlv_stream. quantity_max, Some ( 5 ) ) ;
759
741
760
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
742
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
761
743
. quantity_range ( ten..five)
762
744
. build ( ) ;
763
745
let tlv_stream = offer. as_tlv_stream ( ) ;
@@ -766,7 +748,7 @@ mod tests {
766
748
assert_eq ! ( tlv_stream. quantity_min, None ) ;
767
749
assert_eq ! ( tlv_stream. quantity_max, None ) ;
768
750
769
- let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( ) )
751
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
770
752
. quantity_fixed ( five)
771
753
. quantity_range ( ..ten)
772
754
. build ( ) ;
0 commit comments