@@ -8,11 +8,22 @@ import (
8
8
"github.com/btcsuite/btcd/chaincfg/chainhash"
9
9
"github.com/btcsuite/btcd/wire"
10
10
"github.com/lightningnetwork/lnd/channeldb"
11
+ "github.com/stretchr/testify/require"
11
12
)
12
13
13
14
func initHintCache (t * testing.T ) * HeightHintCache {
14
15
t .Helper ()
15
16
17
+ defaultCfg := CacheConfig {
18
+ QueryDisable : false ,
19
+ }
20
+
21
+ return initHintCacheWithConfig (t , defaultCfg )
22
+ }
23
+
24
+ func initHintCacheWithConfig (t * testing.T , cfg CacheConfig ) * HeightHintCache {
25
+ t .Helper ()
26
+
16
27
tempDir , err := ioutil .TempDir ("" , "kek" )
17
28
if err != nil {
18
29
t .Fatalf ("unable to create temp dir: %v" , err )
@@ -21,10 +32,7 @@ func initHintCache(t *testing.T) *HeightHintCache {
21
32
if err != nil {
22
33
t .Fatalf ("unable to create db: %v" , err )
23
34
}
24
- testCfg := CacheConfig {
25
- QueryDisable : false ,
26
- }
27
- hintCache , err := NewHeightHintCache (testCfg , db )
35
+ hintCache , err := NewHeightHintCache (cfg , db )
28
36
if err != nil {
29
37
t .Fatalf ("unable to create hint cache: %v" , err )
30
38
}
@@ -154,3 +162,42 @@ func TestHeightHintCacheSpends(t *testing.T) {
154
162
}
155
163
}
156
164
}
165
+
166
+ // TestQueryDisable asserts querying for confirmation or spend hints always
167
+ // return height zero when QueryDisabled is set to true in the CacheConfig.
168
+ func TestQueryDisable (t * testing.T ) {
169
+ cfg := CacheConfig {
170
+ QueryDisable : true ,
171
+ }
172
+
173
+ hintCache := initHintCacheWithConfig (t , cfg )
174
+
175
+ // Insert a new confirmation hint with a non-zero height.
176
+ const confHeight = 100
177
+ confRequest := ConfRequest {
178
+ TxID : chainhash.Hash {0x01 , 0x02 , 0x03 },
179
+ }
180
+ err := hintCache .CommitConfirmHint (confHeight , confRequest )
181
+ require .Nil (t , err )
182
+
183
+ // Query for the confirmation hint, which should return zero.
184
+ cachedConfHeight , err := hintCache .QueryConfirmHint (confRequest )
185
+ require .Nil (t , err )
186
+ require .Equal (t , uint32 (0 ), cachedConfHeight )
187
+
188
+ // Insert a new spend hint with a non-zero height.
189
+ const spendHeight = 200
190
+ spendRequest := SpendRequest {
191
+ OutPoint : wire.OutPoint {
192
+ Hash : chainhash.Hash {0x4 , 0x05 , 0x06 },
193
+ Index : 42 ,
194
+ },
195
+ }
196
+ err = hintCache .CommitSpendHint (spendHeight , spendRequest )
197
+ require .Nil (t , err )
198
+
199
+ // Query for the spend hint, which should return zero.
200
+ cachedSpendHeight , err := hintCache .QuerySpendHint (spendRequest )
201
+ require .Nil (t , err )
202
+ require .Equal (t , uint32 (0 ), cachedSpendHeight )
203
+ }
0 commit comments