@@ -10,7 +10,7 @@ import (
10
10
"github.com/lightningnetwork/lnd/channeldb"
11
11
)
12
12
13
- func initHintCache (t * testing.T ) * HeightHintCache {
13
+ func initHintCache (t * testing.T , disable bool ) * HeightHintCache {
14
14
t .Helper ()
15
15
16
16
tempDir , err := ioutil .TempDir ("" , "kek" )
@@ -21,7 +21,7 @@ func initHintCache(t *testing.T) *HeightHintCache {
21
21
if err != nil {
22
22
t .Fatalf ("unable to create db: %v" , err )
23
23
}
24
- hintCache , err := NewHeightHintCache (db )
24
+ hintCache , err := NewHeightHintCache (db , disable )
25
25
if err != nil {
26
26
t .Fatalf ("unable to create hint cache: %v" , err )
27
27
}
@@ -34,7 +34,7 @@ func initHintCache(t *testing.T) *HeightHintCache {
34
34
func TestHeightHintCacheConfirms (t * testing.T ) {
35
35
t .Parallel ()
36
36
37
- hintCache := initHintCache (t )
37
+ hintCache := initHintCache (t , false )
38
38
39
39
// Querying for a transaction hash not found within the cache should
40
40
// return an error indication so.
@@ -93,7 +93,7 @@ func TestHeightHintCacheConfirms(t *testing.T) {
93
93
func TestHeightHintCacheSpends (t * testing.T ) {
94
94
t .Parallel ()
95
95
96
- hintCache := initHintCache (t )
96
+ hintCache := initHintCache (t , false )
97
97
98
98
// Querying for an outpoint not found within the cache should return an
99
99
// error indication so.
@@ -146,3 +146,76 @@ func TestHeightHintCacheSpends(t *testing.T) {
146
146
}
147
147
}
148
148
}
149
+
150
+ // TestHeightHintCacheDisabled asserts that a disabled height hint cache never
151
+ // returns spend or confirm hints that are committed.
152
+ func TestHeightHintCacheDisabled (t * testing.T ) {
153
+ t .Parallel ()
154
+
155
+ const height uint32 = 100
156
+
157
+ // Create a disabled height hint cache.
158
+ hintCache := initHintCache (t , true )
159
+
160
+ // Querying a disabled cache w/ no spend hint should return not found.
161
+ var outpoint wire.OutPoint
162
+ _ , err := hintCache .QuerySpendHint (outpoint )
163
+ if err != ErrSpendHintNotFound {
164
+ t .Fatalf ("expected ErrSpendHintNotFound, got: %v" , err )
165
+ }
166
+
167
+ // Commit a spend hint to the disabled cache, which should be a noop.
168
+ if err := hintCache .CommitSpendHint (height , outpoint ); err != nil {
169
+ t .Fatalf ("unable to commit spend hint: %v" , err )
170
+ }
171
+
172
+ // Querying a disabled cache after commit noop should return not found.
173
+ _ , err = hintCache .QuerySpendHint (outpoint )
174
+ if err != ErrSpendHintNotFound {
175
+ t .Fatalf ("expected ErrSpendHintNotFound, got: %v" , err )
176
+ }
177
+
178
+ // Reenable the cache, this time actually committing a spend hint.
179
+ hintCache .disabled = false
180
+ if err := hintCache .CommitSpendHint (height , outpoint ); err != nil {
181
+ t .Fatalf ("unable to commit spend hint: %v" , err )
182
+ }
183
+
184
+ // Disable the cache again, spend hint should not be found.
185
+ hintCache .disabled = true
186
+ _ , err = hintCache .QuerySpendHint (outpoint )
187
+ if err != ErrSpendHintNotFound {
188
+ t .Fatalf ("expected ErrSpendHintNotFound, got: %v" , err )
189
+ }
190
+
191
+ // Querying a disabled cache w/ no conf hint should return not found.
192
+ var txid chainhash.Hash
193
+ _ , err = hintCache .QueryConfirmHint (txid )
194
+ if err != ErrConfirmHintNotFound {
195
+ t .Fatalf ("expected ErrConfirmHintNotFound, got: %v" , err )
196
+ }
197
+
198
+ // Commit a conf hint to the disabled cache, which should be a noop.
199
+ if err := hintCache .CommitConfirmHint (height , txid ); err != nil {
200
+ t .Fatalf ("unable to commit spend hint: %v" , err )
201
+ }
202
+
203
+ // Querying a disabled cache after commit noop should return not found.
204
+ _ , err = hintCache .QueryConfirmHint (txid )
205
+ if err != ErrConfirmHintNotFound {
206
+ t .Fatalf ("expected ErrConfirmHintNotFound, got: %v" , err )
207
+ }
208
+
209
+ // Reenable the cache, this time actually committing a conf hint.
210
+ hintCache .disabled = false
211
+ if err := hintCache .CommitConfirmHint (height , txid ); err != nil {
212
+ t .Fatalf ("unable to commit spend hint: %v" , err )
213
+ }
214
+
215
+ // Disable the cache again, conf hint should not be found.
216
+ hintCache .disabled = true
217
+ _ , err = hintCache .QueryConfirmHint (txid )
218
+ if err != ErrConfirmHintNotFound {
219
+ t .Fatalf ("expected ErrConfirmHintNotFound, got: %v" , err )
220
+ }
221
+ }
0 commit comments