Skip to content

Commit 8af0072

Browse files
committed
sphinx_test: reorder to close log before removing directory
1 parent e20d688 commit 8af0072

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

sphinx_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ func TestBolt4Packet(t *testing.T) {
184184
// shutdown deletes the temporary directory that the test database uses
185185
// and handles closing the database.
186186
func shutdown(dir string, d ReplayLog) {
187-
os.RemoveAll(dir)
188187
d.Stop()
188+
os.RemoveAll(dir)
189189
}
190190

191191
func TestSphinxCorrectness(t *testing.T) {
@@ -205,7 +205,7 @@ func TestSphinxCorrectness(t *testing.T) {
205205
hop := nodes[i]
206206

207207
t.Logf("Processing at hop: %v \n", i)
208-
onionPacket, err := hop.ProcessOnionPacket(fwdMsg, nil)
208+
onionPacket, err := hop.ProcessOnionPacket(fwdMsg, nil, uint32(i)+1)
209209
if err != nil {
210210
t.Fatalf("Node %v was unable to process the "+
211211
"forwarding message: %v", i, err)
@@ -268,7 +268,7 @@ func TestSphinxSingleHop(t *testing.T) {
268268

269269
// Simulating a direct single-hop payment, send the sphinx packet to
270270
// the destination node, making it process the packet fully.
271-
processedPacket, err := nodes[0].ProcessOnionPacket(fwdMsg, nil)
271+
processedPacket, err := nodes[0].ProcessOnionPacket(fwdMsg, nil, 1)
272272
if err != nil {
273273
t.Fatalf("unable to process sphinx packet: %v", err)
274274
}
@@ -295,13 +295,13 @@ func TestSphinxNodeRelpay(t *testing.T) {
295295

296296
// Allow the node to process the initial packet, this should proceed
297297
// without any failures.
298-
if _, err := nodes[0].ProcessOnionPacket(fwdMsg, nil); err != nil {
298+
if _, err := nodes[0].ProcessOnionPacket(fwdMsg, nil, 1); err != nil {
299299
t.Fatalf("unable to process sphinx packet: %v", err)
300300
}
301301

302302
// Now, force the node to process the packet a second time, this should
303303
// fail with a detected replay error.
304-
if _, err := nodes[0].ProcessOnionPacket(fwdMsg, nil); err != ErrReplayedPacket {
304+
if _, err := nodes[0].ProcessOnionPacket(fwdMsg, nil, 1); err != ErrReplayedPacket {
305305
t.Fatalf("sphinx packet replay should be rejected, instead error is %v", err)
306306
}
307307
}
@@ -322,14 +322,14 @@ func TestSphinxNodeRelpaySameBatch(t *testing.T) {
322322

323323
// Allow the node to process the initial packet, this should proceed
324324
// without any failures.
325-
if err := tx.ProcessOnionPacket(0, fwdMsg, nil); err != nil {
325+
if err := tx.ProcessOnionPacket(0, fwdMsg, nil, 1); err != nil {
326326
t.Fatalf("unable to process sphinx packet: %v", err)
327327
}
328328

329329
// Now, force the node to process the packet a second time, this call
330330
// should not fail, even though the batch has internally recorded this
331331
// as a duplicate.
332-
err = tx.ProcessOnionPacket(1, fwdMsg, nil)
332+
err = tx.ProcessOnionPacket(1, fwdMsg, nil, 1)
333333
if err != nil {
334334
t.Fatalf("adding duplicate sphinx packet to batch should not "+
335335
"result in an error, instead got: %v", err)
@@ -368,7 +368,7 @@ func TestSphinxNodeRelpayLaterBatch(t *testing.T) {
368368

369369
// Allow the node to process the initial packet, this should proceed
370370
// without any failures.
371-
if err := tx.ProcessOnionPacket(uint16(0), fwdMsg, nil); err != nil {
371+
if err := tx.ProcessOnionPacket(uint16(0), fwdMsg, nil, 1); err != nil {
372372
t.Fatalf("unable to process sphinx packet: %v", err)
373373
}
374374

@@ -381,7 +381,7 @@ func TestSphinxNodeRelpayLaterBatch(t *testing.T) {
381381

382382
// Now, force the node to process the packet a second time, this should
383383
// fail with a detected replay error.
384-
err = tx2.ProcessOnionPacket(uint16(0), fwdMsg, nil)
384+
err = tx2.ProcessOnionPacket(uint16(0), fwdMsg, nil, 1)
385385
if err != nil {
386386
t.Fatalf("sphinx packet replay should not have been rejected, "+
387387
"instead error is %v", err)
@@ -413,7 +413,7 @@ func TestSphinxNodeRelpayBatchIdempotency(t *testing.T) {
413413

414414
// Allow the node to process the initial packet, this should proceed
415415
// without any failures.
416-
if err := tx.ProcessOnionPacket(uint16(0), fwdMsg, nil); err != nil {
416+
if err := tx.ProcessOnionPacket(uint16(0), fwdMsg, nil, 1); err != nil {
417417
t.Fatalf("unable to process sphinx packet: %v", err)
418418
}
419419

@@ -426,7 +426,7 @@ func TestSphinxNodeRelpayBatchIdempotency(t *testing.T) {
426426

427427
// Now, force the node to process the packet a second time, this should
428428
// not fail with a detected replay error.
429-
err = tx2.ProcessOnionPacket(uint16(0), fwdMsg, nil)
429+
err = tx2.ProcessOnionPacket(uint16(0), fwdMsg, nil, 1)
430430
if err != nil {
431431
t.Fatalf("sphinx packet replay should not have been rejected, "+
432432
"instead error is %v", err)
@@ -460,7 +460,8 @@ func TestSphinxAssocData(t *testing.T) {
460460
nodes[0].log.Start()
461461
defer shutdown("0", nodes[0].log)
462462

463-
if _, err := nodes[0].ProcessOnionPacket(fwdMsg, []byte("somethingelse")); err == nil {
463+
_, err = nodes[0].ProcessOnionPacket(fwdMsg, []byte("somethingelse"), 1)
464+
if err == nil {
464465
t.Fatalf("we should fail when associated data changes")
465466
}
466467

0 commit comments

Comments
 (0)