// src/smoke/libp2p.ts
import { fileURLToPath } from "url";
import { noise } from "@chainsafe/libp2p-noise";
import { yamux } from "@chainsafe/libp2p-yamux";
import { tcp } from "@libp2p/tcp";
import { createLibp2p } from "libp2p";
async function runLibp2pSmokeTest() {
  const node = await createLibp2p({
    addresses: {
      listen: ["/ip4/127.0.0.1/tcp/0"]
    },
    transports: [tcp()],
    connectionEncrypters: [noise()],
    streamMuxers: [yamux()]
  });
  const nodeCreated = Boolean(node);
  await node.start();
  const nodeStarted = node.status === "started";
  const peerId = node.peerId.toString();
  const listeningAddrs = node.getMultiaddrs().map((m) => m.toString());
  await node.stop();
  const nodeStopped = node.status === "stopped";
  return {
    nodeCreated,
    nodeStarted,
    peerId,
    listeningAddrs,
    nodeStopped
  };
}
var isMain = process.argv[1] !== void 0 && fileURLToPath(import.meta.url) === process.argv[1];
if (isMain) {
  try {
    const report = await runLibp2pSmokeTest();
    console.log("libp2p smoke test report:");
    console.log(JSON.stringify(report, null, 2));
    const allGood = report.nodeCreated && report.nodeStarted && report.nodeStopped && report.peerId.length > 0 && report.listeningAddrs.length > 0;
    if (!allGood) {
      console.error("libp2p smoke test failed");
      process.exit(1);
    }
    console.log("libp2p smoke test passed");
    process.exit(0);
  } catch (err) {
    console.error("libp2p smoke test error:", err);
    process.exit(1);
  }
}
export {
  runLibp2pSmokeTest
};
//# sourceMappingURL=libp2p.js.map