44 "bytes"
55 "encoding/hex"
66 "fmt"
7- "os"
87 "reflect"
9- "strconv"
108 "testing"
119
1210 "github.com/davecgh/go-spew/spew"
@@ -99,9 +97,8 @@ func newTestRoute(numHops int) ([]*Router, *[]HopData, *OnionPacket, error) {
9997 " random key for sphinx node: %v" , err )
10098 }
10199
102- dbPath := strconv .Itoa (i )
103-
104- nodes [i ] = NewRouter (dbPath , privKey , & chaincfg .MainNetParams , nil )
100+ nodes [i ] = NewRouter (privKey , & chaincfg .MainNetParams ,
101+ NewMemoryReplayLog ())
105102 }
106103
107104 // Gather all the pub keys in the path.
@@ -181,13 +178,6 @@ func TestBolt4Packet(t *testing.T) {
181178 }
182179}
183180
184- // shutdown deletes the temporary directory that the test database uses
185- // and handles closing the database.
186- func shutdown (dir string , d ReplayLog ) {
187- d .Stop ()
188- os .RemoveAll (dir )
189- }
190-
191181func TestSphinxCorrectness (t * testing.T ) {
192182 nodes , hopDatas , fwdMsg , err := newTestRoute (NumMaxHops )
193183 if err != nil {
@@ -197,10 +187,9 @@ func TestSphinxCorrectness(t *testing.T) {
197187 // Now simulate the message propagating through the mix net eventually
198188 // reaching the final destination.
199189 for i := 0 ; i < len (nodes ); i ++ {
200- // Start each node's DecayedLog and defer shutdown
201- tempDir := strconv .Itoa (i )
190+ // Start each node's ReplayLog and defer shutdown
202191 nodes [i ].log .Start ()
203- defer shutdown ( tempDir , nodes [i ].log )
192+ defer nodes [i ].log . Stop ( )
204193
205194 hop := nodes [i ]
206195
@@ -262,9 +251,9 @@ func TestSphinxSingleHop(t *testing.T) {
262251 t .Fatalf ("unable to create test route: %v" , err )
263252 }
264253
265- // Start the DecayedLog and defer shutdown
254+ // Start the ReplayLog and defer shutdown
266255 nodes [0 ].log .Start ()
267- defer shutdown ( "0" , nodes [0 ].log )
256+ defer nodes [0 ].log . Stop ( )
268257
269258 // Simulating a direct single-hop payment, send the sphinx packet to
270259 // the destination node, making it process the packet fully.
@@ -289,9 +278,9 @@ func TestSphinxNodeRelpay(t *testing.T) {
289278 t .Fatalf ("unable to create test route: %v" , err )
290279 }
291280
292- // Start the DecayedLog and defer shutdown
281+ // Start the ReplayLog and defer shutdown
293282 nodes [0 ].log .Start ()
294- defer shutdown ( "0" , nodes [0 ].log )
283+ defer nodes [0 ].log . Stop ( )
295284
296285 // Allow the node to process the initial packet, this should proceed
297286 // without any failures.
@@ -314,9 +303,9 @@ func TestSphinxNodeRelpaySameBatch(t *testing.T) {
314303 t .Fatalf ("unable to create test route: %v" , err )
315304 }
316305
317- // Start the DecayedLog and defer shutdown
306+ // Start the ReplayLog and defer shutdown
318307 nodes [0 ].log .Start ()
319- defer shutdown ( "0" , nodes [0 ].log )
308+ defer nodes [0 ].log . Stop ( )
320309
321310 tx := nodes [0 ].BeginTxn ([]byte ("0" ), 2 )
322311
@@ -360,9 +349,9 @@ func TestSphinxNodeRelpayLaterBatch(t *testing.T) {
360349 t .Fatalf ("unable to create test route: %v" , err )
361350 }
362351
363- // Start the DecayedLog and defer shutdown
352+ // Start the ReplayLog and defer shutdown
364353 nodes [0 ].log .Start ()
365- defer shutdown ( "0" , nodes [0 ].log )
354+ defer nodes [0 ].log . Stop ( )
366355
367356 tx := nodes [0 ].BeginTxn ([]byte ("0" ), 1 )
368357
@@ -397,17 +386,17 @@ func TestSphinxNodeRelpayLaterBatch(t *testing.T) {
397386 }
398387}
399388
400- func TestSphinxNodeRelpayBatchIdempotency (t * testing.T ) {
389+ func TestSphinxNodeReplayBatchIdempotency (t * testing.T ) {
401390 // We'd like to ensure that the sphinx node itself rejects all replayed
402391 // packets which share the same shared secret.
403392 nodes , _ , fwdMsg , err := newTestRoute (NumMaxHops )
404393 if err != nil {
405394 t .Fatalf ("unable to create test route: %v" , err )
406395 }
407396
408- // Start the DecayedLog and defer shutdown
397+ // Start the ReplayLog and defer shutdown
409398 nodes [0 ].log .Start ()
410- defer shutdown ( "0" , nodes [0 ].log )
399+ defer nodes [0 ].log . Stop ( )
411400
412401 tx := nodes [0 ].BeginTxn ([]byte ("0" ), 1 )
413402
@@ -456,9 +445,9 @@ func TestSphinxAssocData(t *testing.T) {
456445 t .Fatalf ("unable to create random onion packet: %v" , err )
457446 }
458447
459- // Start the DecayedLog and defer shutdown
448+ // Start the ReplayLog and defer shutdown
460449 nodes [0 ].log .Start ()
461- defer shutdown ( "0" , nodes [0 ].log )
450+ defer nodes [0 ].log . Stop ( )
462451
463452 _ , err = nodes [0 ].ProcessOnionPacket (fwdMsg , []byte ("somethingelse" ), 1 )
464453 if err == nil {
0 commit comments