Skip to content

Commit

Permalink
test: add conductor api serialization guard (#46)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jost-s authored Dec 11, 2023
1 parent e1c42dd commit 5b7c1aa
Show file tree
Hide file tree
Showing 9 changed files with 541 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- 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"
13 changes: 7 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
- 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"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Cargo.lock
target
.cargo
**/*.rs.bk
.pre-commit-config.yaml

# Environment Cruft
.idea
Expand Down
2 changes: 1 addition & 1 deletion crates/holochain_serialized_bytes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 31 additions & 0 deletions crates/holochain_serialized_bytes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 5b7c1aa

Please sign in to comment.