| 617 | |
| 618 | #[test] |
| 619 | fn test_htlc_accepted_hook() { |
| 620 | let r = serde_json::json!({ |
| 621 | "peer_id": "02df5ffe895c778e10f7742a6c5b8a0cefbe9465df58b92fadeb883752c8107c8f", |
| 622 | "onion": { |
| 623 | "payload": "", |
| 624 | "short_channel_id": "1x2x3", |
| 625 | "forward_msat": 42, |
| 626 | "outgoing_cltv_value": 500014, |
| 627 | "shared_secret": "0000000000000000000000000000000000000000000000000000000000000000", |
| 628 | "next_onion": "[1365bytes of serialized onion]" |
| 629 | }, |
| 630 | "htlc": { |
| 631 | "short_channel_id": "4x5x6", |
| 632 | "id": 27, |
| 633 | "amount_msat": 43, |
| 634 | "cltv_expiry": 500028, |
| 635 | "cltv_expiry_relative": 10, |
| 636 | "payment_hash": "0000000000000000000000000000000000000000000000000000000000000000", |
| 637 | "extra_tlvs": "fdffff012afe00010001020539" |
| 638 | }, |
| 639 | "forward_to": "0000000000000000000000000000000000000000000000000000000000000000" |
| 640 | }); |
| 641 | let d: HtlcAcceptedEvent = serde_json::from_value(r).unwrap(); |
| 642 | assert_eq!( |
| 643 | d.peer_id.unwrap().to_string(), |
| 644 | "02df5ffe895c778e10f7742a6c5b8a0cefbe9465df58b92fadeb883752c8107c8f" |
| 645 | ); |
| 646 | |
| 647 | assert_eq!(d.onion.payload, ""); |
| 648 | assert_eq!(d.onion.short_channel_id.unwrap().to_string(), "1x2x3"); |
| 649 | assert_eq!(d.onion.forward_msat.unwrap(), Amount::from_msat(42)); |
| 650 | assert_eq!(d.onion.outgoing_cltv_value.unwrap(), 500014); |
| 651 | assert_eq!( |
| 652 | hex::encode(d.onion.shared_secret.to_vec()), |
| 653 | "0000000000000000000000000000000000000000000000000000000000000000" |
| 654 | ); |
| 655 | assert_eq!(d.onion.next_onion, "[1365bytes of serialized onion]"); |
| 656 | |
| 657 | assert_eq!(d.htlc.short_channel_id.to_string(), "4x5x6"); |
| 658 | assert_eq!(d.htlc.id, 27); |
| 659 | assert_eq!(d.htlc.amount_msat, Amount::from_msat(43)); |
| 660 | assert_eq!(d.htlc.cltv_expiry, 500028); |
| 661 | assert_eq!(d.htlc.cltv_expiry_relative, 10); |
| 662 | assert_eq!( |
| 663 | d.htlc.payment_hash.to_string(), |
| 664 | "0000000000000000000000000000000000000000000000000000000000000000" |
| 665 | ); |
| 666 | assert_eq!( |
| 667 | d.htlc.extra_tlvs.as_ref().unwrap(), |
| 668 | "fdffff012afe00010001020539" |
| 669 | ); |
| 670 | |
| 671 | assert_eq!( |
| 672 | d.forward_to.unwrap().to_string(), |
| 673 | "0000000000000000000000000000000000000000000000000000000000000000" |
| 674 | ); |
| 675 | assert_serde_roundtrip!(d, HtlcAcceptedEvent); |
| 676 | } |