logos-delivery/tests/waku_lightpush/lightpush_utils.nim

34 lines
938 B
Nim
Raw Normal View History

{.used.}
import std/options, chronos, chronicles, libp2p/crypto/crypto
import
waku/node/peer_manager,
waku/waku_core,
feat: lightpush v3 (#3279) * Separate new lightpush protocol New RPC defined Rename al occurence of old lightpush to legacy lightpush, fix rest tests of lightpush New lightpush protocol added back Setup new lightpush protocol, mounting and rest api for it modified: apps/chat2/chat2.nim modified: tests/node/test_wakunode_lightpush.nim modified: tests/node/test_wakunode_sharding.nim modified: tests/test_peer_manager.nim modified: tests/test_wakunode_lightpush.nim renamed: tests/waku_lightpush/lightpush_utils.nim -> tests/waku_lightpush_legacy/lightpush_utils.nim renamed: tests/waku_lightpush/test_all.nim -> tests/waku_lightpush_legacy/test_all.nim renamed: tests/waku_lightpush/test_client.nim -> tests/waku_lightpush_legacy/test_client.nim renamed: tests/waku_lightpush/test_ratelimit.nim -> tests/waku_lightpush_legacy/test_ratelimit.nim modified: tests/wakunode_rest/test_all.nim renamed: tests/wakunode_rest/test_rest_lightpush.nim -> tests/wakunode_rest/test_rest_lightpush_legacy.nim modified: waku/factory/node_factory.nim modified: waku/node/waku_node.nim modified: waku/waku_api/rest/admin/handlers.nim modified: waku/waku_api/rest/builder.nim new file: waku/waku_api/rest/legacy_lightpush/client.nim new file: waku/waku_api/rest/legacy_lightpush/handlers.nim new file: waku/waku_api/rest/legacy_lightpush/types.nim modified: waku/waku_api/rest/lightpush/client.nim modified: waku/waku_api/rest/lightpush/handlers.nim modified: waku/waku_api/rest/lightpush/types.nim modified: waku/waku_core/codecs.nim modified: waku/waku_lightpush.nim modified: waku/waku_lightpush/callbacks.nim modified: waku/waku_lightpush/client.nim modified: waku/waku_lightpush/common.nim modified: waku/waku_lightpush/protocol.nim modified: waku/waku_lightpush/rpc.nim modified: waku/waku_lightpush/rpc_codec.nim modified: waku/waku_lightpush/self_req_handler.nim new file: waku/waku_lightpush_legacy.nim renamed: waku/waku_lightpush/README.md -> waku/waku_lightpush_legacy/README.md new file: waku/waku_lightpush_legacy/callbacks.nim new file: waku/waku_lightpush_legacy/client.nim new file: waku/waku_lightpush_legacy/common.nim new file: waku/waku_lightpush_legacy/protocol.nim new file: waku/waku_lightpush_legacy/protocol_metrics.nim new file: waku/waku_lightpush_legacy/rpc.nim new file: waku/waku_lightpush_legacy/rpc_codec.nim new file: waku/waku_lightpush_legacy/self_req_handler.nim Adapt to non-invasive libp2p observers cherry pick latest lightpush (v1) changes into legacy lightpush code after rebase to latest master Fix vendor dependencies from origin/master after failed rebase of them Adjust examples, test to new lightpush - keep using of legacy Fixup error code mappings Fix REST admin interface with distinct legacy and new lightpush Fix lightpush v2 tests * Utilize new publishEx interface of pubsub libp2p * Adapt to latest libp2p pubslih design changes. publish returns an outcome as Result error. * Fix review findings * Fix tests, re-added lost one * Fix rebase * Apply suggestions from code review Co-authored-by: Ivan FB <128452529+Ivansete-status@users.noreply.github.com> * Addressing review comments * Fix incentivization tests * Fix build failed on libwaku * Change new lightpush endpoint version to 3 instead of 2. Noticed that old and new lightpush metrics can cause trouble in monitoring dashboards so decided to give new name as v3 for the new lightpush metrics and change legacy ones back - temporarly till old lightpush will be decommissioned * Fixing flaky test with rate limit timing * Fixing logscope of lightpush and legacy lightpush --------- Co-authored-by: Ivan FB <128452529+Ivansete-status@users.noreply.github.com>
2025-03-05 12:07:56 +01:00
waku/waku_core/topics/sharding,
waku/waku_lightpush,
waku/waku_lightpush/[client, common],
waku/common/rate_limit/setting,
../testlib/[common, wakucore]
proc newTestWakuLightpushNode*(
switch: Switch,
handler: PushMessageHandler,
rateLimitSetting: Option[RateLimitSetting] = none[RateLimitSetting](),
): Future[WakuLightPush] {.async.} =
let
peerManager = PeerManager.new(switch)
wakuAutoSharding = Sharding(clusterId: 1, shardCountGenZero: 8)
proto = WakuLightPush.new(
fix(tests): libp2p v2.0.0 API migrations across test suite Three small classes of fix across 12 test files (uncovered by a local `nim c` sweep of tests/all_tests_common.nim + tests/all_tests_waku.nim): 1. `rng` no longer auto-calls when used as an argument: libp2p v2.0.0 exports its own `rng` symbol (SwitchBuilder field), so Nim's resolver sees the testlib `common.rng` template ambiguously and stops auto- calling it. Add explicit `()`: - tests/test_helpers.nim - tests/waku_filter_v2/waku_filter_utils.nim - tests/waku_lightpush/lightpush_utils.nim - tests/waku_lightpush_legacy/lightpush_utils.nim - tests/node/test_wakunode_filter.nim - tests/waku_store/store_utils.nim 2. `PeerId.random()` zero-arg form removed in v2.0.0; new signature takes `rng: Rng`. Add `newRng()` + `libp2p/crypto/crypto` import: - tests/common/test_requestratelimiter.nim - tests/common/test_ratelimit_setting.nim 3. `some()` ambiguity vs `Opt.some` — files that don't directly `import std/options` get `Opt.some` template only, breaking calls intended for `Option[T]`. Add `std/options` to imports: - tests/waku_store/test_wakunode_store.nim - tests/waku_relay/test_wakunode_relay.nim 4. Two more API removals: - tests/testlib/wakunode.nim — `builders.MaxConnections` was removed; use `DefaultMaxConnections` from `libp2p/connmanager`. - tests/waku_rln_relay/utils_onchain.nim — `keys.PrivateKey.random (rng[])` `rng` ambiguous between testlib/common and eth/keys exports; qualify as `common.rng()[]`. There are still more test-compile errors past this point — this is incremental progress, not a complete v2.0.0 test-suite migration.
2026-06-04 18:55:26 +05:30
peerManager, rng(), handler, some(wakuAutoSharding), rateLimitSetting
)
await proto.start()
switch.mount(proto)
return proto
proc newTestWakuLightpushClient*(switch: Switch): WakuLightPushClient =
let peerManager = PeerManager.new(switch)
fix(tests): libp2p v2.0.0 API migrations across test suite Three small classes of fix across 12 test files (uncovered by a local `nim c` sweep of tests/all_tests_common.nim + tests/all_tests_waku.nim): 1. `rng` no longer auto-calls when used as an argument: libp2p v2.0.0 exports its own `rng` symbol (SwitchBuilder field), so Nim's resolver sees the testlib `common.rng` template ambiguously and stops auto- calling it. Add explicit `()`: - tests/test_helpers.nim - tests/waku_filter_v2/waku_filter_utils.nim - tests/waku_lightpush/lightpush_utils.nim - tests/waku_lightpush_legacy/lightpush_utils.nim - tests/node/test_wakunode_filter.nim - tests/waku_store/store_utils.nim 2. `PeerId.random()` zero-arg form removed in v2.0.0; new signature takes `rng: Rng`. Add `newRng()` + `libp2p/crypto/crypto` import: - tests/common/test_requestratelimiter.nim - tests/common/test_ratelimit_setting.nim 3. `some()` ambiguity vs `Opt.some` — files that don't directly `import std/options` get `Opt.some` template only, breaking calls intended for `Option[T]`. Add `std/options` to imports: - tests/waku_store/test_wakunode_store.nim - tests/waku_relay/test_wakunode_relay.nim 4. Two more API removals: - tests/testlib/wakunode.nim — `builders.MaxConnections` was removed; use `DefaultMaxConnections` from `libp2p/connmanager`. - tests/waku_rln_relay/utils_onchain.nim — `keys.PrivateKey.random (rng[])` `rng` ambiguous between testlib/common and eth/keys exports; qualify as `common.rng()[]`. There are still more test-compile errors past this point — this is incremental progress, not a complete v2.0.0 test-suite migration.
2026-06-04 18:55:26 +05:30
WakuLightPushClient.new(peerManager, rng())