Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add conductor api serialization guard #46

Merged
merged 12 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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: 0 additions & 14 deletions .github/workflows/lint.yaml

This file was deleted.

17 changes: 11 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ name: test
on: [push]

jobs:
cargo-test:
lint-and-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 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"
- 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.181", features = ["serde_derive"] }
jost-s marked this conversation as resolved.
Show resolved Hide resolved
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