From 5b7c1aa4872a60d9463e6af51c3098e723202323 Mon Sep 17 00:00:00 2001 From: Jost Schulte Date: Mon, 11 Dec 2023 13:07:07 -0600 Subject: [PATCH] test: add conductor api serialization guard (#46) * build(serde): set minimum v1.0.181 * test: conductor api serialization * ci: update actions * ci: try without nix * ci: clean up ci config * ci: switch to flake & lint and test in one action * ci: install nix * build(nix): slim down to rustDev shell * fix: clippy & fmt commands * ci: split workflow into test + lint * build(serde): pin to v1.0.193 * ci: rename jobs --- .github/workflows/build.yaml | 2 +- .github/workflows/lint.yaml | 14 +- .github/workflows/test.yaml | 13 +- .gitignore | 1 + crates/holochain_serialized_bytes/Cargo.toml | 2 +- crates/holochain_serialized_bytes/src/lib.rs | 31 ++ flake.lock | 467 +++++++++++++++++++ flake.nix | 24 + test/holochain_serialized_bytes/Cargo.toml | 2 +- 9 files changed, 541 insertions(+), 15 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 5ca5b57..592612c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -9,7 +9,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 61f3880..354678d 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -6,9 +6,11 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: cachix/install-nix-action@v18 - with: - nix_path: nixpkgs=channel:nixos-unstable - - run: nix-shell --run hn-rust-fmt-check - - run: nix-shell --run hn-rust-clippy \ No newline at end of file + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v23 + - name: Build Nix packages for dev shell + run: nix develop -c $SHELL -c "rustc --version --verbose" + - name: Run fmt + run: nix develop -c $SHELL -c "script-holochain-tests-static-fmt" + - name: Run clippy + run: nix develop -c $SHELL -c "script-holochain-tests-static-clippy" diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 38d6bce..a719d3d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -3,11 +3,12 @@ name: test on: [push] jobs: - cargo-test: + test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: cachix/install-nix-action@v18 - with: - nix_path: nixpkgs=channel:nixos-unstable - - run: nix-shell --run "cargo test" \ No newline at end of file + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v23 + - name: Build Nix packages for dev shell + run: nix develop -c $SHELL -c "rustc --version --verbose" + - name: Run tests + run: nix develop -c $SHELL -c "cargo test" diff --git a/.gitignore b/.gitignore index dd0c1aa..b4ee9c7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ Cargo.lock target .cargo **/*.rs.bk +.pre-commit-config.yaml # Environment Cruft .idea diff --git a/crates/holochain_serialized_bytes/Cargo.toml b/crates/holochain_serialized_bytes/Cargo.toml index acc639b..b7dfc4a 100644 --- a/crates/holochain_serialized_bytes/Cargo.toml +++ b/crates/holochain_serialized_bytes/Cargo.toml @@ -12,7 +12,7 @@ repository = "https://github.com/holochain/holochain-serialization" edition = "2018" [dependencies] -serde = { version = "1.0.123", features = ["serde_derive"] } +serde = { version = "=1.0.193", features = ["serde_derive"] } serde_json = { version = "1.0.51", features = ["preserve_order"] } holochain_serialized_bytes_derive = { version = "=0.0.53", path = "../holochain_serialized_bytes_derive" } rmp-serde = "0.15" diff --git a/crates/holochain_serialized_bytes/src/lib.rs b/crates/holochain_serialized_bytes/src/lib.rs index 89869e2..2ba515e 100644 --- a/crates/holochain_serialized_bytes/src/lib.rs +++ b/crates/holochain_serialized_bytes/src/lib.rs @@ -310,9 +310,40 @@ impl<'a> TryFrom<&'a SerializedBytes> for SerializedBytes { #[cfg(test)] pub mod tests { + use serde_json::Value; + use super::prelude::*; use std::convert::TryInto; + #[test] + fn conductor_api() { + use rmp_serde::Deserializer; + + #[derive(Serialize, Deserialize, Debug)] + #[serde(rename_all = "snake_case", tag = "type", content = "data")] + enum ConductorApi { + Request { param: i32 }, + } + + let request = ConductorApi::Request { param: 100 }; + let request_encoded = encode(&request).unwrap(); + assert_eq!( + request_encoded, + [ + 130, 164, 116, 121, 112, 101, 129, 167, 114, 101, 113, 117, 101, 115, 116, 192, + 164, 100, 97, 116, 97, 129, 165, 112, 97, 114, 97, 109, 100 + ] + ); + + let mut deserializer = Deserializer::new(&*request_encoded); + let value: Value = Deserialize::deserialize(&mut deserializer).unwrap(); + let json_string = serde_json::to_string(&value).unwrap(); + assert_eq!( + r#"{"type":{"request":null},"data":{"param":100}}"#, + json_string + ); + } + /// struct with a utf8 string in it #[derive(Serialize, Deserialize, PartialEq, Debug, Clone, SerializedBytes)] struct Foo { diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..305b35f --- /dev/null +++ b/flake.lock @@ -0,0 +1,467 @@ +{ + "nodes": { + "cargo-chef": { + "flake": false, + "locked": { + "lastModified": 1672901199, + "narHash": "sha256-MHTuR4aQ1rQaBKx1vWDy2wbvcT0ZAzpkVB2zylSC+k0=", + "owner": "LukeMathWalker", + "repo": "cargo-chef", + "rev": "5c9f11578a2e0783cce27666737d50f84510b8b5", + "type": "github" + }, + "original": { + "owner": "LukeMathWalker", + "ref": "main", + "repo": "cargo-chef", + "type": "github" + } + }, + "cargo-rdme": { + "flake": false, + "locked": { + "lastModified": 1675118998, + "narHash": "sha256-lrYWqu3h88fr8gG3Yo5GbFGYaq5/1Os7UtM+Af0Bg4k=", + "owner": "orium", + "repo": "cargo-rdme", + "rev": "f9dbb6bccc078f4869f45ae270a2890ac9a75877", + "type": "github" + }, + "original": { + "owner": "orium", + "ref": "v1.1.0", + "repo": "cargo-rdme", + "type": "github" + } + }, + "crane": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": [ + "holonix", + "nixpkgs" + ], + "rust-overlay": "rust-overlay" + }, + "locked": { + "lastModified": 1675475924, + "narHash": "sha256-KWdfV9a6+zG6Ij/7PZYLnomjBZZUu8gdRy+hfjGrrJQ=", + "owner": "ipetkov", + "repo": "crane", + "rev": "1bde9c762ebf26de9f8ecf502357c92105bc4577", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "crate2nix": { + "flake": false, + "locked": { + "lastModified": 1693149153, + "narHash": "sha256-HUszQcnIal1FFRAWraODDbxTp0HECwczRTD+Zf0v9o0=", + "owner": "kolloch", + "repo": "crate2nix", + "rev": "8749f46953b46d44fd181b002399e4a20371f323", + "type": "github" + }, + "original": { + "owner": "kolloch", + "repo": "crate2nix", + "type": "github" + } + }, + "empty": { + "flake": false, + "locked": { + "lastModified": 1683792623, + "narHash": "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo=", + "owner": "steveej", + "repo": "empty", + "rev": "8e328e450e4cd32e072eba9e99fe92cf2a1ef5cf", + "type": "github" + }, + "original": { + "owner": "steveej", + "repo": "empty", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1675295133, + "narHash": "sha256-dU8fuLL98WFXG0VnRgM00bqKX6CEPBLybhiIDIgO45o=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "bf53492df08f3178ce85e0c9df8ed8d03c030c9f", + "type": "github" + }, + "original": { + "id": "flake-parts", + "type": "indirect" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "holochain": { + "flake": false, + "locked": { + "lastModified": 1700008501, + "narHash": "sha256-dfktlBmLf6vea5lCxFCFSD56xwdIesaGsBE3Krzt1l4=", + "owner": "holochain", + "repo": "holochain", + "rev": "6507dc5c874e9148cbd08cd0356031fe28066a8d", + "type": "github" + }, + "original": { + "owner": "holochain", + "ref": "holochain-0.3.0-beta-dev.24", + "repo": "holochain", + "type": "github" + } + }, + "holonix": { + "inputs": { + "cargo-chef": "cargo-chef", + "cargo-rdme": "cargo-rdme", + "crane": "crane", + "crate2nix": "crate2nix", + "empty": "empty", + "flake-compat": "flake-compat_2", + "flake-parts": "flake-parts", + "holochain": [ + "holonix", + "empty" + ], + "lair": [ + "holonix", + "empty" + ], + "launcher": [ + "holonix", + "empty" + ], + "nix-filter": "nix-filter", + "nixpkgs": "nixpkgs", + "pre-commit-hooks-nix": "pre-commit-hooks-nix", + "repo-git": "repo-git", + "rust-overlay": "rust-overlay_2", + "scaffolding": [ + "holonix", + "empty" + ], + "versions": [ + "versions" + ] + }, + "locked": { + "lastModified": 1700609794, + "narHash": "sha256-ucEV/uaVNDP4c6t3oi5GmHZThTxVSQeBiSHelwh7Ce8=", + "owner": "holochain", + "repo": "holochain", + "rev": "d8ac8141864965481fc64db1bfa5b1902caae6fe", + "type": "github" + }, + "original": { + "owner": "holochain", + "repo": "holochain", + "type": "github" + } + }, + "lair": { + "flake": false, + "locked": { + "lastModified": 1691746070, + "narHash": "sha256-CHsTI4yIlkfnYWx2sNgzAoDBvKTLIChybzyJNbB1sMU=", + "owner": "holochain", + "repo": "lair", + "rev": "6ab41b60744515f1760669db6fc5272298a5f324", + "type": "github" + }, + "original": { + "owner": "holochain", + "ref": "lair_keystore-v0.3.0", + "repo": "lair", + "type": "github" + } + }, + "launcher": { + "flake": false, + "locked": { + "lastModified": 1696872398, + "narHash": "sha256-wRFBUxweljJShXNEZlZGUKScBPVQm6ydH1QFvoNlbIE=", + "owner": "holochain", + "repo": "launcher", + "rev": "1beda27221504085ae1dd537788433bee9c6f353", + "type": "github" + }, + "original": { + "owner": "holochain", + "ref": "holochain-weekly", + "repo": "launcher", + "type": "github" + } + }, + "nix-filter": { + "locked": { + "lastModified": 1675361037, + "narHash": "sha256-CTbDuDxFD3U3g/dWUB+r+B/snIe+qqP1R+1myuFGe2I=", + "owner": "numtide", + "repo": "nix-filter", + "rev": "e1b2f96c2a31415f362268bc48c3fccf47dff6eb", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "nix-filter", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1700390070, + "narHash": "sha256-de9KYi8rSJpqvBfNwscWdalIJXPo8NjdIZcEJum1mH0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e4ad989506ec7d71f7302cc3067abd82730a4beb", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1675183161, + "narHash": "sha256-Zq8sNgAxDckpn7tJo7V1afRSk2eoVbu3OjI1QklGLNg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e1e1b192c1a5aab2960bf0a0bd53a2e8124fa18e", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks-nix": { + "flake": false, + "locked": { + "lastModified": 1676513100, + "narHash": "sha256-MK39nQV86L2ag4TmcK5/+r1ULpzRLPbbfvWbPvIoYJE=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "5f0cba88ac4d6dd8cad5c6f6f1540b3d6a21a798", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "repo-git": { + "flake": false, + "locked": { + "narHash": "sha256-d6xi4mKdjkX2JFicDIv5niSzpyI0m/Hnm8GGAIU04kY=", + "type": "file", + "url": "file:/dev/null" + }, + "original": { + "type": "file", + "url": "file:/dev/null" + } + }, + "root": { + "inputs": { + "holonix": "holonix", + "nixpkgs": [ + "holonix", + "nixpkgs" + ], + "versions": "versions" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "holonix", + "crane", + "flake-utils" + ], + "nixpkgs": [ + "holonix", + "crane", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1675391458, + "narHash": "sha256-ukDKZw922BnK5ohL9LhwtaDAdCsJL7L6ScNEyF1lO9w=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "383a4acfd11d778d5c2efcf28376cbd845eeaedf", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "rust-overlay_2": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "holonix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1700533079, + "narHash": "sha256-K/8s5LXVQquJWrMcM7NG70o/S5Bxm2D64on5qju3tQY=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "6da9555a6d691bcdf43f90d8fd445e96d246f807", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "scaffolding": { + "flake": false, + "locked": { + "lastModified": 1695674679, + "narHash": "sha256-IwgQbgitUo61ZXYSXBAro5ThfYy/yMGmzZGTb3c6sT0=", + "owner": "holochain", + "repo": "scaffolding", + "rev": "821439b8dd49d5ce594be04c4720df25e88a4dbc", + "type": "github" + }, + "original": { + "owner": "holochain", + "ref": "holochain-0.2", + "repo": "scaffolding", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "versions": { + "inputs": { + "holochain": "holochain", + "lair": "lair", + "launcher": "launcher", + "scaffolding": "scaffolding" + }, + "locked": { + "dir": "versions/weekly", + "lastModified": 1700609794, + "narHash": "sha256-ucEV/uaVNDP4c6t3oi5GmHZThTxVSQeBiSHelwh7Ce8=", + "owner": "holochain", + "repo": "holochain", + "rev": "d8ac8141864965481fc64db1bfa5b1902caae6fe", + "type": "github" + }, + "original": { + "dir": "versions/weekly", + "owner": "holochain", + "repo": "holochain", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..564172e --- /dev/null +++ b/flake.nix @@ -0,0 +1,24 @@ +{ + inputs = { + nixpkgs.follows = "holonix/nixpkgs"; + + versions.url = "github:holochain/holochain?dir=versions/weekly"; + holonix.url = "github:holochain/holochain"; + holonix.inputs.versions.follows = "versions"; + }; + + outputs = inputs@{ holonix, ... }: + holonix.inputs.flake-parts.lib.mkFlake { inherit inputs; } { + systems = builtins.attrNames holonix.devShells; + + perSystem = { config, system, pkgs, ... }: + { + devShells.default = pkgs.mkShell { + inputsFrom = [ holonix.devShells.${system}.coreDev ]; + packages = with pkgs; [ + # add further packages from nixpkgs + ]; + }; + }; + }; +} diff --git a/test/holochain_serialized_bytes/Cargo.toml b/test/holochain_serialized_bytes/Cargo.toml index cee63cc..e7c27ef 100644 --- a/test/holochain_serialized_bytes/Cargo.toml +++ b/test/holochain_serialized_bytes/Cargo.toml @@ -12,7 +12,7 @@ repository = "https://github.com/holochain/holochain-serialization" [dependencies] holochain_serialized_bytes = { version = "=0.0.53", path = "../../crates/holochain_serialized_bytes" } -serde = "1.0.123" +serde = "=1.0.193" [dev-dependencies] test-fuzz = "=3.0.4"