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

ZMQ PUB/SUB JSON Types #330

Merged
merged 21 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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
21 changes: 21 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ members = [
"rpc/json-rpc",
"rpc/types",
"rpc/interface",
"zmq/types",
]

[profile.release]
Expand Down Expand Up @@ -321,4 +322,4 @@ non_camel_case_types = "deny"
# unused_results = "deny"
# non_exhaustive_omitted_patterns = "deny"
# missing_docs = "deny"
# missing_copy_implementations = "deny"
# missing_copy_implementations = "deny"
20 changes: 20 additions & 0 deletions zmq/types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "cuprate-zmq-types"
version = "0.1.0"
edition = "2021"
description = "Types for the ZMQ Pub/Sub API"
license = "MIT"
authors = ["dimalinux", "The Monero Project"]
dimalinux marked this conversation as resolved.
Show resolved Hide resolved
repository = "https://github.com/Cuprate/cuprate/tree/main/zmq/types"

[dependencies]
serde = { workspace = true, features = ["derive"] }
hex = { workspace = true, features = ["std", "serde"] }
cuprate-types = { path = "../../types", features = ["hex"] }
dimalinux marked this conversation as resolved.
Show resolved Hide resolved

[dev-dependencies]
serde_json = { workspace = true, features = ["std"] }
assert-json-diff = "2.0.2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO I would rather have worse error messages on tests than pull an extra dep in

Copy link
Contributor Author

@dimalinux dimalinux Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pulled it in as a dev-only dependency, because testing JSON equality is a very non-trivial thing to do. Client readers are not supposed to care about whitespace or the order of fields within an object. If the input object is a map, its field output emit order can even vary between test runs.

In Golang, the feature to test JSON equality is built right into the most popular testing library (testify). assert-json-diff appeared to be the most widely used option for testing JSON-backwards-compatibility in Rust.

I did verify that the library differentiates between empty lists and nil lists, and the other types of backwards compatibility that we care about.

If, after reading this, we still don't want to use the assert-json-diff crate, let me know and I'll find a way to make the tests work without it. We are not using any maps, so it should be possible. The expected values will probably have to be on single, super-long lines, so they won't be human readable. Or I can get the test samples formatted in the same way as serde's pretty print and use multi-line raw strings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seen as it is only a dev dep we can keep it for now, although it might get removed to reduce the number of deps in the future


[lints]
workspace = true
Loading