@@ -24,7 +24,7 @@ func TestCoreExchange_RequestHeaders(t *testing.T) {
24
24
25
25
cfg := DefaultTestConfig ()
26
26
fetcher , cctx := createCoreFetcher (t , cfg )
27
- generateNonEmptyBlocks (t , ctx , fetcher , cfg , cctx )
27
+ nonEmptyBlocks := generateNonEmptyBlocks (t , ctx , fetcher , cfg , cctx )
28
28
29
29
store , err := store .NewStore (store .DefaultParameters (), t .TempDir ())
30
30
require .NoError (t , err )
@@ -39,15 +39,15 @@ func TestCoreExchange_RequestHeaders(t *testing.T) {
39
39
genHeader , err := ce .Get (ctx , genBlock .Header .Hash ().Bytes ())
40
40
require .NoError (t , err )
41
41
42
- to := uint64 ( 30 )
42
+ to := nonEmptyBlocks [ len ( nonEmptyBlocks ) - 1 ]. height
43
43
expectedFirstHeightInRange := genHeader .Height () + 1
44
44
expectedLastHeightInRange := to - 1
45
45
expectedLenHeaders := to - expectedFirstHeightInRange
46
46
47
- _ , err = cctx .WaitForHeightWithTimeout (30 , 10 * time .Second )
47
+ _ , err = cctx .WaitForHeightWithTimeout (int64 ( to ) , 10 * time .Second )
48
48
require .NoError (t , err )
49
49
50
- // request headers from height 1 to 20 [2:30 )
50
+ // request headers from height 1 to last non-empty block height [2:to )
51
51
headers , err := ce .GetRangeByHeight (context .Background (), genHeader , to )
52
52
require .NoError (t , err )
53
53
@@ -74,7 +74,7 @@ func TestExchange_DoNotStoreHistoric(t *testing.T) {
74
74
75
75
cfg := DefaultTestConfig ()
76
76
fetcher , cctx := createCoreFetcher (t , cfg )
77
- generateNonEmptyBlocks (t , ctx , fetcher , cfg , cctx )
77
+ nonEmptyBlocks := generateNonEmptyBlocks (t , ctx , fetcher , cfg , cctx )
78
78
79
79
store , err := store .NewStore (store .DefaultParameters (), t .TempDir ())
80
80
require .NoError (t , err )
@@ -94,10 +94,12 @@ func TestExchange_DoNotStoreHistoric(t *testing.T) {
94
94
genHeader , err := ce .Get (ctx , genBlock .Header .Hash ().Bytes ())
95
95
require .NoError (t , err )
96
96
97
- err = cctx .WaitForBlocks (30 )
97
+ to := nonEmptyBlocks [len (nonEmptyBlocks )- 1 ].height
98
+
99
+ err = cctx .WaitForBlocks (int64 (to ))
98
100
require .NoError (t , err )
99
101
100
- headers , err := ce .GetRangeByHeight (ctx , genHeader , 30 )
102
+ headers , err := ce .GetRangeByHeight (ctx , genHeader , to )
101
103
require .NoError (t , err )
102
104
103
105
// ensure none of the "historic" EDSs were stored
@@ -121,11 +123,10 @@ func TestExchange_DoNotStoreHistoric(t *testing.T) {
121
123
func TestExchange_StoreHistoricIfArchival (t * testing.T ) {
122
124
ctx , cancel := context .WithCancel (context .Background ())
123
125
t .Cleanup (cancel )
124
- t .Setenv ("CELESTIA_OVERRIDE_AVAILABILITY_WINDOW" , "1ns" ) // all blocks will be "historic"
125
126
126
127
cfg := DefaultTestConfig ()
127
128
fetcher , cctx := createCoreFetcher (t , cfg )
128
- generateNonEmptyBlocks (t , ctx , fetcher , cfg , cctx )
129
+ nonEmptyBlocks := generateNonEmptyBlocks (t , ctx , fetcher , cfg , cctx )
129
130
130
131
store , err := store .NewStore (store .DefaultParameters (), t .TempDir ())
131
132
require .NoError (t , err )
@@ -134,7 +135,8 @@ func TestExchange_StoreHistoricIfArchival(t *testing.T) {
134
135
fetcher ,
135
136
store ,
136
137
header .MakeExtendedHeader ,
137
- WithArchivalMode (), // make sure to store them anyway
138
+ WithAvailabilityWindow (time .Nanosecond ), // all blocks will be historic
139
+ WithArchivalMode (), // make sure to store them anyway
138
140
)
139
141
require .NoError (t , err )
140
142
@@ -145,10 +147,12 @@ func TestExchange_StoreHistoricIfArchival(t *testing.T) {
145
147
genHeader , err := ce .Get (ctx , genBlock .Header .Hash ().Bytes ())
146
148
require .NoError (t , err )
147
149
148
- _ , err = cctx .WaitForHeight (30 )
150
+ to := nonEmptyBlocks [len (nonEmptyBlocks )- 1 ].height
151
+
152
+ _ , err = cctx .WaitForHeight (int64 (to ))
149
153
require .NoError (t , err )
150
154
151
- headers , err := ce .GetRangeByHeight (ctx , genHeader , 30 )
155
+ headers , err := ce .GetRangeByHeight (ctx , genHeader , to )
152
156
require .NoError (t , err )
153
157
154
158
// ensure all "historic" EDSs were stored but not the .q4 files
@@ -205,14 +209,19 @@ func fillBlocks(
205
209
}
206
210
}
207
211
212
+ type testBlocks struct {
213
+ height uint64
214
+ datahash share.DataHash
215
+ }
216
+
208
217
// generateNonEmptyBlocks generates at least 20 non-empty blocks
209
218
func generateNonEmptyBlocks (
210
219
t * testing.T ,
211
220
ctx context.Context ,
212
221
fetcher * BlockFetcher ,
213
222
cfg * testnode.Config ,
214
223
cctx testnode.Context ,
215
- ) []share. DataHash {
224
+ ) []testBlocks {
216
225
// generate several non-empty blocks
217
226
generateCtx , generateCtxCancel := context .WithCancel (context .Background ())
218
227
@@ -221,7 +230,7 @@ func generateNonEmptyBlocks(
221
230
222
231
go fillBlocks (t , generateCtx , cfg , cctx )
223
232
224
- hashes := make ([]share. DataHash , 0 , 20 )
233
+ filledBlocks := make ([]testBlocks , 0 , 20 )
225
234
226
235
i := 0
227
236
for i < 20 {
@@ -232,13 +241,16 @@ func generateNonEmptyBlocks(
232
241
if bytes .Equal (share .EmptyEDSDataHash (), b .Data .Hash ()) {
233
242
continue
234
243
}
235
- hashes = append (hashes , share .DataHash (b .Data .Hash ()))
244
+ filledBlocks = append (filledBlocks , testBlocks {
245
+ height : uint64 (b .Header .Height ),
246
+ datahash : share .DataHash (b .Data .Hash ()),
247
+ })
236
248
i ++
237
249
case <- ctx .Done ():
238
250
t .Fatal ("failed to fill blocks within timeout" )
239
251
}
240
252
}
241
253
generateCtxCancel ()
242
254
243
- return hashes
255
+ return filledBlocks
244
256
}
0 commit comments