Skip to content

Commit 9cb8ada

Browse files
committed
feat(browser-tests): use nwaku-style format for light push log
1 parent 7a41587 commit 9cb8ada

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

packages/browser-tests/src/routes/waku.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ router.post(
5959
transformResult: (result) => {
6060
if (result && result.successes && result.successes.length > 0) {
6161
console.log("[Server] Message successfully sent via v3 lightpush!");
62+
63+
const sentTime = Date.now() * 1000000;
64+
const msgHash = result.messageHash;
65+
66+
const myPeerId = result.myPeerId || 'unknown';
67+
result.successes.forEach((peerId: string) => {
68+
console.log(`publishWithConn my_peer_id=${myPeerId} peer_id=${peerId} msg_hash=${msgHash} sentTime=${sentTime}`);
69+
});
70+
6271
return {
6372
success: true,
6473
result,

packages/browser-tests/web/index.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import {
99
AutoSharding,
1010
DEFAULT_CLUSTER_ID,
1111
DEFAULT_NUM_SHARDS,
12+
IMessage,
1213
ShardId,
1314
StaticSharding,
1415
} from "@waku/interfaces";
1516
import { bootstrap } from "@libp2p/bootstrap";
1617
import { EnrDecoder, TransportProtocol } from "@waku/enr";
1718
import type { ITestBrowser } from "../types/global.js";
1819
import { StaticShardingRoutingInfo } from "@waku/utils";
20+
import { messageHashStr } from "@waku/core";
1921

2022
export interface SerializableSDKProtocolResult {
2123
successes: string[];
@@ -24,6 +26,7 @@ export interface SerializableSDKProtocolResult {
2426
peerId?: string;
2527
}>;
2628
myPeerId?: string;
29+
messageHash?: string;
2730
}
2831

2932
function makeSerializable(result: any): SerializableSDKProtocolResult {
@@ -173,6 +176,11 @@ export class WakuHeadless {
173176
processedPayload = new TextEncoder().encode(payload);
174177
}
175178

179+
const message: IMessage = {
180+
payload: processedPayload,
181+
timestamp: new Date(),
182+
};
183+
176184
try {
177185
const lightPush = this.waku.lightPush;
178186
if (!lightPush) {
@@ -197,6 +205,11 @@ export class WakuHeadless {
197205
console.log("Pubsub topic:", pubsubTopic);
198206
console.log("Encoder pubsub topic:", encoder.pubsubTopic);
199207

208+
const protoObj = await encoder.toProtoObj(message);
209+
if (!protoObj) {
210+
throw new Error("Failed to convert message to proto object");
211+
}
212+
200213
if (pubsubTopic && pubsubTopic !== encoder.pubsubTopic) {
201214
console.warn(
202215
`Explicit pubsubTopic ${pubsubTopic} provided, but auto-sharding determined ${encoder.pubsubTopic}. Using auto-sharding.`,
@@ -210,10 +223,7 @@ export class WakuHeadless {
210223
this.lightpushNode,
211224
);
212225
if (preferredPeerId) {
213-
result = await lightPush.send(encoder, {
214-
payload: processedPayload,
215-
timestamp: new Date(),
216-
});
226+
result = await lightPush.send(encoder, message);
217227
console.log("✅ Message sent via preferred lightpush node");
218228
} else {
219229
throw new Error(
@@ -225,20 +235,25 @@ export class WakuHeadless {
225235
"Couldn't send message via preferred lightpush node:",
226236
error,
227237
);
228-
result = await lightPush.send(encoder, {
229-
payload: processedPayload,
230-
timestamp: new Date(),
231-
});
238+
result = await lightPush.send(encoder, message);
232239
}
233240
} else {
234-
result = await lightPush.send(encoder, {
235-
payload: processedPayload,
236-
timestamp: new Date(),
237-
});
241+
result = await lightPush.send(encoder, message);
238242
}
239243

240244
const serializableResult = makeSerializable(result);
241245

246+
serializableResult.myPeerId = this.waku.libp2p.peerId.toString();
247+
248+
const messageHash = '0x' + messageHashStr(
249+
encoder.pubsubTopic,
250+
protoObj,
251+
);
252+
253+
console.log("Message hash:", messageHash);
254+
255+
serializableResult.messageHash = messageHash;
256+
242257
return serializableResult;
243258
} catch (error) {
244259
console.error("Error sending message via v3 lightpush:", error);

0 commit comments

Comments
 (0)