diff --git a/lib/http-bridge/test/integration/js/mock-daedalus.js b/lib/http-bridge/test/integration/js/mock-daedalus.js new file mode 100755 index 00000000000..a4aa4d36d78 --- /dev/null +++ b/lib/http-bridge/test/integration/js/mock-daedalus.js @@ -0,0 +1,57 @@ +#!/usr/bin/env node + +// This runs cardano-wallet-launcher in the same way that Daedalus would. +// It needs node, cardano-wallet, and cardano-wallet-launcher on the PATH to run. + +const child_process = require("child_process"); +const http = require('http'); + +function main() { + // const proc = child_process.spawn("cardano-wallet", ["server"], { + const proc = child_process.spawn("cardano-wallet-launcher", [], { + stdio: ["ignore", "inherit", "inherit", "ipc"] + }); + + proc.on("close", function(code, signal) { + console.log("JS: child_process stdio streams closed"); + process.exit(1); + }); + + proc.on("disconnect", function() { + console.log("JS: child_process disconnected"); + process.exit(2); + }); + + proc.on("error", function(err) { + console.log("JS: error child_process: " + err); + process.exit(3); + }); + + proc.on("exit", function(code, signal) { + console.log("JS: child_process exited with status " + code + " or signal " + signal); + process.exit(4); + }); + + proc.on("message", function(msg) { + console.log("JS: message received", msg); + if (msg.Started) { + proc.send("QueryPort"); + } else if (msg.ReplyPort) { + http.get({ + hostname: "localhost", + port: msg.ReplyPort, + path: "/v2/wallets", + agent: false + }, (res) => { + console.log("JS: response from wallet: " + res.statusCode); + res.resume(); + res.on("end", () => { + console.log("JS: request response from wallet finished, exiting."); + process.exit(0); + }); + }); + } + }); +} + +main();