Skip to content

Commit 45e4218

Browse files
committed
simplify
1 parent b964a7b commit 45e4218

File tree

1 file changed

+16
-37
lines changed

1 file changed

+16
-37
lines changed

test/e2e/da_posting_integration_test.go

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
tastorada "github.com/celestiaorg/tastora/framework/docker/dataavailability"
2020
"github.com/celestiaorg/tastora/framework/docker/evstack"
2121
"github.com/celestiaorg/tastora/framework/testutil/query"
22+
"github.com/celestiaorg/tastora/framework/testutil/wait"
2223
tastoratypes "github.com/celestiaorg/tastora/framework/types"
2324
sdk "github.com/cosmos/cosmos-sdk/types"
2425
"github.com/cosmos/cosmos-sdk/types/module/testutil"
@@ -193,16 +194,16 @@ func TestEvNode_PostsToDA(t *testing.T) {
193194
_, err = cli.Post(ctx, "/tx", key, value)
194195
require.NoError(t, err)
195196

196-
waitFor(ctx, t, 30*time.Second, 2*time.Second, func() bool {
197+
wait.ForCondition(ctx, 30*time.Second, 2*time.Second, func() (bool, error) {
197198
res, err := cli.Get(ctx, "/kv?key="+key)
198199
if err != nil {
199-
return false
200+
return false, nil
200201
}
201-
return string(res) == value
202-
}, "ev-node should serve the kv value")
202+
return string(res) == value, nil
203+
})
203204

204205
// 6) Assert data landed on DA via celestia-node blob RPC (namespace ev-data)
205-
daRPCAddr := fmt.Sprintf("http://127.0.0.1:%s", bridgeNetInfo.External.Ports.RPC)
206+
daRPCAddr := fmt.Sprintf("http://%s", bridgeNetInfo.Internal.RPCAddress())
206207
daClient, err := jsonrpc.NewClient(ctx, zerolog.Nop(), daRPCAddr, authToken, seqcommon.AbsoluteMaxBlobSize)
207208
require.NoError(t, err, "new da client")
208209
defer daClient.Close()
@@ -212,10 +213,10 @@ func TestEvNode_PostsToDA(t *testing.T) {
212213
require.NoError(t, err, "tm rpc client")
213214

214215
var pfbHeight int64
215-
waitFor(ctx, t, time.Minute, 5*time.Second, func() bool {
216+
wait.ForCondition(ctx, time.Minute, 5*time.Second, func() (bool, error) {
216217
res, err := tmRPC.TxSearch(ctx, "message.action='/celestia.blob.v1.MsgPayForBlobs'", false, nil, nil, "desc")
217218
if err != nil || len(res.Txs) == 0 {
218-
return false
219+
return false, nil
219220
}
220221
dataNSB64 := base64.StdEncoding.EncodeToString(dataNamespace.Bytes())
221222
for _, tx := range res.Txs {
@@ -229,17 +230,17 @@ func TestEvNode_PostsToDA(t *testing.T) {
229230
for _, attr := range ev.Attributes {
230231
if string(attr.Key) == "namespaces" && strings.Contains(string(attr.Value), dataNSB64) {
231232
pfbHeight = tx.Height
232-
return true
233+
return true, nil
233234
}
234235
}
235236
}
236237
}
237-
return false
238-
}, "expected a PayForBlobs tx on celestia-app")
238+
return false, nil
239+
})
239240

240-
waitFor(ctx, t, time.Minute, 5*time.Second, func() bool {
241+
wait.ForCondition(ctx, time.Minute, 5*time.Second, func() (bool, error) {
241242
if pfbHeight == 0 {
242-
return false
243+
return false, nil
243244
}
244245
for h := pfbHeight; h <= pfbHeight+10; h++ {
245246
ids, err := daClient.DA.GetIDs(ctx, uint64(h), dataNamespace.Bytes())
@@ -248,11 +249,11 @@ func TestEvNode_PostsToDA(t *testing.T) {
248249
continue
249250
}
250251
if ids != nil && len(ids.IDs) > 0 {
251-
return true
252+
return true, nil
252253
}
253254
}
254-
return false
255-
}, "expected blob in DA for namespace ev-data")
255+
return false, nil
256+
})
256257
}
257258

258259
// newHTTPClient is a small helper to avoid importing the docker_e2e client.
@@ -309,25 +310,3 @@ func getEnvDefault(key, def string) string {
309310
}
310311
return def
311312
}
312-
313-
// waitFor polls condition until it returns true, context is cancelled, or timeout expires.
314-
func waitFor(ctx context.Context, t *testing.T, timeout, interval time.Duration, condition func() bool, msg string) {
315-
t.Helper()
316-
deadline := time.Now().Add(timeout)
317-
ticker := time.NewTicker(interval)
318-
defer ticker.Stop()
319-
320-
for {
321-
select {
322-
case <-ctx.Done():
323-
t.Fatalf("%s: context cancelled: %v", msg, ctx.Err())
324-
case <-ticker.C:
325-
if time.Now().After(deadline) {
326-
t.Fatalf("%s: timed out after %v", msg, timeout)
327-
}
328-
if condition() {
329-
return
330-
}
331-
}
332-
}
333-
}

0 commit comments

Comments
 (0)