Browse Source

Shared the .vscode directory between the different crates.

Matthew Carr 2 years ago
parent
commit
22afbad1b8

+ 28 - 0
crates/.vscode/launch.json

@@ -0,0 +1,28 @@
+{
+    // Use IntelliSense to learn about possible attributes.
+    // Hover to view descriptions of existing attributes.
+    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "type": "lldb",
+            "request": "launch",
+            "name": "Debug binary",
+            "cargo": {
+                "args": [ "build" ]
+            },
+            "args": [],
+            "cwd": "${workspaceFolder}"
+        },
+        {
+            "type": "lldb",
+            "request": "launch",
+            "name": "Debug unit tests",
+            "cargo": {
+                "args": [ "test" ]
+            },
+            "args": [],
+            "cwd": "${workspaceFolder}"
+        }
+    ]
+}

+ 0 - 0
crates/node/.vscode/settings.json → crates/.vscode/settings.json


+ 0 - 0
crates/node/.vscode/tasks.json → crates/.vscode/tasks.json


+ 1 - 0
crates/btnode/.vscode

@@ -0,0 +1 @@
+../.vscode

+ 16 - 16
crates/node/Cargo.lock → crates/btnode/Cargo.lock

@@ -49,6 +49,22 @@ version = "1.3.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
 
+[[package]]
+name = "btnode"
+version = "0.1.0"
+dependencies = [
+ "base64-url",
+ "env_logger",
+ "harness",
+ "log",
+ "openssl",
+ "serde",
+ "serde-big-array",
+ "serde-block-tree",
+ "strum",
+ "strum_macros",
+]
+
 [[package]]
 name = "cc"
 version = "1.0.73"
@@ -140,22 +156,6 @@ version = "2.5.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
 
-[[package]]
-name = "node"
-version = "0.1.0"
-dependencies = [
- "base64-url",
- "env_logger",
- "harness",
- "log",
- "openssl",
- "serde",
- "serde-big-array",
- "serde-block-tree",
- "strum",
- "strum_macros",
-]
-
 [[package]]
 name = "once_cell"
 version = "1.13.0"

+ 1 - 1
crates/node/Cargo.toml → crates/btnode/Cargo.toml

@@ -1,5 +1,5 @@
 [package]
-name = "node"
+name = "btnode"
 version = "0.1.0"
 authors = ["Matthew Carr <mdcarr941@gmail.com>"]
 edition = "2021"

+ 0 - 0
crates/node/README.md → crates/btnode/README.md


+ 0 - 0
crates/node/src/crypto.rs → crates/btnode/src/crypto.rs


+ 9 - 1
crates/node/src/main.rs → crates/btnode/src/main.rs

@@ -367,7 +367,15 @@ fn main() {
             Ok(message) => message,
         };
         match message {
-            Message::Echo(_) => send(&mut out_lock, &message), 
+            Message::Echo(_) => {
+                if let Err(err) = write_to(&message, &mut out_lock) {
+                    error!("Failed to serialize message {:?}", err);
+                    return;
+                }
+                if let Err(err) = out_lock.flush() {
+                    error!("Failed to flush stdout {:?}", err);
+                }
+            }, 
         }
     }
 }

+ 0 - 0
crates/node/src/serde_tests.rs → crates/btnode/src/serde_tests.rs


+ 0 - 0
crates/node/src/test_helpers.rs → crates/btnode/src/test_helpers.rs


+ 1 - 0
crates/harness/.vscode

@@ -0,0 +1 @@
+../.vscode

+ 21 - 16
crates/harness/src/lib.rs

@@ -21,7 +21,7 @@ pub struct Node {
 
 impl Node {
     pub fn new() -> Result<Node, std::io::Error> {
-        let mut child = Command::new("blocktree-node")
+        let mut child = Command::new("btnode")
             .stdin(Stdio::piped())
             .stdout(Stdio::piped())
             .stderr(Stdio::inherit())
@@ -82,27 +82,32 @@ impl Drop for Node {
 mod test {
     use super::*;
     use ctor::ctor;
-    use env_logger;
+    use log::info;
 
     #[ctor]
-    fn setup_logging() {
-        env_logger::init();
-    }
-
-    #[test]
-    fn node_new() {
-        Node::new().unwrap();
+    fn test_init() {
+        use env_logger::{self, Env};
+        env_logger::init_from_env(Env::default().default_filter_or("debug"));
+        info!("Using cargo to install btnode...");
+        let success = Command::new("cargo")
+            .args(["install", "--path", "../btnode"])
+            .status()
+            .expect("failed to invoke cargo")
+            .success();
+        assert!(success, "failed to build btnode");
     }
 
     #[test]
     fn message_echo() {
         let mut node = Node::new().unwrap();
-        let payload = "Howdy".to_string();
-        node.send(&Message::Echo(payload.clone())).unwrap();
-        let reply = node.receive(Duration::from_millis(100)).unwrap();
-        let reply_payload = match reply {
-            Message::Echo(payload) => Some(payload),
-        };
-        assert_eq!(Some(payload), reply_payload);
+        for k in 0..7 {
+            let expected = format!("Rep number {}", k);
+            node.send(&Message::Echo(expected.clone())).unwrap();
+            let reply = node.receive(Duration::from_millis(100)).unwrap();
+            let reply_payload = match reply {
+                Message::Echo(actual) => actual,
+            };
+            assert_eq!(expected, reply_payload.as_str());
+        }
     }
 }

+ 0 - 45
crates/node/.vscode/launch.json

@@ -1,45 +0,0 @@
-{
-    // Use IntelliSense to learn about possible attributes.
-    // Hover to view descriptions of existing attributes.
-    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
-    "version": "0.2.0",
-    "configurations": [
-        {
-            "type": "lldb",
-            "request": "launch",
-            "name": "Debug executable 'node'",
-            "cargo": {
-                "args": [
-                    "build",
-                    "--bin=node",
-                    "--package=node"
-                ],
-                "filter": {
-                    "name": "node",
-                    "kind": "bin"
-                }
-            },
-            "args": [],
-            "cwd": "${workspaceFolder}"
-        },
-        {
-            "type": "lldb",
-            "request": "launch",
-            "name": "Debug unit tests in executable 'node'",
-            "cargo": {
-                "args": [
-                    "test",
-                    "--no-run",
-                    "--bin=node",
-                    "--package=node"
-                ],
-                "filter": {
-                    "name": "node",
-                    "kind": "bin"
-                }
-            },
-            "args": [],
-            "cwd": "${workspaceFolder}"
-        }
-    ]
-}

+ 1 - 0
crates/sandbox/.vscode

@@ -0,0 +1 @@
+../.vscode

+ 1 - 0
crates/serde-block-tree/.vscode

@@ -0,0 +1 @@
+../.vscode

+ 0 - 45
crates/serde-block-tree/.vscode/launch.json

@@ -1,45 +0,0 @@
-{
-    // Use IntelliSense to learn about possible attributes.
-    // Hover to view descriptions of existing attributes.
-    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
-    "version": "0.2.0",
-    "configurations": [
-        {
-            "type": "lldb",
-            "request": "launch",
-            "name": "Debug executable 'node'",
-            "cargo": {
-                "args": [
-                    "build",
-                    "--bin=node",
-                    "--package=node"
-                ],
-                "filter": {
-                    "name": "node",
-                    "kind": "bin"
-                }
-            },
-            "args": [],
-            "cwd": "${workspaceFolder}"
-        },
-        {
-            "type": "lldb",
-            "request": "launch",
-            "name": "Debug unit tests in executable 'node'",
-            "cargo": {
-                "args": [
-                    "test",
-                    "--no-run",
-                    "--bin=node",
-                    "--package=node"
-                ],
-                "filter": {
-                    "name": "node",
-                    "kind": "bin"
-                }
-            },
-            "args": [],
-            "cwd": "${workspaceFolder}"
-        }
-    ]
-}

+ 0 - 8
crates/serde-block-tree/.vscode/settings.json

@@ -1,8 +0,0 @@
-{
-    "cSpell.words": [
-        "Asym",
-        "blocktree",
-        "newtype",
-        "Xsalsa"
-    ]
-}

+ 0 - 25
crates/serde-block-tree/.vscode/tasks.json

@@ -1,25 +0,0 @@
-{
-    // See https://go.microsoft.com/fwlink/?LinkId=733558
-    // for the documentation about the tasks.json format
-    "version": "2.0.0",
-    "tasks": [
-        {
-            "type": "cargo",
-            "subcommand": "test",
-            "problemMatcher": [
-                "$rustc"
-            ],
-            "group": "test",
-            "label": "test"
-        },
-        {
-            "type": "cargo",
-            "subcommand": "build",
-            "problemMatcher": [
-                "$rustc"
-            ],
-            "group": "build",
-            "label": "cargo build"
-        }
-    ]
-}

+ 1 - 0
crates/test-harness/.vscode

@@ -0,0 +1 @@
+../.vscode

+ 1 - 0
crates/web-host/.vscode

@@ -0,0 +1 @@
+../.vscode