@@ -572,6 +572,132 @@ describe('EventServer', () => {
572
572
} ) ;
573
573
574
574
describe ( 'gap detection' , ( ) => {
575
+ test ( 'server rejects payload with first inscription gap when streaming' , async ( ) => {
576
+ await db . updateInscriptions (
577
+ new TestChainhookPayloadBuilder ( )
578
+ . streamingBlocks ( false )
579
+ . apply ( )
580
+ . block ( {
581
+ height : 778575 ,
582
+ hash : '0x00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d' ,
583
+ timestamp : 1676913207 ,
584
+ } )
585
+ . transaction ( {
586
+ hash : '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201' ,
587
+ } )
588
+ . inscriptionRevealed ( {
589
+ content_bytes : '0x48656C6C6F' ,
590
+ content_type : 'text/plain;charset=utf-8' ,
591
+ content_length : 5 ,
592
+ inscription_number : { classic : 0 , jubilee : 0 } ,
593
+ inscription_fee : 705 ,
594
+ inscription_id : '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0' ,
595
+ inscription_output_value : 10000 ,
596
+ inscriber_address : 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj' ,
597
+ ordinal_number : 257418248345364 ,
598
+ ordinal_block_height : 650000 ,
599
+ ordinal_offset : 0 ,
600
+ satpoint_post_inscription :
601
+ '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0:0' ,
602
+ inscription_input_index : 0 ,
603
+ transfers_pre_inscription : 0 ,
604
+ tx_index : 0 ,
605
+ curse_type : null ,
606
+ inscription_pointer : null ,
607
+ delegate : null ,
608
+ metaprotocol : null ,
609
+ metadata : null ,
610
+ parent : null ,
611
+ } )
612
+ . build ( )
613
+ ) ;
614
+ const errorPayload1 = new TestChainhookPayloadBuilder ( )
615
+ . streamingBlocks ( false )
616
+ . apply ( )
617
+ . block ( {
618
+ height : 778576 ,
619
+ hash : '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d' ,
620
+ timestamp : 1676913207 ,
621
+ } )
622
+ . transaction ( {
623
+ hash : '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc' ,
624
+ } )
625
+ . inscriptionRevealed ( {
626
+ content_bytes : '0x48656C6C6F' ,
627
+ content_type : 'text/plain;charset=utf-8' ,
628
+ content_length : 5 ,
629
+ inscription_number : { classic : 5 , jubilee : 5 } , // Gap at 5 but block is not streamed
630
+ inscription_fee : 705 ,
631
+ inscription_id : '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0' ,
632
+ inscription_output_value : 10000 ,
633
+ inscriber_address : 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td' ,
634
+ ordinal_number : 1050000000000000 ,
635
+ ordinal_block_height : 650000 ,
636
+ ordinal_offset : 0 ,
637
+ satpoint_post_inscription :
638
+ '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0:0' ,
639
+ inscription_input_index : 0 ,
640
+ transfers_pre_inscription : 0 ,
641
+ tx_index : 0 ,
642
+ curse_type : null ,
643
+ inscription_pointer : null ,
644
+ delegate : null ,
645
+ metaprotocol : null ,
646
+ metadata : null ,
647
+ parent : null ,
648
+ } )
649
+ . build ( ) ;
650
+ // Not streamed, accepts block.
651
+ await expect ( db . updateInscriptions ( errorPayload1 ) ) . resolves . not . toThrow (
652
+ BadPayloadRequestError
653
+ ) ;
654
+
655
+ const errorPayload2 = new TestChainhookPayloadBuilder ( )
656
+ . streamingBlocks ( true )
657
+ . apply ( )
658
+ . block ( {
659
+ height : 778579 ,
660
+ hash : '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d' ,
661
+ timestamp : 1676913207 ,
662
+ } )
663
+ . transaction ( {
664
+ hash : '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc' ,
665
+ } )
666
+ . inscriptionRevealed ( {
667
+ content_bytes : '0x48656C6C6F' ,
668
+ content_type : 'text/plain;charset=utf-8' ,
669
+ content_length : 5 ,
670
+ inscription_number : { classic : 10 , jubilee : 10 } , // Gap at 10
671
+ inscription_fee : 705 ,
672
+ inscription_id : '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0' ,
673
+ inscription_output_value : 10000 ,
674
+ inscriber_address : 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td' ,
675
+ ordinal_number : 1050000000000000 ,
676
+ ordinal_block_height : 650000 ,
677
+ ordinal_offset : 0 ,
678
+ satpoint_post_inscription :
679
+ '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0:0' ,
680
+ inscription_input_index : 0 ,
681
+ transfers_pre_inscription : 0 ,
682
+ tx_index : 0 ,
683
+ curse_type : null ,
684
+ inscription_pointer : null ,
685
+ delegate : null ,
686
+ metaprotocol : null ,
687
+ metadata : null ,
688
+ parent : null ,
689
+ } )
690
+ . build ( ) ;
691
+ await expect ( db . updateInscriptions ( errorPayload2 ) ) . rejects . toThrow ( BadPayloadRequestError ) ;
692
+ const response = await server [ 'fastify' ] . inject ( {
693
+ method : 'POST' ,
694
+ url : `/payload` ,
695
+ headers : { authorization : `Bearer ${ ENV . ORDHOOK_NODE_AUTH_TOKEN } ` } ,
696
+ payload : errorPayload2 ,
697
+ } ) ;
698
+ expect ( response . statusCode ) . toBe ( 400 ) ;
699
+ } ) ;
700
+
575
701
test ( 'server ignores past blocks' , async ( ) => {
576
702
const payload = new TestChainhookPayloadBuilder ( )
577
703
. apply ( )
0 commit comments