@@ -2322,6 +2322,76 @@ describe('tx tests', () => {
23222322 ) ;
23232323 } ) ;
23242324
2325+ test ( 'tx list - filter by searchTerm using trigram' , async ( ) => {
2326+ const transferTokenTx = {
2327+ tx_id : '0x1111' ,
2328+ contract_call_function_name : 'transferToken' ,
2329+ } ;
2330+
2331+ const stakeTokenTx = {
2332+ tx_id : '0x2222' ,
2333+ contract_call_function_name : 'stakeToken' ,
2334+ } ;
2335+
2336+ const burnTokenTx = {
2337+ tx_id : '0x3333' ,
2338+ contract_call_function_name : 'burnToken' ,
2339+ }
2340+
2341+ const block1 = new TestBlockBuilder ( { block_height : 1 , index_block_hash : '0x01' } )
2342+ . addTx ( transferTokenTx )
2343+ . build ( ) ;
2344+ await db . update ( block1 ) ;
2345+
2346+ const block2 = new TestBlockBuilder ( {
2347+ block_height : 2 ,
2348+ index_block_hash : '0x02' ,
2349+ parent_block_hash : block1 . block . block_hash ,
2350+ parent_index_block_hash : block1 . block . index_block_hash ,
2351+ } )
2352+ . addTx ( stakeTokenTx )
2353+ . addTx ( burnTokenTx )
2354+ . build ( ) ;
2355+ await db . update ( block2 ) ;
2356+
2357+ const searchTerm = 'transfer' ;
2358+
2359+ const txsReq = await supertest ( api . server ) . get ( `/extended/v1/tx?search_term=${ searchTerm } ` ) ;
2360+ expect ( txsReq . status ) . toBe ( 200 ) ;
2361+ expect ( txsReq . body ) . toEqual (
2362+ expect . objectContaining ( {
2363+ results : [
2364+ expect . objectContaining ( {
2365+ tx_id : transferTokenTx . tx_id ,
2366+ } ) ,
2367+ ] ,
2368+ } )
2369+ ) ;
2370+
2371+ const broadSearchTerm = 'token' ;
2372+
2373+ const txsReqBroad = await supertest ( api . server ) . get (
2374+ `/extended/v1/tx?search_term=${ broadSearchTerm } `
2375+ ) ;
2376+ expect ( txsReqBroad . status ) . toBe ( 200 ) ;
2377+
2378+ expect ( txsReqBroad . body ) . toEqual (
2379+ expect . objectContaining ( {
2380+ results : [
2381+ expect . objectContaining ( {
2382+ tx_id : burnTokenTx . tx_id ,
2383+ } ) ,
2384+ expect . objectContaining ( {
2385+ tx_id : stakeTokenTx . tx_id ,
2386+ } ) ,
2387+ expect . objectContaining ( {
2388+ tx_id : transferTokenTx . tx_id ,
2389+ } ) ,
2390+ ] ,
2391+ } )
2392+ ) ;
2393+ } ) ;
2394+
23252395 test ( 'tx list - filter by contract id/name' , async ( ) => {
23262396 const testContractAddr = 'ST27W5M8BRKA7C5MZE2R1S1F4XTPHFWFRNHA9M04Y.hello-world' ;
23272397 const testContractFnName = 'test-contract-fn' ;
0 commit comments