@@ -818,131 +818,157 @@ describe('Rosetta API', () => {
818818 } ) ;
819819 } ) ;
820820
821- test ( 'epoch3 tenure-change block/transaction' , async ( ) => {
822- const parentData = new TestBlockBuilder ( ) . addTx ( ) . build ( ) ;
823- const block1 : TestBlockArgs = {
824- block_height : 2 ,
825- block_hash : '0xd0dd05e3d0a1bd60640c9d9d30d57012ffe47b52fe643140c39199c757d37e3f' ,
826- index_block_hash : '0x6a36c14514047074c2877065809bbb70d81d52507747f4616da997deb7228fad' ,
827- parent_index_block_hash : parentData . block . index_block_hash ,
828- parent_block_hash : parentData . block . block_hash ,
829- parent_microblock_hash : '0x0000000000000000000000000000000000000000000000000000000000000000' ,
830- burn_block_hash : '0xfe15c0d3ebe314fad720a08b839a004c2e6386f5aecc19ec74807d1920cb6aeb' ,
831- miner_txid : '0x0000000000000000000000000000000000000000000000000000000000000000' ,
832- } ;
833- const txTenureChange1 : TestTxArgs = {
834- tx_id : '0xc152de9376bab4fc27291c9cd088643698290a12bb511d768f873cb3d280eb48' ,
835- tx_index : 1 ,
836- type_id : DbTxTypeId . TenureChange ,
837- status : DbTxStatus . Success ,
838- raw_result : '0x0703' ,
839- canonical : true ,
840- microblock_canonical : true ,
841- microblock_sequence : 2147483647 ,
842- microblock_hash : '0x00' ,
843- fee_rate : 0n ,
844- sender_address : 'ST1HB1T8WRNBYB0Y3T7WXZS38NKKPTBR3EG9EPJKR' ,
845- tenure_change_tenure_consensus_hash : '0x2fedd90a5f318ed8cec419fd1c6656b5af452497' ,
846- tenure_change_prev_tenure_consensus_hash : '0x5104aae6d442b49c8e8d2031df7f40b67528e654' ,
847- tenure_change_burn_view_consensus_hash : '0x2fedd90a5f318ed8cec419fd1c6656b5af452497' ,
848- tenure_change_previous_tenure_end :
849- '0xb77b061202b1e6dce889ba1633efa969d3c24679d32a7542d29015ee94e8a860' ,
850- tenure_change_previous_tenure_blocks : 9 ,
851- tenure_change_cause : 4 ,
852- tenure_change_pubkey_hash : '0x62b4273562dfa3825496094507564bf2b30c8b11' ,
853- } ;
854- const blockData1 = new TestBlockBuilder ( block1 ) . addTx ( txTenureChange1 ) . build ( ) ;
855-
856- await db . update ( parentData ) ;
857- await db . update ( blockData1 ) ;
858-
859- const query1 = await supertest ( api . server )
860- . post ( `/rosetta/v1/block/transaction` )
861- . send ( {
862- network_identifier : { blockchain : 'stacks' , network : 'testnet' } ,
863- block_identifier : {
864- index : blockData1 . block . block_height ,
865- hash : blockData1 . block . block_hash ,
866- } ,
867- transaction_identifier : { hash : txTenureChange1 . tx_id } ,
868- } ) ;
869- expect ( query1 . status ) . toBe ( 200 ) ;
870- expect ( query1 . type ) . toBe ( 'application/json' ) ;
871- expect ( query1 . body ) . toEqual ( {
872- transaction_identifier : {
873- hash : txTenureChange1 . tx_id ,
874- } ,
875- operations : [
876- {
877- operation_identifier : {
878- index : 0 ,
879- } ,
880- type : 'tenure_change' ,
881- status : 'success' ,
882- metadata : {
883- tenure_consensus_hash : txTenureChange1 . tenure_change_tenure_consensus_hash ,
884- prev_tenure_consensus_hash : txTenureChange1 . tenure_change_prev_tenure_consensus_hash ,
885- burn_view_consensus_hash : txTenureChange1 . tenure_change_burn_view_consensus_hash ,
886- previous_tenure_end : txTenureChange1 . tenure_change_previous_tenure_end ,
887- previous_tenure_blocks : txTenureChange1 . tenure_change_previous_tenure_blocks ,
888- cause : 'extended_read_length' ,
889- pubkey_hash : txTenureChange1 . tenure_change_pubkey_hash ,
821+ describe ( 'epoch3 tenure-change block/transaction' , ( ) => {
822+ const changeTenure = async ( cause : number , causeString : string ) => {
823+ const parentData = new TestBlockBuilder ( ) . addTx ( ) . build ( ) ;
824+ const block1 : TestBlockArgs = {
825+ block_height : 2 ,
826+ block_hash : '0xd0dd05e3d0a1bd60640c9d9d30d57012ffe47b52fe643140c39199c757d37e3f' ,
827+ index_block_hash : '0x6a36c14514047074c2877065809bbb70d81d52507747f4616da997deb7228fad' ,
828+ parent_index_block_hash : parentData . block . index_block_hash ,
829+ parent_block_hash : parentData . block . block_hash ,
830+ parent_microblock_hash :
831+ '0x0000000000000000000000000000000000000000000000000000000000000000' ,
832+ burn_block_hash : '0xfe15c0d3ebe314fad720a08b839a004c2e6386f5aecc19ec74807d1920cb6aeb' ,
833+ miner_txid : '0x0000000000000000000000000000000000000000000000000000000000000000' ,
834+ } ;
835+ const txTenureChange1 : TestTxArgs = {
836+ tx_id : '0xc152de9376bab4fc27291c9cd088643698290a12bb511d768f873cb3d280eb48' ,
837+ tx_index : 1 ,
838+ type_id : DbTxTypeId . TenureChange ,
839+ status : DbTxStatus . Success ,
840+ raw_result : '0x0703' ,
841+ canonical : true ,
842+ microblock_canonical : true ,
843+ microblock_sequence : 2147483647 ,
844+ microblock_hash : '0x00' ,
845+ fee_rate : 0n ,
846+ sender_address : 'ST1HB1T8WRNBYB0Y3T7WXZS38NKKPTBR3EG9EPJKR' ,
847+ tenure_change_tenure_consensus_hash : '0x2fedd90a5f318ed8cec419fd1c6656b5af452497' ,
848+ tenure_change_prev_tenure_consensus_hash : '0x5104aae6d442b49c8e8d2031df7f40b67528e654' ,
849+ tenure_change_burn_view_consensus_hash : '0x2fedd90a5f318ed8cec419fd1c6656b5af452497' ,
850+ tenure_change_previous_tenure_end :
851+ '0xb77b061202b1e6dce889ba1633efa969d3c24679d32a7542d29015ee94e8a860' ,
852+ tenure_change_previous_tenure_blocks : 9 ,
853+ tenure_change_cause : cause ,
854+ tenure_change_pubkey_hash : '0x62b4273562dfa3825496094507564bf2b30c8b11' ,
855+ } ;
856+ const blockData1 = new TestBlockBuilder ( block1 ) . addTx ( txTenureChange1 ) . build ( ) ;
857+
858+ await db . update ( parentData ) ;
859+ await db . update ( blockData1 ) ;
860+
861+ const query1 = await supertest ( api . server )
862+ . post ( `/rosetta/v1/block/transaction` )
863+ . send ( {
864+ network_identifier : { blockchain : 'stacks' , network : 'testnet' } ,
865+ block_identifier : {
866+ index : blockData1 . block . block_height ,
867+ hash : blockData1 . block . block_hash ,
890868 } ,
869+ transaction_identifier : { hash : txTenureChange1 . tx_id } ,
870+ } ) ;
871+ expect ( query1 . status ) . toBe ( 200 ) ;
872+ expect ( query1 . type ) . toBe ( 'application/json' ) ;
873+ expect ( query1 . body ) . toEqual ( {
874+ transaction_identifier : {
875+ hash : txTenureChange1 . tx_id ,
891876 } ,
892- ] ,
893- } ) ;
894-
895- const query2 = await supertest ( api . address )
896- . post ( `/rosetta/v1/block` )
897- . send ( {
898- network_identifier : { blockchain : 'stacks' , network : 'testnet' } ,
899- block_identifier : { index : blockData1 . block . block_height } ,
900- } ) ;
901- expect ( query1 . status ) . toBe ( 200 ) ;
902- expect ( query1 . type ) . toBe ( 'application/json' ) ;
903- const expected : RosettaBlockResponse = {
904- block : {
905- block_identifier : {
906- index : blockData1 . block . block_height ,
907- hash : blockData1 . block . block_hash ,
908- } ,
909- parent_block_identifier : {
910- index : blockData1 . block . block_height - 1 ,
911- hash : blockData1 . block . parent_block_hash ,
912- } ,
913- timestamp : blockData1 . block . burn_block_time * 1000 ,
914- transactions : [
877+ operations : [
915878 {
916- transaction_identifier : {
917- hash : txTenureChange1 . tx_id as string ,
879+ operation_identifier : {
880+ index : 0 ,
881+ } ,
882+ type : 'tenure_change' ,
883+ status : 'success' ,
884+ metadata : {
885+ tenure_consensus_hash : txTenureChange1 . tenure_change_tenure_consensus_hash ,
886+ prev_tenure_consensus_hash : txTenureChange1 . tenure_change_prev_tenure_consensus_hash ,
887+ burn_view_consensus_hash : txTenureChange1 . tenure_change_burn_view_consensus_hash ,
888+ previous_tenure_end : txTenureChange1 . tenure_change_previous_tenure_end ,
889+ previous_tenure_blocks : txTenureChange1 . tenure_change_previous_tenure_blocks ,
890+ cause : causeString ,
891+ pubkey_hash : txTenureChange1 . tenure_change_pubkey_hash ,
918892 } ,
919- operations : [
920- {
921- operation_identifier : {
922- index : 0 ,
923- } ,
924- type : 'tenure_change' ,
925- status : 'success' ,
926- metadata : {
927- tenure_consensus_hash : txTenureChange1 . tenure_change_tenure_consensus_hash ,
928- prev_tenure_consensus_hash :
929- txTenureChange1 . tenure_change_prev_tenure_consensus_hash ,
930- burn_view_consensus_hash : txTenureChange1 . tenure_change_burn_view_consensus_hash ,
931- previous_tenure_end : txTenureChange1 . tenure_change_previous_tenure_end ,
932- previous_tenure_blocks : txTenureChange1 . tenure_change_previous_tenure_blocks ,
933- cause : 'extended_read_length' ,
934- pubkey_hash : txTenureChange1 . tenure_change_pubkey_hash ,
935- } ,
936- } ,
937- ] ,
938893 } ,
939894 ] ,
940- metadata : {
941- burn_block_height : blockData1 . block . burn_block_height ,
895+ } ) ;
896+
897+ const query2 = await supertest ( api . address )
898+ . post ( `/rosetta/v1/block` )
899+ . send ( {
900+ network_identifier : { blockchain : 'stacks' , network : 'testnet' } ,
901+ block_identifier : { index : blockData1 . block . block_height } ,
902+ } ) ;
903+ expect ( query1 . status ) . toBe ( 200 ) ;
904+ expect ( query1 . type ) . toBe ( 'application/json' ) ;
905+ const expected : RosettaBlockResponse = {
906+ block : {
907+ block_identifier : {
908+ index : blockData1 . block . block_height ,
909+ hash : blockData1 . block . block_hash ,
910+ } ,
911+ parent_block_identifier : {
912+ index : blockData1 . block . block_height - 1 ,
913+ hash : blockData1 . block . parent_block_hash ,
914+ } ,
915+ timestamp : blockData1 . block . burn_block_time * 1000 ,
916+ transactions : [
917+ {
918+ transaction_identifier : {
919+ hash : txTenureChange1 . tx_id as string ,
920+ } ,
921+ operations : [
922+ {
923+ operation_identifier : {
924+ index : 0 ,
925+ } ,
926+ type : 'tenure_change' ,
927+ status : 'success' ,
928+ metadata : {
929+ tenure_consensus_hash : txTenureChange1 . tenure_change_tenure_consensus_hash ,
930+ prev_tenure_consensus_hash :
931+ txTenureChange1 . tenure_change_prev_tenure_consensus_hash ,
932+ burn_view_consensus_hash :
933+ txTenureChange1 . tenure_change_burn_view_consensus_hash ,
934+ previous_tenure_end : txTenureChange1 . tenure_change_previous_tenure_end ,
935+ previous_tenure_blocks : txTenureChange1 . tenure_change_previous_tenure_blocks ,
936+ cause : causeString ,
937+ pubkey_hash : txTenureChange1 . tenure_change_pubkey_hash ,
938+ } ,
939+ } ,
940+ ] ,
941+ } ,
942+ ] ,
943+ metadata : {
944+ burn_block_height : blockData1 . block . burn_block_height ,
945+ } ,
942946 } ,
943- } ,
947+ } ;
948+ expect ( query2 . body ) . toEqual ( expected ) ;
944949 } ;
945- expect ( query2 . body ) . toEqual ( expected ) ;
950+
951+ test ( 'block_found' , async ( ) => {
952+ await expect ( changeTenure ( 0 , 'block_found' ) ) . resolves . not . toThrow ( ) ;
953+ } ) ;
954+ test ( 'extended' , async ( ) => {
955+ await expect ( changeTenure ( 1 , 'extended' ) ) . resolves . not . toThrow ( ) ;
956+ } ) ;
957+ test ( 'extended_runtime' , async ( ) => {
958+ await expect ( changeTenure ( 2 , 'extended_runtime' ) ) . resolves . not . toThrow ( ) ;
959+ } ) ;
960+ test ( 'extended_read_count' , async ( ) => {
961+ await expect ( changeTenure ( 3 , 'extended_read_count' ) ) . resolves . not . toThrow ( ) ;
962+ } ) ;
963+ test ( 'extended_read_length' , async ( ) => {
964+ await expect ( changeTenure ( 4 , 'extended_read_length' ) ) . resolves . not . toThrow ( ) ;
965+ } ) ;
966+ test ( 'extended_write_length' , async ( ) => {
967+ await expect ( changeTenure ( 5 , 'extended_write_count' ) ) . resolves . not . toThrow ( ) ;
968+ } ) ;
969+ test ( 'extended_read_count' , async ( ) => {
970+ await expect ( changeTenure ( 6 , 'extended_write_length' ) ) . resolves . not . toThrow ( ) ;
971+ } ) ;
946972 } ) ;
947973
948974 test ( 'block/transaction - invalid transaction hash' , async ( ) => {
0 commit comments