@@ -2,6 +2,8 @@ package sphinx
22
33import (
44 "testing"
5+
6+ "github.com/stretchr/testify/require"
57)
68
79// TestMemoryReplayLogStorageAndRetrieval tests that the non-batch methods on
@@ -130,3 +132,81 @@ func TestMemoryReplayLogPutBatch(t *testing.T) {
130132 t .Fatalf ("Unexpected replay set after adding batch 2 to log: %v" , err )
131133 }
132134}
135+
136+ // TestNoOpReplayLog tests that NoOpReplayLog performs no replay protection,
137+ // allowing all packets through without storing any state.
138+ func TestNoOpReplayLog (t * testing.T ) {
139+ t .Parallel ()
140+
141+ rl := NewNoOpReplayLog ()
142+
143+ // Start and Stop should succeed without error.
144+ require .NoError (t , rl .Start ())
145+ defer func () {
146+ require .NoError (t , rl .Stop ())
147+ }()
148+
149+ var hashPrefix HashPrefix
150+
151+ hashPrefix [0 ] = 1
152+
153+ // Get should always return ErrLogEntryNotFound since nothing is stored.
154+ _ , err := rl .Get (& hashPrefix )
155+ require .ErrorIs (t , err , ErrLogEntryNotFound )
156+
157+ // Put should always succeed.
158+ require .NoError (t , rl .Put (& hashPrefix , 1 ))
159+
160+ // Put the same packet again - should still succeed (no replay
161+ // detection).
162+ require .NoError (t , rl .Put (& hashPrefix , 1 ))
163+
164+ // Get should still return ErrLogEntryNotFound (nothing is stored).
165+ _ , err = rl .Get (& hashPrefix )
166+ require .ErrorIs (t , err , ErrLogEntryNotFound )
167+
168+ // Delete should succeed.
169+ require .NoError (t , rl .Delete (& hashPrefix ))
170+ }
171+
172+ // TestNoOpReplayLogPutBatch tests that NoOpReplayLog's PutBatch marks batches
173+ // as committed and never reports replays.
174+ func TestNoOpReplayLogPutBatch (t * testing.T ) {
175+ t .Parallel ()
176+
177+ rl := NewNoOpReplayLog ()
178+
179+ var hashPrefix1 , hashPrefix2 HashPrefix
180+
181+ hashPrefix1 [0 ] = 1
182+ hashPrefix2 [0 ] = 2
183+
184+ // Create a batch with duplicate packets.
185+ batch1 := NewBatch ([]byte {1 })
186+ require .NoError (t , batch1 .Put (1 , & hashPrefix1 , 1 ))
187+ require .NoError (t , batch1 .Put (2 , & hashPrefix1 , 1 ))
188+
189+ replays , err := rl .PutBatch (batch1 )
190+ require .NoError (t , err )
191+ require .True (t , batch1 .IsCommitted , "Batch should be marked as " +
192+ "committed" )
193+
194+ // NoOpReplayLog doesn't detect intra-batch replays (that's done by
195+ // Batch itself), but it should return an empty set from its own
196+ // detection.
197+ require .NotNil (t , replays )
198+
199+ // Create another batch with the same hash prefix - should not detect
200+ // replay since NoOpReplayLog doesn't store anything.
201+ batch2 := NewBatch ([]byte {2 })
202+ require .NoError (t , batch2 .Put (1 , & hashPrefix1 , 1 ))
203+ require .NoError (t , batch2 .Put (2 , & hashPrefix2 , 2 ))
204+
205+ replays , err = rl .PutBatch (batch2 )
206+ require .NoError (t , err )
207+ require .True (t , batch2 .IsCommitted , "Batch should be marked as " +
208+ "committed" )
209+
210+ // Should report no replays since NoOpReplayLog doesn't track state.
211+ require .Equal (t , 0 , replays .Size (), "Expected empty replay set" )
212+ }
0 commit comments