Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Add DaedalusIPC nodejs test #221

Merged
merged 3 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cardano-shell.cabal
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cabal-version: 2.2
name: cardano-shell
version: 0.1.0.0
description: Please see the README on GitHub at <https://github.com/githubuser/cardano-shell#readme>
Expand All @@ -10,10 +11,10 @@ copyright: 2018 IOHK
license: MIT
license-file: LICENSE
build-type: Simple
cabal-version: >= 1.10
extra-source-files:
ChangeLog.md
README.md
test/js/mock-daedalus.js

source-repository head
type: git
Expand Down Expand Up @@ -208,6 +209,7 @@ test-suite cardano-shell-test
other-modules:
Paths_cardano_shell
DhallConfigSpec
DaedalusIPCSpec
UpdaterSpec
if !os(windows)
other-modules:
Expand All @@ -224,6 +226,7 @@ test-suite cardano-shell-test
, cardano-prelude
, dhall
, safe-exceptions
, process
-- quickcheck
, QuickCheck
-- SM
Expand All @@ -237,6 +240,8 @@ test-suite cardano-shell-test
, concurrency
, dejafu
, hunit-dejafu
build-tool-depends:
cardano-shell:daedalus-ipc
default-language: Haskell2010
default-extensions: NoImplicitPrelude
OverloadedStrings
Expand Down
6 changes: 5 additions & 1 deletion nix/.stack.nix/cardano-shell.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions nix/iohk-nix-src.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"url": "https://github.com/input-output-hk/iohk-nix",
"rev": "eec83e9bba05093c94004a001caebae252c0c83b",
"date": "2019-06-26T17:23:10+00:00",
"sha256": "00b11qmgr57pm6gg7a8m6fzjj6m5wmh8hnwg16jnqsmf52882y2j",
"rev": "3cee475f26458ef113a494b216b1504513fa4d03",
"date": "2019-07-05T14:51:43+00:00",
"sha256": "04dqb2ii03y1lvyqn3v3xwardym2h6g5zbgvjljam758w768vmii",
"fetchSubmodules": false
}
5 changes: 5 additions & 0 deletions nix/pkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ let
# turtle seems to have the same issue.
packages.turtle.doExactConfig = true;
}

{
packages.cardano-shell.src = haskell.cleanSourceHaskell ../.;
packages.cardano-shell.components.tests.cardano-shell-test.build-tools = [ pkgs.nodejs ];
}
];
};

Expand Down
17 changes: 17 additions & 0 deletions test/DaedalusIPCSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module DaedalusIPCSpec
( spec
) where

import Cardano.Prelude

import System.Exit (ExitCode (..))
import System.Process ( createProcess, proc, waitForProcess)
import Test.Hspec (Spec, describe, it, shouldReturn)

spec :: Spec
spec = describe "DaedalusIPC" $ do
it "should reply with the port when asked" $ do
let port = 42 :: Int
let testScript = "test/js/mock-daedalus.js"
(_, _, _, ph) <- createProcess (proc "node" [testScript, show port])
waitForProcess ph `shouldReturn` ExitSuccess
5 changes: 2 additions & 3 deletions test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Cardano.Shell.Types (CardanoFeature (..))
import DhallConfigSpec (dhallConfigSpec, mkConfigSpec)
import NodeIPCSMSpec (nodeIPCSMSpec)
import NodeIPCSpec (nodeIPCSpec)
import qualified DaedalusIPCSpec as DaedalusIPC
import UpdaterSpec (updaterSpec)

-- | Entry point for tests.
Expand All @@ -30,6 +31,7 @@ main = hspec $ do
describe "Cardano configurations" mkConfigSpec
describe "NodeIPC state machine" nodeIPCSMSpec
describe "NodeIPC" nodeIPCSpec
describe "DaedalusIPC" DaedalusIPC.spec
describe "Update system" updaterSpec

-- | A valid concurrency specification.
Expand Down Expand Up @@ -146,6 +148,3 @@ concurrencyDSLGenerator = frequency
-- | A delay from one millisecond to ten milliseconds.
generateMillisecondDelay :: Gen Int
generateMillisecondDelay = choose (1, 10)



54 changes: 54 additions & 0 deletions test/js/mock-daedalus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env node

// This runs the daedalus-ipc executable in the same way that Daedalus would run cardano-wallet.
// It needs node and daedalus-ipc on the PATH to run.

const child_process = require("child_process");
const http = require('http');

function main() {
let port = process.argv[2];
const proc = child_process.spawn("daedalus-ipc", [port],
{ stdio: ["ignore", "inherit", "inherit", "ipc"] }
);

proc.on("close", function(code, signal) {
console.log("JS: child_process stdio streams closed");
process.exit(2);
});

proc.on("disconnect", function() {
console.log("JS: child_process disconnected");
process.exit(3);
});

proc.on("error", function(err) {
console.log("JS: error child_process: " + err);
process.exit(4);
});

proc.on("exit", function(code, signal) {
console.log("JS: child_process exited with status " + code + " or signal " + signal);
process.exit(5);
});

proc.on("message", function(msg) {
console.log("JS: message received", msg);
// See CardanoNode.js in Daedalus for the message types in use.
if (msg.Started) {
console.log("JS: sending a bogus message");
proc.send("hello");
} else if (msg.ParseError && msg.ParseError.match(/encountered String/)) {
console.log("JS: sending QueryPort");
proc.send({ QueryPort: [] });
} else if (msg.ParseError) {
console.log("JS: i did not expect that");
process.exit(6);
} else if (msg.ReplyPort) {
console.log("JS: received ReplyPort " + msg.ReplyPort + ", expecting " + port);
process.exit(msg.ReplyPort == port ? 0 : 1);
}
});
}

main();