@@ -1066,6 +1066,118 @@ BOOST_AUTO_TEST_SUITE(slice_tests)
10661066 BOOST_REQUIRE (!block2);
10671067 }
10681068
1069+ // Verify basics of get_trx_block_number()
1070+ BOOST_FIXTURE_TEST_CASE (test_get_trx_block_number_basic, test_fixture)
1071+ {
1072+ chain::transaction_id_type trx_id1 = " 0000000000000000000000000000000000000000000000000000000000000001" _h;
1073+ chain::transaction_id_type trx_id2 = " 0000000000000000000000000000000000000000000000000000000000000002" _h;
1074+ uint32_t block_num1 = 1 ;
1075+ uint32_t block_num2 = 2 ;
1076+
1077+ transaction_trace_v2 trx_trace1 {
1078+ trx_id1,
1079+ actions,
1080+ fc::enum_type<uint8_t , chain::transaction_receipt_header::status_enum>{chain::transaction_receipt_header::status_enum::executed},
1081+ 10 ,
1082+ 5 ,
1083+ { chain::signature_type () },
1084+ { chain::time_point_sec (), 1 , 0 , 100 , 50 , 0 }
1085+ };
1086+
1087+ transaction_trace_v2 trx_trace2 {
1088+ trx_id2,
1089+ actions,
1090+ fc::enum_type<uint8_t , chain::transaction_receipt_header::status_enum>{chain::transaction_receipt_header::status_enum::executed},
1091+ 10 ,
1092+ 5 ,
1093+ { chain::signature_type () },
1094+ { chain::time_point_sec (), 1 , 0 , 100 , 50 , 0 }
1095+ };
1096+
1097+ // block 1 includes trx_trace1
1098+ block_trace_v2 block_trace1 {
1099+ " b000000000000000000000000000000000000000000000000000000000000001" _h,
1100+ block_num1,
1101+ " 0000000000000000000000000000000000000000000000000000000000000000" _h,
1102+ chain::block_timestamp_type (0 ),
1103+ " test" _n,
1104+ " 0000000000000000000000000000000000000000000000000000000000000000" _h,
1105+ " 0000000000000000000000000000000000000000000000000000000000000000" _h,
1106+ 0 ,
1107+ std::vector<transaction_trace_v2> {
1108+ trx_trace1
1109+ }
1110+ };
1111+
1112+ // block 2 includes trx_trace2
1113+ block_trace_v2 block_trace2 {
1114+ " b000000000000000000000000000000000000000000000000000000000000003" _h,
1115+ block_num2,
1116+ " 0000000000000000000000000000000000000000000000000000000000000000" _h,
1117+ chain::block_timestamp_type (0 ),
1118+ " test" _n,
1119+ " 0000000000000000000000000000000000000000000000000000000000000000" _h,
1120+ " 0000000000000000000000000000000000000000000000000000000000000000" _h,
1121+ 0 ,
1122+ std::vector<transaction_trace_v2> {
1123+ trx_trace2
1124+ }
1125+ };
1126+
1127+ block_trxs_entry block_trxs_entry1 {
1128+ .ids = {trx_id1},
1129+ .block_num = block_num1
1130+ };
1131+
1132+ block_trxs_entry block_trxs_entry2 {
1133+ .ids = {trx_id2},
1134+ .block_num = block_num2
1135+ };
1136+
1137+ fc::temp_directory tempdir;
1138+ store_provider sp (tempdir.path (), 100 , std::optional<uint32_t >(), std::optional<uint32_t >(), 0 );
1139+
1140+ // on_accepted_block of block 1
1141+ sp.append (block_trace1);
1142+ sp.append_trx_ids (block_trxs_entry1);
1143+
1144+ // block 1 is reversible and get_trx_block_number should find trx_id1 in block 1
1145+ get_block_n block_num = sp.get_trx_block_number (trx_id1, {});
1146+ BOOST_REQUIRE (block_num);
1147+ BOOST_REQUIRE_EQUAL (*block_num, block_num1);
1148+
1149+ // block 1 becomes final
1150+ sp.append_lib (block_num1);
1151+
1152+ // get_trx_block_number should find trx_id1 in block 1
1153+ block_num = sp.get_trx_block_number (trx_id1, {});
1154+ BOOST_REQUIRE (block_num);
1155+ BOOST_REQUIRE_EQUAL (*block_num, block_num1);
1156+
1157+ // on_accepted_block of block 2
1158+ sp.append (block_trace2);
1159+ sp.append_trx_ids (block_trxs_entry2);
1160+
1161+ // get_trx_block_number should find both trx_id1 and trx_id2
1162+ block_num = sp.get_trx_block_number (trx_id1, {});
1163+ BOOST_REQUIRE (block_num);
1164+ BOOST_REQUIRE_EQUAL (*block_num, block_num1);
1165+ block_num = sp.get_trx_block_number (trx_id2, {});
1166+ BOOST_REQUIRE (block_num);
1167+ BOOST_REQUIRE_EQUAL (*block_num, block_num2);
1168+
1169+ // block 2 becomes final
1170+ sp.append_lib (block_num2);
1171+
1172+ // get_trx_block_number should still find both trx_id1 and trx_id2
1173+ block_num = sp.get_trx_block_number (trx_id1, {});
1174+ BOOST_REQUIRE (block_num);
1175+ BOOST_REQUIRE_EQUAL (*block_num, block_num1);
1176+ block_num = sp.get_trx_block_number (trx_id2, {});
1177+ BOOST_REQUIRE (block_num);
1178+ BOOST_REQUIRE_EQUAL (*block_num, block_num2);
1179+ }
1180+
10691181// This test verifies the bug reported by https://github.com/AntelopeIO/spring/issues/942
10701182// is fixed. The bug was if the block containing a transaction forked out,
10711183// get_trx_block_number() always returned the latest block whose block number was
0 commit comments