@@ -70,9 +70,13 @@ func TestSearch_TransactionHash(t *testing.T) {
70
70
71
71
txHash := "0x1234567890123456789012345678901234567890123456789012345678901234"
72
72
73
+ // Mock the 3 GetTransactions calls for different time ranges
74
+ // 1. Past 5 days (startOffsetDays=5, endOffsetDays=0)
73
75
mockStorage .EXPECT ().GetTransactions (mock .MatchedBy (func (filter storage.QueryFilter ) bool {
74
76
return filter .ChainId .Cmp (big .NewInt (1 )) == 0 &&
75
- filter .FilterParams ["hash" ] == txHash
77
+ filter .FilterParams ["hash" ] == txHash &&
78
+ filter .FilterParams ["block_timestamp_gte" ] != "" &&
79
+ filter .FilterParams ["block_timestamp_lte" ] == ""
76
80
})).Return (storage.QueryResult [common.Transaction ]{
77
81
Data : []common.Transaction {{
78
82
Hash : txHash ,
@@ -84,9 +88,33 @@ func TestSearch_TransactionHash(t *testing.T) {
84
88
}},
85
89
}, nil )
86
90
87
- // Mock other necessary calls for block and logs search
88
- mockStorage .EXPECT ().GetBlocks (mock .Anything ).Return (storage.QueryResult [common.Block ]{}, nil )
89
- mockStorage .EXPECT ().GetLogs (mock .Anything ).Return (storage.QueryResult [common.Log ]{}, nil )
91
+ // 2. 5-30 days (startOffsetDays=30, endOffsetDays=5)
92
+ mockStorage .EXPECT ().GetTransactions (mock .MatchedBy (func (filter storage.QueryFilter ) bool {
93
+ return filter .ChainId .Cmp (big .NewInt (1 )) == 0 &&
94
+ filter .FilterParams ["hash" ] == txHash &&
95
+ filter .FilterParams ["block_timestamp_gte" ] != "" &&
96
+ filter .FilterParams ["block_timestamp_lte" ] != ""
97
+ })).Return (storage.QueryResult [common.Transaction ]{}, nil )
98
+
99
+ // 3. More than 30 days (startOffsetDays=0, endOffsetDays=30)
100
+ mockStorage .EXPECT ().GetTransactions (mock .MatchedBy (func (filter storage.QueryFilter ) bool {
101
+ return filter .ChainId .Cmp (big .NewInt (1 )) == 0 &&
102
+ filter .FilterParams ["hash" ] == txHash &&
103
+ filter .FilterParams ["block_timestamp_gte" ] == "" &&
104
+ filter .FilterParams ["block_timestamp_lte" ] != ""
105
+ })).Return (storage.QueryResult [common.Transaction ]{}, nil )
106
+
107
+ // Mock the GetBlocks call for block hash search
108
+ mockStorage .EXPECT ().GetBlocks (mock .MatchedBy (func (filter storage.QueryFilter ) bool {
109
+ return filter .ChainId .Cmp (big .NewInt (1 )) == 0 &&
110
+ filter .FilterParams ["hash" ] == txHash
111
+ })).Return (storage.QueryResult [common.Block ]{}, nil )
112
+
113
+ // Mock the GetLogs call for topic_0 search
114
+ mockStorage .EXPECT ().GetLogs (mock .MatchedBy (func (filter storage.QueryFilter ) bool {
115
+ return filter .ChainId .Cmp (big .NewInt (1 )) == 0 &&
116
+ filter .Signature == txHash
117
+ })).Return (storage.QueryResult [common.Log ]{}, nil )
90
118
91
119
w := httptest .NewRecorder ()
92
120
req , _ := http .NewRequest ("GET" , "/v1/search/1/" + txHash , nil )
@@ -112,7 +140,7 @@ func TestSearch_Address(t *testing.T) {
112
140
router , mockStorage := setupTestRouter ()
113
141
114
142
address := "0x1234567890123456789012345678901234567890"
115
- mockStorage .On ( " GetTransactions" , mock .MatchedBy (func (filter storage.QueryFilter ) bool {
143
+ mockStorage .EXPECT (). GetTransactions ( mock .MatchedBy (func (filter storage.QueryFilter ) bool {
116
144
return filter .ChainId .Cmp (big .NewInt (1 )) == 0 &&
117
145
filter .ContractAddress == address
118
146
})).Return (storage.QueryResult [common.Transaction ]{
@@ -126,7 +154,7 @@ func TestSearch_Address(t *testing.T) {
126
154
}},
127
155
}, nil )
128
156
129
- mockStorage .On ( " GetTransactions" , mock .MatchedBy (func (filter storage.QueryFilter ) bool {
157
+ mockStorage .EXPECT (). GetTransactions ( mock .MatchedBy (func (filter storage.QueryFilter ) bool {
130
158
return filter .ChainId .Cmp (big .NewInt (1 )) == 0 &&
131
159
filter .FromAddress == address
132
160
})).Return (storage.QueryResult [common.Transaction ]{
@@ -164,7 +192,7 @@ func TestSearch_Contract(t *testing.T) {
164
192
router , mockStorage := setupTestRouter ()
165
193
166
194
address := "0x1234567890123456789012345678901234567890"
167
- mockStorage .On ( " GetTransactions" , mock .MatchedBy (func (filter storage.QueryFilter ) bool {
195
+ mockStorage .EXPECT (). GetTransactions ( mock .MatchedBy (func (filter storage.QueryFilter ) bool {
168
196
return filter .ChainId .Cmp (big .NewInt (1 )) == 0 &&
169
197
filter .ContractAddress == address
170
198
})).Return (storage.QueryResult [common.Transaction ]{
@@ -204,7 +232,7 @@ func TestSearch_FunctionSignature(t *testing.T) {
204
232
router , mockStorage := setupTestRouter ()
205
233
206
234
signature := "0x12345678"
207
- mockStorage .On ( " GetTransactions" , mock .MatchedBy (func (filter storage.QueryFilter ) bool {
235
+ mockStorage .EXPECT (). GetTransactions ( mock .MatchedBy (func (filter storage.QueryFilter ) bool {
208
236
return filter .ChainId .Cmp (big .NewInt (1 )) == 0 &&
209
237
filter .Signature == signature
210
238
})).Return (storage.QueryResult [common.Transaction ]{
0 commit comments